diff --git a/src/resources/extensions/gsd/auto.ts b/src/resources/extensions/gsd/auto.ts index 062715bbd..0c6d67c21 100644 --- a/src/resources/extensions/gsd/auto.ts +++ b/src/resources/extensions/gsd/auto.ts @@ -38,6 +38,7 @@ import { clearActivityLogState } from "./activity-log.js"; import { synthesizeCrashRecovery, getDeepDiagnostic, + readActiveMilestoneId, } from "./session-forensics.js"; import { writeLock, @@ -980,7 +981,11 @@ function buildLoopDeps(): LoopDeps { startUnitSupervision, // Prompt helpers - getDeepDiagnostic, + getDeepDiagnostic: (basePath: string) => { + const mid = readActiveMilestoneId(basePath); + const wtPath = mid ? getAutoWorktreePath(basePath, mid) : undefined; + return getDeepDiagnostic(basePath, wtPath ?? undefined); + }, isDbAvailable, reorderForCaching, diff --git a/src/resources/extensions/gsd/session-forensics.ts b/src/resources/extensions/gsd/session-forensics.ts index e5dbe78e0..f01a4b8e1 100644 --- a/src/resources/extensions/gsd/session-forensics.ts +++ b/src/resources/extensions/gsd/session-forensics.ts @@ -25,7 +25,6 @@ import { truncateWithEllipsis } from "../shared/format-utils.js"; import { nativeParseJsonlTail } from "./native-parser-bridge.js"; import { MAX_JSONL_BYTES, parseJSONL } from "./jsonl-utils.js"; import { nativeWorkingTreeStatus, nativeDiffStat } from "./native-git-bridge.js"; -import { getAutoWorktreePath } from "./auto-worktree.js"; // ─── Types ──────────────────────────────────────────────────────────────────── @@ -295,17 +294,13 @@ export function synthesizeCrashRecovery( * Deep diagnostic from any JSONL source (activity log or session file). * Replaces the old shallow getLastActivityDiagnostic(). */ -export function getDeepDiagnostic(basePath: string): string | null { - // Try worktree activity logs first if an auto-worktree is active +export function getDeepDiagnostic(basePath: string, worktreePath?: string): string | null { + // Try worktree activity logs first if a worktree path is provided let trace: ExecutionTrace | null = null; try { - const mid = readActiveMilestoneId(basePath); - if (mid) { - const wtPath = getAutoWorktreePath(basePath, mid); - if (wtPath) { - const wtActivityDir = join(gsdRoot(wtPath), "activity"); - trace = readLastActivityLog(wtActivityDir); - } + if (worktreePath) { + const wtActivityDir = join(gsdRoot(worktreePath), "activity"); + trace = readLastActivityLog(wtActivityDir); } } catch { /* non-fatal — fall through to root */ } @@ -323,7 +318,7 @@ export function getDeepDiagnostic(basePath: string): string | null { * Read the active milestone ID directly from STATE.md without async deriveState(). * Looks for `**Active Milestone:** M001` pattern. */ -function readActiveMilestoneId(basePath: string): string | null { +export function readActiveMilestoneId(basePath: string): string | null { try { const statePath = join(gsdRoot(basePath), "STATE.md"); if (!existsSync(statePath)) return null;