gsd-pi 2.76.0 → 2.77.0

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 (536) hide show
  1. package/README.md +45 -25
  2. package/dist/claude-cli-check.js +32 -3
  3. package/dist/mcp-server.d.ts +7 -0
  4. package/dist/mcp-server.js +35 -1
  5. package/dist/onboarding.js +45 -0
  6. package/dist/resource-loader.d.ts +1 -1
  7. package/dist/resource-loader.js +2 -8
  8. package/dist/resources/agents/researcher.md +1 -1
  9. package/dist/resources/extensions/claude-code-cli/readiness.js +31 -8
  10. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +77 -17
  11. package/dist/resources/extensions/gsd/auto/loop.js +9 -0
  12. package/dist/resources/extensions/gsd/auto/phases.js +104 -11
  13. package/dist/resources/extensions/gsd/auto/run-unit.js +38 -2
  14. package/dist/resources/extensions/gsd/auto/session.js +22 -1
  15. package/dist/resources/extensions/gsd/auto-dispatch.js +16 -3
  16. package/dist/resources/extensions/gsd/auto-model-selection.js +53 -16
  17. package/dist/resources/extensions/gsd/auto-post-unit.js +25 -2
  18. package/dist/resources/extensions/gsd/auto-prompts.js +14 -0
  19. package/dist/resources/extensions/gsd/auto-recovery.js +32 -1
  20. package/dist/resources/extensions/gsd/auto-start.js +58 -57
  21. package/dist/resources/extensions/gsd/auto-verification.js +33 -0
  22. package/dist/resources/extensions/gsd/auto-worktree.js +51 -53
  23. package/dist/resources/extensions/gsd/auto.js +70 -28
  24. package/dist/resources/extensions/gsd/blocked-models.js +68 -0
  25. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +93 -1
  26. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +39 -9
  27. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +93 -0
  28. package/dist/resources/extensions/gsd/bootstrap/memory-tools.js +3 -0
  29. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +12 -0
  30. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +52 -6
  31. package/dist/resources/extensions/gsd/bootstrap/system-context.js +84 -23
  32. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +34 -2
  33. package/dist/resources/extensions/gsd/clean-root-preflight.js +93 -0
  34. package/dist/resources/extensions/gsd/commands-extract-learnings.js +54 -89
  35. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +968 -23
  36. package/dist/resources/extensions/gsd/compaction-snapshot.js +121 -0
  37. package/dist/resources/extensions/gsd/complexity-classifier.js +5 -3
  38. package/dist/resources/extensions/gsd/db-writer.js +88 -16
  39. package/dist/resources/extensions/gsd/doctor-git-checks.js +23 -29
  40. package/dist/resources/extensions/gsd/doctor-providers.js +51 -5
  41. package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +1 -0
  42. package/dist/resources/extensions/gsd/error-classifier.js +31 -3
  43. package/dist/resources/extensions/gsd/exec-history.js +120 -0
  44. package/dist/resources/extensions/gsd/exec-sandbox.js +258 -0
  45. package/dist/resources/extensions/gsd/gitignore.js +1 -0
  46. package/dist/resources/extensions/gsd/gsd-db.js +168 -23
  47. package/dist/resources/extensions/gsd/guided-flow.js +190 -1
  48. package/dist/resources/extensions/gsd/health-widget.js +4 -1
  49. package/dist/resources/extensions/gsd/hook-emitter.js +108 -0
  50. package/dist/resources/extensions/gsd/init-wizard.js +15 -1
  51. package/dist/resources/extensions/gsd/key-manager.js +28 -0
  52. package/dist/resources/extensions/gsd/memory-backfill.js +126 -0
  53. package/dist/resources/extensions/gsd/memory-store.js +19 -0
  54. package/dist/resources/extensions/gsd/model-router.js +36 -3
  55. package/dist/resources/extensions/gsd/pre-execution-checks.js +44 -9
  56. package/dist/resources/extensions/gsd/preferences-types.js +9 -0
  57. package/dist/resources/extensions/gsd/preferences-validation.js +83 -0
  58. package/dist/resources/extensions/gsd/preferences.js +17 -17
  59. package/dist/resources/extensions/gsd/prompt-loader.js +22 -7
  60. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  61. package/dist/resources/extensions/gsd/prompts/complete-slice.md +2 -2
  62. package/dist/resources/extensions/gsd/prompts/debug-diagnose.md +2 -0
  63. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  64. package/dist/resources/extensions/gsd/prompts/discuss.md +29 -2
  65. package/dist/resources/extensions/gsd/prompts/execute-task.md +3 -2
  66. package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  67. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -0
  68. package/dist/resources/extensions/gsd/prompts/research-slice.md +1 -0
  69. package/dist/resources/extensions/gsd/safety/evidence-collector.js +96 -0
  70. package/dist/resources/extensions/gsd/safety/file-change-validator.js +13 -5
  71. package/dist/resources/extensions/gsd/safety/safety-harness.js +5 -1
  72. package/dist/resources/extensions/gsd/state.js +43 -4
  73. package/dist/resources/extensions/gsd/token-counter.js +22 -5
  74. package/dist/resources/extensions/gsd/tools/complete-milestone.js +16 -10
  75. package/dist/resources/extensions/gsd/tools/exec-search-tool.js +59 -0
  76. package/dist/resources/extensions/gsd/tools/exec-tool.js +126 -0
  77. package/dist/resources/extensions/gsd/tools/memory-tools.js +26 -1
  78. package/dist/resources/extensions/gsd/tools/resume-tool.js +23 -0
  79. package/dist/resources/extensions/gsd/uok/plan-v2.js +20 -3
  80. package/dist/resources/extensions/gsd/workflow-mcp.js +3 -0
  81. package/dist/resources/extensions/gsd/workflow-templates/spike.md +6 -0
  82. package/dist/resources/extensions/gsd/worktree-resolver.js +50 -10
  83. package/dist/resources/extensions/search-the-web/command-search-provider.js +5 -4
  84. package/dist/resources/extensions/search-the-web/native-search.js +45 -13
  85. package/dist/resources/skills/api-design/SKILL.md +190 -0
  86. package/dist/resources/skills/create-mcp-server/SKILL.md +121 -0
  87. package/dist/resources/skills/decompose-into-slices/SKILL.md +139 -0
  88. package/dist/resources/skills/dependency-upgrade/SKILL.md +158 -0
  89. package/dist/resources/skills/design-an-interface/SKILL.md +102 -0
  90. package/dist/resources/skills/forensics/SKILL.md +153 -0
  91. package/dist/resources/skills/grill-me/SKILL.md +93 -0
  92. package/dist/resources/skills/handoff/SKILL.md +121 -0
  93. package/dist/resources/skills/observability/SKILL.md +174 -0
  94. package/dist/resources/skills/security-review/SKILL.md +181 -0
  95. package/dist/resources/skills/spike-wrap-up/SKILL.md +138 -0
  96. package/dist/resources/skills/tdd/SKILL.md +112 -0
  97. package/dist/resources/skills/verify-before-complete/SKILL.md +98 -0
  98. package/dist/resources/skills/write-docs/SKILL.md +82 -0
  99. package/dist/resources/skills/write-milestone-brief/SKILL.md +135 -0
  100. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  101. package/dist/web/standalone/.next/BUILD_ID +1 -1
  102. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  103. package/dist/web/standalone/.next/build-manifest.json +2 -2
  104. package/dist/web/standalone/.next/required-server-files.json +1 -1
  105. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  106. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  107. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  108. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  109. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  110. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  111. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  112. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  113. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  114. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  115. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  116. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  117. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  118. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  119. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  120. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  121. package/dist/web/standalone/.next/server/app/index.html +1 -1
  122. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  123. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  124. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  125. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  126. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  127. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  128. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  129. package/dist/web/standalone/.next/server/chunks/6897.js +2 -2
  130. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  131. package/dist/web/standalone/.next/server/middleware-manifest.json +1 -1
  132. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  133. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  134. package/dist/web/standalone/server.js +1 -1
  135. package/dist/welcome-screen.js +6 -1
  136. package/dist/wizard.js +2 -0
  137. package/package.json +1 -1
  138. package/packages/daemon/package.json +2 -2
  139. package/packages/mcp-server/dist/remote-questions.d.ts +45 -0
  140. package/packages/mcp-server/dist/remote-questions.d.ts.map +1 -0
  141. package/packages/mcp-server/dist/remote-questions.js +732 -0
  142. package/packages/mcp-server/dist/remote-questions.js.map +1 -0
  143. package/packages/mcp-server/dist/server.d.ts +7 -0
  144. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  145. package/packages/mcp-server/dist/server.js +70 -8
  146. package/packages/mcp-server/dist/server.js.map +1 -1
  147. package/packages/mcp-server/dist/session-manager.d.ts +14 -0
  148. package/packages/mcp-server/dist/session-manager.d.ts.map +1 -1
  149. package/packages/mcp-server/dist/session-manager.js +49 -1
  150. package/packages/mcp-server/dist/session-manager.js.map +1 -1
  151. package/packages/mcp-server/dist/workflow-tools.d.ts +1 -1
  152. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  153. package/packages/mcp-server/dist/workflow-tools.js +163 -25
  154. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  155. package/packages/mcp-server/package.json +4 -3
  156. package/packages/mcp-server/src/mcp-server.test.ts +67 -0
  157. package/packages/mcp-server/src/remote-questions.test.ts +294 -0
  158. package/packages/mcp-server/src/remote-questions.ts +916 -0
  159. package/packages/mcp-server/src/server.ts +89 -14
  160. package/packages/mcp-server/src/session-manager.ts +43 -1
  161. package/packages/mcp-server/src/workflow-tools.test.ts +146 -1
  162. package/packages/mcp-server/src/workflow-tools.ts +215 -43
  163. package/packages/mcp-server/tsconfig.test.json +19 -0
  164. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  165. package/packages/native/package.json +1 -1
  166. package/packages/pi-agent-core/dist/agent-loop.js +12 -0
  167. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  168. package/packages/pi-agent-core/dist/types.d.ts +30 -0
  169. package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
  170. package/packages/pi-agent-core/dist/types.js.map +1 -1
  171. package/packages/pi-agent-core/package.json +1 -1
  172. package/packages/pi-agent-core/src/agent-loop.ts +14 -0
  173. package/packages/pi-agent-core/src/types.ts +34 -0
  174. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
  175. package/packages/pi-ai/dist/models/custom.d.ts +38 -0
  176. package/packages/pi-ai/dist/models/custom.d.ts.map +1 -1
  177. package/packages/pi-ai/dist/models/custom.js +41 -0
  178. package/packages/pi-ai/dist/models/custom.js.map +1 -1
  179. package/packages/pi-ai/dist/providers/anthropic-auth.test.js +1 -1
  180. package/packages/pi-ai/dist/providers/anthropic-auth.test.js.map +1 -1
  181. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.d.ts +2 -0
  182. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.d.ts.map +1 -0
  183. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.js +13 -0
  184. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.js.map +1 -0
  185. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  186. package/packages/pi-ai/dist/providers/anthropic-shared.js +27 -4
  187. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  188. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  189. package/packages/pi-ai/dist/providers/anthropic.js +13 -4
  190. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  191. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts +2 -0
  192. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts.map +1 -0
  193. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js +80 -0
  194. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js.map +1 -0
  195. package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  196. package/packages/pi-ai/dist/providers/openai-completions.js +60 -15
  197. package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
  198. package/packages/pi-ai/dist/providers/simple-options.d.ts +10 -0
  199. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  200. package/packages/pi-ai/dist/providers/simple-options.js +16 -1
  201. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  202. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts +17 -0
  203. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts.map +1 -0
  204. package/packages/pi-ai/dist/providers/think-tag-parser.js +75 -0
  205. package/packages/pi-ai/dist/providers/think-tag-parser.js.map +1 -0
  206. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts +2 -0
  207. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts.map +1 -0
  208. package/packages/pi-ai/dist/providers/think-tag-parser.test.js +41 -0
  209. package/packages/pi-ai/dist/providers/think-tag-parser.test.js.map +1 -0
  210. package/packages/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -1
  211. package/packages/pi-ai/dist/utils/oauth/github-copilot.js +12 -2
  212. package/packages/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -1
  213. package/packages/pi-ai/dist/utils/oauth/github-copilot.test.js +164 -14
  214. package/packages/pi-ai/dist/utils/oauth/github-copilot.test.js.map +1 -1
  215. package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
  216. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +15 -3
  217. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
  218. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.d.ts +2 -0
  219. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.d.ts.map +1 -0
  220. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.js +67 -0
  221. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.js.map +1 -0
  222. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
  223. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +16 -3
  224. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
  225. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.d.ts +2 -0
  226. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.d.ts.map +1 -0
  227. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.js +67 -0
  228. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.js.map +1 -0
  229. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.d.ts +2 -0
  230. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.d.ts.map +1 -0
  231. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.js +289 -0
  232. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.js.map +1 -0
  233. package/packages/pi-ai/package.json +1 -1
  234. package/packages/pi-ai/src/models/custom.ts +42 -0
  235. package/packages/pi-ai/src/providers/anthropic-auth.test.ts +1 -1
  236. package/packages/pi-ai/src/providers/anthropic-bearer-auth.test.ts +26 -0
  237. package/packages/pi-ai/src/providers/anthropic-shared.ts +26 -5
  238. package/packages/pi-ai/src/providers/anthropic.ts +15 -4
  239. package/packages/pi-ai/src/providers/minimax-tool-name.test.ts +98 -0
  240. package/packages/pi-ai/src/providers/openai-completions.ts +57 -16
  241. package/packages/pi-ai/src/providers/simple-options.ts +17 -1
  242. package/packages/pi-ai/src/providers/think-tag-parser.test.ts +44 -0
  243. package/packages/pi-ai/src/providers/think-tag-parser.ts +94 -0
  244. package/packages/pi-ai/src/utils/oauth/github-copilot.test.ts +200 -23
  245. package/packages/pi-ai/src/utils/oauth/github-copilot.ts +12 -2
  246. package/packages/pi-ai/src/utils/oauth/google-antigravity.test.ts +84 -0
  247. package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +15 -5
  248. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.test.ts +84 -0
  249. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +16 -5
  250. package/packages/pi-ai/src/utils/oauth/oauth-providers.test.ts +363 -0
  251. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  252. package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js +3 -2
  253. package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js.map +1 -1
  254. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +2 -0
  255. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  256. package/packages/pi-coding-agent/dist/core/agent-session.js +32 -2
  257. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  258. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +1 -1
  259. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  260. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  261. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  262. package/packages/pi-coding-agent/dist/core/extensions/loader.js +4 -0
  263. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  264. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +35 -2
  265. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  266. package/packages/pi-coding-agent/dist/core/extensions/runner.js +233 -0
  267. package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  268. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +205 -2
  269. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  270. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  271. package/packages/pi-coding-agent/dist/core/hooks-runner.d.ts +53 -0
  272. package/packages/pi-coding-agent/dist/core/hooks-runner.d.ts.map +1 -0
  273. package/packages/pi-coding-agent/dist/core/hooks-runner.js +337 -0
  274. package/packages/pi-coding-agent/dist/core/hooks-runner.js.map +1 -0
  275. package/packages/pi-coding-agent/dist/core/hooks-runner.test.d.ts +2 -0
  276. package/packages/pi-coding-agent/dist/core/hooks-runner.test.d.ts.map +1 -0
  277. package/packages/pi-coding-agent/dist/core/hooks-runner.test.js +234 -0
  278. package/packages/pi-coding-agent/dist/core/hooks-runner.test.js.map +1 -0
  279. package/packages/pi-coding-agent/dist/core/index.d.ts +1 -0
  280. package/packages/pi-coding-agent/dist/core/index.d.ts.map +1 -1
  281. package/packages/pi-coding-agent/dist/core/index.js +1 -0
  282. package/packages/pi-coding-agent/dist/core/index.js.map +1 -1
  283. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts +3 -1
  284. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts.map +1 -1
  285. package/packages/pi-coding-agent/dist/core/model-discovery.js +92 -12
  286. package/packages/pi-coding-agent/dist/core/model-discovery.js.map +1 -1
  287. package/packages/pi-coding-agent/dist/core/model-discovery.test.js +16 -1
  288. package/packages/pi-coding-agent/dist/core/model-discovery.test.js.map +1 -1
  289. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.d.ts +2 -0
  290. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.d.ts.map +1 -0
  291. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.js +40 -0
  292. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.js.map +1 -0
  293. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts +2 -0
  294. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts.map +1 -0
  295. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js +203 -0
  296. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js.map +1 -0
  297. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js +61 -1
  298. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js.map +1 -1
  299. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +5 -0
  300. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  301. package/packages/pi-coding-agent/dist/core/model-registry.js +90 -10
  302. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  303. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts +2 -0
  304. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts.map +1 -0
  305. package/packages/pi-coding-agent/dist/core/redact-secrets.js +49 -0
  306. package/packages/pi-coding-agent/dist/core/redact-secrets.js.map +1 -0
  307. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts +2 -0
  308. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts.map +1 -0
  309. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js +67 -0
  310. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js.map +1 -0
  311. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  312. package/packages/pi-coding-agent/dist/core/session-manager.js +10 -6
  313. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  314. package/packages/pi-coding-agent/dist/core/session-manager.test.js +45 -1
  315. package/packages/pi-coding-agent/dist/core/session-manager.test.js.map +1 -1
  316. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +55 -0
  317. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  318. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  319. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  320. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  321. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  322. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
  323. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
  324. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +5 -4
  325. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
  326. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map +1 -1
  327. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js +13 -7
  328. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js.map +1 -1
  329. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +7 -6
  330. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  331. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +29 -21
  332. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  333. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  334. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +13 -1
  335. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  336. package/packages/pi-coding-agent/package.json +1 -1
  337. package/packages/pi-coding-agent/src/core/agent-session-abort-order.test.ts +3 -2
  338. package/packages/pi-coding-agent/src/core/agent-session.ts +38 -2
  339. package/packages/pi-coding-agent/src/core/extensions/index.ts +16 -0
  340. package/packages/pi-coding-agent/src/core/extensions/loader.ts +5 -0
  341. package/packages/pi-coding-agent/src/core/extensions/runner.ts +351 -0
  342. package/packages/pi-coding-agent/src/core/extensions/types.ts +258 -0
  343. package/packages/pi-coding-agent/src/core/hooks-runner.test.ts +269 -0
  344. package/packages/pi-coding-agent/src/core/hooks-runner.ts +460 -0
  345. package/packages/pi-coding-agent/src/core/index.ts +10 -0
  346. package/packages/pi-coding-agent/src/core/model-discovery.test.ts +19 -0
  347. package/packages/pi-coding-agent/src/core/model-discovery.ts +99 -12
  348. package/packages/pi-coding-agent/src/core/model-registry-auth-header.test.ts +44 -0
  349. package/packages/pi-coding-agent/src/core/model-registry-custom-caps.test.ts +245 -0
  350. package/packages/pi-coding-agent/src/core/model-registry-discovery.test.ts +75 -0
  351. package/packages/pi-coding-agent/src/core/model-registry.ts +102 -10
  352. package/packages/pi-coding-agent/src/core/redact-secrets.test.ts +86 -0
  353. package/packages/pi-coding-agent/src/core/redact-secrets.ts +58 -0
  354. package/packages/pi-coding-agent/src/core/session-manager.test.ts +65 -1
  355. package/packages/pi-coding-agent/src/core/session-manager.ts +10 -6
  356. package/packages/pi-coding-agent/src/core/settings-manager.ts +57 -0
  357. package/packages/pi-coding-agent/src/index.ts +16 -0
  358. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +6 -6
  359. package/packages/pi-coding-agent/src/modes/interactive/components/provider-manager.ts +16 -7
  360. package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +36 -22
  361. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +13 -1
  362. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  363. package/packages/pi-tui/package.json +1 -1
  364. package/packages/rpc-client/package.json +1 -1
  365. package/pkg/package.json +1 -1
  366. package/scripts/link-workspace-packages.cjs +1 -0
  367. package/src/resources/agents/researcher.md +1 -1
  368. package/src/resources/extensions/claude-code-cli/readiness.ts +32 -8
  369. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +78 -17
  370. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +149 -5
  371. package/src/resources/extensions/gsd/auto/loop-deps.ts +14 -0
  372. package/src/resources/extensions/gsd/auto/loop.ts +9 -0
  373. package/src/resources/extensions/gsd/auto/phases.ts +131 -10
  374. package/src/resources/extensions/gsd/auto/run-unit.ts +40 -2
  375. package/src/resources/extensions/gsd/auto/session.ts +35 -2
  376. package/src/resources/extensions/gsd/auto-dispatch.ts +16 -3
  377. package/src/resources/extensions/gsd/auto-model-selection.ts +71 -15
  378. package/src/resources/extensions/gsd/auto-post-unit.ts +29 -3
  379. package/src/resources/extensions/gsd/auto-prompts.ts +28 -1
  380. package/src/resources/extensions/gsd/auto-recovery.ts +26 -1
  381. package/src/resources/extensions/gsd/auto-start.ts +60 -68
  382. package/src/resources/extensions/gsd/auto-verification.ts +33 -0
  383. package/src/resources/extensions/gsd/auto-worktree.ts +62 -63
  384. package/src/resources/extensions/gsd/auto.ts +73 -28
  385. package/src/resources/extensions/gsd/blocked-models.ts +98 -0
  386. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +120 -1
  387. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +40 -9
  388. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +109 -0
  389. package/src/resources/extensions/gsd/bootstrap/memory-tools.ts +5 -0
  390. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +15 -0
  391. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +54 -6
  392. package/src/resources/extensions/gsd/bootstrap/system-context.ts +89 -26
  393. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +35 -2
  394. package/src/resources/extensions/gsd/clean-root-preflight.ts +111 -0
  395. package/src/resources/extensions/gsd/commands-extract-learnings.ts +55 -90
  396. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +898 -32
  397. package/src/resources/extensions/gsd/compaction-snapshot.ts +165 -0
  398. package/src/resources/extensions/gsd/complexity-classifier.ts +5 -3
  399. package/src/resources/extensions/gsd/db-writer.ts +88 -17
  400. package/src/resources/extensions/gsd/doctor-git-checks.ts +23 -27
  401. package/src/resources/extensions/gsd/doctor-providers.ts +59 -6
  402. package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +2 -0
  403. package/src/resources/extensions/gsd/error-classifier.ts +36 -3
  404. package/src/resources/extensions/gsd/exec-history.ts +153 -0
  405. package/src/resources/extensions/gsd/exec-sandbox.ts +326 -0
  406. package/src/resources/extensions/gsd/gitignore.ts +1 -1
  407. package/src/resources/extensions/gsd/gsd-db.ts +186 -23
  408. package/src/resources/extensions/gsd/guided-flow.ts +222 -1
  409. package/src/resources/extensions/gsd/health-widget.ts +3 -1
  410. package/src/resources/extensions/gsd/hook-emitter.ts +188 -0
  411. package/src/resources/extensions/gsd/init-wizard.ts +15 -1
  412. package/src/resources/extensions/gsd/journal.ts +2 -1
  413. package/src/resources/extensions/gsd/key-manager.ts +28 -0
  414. package/src/resources/extensions/gsd/memory-backfill.ts +140 -0
  415. package/src/resources/extensions/gsd/memory-store.ts +26 -0
  416. package/src/resources/extensions/gsd/model-router.ts +42 -1
  417. package/src/resources/extensions/gsd/pre-execution-checks.ts +46 -10
  418. package/src/resources/extensions/gsd/preferences-types.ts +46 -0
  419. package/src/resources/extensions/gsd/preferences-validation.ts +79 -0
  420. package/src/resources/extensions/gsd/preferences.ts +17 -17
  421. package/src/resources/extensions/gsd/prompt-loader.ts +30 -7
  422. package/src/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  423. package/src/resources/extensions/gsd/prompts/complete-slice.md +2 -2
  424. package/src/resources/extensions/gsd/prompts/debug-diagnose.md +2 -0
  425. package/src/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  426. package/src/resources/extensions/gsd/prompts/discuss.md +29 -2
  427. package/src/resources/extensions/gsd/prompts/execute-task.md +3 -2
  428. package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  429. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -0
  430. package/src/resources/extensions/gsd/prompts/research-slice.md +1 -0
  431. package/src/resources/extensions/gsd/safety/evidence-collector.ts +119 -0
  432. package/src/resources/extensions/gsd/safety/file-change-validator.ts +17 -4
  433. package/src/resources/extensions/gsd/safety/safety-harness.ts +9 -0
  434. package/src/resources/extensions/gsd/state.ts +45 -4
  435. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +188 -2
  436. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +95 -1
  437. package/src/resources/extensions/gsd/tests/auto-paused-session-validation.test.ts +12 -0
  438. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +49 -0
  439. package/src/resources/extensions/gsd/tests/auto-start-bootstrap-await-3420.test.ts +141 -0
  440. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +33 -3
  441. package/src/resources/extensions/gsd/tests/auto-thinking-restore.test.ts +38 -0
  442. package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +23 -0
  443. package/src/resources/extensions/gsd/tests/blocked-models.test.ts +98 -0
  444. package/src/resources/extensions/gsd/tests/bundled-skill-triggers.test.ts +54 -0
  445. package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +186 -0
  446. package/src/resources/extensions/gsd/tests/commands-extract-learnings.test.ts +68 -66
  447. package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +123 -0
  448. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +61 -1
  449. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  450. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  451. package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +3 -3
  452. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +2 -0
  453. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +42 -0
  454. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +8 -4
  455. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +148 -3
  456. package/src/resources/extensions/gsd/tests/double-merge-guard.test.ts +1 -1
  457. package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +306 -1
  458. package/src/resources/extensions/gsd/tests/escalation.test.ts +1 -1
  459. package/src/resources/extensions/gsd/tests/exec-history.test.ts +237 -0
  460. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +210 -0
  461. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +58 -0
  462. package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +40 -9
  463. package/src/resources/extensions/gsd/tests/freeform-decisions.test.ts +62 -0
  464. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +447 -1
  465. package/src/resources/extensions/gsd/tests/init-wizard.test.ts +27 -0
  466. package/src/resources/extensions/gsd/tests/integration/doctor-git-symlink-cwd.test.ts +11 -0
  467. package/src/resources/extensions/gsd/tests/integration/doctor-git.test.ts +78 -0
  468. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +1 -0
  469. package/src/resources/extensions/gsd/tests/integration/gitignore-tracked-gsd.test.ts +1 -0
  470. package/src/resources/extensions/gsd/tests/integration/idle-recovery.test.ts +30 -0
  471. package/src/resources/extensions/gsd/tests/interactive-routing-bypass.test.ts +1 -1
  472. package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +1 -1
  473. package/src/resources/extensions/gsd/tests/issue-4540-regressions.test.ts +288 -0
  474. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +37 -0
  475. package/src/resources/extensions/gsd/tests/key-manager.test.ts +9 -0
  476. package/src/resources/extensions/gsd/tests/load-memory-block.test.ts +36 -0
  477. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -1
  478. package/src/resources/extensions/gsd/tests/memory-pressure-stuck-state.test.ts +12 -0
  479. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -2
  480. package/src/resources/extensions/gsd/tests/parallel-research-dispatch.test.ts +19 -0
  481. package/src/resources/extensions/gsd/tests/plan-gate-failed-doctor-heal-hint.test.ts +37 -0
  482. package/src/resources/extensions/gsd/tests/pre-exec-backtick-strip.test.ts +14 -0
  483. package/src/resources/extensions/gsd/tests/pre-exec-gate-loop.test.ts +272 -0
  484. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +356 -0
  485. package/src/resources/extensions/gsd/tests/preferences.test.ts +110 -0
  486. package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +44 -0
  487. package/src/resources/extensions/gsd/tests/prompt-loader-extension-dir.test.ts +49 -0
  488. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +103 -4
  489. package/src/resources/extensions/gsd/tests/ready-phrase-no-files-4573.test.ts +388 -0
  490. package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +9 -3
  491. package/src/resources/extensions/gsd/tests/resume-dispatch-worktree.test.ts +230 -0
  492. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +205 -0
  493. package/src/resources/extensions/gsd/tests/save-gate-result-render.test.ts +95 -0
  494. package/src/resources/extensions/gsd/tests/schema-v21-sequence.test.ts +413 -0
  495. package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +32 -40
  496. package/src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts +56 -0
  497. package/src/resources/extensions/gsd/tests/token-counter.test.ts +105 -1
  498. package/src/resources/extensions/gsd/tests/tool-compatibility.test.ts +107 -0
  499. package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +23 -0
  500. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +9 -3
  501. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +65 -2
  502. package/src/resources/extensions/gsd/tests/worktree-db.test.ts +35 -0
  503. package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +6 -1
  504. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +78 -5
  505. package/src/resources/extensions/gsd/tests/write-gate.test.ts +64 -0
  506. package/src/resources/extensions/gsd/tests/zombie-gsd-state.test.ts +3 -1
  507. package/src/resources/extensions/gsd/token-counter.ts +22 -5
  508. package/src/resources/extensions/gsd/tools/complete-milestone.ts +15 -9
  509. package/src/resources/extensions/gsd/tools/exec-search-tool.ts +81 -0
  510. package/src/resources/extensions/gsd/tools/exec-tool.ts +183 -0
  511. package/src/resources/extensions/gsd/tools/memory-tools.ts +31 -1
  512. package/src/resources/extensions/gsd/tools/resume-tool.ts +40 -0
  513. package/src/resources/extensions/gsd/uok/plan-v2.ts +26 -3
  514. package/src/resources/extensions/gsd/workflow-logger.ts +4 -1
  515. package/src/resources/extensions/gsd/workflow-mcp.ts +3 -0
  516. package/src/resources/extensions/gsd/workflow-templates/spike.md +6 -0
  517. package/src/resources/extensions/gsd/worktree-resolver.ts +54 -9
  518. package/src/resources/extensions/search-the-web/command-search-provider.ts +5 -4
  519. package/src/resources/extensions/search-the-web/native-search.ts +48 -12
  520. package/src/resources/skills/api-design/SKILL.md +190 -0
  521. package/src/resources/skills/create-mcp-server/SKILL.md +121 -0
  522. package/src/resources/skills/decompose-into-slices/SKILL.md +139 -0
  523. package/src/resources/skills/dependency-upgrade/SKILL.md +158 -0
  524. package/src/resources/skills/design-an-interface/SKILL.md +102 -0
  525. package/src/resources/skills/forensics/SKILL.md +153 -0
  526. package/src/resources/skills/grill-me/SKILL.md +93 -0
  527. package/src/resources/skills/handoff/SKILL.md +121 -0
  528. package/src/resources/skills/observability/SKILL.md +174 -0
  529. package/src/resources/skills/security-review/SKILL.md +181 -0
  530. package/src/resources/skills/spike-wrap-up/SKILL.md +138 -0
  531. package/src/resources/skills/tdd/SKILL.md +112 -0
  532. package/src/resources/skills/verify-before-complete/SKILL.md +98 -0
  533. package/src/resources/skills/write-docs/SKILL.md +82 -0
  534. package/src/resources/skills/write-milestone-brief/SKILL.md +135 -0
  535. /package/dist/web/standalone/.next/static/{ssX7BLv3Dw9Fb4CtrCGeR → pV-mPo7rYGb5JBC09C8GG}/_buildManifest.js +0 -0
  536. /package/dist/web/standalone/.next/static/{ssX7BLv3Dw9Fb4CtrCGeR → pV-mPo7rYGb5JBC09C8GG}/_ssgManifest.js +0 -0
@@ -68,8 +68,13 @@ export function extractPackageReferences(description) {
68
68
  }
69
69
  }
70
70
  }
71
- // require('pkg') or import from 'pkg' in code blocks
72
- const importPattern = /(?:require\s*\(\s*['"]|from\s+['"])([a-zA-Z0-9@/_-]+)['"\)]/g;
71
+ // require('pkg') or `import ... from 'pkg'` in code blocks.
72
+ // The `from\s+['"]` branch MUST be preceded by an `import` keyword so that
73
+ // natural-language prose like `from "What's Next"` or `from 'master'` does
74
+ // not produce false package-existence failures. Requiring the leading import
75
+ // keyword anchors the match to JavaScript/TypeScript syntax.
76
+ // See: https://github.com/gsd-build/gsd-2/issues/4388
77
+ const importPattern = /(?:require\s*\(\s*['"]|import\b[\s\S]*?\bfrom\s+['"])([a-zA-Z0-9@/_-]+)['"\)]/g;
73
78
  let importMatch;
74
79
  while ((importMatch = importPattern.exec(description)) !== null) {
75
80
  // Skip relative imports and node builtins
@@ -276,9 +281,23 @@ function extractPathFromAnnotation(raw) {
276
281
  if (backtickMatch) {
277
282
  return backtickMatch[2].trim();
278
283
  }
284
+ // Strip leading/trailing double or single quotes wrapping the whole value.
285
+ // Plan documents sometimes emit `"src/foo.ts"` or `'src/bar.ts'` as input
286
+ // annotations. Stripping the wrapper allows the inner path to be checked
287
+ // correctly instead of producing a false-positive "file not found" error
288
+ // for a literal string with quote characters in it (#3747).
289
+ const quoteMatch = trimmed.match(/^(["'])([^"']+)\1$/);
290
+ if (quoteMatch) {
291
+ return quoteMatch[2].trim();
292
+ }
279
293
  const annotatedMatch = trimmed.match(/^(.+?)\s+[—–-]\s+.+$/);
280
294
  if (annotatedMatch) {
281
- return annotatedMatch[1].trim();
295
+ const prefix = annotatedMatch[1].trim();
296
+ const prefixBacktickMatch = prefix.match(/`([^`]+)`/);
297
+ if (prefixBacktickMatch && looksLikePathOrUrl(prefixBacktickMatch[1].trim())) {
298
+ return prefixBacktickMatch[1].trim();
299
+ }
300
+ return prefix.replace(/`/g, "").trim();
282
301
  }
283
302
  // Fallback: scan all backticked tokens and return the first one that looks
284
303
  // like a path or URL. Handles prose-annotated bullets such as:
@@ -333,13 +352,19 @@ function containsGlobPattern(candidate) {
333
352
  }
334
353
  /**
335
354
  * Build a set of files that will be created by tasks up to (but not including) taskIndex.
355
+ * Also includes outputs of completed tasks at any position — a completed task has already
356
+ * run and its outputs are available regardless of sequence position or disk state (#4071).
336
357
  * All paths are normalized for consistent comparison.
337
358
  */
338
359
  function getExpectedOutputsUpTo(tasks, taskIndex) {
339
360
  const outputs = new Set();
340
- for (let i = 0; i < taskIndex; i++) {
341
- for (const file of tasks[i].expected_output) {
342
- outputs.add(normalizeFilePath(file));
361
+ for (let i = 0; i < tasks.length; i++) {
362
+ const task = tasks[i];
363
+ // Include prior tasks (i < taskIndex) OR completed tasks at any position
364
+ if (i < taskIndex || task.status === "completed") {
365
+ for (const file of task.expected_output) {
366
+ outputs.add(normalizeFilePath(file));
367
+ }
343
368
  }
344
369
  }
345
370
  return outputs;
@@ -416,8 +441,14 @@ export function checkTaskOrdering(tasks, basePath) {
416
441
  const task = tasks[i];
417
442
  for (const file of task.expected_output) {
418
443
  const normalizedFile = normalizeFilePath(file);
419
- if (!fileCreators.has(normalizedFile)) {
420
- fileCreators.set(normalizedFile, { taskId: task.id, index: i, originalPath: file });
444
+ const existing = fileCreators.get(normalizedFile);
445
+ if (!existing || (!existing.completed && task.status === "completed")) {
446
+ fileCreators.set(normalizedFile, {
447
+ taskId: task.id,
448
+ index: i,
449
+ originalPath: file,
450
+ completed: task.status === "completed",
451
+ });
421
452
  }
422
453
  }
423
454
  }
@@ -441,7 +472,11 @@ export function checkTaskOrdering(tasks, basePath) {
441
472
  const creator = fileCreators.get(normalizedFile);
442
473
  const absolutePath = resolve(basePath, normalizedFile);
443
474
  const existsOnDisk = existsSync(absolutePath);
444
- if (creator && creator.index > i && !existsOnDisk) {
475
+ // Skip if the creating task has already completed its output is available
476
+ // regardless of disk state (e.g. file was a temp artifact cleaned up after
477
+ // the task ran, or a replan introduced a new earlier-sequence task that
478
+ // reads this pre-execution output). (#4071)
479
+ if (creator && creator.index > i && !existsOnDisk && !creator.completed) {
445
480
  // Task reads file that is created later — impossible ordering
446
481
  results.push({
447
482
  category: "file",
@@ -5,6 +5,14 @@
5
5
  * both the validation and runtime modules can import them without pulling
6
6
  * in filesystem or loading logic.
7
7
  */
8
+ /**
9
+ * Resolve whether context-mode features (gsd_exec sandbox + compaction
10
+ * snapshot) should be active. Default is ON: missing config or missing
11
+ * `enabled` is treated as true. Only `enabled: false` disables.
12
+ */
13
+ export function isContextModeEnabled(prefs) {
14
+ return prefs?.context_mode?.enabled !== false;
15
+ }
8
16
  /** Default preference values for each workflow mode. */
9
17
  export const MODE_DEFAULTS = {
10
18
  solo: {
@@ -87,6 +95,7 @@ export const KNOWN_PREFERENCE_KEYS = new Set([
87
95
  "flat_rate_providers",
88
96
  "language",
89
97
  "context_window_override",
98
+ "context_mode",
90
99
  ]);
91
100
  /** Canonical list of all dispatch unit types. */
92
101
  export const KNOWN_UNIT_TYPES = [
@@ -660,6 +660,55 @@ export function validatePreferences(preferences) {
660
660
  errors.push("context_management must be an object");
661
661
  }
662
662
  }
663
+ // ─── Context Mode (gsd_exec sandbox) ────────────────────────────────────
664
+ if (preferences.context_mode !== undefined) {
665
+ if (typeof preferences.context_mode === "object" && preferences.context_mode !== null) {
666
+ const cmode = preferences.context_mode;
667
+ const validCmode = {};
668
+ if (cmode.enabled !== undefined) {
669
+ if (typeof cmode.enabled === "boolean")
670
+ validCmode.enabled = cmode.enabled;
671
+ else
672
+ errors.push("context_mode.enabled must be a boolean");
673
+ }
674
+ if (cmode.exec_timeout_ms !== undefined) {
675
+ const t = cmode.exec_timeout_ms;
676
+ if (typeof t === "number" && t >= 1000 && t <= 600_000)
677
+ validCmode.exec_timeout_ms = Math.floor(t);
678
+ else
679
+ errors.push("context_mode.exec_timeout_ms must be a number between 1000 and 600000");
680
+ }
681
+ if (cmode.exec_stdout_cap_bytes !== undefined) {
682
+ const b = cmode.exec_stdout_cap_bytes;
683
+ if (typeof b === "number" && b >= 4096 && b <= 16_777_216)
684
+ validCmode.exec_stdout_cap_bytes = Math.floor(b);
685
+ else
686
+ errors.push("context_mode.exec_stdout_cap_bytes must be a number between 4096 and 16777216");
687
+ }
688
+ if (cmode.exec_digest_chars !== undefined) {
689
+ const c = cmode.exec_digest_chars;
690
+ if (typeof c === "number" && c >= 0 && c <= 4000)
691
+ validCmode.exec_digest_chars = Math.floor(c);
692
+ else
693
+ errors.push("context_mode.exec_digest_chars must be a number between 0 and 4000");
694
+ }
695
+ if (cmode.exec_env_allowlist !== undefined) {
696
+ if (Array.isArray(cmode.exec_env_allowlist) &&
697
+ cmode.exec_env_allowlist.every((v) => typeof v === "string" && /^[A-Z_][A-Z0-9_]*$/i.test(v))) {
698
+ validCmode.exec_env_allowlist = cmode.exec_env_allowlist;
699
+ }
700
+ else {
701
+ errors.push("context_mode.exec_env_allowlist must be an array of valid env var names");
702
+ }
703
+ }
704
+ if (Object.keys(validCmode).length > 0) {
705
+ validated.context_mode = validCmode;
706
+ }
707
+ }
708
+ else {
709
+ errors.push("context_mode must be an object");
710
+ }
711
+ }
663
712
  // ─── Parallel Config ────────────────────────────────────────────────────
664
713
  if (preferences.parallel && typeof preferences.parallel === "object") {
665
714
  const p = preferences.parallel;
@@ -716,6 +765,40 @@ export function validatePreferences(preferences) {
716
765
  validated.parallel = parallel;
717
766
  }
718
767
  }
768
+ // ─── Slice Parallel Config ───────────────────────────────────────────────
769
+ if (preferences.slice_parallel !== undefined) {
770
+ if (typeof preferences.slice_parallel === "object" && preferences.slice_parallel !== null) {
771
+ const sp = preferences.slice_parallel;
772
+ const validSp = {};
773
+ if (sp.enabled !== undefined) {
774
+ if (typeof sp.enabled === "boolean")
775
+ validSp.enabled = sp.enabled;
776
+ else
777
+ errors.push("slice_parallel.enabled must be a boolean");
778
+ }
779
+ if (sp.max_workers !== undefined) {
780
+ const maxWorkers = typeof sp.max_workers === "number" ? sp.max_workers : Number(sp.max_workers);
781
+ if (Number.isFinite(maxWorkers) && maxWorkers >= 1 && maxWorkers <= 8) {
782
+ validSp.max_workers = Math.floor(maxWorkers);
783
+ }
784
+ else {
785
+ errors.push("slice_parallel.max_workers must be a number between 1 and 8");
786
+ }
787
+ }
788
+ const knownSliceParallelKeys = new Set(["enabled", "max_workers"]);
789
+ for (const key of Object.keys(sp)) {
790
+ if (!knownSliceParallelKeys.has(key)) {
791
+ warnings.push(`unknown slice_parallel key "${key}" — ignored`);
792
+ }
793
+ }
794
+ if (Object.keys(validSp).length > 0) {
795
+ validated.slice_parallel = validSp;
796
+ }
797
+ }
798
+ else {
799
+ errors.push("slice_parallel must be an object");
800
+ }
801
+ }
719
802
  // ─── Reactive Execution ─────────────────────────────────────────────────
720
803
  if (preferences.reactive_execution !== undefined) {
721
804
  if (typeof preferences.reactive_execution === "object" && preferences.reactive_execution !== null) {
@@ -26,12 +26,12 @@ export { resolveAllSkillReferences } from "./preferences-skills.js";
26
26
  // These lived in preferences-skills.ts but imported loadEffectiveGSDPreferences
27
27
  // back from this file, creating a circular dependency. Moved here since they
28
28
  // are trivial wrappers over loadEffectiveGSDPreferences.
29
- export function resolveSkillDiscoveryMode() {
30
- const prefs = loadEffectiveGSDPreferences();
29
+ export function resolveSkillDiscoveryMode(basePath) {
30
+ const prefs = loadEffectiveGSDPreferences(basePath);
31
31
  return prefs?.preferences.skill_discovery ?? "suggest";
32
32
  }
33
- export function resolveSkillStalenessDays() {
34
- const prefs = loadEffectiveGSDPreferences();
33
+ export function resolveSkillStalenessDays(basePath) {
34
+ const prefs = loadEffectiveGSDPreferences(basePath);
35
35
  return prefs?.preferences.skill_staleness_days ?? 60;
36
36
  }
37
37
  // ─── Re-exports: models ─────────────────────────────────────────────────────
@@ -46,16 +46,16 @@ function globalPreferencesPath() {
46
46
  function legacyGlobalPreferencesPath() {
47
47
  return join(homedir(), ".pi", "agent", "gsd-preferences.md");
48
48
  }
49
- function projectPreferencesPath() {
50
- return join(gsdRoot(process.cwd()), "PREFERENCES.md");
49
+ function projectPreferencesPath(basePath = process.cwd()) {
50
+ return join(gsdRoot(basePath), "PREFERENCES.md");
51
51
  }
52
52
  // Legacy lowercase files can still exist in older projects. Keep them as a
53
53
  // compatibility-only fallback, but route new reads/writes through PREFERENCES.md.
54
54
  function legacyGlobalPreferencesPathLowercase() {
55
55
  return join(gsdHome(), "preferences.md");
56
56
  }
57
- function legacyProjectPreferencesPathLowercase() {
58
- return join(gsdRoot(process.cwd()), "preferences.md");
57
+ function legacyProjectPreferencesPathLowercase(basePath = process.cwd()) {
58
+ return join(gsdRoot(basePath), "preferences.md");
59
59
  }
60
60
  export function getGlobalGSDPreferencesPath() {
61
61
  return globalPreferencesPath();
@@ -63,8 +63,8 @@ export function getGlobalGSDPreferencesPath() {
63
63
  export function getLegacyGlobalGSDPreferencesPath() {
64
64
  return legacyGlobalPreferencesPath();
65
65
  }
66
- export function getProjectGSDPreferencesPath() {
67
- return projectPreferencesPath();
66
+ export function getProjectGSDPreferencesPath(basePath) {
67
+ return projectPreferencesPath(basePath);
68
68
  }
69
69
  // ─── Loading ────────────────────────────────────────────────────────────────
70
70
  export function loadGlobalGSDPreferences() {
@@ -72,13 +72,13 @@ export function loadGlobalGSDPreferences() {
72
72
  ?? loadPreferencesFile(legacyGlobalPreferencesPathLowercase(), "global")
73
73
  ?? loadPreferencesFile(legacyGlobalPreferencesPath(), "global");
74
74
  }
75
- export function loadProjectGSDPreferences() {
76
- return loadPreferencesFile(projectPreferencesPath(), "project")
77
- ?? loadPreferencesFile(legacyProjectPreferencesPathLowercase(), "project");
75
+ export function loadProjectGSDPreferences(basePath) {
76
+ return loadPreferencesFile(projectPreferencesPath(basePath), "project")
77
+ ?? loadPreferencesFile(legacyProjectPreferencesPathLowercase(basePath), "project");
78
78
  }
79
- export function loadEffectiveGSDPreferences() {
79
+ export function loadEffectiveGSDPreferences(basePath) {
80
80
  const globalPreferences = loadGlobalGSDPreferences();
81
- const projectPreferences = loadProjectGSDPreferences();
81
+ const projectPreferences = loadProjectGSDPreferences(basePath);
82
82
  if (!globalPreferences && !projectPreferences)
83
83
  return null;
84
84
  let result;
@@ -489,8 +489,8 @@ export function resolvePreDispatchHooks() {
489
489
  * Worktree isolation requires explicit opt-in because it depends on git
490
490
  * branch infrastructure that must be set up before use.
491
491
  */
492
- export function getIsolationMode() {
493
- const prefs = loadEffectiveGSDPreferences()?.preferences?.git;
492
+ export function getIsolationMode(basePath) {
493
+ const prefs = loadEffectiveGSDPreferences(basePath)?.preferences?.git;
494
494
  if (prefs?.isolation === "worktree")
495
495
  return "worktree";
496
496
  if (prefs?.isolation === "branch")
@@ -22,6 +22,27 @@ import { join, dirname } from "node:path";
22
22
  import { fileURLToPath } from "node:url";
23
23
  import { homedir } from "node:os";
24
24
  import { logWarning } from "./workflow-logger.js";
25
+ function hasRequiredExtensionAssets(rootDir, exists = existsSync) {
26
+ return (exists(join(rootDir, "prompts")) &&
27
+ exists(join(rootDir, "templates", "task-summary.md")));
28
+ }
29
+ export function resolveExtensionDirFromCandidates(moduleDir, agentGsdDir, exists = existsSync) {
30
+ const moduleUsable = hasRequiredExtensionAssets(moduleDir, exists);
31
+ const agentUsable = hasRequiredExtensionAssets(agentGsdDir, exists);
32
+ // Prefer the user-local extension tree when both are valid. This avoids
33
+ // leaking npm/global-install paths into prompts on Windows.
34
+ if (agentUsable)
35
+ return agentGsdDir;
36
+ if (moduleUsable)
37
+ return moduleDir;
38
+ // Degraded fallback: if required template is missing in both locations,
39
+ // keep previous behavior and prefer whichever still has prompts/.
40
+ if (exists(join(moduleDir, "prompts")))
41
+ return moduleDir;
42
+ if (exists(join(agentGsdDir, "prompts")))
43
+ return agentGsdDir;
44
+ return moduleDir;
45
+ }
25
46
  /**
26
47
  * Resolve the GSD extension directory.
27
48
  *
@@ -34,15 +55,9 @@ import { logWarning } from "./workflow-logger.js";
34
55
  */
35
56
  function resolveExtensionDir() {
36
57
  const moduleDir = dirname(fileURLToPath(import.meta.url));
37
- if (existsSync(join(moduleDir, "prompts")))
38
- return moduleDir;
39
- // Fallback: user-local agent directory
40
58
  const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
41
59
  const agentGsdDir = join(gsdHome, "agent", "extensions", "gsd");
42
- if (existsSync(join(agentGsdDir, "prompts")))
43
- return agentGsdDir;
44
- // Last resort: return the module dir (warmCache will silently handle the miss)
45
- return moduleDir;
60
+ return resolveExtensionDirFromCandidates(moduleDir, agentGsdDir);
46
61
  }
47
62
  const __extensionDir = resolveExtensionDir();
48
63
  const promptsDir = join(__extensionDir, "prompts");
@@ -59,7 +59,7 @@ Then:
59
59
  - `followUps` (string) — Follow-up items for future milestones
60
60
  - `deviations` (string) — Deviations from the original plan
61
61
  11. Update `.gsd/PROJECT.md`: use the `write` tool with `path: ".gsd/PROJECT.md"` and `content` containing the full updated document reflecting milestone completion and current project state. Do NOT use the `edit` tool for this — PROJECT.md is a full-document refresh.
62
- 12. Extract structured learnings from this milestone and persist them to the cross-session knowledge surfaces. Follow the procedure block immediately below — it writes `{{milestoneId}}-LEARNINGS.md`, appends Patterns and Lessons to `.gsd/KNOWLEDGE.md`, and persists Decisions via the `gsd_save_decision` MCP tool.
62
+ 12. Extract structured learnings from this milestone and persist them to the GSD memory store. Follow the procedure block immediately below — it writes `{{milestoneId}}-LEARNINGS.md` as the audit trail and persists Patterns, Lessons, and Decisions via `capture_thought` (categories: pattern, gotcha/convention, architecture). The memory store is the single source of truth for cross-session durable knowledge (ADR-013).
63
63
 
64
64
  {{extractLearningsSteps}}
65
65
 
@@ -29,8 +29,8 @@ Then:
29
29
  6. If this slice produced evidence that a requirement changed status (Active → Validated, Active → Deferred, etc.), call `gsd_requirement_update` with the requirement ID, updated `status`, and `validation` evidence. Do NOT write `.gsd/REQUIREMENTS.md` directly — the engine renders it from the database.
30
30
  7. Prepare the slice completion content you will pass to `gsd_complete_slice` using the camelCase fields `milestoneId`, `sliceId`, `sliceTitle`, `oneLiner`, `narrative`, `verification`, and `uatContent`. Do **not** manually write `{{sliceSummaryPath}}`. Do **not** manually write `{{sliceUatPath}}` — the DB-backed tool is the canonical write path for both artifacts.
31
31
  8. Draft the UAT content you will pass as `uatContent` — a concrete UAT script with real test cases derived from the slice plan and task summaries. Include preconditions, numbered steps with expected outcomes, and edge cases. This must NOT be a placeholder or generic template — tailor every test case to what this slice actually built.
32
- 9. Review task summaries for `key_decisions`. Append any significant decisions to `.gsd/DECISIONS.md` if missing.
33
- 10. Review task summaries for patterns, gotchas, or non-obvious lessons learned. If any would save future agents from repeating investigation or hitting the same issues, append them to `.gsd/KNOWLEDGE.md`. Only add entries that are genuinely useful don't pad with obvious observations.
32
+ 9. Review task summaries for `key_decisions`. For each significant decision, call `capture_thought` with `category: "architecture"` (or `"pattern"`) and a `structuredFields` payload of `{ scope, decision, choice, rationale, made_by: "agent", revisable }`.
33
+ 10. Review task summaries for patterns, gotchas, or non-obvious lessons learned. For each one that would save future agents from repeating investigation, call `capture_thought` with the matching category (`gotcha`, `convention`, `pattern`, `environment`). The memory store is the single source of truth (ADR-013); do not append to `.gsd/DECISIONS.md` or `.gsd/KNOWLEDGE.md` directly.
34
34
  11. Call `gsd_complete_slice` with the camelCase fields `milestoneId`, `sliceId`, `sliceTitle`, `oneLiner`, `narrative`, `verification`, and `uatContent`, plus any optional enrichment fields you have. Do NOT manually mark the roadmap checkbox — the tool writes to the DB, renders `{{sliceSummaryPath}}` and `{{sliceUatPath}}`, and updates the ROADMAP.md projection automatically.
35
35
  12. Do not run git commands — the system commits your changes and handles any merge after this unit succeeds.
36
36
  13. Update `.gsd/PROJECT.md` if it exists — refresh current state if needed: use the `write` tool with `path: ".gsd/PROJECT.md"` and `content` containing the full updated document reflecting current project state. Do NOT use the `edit` tool for this — PROJECT.md is a full-document refresh.
@@ -18,8 +18,10 @@ Goal semantics:
18
18
  ## Instructions
19
19
 
20
20
  1. Read `.gsd/debug/sessions/{{slug}}.json` for any prior session context.
21
+ 1a. Call `memory_query` with keywords from the issue (error text, subsystem, file paths). A prior session may have captured this exact gotcha — finding it now saves the investigation.
21
22
  2. Investigate the reported issue in `{{workingDirectory}}`.
22
23
  3. Follow the goal constraint above strictly.
23
24
  4. When complete, surface a clear summary: what failed, why, and what was done (or what a fix would require for root-cause-only mode).
25
+ 5. Once root cause is identified, call `capture_thought` with `category: "gotcha"` so future debug sessions can find it via `memory_query`. Keep the content to 1–3 sentences — the symptom, the root cause, and the fix or guard.
24
26
 
25
27
  {{skillActivation}}
@@ -162,6 +162,10 @@ Preserve the specification's exact terminology, emphasis, and specific framing.
162
162
  6. For each architectural or pattern decision, call `gsd_decision_save` — the tool auto-assigns IDs and regenerates `.gsd/DECISIONS.md` automatically.
163
163
  7. {{commitInstruction}}
164
164
 
165
+ ### Ready-phrase pre-condition (NON-BYPASSABLE)
166
+
167
+ Before emitting the ready phrase, verify in the CURRENT turn that you have written `.gsd/PROJECT.md`, `.gsd/REQUIREMENTS.md`, `{{contextPath}}`, and called `gsd_plan_milestone`. If any is missing, **STOP** — emit the missing tool calls in this same turn. The system rejects premature ready signals and retries are capped.
168
+
165
169
  After writing the files, say exactly: "Milestone {{milestoneId}} ready." — nothing else. Auto-mode will start automatically.
166
170
 
167
171
  ### Multi-Milestone
@@ -234,6 +238,10 @@ For single-milestone projects, do NOT write this file.
234
238
 
235
239
  7. {{multiMilestoneCommitInstruction}}
236
240
 
241
+ ### Ready-phrase pre-condition (NON-BYPASSABLE)
242
+
243
+ Before emitting the ready phrase, verify in the CURRENT turn that you have written `.gsd/PROJECT.md`, `.gsd/REQUIREMENTS.md`, the primary `CONTEXT.md`, called `gsd_plan_milestone` for the primary milestone, and written `.gsd/DISCUSSION-MANIFEST.json` with `gates_completed === total`. If any is missing, **STOP** — emit the missing tool calls in this same turn. The system rejects premature ready signals and retries are capped.
244
+
237
245
  After writing the files, say exactly: "Milestone {{milestoneId}} ready." — nothing else. Auto-mode will start automatically.
238
246
 
239
247
  ## Critical Rules
@@ -339,7 +339,20 @@ These sections are in addition to whatever other context the discussion surfaced
339
339
  6. For each architectural or pattern decision made during discussion, call `gsd_decision_save` — the tool auto-assigns IDs and regenerates `.gsd/DECISIONS.md` automatically.
340
340
  7. {{commitInstruction}}
341
341
 
342
- After writing the files, say exactly: "Milestone {{milestoneId}} ready." — nothing else. Auto-mode will start automatically.
342
+ ### Ready-phrase pre-condition (NON-BYPASSABLE)
343
+
344
+ Before emitting the ready phrase, verify in the CURRENT turn that you have:
345
+
346
+ - [ ] Written `.gsd/PROJECT.md` (step 2)
347
+ - [ ] Written `.gsd/REQUIREMENTS.md` (step 3)
348
+ - [ ] Written `{{contextPath}}` (step 4)
349
+ - [ ] Called `gsd_plan_milestone` (step 5)
350
+
351
+ If ANY box is unchecked, **STOP**. Do NOT emit the ready phrase. Emit the missing tool calls in this same turn. The system detects missing artifacts and will reject premature ready signals — you will be asked again and retries are capped.
352
+
353
+ Do not announce the ready phrase as something you are "about to" do. Do not narrate "now writing the files" as a substitute for actually writing them. The ready phrase is a post-write signal, not an intent signal.
354
+
355
+ After completing steps 1–7 above, say exactly: "Milestone {{milestoneId}} ready." — nothing else. Auto-mode will start automatically.
343
356
 
344
357
  ### Multi-Milestone
345
358
 
@@ -418,6 +431,20 @@ For single-milestone projects, do NOT write this file — it is only for multi-m
418
431
 
419
432
  7. {{multiMilestoneCommitInstruction}}
420
433
 
421
- After writing the files, say exactly: "Milestone M001 ready." — nothing else. Auto-mode will start automatically.
434
+ ### Ready-phrase pre-condition (NON-BYPASSABLE)
435
+
436
+ Before emitting the ready phrase, verify in the CURRENT turn that you have:
437
+
438
+ - [ ] Written `.gsd/PROJECT.md` (Phase 1)
439
+ - [ ] Written `.gsd/REQUIREMENTS.md` (Phase 1)
440
+ - [ ] Written primary-milestone `CONTEXT.md` (Phase 2)
441
+ - [ ] Called `gsd_plan_milestone` for the primary milestone (Phase 2)
442
+ - [ ] Written `.gsd/DISCUSSION-MANIFEST.json` with `gates_completed === total` (Phase 3)
443
+
444
+ If ANY box is unchecked, **STOP**. Do NOT emit the ready phrase. Emit the missing tool calls in this same turn. The system detects missing artifacts and will reject premature ready signals — you will be asked again and retries are capped.
445
+
446
+ Do not announce the ready phrase as something you are "about to" do. Do not narrate "now writing the files" as a substitute for actually writing them. The ready phrase is a post-write signal, not an intent signal.
447
+
448
+ After completing all phases above, say exactly: "Milestone M001 ready." — nothing else. Auto-mode will start automatically.
422
449
 
423
450
  {{inlinedTemplates}}
@@ -32,6 +32,7 @@ A researcher explored the codebase and a planner decomposed the work — you are
32
32
 
33
33
  Then:
34
34
  0. Narrate step transitions, key implementation decisions, and verification outcomes as you work. Keep it terse — one line between tool-call clusters, not between every call — but write complete sentences in user-facing prose, not shorthand notes or scratchpad fragments.
35
+ 0a. Call `memory_query` with 2-4 keywords drawn from the task title and the files it touches. Surface any prior gotchas, conventions, or architectural decisions before you start changing code. Skip only if the task is trivially mechanical.
35
36
  1. {{skillActivation}} Follow any activated skills before writing code. If no skills match this task, skip this step.
36
37
  2. Execute the steps in the inlined task plan, adapting minor local mismatches when the surrounding code differs from the planner's snapshot
37
38
  3. Before any `Write` that creates an artifact or output file, check whether that path already exists. If it does, read it first and decide whether the work is already done, should be extended, or truly needs replacement. "Create" in the plan does **not** mean the file is missing — a prior session may already have started it.
@@ -81,8 +82,8 @@ Then:
81
82
  **Scope:** Escalation is instrumented only in `execute-task`. Refine-slice escalation is deferred. Reactive-execute batches run to completion before escalations are surfaced — the dispatch pause happens on the next loop iteration, not mid-batch.
82
83
 
83
84
  The `escalation` payload is ignored unless `phases.mid_execution_escalation` is enabled; populate it anyway for audit logs.
84
- 17. If you made an architectural, pattern, library, or observability decision during this task that downstream work should know about, append it to `.gsd/DECISIONS.md` (read the template at `~/.gsd/agent/extensions/gsd/templates/decisions.md` if the file doesn't exist yet). Not every task produces decisions — only append when a meaningful choice was made.
85
- 18. If you discover a non-obvious rule, recurring gotcha, or useful pattern during execution, append it to `.gsd/KNOWLEDGE.md`. Only add entries that would save future agents from repeating your investigation. Don't add obvious things.
85
+ 17. If you made an architectural, pattern, library, or observability decision during this task that downstream work should know about, call `capture_thought` with `category: "architecture"` (or `"pattern"`). For decisions, populate `structuredFields` with `{ scope, decision, choice, rationale, made_by: "agent", revisable }` so future projection back to a human-visible decisions register stays lossless. Not every task produces decisions — only capture when a meaningful choice was made.
86
+ 18. If you discover a non-obvious rule, recurring gotcha, or useful pattern during execution, call `capture_thought` with `category: "gotcha"`, `"convention"`, `"pattern"`, or `"environment"` as appropriate. Only capture entries that would save future agents from repeating your investigation — don't capture obvious things. The memory store is the single source of truth for cross-session knowledge (ADR-013); do not append to `.gsd/DECISIONS.md` or `.gsd/KNOWLEDGE.md` directly.
86
87
  19. Read the template at `~/.gsd/agent/extensions/gsd/templates/task-summary.md`
87
88
  20. Use that template to prepare the completion content you will pass to `gsd_complete_task` using the camelCase fields `milestoneId`, `sliceId`, `taskId`, `oneLiner`, `narrative`, `verification`, and `verificationEvidence`. Do **not** manually write `{{taskSummaryPath}}` — the DB-backed tool is the canonical write path and renders the summary file for you.
88
89
  21. Call `gsd_complete_task` with milestoneId, sliceId, taskId, and the completion fields derived from the template. This is your final required step — do NOT manually edit PLAN.md checkboxes. The tool marks the task complete, updates the DB, renders `{{taskSummaryPath}}`, and updates PLAN.md automatically.
@@ -15,8 +15,11 @@ Dispatch ALL slices simultaneously using the `subagent` tool in **parallel mode*
15
15
  1. Call `subagent` with `tasks: [...]` containing one entry per slice below
16
16
  2. Wait for ALL subagents to complete
17
17
  3. Verify each slice's RESEARCH file was written (check the `.gsd/{{mid}}/` directory)
18
- 4. If any subagent failed to write its RESEARCH file, re-run it individually
19
- 5. Report which slices completed research and which (if any) failed
18
+ 4. If a subagent failed to write its RESEARCH file, retry it **once** individually
19
+ 5. If it fails a second time, write a partial RESEARCH file for that slice with a `## BLOCKER` section explaining the failure — do NOT retry again
20
+ 6. Report which slices completed research and which (if any) needed a blocker note
21
+
22
+ **Important**: Each failed slice gets exactly one retry. After that, write the blocker and move on. Never retry the same slice more than once.
20
23
 
21
24
  ## Subagent Prompts
22
25
 
@@ -44,6 +44,7 @@ Narrate your decomposition reasoning — why you're grouping work this way, what
44
44
 
45
45
  Then:
46
46
  0. If `REQUIREMENTS.md` was preloaded above, identify which Active requirements the roadmap says this slice owns or supports. These are the requirements this plan must deliver — every owned requirement needs at least one task that directly advances it, and verification must prove the requirement is met.
47
+ 0a. Call `memory_query` with keywords from the slice title and the source files listed below. Prior architectural decisions, conventions, and gotchas in this area should inform task decomposition — not be re-derived during execution.
47
48
  1. Read the templates:
48
49
  - `~/.gsd/agent/extensions/gsd/templates/plan.md`
49
50
  - `~/.gsd/agent/extensions/gsd/templates/task-plan.md`
@@ -42,6 +42,7 @@ An honest "this is straightforward, here's the pattern to follow" is more valuab
42
42
 
43
43
  Research what this slice needs. Narrate key findings and surprises as you go — what exists, what's missing, what constrains the approach.
44
44
  0. If `REQUIREMENTS.md` was preloaded above, identify which Active requirements this slice owns or supports. Research should target these requirements — surfacing risks, unknowns, and implementation constraints that could affect whether the slice actually delivers them.
45
+ 0a. Call `memory_query` with keywords from the slice title and scope. Prior slices may have captured architecture notes, conventions, or gotchas in subsystems you're about to explore — pulling them now prevents re-discovering known constraints.
45
46
  1. {{skillActivation}} Reference specific rules from loaded skills in your findings where they inform the implementation approach.
46
47
  2. **Skill Discovery ({{skillDiscoveryMode}}):**{{skillDiscoveryInstructions}}
47
48
  3. Explore relevant code for this slice's scope. For targeted exploration, use `rg`, `find`, and reads. For broad or unfamiliar subsystems, use `scout` to map the relevant area first.
@@ -3,9 +3,17 @@
3
3
  * Tracks every bash command, file write, and file edit during a unit execution.
4
4
  * Evidence is compared against LLM completion claims in evidence-cross-ref.ts.
5
5
  *
6
+ * Evidence is persisted to .gsd/safety/evidence-<mid>-<sid>-<tid>.json so it
7
+ * survives session restarts (pause/resume, crash recovery). On unit start,
8
+ * call resetEvidence() then loadEvidenceFromDisk(). On every new tool call,
9
+ * saveEvidenceToDisk() is called automatically by recordToolCall/recordToolResult.
10
+ *
6
11
  * Follows the same module-level Map pattern as auto-tool-tracking.ts.
7
12
  * Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
8
13
  */
14
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync, } from "node:fs";
15
+ import { join, dirname } from "node:path";
16
+ import { randomBytes } from "node:crypto";
9
17
  // ─── Module State ───────────────────────────────────────────────────────────
10
18
  let unitEvidence = [];
11
19
  // ─── Public API ─────────────────────────────────────────────────────────────
@@ -27,6 +35,94 @@ export function getFilePaths() {
27
35
  .filter((e) => e.kind === "write" || e.kind === "edit")
28
36
  .map(e => e.path);
29
37
  }
38
+ // ─── Persistence (Bug #4385 — evidence must survive session restarts) ────────
39
+ /**
40
+ * Build the path for the evidence JSON file for a given unit.
41
+ * Lives under .gsd/safety/ which is gitignored and session-scoped.
42
+ */
43
+ function evidencePath(basePath, milestoneId, sliceId, taskId) {
44
+ return join(basePath, ".gsd", "safety", `evidence-${milestoneId}-${sliceId}-${taskId}.json`);
45
+ }
46
+ /**
47
+ * Validate that a parsed value is an array of EvidenceEntry objects.
48
+ * Rejects corrupt / schema-mismatch data rather than letting it poison state.
49
+ */
50
+ function isEvidenceArray(data) {
51
+ if (!Array.isArray(data))
52
+ return false;
53
+ return data.every((e) => {
54
+ if (e === null || typeof e !== "object")
55
+ return false;
56
+ const rec = e;
57
+ if (typeof rec.toolCallId !== "string")
58
+ return false;
59
+ if (typeof rec.timestamp !== "number")
60
+ return false;
61
+ if (rec.kind === "bash") {
62
+ return (typeof rec.command === "string" &&
63
+ typeof rec.exitCode === "number" &&
64
+ typeof rec.outputSnippet === "string");
65
+ }
66
+ if (rec.kind === "write" || rec.kind === "edit") {
67
+ return typeof rec.path === "string";
68
+ }
69
+ return false;
70
+ });
71
+ }
72
+ /**
73
+ * Persist the current in-memory evidence to disk so it survives a session
74
+ * restart. Called from saveEvidenceToDisk after recordToolCall/recordToolResult.
75
+ * Non-fatal — persistence failures must never break unit execution.
76
+ */
77
+ export function saveEvidenceToDisk(basePath, milestoneId, sliceId, taskId) {
78
+ try {
79
+ const path = evidencePath(basePath, milestoneId, sliceId, taskId);
80
+ mkdirSync(dirname(path), { recursive: true });
81
+ const tmp = `${path}.tmp.${randomBytes(4).toString("hex")}`;
82
+ writeFileSync(tmp, JSON.stringify(unitEvidence, null, 2) + "\n", "utf-8");
83
+ renameSync(tmp, path);
84
+ }
85
+ catch {
86
+ // Non-fatal — don't let persistence failures break unit execution
87
+ }
88
+ }
89
+ /**
90
+ * Load persisted evidence from disk into the in-memory array.
91
+ * Call after resetEvidence() on session resume to restore context for a
92
+ * partially-executed unit. If the file does not exist (fresh unit), this
93
+ * is a no-op — getEvidence() will return [] which is correct.
94
+ */
95
+ export function loadEvidenceFromDisk(basePath, milestoneId, sliceId, taskId) {
96
+ try {
97
+ const path = evidencePath(basePath, milestoneId, sliceId, taskId);
98
+ if (!existsSync(path))
99
+ return;
100
+ const raw = readFileSync(path, "utf-8");
101
+ const parsed = JSON.parse(raw);
102
+ if (isEvidenceArray(parsed)) {
103
+ unitEvidence = parsed;
104
+ }
105
+ }
106
+ catch {
107
+ // Non-fatal — corrupt / missing file is treated as empty evidence
108
+ }
109
+ }
110
+ /**
111
+ * Delete the persisted evidence file for a unit after it has been fully
112
+ * processed. Prevents stale evidence from affecting future retries of
113
+ * the same unit ID.
114
+ */
115
+ export function clearEvidenceFromDisk(basePath, milestoneId, sliceId, taskId) {
116
+ try {
117
+ const path = evidencePath(basePath, milestoneId, sliceId, taskId);
118
+ if (existsSync(path)) {
119
+ unlinkSync(path);
120
+ }
121
+ }
122
+ catch {
123
+ // Non-fatal
124
+ }
125
+ }
30
126
  // ─── Recording (called from register-hooks.ts) ─────────────────────────────
31
127
  /**
32
128
  * Record a tool call at dispatch time (before execution).