From 5fdc0a33818db9adc8dfef829721c779b7da2123 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Tue, 4 Aug 2026 15:06:15 -0700 Subject: [PATCH] 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 --- .../server/src/project/AgentSessionScanner.ts | 35 +++++++------------ apps/server/src/ws.ts | 17 ++------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index f83f6ecfe2..dfe6ad7c7f 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -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", - { - 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; + readonly scan: Effect.Effect; } >()("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 => [])); @@ -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)) { diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 0172130106..423ef6c008 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -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,