gsd-pi 2.76.0-dev.82e249f7b → 2.76.0-dev.97f5583d9

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 (271) hide show
  1. package/dist/claude-cli-check.js +32 -3
  2. package/dist/mcp-server.d.ts +7 -0
  3. package/dist/mcp-server.js +35 -1
  4. package/dist/resource-loader.d.ts +1 -1
  5. package/dist/resource-loader.js +2 -8
  6. package/dist/resources/extensions/claude-code-cli/readiness.js +4 -3
  7. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +77 -17
  8. package/dist/resources/extensions/gsd/auto/phases.js +42 -1
  9. package/dist/resources/extensions/gsd/auto/run-unit.js +27 -0
  10. package/dist/resources/extensions/gsd/auto/session.js +12 -0
  11. package/dist/resources/extensions/gsd/auto-dispatch.js +16 -3
  12. package/dist/resources/extensions/gsd/auto-model-selection.js +1 -1
  13. package/dist/resources/extensions/gsd/auto-post-unit.js +25 -2
  14. package/dist/resources/extensions/gsd/auto-prompts.js +14 -0
  15. package/dist/resources/extensions/gsd/auto-recovery.js +13 -0
  16. package/dist/resources/extensions/gsd/auto-start.js +27 -18
  17. package/dist/resources/extensions/gsd/auto-worktree.js +51 -53
  18. package/dist/resources/extensions/gsd/auto.js +55 -27
  19. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +17 -1
  20. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +39 -9
  21. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +93 -0
  22. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +2 -0
  23. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +51 -5
  24. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +34 -2
  25. package/dist/resources/extensions/gsd/clean-root-preflight.js +93 -0
  26. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +968 -23
  27. package/dist/resources/extensions/gsd/compaction-snapshot.js +121 -0
  28. package/dist/resources/extensions/gsd/error-classifier.js +10 -3
  29. package/dist/resources/extensions/gsd/exec-history.js +120 -0
  30. package/dist/resources/extensions/gsd/exec-sandbox.js +258 -0
  31. package/dist/resources/extensions/gsd/gsd-db.js +115 -7
  32. package/dist/resources/extensions/gsd/guided-flow.js +189 -0
  33. package/dist/resources/extensions/gsd/health-widget.js +4 -1
  34. package/dist/resources/extensions/gsd/init-wizard.js +15 -1
  35. package/dist/resources/extensions/gsd/key-manager.js +6 -0
  36. package/dist/resources/extensions/gsd/model-router.js +36 -3
  37. package/dist/resources/extensions/gsd/pre-execution-checks.js +35 -9
  38. package/dist/resources/extensions/gsd/preferences-types.js +9 -0
  39. package/dist/resources/extensions/gsd/preferences-validation.js +83 -0
  40. package/dist/resources/extensions/gsd/preferences.js +17 -17
  41. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  42. package/dist/resources/extensions/gsd/prompts/discuss.md +29 -2
  43. package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  44. package/dist/resources/extensions/gsd/safety/evidence-collector.js +96 -0
  45. package/dist/resources/extensions/gsd/safety/file-change-validator.js +13 -5
  46. package/dist/resources/extensions/gsd/safety/safety-harness.js +5 -1
  47. package/dist/resources/extensions/gsd/token-counter.js +22 -5
  48. package/dist/resources/extensions/gsd/tools/exec-search-tool.js +59 -0
  49. package/dist/resources/extensions/gsd/tools/exec-tool.js +126 -0
  50. package/dist/resources/extensions/gsd/tools/resume-tool.js +23 -0
  51. package/dist/resources/extensions/gsd/uok/plan-v2.js +20 -3
  52. package/dist/resources/extensions/gsd/workflow-mcp.js +3 -0
  53. package/dist/resources/skills/verify-before-complete/SKILL.md +2 -1
  54. package/dist/resources/skills/write-docs/SKILL.md +2 -1
  55. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  56. package/dist/web/standalone/.next/BUILD_ID +1 -1
  57. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  58. package/dist/web/standalone/.next/build-manifest.json +2 -2
  59. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  60. package/dist/web/standalone/.next/required-server-files.json +1 -1
  61. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  62. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  65. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  66. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  67. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  68. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  70. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  75. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/index.html +1 -1
  78. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  79. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  85. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  86. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  87. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  88. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  89. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  90. package/dist/web/standalone/server.js +1 -1
  91. package/package.json +1 -1
  92. package/packages/mcp-server/dist/remote-questions.d.ts +45 -0
  93. package/packages/mcp-server/dist/remote-questions.d.ts.map +1 -0
  94. package/packages/mcp-server/dist/remote-questions.js +732 -0
  95. package/packages/mcp-server/dist/remote-questions.js.map +1 -0
  96. package/packages/mcp-server/dist/server.d.ts +7 -0
  97. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  98. package/packages/mcp-server/dist/server.js +41 -4
  99. package/packages/mcp-server/dist/server.js.map +1 -1
  100. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  101. package/packages/mcp-server/dist/workflow-tools.js +64 -25
  102. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  103. package/packages/mcp-server/package.json +2 -1
  104. package/packages/mcp-server/src/mcp-server.test.ts +30 -0
  105. package/packages/mcp-server/src/remote-questions.test.ts +294 -0
  106. package/packages/mcp-server/src/remote-questions.ts +916 -0
  107. package/packages/mcp-server/src/server.ts +62 -10
  108. package/packages/mcp-server/src/workflow-tools.test.ts +146 -1
  109. package/packages/mcp-server/src/workflow-tools.ts +84 -43
  110. package/packages/mcp-server/tsconfig.test.json +19 -0
  111. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  112. package/packages/pi-ai/dist/providers/anthropic-auth.test.js +1 -1
  113. package/packages/pi-ai/dist/providers/anthropic-auth.test.js.map +1 -1
  114. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  115. package/packages/pi-ai/dist/providers/anthropic-shared.js +27 -4
  116. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  117. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  118. package/packages/pi-ai/dist/providers/anthropic.js +8 -3
  119. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  120. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts +2 -0
  121. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts.map +1 -0
  122. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js +80 -0
  123. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js.map +1 -0
  124. package/packages/pi-ai/dist/providers/simple-options.d.ts +10 -0
  125. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  126. package/packages/pi-ai/dist/providers/simple-options.js +16 -1
  127. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  128. package/packages/pi-ai/src/providers/anthropic-auth.test.ts +1 -1
  129. package/packages/pi-ai/src/providers/anthropic-shared.ts +26 -5
  130. package/packages/pi-ai/src/providers/anthropic.ts +9 -3
  131. package/packages/pi-ai/src/providers/minimax-tool-name.test.ts +98 -0
  132. package/packages/pi-ai/src/providers/simple-options.ts +17 -1
  133. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  134. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts +2 -0
  135. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts.map +1 -0
  136. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js +203 -0
  137. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js.map +1 -0
  138. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  139. package/packages/pi-coding-agent/dist/core/model-registry.js +14 -0
  140. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  141. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts +2 -0
  142. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts.map +1 -0
  143. package/packages/pi-coding-agent/dist/core/redact-secrets.js +49 -0
  144. package/packages/pi-coding-agent/dist/core/redact-secrets.js.map +1 -0
  145. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts +2 -0
  146. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts.map +1 -0
  147. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js +67 -0
  148. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js.map +1 -0
  149. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  150. package/packages/pi-coding-agent/dist/core/session-manager.js +9 -5
  151. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  152. package/packages/pi-coding-agent/dist/core/session-manager.test.js +25 -1
  153. package/packages/pi-coding-agent/dist/core/session-manager.test.js.map +1 -1
  154. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
  155. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
  156. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +5 -4
  157. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
  158. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +7 -6
  159. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  160. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +29 -21
  161. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  162. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  163. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +13 -1
  164. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  165. package/packages/pi-coding-agent/src/core/model-registry-custom-caps.test.ts +245 -0
  166. package/packages/pi-coding-agent/src/core/model-registry.ts +16 -0
  167. package/packages/pi-coding-agent/src/core/redact-secrets.test.ts +86 -0
  168. package/packages/pi-coding-agent/src/core/redact-secrets.ts +58 -0
  169. package/packages/pi-coding-agent/src/core/session-manager.test.ts +36 -1
  170. package/packages/pi-coding-agent/src/core/session-manager.ts +9 -5
  171. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +6 -6
  172. package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +36 -22
  173. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +13 -1
  174. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  175. package/src/resources/extensions/claude-code-cli/readiness.ts +4 -3
  176. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +78 -17
  177. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +149 -5
  178. package/src/resources/extensions/gsd/auto/loop-deps.ts +13 -0
  179. package/src/resources/extensions/gsd/auto/phases.ts +66 -1
  180. package/src/resources/extensions/gsd/auto/run-unit.ts +29 -0
  181. package/src/resources/extensions/gsd/auto/session.ts +22 -0
  182. package/src/resources/extensions/gsd/auto-dispatch.ts +16 -3
  183. package/src/resources/extensions/gsd/auto-model-selection.ts +1 -1
  184. package/src/resources/extensions/gsd/auto-post-unit.ts +29 -3
  185. package/src/resources/extensions/gsd/auto-prompts.ts +28 -1
  186. package/src/resources/extensions/gsd/auto-recovery.ts +15 -0
  187. package/src/resources/extensions/gsd/auto-start.ts +29 -19
  188. package/src/resources/extensions/gsd/auto-worktree.ts +62 -63
  189. package/src/resources/extensions/gsd/auto.ts +58 -27
  190. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +23 -1
  191. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +40 -9
  192. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +109 -0
  193. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +2 -0
  194. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +53 -5
  195. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +35 -2
  196. package/src/resources/extensions/gsd/clean-root-preflight.ts +111 -0
  197. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +898 -32
  198. package/src/resources/extensions/gsd/compaction-snapshot.ts +165 -0
  199. package/src/resources/extensions/gsd/error-classifier.ts +10 -3
  200. package/src/resources/extensions/gsd/exec-history.ts +153 -0
  201. package/src/resources/extensions/gsd/exec-sandbox.ts +326 -0
  202. package/src/resources/extensions/gsd/gsd-db.ts +122 -7
  203. package/src/resources/extensions/gsd/guided-flow.ts +221 -0
  204. package/src/resources/extensions/gsd/health-widget.ts +3 -1
  205. package/src/resources/extensions/gsd/init-wizard.ts +15 -1
  206. package/src/resources/extensions/gsd/journal.ts +2 -1
  207. package/src/resources/extensions/gsd/key-manager.ts +6 -0
  208. package/src/resources/extensions/gsd/model-router.ts +42 -1
  209. package/src/resources/extensions/gsd/pre-execution-checks.ts +36 -10
  210. package/src/resources/extensions/gsd/preferences-types.ts +46 -0
  211. package/src/resources/extensions/gsd/preferences-validation.ts +79 -0
  212. package/src/resources/extensions/gsd/preferences.ts +17 -17
  213. package/src/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  214. package/src/resources/extensions/gsd/prompts/discuss.md +29 -2
  215. package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  216. package/src/resources/extensions/gsd/safety/evidence-collector.ts +119 -0
  217. package/src/resources/extensions/gsd/safety/file-change-validator.ts +17 -4
  218. package/src/resources/extensions/gsd/safety/safety-harness.ts +9 -0
  219. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +119 -1
  220. package/src/resources/extensions/gsd/tests/auto-paused-session-validation.test.ts +12 -0
  221. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +49 -0
  222. package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +186 -0
  223. package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +123 -0
  224. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  225. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  226. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +2 -0
  227. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +31 -0
  228. package/src/resources/extensions/gsd/tests/double-merge-guard.test.ts +1 -1
  229. package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +1 -1
  230. package/src/resources/extensions/gsd/tests/escalation.test.ts +1 -1
  231. package/src/resources/extensions/gsd/tests/exec-history.test.ts +124 -0
  232. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +210 -0
  233. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +58 -0
  234. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +152 -1
  235. package/src/resources/extensions/gsd/tests/init-wizard.test.ts +27 -0
  236. package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +1 -1
  237. package/src/resources/extensions/gsd/tests/issue-4540-regressions.test.ts +288 -0
  238. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +2 -0
  239. package/src/resources/extensions/gsd/tests/key-manager.test.ts +7 -0
  240. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -1
  241. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -2
  242. package/src/resources/extensions/gsd/tests/parallel-research-dispatch.test.ts +19 -0
  243. package/src/resources/extensions/gsd/tests/pre-exec-backtick-strip.test.ts +14 -0
  244. package/src/resources/extensions/gsd/tests/pre-exec-gate-loop.test.ts +272 -0
  245. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +234 -0
  246. package/src/resources/extensions/gsd/tests/preferences.test.ts +110 -0
  247. package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +44 -0
  248. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +48 -0
  249. package/src/resources/extensions/gsd/tests/ready-phrase-no-files-4573.test.ts +388 -0
  250. package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +9 -3
  251. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +205 -0
  252. package/src/resources/extensions/gsd/tests/save-gate-result-render.test.ts +95 -0
  253. package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +32 -40
  254. package/src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts +56 -0
  255. package/src/resources/extensions/gsd/tests/token-counter.test.ts +105 -1
  256. package/src/resources/extensions/gsd/tests/tool-compatibility.test.ts +107 -0
  257. package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +23 -0
  258. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +65 -2
  259. package/src/resources/extensions/gsd/tests/write-gate.test.ts +64 -0
  260. package/src/resources/extensions/gsd/tests/zombie-gsd-state.test.ts +3 -1
  261. package/src/resources/extensions/gsd/token-counter.ts +22 -5
  262. package/src/resources/extensions/gsd/tools/exec-search-tool.ts +81 -0
  263. package/src/resources/extensions/gsd/tools/exec-tool.ts +183 -0
  264. package/src/resources/extensions/gsd/tools/resume-tool.ts +40 -0
  265. package/src/resources/extensions/gsd/uok/plan-v2.ts +26 -3
  266. package/src/resources/extensions/gsd/workflow-logger.ts +3 -1
  267. package/src/resources/extensions/gsd/workflow-mcp.ts +3 -0
  268. package/src/resources/skills/verify-before-complete/SKILL.md +2 -1
  269. package/src/resources/skills/write-docs/SKILL.md +2 -1
  270. /package/dist/web/standalone/.next/static/{ecSsu49rxxcpbNmVP4mLD → lLdDRDspgYzfz0bJAmUSz}/_buildManifest.js +0 -0
  271. /package/dist/web/standalone/.next/static/{ecSsu49rxxcpbNmVP4mLD → lLdDRDspgYzfz0bJAmUSz}/_ssgManifest.js +0 -0
@@ -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")
@@ -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}}
@@ -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
 
@@ -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).
@@ -4,13 +4,18 @@
4
4
  *
5
5
  * Uses tasks.expected_output (DB column, populated from per-task ## Expected Output)
6
6
  * and tasks.files (from slice PLAN.md - Files: subline) as the expected set.
7
- * Compares against git diff HEAD~1 --name-only after auto-commit.
7
+ * Compares against `git diff-tree --root --no-commit-id -r --name-only HEAD` after auto-commit.
8
+ * Using diff-tree --root handles initial commits, shallow clones, and merge commits correctly
9
+ * (Bug #4385 — git diff HEAD~1 failed on initial commits).
8
10
  *
9
11
  * Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
10
12
  */
13
+ import { createRequire } from "node:module";
11
14
  import { execFileSync } from "node:child_process";
12
15
  import { normalizePlannedFileReference } from "../files.js";
13
16
  import { logWarning } from "../workflow-logger.js";
17
+ const _require = createRequire(import.meta.url);
18
+ const picomatch = _require("picomatch");
14
19
  // ─── Public API ─────────────────────────────────────────────────────────────
15
20
  /**
16
21
  * Validate file changes after auto-commit for an execute-task unit.
@@ -20,7 +25,7 @@ import { logWarning } from "../workflow-logger.js";
20
25
  * @param expectedOutput - JSON array from tasks.expected_output DB column
21
26
  * @param plannedFiles - JSON array from tasks.files DB column
22
27
  */
23
- export function validateFileChanges(basePath, expectedOutput, plannedFiles) {
28
+ export function validateFileChanges(basePath, expectedOutput, plannedFiles, fileChangeAllowlist = []) {
24
29
  const allExpected = new Set([...expectedOutput, ...plannedFiles]);
25
30
  // If no expected files were planned, skip validation
26
31
  if (allExpected.size === 0)
@@ -33,8 +38,11 @@ export function validateFileChanges(basePath, expectedOutput, plannedFiles) {
33
38
  const projectFiles = actualFiles.filter(f => !f.startsWith(".gsd/") && !f.startsWith(".gsd\\"));
34
39
  // Normalize expected paths (strip leading ./ or /)
35
40
  const normalizedExpected = new Set([...allExpected].map((f) => normalizePlannedFileReference(f).replace(/^\.\//, "").replace(/^\//, "")));
36
- // Compute symmetric difference
37
- const unexpectedFiles = projectFiles.filter(f => !normalizedExpected.has(f));
41
+ // Build allowlist matchers once (dot: true so patterns like `**/.hidden` work).
42
+ const allowlistMatchers = fileChangeAllowlist.map(p => picomatch(p, { dot: true }));
43
+ const isAllowlisted = (f) => allowlistMatchers.some(m => m(f));
44
+ // Compute symmetric difference, excluding allowlisted files
45
+ const unexpectedFiles = projectFiles.filter(f => !normalizedExpected.has(f) && !isAllowlisted(f));
38
46
  const missingFiles = [...normalizedExpected].filter(f => !projectFiles.includes(f));
39
47
  const violations = [];
40
48
  for (const f of unexpectedFiles) {
@@ -62,7 +70,7 @@ export function validateFileChanges(basePath, expectedOutput, plannedFiles) {
62
70
  // ─── Internals ──────────────────────────────────────────────────────────────
63
71
  function getChangedFilesFromLastCommit(basePath) {
64
72
  try {
65
- const result = execFileSync("git", ["diff", "--name-only", "HEAD~1", "HEAD"], { cwd: basePath, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
73
+ const result = execFileSync("git", ["diff-tree", "--root", "--no-commit-id", "-r", "--name-only", "HEAD"], { cwd: basePath, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
66
74
  return result ? result.split("\n").filter(Boolean) : [];
67
75
  }
68
76
  catch (e) {
@@ -23,6 +23,7 @@ const DEFAULTS = {
23
23
  checkpoints: true,
24
24
  auto_rollback: false,
25
25
  timeout_scale_cap: 6,
26
+ file_change_allowlist: [],
26
27
  };
27
28
  // ─── Public API ─────────────────────────────────────────────────────────────
28
29
  /**
@@ -42,6 +43,9 @@ export function resolveSafetyHarnessConfig(raw) {
42
43
  checkpoints: typeof raw.checkpoints === "boolean" ? raw.checkpoints : DEFAULTS.checkpoints,
43
44
  auto_rollback: typeof raw.auto_rollback === "boolean" ? raw.auto_rollback : DEFAULTS.auto_rollback,
44
45
  timeout_scale_cap: typeof raw.timeout_scale_cap === "number" ? raw.timeout_scale_cap : DEFAULTS.timeout_scale_cap,
46
+ file_change_allowlist: Array.isArray(raw.file_change_allowlist)
47
+ ? raw.file_change_allowlist.filter((p) => typeof p === "string")
48
+ : DEFAULTS.file_change_allowlist,
45
49
  };
46
50
  }
47
51
  /**
@@ -56,7 +60,7 @@ export function isHarnessEnabled(raw) {
56
60
  return DEFAULTS.enabled;
57
61
  }
58
62
  // ─── Re-exports ─────────────────────────────────────────────────────────────
59
- export { resetEvidence, getEvidence, getBashEvidence, getFilePaths, recordToolCall, recordToolResult, } from "./evidence-collector.js";
63
+ export { resetEvidence, getEvidence, getBashEvidence, getFilePaths, recordToolCall, recordToolResult, saveEvidenceToDisk, loadEvidenceFromDisk, clearEvidenceFromDisk, } from "./evidence-collector.js";
60
64
  export { classifyCommand } from "./destructive-guard.js";
61
65
  export { validateFileChanges } from "./file-change-validator.js";
62
66
  export { crossReferenceEvidence } from "./evidence-cross-ref.js";
@@ -16,7 +16,11 @@ async function getEncoder() {
16
16
  try {
17
17
  // @ts-ignore — tiktoken may not have type declarations in extensions tsconfig
18
18
  const tiktoken = await import("tiktoken");
19
- encoder = tiktoken.encoding_for_model("gpt-4o");
19
+ // Use cl100k_base — the most conservative and broadly compatible BPE encoding.
20
+ // It is shared by GPT-3.5/GPT-4 and gives a safer (larger) estimate than
21
+ // gpt-4o's o200k_base encoding, which produces fewer tokens for the same text
22
+ // and would cause context windows for non-OpenAI providers to be under-counted.
23
+ encoder = tiktoken.get_encoding("cl100k_base");
20
24
  return encoder;
21
25
  }
22
26
  catch {
@@ -24,19 +28,32 @@ async function getEncoder() {
24
28
  return null;
25
29
  }
26
30
  }
27
- export async function countTokens(text) {
31
+ /**
32
+ * Count tokens in `text` using tiktoken (cl100k_base) when available.
33
+ *
34
+ * When tiktoken is not loaded, falls back to a provider-aware character-ratio
35
+ * estimate via `estimateTokensForProvider`. Passing `provider` is recommended
36
+ * so the heuristic fallback is as accurate as possible.
37
+ */
38
+ export async function countTokens(text, provider) {
28
39
  const enc = await getEncoder();
29
40
  if (enc) {
30
41
  const tokens = enc.encode(text);
31
42
  return tokens.length;
32
43
  }
33
- return Math.ceil(text.length / 4);
44
+ return estimateTokensForProvider(text, provider ?? "unknown");
34
45
  }
35
- export function countTokensSync(text) {
46
+ /**
47
+ * Synchronous token count — only accurate after `initTokenCounter()` resolves.
48
+ *
49
+ * Before init, or when tiktoken is unavailable, falls back to a provider-aware
50
+ * character-ratio estimate. Passing `provider` is recommended.
51
+ */
52
+ export function countTokensSync(text, provider) {
36
53
  if (encoder) {
37
54
  return encoder.encode(text).length;
38
55
  }
39
- return Math.ceil(text.length / 4);
56
+ return estimateTokensForProvider(text, provider ?? "unknown");
40
57
  }
41
58
  export async function initTokenCounter() {
42
59
  const enc = await getEncoder();
@@ -0,0 +1,59 @@
1
+ // GSD Exec Search Tool — lists and filters prior gsd_exec runs.
2
+ //
3
+ // Scans .gsd/exec/*.meta.json and returns a ranked summary so agents can
4
+ // re-discover past runs without re-executing. Read-only; no DB writes.
5
+ import { searchExecHistory } from "../exec-history.js";
6
+ export function executeExecSearch(params, opts) {
7
+ const searchOpts = {
8
+ query: typeof params.query === "string" ? params.query : undefined,
9
+ runtime: params.runtime,
10
+ failing_only: params.failing_only === true,
11
+ limit: typeof params.limit === "number" ? params.limit : undefined,
12
+ };
13
+ const hits = searchExecHistory(opts.baseDir, searchOpts);
14
+ if (hits.length === 0) {
15
+ return {
16
+ content: [{ type: "text", text: "No prior gsd_exec runs match those filters." }],
17
+ details: { operation: "gsd_exec_search", matches: 0 },
18
+ };
19
+ }
20
+ const lines = [`Found ${hits.length} exec run(s), most recent first:`];
21
+ for (const hit of hits) {
22
+ const e = hit.entry;
23
+ const status = formatStatus(e);
24
+ const purpose = e.purpose ? ` — ${e.purpose}` : "";
25
+ const truncated = e.stdout_truncated ? " (stdout truncated)" : "";
26
+ lines.push(`- [${e.id}] ${e.runtime} ${status} ${e.duration_ms}ms${truncated}${purpose}`, ` stdout: ${e.stdout_path}`);
27
+ if (hit.digest_preview) {
28
+ const preview = hit.digest_preview.replace(/\n/g, "\n ");
29
+ lines.push(` preview:\n ${preview}`);
30
+ }
31
+ }
32
+ return {
33
+ content: [{ type: "text", text: lines.join("\n") }],
34
+ details: {
35
+ operation: "gsd_exec_search",
36
+ matches: hits.length,
37
+ results: hits.map((hit) => ({
38
+ id: hit.entry.id,
39
+ runtime: hit.entry.runtime,
40
+ exit_code: hit.entry.exit_code,
41
+ timed_out: hit.entry.timed_out,
42
+ duration_ms: hit.entry.duration_ms,
43
+ purpose: hit.entry.purpose,
44
+ stdout_path: hit.entry.stdout_path,
45
+ stderr_path: hit.entry.stderr_path,
46
+ meta_path: hit.entry.meta_path,
47
+ })),
48
+ },
49
+ };
50
+ }
51
+ function formatStatus(entry) {
52
+ if (entry.timed_out)
53
+ return "timeout";
54
+ if (entry.signal)
55
+ return `signal:${entry.signal}`;
56
+ if (entry.exit_code === null)
57
+ return "exit:null";
58
+ return `exit:${entry.exit_code}`;
59
+ }