refactor: scanner fails with the contract error; env via HostProcessEnvironment

The server-local error was a field-for-field clone of the contract
AgentSessionScanError, so the ws.ts mapping was an identity re-tag; the
service now fails with the contract error directly. CLAUDE_CONFIG_DIR reads
through the injectable HostProcessEnvironment reference.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-08-04 15:06:15 -07:00
1 parent 72a3c9f0e1
commit 5fdc0a3381
2 files changed
+16 -36

No files matched your search

+13 -22
View File
@@ -15,7 +15,11 @@
*/
import * as NodeOS from "node:os";
import type { AgentSessionProjectCandidate, AgentSessionScanResult } from "@t3tools/contracts";
import {
AgentSessionScanError,
type AgentSessionProjectCandidate,
type AgentSessionScanResult,
} from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
@@ -23,9 +27,8 @@ import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import * as Schema from "effect/Schema";
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
import { HostProcessEnvironment, HostProcessPlatform } from "@t3tools/shared/hostProcess";
import * as ServerConfig from "../config.ts";
import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
@@ -46,18 +49,6 @@ const TRANSCRIPT_PREFIX_BYTES = 32 * 1024;
*/
const MAX_TRANSCRIPTS_PER_SOURCE = 5000;
export class AgentSessionScanFailedError extends Schema.TaggedErrorClass<AgentSessionScanFailedError>()(
"AgentSessionScanFailedError",
{
operation: Schema.Literals(["read-settings", "read-projects"]),
cause: Schema.Defect(),
},
) {
override get message(): string {
return `Failed to scan agent sessions during ${this.operation}.`;
}
}
/** Service tag for agent session discovery. */
export class AgentSessionScanner extends Context.Service<
AgentSessionScanner,
@@ -65,9 +56,10 @@ export class AgentSessionScanner extends Context.Service<
/**
* Discover every directory the configured Claude and Codex homes have run
* a session in. Candidates are returned newest-first; the client decides
* which ones to import and how far back to look.
* which ones to import and how far back to look. Fails with the contract
* error directly — there is no server-local context worth wrapping.
*/
readonly scan: Effect.Effect<AgentSessionScanResult, AgentSessionScanFailedError>;
readonly scan: Effect.Effect<AgentSessionScanResult, AgentSessionScanError>;
}
>()("t3/project/AgentSessionScanner") {}
@@ -145,6 +137,7 @@ export const make = Effect.gen(function* () {
// Windows filesystems are case-insensitive, so path prefix checks there
// must case fold.
const foldWorktreeCase = (yield* HostProcessPlatform) === "win32";
const hostEnvironment = yield* HostProcessEnvironment;
const listDirectory = (directory: string) =>
fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
@@ -209,7 +202,7 @@ export const make = Effect.gen(function* () {
if (configured.length > 0) {
return path.resolve(expandHomePath(configured));
}
const fromEnvironment = process.env.CLAUDE_CONFIG_DIR?.trim() ?? "";
const fromEnvironment = hostEnvironment.CLAUDE_CONFIG_DIR?.trim() ?? "";
if (fromEnvironment.length > 0) {
return path.resolve(expandHomePath(fromEnvironment));
}
@@ -328,9 +321,7 @@ export const make = Effect.gen(function* () {
const scan: AgentSessionScanner["Service"]["scan"] = Effect.gen(function* () {
const settings = yield* serverSettings.getSettings.pipe(
Effect.mapError(
(cause) => new AgentSessionScanFailedError({ operation: "read-settings", cause }),
),
Effect.mapError((cause) => new AgentSessionScanError({ operation: "read-settings", cause })),
);
const raw = [
@@ -403,7 +394,7 @@ export const make = Effect.gen(function* () {
.getActiveProjectByWorkspaceRoot(lookupPath)
.pipe(
Effect.mapError(
(cause) => new AgentSessionScanFailedError({ operation: "read-projects", cause }),
(cause) => new AgentSessionScanError({ operation: "read-projects", cause }),
),
);
if (Option.isSome(existingProject)) {
+3 -14
View File
@@ -46,7 +46,6 @@ import {
type ServerSelfUpdateProgressEvent,
type FilesystemBrowseFailure,
FilesystemBrowseError,
AgentSessionScanError,
AssetWorkspaceContextNotFoundError,
AssetWorkspaceContextResolutionError,
RpcClientId,
@@ -1703,19 +1702,9 @@ const makeWsRpcLayer = (
{ "rpc.aggregate": "workspace" },
),
[WS_METHODS.agentSessionsScan]: () =>
observeRpcEffect(
WS_METHODS.agentSessionsScan,
agentSessionScanner.scan.pipe(
Effect.mapError(
(cause) =>
new AgentSessionScanError({
operation: cause.operation,
cause,
}),
),
),
{ "rpc.aggregate": "workspace" },
),
observeRpcEffect(WS_METHODS.agentSessionsScan, agentSessionScanner.scan, {
"rpc.aggregate": "workspace",
}),
[WS_METHODS.assetsCreateUrl]: (input) =>
observeRpcEffect(
WS_METHODS.assetsCreateUrl,