gsd-pi 2.32.0 → 2.33.0-dev.69bff0f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +22 -20
  2. package/dist/resource-loader.js +13 -3
  3. package/dist/resources/extensions/gsd/auto-dashboard.ts +3 -1
  4. package/dist/resources/extensions/gsd/auto-dispatch.ts +40 -12
  5. package/dist/resources/extensions/gsd/auto-idempotency.ts +3 -2
  6. package/dist/resources/extensions/gsd/auto-observability.ts +2 -4
  7. package/dist/resources/extensions/gsd/auto-post-unit.ts +5 -5
  8. package/dist/resources/extensions/gsd/auto-prompts.ts +46 -44
  9. package/dist/resources/extensions/gsd/auto-recovery.ts +8 -22
  10. package/dist/resources/extensions/gsd/auto-start.ts +8 -6
  11. package/dist/resources/extensions/gsd/auto-stuck-detection.ts +3 -2
  12. package/dist/resources/extensions/gsd/auto-supervisor.ts +10 -5
  13. package/dist/resources/extensions/gsd/auto-timeout-recovery.ts +2 -1
  14. package/dist/resources/extensions/gsd/auto-timers.ts +3 -2
  15. package/dist/resources/extensions/gsd/auto-verification.ts +6 -6
  16. package/dist/resources/extensions/gsd/auto-worktree.ts +140 -5
  17. package/dist/resources/extensions/gsd/auto.ts +108 -182
  18. package/dist/resources/extensions/gsd/commands-inspect.ts +2 -1
  19. package/dist/resources/extensions/gsd/commands-workflow-templates.ts +2 -1
  20. package/dist/resources/extensions/gsd/commands.ts +14 -2
  21. package/dist/resources/extensions/gsd/complexity-classifier.ts +5 -7
  22. package/dist/resources/extensions/gsd/crash-recovery.ts +15 -2
  23. package/dist/resources/extensions/gsd/dispatch-guard.ts +2 -1
  24. package/dist/resources/extensions/gsd/error-utils.ts +6 -0
  25. package/dist/resources/extensions/gsd/export.ts +2 -1
  26. package/dist/resources/extensions/gsd/git-service.ts +3 -2
  27. package/dist/resources/extensions/gsd/guided-flow.ts +3 -2
  28. package/dist/resources/extensions/gsd/index.ts +12 -5
  29. package/dist/resources/extensions/gsd/key-manager.ts +2 -1
  30. package/dist/resources/extensions/gsd/marketplace-discovery.ts +4 -3
  31. package/dist/resources/extensions/gsd/metrics.ts +3 -3
  32. package/dist/resources/extensions/gsd/migrate-external.ts +21 -4
  33. package/dist/resources/extensions/gsd/milestone-ids.ts +2 -1
  34. package/dist/resources/extensions/gsd/native-git-bridge.ts +2 -1
  35. package/dist/resources/extensions/gsd/parallel-merge.ts +2 -1
  36. package/dist/resources/extensions/gsd/parallel-orchestrator.ts +2 -1
  37. package/dist/resources/extensions/gsd/post-unit-hooks.ts +8 -9
  38. package/dist/resources/extensions/gsd/quick.ts +58 -3
  39. package/dist/resources/extensions/gsd/repo-identity.ts +22 -1
  40. package/dist/resources/extensions/gsd/session-lock.ts +86 -11
  41. package/dist/resources/extensions/gsd/tests/all-milestones-complete-merge.test.ts +14 -11
  42. package/dist/resources/extensions/gsd/tests/auto-dispatch-loop.test.ts +691 -0
  43. package/dist/resources/extensions/gsd/tests/cache-staleness-regression.test.ts +317 -0
  44. package/dist/resources/extensions/gsd/tests/context-compression.test.ts +1 -1
  45. package/dist/resources/extensions/gsd/tests/loop-regression.test.ts +877 -0
  46. package/dist/resources/extensions/gsd/tests/roadmap-parse-regression.test.ts +358 -0
  47. package/dist/resources/extensions/gsd/tests/session-lock-regression.test.ts +216 -0
  48. package/dist/resources/extensions/gsd/tests/session-lock.test.ts +119 -0
  49. package/dist/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +206 -0
  50. package/dist/resources/extensions/gsd/undo.ts +5 -7
  51. package/dist/resources/extensions/gsd/unit-id.ts +14 -0
  52. package/dist/resources/extensions/gsd/unit-runtime.ts +2 -1
  53. package/dist/resources/extensions/gsd/worktree-command.ts +8 -7
  54. package/package.json +3 -2
  55. package/packages/pi-coding-agent/package.json +1 -1
  56. package/pkg/package.json +1 -1
  57. package/src/resources/extensions/gsd/auto-dashboard.ts +3 -1
  58. package/src/resources/extensions/gsd/auto-dispatch.ts +40 -12
  59. package/src/resources/extensions/gsd/auto-idempotency.ts +3 -2
  60. package/src/resources/extensions/gsd/auto-observability.ts +2 -4
  61. package/src/resources/extensions/gsd/auto-post-unit.ts +5 -5
  62. package/src/resources/extensions/gsd/auto-prompts.ts +46 -44
  63. package/src/resources/extensions/gsd/auto-recovery.ts +8 -22
  64. package/src/resources/extensions/gsd/auto-start.ts +8 -6
  65. package/src/resources/extensions/gsd/auto-stuck-detection.ts +3 -2
  66. package/src/resources/extensions/gsd/auto-supervisor.ts +10 -5
  67. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +2 -1
  68. package/src/resources/extensions/gsd/auto-timers.ts +3 -2
  69. package/src/resources/extensions/gsd/auto-verification.ts +6 -6
  70. package/src/resources/extensions/gsd/auto-worktree.ts +140 -5
  71. package/src/resources/extensions/gsd/auto.ts +108 -182
  72. package/src/resources/extensions/gsd/commands-inspect.ts +2 -1
  73. package/src/resources/extensions/gsd/commands-workflow-templates.ts +2 -1
  74. package/src/resources/extensions/gsd/commands.ts +14 -2
  75. package/src/resources/extensions/gsd/complexity-classifier.ts +5 -7
  76. package/src/resources/extensions/gsd/crash-recovery.ts +15 -2
  77. package/src/resources/extensions/gsd/dispatch-guard.ts +2 -1
  78. package/src/resources/extensions/gsd/error-utils.ts +6 -0
  79. package/src/resources/extensions/gsd/export.ts +2 -1
  80. package/src/resources/extensions/gsd/git-service.ts +3 -2
  81. package/src/resources/extensions/gsd/guided-flow.ts +3 -2
  82. package/src/resources/extensions/gsd/index.ts +12 -5
  83. package/src/resources/extensions/gsd/key-manager.ts +2 -1
  84. package/src/resources/extensions/gsd/marketplace-discovery.ts +4 -3
  85. package/src/resources/extensions/gsd/metrics.ts +3 -3
  86. package/src/resources/extensions/gsd/migrate-external.ts +21 -4
  87. package/src/resources/extensions/gsd/milestone-ids.ts +2 -1
  88. package/src/resources/extensions/gsd/native-git-bridge.ts +2 -1
  89. package/src/resources/extensions/gsd/parallel-merge.ts +2 -1
  90. package/src/resources/extensions/gsd/parallel-orchestrator.ts +2 -1
  91. package/src/resources/extensions/gsd/post-unit-hooks.ts +8 -9
  92. package/src/resources/extensions/gsd/quick.ts +58 -3
  93. package/src/resources/extensions/gsd/repo-identity.ts +22 -1
  94. package/src/resources/extensions/gsd/session-lock.ts +86 -11
  95. package/src/resources/extensions/gsd/tests/all-milestones-complete-merge.test.ts +14 -11
  96. package/src/resources/extensions/gsd/tests/auto-dispatch-loop.test.ts +691 -0
  97. package/src/resources/extensions/gsd/tests/cache-staleness-regression.test.ts +317 -0
  98. package/src/resources/extensions/gsd/tests/context-compression.test.ts +1 -1
  99. package/src/resources/extensions/gsd/tests/loop-regression.test.ts +877 -0
  100. package/src/resources/extensions/gsd/tests/roadmap-parse-regression.test.ts +358 -0
  101. package/src/resources/extensions/gsd/tests/session-lock-regression.test.ts +216 -0
  102. package/src/resources/extensions/gsd/tests/session-lock.test.ts +119 -0
  103. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +206 -0
  104. package/src/resources/extensions/gsd/undo.ts +5 -7
  105. package/src/resources/extensions/gsd/unit-id.ts +14 -0
  106. package/src/resources/extensions/gsd/unit-runtime.ts +2 -1
  107. package/src/resources/extensions/gsd/worktree-command.ts +8 -7
  108. package/dist/resources/extensions/mcporter/extension-manifest.json +0 -12
  109. package/src/resources/extensions/mcporter/extension-manifest.json +0 -12
@@ -12,6 +12,7 @@ import {
12
12
  formatValidationIssues,
13
13
  } from "./observability-validator.js";
14
14
  import type { ValidationIssue } from "./observability-validator.js";
15
+ import { parseUnitId } from "./unit-id.js";
15
16
 
16
17
  export async function collectObservabilityWarnings(
17
18
  ctx: ExtensionContext,
@@ -22,10 +23,7 @@ export async function collectObservabilityWarnings(
22
23
  // Hook units have custom artifacts — skip standard observability checks
23
24
  if (unitType.startsWith("hook/")) return [];
24
25
 
25
- const parts = unitId.split("/");
26
- const mid = parts[0];
27
- const sid = parts[1];
28
- const tid = parts[2];
26
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
29
27
 
30
28
  if (!mid || !sid) return [];
31
29
 
@@ -61,6 +61,7 @@ import {
61
61
  } from "./auto-dashboard.js";
62
62
  import { join } from "node:path";
63
63
  import { STATE_REBUILD_MIN_INTERVAL_MS } from "./auto-constants.js";
64
+ import { parseUnitId } from "./unit-id.js";
64
65
 
65
66
  /**
66
67
  * Initialize a unit dispatch: stamp the current time, set `s.currentUnit`,
@@ -134,8 +135,7 @@ export async function postUnitPreVerification(pctx: PostUnitContext): Promise<"d
134
135
  let taskContext: TaskCommitContext | undefined;
135
136
 
136
137
  if (s.currentUnit.type === "execute-task") {
137
- const parts = s.currentUnit.id.split("/");
138
- const [mid, sid, tid] = parts;
138
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(s.currentUnit.id);
139
139
  if (mid && sid && tid) {
140
140
  const summaryPath = resolveTaskFile(s.basePath, mid, sid, tid, "SUMMARY");
141
141
  if (summaryPath) {
@@ -167,8 +167,8 @@ export async function postUnitPreVerification(pctx: PostUnitContext): Promise<"d
167
167
 
168
168
  // Doctor: fix mechanical bookkeeping
169
169
  try {
170
- const scopeParts = s.currentUnit.id.split("/").slice(0, 2);
171
- const doctorScope = scopeParts.join("/");
170
+ const { milestone, slice } = parseUnitId(s.currentUnit.id);
171
+ const doctorScope = slice ? `${milestone}/${slice}` : milestone;
172
172
  const sliceTerminalUnits = new Set(["complete-slice", "run-uat"]);
173
173
  const effectiveFixLevel = sliceTerminalUnits.has(s.currentUnit.type) ? "all" as const : "task" as const;
174
174
  const report = await runGSDDoctor(s.basePath, { fix: true, scope: doctorScope, fixLevel: effectiveFixLevel });
@@ -348,7 +348,7 @@ export async function postUnitPostVerification(pctx: PostUnitContext): Promise<"
348
348
  // instead of dispatching LLM sessions for complete-slice / validate-milestone.
349
349
  if (s.currentUnit?.type === "execute-task" && !s.stepMode) {
350
350
  try {
351
- const [mid, sid] = s.currentUnit.id.split("/");
351
+ const { milestone: mid, slice: sid } = parseUnitId(s.currentUnit.id);
352
352
  if (mid && sid) {
353
353
  const state = await deriveState(s.basePath);
354
354
  if (state.phase === "summarizing" && state.activeSlice?.id === sid) {
@@ -189,30 +189,52 @@ export async function inlineGsdRootFile(
189
189
  // ─── DB-Aware Inline Helpers ──────────────────────────────────────────────
190
190
 
191
191
  /**
192
- * Inline decisions with optional milestone scoping from the DB.
193
- * Falls back to filesystem via inlineGsdRootFile when DB unavailable or empty.
192
+ * Shared DB-fallback pattern: attempt a DB query via the context-store, format
193
+ * the result, and fall back to the filesystem file when the DB is unavailable
194
+ * or the query yields no results.
195
+ *
196
+ * @param base Project root for filesystem fallback
197
+ * @param label Section heading (e.g. "Decisions")
198
+ * @param filename Filesystem fallback file (e.g. "decisions.md")
199
+ * @param queryDb Async callback receiving the dynamically-imported
200
+ * context-store module. Returns formatted markdown or null.
194
201
  */
195
- export async function inlineDecisionsFromDb(
196
- base: string, milestoneId?: string, scope?: string, level?: InlineLevel,
202
+ async function inlineFromDbOrFile(
203
+ base: string,
204
+ label: string,
205
+ filename: string,
206
+ queryDb: (cs: typeof import("./context-store.js")) => string | null,
197
207
  ): Promise<string | null> {
198
- const inlineLevel = level ?? resolveInlineLevel();
199
208
  try {
200
209
  const { isDbAvailable } = await import("./gsd-db.js");
201
210
  if (isDbAvailable()) {
202
- const { queryDecisions, formatDecisionsForPrompt } = await import("./context-store.js");
203
- const decisions = queryDecisions({ milestoneId, scope });
204
- if (decisions.length > 0) {
205
- // Use compact format for non-full levels to save ~35% tokens
206
- const formatted = inlineLevel !== "full"
207
- ? formatDecisionsCompact(decisions)
208
- : formatDecisionsForPrompt(decisions);
209
- return `### Decisions\nSource: \`.gsd/DECISIONS.md\`\n\n${formatted}`;
211
+ const contextStore = await import("./context-store.js");
212
+ const content = queryDb(contextStore);
213
+ if (content) {
214
+ return `### ${label}\nSource: \`.gsd/${filename.toUpperCase().replace(/\.MD$/i, "")}.md\`\n\n${content}`;
210
215
  }
211
216
  }
212
217
  } catch {
213
218
  // DB not available — fall through to filesystem
214
219
  }
215
- return inlineGsdRootFile(base, "decisions.md", "Decisions");
220
+ return inlineGsdRootFile(base, filename, label);
221
+ }
222
+
223
+ /**
224
+ * Inline decisions with optional milestone scoping from the DB.
225
+ * Falls back to filesystem via inlineGsdRootFile when DB unavailable or empty.
226
+ */
227
+ export async function inlineDecisionsFromDb(
228
+ base: string, milestoneId?: string, scope?: string, level?: InlineLevel,
229
+ ): Promise<string | null> {
230
+ const inlineLevel = level ?? resolveInlineLevel();
231
+ return inlineFromDbOrFile(base, "Decisions", "decisions.md", (cs) => {
232
+ const decisions = cs.queryDecisions({ milestoneId, scope });
233
+ if (decisions.length === 0) return null;
234
+ return inlineLevel !== "full"
235
+ ? formatDecisionsCompact(decisions)
236
+ : cs.formatDecisionsForPrompt(decisions);
237
+ });
216
238
  }
217
239
 
218
240
  /**
@@ -223,23 +245,13 @@ export async function inlineRequirementsFromDb(
223
245
  base: string, sliceId?: string, level?: InlineLevel,
224
246
  ): Promise<string | null> {
225
247
  const inlineLevel = level ?? resolveInlineLevel();
226
- try {
227
- const { isDbAvailable } = await import("./gsd-db.js");
228
- if (isDbAvailable()) {
229
- const { queryRequirements, formatRequirementsForPrompt } = await import("./context-store.js");
230
- const requirements = queryRequirements({ sliceId });
231
- if (requirements.length > 0) {
232
- // Use compact format for non-full levels to save ~40% tokens
233
- const formatted = inlineLevel !== "full"
234
- ? formatRequirementsCompact(requirements)
235
- : formatRequirementsForPrompt(requirements);
236
- return `### Requirements\nSource: \`.gsd/REQUIREMENTS.md\`\n\n${formatted}`;
237
- }
238
- }
239
- } catch {
240
- // DB not available — fall through to filesystem
241
- }
242
- return inlineGsdRootFile(base, "requirements.md", "Requirements");
248
+ return inlineFromDbOrFile(base, "Requirements", "requirements.md", (cs) => {
249
+ const requirements = cs.queryRequirements({ sliceId });
250
+ if (requirements.length === 0) return null;
251
+ return inlineLevel !== "full"
252
+ ? formatRequirementsCompact(requirements)
253
+ : cs.formatRequirementsForPrompt(requirements);
254
+ });
243
255
  }
244
256
 
245
257
  /**
@@ -249,19 +261,9 @@ export async function inlineRequirementsFromDb(
249
261
  export async function inlineProjectFromDb(
250
262
  base: string,
251
263
  ): Promise<string | null> {
252
- try {
253
- const { isDbAvailable } = await import("./gsd-db.js");
254
- if (isDbAvailable()) {
255
- const { queryProject } = await import("./context-store.js");
256
- const content = queryProject();
257
- if (content) {
258
- return `### Project\nSource: \`.gsd/PROJECT.md\`\n\n${content}`;
259
- }
260
- }
261
- } catch {
262
- // DB not available — fall through to filesystem
263
- }
264
- return inlineGsdRootFile(base, "project.md", "Project");
264
+ return inlineFromDbOrFile(base, "Project", "project.md", (cs) => {
265
+ return cs.queryProject();
266
+ });
265
267
  }
266
268
 
267
269
  // ─── Skill Discovery ──────────────────────────────────────────────────────
@@ -42,6 +42,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "
42
42
  import { atomicWriteSync } from "./atomic-write.js";
43
43
  import { loadJsonFileOrNull } from "./json-persistence.js";
44
44
  import { dirname, join } from "node:path";
45
+ import { parseUnitId } from "./unit-id.js";
45
46
 
46
47
  // ─── Artifact Resolution & Verification ───────────────────────────────────────
47
48
 
@@ -49,9 +50,7 @@ import { dirname, join } from "node:path";
49
50
  * Resolve the expected artifact for a unit to an absolute path.
50
51
  */
51
52
  export function resolveExpectedArtifactPath(unitType: string, unitId: string, base: string): string | null {
52
- const parts = unitId.split("/");
53
- const mid = parts[0]!;
54
- const sid = parts[1];
53
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
55
54
  switch (unitType) {
56
55
  case "research-milestone": {
57
56
  const dir = resolveMilestonePath(base, mid);
@@ -78,7 +77,6 @@ export function resolveExpectedArtifactPath(unitType: string, unitId: string, ba
78
77
  return dir ? join(dir, buildSliceFileName(sid!, "UAT-RESULT")) : null;
79
78
  }
80
79
  case "execute-task": {
81
- const tid = parts[2];
82
80
  const dir = resolveSlicePath(base, mid, sid!);
83
81
  return dir && tid ? join(dir, "tasks", buildTaskFileName(tid, "SUMMARY")) : null;
84
82
  }
@@ -167,10 +165,7 @@ export function verifyExpectedArtifact(unitType: string, unitId: string, base: s
167
165
 
168
166
  // execute-task must also have its checkbox marked [x] in the slice plan
169
167
  if (unitType === "execute-task") {
170
- const parts = unitId.split("/");
171
- const mid = parts[0];
172
- const sid = parts[1];
173
- const tid = parts[2];
168
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
174
169
  if (mid && sid && tid) {
175
170
  const planAbs = resolveSliceFile(base, mid, sid, "PLAN");
176
171
  if (planAbs && existsSync(planAbs)) {
@@ -187,9 +182,7 @@ export function verifyExpectedArtifact(unitType: string, unitId: string, base: s
187
182
  // but omitted T{tid}-PLAN.md files would be marked complete, causing execute-task
188
183
  // to dispatch with a missing task plan (see issue #739).
189
184
  if (unitType === "plan-slice") {
190
- const parts = unitId.split("/");
191
- const mid = parts[0];
192
- const sid = parts[1];
185
+ const { milestone: mid, slice: sid } = parseUnitId(unitId);
193
186
  if (mid && sid) {
194
187
  try {
195
188
  const planContent = readFileSync(absPath, "utf-8");
@@ -213,9 +206,8 @@ export function verifyExpectedArtifact(unitType: string, unitId: string, base: s
213
206
  // state machine keeps returning the same complete-slice unit (roadmap still shows
214
207
  // the slice incomplete), so dispatchNextUnit recurses forever.
215
208
  if (unitType === "complete-slice") {
216
- const parts = unitId.split("/");
217
- const mid = parts[0];
218
- const sid = parts[1];
209
+ const { milestone: mid, slice: sid } = parseUnitId(unitId);
210
+
219
211
  if (mid && sid) {
220
212
  const dir = resolveSlicePath(base, mid, sid);
221
213
  if (dir) {
@@ -268,9 +260,7 @@ export function writeBlockerPlaceholder(unitType: string, unitId: string, base:
268
260
  }
269
261
 
270
262
  export function diagnoseExpectedArtifact(unitType: string, unitId: string, base: string): string | null {
271
- const parts = unitId.split("/");
272
- const mid = parts[0];
273
- const sid = parts[1];
263
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
274
264
  switch (unitType) {
275
265
  case "research-milestone":
276
266
  return `${relMilestoneFile(base, mid!, "RESEARCH")} (milestone research)`;
@@ -281,7 +271,6 @@ export function diagnoseExpectedArtifact(unitType: string, unitId: string, base:
281
271
  case "plan-slice":
282
272
  return `${relSliceFile(base, mid!, sid!, "PLAN")} (slice plan)`;
283
273
  case "execute-task": {
284
- const tid = parts[2];
285
274
  return `Task ${tid} marked [x] in ${relSliceFile(base, mid!, sid!, "PLAN")} + summary written`;
286
275
  }
287
276
  case "complete-slice":
@@ -539,10 +528,7 @@ export async function selfHealRuntimeRecords(
539
528
  * These are shown when automatic reconciliation is not possible.
540
529
  */
541
530
  export function buildLoopRemediationSteps(unitType: string, unitId: string, base: string): string | null {
542
- const parts = unitId.split("/");
543
- const mid = parts[0];
544
- const sid = parts[1];
545
- const tid = parts[2];
531
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
546
532
  switch (unitType) {
547
533
  case "execute-task": {
548
534
  if (!mid || !sid || !tid) break;
@@ -63,6 +63,8 @@ import { debugLog, enableDebug, isDebugEnabled, getDebugLogPath } from "./debug-
63
63
  import type { AutoSession } from "./auto/session.js";
64
64
  import { existsSync, mkdirSync, readdirSync, statSync, unlinkSync } from "node:fs";
65
65
  import { join } from "node:path";
66
+ import { getErrorMessage } from "./error-utils.js";
67
+ import { parseUnitId } from "./unit-id.js";
66
68
 
67
69
  export interface BootstrapDeps {
68
70
  shouldUseWorktreeIsolation: () => boolean;
@@ -138,7 +140,7 @@ export async function bootstrapAutoSession(
138
140
  if (crashLock && crashLock.pid !== process.pid) {
139
141
  // We already hold the session lock, so no concurrent session is running.
140
142
  // The crash lock is from a dead process — recover context from it.
141
- const recoveredMid = crashLock.unitId.split("/")[0];
143
+ const recoveredMid = parseUnitId(crashLock.unitId).milestone;
142
144
  const milestoneAlreadyComplete = recoveredMid
143
145
  ? !!resolveMilestoneFile(base, recoveredMid, "SUMMARY")
144
146
  : false;
@@ -201,11 +203,11 @@ export async function bootstrapAutoSession(
201
203
  if (!midMatch) continue;
202
204
  const mid = midMatch[1];
203
205
  if (resolveMilestoneFile(base, mid, "SUMMARY")) {
204
- try { unlinkSync(join(runtimeUnitsDir, file)); } catch (e) { debugLog("stale-unit-cleanup-failed", { file, error: e instanceof Error ? e.message : String(e) }); }
206
+ try { unlinkSync(join(runtimeUnitsDir, file)); } catch (e) { debugLog("stale-unit-cleanup-failed", { file, error: getErrorMessage(e) }); }
205
207
  }
206
208
  }
207
209
  }
208
- } catch (e) { debugLog("stale-unit-dir-cleanup-failed", { error: e instanceof Error ? e.message : String(e) }); }
210
+ } catch (e) { debugLog("stale-unit-dir-cleanup-failed", { error: getErrorMessage(e) }); }
209
211
 
210
212
  let state = await deriveState(base);
211
213
 
@@ -343,7 +345,7 @@ export async function bootstrapAutoSession(
343
345
  registerSigtermHandler(s.originalBasePath);
344
346
  } catch (err) {
345
347
  ctx.ui.notify(
346
- `Auto-worktree setup failed: ${err instanceof Error ? err.message : String(err)}. Continuing in project root.`,
348
+ `Auto-worktree setup failed: ${getErrorMessage(err)}. Continuing in project root.`,
347
349
  "warning",
348
350
  );
349
351
  }
@@ -435,7 +437,7 @@ export async function bootstrapAutoSession(
435
437
  }
436
438
  } catch (err) {
437
439
  ctx.ui.notify(
438
- `Secrets check error: ${err instanceof Error ? err.message : String(err)}. Continuing without secrets.`,
440
+ `Secrets check error: ${getErrorMessage(err)}. Continuing without secrets.`,
439
441
  "warning",
440
442
  );
441
443
  }
@@ -453,7 +455,7 @@ export async function bootstrapAutoSession(
453
455
  ctx.ui.notify("Removed stale .git/index.lock from prior crash.", "info");
454
456
  }
455
457
  }
456
- } catch (e) { debugLog("git-lock-cleanup-failed", { error: e instanceof Error ? e.message : String(e) }); }
458
+ } catch (e) { debugLog("git-lock-cleanup-failed", { error: getErrorMessage(e) }); }
457
459
 
458
460
  // Pre-flight: validate milestone queue
459
461
  try {
@@ -39,6 +39,7 @@ import {
39
39
  import type { AutoSession } from "./auto/session.js";
40
40
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
41
41
  import { join } from "node:path";
42
+ import { parseUnitId } from "./unit-id.js";
42
43
 
43
44
  export interface StuckContext {
44
45
  s: AutoSession;
@@ -99,7 +100,7 @@ export async function checkStuckAndRecover(sctx: StuckContext): Promise<StuckRes
99
100
 
100
101
  // Final reconciliation pass for execute-task
101
102
  if (unitType === "execute-task") {
102
- const [mid, sid, tid] = unitId.split("/");
103
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
103
104
  if (mid && sid && tid) {
104
105
  const status = await inspectExecuteTaskDurability(basePath, unitId);
105
106
  if (status) {
@@ -168,7 +169,7 @@ export async function checkStuckAndRecover(sctx: StuckContext): Promise<StuckRes
168
169
  // Adaptive self-repair: each retry attempts a different remediation step.
169
170
  if (unitType === "execute-task") {
170
171
  const status = await inspectExecuteTaskDurability(basePath, unitId);
171
- const [mid, sid, tid] = unitId.split("/");
172
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
172
173
  if (status && mid && sid && tid) {
173
174
  if (status.summaryExists && !status.taskChecked) {
174
175
  const repaired = skipExecuteTask(basePath, mid, sid, tid, status, "self-repair", 0);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Auto-mode Supervisor — SIGTERM handling and working-tree activity detection.
2
+ * Auto-mode Supervisor — signal handling and working-tree activity detection.
3
3
  *
4
4
  * Pure functions — no module-level globals or AutoContext dependency.
5
5
  */
@@ -8,10 +8,10 @@ import { clearLock } from "./crash-recovery.js";
8
8
  import { releaseSessionLock } from "./session-lock.js";
9
9
  import { nativeHasChanges } from "./native-git-bridge.js";
10
10
 
11
- // ─── SIGTERM Handling ─────────────────────────────────────────────────────────
11
+ // ─── Signal Handling ──────────────────────────────────────────────────────────
12
12
 
13
13
  /**
14
- * Register a SIGTERM handler that clears the lock file and exits cleanly.
14
+ * Register SIGTERM and SIGINT handlers that clear lock files and exit cleanly.
15
15
  * Captures the active base path at registration time so the handler
16
16
  * always references the correct path even if the module variable changes.
17
17
  * Removes any previously registered handler before installing the new one.
@@ -22,20 +22,25 @@ export function registerSigtermHandler(
22
22
  currentBasePath: string,
23
23
  previousHandler: (() => void) | null,
24
24
  ): () => void {
25
- if (previousHandler) process.off("SIGTERM", previousHandler);
25
+ if (previousHandler) {
26
+ process.off("SIGTERM", previousHandler);
27
+ process.off("SIGINT", previousHandler);
28
+ }
26
29
  const handler = () => {
27
30
  releaseSessionLock(currentBasePath);
28
31
  clearLock(currentBasePath);
29
32
  process.exit(0);
30
33
  };
31
34
  process.on("SIGTERM", handler);
35
+ process.on("SIGINT", handler);
32
36
  return handler;
33
37
  }
34
38
 
35
- /** Deregister the SIGTERM handler (called on stop/pause). */
39
+ /** Deregister signal handlers (called on stop/pause). */
36
40
  export function deregisterSigtermHandler(handler: (() => void) | null): void {
37
41
  if (handler) {
38
42
  process.off("SIGTERM", handler);
43
+ process.off("SIGINT", handler);
39
44
  }
40
45
  }
41
46
 
@@ -18,6 +18,7 @@ import {
18
18
  writeBlockerPlaceholder,
19
19
  } from "./auto-recovery.js";
20
20
  import { existsSync } from "node:fs";
21
+ import { parseUnitId } from "./unit-id.js";
21
22
 
22
23
  export interface RecoveryContext {
23
24
  basePath: string;
@@ -128,7 +129,7 @@ export async function recoverTimedOutUnit(
128
129
 
129
130
  // Retries exhausted — write missing durable artifacts and advance.
130
131
  const diagnostic = formatExecuteTaskRecoveryStatus(status);
131
- const [mid, sid, tid] = unitId.split("/");
132
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
132
133
  const skipped = mid && sid && tid
133
134
  ? skipExecuteTask(basePath, mid, sid, tid, status, reason, maxRecoveryAttempts)
134
135
  : false;
@@ -20,6 +20,7 @@ import { closeoutUnit, type CloseoutOptions } from "./auto-unit-closeout.js";
20
20
  import { saveActivityLog } from "./activity-log.js";
21
21
  import { recoverTimedOutUnit, type RecoveryContext } from "./auto-timeout-recovery.js";
22
22
  import type { AutoSession } from "./auto/session.js";
23
+ import { getErrorMessage } from "./error-utils.js";
23
24
 
24
25
  export interface SupervisionContext {
25
26
  s: AutoSession;
@@ -127,7 +128,7 @@ export function startUnitSupervision(sctx: SupervisionContext): void {
127
128
  );
128
129
  await pauseAuto(ctx, pi);
129
130
  } catch (err) {
130
- const message = err instanceof Error ? err.message : String(err);
131
+ const message = getErrorMessage(err);
131
132
  console.error(`[idle-watchdog] Unhandled error: ${message}`);
132
133
  try {
133
134
  ctx.ui.notify(`Idle watchdog error: ${message}`, "warning");
@@ -159,7 +160,7 @@ export function startUnitSupervision(sctx: SupervisionContext): void {
159
160
  );
160
161
  await pauseAuto(ctx, pi);
161
162
  } catch (err) {
162
- const message = err instanceof Error ? err.message : String(err);
163
+ const message = getErrorMessage(err);
163
164
  console.error(`[hard-timeout] Unhandled error: ${message}`);
164
165
  try {
165
166
  ctx.ui.notify(`Hard timeout error: ${message}`, "warning");
@@ -24,6 +24,8 @@ import { writeVerificationJSON } from "./verification-evidence.js";
24
24
  import { removePersistedKey } from "./auto-recovery.js";
25
25
  import type { AutoSession, PendingVerificationRetry } from "./auto/session.js";
26
26
  import { join } from "node:path";
27
+ import { getErrorMessage } from "./error-utils.js";
28
+ import { parseUnitId } from "./unit-id.js";
27
29
 
28
30
  export interface VerificationContext {
29
31
  s: AutoSession;
@@ -57,10 +59,9 @@ export async function runPostUnitVerification(
57
59
  const prefs = effectivePrefs?.preferences;
58
60
 
59
61
  // Read task plan verify field
60
- const parts = s.currentUnit.id.split("/");
62
+ const { milestone: mid, slice: sid, task: tid } = parseUnitId(s.currentUnit.id);
61
63
  let taskPlanVerify: string | undefined;
62
- if (parts.length >= 3) {
63
- const [mid, sid, tid] = parts;
64
+ if (mid && sid && tid) {
64
65
  const planFile = resolveSliceFile(s.basePath, mid, sid, "PLAN");
65
66
  if (planFile) {
66
67
  const planContent = await loadFile(planFile);
@@ -152,9 +153,8 @@ export async function runPostUnitVerification(
152
153
 
153
154
  // Write verification evidence JSON
154
155
  const attempt = s.verificationRetryCount.get(s.currentUnit.id) ?? 0;
155
- if (parts.length >= 3) {
156
+ if (mid && sid && tid) {
156
157
  try {
157
- const [mid, sid, tid] = parts;
158
158
  const sDir = resolveSlicePath(s.basePath, mid, sid);
159
159
  if (sDir) {
160
160
  const tasksDir = join(sDir, "tasks");
@@ -204,7 +204,7 @@ export async function runPostUnitVerification(
204
204
  try {
205
205
  await dispatchNextUnit(ctx, pi);
206
206
  } catch (retryDispatchErr) {
207
- const msg = retryDispatchErr instanceof Error ? retryDispatchErr.message : String(retryDispatchErr);
207
+ const msg = getErrorMessage(retryDispatchErr);
208
208
  ctx.ui.notify(`Verification retry dispatch error: ${msg}`, "error");
209
209
  startDispatchGapWatchdog(ctx, pi);
210
210
  }