@opengsd/gsd-pi 1.1.1-dev.b2556262 → 1.2.0-dev.844675c9

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 (211) hide show
  1. package/dist/project-sessions.js +4 -2
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +17 -9
  4. package/dist/resources/extensions/gsd/auto/contracts.js +8 -1
  5. package/dist/resources/extensions/gsd/auto/orchestrator.js +659 -57
  6. package/dist/resources/extensions/gsd/auto-prompts.js +110 -1
  7. package/dist/resources/extensions/gsd/auto-runtime-state.js +3 -0
  8. package/dist/resources/extensions/gsd/auto-tool-tracking.js +5 -0
  9. package/dist/resources/extensions/gsd/auto-unit-tool-scope.js +29 -0
  10. package/dist/resources/extensions/gsd/auto-worktree.js +24 -17
  11. package/dist/resources/extensions/gsd/auto.js +62 -464
  12. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +4 -1
  13. package/dist/resources/extensions/gsd/debug-logger.js +10 -0
  14. package/dist/resources/extensions/gsd/doctor-proactive.js +7 -2
  15. package/dist/resources/extensions/gsd/guided-flow.js +2 -2
  16. package/dist/resources/extensions/gsd/markdown-renderer.js +31 -32
  17. package/dist/resources/extensions/gsd/mcp-filter.js +6 -0
  18. package/dist/resources/extensions/gsd/native-git-bridge.js +45 -0
  19. package/dist/resources/extensions/gsd/prompts/discuss.md +6 -7
  20. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +5 -7
  21. package/dist/resources/extensions/gsd/prompts/guided-discuss-project.md +3 -5
  22. package/dist/resources/extensions/gsd/prompts/guided-discuss-requirements.md +1 -2
  23. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +5 -6
  24. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  25. package/dist/resources/extensions/gsd/prompts/research-milestone.md +2 -2
  26. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +5 -3
  27. package/dist/resources/extensions/gsd/schemas/parsers.js +6 -1
  28. package/dist/resources/extensions/gsd/state-reconciliation/drift/artifact-db.js +21 -1
  29. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +169 -20
  30. package/dist/resources/extensions/gsd/user-input-boundary.js +42 -4
  31. package/dist/tsconfig.extensions.tsbuildinfo +1 -0
  32. package/dist/web/standalone/.next/BUILD_ID +1 -1
  33. package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
  34. package/dist/web/standalone/.next/build-manifest.json +2 -2
  35. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  36. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  37. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  45. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  53. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  54. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  55. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  56. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  57. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  58. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  59. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  60. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  61. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  62. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  63. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  64. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  65. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  66. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  67. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  68. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  69. package/dist/web/standalone/.next/server/app/api/mcp-connections/route.js.nft.json +1 -1
  70. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
  71. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  72. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  73. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  74. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  75. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  76. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  77. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  78. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  79. package/dist/web/standalone/.next/server/app/api/shutdown/route.js.nft.json +1 -1
  80. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  81. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  82. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  83. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  84. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  85. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  86. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  87. package/dist/web/standalone/.next/server/app/index.html +1 -1
  88. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  91. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
  95. package/dist/web/standalone/.next/server/chunks/5047.js +2 -0
  96. package/dist/web/standalone/.next/server/chunks/5124.js +1 -0
  97. package/dist/web/standalone/.next/server/chunks/8357.js +2 -2
  98. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  99. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  100. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  101. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  102. package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
  103. package/dist/web/standalone/node_modules/node-pty/build/Makefile +1 -1
  104. package/dist/web/standalone/node_modules/postcss/lib/container.js +26 -18
  105. package/dist/web/standalone/node_modules/postcss/lib/css-syntax-error.js +47 -14
  106. package/dist/web/standalone/node_modules/postcss/lib/declaration.js +4 -4
  107. package/dist/web/standalone/node_modules/postcss/lib/fromJSON.js +3 -3
  108. package/dist/web/standalone/node_modules/postcss/lib/input.js +54 -29
  109. package/dist/web/standalone/node_modules/postcss/lib/lazy-result.js +47 -37
  110. package/dist/web/standalone/node_modules/postcss/lib/map-generator.js +26 -9
  111. package/dist/web/standalone/node_modules/postcss/lib/no-work-result.js +57 -55
  112. package/dist/web/standalone/node_modules/postcss/lib/node.js +99 -31
  113. package/dist/web/standalone/node_modules/postcss/lib/parse.js +1 -1
  114. package/dist/web/standalone/node_modules/postcss/lib/parser.js +10 -9
  115. package/dist/web/standalone/node_modules/postcss/lib/postcss.js +12 -12
  116. package/dist/web/standalone/node_modules/postcss/lib/previous-map.js +30 -11
  117. package/dist/web/standalone/node_modules/postcss/lib/processor.js +7 -7
  118. package/dist/web/standalone/node_modules/postcss/lib/result.js +5 -5
  119. package/dist/web/standalone/node_modules/postcss/lib/rule.js +6 -6
  120. package/dist/web/standalone/node_modules/postcss/lib/stringifier.js +69 -28
  121. package/dist/web/standalone/node_modules/postcss/lib/tokenize.js +6 -2
  122. package/dist/web/standalone/node_modules/postcss/package.json +48 -48
  123. package/package.json +16 -11
  124. package/packages/cloud-mcp-gateway/package.json +2 -2
  125. package/packages/contracts/package.json +1 -1
  126. package/packages/daemon/package.json +4 -4
  127. package/packages/gsd-agent-core/package.json +5 -5
  128. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js +1 -1
  129. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js.map +1 -1
  130. package/packages/gsd-agent-modes/package.json +7 -7
  131. package/packages/mcp-server/package.json +3 -3
  132. package/packages/native/package.json +1 -1
  133. package/packages/pi-agent-core/package.json +1 -1
  134. package/packages/pi-ai/dist/models.generated.d.ts +0 -34
  135. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  136. package/packages/pi-ai/dist/models.generated.js +12 -46
  137. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  138. package/packages/pi-ai/package.json +1 -1
  139. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  140. package/packages/pi-coding-agent/dist/core/auth-storage.js +11 -3
  141. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  142. package/packages/pi-coding-agent/package.json +7 -7
  143. package/packages/pi-tui/package.json +2 -2
  144. package/packages/rpc-client/package.json +2 -2
  145. package/pkg/package.json +1 -1
  146. package/scripts/install/deps.js +10 -0
  147. package/scripts/link-workspace-packages.cjs +7 -40
  148. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +18 -8
  149. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +2 -2
  150. package/src/resources/extensions/gsd/auto/contracts.ts +8 -119
  151. package/src/resources/extensions/gsd/auto/orchestrator.ts +794 -58
  152. package/src/resources/extensions/gsd/auto-prompts.ts +114 -1
  153. package/src/resources/extensions/gsd/auto-runtime-state.ts +4 -0
  154. package/src/resources/extensions/gsd/auto-tool-tracking.ts +5 -0
  155. package/src/resources/extensions/gsd/auto-unit-tool-scope.ts +33 -0
  156. package/src/resources/extensions/gsd/auto-worktree.ts +24 -16
  157. package/src/resources/extensions/gsd/auto.ts +81 -500
  158. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +4 -0
  159. package/src/resources/extensions/gsd/debug-logger.ts +11 -0
  160. package/src/resources/extensions/gsd/doctor-proactive.ts +8 -2
  161. package/src/resources/extensions/gsd/guided-flow.ts +2 -2
  162. package/src/resources/extensions/gsd/markdown-renderer.ts +38 -19
  163. package/src/resources/extensions/gsd/mcp-filter.ts +7 -0
  164. package/src/resources/extensions/gsd/native-git-bridge.ts +48 -0
  165. package/src/resources/extensions/gsd/prompts/discuss.md +6 -7
  166. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +5 -7
  167. package/src/resources/extensions/gsd/prompts/guided-discuss-project.md +3 -5
  168. package/src/resources/extensions/gsd/prompts/guided-discuss-requirements.md +1 -2
  169. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +5 -6
  170. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  171. package/src/resources/extensions/gsd/prompts/research-milestone.md +2 -2
  172. package/src/resources/extensions/gsd/prompts/validate-milestone.md +5 -3
  173. package/src/resources/extensions/gsd/schemas/parsers.ts +6 -1
  174. package/src/resources/extensions/gsd/state-reconciliation/drift/artifact-db.ts +31 -10
  175. package/src/resources/extensions/gsd/tests/artifact-db-drift-memo.test.ts +66 -0
  176. package/src/resources/extensions/gsd/tests/auto-dispatch-baseline-harness.test.ts +53 -0
  177. package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +590 -855
  178. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +38 -10
  179. package/src/resources/extensions/gsd/tests/debug-logger.test.ts +15 -0
  180. package/src/resources/extensions/gsd/tests/execute-summary-save-empty-project.test.ts +64 -1
  181. package/src/resources/extensions/gsd/tests/integration/merge-strategy-regular.test.ts +157 -0
  182. package/src/resources/extensions/gsd/tests/markdown-renderer-parse-cache.test.ts +75 -0
  183. package/src/resources/extensions/gsd/tests/native-merge-regular.test.ts +139 -0
  184. package/src/resources/extensions/gsd/tests/orchestrator-legacy-parity.test.ts +127 -0
  185. package/src/resources/extensions/gsd/tests/parse-project-milestone-bridge.test.ts +77 -0
  186. package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +4 -2
  187. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +29 -2
  188. package/src/resources/extensions/gsd/tests/research-milestone-composer.test.ts +65 -0
  189. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +19 -5
  190. package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +38 -0
  191. package/src/resources/extensions/gsd/tests/user-input-boundary.test.ts +62 -0
  192. package/src/resources/extensions/gsd/tests/worktree-safety.test.ts +24 -0
  193. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +15 -3
  194. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +183 -21
  195. package/src/resources/extensions/gsd/user-input-boundary.ts +37 -5
  196. package/dist/web/standalone/.next/server/chunks/678.js +0 -2
  197. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/gsd-widget-prototype.d.ts +0 -21
  198. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/gsd-widget-prototype.d.ts.map +0 -1
  199. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/gsd-widget-prototype.js +0 -213
  200. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/gsd-widget-prototype.js.map +0 -1
  201. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-density-prototype.d.ts +0 -28
  202. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-density-prototype.d.ts.map +0 -1
  203. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-density-prototype.js +0 -249
  204. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-density-prototype.js.map +0 -1
  205. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-design-prototype.d.ts +0 -19
  206. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-design-prototype.d.ts.map +0 -1
  207. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-design-prototype.js +0 -797
  208. package/packages/gsd-agent-modes/dist/modes/interactive/components/__prototype__/transcript-design-prototype.js.map +0 -1
  209. package/scripts/ensure-workspace-builds.cjs +0 -129
  210. /package/dist/web/standalone/.next/static/{tJOKQbQRO-9MiFDO8DIDS → Qbr81pQ-pbQXP4bq2VXLv}/_buildManifest.js +0 -0
  211. /package/dist/web/standalone/.next/static/{tJOKQbQRO-9MiFDO8DIDS → Qbr81pQ-pbQXP4bq2VXLv}/_ssgManifest.js +0 -0
@@ -205,12 +205,17 @@ export async function preDispatchHealthGate(basePath) {
205
205
  catch {
206
206
  // Non-fatal — dispatch continues without STATE.md if rebuild fails
207
207
  }
208
+ // #442 Phase 1.7: resolve repo-ness once per gate. ensureWorkspaceGitReady
209
+ // has already run, and nothing below initializes/deinitializes the repo, so
210
+ // the two downstream blocks (integration-branch check, stale-changes
211
+ // snapshot) can share one nativeIsRepo result instead of querying twice.
212
+ const isRepo = nativeIsRepo(basePath);
208
213
  // ── Integration branch existence check ──
209
214
  // If the active milestone's recorded integration branch no longer exists in
210
215
  // git, the merge-back at the end of the milestone will fail. Block dispatch
211
216
  // now to surface this before work is lost.
212
217
  try {
213
- if (nativeIsRepo(basePath)) {
218
+ if (isRepo) {
214
219
  const state = await deriveState(basePath);
215
220
  if (state.activeMilestone) {
216
221
  const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git ?? {};
@@ -231,7 +236,7 @@ export async function preDispatchHealthGate(basePath) {
231
236
  // If the working tree is dirty and no commit has happened recently,
232
237
  // create a safety snapshot so work isn't lost if the next unit crashes.
233
238
  try {
234
- if (nativeIsRepo(basePath)) {
239
+ if (isRepo) {
235
240
  const prefs = loadEffectiveGSDPreferences()?.preferences ?? {};
236
241
  // `git.snapshots: false` is the canonical toggle that disables WIP
237
242
  // snapshot commits — honour it before touching the threshold path (#4420).
@@ -1056,8 +1056,8 @@ async function buildDiscussPreparationContext(ctx, basePath, mode = "greenfield"
1056
1056
  if (parts.length === 0)
1057
1057
  return "";
1058
1058
  const guidance = mode === "milestone"
1059
- ? "Use these findings as background only — they describe what already exists, NOT what the user wants next. After investigation, send **one** message: a short recap (at most 2-3 sentences) plus 1-3 focused questions, then **stop**. Do not dump a feature-menu brainstorm or send a second message restating the same question."
1060
- : "Use these findings as background context — they describe what already exists, NOT what the user wants to build. Always ask the user what they want to build first.";
1059
+ ? "Use these findings as background only — they describe what already exists, NOT what the user wants next. This snapshot already covers code reality: do NOT survey the codebase before asking. Send **one** message: a short recap (at most 2-3 sentences) plus 1-3 focused questions, then **stop**. Do not dump a feature-menu brainstorm or send a second message restating the same question."
1060
+ : "Use these findings as background context — they describe what already exists, NOT what the user wants to build. This snapshot already covers code reality: do NOT survey the codebase before asking. Always ask the user what they want to build first.";
1061
1061
  return `\n\n## Preparation Context\n\nThe system analyzed the codebase before this discussion. ${guidance}\n\n${parts.join("\n\n")}`;
1062
1062
  }
1063
1063
  catch (err) {
@@ -8,14 +8,14 @@
8
8
  //
9
9
  // Critical invariant: rendered markdown must round-trip through
10
10
  // parseRoadmap(), parsePlan(), parseSummary() in files.ts.
11
- import { readFileSync, existsSync, mkdirSync } from "node:fs";
11
+ import { readFileSync, existsSync, mkdirSync, statSync } from "node:fs";
12
12
  import { logWarning } from "./workflow-logger.js";
13
13
  import { isClosedStatus } from "./status-guards.js";
14
14
  import { dirname, join, relative } from "node:path";
15
- import { createRequire } from "node:module";
16
15
  import { getAllMilestones, getMilestone, getMilestoneSlices, getSliceTasks, getTask, getSlice, insertArtifact, getGateResults, } from "./gsd-db.js";
17
16
  import { resolveDir, resolveFile, resolveSliceFile, resolveSlicePath, gsdProjectionRoot, gsdRoot, buildMilestoneFileName, buildTaskFileName, buildSliceFileName, } from "./paths.js";
18
- import { saveFile, clearParseCache } from "./files.js";
17
+ import { saveFile, clearParseCache, registerCacheClearCallback } from "./files.js";
18
+ import { parseRoadmap, parsePlan } from "./parsers-legacy.js";
19
19
  import { invalidateStateCache } from "./state.js";
20
20
  import { clearPathCache } from "./paths.js";
21
21
  // ─── Helpers ──────────────────────────────────────────────────────────────
@@ -562,34 +562,35 @@ export async function renderAllFromDb(basePath) {
562
562
  }
563
563
  return result;
564
564
  }
565
- /**
566
- * Detect stale renders by comparing DB state against file content.
567
- *
568
- * Checks:
569
- * 1. Roadmap checkbox states vs DB slice statuses
570
- * 2. Plan checkbox states vs DB task statuses
571
- * 3. Missing SUMMARY.md files for complete tasks with full_summary_md
572
- * 4. Missing SUMMARY.md/UAT.md files for complete slices with content
573
- *
574
- * Returns a list of stale entries with file path and reason.
575
- * Logs to stderr when stale files are detected.
576
- */
577
- export function detectStaleRenders(basePath) {
578
- // Lazy-load parsers — intentional disk-vs-DB comparison requires parsers
579
- const _require = createRequire(import.meta.url);
580
- let parseRoadmap, parsePlan;
565
+ const _projectionParseCache = new Map();
566
+ registerCacheClearCallback(() => _projectionParseCache.clear());
567
+ function parseProjectionByIdentity(path, parse) {
568
+ let st = null;
581
569
  try {
582
- // Prefer compiled JS for packaged/runtime installs; TS exists only in source/dev contexts.
583
- const m = _require("./parsers-legacy.js");
584
- parseRoadmap = m.parseRoadmap;
585
- parsePlan = m.parsePlan;
570
+ st = statSync(path);
586
571
  }
587
- catch (e) {
588
- logWarning("renderer", `parsers-legacy.js require failed, falling back to .ts: ${e.message}`);
589
- const m = _require("./parsers-legacy.ts");
590
- parseRoadmap = m.parseRoadmap;
591
- parsePlan = m.parsePlan;
572
+ catch {
573
+ st = null;
574
+ }
575
+ if (st) {
576
+ const hit = _projectionParseCache.get(path);
577
+ if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) {
578
+ return hit.parsed;
579
+ }
580
+ const parsed = parse(readFileSync(path, "utf-8"));
581
+ _projectionParseCache.set(path, { mtimeMs: st.mtimeMs, size: st.size, parsed });
582
+ return parsed;
592
583
  }
584
+ // stat failed (e.g. file vanished between existsSync and here) — fall back to
585
+ // the original plain read+parse so error handling is unchanged.
586
+ return parse(readFileSync(path, "utf-8"));
587
+ }
588
+ export function detectStaleRenders(basePath) {
589
+ // parseRoadmap/parsePlan are statically imported (#442 Phase 1.4): the
590
+ // per-call createRequire("./parsers-legacy") that used to live here ran on
591
+ // every dispatch. The static `./parsers-legacy.js` specifier resolves in
592
+ // both packaged (.js) and source (.ts via the strip-types loader) contexts —
593
+ // the same form a dozen other modules already use.
593
594
  const stale = [];
594
595
  const milestones = getAllMilestones();
595
596
  for (const milestone of milestones) {
@@ -598,8 +599,7 @@ export function detectStaleRenders(basePath) {
598
599
  const roadmapPath = resolveRoadmapProjectionPath(basePath, milestone.id);
599
600
  if (existsSync(roadmapPath)) {
600
601
  try {
601
- const content = readFileSync(roadmapPath, "utf-8");
602
- const parsed = parseRoadmap(content);
602
+ const parsed = parseProjectionByIdentity(roadmapPath, parseRoadmap);
603
603
  for (const slice of slices) {
604
604
  const isCompleteInDb = isClosedStatus(slice.status);
605
605
  const roadmapSlice = parsed.slices.find((s) => s.id === slice.id);
@@ -630,8 +630,7 @@ export function detectStaleRenders(basePath) {
630
630
  const planPath = resolveSliceFile(basePath, milestone.id, slice.id, "PLAN");
631
631
  if (planPath && existsSync(planPath)) {
632
632
  try {
633
- const content = readFileSync(planPath, "utf-8");
634
- const parsed = parsePlan(content);
633
+ const parsed = parseProjectionByIdentity(planPath, parsePlan);
635
634
  for (const task of tasks) {
636
635
  const isDoneInDb = isClosedStatus(task.status);
637
636
  const planTask = parsed.tasks.find((t) => t.id === task.id);
@@ -1,4 +1,5 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
2
3
  import { resolve } from "node:path";
3
4
  import { resolveModelMcpConfig } from "./preferences-mcp.js";
4
5
  function isRecord(value) {
@@ -88,6 +89,11 @@ export function discoverBrowserMcpServerName(projectDir) {
88
89
  export function discoverMcpServerNames(projectDir) {
89
90
  return discoverMcpServers(projectDir).map((server) => server.name);
90
91
  }
92
+ export function discoverUserMcpServerNames() {
93
+ const userSettingsPath = resolve(homedir(), ".claude", "settings.json");
94
+ const userSettings = readJsonFile(userSettingsPath, true);
95
+ return collectServerEntries(userSettings?.mcpServers).map((s) => s.name);
96
+ }
91
97
  export function computeMcpDisallowedTools(modelId, mcpConfig, discoveredServers, workflowServerName) {
92
98
  if (!mcpConfig)
93
99
  return [];
@@ -11,6 +11,7 @@ import { GSDError, GSD_GIT_ERROR } from "./errors.js";
11
11
  import { GIT_NO_PROMPT_ENV } from "./git-constants.js";
12
12
  import { getErrorMessage } from "./error-utils.js";
13
13
  import { isInfrastructureError } from "./auto/infra-errors.js";
14
+ import { debugCount } from "./debug-logger.js";
14
15
  // Issue #453: keep auto-mode bookkeeping on the stable git CLI path unless a
15
16
  // caller explicitly opts into the native helper.
16
17
  const NATIVE_GSD_GIT_ENABLED = process.env.GSD_ENABLE_NATIVE_GSD_GIT === "1";
@@ -40,6 +41,8 @@ function loadNative() {
40
41
  // ─── Fallback Helpers ──────────────────────────────────────────────────────
41
42
  /** Run a git command via execFileSync. Returns trimmed stdout. */
42
43
  function gitExec(basePath, args, allowFailure = false) {
44
+ // Counts git CLI shell-outs only (native libgit2 paths bypass this helper).
45
+ debugCount("gitInvocations");
43
46
  try {
44
47
  return execFileSync("git", args, {
45
48
  cwd: basePath,
@@ -64,6 +67,8 @@ function isRetryableGitError(err) {
64
67
  return code !== null && TRANSIENT_GIT_RETRY_CODES.has(code);
65
68
  }
66
69
  function execGitFileSyncWithRetry(basePath, args, options) {
70
+ // Counts git CLI shell-outs only (native libgit2 paths bypass this helper).
71
+ debugCount("gitInvocations");
67
72
  try {
68
73
  return execFileSync("git", args, {
69
74
  cwd: basePath,
@@ -77,6 +82,8 @@ function execGitFileSyncWithRetry(basePath, args, options) {
77
82
  if (!isRetryableGitError(err))
78
83
  throw err;
79
84
  sleepSync(GIT_RETRY_DELAY_MS);
85
+ // Retry is a second physical shell-out — count it too.
86
+ debugCount("gitInvocations");
80
87
  return execFileSync("git", args, {
81
88
  cwd: basePath,
82
89
  stdio: ["ignore", "pipe", "pipe"],
@@ -88,6 +95,8 @@ function execGitFileSyncWithRetry(basePath, args, options) {
88
95
  }
89
96
  /** Run a git command via execFileSync. Returns trimmed stdout. */
90
97
  function gitFileExec(basePath, args, allowFailure = false) {
98
+ // Counts git CLI shell-outs only (native libgit2 paths bypass this helper).
99
+ debugCount("gitInvocations");
91
100
  try {
92
101
  return execFileSync("git", args, {
93
102
  cwd: basePath,
@@ -921,6 +930,42 @@ export function nativeMergeSquash(basePath, branch) {
921
930
  throw err;
922
931
  }
923
932
  }
933
+ /**
934
+ * Regular (non-squash) merge a branch (stages changes, does NOT commit).
935
+ * Uses --no-ff to ensure a proper merge commit and --no-commit so the caller
936
+ * can supply a custom commit message via nativeCommit.
937
+ * Respects the user's global git merge.ff config; --no-ff is additive here.
938
+ */
939
+ export function nativeMergeRegular(basePath, branch) {
940
+ try {
941
+ execFileSync("git", ["merge", "--no-ff", "--no-commit", branch], {
942
+ cwd: basePath,
943
+ stdio: ["ignore", "pipe", "pipe"],
944
+ encoding: "utf-8",
945
+ env: GIT_NO_PROMPT_ENV,
946
+ });
947
+ return { success: true, conflicts: [] };
948
+ }
949
+ catch (err) {
950
+ const stderr = err instanceof Error ? err.stderr ?? err.message : String(err);
951
+ if (stderr.includes("local changes would be overwritten") ||
952
+ stderr.includes("not possible because you have unmerged files") ||
953
+ stderr.includes("overwritten by merge")) {
954
+ const dirtyFiles = stderr
955
+ .split("\n")
956
+ .filter((line) => line.startsWith("\t"))
957
+ .map((line) => line.trim())
958
+ .filter(Boolean);
959
+ return { success: false, conflicts: ["__dirty_working_tree__"], dirtyFiles };
960
+ }
961
+ const conflictOutput = gitExec(basePath, ["diff", "--name-only", "--diff-filter=U"], true);
962
+ const conflicts = conflictOutput ? conflictOutput.split("\n").filter(Boolean) : [];
963
+ if (conflicts.length > 0) {
964
+ return { success: false, conflicts };
965
+ }
966
+ throw err;
967
+ }
968
+ }
924
969
  /**
925
970
  * Abort an in-progress merge.
926
971
  * Native: libgit2 reset + cleanup.
@@ -31,18 +31,17 @@ After reflection is confirmed, choose the approach from actual scope, not a labe
31
31
 
32
32
  {{preparationContext}}
33
33
 
34
- ## Mandatory Investigation Before First Question Round
34
+ ## Ground the First Question Round
35
35
 
36
- Before the first question round, gather enough evidence for grounded questions:
37
- 1. Scout relevant code with `ls`, `find`, `rg`, or `scout`.
38
- 2. Check mentioned tech with `resolve_library` / `get_library_docs`.
39
- 3. Use web tools only for current external facts.
36
+ Ground your questions in the **Preparation Context above** (codebase snapshot, prior context) plus the user's reflected vision — that is authoritative. **Do not survey the codebase** with `ls`/`find`/`rg`/`scout` before asking; the snapshot already covers code reality. Read a specific file only when a question's answer genuinely hinges on it.
37
+ 1. Check mentioned tech with `resolve_library` / `get_library_docs`.
38
+ 2. Use web tools only for current external facts.
40
39
 
41
- Budget searches across the discussion; prefer docs and one-shot `search_and_read`. Re-investigate only when answers expose new gaps.
40
+ Budget searches across the discussion; prefer docs and one-shot `search_and_read`. Read on-demand only when an answer exposes a specific gap.
42
41
 
43
42
  ## Layered Question Rounds
44
43
 
45
- Questions have four layers. At each layer, ask 1-3 open questions per round, investigate as needed, and gate before advancing.
44
+ Questions have four layers. At each layer, ask 1-3 open questions per round, read a specific file on-demand if an answer needs it, and gate before advancing.
46
45
 
47
46
  **Default to open questions.** Use `ask_user_questions` only for 2-3 distinct paths with clear tradeoffs. Use plain text for nuanced design questions.
48
47
 
@@ -19,15 +19,13 @@ Discuss milestone {{milestoneId}} ("{{milestoneTitle}}"). Identify real gray are
19
19
  Before asking, read `.gsd/PROJECT.md` and find `## Project Shape` -> `**Complexity:**`. Use `simple` or `complex`; default to `complex` if missing, stale, or unclear.
20
20
 
21
21
  - `simple`: 1-2 plain-text rounds; skip parallel-research investigation; use `ask_user_questions` only for concrete alternatives.
22
- - `complex`: investigate first, use 3-4-option structured questions, and expect multiple rounds.
22
+ - `complex`: ground in the preloaded context first, use 3-4-option structured questions, and expect multiple rounds.
23
23
 
24
24
  ### Before your first question round
25
25
 
26
- Investigate enough to avoid assumption-driven questions:
27
- - Scout existing code with `rg`, `find`, or `scout`.
28
- - Check roadmap context above for surrounding scope.
29
- - Use `resolve_library` / `get_library_docs` for unfamiliar libraries; prefer them over web search.
26
+ Ground your questions in the **preloaded context above** (milestone roadmap/context/research, the decisions register, prior-milestone summaries) plus any Preparation Context snapshot — those are authoritative. **Do not survey the codebase** with `rg`/`find`/`scout` before asking; the preloaded files are marked do-not-re-read. Read a specific file only when a question's answer genuinely hinges on it.
30
27
  - Identify the 3-5 behavioral or architectural unknowns that materially change what gets built.
28
+ - Use `resolve_library` / `get_library_docs` for unfamiliar libraries; prefer them over web search.
31
29
 
32
30
  **Web search budget:** Limited per turn, typically 3-5. Prefer docs tools and `search_and_read`; use 2-3 searches in the first pass and save the rest.
33
31
 
@@ -43,13 +41,13 @@ Ask **1–3 questions per round**. Target one focus at a time:
43
41
 
44
42
  **Never fabricate or simulate user input.** Never generate fake transcript markers like `[User]`, `[Human]`, or `User:`. Ask one question round, then wait for the user's actual response before continuing.
45
43
 
46
- **Single user-facing message (NON-BYPASSABLE):** After investigation, send **one** assistant message that contains your questions (and at most a short recap — 2-3 sentences, not a feature catalog). **End the turn there.** Do not send a second message that restates the same ask ("what do you want M00X to be?", "before I can write the context file…", etc.). If you already asked, stop — do not elaborate in a follow-up message in the same turn.
44
+ **Single user-facing message (NON-BYPASSABLE):** After grounding in the preloaded context, send **one** assistant message that contains your questions (and at most a short recap — 2-3 sentences, not a feature catalog). **End the turn there.** Do not send a second message that restates the same ask ("what do you want M00X to be?", "before I can write the context file…", etc.). If you already asked, stop — do not elaborate in a follow-up message in the same turn.
47
45
 
48
46
  **If `{{structuredQuestionsAvailable}}` is `true`:** use `ask_user_questions` exactly once per turn with 1-3 question objects. Keep labels short (3-5 words). In `complex` mode, multi-choice questions MUST offer **3 or 4 concrete, researched options** plus **"Other — let me discuss"**; options must be grounded in the investigation, not placeholders. In `simple` mode, 2 options is fine for binary alternatives. Binary depth-check/wrap-up gates are exempt. If the user chooses "Other — let me discuss" or gives a long freeform answer, switch to plain-text follow-up before resuming structured questions.
49
47
 
50
48
  **If `{{structuredQuestionsAvailable}}` is `false`:** ask questions in plain text. Keep each round to 1–3 focused questions. Wait for answers before asking the next round.
51
49
 
52
- After each answer, investigate only new unknowns, then ask the next round.
50
+ After each answer, resolve only the new unknowns from context (re-read a specific file only if one is needed), then ask the next round.
53
51
 
54
52
  ### Round cadence
55
53
 
@@ -38,9 +38,7 @@ Persist the verdict through `gsd_summary_save` with `artifact_type: "PROJECT"` i
38
38
 
39
39
  ### Before deeper rounds
40
40
 
41
- Investigate enough to avoid assumption-driven questions:
42
- - Scout code with `rg`, `find`, or `scout` for greenfield/brownfield and framework signals.
43
- - Check prior `.planning/` or `.gsd/` artifacts.
41
+ Ground your questions in the **Preparation Context snapshot above** (stack, structure, greenfield/brownfield and framework signals) plus any prior `.planning/` or `.gsd/` artifacts — those are authoritative. **Do not survey the codebase** with `rg`/`find`/`scout` before asking; read a specific file only when a question's answer genuinely hinges on it.
44
42
  - Use `resolve_library` / `get_library_docs` for unfamiliar mentioned libraries.
45
43
 
46
44
  **Web search budget:** typically 3-5 per turn. Prefer docs tools; use 2-3 searches first and save the rest.
@@ -53,13 +51,13 @@ Ask **1–3 questions per round**, one focus at a time: what, who, core value, a
53
51
 
54
52
  **Shape-dependent cadence:**
55
53
  - **`simple`**: 1-2 plain-text rounds; use `ask_user_questions` only for concrete alternatives; reach the depth checklist quickly.
56
- - **`complex`**: full investigation, multiple rounds, structured questions when meaningful alternatives exist.
54
+ - **`complex`**: ground in the snapshot and prior artifacts, multiple rounds, structured questions when meaningful alternatives exist.
57
55
 
58
56
  **If `{{structuredQuestionsAvailable}}` is `true` and you use `ask_user_questions`:** ask 1-3 questions per call. Every question needs stable lowercase `id`. Keep labels short (3-5 words). In **`complex`** mode, multi-choice questions MUST offer **3 or 4 concrete, researched options** plus **"Other — let me discuss"**; options must be grounded in the investigation, not placeholders. In **`simple`** mode, 2 options is fine. Binary depth-check/wrap-up gates are exempt. Wait for each tool result before the next round.
59
57
 
60
58
  **If `{{structuredQuestionsAvailable}}` is `false`:** ask questions in plain text. Keep each round to 1–3 focused questions.
61
59
 
62
- After each round, investigate only new unknowns, then ask the next round.
60
+ After each round, resolve only new unknowns from context (read a specific file only if one is needed), then ask the next round.
63
61
 
64
62
  ### Round cadence
65
63
 
@@ -34,8 +34,7 @@ Before your first action, print this banner verbatim in chat:
34
34
 
35
35
  ### Before your first question round
36
36
 
37
- Before questioning, investigate enough to avoid assumption-driven requirements:
38
- - Scout existing capabilities; already-built work is `Validated` or `Active`.
37
+ Ground your requirements in **PROJECT.md, any existing REQUIREMENTS.md, and the Preparation Context snapshot** — those are authoritative for what already exists (already-built work is `Validated` or `Active`). **Do not survey the codebase**; read a specific file only when a requirement's scope genuinely hinges on it.
39
38
  - Cross-check milestone sequence; every milestone needs at least one owned Active requirement.
40
39
  - Use `resolve_library` / `get_library_docs` for libraries that imply capabilities.
41
40
  - Identify domain table-stakes only when PROJECT.md confidence is low.
@@ -13,12 +13,11 @@ Do **not** center the discussion on tech stack trivia, naming, or speculative ar
13
13
  Before the first question round, read `.gsd/PROJECT.md` and look for `## Project Shape` → `**Complexity:**`. Verdicts are **`simple`** or **`complex`**; default to `complex` if missing or unclear.
14
14
 
15
15
  - **`simple`** — use 1–2 plain-text rounds, then write context. Skip parallel-research investigation.
16
- - **`complex`** — investigate first, then ask structured 3–4-option questions.
16
+ - **`complex`** — ground in the preloaded context first, then ask structured 3–4-option questions.
17
17
 
18
- ### Investigation
18
+ ### Grounding
19
19
 
20
- Do enough targeted investigation that questions reflect reality:
21
- - Scout touched code with `rg`, `find`, or `scout` for broad unfamiliar areas.
20
+ Ground your questions in the **preloaded slice context above** plus any Preparation Context snapshot — those are authoritative. **Do not survey the codebase** with `rg`/`find`/`scout` before asking; read a specific file only when a question's answer genuinely hinges on it.
22
21
  - Check roadmap context for predecessor and dependent work.
23
22
  - For unfamiliar libraries, prefer `resolve_library` / `get_library_docs` over `search-the-web`.
24
23
  - Identify the 3–5 biggest behavioural unknowns where the user's answer materially changes the build.
@@ -31,7 +30,7 @@ Do **not** go deep; stop when you can ask grounded questions.
31
30
 
32
31
  **Never fabricate or simulate user input.** Never generate fake transcript markers like `[User]`, `[Human]`, or `User:`. Ask one question round, then wait for the user's actual response before continuing.
33
32
 
34
- **If `{{structuredQuestionsAvailable}}` is `true`:** Ask **1–3 questions per round** using `ask_user_questions`. In **`complex`** mode, each multi-choice question MUST present **3 or 4 concrete, researched options** plus final **"Other — let me discuss"** option; options must be grounded in the investigation above (codebase signals, library docs, prior `.gsd/` artifacts), not placeholders. In **`simple`** mode, 2 options is fine. Binary wrap-up gates are exempt. **Call `ask_user_questions` exactly once per turn — never make multiple calls with the same or overlapping questions. Wait for the user's response before asking the next round.**
33
+ **If `{{structuredQuestionsAvailable}}` is `true`:** Ask **1–3 questions per round** using `ask_user_questions`. In **`complex`** mode, each multi-choice question MUST present **3 or 4 concrete, researched options** plus final **"Other — let me discuss"** option; options must be grounded in the preloaded context above (slice context, codebase snapshot, library docs, prior `.gsd/` artifacts), not placeholders. In **`simple`** mode, 2 options is fine. Binary wrap-up gates are exempt. **Call `ask_user_questions` exactly once per turn — never make multiple calls with the same or overlapping questions. Wait for the user's response before asking the next round.**
35
34
  **If `{{structuredQuestionsAvailable}}` is `false`:** Ask **1–3 numbered plain-text questions per round**, then wait.
36
35
  Focus questions on:
37
36
  - **UX and user-facing behaviour** — what users see, click, trigger, or experience.
@@ -39,7 +38,7 @@ Focus questions on:
39
38
  - **Scope boundaries** — what is in, out, or deferred.
40
39
  - **Feel and experience** — tone, responsiveness, feedback, transitions, and what "done" feels like.
41
40
 
42
- After answers, investigate new unknowns if needed, then ask the next round.
41
+ After answers, resolve new unknowns from context (read a specific file only if needed), then ask the next round.
43
42
 
44
43
  ### Round cadence
45
44
 
@@ -38,7 +38,7 @@ If slice research is inlined, trust its architectural findings, but verify every
38
38
 
39
39
  1. If requirements are preloaded, identify owned and supporting Active requirements.
40
40
  2. Call `memory_query` with keywords from the slice title and source files.
41
- 3. Read `{{planTemplatePath}}` and `{{taskPlanTemplatePath}}`.
41
+ 3. Use the inlined Output Template sections already present in this prompt. Do not read template files from disk.
42
42
  4. {{skillActivation}} Record expected executor skills in each task plan's `skills_used` frontmatter.
43
43
  5. Define slice verification before tasks. Non-trivial slices need real tests or executable assertions; boundary contracts need contract-exercising checks. Tests must not read .gitignore/gitignored paths such as `.gsd/`, `.planning/`, or `.audits/`.
44
44
  6. Include Threat Surface (Q3), Requirement Impact (Q4), proof level, observability, integration closure, Failure Modes (Q5), Load Profile (Q6), and Negative Tests (Q7) only where applicable.
@@ -25,12 +25,12 @@ A milestone adding a small feature to an established codebase needs targeted res
25
25
  Then research the codebase and relevant technologies. Narrate key findings and surprises as you go — what exists, what's missing, what constrains the approach.
26
26
  1. {{skillActivation}}
27
27
  2. **Skill Discovery ({{skillDiscoveryMode}}):**{{skillDiscoveryInstructions}}
28
- 3. Explore relevant code. For small/familiar codebases, use `rg`, `find`, and targeted reads. For large or unfamiliar codebases, use `scout` to build a broad map efficiently before diving in.
28
+ 3. **Ground in the preloaded context, do not re-survey.** The Codebase Snapshot and Project Classification above describe current code reality and project size — treat them as authoritative. Do NOT open-endedly survey the tree (`rg`/`find`/`scout`) to rediscover what they already cover. Read a specific file with a targeted `read` only when a research question's answer hinges on that file's exact contents. Match research depth to the classified project size: a tiny project needs a short, targeted research note, not a broad survey.
29
29
  4. Use `resolve_library` / `get_library_docs` for unfamiliar libraries — skip this for libraries already used in the codebase
30
30
  5. **Web search budget:** You have a limited budget of web searches (max ~15 per session). Use them strategically — prefer `resolve_library` / `get_library_docs` for library documentation. Do NOT repeat the same or similar queries. If a search didn't find what you need, rephrase once or move on. Target 3-5 total web searches for a typical research unit.
31
31
  6. Use the **Research** output template from the inlined context above — include only sections that have real content
32
32
  7. If `.gsd/REQUIREMENTS.md` exists, research against it. Identify which Active requirements are table stakes, likely omissions, overbuilt risks, or domain-standard behaviors the user may or may not want.
33
- 8. Call `gsd_summary_save` with `milestone_id: {{milestoneId}}`, `artifact_type: "RESEARCH"`, and the full research markdown as `content` — the tool computes the file path and persists to both DB and disk.
33
+ 8. Call `gsd_summary_save` with `milestone_id: {{milestoneId}}`, `artifact_type: "RESEARCH"`, and the full research markdown as `content` — the tool computes the file path and persists to both DB and disk. Save **incrementally**: once you have substantive findings, save them, then enrich and re-save as you learn more. This makes your research durable — if this unit is interrupted, a re-dispatch resumes from your last saved draft instead of restarting. If a "Resume — Prior Partial Research" block is present above, extend that draft rather than starting over.
34
34
 
35
35
  ## Strategic Questions to Answer
36
36
 
@@ -24,16 +24,18 @@ Roadmap, slice summaries, assessments, requirements, decisions, and project cont
24
24
 
25
25
  ### Step 1 - Dispatch Parallel Reviewers
26
26
 
27
+ The Inlined Context above already preloads the evidence reviewers need — the roadmap, per-slice SUMMARY/ASSESSMENT excerpts, requirements, and verification classes. **Embed the relevant preloaded evidence directly into each reviewer's task prompt** so reviewers work from it instead of re-reading the same artifacts from disk. Each reviewer should read a full file only when its excerpt is missing, truncated, or internally inconsistent — never as a routine first step. This avoids three reviewers independently re-surveying artifacts the orchestrator already holds.
28
+
27
29
  Call `subagent` with `tasks: [...]` containing ALL THREE reviewers simultaneously:
28
30
 
29
31
  **Reviewer A - Requirements Coverage**
30
- Prompt: "Review milestone {{milestoneId}} requirements coverage. Working directory: {{workingDirectory}}. Read `.gsd/REQUIREMENTS.md` or use the inlined requirements context. For each requirement, check slice SUMMARY files under `.gsd/milestones/{{milestoneId}}/slices/` and mark COVERED, PARTIAL, or MISSING. Output table: Requirement | Status | Evidence. End with one-line verdict: PASS if all covered, NEEDS-ATTENTION if partials exist, FAIL if any missing."
32
+ Prompt: "Review milestone {{milestoneId}} requirements coverage. Working directory: {{workingDirectory}}. Use the preloaded requirements and slice SUMMARY evidence embedded in this task — do not re-read them from disk. For each requirement, mark COVERED, PARTIAL, or MISSING against that evidence. Read a full SUMMARY under `.gsd/milestones/{{milestoneId}}/slices/` only if its preloaded excerpt is missing, truncated, or inconsistent. Output table: Requirement | Status | Evidence. End with one-line verdict: PASS if all covered, NEEDS-ATTENTION if partials exist, FAIL if any missing."
31
33
 
32
34
  **Reviewer B - Cross-Slice Integration**
33
- Prompt: "Review milestone {{milestoneId}} cross-slice integration. Working directory: {{workingDirectory}}. Read `{{roadmapPath}}` and find the boundary map (produces/consumes contracts). For each boundary, confirm producer SUMMARY produced the artifact and consumer SUMMARY consumed it. Output table: Boundary | Producer Summary | Consumer Summary | Status. End with one-line verdict: PASS if all boundaries honored, NEEDS-ATTENTION if any gaps."
35
+ Prompt: "Review milestone {{milestoneId}} cross-slice integration. Working directory: {{workingDirectory}}. Use the preloaded roadmap and slice SUMMARY evidence embedded in this task — do not re-read them from disk. Find the boundary map (produces/consumes contracts) in the roadmap. For each boundary, confirm producer SUMMARY produced the artifact and consumer SUMMARY consumed it. Read `{{roadmapPath}}` or a full SUMMARY only if the preloaded evidence is missing, truncated, or inconsistent. Output table: Boundary | Producer Summary | Consumer Summary | Status. End with one-line verdict: PASS if all boundaries honored, NEEDS-ATTENTION if any gaps."
34
36
 
35
37
  **Reviewer C - Assessment & Acceptance Criteria**
36
- Prompt: "Review milestone {{milestoneId}} assessment evidence and acceptance criteria. Working directory: {{workingDirectory}}. Read `.gsd/milestones/{{milestoneId}}/{{milestoneId}}-CONTEXT.md` for criteria. Check slice SUMMARY and ASSESSMENT files under `.gsd/milestones/{{milestoneId}}/slices/`; UAT files are specs, not evidence. Verify each criterion maps to passing evidence. Then review the inlined `Verification Classes (from planning)` table. For every planned row in that table, output a `Verification Classes` table with columns `Class | Planned Check | Evidence | Verdict`. Preserve every planned non-empty class row; do not summarize, rename, combine, or omit planned classes. The first cell of each row must be exactly `Contract`, `Integration`, `Operational`, or `UAT` when that class is present in planning. If a planned class lacks evidence, still include its canonical row and mark the verdict NEEDS-ATTENTION or FAIL. If a planned browser/UAT class has no ASSESSMENT with browser/runtime actions and assertions, return NEEDS-ATTENTION. If no verification classes were planned, say that explicitly. Output sections `Acceptance Criteria` with checklist `[ ] Criterion | Evidence`, and `Verification Classes` with the table. End with one-line verdict: PASS if all criteria and classes are covered by evidence, NEEDS-ATTENTION if gaps exist."
38
+ Prompt: "Review milestone {{milestoneId}} assessment evidence and acceptance criteria. Working directory: {{workingDirectory}}. Use the preloaded milestone context, slice SUMMARY, and ASSESSMENT evidence embedded in this task — do not re-read them from disk. Read `.gsd/milestones/{{milestoneId}}/{{milestoneId}}-CONTEXT.md`, a full SUMMARY, or a full ASSESSMENT only if the preloaded excerpt is missing, truncated, or inconsistent. UAT files are specs, not evidence. Verify each criterion maps to passing evidence. Then review the inlined `Verification Classes (from planning)` table. For every planned row in that table, output a `Verification Classes` table with columns `Class | Planned Check | Evidence | Verdict`. Preserve every planned non-empty class row; do not summarize, rename, combine, or omit planned classes. The first cell of each row must be exactly `Contract`, `Integration`, `Operational`, or `UAT` when that class is present in planning. If a planned class lacks evidence, still include its canonical row and mark the verdict NEEDS-ATTENTION or FAIL. If a planned browser/UAT class has no ASSESSMENT with browser/runtime actions and assertions, return NEEDS-ATTENTION. If no verification classes were planned, say that explicitly. Output sections `Acceptance Criteria` with checklist `[ ] Criterion | Evidence`, and `Verification Classes` with the table. End with one-line verdict: PASS if all criteria and classes are covered by evidence, NEEDS-ATTENTION if gaps exist."
37
39
 
38
40
  ### Step 2 - Synthesize Findings
39
41
 
@@ -6,7 +6,12 @@
6
6
  const TEMPLATE_TOKEN_RE = /\{\{[^}]+\}\}/;
7
7
  const H2_RE = /^##\s+(.+)$/gm;
8
8
  const H3_RE = /^###\s+(.+)$/gm;
9
- const MILESTONE_LINE_RE = /^-\s+\[([ x])\]\s+(M\d{3}):\s+(.+?)\s+(?:—|--|-)\s+(.+)$/gm;
9
+ // A milestone line is single-line by construction. Every inter-token gap uses
10
+ // horizontal-whitespace classes (`[^\S\n]`) rather than `\s`, because `\s`
11
+ // matches newlines: a line missing a valid separator would otherwise let the
12
+ // `\s+(?:—|--|-)\s+` clause "bridge" onto the NEXT bullet's `- `, consuming it
13
+ // as the separator and silently swallowing the following well-formed milestone.
14
+ const MILESTONE_LINE_RE = /^-[^\S\n]+\[([ x])\][^\S\n]+(M\d{3}):[^\S\n]+(.+?)[^\S\n]+(?:—|--|-)[^\S\n]+(.+)$/gm;
10
15
  const SLICE_HEADER_RE = /^###\s+(S\d{2})\s*(?:—|--|-)\s+(.+)$/m;
11
16
  const REQUIREMENT_HEADER_RE = /^###\s+(R\d{3})\s*(?:—|--|-)\s+(.+)$/m;
12
17
  function splitH2Sections(content) {
@@ -250,7 +250,27 @@ function detectDiskSliceIdDivergenceForMilestone(basePath, milestoneId) {
250
250
  }
251
251
  return drifts;
252
252
  }
253
- export function detectArtifactDbDrift(_state, ctx) {
253
+ // #442 Phase 1.6: the three artifact/DB drift handlers (disk-slice-id,
254
+ // artifact-db-status, completed-milestone-reopened) each call
255
+ // detectArtifactDbDrift and then filter for their own kind — so the full
256
+ // milestone→slice→task walk + artifact SQL + disk scan would run THREE times
257
+ // per detection pass and discard 2/3 of the work. Memoize the result per
258
+ // DriftContext so the three handlers share one computation. The key is the
259
+ // ctx object, which detectAllDrift rebuilds for every pass (and which is
260
+ // unreferenced once the pass ends, so the WeakMap entry is GC'd) — DB/disk
261
+ // state is immutable within a single pass (repairs run only after detection),
262
+ // so this is behavior-preserving. A fresh ctx (e.g. the maintenance command's
263
+ // inline { basePath, state }) always recomputes.
264
+ const _artifactDbDriftMemo = new WeakMap();
265
+ export function detectArtifactDbDrift(state, ctx) {
266
+ const cached = _artifactDbDriftMemo.get(ctx);
267
+ if (cached)
268
+ return cached;
269
+ const computed = computeArtifactDbDrift(state, ctx);
270
+ _artifactDbDriftMemo.set(ctx, computed);
271
+ return computed;
272
+ }
273
+ function computeArtifactDbDrift(_state, ctx) {
254
274
  if (!isDbAvailable())
255
275
  return [];
256
276
  const drifts = [];