gsd-pi 2.81.0-dev.72a81bdf3 → 2.82.0-dev.20138ae42

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 (463) hide show
  1. package/README.md +50 -31
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/GSD-WORKFLOW.md +10 -1
  4. package/dist/resources/extensions/browser-tools/tools/screenshot.js +1 -0
  5. package/dist/resources/extensions/browser-tools/tools/zoom.js +1 -0
  6. package/dist/resources/extensions/claude-code-cli/partial-builder.js +2 -1
  7. package/dist/resources/extensions/cmux/index.js +5 -0
  8. package/dist/resources/extensions/gsd/auto/infra-errors.js +9 -3
  9. package/dist/resources/extensions/gsd/auto/loop.js +5 -5
  10. package/dist/resources/extensions/gsd/auto/orchestrator.js +124 -6
  11. package/dist/resources/extensions/gsd/auto/phases.js +30 -1
  12. package/dist/resources/extensions/gsd/auto/workflow-memory-pressure.js +12 -0
  13. package/dist/resources/extensions/gsd/auto-dashboard.js +66 -1
  14. package/dist/resources/extensions/gsd/auto-dispatch.js +13 -6
  15. package/dist/resources/extensions/gsd/auto-model-selection.js +2 -0
  16. package/dist/resources/extensions/gsd/auto-post-unit.js +233 -127
  17. package/dist/resources/extensions/gsd/auto-prompts.js +13 -5
  18. package/dist/resources/extensions/gsd/auto-recovery.js +31 -1
  19. package/dist/resources/extensions/gsd/auto-start.js +85 -12
  20. package/dist/resources/extensions/gsd/auto-verification.js +28 -22
  21. package/dist/resources/extensions/gsd/auto-worktree.js +111 -1
  22. package/dist/resources/extensions/gsd/auto.js +158 -55
  23. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +25 -6
  24. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +9 -8
  25. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +9 -2
  26. package/dist/resources/extensions/gsd/bootstrap/subagent-input.js +21 -9
  27. package/dist/resources/extensions/gsd/bootstrap/system-context.js +55 -12
  28. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +16 -2
  29. package/dist/resources/extensions/gsd/clean-root-preflight.js +170 -8
  30. package/dist/resources/extensions/gsd/commands/catalog.js +4 -1
  31. package/dist/resources/extensions/gsd/commands/handlers/core.js +38 -1
  32. package/dist/resources/extensions/gsd/commands-bootstrap.js +5 -0
  33. package/dist/resources/extensions/gsd/commands-handlers.js +15 -2
  34. package/dist/resources/extensions/gsd/context-store.js +112 -0
  35. package/dist/resources/extensions/gsd/crash-recovery.js +31 -5
  36. package/dist/resources/extensions/gsd/db/unit-dispatches.js +3 -2
  37. package/dist/resources/extensions/gsd/db-writer.js +150 -84
  38. package/dist/resources/extensions/gsd/dispatch-guard.js +2 -2
  39. package/dist/resources/extensions/gsd/docs/preferences-reference.md +1 -1
  40. package/dist/resources/extensions/gsd/doctor-git-checks.js +41 -6
  41. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +28 -11
  42. package/dist/resources/extensions/gsd/doctor.js +2 -28
  43. package/dist/resources/extensions/gsd/export-html.js +27 -425
  44. package/dist/resources/extensions/gsd/git-service.js +39 -1
  45. package/dist/resources/extensions/gsd/gsd-db.js +1 -0
  46. package/dist/resources/extensions/gsd/guided-flow.js +93 -111
  47. package/dist/resources/extensions/gsd/guided-unit-context.js +23 -0
  48. package/dist/resources/extensions/gsd/knowledge-backfill.js +144 -0
  49. package/dist/resources/extensions/gsd/knowledge-capture.js +136 -0
  50. package/dist/resources/extensions/gsd/knowledge-parser.js +154 -0
  51. package/dist/resources/extensions/gsd/knowledge-projection.js +210 -0
  52. package/dist/resources/extensions/gsd/markdown-renderer.js +6 -1
  53. package/dist/resources/extensions/gsd/md-importer.js +1 -1
  54. package/dist/resources/extensions/gsd/memory-backfill.js +73 -17
  55. package/dist/resources/extensions/gsd/memory-consolidation-scanner.js +222 -0
  56. package/dist/resources/extensions/gsd/migrate/command.js +5 -0
  57. package/dist/resources/extensions/gsd/migrate/parsers.js +10 -0
  58. package/dist/resources/extensions/gsd/migrate/preview.js +9 -0
  59. package/dist/resources/extensions/gsd/migrate/transformer.js +51 -4
  60. package/dist/resources/extensions/gsd/migrate/writer.js +11 -1
  61. package/dist/resources/extensions/gsd/migration-auto-check.js +12 -17
  62. package/dist/resources/extensions/gsd/milestone-actions.js +11 -4
  63. package/dist/resources/extensions/gsd/native-git-bridge.js +48 -12
  64. package/dist/resources/extensions/gsd/pending-auto-start.js +52 -0
  65. package/dist/resources/extensions/gsd/post-execution-checks.js +73 -2
  66. package/dist/resources/extensions/gsd/pre-execution-checks.js +28 -1
  67. package/dist/resources/extensions/gsd/prompt-loader.js +1 -1
  68. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  69. package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  70. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +8 -8
  71. package/dist/resources/extensions/gsd/prompts/discuss.md +9 -9
  72. package/dist/resources/extensions/gsd/prompts/guided-discuss-project.md +4 -4
  73. package/dist/resources/extensions/gsd/prompts/guided-discuss-requirements.md +3 -3
  74. package/dist/resources/extensions/gsd/prompts/plan-slice.md +4 -4
  75. package/dist/resources/extensions/gsd/prompts/queue.md +4 -4
  76. package/dist/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  77. package/dist/resources/extensions/gsd/prompts/rewrite-docs.md +1 -1
  78. package/dist/resources/extensions/gsd/prompts/system.md +2 -2
  79. package/dist/resources/extensions/gsd/provider-switch-observer.js +146 -0
  80. package/dist/resources/extensions/gsd/smart-entry-routing.js +36 -0
  81. package/dist/resources/extensions/gsd/state-reconciliation/drift/merge-state.js +6 -1
  82. package/dist/resources/extensions/gsd/state-reconciliation/drift/project-md.js +9 -14
  83. package/dist/resources/extensions/gsd/state-reconciliation/drift/roadmap.js +19 -24
  84. package/dist/resources/extensions/gsd/status-guards.js +4 -0
  85. package/dist/resources/extensions/gsd/templates/knowledge.md +2 -2
  86. package/dist/resources/extensions/gsd/templates/plan.md +8 -5
  87. package/dist/resources/extensions/gsd/templates/task-plan.md +4 -2
  88. package/dist/resources/extensions/gsd/tools/complete-milestone.js +6 -8
  89. package/dist/resources/extensions/gsd/tools/complete-slice.js +6 -8
  90. package/dist/resources/extensions/gsd/tools/plan-milestone.js +7 -1
  91. package/dist/resources/extensions/gsd/tools/plan-slice.js +89 -14
  92. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +119 -0
  93. package/dist/resources/extensions/gsd/unit-context-manifest.js +32 -10
  94. package/dist/resources/extensions/gsd/validation.js +23 -1
  95. package/dist/resources/extensions/gsd/verification-gate.js +68 -7
  96. package/dist/resources/extensions/gsd/verification-verdict.js +26 -0
  97. package/dist/resources/extensions/gsd/workflow-projections.js +6 -8
  98. package/dist/resources/extensions/gsd/worktree-lifecycle.js +54 -10
  99. package/dist/resources/extensions/shared/html-shell.js +388 -0
  100. package/dist/resources/extensions/subagent/index.js +448 -78
  101. package/dist/resources/extensions/subagent/launch.js +77 -0
  102. package/dist/resources/extensions/subagent/run-store.js +148 -0
  103. package/dist/resources/extensions/visual-brief/artifact-policy.js +29 -0
  104. package/dist/resources/extensions/visual-brief/extension-manifest.json +8 -0
  105. package/dist/resources/extensions/visual-brief/index.js +5 -0
  106. package/dist/resources/extensions/visual-brief/page-contract.js +124 -0
  107. package/dist/resources/extensions/visual-brief/prompts.js +140 -0
  108. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  109. package/dist/web/standalone/.next/BUILD_ID +1 -1
  110. package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
  111. package/dist/web/standalone/.next/build-manifest.json +3 -3
  112. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  113. package/dist/web/standalone/.next/react-loadable-manifest.json +3 -3
  114. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  115. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  116. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  117. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  118. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  119. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  120. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  121. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  122. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  123. package/dist/web/standalone/.next/server/app/_not-found/page.js +2 -2
  124. package/dist/web/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  125. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  126. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  127. package/dist/web/standalone/.next/server/app/_not-found.rsc +4 -7
  128. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +4 -7
  129. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  130. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +4 -5
  131. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  132. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  133. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -5
  134. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  135. package/dist/web/standalone/.next/server/app/index.html +1 -1
  136. package/dist/web/standalone/.next/server/app/index.rsc +4 -7
  137. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  138. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -7
  139. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  140. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +4 -5
  141. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -5
  142. package/dist/web/standalone/.next/server/app/page.js +2 -2
  143. package/dist/web/standalone/.next/server/app/page.js.nft.json +1 -1
  144. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  145. package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
  146. package/dist/web/standalone/.next/server/chunks/4266.js +2 -0
  147. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  148. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  149. package/dist/web/standalone/.next/server/next-font-manifest.js +1 -1
  150. package/dist/web/standalone/.next/server/next-font-manifest.json +1 -1
  151. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  152. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  153. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  154. package/dist/web/standalone/.next/static/chunks/2973.33f26573894b6153.js +2 -0
  155. package/dist/web/standalone/.next/static/chunks/{8359.e059d86b255fce1c.js → 8359.7eb3bb8f8ecf4c01.js} +2 -2
  156. package/dist/web/standalone/.next/static/chunks/app/layout-8c10ec293ae0f1d5.js +1 -0
  157. package/dist/web/standalone/.next/static/chunks/{webpack-de742b64187e13fe.js → webpack-9a4db269f9ed63ad.js} +1 -1
  158. package/dist/web/standalone/.next/static/css/746ee28c929d1880.css +1 -0
  159. package/package.json +6 -5
  160. package/packages/contracts/dist/rpc.test.js +7 -0
  161. package/packages/contracts/dist/rpc.test.js.map +1 -1
  162. package/packages/contracts/dist/workflow.d.ts +21 -0
  163. package/packages/contracts/dist/workflow.d.ts.map +1 -1
  164. package/packages/contracts/dist/workflow.js +24 -0
  165. package/packages/contracts/dist/workflow.js.map +1 -1
  166. package/packages/contracts/src/rpc.test.ts +8 -0
  167. package/packages/contracts/src/workflow.ts +24 -0
  168. package/packages/daemon/package.json +2 -2
  169. package/packages/mcp-server/README.md +14 -3
  170. package/packages/mcp-server/dist/workflow-tools.d.ts +0 -3
  171. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  172. package/packages/mcp-server/dist/workflow-tools.js +80 -0
  173. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  174. package/packages/mcp-server/package.json +2 -2
  175. package/packages/mcp-server/src/workflow-tools-parity.test.ts +244 -0
  176. package/packages/mcp-server/src/workflow-tools.test.ts +23 -1
  177. package/packages/mcp-server/src/workflow-tools.ts +168 -0
  178. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  179. package/packages/native/package.json +1 -1
  180. package/packages/native/tsconfig.json +2 -1
  181. package/packages/native/tsconfig.tsbuildinfo +1 -1
  182. package/packages/pi-agent-core/package.json +1 -1
  183. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
  184. package/packages/pi-ai/dist/index.d.ts +2 -2
  185. package/packages/pi-ai/dist/index.d.ts.map +1 -1
  186. package/packages/pi-ai/dist/index.js +1 -1
  187. package/packages/pi-ai/dist/index.js.map +1 -1
  188. package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  189. package/packages/pi-ai/dist/providers/openai-codex-responses.js +82 -1
  190. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  191. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts +2 -0
  192. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts.map +1 -0
  193. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js +52 -0
  194. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js.map +1 -0
  195. package/packages/pi-ai/dist/providers/simple-options.d.ts +2 -4
  196. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  197. package/packages/pi-ai/dist/providers/simple-options.js +5 -6
  198. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  199. package/packages/pi-ai/dist/providers/simple-options.test.d.ts +2 -0
  200. package/packages/pi-ai/dist/providers/simple-options.test.d.ts.map +1 -0
  201. package/packages/pi-ai/dist/providers/simple-options.test.js +50 -0
  202. package/packages/pi-ai/dist/providers/simple-options.test.js.map +1 -0
  203. package/packages/pi-ai/dist/providers/transform-messages.d.ts +11 -0
  204. package/packages/pi-ai/dist/providers/transform-messages.d.ts.map +1 -1
  205. package/packages/pi-ai/dist/providers/transform-messages.js +20 -0
  206. package/packages/pi-ai/dist/providers/transform-messages.js.map +1 -1
  207. package/packages/pi-ai/package.json +1 -1
  208. package/packages/pi-ai/src/index.ts +7 -2
  209. package/packages/pi-ai/src/providers/openai-codex-responses.test.ts +63 -0
  210. package/packages/pi-ai/src/providers/openai-codex-responses.ts +91 -1
  211. package/packages/pi-ai/src/providers/simple-options.test.ts +60 -0
  212. package/packages/pi-ai/src/providers/simple-options.ts +5 -6
  213. package/packages/pi-ai/src/providers/transform-messages.ts +24 -0
  214. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  215. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts +2 -0
  216. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts.map +1 -0
  217. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js +66 -0
  218. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js.map +1 -0
  219. package/packages/pi-coding-agent/dist/core/agent-session.js +1 -1
  220. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  221. package/packages/pi-coding-agent/dist/core/system-prompt.js +4 -4
  222. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  223. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  224. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +24 -6
  225. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  226. package/packages/pi-coding-agent/dist/tests/system-prompt-file-safety.test.d.ts +2 -0
  227. package/packages/pi-coding-agent/dist/tests/system-prompt-file-safety.test.d.ts.map +1 -0
  228. package/packages/pi-coding-agent/dist/tests/system-prompt-file-safety.test.js +17 -0
  229. package/packages/pi-coding-agent/dist/tests/system-prompt-file-safety.test.js.map +1 -0
  230. package/packages/pi-coding-agent/package.json +1 -1
  231. package/packages/pi-coding-agent/src/core/agent-session-thinking-level.test.ts +79 -0
  232. package/packages/pi-coding-agent/src/core/agent-session.ts +1 -1
  233. package/packages/pi-coding-agent/src/core/system-prompt.ts +4 -4
  234. package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +23 -7
  235. package/packages/pi-coding-agent/src/tests/system-prompt-file-safety.test.ts +22 -0
  236. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  237. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  238. package/packages/pi-tui/dist/tui.js +5 -0
  239. package/packages/pi-tui/dist/tui.js.map +1 -1
  240. package/packages/pi-tui/package.json +1 -1
  241. package/packages/pi-tui/src/tui.ts +6 -0
  242. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
  243. package/packages/rpc-client/package.json +1 -1
  244. package/packages/rpc-client/tsconfig.tsbuildinfo +1 -1
  245. package/pkg/package.json +1 -1
  246. package/src/resources/GSD-WORKFLOW.md +10 -1
  247. package/src/resources/extensions/browser-tools/tools/screenshot.ts +1 -0
  248. package/src/resources/extensions/browser-tools/tools/zoom.ts +1 -0
  249. package/src/resources/extensions/claude-code-cli/partial-builder.ts +2 -1
  250. package/src/resources/extensions/claude-code-cli/tests/partial-builder.test.ts +19 -2
  251. package/src/resources/extensions/cmux/index.ts +6 -0
  252. package/src/resources/extensions/gsd/auto/contracts.ts +59 -16
  253. package/src/resources/extensions/gsd/auto/infra-errors.ts +9 -3
  254. package/src/resources/extensions/gsd/auto/loop.ts +8 -5
  255. package/src/resources/extensions/gsd/auto/orchestrator.ts +129 -6
  256. package/src/resources/extensions/gsd/auto/phases.ts +36 -1
  257. package/src/resources/extensions/gsd/auto/workflow-memory-pressure.ts +13 -0
  258. package/src/resources/extensions/gsd/auto-dashboard.ts +72 -1
  259. package/src/resources/extensions/gsd/auto-dispatch.ts +14 -6
  260. package/src/resources/extensions/gsd/auto-model-selection.ts +2 -1
  261. package/src/resources/extensions/gsd/auto-post-unit.ts +266 -139
  262. package/src/resources/extensions/gsd/auto-prompts.ts +13 -5
  263. package/src/resources/extensions/gsd/auto-recovery.ts +29 -0
  264. package/src/resources/extensions/gsd/auto-start.ts +92 -9
  265. package/src/resources/extensions/gsd/auto-verification.ts +36 -34
  266. package/src/resources/extensions/gsd/auto-worktree.ts +119 -1
  267. package/src/resources/extensions/gsd/auto.ts +167 -53
  268. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +33 -6
  269. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +9 -8
  270. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +10 -2
  271. package/src/resources/extensions/gsd/bootstrap/subagent-input.ts +19 -7
  272. package/src/resources/extensions/gsd/bootstrap/system-context.ts +58 -15
  273. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +19 -3
  274. package/src/resources/extensions/gsd/clean-root-preflight.ts +174 -8
  275. package/src/resources/extensions/gsd/commands/catalog.ts +4 -1
  276. package/src/resources/extensions/gsd/commands/handlers/core.ts +41 -1
  277. package/src/resources/extensions/gsd/commands-bootstrap.ts +10 -0
  278. package/src/resources/extensions/gsd/commands-handlers.ts +19 -2
  279. package/src/resources/extensions/gsd/context-store.ts +120 -1
  280. package/src/resources/extensions/gsd/crash-recovery.ts +30 -4
  281. package/src/resources/extensions/gsd/db/unit-dispatches.ts +4 -3
  282. package/src/resources/extensions/gsd/db-writer.ts +167 -84
  283. package/src/resources/extensions/gsd/dispatch-guard.ts +2 -2
  284. package/src/resources/extensions/gsd/docs/preferences-reference.md +1 -1
  285. package/src/resources/extensions/gsd/doctor-git-checks.ts +44 -6
  286. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +25 -13
  287. package/src/resources/extensions/gsd/doctor-types.ts +2 -0
  288. package/src/resources/extensions/gsd/doctor.ts +2 -27
  289. package/src/resources/extensions/gsd/export-html.ts +27 -427
  290. package/src/resources/extensions/gsd/git-service.ts +45 -1
  291. package/src/resources/extensions/gsd/gsd-db.ts +3 -0
  292. package/src/resources/extensions/gsd/guided-flow.ts +126 -128
  293. package/src/resources/extensions/gsd/guided-unit-context.ts +30 -0
  294. package/src/resources/extensions/gsd/knowledge-backfill.ts +164 -0
  295. package/src/resources/extensions/gsd/knowledge-capture.ts +160 -0
  296. package/src/resources/extensions/gsd/knowledge-parser.ts +174 -0
  297. package/src/resources/extensions/gsd/knowledge-projection.ts +241 -0
  298. package/src/resources/extensions/gsd/markdown-renderer.ts +6 -1
  299. package/src/resources/extensions/gsd/md-importer.ts +1 -1
  300. package/src/resources/extensions/gsd/memory-backfill.ts +89 -17
  301. package/src/resources/extensions/gsd/memory-consolidation-scanner.ts +277 -0
  302. package/src/resources/extensions/gsd/migrate/command.ts +5 -0
  303. package/src/resources/extensions/gsd/migrate/parsers.ts +11 -0
  304. package/src/resources/extensions/gsd/migrate/preview.ts +10 -0
  305. package/src/resources/extensions/gsd/migrate/transformer.ts +58 -4
  306. package/src/resources/extensions/gsd/migrate/writer.ts +14 -1
  307. package/src/resources/extensions/gsd/migration-auto-check.ts +15 -23
  308. package/src/resources/extensions/gsd/milestone-actions.ts +10 -4
  309. package/src/resources/extensions/gsd/native-git-bridge.ts +54 -12
  310. package/src/resources/extensions/gsd/pending-auto-start.ts +79 -0
  311. package/src/resources/extensions/gsd/post-execution-checks.ts +87 -2
  312. package/src/resources/extensions/gsd/pre-execution-checks.ts +32 -1
  313. package/src/resources/extensions/gsd/prompt-loader.ts +1 -1
  314. package/src/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  315. package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  316. package/src/resources/extensions/gsd/prompts/discuss-headless.md +8 -8
  317. package/src/resources/extensions/gsd/prompts/discuss.md +9 -9
  318. package/src/resources/extensions/gsd/prompts/guided-discuss-project.md +4 -4
  319. package/src/resources/extensions/gsd/prompts/guided-discuss-requirements.md +3 -3
  320. package/src/resources/extensions/gsd/prompts/plan-slice.md +4 -4
  321. package/src/resources/extensions/gsd/prompts/queue.md +4 -4
  322. package/src/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  323. package/src/resources/extensions/gsd/prompts/rewrite-docs.md +1 -1
  324. package/src/resources/extensions/gsd/prompts/system.md +2 -2
  325. package/src/resources/extensions/gsd/provider-switch-observer.ts +185 -0
  326. package/src/resources/extensions/gsd/smart-entry-routing.ts +77 -0
  327. package/src/resources/extensions/gsd/state-reconciliation/drift/merge-state.ts +8 -1
  328. package/src/resources/extensions/gsd/state-reconciliation/drift/project-md.ts +12 -15
  329. package/src/resources/extensions/gsd/state-reconciliation/drift/roadmap.ts +17 -25
  330. package/src/resources/extensions/gsd/status-guards.ts +5 -0
  331. package/src/resources/extensions/gsd/templates/knowledge.md +2 -2
  332. package/src/resources/extensions/gsd/templates/plan.md +8 -5
  333. package/src/resources/extensions/gsd/templates/task-plan.md +4 -2
  334. package/src/resources/extensions/gsd/tests/auto-dashboard.test.ts +71 -0
  335. package/src/resources/extensions/gsd/tests/auto-deterministic-error-classification-4973.test.ts +116 -0
  336. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +129 -0
  337. package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +487 -4
  338. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +12 -11
  339. package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +53 -2
  340. package/src/resources/extensions/gsd/tests/auto-post-unit-step-message.test.ts +12 -1
  341. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +15 -1
  342. package/src/resources/extensions/gsd/tests/auto-runtime-state.test.ts +4 -4
  343. package/src/resources/extensions/gsd/tests/auto-start-orphan-bootstrap.test.ts +1 -0
  344. package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +69 -1
  345. package/src/resources/extensions/gsd/tests/brief-command.test.ts +89 -0
  346. package/src/resources/extensions/gsd/tests/browser-tools-compatibility-declarations.test.ts +62 -0
  347. package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +107 -2
  348. package/src/resources/extensions/gsd/tests/clear-stale-autostart.test.ts +11 -2
  349. package/src/resources/extensions/gsd/tests/closeout-git-deferral.test.ts +16 -0
  350. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +4 -1
  351. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +5 -9
  352. package/src/resources/extensions/gsd/tests/complete-task.test.ts +3 -1
  353. package/src/resources/extensions/gsd/tests/context-store-decisions-from-memories.test.ts +312 -0
  354. package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +43 -2
  355. package/src/resources/extensions/gsd/tests/db-authority-regression.test.ts +208 -0
  356. package/src/resources/extensions/gsd/tests/db-writer.test.ts +13 -8
  357. package/src/resources/extensions/gsd/tests/decisions-projection-from-memories.test.ts +453 -0
  358. package/src/resources/extensions/gsd/tests/decisions-stop-table-writes.test.ts +348 -0
  359. package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +59 -2
  360. package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +39 -0
  361. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +27 -0
  362. package/src/resources/extensions/gsd/tests/evidence-cross-ref.test.ts +38 -0
  363. package/src/resources/extensions/gsd/tests/export-html-enhancements.test.ts +8 -0
  364. package/src/resources/extensions/gsd/tests/freeform-decisions.test.ts +8 -4
  365. package/src/resources/extensions/gsd/tests/gsd-tools.test.ts +11 -7
  366. package/src/resources/extensions/gsd/tests/guided-discuss-project-prompt-rendering.test.ts +2 -0
  367. package/src/resources/extensions/gsd/tests/guided-dispatch-root.test.ts +106 -0
  368. package/src/resources/extensions/gsd/tests/guided-flow-session-isolation.test.ts +59 -11
  369. package/src/resources/extensions/gsd/tests/guided-flow.test.ts +21 -0
  370. package/src/resources/extensions/gsd/tests/guided-tool-contract.test.ts +65 -0
  371. package/src/resources/extensions/gsd/tests/headless-milestone-parity.test.ts +7 -7
  372. package/src/resources/extensions/gsd/tests/hook-model-resolution.test.ts +5 -0
  373. package/src/resources/extensions/gsd/tests/infra-error.test.ts +2 -2
  374. package/src/resources/extensions/gsd/tests/infra-errors-cooldown.test.ts +9 -0
  375. package/src/resources/extensions/gsd/tests/integration/doctor-git.test.ts +44 -0
  376. package/src/resources/extensions/gsd/tests/integration/doctor-runtime.test.ts +20 -0
  377. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +103 -1
  378. package/src/resources/extensions/gsd/tests/integration/integration-lifecycle.test.ts +13 -5
  379. package/src/resources/extensions/gsd/tests/integration/migrate-command.test.ts +48 -3
  380. package/src/resources/extensions/gsd/tests/integration/state-machine-runtime-failures.test.ts +6 -1
  381. package/src/resources/extensions/gsd/tests/knowledge-backfill-projection.test.ts +323 -0
  382. package/src/resources/extensions/gsd/tests/knowledge-capture.test.ts +242 -0
  383. package/src/resources/extensions/gsd/tests/knowledge.test.ts +47 -2
  384. package/src/resources/extensions/gsd/tests/load-knowledge-block-rules-only.test.ts +209 -0
  385. package/src/resources/extensions/gsd/tests/memory-consolidation-scanner.test.ts +316 -0
  386. package/src/resources/extensions/gsd/tests/migrate-transformer.test.ts +5 -1
  387. package/src/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +24 -1
  388. package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +6 -1
  389. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +26 -18
  390. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +63 -2
  391. package/src/resources/extensions/gsd/tests/orphaned-worktree-audit.test.ts +121 -1
  392. package/src/resources/extensions/gsd/tests/park-db-sync.test.ts +55 -1
  393. package/src/resources/extensions/gsd/tests/pending-autostart-scope.test.ts +29 -5
  394. package/src/resources/extensions/gsd/tests/plan-milestone-sketch-render.test.ts +157 -0
  395. package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +26 -0
  396. package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +2 -0
  397. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +225 -1
  398. package/src/resources/extensions/gsd/tests/plan-task.test.ts +17 -0
  399. package/src/resources/extensions/gsd/tests/post-exec-retry-bypass.test.ts +79 -1
  400. package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +86 -0
  401. package/src/resources/extensions/gsd/tests/post-unit-git-failure.test.ts +1 -1
  402. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +53 -0
  403. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +8 -0
  404. package/src/resources/extensions/gsd/tests/prompt-loader.test.ts +23 -0
  405. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +20 -1
  406. package/src/resources/extensions/gsd/tests/provider-switch-observer.test.ts +252 -0
  407. package/src/resources/extensions/gsd/tests/remediation-completion-guard.test.ts +46 -2
  408. package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +16 -4
  409. package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +10 -0
  410. package/src/resources/extensions/gsd/tests/smart-entry-routing.test.ts +113 -0
  411. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +53 -2
  412. package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +6 -0
  413. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +119 -23
  414. package/src/resources/extensions/gsd/tests/stuck-state-via-db.test.ts +64 -1
  415. package/src/resources/extensions/gsd/tests/summary-render-parity.test.ts +7 -3
  416. package/src/resources/extensions/gsd/tests/unit-context-manifest.test.ts +86 -7
  417. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +110 -1
  418. package/src/resources/extensions/gsd/tests/verification-verdict.test.ts +78 -0
  419. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +1 -1
  420. package/src/resources/extensions/gsd/tests/workflow-memory-pressure.test.ts +21 -1
  421. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +1 -1
  422. package/src/resources/extensions/gsd/tests/worktree-git-pathspec.test.ts +39 -0
  423. package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +64 -12
  424. package/src/resources/extensions/gsd/tests/worktree-lifecycle.test.ts +25 -0
  425. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +54 -0
  426. package/src/resources/extensions/gsd/tools/complete-milestone.ts +8 -10
  427. package/src/resources/extensions/gsd/tools/complete-slice.ts +6 -8
  428. package/src/resources/extensions/gsd/tools/plan-milestone.ts +5 -1
  429. package/src/resources/extensions/gsd/tools/plan-slice.ts +98 -12
  430. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +135 -0
  431. package/src/resources/extensions/gsd/types.ts +1 -1
  432. package/src/resources/extensions/gsd/unit-context-manifest.ts +47 -11
  433. package/src/resources/extensions/gsd/validation.ts +23 -1
  434. package/src/resources/extensions/gsd/verification-gate.ts +78 -6
  435. package/src/resources/extensions/gsd/verification-verdict.ts +47 -0
  436. package/src/resources/extensions/gsd/workflow-logger.ts +4 -0
  437. package/src/resources/extensions/gsd/workflow-projections.ts +6 -8
  438. package/src/resources/extensions/gsd/worktree-lifecycle.ts +61 -10
  439. package/src/resources/extensions/shared/html-shell.ts +412 -0
  440. package/src/resources/extensions/subagent/index.ts +567 -103
  441. package/src/resources/extensions/subagent/launch.ts +131 -0
  442. package/src/resources/extensions/subagent/run-store.ts +218 -0
  443. package/src/resources/extensions/subagent/tests/launch.test.ts +115 -0
  444. package/src/resources/extensions/subagent/tests/run-store.test.ts +111 -0
  445. package/src/resources/extensions/visual-brief/artifact-policy.ts +41 -0
  446. package/src/resources/extensions/visual-brief/extension-manifest.json +8 -0
  447. package/src/resources/extensions/visual-brief/index.ts +8 -0
  448. package/src/resources/extensions/visual-brief/page-contract.ts +136 -0
  449. package/src/resources/extensions/visual-brief/prompts.ts +183 -0
  450. package/src/resources/extensions/visual-brief/tests/visual-brief.test.ts +212 -0
  451. package/dist/web/standalone/.next/server/chunks/5822.js +0 -2
  452. package/dist/web/standalone/.next/static/chunks/2556.0527fea66e123b7f.js +0 -1
  453. package/dist/web/standalone/.next/static/chunks/app/layout-a16c7a7ecdf0c2cf.js +0 -1
  454. package/dist/web/standalone/.next/static/css/54ec2745c1da488b.css +0 -1
  455. package/dist/web/standalone/.next/static/css/de70bee13400563f.css +0 -1
  456. package/dist/web/standalone/.next/static/media/4cf2300e9c8272f7-s.p.woff2 +0 -0
  457. package/dist/web/standalone/.next/static/media/747892c23ea88013-s.woff2 +0 -0
  458. package/dist/web/standalone/.next/static/media/8d697b304b401681-s.woff2 +0 -0
  459. package/dist/web/standalone/.next/static/media/93f479601ee12b01-s.p.woff2 +0 -0
  460. package/dist/web/standalone/.next/static/media/9610d9e46709d722-s.woff2 +0 -0
  461. package/dist/web/standalone/.next/static/media/ba015fad6dcf6784-s.woff2 +0 -0
  462. /package/dist/web/standalone/.next/static/{rIkMv4YSNlfSeqmGqWVns → xRy4LqKSNKdT7y6ATYyEl}/_buildManifest.js +0 -0
  463. /package/dist/web/standalone/.next/static/{rIkMv4YSNlfSeqmGqWVns → xRy4LqKSNKdT7y6ATYyEl}/_ssgManifest.js +0 -0
@@ -123,9 +123,9 @@ export function buildSystemPrompt(options = {}) {
123
123
  else if (hasBash && (hasGrep || hasFind || hasLs)) {
124
124
  addGuideline("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
125
125
  }
126
- // Read before edit guideline
127
- if (hasRead && hasEdit) {
128
- addGuideline("Use read to examine files before editing. You must use this tool instead of cat or sed.");
126
+ // Read before file mutation guideline
127
+ if (hasRead && (hasEdit || hasWrite)) {
128
+ addGuideline("Use read to examine relevant existing files before editing or overwriting. Before write creates or replaces a file, verify the target path; if it exists, read it first. Use read instead of cat or sed for file inspection.");
129
129
  }
130
130
  // Edit guideline
131
131
  if (hasEdit) {
@@ -133,7 +133,7 @@ export function buildSystemPrompt(options = {}) {
133
133
  }
134
134
  // Write guideline
135
135
  if (hasWrite) {
136
- addGuideline("Use write only for new files or complete rewrites");
136
+ addGuideline("Use write only for new files or complete rewrites after verifying the target path");
137
137
  }
138
138
  // LSP guideline
139
139
  if (hasLsp) {
@@ -1 +1 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CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2FAA2F;IAC3F,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/**\n\t * Optional predicate applied to the `skills` list before rendering the\n\t * <available_skills> catalog. Returning `false` omits a skill from the\n\t * prompt (the skill remains loaded and invocable by name — only the\n\t * catalog listing is suppressed).\n\t *\n\t * Intended for consumers that can narrow the relevant skill surface\n\t * (e.g. per-unit-type manifests) to reduce cached system-prompt bloat.\n\t * When omitted, all non-`disableModelInvocation` skills render — i.e.\n\t * behavior is unchanged from before this option existed.\n\t *\n\t * Contract: the predicate must be **pure and synchronous**. It may be\n\t * invoked on every system-prompt rebuild (tool-set changes and\n\t * runtime resource-loader extensions both trigger one), so any state\n\t * the closure captures should be stable across the rebuild window.\n\t * If the predicate throws, `buildSystemPrompt` logs a warning and\n\t * falls back to the unfiltered skill list — callers never see the\n\t * exception and the session stays consistent.\n\t */\n\tskillFilter?: (skill: Skill) => boolean;\n\t/**\n\t * Append a `Current date and time: <toLocaleString>` line to the system\n\t * prompt. Default: `false`.\n\t *\n\t * Provider prompt caches generally depend on stable prompt prefixes.\n\t * Embedding a per-call timestamp in the system prompt invalidates that\n\t * stability on every request, often forcing full prompt reprocessing.\n\t * Most agentic flows do not need wall-clock awareness in the system\n\t * prompt — opt in only when the consumer genuinely needs it, and inject\n\t * it via a non-cached channel (user message) when possible.\n\t */\n\tincludeDateTime?: boolean;\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tskillFilter,\n\t\tincludeDateTime = false,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\t// Per-call timestamps invalidate provider prompt cache stability. Compute\n\t// lazily and only when explicitly opted in via `includeDateTime`.\n\tconst dateTimeLine = includeDateTime\n\t\t? `\\nCurrent date and time: ${new Date().toLocaleString(\"en-US\", {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"2-digit\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t\ttimeZoneName: \"short\",\n\t\t})}`\n\t\t: \"\";\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skillsBase = providedSkills ?? [];\n\tlet skills = skillsBase;\n\tif (skillFilter) {\n\t\ttry {\n\t\t\tskills = skillsBase.filter(skillFilter);\n\t\t} catch (error) {\n\t\t\t// A consumer's predicate threw. Fall back to the unfiltered list so\n\t\t\t// the session stays consistent — callers (e.g. AgentSession.setTools)\n\t\t\t// must not be left with updated tools but a stale system prompt.\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconsole.warn(`buildSystemPrompt: skillFilter threw; falling back to unfiltered skills. Error: ${message}`);\n\t\t\tskills = skillsBase;\n\t\t}\n\t}\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\t\tprompt += dateTimeLine;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = toPosixPath(getReadmePath());\n\tconst docsPath = toPosixPath(getDocsPath());\n\tconst examplesPath = toPosixPath(getExamplesPath());\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\tprompt += dateTimeLine;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAA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,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2FAA2F;IAC3F,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/**\n\t * Optional predicate applied to the `skills` list before rendering the\n\t * <available_skills> catalog. Returning `false` omits a skill from the\n\t * prompt (the skill remains loaded and invocable by name — only the\n\t * catalog listing is suppressed).\n\t *\n\t * Intended for consumers that can narrow the relevant skill surface\n\t * (e.g. per-unit-type manifests) to reduce cached system-prompt bloat.\n\t * When omitted, all non-`disableModelInvocation` skills render — i.e.\n\t * behavior is unchanged from before this option existed.\n\t *\n\t * Contract: the predicate must be **pure and synchronous**. It may be\n\t * invoked on every system-prompt rebuild (tool-set changes and\n\t * runtime resource-loader extensions both trigger one), so any state\n\t * the closure captures should be stable across the rebuild window.\n\t * If the predicate throws, `buildSystemPrompt` logs a warning and\n\t * falls back to the unfiltered skill list — callers never see the\n\t * exception and the session stays consistent.\n\t */\n\tskillFilter?: (skill: Skill) => boolean;\n\t/**\n\t * Append a `Current date and time: <toLocaleString>` line to the system\n\t * prompt. Default: `false`.\n\t *\n\t * Provider prompt caches generally depend on stable prompt prefixes.\n\t * Embedding a per-call timestamp in the system prompt invalidates that\n\t * stability on every request, often forcing full prompt reprocessing.\n\t * Most agentic flows do not need wall-clock awareness in the system\n\t * prompt — opt in only when the consumer genuinely needs it, and inject\n\t * it via a non-cached channel (user message) when possible.\n\t */\n\tincludeDateTime?: boolean;\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tskillFilter,\n\t\tincludeDateTime = false,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\t// Per-call timestamps invalidate provider prompt cache stability. Compute\n\t// lazily and only when explicitly opted in via `includeDateTime`.\n\tconst dateTimeLine = includeDateTime\n\t\t? `\\nCurrent date and time: ${new Date().toLocaleString(\"en-US\", {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"2-digit\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t\ttimeZoneName: \"short\",\n\t\t})}`\n\t\t: \"\";\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skillsBase = providedSkills ?? [];\n\tlet skills = skillsBase;\n\tif (skillFilter) {\n\t\ttry {\n\t\t\tskills = skillsBase.filter(skillFilter);\n\t\t} catch (error) {\n\t\t\t// A consumer's predicate threw. Fall back to the unfiltered list so\n\t\t\t// the session stays consistent — callers (e.g. AgentSession.setTools)\n\t\t\t// must not be left with updated tools but a stale system prompt.\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconsole.warn(`buildSystemPrompt: skillFilter threw; falling back to unfiltered skills. Error: ${message}`);\n\t\t\tskills = skillsBase;\n\t\t}\n\t}\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\t\tprompt += dateTimeLine;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = toPosixPath(getReadmePath());\n\tconst docsPath = toPosixPath(getDocsPath());\n\tconst examplesPath = toPosixPath(getExamplesPath());\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\t// Read before file mutation guideline\n\tif (hasRead && (hasEdit || hasWrite)) {\n\t\taddGuideline(\"Use read to examine relevant existing files before editing or overwriting. Before write creates or replaces a file, verify the target path; if it exists, read it first. Use read instead of cat or sed for file inspection.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites after verifying the target path\");\n\t}\n\n\t// LSP guideline\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t`Use lsp as the primary tool for code navigation in typed codebases:\n- Navigation: definition, type_definition, implementation, references, incoming_calls, outgoing_calls\n- Understanding: hover (types + docs), signature (parameter info), symbols (file/workspace search)\n- Refactoring: rename (project-wide), code_actions (quick-fixes, imports, refactors), format (formatter)\n- Verification: diagnostics after edits to catch type errors immediately\n- Never grep for a symbol definition when lsp can resolve it semantically\n- Never shell out to a formatter when lsp format is available`,\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time (only when opted in — see includeDateTime docs) and working directory last\n\tprompt += dateTimeLine;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC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}
@@ -15,6 +15,19 @@ function sanitizeStatusText(text) {
15
15
  .replace(/ +/g, " ")
16
16
  .trim();
17
17
  }
18
+ function truncateFooterPath(text, width) {
19
+ if (visibleWidth(text) <= width)
20
+ return text;
21
+ const tailMatch = text.match(/( \([^)]+\)(?: • .*)?)$/);
22
+ if (!tailMatch)
23
+ return truncateToWidth(text, width, "...");
24
+ const tail = tailMatch[1];
25
+ const tailWidth = visibleWidth(tail);
26
+ if (tailWidth >= width - 4)
27
+ return truncateToWidth(text, width, "...");
28
+ const head = text.slice(0, -tail.length);
29
+ return `${truncateToWidth(head, width - tailWidth, "...")}${tail}`;
30
+ }
18
31
  /**
19
32
  * Format token counts (similar to web-ui)
20
33
  */
@@ -197,9 +210,6 @@ export class FooterComponent {
197
210
  }
198
211
  }
199
212
  }
200
- // Apply dim to the stats group before handing it to the shared footer strip.
201
- // statsLeft may contain color codes for context %, so keep coloring local to the group.
202
- const dimStatsLeft = theme.fg("dim", statsLeft);
203
213
  // Extension statuses right-aligned on the pwd line (sorted by key).
204
214
  // Keeps the footer compact by avoiding a dedicated row when the content
205
215
  // fits alongside pwd. Falls back to pwd-only if the combined line would
@@ -211,12 +221,20 @@ export class FooterComponent {
211
221
  .map(([, text]) => sanitizeStatusText(text))
212
222
  .join(" ")
213
223
  : "";
224
+ const footerRight = [rightSide, extStatusText].filter(Boolean).join(" ");
225
+ const gsdSegment = theme.fg("accent", "● GSD");
226
+ const dimStatsLeft = theme.fg("dim", statsLeft);
227
+ const innerWidth = Math.max(1, width - 2);
228
+ const rightWidth = visibleWidth(footerRight);
229
+ const leftBudget = footerRight ? Math.max(1, innerWidth - rightWidth - 3) : innerWidth;
230
+ const sepWidth = visibleWidth(" │ ");
231
+ const pwdBudget = Math.max(1, leftBudget - visibleWidth(gsdSegment) - visibleWidth(dimStatsLeft) - sepWidth * 2);
232
+ const pwdSegment = theme.fg("dim", truncateFooterPath(pwd, pwdBudget));
214
233
  const leftSegments = [
215
- theme.fg("accent", "● GSD"),
216
- theme.fg("dim", pwd),
234
+ gsdSegment,
235
+ pwdSegment,
217
236
  dimStatsLeft,
218
237
  ];
219
- const footerRight = [rightSide, extStatusText].filter(Boolean).join(" ");
220
238
  return renderFooterStrip(leftSegments, footerRight, width);
221
239
  }
222
240
  }
@@ -1 +1 @@
1
- {"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,iHAAiH;AAEjH,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG5E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACvC,qFAAqF;IACrF,OAAO,IAAI;SACT,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;SACzB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,IAAI,EAAE,CAAC;AACV,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,KAAa;IAClC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1C,IAAI,KAAK,GAAG,KAAK;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1D,IAAI,KAAK,GAAG,OAAO;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3D,IAAI,KAAK,GAAG,QAAQ;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAChE,OAAO,GAAG,IAAI,CAAC,KAAK,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AAG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAEhD,oEAAoE;QACpE,wEAAwE;QACxE,wEAAwE;QACxE,gBAAgB;QAChB,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC;QACjE,MAAM,aAAa,GAClB,iBAAiB,CAAC,IAAI,GAAG,CAAC;YACzB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;iBACtC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;iBACtC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;iBAC3C,IAAI,CAAC,GAAG,CAAC;YACZ,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,YAAY,GAAG;YACpB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;YAC3B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC;YACpB,YAAY;SACZ,CAAC;QACF,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzE,OAAO,iBAAiB,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["// Project/App: GSD-2\n// File Purpose: Interactive terminal footer renderer for workspace, model, usage, context, and extension status.\n\nimport { type Component, truncateToWidth, visibleWidth } from \"@gsd/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.js\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { providerAuthBadge, providerDisplayName } from \"./model-selector.js\";\nimport { renderFooterStrip } from \"./transcript-design.js\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts (similar to web-ui)\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\n/**\n * Format a cost value for compact display.\n * Uses fewer decimal places for larger amounts.\n * @internal Exported for testing only.\n */\nexport function formatPromptCost(cost: number): string {\n\tif (cost < 0.001) return `$${cost.toFixed(4)}`;\n\tif (cost < 0.01) return `$${cost.toFixed(3)}`;\n\tif (cost < 1) return `$${cost.toFixed(3)}`;\n\treturn `$${cost.toFixed(2)}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\n\tconstructor(\n\t\tprivate session: AgentSession,\n\t\tprivate footerData: ReadonlyFooterDataProvider,\n\t) {}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\n\t\tconst usageTotals = this.session.sessionManager.getUsageTotals();\n\t\tconst totalInput = usageTotals.input;\n\t\tconst totalOutput = usageTotals.output;\n\t\tconst totalCacheRead = usageTotals.cacheRead;\n\t\tconst totalCacheWrite = usageTotals.cacheWrite;\n\t\tconst totalCost = usageTotals.cost;\n\n\t\t// Use activeInferenceModel during streaming to show the model actually\n\t\t// being used, not the configured model which may have been switched mid-turn.\n\t\tconst displayModel = state.activeInferenceModel ?? state.model;\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextWindow = contextUsage?.contextWindow ?? displayModel?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = process.cwd();\n\t\tconst home = process.env.HOME || process.env.USERPROFILE;\n\t\tif (home && pwd.startsWith(home)) {\n\t\t\tpwd = `~${pwd.slice(home.length)}`;\n\t\t}\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line as separate groups joined by a dim middle-dot separator\n\t\tconst sep = ` ${theme.fg(\"dim\", \"\\u00B7\")} `;\n\n\t\t// Group 1: total tokens.\n\t\tconst tokenGroup: string[] = [];\n\t\tconst totalTokens = totalInput + totalOutput + totalCacheRead + totalCacheWrite;\n\t\tif (totalTokens > 0) tokenGroup.push(formatTokens(totalTokens));\n\n\t\t// Group 2: cache efficiency — cacheRead / all input-side tokens.\n\t\t// Collapses the old cr/cw pair into a single \"how much was served\n\t\t// from cache\" signal. cr/cw breakdown moved to `/stats`.\n\t\tconst cacheGroup: string[] = [];\n\t\tconst inputSide = totalInput + totalCacheRead + totalCacheWrite;\n\t\tif (totalCacheRead > 0 && inputSide > 0) {\n\t\t\tconst cachedPct = Math.round((totalCacheRead / inputSide) * 100);\n\t\t\tcacheGroup.push(`${cachedPct}% cached`);\n\t\t}\n\n\t\t// Group 3: cost\n\t\tconst costGroup: string[] = [];\n\t\tconst usingSubscription = displayModel ? this.session.modelRegistry.isUsingOAuth(displayModel) : false;\n\t\tif (totalCost || usingSubscription) {\n\t\t\tconst costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tcostGroup.push(costStr);\n\t\t}\n\n\t\t// Per-prompt cost annotation (opt-in via show_token_cost preference, #1515)\n\t\tif (process.env.GSD_SHOW_TOKEN_COST === \"1\") {\n\t\t\tconst lastTurnCost = this.session.getLastTurnCost();\n\t\t\tif (lastTurnCost > 0) {\n\t\t\t\tcostGroup.push(`(last: ${formatPromptCost(lastTurnCost)})`);\n\t\t\t}\n\t\t}\n\n\t\t// Group 4: context bar + percentage (mirrors /gsd auto dashboard style).\n\t\t// Bar colors track the same thresholds as the percent text.\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst barColor: \"error\" | \"warning\" | \"success\" =\n\t\t\tcontextPercentValue > 90 ? \"error\" : contextPercentValue > 70 ? \"warning\" : \"success\";\n\t\tconst BAR_WIDTH = 8;\n\t\tconst filled = contextUsage?.percent !== null\n\t\t\t? Math.max(0, Math.min(BAR_WIDTH, Math.round((contextPercentValue / 100) * BAR_WIDTH)))\n\t\t\t: 0;\n\t\tconst bar =\n\t\t\ttheme.fg(barColor, \"█\".repeat(filled)) +\n\t\t\ttheme.fg(\"dim\", \"░\".repeat(Math.max(0, BAR_WIDTH - filled)));\n\t\tconst pctText = contextPercent === \"?\" ? \"?\" : `${contextPercent}%`;\n\t\tconst suffix = `/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tconst colorizedPct =\n\t\t\tcontextPercentValue > 90\n\t\t\t\t? theme.fg(\"error\", pctText)\n\t\t\t\t: contextPercentValue > 70\n\t\t\t\t\t? theme.fg(\"warning\", pctText)\n\t\t\t\t\t: pctText;\n\t\tconst contextPercentStr = `${bar} ${colorizedPct}${suffix}`;\n\n\t\t// Assemble groups: items within a group are space-separated,\n\t\t// groups are separated by a dim middle-dot\n\t\tconst groups: string[] = [];\n\t\tif (tokenGroup.length > 0) groups.push(tokenGroup.join(\" \"));\n\t\tif (cacheGroup.length > 0) groups.push(cacheGroup.join(\" \"));\n\t\tif (costGroup.length > 0) groups.push(costGroup.join(\" \"));\n\t\tgroups.push(contextPercentStr);\n\n\t\tlet statsLeft = groups.join(sep);\n\n\t\t// Add model name on the right side, plus thinking level if model supports it\n\t\tconst modelName = displayModel?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (displayModel?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room.\n\t\t// Include the auth mode so users can tell at a glance whether the active model is\n\t\t// API-key-backed, OAuth-backed, or delegated to a third-party CLI.\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && displayModel) {\n\t\t\tconst authMode = this.session.modelRegistry.getProviderAuthMode(displayModel.provider);\n\t\t\tconst authLabel = providerAuthBadge(authMode);\n\t\t\tconst providerLabel = providerDisplayName(displayModel.provider);\n\t\t\tconst parenthetical = authLabel ? `${providerLabel} · ${authLabel}` : providerLabel;\n\t\t\trightSide = `(${parenthetical}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide: drop the auth suffix first, then fall back to no parenthetical.\n\t\t\t\trightSide = `(${providerLabel}) ${rightSideWithoutProvider}`;\n\t\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Apply dim to the stats group before handing it to the shared footer strip.\n\t\t// statsLeft may contain color codes for context %, so keep coloring local to the group.\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\n\t\t// Extension statuses right-aligned on the pwd line (sorted by key).\n\t\t// Keeps the footer compact by avoiding a dedicated row when the content\n\t\t// fits alongside pwd. Falls back to pwd-only if the combined line would\n\t\t// exceed width.\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tconst extStatusText =\n\t\t\textensionStatuses.size > 0\n\t\t\t\t? Array.from(extensionStatuses.entries())\n\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t.map(([, text]) => sanitizeStatusText(text))\n\t\t\t\t\t\t.join(\" \")\n\t\t\t\t: \"\";\n\n\t\tconst leftSegments = [\n\t\t\ttheme.fg(\"accent\", \"● GSD\"),\n\t\t\ttheme.fg(\"dim\", pwd),\n\t\t\tdimStatsLeft,\n\t\t];\n\t\tconst footerRight = [rightSide, extStatusText].filter(Boolean).join(\" \");\n\t\treturn renderFooterStrip(leftSegments, footerRight, width);\n\t}\n}\n"]}
1
+ {"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AA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AU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACvF,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;QACjH,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;QAEvE,MAAM,YAAY,GAAG;YACpB,UAAU;YACV,UAAU;YACV,YAAY;SACZ,CAAC;QACF,OAAO,iBAAiB,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["// Project/App: GSD-2\n// File Purpose: Interactive terminal footer renderer for workspace, model, usage, context, and extension status.\n\nimport { type Component, truncateToWidth, visibleWidth } from \"@gsd/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.js\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { providerAuthBadge, providerDisplayName } from \"./model-selector.js\";\nimport { renderFooterStrip } from \"./transcript-design.js\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\nfunction truncateFooterPath(text: string, width: number): string {\n\tif (visibleWidth(text) <= width) return text;\n\tconst tailMatch = text.match(/( \\([^)]+\\)(?: • .*)?)$/);\n\tif (!tailMatch) return truncateToWidth(text, width, \"...\");\n\tconst tail = tailMatch[1];\n\tconst tailWidth = visibleWidth(tail);\n\tif (tailWidth >= width - 4) return truncateToWidth(text, width, \"...\");\n\tconst head = text.slice(0, -tail.length);\n\treturn `${truncateToWidth(head, width - tailWidth, \"...\")}${tail}`;\n}\n\n/**\n * Format token counts (similar to web-ui)\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\n/**\n * Format a cost value for compact display.\n * Uses fewer decimal places for larger amounts.\n * @internal Exported for testing only.\n */\nexport function formatPromptCost(cost: number): string {\n\tif (cost < 0.001) return `$${cost.toFixed(4)}`;\n\tif (cost < 0.01) return `$${cost.toFixed(3)}`;\n\tif (cost < 1) return `$${cost.toFixed(3)}`;\n\treturn `$${cost.toFixed(2)}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\n\tconstructor(\n\t\tprivate session: AgentSession,\n\t\tprivate footerData: ReadonlyFooterDataProvider,\n\t) {}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\n\t\tconst usageTotals = this.session.sessionManager.getUsageTotals();\n\t\tconst totalInput = usageTotals.input;\n\t\tconst totalOutput = usageTotals.output;\n\t\tconst totalCacheRead = usageTotals.cacheRead;\n\t\tconst totalCacheWrite = usageTotals.cacheWrite;\n\t\tconst totalCost = usageTotals.cost;\n\n\t\t// Use activeInferenceModel during streaming to show the model actually\n\t\t// being used, not the configured model which may have been switched mid-turn.\n\t\tconst displayModel = state.activeInferenceModel ?? state.model;\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextWindow = contextUsage?.contextWindow ?? displayModel?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = process.cwd();\n\t\tconst home = process.env.HOME || process.env.USERPROFILE;\n\t\tif (home && pwd.startsWith(home)) {\n\t\t\tpwd = `~${pwd.slice(home.length)}`;\n\t\t}\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line as separate groups joined by a dim middle-dot separator\n\t\tconst sep = ` ${theme.fg(\"dim\", \"\\u00B7\")} `;\n\n\t\t// Group 1: total tokens.\n\t\tconst tokenGroup: string[] = [];\n\t\tconst totalTokens = totalInput + totalOutput + totalCacheRead + totalCacheWrite;\n\t\tif (totalTokens > 0) tokenGroup.push(formatTokens(totalTokens));\n\n\t\t// Group 2: cache efficiency — cacheRead / all input-side tokens.\n\t\t// Collapses the old cr/cw pair into a single \"how much was served\n\t\t// from cache\" signal. cr/cw breakdown moved to `/stats`.\n\t\tconst cacheGroup: string[] = [];\n\t\tconst inputSide = totalInput + totalCacheRead + totalCacheWrite;\n\t\tif (totalCacheRead > 0 && inputSide > 0) {\n\t\t\tconst cachedPct = Math.round((totalCacheRead / inputSide) * 100);\n\t\t\tcacheGroup.push(`${cachedPct}% cached`);\n\t\t}\n\n\t\t// Group 3: cost\n\t\tconst costGroup: string[] = [];\n\t\tconst usingSubscription = displayModel ? this.session.modelRegistry.isUsingOAuth(displayModel) : false;\n\t\tif (totalCost || usingSubscription) {\n\t\t\tconst costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tcostGroup.push(costStr);\n\t\t}\n\n\t\t// Per-prompt cost annotation (opt-in via show_token_cost preference, #1515)\n\t\tif (process.env.GSD_SHOW_TOKEN_COST === \"1\") {\n\t\t\tconst lastTurnCost = this.session.getLastTurnCost();\n\t\t\tif (lastTurnCost > 0) {\n\t\t\t\tcostGroup.push(`(last: ${formatPromptCost(lastTurnCost)})`);\n\t\t\t}\n\t\t}\n\n\t\t// Group 4: context bar + percentage (mirrors /gsd auto dashboard style).\n\t\t// Bar colors track the same thresholds as the percent text.\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst barColor: \"error\" | \"warning\" | \"success\" =\n\t\t\tcontextPercentValue > 90 ? \"error\" : contextPercentValue > 70 ? \"warning\" : \"success\";\n\t\tconst BAR_WIDTH = 8;\n\t\tconst filled = contextUsage?.percent !== null\n\t\t\t? Math.max(0, Math.min(BAR_WIDTH, Math.round((contextPercentValue / 100) * BAR_WIDTH)))\n\t\t\t: 0;\n\t\tconst bar =\n\t\t\ttheme.fg(barColor, \"█\".repeat(filled)) +\n\t\t\ttheme.fg(\"dim\", \"░\".repeat(Math.max(0, BAR_WIDTH - filled)));\n\t\tconst pctText = contextPercent === \"?\" ? \"?\" : `${contextPercent}%`;\n\t\tconst suffix = `/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tconst colorizedPct =\n\t\t\tcontextPercentValue > 90\n\t\t\t\t? theme.fg(\"error\", pctText)\n\t\t\t\t: contextPercentValue > 70\n\t\t\t\t\t? theme.fg(\"warning\", pctText)\n\t\t\t\t\t: pctText;\n\t\tconst contextPercentStr = `${bar} ${colorizedPct}${suffix}`;\n\n\t\t// Assemble groups: items within a group are space-separated,\n\t\t// groups are separated by a dim middle-dot\n\t\tconst groups: string[] = [];\n\t\tif (tokenGroup.length > 0) groups.push(tokenGroup.join(\" \"));\n\t\tif (cacheGroup.length > 0) groups.push(cacheGroup.join(\" \"));\n\t\tif (costGroup.length > 0) groups.push(costGroup.join(\" \"));\n\t\tgroups.push(contextPercentStr);\n\n\t\tlet statsLeft = groups.join(sep);\n\n\t\t// Add model name on the right side, plus thinking level if model supports it\n\t\tconst modelName = displayModel?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (displayModel?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room.\n\t\t// Include the auth mode so users can tell at a glance whether the active model is\n\t\t// API-key-backed, OAuth-backed, or delegated to a third-party CLI.\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && displayModel) {\n\t\t\tconst authMode = this.session.modelRegistry.getProviderAuthMode(displayModel.provider);\n\t\t\tconst authLabel = providerAuthBadge(authMode);\n\t\t\tconst providerLabel = providerDisplayName(displayModel.provider);\n\t\t\tconst parenthetical = authLabel ? `${providerLabel} · ${authLabel}` : providerLabel;\n\t\t\trightSide = `(${parenthetical}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide: drop the auth suffix first, then fall back to no parenthetical.\n\t\t\t\trightSide = `(${providerLabel}) ${rightSideWithoutProvider}`;\n\t\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Extension statuses right-aligned on the pwd line (sorted by key).\n\t\t// Keeps the footer compact by avoiding a dedicated row when the content\n\t\t// fits alongside pwd. Falls back to pwd-only if the combined line would\n\t\t// exceed width.\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tconst extStatusText =\n\t\t\textensionStatuses.size > 0\n\t\t\t\t? Array.from(extensionStatuses.entries())\n\t\t\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t\t\t.map(([, text]) => sanitizeStatusText(text))\n\t\t\t\t\t\t.join(\" \")\n\t\t\t\t: \"\";\n\n\t\tconst footerRight = [rightSide, extStatusText].filter(Boolean).join(\" \");\n\t\tconst gsdSegment = theme.fg(\"accent\", \"● GSD\");\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\t\tconst innerWidth = Math.max(1, width - 2);\n\t\tconst rightWidth = visibleWidth(footerRight);\n\t\tconst leftBudget = footerRight ? Math.max(1, innerWidth - rightWidth - 3) : innerWidth;\n\t\tconst sepWidth = visibleWidth(\" │ \");\n\t\tconst pwdBudget = Math.max(1, leftBudget - visibleWidth(gsdSegment) - visibleWidth(dimStatsLeft) - sepWidth * 2);\n\t\tconst pwdSegment = theme.fg(\"dim\", truncateFooterPath(pwd, pwdBudget));\n\n\t\tconst leftSegments = [\n\t\t\tgsdSegment,\n\t\t\tpwdSegment,\n\t\t\tdimStatsLeft,\n\t\t];\n\t\treturn renderFooterStrip(leftSegments, footerRight, width);\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=system-prompt-file-safety.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt-file-safety.test.d.ts","sourceRoot":"","sources":["../../src/tests/system-prompt-file-safety.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ // GSD-2 pi-coding-agent system prompt file-safety regression tests.
2
+ import test from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { buildSystemPrompt } from "../core/system-prompt.js";
5
+ test("buildSystemPrompt: read and write tools require reading before overwrite", () => {
6
+ const prompt = buildSystemPrompt({ selectedTools: ["read", "write"] });
7
+ assert.match(prompt, /before editing or overwriting/i);
8
+ assert.match(prompt, /Before write creates or replaces a file, verify the target path/i);
9
+ assert.match(prompt, /if it exists, read it first/i);
10
+ assert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);
11
+ });
12
+ test("buildSystemPrompt: write-only tool guidance does not reference unavailable read tool", () => {
13
+ const prompt = buildSystemPrompt({ selectedTools: ["write"] });
14
+ assert.doesNotMatch(prompt, /read it first/i);
15
+ assert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);
16
+ });
17
+ //# sourceMappingURL=system-prompt-file-safety.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt-file-safety.test.js","sourceRoot":"","sources":["../../src/tests/system-prompt-file-safety.test.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,IAAI,CAAC,0EAA0E,EAAE,GAAG,EAAE;IACrF,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAEvE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,kEAAkE,CAAC,CAAC;IACzF,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAC;IACrD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,oFAAoF,CAAC,CAAC;AAC5G,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sFAAsF,EAAE,GAAG,EAAE;IACjG,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAE/D,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,oFAAoF,CAAC,CAAC;AAC5G,CAAC,CAAC,CAAC","sourcesContent":["// GSD-2 pi-coding-agent system prompt file-safety regression tests.\n\nimport test from \"node:test\";\nimport assert from \"node:assert/strict\";\n\nimport { buildSystemPrompt } from \"../core/system-prompt.js\";\n\ntest(\"buildSystemPrompt: read and write tools require reading before overwrite\", () => {\n\tconst prompt = buildSystemPrompt({ selectedTools: [\"read\", \"write\"] });\n\n\tassert.match(prompt, /before editing or overwriting/i);\n\tassert.match(prompt, /Before write creates or replaces a file, verify the target path/i);\n\tassert.match(prompt, /if it exists, read it first/i);\n\tassert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);\n});\n\ntest(\"buildSystemPrompt: write-only tool guidance does not reference unavailable read tool\", () => {\n\tconst prompt = buildSystemPrompt({ selectedTools: [\"write\"] });\n\n\tassert.doesNotMatch(prompt, /read it first/i);\n\tassert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);\n});\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-coding-agent",
3
- "version": "2.81.0",
3
+ "version": "2.82.0",
4
4
  "description": "Coding agent CLI (vendored from pi-mono)",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -0,0 +1,79 @@
1
+ // Regression test for #5102: disabling thinking on one reasoning-capable
2
+ // model must not silently persist "off" as the global default.
3
+
4
+ import assert from "node:assert/strict";
5
+ import { mkdtempSync, rmSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { afterEach, beforeEach, describe, it } from "node:test";
9
+
10
+ import { Agent } from "@gsd/pi-agent-core";
11
+ import { getModel } from "@gsd/pi-ai";
12
+ import { AgentSession } from "./agent-session.js";
13
+ import { AuthStorage } from "./auth-storage.js";
14
+ import { ModelRegistry } from "./model-registry.js";
15
+ import { DefaultResourceLoader } from "./resource-loader.js";
16
+ import { SessionManager } from "./session-manager.js";
17
+ import { SettingsManager } from "./settings-manager.js";
18
+
19
+ let testDir: string;
20
+
21
+ async function createSession(): Promise<{ session: AgentSession; settingsManager: SettingsManager }> {
22
+ const agentDir = join(testDir, "agent-home");
23
+ const authStorage = AuthStorage.inMemory({});
24
+ const modelRegistry = new ModelRegistry(authStorage, join(agentDir, "models.json"));
25
+ const settingsManager = SettingsManager.inMemory({ defaultThinkingLevel: "high" });
26
+ const resourceLoader = new DefaultResourceLoader({
27
+ cwd: testDir,
28
+ agentDir,
29
+ settingsManager,
30
+ noExtensions: true,
31
+ noPromptTemplates: true,
32
+ noThemes: true,
33
+ });
34
+ await resourceLoader.reload();
35
+
36
+ const session = new AgentSession({
37
+ agent: new Agent({
38
+ initialState: {
39
+ model: getModel("zai", "glm-5.1" as any),
40
+ thinkingLevel: "high",
41
+ },
42
+ }),
43
+ sessionManager: SessionManager.inMemory(testDir),
44
+ settingsManager,
45
+ cwd: testDir,
46
+ resourceLoader,
47
+ modelRegistry,
48
+ });
49
+
50
+ return { session, settingsManager };
51
+ }
52
+
53
+ describe("AgentSession thinking level persistence", () => {
54
+ beforeEach(() => {
55
+ testDir = mkdtempSync(join(tmpdir(), "agent-session-thinking-level-"));
56
+ });
57
+
58
+ afterEach(() => {
59
+ rmSync(testDir, { recursive: true, force: true });
60
+ });
61
+
62
+ it("does not persist off as the global default for reasoning-capable models", async () => {
63
+ const { session, settingsManager } = await createSession();
64
+
65
+ session.setThinkingLevel("off");
66
+
67
+ assert.equal(session.thinkingLevel, "off");
68
+ assert.equal(settingsManager.getDefaultThinkingLevel(), "high");
69
+ });
70
+
71
+ it("still persists non-off thinking levels as the global default", async () => {
72
+ const { session, settingsManager } = await createSession();
73
+
74
+ session.setThinkingLevel("low");
75
+
76
+ assert.equal(session.thinkingLevel, "low");
77
+ assert.equal(settingsManager.getDefaultThinkingLevel(), "low");
78
+ });
79
+ });
@@ -1945,7 +1945,7 @@ export class AgentSession {
1945
1945
 
1946
1946
  if (isChanging) {
1947
1947
  this.sessionManager.appendThinkingLevelChange(effectiveLevel);
1948
- if (this.supportsThinking() || effectiveLevel !== "off") {
1948
+ if (effectiveLevel !== "off") {
1949
1949
  this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
1950
1950
  }
1951
1951
  this._emitSessionStateChanged("set_thinking_level");
@@ -203,9 +203,9 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
203
203
  addGuideline("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
204
204
  }
205
205
 
206
- // Read before edit guideline
207
- if (hasRead && hasEdit) {
208
- addGuideline("Use read to examine files before editing. You must use this tool instead of cat or sed.");
206
+ // Read before file mutation guideline
207
+ if (hasRead && (hasEdit || hasWrite)) {
208
+ addGuideline("Use read to examine relevant existing files before editing or overwriting. Before write creates or replaces a file, verify the target path; if it exists, read it first. Use read instead of cat or sed for file inspection.");
209
209
  }
210
210
 
211
211
  // Edit guideline
@@ -215,7 +215,7 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
215
215
 
216
216
  // Write guideline
217
217
  if (hasWrite) {
218
- addGuideline("Use write only for new files or complete rewrites");
218
+ addGuideline("Use write only for new files or complete rewrites after verifying the target path");
219
219
  }
220
220
 
221
221
  // LSP guideline
@@ -20,6 +20,17 @@ function sanitizeStatusText(text: string): string {
20
20
  .trim();
21
21
  }
22
22
 
23
+ function truncateFooterPath(text: string, width: number): string {
24
+ if (visibleWidth(text) <= width) return text;
25
+ const tailMatch = text.match(/( \([^)]+\)(?: • .*)?)$/);
26
+ if (!tailMatch) return truncateToWidth(text, width, "...");
27
+ const tail = tailMatch[1];
28
+ const tailWidth = visibleWidth(tail);
29
+ if (tailWidth >= width - 4) return truncateToWidth(text, width, "...");
30
+ const head = text.slice(0, -tail.length);
31
+ return `${truncateToWidth(head, width - tailWidth, "...")}${tail}`;
32
+ }
33
+
23
34
  /**
24
35
  * Format token counts (similar to web-ui)
25
36
  */
@@ -222,10 +233,6 @@ export class FooterComponent implements Component {
222
233
  }
223
234
  }
224
235
 
225
- // Apply dim to the stats group before handing it to the shared footer strip.
226
- // statsLeft may contain color codes for context %, so keep coloring local to the group.
227
- const dimStatsLeft = theme.fg("dim", statsLeft);
228
-
229
236
  // Extension statuses right-aligned on the pwd line (sorted by key).
230
237
  // Keeps the footer compact by avoiding a dedicated row when the content
231
238
  // fits alongside pwd. Falls back to pwd-only if the combined line would
@@ -239,12 +246,21 @@ export class FooterComponent implements Component {
239
246
  .join(" ")
240
247
  : "";
241
248
 
249
+ const footerRight = [rightSide, extStatusText].filter(Boolean).join(" ");
250
+ const gsdSegment = theme.fg("accent", "● GSD");
251
+ const dimStatsLeft = theme.fg("dim", statsLeft);
252
+ const innerWidth = Math.max(1, width - 2);
253
+ const rightWidth = visibleWidth(footerRight);
254
+ const leftBudget = footerRight ? Math.max(1, innerWidth - rightWidth - 3) : innerWidth;
255
+ const sepWidth = visibleWidth(" │ ");
256
+ const pwdBudget = Math.max(1, leftBudget - visibleWidth(gsdSegment) - visibleWidth(dimStatsLeft) - sepWidth * 2);
257
+ const pwdSegment = theme.fg("dim", truncateFooterPath(pwd, pwdBudget));
258
+
242
259
  const leftSegments = [
243
- theme.fg("accent", "● GSD"),
244
- theme.fg("dim", pwd),
260
+ gsdSegment,
261
+ pwdSegment,
245
262
  dimStatsLeft,
246
263
  ];
247
- const footerRight = [rightSide, extStatusText].filter(Boolean).join(" ");
248
264
  return renderFooterStrip(leftSegments, footerRight, width);
249
265
  }
250
266
  }
@@ -0,0 +1,22 @@
1
+ // GSD-2 pi-coding-agent system prompt file-safety regression tests.
2
+
3
+ import test from "node:test";
4
+ import assert from "node:assert/strict";
5
+
6
+ import { buildSystemPrompt } from "../core/system-prompt.js";
7
+
8
+ test("buildSystemPrompt: read and write tools require reading before overwrite", () => {
9
+ const prompt = buildSystemPrompt({ selectedTools: ["read", "write"] });
10
+
11
+ assert.match(prompt, /before editing or overwriting/i);
12
+ assert.match(prompt, /Before write creates or replaces a file, verify the target path/i);
13
+ assert.match(prompt, /if it exists, read it first/i);
14
+ assert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);
15
+ });
16
+
17
+ test("buildSystemPrompt: write-only tool guidance does not reference unavailable read tool", () => {
18
+ const prompt = buildSystemPrompt({ selectedTools: ["write"] });
19
+
20
+ assert.doesNotMatch(prompt, /read it first/i);
21
+ assert.match(prompt, /Use write only for new files or complete rewrites after verifying the target path/i);
22
+ });