gsd-pi 2.73.1-dev.d987996 → 2.74.0-dev.0306a2e

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 (535) hide show
  1. package/dist/cli-web-branch.d.ts +4 -3
  2. package/dist/cli-web-branch.js +10 -7
  3. package/dist/cli.js +184 -206
  4. package/dist/headless-query.js +4 -1
  5. package/dist/help-text.js +23 -0
  6. package/dist/logo.d.ts +1 -1
  7. package/dist/logo.js +1 -1
  8. package/dist/onboarding.js +59 -53
  9. package/dist/resource-loader.js +2 -2
  10. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +68 -4
  11. package/dist/resources/extensions/gsd/activity-log.js +16 -0
  12. package/dist/resources/extensions/gsd/auto/detect-stuck.js +11 -4
  13. package/dist/resources/extensions/gsd/auto/loop.js +147 -10
  14. package/dist/resources/extensions/gsd/auto/phases.js +173 -13
  15. package/dist/resources/extensions/gsd/auto/session.js +10 -0
  16. package/dist/resources/extensions/gsd/auto-dispatch.js +22 -4
  17. package/dist/resources/extensions/gsd/auto-model-selection.js +105 -16
  18. package/dist/resources/extensions/gsd/auto-post-unit.js +254 -15
  19. package/dist/resources/extensions/gsd/auto-prompts.js +12 -0
  20. package/dist/resources/extensions/gsd/auto-start.js +23 -6
  21. package/dist/resources/extensions/gsd/auto-timeout-recovery.js +13 -0
  22. package/dist/resources/extensions/gsd/auto-unit-closeout.js +18 -0
  23. package/dist/resources/extensions/gsd/auto-verification.js +186 -3
  24. package/dist/resources/extensions/gsd/auto.js +65 -12
  25. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +30 -8
  26. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +41 -2
  27. package/dist/resources/extensions/gsd/commands/catalog.js +26 -1
  28. package/dist/resources/extensions/gsd/commands/handlers/ops.js +25 -0
  29. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +68 -9
  30. package/dist/resources/extensions/gsd/commands-add-tests.js +111 -0
  31. package/dist/resources/extensions/gsd/commands-backlog.js +140 -0
  32. package/dist/resources/extensions/gsd/commands-do.js +79 -0
  33. package/dist/resources/extensions/gsd/commands-extract-learnings.js +225 -0
  34. package/dist/resources/extensions/gsd/commands-handlers.js +8 -2
  35. package/dist/resources/extensions/gsd/commands-maintenance.js +6 -6
  36. package/dist/resources/extensions/gsd/commands-pr-branch.js +180 -0
  37. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
  38. package/dist/resources/extensions/gsd/commands-session-report.js +82 -0
  39. package/dist/resources/extensions/gsd/commands-ship.js +187 -0
  40. package/dist/resources/extensions/gsd/db-writer.js +3 -5
  41. package/dist/resources/extensions/gsd/docs/preferences-reference.md +15 -2
  42. package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +144 -0
  43. package/dist/resources/extensions/gsd/ecosystem/loader.js +145 -0
  44. package/dist/resources/extensions/gsd/git-service.js +49 -1
  45. package/dist/resources/extensions/gsd/graph-context.js +157 -0
  46. package/dist/resources/extensions/gsd/gsd-db.js +581 -2
  47. package/dist/resources/extensions/gsd/guided-flow.js +23 -0
  48. package/dist/resources/extensions/gsd/index.js +15 -2
  49. package/dist/resources/extensions/gsd/init-wizard.js +1 -0
  50. package/dist/resources/extensions/gsd/journal.js +27 -0
  51. package/dist/resources/extensions/gsd/md-importer.js +3 -4
  52. package/dist/resources/extensions/gsd/memory-store.js +19 -51
  53. package/dist/resources/extensions/gsd/metrics.js +19 -0
  54. package/dist/resources/extensions/gsd/milestone-validation-gates.js +13 -12
  55. package/dist/resources/extensions/gsd/native-git-bridge.js +7 -4
  56. package/dist/resources/extensions/gsd/notification-widget.js +2 -2
  57. package/dist/resources/extensions/gsd/parallel-orchestrator.js +33 -1
  58. package/dist/resources/extensions/gsd/preferences-models.js +63 -3
  59. package/dist/resources/extensions/gsd/preferences-types.js +2 -0
  60. package/dist/resources/extensions/gsd/preferences-validation.js +130 -2
  61. package/dist/resources/extensions/gsd/preferences.js +26 -0
  62. package/dist/resources/extensions/gsd/prompts/add-tests.md +35 -0
  63. package/dist/resources/extensions/gsd/slice-parallel-orchestrator.js +12 -2
  64. package/dist/resources/extensions/gsd/state.js +66 -15
  65. package/dist/resources/extensions/gsd/templates/PREFERENCES.md +18 -0
  66. package/dist/resources/extensions/gsd/tools/complete-slice.js +20 -0
  67. package/dist/resources/extensions/gsd/tools/validate-milestone.js +39 -4
  68. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +3 -14
  69. package/dist/resources/extensions/gsd/triage-resolution.js +2 -5
  70. package/dist/resources/extensions/gsd/unit-ownership.js +1 -1
  71. package/dist/resources/extensions/gsd/uok/audit-toggle.js +7 -0
  72. package/dist/resources/extensions/gsd/uok/audit.js +40 -0
  73. package/dist/resources/extensions/gsd/uok/contracts.js +1 -0
  74. package/dist/resources/extensions/gsd/uok/execution-graph.js +179 -0
  75. package/dist/resources/extensions/gsd/uok/flags.js +29 -0
  76. package/dist/resources/extensions/gsd/uok/gate-runner.js +109 -0
  77. package/dist/resources/extensions/gsd/uok/gitops.js +53 -0
  78. package/dist/resources/extensions/gsd/uok/kernel.js +80 -0
  79. package/dist/resources/extensions/gsd/uok/loop-adapter.js +133 -0
  80. package/dist/resources/extensions/gsd/uok/model-policy.js +66 -0
  81. package/dist/resources/extensions/gsd/uok/plan-v2.js +132 -0
  82. package/dist/resources/extensions/gsd/workflow-logger.js +22 -0
  83. package/dist/resources/extensions/gsd/workflow-manifest.js +8 -69
  84. package/dist/resources/extensions/gsd/workflow-migration.js +21 -22
  85. package/dist/resources/extensions/gsd/workflow-projections.js +4 -1
  86. package/dist/resources/extensions/gsd/workflow-reconcile.js +14 -11
  87. package/dist/resources/extensions/ttsr/ttsr-manager.js +3 -1
  88. package/dist/tsconfig.extensions.tsbuildinfo +1 -0
  89. package/dist/update-check.d.ts +1 -0
  90. package/dist/update-check.js +13 -5
  91. package/dist/update-cmd.js +4 -3
  92. package/dist/web/standalone/.next/BUILD_ID +1 -1
  93. package/dist/web/standalone/.next/app-path-routes-manifest.json +13 -13
  94. package/dist/web/standalone/.next/build-manifest.json +2 -2
  95. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  96. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  97. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  98. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  99. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  100. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  101. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  102. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  103. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  104. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  105. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  106. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  107. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  108. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  109. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  110. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  111. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  112. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  113. package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +1 -1
  114. package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +1 -1
  115. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
  116. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +1 -1
  117. package/dist/web/standalone/.next/server/app/index.html +1 -1
  118. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  119. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  120. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  121. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  122. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  123. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  124. package/dist/web/standalone/.next/server/app-paths-manifest.json +13 -13
  125. package/dist/web/standalone/.next/server/chunks/6897.js +3 -3
  126. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  127. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  128. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  129. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  130. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  131. package/package.json +3 -3
  132. package/packages/daemon/package.json +2 -2
  133. package/packages/mcp-server/dist/index.d.ts +3 -0
  134. package/packages/mcp-server/dist/index.d.ts.map +1 -1
  135. package/packages/mcp-server/dist/index.js +3 -0
  136. package/packages/mcp-server/dist/index.js.map +1 -1
  137. package/packages/mcp-server/dist/readers/graph.d.ts +87 -0
  138. package/packages/mcp-server/dist/readers/graph.d.ts.map +1 -0
  139. package/packages/mcp-server/dist/readers/graph.js +655 -0
  140. package/packages/mcp-server/dist/readers/graph.js.map +1 -0
  141. package/packages/mcp-server/dist/readers/index.d.ts +2 -0
  142. package/packages/mcp-server/dist/readers/index.d.ts.map +1 -1
  143. package/packages/mcp-server/dist/readers/index.js +1 -0
  144. package/packages/mcp-server/dist/readers/index.js.map +1 -1
  145. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  146. package/packages/mcp-server/dist/server.js +65 -0
  147. package/packages/mcp-server/dist/server.js.map +1 -1
  148. package/packages/mcp-server/package.json +2 -2
  149. package/packages/mcp-server/src/index.ts +15 -0
  150. package/packages/mcp-server/src/readers/graph.test.ts +604 -0
  151. package/packages/mcp-server/src/readers/graph.ts +855 -0
  152. package/packages/mcp-server/src/readers/index.ts +12 -0
  153. package/packages/mcp-server/src/server.ts +83 -0
  154. package/packages/mcp-server/tsconfig.json +1 -0
  155. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -0
  156. package/packages/native/package.json +2 -2
  157. package/packages/native/tsconfig.tsbuildinfo +1 -0
  158. package/packages/pi-agent-core/package.json +1 -1
  159. package/packages/pi-agent-core/tsconfig.json +1 -0
  160. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -0
  161. package/packages/pi-ai/dist/index.d.ts +2 -9
  162. package/packages/pi-ai/dist/index.d.ts.map +1 -1
  163. package/packages/pi-ai/dist/index.js +2 -9
  164. package/packages/pi-ai/dist/index.js.map +1 -1
  165. package/packages/pi-ai/dist/models/capability-patches.d.ts +19 -0
  166. package/packages/pi-ai/dist/models/capability-patches.d.ts.map +1 -0
  167. package/packages/pi-ai/dist/models/capability-patches.js +36 -0
  168. package/packages/pi-ai/dist/models/capability-patches.js.map +1 -0
  169. package/packages/pi-ai/dist/{models.custom.d.ts → models/custom.d.ts} +1 -1
  170. package/packages/pi-ai/dist/models/custom.d.ts.map +1 -0
  171. package/packages/pi-ai/dist/{models.custom.js → models/custom.js} +4 -4
  172. package/packages/pi-ai/dist/models/custom.js.map +1 -0
  173. package/packages/pi-ai/dist/models/generated/amazon-bedrock.d.ts +1482 -0
  174. package/packages/pi-ai/dist/models/generated/amazon-bedrock.d.ts.map +1 -0
  175. package/packages/pi-ai/dist/models/generated/amazon-bedrock.js +1484 -0
  176. package/packages/pi-ai/dist/models/generated/amazon-bedrock.js.map +1 -0
  177. package/packages/pi-ai/dist/models/generated/anthropic.d.ts +377 -0
  178. package/packages/pi-ai/dist/models/generated/anthropic.d.ts.map +1 -0
  179. package/packages/pi-ai/dist/models/generated/anthropic.js +379 -0
  180. package/packages/pi-ai/dist/models/generated/anthropic.js.map +1 -0
  181. package/packages/pi-ai/dist/models/generated/azure-openai-responses.d.ts +700 -0
  182. package/packages/pi-ai/dist/models/generated/azure-openai-responses.d.ts.map +1 -0
  183. package/packages/pi-ai/dist/models/generated/azure-openai-responses.js +702 -0
  184. package/packages/pi-ai/dist/models/generated/azure-openai-responses.js.map +1 -0
  185. package/packages/pi-ai/dist/models/generated/cerebras.d.ts +71 -0
  186. package/packages/pi-ai/dist/models/generated/cerebras.d.ts.map +1 -0
  187. package/packages/pi-ai/dist/models/generated/cerebras.js +73 -0
  188. package/packages/pi-ai/dist/models/generated/cerebras.js.map +1 -0
  189. package/packages/pi-ai/dist/models/generated/github-copilot.d.ts +590 -0
  190. package/packages/pi-ai/dist/models/generated/github-copilot.d.ts.map +1 -0
  191. package/packages/pi-ai/dist/models/generated/github-copilot.js +444 -0
  192. package/packages/pi-ai/dist/models/generated/github-copilot.js.map +1 -0
  193. package/packages/pi-ai/dist/models/generated/google-antigravity.d.ts +156 -0
  194. package/packages/pi-ai/dist/models/generated/google-antigravity.d.ts.map +1 -0
  195. package/packages/pi-ai/dist/models/generated/google-antigravity.js +158 -0
  196. package/packages/pi-ai/dist/models/generated/google-antigravity.js.map +1 -0
  197. package/packages/pi-ai/dist/models/generated/google-gemini-cli.d.ts +105 -0
  198. package/packages/pi-ai/dist/models/generated/google-gemini-cli.d.ts.map +1 -0
  199. package/packages/pi-ai/dist/models/generated/google-gemini-cli.js +107 -0
  200. package/packages/pi-ai/dist/models/generated/google-gemini-cli.js.map +1 -0
  201. package/packages/pi-ai/dist/models/generated/google-vertex.d.ts +207 -0
  202. package/packages/pi-ai/dist/models/generated/google-vertex.d.ts.map +1 -0
  203. package/packages/pi-ai/dist/models/generated/google-vertex.js +209 -0
  204. package/packages/pi-ai/dist/models/generated/google-vertex.js.map +1 -0
  205. package/packages/pi-ai/dist/models/generated/google.d.ts +462 -0
  206. package/packages/pi-ai/dist/models/generated/google.d.ts.map +1 -0
  207. package/packages/pi-ai/dist/models/generated/google.js +464 -0
  208. package/packages/pi-ai/dist/models/generated/google.js.map +1 -0
  209. package/packages/pi-ai/dist/models/generated/groq.d.ts +309 -0
  210. package/packages/pi-ai/dist/models/generated/groq.d.ts.map +1 -0
  211. package/packages/pi-ai/dist/models/generated/groq.js +311 -0
  212. package/packages/pi-ai/dist/models/generated/groq.js.map +1 -0
  213. package/packages/pi-ai/dist/models/generated/huggingface.d.ts +383 -0
  214. package/packages/pi-ai/dist/models/generated/huggingface.d.ts.map +1 -0
  215. package/packages/pi-ai/dist/models/generated/huggingface.js +347 -0
  216. package/packages/pi-ai/dist/models/generated/huggingface.js.map +1 -0
  217. package/packages/pi-ai/dist/{models.generated.d.ts → models/generated/index.d.ts} +1 -1
  218. package/packages/pi-ai/dist/{models.generated.d.ts.map → models/generated/index.d.ts.map} +1 -1
  219. package/packages/pi-ai/dist/models/generated/index.js +51 -0
  220. package/packages/pi-ai/dist/models/generated/index.js.map +1 -0
  221. package/packages/pi-ai/dist/models/generated/kimi-coding.d.ts +37 -0
  222. package/packages/pi-ai/dist/models/generated/kimi-coding.d.ts.map +1 -0
  223. package/packages/pi-ai/dist/models/generated/kimi-coding.js +39 -0
  224. package/packages/pi-ai/dist/models/generated/kimi-coding.js.map +1 -0
  225. package/packages/pi-ai/dist/models/generated/minimax-cn.d.ts +105 -0
  226. package/packages/pi-ai/dist/models/generated/minimax-cn.d.ts.map +1 -0
  227. package/packages/pi-ai/dist/models/generated/minimax-cn.js +107 -0
  228. package/packages/pi-ai/dist/models/generated/minimax-cn.js.map +1 -0
  229. package/packages/pi-ai/dist/models/generated/minimax.d.ts +105 -0
  230. package/packages/pi-ai/dist/models/generated/minimax.d.ts.map +1 -0
  231. package/packages/pi-ai/dist/models/generated/minimax.js +107 -0
  232. package/packages/pi-ai/dist/models/generated/minimax.js.map +1 -0
  233. package/packages/pi-ai/dist/models/generated/mistral.d.ts +445 -0
  234. package/packages/pi-ai/dist/models/generated/mistral.d.ts.map +1 -0
  235. package/packages/pi-ai/dist/models/generated/mistral.js +447 -0
  236. package/packages/pi-ai/dist/models/generated/mistral.js.map +1 -0
  237. package/packages/pi-ai/dist/models/generated/openai-codex.d.ts +139 -0
  238. package/packages/pi-ai/dist/models/generated/openai-codex.d.ts.map +1 -0
  239. package/packages/pi-ai/dist/models/generated/openai-codex.js +141 -0
  240. package/packages/pi-ai/dist/models/generated/openai-codex.js.map +1 -0
  241. package/packages/pi-ai/dist/models/generated/openai.d.ts +700 -0
  242. package/packages/pi-ai/dist/models/generated/openai.d.ts.map +1 -0
  243. package/packages/pi-ai/dist/models/generated/openai.js +702 -0
  244. package/packages/pi-ai/dist/models/generated/openai.js.map +1 -0
  245. package/packages/pi-ai/dist/models/generated/opencode-go.d.ts +122 -0
  246. package/packages/pi-ai/dist/models/generated/opencode-go.d.ts.map +1 -0
  247. package/packages/pi-ai/dist/models/generated/opencode-go.js +124 -0
  248. package/packages/pi-ai/dist/models/generated/opencode-go.js.map +1 -0
  249. package/packages/pi-ai/dist/models/generated/opencode.d.ts +530 -0
  250. package/packages/pi-ai/dist/models/generated/opencode.d.ts.map +1 -0
  251. package/packages/pi-ai/dist/models/generated/opencode.js +532 -0
  252. package/packages/pi-ai/dist/models/generated/opencode.js.map +1 -0
  253. package/packages/pi-ai/dist/models/generated/openrouter.d.ts +4270 -0
  254. package/packages/pi-ai/dist/models/generated/openrouter.d.ts.map +1 -0
  255. package/packages/pi-ai/dist/models/generated/openrouter.js +4272 -0
  256. package/packages/pi-ai/dist/models/generated/openrouter.js.map +1 -0
  257. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.d.ts +2604 -0
  258. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.d.ts.map +1 -0
  259. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.js +2606 -0
  260. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.js.map +1 -0
  261. package/packages/pi-ai/dist/models/generated/xai.d.ts +411 -0
  262. package/packages/pi-ai/dist/models/generated/xai.d.ts.map +1 -0
  263. package/packages/pi-ai/dist/models/generated/xai.js +413 -0
  264. package/packages/pi-ai/dist/models/generated/xai.js.map +1 -0
  265. package/packages/pi-ai/dist/models/generated/zai.d.ts +276 -0
  266. package/packages/pi-ai/dist/models/generated/zai.d.ts.map +1 -0
  267. package/packages/pi-ai/dist/models/generated/zai.js +239 -0
  268. package/packages/pi-ai/dist/models/generated/zai.js.map +1 -0
  269. package/packages/pi-ai/dist/models/index.d.ts +27 -0
  270. package/packages/pi-ai/dist/models/index.d.ts.map +1 -0
  271. package/packages/pi-ai/dist/models/index.js +80 -0
  272. package/packages/pi-ai/dist/models/index.js.map +1 -0
  273. package/packages/pi-ai/dist/models.d.ts +1 -36
  274. package/packages/pi-ai/dist/models.d.ts.map +1 -1
  275. package/packages/pi-ai/dist/models.generated.test.js +1 -2
  276. package/packages/pi-ai/dist/models.generated.test.js.map +1 -1
  277. package/packages/pi-ai/dist/models.js +3 -112
  278. package/packages/pi-ai/dist/models.js.map +1 -1
  279. package/packages/pi-ai/dist/models.test.js +6 -5
  280. package/packages/pi-ai/dist/models.test.js.map +1 -1
  281. package/packages/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  282. package/packages/pi-ai/dist/utils/overflow.js +12 -0
  283. package/packages/pi-ai/dist/utils/overflow.js.map +1 -1
  284. package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts +2 -0
  285. package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts.map +1 -0
  286. package/packages/pi-ai/dist/utils/tests/overflow.test.js +50 -0
  287. package/packages/pi-ai/dist/utils/tests/overflow.test.js.map +1 -0
  288. package/packages/pi-ai/package.json +1 -1
  289. package/packages/pi-ai/scripts/generate-models.ts +74 -40
  290. package/packages/pi-ai/src/index.ts +5 -9
  291. package/packages/pi-ai/src/models/capability-patches.ts +40 -0
  292. package/packages/pi-ai/src/{models.custom.ts → models/custom.ts} +4 -4
  293. package/packages/pi-ai/src/models/generated/amazon-bedrock.ts +1486 -0
  294. package/packages/pi-ai/src/models/generated/anthropic.ts +381 -0
  295. package/packages/pi-ai/src/models/generated/azure-openai-responses.ts +704 -0
  296. package/packages/pi-ai/src/models/generated/cerebras.ts +75 -0
  297. package/packages/pi-ai/src/models/generated/github-copilot.ts +446 -0
  298. package/packages/pi-ai/src/models/generated/google-antigravity.ts +160 -0
  299. package/packages/pi-ai/src/models/generated/google-gemini-cli.ts +109 -0
  300. package/packages/pi-ai/src/models/generated/google-vertex.ts +211 -0
  301. package/packages/pi-ai/src/models/generated/google.ts +466 -0
  302. package/packages/pi-ai/src/models/generated/groq.ts +313 -0
  303. package/packages/pi-ai/src/models/generated/huggingface.ts +349 -0
  304. package/packages/pi-ai/src/models/generated/index.ts +52 -0
  305. package/packages/pi-ai/src/models/generated/kimi-coding.ts +41 -0
  306. package/packages/pi-ai/src/models/generated/minimax-cn.ts +109 -0
  307. package/packages/pi-ai/src/models/generated/minimax.ts +109 -0
  308. package/packages/pi-ai/src/models/generated/mistral.ts +449 -0
  309. package/packages/pi-ai/src/models/generated/openai-codex.ts +143 -0
  310. package/packages/pi-ai/src/models/generated/openai.ts +704 -0
  311. package/packages/pi-ai/src/models/generated/opencode-go.ts +126 -0
  312. package/packages/pi-ai/src/models/generated/opencode.ts +534 -0
  313. package/packages/pi-ai/src/models/generated/openrouter.ts +4274 -0
  314. package/packages/pi-ai/src/models/generated/vercel-ai-gateway.ts +2608 -0
  315. package/packages/pi-ai/src/models/generated/xai.ts +415 -0
  316. package/packages/pi-ai/src/models/generated/zai.ts +241 -0
  317. package/packages/pi-ai/src/models/index.ts +106 -0
  318. package/packages/pi-ai/src/models.generated.test.ts +1 -2
  319. package/packages/pi-ai/src/models.test.ts +6 -5
  320. package/packages/pi-ai/src/models.ts +3 -153
  321. package/packages/pi-ai/src/utils/overflow.ts +14 -1
  322. package/packages/pi-ai/src/utils/tests/overflow.test.ts +58 -0
  323. package/packages/pi-ai/tsconfig.json +1 -0
  324. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -0
  325. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +721 -8
  326. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  327. package/packages/pi-coding-agent/dist/core/compaction/utils.js +5 -5
  328. package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
  329. package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts +2 -0
  330. package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts.map +1 -0
  331. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js +45 -0
  332. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js.map +1 -0
  333. package/packages/pi-coding-agent/dist/core/model-registry-env-fallback.test.d.ts +2 -0
  334. package/packages/pi-coding-agent/dist/core/model-registry-env-fallback.test.d.ts.map +1 -0
  335. package/packages/pi-coding-agent/dist/core/model-registry-env-fallback.test.js +52 -0
  336. package/packages/pi-coding-agent/dist/core/model-registry-env-fallback.test.js.map +1 -0
  337. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  338. package/packages/pi-coding-agent/dist/core/model-registry.js +2 -2
  339. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  340. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts +12 -2
  341. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  342. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +65 -28
  343. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  344. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts +2 -1
  345. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  346. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +9 -3
  347. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  348. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts +2 -0
  349. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts.map +1 -0
  350. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js +52 -0
  351. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js.map +1 -0
  352. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  353. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +305 -20
  354. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  355. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.d.ts +2 -0
  356. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.d.ts.map +1 -0
  357. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.js +38 -0
  358. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.js.map +1 -0
  359. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +13 -0
  360. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  361. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +59 -6
  362. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  363. package/packages/pi-coding-agent/package.json +1 -1
  364. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +884 -8
  365. package/packages/pi-coding-agent/src/core/compaction/utils.ts +5 -5
  366. package/packages/pi-coding-agent/src/core/compaction-utils.test.ts +50 -0
  367. package/packages/pi-coding-agent/src/core/model-registry-env-fallback.test.ts +59 -0
  368. package/packages/pi-coding-agent/src/core/model-registry.ts +2 -1
  369. package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +78 -32
  370. package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.test.ts +73 -0
  371. package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.ts +9 -3
  372. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +381 -39
  373. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-ordering.test.ts +44 -0
  374. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +79 -6
  375. package/packages/pi-coding-agent/src/types/ambient-modules.d.ts +69 -0
  376. package/packages/pi-coding-agent/tsconfig.json +3 -2
  377. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -0
  378. package/packages/pi-tui/dist/__tests__/tui.test.js +60 -1
  379. package/packages/pi-tui/dist/__tests__/tui.test.js.map +1 -1
  380. package/packages/pi-tui/dist/tui.d.ts +8 -0
  381. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  382. package/packages/pi-tui/dist/tui.js +32 -3
  383. package/packages/pi-tui/dist/tui.js.map +1 -1
  384. package/packages/pi-tui/package.json +1 -1
  385. package/packages/pi-tui/src/__tests__/tui.test.ts +76 -1
  386. package/packages/pi-tui/src/tui.ts +31 -3
  387. package/packages/pi-tui/tsconfig.json +1 -0
  388. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -0
  389. package/packages/rpc-client/package.json +1 -1
  390. package/packages/rpc-client/tsconfig.json +1 -0
  391. package/packages/rpc-client/tsconfig.tsbuildinfo +1 -0
  392. package/pkg/package.json +1 -1
  393. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +107 -5
  394. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +111 -2
  395. package/src/resources/extensions/gsd/activity-log.ts +21 -0
  396. package/src/resources/extensions/gsd/auto/detect-stuck.ts +12 -4
  397. package/src/resources/extensions/gsd/auto/loop-deps.ts +10 -0
  398. package/src/resources/extensions/gsd/auto/loop.ts +159 -10
  399. package/src/resources/extensions/gsd/auto/phases.ts +213 -13
  400. package/src/resources/extensions/gsd/auto/session.ts +10 -0
  401. package/src/resources/extensions/gsd/auto-dispatch.ts +26 -10
  402. package/src/resources/extensions/gsd/auto-model-selection.ts +151 -16
  403. package/src/resources/extensions/gsd/auto-post-unit.ts +278 -16
  404. package/src/resources/extensions/gsd/auto-prompts.ts +13 -0
  405. package/src/resources/extensions/gsd/auto-start.ts +30 -6
  406. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +17 -0
  407. package/src/resources/extensions/gsd/auto-unit-closeout.ts +25 -1
  408. package/src/resources/extensions/gsd/auto-verification.ts +225 -3
  409. package/src/resources/extensions/gsd/auto.ts +72 -16
  410. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +38 -8
  411. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +52 -2
  412. package/src/resources/extensions/gsd/commands/catalog.ts +26 -1
  413. package/src/resources/extensions/gsd/commands/handlers/ops.ts +25 -0
  414. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +74 -9
  415. package/src/resources/extensions/gsd/commands-add-tests.ts +137 -0
  416. package/src/resources/extensions/gsd/commands-backlog.ts +182 -0
  417. package/src/resources/extensions/gsd/commands-do.ts +109 -0
  418. package/src/resources/extensions/gsd/commands-extract-learnings.ts +304 -0
  419. package/src/resources/extensions/gsd/commands-handlers.ts +8 -2
  420. package/src/resources/extensions/gsd/commands-maintenance.ts +6 -6
  421. package/src/resources/extensions/gsd/commands-pr-branch.ts +234 -0
  422. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
  423. package/src/resources/extensions/gsd/commands-session-report.ts +101 -0
  424. package/src/resources/extensions/gsd/commands-ship.ts +219 -0
  425. package/src/resources/extensions/gsd/db-writer.ts +3 -5
  426. package/src/resources/extensions/gsd/docs/preferences-reference.md +15 -2
  427. package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +228 -0
  428. package/src/resources/extensions/gsd/ecosystem/loader.ts +201 -0
  429. package/src/resources/extensions/gsd/git-service.ts +68 -0
  430. package/src/resources/extensions/gsd/graph-context.ts +212 -0
  431. package/src/resources/extensions/gsd/gsd-db.ts +788 -3
  432. package/src/resources/extensions/gsd/guided-flow.ts +32 -0
  433. package/src/resources/extensions/gsd/index.ts +18 -2
  434. package/src/resources/extensions/gsd/init-wizard.ts +3 -2
  435. package/src/resources/extensions/gsd/journal.ts +30 -0
  436. package/src/resources/extensions/gsd/md-importer.ts +3 -5
  437. package/src/resources/extensions/gsd/memory-store.ts +31 -62
  438. package/src/resources/extensions/gsd/metrics.ts +26 -0
  439. package/src/resources/extensions/gsd/milestone-validation-gates.ts +13 -14
  440. package/src/resources/extensions/gsd/native-git-bridge.ts +11 -12
  441. package/src/resources/extensions/gsd/notification-widget.ts +2 -2
  442. package/src/resources/extensions/gsd/parallel-orchestrator.ts +40 -1
  443. package/src/resources/extensions/gsd/preferences-models.ts +61 -3
  444. package/src/resources/extensions/gsd/preferences-types.ts +44 -0
  445. package/src/resources/extensions/gsd/preferences-validation.ts +130 -2
  446. package/src/resources/extensions/gsd/preferences.ts +28 -0
  447. package/src/resources/extensions/gsd/prompts/add-tests.md +35 -0
  448. package/src/resources/extensions/gsd/session-lock.ts +14 -2
  449. package/src/resources/extensions/gsd/slice-parallel-orchestrator.ts +20 -1
  450. package/src/resources/extensions/gsd/state.ts +80 -17
  451. package/src/resources/extensions/gsd/templates/PREFERENCES.md +18 -0
  452. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +9 -5
  453. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +20 -0
  454. package/src/resources/extensions/gsd/tests/auto-post-unit-step-message.test.ts +53 -0
  455. package/src/resources/extensions/gsd/tests/auto-project-root-env.test.ts +7 -3
  456. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +51 -2
  457. package/src/resources/extensions/gsd/tests/cold-resume-db-reopen.test.ts +6 -2
  458. package/src/resources/extensions/gsd/tests/commands-backlog.test.ts +158 -0
  459. package/src/resources/extensions/gsd/tests/commands-do.test.ts +127 -0
  460. package/src/resources/extensions/gsd/tests/commands-extract-learnings.test.ts +340 -0
  461. package/src/resources/extensions/gsd/tests/commands-pr-branch.test.ts +68 -0
  462. package/src/resources/extensions/gsd/tests/commands-session-report.test.ts +82 -0
  463. package/src/resources/extensions/gsd/tests/commands-ship.test.ts +71 -0
  464. package/src/resources/extensions/gsd/tests/commands-workflow-custom.test.ts +14 -0
  465. package/src/resources/extensions/gsd/tests/complete-milestone-false-merge.test.ts +142 -0
  466. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  467. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  468. package/src/resources/extensions/gsd/tests/completed-at-reconcile.test.ts +42 -0
  469. package/src/resources/extensions/gsd/tests/derive-state-crossval.test.ts +3 -2
  470. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +3 -2
  471. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +68 -8
  472. package/src/resources/extensions/gsd/tests/derive-state.test.ts +3 -3
  473. package/src/resources/extensions/gsd/tests/extension-bootstrap-isolation.test.ts +154 -0
  474. package/src/resources/extensions/gsd/tests/finalize-timeout-guard.test.ts +10 -7
  475. package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +137 -1
  476. package/src/resources/extensions/gsd/tests/graph-context.test.ts +337 -0
  477. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +1 -1
  478. package/src/resources/extensions/gsd/tests/health-widget.test.ts +1 -1
  479. package/src/resources/extensions/gsd/tests/integration/state-machine-edge-cases.test.ts +4 -2
  480. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +68 -1
  481. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -2
  482. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -3
  483. package/src/resources/extensions/gsd/tests/model-isolation.test.ts +91 -2
  484. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +140 -0
  485. package/src/resources/extensions/gsd/tests/post-exec-retry-bypass.test.ts +79 -1
  486. package/src/resources/extensions/gsd/tests/post-unit-state-rebuild.test.ts +2 -1
  487. package/src/resources/extensions/gsd/tests/pre-execution-pause-wiring.test.ts +40 -1
  488. package/src/resources/extensions/gsd/tests/preferences.test.ts +47 -0
  489. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +1 -1
  490. package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +180 -0
  491. package/src/resources/extensions/gsd/tests/state-machine-full-walkthrough.test.ts +5 -7
  492. package/src/resources/extensions/gsd/tests/token-profile.test.ts +9 -6
  493. package/src/resources/extensions/gsd/tests/uok-audit-unified.test.ts +101 -0
  494. package/src/resources/extensions/gsd/tests/uok-contracts.test.ts +85 -0
  495. package/src/resources/extensions/gsd/tests/uok-execution-graph.test.ts +69 -0
  496. package/src/resources/extensions/gsd/tests/uok-flags.test.ts +39 -0
  497. package/src/resources/extensions/gsd/tests/uok-gate-runner.test.ts +70 -0
  498. package/src/resources/extensions/gsd/tests/uok-gitops-turn-action.test.ts +85 -0
  499. package/src/resources/extensions/gsd/tests/uok-gitops-wiring.test.ts +35 -0
  500. package/src/resources/extensions/gsd/tests/uok-model-policy.test.ts +89 -0
  501. package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +167 -0
  502. package/src/resources/extensions/gsd/tests/uok-preferences.test.ts +42 -0
  503. package/src/resources/extensions/gsd/tests/validate-milestone-stuck-guard.test.ts +179 -0
  504. package/src/resources/extensions/gsd/tests/validate-milestone-write-order.test.ts +39 -0
  505. package/src/resources/extensions/gsd/tests/workflow-logger-wiring.test.ts +223 -0
  506. package/src/resources/extensions/gsd/tools/complete-slice.ts +26 -0
  507. package/src/resources/extensions/gsd/tools/validate-milestone.ts +48 -3
  508. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +3 -11
  509. package/src/resources/extensions/gsd/triage-resolution.ts +2 -7
  510. package/src/resources/extensions/gsd/types.ts +14 -1
  511. package/src/resources/extensions/gsd/unit-ownership.ts +2 -2
  512. package/src/resources/extensions/gsd/uok/audit-toggle.ts +9 -0
  513. package/src/resources/extensions/gsd/uok/audit.ts +51 -0
  514. package/src/resources/extensions/gsd/uok/contracts.ts +135 -0
  515. package/src/resources/extensions/gsd/uok/execution-graph.ts +241 -0
  516. package/src/resources/extensions/gsd/uok/flags.ts +45 -0
  517. package/src/resources/extensions/gsd/uok/gate-runner.ts +146 -0
  518. package/src/resources/extensions/gsd/uok/gitops.ts +75 -0
  519. package/src/resources/extensions/gsd/uok/kernel.ts +105 -0
  520. package/src/resources/extensions/gsd/uok/loop-adapter.ts +162 -0
  521. package/src/resources/extensions/gsd/uok/model-policy.ts +112 -0
  522. package/src/resources/extensions/gsd/uok/plan-v2.ts +156 -0
  523. package/src/resources/extensions/gsd/workflow-logger.ts +27 -1
  524. package/src/resources/extensions/gsd/workflow-manifest.ts +9 -104
  525. package/src/resources/extensions/gsd/workflow-migration.ts +21 -29
  526. package/src/resources/extensions/gsd/workflow-projections.ts +8 -1
  527. package/src/resources/extensions/gsd/workflow-reconcile.ts +15 -15
  528. package/src/resources/extensions/ttsr/ttsr-manager.ts +10 -5
  529. package/packages/pi-ai/dist/models.custom.d.ts.map +0 -1
  530. package/packages/pi-ai/dist/models.custom.js.map +0 -1
  531. package/packages/pi-ai/dist/models.generated.js +0 -14343
  532. package/packages/pi-ai/dist/models.generated.js.map +0 -1
  533. package/packages/pi-ai/src/models.generated.ts +0 -14345
  534. /package/dist/web/standalone/.next/static/{cGmbVq2su4f9tMpgIkG8u → tqdo0yKKYz6fJXQnIgbdx}/_buildManifest.js +0 -0
  535. /package/dist/web/standalone/.next/static/{cGmbVq2su4f9tMpgIkG8u → tqdo0yKKYz6fJXQnIgbdx}/_ssgManifest.js +0 -0
@@ -94,7 +94,7 @@ function createHost() {
94
94
  return host;
95
95
  }
96
96
 
97
- test("chat-controller keeps tool output ahead of delayed assistant text for external tool streams", async () => {
97
+ test("chat-controller renders content blocks in content[] index order (tool-first stream)", async () => {
98
98
  // ToolExecutionComponent uses the global theme singleton.
99
99
  // Install a minimal no-op theme implementation for this unit test.
100
100
  (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
@@ -116,7 +116,6 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
116
116
 
117
117
  await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
118
118
 
119
- assert.equal(host.streamingComponent, undefined, "assistant component should be deferred at message_start");
120
119
  assert.equal(host.chatContainer.children.length, 0, "nothing should render before content arrives");
121
120
 
122
121
  await handleAgentEvent(
@@ -140,11 +139,10 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
140
139
  } as any,
141
140
  );
142
141
 
143
- assert.equal(host.streamingComponent, undefined, "assistant text container should remain deferred for tool-only updates");
142
+ // content[0] = toolCall ToolExecutionComponent renders first
144
143
  assert.equal(host.chatContainer.children.length, 1, "tool execution block should render immediately");
145
144
  assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
146
145
 
147
- // Re-assert required host method before the text-bearing update path.
148
146
  host.getMarkdownThemeWithSettings = () => ({});
149
147
 
150
148
  await handleAgentEvent(
@@ -161,12 +159,13 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
161
159
  } as any,
162
160
  );
163
161
 
164
- assert.equal(host.chatContainer.children.length, 2, "assistant content should render after existing tool output");
162
+ // content[0]=toolCall, content[1]=text order: tool, then text
163
+ assert.equal(host.chatContainer.children.length, 2, "text run should render after tool in content[] order");
165
164
  assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
166
165
  assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
167
166
  });
168
167
 
169
- test("chat-controller keeps serverToolUse output ahead of assistant text when external results arrive", async () => {
168
+ test("chat-controller renders serverToolUse before trailing text matching content[] index order", async () => {
170
169
  (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
171
170
  fg: (_key: string, text: string) => text,
172
171
  bg: (_key: string, text: string) => text,
@@ -199,7 +198,7 @@ test("chat-controller keeps serverToolUse output ahead of assistant text when ex
199
198
  } as any,
200
199
  );
201
200
 
202
- assert.equal(host.streamingComponent, undefined, "assistant content should stay deferred while only tool content streams");
201
+ // content[0] = serverToolUse ToolExecutionComponent renders first
203
202
  assert.equal(host.chatContainer.children.length, 1, "server tool block should render immediately");
204
203
  assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
205
204
 
@@ -229,11 +228,461 @@ test("chat-controller keeps serverToolUse output ahead of assistant text when ex
229
228
  } as any,
230
229
  );
231
230
 
232
- assert.equal(host.chatContainer.children.length, 2, "assistant text should render after existing server tool output");
231
+ // content[0]=serverToolUse, content[1]=text order: tool, then text
232
+ assert.equal(host.chatContainer.children.length, 2, "text run should render after server tool in content[] order");
233
233
  assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
234
234
  assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
235
235
  });
236
236
 
237
+ test("chat-controller replays final message_end content when result adds unstreamed trailing text", async () => {
238
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
239
+ fg: (_key: string, text: string) => text,
240
+ bg: (_key: string, text: string) => text,
241
+ bold: (text: string) => text,
242
+ italic: (text: string) => text,
243
+ truncate: (text: string) => text,
244
+ };
245
+
246
+ const host = createHost();
247
+ host.getMarkdownThemeWithSettings = () => ({});
248
+
249
+ const tool = {
250
+ type: "toolCall",
251
+ id: "mcp-end-replay-1",
252
+ name: "read",
253
+ mcpServer: "filesystem",
254
+ arguments: { filePath: "/tmp/demo.txt" },
255
+ };
256
+
257
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
258
+
259
+ const streamedContent = [
260
+ tool,
261
+ { type: "thinking", thinking: "I am analyzing tool output..." },
262
+ ];
263
+ await handleAgentEvent(
264
+ host,
265
+ {
266
+ type: "message_update",
267
+ message: makeAssistant(streamedContent),
268
+ assistantMessageEvent: {
269
+ type: "thinking_delta",
270
+ contentIndex: 1,
271
+ delta: "I am analyzing tool output...",
272
+ partial: makeAssistant(streamedContent),
273
+ },
274
+ } as any,
275
+ );
276
+
277
+ assert.equal(host.chatContainer.children.length, 2, "streaming shows tool + thinking only");
278
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
279
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
280
+
281
+ // Final payload includes trailing text that never arrived as message_update.
282
+ const finalContent = [
283
+ tool,
284
+ { type: "thinking", thinking: "I am analyzing tool output..." },
285
+ { type: "text", text: "Correct anything important I missed?" },
286
+ ];
287
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
288
+
289
+ assert.equal(host.chatContainer.children.length, 3, "message_end should replay and include trailing text segment");
290
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
291
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
292
+ assert.equal(host.chatContainer.children[2]?.constructor?.name, "AssistantMessageComponent");
293
+ });
294
+
295
+ test("chat-controller keeps pre-tool prose visible until post-tool prose arrives, then prunes it", async () => {
296
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
297
+ fg: (_key: string, text: string) => text,
298
+ bg: (_key: string, text: string) => text,
299
+ bold: (text: string) => text,
300
+ italic: (text: string) => text,
301
+ truncate: (text: string) => text,
302
+ };
303
+
304
+ const host = createHost();
305
+ host.getMarkdownThemeWithSettings = () => ({});
306
+
307
+ const mcpTool = {
308
+ type: "toolCall",
309
+ id: "mcp-tool-1",
310
+ name: "read",
311
+ mcpServer: "filesystem",
312
+ arguments: { filePath: "/tmp/demo.txt" },
313
+ };
314
+
315
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
316
+
317
+ // Provisional assistant text arrives first.
318
+ await handleAgentEvent(
319
+ host,
320
+ {
321
+ type: "message_update",
322
+ message: makeAssistant([{ type: "text", text: "Let me inspect the workspace first." }]),
323
+ assistantMessageEvent: {
324
+ type: "text_delta",
325
+ contentIndex: 0,
326
+ delta: "Let me inspect the workspace first.",
327
+ partial: makeAssistant([{ type: "text", text: "Let me inspect the workspace first." }]),
328
+ },
329
+ } as any,
330
+ );
331
+ assert.equal(host.chatContainer.children.length, 1);
332
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
333
+
334
+ // MCP tool appears; provisional text should remain visible until post-tool prose exists.
335
+ await handleAgentEvent(
336
+ host,
337
+ {
338
+ type: "message_update",
339
+ message: makeAssistant([{ type: "text", text: "Let me inspect the workspace first." }, mcpTool]),
340
+ assistantMessageEvent: {
341
+ type: "toolcall_end",
342
+ contentIndex: 1,
343
+ toolCall: {
344
+ ...mcpTool,
345
+ externalResult: {
346
+ content: [{ type: "text", text: "file preview" }],
347
+ details: {},
348
+ isError: false,
349
+ },
350
+ },
351
+ partial: makeAssistant([{ type: "text", text: "Let me inspect the workspace first." }, mcpTool]),
352
+ },
353
+ } as any,
354
+ );
355
+ assert.equal(host.chatContainer.children.length, 2, "pre-tool prose should remain during tool-only window");
356
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
357
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent");
358
+
359
+ // Post-tool prose arrives: pre-tool prose should now be pruned.
360
+ const finalContent = [
361
+ { type: "text", text: "Let me inspect the workspace first." },
362
+ mcpTool,
363
+ { type: "text", text: "Which missing feature matters most to you?" },
364
+ ];
365
+ await handleAgentEvent(
366
+ host,
367
+ {
368
+ type: "message_update",
369
+ message: makeAssistant(finalContent),
370
+ assistantMessageEvent: {
371
+ type: "text_delta",
372
+ contentIndex: 2,
373
+ delta: "Which missing feature matters most to you?",
374
+ partial: makeAssistant(finalContent),
375
+ },
376
+ } as any,
377
+ );
378
+ assert.equal(host.chatContainer.children.length, 2);
379
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
380
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
381
+
382
+ // Finalize to tear down any pinned spinner state.
383
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
384
+ });
385
+
386
+ test("chat-controller keeps pre-tool thinking visible for claude-code MCP turns without post-tool prose", async () => {
387
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
388
+ fg: (_key: string, text: string) => text,
389
+ bg: (_key: string, text: string) => text,
390
+ bold: (text: string) => text,
391
+ italic: (text: string) => text,
392
+ truncate: (text: string) => text,
393
+ };
394
+
395
+ const host = createHost();
396
+ host.getMarkdownThemeWithSettings = () => ({});
397
+
398
+ const mcpTool = {
399
+ type: "toolCall",
400
+ id: "mcp-tool-thinking-1",
401
+ name: "read",
402
+ mcpServer: "filesystem",
403
+ arguments: { filePath: "/tmp/demo.txt" },
404
+ };
405
+
406
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
407
+
408
+ const thinkingOnly = [{ type: "thinking", thinking: "I should inspect the workspace." }];
409
+ await handleAgentEvent(
410
+ host,
411
+ {
412
+ type: "message_update",
413
+ message: makeAssistant(thinkingOnly),
414
+ assistantMessageEvent: {
415
+ type: "thinking_delta",
416
+ contentIndex: 0,
417
+ delta: "I should inspect the workspace.",
418
+ partial: makeAssistant(thinkingOnly),
419
+ },
420
+ } as any,
421
+ );
422
+ assert.equal(host.chatContainer.children.length, 1);
423
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
424
+
425
+ await handleAgentEvent(
426
+ host,
427
+ {
428
+ type: "message_update",
429
+ message: makeAssistant([thinkingOnly[0], mcpTool]),
430
+ assistantMessageEvent: {
431
+ type: "toolcall_end",
432
+ contentIndex: 1,
433
+ toolCall: {
434
+ ...mcpTool,
435
+ externalResult: {
436
+ content: [{ type: "text", text: "file preview" }],
437
+ details: {},
438
+ isError: false,
439
+ },
440
+ },
441
+ partial: makeAssistant([thinkingOnly[0], mcpTool]),
442
+ },
443
+ } as any,
444
+ );
445
+
446
+ assert.equal(host.chatContainer.children.length, 2, "thinking should remain visible while only tool output is present");
447
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
448
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent");
449
+
450
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant([thinkingOnly[0], mcpTool]) } as any);
451
+ });
452
+
453
+ test("chat-controller prunes orphaned provisional text after claude-code sub-turn shrink when MCP tools appear", async () => {
454
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
455
+ fg: (_key: string, text: string) => text,
456
+ bg: (_key: string, text: string) => text,
457
+ bold: (text: string) => text,
458
+ italic: (text: string) => text,
459
+ truncate: (text: string) => text,
460
+ };
461
+
462
+ const host = createHost();
463
+ host.getMarkdownThemeWithSettings = () => ({});
464
+
465
+ const mcpTool = {
466
+ type: "toolCall",
467
+ id: "mcp-tool-shrink-1",
468
+ name: "glob",
469
+ mcpServer: "filesystem",
470
+ arguments: { pattern: "**/*" },
471
+ };
472
+
473
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
474
+
475
+ // Sub-turn 1: generate longer provisional text content.
476
+ await handleAgentEvent(
477
+ host,
478
+ {
479
+ type: "message_update",
480
+ message: makeAssistant([{ type: "text", text: "Old provisional preface." }, { type: "text", text: "More old text." }]),
481
+ assistantMessageEvent: {
482
+ type: "text_delta",
483
+ contentIndex: 1,
484
+ delta: "More old text.",
485
+ partial: makeAssistant([{ type: "text", text: "Old provisional preface." }, { type: "text", text: "More old text." }]),
486
+ },
487
+ } as any,
488
+ );
489
+ assert.equal(host.chatContainer.children.length, 1, "first sub-turn text run should render");
490
+
491
+ // Sub-turn 2 starts (content shrink): old component is orphaned by design.
492
+ await handleAgentEvent(
493
+ host,
494
+ {
495
+ type: "message_update",
496
+ message: makeAssistant([{ type: "text", text: "New provisional text before tool." }]),
497
+ assistantMessageEvent: {
498
+ type: "text_delta",
499
+ contentIndex: 0,
500
+ delta: "New provisional text before tool.",
501
+ partial: makeAssistant([{ type: "text", text: "New provisional text before tool." }]),
502
+ },
503
+ } as any,
504
+ );
505
+ assert.equal(host.chatContainer.children.length, 2, "shrink keeps prior text until MCP tool context appears");
506
+
507
+ // MCP tool appears in sub-turn 2: tool-only windows keep provisional prose visible.
508
+ await handleAgentEvent(
509
+ host,
510
+ {
511
+ type: "message_update",
512
+ message: makeAssistant([{ type: "text", text: "New provisional text before tool." }, mcpTool]),
513
+ assistantMessageEvent: {
514
+ type: "toolcall_end",
515
+ contentIndex: 1,
516
+ toolCall: {
517
+ ...mcpTool,
518
+ externalResult: {
519
+ content: [{ type: "text", text: "glob output" }],
520
+ details: {},
521
+ isError: false,
522
+ },
523
+ },
524
+ partial: makeAssistant([{ type: "text", text: "New provisional text before tool." }, mcpTool]),
525
+ },
526
+ } as any,
527
+ );
528
+ assert.equal(host.chatContainer.children.length, 3, "stale text runs are deferred until post-tool prose arrives");
529
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
530
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
531
+ assert.equal(host.chatContainer.children[2]?.constructor?.name, "ToolExecutionComponent");
532
+
533
+ const finalContent = [mcpTool, { type: "text", text: "Final visible question?" }];
534
+ await handleAgentEvent(
535
+ host,
536
+ {
537
+ type: "message_update",
538
+ message: makeAssistant(finalContent),
539
+ assistantMessageEvent: {
540
+ type: "text_delta",
541
+ contentIndex: 1,
542
+ delta: "Final visible question?",
543
+ partial: makeAssistant(finalContent),
544
+ },
545
+ } as any,
546
+ );
547
+ assert.equal(host.chatContainer.children.length, 2);
548
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
549
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
550
+
551
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
552
+ });
553
+
554
+ test("chat-controller prunes orphans from multiple sub-turn shrinks before MCP post-tool prose", async () => {
555
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
556
+ fg: (_key: string, text: string) => text,
557
+ bg: (_key: string, text: string) => text,
558
+ bold: (text: string) => text,
559
+ italic: (text: string) => text,
560
+ truncate: (text: string) => text,
561
+ };
562
+
563
+ const host = createHost();
564
+ host.getMarkdownThemeWithSettings = () => ({});
565
+
566
+ const mcpTool = {
567
+ type: "toolCall",
568
+ id: "mcp-tool-multi-shrink-1",
569
+ name: "glob",
570
+ mcpServer: "filesystem",
571
+ arguments: { pattern: "**/*" },
572
+ };
573
+
574
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
575
+
576
+ // Sub-turn 1: 3 text blocks (merged into one text-run).
577
+ const subTurn1 = [
578
+ { type: "text", text: "First provisional A." },
579
+ { type: "text", text: "First provisional B." },
580
+ { type: "text", text: "First provisional C." },
581
+ ];
582
+ await handleAgentEvent(
583
+ host,
584
+ {
585
+ type: "message_update",
586
+ message: makeAssistant(subTurn1),
587
+ assistantMessageEvent: {
588
+ type: "text_delta",
589
+ contentIndex: 2,
590
+ delta: "First provisional C.",
591
+ partial: makeAssistant(subTurn1),
592
+ },
593
+ } as any,
594
+ );
595
+ assert.equal(host.chatContainer.children.length, 1, "first sub-turn renders 1 text-run");
596
+
597
+ // Sub-turn 2 (first shrink 3 → 2 blocks).
598
+ const subTurn2 = [
599
+ { type: "text", text: "Second provisional A." },
600
+ { type: "text", text: "Second provisional B." },
601
+ ];
602
+ await handleAgentEvent(
603
+ host,
604
+ {
605
+ type: "message_update",
606
+ message: makeAssistant(subTurn2),
607
+ assistantMessageEvent: {
608
+ type: "text_delta",
609
+ contentIndex: 1,
610
+ delta: "Second provisional B.",
611
+ partial: makeAssistant(subTurn2),
612
+ },
613
+ } as any,
614
+ );
615
+ assert.equal(host.chatContainer.children.length, 2, "first shrink appends, keeps prior text as frozen history");
616
+
617
+ // Sub-turn 3 (second shrink 2 → 1 block). This is the critical step —
618
+ // without orphan accumulation, sub-turn 1's orphaned segment would be
619
+ // dropped from tracking here and later strand in the container.
620
+ const subTurn3 = [{ type: "text", text: "Third provisional." }];
621
+ await handleAgentEvent(
622
+ host,
623
+ {
624
+ type: "message_update",
625
+ message: makeAssistant(subTurn3),
626
+ assistantMessageEvent: {
627
+ type: "text_delta",
628
+ contentIndex: 0,
629
+ delta: "Third provisional.",
630
+ partial: makeAssistant(subTurn3),
631
+ },
632
+ } as any,
633
+ );
634
+ assert.equal(host.chatContainer.children.length, 3, "second shrink appends again, still no prune (no post-tool text)");
635
+
636
+ // MCP tool appears — tool-only window still keeps provisional prose visible.
637
+ await handleAgentEvent(
638
+ host,
639
+ {
640
+ type: "message_update",
641
+ message: makeAssistant([{ type: "text", text: "Third provisional." }, mcpTool]),
642
+ assistantMessageEvent: {
643
+ type: "toolcall_end",
644
+ contentIndex: 1,
645
+ toolCall: {
646
+ ...mcpTool,
647
+ externalResult: {
648
+ content: [{ type: "text", text: "glob output" }],
649
+ details: {},
650
+ isError: false,
651
+ },
652
+ },
653
+ partial: makeAssistant([{ type: "text", text: "Third provisional." }, mcpTool]),
654
+ },
655
+ } as any,
656
+ );
657
+ assert.equal(host.chatContainer.children.length, 4, "tool-only window keeps all three provisional text-runs");
658
+
659
+ // Final post-tool text arrives — prune must drop ALL three pre-tool
660
+ // provisional text-runs across both shrinks, leaving only tool + final text.
661
+ const finalContent = [mcpTool, { type: "text", text: "Final answer." }];
662
+ await handleAgentEvent(
663
+ host,
664
+ {
665
+ type: "message_update",
666
+ message: makeAssistant(finalContent),
667
+ assistantMessageEvent: {
668
+ type: "text_delta",
669
+ contentIndex: 1,
670
+ delta: "Final answer.",
671
+ partial: makeAssistant(finalContent),
672
+ },
673
+ } as any,
674
+ );
675
+ assert.equal(
676
+ host.chatContainer.children.length,
677
+ 2,
678
+ "all pre-tool provisional segments from every shrink must be pruned once post-tool prose arrives",
679
+ );
680
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
681
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
682
+
683
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
684
+ });
685
+
237
686
  test("chat-controller pins latest assistant text above editor when tool calls are present", async () => {
238
687
  (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
239
688
  fg: (_key: string, text: string) => text,
@@ -466,3 +915,430 @@ test("chat-controller does not pin when there are no tool calls", async () => {
466
915
 
467
916
  assert.equal(host.pinnedMessageContainer.children.length, 0, "pinned zone should stay empty without tool calls");
468
917
  });
918
+
919
+ // Regression test for issue #4144: interleaved text/tool content must render in content[] index order.
920
+ // Stream: [text "A", toolCall T1, text "B", toolCall T2, text "C"]
921
+ // Expected chatContainer order: textRun(A), toolExec(T1), textRun(B), toolExec(T2), textRun(C)
922
+ // Each AssistantMessageComponent must render ONLY its own text — no duplication after message_end.
923
+ test("chat-controller renders interleaved text and tool blocks in content[] index order (#4144)", async () => {
924
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
925
+ fg: (_key: string, text: string) => text,
926
+ bg: (_key: string, text: string) => text,
927
+ bold: (text: string) => text,
928
+ italic: (text: string) => text,
929
+ truncate: (text: string) => text,
930
+ };
931
+
932
+ const host = createHost();
933
+ host.getMarkdownThemeWithSettings = () => ({});
934
+
935
+ const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
936
+ const t2 = { type: "toolCall", id: "t2", name: "tool_two", arguments: {} };
937
+
938
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
939
+
940
+ // Stream text "A" at index 0
941
+ await handleAgentEvent(host, {
942
+ type: "message_update",
943
+ message: makeAssistant([{ type: "text", text: "A" }]),
944
+ assistantMessageEvent: {
945
+ type: "text_delta",
946
+ contentIndex: 0,
947
+ delta: "A",
948
+ partial: makeAssistant([{ type: "text", text: "A" }]),
949
+ },
950
+ } as any);
951
+
952
+ // Stream toolCall T1 at index 1
953
+ await handleAgentEvent(host, {
954
+ type: "message_update",
955
+ message: makeAssistant([{ type: "text", text: "A" }, t1]),
956
+ assistantMessageEvent: {
957
+ type: "toolcall_end",
958
+ contentIndex: 1,
959
+ toolCall: {
960
+ ...t1,
961
+ externalResult: { content: [{ type: "text", text: "result1" }], details: {}, isError: false },
962
+ },
963
+ partial: makeAssistant([{ type: "text", text: "A" }, t1]),
964
+ },
965
+ } as any);
966
+
967
+ // Stream text "B" at index 2
968
+ await handleAgentEvent(host, {
969
+ type: "message_update",
970
+ message: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
971
+ assistantMessageEvent: {
972
+ type: "text_delta",
973
+ contentIndex: 2,
974
+ delta: "B",
975
+ partial: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
976
+ },
977
+ } as any);
978
+
979
+ // Stream toolCall T2 at index 3
980
+ await handleAgentEvent(host, {
981
+ type: "message_update",
982
+ message: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2]),
983
+ assistantMessageEvent: {
984
+ type: "toolcall_end",
985
+ contentIndex: 3,
986
+ toolCall: {
987
+ ...t2,
988
+ externalResult: { content: [{ type: "text", text: "result2" }], details: {}, isError: false },
989
+ },
990
+ partial: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2]),
991
+ },
992
+ } as any);
993
+
994
+ // Stream text "C" at index 4
995
+ const finalContent = [
996
+ { type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2, { type: "text", text: "C" },
997
+ ];
998
+ await handleAgentEvent(host, {
999
+ type: "message_update",
1000
+ message: makeAssistant(finalContent),
1001
+ assistantMessageEvent: {
1002
+ type: "text_delta",
1003
+ contentIndex: 4,
1004
+ delta: "C",
1005
+ partial: makeAssistant(finalContent),
1006
+ },
1007
+ } as any);
1008
+
1009
+ // Finalize — exercises the message_end path where a buggy setRange(undefined) would cause duplication
1010
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
1011
+
1012
+ // Assert interleaved order: textRun(A), toolExec(T1), textRun(B), toolExec(T2), textRun(C)
1013
+ assert.equal(host.chatContainer.children.length, 5, "should have 5 children in interleaved order");
1014
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent", "index 0: text run A");
1015
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent", "index 1: tool T1");
1016
+ assert.equal(host.chatContainer.children[2]?.constructor?.name, "AssistantMessageComponent", "index 2: text run B");
1017
+ assert.equal(host.chatContainer.children[3]?.constructor?.name, "ToolExecutionComponent", "index 3: tool T2");
1018
+ assert.equal(host.chatContainer.children[4]?.constructor?.name, "AssistantMessageComponent", "index 4: text run C");
1019
+
1020
+ // Helper: collect the text of all Markdown children inside an AssistantMessageComponent.
1021
+ // Structure: AssistantMessageComponent (Container) -> contentContainer (children[0]) -> Markdown nodes.
1022
+ function getRenderedTexts(comp: any): string[] {
1023
+ const contentContainer = comp.children?.[0];
1024
+ if (!contentContainer) return [];
1025
+ return (contentContainer.children ?? [])
1026
+ .filter((c: any) => c.constructor?.name === "Markdown")
1027
+ .map((c: any) => (c as any).text as string);
1028
+ }
1029
+
1030
+ // Each text-run component must contain only its own text — no cross-contamination after message_end
1031
+ assert.deepEqual(getRenderedTexts(host.chatContainer.children[0]), ["A"], "text run A must contain only 'A'");
1032
+ assert.deepEqual(getRenderedTexts(host.chatContainer.children[2]), ["B"], "text run B must contain only 'B'");
1033
+ assert.deepEqual(getRenderedTexts(host.chatContainer.children[4]), ["C"], "text run C must contain only 'C'");
1034
+ });
1035
+
1036
+ test("chat-controller does not duplicate text when content is [text, tool, text] (interleaved stream)", async () => {
1037
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
1038
+ fg: (_key: string, text: string) => text,
1039
+ bg: (_key: string, text: string) => text,
1040
+ bold: (text: string) => text,
1041
+ italic: (text: string) => text,
1042
+ truncate: (text: string) => text,
1043
+ };
1044
+
1045
+ const host = createHost();
1046
+ host.getMarkdownThemeWithSettings = () => ({});
1047
+
1048
+ const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
1049
+
1050
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
1051
+
1052
+ // Step 1: text "A" at index 0
1053
+ await handleAgentEvent(host, {
1054
+ type: "message_update",
1055
+ message: makeAssistant([{ type: "text", text: "A" }]),
1056
+ assistantMessageEvent: {
1057
+ type: "text_delta",
1058
+ contentIndex: 0,
1059
+ delta: "A",
1060
+ partial: makeAssistant([{ type: "text", text: "A" }]),
1061
+ },
1062
+ } as any);
1063
+
1064
+ // Step 2: toolCall at index 1
1065
+ await handleAgentEvent(host, {
1066
+ type: "message_update",
1067
+ message: makeAssistant([{ type: "text", text: "A" }, t1]),
1068
+ assistantMessageEvent: {
1069
+ type: "toolcall_end",
1070
+ contentIndex: 1,
1071
+ toolCall: {
1072
+ ...t1,
1073
+ externalResult: { content: [{ type: "text", text: "result1" }], details: {}, isError: false },
1074
+ },
1075
+ partial: makeAssistant([{ type: "text", text: "A" }, t1]),
1076
+ },
1077
+ } as any);
1078
+
1079
+ // Step 3: text "B" at index 2
1080
+ const finalContent = [{ type: "text", text: "A" }, t1, { type: "text", text: "B" }];
1081
+ await handleAgentEvent(host, {
1082
+ type: "message_update",
1083
+ message: makeAssistant(finalContent),
1084
+ assistantMessageEvent: {
1085
+ type: "text_delta",
1086
+ contentIndex: 2,
1087
+ delta: "B",
1088
+ partial: makeAssistant(finalContent),
1089
+ },
1090
+ } as any);
1091
+
1092
+ assert.equal(host.chatContainer.children.length, 3);
1093
+ assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
1094
+ assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent");
1095
+ assert.equal(host.chatContainer.children[2]?.constructor?.name, "AssistantMessageComponent");
1096
+
1097
+ const firstText = host.chatContainer.children[0];
1098
+ const secondText = host.chatContainer.children[2];
1099
+ assert.notEqual(firstText, secondText, "text-before-tool and text-after-tool must be separate component instances");
1100
+ assert.deepEqual((firstText as any).range, { startIndex: 0, endIndex: 0 }, "first text-run covers only content[0]");
1101
+ assert.deepEqual((secondText as any).range, { startIndex: 2, endIndex: 2 }, "second text-run covers only content[2]");
1102
+
1103
+ // Finalize — regression guard: range must NOT be cleared on message_end (would cause duplication)
1104
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
1105
+
1106
+ assert.deepEqual((secondText as any).range, { startIndex: 2, endIndex: 2 }, "range must not be cleared on message_end (would cause duplication)");
1107
+ });
1108
+
1109
+ // Regression for the claude-code sub-turn bug that followed #4144:
1110
+ // an adapter can reset content[] back to 0/1 mid-lifecycle when a new provider
1111
+ // sub-turn begins. The segment walker must NOT update prior-sub-turn text-run
1112
+ // components in place (which would destroy earlier history) and must NOT reuse
1113
+ // stale tool registrations for a new tool at the same contentIndex. Prior
1114
+ // sub-turn children must stay frozen; new sub-turn segments must append after
1115
+ // them, and the pinned "Latest Output" mirror must re-evaluate for the new sub-turn.
1116
+ test("chat-controller freezes prior sub-turn and appends new segments when content shrinks", async () => {
1117
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
1118
+ fg: (_key: string, text: string) => text,
1119
+ bg: (_key: string, text: string) => text,
1120
+ bold: (text: string) => text,
1121
+ italic: (text: string) => text,
1122
+ truncate: (text: string) => text,
1123
+ };
1124
+
1125
+ const host = createHost();
1126
+ host.getMarkdownThemeWithSettings = () => ({});
1127
+
1128
+ const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
1129
+ const t2 = { type: "toolCall", id: "t2", name: "tool_two", arguments: {} };
1130
+
1131
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
1132
+
1133
+ // Sub-turn 1: grow to [A, T1, B]
1134
+ await handleAgentEvent(host, {
1135
+ type: "message_update",
1136
+ message: makeAssistant([{ type: "text", text: "A" }]),
1137
+ assistantMessageEvent: {
1138
+ type: "text_delta", contentIndex: 0, delta: "A",
1139
+ partial: makeAssistant([{ type: "text", text: "A" }]),
1140
+ },
1141
+ } as any);
1142
+ await handleAgentEvent(host, {
1143
+ type: "message_update",
1144
+ message: makeAssistant([{ type: "text", text: "A" }, t1]),
1145
+ assistantMessageEvent: {
1146
+ type: "toolcall_end", contentIndex: 1,
1147
+ toolCall: { ...t1, externalResult: { content: [{ type: "text", text: "r1" }], details: {}, isError: false } },
1148
+ partial: makeAssistant([{ type: "text", text: "A" }, t1]),
1149
+ },
1150
+ } as any);
1151
+ await handleAgentEvent(host, {
1152
+ type: "message_update",
1153
+ message: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
1154
+ assistantMessageEvent: {
1155
+ type: "text_delta", contentIndex: 2, delta: "B",
1156
+ partial: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
1157
+ },
1158
+ } as any);
1159
+
1160
+ assert.equal(host.chatContainer.children.length, 3, "sub-turn 1 renders 3 children");
1161
+ const priorA = host.chatContainer.children[0];
1162
+ const priorT1 = host.chatContainer.children[1];
1163
+ const priorB = host.chatContainer.children[2];
1164
+
1165
+ // Sub-turn boundary: adapter resets content[] to [C]
1166
+ await handleAgentEvent(host, {
1167
+ type: "message_update",
1168
+ message: makeAssistant([{ type: "text", text: "C" }]),
1169
+ assistantMessageEvent: {
1170
+ type: "text_delta", contentIndex: 0, delta: "C",
1171
+ partial: makeAssistant([{ type: "text", text: "C" }]),
1172
+ },
1173
+ } as any);
1174
+
1175
+ // Prior 3 children must still exist in DOM — and a NEW text-run for "C" appended after them.
1176
+ assert.equal(host.chatContainer.children.length, 4, "shrink must append new segment, not replace prior history");
1177
+ assert.equal(host.chatContainer.children[0], priorA, "prior A component stays at index 0");
1178
+ assert.equal(host.chatContainer.children[1], priorT1, "prior T1 component stays at index 1");
1179
+ assert.equal(host.chatContainer.children[2], priorB, "prior B component stays at index 2");
1180
+ assert.notEqual(host.chatContainer.children[3], priorA, "new C text-run must be a different component from prior A");
1181
+ assert.equal(host.chatContainer.children[3]?.constructor?.name, "AssistantMessageComponent");
1182
+
1183
+ // Prior A component must still render "A", not be overwritten with "C".
1184
+ function getRenderedTexts(comp: any): string[] {
1185
+ const contentContainer = comp.children?.[0];
1186
+ if (!contentContainer) return [];
1187
+ return (contentContainer.children ?? [])
1188
+ .filter((c: any) => c.constructor?.name === "Markdown")
1189
+ .map((c: any) => (c as any).text as string);
1190
+ }
1191
+ assert.deepEqual(getRenderedTexts(priorA), ["A"], "prior A text-run must still contain 'A' after shrink");
1192
+ assert.deepEqual(getRenderedTexts(priorB), ["B"], "prior B text-run must still contain 'B' after shrink");
1193
+ assert.deepEqual(getRenderedTexts(host.chatContainer.children[3]), ["C"], "new text-run must contain only 'C'");
1194
+
1195
+ // Sub-turn 2 grows with a new tool T2 at contentIndex=1.
1196
+ await handleAgentEvent(host, {
1197
+ type: "message_update",
1198
+ message: makeAssistant([{ type: "text", text: "C" }, t2]),
1199
+ assistantMessageEvent: {
1200
+ type: "toolcall_end", contentIndex: 1,
1201
+ toolCall: { ...t2, externalResult: { content: [{ type: "text", text: "r2" }], details: {}, isError: false } },
1202
+ partial: makeAssistant([{ type: "text", text: "C" }, t2]),
1203
+ },
1204
+ } as any);
1205
+
1206
+ // T2 must be appended after the new C text-run, not conflated with the stale T1 registration.
1207
+ assert.equal(host.chatContainer.children.length, 5, "new tool appends after new text-run");
1208
+ assert.equal(host.chatContainer.children[4]?.constructor?.name, "ToolExecutionComponent");
1209
+ assert.notEqual(host.chatContainer.children[4], priorT1, "new T2 must be a different component from prior T1");
1210
+
1211
+ // Finalize so the module-level pinned spinner (setInterval) is torn down and the test process can exit.
1212
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant([{ type: "text", text: "C" }, t2]) } as any);
1213
+ });
1214
+
1215
+ // Regression: after a sub-turn shrink, lastPinnedText must be cleared so the
1216
+ // pinned "Latest Output" mirror can display text from the new sub-turn instead
1217
+ // of staying frozen on a stale snapshot (the "bottom green stays" symptom).
1218
+ test("chat-controller updates pinned zone after sub-turn shrink", async () => {
1219
+ (globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
1220
+ fg: (_key: string, text: string) => text,
1221
+ bg: (_key: string, text: string) => text,
1222
+ bold: (text: string) => text,
1223
+ italic: (text: string) => text,
1224
+ truncate: (text: string) => text,
1225
+ };
1226
+
1227
+ const host = createHost();
1228
+ host.getMarkdownThemeWithSettings = () => ({});
1229
+
1230
+ const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
1231
+ const t2 = { type: "toolCall", id: "t2", name: "tool_two", arguments: {} };
1232
+
1233
+ await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
1234
+
1235
+ // Sub-turn 1 with pinnable text before a tool → populates pinned zone with "first".
1236
+ await handleAgentEvent(host, {
1237
+ type: "message_update",
1238
+ message: makeAssistant([{ type: "text", text: "first" }, t1]),
1239
+ assistantMessageEvent: {
1240
+ type: "toolcall_end", contentIndex: 1,
1241
+ toolCall: { ...t1, externalResult: { content: [{ type: "text", text: "r1" }], details: {}, isError: false } },
1242
+ partial: makeAssistant([{ type: "text", text: "first" }, t1]),
1243
+ },
1244
+ } as any);
1245
+ const pinnedMarkdown = host.pinnedMessageContainer.children[1];
1246
+ assert.equal((pinnedMarkdown as any)?.text, "first", "pinned zone seeded with sub-turn 1 text");
1247
+
1248
+ // Sub-turn boundary: content resets to [second, t2].
1249
+ await handleAgentEvent(host, {
1250
+ type: "message_update",
1251
+ message: makeAssistant([{ type: "text", text: "second" }, t2]),
1252
+ assistantMessageEvent: {
1253
+ type: "toolcall_end", contentIndex: 1,
1254
+ toolCall: { ...t2, externalResult: { content: [{ type: "text", text: "r2" }], details: {}, isError: false } },
1255
+ partial: makeAssistant([{ type: "text", text: "second" }, t2]),
1256
+ },
1257
+ } as any);
1258
+
1259
+ // Pinned markdown must now reflect the new sub-turn's text, not stay frozen on "first".
1260
+ assert.equal((pinnedMarkdown as any)?.text, "second", "pinned zone must update after sub-turn shrink (#4144 regression)");
1261
+
1262
+ // Finalize so the module-level pinned spinner (setInterval) is torn down and the test process can exit.
1263
+ await handleAgentEvent(host, { type: "message_end", message: makeAssistant([{ type: "text", text: "second" }, t2]) } as any);
1264
+ });
1265
+
1266
+ test("chat-controller: agent_end without message_end must not remove streaming component from DOM (regression #4197)", async () => {
1267
+ const host = createHost();
1268
+
1269
+ await handleAgentEvent(host, {
1270
+ type: "message_start",
1271
+ message: makeAssistant([]),
1272
+ } as any);
1273
+
1274
+ // Simulate partial streaming that creates an AssistantMessageComponent
1275
+ await handleAgentEvent(host, {
1276
+ type: "message_update",
1277
+ message: makeAssistant([{ type: "text", text: "partial answer" }]),
1278
+ assistantMessageEvent: {
1279
+ type: "text_delta",
1280
+ contentIndex: 0,
1281
+ delta: "partial answer",
1282
+ partial: makeAssistant([{ type: "text", text: "partial answer" }]),
1283
+ },
1284
+ } as any);
1285
+
1286
+ // Precondition: component is in DOM
1287
+ assert.equal(
1288
+ host.chatContainer.children.length,
1289
+ 1,
1290
+ "streaming component must be in DOM after message_update",
1291
+ );
1292
+ const comp = host.chatContainer.children[0];
1293
+
1294
+ // Simulate abort: agent_end fires WITHOUT message_end
1295
+ await handleAgentEvent(host, { type: "agent_end" } as any);
1296
+
1297
+ assert.equal(
1298
+ host.chatContainer.children.length,
1299
+ 1,
1300
+ "agent_end must NOT remove the streaming component from the DOM (issue #4197)",
1301
+ );
1302
+ assert.equal(
1303
+ host.chatContainer.children[0],
1304
+ comp,
1305
+ "the same component instance must remain in the DOM after agent_end",
1306
+ );
1307
+ });
1308
+
1309
+ test("chat-controller: agent_end after message_end must not alter DOM", async () => {
1310
+ const host = createHost();
1311
+ const content = [{ type: "text", text: "complete answer" }];
1312
+
1313
+ await handleAgentEvent(host, {
1314
+ type: "message_start",
1315
+ message: makeAssistant([]),
1316
+ } as any);
1317
+
1318
+ await handleAgentEvent(host, {
1319
+ type: "message_update",
1320
+ message: makeAssistant(content),
1321
+ assistantMessageEvent: {
1322
+ type: "text_delta",
1323
+ contentIndex: 0,
1324
+ delta: "complete answer",
1325
+ partial: makeAssistant(content),
1326
+ },
1327
+ } as any);
1328
+
1329
+ await handleAgentEvent(host, {
1330
+ type: "message_end",
1331
+ message: makeAssistant(content),
1332
+ } as any);
1333
+
1334
+ const countAfterMessageEnd = host.chatContainer.children.length;
1335
+ assert.ok(countAfterMessageEnd > 0, "component must be present after message_end");
1336
+
1337
+ await handleAgentEvent(host, { type: "agent_end" } as any);
1338
+
1339
+ assert.equal(
1340
+ host.chatContainer.children.length,
1341
+ countAfterMessageEnd,
1342
+ "agent_end after message_end must not add or remove DOM nodes",
1343
+ );
1344
+ });