gsd-pi 2.52.0-dev.585e355 → 2.52.0-dev.655ad8a

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 (76) hide show
  1. package/README.md +55 -32
  2. package/dist/headless-query.js +1 -1
  3. package/dist/resources/extensions/get-secrets-from-user.js +7 -0
  4. package/dist/resources/extensions/gsd/auto/phases.js +28 -8
  5. package/dist/resources/extensions/gsd/auto-dispatch.js +5 -1
  6. package/dist/resources/extensions/gsd/auto-worktree.js +70 -14
  7. package/dist/resources/extensions/gsd/auto.js +22 -0
  8. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +4 -10
  9. package/dist/resources/extensions/gsd/guided-flow.js +4 -3
  10. package/dist/resources/extensions/gsd/parallel-orchestrator.js +18 -2
  11. package/dist/resources/extensions/gsd/state.js +5 -11
  12. package/dist/resources/extensions/shared/rtk.js +9 -1
  13. package/dist/web/standalone/.next/BUILD_ID +1 -1
  14. package/dist/web/standalone/.next/app-path-routes-manifest.json +14 -14
  15. package/dist/web/standalone/.next/build-manifest.json +3 -3
  16. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  17. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  18. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  19. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  27. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/index.html +1 -1
  35. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app-paths-manifest.json +14 -14
  42. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  43. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  44. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  45. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  46. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  47. package/dist/web/standalone/.next/static/chunks/4024.87fd909ae0110f50.js +9 -0
  48. package/dist/web/standalone/.next/static/chunks/{webpack-024d82be84800e52.js → webpack-bca0e732db0dcec3.js} +1 -1
  49. package/package.json +1 -1
  50. package/src/resources/extensions/get-secrets-from-user.ts +8 -0
  51. package/src/resources/extensions/gsd/auto/phases.ts +38 -7
  52. package/src/resources/extensions/gsd/auto-dispatch.ts +6 -1
  53. package/src/resources/extensions/gsd/auto-worktree.ts +73 -14
  54. package/src/resources/extensions/gsd/auto.ts +21 -0
  55. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +4 -11
  56. package/src/resources/extensions/gsd/guided-flow.ts +4 -3
  57. package/src/resources/extensions/gsd/parallel-orchestrator.ts +23 -1
  58. package/src/resources/extensions/gsd/state.ts +5 -10
  59. package/src/resources/extensions/gsd/tests/active-milestone-id-guard.test.ts +91 -0
  60. package/src/resources/extensions/gsd/tests/auto-stale-lock-self-kill.test.ts +87 -0
  61. package/src/resources/extensions/gsd/tests/auto-worktree-auto-resolve.test.ts +80 -0
  62. package/src/resources/extensions/gsd/tests/auto-worktree-milestone-merge.test.ts +1 -1
  63. package/src/resources/extensions/gsd/tests/collect-from-manifest.test.ts +39 -0
  64. package/src/resources/extensions/gsd/tests/git-service.test.ts +28 -27
  65. package/src/resources/extensions/gsd/tests/milestone-report-path.test.ts +51 -0
  66. package/src/resources/extensions/gsd/tests/parallel-orchestrator-zombie-cleanup.test.ts +277 -0
  67. package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +103 -0
  68. package/src/resources/extensions/gsd/tests/rate-limit-model-fallback.test.ts +90 -0
  69. package/src/resources/extensions/gsd/tests/session-lock-transient-read.test.ts +9 -8
  70. package/src/resources/extensions/gsd/tests/stash-pop-gsd-conflict.test.ts +125 -0
  71. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +12 -2
  72. package/src/resources/extensions/gsd/tests/validation-gate-patterns.test.ts +124 -0
  73. package/src/resources/extensions/shared/rtk.ts +10 -1
  74. package/dist/web/standalone/.next/static/chunks/4024.21054f459af5cc78.js +0 -9
  75. /package/dist/web/standalone/.next/static/{KTe1kB5nPLQFIIFz2OcmI → zpvUPKoW5jRAMB_fWHlPi}/_buildManifest.js +0 -0
  76. /package/dist/web/standalone/.next/static/{KTe1kB5nPLQFIIFz2OcmI → zpvUPKoW5jRAMB_fWHlPi}/_ssgManifest.js +0 -0
package/README.md CHANGED
@@ -27,55 +27,78 @@ One command. Walk away. Come back to a built project with clean git history.
27
27
 
28
28
  ---
29
29
 
30
- ## What's New in v2.46.0
30
+ ## What's New in v2.52.0
31
31
 
32
- ### Single-Writer State Engine
32
+ ### VS Code Extension & Web UI
33
33
 
34
- The biggest architectural change since DB-backed planning tools. The single-writer engine enforces disciplined state transitions through three iterations:
34
+ - **VS Code integration** status bar, file decorations, bash terminal, session tree, conversation history, and code lens. (#2651)
35
+ - **Dark mode contrast** — raised token floor and flattened opacity tier system for better readability. (#2734)
36
+ - **Auth token gate** — synthetic 401 on missing token, unauthenticated boot state, and recovery screen. (#2740)
35
37
 
36
- - **v2 discipline layer** — adds a write-side discipline layer on top of the DB architecture, ensuring all state mutations flow through controlled tool calls.
37
- - **v3 — state machine guards, actor identity, reversibility** — introduces formal state machine guards, tracks which actor (human vs agent) initiated each transition, and makes transitions reversible.
38
- - **Hardened** — closes TOCTOU race conditions, intercepts bypass attempts, and resolves status inconsistencies.
38
+ ### Capability Metadata & Model Routing
39
39
 
40
- All prompts are now aligned with the single-writer tool API, and a new **workflow-logger** is wired into the engine, tool, manifest, and reconcile paths for full observability. (#2494)
41
-
42
- ### v2.45.0 — New Commands and Capabilities
43
-
44
- - **`/gsd rethink`** — conversational project reorganization. Rethink your milestone structure, slice decomposition, or overall approach through guided discussion. (#2459)
45
- - **`/gsd mcp`** — MCP server status and connectivity. Check which MCP servers are configured, connected, and healthy. (#2362)
46
- - **Complete offline mode** — GSD now works fully offline with local models. (#2429)
47
- - **Global KNOWLEDGE.md injection** — `~/.gsd/agent/KNOWLEDGE.md` is injected into the system prompt, so cross-project knowledge persists globally. (#2331)
48
- - **Mobile-responsive web UI** — the browser interface now works on phones and tablets. (#2354)
49
- - **DB tool previews** — `renderCall`/`renderResult` previews on DB tools show what each tool call does before and after execution. (#2273)
50
- - **Message timestamps** — user and assistant messages now include timestamps. (#2368)
40
+ - **Capability-based model selection** replaced model-ID pattern matching with capability metadata, making custom provider integration more reliable. (#2548)
51
41
 
52
42
  ### Key Changes
53
43
 
54
- - **Default isolation mode changed to `none`** `git.isolation` now defaults to `none` instead of `worktree`. Projects that rely on worktree isolation should set `git.isolation: worktree` explicitly in preferences. (#2481)
55
- - **Startup checks** — GSD now validates Node.js version and git availability at startup, with clear error messages. (#2463)
56
- - **Worktree lifecycle journaling** — worktree create, switch, merge, and remove events are recorded in the event journal. (#2486)
57
- - **Milestone verification gate** — milestone completion is blocked when verification fails, preventing premature closure. (#2500)
44
+ - **`--bare` mode**wired across headless, pi-coding-agent, and resource-loader for minimal-output operation.
45
+ - **RPC protocol v2** — new types, init handshake with version detection, and runId generation on prompt/steer/follow_up commands.
46
+ - **PREFERENCES.md rename** — `preferences.md` renamed to `PREFERENCES.md` for consistency. (#2700, #2738)
47
+ - **Comprehensive SQLite audit** — indexes, caching, safety, and reconciliation fixes across gsd-db.
48
+ - **Unified error classifier** — three overlapping error classifiers consolidated into a single classify-decide-act pipeline.
58
49
 
59
50
  ### Key Fixes
60
51
 
61
- - **Auto-mode stability** — recovery attempts reset on unit re-dispatch (#2424), survivor branch recovery handles `phase=complete` (#2427), and auto mode stops on real merge conflicts (#2428).
62
- - **Supervision timeouts** — now respect task `est:` annotations, so complex tasks get proportionally longer timeouts. (#2434)
63
- - **`auto_pr: true` fixed** — three interacting bugs prevented auto-PR creation; all three are resolved. (#2433)
64
- - **Rich task plan preservation** — plans survive DB roundtrip without losing structured content. (#2453)
65
- - **Artifact truncation prevention** — `saveArtifactToDb` no longer overwrites larger files with truncated content. (#2447)
66
- - **Worktree teardown** — submodule state is detected and preserved during teardown (#2425), and worktree merge back to main works after `stopAuto` on milestone completion (#2430).
67
- - **Windows portability** — `retentionDays=0` handling and CRLF fixes on Windows. (#2460)
68
- - **Voice on Linux** — misleading portaudio error on PEP 668 systems replaced with actionable guidance. (#2407)
52
+ - **Auto-mode stops on provider errors** — auto loop now halts after provider errors instead of retrying indefinitely. (#2762, #2764)
53
+ - **Transaction safety** — state machine guards moved inside transactions in 5 tool handlers (#2752), and `transaction()` made re-entrant.
54
+ - **Worktree seeding** — `preferences.md` seeded into auto-mode worktrees and included in worktree sync. (#2693)
55
+ - **Idle watchdog** — interactive tools exempted from stall detection (#2676), and filesystem activity no longer overrides stalled-tool detection. (#2697)
56
+ - **Milestone guards** — `allSlicesDone` guarded against vacuous truth on empty slice arrays (#2679), and `complete-milestone` dispatch blocked when validation is `needs-remediation`. (#2682)
57
+ - **Docker overhaul** — fragile setup replaced with proven container patterns. (#2716)
58
+ - **Windows** — EINVAL prevented by disabling detached process groups on Win32. (#2744)
59
+ - **Audit log** — `setLogBasePath` wired into engine init to resurrect audit logging. (#2745)
60
+
61
+ ### v2.51.0 — Skills, RTK, and Verification
62
+
63
+ - **`/terminal` command** — direct shell execution from the slash command interface. (#2349)
64
+ - **Managed RTK integration** — RTK binary auto-provisioned with opt-in preference and web UI toggle. (#2620)
65
+ - **Verification classes** — compliance checked before milestone completion, with classes injected into validation prompts. (#2621, #2623)
66
+ - **Skills overhaul** — 30+ new skill packs covering major frameworks, databases, and cloud platforms; curated catalog with `~/.agents/skills/` as primary directory.
67
+
68
+ ### v2.50.0 — Quality Gates
69
+
70
+ - **Quality gates** — 8-question quality gates added to planning and completion templates, with parallel evaluation via `evaluating-gates` phase.
71
+ - **Structured error propagation** — errors wired through `UnitResult` for better diagnostics.
72
+
73
+ ### v2.49.0 — Git Trailers & Yolo Mode
74
+
75
+ - **`--yolo` flag** — `/gsd auto --yolo` for non-interactive project init.
76
+ - **Git trailers** — GSD metadata moved from commit subject scopes to git trailers.
77
+
78
+ ### v2.48.0 — Forensics & Discussion
79
+
80
+ - **`/gsd discuss` for queued milestones** — target milestones still in the queue. (#2349)
81
+ - **Enhanced forensics** — journal and activity log awareness added to `/gsd forensics`.
82
+
83
+ ### v2.47.0 — External Providers
84
+
85
+ - **External tool execution mode** — `externalToolExecution` mode for external providers in agent-core.
86
+ - **Claude Code CLI provider** — new provider extension for Claude Code CLI. (#2382)
69
87
 
70
- ### Previous highlights (v2.42–v2.44)
88
+ ### Previous highlights (v2.42–v2.46)
71
89
 
90
+ - **Single-writer state engine** — disciplined state transitions with machine guards, actor identity, reversibility, and TOCTOU hardening. (#2494)
91
+ - **`/gsd rethink`** — conversational project reorganization. (#2459)
92
+ - **`/gsd mcp`** — MCP server status and connectivity. (#2362)
93
+ - **Complete offline mode** — fully offline with local models. (#2429)
94
+ - **Global KNOWLEDGE.md injection** — cross-project knowledge via `~/.gsd/agent/KNOWLEDGE.md`. (#2331)
95
+ - **Mobile-responsive web UI** — browser interface works on phones and tablets. (#2354)
96
+ - **Default isolation mode changed to `none`** — set `git.isolation: worktree` explicitly if needed. (#2481)
72
97
  - **Non-API-key provider extensions** — support for Claude Code CLI and similar providers. (#2382)
73
98
  - **Docker sandbox template** — official Docker template for isolated auto mode. (#2360)
74
99
  - **DB-backed planning tools** — write-side state transitions use atomic SQLite tool calls. (#2141)
75
100
  - **Declarative workflow engine** — YAML workflows through auto-loop. (#2024)
76
101
  - **`/gsd fast`** — toggle service tier for prioritized API routing. (#1862)
77
- - **Forensics dedup** — duplicate detection before issue creation. (#2105)
78
- - **Startup optimizations** — pre-compiled extensions, compile cache, batch discovery. (#2125)
79
102
 
80
103
  ---
81
104
 
@@ -36,7 +36,7 @@ export async function handleQuery(basePath) {
36
36
  const state = await deriveState(basePath);
37
37
  // Derive next dispatch action
38
38
  let next;
39
- if (!state.activeMilestone) {
39
+ if (!state.activeMilestone?.id) {
40
40
  next = {
41
41
  action: 'stop',
42
42
  reason: state.phase === 'complete' ? 'All milestones complete.' : state.nextAction,
@@ -25,6 +25,11 @@ function maskPreview(value) {
25
25
  function shellEscapeSingle(value) {
26
26
  return `'${value.replace(/'/g, `'\\''`)}'`;
27
27
  }
28
+ function hydrateProcessEnv(key, value) {
29
+ // Make newly collected secrets immediately visible to the current session.
30
+ // Some extensions read process.env directly and do not reload .env on every call.
31
+ process.env[key] = value;
32
+ }
28
33
  async function writeEnvKey(filePath, key, value) {
29
34
  let content = "";
30
35
  try {
@@ -246,6 +251,7 @@ async function applySecrets(provided, destination, opts) {
246
251
  try {
247
252
  await writeEnvKey(opts.envFilePath, key, value);
248
253
  applied.push(key);
254
+ hydrateProcessEnv(key, value);
249
255
  }
250
256
  catch (err) {
251
257
  errors.push(`${key}: ${err.message}`);
@@ -265,6 +271,7 @@ async function applySecrets(provided, destination, opts) {
265
271
  }
266
272
  else {
267
273
  applied.push(key);
274
+ hydrateProcessEnv(key, value);
268
275
  }
269
276
  }
270
277
  catch (err) {
@@ -15,12 +15,20 @@ import { PROJECT_FILES } from "../detection.js";
15
15
  import { MergeConflictError } from "../git-service.js";
16
16
  import { join } from "node:path";
17
17
  import { existsSync, cpSync } from "node:fs";
18
- import { logWarning } from "../workflow-logger.js";
18
+ import { logWarning, logError } from "../workflow-logger.js";
19
19
  import { gsdRoot } from "../paths.js";
20
20
  import { atomicWriteSync } from "../atomic-write.js";
21
21
  import { verifyExpectedArtifact } from "../auto-recovery.js";
22
22
  import { writeUnitRuntimeRecord } from "../unit-runtime.js";
23
23
  // ─── generateMilestoneReport ──────────────────────────────────────────────────
24
+ /**
25
+ * Resolve the base path for milestone reports.
26
+ * Prefers originalBasePath (project root) over basePath (which may be a worktree).
27
+ * Exported for testing as _resolveReportBasePath.
28
+ */
29
+ export function _resolveReportBasePath(s) {
30
+ return s.originalBasePath || s.basePath;
31
+ }
24
32
  /**
25
33
  * Generate and write an HTML milestone report snapshot.
26
34
  * Extracted from the milestone-transition block in autoLoop.
@@ -30,18 +38,19 @@ async function generateMilestoneReport(s, ctx, milestoneId) {
30
38
  const { generateHtmlReport } = await importExtensionModule(import.meta.url, "../export-html.js");
31
39
  const { writeReportSnapshot } = await importExtensionModule(import.meta.url, "../reports.js");
32
40
  const { basename } = await import("node:path");
33
- const snapData = await loadVisualizerData(s.basePath);
41
+ const reportBasePath = _resolveReportBasePath(s);
42
+ const snapData = await loadVisualizerData(reportBasePath);
34
43
  const completedMs = snapData.milestones.find((m) => m.id === milestoneId);
35
44
  const msTitle = completedMs?.title ?? milestoneId;
36
45
  const gsdVersion = process.env.GSD_VERSION ?? "0.0.0";
37
- const projName = basename(s.basePath);
46
+ const projName = basename(reportBasePath);
38
47
  const doneSlices = snapData.milestones.reduce((acc, m) => acc + m.slices.filter((sl) => sl.done).length, 0);
39
48
  const totalSlices = snapData.milestones.reduce((acc, m) => acc + m.slices.length, 0);
40
49
  const outPath = writeReportSnapshot({
41
- basePath: s.basePath,
50
+ basePath: reportBasePath,
42
51
  html: generateHtmlReport(snapData, {
43
52
  projectName: projName,
44
- projectPath: s.basePath,
53
+ projectPath: reportBasePath,
45
54
  gsdVersion,
46
55
  milestoneId,
47
56
  indexRelPath: "index.html",
@@ -50,7 +59,7 @@ async function generateMilestoneReport(s, ctx, milestoneId) {
50
59
  milestoneTitle: msTitle,
51
60
  kind: "milestone",
52
61
  projectName: projName,
53
- projectPath: s.basePath,
62
+ projectPath: reportBasePath,
54
63
  gsdVersion,
55
64
  totalCost: snapData.totals?.cost ?? 0,
56
65
  totalTokens: snapData.totals?.tokens.total ?? 0,
@@ -160,8 +169,11 @@ export async function runPreDispatch(ic, loopState) {
160
169
  await deps.stopAuto(ctx, pi, `Merge conflict on milestone ${s.currentMilestoneId}`);
161
170
  return { action: "break", reason: "merge-conflict" };
162
171
  }
163
- // Non-conflict merge errors — log and continue
164
- logWarning("engine", "Milestone merge failed with non-conflict error", { milestone: s.currentMilestoneId, error: String(mergeErr) });
172
+ // Non-conflict merge errors — stop auto to avoid advancing with unmerged work
173
+ logError("engine", "Milestone merge failed with non-conflict error", { milestone: s.currentMilestoneId, error: String(mergeErr) });
174
+ ctx.ui.notify(`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /gsd auto to resume.`, "error");
175
+ await deps.stopAuto(ctx, pi, `Merge error on milestone ${s.currentMilestoneId}: ${String(mergeErr)}`);
176
+ return { action: "break", reason: "merge-failed" };
165
177
  }
166
178
  // PR creation (auto_pr) is handled inside mergeMilestoneToMain (#2302)
167
179
  deps.invalidateAllCaches();
@@ -228,6 +240,10 @@ export async function runPreDispatch(ic, loopState) {
228
240
  await deps.stopAuto(ctx, pi, `Merge conflict on milestone ${s.currentMilestoneId}`);
229
241
  return { action: "break", reason: "merge-conflict" };
230
242
  }
243
+ logError("engine", "Milestone merge failed with non-conflict error", { milestone: s.currentMilestoneId, error: String(mergeErr) });
244
+ ctx.ui.notify(`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /gsd auto to resume.`, "error");
245
+ await deps.stopAuto(ctx, pi, `Merge error on milestone ${s.currentMilestoneId}: ${String(mergeErr)}`);
246
+ return { action: "break", reason: "merge-failed" };
231
247
  }
232
248
  // PR creation (auto_pr) is handled inside mergeMilestoneToMain (#2302)
233
249
  }
@@ -295,6 +311,10 @@ export async function runPreDispatch(ic, loopState) {
295
311
  await deps.stopAuto(ctx, pi, `Merge conflict on milestone ${s.currentMilestoneId}`);
296
312
  return { action: "break", reason: "merge-conflict" };
297
313
  }
314
+ logError("engine", "Milestone merge failed with non-conflict error", { milestone: s.currentMilestoneId, error: String(mergeErr) });
315
+ ctx.ui.notify(`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /gsd auto to resume.`, "error");
316
+ await deps.stopAuto(ctx, pi, `Merge error on milestone ${s.currentMilestoneId}: ${String(mergeErr)}`);
317
+ return { action: "break", reason: "merge-failed" };
298
318
  }
299
319
  // PR creation (auto_pr) is handled inside mergeMilestoneToMain (#2302)
300
320
  }
@@ -531,8 +531,12 @@ export const DISPATCH_RULES = [
531
531
  if (validationPath) {
532
532
  const validationContent = await loadFile(validationPath);
533
533
  if (validationContent) {
534
- const hasOperationalCheck = validationContent.includes("Operational") &&
534
+ // Accept either the structured template format (table with MET/N/A)
535
+ // or prose evidence patterns the validation agent may emit.
536
+ const structuredMatch = validationContent.includes("Operational") &&
535
537
  (validationContent.includes("MET") || validationContent.includes("N/A"));
538
+ const proseMatch = /[Oo]perational[\s:][^\n]*(?:pass|verified|confirmed|met|complete|true|yes|addressed|covered|n\/a|not\s+applicable)/i.test(validationContent);
539
+ const hasOperationalCheck = structuredMatch || proseMatch;
536
540
  if (!hasOperationalCheck) {
537
541
  return {
538
542
  action: "stop",
@@ -104,6 +104,21 @@ function clearProjectRootStateFiles(basePath, milestoneId) {
104
104
  }
105
105
  }
106
106
  }
107
+ // ─── Build Artifact Auto-Resolve ─────────────────────────────────────────────
108
+ /** Patterns for machine-generated build artifacts that can be safely
109
+ * auto-resolved by accepting --theirs during merge. These files are
110
+ * regenerable and never contain meaningful manual edits. */
111
+ export const SAFE_AUTO_RESOLVE_PATTERNS = [
112
+ /\.tsbuildinfo$/,
113
+ /\.pyc$/,
114
+ /\/__pycache__\//,
115
+ /\.DS_Store$/,
116
+ /\.map$/,
117
+ ];
118
+ /** Returns true if the file path is safe to auto-resolve during merge.
119
+ * Covers `.gsd/` state files and common build artifacts. */
120
+ export const isSafeToAutoResolve = (filePath) => filePath.startsWith(".gsd/") ||
121
+ SAFE_AUTO_RESOLVE_PATTERNS.some((re) => re.test(filePath));
107
122
  // ─── Dispatch-Level Sync (project root ↔ worktree) ──────────────────────────
108
123
  /**
109
124
  * Sync milestone artifacts from project root INTO worktree before deriveState.
@@ -1191,27 +1206,27 @@ export function mergeMilestoneToMain(originalBasePath_, milestoneId, roadmapCont
1191
1206
  ? mergeResult.conflicts
1192
1207
  : nativeConflictFiles(originalBasePath_);
1193
1208
  if (conflictedFiles.length > 0) {
1194
- // Separate .gsd/ state file conflicts from real code conflicts.
1195
- // GSD state files (STATE.md, auto.lock, etc.)
1196
- // diverge between branches during normal operation always prefer the
1197
- // milestone branch version since it has the latest execution state.
1198
- const gsdConflicts = conflictedFiles.filter((f) => f.startsWith(".gsd/"));
1199
- const codeConflicts = conflictedFiles.filter((f) => !f.startsWith(".gsd/"));
1200
- // Auto-resolve .gsd/ conflicts by accepting the milestone branch version
1201
- if (gsdConflicts.length > 0) {
1202
- for (const gsdFile of gsdConflicts) {
1209
+ // Separate auto-resolvable conflicts (GSD state files + build artifacts)
1210
+ // from real code conflicts. GSD state files diverge between branches
1211
+ // during normal operation. Build artifacts are machine-generated and
1212
+ // regenerable. Both are safe to accept from the milestone branch.
1213
+ const autoResolvable = conflictedFiles.filter(isSafeToAutoResolve);
1214
+ const codeConflicts = conflictedFiles.filter((f) => !isSafeToAutoResolve(f));
1215
+ // Auto-resolve safe conflicts by accepting the milestone branch version
1216
+ if (autoResolvable.length > 0) {
1217
+ for (const safeFile of autoResolvable) {
1203
1218
  try {
1204
- nativeCheckoutTheirs(originalBasePath_, [gsdFile]);
1205
- nativeAddPaths(originalBasePath_, [gsdFile]);
1219
+ nativeCheckoutTheirs(originalBasePath_, [safeFile]);
1220
+ nativeAddPaths(originalBasePath_, [safeFile]);
1206
1221
  }
1207
1222
  catch {
1208
1223
  // If checkout --theirs fails, try removing the file from the merge
1209
1224
  // (it's a runtime file that shouldn't be committed anyway)
1210
- nativeRmForce(originalBasePath_, [gsdFile]);
1225
+ nativeRmForce(originalBasePath_, [safeFile]);
1211
1226
  }
1212
1227
  }
1213
1228
  }
1214
- // If there are still non-.gsd conflicts, escalate
1229
+ // If there are still real code conflicts, escalate
1215
1230
  if (codeConflicts.length > 0) {
1216
1231
  // Pop stash before throwing so local work is not lost (#2151).
1217
1232
  if (stashed) {
@@ -1256,7 +1271,48 @@ export function mergeMilestoneToMain(originalBasePath_, milestoneId, roadmapCont
1256
1271
  });
1257
1272
  }
1258
1273
  catch {
1259
- // Stash pop conflict is non-fatal stash entry persists for manual resolution.
1274
+ // Stash pop after squash merge can conflict on .gsd/ state files that
1275
+ // diverged between branches. Left unresolved, these UU entries block
1276
+ // every subsequent merge. Auto-resolve them the same way we handle
1277
+ // .gsd/ conflicts during the merge itself: accept HEAD (the just-committed
1278
+ // version) and drop the now-applied stash.
1279
+ const uu = nativeConflictFiles(originalBasePath_);
1280
+ const gsdUU = uu.filter((f) => f.startsWith(".gsd/"));
1281
+ const nonGsdUU = uu.filter((f) => !f.startsWith(".gsd/"));
1282
+ if (gsdUU.length > 0) {
1283
+ for (const f of gsdUU) {
1284
+ try {
1285
+ // Accept the committed (HEAD) version of the state file
1286
+ execFileSync("git", ["checkout", "HEAD", "--", f], {
1287
+ cwd: originalBasePath_,
1288
+ stdio: ["ignore", "pipe", "pipe"],
1289
+ encoding: "utf-8",
1290
+ });
1291
+ nativeAddPaths(originalBasePath_, [f]);
1292
+ }
1293
+ catch {
1294
+ // Last resort: remove the conflicted state file
1295
+ nativeRmForce(originalBasePath_, [f]);
1296
+ }
1297
+ }
1298
+ }
1299
+ if (nonGsdUU.length === 0) {
1300
+ // All conflicts were .gsd/ files — safe to drop the stash
1301
+ try {
1302
+ execFileSync("git", ["stash", "drop"], {
1303
+ cwd: originalBasePath_,
1304
+ stdio: ["ignore", "pipe", "pipe"],
1305
+ encoding: "utf-8",
1306
+ });
1307
+ }
1308
+ catch { /* stash may already be consumed */ }
1309
+ }
1310
+ else {
1311
+ // Non-.gsd conflicts remain — leave stash for manual resolution
1312
+ logWarning("reconcile", "Stash pop conflict on non-.gsd files after merge", {
1313
+ files: nonGsdUU.join(", "),
1314
+ });
1315
+ }
1260
1316
  }
1261
1317
  }
1262
1318
  // 9b. Safety check (#1792): if nothing was committed, verify the milestone
@@ -215,6 +215,12 @@ export function stopAutoRemote(projectRoot) {
215
215
  const lock = readCrashLock(projectRoot);
216
216
  if (!lock)
217
217
  return { found: false };
218
+ // Never SIGTERM ourselves — a stale lock with our own PID is not a remote
219
+ // session, it is leftover from a prior loop exit in this process. (#2730)
220
+ if (lock.pid === process.pid) {
221
+ clearLock(projectRoot);
222
+ return { found: false };
223
+ }
218
224
  if (!isLockProcessAlive(lock)) {
219
225
  // Stale lock — clean it up
220
226
  clearLock(projectRoot);
@@ -239,6 +245,10 @@ export function checkRemoteAutoSession(projectRoot) {
239
245
  const lock = readCrashLock(projectRoot);
240
246
  if (!lock)
241
247
  return { running: false };
248
+ // Our own PID is not a "remote" session — it is a stale lock left by this
249
+ // process (e.g. after step-mode exit without full cleanup). (#2730)
250
+ if (lock.pid === process.pid)
251
+ return { running: false };
242
252
  if (!isLockProcessAlive(lock)) {
243
253
  // Stale lock from a dead process — not a live remote session
244
254
  return { running: false };
@@ -321,6 +331,18 @@ function cleanupAfterLoopExit(ctx) {
321
331
  s.currentUnit = null;
322
332
  s.active = false;
323
333
  clearUnitTimeout();
334
+ // Clear crash lock and release session lock so the next `/gsd next` does
335
+ // not see a stale lock with the current PID and treat it as a "remote"
336
+ // session (which would cause it to SIGTERM itself). (#2730)
337
+ try {
338
+ if (lockBase())
339
+ clearLock(lockBase());
340
+ if (lockBase())
341
+ releaseSessionLock(lockBase());
342
+ }
343
+ catch {
344
+ /* best-effort — mirror stopAuto cleanup */
345
+ }
324
346
  ctx.ui.setStatus("gsd-auto", undefined);
325
347
  ctx.ui.setWidget("gsd-progress", undefined);
326
348
  ctx.ui.setFooter(undefined);
@@ -77,15 +77,9 @@ export async function handleAgentEnd(pi, event, ctx) {
77
77
  retryState.currentRetryModelId = undefined;
78
78
  ctx.ui.notify(`Network retries exhausted for ${currentModelId}. Attempting model fallback.`, "warning");
79
79
  }
80
- // --- Rate limit: skip model fallback, go straight to pause ---
81
- // Rate-limiting is a provider issue, not a model issue.
82
- // Switching models won't help if the provider is throttling you.
83
- if (cls.kind === "rate-limit") {
84
- await pauseTransientWithBackoff(cls, pi, ctx, errorDetail, true);
85
- return;
86
- }
87
- // --- Server/connection/stream errors: try model fallback first ---
88
- if (cls.kind === "network" || cls.kind === "server" || cls.kind === "connection" || cls.kind === "stream") {
80
+ // --- Transient errors: try model fallback first, then pause ---
81
+ // Rate limits are often per-model, so switching models can bypass them.
82
+ if (cls.kind === "rate-limit" || cls.kind === "network" || cls.kind === "server" || cls.kind === "connection" || cls.kind === "stream") {
89
83
  // Try model fallback
90
84
  const dash = getAutoDashboardData();
91
85
  if (dash.currentUnit) {
@@ -128,7 +122,7 @@ export async function handleAgentEnd(pi, event, ctx) {
128
122
  }
129
123
  // --- Transient fallback: pause with auto-resume ---
130
124
  if (isTransient(cls)) {
131
- await pauseTransientWithBackoff(cls, pi, ctx, errorDetail, false);
125
+ await pauseTransientWithBackoff(cls, pi, ctx, errorDetail, cls.kind === "rate-limit");
132
126
  return;
133
127
  }
134
128
  // --- Permanent / unknown: pause indefinitely ---
@@ -408,8 +408,9 @@ export async function showDiscuss(ctx, pi, basePath) {
408
408
  // Invalidate caches to pick up artifacts written by a just-completed discuss/plan
409
409
  invalidateAllCaches();
410
410
  const state = await deriveState(basePath);
411
- // No active milestone check for pending milestones to discuss instead
412
- if (!state.activeMilestone) {
411
+ // No active milestone (or corrupted milestone with undefined id)
412
+ // check for pending milestones to discuss instead
413
+ if (!state.activeMilestone?.id) {
413
414
  const pendingMilestones = state.registry.filter(m => m.status === "pending");
414
415
  if (pendingMilestones.length === 0) {
415
416
  ctx.ui.notify("No active milestone. Run /gsd to create one first.", "warning");
@@ -864,7 +865,7 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
864
865
  }
865
866
  }
866
867
  const state = await deriveState(basePath);
867
- if (!state.activeMilestone) {
868
+ if (!state.activeMilestone?.id) {
868
869
  // Guard: if a discuss session is already in flight, don't re-inject the prompt.
869
870
  // Both /gsd and /gsd auto reach this branch when no milestone exists yet.
870
871
  // Without this guard, every subsequent /gsd call overwrites pendingAutoStart
@@ -131,8 +131,15 @@ function appendWorkerLog(basePath, milestoneId, chunk) {
131
131
  }
132
132
  }
133
133
  function restoreRuntimeState(basePath) {
134
- if (state?.active)
135
- return true;
134
+ if (state?.active) {
135
+ // Verify at least one worker is alive — if all are in terminal states,
136
+ // the cached state is stale and we should fall through to cleanup.
137
+ const hasLiveWorker = [...state.workers.values()].some((w) => w.state !== "error" && w.state !== "stopped");
138
+ if (hasLiveWorker)
139
+ return true;
140
+ // All workers dead — clear stale state so restoreState() can clean up.
141
+ state = null;
142
+ }
136
143
  const restored = restoreState(basePath);
137
144
  if (restored && restored.workers.length > 0) {
138
145
  const config = resolveParallelConfig(undefined);
@@ -778,6 +785,15 @@ export function refreshWorkerStatuses(basePath, options = {}) {
778
785
  for (const worker of state.workers.values()) {
779
786
  state.totalCost += worker.cost;
780
787
  }
788
+ // If all workers are in a terminal state (error/stopped), the orchestration
789
+ // is finished — deactivate and clean up so zombie workers don't persist.
790
+ const allDead = [...state.workers.values()].every((w) => w.state === "error" || w.state === "stopped");
791
+ if (allDead) {
792
+ state.active = false;
793
+ removeStateFile(basePath);
794
+ state = null;
795
+ return;
796
+ }
781
797
  // Persist updated state for crash recovery
782
798
  persistState(basePath);
783
799
  }
@@ -40,19 +40,13 @@ export function isMilestoneComplete(roadmap) {
40
40
  return roadmap.slices.length > 0 && roadmap.slices.every(s => s.done);
41
41
  }
42
42
  /**
43
- * Check whether a VALIDATION file's verdict is terminal (pass or needs-attention).
44
- * A non-terminal verdict (needs-remediation) means validation must re-run
45
- * after remediation slices are executed.
43
+ * Check whether a VALIDATION file's verdict is terminal.
44
+ * Any successfully extracted verdict (pass, needs-attention, needs-remediation,
45
+ * fail, etc.) means validation completed. Only return false when no verdict
46
+ * could be parsed — i.e. extractVerdict() returns undefined (#2769).
46
47
  */
47
48
  export function isValidationTerminal(validationContent) {
48
- const v = extractVerdict(validationContent);
49
- if (!v)
50
- return false;
51
- // 'pass' and 'needs-attention' are always terminal.
52
- // 'needs-remediation' is treated as terminal to prevent infinite loops
53
- // when no remediation slices exist in the roadmap (#832). The validation
54
- // report is preserved on disk for manual review.
55
- return v === 'pass' || v === 'needs-attention' || v === 'needs-remediation';
49
+ return extractVerdict(validationContent) != null;
56
50
  }
57
51
  const CACHE_TTL_MS = 100;
58
52
  let _stateCache = null;
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
4
4
  import { delimiter, join } from "node:path";
5
5
  const GSD_RTK_PATH_ENV = "GSD_RTK_PATH";
6
6
  const GSD_RTK_DISABLED_ENV = "GSD_RTK_DISABLED";
7
+ const GSD_RTK_REWRITE_TIMEOUT_MS_ENV = "GSD_RTK_REWRITE_TIMEOUT_MS";
7
8
  const RTK_TELEMETRY_DISABLED_ENV = "RTK_TELEMETRY_DISABLED";
8
9
  const RTK_REWRITE_TIMEOUT_MS = 5_000;
9
10
  function isTruthy(value) {
@@ -12,6 +13,13 @@ function isTruthy(value) {
12
13
  const normalized = value.trim().toLowerCase();
13
14
  return normalized === "1" || normalized === "true" || normalized === "yes";
14
15
  }
16
+ function getRewriteTimeoutMs(env = process.env) {
17
+ const configured = Number.parseInt(env[GSD_RTK_REWRITE_TIMEOUT_MS_ENV] ?? "", 10);
18
+ if (Number.isFinite(configured) && configured > 0) {
19
+ return configured;
20
+ }
21
+ return RTK_REWRITE_TIMEOUT_MS;
22
+ }
15
23
  export function isRtkEnabled(env = process.env) {
16
24
  return !isTruthy(env[GSD_RTK_DISABLED_ENV]);
17
25
  }
@@ -89,7 +97,7 @@ export function rewriteCommandWithRtk(command, options = {}) {
89
97
  encoding: "utf-8",
90
98
  env: buildRtkEnv(env),
91
99
  stdio: ["ignore", "pipe", "ignore"],
92
- timeout: RTK_REWRITE_TIMEOUT_MS,
100
+ timeout: getRewriteTimeoutMs(env),
93
101
  // .cmd/.bat wrappers (used by fake-rtk in tests) require shell:true on Windows
94
102
  shell: /\.(cmd|bat)$/i.test(binaryPath),
95
103
  });
@@ -1 +1 @@
1
- KTe1kB5nPLQFIIFz2OcmI
1
+ zpvUPKoW5jRAMB_fWHlPi
@@ -2,45 +2,45 @@
2
2
  "/_not-found/page": "/_not-found",
3
3
  "/_global-error/page": "/_global-error",
4
4
  "/api/bridge-terminal/input/route": "/api/bridge-terminal/input",
5
- "/api/bridge-terminal/resize/route": "/api/bridge-terminal/resize",
6
5
  "/api/boot/route": "/api/boot",
6
+ "/api/bridge-terminal/resize/route": "/api/bridge-terminal/resize",
7
7
  "/api/bridge-terminal/stream/route": "/api/bridge-terminal/stream",
8
+ "/api/cleanup/route": "/api/cleanup",
9
+ "/api/dev-mode/route": "/api/dev-mode",
8
10
  "/api/doctor/route": "/api/doctor",
9
11
  "/api/browse-directories/route": "/api/browse-directories",
10
- "/api/export-data/route": "/api/export-data",
11
- "/api/cleanup/route": "/api/cleanup",
12
12
  "/api/captures/route": "/api/captures",
13
- "/api/dev-mode/route": "/api/dev-mode",
14
- "/api/git/route": "/api/git",
13
+ "/api/export-data/route": "/api/export-data",
15
14
  "/api/forensics/route": "/api/forensics",
15
+ "/api/git/route": "/api/git",
16
16
  "/api/history/route": "/api/history",
17
17
  "/api/hooks/route": "/api/hooks",
18
+ "/api/knowledge/route": "/api/knowledge",
18
19
  "/api/inspect/route": "/api/inspect",
19
20
  "/api/experimental/route": "/api/experimental",
20
- "/api/knowledge/route": "/api/knowledge",
21
21
  "/api/live-state/route": "/api/live-state",
22
- "/api/preferences/route": "/api/preferences",
23
22
  "/api/recovery/route": "/api/recovery",
23
+ "/api/preferences/route": "/api/preferences",
24
+ "/api/onboarding/route": "/api/onboarding",
24
25
  "/api/projects/route": "/api/projects",
25
26
  "/api/session/browser/route": "/api/session/browser",
26
- "/api/onboarding/route": "/api/onboarding",
27
27
  "/api/session/command/route": "/api/session/command",
28
- "/api/session/manage/route": "/api/session/manage",
29
28
  "/api/session/events/route": "/api/session/events",
30
29
  "/api/settings-data/route": "/api/settings-data",
30
+ "/api/session/manage/route": "/api/session/manage",
31
31
  "/api/shutdown/route": "/api/shutdown",
32
32
  "/api/skill-health/route": "/api/skill-health",
33
33
  "/api/steer/route": "/api/steer",
34
34
  "/api/terminal/input/route": "/api/terminal/input",
35
35
  "/api/switch-root/route": "/api/switch-root",
36
+ "/api/files/route": "/api/files",
37
+ "/api/terminal/sessions/route": "/api/terminal/sessions",
36
38
  "/api/terminal/resize/route": "/api/terminal/resize",
37
39
  "/api/terminal/stream/route": "/api/terminal/stream",
38
- "/api/terminal/sessions/route": "/api/terminal/sessions",
39
- "/api/remote-questions/route": "/api/remote-questions",
40
- "/api/terminal/upload/route": "/api/terminal/upload",
41
- "/api/files/route": "/api/files",
42
- "/api/visualizer/route": "/api/visualizer",
43
40
  "/api/update/route": "/api/update",
41
+ "/api/terminal/upload/route": "/api/terminal/upload",
44
42
  "/api/undo/route": "/api/undo",
43
+ "/api/remote-questions/route": "/api/remote-questions",
44
+ "/api/visualizer/route": "/api/visualizer",
45
45
  "/page": "/"
46
46
  }