gsd-pi 2.77.0-dev.538325aea → 2.77.0-dev.eaa4973bc

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 (874) hide show
  1. package/dist/cli-web-branch.d.ts +1 -0
  2. package/dist/cli-web-branch.js +3 -0
  3. package/dist/cli.js +59 -15
  4. package/dist/extension-discovery.d.ts +6 -0
  5. package/dist/extension-discovery.js +37 -0
  6. package/dist/extension-registry.d.ts +3 -0
  7. package/dist/extension-registry.js +1 -1
  8. package/dist/extension-sort.d.ts +18 -0
  9. package/dist/extension-sort.js +114 -0
  10. package/dist/extension-validator.d.ts +47 -0
  11. package/dist/extension-validator.js +127 -0
  12. package/dist/headless-ui.d.ts +1 -1
  13. package/dist/headless.js +4 -2
  14. package/dist/loader.js +36 -7
  15. package/dist/onboarding.js +5 -5
  16. package/dist/provider-migrations.d.ts +20 -2
  17. package/dist/provider-migrations.js +15 -2
  18. package/dist/remote-questions-config.js +1 -1
  19. package/dist/resources/extensions/async-jobs/async-bash-tool.js +1 -1
  20. package/dist/resources/extensions/aws-auth/index.js +1 -2
  21. package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +9 -6
  22. package/dist/resources/extensions/bg-shell/process-manager.js +1 -2
  23. package/dist/resources/extensions/browser-tools/index.js +1 -0
  24. package/dist/resources/extensions/claude-code-cli/index.js +1 -1
  25. package/dist/resources/extensions/claude-code-cli/partial-builder.js +17 -106
  26. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +71 -57
  27. package/dist/resources/extensions/cmux/index.js +20 -0
  28. package/dist/resources/extensions/google-search/extension-manifest.json +5 -4
  29. package/dist/resources/extensions/google-search/index.js +2 -375
  30. package/dist/resources/extensions/gsd/abandon-detect.js +44 -0
  31. package/dist/resources/extensions/gsd/auto/resolve.js +24 -0
  32. package/dist/resources/extensions/gsd/auto/run-unit.js +10 -2
  33. package/dist/resources/extensions/gsd/auto/turn-epoch.js +95 -0
  34. package/dist/resources/extensions/gsd/auto-dispatch.js +24 -0
  35. package/dist/resources/extensions/gsd/auto-loop.js +1 -1
  36. package/dist/resources/extensions/gsd/auto-post-unit.js +31 -0
  37. package/dist/resources/extensions/gsd/auto-timeout-recovery.js +11 -5
  38. package/dist/resources/extensions/gsd/auto-unit-closeout.js +11 -2
  39. package/dist/resources/extensions/gsd/auto-worktree.js +58 -8
  40. package/dist/resources/extensions/gsd/auto.js +31 -14
  41. package/dist/resources/extensions/gsd/bootstrap/provider-error-resume.js +4 -2
  42. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +11 -0
  43. package/dist/resources/extensions/gsd/bootstrap/system-context.js +11 -6
  44. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +31 -4
  45. package/dist/resources/extensions/gsd/commands-cmux.js +9 -6
  46. package/dist/resources/extensions/gsd/commands-extensions.js +634 -43
  47. package/dist/resources/extensions/gsd/file-lock.js +49 -9
  48. package/dist/resources/extensions/gsd/git-service.js +1 -0
  49. package/dist/resources/extensions/gsd/gitignore.js +1 -0
  50. package/dist/resources/extensions/gsd/guided-flow-queue.js +4 -1
  51. package/dist/resources/extensions/gsd/guided-flow.js +1 -1
  52. package/dist/resources/extensions/gsd/journal.js +17 -2
  53. package/dist/resources/extensions/gsd/milestone-actions.js +15 -0
  54. package/dist/resources/extensions/gsd/notifications.js +30 -16
  55. package/dist/resources/extensions/gsd/reports.js +5 -4
  56. package/dist/resources/extensions/gsd/tools/complete-slice.js +21 -0
  57. package/dist/resources/extensions/gsd/tools/complete-task.js +31 -0
  58. package/dist/resources/extensions/gsd/uok/audit.js +18 -2
  59. package/dist/resources/extensions/gsd/workflow-logger.js +10 -2
  60. package/dist/resources/extensions/gsd/worktree-manager.js +1 -0
  61. package/dist/resources/extensions/mcp-client/auth.js +10 -1
  62. package/dist/resources/extensions/mcp-client/index.js +119 -10
  63. package/dist/resources/extensions/ollama/index.js +2 -1
  64. package/dist/resources/extensions/ollama/ollama-chat-provider.js +15 -5
  65. package/dist/resources/extensions/remote-questions/config.js +1 -12
  66. package/dist/resources/extensions/shared/cmux-events.js +12 -0
  67. package/dist/resources/extensions/shared/rtk-session-stats.js +1 -2
  68. package/dist/resources/extensions/universal-config/index.js +1 -1
  69. package/dist/resources/skills/create-skill/SKILL.md +2 -2
  70. package/dist/resources/skills/create-skill/references/gsd-skill-ecosystem.md +4 -4
  71. package/dist/resources/skills/create-skill/workflows/audit-skill.md +4 -4
  72. package/dist/resources/skills/create-skill/workflows/create-new-skill.md +5 -5
  73. package/dist/security-overrides.d.ts +1 -4
  74. package/dist/security-overrides.js +3 -16
  75. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  76. package/dist/web/standalone/.next/BUILD_ID +1 -1
  77. package/dist/web/standalone/.next/app-path-routes-manifest.json +11 -11
  78. package/dist/web/standalone/.next/build-manifest.json +3 -3
  79. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  80. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  81. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  82. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  87. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  90. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  91. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
  98. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  99. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
  100. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  101. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
  102. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  103. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +1 -1
  104. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  105. package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
  106. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  107. package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
  108. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  109. package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
  110. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  111. package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
  112. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  113. package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
  114. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  115. package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
  116. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  117. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  118. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  119. package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
  120. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  121. package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
  122. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  123. package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
  124. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  125. package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
  126. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  127. package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
  128. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  129. package/dist/web/standalone/.next/server/app/api/notifications/route.js +1 -1
  130. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
  131. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  132. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  133. package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
  134. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  135. package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
  136. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  137. package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
  138. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  139. package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
  140. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  141. package/dist/web/standalone/.next/server/app/api/session/events/route.js +1 -1
  142. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  143. package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
  144. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  145. package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
  146. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  147. package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
  148. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  149. package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
  150. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  151. package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
  152. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  153. package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +1 -1
  154. package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +1 -1
  155. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
  156. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  157. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +1 -1
  158. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  159. package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
  160. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  161. package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
  162. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  163. package/dist/web/standalone/.next/server/app/index.html +1 -1
  164. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  165. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  166. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  167. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  168. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  169. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  170. package/dist/web/standalone/.next/server/app-paths-manifest.json +11 -11
  171. package/dist/web/standalone/.next/server/chunks/1926.js +1 -0
  172. package/dist/web/standalone/.next/server/chunks/6897.js +2 -2
  173. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  174. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  175. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  176. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  177. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  178. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  179. package/dist/web/standalone/.next/static/chunks/2826.e9f5195e91f9cad2.js +11 -0
  180. package/dist/web/standalone/.next/static/chunks/{webpack-1832629448831fdc.js → webpack-2e68521d7c82f7c2.js} +1 -1
  181. package/dist/web-mode.js +1 -1
  182. package/dist/welcome-screen.js +20 -19
  183. package/dist/wizard.js +5 -2
  184. package/package.json +16 -32
  185. package/packages/mcp-server/README.md +3 -3
  186. package/packages/mcp-server/dist/env-writer.d.ts +1 -0
  187. package/packages/mcp-server/dist/env-writer.d.ts.map +1 -1
  188. package/packages/mcp-server/dist/env-writer.js +74 -6
  189. package/packages/mcp-server/dist/env-writer.js.map +1 -1
  190. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  191. package/packages/mcp-server/dist/server.js +36 -17
  192. package/packages/mcp-server/dist/server.js.map +1 -1
  193. package/packages/mcp-server/package.json +5 -0
  194. package/packages/mcp-server/src/env-writer.test.ts +79 -1
  195. package/packages/mcp-server/src/env-writer.ts +76 -6
  196. package/packages/mcp-server/src/readers/readers.test.ts +5 -1
  197. package/packages/mcp-server/src/server.ts +45 -19
  198. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  199. package/packages/native/package.json +5 -0
  200. package/packages/native/src/__tests__/clipboard.test.mjs +69 -23
  201. package/packages/native/tsconfig.json +1 -2
  202. package/packages/native/tsconfig.tsbuildinfo +1 -0
  203. package/packages/pi-agent-core/package.json +5 -0
  204. package/packages/pi-agent-core/src/agent-loop.test.ts +220 -15
  205. package/packages/pi-ai/package.json +5 -0
  206. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  207. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +25 -0
  208. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  209. package/packages/pi-coding-agent/dist/core/compaction/compaction.js +105 -6
  210. package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  211. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js +230 -28
  212. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js.map +1 -1
  213. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +30 -2
  214. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
  215. package/packages/pi-coding-agent/dist/core/compaction/utils.js +113 -12
  216. package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
  217. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +1 -0
  218. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -1
  219. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +29 -18
  220. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -1
  221. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.d.ts +2 -0
  222. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.d.ts.map +1 -0
  223. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.js +130 -0
  224. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.js.map +1 -0
  225. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js +56 -1
  226. package/packages/pi-coding-agent/dist/core/compaction-utils.test.js.map +1 -1
  227. package/packages/pi-coding-agent/dist/core/discovery-cache.test.js +8 -15
  228. package/packages/pi-coding-agent/dist/core/discovery-cache.test.js.map +1 -1
  229. package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.d.ts +25 -0
  230. package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.d.ts.map +1 -0
  231. package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.js +109 -0
  232. package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.js.map +1 -0
  233. package/packages/pi-coding-agent/dist/core/extensions/extension-registry.d.ts +67 -0
  234. package/packages/pi-coding-agent/dist/core/extensions/extension-registry.d.ts.map +1 -0
  235. package/packages/pi-coding-agent/dist/core/extensions/extension-registry.js +167 -0
  236. package/packages/pi-coding-agent/dist/core/extensions/extension-registry.js.map +1 -0
  237. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +3 -2
  238. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  239. package/packages/pi-coding-agent/dist/core/extensions/loader.js +24 -8
  240. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  241. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +7 -0
  242. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  243. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  244. package/packages/pi-coding-agent/dist/core/lsp/lsp-integration.test.js +11 -0
  245. package/packages/pi-coding-agent/dist/core/lsp/lsp-integration.test.js.map +1 -1
  246. package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js +2 -2
  247. package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js.map +1 -1
  248. package/packages/pi-coding-agent/dist/core/resource-loader.js +1 -1
  249. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  250. package/packages/pi-coding-agent/dist/core/sdk.d.ts +1 -0
  251. package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
  252. package/packages/pi-coding-agent/dist/core/sdk.js +4 -1
  253. package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
  254. package/packages/pi-coding-agent/dist/core/sdk.test.js +19 -1
  255. package/packages/pi-coding-agent/dist/core/sdk.test.js.map +1 -1
  256. package/packages/pi-coding-agent/dist/core/system-prompt.js +3 -3
  257. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  258. package/packages/pi-coding-agent/dist/core/tools/path-utils.test.js +2 -1
  259. package/packages/pi-coding-agent/dist/core/tools/path-utils.test.js.map +1 -1
  260. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/provider-display-name.test.js +15 -6
  261. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/provider-display-name.test.js.map +1 -1
  262. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  263. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -5
  264. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  265. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts +7 -1
  266. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  267. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js +31 -9
  268. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js.map +1 -1
  269. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js +14 -0
  270. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js.map +1 -1
  271. package/packages/pi-coding-agent/package.json +5 -0
  272. package/packages/pi-coding-agent/src/core/compaction/compaction.test.ts +368 -28
  273. package/packages/pi-coding-agent/src/core/compaction/compaction.ts +122 -6
  274. package/packages/pi-coding-agent/src/core/compaction/utils.ts +111 -13
  275. package/packages/pi-coding-agent/src/core/compaction-orchestrator.test.ts +154 -0
  276. package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +32 -18
  277. package/packages/pi-coding-agent/src/core/compaction-utils.test.ts +68 -1
  278. package/packages/pi-coding-agent/src/core/discovery-cache.test.ts +9 -18
  279. package/packages/pi-coding-agent/src/core/extensions/extension-discovery.ts +119 -0
  280. package/packages/pi-coding-agent/src/core/extensions/extension-registry.ts +222 -0
  281. package/packages/pi-coding-agent/src/core/extensions/loader.ts +24 -11
  282. package/packages/pi-coding-agent/src/core/extensions/types.ts +8 -0
  283. package/packages/pi-coding-agent/src/core/lsp/lsp-integration.test.ts +13 -0
  284. package/packages/pi-coding-agent/src/core/model-registry-auth-mode.test.ts +2 -2
  285. package/packages/pi-coding-agent/src/core/resource-loader.ts +1 -1
  286. package/packages/pi-coding-agent/src/core/sdk.test.ts +25 -1
  287. package/packages/pi-coding-agent/src/core/sdk.ts +10 -3
  288. package/packages/pi-coding-agent/src/core/system-prompt.ts +3 -3
  289. package/packages/pi-coding-agent/src/core/tools/path-utils.test.ts +2 -1
  290. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/provider-display-name.test.ts +17 -7
  291. package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +14 -5
  292. package/packages/pi-coding-agent/src/modes/interactive/components/model-selector.ts +45 -11
  293. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.test.ts +14 -0
  294. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  295. package/packages/pi-tui/dist/__tests__/autocomplete.test.js +12 -5
  296. package/packages/pi-tui/dist/__tests__/autocomplete.test.js.map +1 -1
  297. package/packages/pi-tui/dist/__tests__/stdin-buffer.test.js +19 -0
  298. package/packages/pi-tui/dist/__tests__/stdin-buffer.test.js.map +1 -1
  299. package/packages/pi-tui/dist/stdin-buffer.d.ts +7 -0
  300. package/packages/pi-tui/dist/stdin-buffer.d.ts.map +1 -1
  301. package/packages/pi-tui/dist/stdin-buffer.js +20 -0
  302. package/packages/pi-tui/dist/stdin-buffer.js.map +1 -1
  303. package/packages/pi-tui/package.json +5 -0
  304. package/packages/pi-tui/src/__tests__/autocomplete.test.ts +20 -5
  305. package/packages/pi-tui/src/__tests__/stdin-buffer.test.ts +25 -0
  306. package/packages/pi-tui/src/stdin-buffer.ts +26 -0
  307. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
  308. package/packages/rpc-client/package.json +5 -0
  309. package/pkg/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  310. package/pkg/dist/core/export-html/ansi-to-html.js +0 -1
  311. package/pkg/dist/core/export-html/ansi-to-html.js.map +1 -1
  312. package/pkg/dist/core/export-html/index.d.ts +1 -1
  313. package/pkg/dist/core/export-html/index.d.ts.map +1 -1
  314. package/pkg/dist/core/export-html/index.js +5 -39
  315. package/pkg/dist/core/export-html/index.js.map +1 -1
  316. package/pkg/dist/core/export-html/tool-renderer.d.ts +2 -2
  317. package/pkg/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  318. package/pkg/dist/core/export-html/tool-renderer.js.map +1 -1
  319. package/scripts/ensure-workspace-builds.cjs +0 -2
  320. package/scripts/lib/workspace-manifest.cjs +86 -0
  321. package/scripts/link-workspace-packages.cjs +5 -19
  322. package/src/resources/extensions/async-jobs/async-bash-tool.ts +1 -1
  323. package/src/resources/extensions/aws-auth/index.ts +1 -2
  324. package/src/resources/extensions/bg-shell/bg-shell-lifecycle.ts +7 -4
  325. package/src/resources/extensions/bg-shell/index.ts +1 -2
  326. package/src/resources/extensions/bg-shell/process-manager.ts +1 -2
  327. package/src/resources/extensions/browser-tools/index.ts +1 -2
  328. package/src/resources/extensions/claude-code-cli/index.ts +1 -1
  329. package/src/resources/extensions/claude-code-cli/partial-builder.ts +23 -115
  330. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +81 -61
  331. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +91 -22
  332. package/src/resources/extensions/cmux/index.ts +35 -10
  333. package/src/resources/extensions/google-search/extension-manifest.json +5 -4
  334. package/src/resources/extensions/google-search/index.ts +8 -470
  335. package/src/resources/extensions/gsd/abandon-detect.ts +62 -0
  336. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -1
  337. package/src/resources/extensions/gsd/auto/resolve.ts +29 -0
  338. package/src/resources/extensions/gsd/auto/run-unit.ts +16 -2
  339. package/src/resources/extensions/gsd/auto/turn-epoch.ts +108 -0
  340. package/src/resources/extensions/gsd/auto/types.ts +1 -1
  341. package/src/resources/extensions/gsd/auto-dispatch.ts +20 -0
  342. package/src/resources/extensions/gsd/auto-loop.ts +1 -1
  343. package/src/resources/extensions/gsd/auto-post-unit.ts +30 -0
  344. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +12 -5
  345. package/src/resources/extensions/gsd/auto-unit-closeout.ts +14 -3
  346. package/src/resources/extensions/gsd/auto-worktree.ts +60 -5
  347. package/src/resources/extensions/gsd/auto.ts +37 -18
  348. package/src/resources/extensions/gsd/bootstrap/provider-error-resume.ts +6 -2
  349. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +11 -0
  350. package/src/resources/extensions/gsd/bootstrap/system-context.ts +13 -9
  351. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +27 -8
  352. package/src/resources/extensions/gsd/commands-cmux.ts +10 -6
  353. package/src/resources/extensions/gsd/commands-extensions.ts +747 -41
  354. package/src/resources/extensions/gsd/file-lock.ts +84 -11
  355. package/src/resources/extensions/gsd/git-service.ts +1 -0
  356. package/src/resources/extensions/gsd/gitignore.ts +1 -0
  357. package/src/resources/extensions/gsd/guided-flow-queue.ts +4 -1
  358. package/src/resources/extensions/gsd/guided-flow.ts +1 -1
  359. package/src/resources/extensions/gsd/journal.ts +27 -2
  360. package/src/resources/extensions/gsd/milestone-actions.ts +18 -0
  361. package/src/resources/extensions/gsd/notifications.ts +27 -15
  362. package/src/resources/extensions/gsd/reports.ts +5 -4
  363. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +11 -2
  364. package/src/resources/extensions/gsd/tests/auto-mode-guards.test.ts +79 -0
  365. package/src/resources/extensions/gsd/tests/cmux.test.ts +5 -9
  366. package/src/resources/extensions/gsd/tests/file-lock.test.ts +86 -12
  367. package/src/resources/extensions/gsd/tests/google-search-stub.test.ts +121 -0
  368. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +30 -0
  369. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +3 -2
  370. package/src/resources/extensions/gsd/tests/mcp-client-security.test.ts +76 -0
  371. package/src/resources/extensions/gsd/tests/milestone-transition-state-rebuild.test.ts +4 -2
  372. package/src/resources/extensions/gsd/tests/parallel-commit-scope.test.ts +5 -0
  373. package/src/resources/extensions/gsd/tests/parallel-skill-prompt-integration.test.ts +150 -0
  374. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +39 -25
  375. package/src/resources/extensions/gsd/tests/queue-auto-guard.test.ts +181 -0
  376. package/src/resources/extensions/gsd/tests/quick-auto-guard.test.ts +13 -7
  377. package/src/resources/extensions/gsd/tests/require-slice-discussion-dispatch.test.ts +170 -0
  378. package/src/resources/extensions/gsd/tests/rewrite-docs-abandon-detect.test.ts +195 -0
  379. package/src/resources/extensions/gsd/tests/stuck-detection-coverage.test.ts +2 -2
  380. package/src/resources/extensions/gsd/tests/triage-resolution.test.ts +50 -2
  381. package/src/resources/extensions/gsd/tests/turn-epoch.test.ts +162 -0
  382. package/src/resources/extensions/gsd/tests/validate-extension-package.test.ts +168 -0
  383. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +25 -2
  384. package/src/resources/extensions/gsd/tools/complete-slice.ts +38 -0
  385. package/src/resources/extensions/gsd/tools/complete-task.ts +49 -0
  386. package/src/resources/extensions/gsd/uok/audit.ts +20 -2
  387. package/src/resources/extensions/gsd/workflow-logger.ts +22 -3
  388. package/src/resources/extensions/gsd/worktree-manager.ts +1 -0
  389. package/src/resources/extensions/mcp-client/auth.ts +12 -1
  390. package/src/resources/extensions/mcp-client/index.ts +130 -11
  391. package/src/resources/extensions/ollama/index.ts +3 -3
  392. package/src/resources/extensions/ollama/ollama-chat-provider.ts +18 -6
  393. package/src/resources/extensions/remote-questions/config.ts +4 -15
  394. package/src/resources/extensions/search-the-web/index.ts +1 -2
  395. package/src/resources/extensions/shared/cmux-events.ts +59 -0
  396. package/src/resources/extensions/shared/rtk-session-stats.ts +1 -2
  397. package/src/resources/extensions/shared/tests/format-utils.test.ts +3 -5
  398. package/src/resources/extensions/universal-config/index.ts +1 -1
  399. package/src/resources/skills/create-skill/SKILL.md +2 -2
  400. package/src/resources/skills/create-skill/references/gsd-skill-ecosystem.md +4 -4
  401. package/src/resources/skills/create-skill/workflows/audit-skill.md +4 -4
  402. package/src/resources/skills/create-skill/workflows/create-new-skill.md +5 -5
  403. package/dist/web/standalone/.next/server/chunks/7461.js +0 -1
  404. package/dist/web/standalone/.next/static/chunks/2826.d445fb428ef41fa1.js +0 -9
  405. package/packages/gsd-agent-core/dist/agent-session.d.ts +0 -716
  406. package/packages/gsd-agent-core/dist/agent-session.d.ts.map +0 -1
  407. package/packages/gsd-agent-core/dist/agent-session.js +0 -2595
  408. package/packages/gsd-agent-core/dist/agent-session.js.map +0 -1
  409. package/packages/gsd-agent-core/dist/artifact-manager.d.ts +0 -52
  410. package/packages/gsd-agent-core/dist/artifact-manager.d.ts.map +0 -1
  411. package/packages/gsd-agent-core/dist/artifact-manager.js +0 -118
  412. package/packages/gsd-agent-core/dist/artifact-manager.js.map +0 -1
  413. package/packages/gsd-agent-core/dist/bash-executor.d.ts +0 -57
  414. package/packages/gsd-agent-core/dist/bash-executor.d.ts.map +0 -1
  415. package/packages/gsd-agent-core/dist/bash-executor.js +0 -282
  416. package/packages/gsd-agent-core/dist/bash-executor.js.map +0 -1
  417. package/packages/gsd-agent-core/dist/blob-store.d.ts +0 -39
  418. package/packages/gsd-agent-core/dist/blob-store.d.ts.map +0 -1
  419. package/packages/gsd-agent-core/dist/blob-store.js +0 -151
  420. package/packages/gsd-agent-core/dist/blob-store.js.map +0 -1
  421. package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts +0 -90
  422. package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts.map +0 -1
  423. package/packages/gsd-agent-core/dist/compaction/branch-summarization.js +0 -207
  424. package/packages/gsd-agent-core/dist/compaction/branch-summarization.js.map +0 -1
  425. package/packages/gsd-agent-core/dist/compaction/compaction.d.ts +0 -137
  426. package/packages/gsd-agent-core/dist/compaction/compaction.d.ts.map +0 -1
  427. package/packages/gsd-agent-core/dist/compaction/compaction.js +0 -621
  428. package/packages/gsd-agent-core/dist/compaction/compaction.js.map +0 -1
  429. package/packages/gsd-agent-core/dist/compaction/index.d.ts +0 -7
  430. package/packages/gsd-agent-core/dist/compaction/index.d.ts.map +0 -1
  431. package/packages/gsd-agent-core/dist/compaction/index.js +0 -7
  432. package/packages/gsd-agent-core/dist/compaction/index.js.map +0 -1
  433. package/packages/gsd-agent-core/dist/compaction/utils.d.ts +0 -78
  434. package/packages/gsd-agent-core/dist/compaction/utils.d.ts.map +0 -1
  435. package/packages/gsd-agent-core/dist/compaction/utils.js +0 -263
  436. package/packages/gsd-agent-core/dist/compaction/utils.js.map +0 -1
  437. package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts +0 -90
  438. package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts.map +0 -1
  439. package/packages/gsd-agent-core/dist/compaction-orchestrator.js +0 -338
  440. package/packages/gsd-agent-core/dist/compaction-orchestrator.js.map +0 -1
  441. package/packages/gsd-agent-core/dist/contextual-tips.d.ts +0 -43
  442. package/packages/gsd-agent-core/dist/contextual-tips.d.ts.map +0 -1
  443. package/packages/gsd-agent-core/dist/contextual-tips.js +0 -208
  444. package/packages/gsd-agent-core/dist/contextual-tips.js.map +0 -1
  445. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts +0 -18
  446. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts.map +0 -1
  447. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js +0 -250
  448. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js.map +0 -1
  449. package/packages/gsd-agent-core/dist/export-html/index.d.ts +0 -37
  450. package/packages/gsd-agent-core/dist/export-html/index.d.ts.map +0 -1
  451. package/packages/gsd-agent-core/dist/export-html/index.js +0 -257
  452. package/packages/gsd-agent-core/dist/export-html/index.js.map +0 -1
  453. package/packages/gsd-agent-core/dist/export-html/template.css +0 -971
  454. package/packages/gsd-agent-core/dist/export-html/template.html +0 -54
  455. package/packages/gsd-agent-core/dist/export-html/template.js +0 -1583
  456. package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts +0 -38
  457. package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts.map +0 -1
  458. package/packages/gsd-agent-core/dist/export-html/tool-renderer.js +0 -70
  459. package/packages/gsd-agent-core/dist/export-html/tool-renderer.js.map +0 -1
  460. package/packages/gsd-agent-core/dist/export-html/vendor/highlight.min.js +0 -1213
  461. package/packages/gsd-agent-core/dist/export-html/vendor/marked.min.js +0 -6
  462. package/packages/gsd-agent-core/dist/fallback-resolver.d.ts +0 -75
  463. package/packages/gsd-agent-core/dist/fallback-resolver.d.ts.map +0 -1
  464. package/packages/gsd-agent-core/dist/fallback-resolver.js +0 -118
  465. package/packages/gsd-agent-core/dist/fallback-resolver.js.map +0 -1
  466. package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts +0 -44
  467. package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts.map +0 -1
  468. package/packages/gsd-agent-core/dist/image-overflow-recovery.js +0 -99
  469. package/packages/gsd-agent-core/dist/image-overflow-recovery.js.map +0 -1
  470. package/packages/gsd-agent-core/dist/index.d.ts +0 -14
  471. package/packages/gsd-agent-core/dist/index.d.ts.map +0 -1
  472. package/packages/gsd-agent-core/dist/index.js +0 -19
  473. package/packages/gsd-agent-core/dist/index.js.map +0 -1
  474. package/packages/gsd-agent-core/dist/keybindings.d.ts +0 -47
  475. package/packages/gsd-agent-core/dist/keybindings.d.ts.map +0 -1
  476. package/packages/gsd-agent-core/dist/keybindings.js +0 -156
  477. package/packages/gsd-agent-core/dist/keybindings.js.map +0 -1
  478. package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts +0 -42
  479. package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts.map +0 -1
  480. package/packages/gsd-agent-core/dist/lifecycle-hooks.js +0 -204
  481. package/packages/gsd-agent-core/dist/lifecycle-hooks.js.map +0 -1
  482. package/packages/gsd-agent-core/dist/retry-handler.d.ts +0 -128
  483. package/packages/gsd-agent-core/dist/retry-handler.d.ts.map +0 -1
  484. package/packages/gsd-agent-core/dist/retry-handler.js +0 -518
  485. package/packages/gsd-agent-core/dist/retry-handler.js.map +0 -1
  486. package/packages/gsd-agent-core/dist/sdk.d.ts +0 -159
  487. package/packages/gsd-agent-core/dist/sdk.d.ts.map +0 -1
  488. package/packages/gsd-agent-core/dist/sdk.js +0 -375
  489. package/packages/gsd-agent-core/dist/sdk.js.map +0 -1
  490. package/packages/gsd-agent-core/dist/system-prompt.d.ts +0 -28
  491. package/packages/gsd-agent-core/dist/system-prompt.d.ts.map +0 -1
  492. package/packages/gsd-agent-core/dist/system-prompt.js +0 -201
  493. package/packages/gsd-agent-core/dist/system-prompt.js.map +0 -1
  494. package/packages/gsd-agent-core/package.json +0 -25
  495. package/packages/gsd-agent-core/scripts/copy-assets.cjs +0 -43
  496. package/packages/gsd-agent-core/src/agent-session.test.ts +0 -169
  497. package/packages/gsd-agent-core/src/agent-session.ts +0 -3358
  498. package/packages/gsd-agent-core/src/artifact-manager.ts +0 -126
  499. package/packages/gsd-agent-core/src/bash-executor.ts +0 -352
  500. package/packages/gsd-agent-core/src/blob-store.ts +0 -154
  501. package/packages/gsd-agent-core/src/compaction/branch-summarization.ts +0 -317
  502. package/packages/gsd-agent-core/src/compaction/compaction.ts +0 -855
  503. package/packages/gsd-agent-core/src/compaction/index.ts +0 -7
  504. package/packages/gsd-agent-core/src/compaction/utils.ts +0 -312
  505. package/packages/gsd-agent-core/src/compaction-orchestrator.ts +0 -449
  506. package/packages/gsd-agent-core/src/contextual-tips.ts +0 -232
  507. package/packages/gsd-agent-core/src/export-html/ansi-to-html.ts +0 -259
  508. package/packages/gsd-agent-core/src/export-html/index.ts +0 -345
  509. package/packages/gsd-agent-core/src/export-html/template.css +0 -971
  510. package/packages/gsd-agent-core/src/export-html/template.html +0 -54
  511. package/packages/gsd-agent-core/src/export-html/template.js +0 -1583
  512. package/packages/gsd-agent-core/src/export-html/tool-renderer.ts +0 -114
  513. package/packages/gsd-agent-core/src/export-html/vendor/highlight.min.js +0 -1213
  514. package/packages/gsd-agent-core/src/export-html/vendor/marked.min.js +0 -6
  515. package/packages/gsd-agent-core/src/fallback-resolver.ts +0 -193
  516. package/packages/gsd-agent-core/src/image-overflow-recovery.ts +0 -120
  517. package/packages/gsd-agent-core/src/index.ts +0 -68
  518. package/packages/gsd-agent-core/src/keybindings.ts +0 -220
  519. package/packages/gsd-agent-core/src/lifecycle-hooks.ts +0 -284
  520. package/packages/gsd-agent-core/src/retry-handler.ts +0 -620
  521. package/packages/gsd-agent-core/src/sdk.ts +0 -550
  522. package/packages/gsd-agent-core/src/system-prompt.ts +0 -270
  523. package/packages/gsd-agent-core/tsconfig.json +0 -28
  524. package/packages/gsd-agent-core/tsconfig.tsbuildinfo +0 -1
  525. package/packages/gsd-agent-modes/dist/cli/args.d.ts +0 -58
  526. package/packages/gsd-agent-modes/dist/cli/args.d.ts.map +0 -1
  527. package/packages/gsd-agent-modes/dist/cli/args.js +0 -324
  528. package/packages/gsd-agent-modes/dist/cli/args.js.map +0 -1
  529. package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts +0 -13
  530. package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts.map +0 -1
  531. package/packages/gsd-agent-modes/dist/cli/config-selector.js +0 -32
  532. package/packages/gsd-agent-modes/dist/cli/config-selector.js.map +0 -1
  533. package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts +0 -15
  534. package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts.map +0 -1
  535. package/packages/gsd-agent-modes/dist/cli/file-processor.js +0 -86
  536. package/packages/gsd-agent-modes/dist/cli/file-processor.js.map +0 -1
  537. package/packages/gsd-agent-modes/dist/cli/list-models.d.ts +0 -21
  538. package/packages/gsd-agent-modes/dist/cli/list-models.d.ts.map +0 -1
  539. package/packages/gsd-agent-modes/dist/cli/list-models.js +0 -114
  540. package/packages/gsd-agent-modes/dist/cli/list-models.js.map +0 -1
  541. package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts +0 -10
  542. package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts.map +0 -1
  543. package/packages/gsd-agent-modes/dist/cli/session-picker.js +0 -37
  544. package/packages/gsd-agent-modes/dist/cli/session-picker.js.map +0 -1
  545. package/packages/gsd-agent-modes/dist/index.d.ts +0 -7
  546. package/packages/gsd-agent-modes/dist/index.d.ts.map +0 -1
  547. package/packages/gsd-agent-modes/dist/index.js +0 -7
  548. package/packages/gsd-agent-modes/dist/index.js.map +0 -1
  549. package/packages/gsd-agent-modes/dist/main.d.ts +0 -8
  550. package/packages/gsd-agent-modes/dist/main.d.ts.map +0 -1
  551. package/packages/gsd-agent-modes/dist/main.js +0 -491
  552. package/packages/gsd-agent-modes/dist/main.js.map +0 -1
  553. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts +0 -34
  554. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts.map +0 -1
  555. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js +0 -330
  556. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js.map +0 -1
  557. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts +0 -29
  558. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  559. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js +0 -141
  560. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js.map +0 -1
  561. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts +0 -36
  562. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  563. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js +0 -157
  564. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js.map +0 -1
  565. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  566. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  567. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js +0 -48
  568. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  569. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  570. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  571. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js +0 -43
  572. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  573. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts +0 -11
  574. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts.map +0 -1
  575. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js +0 -47
  576. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js.map +0 -1
  577. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  578. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  579. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js +0 -44
  580. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  581. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts +0 -71
  582. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  583. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js +0 -474
  584. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js.map +0 -1
  585. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts +0 -15
  586. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  587. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js +0 -32
  588. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  589. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts +0 -22
  590. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  591. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js +0 -70
  592. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js.map +0 -1
  593. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts +0 -20
  594. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  595. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js +0 -75
  596. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js.map +0 -1
  597. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  598. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  599. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js +0 -140
  600. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js.map +0 -1
  601. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts +0 -12
  602. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts.map +0 -1
  603. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js +0 -133
  604. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js.map +0 -1
  605. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts +0 -33
  606. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  607. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js +0 -82
  608. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  609. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts +0 -20
  610. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  611. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js +0 -111
  612. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js.map +0 -1
  613. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts +0 -24
  614. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  615. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js +0 -63
  616. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js.map +0 -1
  617. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts +0 -33
  618. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  619. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js +0 -118
  620. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js.map +0 -1
  621. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts +0 -32
  622. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts.map +0 -1
  623. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js +0 -230
  624. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js.map +0 -1
  625. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts +0 -34
  626. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts.map +0 -1
  627. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js +0 -36
  628. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js.map +0 -1
  629. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts +0 -48
  630. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
  631. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js +0 -72
  632. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
  633. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts +0 -63
  634. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  635. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js +0 -213
  636. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js.map +0 -1
  637. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts +0 -86
  638. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  639. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js +0 -536
  640. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js.map +0 -1
  641. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts +0 -19
  642. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  643. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js +0 -93
  644. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  645. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts +0 -30
  646. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts.map +0 -1
  647. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js +0 -169
  648. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js.map +0 -1
  649. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -49
  650. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  651. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js +0 -267
  652. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  653. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts +0 -21
  654. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  655. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js +0 -155
  656. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  657. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts +0 -97
  658. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  659. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js +0 -810
  660. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js.map +0 -1
  661. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts +0 -71
  662. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  663. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js +0 -320
  664. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js.map +0 -1
  665. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  666. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  667. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js +0 -34
  668. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  669. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  670. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  671. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js +0 -46
  672. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  673. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  674. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  675. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js +0 -45
  676. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js.map +0 -1
  677. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
  678. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  679. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js +0 -46
  680. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  681. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts +0 -15
  682. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts.map +0 -1
  683. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js +0 -40
  684. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js.map +0 -1
  685. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +0 -111
  686. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  687. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +0 -984
  688. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +0 -1
  689. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts +0 -44
  690. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts.map +0 -1
  691. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js +0 -61
  692. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js.map +0 -1
  693. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts +0 -109
  694. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  695. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js +0 -1035
  696. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js.map +0 -1
  697. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  698. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  699. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js +0 -112
  700. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  701. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts +0 -12
  702. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  703. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js +0 -38
  704. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js.map +0 -1
  705. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
  706. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
  707. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js +0 -33
  708. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js.map +0 -1
  709. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +0 -27
  710. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +0 -1
  711. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +0 -793
  712. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +0 -1
  713. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts +0 -4
  714. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts.map +0 -1
  715. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js +0 -62
  716. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js.map +0 -1
  717. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts +0 -22
  718. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts.map +0 -1
  719. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js +0 -118
  720. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js.map +0 -1
  721. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts +0 -7
  722. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts.map +0 -1
  723. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js +0 -68
  724. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js.map +0 -1
  725. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts +0 -50
  726. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts.map +0 -1
  727. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js +0 -2
  728. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js.map +0 -1
  729. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +0 -358
  730. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  731. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +0 -3409
  732. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +0 -1
  733. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts +0 -77
  734. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts.map +0 -1
  735. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js +0 -529
  736. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js.map +0 -1
  737. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts +0 -6
  738. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts.map +0 -1
  739. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js +0 -15
  740. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js.map +0 -1
  741. package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts +0 -28
  742. package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts.map +0 -1
  743. package/packages/gsd-agent-modes/dist/modes/print-mode.js +0 -84
  744. package/packages/gsd-agent-modes/dist/modes/print-mode.js.map +0 -1
  745. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts +0 -17
  746. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts.map +0 -1
  747. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js +0 -49
  748. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js.map +0 -1
  749. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts +0 -37
  750. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts.map +0 -1
  751. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js +0 -84
  752. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js.map +0 -1
  753. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts +0 -243
  754. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts.map +0 -1
  755. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js +0 -464
  756. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js.map +0 -1
  757. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts +0 -25
  758. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +0 -1
  759. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +0 -750
  760. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +0 -1
  761. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts +0 -511
  762. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts.map +0 -1
  763. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js +0 -8
  764. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js.map +0 -1
  765. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts +0 -19
  766. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts.map +0 -1
  767. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js +0 -45
  768. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js.map +0 -1
  769. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts +0 -22
  770. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts.map +0 -1
  771. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js +0 -21
  772. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js.map +0 -1
  773. package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts +0 -4
  774. package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts.map +0 -1
  775. package/packages/gsd-agent-modes/dist/pi-tui-compat.js +0 -3
  776. package/packages/gsd-agent-modes/dist/pi-tui-compat.js.map +0 -1
  777. package/packages/gsd-agent-modes/dist/theme.d.ts +0 -15
  778. package/packages/gsd-agent-modes/dist/theme.d.ts.map +0 -1
  779. package/packages/gsd-agent-modes/dist/theme.js +0 -23
  780. package/packages/gsd-agent-modes/dist/theme.js.map +0 -1
  781. package/packages/gsd-agent-modes/dist/utils/theme.d.ts +0 -16
  782. package/packages/gsd-agent-modes/dist/utils/theme.d.ts.map +0 -1
  783. package/packages/gsd-agent-modes/dist/utils/theme.js +0 -11
  784. package/packages/gsd-agent-modes/dist/utils/theme.js.map +0 -1
  785. package/packages/gsd-agent-modes/package.json +0 -23
  786. package/packages/gsd-agent-modes/src/cli/args.ts +0 -350
  787. package/packages/gsd-agent-modes/src/cli/config-selector.ts +0 -54
  788. package/packages/gsd-agent-modes/src/cli/file-processor.ts +0 -107
  789. package/packages/gsd-agent-modes/src/cli/list-models.ts +0 -141
  790. package/packages/gsd-agent-modes/src/cli/session-picker.ts +0 -59
  791. package/packages/gsd-agent-modes/src/index.ts +0 -6
  792. package/packages/gsd-agent-modes/src/main.ts +0 -614
  793. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/login-dialog.test.ts +0 -24
  794. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/provider-display-name.test.ts +0 -18
  795. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/timestamp.test.ts +0 -38
  796. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/tool-execution.test.ts +0 -171
  797. package/packages/gsd-agent-modes/src/modes/interactive/components/armin.ts +0 -382
  798. package/packages/gsd-agent-modes/src/modes/interactive/components/assistant-message.ts +0 -178
  799. package/packages/gsd-agent-modes/src/modes/interactive/components/bash-execution.ts +0 -212
  800. package/packages/gsd-agent-modes/src/modes/interactive/components/bordered-loader.ts +0 -66
  801. package/packages/gsd-agent-modes/src/modes/interactive/components/branch-summary-message.ts +0 -59
  802. package/packages/gsd-agent-modes/src/modes/interactive/components/chat-frame.ts +0 -67
  803. package/packages/gsd-agent-modes/src/modes/interactive/components/compaction-summary-message.ts +0 -60
  804. package/packages/gsd-agent-modes/src/modes/interactive/components/config-selector.ts +0 -597
  805. package/packages/gsd-agent-modes/src/modes/interactive/components/countdown-timer.ts +0 -41
  806. package/packages/gsd-agent-modes/src/modes/interactive/components/custom-editor.ts +0 -88
  807. package/packages/gsd-agent-modes/src/modes/interactive/components/custom-message.ts +0 -100
  808. package/packages/gsd-agent-modes/src/modes/interactive/components/daxnuts.ts +0 -165
  809. package/packages/gsd-agent-modes/src/modes/interactive/components/diff.ts +0 -147
  810. package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.test.ts +0 -73
  811. package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.ts +0 -89
  812. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-editor.ts +0 -151
  813. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-input.ts +0 -100
  814. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-selector.ts +0 -156
  815. package/packages/gsd-agent-modes/src/modes/interactive/components/footer.ts +0 -257
  816. package/packages/gsd-agent-modes/src/modes/interactive/components/index.ts +0 -35
  817. package/packages/gsd-agent-modes/src/modes/interactive/components/keybinding-hints.ts +0 -84
  818. package/packages/gsd-agent-modes/src/modes/interactive/components/login-dialog.ts +0 -257
  819. package/packages/gsd-agent-modes/src/modes/interactive/components/model-selector.ts +0 -656
  820. package/packages/gsd-agent-modes/src/modes/interactive/components/oauth-selector.ts +0 -122
  821. package/packages/gsd-agent-modes/src/modes/interactive/components/provider-manager.ts +0 -210
  822. package/packages/gsd-agent-modes/src/modes/interactive/components/scoped-models-selector.ts +0 -342
  823. package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector-search.ts +0 -194
  824. package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector.ts +0 -1011
  825. package/packages/gsd-agent-modes/src/modes/interactive/components/settings-selector.ts +0 -452
  826. package/packages/gsd-agent-modes/src/modes/interactive/components/show-images-selector.ts +0 -45
  827. package/packages/gsd-agent-modes/src/modes/interactive/components/skill-invocation-message.ts +0 -56
  828. package/packages/gsd-agent-modes/src/modes/interactive/components/theme-selector.ts +0 -63
  829. package/packages/gsd-agent-modes/src/modes/interactive/components/thinking-selector.ts +0 -64
  830. package/packages/gsd-agent-modes/src/modes/interactive/components/timestamp.ts +0 -48
  831. package/packages/gsd-agent-modes/src/modes/interactive/components/tool-execution.ts +0 -1157
  832. package/packages/gsd-agent-modes/src/modes/interactive/components/tree-render-utils.ts +0 -81
  833. package/packages/gsd-agent-modes/src/modes/interactive/components/tree-selector.ts +0 -1208
  834. package/packages/gsd-agent-modes/src/modes/interactive/components/user-message-selector.ts +0 -145
  835. package/packages/gsd-agent-modes/src/modes/interactive/components/user-message.ts +0 -44
  836. package/packages/gsd-agent-modes/src/modes/interactive/components/visual-truncate.ts +0 -50
  837. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller-ordering.test.ts +0 -1430
  838. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.test.ts +0 -71
  839. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.ts +0 -957
  840. package/packages/gsd-agent-modes/src/modes/interactive/controllers/extension-ui-controller.ts +0 -63
  841. package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.test.ts +0 -183
  842. package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.ts +0 -140
  843. package/packages/gsd-agent-modes/src/modes/interactive/controllers/model-controller.ts +0 -77
  844. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-ordering.test.ts +0 -44
  845. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-state.ts +0 -49
  846. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode.ts +0 -4195
  847. package/packages/gsd-agent-modes/src/modes/interactive/slash-command-handlers.ts +0 -670
  848. package/packages/gsd-agent-modes/src/modes/interactive/utils/shorten-path.ts +0 -14
  849. package/packages/gsd-agent-modes/src/modes/print-mode.ts +0 -106
  850. package/packages/gsd-agent-modes/src/modes/rpc/jsonl.ts +0 -58
  851. package/packages/gsd-agent-modes/src/modes/rpc/remote-terminal.ts +0 -109
  852. package/packages/gsd-agent-modes/src/modes/rpc/rpc-client.ts +0 -572
  853. package/packages/gsd-agent-modes/src/modes/rpc/rpc-mode.ts +0 -902
  854. package/packages/gsd-agent-modes/src/modes/rpc/rpc-protocol-v2.test.ts +0 -971
  855. package/packages/gsd-agent-modes/src/modes/rpc/rpc-types.ts +0 -335
  856. package/packages/gsd-agent-modes/src/modes/shared/command-context-actions.ts +0 -53
  857. package/packages/gsd-agent-modes/src/pi-coding-agent-compat.ts +0 -42
  858. package/packages/gsd-agent-modes/src/pi-tui-compat.ts +0 -4
  859. package/packages/gsd-agent-modes/src/theme.ts +0 -25
  860. package/packages/gsd-agent-modes/src/utils/theme.ts +0 -24
  861. package/packages/gsd-agent-modes/tsconfig.json +0 -28
  862. package/packages/gsd-agent-modes/tsconfig.tsbuildinfo +0 -1
  863. package/packages/gsd-agent-types/dist/index.d.ts +0 -176
  864. package/packages/gsd-agent-types/dist/index.d.ts.map +0 -1
  865. package/packages/gsd-agent-types/dist/index.js +0 -24
  866. package/packages/gsd-agent-types/dist/index.js.map +0 -1
  867. package/packages/gsd-agent-types/package.json +0 -24
  868. package/packages/gsd-agent-types/src/index.ts +0 -206
  869. package/packages/gsd-agent-types/tsconfig.json +0 -25
  870. package/packages/gsd-agent-types/tsconfig.tsbuildinfo +0 -1
  871. package/packages/native/dist/tsconfig.tsbuildinfo +0 -1
  872. package/src/resources/extensions/claude-code-cli/tests/provider-registration.test.ts +0 -27
  873. /package/dist/web/standalone/.next/static/{gy6_foLMsEzdGBT19c3hr → 5wbu35_C2_MQ3Jj1lEVDx}/_buildManifest.js +0 -0
  874. /package/dist/web/standalone/.next/static/{gy6_foLMsEzdGBT19c3hr → 5wbu35_C2_MQ3Jj1lEVDx}/_ssgManifest.js +0 -0
@@ -1,3409 +0,0 @@
1
- /**
2
- * Interactive mode for the coding agent.
3
- * Handles TUI rendering and user interaction, delegating business logic to AgentSession.
4
- */
5
- import * as crypto from "node:crypto";
6
- import * as fs from "node:fs";
7
- import * as os from "node:os";
8
- import * as path from "node:path";
9
- import { listDescendants } from "@gsd/native";
10
- import { CombinedAutocompleteProvider, Container, fuzzyFilter, Loader, Markdown, matchesKey, ProcessTerminal, Spacer, Text, TruncatedText, TUI, visibleWidth, } from "@gsd/pi-tui";
11
- import { spawn, spawnSync } from "child_process";
12
- import { VERSION } from "@gsd/pi-coding-agent";
13
- import { parseSkillBlock } from "@gsd/pi-coding-agent";
14
- import { isServerToolUseBlock, isWebSearchResultBlock } from "@gsd/agent-types";
15
- import { KeybindingsManager } from "@gsd/agent-core";
16
- import { SessionManager } from "@gsd/pi-coding-agent";
17
- import { AssistantMessageComponent } from "./components/assistant-message.js";
18
- import { BashExecutionComponent } from "./components/bash-execution.js";
19
- import { BorderedLoader } from "./components/bordered-loader.js";
20
- import { BranchSummaryMessageComponent } from "./components/branch-summary-message.js";
21
- import { CompactionSummaryMessageComponent } from "./components/compaction-summary-message.js";
22
- import { CustomEditor } from "./components/custom-editor.js";
23
- import { CustomMessageComponent } from "./components/custom-message.js";
24
- import { DaxnutsComponent } from "./components/daxnuts.js";
25
- import { DynamicBorder } from "./components/dynamic-border.js";
26
- import { ExtensionEditorComponent } from "./components/extension-editor.js";
27
- import { ExtensionInputComponent } from "./components/extension-input.js";
28
- import { ExtensionSelectorComponent } from "./components/extension-selector.js";
29
- import { FooterComponent } from "./components/footer.js";
30
- import { appKey, appKeyHint, keyHint, rawKeyHint } from "./components/keybinding-hints.js";
31
- import { LoginDialogComponent } from "./components/login-dialog.js";
32
- import { ModelSelectorComponent, providerDisplayName } from "./components/model-selector.js";
33
- import { OAuthSelectorComponent } from "./components/oauth-selector.js";
34
- import { ProviderManagerComponent } from "./components/provider-manager.js";
35
- import { ScopedModelsSelectorComponent } from "./components/scoped-models-selector.js";
36
- import { SessionSelectorComponent } from "./components/session-selector.js";
37
- import { SettingsSelectorComponent } from "./components/settings-selector.js";
38
- import { SkillInvocationMessageComponent } from "./components/skill-invocation-message.js";
39
- import { ToolExecutionComponent } from "./components/tool-execution.js";
40
- import { TreeSelectorComponent } from "./components/tree-selector.js";
41
- import { UserMessageComponent } from "./components/user-message.js";
42
- import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
43
- import { APP_NAME, BUILTIN_SLASH_COMMANDS, ContextualTips, FooterDataProvider, createCompactionSummaryMessage, ensureTool, extensionForImageMimeType, getAuthPath, getChangelogPath, getDebugLogPath, getNewEntries, getUpdateInstruction, parseChangelog, readClipboardImage, resolveModelScope, } from "../../pi-coding-agent-compat.js";
44
- import { getAppKeyDisplay } from "./slash-command-handlers.js";
45
- import { handleAgentEvent } from "./controllers/chat-controller.js";
46
- import { createExtensionUIContext as buildExtensionUIContext } from "./controllers/extension-ui-controller.js";
47
- import { setupEditorSubmitHandler as setupEditorSubmitHandlerController } from "./controllers/input-controller.js";
48
- import { findExactModelMatch as findExactModelMatchController, getModelCandidates as getModelCandidatesController, handleModelCommand as handleModelCommandController, updateAvailableProviderCount as updateAvailableProviderCountController, } from "./controllers/model-controller.js";
49
- import { getMarkdownTheme, initTheme, } from "@gsd/pi-coding-agent";
50
- import { getAvailableThemes, getEditorTheme, onThemeChange, setRegisteredThemes, setTheme, stopThemeWatcher } from "../../pi-coding-agent-compat.js";
51
- import { theme } from "../../theme.js";
52
- function isExpandable(obj) {
53
- return typeof obj === "object" && obj !== null && "setExpanded" in obj && typeof obj.setExpanded === "function";
54
- }
55
- /**
56
- * Build replay segments for historical assistant messages so rebuild paths
57
- * preserve the original content[] ordering between assistant prose and tools.
58
- */
59
- export function buildAssistantReplaySegments(contentBlocks) {
60
- const segments = [];
61
- let runStart = -1;
62
- for (let i = 0; i < contentBlocks.length; i++) {
63
- const block = contentBlocks[i];
64
- const blockType = typeof block === "object" && block !== null && "type" in block ? block.type : undefined;
65
- const isAssistantText = blockType === "text" || blockType === "thinking";
66
- const isTool = blockType === "toolCall" || blockType === "serverToolUse";
67
- if (isAssistantText) {
68
- if (runStart === -1)
69
- runStart = i;
70
- continue;
71
- }
72
- if (runStart !== -1) {
73
- segments.push({ kind: "assistant", startIndex: runStart, endIndex: i - 1 });
74
- runStart = -1;
75
- }
76
- if (isTool) {
77
- segments.push({ kind: "tool", contentIndex: i });
78
- }
79
- }
80
- if (runStart !== -1) {
81
- segments.push({ kind: "assistant", startIndex: runStart, endIndex: contentBlocks.length - 1 });
82
- }
83
- return segments;
84
- }
85
- export class InteractiveMode {
86
- // Cap rendered chat components to prevent unbounded memory/CPU growth.
87
- // Only render-components are removed — session transcript stays on disk.
88
- static { this.MAX_CHAT_COMPONENTS = 100; }
89
- // Convenience accessors
90
- get agent() {
91
- return this.session.agent;
92
- }
93
- get sessionManager() {
94
- return this.session.sessionManager;
95
- }
96
- get settingsManager() {
97
- return this.session.settingsManager;
98
- }
99
- constructor(session, options = {}) {
100
- this.options = options;
101
- this.isInitialized = false;
102
- this.loadingAnimation = undefined;
103
- this.pendingWorkingMessage = undefined;
104
- this.defaultWorkingMessage = "Working...";
105
- this.lastSigintTime = 0;
106
- this.lastEscapeTime = 0;
107
- this.changelogMarkdown = undefined;
108
- // Status line tracking (for mutating immediately-sequential status updates)
109
- this.lastStatusSpacer = undefined;
110
- this.lastStatusText = undefined;
111
- // Streaming message tracking
112
- this.streamingComponent = undefined;
113
- this.streamingMessage = undefined;
114
- // Tool execution tracking: toolCallId -> component
115
- this.pendingTools = new Map();
116
- // Tool output expansion state
117
- this.toolOutputExpanded = false;
118
- // Thinking block visibility state
119
- this.hideThinkingBlock = false;
120
- // Skill commands: command name -> skill file path
121
- this.skillCommands = new Map();
122
- // Track if editor is in bash mode (text starts with !)
123
- this.isBashMode = false;
124
- // Contextual tips — session-scoped, non-intrusive hints
125
- this.contextualTips = new ContextualTips();
126
- // Track current bash execution component
127
- this.bashComponent = undefined;
128
- // Track pending bash components (shown in pending area, moved to chat on submit)
129
- this.pendingBashComponents = [];
130
- // Auto-compaction state
131
- this.autoCompactionLoader = undefined;
132
- // Auto-retry state
133
- this.retryLoader = undefined;
134
- // Messages queued while compaction is running
135
- this.compactionQueuedMessages = [];
136
- // Shutdown state
137
- this.shutdownRequested = false;
138
- // Extension UI state
139
- this.extensionSelector = undefined;
140
- this.extensionInput = undefined;
141
- this.extensionEditor = undefined;
142
- this.extensionTerminalInputUnsubscribers = new Set();
143
- // Extension widgets (components rendered above/below the editor)
144
- this.extensionWidgetsAbove = new Map();
145
- this.extensionWidgetsBelow = new Map();
146
- // Custom footer from extension (undefined = use built-in footer)
147
- this.customFooter = undefined;
148
- // Built-in header (logo + keybinding hints + changelog)
149
- this.builtInHeader = undefined;
150
- // Custom header from extension (undefined = use built-in header)
151
- this.customHeader = undefined;
152
- /**
153
- * Gracefully shutdown the agent.
154
- * Emits shutdown event to extensions, then exits.
155
- */
156
- this.isShuttingDown = false;
157
- this.session = session;
158
- this.version = VERSION;
159
- this.ui = new TUI(options.terminal ?? new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
160
- this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
161
- this.headerContainer = new Container();
162
- this.chatContainer = new Container();
163
- this.pendingMessagesContainer = new Container();
164
- this.statusContainer = new Container();
165
- this.pinnedMessageContainer = new Container();
166
- this.widgetContainerAbove = new Container();
167
- this.widgetContainerBelow = new Container();
168
- this.keybindings = KeybindingsManager.create();
169
- const editorPaddingX = this.settingsManager.getEditorPaddingX();
170
- const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
171
- this.defaultEditor = new CustomEditor(this.ui, getEditorTheme(), this.keybindings, {
172
- paddingX: editorPaddingX,
173
- autocompleteMaxVisible,
174
- });
175
- this.editor = this.defaultEditor;
176
- this.editorContainer = new Container();
177
- this.editorContainer.addChild(this.editor);
178
- this.footerDataProvider = new FooterDataProvider();
179
- /* vendor-seam: dual-module-path — AgentSession resolves to @gsd/pi-coding-agent in FooterComponent but @gsd/agent-core here */
180
- this.footer = new FooterComponent(session, this.footerDataProvider);
181
- this.footer.setAutoCompactEnabled(session.autoCompactionEnabled);
182
- // Load hide thinking block setting
183
- this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
184
- // Register themes from resource loader and initialize
185
- /* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
186
- setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
187
- initTheme(this.settingsManager.getTheme(), true);
188
- }
189
- setupAutocomplete() {
190
- // Define commands for autocomplete
191
- const slashCommands = BUILTIN_SLASH_COMMANDS.map((command) => ({
192
- name: command.name,
193
- description: command.description,
194
- }));
195
- const modelCommand = slashCommands.find((command) => command.name === "model");
196
- if (modelCommand) {
197
- modelCommand.getArgumentCompletions = (prefix) => {
198
- // Get available models (scoped or from registry)
199
- const models = this.session.scopedModels.length > 0
200
- ? this.session.scopedModels.map((s) => s.model)
201
- : this.session.modelRegistry.getAvailable();
202
- if (models.length === 0)
203
- return null;
204
- // Create items with provider/id format
205
- const items = models.map((m) => ({
206
- id: m.id,
207
- provider: m.provider,
208
- label: `${m.provider}/${m.id}`,
209
- }));
210
- // Fuzzy filter by model ID + provider (allows "opus anthropic" to match)
211
- const filtered = fuzzyFilter(items, prefix, (item) => `${item.id} ${item.provider}`);
212
- if (filtered.length === 0)
213
- return null;
214
- return filtered.map((item) => ({
215
- value: item.label,
216
- label: item.id,
217
- description: providerDisplayName(item.provider),
218
- }));
219
- };
220
- }
221
- // Add argument completions for /thinking
222
- const thinkingCommand = slashCommands.find((command) => command.name === "thinking");
223
- if (thinkingCommand) {
224
- thinkingCommand.getArgumentCompletions = (prefix) => {
225
- const levels = [
226
- { value: "off", label: "off", description: "Disable extended thinking" },
227
- { value: "minimal", label: "minimal", description: "Minimal thinking budget" },
228
- { value: "low", label: "low", description: "Low thinking budget" },
229
- { value: "medium", label: "medium", description: "Medium thinking budget" },
230
- { value: "high", label: "high", description: "High thinking budget" },
231
- { value: "xhigh", label: "xhigh", description: "Maximum thinking budget" },
232
- ];
233
- const filtered = levels.filter((l) => l.value.startsWith(prefix.trim().toLowerCase()));
234
- return filtered.length > 0 ? filtered : null;
235
- };
236
- }
237
- // Convert prompt templates to SlashCommand format for autocomplete
238
- const templateCommands = this.session.promptTemplates.map((cmd) => ({
239
- name: cmd.name,
240
- description: cmd.description,
241
- }));
242
- // Convert extension commands to SlashCommand format
243
- const builtinCommandNames = new Set(slashCommands.map((c) => c.name));
244
- const extensionCommands = (this.session.extensionRunner?.getRegisteredCommands() ?? []).filter((cmd) => !builtinCommandNames.has(cmd.name)).map((cmd) => ({
245
- name: cmd.name,
246
- description: cmd.description ?? "(extension command)",
247
- getArgumentCompletions: cmd.getArgumentCompletions,
248
- }));
249
- // Build skill commands from session.skills (if enabled)
250
- this.skillCommands.clear();
251
- const skillCommandList = [];
252
- if (this.settingsManager.getEnableSkillCommands()) {
253
- for (const skill of this.session.resourceLoader.getSkills().skills) {
254
- const commandName = `skill:${skill.name}`;
255
- this.skillCommands.set(commandName, skill.filePath);
256
- skillCommandList.push({ name: commandName, description: skill.description });
257
- }
258
- }
259
- // Setup autocomplete
260
- this.autocompleteProvider = new CombinedAutocompleteProvider([...slashCommands, ...templateCommands, ...extensionCommands, ...skillCommandList], process.cwd());
261
- this.defaultEditor.setAutocompleteProvider(this.autocompleteProvider);
262
- if (this.editor !== this.defaultEditor) {
263
- this.editor.setAutocompleteProvider?.(this.autocompleteProvider);
264
- }
265
- }
266
- async init() {
267
- if (this.isInitialized)
268
- return;
269
- // Load changelog (only show new entries, skip for resumed sessions)
270
- this.changelogMarkdown = this.getChangelogForDisplay();
271
- // Ensure rg is available (downloads if missing, adds to PATH via getBinDir)
272
- // rg is needed for grep tool and bash commands
273
- await ensureTool("rg");
274
- // Add header container as first child
275
- this.ui.addChild(this.headerContainer);
276
- // Add header with keybindings from config (unless silenced)
277
- if (this.options.verbose || !this.settingsManager.getQuietStartup()) {
278
- const logo = theme.bold(theme.fg("accent", APP_NAME)) + theme.fg("dim", ` v${this.version}`);
279
- // Build startup instructions using keybinding hint helpers
280
- const kb = this.keybindings;
281
- const hint = (action, desc) => appKeyHint(kb, action, desc);
282
- const instructions = [
283
- hint("interrupt", "to interrupt"),
284
- hint("clear", "to clear"),
285
- rawKeyHint(`${appKey(kb, "clear")} twice`, "to exit"),
286
- hint("exit", "to exit (empty)"),
287
- hint("suspend", "to suspend"),
288
- keyHint("deleteToLineEnd", "to delete to end"),
289
- hint("cycleThinkingLevel", "to cycle thinking level"),
290
- rawKeyHint(`${appKey(kb, "cycleModelForward")}/${appKey(kb, "cycleModelBackward")}`, "to cycle models"),
291
- hint("selectModel", "to select model"),
292
- hint("expandTools", "to expand tools"),
293
- hint("toggleThinking", "to expand thinking"),
294
- hint("externalEditor", "for external editor"),
295
- rawKeyHint("/", "for commands"),
296
- rawKeyHint("!", "to run bash"),
297
- rawKeyHint("!!", "to run bash (no context)"),
298
- hint("followUp", "to queue follow-up"),
299
- hint("dequeue", "to edit all queued messages"),
300
- hint("pasteImage", "to paste image"),
301
- rawKeyHint("drop files", "to attach"),
302
- ].join("\n");
303
- this.builtInHeader = new Text(`${logo}\n${instructions}`, 1, 0);
304
- // Setup UI layout
305
- this.headerContainer.addChild(new Spacer(1));
306
- this.headerContainer.addChild(this.builtInHeader);
307
- this.headerContainer.addChild(new Spacer(1));
308
- // Add changelog if provided
309
- if (this.changelogMarkdown) {
310
- this.headerContainer.addChild(new DynamicBorder());
311
- if (this.settingsManager.getCollapseChangelog()) {
312
- const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
313
- const latestVersion = versionMatch ? versionMatch[1] : this.version;
314
- const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
315
- this.headerContainer.addChild(new Text(condensedText, 1, 0));
316
- }
317
- else {
318
- this.headerContainer.addChild(new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0));
319
- this.headerContainer.addChild(new Spacer(1));
320
- this.headerContainer.addChild(new Markdown(this.changelogMarkdown.trim(), 1, 0, this.getMarkdownThemeWithSettings()));
321
- this.headerContainer.addChild(new Spacer(1));
322
- }
323
- this.headerContainer.addChild(new DynamicBorder());
324
- }
325
- }
326
- else {
327
- // Minimal header when silenced
328
- this.builtInHeader = new Text("", 0, 0);
329
- this.headerContainer.addChild(this.builtInHeader);
330
- if (this.changelogMarkdown) {
331
- // Still show changelog notification even in silent mode
332
- this.headerContainer.addChild(new Spacer(1));
333
- const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
334
- const latestVersion = versionMatch ? versionMatch[1] : this.version;
335
- const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
336
- this.headerContainer.addChild(new Text(condensedText, 1, 0));
337
- }
338
- }
339
- this.ui.addChild(this.chatContainer);
340
- this.ui.addChild(this.pendingMessagesContainer);
341
- this.ui.addChild(this.statusContainer);
342
- this.ui.addChild(this.pinnedMessageContainer);
343
- this.renderWidgets(); // Initialize with default spacer
344
- this.ui.addChild(this.widgetContainerAbove);
345
- this.ui.addChild(this.editorContainer);
346
- this.ui.addChild(this.widgetContainerBelow);
347
- this.ui.addChild(this.footer);
348
- this.ui.setFocus(this.editor);
349
- this.setupKeyHandlers();
350
- this.setupEditorSubmitHandler();
351
- // Initialize extensions first so resources are shown before messages
352
- await this.initExtensions();
353
- // Render initial messages AFTER showing loaded resources
354
- this.renderInitialMessages();
355
- // Start the UI
356
- this.ui.start();
357
- this.isInitialized = true;
358
- // Set terminal title
359
- this.updateTerminalTitle();
360
- // Subscribe to agent events
361
- this.subscribeToAgent();
362
- // Set up theme file watcher
363
- onThemeChange(() => {
364
- this.ui.invalidate();
365
- this.updateEditorBorderColor();
366
- this.ui.requestRender();
367
- });
368
- // Set up git branch watcher (uses provider instead of footer)
369
- this._branchChangeUnsub = this.footerDataProvider.onBranchChange(() => {
370
- this.ui.requestRender();
371
- });
372
- // Initialize available provider count for footer display
373
- await this.updateAvailableProviderCount();
374
- }
375
- /**
376
- * Update terminal title with session name and cwd.
377
- */
378
- updateTerminalTitle() {
379
- const cwdBasename = path.basename(process.cwd());
380
- const sessionName = this.sessionManager.getSessionName();
381
- if (sessionName) {
382
- this.ui.terminal.setTitle(`π - ${sessionName} - ${cwdBasename}`);
383
- }
384
- else {
385
- this.ui.terminal.setTitle(`π - ${cwdBasename}`);
386
- }
387
- }
388
- /**
389
- * Run the interactive mode. This is the main entry point.
390
- * Initializes the UI, shows warnings, processes initial messages, and starts the interactive loop.
391
- */
392
- async run() {
393
- await this.init();
394
- // Start version check asynchronously
395
- this.checkForNewVersion().then((newVersion) => {
396
- if (newVersion) {
397
- this.showNewVersionNotification(newVersion);
398
- }
399
- });
400
- // Check tmux keyboard setup asynchronously
401
- this.checkTmuxKeyboardSetup().then((warning) => {
402
- if (warning) {
403
- this.showWarning(warning);
404
- }
405
- });
406
- // Show startup warnings
407
- const { migratedProviders, modelFallbackMessage, initialMessage, initialImages, initialMessages } = this.options;
408
- if (migratedProviders && migratedProviders.length > 0) {
409
- this.showWarning(`Migrated credentials to auth.json: ${migratedProviders.join(", ")}`);
410
- }
411
- const modelsJsonError = this.session.modelRegistry.getError();
412
- if (modelsJsonError) {
413
- this.showError(`models.json error: ${modelsJsonError}`);
414
- }
415
- if (modelFallbackMessage) {
416
- this.showWarning(modelFallbackMessage);
417
- }
418
- // Process initial messages
419
- if (initialMessage) {
420
- try {
421
- await this.session.prompt(initialMessage, { images: initialImages });
422
- }
423
- catch (error) {
424
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
425
- this.showError(errorMessage);
426
- }
427
- }
428
- if (initialMessages) {
429
- for (const message of initialMessages) {
430
- try {
431
- await this.session.prompt(message);
432
- }
433
- catch (error) {
434
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
435
- this.showError(errorMessage);
436
- }
437
- }
438
- }
439
- // Main interactive loop
440
- while (true) {
441
- const userInput = await this.getUserInput();
442
- try {
443
- await this.session.prompt(userInput);
444
- }
445
- catch (error) {
446
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
447
- this.showError(errorMessage);
448
- }
449
- }
450
- }
451
- /**
452
- * Check npm registry for a newer version.
453
- */
454
- async checkForNewVersion() {
455
- if (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE)
456
- return undefined;
457
- try {
458
- const response = await fetch("https://registry.npmjs.org/@gsd/pi-coding-agent/latest", {
459
- signal: AbortSignal.timeout(10000),
460
- });
461
- if (!response.ok)
462
- return undefined;
463
- const data = (await response.json());
464
- const latestVersion = data.version;
465
- if (latestVersion && latestVersion !== this.version) {
466
- return latestVersion;
467
- }
468
- return undefined;
469
- }
470
- catch {
471
- return undefined;
472
- }
473
- }
474
- async checkTmuxKeyboardSetup() {
475
- if (!process.env.TMUX)
476
- return undefined;
477
- const runTmuxShow = (option) => {
478
- return new Promise((resolve) => {
479
- const proc = spawn("tmux", ["show", "-gv", option], {
480
- stdio: ["ignore", "pipe", "ignore"],
481
- });
482
- let stdout = "";
483
- const timer = setTimeout(() => {
484
- proc.kill();
485
- resolve(undefined);
486
- }, 2000);
487
- proc.stdout?.on("data", (data) => {
488
- stdout += data.toString();
489
- });
490
- proc.on("error", () => {
491
- clearTimeout(timer);
492
- resolve(undefined);
493
- });
494
- proc.on("close", (code) => {
495
- clearTimeout(timer);
496
- resolve(code === 0 ? stdout.trim() : undefined);
497
- });
498
- });
499
- };
500
- const [extendedKeys, extendedKeysFormat] = await Promise.all([
501
- runTmuxShow("extended-keys"),
502
- runTmuxShow("extended-keys-format"),
503
- ]);
504
- if (extendedKeys !== "on" && extendedKeys !== "always") {
505
- return "tmux extended-keys is off. Modified Enter keys may not work. Add `set -g extended-keys on` to ~/.tmux.conf and restart tmux.";
506
- }
507
- if (extendedKeysFormat === "xterm") {
508
- return "tmux extended-keys-format is xterm. Pi works best with csi-u. Add `set -g extended-keys-format csi-u` to ~/.tmux.conf and restart tmux.";
509
- }
510
- return undefined;
511
- }
512
- /**
513
- * Get changelog entries to display on startup.
514
- * Only shows new entries since last seen version, skips for resumed sessions.
515
- */
516
- getChangelogForDisplay() {
517
- // Skip changelog for resumed/continued sessions (already have messages)
518
- if (this.session.state.messages.length > 0) {
519
- return undefined;
520
- }
521
- const lastVersion = this.settingsManager.getLastChangelogVersion();
522
- const changelogPath = getChangelogPath();
523
- const entries = parseChangelog(changelogPath);
524
- if (!lastVersion) {
525
- // Fresh install - just record the version, don't show changelog
526
- this.settingsManager.setLastChangelogVersion(VERSION);
527
- return undefined;
528
- }
529
- else {
530
- const newEntries = getNewEntries(entries, lastVersion);
531
- if (newEntries.length > 0) {
532
- this.settingsManager.setLastChangelogVersion(VERSION);
533
- return newEntries.map((e) => e.content).join("\n\n");
534
- }
535
- }
536
- return undefined;
537
- }
538
- getMarkdownThemeWithSettings() {
539
- return {
540
- ...getMarkdownTheme(),
541
- codeBlockIndent: this.settingsManager.getCodeBlockIndent(),
542
- };
543
- }
544
- // =========================================================================
545
- // Extension System
546
- // =========================================================================
547
- formatDisplayPath(p) {
548
- const home = os.homedir();
549
- let result = p;
550
- // Replace home directory with ~
551
- if (result.startsWith(home)) {
552
- result = `~${result.slice(home.length)}`;
553
- }
554
- return result;
555
- }
556
- /**
557
- * Get a short path relative to the package root for display.
558
- */
559
- getShortPath(fullPath, source) {
560
- // For npm packages, show path relative to node_modules/pkg/
561
- const npmMatch = fullPath.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);
562
- if (npmMatch && source.startsWith("npm:")) {
563
- return npmMatch[2];
564
- }
565
- // For git packages, show path relative to repo root
566
- const gitMatch = fullPath.match(/git\/[^/]+\/[^/]+\/(.*)/);
567
- if (gitMatch && source.startsWith("git:")) {
568
- return gitMatch[1];
569
- }
570
- // For local/auto, just use formatDisplayPath
571
- return this.formatDisplayPath(fullPath);
572
- }
573
- getDisplaySourceInfo(source, scope) {
574
- if (source === "local") {
575
- if (scope === "user") {
576
- return { label: "user", color: "muted" };
577
- }
578
- if (scope === "project") {
579
- return { label: "project", color: "muted" };
580
- }
581
- if (scope === "temporary") {
582
- return { label: "path", scopeLabel: "temp", color: "muted" };
583
- }
584
- return { label: "path", color: "muted" };
585
- }
586
- if (source === "cli") {
587
- return { label: "path", scopeLabel: scope === "temporary" ? "temp" : undefined, color: "muted" };
588
- }
589
- const scopeLabel = scope === "user" ? "user" : scope === "project" ? "project" : scope === "temporary" ? "temp" : undefined;
590
- return { label: source, scopeLabel, color: "accent" };
591
- }
592
- getScopeGroup(source, scope) {
593
- if (source === "cli" || scope === "temporary")
594
- return "path";
595
- if (scope === "user")
596
- return "user";
597
- if (scope === "project")
598
- return "project";
599
- return "path";
600
- }
601
- isPackageSource(source) {
602
- return source.startsWith("npm:") || source.startsWith("git:");
603
- }
604
- buildScopeGroups(paths, metadata) {
605
- const groups = {
606
- user: { scope: "user", paths: [], packages: new Map() },
607
- project: { scope: "project", paths: [], packages: new Map() },
608
- path: { scope: "path", paths: [], packages: new Map() },
609
- };
610
- for (const p of paths) {
611
- const meta = this.findMetadata(p, metadata);
612
- const source = meta?.source ?? "local";
613
- const scope = meta?.scope ?? "project";
614
- const groupKey = this.getScopeGroup(source, scope);
615
- const group = groups[groupKey];
616
- if (this.isPackageSource(source)) {
617
- const list = group.packages.get(source) ?? [];
618
- list.push(p);
619
- group.packages.set(source, list);
620
- }
621
- else {
622
- group.paths.push(p);
623
- }
624
- }
625
- return [groups.project, groups.user, groups.path].filter((group) => group.paths.length > 0 || group.packages.size > 0);
626
- }
627
- formatScopeGroups(groups, options) {
628
- const lines = [];
629
- for (const group of groups) {
630
- lines.push(` ${theme.fg("accent", group.scope)}`);
631
- const sortedPaths = [...group.paths].sort((a, b) => a.localeCompare(b));
632
- for (const p of sortedPaths) {
633
- lines.push(theme.fg("dim", ` ${options.formatPath(p)}`));
634
- }
635
- const sortedPackages = Array.from(group.packages.entries()).sort(([a], [b]) => a.localeCompare(b));
636
- for (const [source, paths] of sortedPackages) {
637
- lines.push(` ${theme.fg("mdLink", source)}`);
638
- const sortedPackagePaths = [...paths].sort((a, b) => a.localeCompare(b));
639
- for (const p of sortedPackagePaths) {
640
- lines.push(theme.fg("dim", ` ${options.formatPackagePath(p, source)}`));
641
- }
642
- }
643
- }
644
- return lines.join("\n");
645
- }
646
- /**
647
- * Find metadata for a path, checking parent directories if exact match fails.
648
- * Package manager stores metadata for directories, but we display file paths.
649
- */
650
- findMetadata(p, metadata) {
651
- // Try exact match first
652
- const exact = metadata.get(p);
653
- if (exact)
654
- return exact;
655
- // Try parent directories (package manager stores directory paths)
656
- let current = p;
657
- let parent = path.dirname(current);
658
- while (parent !== current) {
659
- const meta = metadata.get(parent);
660
- if (meta)
661
- return meta;
662
- current = parent;
663
- parent = path.dirname(current);
664
- }
665
- return undefined;
666
- }
667
- /**
668
- * Format a path with its source/scope info from metadata.
669
- */
670
- formatPathWithSource(p, metadata) {
671
- const meta = this.findMetadata(p, metadata);
672
- if (meta) {
673
- const shortPath = this.getShortPath(p, meta.source);
674
- const { label, scopeLabel } = this.getDisplaySourceInfo(meta.source, meta.scope);
675
- const labelText = scopeLabel ? `${label} (${scopeLabel})` : label;
676
- return `${labelText} ${shortPath}`;
677
- }
678
- return this.formatDisplayPath(p);
679
- }
680
- /**
681
- * Format resource diagnostics with nice collision display using metadata.
682
- */
683
- formatDiagnostics(diagnostics, metadata) {
684
- const lines = [];
685
- // Group collision diagnostics by name
686
- const collisions = new Map();
687
- const otherDiagnostics = [];
688
- for (const d of diagnostics) {
689
- if (d.type === "collision" && d.collision) {
690
- const list = collisions.get(d.collision.name) ?? [];
691
- list.push(d);
692
- collisions.set(d.collision.name, list);
693
- }
694
- else {
695
- otherDiagnostics.push(d);
696
- }
697
- }
698
- // Format collision diagnostics grouped by name
699
- for (const [name, collisionList] of collisions) {
700
- const first = collisionList[0]?.collision;
701
- if (!first)
702
- continue;
703
- lines.push(theme.fg("warning", ` "${name}" collision:`));
704
- // Show winner
705
- lines.push(theme.fg("dim", ` ${theme.fg("success", "✓")} ${this.formatPathWithSource(first.winnerPath, metadata)}`));
706
- // Show all losers
707
- for (const d of collisionList) {
708
- if (d.collision) {
709
- lines.push(theme.fg("dim", ` ${theme.fg("warning", "✗")} ${this.formatPathWithSource(d.collision.loserPath, metadata)} (skipped)`));
710
- }
711
- }
712
- }
713
- // Format other diagnostics (skill name collisions, parse errors, etc.)
714
- for (const d of otherDiagnostics) {
715
- if (d.path) {
716
- // Use metadata-aware formatting for paths
717
- const sourceInfo = this.formatPathWithSource(d.path, metadata);
718
- lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${sourceInfo}`));
719
- lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${d.message}`));
720
- }
721
- else {
722
- lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${d.message}`));
723
- }
724
- }
725
- return lines.join("\n");
726
- }
727
- showLoadedResources(options) {
728
- const showListing = options?.force || this.options.verbose || !this.settingsManager.getQuietStartup();
729
- const showDiagnostics = showListing || options?.showDiagnosticsWhenQuiet === true;
730
- if (!showListing && !showDiagnostics) {
731
- return;
732
- }
733
- const metadata = (this.session.resourceLoader.getPathMetadata?.()
734
- ?? new Map());
735
- const sectionHeader = (name, color = "mdHeading") => theme.fg(color, `[${name}]`);
736
- const skillsResult = this.session.resourceLoader.getSkills();
737
- const promptsResult = this.session.resourceLoader.getPrompts();
738
- const themesResult = this.session.resourceLoader.getThemes();
739
- if (showListing) {
740
- const contextFiles = this.session.resourceLoader.getAgentsFiles().agentsFiles;
741
- if (contextFiles.length > 0) {
742
- this.chatContainer.addChild(new Spacer(1));
743
- const contextList = contextFiles
744
- .map((f) => theme.fg("dim", ` ${this.formatDisplayPath(f.path)}`))
745
- .join("\n");
746
- this.chatContainer.addChild(new Text(`${sectionHeader("Context")}\n${contextList}`, 0, 0));
747
- this.chatContainer.addChild(new Spacer(1));
748
- }
749
- const skills = skillsResult.skills;
750
- if (skills.length > 0) {
751
- const skillPaths = skills.map((s) => s.filePath);
752
- const groups = this.buildScopeGroups(skillPaths, metadata);
753
- const skillList = this.formatScopeGroups(groups, {
754
- formatPath: (p) => this.formatDisplayPath(p),
755
- formatPackagePath: (p, source) => this.getShortPath(p, source),
756
- });
757
- this.chatContainer.addChild(new Text(`${sectionHeader("Skills")}\n${skillList}`, 0, 0));
758
- this.chatContainer.addChild(new Spacer(1));
759
- }
760
- const templates = this.session.promptTemplates;
761
- if (templates.length > 0) {
762
- const templatePaths = templates.map((t) => t.filePath);
763
- const groups = this.buildScopeGroups(templatePaths, metadata);
764
- const templateByPath = new Map(templates.map((t) => [t.filePath, t]));
765
- const templateList = this.formatScopeGroups(groups, {
766
- formatPath: (p) => {
767
- const template = templateByPath.get(p);
768
- return template ? `/${template.name}` : this.formatDisplayPath(p);
769
- },
770
- formatPackagePath: (p) => {
771
- const template = templateByPath.get(p);
772
- return template ? `/${template.name}` : this.formatDisplayPath(p);
773
- },
774
- });
775
- this.chatContainer.addChild(new Text(`${sectionHeader("Prompts")}\n${templateList}`, 0, 0));
776
- this.chatContainer.addChild(new Spacer(1));
777
- }
778
- const extensionPaths = options?.extensionPaths ?? [];
779
- if (extensionPaths.length > 0) {
780
- const groups = this.buildScopeGroups(extensionPaths, metadata);
781
- const extList = this.formatScopeGroups(groups, {
782
- formatPath: (p) => this.formatDisplayPath(p),
783
- formatPackagePath: (p, source) => this.getShortPath(p, source),
784
- });
785
- this.chatContainer.addChild(new Text(`${sectionHeader("Extensions", "mdHeading")}\n${extList}`, 0, 0));
786
- this.chatContainer.addChild(new Spacer(1));
787
- }
788
- // Show loaded themes (excluding built-in)
789
- const loadedThemes = themesResult.themes;
790
- const customThemes = loadedThemes.filter((t) => t.sourcePath);
791
- if (customThemes.length > 0) {
792
- const themePaths = customThemes.map((t) => t.sourcePath);
793
- const groups = this.buildScopeGroups(themePaths, metadata);
794
- const themeList = this.formatScopeGroups(groups, {
795
- formatPath: (p) => this.formatDisplayPath(p),
796
- formatPackagePath: (p, source) => this.getShortPath(p, source),
797
- });
798
- this.chatContainer.addChild(new Text(`${sectionHeader("Themes")}\n${themeList}`, 0, 0));
799
- this.chatContainer.addChild(new Spacer(1));
800
- }
801
- }
802
- if (showDiagnostics) {
803
- const skillDiagnostics = skillsResult.diagnostics;
804
- if (skillDiagnostics.length > 0) {
805
- const collisionDiags = skillDiagnostics.filter(d => d.type === "collision");
806
- const issueDiags = skillDiagnostics.filter(d => d.type !== "collision");
807
- if (collisionDiags.length > 0) {
808
- const collisionLines = this.formatDiagnostics(collisionDiags, metadata);
809
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Skill conflicts]")}\n${collisionLines}`, 0, 0));
810
- this.chatContainer.addChild(new Spacer(1));
811
- }
812
- if (issueDiags.length > 0) {
813
- const issueLines = this.formatDiagnostics(issueDiags, metadata);
814
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Skill issues]")}\n${issueLines}`, 0, 0));
815
- this.chatContainer.addChild(new Spacer(1));
816
- }
817
- }
818
- const promptDiagnostics = promptsResult.diagnostics;
819
- if (promptDiagnostics.length > 0) {
820
- const warningLines = this.formatDiagnostics(promptDiagnostics, metadata);
821
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Prompt conflicts]")}\n${warningLines}`, 0, 0));
822
- this.chatContainer.addChild(new Spacer(1));
823
- }
824
- const extensionDiagnostics = [];
825
- const extensionErrors = this.session.resourceLoader.getExtensions().errors;
826
- if (extensionErrors.length > 0) {
827
- for (const error of extensionErrors) {
828
- extensionDiagnostics.push({ type: "error", message: error.error, path: error.path });
829
- }
830
- }
831
- const commandDiagnostics = this.session.extensionRunner?.getCommandDiagnostics() ?? [];
832
- extensionDiagnostics.push(...commandDiagnostics);
833
- const shortcutDiagnostics = this.session.extensionRunner?.getShortcutDiagnostics() ?? [];
834
- extensionDiagnostics.push(...shortcutDiagnostics);
835
- if (extensionDiagnostics.length > 0) {
836
- const warningLines = this.formatDiagnostics(extensionDiagnostics, metadata);
837
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Extension issues]")}\n${warningLines}`, 0, 0));
838
- this.chatContainer.addChild(new Spacer(1));
839
- }
840
- const themeDiagnostics = themesResult.diagnostics;
841
- if (themeDiagnostics.length > 0) {
842
- const warningLines = this.formatDiagnostics(themeDiagnostics, metadata);
843
- this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Theme conflicts]")}\n${warningLines}`, 0, 0));
844
- this.chatContainer.addChild(new Spacer(1));
845
- }
846
- }
847
- }
848
- /**
849
- * Initialize the extension system with TUI-based UI context.
850
- */
851
- async initExtensions() {
852
- if (this.options.bindExtensions !== false) {
853
- const uiContext = this.createExtensionUIContext();
854
- await this.session.bindExtensions({
855
- uiContext,
856
- commandContextActions: {
857
- waitForIdle: () => this.session.agent.waitForIdle(),
858
- newSession: async (options) => {
859
- if (this.loadingAnimation) {
860
- this.loadingAnimation.stop();
861
- this.loadingAnimation = undefined;
862
- }
863
- this.statusContainer.clear();
864
- // Delegate to AgentSession (handles setup + agent state sync)
865
- const success = await this.session.newSession(options);
866
- if (!success) {
867
- return { cancelled: true };
868
- }
869
- // Clear UI state
870
- this.chatContainer.clear();
871
- this.pendingMessagesContainer.clear();
872
- this.compactionQueuedMessages = [];
873
- this.streamingComponent = undefined;
874
- this.streamingMessage = undefined;
875
- this.pendingTools.clear();
876
- // Render any messages added via setup, or show empty session
877
- this.renderInitialMessages();
878
- this.ui.requestRender();
879
- return { cancelled: false };
880
- },
881
- fork: async (entryId) => {
882
- const result = await this.session.fork(entryId);
883
- if (result.cancelled) {
884
- return { cancelled: true };
885
- }
886
- this.chatContainer.clear();
887
- this.renderInitialMessages();
888
- this.editor.setText(result.selectedText);
889
- this.showStatus("Forked to new session");
890
- return { cancelled: false };
891
- },
892
- navigateTree: async (targetId, options) => {
893
- const result = await this.session.navigateTree(targetId, {
894
- summarize: options?.summarize,
895
- customInstructions: options?.customInstructions,
896
- replaceInstructions: options?.replaceInstructions,
897
- label: options?.label,
898
- });
899
- if (result.cancelled) {
900
- return { cancelled: true };
901
- }
902
- this.chatContainer.clear();
903
- this.renderInitialMessages();
904
- if (result.editorText && !this.editor.getText().trim()) {
905
- this.editor.setText(result.editorText);
906
- }
907
- this.showStatus("Navigated to selected point");
908
- return { cancelled: false };
909
- },
910
- switchSession: async (sessionPath) => {
911
- await this.handleResumeSession(sessionPath);
912
- return { cancelled: false };
913
- },
914
- reload: async () => {
915
- await this.handleReloadCommand();
916
- },
917
- },
918
- shutdownHandler: () => {
919
- this.shutdownRequested = true;
920
- if (!this.session.isStreaming) {
921
- void this.shutdown();
922
- }
923
- },
924
- onError: (error) => {
925
- const gsdError = error;
926
- this.showExtensionError(gsdError.extensionPath, gsdError.error, gsdError.stack);
927
- },
928
- });
929
- }
930
- /* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
931
- setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
932
- this.setupAutocomplete();
933
- const extensionRunner = this.session.extensionRunner;
934
- if (!extensionRunner) {
935
- this.showLoadedResources({ extensionPaths: [], force: false });
936
- return;
937
- }
938
- this.setupExtensionShortcuts(extensionRunner);
939
- this.showLoadedResources({ extensionPaths: extensionRunner.getExtensionPaths(), force: false });
940
- }
941
- /**
942
- * Get a tool definition by name (for custom rendering).
943
- */
944
- getRegisteredToolDefinition(toolName) {
945
- return this.session.getRenderableToolDefinition(toolName);
946
- }
947
- /**
948
- * Format web search result content for display in the TUI.
949
- */
950
- formatWebSearchResult(content) {
951
- if (!content)
952
- return "Web search completed";
953
- // Error result — web_search_tool_result_error is a runtime-only type not in pi-ai types
954
- if (typeof content === "object" && content !== null && "type" in content &&
955
- content.type === "web_search_tool_result_error") {
956
- const error = content;
957
- return `Search error: ${error.error_code || "unknown"}`;
958
- }
959
- // Array of search results — items are runtime-only web_search_result objects
960
- if (Array.isArray(content)) {
961
- const results = content
962
- .filter((r) => r.type === "web_search_result");
963
- if (results.length === 0)
964
- return "No results found";
965
- return results
966
- .map((r) => {
967
- const title = r.title || "Untitled";
968
- const url = r.url || "";
969
- return `${title}\n ${url}`;
970
- })
971
- .join("\n");
972
- }
973
- return "Web search completed";
974
- }
975
- /**
976
- * Set up keyboard shortcuts registered by extensions.
977
- */
978
- setupExtensionShortcuts(extensionRunner) {
979
- const shortcuts = extensionRunner.getShortcuts(this.keybindings.getEffectiveConfig());
980
- if (shortcuts.size === 0)
981
- return;
982
- // Create a context for shortcut handlers
983
- const createContext = () => ({
984
- ui: this.createExtensionUIContext(),
985
- hasUI: true,
986
- cwd: process.cwd(),
987
- sessionManager: this.sessionManager,
988
- modelRegistry: this.session.modelRegistry,
989
- model: this.session.model,
990
- isIdle: () => !this.session.isStreaming,
991
- abort: () => this.session.abort(),
992
- hasPendingMessages: () => this.session.pendingMessageCount > 0,
993
- shutdown: () => {
994
- this.shutdownRequested = true;
995
- },
996
- getContextUsage: () => this.session.getContextUsage(),
997
- compact: (options) => {
998
- void (async () => {
999
- try {
1000
- const result = await this.executeCompaction(options?.customInstructions, false);
1001
- if (result) {
1002
- options?.onComplete?.(result);
1003
- }
1004
- }
1005
- catch (error) {
1006
- const err = error instanceof Error ? error : new Error(String(error));
1007
- options?.onError?.(err);
1008
- }
1009
- })();
1010
- },
1011
- getSystemPrompt: () => this.session.systemPrompt,
1012
- });
1013
- // Set up the extension shortcut handler on the default editor
1014
- this.defaultEditor.onExtensionShortcut = (data) => {
1015
- for (const [shortcutStr, shortcut] of shortcuts) {
1016
- // Cast to KeyId - extension shortcuts use the same format
1017
- if (matchesKey(data, shortcutStr)) {
1018
- // Run handler async, don't block input
1019
- Promise.resolve(shortcut.handler(createContext())).catch((err) => {
1020
- this.showError(`Shortcut handler error: ${err instanceof Error ? err.message : String(err)}`);
1021
- });
1022
- return true;
1023
- }
1024
- }
1025
- return false;
1026
- };
1027
- }
1028
- /**
1029
- * Set extension status text in the footer.
1030
- */
1031
- setExtensionStatus(key, text) {
1032
- this.footerDataProvider.setExtensionStatus(key, text);
1033
- this.ui.requestRender();
1034
- }
1035
- /**
1036
- * Set an extension widget (string array or custom component).
1037
- */
1038
- setExtensionWidget(key, content, options) {
1039
- const placement = options?.placement ?? "aboveEditor";
1040
- const removeExisting = (map) => {
1041
- const existing = map.get(key);
1042
- if (existing?.dispose)
1043
- existing.dispose();
1044
- map.delete(key);
1045
- };
1046
- removeExisting(this.extensionWidgetsAbove);
1047
- removeExisting(this.extensionWidgetsBelow);
1048
- if (content === undefined) {
1049
- this.renderWidgets();
1050
- return;
1051
- }
1052
- let component;
1053
- if (Array.isArray(content)) {
1054
- // Wrap string array in a Container with Text components
1055
- const container = new Container();
1056
- for (const line of content.slice(0, InteractiveMode.MAX_WIDGET_LINES)) {
1057
- container.addChild(new Text(line, 1, 0));
1058
- }
1059
- if (content.length > InteractiveMode.MAX_WIDGET_LINES) {
1060
- container.addChild(new Text(theme.fg("muted", "... (widget truncated)"), 1, 0));
1061
- }
1062
- component = container;
1063
- }
1064
- else {
1065
- // Factory function - create component
1066
- component = content(this.ui, theme);
1067
- }
1068
- const targetMap = placement === "belowEditor" ? this.extensionWidgetsBelow : this.extensionWidgetsAbove;
1069
- targetMap.set(key, component);
1070
- this.renderWidgets();
1071
- }
1072
- clearExtensionWidgets() {
1073
- for (const widget of this.extensionWidgetsAbove.values()) {
1074
- widget.dispose?.();
1075
- }
1076
- for (const widget of this.extensionWidgetsBelow.values()) {
1077
- widget.dispose?.();
1078
- }
1079
- this.extensionWidgetsAbove.clear();
1080
- this.extensionWidgetsBelow.clear();
1081
- this.renderWidgets();
1082
- }
1083
- resetExtensionUI() {
1084
- if (this.extensionSelector) {
1085
- this.hideExtensionSelector();
1086
- }
1087
- if (this.extensionInput) {
1088
- this.hideExtensionInput();
1089
- }
1090
- if (this.extensionEditor) {
1091
- this.hideExtensionEditor();
1092
- }
1093
- this.ui.hideOverlay();
1094
- this.clearExtensionTerminalInputListeners();
1095
- this.setExtensionFooter(undefined);
1096
- this.setExtensionHeader(undefined);
1097
- this.clearExtensionWidgets();
1098
- this.footerDataProvider.clearExtensionStatuses();
1099
- this.footer.invalidate();
1100
- this.setCustomEditorComponent(undefined);
1101
- this.defaultEditor.onExtensionShortcut = undefined;
1102
- this.updateTerminalTitle();
1103
- if (this.loadingAnimation) {
1104
- this.loadingAnimation.setMessage(`${this.defaultWorkingMessage} (${appKey(this.keybindings, "interrupt")} to interrupt)`);
1105
- }
1106
- }
1107
- // Maximum total widget lines to prevent viewport overflow
1108
- static { this.MAX_WIDGET_LINES = 10; }
1109
- /**
1110
- * Render all extension widgets to the widget container.
1111
- */
1112
- renderWidgets() {
1113
- if (!this.widgetContainerAbove || !this.widgetContainerBelow)
1114
- return;
1115
- // widgetContainerAbove: spacer collapses when pinned content is visible
1116
- // so there's no extra blank line between pinned output and the editor border.
1117
- // Use detachChildren() (not clear()) — the extensionWidgetsAbove map owns
1118
- // disposal; clear() would dispose every mounted widget on every re-render.
1119
- const aboveGSD = this.widgetContainerAbove;
1120
- if (aboveGSD.detachChildren) {
1121
- aboveGSD.detachChildren();
1122
- }
1123
- else {
1124
- this.widgetContainerAbove.clear();
1125
- }
1126
- const pinned = this.pinnedMessageContainer;
1127
- this.widgetContainerAbove.addChild({
1128
- render: () => pinned.children.length > 0 ? [] : [""],
1129
- invalidate: () => { },
1130
- });
1131
- for (const component of this.extensionWidgetsAbove.values()) {
1132
- this.widgetContainerAbove.addChild(component);
1133
- }
1134
- this.renderWidgetContainer(this.widgetContainerBelow, this.extensionWidgetsBelow, false, false);
1135
- this.ui.requestRender();
1136
- }
1137
- renderWidgetContainer(container, widgets, spacerWhenEmpty, leadingSpacer) {
1138
- // Detach without disposing — the widgets map owns lifecycle; disposing
1139
- // here would kill refresh timers and subscriptions on every re-render.
1140
- const containerGSD = container;
1141
- if (containerGSD.detachChildren) {
1142
- containerGSD.detachChildren();
1143
- }
1144
- else {
1145
- container.clear();
1146
- }
1147
- if (widgets.size === 0) {
1148
- if (spacerWhenEmpty) {
1149
- container.addChild(new Spacer(1));
1150
- }
1151
- return;
1152
- }
1153
- if (leadingSpacer) {
1154
- container.addChild(new Spacer(1));
1155
- }
1156
- for (const component of widgets.values()) {
1157
- container.addChild(component);
1158
- }
1159
- }
1160
- /**
1161
- * Set a custom footer component, or restore the built-in footer.
1162
- */
1163
- setExtensionFooter(factory) {
1164
- // Dispose existing custom footer
1165
- if (this.customFooter?.dispose) {
1166
- this.customFooter.dispose();
1167
- }
1168
- // Remove current footer from UI
1169
- if (this.customFooter) {
1170
- this.ui.removeChild(this.customFooter);
1171
- }
1172
- else {
1173
- this.ui.removeChild(this.footer);
1174
- }
1175
- if (factory) {
1176
- // Create and add custom footer, passing the data provider
1177
- this.customFooter = factory(this.ui, theme, this.footerDataProvider);
1178
- this.ui.addChild(this.customFooter);
1179
- }
1180
- else {
1181
- // Restore built-in footer
1182
- this.customFooter = undefined;
1183
- this.ui.addChild(this.footer);
1184
- }
1185
- this.ui.requestRender();
1186
- }
1187
- /**
1188
- * Set a custom header component, or restore the built-in header.
1189
- */
1190
- setExtensionHeader(factory) {
1191
- // Header may not be initialized yet if called during early initialization
1192
- if (!this.builtInHeader) {
1193
- return;
1194
- }
1195
- // Dispose existing custom header
1196
- if (this.customHeader?.dispose) {
1197
- this.customHeader.dispose();
1198
- }
1199
- // Find the index of the current header in the header container
1200
- const currentHeader = this.customHeader || this.builtInHeader;
1201
- const index = this.headerContainer.children.indexOf(currentHeader);
1202
- if (factory) {
1203
- // Create and add custom header
1204
- this.customHeader = factory(this.ui, theme);
1205
- if (index !== -1) {
1206
- this.headerContainer.children[index] = this.customHeader;
1207
- }
1208
- else {
1209
- // If not found (e.g. builtInHeader was never added), add at the top
1210
- this.headerContainer.children.unshift(this.customHeader);
1211
- }
1212
- }
1213
- else {
1214
- // Restore built-in header
1215
- this.customHeader = undefined;
1216
- if (index !== -1) {
1217
- this.headerContainer.children[index] = this.builtInHeader;
1218
- }
1219
- }
1220
- this.ui.requestRender();
1221
- }
1222
- addExtensionTerminalInputListener(handler) {
1223
- const unsubscribe = this.ui.addInputListener(handler);
1224
- this.extensionTerminalInputUnsubscribers.add(unsubscribe);
1225
- return () => {
1226
- unsubscribe();
1227
- this.extensionTerminalInputUnsubscribers.delete(unsubscribe);
1228
- };
1229
- }
1230
- clearExtensionTerminalInputListeners() {
1231
- for (const unsubscribe of this.extensionTerminalInputUnsubscribers) {
1232
- unsubscribe();
1233
- }
1234
- this.extensionTerminalInputUnsubscribers.clear();
1235
- }
1236
- /**
1237
- * Create the ExtensionUIContext for extensions.
1238
- */
1239
- createExtensionUIContext() {
1240
- return buildExtensionUIContext(this);
1241
- }
1242
- getExtensionUIContext() {
1243
- return this.createExtensionUIContext();
1244
- }
1245
- /**
1246
- * Show a selector for extensions.
1247
- */
1248
- showExtensionSelector(title, options, opts) {
1249
- // If a previous selector is still active, dispose it before creating a
1250
- // new one. This avoids leaking the previous promise and DOM state when
1251
- // showExtensionSelector is called rapidly.
1252
- if (this.extensionSelector) {
1253
- this.hideExtensionSelector();
1254
- }
1255
- return new Promise((resolve) => {
1256
- if (opts?.signal?.aborted) {
1257
- resolve(undefined);
1258
- return;
1259
- }
1260
- const onAbort = () => {
1261
- this.hideExtensionSelector();
1262
- resolve(undefined);
1263
- };
1264
- opts?.signal?.addEventListener("abort", onAbort, { once: true });
1265
- this.extensionSelector = new ExtensionSelectorComponent(title, options, (option) => {
1266
- opts?.signal?.removeEventListener("abort", onAbort);
1267
- this.hideExtensionSelector();
1268
- resolve(option);
1269
- }, () => {
1270
- opts?.signal?.removeEventListener("abort", onAbort);
1271
- this.hideExtensionSelector();
1272
- resolve(undefined);
1273
- }, { tui: this.ui, timeout: opts?.timeout });
1274
- this.editorContainer.clear();
1275
- this.editorContainer.addChild(this.extensionSelector);
1276
- this.ui.setFocus(this.extensionSelector);
1277
- this.ui.requestRender();
1278
- });
1279
- }
1280
- /**
1281
- * Hide the extension selector.
1282
- */
1283
- hideExtensionSelector() {
1284
- this.extensionSelector?.dispose();
1285
- this.editorContainer.clear();
1286
- this.editorContainer.addChild(this.editor);
1287
- this.extensionSelector = undefined;
1288
- this.ui.setFocus(this.editor);
1289
- this.ui.requestRender();
1290
- }
1291
- /**
1292
- * Show a confirmation dialog for extensions.
1293
- */
1294
- async showExtensionConfirm(title, message, opts) {
1295
- const result = await this.showExtensionSelector(`${title}\n${message}`, ["Yes", "No"], opts);
1296
- return result === "Yes";
1297
- }
1298
- /**
1299
- * Show a text input for extensions.
1300
- */
1301
- showExtensionInput(title, placeholder, opts) {
1302
- return new Promise((resolve) => {
1303
- if (opts?.signal?.aborted) {
1304
- resolve(undefined);
1305
- return;
1306
- }
1307
- const onAbort = () => {
1308
- this.hideExtensionInput();
1309
- resolve(undefined);
1310
- };
1311
- opts?.signal?.addEventListener("abort", onAbort, { once: true });
1312
- this.extensionInput = new ExtensionInputComponent(title, placeholder, (value) => {
1313
- opts?.signal?.removeEventListener("abort", onAbort);
1314
- this.hideExtensionInput();
1315
- resolve(value);
1316
- }, () => {
1317
- opts?.signal?.removeEventListener("abort", onAbort);
1318
- this.hideExtensionInput();
1319
- resolve(undefined);
1320
- }, { tui: this.ui, timeout: opts?.timeout, secure: opts?.secure });
1321
- this.editorContainer.clear();
1322
- this.editorContainer.addChild(this.extensionInput);
1323
- this.ui.setFocus(this.extensionInput);
1324
- this.ui.requestRender();
1325
- });
1326
- }
1327
- /**
1328
- * Hide the extension input.
1329
- */
1330
- hideExtensionInput() {
1331
- this.extensionInput?.dispose();
1332
- this.editorContainer.clear();
1333
- this.editorContainer.addChild(this.editor);
1334
- this.extensionInput = undefined;
1335
- this.ui.setFocus(this.editor);
1336
- this.ui.requestRender();
1337
- }
1338
- /**
1339
- * Show a multi-line editor for extensions (with Ctrl+G support).
1340
- */
1341
- showExtensionEditor(title, prefill) {
1342
- return new Promise((resolve) => {
1343
- this.extensionEditor = new ExtensionEditorComponent(this.ui, this.keybindings, title, prefill, (value) => {
1344
- this.hideExtensionEditor();
1345
- resolve(value);
1346
- }, () => {
1347
- this.hideExtensionEditor();
1348
- resolve(undefined);
1349
- });
1350
- this.editorContainer.clear();
1351
- this.editorContainer.addChild(this.extensionEditor);
1352
- this.ui.setFocus(this.extensionEditor);
1353
- this.ui.requestRender();
1354
- });
1355
- }
1356
- /**
1357
- * Hide the extension editor.
1358
- */
1359
- hideExtensionEditor() {
1360
- this.editorContainer.clear();
1361
- this.editorContainer.addChild(this.editor);
1362
- this.extensionEditor = undefined;
1363
- this.ui.setFocus(this.editor);
1364
- this.ui.requestRender();
1365
- }
1366
- /**
1367
- * Set a custom editor component from an extension.
1368
- * Pass undefined to restore the default editor.
1369
- */
1370
- setCustomEditorComponent(factory) {
1371
- // Save text from current editor before switching
1372
- const currentText = this.editor.getText();
1373
- this.editorContainer.clear();
1374
- if (factory) {
1375
- // Create the custom editor with tui, theme, and keybindings
1376
- const newEditor = factory(this.ui, getEditorTheme(), this.keybindings);
1377
- // Wire up callbacks from the default editor
1378
- newEditor.onSubmit = this.defaultEditor.onSubmit;
1379
- newEditor.onChange = this.defaultEditor.onChange;
1380
- // Copy text from previous editor
1381
- newEditor.setText(currentText);
1382
- // Copy appearance settings if supported
1383
- if (newEditor.borderColor !== undefined) {
1384
- newEditor.borderColor = this.defaultEditor.borderColor;
1385
- }
1386
- if (newEditor.setPaddingX !== undefined) {
1387
- newEditor.setPaddingX(this.defaultEditor.getPaddingX());
1388
- }
1389
- // Set autocomplete if supported
1390
- if (newEditor.setAutocompleteProvider && this.autocompleteProvider) {
1391
- newEditor.setAutocompleteProvider(this.autocompleteProvider);
1392
- }
1393
- // If extending CustomEditor, copy app-level handlers
1394
- // Use duck typing since instanceof fails across jiti module boundaries
1395
- const customEditor = newEditor;
1396
- if ("actionHandlers" in customEditor && customEditor.actionHandlers instanceof Map) {
1397
- if (!customEditor.onEscape) {
1398
- customEditor.onEscape = () => this.defaultEditor.onEscape?.();
1399
- }
1400
- if (!customEditor.onCtrlD) {
1401
- customEditor.onCtrlD = () => this.defaultEditor.onCtrlD?.();
1402
- }
1403
- if (!customEditor.onPasteImage) {
1404
- customEditor.onPasteImage = () => this.defaultEditor.onPasteImage?.();
1405
- }
1406
- if (!customEditor.onExtensionShortcut) {
1407
- customEditor.onExtensionShortcut = (data) => this.defaultEditor.onExtensionShortcut?.(data);
1408
- }
1409
- // Copy action handlers (clear, suspend, model switching, etc.)
1410
- for (const [action, handler] of this.defaultEditor.actionHandlers) {
1411
- customEditor.actionHandlers.set(action, handler);
1412
- }
1413
- }
1414
- this.editor = newEditor;
1415
- }
1416
- else {
1417
- // Restore default editor with text from custom editor
1418
- this.defaultEditor.setText(currentText);
1419
- this.editor = this.defaultEditor;
1420
- }
1421
- this.editorContainer.addChild(this.editor);
1422
- this.ui.setFocus(this.editor);
1423
- this.ui.requestRender();
1424
- }
1425
- /**
1426
- * Show a notification for extensions.
1427
- */
1428
- showExtensionNotify(message, type) {
1429
- if (type === "error") {
1430
- this.showError(message);
1431
- }
1432
- else if (type === "warning") {
1433
- this.showWarning(message);
1434
- }
1435
- else if (type === "success") {
1436
- this.showSuccess(message);
1437
- }
1438
- else {
1439
- this.showStatus(message, { append: true });
1440
- }
1441
- }
1442
- /** Show a custom component with keyboard focus. Overlay mode renders on top of existing content. */
1443
- async showExtensionCustom(factory, options) {
1444
- const savedText = this.editor.getText();
1445
- const isOverlay = options?.overlay ?? false;
1446
- const restoreEditor = () => {
1447
- this.editorContainer.clear();
1448
- this.editorContainer.addChild(this.editor);
1449
- this.editor.setText(savedText);
1450
- this.ui.setFocus(this.editor);
1451
- this.ui.requestRender();
1452
- };
1453
- return new Promise((resolve, reject) => {
1454
- let component;
1455
- let closed = false;
1456
- const close = (result) => {
1457
- if (closed)
1458
- return;
1459
- closed = true;
1460
- if (isOverlay)
1461
- this.ui.hideOverlay();
1462
- else
1463
- restoreEditor();
1464
- // Note: both branches above already call requestRender
1465
- resolve(result);
1466
- try {
1467
- component?.dispose?.();
1468
- }
1469
- catch {
1470
- /* ignore dispose errors */
1471
- }
1472
- };
1473
- Promise.resolve(factory(this.ui, theme, this.keybindings, close))
1474
- .then((c) => {
1475
- if (closed)
1476
- return;
1477
- component = c;
1478
- if (isOverlay) {
1479
- // Resolve overlay options - can be static or dynamic function
1480
- const resolveOptions = () => {
1481
- if (options?.overlayOptions) {
1482
- const opts = typeof options.overlayOptions === "function"
1483
- ? options.overlayOptions()
1484
- : options.overlayOptions;
1485
- return opts;
1486
- }
1487
- // Fallback: use component's width property if available
1488
- const w = component.width;
1489
- return w ? { width: w } : undefined;
1490
- };
1491
- const handle = this.ui.showOverlay(component, resolveOptions());
1492
- // Expose handle to caller for visibility control
1493
- options?.onHandle?.(handle);
1494
- }
1495
- else {
1496
- this.editorContainer.clear();
1497
- this.editorContainer.addChild(component);
1498
- this.ui.setFocus(component);
1499
- this.ui.requestRender();
1500
- }
1501
- })
1502
- .catch((err) => {
1503
- if (closed)
1504
- return;
1505
- if (!isOverlay)
1506
- restoreEditor();
1507
- reject(err);
1508
- });
1509
- });
1510
- }
1511
- /**
1512
- * Show an extension error in the UI.
1513
- */
1514
- showExtensionError(extensionPath, error, stack) {
1515
- const errorMsg = `Extension "${extensionPath}" error: ${error}`;
1516
- const errorText = new Text(theme.fg("error", errorMsg), 1, 0);
1517
- this.chatContainer.addChild(errorText);
1518
- if (stack) {
1519
- // Show stack trace in dim color, indented
1520
- const stackLines = stack
1521
- .split("\n")
1522
- .slice(1) // Skip first line (duplicates error message)
1523
- .map((line) => theme.fg("dim", ` ${line.trim()}`))
1524
- .join("\n");
1525
- if (stackLines) {
1526
- this.chatContainer.addChild(new Text(stackLines, 1, 0));
1527
- }
1528
- }
1529
- this.ui.requestRender();
1530
- }
1531
- // =========================================================================
1532
- // Key Handlers
1533
- // =========================================================================
1534
- setupKeyHandlers() {
1535
- // Set up handlers on defaultEditor - they use this.editor for text access
1536
- // so they work correctly regardless of which editor is active
1537
- this.defaultEditor.onEscape = () => {
1538
- if (this.loadingAnimation) {
1539
- this.restoreQueuedMessagesToEditor({ abort: true });
1540
- }
1541
- else if (this.session.isBashRunning) {
1542
- this.session.abortBash();
1543
- }
1544
- else if (this.isBashMode) {
1545
- this.editor.setText("");
1546
- this.isBashMode = false;
1547
- this.updateEditorBorderColor();
1548
- }
1549
- else if (!this.editor.getText().trim()) {
1550
- // Double-escape with empty editor triggers /tree, /fork, or nothing based on setting
1551
- const action = this.settingsManager.getDoubleEscapeAction();
1552
- if (action !== "none") {
1553
- const now = Date.now();
1554
- if (now - this.lastEscapeTime < 500) {
1555
- if (action === "tree") {
1556
- this.showTreeSelector();
1557
- }
1558
- else {
1559
- this.showUserMessageSelector();
1560
- }
1561
- this.lastEscapeTime = 0;
1562
- }
1563
- else {
1564
- this.lastEscapeTime = now;
1565
- }
1566
- }
1567
- }
1568
- };
1569
- // Register app action handlers
1570
- this.defaultEditor.onAction("clear", () => this.handleCtrlC());
1571
- this.defaultEditor.onCtrlD = () => this.handleCtrlD();
1572
- this.defaultEditor.onAction("suspend", () => this.handleCtrlZ());
1573
- this.defaultEditor.onAction("cycleThinkingLevel", () => this.cycleThinkingLevel());
1574
- this.defaultEditor.onAction("cycleModelForward", () => this.cycleModel("forward"));
1575
- this.defaultEditor.onAction("cycleModelBackward", () => this.cycleModel("backward"));
1576
- // Global debug handler on TUI (works regardless of focus)
1577
- this.ui.onDebug = () => this.handleDebugCommand();
1578
- this.defaultEditor.onAction("selectModel", () => this.showModelSelector());
1579
- this.defaultEditor.onAction("expandTools", () => this.toggleToolOutputExpansion());
1580
- this.defaultEditor.onAction("toggleThinking", () => this.toggleThinkingBlockVisibility());
1581
- this.defaultEditor.onAction("externalEditor", () => this.openExternalEditor());
1582
- this.defaultEditor.onAction("followUp", () => this.handleFollowUp());
1583
- this.defaultEditor.onAction("dequeue", () => this.handleDequeue());
1584
- this.defaultEditor.onAction("newSession", () => this.handleClearCommand());
1585
- this.defaultEditor.onAction("tree", () => this.showTreeSelector());
1586
- this.defaultEditor.onAction("fork", () => this.showUserMessageSelector());
1587
- this.defaultEditor.onAction("resume", () => this.showSessionSelector());
1588
- this.defaultEditor.onChange = (text) => {
1589
- const wasBashMode = this.isBashMode;
1590
- this.isBashMode = text.trimStart().startsWith("!");
1591
- if (wasBashMode !== this.isBashMode) {
1592
- this.updateEditorBorderColor();
1593
- }
1594
- };
1595
- // Handle clipboard image paste (triggered on Ctrl+V)
1596
- this.defaultEditor.onPasteImage = () => {
1597
- this.handleClipboardImagePaste();
1598
- };
1599
- }
1600
- async handleClipboardImagePaste() {
1601
- try {
1602
- const image = await readClipboardImage();
1603
- if (!image) {
1604
- return;
1605
- }
1606
- // Write to temp file
1607
- const tmpDir = os.tmpdir();
1608
- const ext = extensionForImageMimeType(image.mimeType) ?? "png";
1609
- const fileName = `pi-clipboard-${crypto.randomUUID()}.${ext}`;
1610
- const filePath = path.join(tmpDir, fileName);
1611
- fs.writeFileSync(filePath, Buffer.from(image.bytes));
1612
- // Insert file path directly
1613
- this.editor.insertTextAtCursor?.(filePath);
1614
- this.ui.requestRender();
1615
- }
1616
- catch {
1617
- // Silently ignore clipboard errors (may not have permission, etc.)
1618
- }
1619
- }
1620
- getSlashCommandContext() {
1621
- return {
1622
- session: this.session,
1623
- ui: this.ui,
1624
- keybindings: this.keybindings,
1625
- chatContainer: this.chatContainer,
1626
- statusContainer: this.statusContainer,
1627
- editorContainer: this.editorContainer,
1628
- headerContainer: this.headerContainer,
1629
- pendingMessagesContainer: this.pendingMessagesContainer,
1630
- editor: this.editor,
1631
- defaultEditor: this.defaultEditor,
1632
- sessionManager: this.sessionManager,
1633
- settingsManager: this.settingsManager,
1634
- invalidateFooter: () => this.footer.invalidate(),
1635
- showStatus: (msg) => this.showStatus(msg),
1636
- showError: (msg) => this.showError(msg),
1637
- showWarning: (msg) => this.showWarning(msg),
1638
- showSelector: (create) => this.showSelector(create),
1639
- updateEditorBorderColor: () => this.updateEditorBorderColor(),
1640
- getMarkdownThemeWithSettings: () => this.getMarkdownThemeWithSettings(),
1641
- requestRender: () => this.ui.requestRender(),
1642
- updateTerminalTitle: () => this.updateTerminalTitle(),
1643
- showSettingsSelector: () => this.showSettingsSelector(),
1644
- showModelsSelector: () => this.showModelsSelector(),
1645
- handleModelCommand: (searchTerm) => this.handleModelCommand(searchTerm),
1646
- showUserMessageSelector: () => this.showUserMessageSelector(),
1647
- showTreeSelector: () => this.showTreeSelector(),
1648
- showProviderManager: () => this.showProviderManager(),
1649
- showOAuthSelector: (mode) => this.showOAuthSelector(mode),
1650
- showSessionSelector: () => this.showSessionSelector(),
1651
- handleClearCommand: () => this.handleClearCommand(),
1652
- handleReloadCommand: () => this.handleReloadCommand(),
1653
- handleDebugCommand: () => this.handleDebugCommand(),
1654
- shutdown: () => this.shutdown(),
1655
- executeCompaction: (instructions, isAuto) => this.executeCompaction(instructions, isAuto),
1656
- handleBashCommand: (command, options) => this.handleBashCommand(command, options?.excludeFromContext, options?.displayCommand, options?.loginShell),
1657
- };
1658
- }
1659
- setupEditorSubmitHandler() {
1660
- setupEditorSubmitHandlerController(this);
1661
- }
1662
- subscribeToAgent() {
1663
- let eventQueue = Promise.resolve();
1664
- this.unsubscribe = this.session.subscribe((event) => {
1665
- eventQueue = eventQueue.then(() => this.handleEvent(event)).catch(() => { });
1666
- });
1667
- }
1668
- async handleEvent(event) {
1669
- await handleAgentEvent(this, event);
1670
- }
1671
- /** Extract text content from a user message */
1672
- getUserMessageText(message) {
1673
- if (message.role !== "user")
1674
- return "";
1675
- const textBlocks = typeof message.content === "string"
1676
- ? [{ type: "text", text: message.content }]
1677
- : message.content.filter((c) => c.type === "text");
1678
- return textBlocks.map((c) => c.text).join("");
1679
- }
1680
- /**
1681
- * Show a status message in the chat.
1682
- *
1683
- * If multiple status messages are emitted back-to-back (without anything else being added to the chat),
1684
- * we update the previous status line instead of appending new ones to avoid log spam.
1685
- */
1686
- showStatus(message, options) {
1687
- const append = options?.append ?? false;
1688
- const children = this.chatContainer.children;
1689
- const last = children.length > 0 ? children[children.length - 1] : undefined;
1690
- const secondLast = children.length > 1 ? children[children.length - 2] : undefined;
1691
- if (!append && last && secondLast && last === this.lastStatusText && secondLast === this.lastStatusSpacer) {
1692
- this.lastStatusText.setText(theme.fg("dim", message));
1693
- this.ui.requestRender();
1694
- return;
1695
- }
1696
- const spacer = new Spacer(1);
1697
- const text = new Text(theme.fg("dim", message), 1, 0);
1698
- this.chatContainer.addChild(spacer);
1699
- this.chatContainer.addChild(text);
1700
- this.lastStatusSpacer = spacer;
1701
- this.lastStatusText = text;
1702
- this.ui.requestRender();
1703
- }
1704
- getTimestampFormat() {
1705
- return this.settingsManager.getTimestampFormat?.() ?? "date-time-iso";
1706
- }
1707
- addMessageToChat(message, options) {
1708
- const timestampFormat = this.getTimestampFormat();
1709
- switch (message.role) {
1710
- case "bashExecution": {
1711
- const component = new BashExecutionComponent(message.command, this.ui, message.excludeFromContext);
1712
- if (message.output) {
1713
- component.appendOutput(message.output);
1714
- }
1715
- component.setComplete(message.exitCode, message.cancelled, message.truncated ? { truncated: true } : undefined, message.fullOutputPath);
1716
- this.chatContainer.addChild(component);
1717
- break;
1718
- }
1719
- case "custom": {
1720
- if (message.display) {
1721
- const renderer = this.session.extensionRunner?.getMessageRenderer(message.customType);
1722
- const component = new CustomMessageComponent(message, renderer, this.getMarkdownThemeWithSettings());
1723
- component.setExpanded(this.toolOutputExpanded);
1724
- this.chatContainer.addChild(component);
1725
- }
1726
- break;
1727
- }
1728
- case "compactionSummary": {
1729
- this.chatContainer.addChild(new Spacer(1));
1730
- const component = new CompactionSummaryMessageComponent(message, this.getMarkdownThemeWithSettings());
1731
- component.setExpanded(this.toolOutputExpanded);
1732
- this.chatContainer.addChild(component);
1733
- break;
1734
- }
1735
- case "branchSummary": {
1736
- this.chatContainer.addChild(new Spacer(1));
1737
- const component = new BranchSummaryMessageComponent(message, this.getMarkdownThemeWithSettings());
1738
- component.setExpanded(this.toolOutputExpanded);
1739
- this.chatContainer.addChild(component);
1740
- break;
1741
- }
1742
- case "user": {
1743
- const textContent = this.getUserMessageText(message);
1744
- if (textContent) {
1745
- const skillBlock = parseSkillBlock(textContent);
1746
- if (skillBlock) {
1747
- // Render skill block (collapsible)
1748
- this.chatContainer.addChild(new Spacer(1));
1749
- const component = new SkillInvocationMessageComponent(skillBlock, this.getMarkdownThemeWithSettings());
1750
- component.setExpanded(this.toolOutputExpanded);
1751
- this.chatContainer.addChild(component);
1752
- // Render user message separately if present
1753
- if (skillBlock.userMessage) {
1754
- const userComponent = new UserMessageComponent(skillBlock.userMessage, this.getMarkdownThemeWithSettings(), message.timestamp, timestampFormat);
1755
- this.chatContainer.addChild(userComponent);
1756
- }
1757
- }
1758
- else {
1759
- const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings(), message.timestamp, timestampFormat);
1760
- this.chatContainer.addChild(userComponent);
1761
- }
1762
- if (options?.populateHistory) {
1763
- this.editor.addToHistory?.(textContent);
1764
- }
1765
- }
1766
- break;
1767
- }
1768
- case "assistant": {
1769
- const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), timestampFormat);
1770
- this.chatContainer.addChild(assistantComponent);
1771
- break;
1772
- }
1773
- case "toolResult": {
1774
- // Tool results are rendered inline with tool calls, handled separately
1775
- break;
1776
- }
1777
- default: {
1778
- const _exhaustive = message;
1779
- }
1780
- }
1781
- this.trimChatHistory();
1782
- }
1783
- /**
1784
- * Remove oldest components when chat exceeds MAX_CHAT_COMPONENTS.
1785
- * Only render-components are removed — session data stays in SessionManager.
1786
- */
1787
- trimChatHistory() {
1788
- while (this.chatContainer.children.length > InteractiveMode.MAX_CHAT_COMPONENTS) {
1789
- const oldest = this.chatContainer.children[0];
1790
- this.chatContainer.removeChild(oldest);
1791
- }
1792
- }
1793
- /**
1794
- * Render session context to chat. Used for initial load and rebuild after compaction.
1795
- * @param sessionContext Session context to render
1796
- * @param options.updateFooter Update footer state
1797
- * @param options.populateHistory Add user messages to editor history
1798
- */
1799
- renderSessionContext(sessionContext, options = {}) {
1800
- this.pendingTools.clear();
1801
- const timestampFormat = this.getTimestampFormat();
1802
- if (options.updateFooter) {
1803
- this.footer.invalidate();
1804
- this.updateEditorBorderColor();
1805
- }
1806
- for (const message of sessionContext.messages) {
1807
- // Assistant messages need special handling for tool calls
1808
- if (message.role === "assistant") {
1809
- const hasToolBlocks = message.content.some((c) => c.type === "toolCall" || isServerToolUseBlock(c));
1810
- if (!hasToolBlocks) {
1811
- this.addMessageToChat(message);
1812
- continue;
1813
- }
1814
- const assistantSegments = [];
1815
- const replaySegments = buildAssistantReplaySegments(message.content);
1816
- for (const segment of replaySegments) {
1817
- if (segment.kind === "assistant") {
1818
- const assistantComponent = new AssistantMessageComponent(message, this.hideThinkingBlock, this.getMarkdownThemeWithSettings(), timestampFormat, { startIndex: segment.startIndex, endIndex: segment.endIndex });
1819
- this.chatContainer.addChild(assistantComponent);
1820
- assistantSegments.push(assistantComponent);
1821
- continue;
1822
- }
1823
- const content = message.content[segment.contentIndex];
1824
- if (content.type === "toolCall") {
1825
- const component = new ToolExecutionComponent(content.name, content.arguments, { showImages: this.settingsManager.getShowImages() }, this.getRegisteredToolDefinition(content.name), this.ui);
1826
- component.setExpanded(this.toolOutputExpanded);
1827
- this.chatContainer.addChild(component);
1828
- if (message.stopReason === "aborted" || message.stopReason === "error") {
1829
- let errorMessage;
1830
- if (message.stopReason === "aborted") {
1831
- const retryAttempt = this.session.retryAttempt;
1832
- errorMessage =
1833
- retryAttempt > 0
1834
- ? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? "s" : ""}`
1835
- : "Operation aborted";
1836
- }
1837
- else {
1838
- errorMessage = message.errorMessage || "Error";
1839
- }
1840
- component.updateResult({ content: [{ type: "text", text: errorMessage }], isError: true });
1841
- }
1842
- else {
1843
- this.pendingTools.set(content.id, component);
1844
- }
1845
- }
1846
- else if (isServerToolUseBlock(content)) {
1847
- // Server-side tool (e.g., native web search)
1848
- const component = new ToolExecutionComponent(content.name, content.input, { showImages: this.settingsManager.getShowImages() }, undefined, this.ui);
1849
- component.setExpanded(this.toolOutputExpanded);
1850
- this.chatContainer.addChild(component);
1851
- // Find matching webSearchResult in this message's content
1852
- const resultBlock = message.content.find((c) => isWebSearchResultBlock(c) && c.toolUseId === content.id);
1853
- if (resultBlock && isWebSearchResultBlock(resultBlock)) {
1854
- const searchContent = resultBlock.content;
1855
- const isError = searchContent && typeof searchContent === "object" && "type" in searchContent && searchContent.type === "web_search_tool_result_error";
1856
- const resultText = this.formatWebSearchResult(searchContent);
1857
- component.updateResult({
1858
- content: [{ type: "text", text: resultText }],
1859
- isError: !!isError,
1860
- });
1861
- }
1862
- else {
1863
- // No result yet (aborted stream?) — show as pending
1864
- if (content.id) {
1865
- this.pendingTools.set(content.id, component);
1866
- }
1867
- }
1868
- }
1869
- }
1870
- // Match streaming-mode behavior: show metadata once on the final
1871
- // assistant prose segment for this message.
1872
- const lastAssistantSegment = assistantSegments[assistantSegments.length - 1];
1873
- lastAssistantSegment?.setShowMetadata(true);
1874
- }
1875
- else if (message.role === "toolResult") {
1876
- // Match tool results to pending tool components
1877
- const component = this.pendingTools.get(message.toolCallId);
1878
- if (component) {
1879
- component.updateResult(message);
1880
- this.pendingTools.delete(message.toolCallId);
1881
- }
1882
- }
1883
- else {
1884
- // All other messages use standard rendering
1885
- this.addMessageToChat(message, options);
1886
- }
1887
- }
1888
- // Any pendingTools entries left over after replay are historical tool
1889
- // calls whose results were squashed out of session context (commonly by
1890
- // compaction). Mark them finished so the frame stops showing "Running".
1891
- for (const component of this.pendingTools.values()) {
1892
- component.markHistoricalNoResult();
1893
- }
1894
- this.pendingTools.clear();
1895
- this.trimChatHistory();
1896
- this.ui.requestRender();
1897
- }
1898
- renderInitialMessages() {
1899
- // Get aligned messages and entries from session context
1900
- const context = this.sessionManager.buildSessionContext();
1901
- this.renderSessionContext(context, {
1902
- updateFooter: true,
1903
- populateHistory: true,
1904
- });
1905
- this.populatePinnedFromMessages(context.messages);
1906
- // Show compaction info if session was compacted
1907
- const allEntries = this.sessionManager.getEntries();
1908
- const compactionCount = allEntries.filter((e) => e.type === "compaction").length;
1909
- if (compactionCount > 0) {
1910
- const times = compactionCount === 1 ? "1 time" : `${compactionCount} times`;
1911
- this.showStatus(`Session compacted ${times}`);
1912
- }
1913
- }
1914
- async getUserInput() {
1915
- return new Promise((resolve) => {
1916
- this.onInputCallback = (text) => {
1917
- this.onInputCallback = undefined;
1918
- resolve(text);
1919
- };
1920
- });
1921
- }
1922
- rebuildChatFromMessages() {
1923
- this.chatContainer.clear();
1924
- this.pinnedMessageContainer.clear();
1925
- const context = this.sessionManager.buildSessionContext();
1926
- this.renderSessionContext(context);
1927
- // Pinned content NOT re-populated here — the streaming lifecycle in
1928
- // chat-controller.ts manages the pinned zone during active work.
1929
- // populatePinnedFromMessages() remains in renderInitialMessages()
1930
- // for the session-resume case at startup.
1931
- }
1932
- /**
1933
- * After rebuilding chat from messages, pin the last assistant text above the
1934
- * editor if tool results would otherwise push it out of the viewport.
1935
- */
1936
- populatePinnedFromMessages(messages) {
1937
- this.pinnedMessageContainer.clear();
1938
- // Walk backwards to find the last assistant message
1939
- let lastAssistant;
1940
- for (let i = messages.length - 1; i >= 0; i--) {
1941
- const msg = messages[i];
1942
- if (msg && "role" in msg && msg.role === "assistant") {
1943
- lastAssistant = msg;
1944
- break;
1945
- }
1946
- }
1947
- if (!lastAssistant)
1948
- return;
1949
- // Check if any tool calls follow the last text block
1950
- const content = lastAssistant.content;
1951
- let lastTextIndex = -1;
1952
- let hasToolAfterText = false;
1953
- for (let i = 0; i < content.length; i++) {
1954
- if (content[i].type === "text")
1955
- lastTextIndex = i;
1956
- }
1957
- if (lastTextIndex >= 0) {
1958
- for (let i = lastTextIndex + 1; i < content.length; i++) {
1959
- const block = content[i];
1960
- if (block.type === "toolCall" || isServerToolUseBlock(block)) {
1961
- hasToolAfterText = true;
1962
- break;
1963
- }
1964
- }
1965
- }
1966
- if (!hasToolAfterText || lastTextIndex < 0)
1967
- return;
1968
- const textBlock = content[lastTextIndex];
1969
- const text = textBlock.text?.trim();
1970
- if (!text)
1971
- return;
1972
- this.pinnedMessageContainer.addChild(new DynamicBorder((str) => theme.fg("dim", str), "Latest Output"));
1973
- this.pinnedMessageContainer.addChild(new Markdown(text, 1, 0, this.getMarkdownThemeWithSettings()));
1974
- }
1975
- // =========================================================================
1976
- // Key handlers
1977
- // =========================================================================
1978
- handleCtrlC() {
1979
- const now = Date.now();
1980
- if (now - this.lastSigintTime < 500) {
1981
- void this.shutdown();
1982
- }
1983
- else {
1984
- this.clearEditor();
1985
- this.lastSigintTime = now;
1986
- }
1987
- }
1988
- handleCtrlD() {
1989
- // Only called when editor is empty (enforced by CustomEditor)
1990
- void this.shutdown();
1991
- }
1992
- async shutdown() {
1993
- const shutdownBehavior = this.options.shutdownBehavior ?? "exit_process";
1994
- if (shutdownBehavior === "ignore") {
1995
- this.showStatus("Quit is unavailable in the browser-attached terminal");
1996
- return;
1997
- }
1998
- if (this.isShuttingDown)
1999
- return;
2000
- this.isShuttingDown = true;
2001
- // Flush any queued settings writes before shutdown
2002
- await this.settingsManager.flush();
2003
- // Emit shutdown event to extensions
2004
- const extensionRunner = this.session.extensionRunner;
2005
- if (extensionRunner?.hasHandlers("session_shutdown")) {
2006
- await extensionRunner.emit({
2007
- type: "session_shutdown",
2008
- });
2009
- }
2010
- // Wait for any pending renders to complete
2011
- // requestRender() uses process.nextTick(), so we wait one tick
2012
- await new Promise((resolve) => process.nextTick(resolve));
2013
- // Drain any in-flight Kitty key release events before stopping.
2014
- // This prevents escape sequences from leaking to the parent shell over slow SSH.
2015
- await this.ui.terminal.drainInput(1000);
2016
- this.stop();
2017
- if (shutdownBehavior === "stop_ui") {
2018
- return;
2019
- }
2020
- // Kill ALL descendant processes to prevent orphans (next-server, pnpm dev, etc.)
2021
- try {
2022
- const descendants = listDescendants(process.pid);
2023
- for (const childPid of descendants) {
2024
- try {
2025
- process.kill(childPid, "SIGTERM");
2026
- }
2027
- catch (_e) { /* ignore — process may have already exited */ }
2028
- }
2029
- if (descendants.length > 0) {
2030
- await new Promise(resolve => setTimeout(resolve, 500));
2031
- for (const childPid of descendants) {
2032
- try {
2033
- process.kill(childPid, "SIGKILL");
2034
- }
2035
- catch (_e) { /* ignore — process may have already exited */ }
2036
- }
2037
- }
2038
- }
2039
- catch (_e) { /* ignore — listDescendants may fail on some platforms */ }
2040
- process.exit(0);
2041
- }
2042
- /**
2043
- * Check if shutdown was requested and perform shutdown if so.
2044
- */
2045
- async checkShutdownRequested() {
2046
- if (!this.shutdownRequested)
2047
- return;
2048
- await this.shutdown();
2049
- }
2050
- handleCtrlZ() {
2051
- // On Windows, SIGTSTP doesn't exist - Ctrl+Z is not supported
2052
- if (process.platform === "win32") {
2053
- return;
2054
- }
2055
- // Ignore SIGINT while suspended so Ctrl+C in the terminal does not
2056
- // kill the backgrounded process. The handler is removed on resume.
2057
- const ignoreSigint = () => { };
2058
- process.on("SIGINT", ignoreSigint);
2059
- try {
2060
- // Set up handler to restore TUI when resumed
2061
- process.once("SIGCONT", () => {
2062
- process.removeListener("SIGINT", ignoreSigint);
2063
- this.ui.start();
2064
- this.ui.requestRender(true);
2065
- });
2066
- // Stop the TUI (restore terminal to normal mode)
2067
- this.ui.stop();
2068
- // Send SIGTSTP to process group (pid=0 means all processes in group)
2069
- process.kill(0, "SIGTSTP");
2070
- }
2071
- catch {
2072
- // If suspend fails (e.g. SIGTSTP not supported), ensure the
2073
- // SIGINT listener doesn't leak.
2074
- process.removeListener("SIGINT", ignoreSigint);
2075
- }
2076
- }
2077
- async handleFollowUp() {
2078
- const text = (this.editor.getExpandedText?.() ?? this.editor.getText()).trim();
2079
- if (!text)
2080
- return;
2081
- if (text.startsWith("/") && !this.isKnownSlashCommand(text)) {
2082
- const command = text.split(/\s/)[0];
2083
- this.showError(`Unknown command: ${command}. Use slash autocomplete to see available commands.`);
2084
- return;
2085
- }
2086
- // Queue input during compaction (extension commands execute immediately)
2087
- if (this.session.isCompacting) {
2088
- if (this.isExtensionCommand(text)) {
2089
- this.editor.addToHistory?.(text);
2090
- this.editor.setText("");
2091
- await this.session.prompt(text);
2092
- }
2093
- else {
2094
- this.queueCompactionMessage(text, "followUp");
2095
- }
2096
- return;
2097
- }
2098
- // Alt+Enter queues a follow-up message (waits until agent finishes)
2099
- // This handles extension commands (execute immediately), prompt template expansion, and queueing
2100
- if (this.session.isStreaming) {
2101
- this.editor.addToHistory?.(text);
2102
- this.editor.setText("");
2103
- await this.session.prompt(text, { streamingBehavior: "followUp" });
2104
- this.updatePendingMessagesDisplay();
2105
- this.ui.requestRender();
2106
- }
2107
- // If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)
2108
- else if (this.editor.onSubmit) {
2109
- this.editor.onSubmit(text);
2110
- }
2111
- }
2112
- handleDequeue() {
2113
- const restored = this.restoreQueuedMessagesToEditor();
2114
- if (restored === 0) {
2115
- this.showStatus("No queued messages to restore");
2116
- }
2117
- else {
2118
- this.showStatus(`Restored ${restored} queued message${restored > 1 ? "s" : ""} to editor`);
2119
- }
2120
- }
2121
- updateEditorBorderColor() {
2122
- if (this.isBashMode) {
2123
- this.editor.borderColor = theme.getBashModeBorderColor();
2124
- }
2125
- else {
2126
- const level = this.session.thinkingLevel || "off";
2127
- this.editor.borderColor = theme.getThinkingBorderColor(level);
2128
- }
2129
- this.ui.requestRender();
2130
- }
2131
- cycleThinkingLevel() {
2132
- const newLevel = this.session.cycleThinkingLevel();
2133
- if (newLevel === undefined) {
2134
- this.showStatus("Current model does not support thinking");
2135
- }
2136
- else {
2137
- this.footer.invalidate();
2138
- this.updateEditorBorderColor();
2139
- this.showStatus(`Thinking level: ${newLevel}`);
2140
- }
2141
- }
2142
- async cycleModel(direction) {
2143
- try {
2144
- const result = await this.session.cycleModel(direction);
2145
- if (result === undefined) {
2146
- const msg = this.session.scopedModels.length > 0 ? "Only one model in scope" : "Only one model available";
2147
- this.showStatus(msg);
2148
- }
2149
- else {
2150
- this.footer.invalidate();
2151
- this.updateEditorBorderColor();
2152
- const thinkingStr = result.model.reasoning && result.thinkingLevel !== "off" ? ` (thinking: ${result.thinkingLevel})` : "";
2153
- this.showStatus(`Switched to ${result.model.name || result.model.id}${thinkingStr}`);
2154
- }
2155
- }
2156
- catch (error) {
2157
- this.showError(error instanceof Error ? error.message : String(error));
2158
- }
2159
- }
2160
- toggleToolOutputExpansion() {
2161
- this.setToolsExpanded(!this.toolOutputExpanded);
2162
- }
2163
- setToolsExpanded(expanded) {
2164
- this.toolOutputExpanded = expanded;
2165
- for (const child of this.chatContainer.children) {
2166
- if (isExpandable(child)) {
2167
- child.setExpanded(expanded);
2168
- }
2169
- }
2170
- this.ui.requestRender();
2171
- }
2172
- toggleThinkingBlockVisibility() {
2173
- this.hideThinkingBlock = !this.hideThinkingBlock;
2174
- this.settingsManager.setHideThinkingBlock(this.hideThinkingBlock);
2175
- // Rebuild chat from session messages
2176
- this.chatContainer.clear();
2177
- this.rebuildChatFromMessages();
2178
- // If streaming, re-add the streaming component with updated visibility and re-render
2179
- if (this.streamingComponent && this.streamingMessage) {
2180
- this.streamingComponent.setHideThinkingBlock(this.hideThinkingBlock);
2181
- this.streamingComponent.updateContent(this.streamingMessage);
2182
- this.chatContainer.addChild(this.streamingComponent);
2183
- }
2184
- this.showStatus(`Thinking blocks: ${this.hideThinkingBlock ? "hidden" : "visible"}`);
2185
- }
2186
- openExternalEditor() {
2187
- // Determine editor (respect $VISUAL, then $EDITOR)
2188
- const editorCmd = process.env.VISUAL || process.env.EDITOR;
2189
- if (!editorCmd) {
2190
- let msg = "No editor configured. Set $VISUAL or $EDITOR environment variable.";
2191
- if (process.env.TERM_PROGRAM === "iTerm.app") {
2192
- msg +=
2193
- "\n\nTip: If you meant to open the GSD dashboard (Ctrl+Alt+G), set Left Option Key to" +
2194
- " \"Esc+\" in iTerm2 → Profiles → Keys. With the default \"Normal\" setting," +
2195
- " Ctrl+Alt+G sends Ctrl+G instead.";
2196
- }
2197
- this.showWarning(msg);
2198
- return;
2199
- }
2200
- const currentText = this.editor.getExpandedText?.() ?? this.editor.getText();
2201
- const tmpFile = path.join(os.tmpdir(), `pi-editor-${Date.now()}.pi.md`);
2202
- try {
2203
- // Write current content to temp file
2204
- fs.writeFileSync(tmpFile, currentText, "utf-8");
2205
- // Stop TUI to release terminal
2206
- this.ui.stop();
2207
- // Split by space to support editor arguments (e.g., "code --wait")
2208
- const [editor, ...editorArgs] = editorCmd.split(" ");
2209
- // Spawn editor synchronously with inherited stdio for interactive editing
2210
- const result = spawnSync(editor, [...editorArgs, tmpFile], {
2211
- stdio: "inherit",
2212
- shell: process.platform === "win32",
2213
- });
2214
- // On successful exit (status 0), replace editor content
2215
- if (result.status === 0) {
2216
- const newContent = fs.readFileSync(tmpFile, "utf-8").replace(/\n$/, "");
2217
- this.editor.setText(newContent);
2218
- }
2219
- // On non-zero exit, keep original text (no action needed)
2220
- }
2221
- finally {
2222
- // Clean up temp file
2223
- try {
2224
- fs.unlinkSync(tmpFile);
2225
- }
2226
- catch {
2227
- // Ignore cleanup errors
2228
- }
2229
- // Restart TUI
2230
- this.ui.start();
2231
- // Force full re-render since external editor uses alternate screen
2232
- this.ui.requestRender(true);
2233
- }
2234
- }
2235
- // =========================================================================
2236
- // UI helpers
2237
- // =========================================================================
2238
- clearEditor() {
2239
- this.editor.setText("");
2240
- this.ui.requestRender();
2241
- }
2242
- showError(errorMessage) {
2243
- this.chatContainer.addChild(new Spacer(1));
2244
- this.chatContainer.addChild(new Text(theme.fg("error", `Error: ${errorMessage}`), 1, 0));
2245
- this.ui.requestRender();
2246
- }
2247
- showWarning(warningMessage) {
2248
- this.chatContainer.addChild(new Spacer(1));
2249
- this.chatContainer.addChild(new Text(theme.fg("warning", `Warning: ${warningMessage}`), 1, 0));
2250
- this.ui.requestRender();
2251
- }
2252
- showSuccess(successMessage) {
2253
- this.chatContainer.addChild(new Spacer(1));
2254
- this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("success", text)));
2255
- this.chatContainer.addChild(new Text(theme.fg("success", successMessage), 1, 0));
2256
- this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("success", text)));
2257
- this.chatContainer.addChild(new Spacer(1));
2258
- this.ui.requestRender();
2259
- }
2260
- showTip(message) {
2261
- this.chatContainer.addChild(new Spacer(1));
2262
- this.chatContainer.addChild(new Text(theme.fg("dim", `💡 ${message}`), 1, 0));
2263
- this.ui.requestRender();
2264
- }
2265
- getContextPercent() {
2266
- return this.session.getContextUsage()?.percent ?? undefined;
2267
- }
2268
- showNewVersionNotification(newVersion) {
2269
- const action = theme.fg("accent", getUpdateInstruction("@gsd/pi-coding-agent"));
2270
- const updateInstruction = theme.fg("muted", `New version ${newVersion} is available. `) + action;
2271
- const changelogUrl = theme.fg("accent", "https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/CHANGELOG.md");
2272
- const changelogLine = theme.fg("muted", "Changelog: ") + changelogUrl;
2273
- this.chatContainer.addChild(new Spacer(1));
2274
- this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
2275
- this.chatContainer.addChild(new Text(`${theme.bold(theme.fg("warning", "Update Available"))}\n${updateInstruction}\n${changelogLine}`, 1, 0));
2276
- this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
2277
- this.ui.requestRender();
2278
- }
2279
- /**
2280
- * Get all queued messages (read-only).
2281
- * Combines session queue and compaction queue.
2282
- */
2283
- getAllQueuedMessages() {
2284
- return {
2285
- steering: [
2286
- ...this.session.getSteeringMessages(),
2287
- ...this.compactionQueuedMessages.filter((msg) => msg.mode === "steer").map((msg) => msg.text),
2288
- ],
2289
- followUp: [
2290
- ...this.session.getFollowUpMessages(),
2291
- ...this.compactionQueuedMessages.filter((msg) => msg.mode === "followUp").map((msg) => msg.text),
2292
- ],
2293
- };
2294
- }
2295
- /**
2296
- * Clear all queued messages and return their contents.
2297
- * Clears both session queue and compaction queue.
2298
- */
2299
- clearAllQueues() {
2300
- const { steering, followUp } = this.session.clearQueue();
2301
- const compactionSteering = this.compactionQueuedMessages
2302
- .filter((msg) => msg.mode === "steer")
2303
- .map((msg) => msg.text);
2304
- const compactionFollowUp = this.compactionQueuedMessages
2305
- .filter((msg) => msg.mode === "followUp")
2306
- .map((msg) => msg.text);
2307
- this.compactionQueuedMessages = [];
2308
- return {
2309
- steering: [...steering, ...compactionSteering],
2310
- followUp: [...followUp, ...compactionFollowUp],
2311
- };
2312
- }
2313
- updatePendingMessagesDisplay() {
2314
- this.pendingMessagesContainer.clear();
2315
- const { steering: steeringMessages, followUp: followUpMessages } = this.getAllQueuedMessages();
2316
- if (steeringMessages.length > 0 || followUpMessages.length > 0) {
2317
- this.pendingMessagesContainer.addChild(new Spacer(1));
2318
- for (const message of steeringMessages) {
2319
- const text = theme.fg("dim", `Steering: ${message}`);
2320
- this.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));
2321
- }
2322
- for (const message of followUpMessages) {
2323
- const text = theme.fg("dim", `Follow-up: ${message}`);
2324
- this.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));
2325
- }
2326
- const dequeueHint = getAppKeyDisplay(this.keybindings, "dequeue");
2327
- const hintText = theme.fg("dim", `↳ ${dequeueHint} to edit all queued messages`);
2328
- this.pendingMessagesContainer.addChild(new TruncatedText(hintText, 1, 0));
2329
- }
2330
- }
2331
- restoreQueuedMessagesToEditor(options) {
2332
- const { steering, followUp } = this.clearAllQueues();
2333
- const allQueued = [...steering, ...followUp];
2334
- if (allQueued.length === 0) {
2335
- this.updatePendingMessagesDisplay();
2336
- if (options?.abort) {
2337
- this.agent.abort();
2338
- }
2339
- return 0;
2340
- }
2341
- const queuedText = allQueued.join("\n\n");
2342
- const currentText = options?.currentText ?? this.editor.getText();
2343
- const combinedText = [queuedText, currentText].filter((t) => t.trim()).join("\n\n");
2344
- this.editor.setText(combinedText);
2345
- this.updatePendingMessagesDisplay();
2346
- if (options?.abort) {
2347
- this.agent.abort();
2348
- }
2349
- return allQueued.length;
2350
- }
2351
- queueCompactionMessage(text, mode) {
2352
- if (text.startsWith("/") && !this.isKnownSlashCommand(text)) {
2353
- const command = text.split(/\s/)[0];
2354
- this.showError(`Unknown command: ${command}. Use slash autocomplete to see available commands.`);
2355
- return;
2356
- }
2357
- this.compactionQueuedMessages.push({ text, mode });
2358
- this.editor.addToHistory?.(text);
2359
- this.editor.setText("");
2360
- this.updatePendingMessagesDisplay();
2361
- this.showStatus("Queued message for after compaction");
2362
- }
2363
- isExtensionCommand(text) {
2364
- if (!text.startsWith("/"))
2365
- return false;
2366
- const extensionRunner = this.session.extensionRunner;
2367
- if (!extensionRunner)
2368
- return false;
2369
- const spaceIndex = text.indexOf(" ");
2370
- const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
2371
- return !!extensionRunner.getCommand(commandName);
2372
- }
2373
- isKnownSlashCommand(text) {
2374
- if (!text.startsWith("/"))
2375
- return false;
2376
- const spaceIndex = text.indexOf(" ");
2377
- const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
2378
- if (BUILTIN_SLASH_COMMANDS.some((command) => command.name === commandName)) {
2379
- return true;
2380
- }
2381
- if (this.isExtensionCommand(text)) {
2382
- return true;
2383
- }
2384
- if (this.session.promptTemplates.some((template) => template.name === commandName)) {
2385
- return true;
2386
- }
2387
- if (commandName.startsWith("skill:") && this.settingsManager.getEnableSkillCommands()) {
2388
- const skillName = commandName.slice("skill:".length);
2389
- return this.session.resourceLoader.getSkills().skills.some((skill) => skill.name === skillName);
2390
- }
2391
- return false;
2392
- }
2393
- async flushCompactionQueue(options) {
2394
- if (this.compactionQueuedMessages.length === 0) {
2395
- return;
2396
- }
2397
- const queuedMessages = [...this.compactionQueuedMessages];
2398
- this.compactionQueuedMessages = [];
2399
- this.updatePendingMessagesDisplay();
2400
- const restoreQueue = (error) => {
2401
- this.session.clearQueue();
2402
- this.compactionQueuedMessages = queuedMessages;
2403
- this.updatePendingMessagesDisplay();
2404
- this.showError(`Failed to send queued message${queuedMessages.length > 1 ? "s" : ""}: ${error instanceof Error ? error.message : String(error)}`);
2405
- };
2406
- try {
2407
- if (options?.willRetry) {
2408
- // When retry is pending, queue messages for the retry turn
2409
- for (const message of queuedMessages) {
2410
- if (this.isExtensionCommand(message.text)) {
2411
- await this.session.prompt(message.text);
2412
- }
2413
- else if (message.mode === "followUp") {
2414
- await this.session.followUp(message.text);
2415
- }
2416
- else {
2417
- await this.session.steer(message.text);
2418
- }
2419
- }
2420
- this.updatePendingMessagesDisplay();
2421
- return;
2422
- }
2423
- // Find first non-extension-command message to use as prompt
2424
- const firstPromptIndex = queuedMessages.findIndex((message) => !this.isExtensionCommand(message.text));
2425
- if (firstPromptIndex === -1) {
2426
- // All extension commands - execute them all
2427
- for (const message of queuedMessages) {
2428
- await this.session.prompt(message.text);
2429
- }
2430
- return;
2431
- }
2432
- // Execute any extension commands before the first prompt
2433
- const preCommands = queuedMessages.slice(0, firstPromptIndex);
2434
- const firstPrompt = queuedMessages[firstPromptIndex];
2435
- const rest = queuedMessages.slice(firstPromptIndex + 1);
2436
- for (const message of preCommands) {
2437
- await this.session.prompt(message.text);
2438
- }
2439
- // Send first prompt (starts streaming)
2440
- const promptPromise = this.session.prompt(firstPrompt.text).catch((error) => {
2441
- restoreQueue(error);
2442
- });
2443
- // Queue remaining messages
2444
- for (const message of rest) {
2445
- if (this.isExtensionCommand(message.text)) {
2446
- await this.session.prompt(message.text);
2447
- }
2448
- else if (message.mode === "followUp") {
2449
- await this.session.followUp(message.text);
2450
- }
2451
- else {
2452
- await this.session.steer(message.text);
2453
- }
2454
- }
2455
- this.updatePendingMessagesDisplay();
2456
- void promptPromise;
2457
- }
2458
- catch (error) {
2459
- restoreQueue(error);
2460
- }
2461
- }
2462
- /** Move pending bash components from pending area to chat */
2463
- flushPendingBashComponents() {
2464
- for (const component of this.pendingBashComponents) {
2465
- this.pendingMessagesContainer.removeChild(component);
2466
- this.chatContainer.addChild(component);
2467
- }
2468
- this.pendingBashComponents = [];
2469
- }
2470
- // =========================================================================
2471
- // Selectors
2472
- // =========================================================================
2473
- /**
2474
- * Shows a selector component in place of the editor.
2475
- * @param create Factory that receives a `done` callback and returns the component and focus target
2476
- */
2477
- showSelector(create) {
2478
- const done = () => {
2479
- this.editorContainer.clear();
2480
- this.editorContainer.addChild(this.editor);
2481
- this.ui.setFocus(this.editor);
2482
- };
2483
- const { component, focus } = create(done);
2484
- this.editorContainer.clear();
2485
- this.editorContainer.addChild(component);
2486
- this.ui.setFocus(focus);
2487
- this.ui.requestRender();
2488
- }
2489
- showSettingsSelector() {
2490
- this.showSelector((done) => {
2491
- const selector = new SettingsSelectorComponent({
2492
- autoCompact: this.session.autoCompactionEnabled,
2493
- showImages: this.settingsManager.getShowImages(),
2494
- autoResizeImages: this.settingsManager.getImageAutoResize(),
2495
- blockImages: this.settingsManager.getBlockImages(),
2496
- enableSkillCommands: this.settingsManager.getEnableSkillCommands(),
2497
- steeringMode: this.session.steeringMode,
2498
- followUpMode: this.session.followUpMode,
2499
- transport: this.settingsManager.getTransport(),
2500
- thinkingLevel: this.session.thinkingLevel,
2501
- availableThinkingLevels: this.session.getAvailableThinkingLevels(),
2502
- currentTheme: this.settingsManager.getTheme() || "dark",
2503
- availableThemes: getAvailableThemes(),
2504
- hideThinkingBlock: this.hideThinkingBlock,
2505
- collapseChangelog: this.settingsManager.getCollapseChangelog(),
2506
- doubleEscapeAction: this.settingsManager.getDoubleEscapeAction(),
2507
- treeFilterMode: this.settingsManager.getTreeFilterMode(),
2508
- showHardwareCursor: this.settingsManager.getShowHardwareCursor(),
2509
- editorPaddingX: this.settingsManager.getEditorPaddingX(),
2510
- autocompleteMaxVisible: this.settingsManager.getAutocompleteMaxVisible(),
2511
- respectGitignoreInPicker: this.settingsManager.getRespectGitignoreInPicker?.() ?? true,
2512
- quietStartup: this.settingsManager.getQuietStartup(),
2513
- clearOnShrink: this.settingsManager.getClearOnShrink(),
2514
- timestampFormat: this.getTimestampFormat(),
2515
- }, {
2516
- onAutoCompactChange: (enabled) => {
2517
- this.session.setAutoCompactionEnabled(enabled);
2518
- this.footer.setAutoCompactEnabled(enabled);
2519
- },
2520
- onShowImagesChange: (enabled) => {
2521
- this.settingsManager.setShowImages(enabled);
2522
- for (const child of this.chatContainer.children) {
2523
- if (child instanceof ToolExecutionComponent) {
2524
- child.setShowImages(enabled);
2525
- }
2526
- }
2527
- },
2528
- onAutoResizeImagesChange: (enabled) => {
2529
- this.settingsManager.setImageAutoResize(enabled);
2530
- },
2531
- onBlockImagesChange: (blocked) => {
2532
- this.settingsManager.setBlockImages(blocked);
2533
- },
2534
- onEnableSkillCommandsChange: (enabled) => {
2535
- this.settingsManager.setEnableSkillCommands(enabled);
2536
- this.setupAutocomplete();
2537
- },
2538
- onSteeringModeChange: (mode) => {
2539
- this.session.setSteeringMode(mode);
2540
- },
2541
- onFollowUpModeChange: (mode) => {
2542
- this.session.setFollowUpMode(mode);
2543
- },
2544
- onTransportChange: (transport) => {
2545
- this.settingsManager.setTransport(transport);
2546
- this.session.agent.setTransport(transport);
2547
- },
2548
- onThinkingLevelChange: (level) => {
2549
- this.session.setThinkingLevel(level);
2550
- this.footer.invalidate();
2551
- this.updateEditorBorderColor();
2552
- },
2553
- onThemeChange: (themeName) => {
2554
- const result = setTheme(themeName, true);
2555
- this.settingsManager.setTheme(themeName);
2556
- this.ui.invalidate();
2557
- if (!result.success) {
2558
- this.showError(`Failed to load theme "${themeName}": ${result.error}\nFell back to dark theme.`);
2559
- }
2560
- },
2561
- onThemePreview: (themeName) => {
2562
- const result = setTheme(themeName, true);
2563
- if (result.success) {
2564
- this.ui.invalidate();
2565
- this.ui.requestRender();
2566
- }
2567
- },
2568
- onHideThinkingBlockChange: (hidden) => {
2569
- this.hideThinkingBlock = hidden;
2570
- this.settingsManager.setHideThinkingBlock(hidden);
2571
- for (const child of this.chatContainer.children) {
2572
- if (child instanceof AssistantMessageComponent) {
2573
- child.setHideThinkingBlock(hidden);
2574
- }
2575
- }
2576
- this.chatContainer.clear();
2577
- this.rebuildChatFromMessages();
2578
- },
2579
- onCollapseChangelogChange: (collapsed) => {
2580
- this.settingsManager.setCollapseChangelog(collapsed);
2581
- },
2582
- onQuietStartupChange: (enabled) => {
2583
- this.settingsManager.setQuietStartup(enabled);
2584
- },
2585
- onDoubleEscapeActionChange: (action) => {
2586
- this.settingsManager.setDoubleEscapeAction(action);
2587
- },
2588
- onTreeFilterModeChange: (mode) => {
2589
- this.settingsManager.setTreeFilterMode(mode);
2590
- },
2591
- onShowHardwareCursorChange: (enabled) => {
2592
- this.settingsManager.setShowHardwareCursor(enabled);
2593
- this.ui.setShowHardwareCursor(enabled);
2594
- },
2595
- onEditorPaddingXChange: (padding) => {
2596
- this.settingsManager.setEditorPaddingX(padding);
2597
- this.defaultEditor.setPaddingX(padding);
2598
- if (this.editor !== this.defaultEditor && this.editor.setPaddingX !== undefined) {
2599
- this.editor.setPaddingX(padding);
2600
- }
2601
- },
2602
- onAutocompleteMaxVisibleChange: (maxVisible) => {
2603
- this.settingsManager.setAutocompleteMaxVisible(maxVisible);
2604
- this.defaultEditor.setAutocompleteMaxVisible(maxVisible);
2605
- if (this.editor !== this.defaultEditor && this.editor.setAutocompleteMaxVisible !== undefined) {
2606
- this.editor.setAutocompleteMaxVisible(maxVisible);
2607
- }
2608
- },
2609
- onClearOnShrinkChange: (enabled) => {
2610
- this.settingsManager.setClearOnShrink(enabled);
2611
- this.ui.setClearOnShrink(enabled);
2612
- },
2613
- onRespectGitignoreInPickerChange: (enabled) => {
2614
- this.settingsManager.setRespectGitignoreInPicker?.(enabled);
2615
- this.autocompleteProvider?.setRespectGitignore?.(enabled);
2616
- },
2617
- onTimestampFormatChange: (format) => {
2618
- this.settingsManager.setTimestampFormat?.(format);
2619
- },
2620
- onCancel: () => {
2621
- done();
2622
- this.ui.requestRender();
2623
- },
2624
- });
2625
- return { component: selector, focus: selector.getSettingsList() };
2626
- });
2627
- }
2628
- async handleModelCommand(searchTerm) {
2629
- await handleModelCommandController(this, searchTerm);
2630
- }
2631
- async findExactModelMatch(searchTerm) {
2632
- return findExactModelMatchController(this, searchTerm);
2633
- }
2634
- async getModelCandidates() {
2635
- return getModelCandidatesController(this);
2636
- }
2637
- /** Update the footer's available provider count from current model candidates */
2638
- async updateAvailableProviderCount() {
2639
- await updateAvailableProviderCountController(this);
2640
- }
2641
- showModelSelector(initialSearchInput) {
2642
- this.showSelector((done) => {
2643
- const selector = new ModelSelectorComponent(this.ui, this.session.model, this.settingsManager, this.session.modelRegistry, this.session.scopedModels, async (model) => {
2644
- try {
2645
- await this.session.setModel(model);
2646
- this.footer.invalidate();
2647
- this.updateEditorBorderColor();
2648
- done();
2649
- this.showStatus(`Model: ${model.id}`);
2650
- this.checkDaxnutsEasterEgg(model);
2651
- }
2652
- catch (error) {
2653
- done();
2654
- this.showError(error instanceof Error ? error.message : String(error));
2655
- }
2656
- }, () => {
2657
- done();
2658
- this.ui.requestRender();
2659
- }, initialSearchInput);
2660
- return { component: selector, focus: selector };
2661
- });
2662
- }
2663
- async showModelsSelector() {
2664
- // Get all available models
2665
- this.session.modelRegistry.refresh();
2666
- const allModels = this.session.modelRegistry.getAvailable();
2667
- if (allModels.length === 0) {
2668
- this.showStatus("No models available");
2669
- return;
2670
- }
2671
- // Check if session has scoped models (from previous session-only changes or CLI --models)
2672
- const sessionScopedModels = this.session.scopedModels;
2673
- const hasSessionScope = sessionScopedModels.length > 0;
2674
- // Build enabled model IDs from session state or settings
2675
- const enabledModelIds = new Set();
2676
- let hasFilter = false;
2677
- if (hasSessionScope) {
2678
- // Use current session's scoped models
2679
- for (const sm of sessionScopedModels) {
2680
- enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
2681
- }
2682
- hasFilter = true;
2683
- }
2684
- else {
2685
- // Fall back to settings
2686
- const patterns = this.settingsManager.getEnabledModels();
2687
- if (patterns !== undefined && patterns.length > 0) {
2688
- hasFilter = true;
2689
- const scopedModels = await resolveModelScope(patterns, this.session.modelRegistry);
2690
- for (const sm of scopedModels) {
2691
- enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
2692
- }
2693
- }
2694
- }
2695
- // Track current enabled state (session-only until persisted)
2696
- const currentEnabledIds = new Set(enabledModelIds);
2697
- let currentHasFilter = hasFilter;
2698
- // Helper to update session's scoped models (session-only, no persist)
2699
- const updateSessionModels = async (enabledIds) => {
2700
- if (enabledIds.size > 0 && enabledIds.size < allModels.length) {
2701
- const newScopedModels = await resolveModelScope(Array.from(enabledIds), this.session.modelRegistry);
2702
- this.session.setScopedModels(newScopedModels.map((sm) => ({
2703
- model: sm.model,
2704
- thinkingLevel: sm.thinkingLevel,
2705
- })));
2706
- }
2707
- else {
2708
- // All enabled or none enabled = no filter
2709
- this.session.setScopedModels([]);
2710
- }
2711
- await this.updateAvailableProviderCount();
2712
- this.ui.requestRender();
2713
- };
2714
- this.showSelector((done) => {
2715
- const selector = new ScopedModelsSelectorComponent({
2716
- allModels,
2717
- enabledModelIds: currentEnabledIds,
2718
- hasEnabledModelsFilter: currentHasFilter,
2719
- }, {
2720
- onModelToggle: async (modelId, enabled) => {
2721
- if (enabled) {
2722
- currentEnabledIds.add(modelId);
2723
- }
2724
- else {
2725
- currentEnabledIds.delete(modelId);
2726
- }
2727
- currentHasFilter = true;
2728
- await updateSessionModels(currentEnabledIds);
2729
- },
2730
- onEnableAll: async (allModelIds) => {
2731
- currentEnabledIds.clear();
2732
- for (const id of allModelIds) {
2733
- currentEnabledIds.add(id);
2734
- }
2735
- currentHasFilter = false;
2736
- await updateSessionModels(currentEnabledIds);
2737
- },
2738
- onClearAll: async () => {
2739
- currentEnabledIds.clear();
2740
- currentHasFilter = true;
2741
- await updateSessionModels(currentEnabledIds);
2742
- },
2743
- onToggleProvider: async (_provider, modelIds, enabled) => {
2744
- for (const id of modelIds) {
2745
- if (enabled) {
2746
- currentEnabledIds.add(id);
2747
- }
2748
- else {
2749
- currentEnabledIds.delete(id);
2750
- }
2751
- }
2752
- currentHasFilter = true;
2753
- await updateSessionModels(currentEnabledIds);
2754
- },
2755
- onPersist: (enabledIds) => {
2756
- // Persist to settings
2757
- const newPatterns = enabledIds.length === allModels.length
2758
- ? undefined // All enabled = clear filter
2759
- : enabledIds;
2760
- this.settingsManager.setEnabledModels(newPatterns);
2761
- this.showStatus("Model selection saved to settings");
2762
- },
2763
- onCancel: () => {
2764
- done();
2765
- this.ui.requestRender();
2766
- },
2767
- });
2768
- return { component: selector, focus: selector };
2769
- });
2770
- }
2771
- showUserMessageSelector() {
2772
- const userMessages = this.session.getUserMessagesForForking();
2773
- if (userMessages.length === 0) {
2774
- this.showStatus("No messages to fork from");
2775
- return;
2776
- }
2777
- this.showSelector((done) => {
2778
- const selector = new UserMessageSelectorComponent(userMessages.map((m) => ({ id: m.entryId, text: m.text })), async (entryId) => {
2779
- const result = await this.session.fork(entryId);
2780
- if (result.cancelled) {
2781
- // Extension cancelled the fork
2782
- done();
2783
- this.ui.requestRender();
2784
- return;
2785
- }
2786
- this.chatContainer.clear();
2787
- this.renderInitialMessages();
2788
- this.editor.setText(result.selectedText);
2789
- done();
2790
- this.showStatus("Branched to new session");
2791
- }, () => {
2792
- done();
2793
- this.ui.requestRender();
2794
- });
2795
- return { component: selector, focus: selector.getMessageList() };
2796
- });
2797
- }
2798
- showTreeSelector(initialSelectedId) {
2799
- const tree = this.sessionManager.getTree();
2800
- const realLeafId = this.sessionManager.getLeafId();
2801
- const initialFilterMode = this.settingsManager.getTreeFilterMode();
2802
- if (tree.length === 0) {
2803
- this.showStatus("No entries in session");
2804
- return;
2805
- }
2806
- this.showSelector((done) => {
2807
- const selector = new TreeSelectorComponent(tree, realLeafId, this.ui.terminal.rows, async (entryId) => {
2808
- // Selecting the current leaf is a no-op (already there)
2809
- if (entryId === realLeafId) {
2810
- done();
2811
- this.showStatus("Already at this point");
2812
- return;
2813
- }
2814
- // Ask about summarization
2815
- done(); // Close selector first
2816
- // Loop until user makes a complete choice or cancels to tree
2817
- let wantsSummary = false;
2818
- let customInstructions;
2819
- // Check if we should skip the prompt (user preference to always default to no summary)
2820
- if (!this.settingsManager.getBranchSummarySkipPrompt()) {
2821
- while (true) {
2822
- const summaryChoice = await this.showExtensionSelector("Summarize branch?", [
2823
- "No summary",
2824
- "Summarize",
2825
- "Summarize with custom prompt",
2826
- ]);
2827
- if (summaryChoice === undefined) {
2828
- // User pressed escape - re-show tree selector with same selection
2829
- this.showTreeSelector(entryId);
2830
- return;
2831
- }
2832
- wantsSummary = summaryChoice !== "No summary";
2833
- if (summaryChoice === "Summarize with custom prompt") {
2834
- customInstructions = await this.showExtensionEditor("Custom summarization instructions");
2835
- if (customInstructions === undefined) {
2836
- // User cancelled - loop back to summary selector
2837
- continue;
2838
- }
2839
- }
2840
- // User made a complete choice
2841
- break;
2842
- }
2843
- }
2844
- // Set up escape handler and loader if summarizing
2845
- let summaryLoader;
2846
- const originalOnEscape = this.defaultEditor.onEscape;
2847
- if (wantsSummary) {
2848
- this.defaultEditor.onEscape = () => {
2849
- this.session.abortBranchSummary();
2850
- };
2851
- this.chatContainer.addChild(new Spacer(1));
2852
- summaryLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), `Summarizing branch... (${appKey(this.keybindings, "interrupt")} to cancel)`);
2853
- this.statusContainer.addChild(summaryLoader);
2854
- this.ui.requestRender();
2855
- }
2856
- try {
2857
- const result = await this.session.navigateTree(entryId, {
2858
- summarize: wantsSummary,
2859
- customInstructions,
2860
- });
2861
- if (result.aborted) {
2862
- // Summarization aborted - re-show tree selector with same selection
2863
- this.showStatus("Branch summarization cancelled");
2864
- this.showTreeSelector(entryId);
2865
- return;
2866
- }
2867
- if (result.cancelled) {
2868
- this.showStatus("Navigation cancelled");
2869
- return;
2870
- }
2871
- // Update UI
2872
- this.chatContainer.clear();
2873
- this.renderInitialMessages();
2874
- if (result.editorText && !this.editor.getText().trim()) {
2875
- this.editor.setText(result.editorText);
2876
- }
2877
- this.showStatus("Navigated to selected point");
2878
- }
2879
- catch (error) {
2880
- this.showError(error instanceof Error ? error.message : String(error));
2881
- }
2882
- finally {
2883
- if (summaryLoader) {
2884
- summaryLoader.stop();
2885
- this.statusContainer.clear();
2886
- }
2887
- this.defaultEditor.onEscape = originalOnEscape;
2888
- }
2889
- }, () => {
2890
- done();
2891
- this.ui.requestRender();
2892
- }, (entryId, label) => {
2893
- this.sessionManager.appendLabelChange(entryId, label);
2894
- this.ui.requestRender();
2895
- }, initialSelectedId, initialFilterMode);
2896
- return { component: selector, focus: selector };
2897
- });
2898
- }
2899
- showSessionSelector() {
2900
- this.showSelector((done) => {
2901
- const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress), SessionManager.listAll, async (sessionPath) => {
2902
- done();
2903
- await this.handleResumeSession(sessionPath);
2904
- }, () => {
2905
- done();
2906
- this.ui.requestRender();
2907
- }, () => {
2908
- void this.shutdown();
2909
- }, () => this.ui.requestRender(), {
2910
- renameSession: async (sessionFilePath, nextName) => {
2911
- const next = (nextName ?? "").trim();
2912
- if (!next)
2913
- return;
2914
- const mgr = SessionManager.open(sessionFilePath);
2915
- mgr.appendSessionInfo(next);
2916
- },
2917
- showRenameHint: true,
2918
- keybindings: this.keybindings,
2919
- }, this.sessionManager.getSessionFile());
2920
- return { component: selector, focus: selector };
2921
- });
2922
- }
2923
- async handleResumeSession(sessionPath) {
2924
- // Stop loading animation
2925
- if (this.loadingAnimation) {
2926
- this.loadingAnimation.stop();
2927
- this.loadingAnimation = undefined;
2928
- }
2929
- this.statusContainer.clear();
2930
- // Clear UI state
2931
- this.pendingMessagesContainer.clear();
2932
- this.compactionQueuedMessages = [];
2933
- this.streamingComponent = undefined;
2934
- this.streamingMessage = undefined;
2935
- this.pendingTools.clear();
2936
- // Switch session via AgentSession (emits extension session events)
2937
- await this.session.switchSession(sessionPath);
2938
- // Clear and re-render the chat
2939
- this.chatContainer.clear();
2940
- this.renderInitialMessages();
2941
- if (this.session.sessionManager.wasInterrupted?.()) {
2942
- this.showStatus("Resumed session (previous session ended unexpectedly — last action may be incomplete)");
2943
- }
2944
- else {
2945
- this.showStatus("Resumed session");
2946
- }
2947
- }
2948
- showProviderManager() {
2949
- this.showSelector((done) => {
2950
- const component = new ProviderManagerComponent(this.ui, this.session.modelRegistry.authStorage, this.session.modelRegistry, () => {
2951
- done();
2952
- this.ui.requestRender();
2953
- }, async (provider) => {
2954
- this.showStatus(`Discovering models for ${provider}...`);
2955
- try {
2956
- const results = await this.session.modelRegistry.discoverModels?.([provider]) ?? [];
2957
- const result = results[0];
2958
- if (result?.error) {
2959
- this.showError(`Discovery failed: ${result.error}`);
2960
- }
2961
- else {
2962
- this.showStatus(`Discovered ${result?.models?.length ?? 0} models from ${provider}`);
2963
- }
2964
- }
2965
- catch (error) {
2966
- this.showError(error instanceof Error ? error.message : String(error));
2967
- }
2968
- done();
2969
- this.ui.requestRender();
2970
- }, async (provider) => {
2971
- // Enter key → auth setup for selected provider (#3579)
2972
- done();
2973
- await this.showLoginDialog(provider);
2974
- });
2975
- return { component, focus: component };
2976
- });
2977
- }
2978
- async showOAuthSelector(mode) {
2979
- if (mode === "logout") {
2980
- const providers = this.session.modelRegistry.authStorage.list();
2981
- const loggedInProviders = providers.filter((p) => this.session.modelRegistry.authStorage.get(p)?.type === "oauth");
2982
- if (loggedInProviders.length === 0) {
2983
- this.showStatus("No OAuth providers logged in. Use /login first.");
2984
- return;
2985
- }
2986
- }
2987
- this.showSelector((done) => {
2988
- const selector = new OAuthSelectorComponent(mode, this.session.modelRegistry.authStorage, (providerId) => {
2989
- done();
2990
- // OAuthSelectorComponent calls this synchronously (no await),
2991
- // so we must catch async errors here to prevent unhandled rejections
2992
- // when the user cancels the login dialog (#821).
2993
- const handleAsync = async () => {
2994
- if (mode === "login") {
2995
- await this.showLoginDialog(providerId);
2996
- }
2997
- else {
2998
- // Logout flow
2999
- const providerInfo = this.session.modelRegistry.authStorage
3000
- .getOAuthProviders()
3001
- .find((p) => p.id === providerId);
3002
- const providerName = providerInfo?.name || providerId;
3003
- try {
3004
- this.session.modelRegistry.authStorage.logout(providerId);
3005
- this.session.modelRegistry.refresh();
3006
- await this.updateAvailableProviderCount();
3007
- // Auto-switch model if current model belongs to the logged-out provider
3008
- const currentModel = this.session.model;
3009
- if (currentModel?.provider === providerId) {
3010
- try {
3011
- const available = this.session.modelRegistry.getAvailable();
3012
- const fallback = available.find((m) => m.provider !== providerId);
3013
- if (fallback) {
3014
- await this.session.setModel(fallback);
3015
- }
3016
- }
3017
- catch {
3018
- // Model switch failed — user can manually switch via /model
3019
- }
3020
- }
3021
- this.showStatus(`Logged out of ${providerName}`);
3022
- }
3023
- catch (error) {
3024
- this.showError(`Logout failed: ${error instanceof Error ? error.message : String(error)}`);
3025
- }
3026
- }
3027
- };
3028
- handleAsync().catch(() => {
3029
- // Swallow — showLoginDialog already handles its own errors.
3030
- // This prevents unhandled rejections when login is cancelled.
3031
- });
3032
- }, () => {
3033
- done();
3034
- this.ui.requestRender();
3035
- });
3036
- return { component: selector, focus: selector };
3037
- });
3038
- }
3039
- async showLoginDialog(providerId) {
3040
- const providerInfo = this.session.modelRegistry.authStorage.getOAuthProviders().find((p) => p.id === providerId);
3041
- const providerName = providerInfo?.name || providerId;
3042
- // Providers that use callback servers (can paste redirect URL)
3043
- const usesCallbackServer = providerInfo?.usesCallbackServer ?? false;
3044
- // Create login dialog component
3045
- const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
3046
- // Completion handled below
3047
- });
3048
- // Show dialog in editor container
3049
- this.editorContainer.clear();
3050
- this.editorContainer.addChild(dialog);
3051
- this.ui.setFocus(dialog);
3052
- this.ui.requestRender();
3053
- // Restore editor helper — also disposes the dialog to reject any
3054
- // dangling promises and prevent the UI from getting stuck.
3055
- const restoreEditor = () => {
3056
- dialog.dispose();
3057
- this.editorContainer.clear();
3058
- this.editorContainer.addChild(this.editor);
3059
- this.ui.setFocus(this.editor);
3060
- this.ui.requestRender();
3061
- };
3062
- try {
3063
- await this.session.modelRegistry.authStorage.login(providerId, {
3064
- onAuth: (info) => {
3065
- dialog.showAuth(info.url, info.instructions);
3066
- if (!usesCallbackServer && providerId === "github-copilot") {
3067
- // GitHub Copilot polls after onAuth
3068
- dialog.showWaiting("Waiting for browser authentication...");
3069
- }
3070
- // For Anthropic: onPrompt is called immediately after
3071
- },
3072
- onPrompt: async (prompt) => {
3073
- return dialog.showPrompt(prompt.message, prompt.placeholder);
3074
- },
3075
- onProgress: (message) => {
3076
- dialog.showProgress(message);
3077
- },
3078
- // Callback-server providers race browser callback with pasted redirect URL.
3079
- // Keep manual-input promise ownership inside provider flow to avoid
3080
- // orphaned rejections when the callback is not consumed.
3081
- onManualCodeInput: usesCallbackServer
3082
- ? () => dialog.showManualInput("Paste redirect URL below, or complete login in browser:")
3083
- : undefined,
3084
- signal: dialog.signal,
3085
- });
3086
- // Success
3087
- restoreEditor();
3088
- this.session.modelRegistry.refresh();
3089
- await this.updateAvailableProviderCount();
3090
- // Auto-switch model if current model has no valid API key
3091
- try {
3092
- const currentModel = this.session.model;
3093
- if (currentModel) {
3094
- const currentKey = await this.session.modelRegistry.getApiKeyForProvider?.(currentModel.provider);
3095
- if (!currentKey) {
3096
- const available = this.session.modelRegistry.getAvailable();
3097
- const newProviderModel = available.find((m) => m.provider === providerId);
3098
- if (newProviderModel) {
3099
- await this.session.setModel(newProviderModel);
3100
- }
3101
- else if (available.length > 0) {
3102
- await this.session.setModel(available[0]);
3103
- }
3104
- }
3105
- }
3106
- }
3107
- catch (_error) {
3108
- // Model switch failed — user can manually switch via /model
3109
- }
3110
- this.showStatus(`Logged in to ${providerName}. Credentials saved to ${getAuthPath()}`);
3111
- }
3112
- catch (error) {
3113
- restoreEditor();
3114
- const errorMsg = error instanceof Error ? error.message : String(error);
3115
- if (errorMsg !== "Login cancelled" && !errorMsg.includes("Superseded") && !errorMsg.includes("disposed")) {
3116
- this.showError(`Failed to login to ${providerName}: ${errorMsg}`);
3117
- }
3118
- }
3119
- }
3120
- // =========================================================================
3121
- // Command handlers
3122
- // =========================================================================
3123
- async handleReloadCommand() {
3124
- if (this.session.isStreaming) {
3125
- this.showWarning("Wait for the current response to finish before reloading.");
3126
- return;
3127
- }
3128
- if (this.session.isCompacting) {
3129
- this.showWarning("Wait for compaction to finish before reloading.");
3130
- return;
3131
- }
3132
- this.resetExtensionUI();
3133
- const loader = new BorderedLoader(this.ui, theme, "Reloading extensions, skills, prompts, themes...", {
3134
- cancellable: false,
3135
- });
3136
- const previousEditor = this.editor;
3137
- this.editorContainer.clear();
3138
- this.editorContainer.addChild(loader);
3139
- this.ui.setFocus(loader);
3140
- this.ui.requestRender();
3141
- const dismissLoader = (editor) => {
3142
- loader.dispose();
3143
- this.editorContainer.clear();
3144
- this.editorContainer.addChild(editor);
3145
- this.ui.setFocus(editor);
3146
- this.ui.requestRender();
3147
- };
3148
- try {
3149
- await this.session.reload();
3150
- /* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
3151
- setRegisteredThemes(this.session.resourceLoader.getThemes().themes);
3152
- this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
3153
- const themeName = this.settingsManager.getTheme();
3154
- const themeResult = themeName ? setTheme(themeName, true) : { success: true };
3155
- if (!themeResult.success) {
3156
- this.showError(`Failed to load theme "${themeName}": ${themeResult.error}\nFell back to dark theme.`);
3157
- }
3158
- const editorPaddingX = this.settingsManager.getEditorPaddingX();
3159
- const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
3160
- this.defaultEditor.setPaddingX(editorPaddingX);
3161
- this.defaultEditor.setAutocompleteMaxVisible(autocompleteMaxVisible);
3162
- if (this.editor !== this.defaultEditor) {
3163
- this.editor.setPaddingX?.(editorPaddingX);
3164
- this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
3165
- }
3166
- this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
3167
- this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
3168
- this.setupAutocomplete();
3169
- const runner = this.session.extensionRunner;
3170
- if (runner) {
3171
- this.setupExtensionShortcuts(runner);
3172
- }
3173
- this.rebuildChatFromMessages();
3174
- dismissLoader(this.editor);
3175
- this.showLoadedResources({
3176
- extensionPaths: runner?.getExtensionPaths() ?? [],
3177
- force: false,
3178
- showDiagnosticsWhenQuiet: true,
3179
- });
3180
- const modelsJsonError = this.session.modelRegistry.getError();
3181
- if (modelsJsonError) {
3182
- this.showError(`models.json error: ${modelsJsonError}`);
3183
- }
3184
- this.showStatus("Reloaded extensions, skills, prompts, themes");
3185
- }
3186
- catch (error) {
3187
- dismissLoader(previousEditor);
3188
- this.showError(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
3189
- }
3190
- }
3191
- async handleClearCommand() {
3192
- // Stop loading animation
3193
- if (this.loadingAnimation) {
3194
- this.loadingAnimation.stop();
3195
- this.loadingAnimation = undefined;
3196
- }
3197
- this.statusContainer.clear();
3198
- // New session via session (emits extension session events)
3199
- await this.session.newSession();
3200
- // Clear UI state
3201
- this.headerContainer.clear();
3202
- this.chatContainer.clear();
3203
- this.pendingMessagesContainer.clear();
3204
- this.compactionQueuedMessages = [];
3205
- this.streamingComponent = undefined;
3206
- this.streamingMessage = undefined;
3207
- this.pendingTools.clear();
3208
- // Reset contextual tips for the new session
3209
- this.contextualTips.reset();
3210
- this.chatContainer.addChild(new Spacer(1));
3211
- this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
3212
- this.ui.requestRender();
3213
- }
3214
- handleDebugCommand() {
3215
- const width = this.ui.terminal.columns;
3216
- const height = this.ui.terminal.rows;
3217
- const allLines = this.ui.render(width);
3218
- const debugLogPath = getDebugLogPath();
3219
- const debugData = [
3220
- `Debug output at ${new Date().toISOString()}`,
3221
- `Terminal: ${width}x${height}`,
3222
- `Total lines: ${allLines.length}`,
3223
- "",
3224
- "=== All rendered lines with visible widths ===",
3225
- ...allLines.map((line, idx) => {
3226
- const vw = visibleWidth(line);
3227
- const escaped = JSON.stringify(line);
3228
- return `[${idx}] (w=${vw}) ${escaped}`;
3229
- }),
3230
- "",
3231
- "=== Agent messages (JSONL) ===",
3232
- ...this.session.messages.map((msg) => JSON.stringify(msg)),
3233
- "",
3234
- ].join("\n");
3235
- fs.mkdirSync(path.dirname(debugLogPath), { recursive: true });
3236
- fs.writeFileSync(debugLogPath, debugData);
3237
- this.chatContainer.addChild(new Spacer(1));
3238
- this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ Debug log written")}\n${theme.fg("muted", debugLogPath)}`, 1, 1));
3239
- this.ui.requestRender();
3240
- }
3241
- handleDaxnuts() {
3242
- this.chatContainer.addChild(new Spacer(1));
3243
- this.chatContainer.addChild(new DaxnutsComponent(this.ui));
3244
- this.ui.requestRender();
3245
- }
3246
- checkDaxnutsEasterEgg(model) {
3247
- if (model.provider === "opencode" && model.id.toLowerCase().includes("kimi-k2.5")) {
3248
- this.handleDaxnuts();
3249
- }
3250
- }
3251
- async handleBashCommand(command, excludeFromContext = false, displayCommand, loginShell) {
3252
- const extensionRunner = this.session.extensionRunner;
3253
- const label = displayCommand || command;
3254
- // Emit user_bash event to let extensions intercept
3255
- const eventResult = extensionRunner
3256
- ? await extensionRunner.emitUserBash({
3257
- type: "user_bash",
3258
- command,
3259
- excludeFromContext,
3260
- cwd: process.cwd(),
3261
- })
3262
- : undefined;
3263
- // If extension returned a full result, use it directly
3264
- if (eventResult?.result) {
3265
- const result = eventResult.result;
3266
- // Create UI component for display
3267
- this.bashComponent = new BashExecutionComponent(label, this.ui, excludeFromContext);
3268
- if (this.session.isStreaming) {
3269
- this.pendingMessagesContainer.addChild(this.bashComponent);
3270
- this.pendingBashComponents.push(this.bashComponent);
3271
- }
3272
- else {
3273
- this.chatContainer.addChild(this.bashComponent);
3274
- }
3275
- // Show output and complete
3276
- if (result.output) {
3277
- this.bashComponent.appendOutput(result.output);
3278
- }
3279
- this.bashComponent.setComplete(result.exitCode, result.cancelled, result.truncated ? { truncated: true, content: result.output } : undefined, result.fullOutputPath);
3280
- // Record the result in session
3281
- this.session.recordBashResult(command, result, { excludeFromContext });
3282
- this.bashComponent = undefined;
3283
- this.ui.requestRender();
3284
- return;
3285
- }
3286
- // Normal execution path (possibly with custom operations)
3287
- const isDeferred = this.session.isStreaming;
3288
- this.bashComponent = new BashExecutionComponent(label, this.ui, excludeFromContext);
3289
- if (isDeferred) {
3290
- // Show in pending area when agent is streaming
3291
- this.pendingMessagesContainer.addChild(this.bashComponent);
3292
- this.pendingBashComponents.push(this.bashComponent);
3293
- }
3294
- else {
3295
- // Show in chat immediately when agent is idle
3296
- this.chatContainer.addChild(this.bashComponent);
3297
- }
3298
- this.ui.requestRender();
3299
- try {
3300
- const result = await this.session.executeBash(command, (chunk) => {
3301
- if (this.bashComponent) {
3302
- this.bashComponent.appendOutput(chunk);
3303
- this.ui.requestRender();
3304
- }
3305
- }, { excludeFromContext, operations: eventResult?.operations, loginShell });
3306
- if (this.bashComponent) {
3307
- this.bashComponent.setComplete(result.exitCode, result.cancelled, result.truncated ? { truncated: true, content: result.output } : undefined, result.fullOutputPath);
3308
- }
3309
- }
3310
- catch (error) {
3311
- if (this.bashComponent) {
3312
- this.bashComponent.setComplete(undefined, false);
3313
- }
3314
- this.showError(`Bash command failed: ${error instanceof Error ? error.message : "Unknown error"}`);
3315
- }
3316
- this.bashComponent = undefined;
3317
- this.ui.requestRender();
3318
- }
3319
- async executeCompaction(customInstructions, isAuto = false) {
3320
- // Stop loading animation
3321
- if (this.loadingAnimation) {
3322
- this.loadingAnimation.stop();
3323
- this.loadingAnimation = undefined;
3324
- }
3325
- this.statusContainer.clear();
3326
- // Set up escape handler during compaction
3327
- const originalOnEscape = this.defaultEditor.onEscape;
3328
- this.defaultEditor.onEscape = () => {
3329
- this.session.abortCompaction();
3330
- };
3331
- // Show compacting status
3332
- this.chatContainer.addChild(new Spacer(1));
3333
- const cancelHint = `(${appKey(this.keybindings, "interrupt")} to cancel)`;
3334
- const label = isAuto ? `Auto-compacting context... ${cancelHint}` : `Compacting context... ${cancelHint}`;
3335
- const compactingLoader = new Loader(this.ui, (spinner) => theme.fg("accent", spinner), (text) => theme.fg("muted", text), label);
3336
- this.statusContainer.addChild(compactingLoader);
3337
- this.ui.requestRender();
3338
- let result;
3339
- try {
3340
- result = await this.session.compact(customInstructions);
3341
- // Rebuild UI
3342
- this.rebuildChatFromMessages();
3343
- // Add compaction component at bottom so user sees it without scrolling
3344
- const msg = createCompactionSummaryMessage(result.summary, result.tokensBefore, new Date().toISOString());
3345
- this.addMessageToChat(msg);
3346
- this.footer.invalidate();
3347
- }
3348
- catch (error) {
3349
- const message = error instanceof Error ? error.message : String(error);
3350
- if (message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError")) {
3351
- this.showError("Compaction cancelled");
3352
- }
3353
- else {
3354
- this.showError(`Compaction failed: ${message}`);
3355
- }
3356
- }
3357
- finally {
3358
- compactingLoader.stop();
3359
- this.statusContainer.clear();
3360
- this.defaultEditor.onEscape = originalOnEscape;
3361
- }
3362
- void this.flushCompactionQueue({ willRetry: false });
3363
- return result;
3364
- }
3365
- requestRender(force = false) {
3366
- if (!this.isInitialized)
3367
- return;
3368
- this.ui.requestRender(force);
3369
- }
3370
- stop() {
3371
- if (this.loadingAnimation) {
3372
- this.loadingAnimation.stop();
3373
- this.loadingAnimation = undefined;
3374
- }
3375
- this.clearExtensionTerminalInputListeners();
3376
- // Clean up branch change listener (Fix 1)
3377
- this._branchChangeUnsub?.();
3378
- this._branchChangeUnsub = undefined;
3379
- // Clean up theme change listener and watcher (Fix 2)
3380
- onThemeChange(() => { });
3381
- stopThemeWatcher();
3382
- // Resolve any pending getUserInput promise so the run() loop can exit (Fix 3)
3383
- if (this.onInputCallback) {
3384
- this.onInputCallback("");
3385
- this.onInputCallback = undefined;
3386
- }
3387
- // Dispose extension widgets, custom footer, and custom header (Fix 4)
3388
- this.clearExtensionWidgets();
3389
- if (this.customFooter?.dispose) {
3390
- this.customFooter.dispose();
3391
- }
3392
- this.customFooter = undefined;
3393
- if (this.customHeader?.dispose) {
3394
- this.customHeader.dispose();
3395
- }
3396
- this.customHeader = undefined;
3397
- this.autocompleteProvider = undefined;
3398
- this.footer.dispose();
3399
- this.footerDataProvider.dispose();
3400
- if (this.unsubscribe) {
3401
- this.unsubscribe();
3402
- }
3403
- if (this.isInitialized) {
3404
- this.ui.stop();
3405
- this.isInitialized = false;
3406
- }
3407
- }
3408
- }
3409
- //# sourceMappingURL=interactive-mode.js.map