gsd-pi 2.80.0-dev.2848d9009 → 2.80.0-dev.2be7caf18

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 (182) hide show
  1. package/README.md +3 -2
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/extensions/gsd/auto/loop.js +32 -1
  4. package/dist/resources/extensions/gsd/auto-prompts.js +13 -1
  5. package/dist/resources/extensions/gsd/auto.js +7 -2
  6. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +27 -20
  7. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +21 -0
  8. package/dist/resources/extensions/gsd/crash-recovery.js +56 -10
  9. package/dist/resources/extensions/gsd/guided-flow.js +33 -6
  10. package/dist/resources/extensions/gsd/migrate/command.js +40 -1
  11. package/dist/resources/extensions/gsd/migration-auto-check.js +87 -0
  12. package/dist/resources/extensions/gsd/planning-path-scope.js +26 -0
  13. package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
  14. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  15. package/dist/resources/extensions/gsd/prompts/quick-task.md +1 -5
  16. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
  17. package/dist/resources/extensions/gsd/quick.js +34 -2
  18. package/dist/resources/extensions/gsd/tools/context-mode-tool-result.js +15 -0
  19. package/dist/resources/extensions/gsd/tools/exec-search-tool.js +5 -0
  20. package/dist/resources/extensions/gsd/tools/exec-tool.js +3 -15
  21. package/dist/resources/extensions/gsd/tools/plan-slice.js +9 -0
  22. package/dist/resources/extensions/gsd/tools/plan-task.js +9 -0
  23. package/dist/resources/extensions/gsd/tools/resume-tool.js +5 -0
  24. package/dist/resources/extensions/gsd/unit-context-composer.js +12 -3
  25. package/dist/resources/extensions/gsd/unit-runtime.js +11 -0
  26. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  27. package/dist/web/standalone/.next/BUILD_ID +1 -1
  28. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  29. package/dist/web/standalone/.next/build-manifest.json +2 -2
  30. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  31. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  32. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  40. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/index.html +1 -1
  48. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  55. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  56. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  57. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  58. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  59. package/package.json +1 -1
  60. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  61. package/packages/mcp-server/dist/workflow-tools.js +22 -17
  62. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  63. package/packages/mcp-server/src/workflow-tools.test.ts +66 -0
  64. package/packages/mcp-server/src/workflow-tools.ts +30 -16
  65. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  66. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  67. package/packages/pi-coding-agent/dist/core/agent-session.js +3 -0
  68. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  69. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +3 -1
  70. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  71. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +11 -0
  72. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  73. package/packages/pi-coding-agent/dist/core/compaction/compaction.js +9 -0
  74. package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  75. package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts +2 -0
  76. package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts.map +1 -0
  77. package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js +103 -0
  78. package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js.map +1 -0
  79. package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts +15 -0
  80. package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts.map +1 -0
  81. package/packages/pi-coding-agent/dist/core/db-snapshot.js +66 -0
  82. package/packages/pi-coding-agent/dist/core/db-snapshot.js.map +1 -0
  83. package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts +2 -0
  84. package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts.map +1 -0
  85. package/packages/pi-coding-agent/dist/core/db-snapshot.test.js +24 -0
  86. package/packages/pi-coding-agent/dist/core/db-snapshot.test.js.map +1 -0
  87. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +1 -0
  88. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  89. package/packages/pi-coding-agent/dist/core/extensions/runner.js +3 -0
  90. package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  91. package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +2 -0
  92. package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
  93. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +7 -0
  94. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  95. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  96. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +20 -0
  97. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  98. package/packages/pi-coding-agent/dist/core/settings-manager.js +25 -0
  99. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  100. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -0
  101. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  102. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +3 -0
  103. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  104. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  105. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +13 -5
  106. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  107. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js +53 -0
  108. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map +1 -1
  109. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  110. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +3 -0
  111. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  112. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts +2 -0
  113. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts.map +1 -0
  114. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js +10 -0
  115. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js.map +1 -0
  116. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.d.ts.map +1 -1
  117. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js +3 -2
  118. package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js.map +1 -1
  119. package/packages/pi-coding-agent/src/core/agent-session.ts +3 -0
  120. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +3 -1
  121. package/packages/pi-coding-agent/src/core/compaction/compaction.ts +18 -0
  122. package/packages/pi-coding-agent/src/core/compaction-threshold.test.ts +121 -0
  123. package/packages/pi-coding-agent/src/core/db-snapshot.test.ts +32 -0
  124. package/packages/pi-coding-agent/src/core/db-snapshot.ts +66 -0
  125. package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +2 -0
  126. package/packages/pi-coding-agent/src/core/extensions/runner.ts +3 -0
  127. package/packages/pi-coding-agent/src/core/extensions/types.ts +7 -0
  128. package/packages/pi-coding-agent/src/core/settings-manager.ts +39 -1
  129. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +4 -0
  130. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.test.ts +56 -0
  131. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +22 -7
  132. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +3 -0
  133. package/packages/pi-coding-agent/src/resources/extensions/memory/storage-safety-guard.test.ts +14 -0
  134. package/packages/pi-coding-agent/src/resources/extensions/memory/storage.ts +3 -2
  135. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  136. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  137. package/packages/pi-tui/dist/tui.js +18 -8
  138. package/packages/pi-tui/dist/tui.js.map +1 -1
  139. package/packages/pi-tui/src/tui.ts +20 -8
  140. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
  141. package/src/resources/extensions/gsd/auto/loop.ts +50 -8
  142. package/src/resources/extensions/gsd/auto-prompts.ts +17 -1
  143. package/src/resources/extensions/gsd/auto.ts +11 -2
  144. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +27 -19
  145. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +22 -0
  146. package/src/resources/extensions/gsd/crash-recovery.ts +67 -10
  147. package/src/resources/extensions/gsd/guided-flow.ts +39 -6
  148. package/src/resources/extensions/gsd/migrate/command.ts +47 -1
  149. package/src/resources/extensions/gsd/migration-auto-check.ts +129 -0
  150. package/src/resources/extensions/gsd/planning-path-scope.ts +35 -0
  151. package/src/resources/extensions/gsd/preferences-types.ts +1 -1
  152. package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
  153. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  154. package/src/resources/extensions/gsd/prompts/quick-task.md +1 -5
  155. package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
  156. package/src/resources/extensions/gsd/quick.ts +37 -2
  157. package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +11 -0
  158. package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +55 -0
  159. package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +22 -0
  160. package/src/resources/extensions/gsd/tests/exec-history.test.ts +15 -0
  161. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +65 -0
  162. package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +48 -0
  163. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +127 -0
  164. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +50 -0
  165. package/src/resources/extensions/gsd/tests/plan-task.test.ts +21 -0
  166. package/src/resources/extensions/gsd/tests/prompt-path-audit.test.ts +40 -0
  167. package/src/resources/extensions/gsd/tests/quick-external-gsd.test.ts +40 -0
  168. package/src/resources/extensions/gsd/tests/smart-entry-complete.test.ts +20 -0
  169. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +17 -0
  170. package/src/resources/extensions/gsd/tests/status-db-open.test.ts +9 -0
  171. package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +136 -4
  172. package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +7 -0
  173. package/src/resources/extensions/gsd/tools/context-mode-tool-result.ts +25 -0
  174. package/src/resources/extensions/gsd/tools/exec-search-tool.ts +7 -7
  175. package/src/resources/extensions/gsd/tools/exec-tool.ts +4 -23
  176. package/src/resources/extensions/gsd/tools/plan-slice.ts +13 -0
  177. package/src/resources/extensions/gsd/tools/plan-task.ts +10 -0
  178. package/src/resources/extensions/gsd/tools/resume-tool.ts +7 -7
  179. package/src/resources/extensions/gsd/unit-context-composer.ts +19 -4
  180. package/src/resources/extensions/gsd/unit-runtime.ts +14 -0
  181. /package/dist/web/standalone/.next/static/{vaQ47E8aNlbbNEDoeME6G → 3EDDd9ULaybSupPoA_vf-}/_buildManifest.js +0 -0
  182. /package/dist/web/standalone/.next/static/{vaQ47E8aNlbbNEDoeME6G → 3EDDd9ULaybSupPoA_vf-}/_ssgManifest.js +0 -0
@@ -21,12 +21,18 @@ import type {
21
21
  ComputedArtifactRegistry,
22
22
  UnitContextManifest,
23
23
  } from "../unit-context-manifest.ts";
24
- import { UNIT_MANIFESTS } from "../unit-context-manifest.ts";
25
- import { buildReassessRoadmapPrompt } from "../auto-prompts.ts";
24
+ import { KNOWN_UNIT_TYPES, UNIT_MANIFESTS } from "../unit-context-manifest.ts";
25
+ import {
26
+ buildExecuteTaskPrompt,
27
+ buildGateEvaluatePrompt,
28
+ buildReassessRoadmapPrompt,
29
+ buildWorkflowPreferencesPrompt,
30
+ } from "../auto-prompts.ts";
26
31
  import { invalidateAllCaches } from "../cache.ts";
27
32
  import {
28
33
  openDatabase,
29
34
  closeDatabase,
35
+ insertGateRow,
30
36
  insertMilestone,
31
37
  upsertMilestonePlanning,
32
38
  insertSlice,
@@ -121,7 +127,7 @@ test("Context Mode composer: standalone output starts with heading and includes
121
127
  assert.ok(out.startsWith("## Context Mode"));
122
128
  assert.match(out, /execution lane/i);
123
129
  assert.match(out, /`gsd_exec`/);
124
- assert.match(out, /noisy commands/);
130
+ assert.match(out, /builds, tests, and diagnostics/);
125
131
  assert.match(out, /`gsd_exec_search`/);
126
132
  assert.match(out, /before reruns/);
127
133
  assert.match(out, /`gsd_resume`/);
@@ -136,7 +142,45 @@ test("Context Mode composer: nested output is compact single sentence", () => {
136
142
  assert.match(out, /`gsd_exec`/);
137
143
  assert.match(out, /`gsd_exec_search`/);
138
144
  assert.match(out, /`gsd_resume`/);
139
- assert.ok(out.length < 180, `nested guidance should stay compact, got ${out.length} chars`);
145
+ assert.ok(out.length < 240, `nested guidance should stay compact, got ${out.length} chars`);
146
+ });
147
+
148
+ const laneLabelByMode: Record<string, string> = {
149
+ interview: "interview",
150
+ research: "research",
151
+ planning: "planning",
152
+ execution: "execution",
153
+ verification: "verification",
154
+ orchestration: "orchestration",
155
+ docs: "documentation",
156
+ };
157
+
158
+ test("Context Mode composer: every known eligible unit renders its configured lane and required tools", () => {
159
+ for (const unitType of KNOWN_UNIT_TYPES) {
160
+ const manifest = UNIT_MANIFESTS[unitType];
161
+ assert.ok(manifest, `missing manifest for ${unitType}`);
162
+ const out = composeContextModeInstructions(unitType, { enabled: true, renderMode: "standalone" });
163
+ if (manifest.contextMode === "none") {
164
+ assert.strictEqual(out, "", `${unitType} should not render Context Mode`);
165
+ continue;
166
+ }
167
+ assert.ok(out.startsWith("## Context Mode"), `${unitType} should render standalone Context Mode heading`);
168
+ assert.match(out, new RegExp(`Lane: \\*\\*${laneLabelByMode[manifest.contextMode]} lane\\*\\*\\.`, "i"));
169
+ assert.match(out, /`gsd_exec`/, `${unitType} should mention gsd_exec`);
170
+ assert.match(out, /`gsd_exec_search`/, `${unitType} should mention gsd_exec_search`);
171
+ assert.match(out, /`gsd_resume`/, `${unitType} should mention gsd_resume`);
172
+ }
173
+ });
174
+
175
+ test("Context Mode composer: workflow-preferences and research-decision render no Context Mode block", () => {
176
+ assert.strictEqual(
177
+ composeContextModeInstructions("workflow-preferences", { enabled: true, renderMode: "standalone" }),
178
+ "",
179
+ );
180
+ assert.strictEqual(
181
+ composeContextModeInstructions("research-decision", { enabled: true, renderMode: "standalone" }),
182
+ "",
183
+ );
140
184
  });
141
185
 
142
186
  // ─── Integration: migrated buildReassessRoadmapPrompt ─────────────────────
@@ -220,6 +264,94 @@ test("#4782 phase 2: buildReassessRoadmapPrompt emits composer-shaped context wi
220
264
  assert.ok(!prompt.includes("Slice Context (from discussion)"));
221
265
  });
222
266
 
267
+ test("Context Mode resume injection: eligible prompts include one bounded snapshot block above inlined context", async (t) => {
268
+ const base = makeFixtureBase();
269
+ t.after(() => cleanup(base));
270
+ invalidateAllCaches();
271
+
272
+ seed(base, "M001");
273
+ writeArtifacts(base);
274
+ writeFileSync(
275
+ join(base, ".gsd", "last-snapshot.md"),
276
+ "# GSD context snapshot\n\nResume evidence.\n",
277
+ "utf-8",
278
+ );
279
+
280
+ const prompt = await buildReassessRoadmapPrompt("M001", "Test", "S01", base);
281
+
282
+ assert.equal(prompt.match(/## Context Snapshot/g)?.length, 1);
283
+ assert.match(prompt, /Source: `\.gsd\/last-snapshot\.md`/);
284
+ assert.match(prompt, /Resume evidence/);
285
+ assert.ok(prompt.indexOf("## Context Mode") < prompt.indexOf("## Context Snapshot"));
286
+ assert.ok(prompt.indexOf("## Context Snapshot") < prompt.indexOf("## Inlined Context"));
287
+ });
288
+
289
+ test("Context Mode resume injection: missing snapshot does not add an empty block", async (t) => {
290
+ const base = makeFixtureBase();
291
+ t.after(() => cleanup(base));
292
+ invalidateAllCaches();
293
+
294
+ seed(base, "M001");
295
+ writeArtifacts(base);
296
+
297
+ const prompt = await buildReassessRoadmapPrompt("M001", "Test", "S01", base);
298
+
299
+ assert.match(prompt, /## Context Mode/);
300
+ assert.doesNotMatch(prompt, /## Context Snapshot/);
301
+ });
302
+
303
+ test("Context Mode resume injection: disabled mode suppresses guidance and snapshot reads", async (t) => {
304
+ const base = makeFixtureBase();
305
+ t.after(() => cleanup(base));
306
+ invalidateAllCaches();
307
+
308
+ seed(base, "M001");
309
+ writeArtifacts(base);
310
+ writeFileSync(join(base, ".gsd", "PREFERENCES.md"), "---\ncontext_mode:\n enabled: false\n---\n", "utf-8");
311
+ writeFileSync(join(base, ".gsd", "last-snapshot.md"), "# GSD context snapshot\n\nDo not inject.\n", "utf-8");
312
+
313
+ const prompt = await buildReassessRoadmapPrompt("M001", "Test", "S01", base);
314
+
315
+ assert.doesNotMatch(prompt, /## Context Mode/);
316
+ assert.doesNotMatch(prompt, /## Context Snapshot/);
317
+ assert.doesNotMatch(prompt, /Do not inject/);
318
+ });
319
+
320
+ test("Context Mode resume injection: none-mode units do not inject snapshots", async () => {
321
+ const base = makeFixtureBase();
322
+ try {
323
+ writeFileSync(join(base, ".gsd", "last-snapshot.md"), "# GSD context snapshot\n\nNo lane.\n", "utf-8");
324
+ const prompt = await buildWorkflowPreferencesPrompt(base);
325
+ assert.doesNotMatch(prompt, /## Context Mode/);
326
+ assert.doesNotMatch(prompt, /## Context Snapshot/);
327
+ assert.doesNotMatch(prompt, /No lane/);
328
+ } finally {
329
+ cleanup(base);
330
+ }
331
+ });
332
+
333
+ test("Context Mode prompt suppression: disabled inlined, phase-anchor, and nested prompts omit Context Mode", async (t) => {
334
+ const base = makeFixtureBase();
335
+ t.after(() => cleanup(base));
336
+ invalidateAllCaches();
337
+
338
+ seed(base, "M001");
339
+ writeArtifacts(base);
340
+ insertGateRow({ milestoneId: "M001", sliceId: "S01", gateId: "Q3", scope: "slice" });
341
+ writeFileSync(join(base, ".gsd", "PREFERENCES.md"), "---\ncontext_mode:\n enabled: false\n---\n", "utf-8");
342
+ writeFileSync(join(base, ".gsd", "last-snapshot.md"), "# GSD context snapshot\n\nDo not inject.\n", "utf-8");
343
+
344
+ const inlinedPrompt = await buildReassessRoadmapPrompt("M001", "Test", "S01", base);
345
+ assert.doesNotMatch(inlinedPrompt, /## Context Mode|Context Mode \(|## Context Snapshot/);
346
+
347
+ const phaseAnchorPrompt = await buildExecuteTaskPrompt("M001", "S01", "First", "T01", "Task", base);
348
+ assert.doesNotMatch(phaseAnchorPrompt, /## Context Mode|Context Mode \(|## Context Snapshot/);
349
+
350
+ const nestedPrompt = await buildGateEvaluatePrompt("M001", "Test", "S01", "First", base);
351
+ assert.match(nestedPrompt, /Use this as the prompt for a `subagent` call/);
352
+ assert.doesNotMatch(nestedPrompt, /## Context Mode|Context Mode \(|## Context Snapshot/);
353
+ });
354
+
223
355
  // ─── v2 surface (#4924) ───────────────────────────────────────────────────
224
356
 
225
357
  const fakeBase: BaseResolverContext = {
@@ -5,6 +5,7 @@ import {
5
5
  clearUnitRuntimeRecord,
6
6
  formatExecuteTaskRecoveryStatus,
7
7
  inspectExecuteTaskDurability,
8
+ isInFlightRuntimePhase,
8
9
  readUnitRuntimeRecord,
9
10
  writeUnitRuntimeRecord,
10
11
  } from "../unit-runtime.ts";
@@ -22,6 +23,12 @@ writeFileSync(
22
23
  "utf-8",
23
24
  );
24
25
 
26
+ console.log("\n=== in-flight runtime phases ===");
27
+ {
28
+ assert.equal(isInFlightRuntimePhase("crashed"), true, "crashed records remain recoverable");
29
+ assert.equal(isInFlightRuntimePhase("finalized"), false, "finalized records are terminal");
30
+ }
31
+
25
32
  console.log("\n=== runtime record write/read/update ===");
26
33
  {
27
34
  const first = writeUnitRuntimeRecord(base, "execute-task", "M100/S02/T09", 1000, { phase: "dispatched" });
@@ -0,0 +1,25 @@
1
+ // Project/App: GSD-2
2
+ // File Purpose: Shared Context Mode tool result helpers.
3
+
4
+ export interface ToolExecutionResult {
5
+ content: Array<{ type: "text"; text: string }>;
6
+ details: Record<string, unknown>;
7
+ isError?: boolean;
8
+ }
9
+
10
+ export type ContextModeToolName = "gsd_exec" | "gsd_exec_search" | "gsd_resume";
11
+
12
+ export function contextModeDisabledResult(operation: ContextModeToolName): ToolExecutionResult {
13
+ return {
14
+ content: [
15
+ {
16
+ type: "text",
17
+ text:
18
+ `${operation} is disabled by \`context_mode.enabled: false\` in preferences. ` +
19
+ "Remove that override or set it to true to re-enable Context Mode tools.",
20
+ },
21
+ ],
22
+ details: { operation, error: "context_mode_disabled" },
23
+ isError: true,
24
+ };
25
+ }
@@ -4,6 +4,8 @@
4
4
  // re-discover past runs without re-executing. Read-only; no DB writes.
5
5
 
6
6
  import { searchExecHistory, type ExecSearchOptions } from "../exec-history.js";
7
+ import { isContextModeEnabled, type ContextModeConfig } from "../preferences-types.js";
8
+ import { contextModeDisabledResult, type ToolExecutionResult } from "./context-mode-tool-result.js";
7
9
 
8
10
  export interface ExecSearchToolParams {
9
11
  query?: string;
@@ -12,16 +14,14 @@ export interface ExecSearchToolParams {
12
14
  limit?: number;
13
15
  }
14
16
 
15
- export interface ToolExecutionResult {
16
- content: Array<{ type: "text"; text: string }>;
17
- details: Record<string, unknown>;
18
- isError?: boolean;
19
- }
20
-
21
17
  export function executeExecSearch(
22
18
  params: ExecSearchToolParams,
23
- opts: { baseDir: string },
19
+ opts: { baseDir: string; preferences?: { context_mode?: ContextModeConfig } | null },
24
20
  ): ToolExecutionResult {
21
+ if (!isContextModeEnabled(opts.preferences)) {
22
+ return contextModeDisabledResult("gsd_exec_search");
23
+ }
24
+
25
25
  const searchOpts: ExecSearchOptions = {
26
26
  query: typeof params.query === "string" ? params.query : undefined,
27
27
  runtime: params.runtime,
@@ -12,6 +12,7 @@ import {
12
12
  type ExecSandboxResult,
13
13
  } from "../exec-sandbox.js";
14
14
  import { isContextModeEnabled, type ContextModeConfig } from "../preferences-types.js";
15
+ import { contextModeDisabledResult, type ToolExecutionResult } from "./context-mode-tool-result.js";
15
16
 
16
17
  export interface ExecToolParams {
17
18
  runtime: ExecSandboxRequest["runtime"];
@@ -20,17 +21,12 @@ export interface ExecToolParams {
20
21
  timeout_ms?: number;
21
22
  }
22
23
 
23
- export interface ToolExecutionResult {
24
- content: Array<{ type: "text"; text: string }>;
25
- details: Record<string, unknown>;
26
- isError?: boolean;
27
- }
28
-
29
24
  export interface ExecToolDeps {
30
25
  baseDir: string;
31
26
  preferences: { context_mode?: ContextModeConfig } | null;
32
27
  /** Optional override for testing. */
33
28
  run?: (req: ExecSandboxRequest, opts: ExecSandboxOptions) => Promise<ExecSandboxResult>;
29
+ env?: NodeJS.ProcessEnv;
34
30
  now?: () => Date;
35
31
  generateId?: () => string;
36
32
  }
@@ -77,21 +73,6 @@ function isEnabled(prefs: ExecToolDeps["preferences"]): boolean {
77
73
  return isContextModeEnabled(prefs);
78
74
  }
79
75
 
80
- function disabledResult(): ToolExecutionResult {
81
- return {
82
- content: [
83
- {
84
- type: "text",
85
- text:
86
- "gsd_exec is disabled by `context_mode.enabled: false` in preferences. Remove that " +
87
- "override (or set it to true) to re-enable sandboxed tool-output execution.",
88
- },
89
- ],
90
- details: { operation: "gsd_exec", error: "context_mode_disabled" },
91
- isError: true,
92
- };
93
- }
94
-
95
76
  function paramError(message: string): ToolExecutionResult {
96
77
  return {
97
78
  content: [{ type: "text", text: `Error: ${message}` }],
@@ -104,7 +85,7 @@ export async function executeGsdExec(
104
85
  params: ExecToolParams,
105
86
  deps: ExecToolDeps,
106
87
  ): Promise<ToolExecutionResult> {
107
- if (!isEnabled(deps.preferences)) return disabledResult();
88
+ if (!isEnabled(deps.preferences)) return contextModeDisabledResult("gsd_exec");
108
89
 
109
90
  const runtime = params.runtime;
110
91
  if (runtime !== "bash" && runtime !== "node" && runtime !== "python") {
@@ -121,7 +102,7 @@ export async function executeGsdExec(
121
102
  const opts = buildExecOptions(
122
103
  deps.baseDir,
123
104
  deps.preferences?.context_mode,
124
- { now: deps.now, generateId: deps.generateId },
105
+ { env: deps.env, now: deps.now, generateId: deps.generateId },
125
106
  );
126
107
  const run = deps.run ?? runExecSandbox;
127
108
 
@@ -18,6 +18,7 @@ import { renderAllProjections } from "../workflow-projections.js";
18
18
  import { writeManifest } from "../workflow-manifest.js";
19
19
  import { appendEvent } from "../workflow-events.js";
20
20
  import { logWarning } from "../workflow-logger.js";
21
+ import { validatePlanningPathScope } from "../planning-path-scope.js";
21
22
 
22
23
  export interface PlanSliceTaskInput {
23
24
  taskId: string;
@@ -141,6 +142,18 @@ export async function handlePlanSlice(
141
142
  return { error: `validation failed: ${(err as Error).message}` };
142
143
  }
143
144
 
145
+ const pathScopeError = validatePlanningPathScope(
146
+ basePath,
147
+ params.tasks.flatMap((task, index) => [
148
+ { field: `tasks[${index}].files`, values: task.files },
149
+ { field: `tasks[${index}].inputs`, values: task.inputs },
150
+ { field: `tasks[${index}].expectedOutput`, values: task.expectedOutput },
151
+ ]),
152
+ );
153
+ if (pathScopeError) {
154
+ return { error: `validation failed: ${pathScopeError}` };
155
+ }
156
+
144
157
  // ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
145
158
  // Guards must be inside the transaction so the state they check cannot
146
159
  // change between the read and the write (#2723).
@@ -8,6 +8,7 @@ import { renderAllProjections } from "../workflow-projections.js";
8
8
  import { writeManifest } from "../workflow-manifest.js";
9
9
  import { appendEvent } from "../workflow-events.js";
10
10
  import { logWarning } from "../workflow-logger.js";
11
+ import { validatePlanningPathScope } from "../planning-path-scope.js";
11
12
 
12
13
  export interface PlanTaskParams {
13
14
  milestoneId: string;
@@ -66,6 +67,15 @@ export async function handlePlanTask(
66
67
  return { error: `validation failed: ${(err as Error).message}` };
67
68
  }
68
69
 
70
+ const pathScopeError = validatePlanningPathScope(basePath, [
71
+ { field: "files", values: params.files },
72
+ { field: "inputs", values: params.inputs },
73
+ { field: "expectedOutput", values: params.expectedOutput },
74
+ ]);
75
+ if (pathScopeError) {
76
+ return { error: `validation failed: ${pathScopeError}` };
77
+ }
78
+
69
79
  // ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
70
80
  // Guards must be inside the transaction so the state they check cannot
71
81
  // change between the read and the write (#2723).
@@ -3,22 +3,22 @@
3
3
  // re-deriving project memory state.
4
4
 
5
5
  import { readCompactionSnapshot } from "../compaction-snapshot.js";
6
+ import { isContextModeEnabled, type ContextModeConfig } from "../preferences-types.js";
7
+ import { contextModeDisabledResult, type ToolExecutionResult } from "./context-mode-tool-result.js";
6
8
 
7
9
  export interface ResumeToolParams {
8
10
  /** Ignored — reserved for future variant (e.g. dated snapshots). */
9
11
  _variant?: string;
10
12
  }
11
13
 
12
- export interface ToolExecutionResult {
13
- content: Array<{ type: "text"; text: string }>;
14
- details: Record<string, unknown>;
15
- isError?: boolean;
16
- }
17
-
18
14
  export function executeResume(
19
15
  _params: ResumeToolParams,
20
- opts: { baseDir: string },
16
+ opts: { baseDir: string; preferences?: { context_mode?: ContextModeConfig } | null },
21
17
  ): ToolExecutionResult {
18
+ if (!isContextModeEnabled(opts.preferences)) {
19
+ return contextModeDisabledResult("gsd_resume");
20
+ }
21
+
22
22
  const snapshot = readCompactionSnapshot(opts.baseDir);
23
23
  if (snapshot == null) {
24
24
  return {
@@ -112,8 +112,22 @@ const CONTEXT_MODE_LANE_LABELS: Record<Exclude<ContextModePolicy, "none">, strin
112
112
  docs: "documentation",
113
113
  };
114
114
 
115
- const CONTEXT_MODE_GUIDANCE =
116
- "Use `gsd_exec` for noisy commands, `gsd_exec_search` before reruns, and `gsd_resume` after compaction or resume.";
115
+ const CONTEXT_MODE_GUIDANCE_BY_LANE: Record<Exclude<ContextModePolicy, "none">, string> = {
116
+ interview:
117
+ "Use `gsd_resume` to restore prior discussion, `gsd_exec` for noisy discovery, and `gsd_exec_search` before repeating scans.",
118
+ research:
119
+ "Use `gsd_exec` for noisy research scans, `gsd_exec_search` before reruns, and `gsd_resume` to restore prior findings.",
120
+ planning:
121
+ "Use `gsd_resume` for planning continuity, `gsd_exec` for noisy checks, and `gsd_exec_search` before rerunning diagnostics.",
122
+ execution:
123
+ "Use `gsd_exec` for builds, tests, and diagnostics, `gsd_exec_search` before reruns, and `gsd_resume` after compaction or resume.",
124
+ verification:
125
+ "Use `gsd_exec` for verification commands, `gsd_exec_search` to reuse prior evidence, and `gsd_resume` after compaction or resume.",
126
+ orchestration:
127
+ "Use `gsd_resume` before resuming orchestration, `gsd_exec_search` to reuse prior runs, and `gsd_exec` for noisy coordination checks.",
128
+ docs:
129
+ "Use `gsd_resume` for prior context, `gsd_exec_search` for saved evidence, and `gsd_exec` for noisy doc validation commands.",
130
+ };
117
131
 
118
132
  /**
119
133
  * Render the Context Mode instruction lane for a unit type. Unknown unit
@@ -129,15 +143,16 @@ export function composeContextModeInstructions(
129
143
  if (!manifest || manifest.contextMode === "none") return "";
130
144
 
131
145
  const lane = CONTEXT_MODE_LANE_LABELS[manifest.contextMode];
146
+ const guidance = CONTEXT_MODE_GUIDANCE_BY_LANE[manifest.contextMode];
132
147
  if (opts.renderMode === "nested") {
133
- return `Context Mode (${lane} lane): ${CONTEXT_MODE_GUIDANCE}`;
148
+ return `Context Mode (${lane} lane): ${guidance}`;
134
149
  }
135
150
 
136
151
  return [
137
152
  "## Context Mode",
138
153
  "",
139
154
  `Lane: **${lane} lane**.`,
140
- CONTEXT_MODE_GUIDANCE,
155
+ guidance,
141
156
  ].join("\n");
142
157
  }
143
158
 
@@ -67,11 +67,25 @@ export type UnitRuntimePhase =
67
67
  | "wrapup-warning-sent"
68
68
  | "timeout"
69
69
  | "finalize-timeout"
70
+ | "crashed"
70
71
  | "recovered"
71
72
  | "finalized"
72
73
  | "paused"
73
74
  | "skipped";
74
75
 
76
+ export const IN_FLIGHT_RUNTIME_PHASES: ReadonlySet<UnitRuntimePhase> = new Set([
77
+ "dispatched",
78
+ "wrapup-warning-sent",
79
+ "timeout",
80
+ "finalize-timeout",
81
+ "crashed",
82
+ "paused",
83
+ ]);
84
+
85
+ export function isInFlightRuntimePhase(phase: UnitRuntimePhase): boolean {
86
+ return IN_FLIGHT_RUNTIME_PHASES.has(phase);
87
+ }
88
+
75
89
  export interface ExecuteTaskRecoveryStatus {
76
90
  planPath: string;
77
91
  summaryPath: string;