koro-ai 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (670) hide show
  1. package/AGENTS.md +69 -0
  2. package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
  3. package/Dockerfile +18 -0
  4. package/README.md +15 -0
  5. package/bin/koro +16 -0
  6. package/bin/opencode +179 -0
  7. package/bunfig.toml +7 -0
  8. package/drizzle.config.ts +10 -0
  9. package/git +0 -0
  10. package/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
  11. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
  12. package/migration/20260211171708_add_project_commands/migration.sql +1 -0
  13. package/migration/20260211171708_add_project_commands/snapshot.json +806 -0
  14. package/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
  15. package/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
  16. package/migration/20260225215848_workspace/migration.sql +7 -0
  17. package/migration/20260225215848_workspace/snapshot.json +959 -0
  18. package/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
  19. package/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
  20. package/migration/20260228203230_blue_harpoon/migration.sql +17 -0
  21. package/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
  22. package/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
  23. package/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
  24. package/migration/20260309230000_move_org_to_state/migration.sql +3 -0
  25. package/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
  26. package/migration/20260312043431_session_message_cursor/migration.sql +4 -0
  27. package/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
  28. package/migration/20260323234822_events/migration.sql +13 -0
  29. package/migration/20260323234822_events/snapshot.json +1271 -0
  30. package/package.json +163 -0
  31. package/parsers-config.ts +290 -0
  32. package/script/build-node.ts +56 -0
  33. package/script/build.ts +276 -0
  34. package/script/check-migrations.ts +16 -0
  35. package/script/postinstall.mjs +131 -0
  36. package/script/publish.ts +181 -0
  37. package/script/schema.ts +63 -0
  38. package/script/seed-e2e.ts +60 -0
  39. package/script/upgrade-opentui.ts +64 -0
  40. package/specs/effect-migration.md +294 -0
  41. package/specs/tui-plugins.md +436 -0
  42. package/src/account/account.sql.ts +39 -0
  43. package/src/account/index.ts +424 -0
  44. package/src/account/repo.ts +163 -0
  45. package/src/account/schema.ts +91 -0
  46. package/src/acp/README.md +174 -0
  47. package/src/acp/agent.ts +1763 -0
  48. package/src/acp/session.ts +116 -0
  49. package/src/acp/types.ts +24 -0
  50. package/src/agent/agent.ts +476 -0
  51. package/src/agent/generate.txt +75 -0
  52. package/src/agent/prompt/compaction.txt +15 -0
  53. package/src/agent/prompt/explore.txt +18 -0
  54. package/src/agent/prompt/summary.txt +11 -0
  55. package/src/agent/prompt/title.txt +44 -0
  56. package/src/auth/index.ts +109 -0
  57. package/src/bus/bus-event.ts +40 -0
  58. package/src/bus/global.ts +10 -0
  59. package/src/bus/index.ts +185 -0
  60. package/src/cli/bootstrap.ts +17 -0
  61. package/src/cli/cmd/account.ts +257 -0
  62. package/src/cli/cmd/acp.ts +70 -0
  63. package/src/cli/cmd/agent.ts +245 -0
  64. package/src/cli/cmd/cmd.ts +7 -0
  65. package/src/cli/cmd/db.ts +119 -0
  66. package/src/cli/cmd/debug/agent.ts +167 -0
  67. package/src/cli/cmd/debug/config.ts +16 -0
  68. package/src/cli/cmd/debug/file.ts +97 -0
  69. package/src/cli/cmd/debug/index.ts +48 -0
  70. package/src/cli/cmd/debug/lsp.ts +53 -0
  71. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  72. package/src/cli/cmd/debug/scrap.ts +16 -0
  73. package/src/cli/cmd/debug/skill.ts +16 -0
  74. package/src/cli/cmd/debug/snapshot.ts +52 -0
  75. package/src/cli/cmd/export.ts +89 -0
  76. package/src/cli/cmd/generate.ts +38 -0
  77. package/src/cli/cmd/github.ts +1646 -0
  78. package/src/cli/cmd/import.ts +207 -0
  79. package/src/cli/cmd/mcp.ts +754 -0
  80. package/src/cli/cmd/models.ts +78 -0
  81. package/src/cli/cmd/plug.ts +233 -0
  82. package/src/cli/cmd/pr.ts +127 -0
  83. package/src/cli/cmd/providers.ts +478 -0
  84. package/src/cli/cmd/run.ts +676 -0
  85. package/src/cli/cmd/serve.ts +24 -0
  86. package/src/cli/cmd/session.ts +159 -0
  87. package/src/cli/cmd/stats.ts +410 -0
  88. package/src/cli/cmd/tui/app.tsx +919 -0
  89. package/src/cli/cmd/tui/attach.ts +88 -0
  90. package/src/cli/cmd/tui/component/border.tsx +21 -0
  91. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  92. package/src/cli/cmd/tui/component/dialog-command.tsx +171 -0
  93. package/src/cli/cmd/tui/component/dialog-import-share.tsx +118 -0
  94. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  95. package/src/cli/cmd/tui/component/dialog-model.tsx +179 -0
  96. package/src/cli/cmd/tui/component/dialog-provider.tsx +329 -0
  97. package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
  98. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  99. package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
  100. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  101. package/src/cli/cmd/tui/component/dialog-status.tsx +168 -0
  102. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  103. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  104. package/src/cli/cmd/tui/component/dialog-variant.tsx +39 -0
  105. package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +320 -0
  106. package/src/cli/cmd/tui/component/error-component.tsx +92 -0
  107. package/src/cli/cmd/tui/component/logo.tsx +85 -0
  108. package/src/cli/cmd/tui/component/plugin-route-missing.tsx +14 -0
  109. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +672 -0
  110. package/src/cli/cmd/tui/component/prompt/frecency.tsx +90 -0
  111. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  112. package/src/cli/cmd/tui/component/prompt/index.tsx +1310 -0
  113. package/src/cli/cmd/tui/component/prompt/part.ts +16 -0
  114. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  115. package/src/cli/cmd/tui/component/spinner.tsx +24 -0
  116. package/src/cli/cmd/tui/component/startup-loading.tsx +63 -0
  117. package/src/cli/cmd/tui/component/task-panel.tsx +44 -0
  118. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  119. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  120. package/src/cli/cmd/tui/component/token-bar.tsx +60 -0
  121. package/src/cli/cmd/tui/component/workspace/dialog-session-list.tsx +151 -0
  122. package/src/cli/cmd/tui/context/args.tsx +15 -0
  123. package/src/cli/cmd/tui/context/directory.ts +13 -0
  124. package/src/cli/cmd/tui/context/exit.tsx +60 -0
  125. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  126. package/src/cli/cmd/tui/context/keybind.tsx +105 -0
  127. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  128. package/src/cli/cmd/tui/context/local.tsx +412 -0
  129. package/src/cli/cmd/tui/context/plugin-keybinds.ts +41 -0
  130. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  131. package/src/cli/cmd/tui/context/route.tsx +52 -0
  132. package/src/cli/cmd/tui/context/sdk.tsx +128 -0
  133. package/src/cli/cmd/tui/context/sync.tsx +504 -0
  134. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  135. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  136. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  137. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  138. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  139. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  140. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  141. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  142. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  143. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  144. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  145. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  146. package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  147. package/src/cli/cmd/tui/context/theme/gtr.json +245 -0
  148. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  149. package/src/cli/cmd/tui/context/theme/koro.json +241 -0
  150. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  151. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  152. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  153. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  154. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  155. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  156. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  157. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  158. package/src/cli/cmd/tui/context/theme/opencode.json +245 -0
  159. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  160. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  161. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  162. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  163. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  164. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  165. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  166. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  167. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  168. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  169. package/src/cli/cmd/tui/context/theme.tsx +1240 -0
  170. package/src/cli/cmd/tui/context/tui-config.tsx +9 -0
  171. package/src/cli/cmd/tui/event.ts +49 -0
  172. package/src/cli/cmd/tui/feature-plugins/home/footer.tsx +93 -0
  173. package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +152 -0
  174. package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +50 -0
  175. package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +63 -0
  176. package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +62 -0
  177. package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +93 -0
  178. package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +66 -0
  179. package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +96 -0
  180. package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +48 -0
  181. package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +270 -0
  182. package/src/cli/cmd/tui/plugin/api.tsx +430 -0
  183. package/src/cli/cmd/tui/plugin/index.ts +3 -0
  184. package/src/cli/cmd/tui/plugin/internal.ts +27 -0
  185. package/src/cli/cmd/tui/plugin/runtime.ts +1033 -0
  186. package/src/cli/cmd/tui/plugin/slots.tsx +60 -0
  187. package/src/cli/cmd/tui/routes/home.tsx +84 -0
  188. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +65 -0
  189. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +110 -0
  190. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  191. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  192. package/src/cli/cmd/tui/routes/session/footer.tsx +93 -0
  193. package/src/cli/cmd/tui/routes/session/index.tsx +2270 -0
  194. package/src/cli/cmd/tui/routes/session/permission.tsx +691 -0
  195. package/src/cli/cmd/tui/routes/session/question.tsx +468 -0
  196. package/src/cli/cmd/tui/routes/session/sidebar.tsx +74 -0
  197. package/src/cli/cmd/tui/routes/session/subagent-footer.tsx +131 -0
  198. package/src/cli/cmd/tui/thread.ts +232 -0
  199. package/src/cli/cmd/tui/ui/dialog-alert.tsx +59 -0
  200. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +89 -0
  201. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +211 -0
  202. package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
  203. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +130 -0
  204. package/src/cli/cmd/tui/ui/dialog-select.tsx +409 -0
  205. package/src/cli/cmd/tui/ui/dialog.tsx +192 -0
  206. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  207. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  208. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  209. package/src/cli/cmd/tui/util/clipboard.ts +192 -0
  210. package/src/cli/cmd/tui/util/editor.ts +37 -0
  211. package/src/cli/cmd/tui/util/model.ts +23 -0
  212. package/src/cli/cmd/tui/util/scroll.ts +23 -0
  213. package/src/cli/cmd/tui/util/selection.ts +25 -0
  214. package/src/cli/cmd/tui/util/signal.ts +7 -0
  215. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  216. package/src/cli/cmd/tui/util/transcript.ts +112 -0
  217. package/src/cli/cmd/tui/win32.ts +129 -0
  218. package/src/cli/cmd/tui/worker.ts +175 -0
  219. package/src/cli/cmd/uninstall.ts +353 -0
  220. package/src/cli/cmd/upgrade.ts +73 -0
  221. package/src/cli/cmd/web.ts +81 -0
  222. package/src/cli/effect/prompt.ts +25 -0
  223. package/src/cli/error.ts +46 -0
  224. package/src/cli/heap.ts +59 -0
  225. package/src/cli/logo.ts +14 -0
  226. package/src/cli/network.ts +60 -0
  227. package/src/cli/ui.ts +133 -0
  228. package/src/cli/upgrade.ts +31 -0
  229. package/src/command/index.ts +195 -0
  230. package/src/command/template/initialize.txt +66 -0
  231. package/src/command/template/review.txt +101 -0
  232. package/src/config/config.ts +1591 -0
  233. package/src/config/markdown.ts +99 -0
  234. package/src/config/paths.ts +181 -0
  235. package/src/config/tui-migrate.ts +155 -0
  236. package/src/config/tui-schema.ts +36 -0
  237. package/src/config/tui.ts +171 -0
  238. package/src/control-plane/adaptors/index.ts +20 -0
  239. package/src/control-plane/adaptors/worktree.ts +38 -0
  240. package/src/control-plane/schema.ts +17 -0
  241. package/src/control-plane/sse.ts +66 -0
  242. package/src/control-plane/types.ts +21 -0
  243. package/src/control-plane/workspace.sql.ts +17 -0
  244. package/src/control-plane/workspace.ts +154 -0
  245. package/src/effect/cross-spawn-spawner.ts +502 -0
  246. package/src/effect/instance-ref.ts +6 -0
  247. package/src/effect/instance-registry.ts +12 -0
  248. package/src/effect/instance-state.ts +82 -0
  249. package/src/effect/run-service.ts +33 -0
  250. package/src/effect/runner.ts +216 -0
  251. package/src/env/index.ts +28 -0
  252. package/src/file/ignore.ts +82 -0
  253. package/src/file/index.ts +686 -0
  254. package/src/file/protected.ts +59 -0
  255. package/src/file/ripgrep.ts +376 -0
  256. package/src/file/time.ts +133 -0
  257. package/src/file/watcher.ts +171 -0
  258. package/src/filesystem/index.ts +226 -0
  259. package/src/flag/flag.ts +155 -0
  260. package/src/format/formatter.ts +413 -0
  261. package/src/format/index.ts +203 -0
  262. package/src/git/index.ts +303 -0
  263. package/src/global/index.ts +161 -0
  264. package/src/id/id.ts +85 -0
  265. package/src/ide/index.ts +74 -0
  266. package/src/index.ts +240 -0
  267. package/src/installation/index.ts +355 -0
  268. package/src/installation/meta.ts +7 -0
  269. package/src/lsp/client.ts +252 -0
  270. package/src/lsp/index.ts +558 -0
  271. package/src/lsp/language.ts +120 -0
  272. package/src/lsp/launch.ts +21 -0
  273. package/src/lsp/server.ts +1958 -0
  274. package/src/mcp/auth.ts +173 -0
  275. package/src/mcp/index.ts +921 -0
  276. package/src/mcp/oauth-callback.ts +215 -0
  277. package/src/mcp/oauth-provider.ts +185 -0
  278. package/src/memory/index.ts +117 -0
  279. package/src/node.ts +1 -0
  280. package/src/npm/index.ts +180 -0
  281. package/src/orchestrator/agent-registry.ts +38 -0
  282. package/src/orchestrator/conflict.ts +25 -0
  283. package/src/orchestrator/context-manager.ts +22 -0
  284. package/src/orchestrator/index.ts +9 -0
  285. package/src/orchestrator/scheduler.ts +30 -0
  286. package/src/orchestrator/state-tracker.ts +71 -0
  287. package/src/orchestrator/task-manager.ts +69 -0
  288. package/src/patch/index.ts +680 -0
  289. package/src/permission/arity.ts +163 -0
  290. package/src/permission/evaluate.ts +15 -0
  291. package/src/permission/index.ts +325 -0
  292. package/src/permission/schema.ts +17 -0
  293. package/src/plugin/codex.ts +596 -0
  294. package/src/plugin/github-copilot/copilot.ts +353 -0
  295. package/src/plugin/github-copilot/models.ts +144 -0
  296. package/src/plugin/index.ts +281 -0
  297. package/src/plugin/install.ts +439 -0
  298. package/src/plugin/loader.ts +174 -0
  299. package/src/plugin/meta.ts +188 -0
  300. package/src/plugin/shared.ts +307 -0
  301. package/src/project/bootstrap.ts +31 -0
  302. package/src/project/instance.ts +175 -0
  303. package/src/project/project.sql.ts +16 -0
  304. package/src/project/project.ts +519 -0
  305. package/src/project/schema.ts +16 -0
  306. package/src/project/state.ts +70 -0
  307. package/src/project/vcs.ts +240 -0
  308. package/src/provider/auth.ts +253 -0
  309. package/src/provider/error.ts +197 -0
  310. package/src/provider/models-snapshot.ts +60410 -0
  311. package/src/provider/models.ts +162 -0
  312. package/src/provider/provider.ts +1677 -0
  313. package/src/provider/schema.ts +38 -0
  314. package/src/provider/sdk/copilot/README.md +5 -0
  315. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
  316. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  317. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
  318. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  319. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +815 -0
  320. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  321. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  322. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +83 -0
  323. package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  324. package/src/provider/sdk/copilot/index.ts +2 -0
  325. package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  326. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
  327. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  328. package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  329. package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  330. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
  331. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1769 -0
  332. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
  333. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  334. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
  335. package/src/provider/sdk/copilot/responses/tool/file-search.ts +127 -0
  336. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +114 -0
  337. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +64 -0
  338. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
  339. package/src/provider/sdk/copilot/responses/tool/web-search.ts +102 -0
  340. package/src/provider/transform.ts +1046 -0
  341. package/src/pty/index.ts +401 -0
  342. package/src/pty/schema.ts +17 -0
  343. package/src/question/index.ts +224 -0
  344. package/src/question/schema.ts +17 -0
  345. package/src/server/error.ts +36 -0
  346. package/src/server/event.ts +7 -0
  347. package/src/server/instance.ts +314 -0
  348. package/src/server/mdns.ts +60 -0
  349. package/src/server/middleware.ts +33 -0
  350. package/src/server/projectors.ts +28 -0
  351. package/src/server/router.ts +99 -0
  352. package/src/server/routes/config.ts +92 -0
  353. package/src/server/routes/event.ts +83 -0
  354. package/src/server/routes/experimental.ts +271 -0
  355. package/src/server/routes/file.ts +197 -0
  356. package/src/server/routes/global.ts +312 -0
  357. package/src/server/routes/mcp.ts +225 -0
  358. package/src/server/routes/permission.ts +69 -0
  359. package/src/server/routes/project.ts +118 -0
  360. package/src/server/routes/provider.ts +171 -0
  361. package/src/server/routes/pty.ts +211 -0
  362. package/src/server/routes/question.ts +99 -0
  363. package/src/server/routes/session.ts +1031 -0
  364. package/src/server/routes/tui.ts +379 -0
  365. package/src/server/routes/workspace.ts +94 -0
  366. package/src/server/server.ts +312 -0
  367. package/src/session/compaction.ts +428 -0
  368. package/src/session/index.ts +887 -0
  369. package/src/session/instruction.ts +258 -0
  370. package/src/session/llm.ts +370 -0
  371. package/src/session/message-v2.ts +1031 -0
  372. package/src/session/message.ts +191 -0
  373. package/src/session/overflow.ts +22 -0
  374. package/src/session/processor.ts +523 -0
  375. package/src/session/projectors.ts +135 -0
  376. package/src/session/prompt/anthropic.txt +105 -0
  377. package/src/session/prompt/beast.txt +147 -0
  378. package/src/session/prompt/build-switch.txt +5 -0
  379. package/src/session/prompt/codex.txt +79 -0
  380. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  381. package/src/session/prompt/default.txt +105 -0
  382. package/src/session/prompt/gemini.txt +155 -0
  383. package/src/session/prompt/gpt.txt +107 -0
  384. package/src/session/prompt/kimi.txt +114 -0
  385. package/src/session/prompt/max-steps.txt +16 -0
  386. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  387. package/src/session/prompt/plan.txt +26 -0
  388. package/src/session/prompt/trinity.txt +97 -0
  389. package/src/session/prompt.ts +1908 -0
  390. package/src/session/retry.ts +106 -0
  391. package/src/session/revert.ts +176 -0
  392. package/src/session/schema.ts +38 -0
  393. package/src/session/session.sql.ts +103 -0
  394. package/src/session/status.ts +102 -0
  395. package/src/session/summary.ts +177 -0
  396. package/src/session/system.ts +76 -0
  397. package/src/session/todo.ts +95 -0
  398. package/src/share/share-next.ts +369 -0
  399. package/src/share/share.sql.ts +13 -0
  400. package/src/shell/shell.ts +110 -0
  401. package/src/skill/discovery.ts +116 -0
  402. package/src/skill/index.ts +277 -0
  403. package/src/snapshot/index.ts +571 -0
  404. package/src/sql.d.ts +4 -0
  405. package/src/storage/db.bun.ts +8 -0
  406. package/src/storage/db.node.ts +8 -0
  407. package/src/storage/db.ts +174 -0
  408. package/src/storage/json-migration.ts +425 -0
  409. package/src/storage/schema.sql.ts +10 -0
  410. package/src/storage/schema.ts +5 -0
  411. package/src/storage/storage.ts +353 -0
  412. package/src/sync/README.md +179 -0
  413. package/src/sync/event.sql.ts +16 -0
  414. package/src/sync/index.ts +263 -0
  415. package/src/sync/schema.ts +14 -0
  416. package/src/token/index.ts +77 -0
  417. package/src/tool/apply_patch.ts +281 -0
  418. package/src/tool/apply_patch.txt +33 -0
  419. package/src/tool/bash.ts +496 -0
  420. package/src/tool/bash.txt +117 -0
  421. package/src/tool/batch.ts +183 -0
  422. package/src/tool/batch.txt +24 -0
  423. package/src/tool/codesearch.ts +132 -0
  424. package/src/tool/codesearch.txt +12 -0
  425. package/src/tool/edit.ts +667 -0
  426. package/src/tool/edit.txt +10 -0
  427. package/src/tool/external-directory.ts +37 -0
  428. package/src/tool/glob.ts +78 -0
  429. package/src/tool/glob.txt +6 -0
  430. package/src/tool/grep.ts +156 -0
  431. package/src/tool/grep.txt +8 -0
  432. package/src/tool/invalid.ts +17 -0
  433. package/src/tool/ls.ts +121 -0
  434. package/src/tool/ls.txt +1 -0
  435. package/src/tool/lsp.ts +97 -0
  436. package/src/tool/lsp.txt +19 -0
  437. package/src/tool/multiedit.ts +46 -0
  438. package/src/tool/multiedit.txt +41 -0
  439. package/src/tool/plan-enter.txt +14 -0
  440. package/src/tool/plan-exit.txt +13 -0
  441. package/src/tool/plan.ts +131 -0
  442. package/src/tool/question.ts +46 -0
  443. package/src/tool/question.txt +10 -0
  444. package/src/tool/read.ts +296 -0
  445. package/src/tool/read.txt +14 -0
  446. package/src/tool/registry.ts +248 -0
  447. package/src/tool/schema.ts +17 -0
  448. package/src/tool/skill.ts +105 -0
  449. package/src/tool/task.ts +166 -0
  450. package/src/tool/task.txt +60 -0
  451. package/src/tool/todo.ts +48 -0
  452. package/src/tool/todowrite.txt +167 -0
  453. package/src/tool/tool.ts +112 -0
  454. package/src/tool/truncate.ts +144 -0
  455. package/src/tool/truncation-dir.ts +4 -0
  456. package/src/tool/webfetch.ts +206 -0
  457. package/src/tool/webfetch.txt +13 -0
  458. package/src/tool/websearch.ts +150 -0
  459. package/src/tool/websearch.txt +14 -0
  460. package/src/tool/write.ts +84 -0
  461. package/src/tool/write.txt +8 -0
  462. package/src/util/abort.ts +35 -0
  463. package/src/util/archive.ts +17 -0
  464. package/src/util/color.ts +19 -0
  465. package/src/util/context.ts +25 -0
  466. package/src/util/data-url.ts +9 -0
  467. package/src/util/defer.ts +12 -0
  468. package/src/util/effect-http-client.ts +11 -0
  469. package/src/util/effect-zod.ts +98 -0
  470. package/src/util/error.ts +77 -0
  471. package/src/util/filesystem.ts +245 -0
  472. package/src/util/flock.ts +333 -0
  473. package/src/util/fn.ts +21 -0
  474. package/src/util/format.ts +20 -0
  475. package/src/util/glob.ts +34 -0
  476. package/src/util/hash.ts +7 -0
  477. package/src/util/iife.ts +3 -0
  478. package/src/util/keybind.ts +103 -0
  479. package/src/util/lazy.ts +23 -0
  480. package/src/util/locale.ts +81 -0
  481. package/src/util/lock.ts +98 -0
  482. package/src/util/log.ts +182 -0
  483. package/src/util/network.ts +9 -0
  484. package/src/util/process.ts +176 -0
  485. package/src/util/queue.ts +32 -0
  486. package/src/util/record.ts +3 -0
  487. package/src/util/rpc.ts +66 -0
  488. package/src/util/schema.ts +53 -0
  489. package/src/util/scrap.ts +10 -0
  490. package/src/util/signal.ts +12 -0
  491. package/src/util/timeout.ts +14 -0
  492. package/src/util/token.ts +7 -0
  493. package/src/util/update-schema.ts +13 -0
  494. package/src/util/which.ts +14 -0
  495. package/src/util/wildcard.ts +59 -0
  496. package/src/worktree/index.ts +612 -0
  497. package/sst-env.d.ts +10 -0
  498. package/test/AGENTS.md +81 -0
  499. package/test/account/repo.test.ts +326 -0
  500. package/test/account/service.test.ts +393 -0
  501. package/test/acp/agent-interface.test.ts +51 -0
  502. package/test/acp/event-subscription.test.ts +685 -0
  503. package/test/agent/agent.test.ts +717 -0
  504. package/test/auth/auth.test.ts +58 -0
  505. package/test/bus/bus-effect.test.ts +164 -0
  506. package/test/bus/bus-integration.test.ts +87 -0
  507. package/test/bus/bus.test.ts +219 -0
  508. package/test/cli/account.test.ts +26 -0
  509. package/test/cli/cmd/tui/prompt-part.test.ts +47 -0
  510. package/test/cli/github-action.test.ts +198 -0
  511. package/test/cli/github-remote.test.ts +80 -0
  512. package/test/cli/import.test.ts +54 -0
  513. package/test/cli/plugin-auth-picker.test.ts +120 -0
  514. package/test/cli/tui/keybind-plugin.test.ts +90 -0
  515. package/test/cli/tui/plugin-add.test.ts +107 -0
  516. package/test/cli/tui/plugin-install.test.ts +89 -0
  517. package/test/cli/tui/plugin-lifecycle.test.ts +225 -0
  518. package/test/cli/tui/plugin-loader-entrypoint.test.ts +492 -0
  519. package/test/cli/tui/plugin-loader-pure.test.ts +72 -0
  520. package/test/cli/tui/plugin-loader.test.ts +752 -0
  521. package/test/cli/tui/plugin-toggle.test.ts +159 -0
  522. package/test/cli/tui/slot-replace.test.tsx +47 -0
  523. package/test/cli/tui/theme-store.test.ts +51 -0
  524. package/test/cli/tui/thread.test.ts +128 -0
  525. package/test/cli/tui/transcript.test.ts +426 -0
  526. package/test/config/agent-color.test.ts +71 -0
  527. package/test/config/config.test.ts +2348 -0
  528. package/test/config/fixtures/empty-frontmatter.md +4 -0
  529. package/test/config/fixtures/frontmatter.md +28 -0
  530. package/test/config/fixtures/markdown-header.md +11 -0
  531. package/test/config/fixtures/no-frontmatter.md +1 -0
  532. package/test/config/fixtures/weird-model-id.md +13 -0
  533. package/test/config/markdown.test.ts +228 -0
  534. package/test/config/tui.test.ts +752 -0
  535. package/test/control-plane/sse.test.ts +56 -0
  536. package/test/effect/cross-spawn-spawner.test.ts +412 -0
  537. package/test/effect/instance-state.test.ts +482 -0
  538. package/test/effect/run-service.test.ts +46 -0
  539. package/test/effect/runner.test.ts +523 -0
  540. package/test/fake/provider.ts +81 -0
  541. package/test/file/fsmonitor.test.ts +62 -0
  542. package/test/file/ignore.test.ts +10 -0
  543. package/test/file/index.test.ts +946 -0
  544. package/test/file/path-traversal.test.ts +198 -0
  545. package/test/file/ripgrep.test.ts +54 -0
  546. package/test/file/time.test.ts +445 -0
  547. package/test/file/watcher.test.ts +247 -0
  548. package/test/filesystem/filesystem.test.ts +319 -0
  549. package/test/fixture/db.ts +11 -0
  550. package/test/fixture/fixture.test.ts +26 -0
  551. package/test/fixture/fixture.ts +172 -0
  552. package/test/fixture/flock-worker.ts +72 -0
  553. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  554. package/test/fixture/plug-worker.ts +93 -0
  555. package/test/fixture/plugin-meta-worker.ts +26 -0
  556. package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
  557. package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
  558. package/test/fixture/skills/cloudflare/SKILL.md +211 -0
  559. package/test/fixture/skills/index.json +6 -0
  560. package/test/fixture/tui-plugin.ts +337 -0
  561. package/test/fixture/tui-runtime.ts +27 -0
  562. package/test/format/format.test.ts +171 -0
  563. package/test/git/git.test.ts +128 -0
  564. package/test/ide/ide.test.ts +82 -0
  565. package/test/installation/installation.test.ts +151 -0
  566. package/test/keybind.test.ts +421 -0
  567. package/test/lib/effect.ts +53 -0
  568. package/test/lib/filesystem.ts +10 -0
  569. package/test/lib/llm-server.ts +795 -0
  570. package/test/lsp/client.test.ts +95 -0
  571. package/test/lsp/index.test.ts +55 -0
  572. package/test/lsp/launch.test.ts +22 -0
  573. package/test/lsp/lifecycle.test.ts +147 -0
  574. package/test/mcp/headers.test.ts +153 -0
  575. package/test/mcp/lifecycle.test.ts +750 -0
  576. package/test/mcp/oauth-auto-connect.test.ts +199 -0
  577. package/test/mcp/oauth-browser.test.ts +249 -0
  578. package/test/memory/abort-leak.test.ts +137 -0
  579. package/test/patch/patch.test.ts +348 -0
  580. package/test/permission/arity.test.ts +33 -0
  581. package/test/permission/next.test.ts +1148 -0
  582. package/test/permission-task.test.ts +323 -0
  583. package/test/plugin/auth-override.test.ts +74 -0
  584. package/test/plugin/codex.test.ts +123 -0
  585. package/test/plugin/github-copilot-models.test.ts +117 -0
  586. package/test/plugin/install-concurrency.test.ts +140 -0
  587. package/test/plugin/install.test.ts +570 -0
  588. package/test/plugin/loader-shared.test.ts +1136 -0
  589. package/test/plugin/meta.test.ts +137 -0
  590. package/test/plugin/trigger.test.ts +111 -0
  591. package/test/preload.ts +90 -0
  592. package/test/project/migrate-global.test.ts +140 -0
  593. package/test/project/project.test.ts +459 -0
  594. package/test/project/state.test.ts +115 -0
  595. package/test/project/vcs.test.ts +228 -0
  596. package/test/project/worktree-remove.test.ts +96 -0
  597. package/test/project/worktree.test.ts +173 -0
  598. package/test/provider/amazon-bedrock.test.ts +447 -0
  599. package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
  600. package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
  601. package/test/provider/gitlab-duo.test.ts +412 -0
  602. package/test/provider/provider.test.ts +2284 -0
  603. package/test/provider/transform.test.ts +2839 -0
  604. package/test/pty/pty-output-isolation.test.ts +141 -0
  605. package/test/pty/pty-session.test.ts +92 -0
  606. package/test/pty/pty-shell.test.ts +59 -0
  607. package/test/question/question.test.ts +453 -0
  608. package/test/server/global-session-list.test.ts +89 -0
  609. package/test/server/project-init-git.test.ts +121 -0
  610. package/test/server/session-actions.test.ts +83 -0
  611. package/test/server/session-list.test.ts +98 -0
  612. package/test/server/session-messages.test.ts +159 -0
  613. package/test/server/session-select.test.ts +84 -0
  614. package/test/session/compaction.test.ts +1212 -0
  615. package/test/session/instruction.test.ts +286 -0
  616. package/test/session/llm.test.ts +1098 -0
  617. package/test/session/message-v2.test.ts +957 -0
  618. package/test/session/messages-pagination.test.ts +885 -0
  619. package/test/session/processor-effect.test.ts +747 -0
  620. package/test/session/prompt-effect.test.ts +1241 -0
  621. package/test/session/prompt.test.ts +518 -0
  622. package/test/session/retry.test.ts +232 -0
  623. package/test/session/revert-compact.test.ts +621 -0
  624. package/test/session/session.test.ts +142 -0
  625. package/test/session/snapshot-tool-race.test.ts +242 -0
  626. package/test/session/structured-output-integration.test.ts +233 -0
  627. package/test/session/structured-output.test.ts +391 -0
  628. package/test/session/system.test.ts +59 -0
  629. package/test/share/share-next.test.ts +333 -0
  630. package/test/shell/shell.test.ts +73 -0
  631. package/test/skill/discovery.test.ts +116 -0
  632. package/test/skill/skill.test.ts +392 -0
  633. package/test/snapshot/snapshot.test.ts +1312 -0
  634. package/test/storage/db.test.ts +14 -0
  635. package/test/storage/json-migration.test.ts +849 -0
  636. package/test/storage/storage.test.ts +295 -0
  637. package/test/sync/index.test.ts +191 -0
  638. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  639. package/test/tool/apply_patch.test.ts +567 -0
  640. package/test/tool/bash.test.ts +1099 -0
  641. package/test/tool/edit.test.ts +681 -0
  642. package/test/tool/external-directory.test.ts +198 -0
  643. package/test/tool/fixtures/large-image.png +0 -0
  644. package/test/tool/fixtures/models-api.json +65179 -0
  645. package/test/tool/grep.test.ts +111 -0
  646. package/test/tool/question.test.ts +126 -0
  647. package/test/tool/read.test.ts +546 -0
  648. package/test/tool/registry.test.ts +126 -0
  649. package/test/tool/skill.test.ts +167 -0
  650. package/test/tool/task.test.ts +49 -0
  651. package/test/tool/tool-define.test.ts +101 -0
  652. package/test/tool/truncation.test.ts +161 -0
  653. package/test/tool/webfetch.test.ts +101 -0
  654. package/test/tool/write.test.ts +353 -0
  655. package/test/util/data-url.test.ts +14 -0
  656. package/test/util/effect-zod.test.ts +61 -0
  657. package/test/util/error.test.ts +38 -0
  658. package/test/util/filesystem.test.ts +656 -0
  659. package/test/util/flock.test.ts +383 -0
  660. package/test/util/format.test.ts +59 -0
  661. package/test/util/glob.test.ts +164 -0
  662. package/test/util/iife.test.ts +36 -0
  663. package/test/util/lazy.test.ts +50 -0
  664. package/test/util/lock.test.ts +72 -0
  665. package/test/util/module.test.ts +59 -0
  666. package/test/util/process.test.ts +128 -0
  667. package/test/util/timeout.test.ts +21 -0
  668. package/test/util/which.test.ts +100 -0
  669. package/test/util/wildcard.test.ts +90 -0
  670. package/tsconfig.json +23 -0
@@ -0,0 +1,2270 @@
1
+ import {
2
+ batch,
3
+ createContext,
4
+ createEffect,
5
+ createMemo,
6
+ createSignal,
7
+ For,
8
+ Match,
9
+ on,
10
+ onMount,
11
+ Show,
12
+ Switch,
13
+ useContext,
14
+ } from "solid-js"
15
+ import { Dynamic } from "solid-js/web"
16
+ import path from "path"
17
+ import { useRoute, useRouteData } from "@tui/context/route"
18
+ import { useSync } from "@tui/context/sync"
19
+ import { SplitBorder } from "@tui/component/border"
20
+ import { Spinner } from "@tui/component/spinner"
21
+ import { selectedForeground, useTheme } from "@tui/context/theme"
22
+ import { BoxRenderable, ScrollBoxRenderable, addDefaultParsers, TextAttributes, RGBA } from "@opentui/core"
23
+ import { Prompt, type PromptRef } from "@tui/component/prompt"
24
+ import type {
25
+ AssistantMessage,
26
+ Part,
27
+ Provider,
28
+ ToolPart,
29
+ UserMessage,
30
+ TextPart,
31
+ ReasoningPart,
32
+ } from "@opencode-ai/sdk/v2"
33
+ import { useLocal } from "@tui/context/local"
34
+ import { Locale } from "@/util/locale"
35
+ import type { Tool } from "@/tool/tool"
36
+ import type { ReadTool } from "@/tool/read"
37
+ import type { WriteTool } from "@/tool/write"
38
+ import { BashTool } from "@/tool/bash"
39
+ import type { GlobTool } from "@/tool/glob"
40
+ import { TodoWriteTool } from "@/tool/todo"
41
+ import type { GrepTool } from "@/tool/grep"
42
+ import type { ListTool } from "@/tool/ls"
43
+ import type { EditTool } from "@/tool/edit"
44
+ import type { ApplyPatchTool } from "@/tool/apply_patch"
45
+ import type { WebFetchTool } from "@/tool/webfetch"
46
+ import type { TaskTool } from "@/tool/task"
47
+ import type { QuestionTool } from "@/tool/question"
48
+ import type { SkillTool } from "@/tool/skill"
49
+ import { useKeyboard, useRenderer, useTerminalDimensions, type JSX } from "@opentui/solid"
50
+ import { useSDK } from "@tui/context/sdk"
51
+ import { useCommandDialog } from "@tui/component/dialog-command"
52
+ import type { DialogContext } from "@tui/ui/dialog"
53
+ import { useKeybind } from "@tui/context/keybind"
54
+ import { parsePatch } from "diff"
55
+ import { useDialog } from "../../ui/dialog"
56
+ import { TodoItem } from "../../component/todo-item"
57
+ import { DialogMessage } from "./dialog-message"
58
+ import type { PromptInfo } from "../../component/prompt/history"
59
+ import { DialogConfirm } from "@tui/ui/dialog-confirm"
60
+ import { DialogTimeline } from "./dialog-timeline"
61
+ import { DialogForkFromTimeline } from "./dialog-fork-from-timeline"
62
+ import { DialogSessionRename } from "../../component/dialog-session-rename"
63
+ import { Sidebar } from "./sidebar"
64
+ import { SubagentFooter } from "./subagent-footer.tsx"
65
+ import { TaskPanel } from "../../component/task-panel"
66
+ import { TaskManager } from "@/orchestrator/task-manager"
67
+ import { Flag } from "@/flag/flag"
68
+ import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
69
+ import parsers from "../../../../../../parsers-config.ts"
70
+ import { Clipboard } from "../../util/clipboard"
71
+ import { Toast, useToast } from "../../ui/toast"
72
+ import { useKV } from "../../context/kv.tsx"
73
+ import { Editor } from "../../util/editor"
74
+ import stripAnsi from "strip-ansi"
75
+ import { usePromptRef } from "../../context/prompt"
76
+ import { useExit } from "../../context/exit"
77
+ import { Filesystem } from "@/util/filesystem"
78
+ import { Global } from "@/global"
79
+ import { PermissionPrompt } from "./permission"
80
+ import { QuestionPrompt } from "./question"
81
+ import { DialogExportOptions } from "../../ui/dialog-export-options"
82
+ import * as Model from "../../util/model"
83
+ import { formatTranscript } from "../../util/transcript"
84
+ import { UI } from "@/cli/ui.ts"
85
+ import { useTuiConfig } from "../../context/tui-config"
86
+ import { getScrollAcceleration } from "../../util/scroll"
87
+ import { TuiPluginRuntime } from "../../plugin"
88
+
89
+ addDefaultParsers(parsers.parsers)
90
+
91
+ const context = createContext<{
92
+ width: number
93
+ sessionID: string
94
+ conceal: () => boolean
95
+ showThinking: () => boolean
96
+ showTimestamps: () => boolean
97
+ showDetails: () => boolean
98
+ showGenericToolOutput: () => boolean
99
+ diffWrapMode: () => "word" | "none"
100
+ providers: () => ReadonlyMap<string, Provider>
101
+ sync: ReturnType<typeof useSync>
102
+ tui: ReturnType<typeof useTuiConfig>
103
+ }>()
104
+
105
+ function use() {
106
+ const ctx = useContext(context)
107
+ if (!ctx) throw new Error("useContext must be used within a Session component")
108
+ return ctx
109
+ }
110
+
111
+ export function Session() {
112
+ const route = useRouteData("session")
113
+ const { navigate } = useRoute()
114
+ const sync = useSync()
115
+ const tuiConfig = useTuiConfig()
116
+ const kv = useKV()
117
+ const { theme } = useTheme()
118
+ const promptRef = usePromptRef()
119
+ const session = createMemo(() => sync.session.get(route.sessionID))
120
+ const children = createMemo(() => {
121
+ const parentID = session()?.parentID ?? session()?.id
122
+ return sync.data.session
123
+ .filter((x) => x.parentID === parentID || x.id === parentID)
124
+ .toSorted((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
125
+ })
126
+ const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])
127
+ const permissions = createMemo(() => {
128
+ if (session()?.parentID) return []
129
+ return children().flatMap((x) => sync.data.permission[x.id] ?? [])
130
+ })
131
+ const questions = createMemo(() => {
132
+ if (session()?.parentID) return []
133
+ return children().flatMap((x) => sync.data.question[x.id] ?? [])
134
+ })
135
+ const visible = createMemo(() => !session()?.parentID && permissions().length === 0 && questions().length === 0)
136
+ const disabled = createMemo(() => permissions().length > 0 || questions().length > 0)
137
+
138
+ const pending = createMemo(() => {
139
+ return messages().findLast((x) => x.role === "assistant" && !x.time.completed)?.id
140
+ })
141
+
142
+ const lastAssistant = createMemo(() => {
143
+ return messages().findLast((x) => x.role === "assistant")
144
+ })
145
+
146
+ const dimensions = useTerminalDimensions()
147
+ const [sidebar, setSidebar] = kv.signal<"auto" | "hide">("sidebar", "auto")
148
+ const [sidebarOpen, setSidebarOpen] = createSignal(false)
149
+ const [conceal, setConceal] = createSignal(true)
150
+ const [showThinking, setShowThinking] = kv.signal("thinking_visibility", true)
151
+ const [timestamps, setTimestamps] = kv.signal<"hide" | "show">("timestamps", "hide")
152
+ const [showDetails, setShowDetails] = kv.signal("tool_details_visibility", true)
153
+ const [showAssistantMetadata, setShowAssistantMetadata] = kv.signal("assistant_metadata_visibility", true)
154
+ const [showScrollbar, setShowScrollbar] = kv.signal("scrollbar_visible", false)
155
+ const [diffWrapMode] = kv.signal<"word" | "none">("diff_wrap_mode", "word")
156
+ const [animationsEnabled, setAnimationsEnabled] = kv.signal("animations_enabled", true)
157
+ const [showGenericToolOutput, setShowGenericToolOutput] = kv.signal("generic_tool_output_visibility", false)
158
+ const taskManager = new TaskManager()
159
+
160
+ const wide = createMemo(() => dimensions().width > 120)
161
+ const sidebarVisible = createMemo(() => {
162
+ if (session()?.parentID) return false
163
+ if (sidebarOpen()) return true
164
+ if (sidebar() === "auto" && wide()) return true
165
+ return false
166
+ })
167
+ const showTimestamps = createMemo(() => timestamps() === "show")
168
+ const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
169
+ const providers = createMemo(() => Model.index(sync.data.provider))
170
+
171
+ const scrollAcceleration = createMemo(() => getScrollAcceleration(tuiConfig))
172
+
173
+ createEffect(() => {
174
+ if (session()?.workspaceID) {
175
+ sdk.setWorkspace(session()?.workspaceID)
176
+ }
177
+ })
178
+
179
+ createEffect(async () => {
180
+ await sync.session
181
+ .sync(route.sessionID)
182
+ .then(() => {
183
+ if (scroll) scroll.scrollBy(100_000)
184
+ })
185
+ .catch((e) => {
186
+ console.error(e)
187
+ toast.show({
188
+ message: `Session not found: ${route.sessionID}`,
189
+ variant: "error",
190
+ })
191
+ return navigate({ type: "home" })
192
+ })
193
+ })
194
+
195
+ const toast = useToast()
196
+ const sdk = useSDK()
197
+
198
+ // Handle initial prompt from fork
199
+ let seeded = false
200
+ let lastSwitch: string | undefined = undefined
201
+ sdk.event.on("message.part.updated", (evt) => {
202
+ const part = evt.properties.part
203
+ if (part.type !== "tool") return
204
+ if (part.sessionID !== route.sessionID) return
205
+ if (part.state.status !== "completed") return
206
+ if (part.id === lastSwitch) return
207
+
208
+ if (part.tool === "plan_exit") {
209
+ local.agent.set("build")
210
+ lastSwitch = part.id
211
+ } else if (part.tool === "plan_enter") {
212
+ local.agent.set("plan")
213
+ lastSwitch = part.id
214
+ }
215
+ })
216
+
217
+ let scroll: ScrollBoxRenderable
218
+ let prompt: PromptRef | undefined
219
+ const bind = (r: PromptRef | undefined) => {
220
+ prompt = r
221
+ promptRef.set(r)
222
+ if (seeded || !route.initialPrompt || !r) return
223
+ seeded = true
224
+ r.set(route.initialPrompt)
225
+ }
226
+ const keybind = useKeybind()
227
+ const dialog = useDialog()
228
+ const renderer = useRenderer()
229
+
230
+ // Allow exit when in child session (prompt is hidden)
231
+ const exit = useExit()
232
+
233
+ createEffect(() => {
234
+ const title = Locale.truncate(session()?.title ?? "", 50)
235
+ const pad = (text: string) => text.padEnd(10, " ")
236
+ const weak = (text: string) => UI.Style.TEXT_DIM + pad(text) + UI.Style.TEXT_NORMAL
237
+ const logo = UI.logo(" ").split(/\r?\n/)
238
+ return exit.message.set(
239
+ [
240
+ ``,
241
+ `${logo[0] ?? ""}`,
242
+ `${logo[1] ?? ""}`,
243
+ `${logo[2] ?? ""}`,
244
+ ``,
245
+ ` ${weak("Session")}${UI.Style.TEXT_NORMAL_BOLD}${title}${UI.Style.TEXT_NORMAL}`,
246
+ ` ${weak("Continue")}${UI.Style.TEXT_NORMAL_BOLD}koro -s ${session()?.id}${UI.Style.TEXT_NORMAL}`,
247
+ ``,
248
+ ].join("\n"),
249
+ )
250
+ })
251
+
252
+ useKeyboard((evt) => {
253
+ if (!session()?.parentID) return
254
+ if (keybind.match("app_exit", evt)) {
255
+ exit()
256
+ }
257
+ })
258
+
259
+ // Helper: Find next visible message boundary in direction
260
+ const findNextVisibleMessage = (direction: "next" | "prev"): string | null => {
261
+ const children = scroll.getChildren()
262
+ const messagesList = messages()
263
+ const scrollTop = scroll.y
264
+
265
+ // Get visible messages sorted by position, filtering for valid non-synthetic, non-ignored content
266
+ const visibleMessages = children
267
+ .filter((c) => {
268
+ if (!c.id) return false
269
+ const message = messagesList.find((m) => m.id === c.id)
270
+ if (!message) return false
271
+
272
+ // Check if message has valid non-synthetic, non-ignored text parts
273
+ const parts = sync.data.part[message.id]
274
+ if (!parts || !Array.isArray(parts)) return false
275
+
276
+ return parts.some((part) => part && part.type === "text" && !part.synthetic && !part.ignored)
277
+ })
278
+ .sort((a, b) => a.y - b.y)
279
+
280
+ if (visibleMessages.length === 0) return null
281
+
282
+ if (direction === "next") {
283
+ // Find first message below current position
284
+ return visibleMessages.find((c) => c.y > scrollTop + 10)?.id ?? null
285
+ }
286
+ // Find last message above current position
287
+ return [...visibleMessages].reverse().find((c) => c.y < scrollTop - 10)?.id ?? null
288
+ }
289
+
290
+ // Helper: Scroll to message in direction or fallback to page scroll
291
+ const scrollToMessage = (direction: "next" | "prev", dialog: ReturnType<typeof useDialog>) => {
292
+ const targetID = findNextVisibleMessage(direction)
293
+
294
+ if (!targetID) {
295
+ scroll.scrollBy(direction === "next" ? scroll.height : -scroll.height)
296
+ dialog.clear()
297
+ return
298
+ }
299
+
300
+ const child = scroll.getChildren().find((c) => c.id === targetID)
301
+ if (child) scroll.scrollBy(child.y - scroll.y - 1)
302
+ dialog.clear()
303
+ }
304
+
305
+ function toBottom() {
306
+ setTimeout(() => {
307
+ if (!scroll || scroll.isDestroyed) return
308
+ scroll.scrollTo(scroll.scrollHeight)
309
+ }, 50)
310
+ }
311
+
312
+ const local = useLocal()
313
+
314
+ function moveFirstChild() {
315
+ if (children().length === 1) return
316
+ const next = children().find((x) => !!x.parentID)
317
+ if (next) {
318
+ navigate({
319
+ type: "session",
320
+ sessionID: next.id,
321
+ })
322
+ }
323
+ }
324
+
325
+ function moveChild(direction: number) {
326
+ if (children().length === 1) return
327
+
328
+ const sessions = children().filter((x) => !!x.parentID)
329
+ let next = sessions.findIndex((x) => x.id === session()?.id) - direction
330
+
331
+ if (next >= sessions.length) next = 0
332
+ if (next < 0) next = sessions.length - 1
333
+ if (sessions[next]) {
334
+ navigate({
335
+ type: "session",
336
+ sessionID: sessions[next].id,
337
+ })
338
+ }
339
+ }
340
+
341
+ function childSessionHandler(func: (dialog: DialogContext) => void) {
342
+ return (dialog: DialogContext) => {
343
+ if (!session()?.parentID || dialog.stack.length > 0) return
344
+ func(dialog)
345
+ }
346
+ }
347
+
348
+ const command = useCommandDialog()
349
+ command.register(() => [
350
+ {
351
+ title: session()?.share?.url ? "Copy share link" : "Share session",
352
+ value: "session.share",
353
+ suggested: route.type === "session",
354
+ keybind: "session_share",
355
+ category: "Session",
356
+ enabled: sync.data.config.share !== "disabled",
357
+ slash: {
358
+ name: "share",
359
+ },
360
+ onSelect: async (dialog) => {
361
+ const copy = (url: string) =>
362
+ Clipboard.copy(url)
363
+ .then(() => toast.show({ message: "Share URL copied to clipboard!", variant: "success" }))
364
+ .catch(() => toast.show({ message: "Failed to copy URL to clipboard", variant: "error" }))
365
+ const url = session()?.share?.url
366
+ if (url) {
367
+ await copy(url)
368
+ dialog.clear()
369
+ return
370
+ }
371
+ if (!kv.get("share_consent", false)) {
372
+ const ok = await DialogConfirm.show(dialog, "Share Session", "Are you sure you want to share it?")
373
+ if (ok !== true) return
374
+ kv.set("share_consent", true)
375
+ }
376
+ await sdk.client.session
377
+ .share({
378
+ sessionID: route.sessionID,
379
+ })
380
+ .then((res) => copy(res.data!.share!.url))
381
+ .catch((error) => {
382
+ toast.show({
383
+ message: error instanceof Error ? error.message : "Failed to share session",
384
+ variant: "error",
385
+ })
386
+ })
387
+ dialog.clear()
388
+ },
389
+ },
390
+ {
391
+ title: "Rename session",
392
+ value: "session.rename",
393
+ keybind: "session_rename",
394
+ category: "Session",
395
+ slash: {
396
+ name: "rename",
397
+ },
398
+ onSelect: (dialog) => {
399
+ dialog.replace(() => <DialogSessionRename session={route.sessionID} />)
400
+ },
401
+ },
402
+ {
403
+ title: "Jump to message",
404
+ value: "session.timeline",
405
+ keybind: "session_timeline",
406
+ category: "Session",
407
+ slash: {
408
+ name: "timeline",
409
+ },
410
+ onSelect: (dialog) => {
411
+ dialog.replace(() => (
412
+ <DialogTimeline
413
+ onMove={(messageID) => {
414
+ const child = scroll.getChildren().find((child) => {
415
+ return child.id === messageID
416
+ })
417
+ if (child) scroll.scrollBy(child.y - scroll.y - 1)
418
+ }}
419
+ sessionID={route.sessionID}
420
+ setPrompt={(promptInfo) => prompt?.set(promptInfo)}
421
+ />
422
+ ))
423
+ },
424
+ },
425
+ {
426
+ title: "Fork from message",
427
+ value: "session.fork",
428
+ keybind: "session_fork",
429
+ category: "Session",
430
+ slash: {
431
+ name: "fork",
432
+ },
433
+ onSelect: (dialog) => {
434
+ dialog.replace(() => (
435
+ <DialogForkFromTimeline
436
+ onMove={(messageID) => {
437
+ const child = scroll.getChildren().find((child) => {
438
+ return child.id === messageID
439
+ })
440
+ if (child) scroll.scrollBy(child.y - scroll.y - 1)
441
+ }}
442
+ sessionID={route.sessionID}
443
+ />
444
+ ))
445
+ },
446
+ },
447
+ {
448
+ title: "Compact session",
449
+ value: "session.compact",
450
+ keybind: "session_compact",
451
+ category: "Session",
452
+ slash: {
453
+ name: "compact",
454
+ aliases: ["summarize"],
455
+ },
456
+ onSelect: (dialog) => {
457
+ const selectedModel = local.model.current()
458
+ if (!selectedModel) {
459
+ toast.show({
460
+ variant: "warning",
461
+ message: "Connect a provider to summarize this session",
462
+ duration: 3000,
463
+ })
464
+ return
465
+ }
466
+ sdk.client.session.summarize({
467
+ sessionID: route.sessionID,
468
+ modelID: selectedModel.modelID,
469
+ providerID: selectedModel.providerID,
470
+ })
471
+ dialog.clear()
472
+ },
473
+ },
474
+ {
475
+ title: "Unshare session",
476
+ value: "session.unshare",
477
+ keybind: "session_unshare",
478
+ category: "Session",
479
+ enabled: !!session()?.share?.url,
480
+ slash: {
481
+ name: "unshare",
482
+ },
483
+ onSelect: async (dialog) => {
484
+ await sdk.client.session
485
+ .unshare({
486
+ sessionID: route.sessionID,
487
+ })
488
+ .then(() => toast.show({ message: "Session unshared successfully", variant: "success" }))
489
+ .catch((error) => {
490
+ toast.show({
491
+ message: error instanceof Error ? error.message : "Failed to unshare session",
492
+ variant: "error",
493
+ })
494
+ })
495
+ dialog.clear()
496
+ },
497
+ },
498
+ {
499
+ title: "Undo previous message",
500
+ value: "session.undo",
501
+ keybind: "messages_undo",
502
+ category: "Session",
503
+ slash: {
504
+ name: "undo",
505
+ },
506
+ onSelect: async (dialog) => {
507
+ const status = sync.data.session_status?.[route.sessionID]
508
+ if (status?.type !== "idle") await sdk.client.session.abort({ sessionID: route.sessionID }).catch(() => {})
509
+ const revert = session()?.revert?.messageID
510
+ const message = messages().findLast((x) => (!revert || x.id < revert) && x.role === "user")
511
+ if (!message) return
512
+ sdk.client.session
513
+ .revert({
514
+ sessionID: route.sessionID,
515
+ messageID: message.id,
516
+ })
517
+ .then(() => {
518
+ toBottom()
519
+ })
520
+ const parts = sync.data.part[message.id]
521
+ prompt?.set(
522
+ parts.reduce(
523
+ (agg, part) => {
524
+ if (part.type === "text") {
525
+ if (!part.synthetic) agg.input += part.text
526
+ }
527
+ if (part.type === "file") agg.parts.push(part)
528
+ return agg
529
+ },
530
+ { input: "", parts: [] as PromptInfo["parts"] },
531
+ ),
532
+ )
533
+ dialog.clear()
534
+ },
535
+ },
536
+ {
537
+ title: "Redo",
538
+ value: "session.redo",
539
+ keybind: "messages_redo",
540
+ category: "Session",
541
+ enabled: !!session()?.revert?.messageID,
542
+ slash: {
543
+ name: "redo",
544
+ },
545
+ onSelect: (dialog) => {
546
+ dialog.clear()
547
+ const messageID = session()?.revert?.messageID
548
+ if (!messageID) return
549
+ const message = messages().find((x) => x.role === "user" && x.id > messageID)
550
+ if (!message) {
551
+ sdk.client.session.unrevert({
552
+ sessionID: route.sessionID,
553
+ })
554
+ prompt?.set({ input: "", parts: [] })
555
+ return
556
+ }
557
+ sdk.client.session.revert({
558
+ sessionID: route.sessionID,
559
+ messageID: message.id,
560
+ })
561
+ },
562
+ },
563
+ {
564
+ title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
565
+ value: "session.sidebar.toggle",
566
+ keybind: "sidebar_toggle",
567
+ category: "Session",
568
+ onSelect: (dialog) => {
569
+ batch(() => {
570
+ const isVisible = sidebarVisible()
571
+ setSidebar(() => (isVisible ? "hide" : "auto"))
572
+ setSidebarOpen(!isVisible)
573
+ })
574
+ dialog.clear()
575
+ },
576
+ },
577
+ {
578
+ title: conceal() ? "Disable code concealment" : "Enable code concealment",
579
+ value: "session.toggle.conceal",
580
+ keybind: "messages_toggle_conceal" as any,
581
+ category: "Session",
582
+ onSelect: (dialog) => {
583
+ setConceal((prev) => !prev)
584
+ dialog.clear()
585
+ },
586
+ },
587
+ {
588
+ title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
589
+ value: "session.toggle.timestamps",
590
+ category: "Session",
591
+ slash: {
592
+ name: "timestamps",
593
+ aliases: ["toggle-timestamps"],
594
+ },
595
+ onSelect: (dialog) => {
596
+ setTimestamps((prev) => (prev === "show" ? "hide" : "show"))
597
+ dialog.clear()
598
+ },
599
+ },
600
+ {
601
+ title: showThinking() ? "Hide thinking" : "Show thinking",
602
+ value: "session.toggle.thinking",
603
+ keybind: "display_thinking",
604
+ category: "Session",
605
+ slash: {
606
+ name: "thinking",
607
+ aliases: ["toggle-thinking"],
608
+ },
609
+ onSelect: (dialog) => {
610
+ setShowThinking((prev) => !prev)
611
+ dialog.clear()
612
+ },
613
+ },
614
+ {
615
+ title: showDetails() ? "Hide tool details" : "Show tool details",
616
+ value: "session.toggle.actions",
617
+ keybind: "tool_details",
618
+ category: "Session",
619
+ onSelect: (dialog) => {
620
+ setShowDetails((prev) => !prev)
621
+ dialog.clear()
622
+ },
623
+ },
624
+ {
625
+ title: "Toggle session scrollbar",
626
+ value: "session.toggle.scrollbar",
627
+ keybind: "scrollbar_toggle",
628
+ category: "Session",
629
+ onSelect: (dialog) => {
630
+ setShowScrollbar((prev) => !prev)
631
+ dialog.clear()
632
+ },
633
+ },
634
+ {
635
+ title: showGenericToolOutput() ? "Hide generic tool output" : "Show generic tool output",
636
+ value: "session.toggle.generic_tool_output",
637
+ category: "Session",
638
+ onSelect: (dialog) => {
639
+ setShowGenericToolOutput((prev) => !prev)
640
+ dialog.clear()
641
+ },
642
+ },
643
+ {
644
+ title: "Page up",
645
+ value: "session.page.up",
646
+ keybind: "messages_page_up",
647
+ category: "Session",
648
+ hidden: true,
649
+ onSelect: (dialog) => {
650
+ scroll.scrollBy(-scroll.height / 2)
651
+ dialog.clear()
652
+ },
653
+ },
654
+ {
655
+ title: "Page down",
656
+ value: "session.page.down",
657
+ keybind: "messages_page_down",
658
+ category: "Session",
659
+ hidden: true,
660
+ onSelect: (dialog) => {
661
+ scroll.scrollBy(scroll.height / 2)
662
+ dialog.clear()
663
+ },
664
+ },
665
+ {
666
+ title: "Line up",
667
+ value: "session.line.up",
668
+ keybind: "messages_line_up",
669
+ category: "Session",
670
+ disabled: true,
671
+ onSelect: (dialog) => {
672
+ scroll.scrollBy(-1)
673
+ dialog.clear()
674
+ },
675
+ },
676
+ {
677
+ title: "Line down",
678
+ value: "session.line.down",
679
+ keybind: "messages_line_down",
680
+ category: "Session",
681
+ disabled: true,
682
+ onSelect: (dialog) => {
683
+ scroll.scrollBy(1)
684
+ dialog.clear()
685
+ },
686
+ },
687
+ {
688
+ title: "Half page up",
689
+ value: "session.half.page.up",
690
+ keybind: "messages_half_page_up",
691
+ category: "Session",
692
+ hidden: true,
693
+ onSelect: (dialog) => {
694
+ scroll.scrollBy(-scroll.height / 4)
695
+ dialog.clear()
696
+ },
697
+ },
698
+ {
699
+ title: "Half page down",
700
+ value: "session.half.page.down",
701
+ keybind: "messages_half_page_down",
702
+ category: "Session",
703
+ hidden: true,
704
+ onSelect: (dialog) => {
705
+ scroll.scrollBy(scroll.height / 4)
706
+ dialog.clear()
707
+ },
708
+ },
709
+ {
710
+ title: "First message",
711
+ value: "session.first",
712
+ keybind: "messages_first",
713
+ category: "Session",
714
+ hidden: true,
715
+ onSelect: (dialog) => {
716
+ scroll.scrollTo(0)
717
+ dialog.clear()
718
+ },
719
+ },
720
+ {
721
+ title: "Last message",
722
+ value: "session.last",
723
+ keybind: "messages_last",
724
+ category: "Session",
725
+ hidden: true,
726
+ onSelect: (dialog) => {
727
+ scroll.scrollTo(scroll.scrollHeight)
728
+ dialog.clear()
729
+ },
730
+ },
731
+ {
732
+ title: "Jump to last user message",
733
+ value: "session.messages_last_user",
734
+ keybind: "messages_last_user",
735
+ category: "Session",
736
+ hidden: true,
737
+ onSelect: () => {
738
+ const messages = sync.data.message[route.sessionID]
739
+ if (!messages || !messages.length) return
740
+
741
+ // Find the most recent user message with non-ignored, non-synthetic text parts
742
+ for (let i = messages.length - 1; i >= 0; i--) {
743
+ const message = messages[i]
744
+ if (!message || message.role !== "user") continue
745
+
746
+ const parts = sync.data.part[message.id]
747
+ if (!parts || !Array.isArray(parts)) continue
748
+
749
+ const hasValidTextPart = parts.some(
750
+ (part) => part && part.type === "text" && !part.synthetic && !part.ignored,
751
+ )
752
+
753
+ if (hasValidTextPart) {
754
+ const child = scroll.getChildren().find((child) => {
755
+ return child.id === message.id
756
+ })
757
+ if (child) scroll.scrollBy(child.y - scroll.y - 1)
758
+ break
759
+ }
760
+ }
761
+ },
762
+ },
763
+ {
764
+ title: "Next message",
765
+ value: "session.message.next",
766
+ keybind: "messages_next",
767
+ category: "Session",
768
+ hidden: true,
769
+ onSelect: (dialog) => scrollToMessage("next", dialog),
770
+ },
771
+ {
772
+ title: "Previous message",
773
+ value: "session.message.previous",
774
+ keybind: "messages_previous",
775
+ category: "Session",
776
+ hidden: true,
777
+ onSelect: (dialog) => scrollToMessage("prev", dialog),
778
+ },
779
+ {
780
+ title: "Copy last assistant message",
781
+ value: "messages.copy",
782
+ keybind: "messages_copy",
783
+ category: "Session",
784
+ onSelect: (dialog) => {
785
+ const revertID = session()?.revert?.messageID
786
+ const lastAssistantMessage = messages().findLast(
787
+ (msg) => msg.role === "assistant" && (!revertID || msg.id < revertID),
788
+ )
789
+ if (!lastAssistantMessage) {
790
+ toast.show({ message: "No assistant messages found", variant: "error" })
791
+ dialog.clear()
792
+ return
793
+ }
794
+
795
+ const parts = sync.data.part[lastAssistantMessage.id] ?? []
796
+ const textParts = parts.filter((part) => part.type === "text")
797
+ if (textParts.length === 0) {
798
+ toast.show({ message: "No text parts found in last assistant message", variant: "error" })
799
+ dialog.clear()
800
+ return
801
+ }
802
+
803
+ const text = textParts
804
+ .map((part) => part.text)
805
+ .join("\n")
806
+ .trim()
807
+ if (!text) {
808
+ toast.show({
809
+ message: "No text content found in last assistant message",
810
+ variant: "error",
811
+ })
812
+ dialog.clear()
813
+ return
814
+ }
815
+
816
+ Clipboard.copy(text)
817
+ .then(() => toast.show({ message: "Message copied to clipboard!", variant: "success" }))
818
+ .catch(() => toast.show({ message: "Failed to copy to clipboard", variant: "error" }))
819
+ dialog.clear()
820
+ },
821
+ },
822
+ {
823
+ title: "Copy session transcript",
824
+ value: "session.copy",
825
+ category: "Session",
826
+ slash: {
827
+ name: "copy",
828
+ },
829
+ onSelect: async (dialog) => {
830
+ try {
831
+ const sessionData = session()
832
+ if (!sessionData) return
833
+ const sessionMessages = messages()
834
+ const transcript = formatTranscript(
835
+ sessionData,
836
+ sessionMessages.map((msg) => ({ info: msg, parts: sync.data.part[msg.id] ?? [] })),
837
+ {
838
+ thinking: showThinking(),
839
+ toolDetails: showDetails(),
840
+ assistantMetadata: showAssistantMetadata(),
841
+ providers: sync.data.provider,
842
+ },
843
+ )
844
+ await Clipboard.copy(transcript)
845
+ toast.show({ message: "Session transcript copied to clipboard!", variant: "success" })
846
+ } catch (error) {
847
+ toast.show({ message: "Failed to copy session transcript", variant: "error" })
848
+ }
849
+ dialog.clear()
850
+ },
851
+ },
852
+ {
853
+ title: "Export session transcript",
854
+ value: "session.export",
855
+ keybind: "session_export",
856
+ category: "Session",
857
+ slash: {
858
+ name: "export",
859
+ },
860
+ onSelect: async (dialog) => {
861
+ try {
862
+ const sessionData = session()
863
+ if (!sessionData) return
864
+ const sessionMessages = messages()
865
+
866
+ const defaultFilename = `session-${sessionData.id.slice(0, 8)}.md`
867
+
868
+ const options = await DialogExportOptions.show(
869
+ dialog,
870
+ defaultFilename,
871
+ showThinking(),
872
+ showDetails(),
873
+ showAssistantMetadata(),
874
+ false,
875
+ )
876
+
877
+ if (options === null) return
878
+
879
+ const transcript = formatTranscript(
880
+ sessionData,
881
+ sessionMessages.map((msg) => ({ info: msg, parts: sync.data.part[msg.id] ?? [] })),
882
+ {
883
+ thinking: options.thinking,
884
+ toolDetails: options.toolDetails,
885
+ assistantMetadata: options.assistantMetadata,
886
+ providers: sync.data.provider,
887
+ },
888
+ )
889
+
890
+ if (options.openWithoutSaving) {
891
+ // Just open in editor without saving
892
+ await Editor.open({ value: transcript, renderer })
893
+ } else {
894
+ const exportDir = process.cwd()
895
+ const filename = options.filename.trim()
896
+ const filepath = path.join(exportDir, filename)
897
+
898
+ await Filesystem.write(filepath, transcript)
899
+
900
+ // Open with EDITOR if available
901
+ const result = await Editor.open({ value: transcript, renderer })
902
+ if (result !== undefined) {
903
+ await Filesystem.write(filepath, result)
904
+ }
905
+
906
+ toast.show({ message: `Session exported to ${filename}`, variant: "success" })
907
+ }
908
+ } catch (error) {
909
+ toast.show({ message: "Failed to export session", variant: "error" })
910
+ }
911
+ dialog.clear()
912
+ },
913
+ },
914
+ {
915
+ title: "Go to child session",
916
+ value: "session.child.first",
917
+ keybind: "session_child_first",
918
+ category: "Session",
919
+ hidden: true,
920
+ onSelect: (dialog) => {
921
+ moveFirstChild()
922
+ dialog.clear()
923
+ },
924
+ },
925
+ {
926
+ title: "Go to parent session",
927
+ value: "session.parent",
928
+ keybind: "session_parent",
929
+ category: "Session",
930
+ hidden: true,
931
+ enabled: !!session()?.parentID,
932
+ onSelect: childSessionHandler((dialog) => {
933
+ const parentID = session()?.parentID
934
+ if (parentID) {
935
+ navigate({
936
+ type: "session",
937
+ sessionID: parentID,
938
+ })
939
+ }
940
+ dialog.clear()
941
+ }),
942
+ },
943
+ {
944
+ title: "Next child session",
945
+ value: "session.child.next",
946
+ keybind: "session_child_cycle",
947
+ category: "Session",
948
+ hidden: true,
949
+ enabled: !!session()?.parentID,
950
+ onSelect: childSessionHandler((dialog) => {
951
+ moveChild(1)
952
+ dialog.clear()
953
+ }),
954
+ },
955
+ {
956
+ title: "Previous child session",
957
+ value: "session.child.previous",
958
+ keybind: "session_child_cycle_reverse",
959
+ category: "Session",
960
+ hidden: true,
961
+ enabled: !!session()?.parentID,
962
+ onSelect: childSessionHandler((dialog) => {
963
+ moveChild(-1)
964
+ dialog.clear()
965
+ }),
966
+ },
967
+ ])
968
+
969
+ const revertInfo = createMemo(() => session()?.revert)
970
+ const revertMessageID = createMemo(() => revertInfo()?.messageID)
971
+
972
+ const revertDiffFiles = createMemo(() => {
973
+ const diffText = revertInfo()?.diff ?? ""
974
+ if (!diffText) return []
975
+
976
+ try {
977
+ const patches = parsePatch(diffText)
978
+ return patches.map((patch) => {
979
+ const filename = patch.newFileName || patch.oldFileName || "unknown"
980
+ const cleanFilename = filename.replace(/^[ab]\//, "")
981
+ return {
982
+ filename: cleanFilename,
983
+ additions: patch.hunks.reduce(
984
+ (sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("+")).length,
985
+ 0,
986
+ ),
987
+ deletions: patch.hunks.reduce(
988
+ (sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("-")).length,
989
+ 0,
990
+ ),
991
+ }
992
+ })
993
+ } catch (error) {
994
+ return []
995
+ }
996
+ })
997
+
998
+ const revertRevertedMessages = createMemo(() => {
999
+ const messageID = revertMessageID()
1000
+ if (!messageID) return []
1001
+ return messages().filter((x) => x.id >= messageID && x.role === "user")
1002
+ })
1003
+
1004
+ const revert = createMemo(() => {
1005
+ const info = revertInfo()
1006
+ if (!info) return
1007
+ if (!info.messageID) return
1008
+ return {
1009
+ messageID: info.messageID,
1010
+ reverted: revertRevertedMessages(),
1011
+ diff: info.diff,
1012
+ diffFiles: revertDiffFiles(),
1013
+ }
1014
+ })
1015
+
1016
+ // snap to bottom when session changes
1017
+ createEffect(on(() => route.sessionID, toBottom))
1018
+
1019
+ return (
1020
+ <context.Provider
1021
+ value={{
1022
+ get width() {
1023
+ return contentWidth()
1024
+ },
1025
+ sessionID: route.sessionID,
1026
+ conceal,
1027
+ showThinking,
1028
+ showTimestamps,
1029
+ showDetails,
1030
+ showGenericToolOutput,
1031
+ diffWrapMode,
1032
+ providers,
1033
+ sync,
1034
+ tui: tuiConfig,
1035
+ }}
1036
+ >
1037
+ <box flexDirection="row">
1038
+ <box flexGrow={1} paddingBottom={1} paddingLeft={2} paddingRight={2} gap={1}>
1039
+ <Show when={session()}>
1040
+ <scrollbox
1041
+ ref={(r) => (scroll = r)}
1042
+ viewportOptions={{
1043
+ paddingRight: 1,
1044
+ }}
1045
+ verticalScrollbarOptions={{
1046
+ paddingLeft: 1,
1047
+ visible: true,
1048
+ trackOptions: {
1049
+ backgroundColor: theme.backgroundElement,
1050
+ foregroundColor: theme.primary,
1051
+ },
1052
+ }}
1053
+ stickyScroll={true}
1054
+ stickyStart="bottom"
1055
+ flexGrow={1}
1056
+ scrollAcceleration={scrollAcceleration()}
1057
+ >
1058
+ <box height={1} />
1059
+ <For each={messages()}>
1060
+ {(message, index) => (
1061
+ <Switch>
1062
+ <Match when={message.id === revert()?.messageID}>
1063
+ {(function () {
1064
+ const command = useCommandDialog()
1065
+ const [hover, setHover] = createSignal(false)
1066
+ const dialog = useDialog()
1067
+
1068
+ const handleUnrevert = async () => {
1069
+ const confirmed = await DialogConfirm.show(
1070
+ dialog,
1071
+ "Confirm Redo",
1072
+ "Are you sure you want to restore the reverted messages?",
1073
+ )
1074
+ if (confirmed) {
1075
+ command.trigger("session.redo")
1076
+ }
1077
+ }
1078
+
1079
+ return (
1080
+ <box
1081
+ onMouseOver={() => setHover(true)}
1082
+ onMouseOut={() => setHover(false)}
1083
+ onMouseUp={handleUnrevert}
1084
+ marginTop={1}
1085
+ flexShrink={0}
1086
+ border={["left"]}
1087
+ customBorderChars={SplitBorder.customBorderChars}
1088
+ borderColor={theme.backgroundPanel}
1089
+ >
1090
+ <box
1091
+ paddingTop={1}
1092
+ paddingBottom={1}
1093
+ paddingLeft={2}
1094
+ backgroundColor={hover() ? theme.backgroundElement : theme.backgroundPanel}
1095
+ >
1096
+ <text fg={theme.textMuted}>{revert()!.reverted.length} message reverted</text>
1097
+ <text fg={theme.textMuted}>
1098
+ <span style={{ fg: theme.text }}>{keybind.print("messages_redo")}</span> or /redo to
1099
+ restore
1100
+ </text>
1101
+ <Show when={revert()!.diffFiles?.length}>
1102
+ <box marginTop={1}>
1103
+ <For each={revert()!.diffFiles}>
1104
+ {(file) => (
1105
+ <text fg={theme.text}>
1106
+ {file.filename}
1107
+ <Show when={file.additions > 0}>
1108
+ <span style={{ fg: theme.diffAdded }}> +{file.additions}</span>
1109
+ </Show>
1110
+ <Show when={file.deletions > 0}>
1111
+ <span style={{ fg: theme.diffRemoved }}> -{file.deletions}</span>
1112
+ </Show>
1113
+ </text>
1114
+ )}
1115
+ </For>
1116
+ </box>
1117
+ </Show>
1118
+ </box>
1119
+ </box>
1120
+ )
1121
+ })()}
1122
+ </Match>
1123
+ <Match when={revert()?.messageID && message.id >= revert()!.messageID}>
1124
+ <></>
1125
+ </Match>
1126
+ <Match when={message.role === "user"}>
1127
+ <UserMessage
1128
+ index={index()}
1129
+ onMouseUp={() => {
1130
+ if (renderer.getSelection()?.getSelectedText()) return
1131
+ dialog.replace(() => (
1132
+ <DialogMessage
1133
+ messageID={message.id}
1134
+ sessionID={route.sessionID}
1135
+ setPrompt={(promptInfo) => prompt?.set(promptInfo)}
1136
+ />
1137
+ ))
1138
+ }}
1139
+ message={message as UserMessage}
1140
+ parts={sync.data.part[message.id] ?? []}
1141
+ pending={pending()}
1142
+ />
1143
+ </Match>
1144
+ <Match when={message.role === "assistant"}>
1145
+ <AssistantMessage
1146
+ last={lastAssistant()?.id === message.id}
1147
+ message={message as AssistantMessage}
1148
+ parts={sync.data.part[message.id] ?? []}
1149
+ />
1150
+ </Match>
1151
+ </Switch>
1152
+ )}
1153
+ </For>
1154
+ </scrollbox>
1155
+ <box flexShrink={0}>
1156
+ <Show when={taskManager.serialize().length > 0}>
1157
+ <TaskPanel tasks={taskManager.serialize()} />
1158
+ </Show>
1159
+ <Show when={permissions().length > 0}>
1160
+ <PermissionPrompt request={permissions()[0]} />
1161
+ </Show>
1162
+ <Show when={permissions().length === 0 && questions().length > 0}>
1163
+ <QuestionPrompt request={questions()[0]} />
1164
+ </Show>
1165
+ <Show when={session()?.parentID}>
1166
+ <SubagentFooter />
1167
+ </Show>
1168
+ <Show when={visible()}>
1169
+ <TuiPluginRuntime.Slot
1170
+ name="session_prompt"
1171
+ mode="replace"
1172
+ session_id={route.sessionID}
1173
+ visible={visible()}
1174
+ disabled={disabled()}
1175
+ on_submit={toBottom}
1176
+ ref={bind}
1177
+ >
1178
+ <Prompt
1179
+ visible={visible()}
1180
+ ref={bind}
1181
+ disabled={disabled()}
1182
+ onSubmit={() => {
1183
+ toBottom()
1184
+ }}
1185
+ sessionID={route.sessionID}
1186
+ right={<TuiPluginRuntime.Slot name="session_prompt_right" session_id={route.sessionID} />}
1187
+ />
1188
+ </TuiPluginRuntime.Slot>
1189
+ </Show>
1190
+ </box>
1191
+ </Show>
1192
+ <Toast />
1193
+ </box>
1194
+ <Show when={sidebarVisible()}>
1195
+ <Switch>
1196
+ <Match when={wide()}>
1197
+ <Sidebar sessionID={route.sessionID} />
1198
+ </Match>
1199
+ <Match when={!wide()}>
1200
+ <box
1201
+ position="absolute"
1202
+ top={0}
1203
+ left={0}
1204
+ right={0}
1205
+ bottom={0}
1206
+ alignItems="flex-end"
1207
+ backgroundColor={RGBA.fromInts(0, 0, 0, 70)}
1208
+ >
1209
+ <Sidebar sessionID={route.sessionID} />
1210
+ </box>
1211
+ </Match>
1212
+ </Switch>
1213
+ </Show>
1214
+ </box>
1215
+ </context.Provider>
1216
+ )
1217
+ }
1218
+
1219
+ const MIME_BADGE: Record<string, string> = {
1220
+ "text/plain": "txt",
1221
+ "image/png": "img",
1222
+ "image/jpeg": "img",
1223
+ "image/gif": "img",
1224
+ "image/webp": "img",
1225
+ "application/pdf": "pdf",
1226
+ "application/x-directory": "dir",
1227
+ }
1228
+
1229
+ function UserMessage(props: {
1230
+ message: UserMessage
1231
+ parts: Part[]
1232
+ onMouseUp: () => void
1233
+ index: number
1234
+ pending?: string
1235
+ }) {
1236
+ const ctx = use()
1237
+ const local = useLocal()
1238
+ const text = createMemo(() => props.parts.flatMap((x) => (x.type === "text" && !x.synthetic ? [x] : []))[0])
1239
+ const files = createMemo(() => props.parts.flatMap((x) => (x.type === "file" ? [x] : [])))
1240
+ const { theme } = useTheme()
1241
+ const [hover, setHover] = createSignal(false)
1242
+ const queued = createMemo(() => props.pending && props.message.id > props.pending)
1243
+ const color = createMemo(() => local.agent.color(props.message.agent))
1244
+ const queuedFg = createMemo(() => selectedForeground(theme, color()))
1245
+ const metadataVisible = createMemo(() => queued() || ctx.showTimestamps())
1246
+
1247
+ const compaction = createMemo(() => props.parts.find((x) => x.type === "compaction"))
1248
+
1249
+ return (
1250
+ <>
1251
+ <Show when={text()}>
1252
+ <box
1253
+ id={props.message.id}
1254
+ border={["left"]}
1255
+ borderColor={color()}
1256
+ customBorderChars={SplitBorder.customBorderChars}
1257
+ marginTop={props.index === 0 ? 0 : 1}
1258
+ >
1259
+ <box
1260
+ onMouseOver={() => {
1261
+ setHover(true)
1262
+ }}
1263
+ onMouseOut={() => {
1264
+ setHover(false)
1265
+ }}
1266
+ onMouseUp={props.onMouseUp}
1267
+ paddingTop={1}
1268
+ paddingBottom={1}
1269
+ paddingLeft={2}
1270
+ backgroundColor={hover() ? theme.backgroundElement : theme.backgroundPanel}
1271
+ flexShrink={0}
1272
+ >
1273
+ <text fg={theme.text}>{text()?.text}</text>
1274
+ <Show when={files().length}>
1275
+ <box flexDirection="row" paddingBottom={metadataVisible() ? 1 : 0} paddingTop={1} gap={1} flexWrap="wrap">
1276
+ <For each={files()}>
1277
+ {(file) => {
1278
+ const bg = createMemo(() => {
1279
+ if (file.mime.startsWith("image/")) return theme.accent
1280
+ if (file.mime === "application/pdf") return theme.primary
1281
+ return theme.secondary
1282
+ })
1283
+ return (
1284
+ <text fg={theme.text}>
1285
+ <span style={{ bg: bg(), fg: theme.background }}> {MIME_BADGE[file.mime] ?? file.mime} </span>
1286
+ <span style={{ bg: theme.backgroundElement, fg: theme.textMuted }}> {file.filename} </span>
1287
+ </text>
1288
+ )
1289
+ }}
1290
+ </For>
1291
+ </box>
1292
+ </Show>
1293
+ <Show
1294
+ when={queued()}
1295
+ fallback={
1296
+ <Show when={ctx.showTimestamps()}>
1297
+ <text fg={theme.textMuted}>
1298
+ <span style={{ fg: theme.textMuted }}>
1299
+ {Locale.todayTimeOrDateTime(props.message.time.created)}
1300
+ </span>
1301
+ </text>
1302
+ </Show>
1303
+ }
1304
+ >
1305
+ <text fg={theme.textMuted}>
1306
+ <span style={{ bg: color(), fg: queuedFg(), bold: true }}> QUEUED </span>
1307
+ </text>
1308
+ </Show>
1309
+ </box>
1310
+ </box>
1311
+ </Show>
1312
+ <Show when={compaction()}>
1313
+ <box
1314
+ marginTop={1}
1315
+ border={["top"]}
1316
+ title=" Compaction "
1317
+ titleAlignment="center"
1318
+ borderColor={theme.borderActive}
1319
+ />
1320
+ </Show>
1321
+ </>
1322
+ )
1323
+ }
1324
+
1325
+ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; last: boolean }) {
1326
+ const ctx = use()
1327
+ const local = useLocal()
1328
+ const { theme } = useTheme()
1329
+ const sync = useSync()
1330
+ const messages = createMemo(() => sync.data.message[props.message.sessionID] ?? [])
1331
+ const model = createMemo(() => Model.name(ctx.providers(), props.message.providerID, props.message.modelID))
1332
+
1333
+ const final = createMemo(() => {
1334
+ return props.message.finish && !["tool-calls", "unknown"].includes(props.message.finish)
1335
+ })
1336
+
1337
+ const duration = createMemo(() => {
1338
+ if (!final()) return 0
1339
+ if (!props.message.time.completed) return 0
1340
+ const user = messages().find((x) => x.role === "user" && x.id === props.message.parentID)
1341
+ if (!user || !user.time) return 0
1342
+ return props.message.time.completed - user.time.created
1343
+ })
1344
+
1345
+ const keybind = useKeybind()
1346
+
1347
+ return (
1348
+ <>
1349
+ <For each={props.parts}>
1350
+ {(part, index) => {
1351
+ const component = createMemo(() => PART_MAPPING[part.type as keyof typeof PART_MAPPING])
1352
+ return (
1353
+ <Show when={component()}>
1354
+ <Dynamic
1355
+ last={index() === props.parts.length - 1}
1356
+ component={component()}
1357
+ part={part as any}
1358
+ message={props.message}
1359
+ />
1360
+ </Show>
1361
+ )
1362
+ }}
1363
+ </For>
1364
+ <Show when={props.parts.some((x) => x.type === "tool" && x.tool === "task")}>
1365
+ <box paddingTop={1} paddingLeft={3}>
1366
+ <text fg={theme.text}>
1367
+ {keybind.print("session_child_first")}
1368
+ <span style={{ fg: theme.textMuted }}> view subagents</span>
1369
+ </text>
1370
+ </box>
1371
+ </Show>
1372
+ <Show when={props.message.error && props.message.error.name !== "MessageAbortedError"}>
1373
+ <box
1374
+ border={["left"]}
1375
+ paddingTop={1}
1376
+ paddingBottom={1}
1377
+ paddingLeft={2}
1378
+ marginTop={1}
1379
+ backgroundColor={theme.backgroundPanel}
1380
+ customBorderChars={SplitBorder.customBorderChars}
1381
+ borderColor={theme.error}
1382
+ >
1383
+ <text fg={theme.textMuted}>{props.message.error?.data.message}</text>
1384
+ </box>
1385
+ </Show>
1386
+ <Switch>
1387
+ <Match when={props.last || final() || props.message.error?.name === "MessageAbortedError"}>
1388
+ <box paddingLeft={3}>
1389
+ <text marginTop={1}>
1390
+ <span
1391
+ style={{
1392
+ fg:
1393
+ props.message.error?.name === "MessageAbortedError"
1394
+ ? theme.textMuted
1395
+ : local.agent.color(props.message.agent),
1396
+ }}
1397
+ >
1398
+ ▣{" "}
1399
+ </span>{" "}
1400
+ <span style={{ fg: theme.text }}>{Locale.titlecase(props.message.mode)}</span>
1401
+ <span style={{ fg: theme.textMuted }}> · {model()}</span>
1402
+ <Show when={duration()}>
1403
+ <span style={{ fg: theme.textMuted }}> · {Locale.duration(duration())}</span>
1404
+ </Show>
1405
+ <Show when={props.message.error?.name === "MessageAbortedError"}>
1406
+ <span style={{ fg: theme.textMuted }}> · interrupted</span>
1407
+ </Show>
1408
+ </text>
1409
+ </box>
1410
+ </Match>
1411
+ </Switch>
1412
+ </>
1413
+ )
1414
+ }
1415
+
1416
+ const PART_MAPPING = {
1417
+ text: TextPart,
1418
+ tool: ToolPart,
1419
+ reasoning: ReasoningPart,
1420
+ }
1421
+
1422
+ function ReasoningPart(props: { last: boolean; part: ReasoningPart; message: AssistantMessage }) {
1423
+ const { theme, subtleSyntax } = useTheme()
1424
+ const ctx = use()
1425
+ const content = createMemo(() => {
1426
+ // Filter out redacted reasoning chunks from OpenRouter
1427
+ // OpenRouter sends encrypted reasoning data that appears as [REDACTED]
1428
+ return props.part.text.replace("[REDACTED]", "").trim()
1429
+ })
1430
+ return (
1431
+ <Show when={content() && ctx.showThinking()}>
1432
+ <box
1433
+ id={"text-" + props.part.id}
1434
+ paddingLeft={2}
1435
+ marginTop={1}
1436
+ flexDirection="column"
1437
+ border={["left"]}
1438
+ customBorderChars={SplitBorder.customBorderChars}
1439
+ borderColor={theme.backgroundElement}
1440
+ >
1441
+ <code
1442
+ filetype="markdown"
1443
+ drawUnstyledText={false}
1444
+ streaming={true}
1445
+ syntaxStyle={subtleSyntax()}
1446
+ content={"_Thinking:_ " + content()}
1447
+ conceal={ctx.conceal()}
1448
+ fg={theme.textMuted}
1449
+ />
1450
+ </box>
1451
+ </Show>
1452
+ )
1453
+ }
1454
+
1455
+ function TextPart(props: { last: boolean; part: TextPart; message: AssistantMessage }) {
1456
+ const ctx = use()
1457
+ const { theme, syntax } = useTheme()
1458
+ return (
1459
+ <Show when={props.part.text.trim()}>
1460
+ <box id={"text-" + props.part.id} paddingLeft={3} marginTop={1} flexShrink={0}>
1461
+ <Switch>
1462
+ <Match when={Flag.OPENCODE_EXPERIMENTAL_MARKDOWN}>
1463
+ <markdown
1464
+ syntaxStyle={syntax()}
1465
+ streaming={true}
1466
+ content={props.part.text.trim()}
1467
+ conceal={ctx.conceal()}
1468
+ fg={theme.markdownText}
1469
+ bg={theme.background}
1470
+ />
1471
+ </Match>
1472
+ <Match when={!Flag.OPENCODE_EXPERIMENTAL_MARKDOWN}>
1473
+ <code
1474
+ filetype="markdown"
1475
+ drawUnstyledText={false}
1476
+ streaming={true}
1477
+ syntaxStyle={syntax()}
1478
+ content={props.part.text.trim()}
1479
+ conceal={ctx.conceal()}
1480
+ fg={theme.text}
1481
+ />
1482
+ </Match>
1483
+ </Switch>
1484
+ </box>
1485
+ </Show>
1486
+ )
1487
+ }
1488
+
1489
+ // Pending messages moved to individual tool pending functions
1490
+
1491
+ function ToolPart(props: { last: boolean; part: ToolPart; message: AssistantMessage }) {
1492
+ const ctx = use()
1493
+ const sync = useSync()
1494
+
1495
+ // Hide tool if showDetails is false and tool completed successfully
1496
+ const shouldHide = createMemo(() => {
1497
+ if (ctx.showDetails()) return false
1498
+ if (props.part.state.status !== "completed") return false
1499
+ return true
1500
+ })
1501
+
1502
+ const toolprops = {
1503
+ get metadata() {
1504
+ return props.part.state.status === "pending" ? {} : (props.part.state.metadata ?? {})
1505
+ },
1506
+ get input() {
1507
+ return props.part.state.input ?? {}
1508
+ },
1509
+ get output() {
1510
+ return props.part.state.status === "completed" ? props.part.state.output : undefined
1511
+ },
1512
+ get permission() {
1513
+ const permissions = sync.data.permission[props.message.sessionID] ?? []
1514
+ const permissionIndex = permissions.findIndex((x) => x.tool?.callID === props.part.callID)
1515
+ return permissions[permissionIndex]
1516
+ },
1517
+ get tool() {
1518
+ return props.part.tool
1519
+ },
1520
+ get part() {
1521
+ return props.part
1522
+ },
1523
+ }
1524
+
1525
+ return (
1526
+ <Show when={!shouldHide()}>
1527
+ <Switch>
1528
+ <Match when={props.part.tool === "bash"}>
1529
+ <Bash {...toolprops} />
1530
+ </Match>
1531
+ <Match when={props.part.tool === "glob"}>
1532
+ <Glob {...toolprops} />
1533
+ </Match>
1534
+ <Match when={props.part.tool === "read"}>
1535
+ <Read {...toolprops} />
1536
+ </Match>
1537
+ <Match when={props.part.tool === "grep"}>
1538
+ <Grep {...toolprops} />
1539
+ </Match>
1540
+ <Match when={props.part.tool === "list"}>
1541
+ <List {...toolprops} />
1542
+ </Match>
1543
+ <Match when={props.part.tool === "webfetch"}>
1544
+ <WebFetch {...toolprops} />
1545
+ </Match>
1546
+ <Match when={props.part.tool === "codesearch"}>
1547
+ <CodeSearch {...toolprops} />
1548
+ </Match>
1549
+ <Match when={props.part.tool === "websearch"}>
1550
+ <WebSearch {...toolprops} />
1551
+ </Match>
1552
+ <Match when={props.part.tool === "write"}>
1553
+ <Write {...toolprops} />
1554
+ </Match>
1555
+ <Match when={props.part.tool === "edit"}>
1556
+ <Edit {...toolprops} />
1557
+ </Match>
1558
+ <Match when={props.part.tool === "task"}>
1559
+ <Task {...toolprops} />
1560
+ </Match>
1561
+ <Match when={props.part.tool === "apply_patch"}>
1562
+ <ApplyPatch {...toolprops} />
1563
+ </Match>
1564
+ <Match when={props.part.tool === "todowrite"}>
1565
+ <TodoWrite {...toolprops} />
1566
+ </Match>
1567
+ <Match when={props.part.tool === "question"}>
1568
+ <Question {...toolprops} />
1569
+ </Match>
1570
+ <Match when={props.part.tool === "skill"}>
1571
+ <Skill {...toolprops} />
1572
+ </Match>
1573
+ <Match when={true}>
1574
+ <GenericTool {...toolprops} />
1575
+ </Match>
1576
+ </Switch>
1577
+ </Show>
1578
+ )
1579
+ }
1580
+
1581
+ type ToolProps<T> = {
1582
+ input: Partial<Tool.InferParameters<T>>
1583
+ metadata: Partial<Tool.InferMetadata<T>>
1584
+ permission: Record<string, any>
1585
+ tool: string
1586
+ output?: string
1587
+ part: ToolPart
1588
+ }
1589
+ function GenericTool(props: ToolProps<any>) {
1590
+ const { theme } = useTheme()
1591
+ const ctx = use()
1592
+ const output = createMemo(() => props.output?.trim() ?? "")
1593
+ const [expanded, setExpanded] = createSignal(false)
1594
+ const lines = createMemo(() => output().split("\n"))
1595
+ const maxLines = 3
1596
+ const overflow = createMemo(() => lines().length > maxLines)
1597
+ const limited = createMemo(() => {
1598
+ if (expanded() || !overflow()) return output()
1599
+ return [...lines().slice(0, maxLines), "…"].join("\n")
1600
+ })
1601
+
1602
+ return (
1603
+ <Show
1604
+ when={props.output && ctx.showGenericToolOutput()}
1605
+ fallback={
1606
+ <InlineTool icon="⚙" pending="Writing command..." complete={true} part={props.part}>
1607
+ {props.tool} {input(props.input)}
1608
+ </InlineTool>
1609
+ }
1610
+ >
1611
+ <BlockTool
1612
+ title={`# ${props.tool} ${input(props.input)}`}
1613
+ part={props.part}
1614
+ onClick={overflow() ? () => setExpanded((prev) => !prev) : undefined}
1615
+ >
1616
+ <box gap={1}>
1617
+ <text fg={theme.text}>{limited()}</text>
1618
+ <Show when={overflow()}>
1619
+ <text fg={theme.textMuted}>{expanded() ? "Click to collapse" : "Click to expand"}</text>
1620
+ </Show>
1621
+ </box>
1622
+ </BlockTool>
1623
+ </Show>
1624
+ )
1625
+ }
1626
+
1627
+ function InlineTool(props: {
1628
+ icon: string
1629
+ iconColor?: RGBA
1630
+ complete: any
1631
+ pending: string
1632
+ spinner?: boolean
1633
+ children: JSX.Element
1634
+ part: ToolPart
1635
+ onClick?: () => void
1636
+ }) {
1637
+ const [margin, setMargin] = createSignal(0)
1638
+ const { theme } = useTheme()
1639
+ const ctx = use()
1640
+ const sync = useSync()
1641
+ const renderer = useRenderer()
1642
+ const [hover, setHover] = createSignal(false)
1643
+
1644
+ const permission = createMemo(() => {
1645
+ const callID = sync.data.permission[ctx.sessionID]?.at(0)?.tool?.callID
1646
+ if (!callID) return false
1647
+ return callID === props.part.callID
1648
+ })
1649
+
1650
+ const fg = createMemo(() => {
1651
+ if (permission()) return theme.warning
1652
+ if (hover() && props.onClick) return theme.text
1653
+ if (props.complete) return theme.textMuted
1654
+ return theme.text
1655
+ })
1656
+
1657
+ const error = createMemo(() => (props.part.state.status === "error" ? props.part.state.error : undefined))
1658
+
1659
+ const denied = createMemo(
1660
+ () =>
1661
+ error()?.includes("QuestionRejectedError") ||
1662
+ error()?.includes("rejected permission") ||
1663
+ error()?.includes("specified a rule") ||
1664
+ error()?.includes("user dismissed"),
1665
+ )
1666
+
1667
+ return (
1668
+ <box
1669
+ marginTop={margin()}
1670
+ paddingLeft={3}
1671
+ onMouseOver={() => props.onClick && setHover(true)}
1672
+ onMouseOut={() => setHover(false)}
1673
+ onMouseUp={() => {
1674
+ if (renderer.getSelection()?.getSelectedText()) return
1675
+ props.onClick?.()
1676
+ }}
1677
+ renderBefore={function () {
1678
+ const el = this as BoxRenderable
1679
+ const parent = el.parent
1680
+ if (!parent) {
1681
+ return
1682
+ }
1683
+ if (el.height > 1) {
1684
+ setMargin(1)
1685
+ return
1686
+ }
1687
+ const children = parent.getChildren()
1688
+ const index = children.indexOf(el)
1689
+ const previous = children[index - 1]
1690
+ if (!previous) {
1691
+ setMargin(0)
1692
+ return
1693
+ }
1694
+ if (previous.height > 1 || previous.id.startsWith("text-")) {
1695
+ setMargin(1)
1696
+ return
1697
+ }
1698
+ }}
1699
+ >
1700
+ <Switch>
1701
+ <Match when={props.spinner}>
1702
+ <Spinner color={fg()} children={props.children} />
1703
+ </Match>
1704
+ <Match when={true}>
1705
+ <text paddingLeft={3} fg={fg()} attributes={denied() ? TextAttributes.STRIKETHROUGH : undefined}>
1706
+ <Show fallback={<>~ {props.pending}</>} when={props.complete}>
1707
+ <span style={{ fg: props.iconColor }}>{props.icon}</span> {props.children}
1708
+ </Show>
1709
+ </text>
1710
+ </Match>
1711
+ </Switch>
1712
+ <Show when={error() && !denied()}>
1713
+ <text fg={theme.error}>{error()}</text>
1714
+ </Show>
1715
+ </box>
1716
+ )
1717
+ }
1718
+
1719
+ function BlockTool(props: {
1720
+ title: string
1721
+ children: JSX.Element
1722
+ onClick?: () => void
1723
+ part?: ToolPart
1724
+ spinner?: boolean
1725
+ }) {
1726
+ const { theme } = useTheme()
1727
+ const renderer = useRenderer()
1728
+ const [hover, setHover] = createSignal(false)
1729
+ const error = createMemo(() => (props.part?.state.status === "error" ? props.part.state.error : undefined))
1730
+ return (
1731
+ <box
1732
+ border={["left"]}
1733
+ paddingTop={1}
1734
+ paddingBottom={1}
1735
+ paddingLeft={2}
1736
+ marginTop={1}
1737
+ gap={1}
1738
+ backgroundColor={hover() ? theme.backgroundMenu : theme.backgroundPanel}
1739
+ customBorderChars={SplitBorder.customBorderChars}
1740
+ borderColor={theme.background}
1741
+ onMouseOver={() => props.onClick && setHover(true)}
1742
+ onMouseOut={() => setHover(false)}
1743
+ onMouseUp={() => {
1744
+ if (renderer.getSelection()?.getSelectedText()) return
1745
+ props.onClick?.()
1746
+ }}
1747
+ >
1748
+ <Show
1749
+ when={props.spinner}
1750
+ fallback={
1751
+ <text paddingLeft={3} fg={theme.textMuted}>
1752
+ {props.title}
1753
+ </text>
1754
+ }
1755
+ >
1756
+ <Spinner color={theme.textMuted}>{props.title.replace(/^# /, "")}</Spinner>
1757
+ </Show>
1758
+ {props.children}
1759
+ <Show when={error()}>
1760
+ <text fg={theme.error}>{error()}</text>
1761
+ </Show>
1762
+ </box>
1763
+ )
1764
+ }
1765
+
1766
+ function Bash(props: ToolProps<typeof BashTool>) {
1767
+ const { theme } = useTheme()
1768
+ const sync = useSync()
1769
+ const isRunning = createMemo(() => props.part.state.status === "running")
1770
+ const output = createMemo(() => stripAnsi(props.metadata.output?.trim() ?? ""))
1771
+ const [expanded, setExpanded] = createSignal(false)
1772
+ const lines = createMemo(() => output().split("\n"))
1773
+ const overflow = createMemo(() => lines().length > 10)
1774
+ const limited = createMemo(() => {
1775
+ if (expanded() || !overflow()) return output()
1776
+ return [...lines().slice(0, 10), "…"].join("\n")
1777
+ })
1778
+
1779
+ const workdirDisplay = createMemo(() => {
1780
+ const workdir = props.input.workdir
1781
+ if (!workdir || workdir === ".") return undefined
1782
+
1783
+ const base = sync.data.path.directory
1784
+ if (!base) return undefined
1785
+
1786
+ const absolute = path.resolve(base, workdir)
1787
+ if (absolute === base) return undefined
1788
+
1789
+ const home = Global.Path.home
1790
+ if (!home) return absolute
1791
+
1792
+ const match = absolute === home || absolute.startsWith(home + path.sep)
1793
+ return match ? absolute.replace(home, "~") : absolute
1794
+ })
1795
+
1796
+ const title = createMemo(() => {
1797
+ const desc = props.input.description ?? "Shell"
1798
+ const wd = workdirDisplay()
1799
+ if (!wd) return `# ${desc}`
1800
+ if (desc.includes(wd)) return `# ${desc}`
1801
+ return `# ${desc} in ${wd}`
1802
+ })
1803
+
1804
+ return (
1805
+ <Switch>
1806
+ <Match when={props.metadata.output !== undefined}>
1807
+ <BlockTool
1808
+ title={title()}
1809
+ part={props.part}
1810
+ spinner={isRunning()}
1811
+ onClick={overflow() ? () => setExpanded((prev) => !prev) : undefined}
1812
+ >
1813
+ <box gap={1}>
1814
+ <text fg={theme.text}>$ {props.input.command}</text>
1815
+ <Show when={output()}>
1816
+ <text fg={theme.text}>{limited()}</text>
1817
+ </Show>
1818
+ <Show when={overflow()}>
1819
+ <text fg={theme.textMuted}>{expanded() ? "Click to collapse" : "Click to expand"}</text>
1820
+ </Show>
1821
+ </box>
1822
+ </BlockTool>
1823
+ </Match>
1824
+ <Match when={true}>
1825
+ <InlineTool icon="$" pending="Writing command..." complete={props.input.command} part={props.part}>
1826
+ {props.input.command}
1827
+ </InlineTool>
1828
+ </Match>
1829
+ </Switch>
1830
+ )
1831
+ }
1832
+
1833
+ function Write(props: ToolProps<typeof WriteTool>) {
1834
+ const { theme, syntax } = useTheme()
1835
+ const code = createMemo(() => {
1836
+ if (!props.input.content) return ""
1837
+ return props.input.content
1838
+ })
1839
+
1840
+ return (
1841
+ <Switch>
1842
+ <Match when={props.metadata.diagnostics !== undefined}>
1843
+ <BlockTool title={"# Wrote " + normalizePath(props.input.filePath!)} part={props.part}>
1844
+ <line_number fg={theme.textMuted} minWidth={3} paddingRight={1}>
1845
+ <code
1846
+ conceal={false}
1847
+ fg={theme.text}
1848
+ filetype={filetype(props.input.filePath!)}
1849
+ syntaxStyle={syntax()}
1850
+ content={code()}
1851
+ />
1852
+ </line_number>
1853
+ <Diagnostics diagnostics={props.metadata.diagnostics} filePath={props.input.filePath ?? ""} />
1854
+ </BlockTool>
1855
+ </Match>
1856
+ <Match when={true}>
1857
+ <InlineTool icon="←" pending="Preparing write..." complete={props.input.filePath} part={props.part}>
1858
+ Write {normalizePath(props.input.filePath!)}
1859
+ </InlineTool>
1860
+ </Match>
1861
+ </Switch>
1862
+ )
1863
+ }
1864
+
1865
+ function Glob(props: ToolProps<typeof GlobTool>) {
1866
+ return (
1867
+ <InlineTool icon="✱" pending="Finding files..." complete={props.input.pattern} part={props.part}>
1868
+ Glob "{props.input.pattern}" <Show when={props.input.path}>in {normalizePath(props.input.path)} </Show>
1869
+ <Show when={props.metadata.count}>
1870
+ ({props.metadata.count} {props.metadata.count === 1 ? "match" : "matches"})
1871
+ </Show>
1872
+ </InlineTool>
1873
+ )
1874
+ }
1875
+
1876
+ function Read(props: ToolProps<typeof ReadTool>) {
1877
+ const { theme } = useTheme()
1878
+ const isRunning = createMemo(() => props.part.state.status === "running")
1879
+ const loaded = createMemo(() => {
1880
+ if (props.part.state.status !== "completed") return []
1881
+ if (props.part.state.time.compacted) return []
1882
+ const value = props.metadata.loaded
1883
+ if (!value || !Array.isArray(value)) return []
1884
+ return value.filter((p): p is string => typeof p === "string")
1885
+ })
1886
+ return (
1887
+ <>
1888
+ <InlineTool
1889
+ icon="→"
1890
+ pending="Reading file..."
1891
+ complete={props.input.filePath}
1892
+ spinner={isRunning()}
1893
+ part={props.part}
1894
+ >
1895
+ Read {normalizePath(props.input.filePath!)} {input(props.input, ["filePath"])}
1896
+ </InlineTool>
1897
+ <For each={loaded()}>
1898
+ {(filepath) => (
1899
+ <box paddingLeft={3}>
1900
+ <text paddingLeft={3} fg={theme.textMuted}>
1901
+ ↳ Loaded {normalizePath(filepath)}
1902
+ </text>
1903
+ </box>
1904
+ )}
1905
+ </For>
1906
+ </>
1907
+ )
1908
+ }
1909
+
1910
+ function Grep(props: ToolProps<typeof GrepTool>) {
1911
+ return (
1912
+ <InlineTool icon="✱" pending="Searching content..." complete={props.input.pattern} part={props.part}>
1913
+ Grep "{props.input.pattern}" <Show when={props.input.path}>in {normalizePath(props.input.path)} </Show>
1914
+ <Show when={props.metadata.matches}>
1915
+ ({props.metadata.matches} {props.metadata.matches === 1 ? "match" : "matches"})
1916
+ </Show>
1917
+ </InlineTool>
1918
+ )
1919
+ }
1920
+
1921
+ function List(props: ToolProps<typeof ListTool>) {
1922
+ const dir = createMemo(() => {
1923
+ if (props.input.path) {
1924
+ return normalizePath(props.input.path)
1925
+ }
1926
+ return ""
1927
+ })
1928
+ return (
1929
+ <InlineTool icon="→" pending="Listing directory..." complete={props.input.path !== undefined} part={props.part}>
1930
+ List {dir()}
1931
+ </InlineTool>
1932
+ )
1933
+ }
1934
+
1935
+ function WebFetch(props: ToolProps<typeof WebFetchTool>) {
1936
+ return (
1937
+ <InlineTool icon="%" pending="Fetching from the web..." complete={(props.input as any).url} part={props.part}>
1938
+ WebFetch {(props.input as any).url}
1939
+ </InlineTool>
1940
+ )
1941
+ }
1942
+
1943
+ function CodeSearch(props: ToolProps<any>) {
1944
+ const input = props.input as any
1945
+ const metadata = props.metadata as any
1946
+ return (
1947
+ <InlineTool icon="◇" pending="Searching code..." complete={input.query} part={props.part}>
1948
+ Exa Code Search "{input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
1949
+ </InlineTool>
1950
+ )
1951
+ }
1952
+
1953
+ function WebSearch(props: ToolProps<any>) {
1954
+ const input = props.input as any
1955
+ const metadata = props.metadata as any
1956
+ return (
1957
+ <InlineTool icon="◈" pending="Searching web..." complete={input.query} part={props.part}>
1958
+ Exa Web Search "{input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
1959
+ </InlineTool>
1960
+ )
1961
+ }
1962
+
1963
+ function Task(props: ToolProps<typeof TaskTool>) {
1964
+ const { navigate } = useRoute()
1965
+ const sync = useSync()
1966
+
1967
+ onMount(() => {
1968
+ if (props.metadata.sessionId && !sync.data.message[props.metadata.sessionId]?.length)
1969
+ sync.session.sync(props.metadata.sessionId)
1970
+ })
1971
+
1972
+ const messages = createMemo(() => sync.data.message[props.metadata.sessionId ?? ""] ?? [])
1973
+
1974
+ const tools = createMemo(() => {
1975
+ return messages().flatMap((msg) =>
1976
+ (sync.data.part[msg.id] ?? [])
1977
+ .filter((part): part is ToolPart => part.type === "tool")
1978
+ .map((part) => ({ tool: part.tool, state: part.state })),
1979
+ )
1980
+ })
1981
+
1982
+ const current = createMemo(() => tools().findLast((x) => (x.state as any).title))
1983
+
1984
+ const isRunning = createMemo(() => props.part.state.status === "running")
1985
+
1986
+ const duration = createMemo(() => {
1987
+ const first = messages().find((x) => x.role === "user")?.time.created
1988
+ const assistant = messages().findLast((x) => x.role === "assistant")?.time.completed
1989
+ if (!first || !assistant) return 0
1990
+ return assistant - first
1991
+ })
1992
+
1993
+ const content = createMemo(() => {
1994
+ if (!props.input.description) return ""
1995
+ let content = [`${Locale.titlecase(props.input.subagent_type ?? "General")} Task — ${props.input.description}`]
1996
+
1997
+ if (isRunning() && tools().length > 0) {
1998
+ // content[0] += ` · ${tools().length} toolcalls`
1999
+ if (current()) content.push(`↳ ${Locale.titlecase(current()!.tool)} ${(current()!.state as any).title}`)
2000
+ else content.push(`↳ ${tools().length} toolcalls`)
2001
+ }
2002
+
2003
+ if (props.part.state.status === "completed") {
2004
+ content.push(`└ ${tools().length} toolcalls · ${Locale.duration(duration())}`)
2005
+ }
2006
+
2007
+ return content.join("\n")
2008
+ })
2009
+
2010
+ return (
2011
+ <InlineTool
2012
+ icon="│"
2013
+ spinner={isRunning()}
2014
+ complete={props.input.description}
2015
+ pending="Delegating..."
2016
+ part={props.part}
2017
+ onClick={() => {
2018
+ if (props.metadata.sessionId) {
2019
+ navigate({ type: "session", sessionID: props.metadata.sessionId })
2020
+ }
2021
+ }}
2022
+ >
2023
+ {content()}
2024
+ </InlineTool>
2025
+ )
2026
+ }
2027
+
2028
+ function Edit(props: ToolProps<typeof EditTool>) {
2029
+ const ctx = use()
2030
+ const { theme, syntax } = useTheme()
2031
+
2032
+ const view = createMemo(() => {
2033
+ const diffStyle = ctx.tui.diff_style
2034
+ if (diffStyle === "stacked") return "unified"
2035
+ // Default to "auto" behavior
2036
+ return ctx.width > 120 ? "split" : "unified"
2037
+ })
2038
+
2039
+ const ft = createMemo(() => filetype(props.input.filePath))
2040
+
2041
+ const diffContent = createMemo(() => props.metadata.diff)
2042
+
2043
+ return (
2044
+ <Switch>
2045
+ <Match when={props.metadata.diff !== undefined}>
2046
+ <BlockTool title={"← Edit " + normalizePath(props.input.filePath!)} part={props.part}>
2047
+ <box paddingLeft={1}>
2048
+ <diff
2049
+ diff={diffContent()}
2050
+ view={view()}
2051
+ filetype={ft()}
2052
+ syntaxStyle={syntax()}
2053
+ showLineNumbers={true}
2054
+ width="100%"
2055
+ wrapMode={ctx.diffWrapMode()}
2056
+ fg={theme.text}
2057
+ addedBg={theme.diffAddedBg}
2058
+ removedBg={theme.diffRemovedBg}
2059
+ contextBg={theme.diffContextBg}
2060
+ addedSignColor={theme.diffHighlightAdded}
2061
+ removedSignColor={theme.diffHighlightRemoved}
2062
+ lineNumberFg={theme.diffLineNumber}
2063
+ lineNumberBg={theme.diffContextBg}
2064
+ addedLineNumberBg={theme.diffAddedLineNumberBg}
2065
+ removedLineNumberBg={theme.diffRemovedLineNumberBg}
2066
+ />
2067
+ </box>
2068
+ <Diagnostics diagnostics={props.metadata.diagnostics} filePath={props.input.filePath ?? ""} />
2069
+ </BlockTool>
2070
+ </Match>
2071
+ <Match when={true}>
2072
+ <InlineTool icon="←" pending="Preparing edit..." complete={props.input.filePath} part={props.part}>
2073
+ Edit {normalizePath(props.input.filePath!)} {input({ replaceAll: props.input.replaceAll })}
2074
+ </InlineTool>
2075
+ </Match>
2076
+ </Switch>
2077
+ )
2078
+ }
2079
+
2080
+ function ApplyPatch(props: ToolProps<typeof ApplyPatchTool>) {
2081
+ const ctx = use()
2082
+ const { theme, syntax } = useTheme()
2083
+
2084
+ const files = createMemo(() => props.metadata.files ?? [])
2085
+
2086
+ const view = createMemo(() => {
2087
+ const diffStyle = ctx.tui.diff_style
2088
+ if (diffStyle === "stacked") return "unified"
2089
+ return ctx.width > 120 ? "split" : "unified"
2090
+ })
2091
+
2092
+ function Diff(p: { diff: string; filePath: string }) {
2093
+ return (
2094
+ <box paddingLeft={1}>
2095
+ <diff
2096
+ diff={p.diff}
2097
+ view={view()}
2098
+ filetype={filetype(p.filePath)}
2099
+ syntaxStyle={syntax()}
2100
+ showLineNumbers={true}
2101
+ width="100%"
2102
+ wrapMode={ctx.diffWrapMode()}
2103
+ fg={theme.text}
2104
+ addedBg={theme.diffAddedBg}
2105
+ removedBg={theme.diffRemovedBg}
2106
+ contextBg={theme.diffContextBg}
2107
+ addedSignColor={theme.diffHighlightAdded}
2108
+ removedSignColor={theme.diffHighlightRemoved}
2109
+ lineNumberFg={theme.diffLineNumber}
2110
+ lineNumberBg={theme.diffContextBg}
2111
+ addedLineNumberBg={theme.diffAddedLineNumberBg}
2112
+ removedLineNumberBg={theme.diffRemovedLineNumberBg}
2113
+ />
2114
+ </box>
2115
+ )
2116
+ }
2117
+
2118
+ function title(file: { type: string; relativePath: string; filePath: string; deletions: number }) {
2119
+ if (file.type === "delete") return "# Deleted " + file.relativePath
2120
+ if (file.type === "add") return "# Created " + file.relativePath
2121
+ if (file.type === "move") return "# Moved " + normalizePath(file.filePath) + " → " + file.relativePath
2122
+ return "← Patched " + file.relativePath
2123
+ }
2124
+
2125
+ return (
2126
+ <Switch>
2127
+ <Match when={files().length > 0}>
2128
+ <For each={files()}>
2129
+ {(file) => (
2130
+ <BlockTool title={title(file)} part={props.part}>
2131
+ <Show
2132
+ when={file.type !== "delete"}
2133
+ fallback={
2134
+ <text fg={theme.diffRemoved}>
2135
+ -{file.deletions} line{file.deletions !== 1 ? "s" : ""}
2136
+ </text>
2137
+ }
2138
+ >
2139
+ <Diff diff={file.diff} filePath={file.filePath} />
2140
+ <Diagnostics diagnostics={props.metadata.diagnostics} filePath={file.movePath ?? file.filePath} />
2141
+ </Show>
2142
+ </BlockTool>
2143
+ )}
2144
+ </For>
2145
+ </Match>
2146
+ <Match when={true}>
2147
+ <InlineTool icon="%" pending="Preparing patch..." complete={false} part={props.part}>
2148
+ Patch
2149
+ </InlineTool>
2150
+ </Match>
2151
+ </Switch>
2152
+ )
2153
+ }
2154
+
2155
+ function TodoWrite(props: ToolProps<typeof TodoWriteTool>) {
2156
+ return (
2157
+ <Switch>
2158
+ <Match when={props.metadata.todos?.length}>
2159
+ <BlockTool title="# Todos" part={props.part}>
2160
+ <box>
2161
+ <For each={props.input.todos ?? []}>
2162
+ {(todo) => <TodoItem status={todo.status} content={todo.content} />}
2163
+ </For>
2164
+ </box>
2165
+ </BlockTool>
2166
+ </Match>
2167
+ <Match when={true}>
2168
+ <InlineTool icon="⚙" pending="Updating todos..." complete={false} part={props.part}>
2169
+ Updating todos...
2170
+ </InlineTool>
2171
+ </Match>
2172
+ </Switch>
2173
+ )
2174
+ }
2175
+
2176
+ function Question(props: ToolProps<typeof QuestionTool>) {
2177
+ const { theme } = useTheme()
2178
+ const count = createMemo(() => props.input.questions?.length ?? 0)
2179
+
2180
+ function format(answer?: string[]) {
2181
+ if (!answer?.length) return "(no answer)"
2182
+ return answer.join(", ")
2183
+ }
2184
+
2185
+ return (
2186
+ <Switch>
2187
+ <Match when={props.metadata.answers}>
2188
+ <BlockTool title="# Questions" part={props.part}>
2189
+ <box gap={1}>
2190
+ <For each={props.input.questions ?? []}>
2191
+ {(q, i) => (
2192
+ <box flexDirection="column">
2193
+ <text fg={theme.textMuted}>{q.question}</text>
2194
+ <text fg={theme.text}>{format(props.metadata.answers?.[i()])}</text>
2195
+ </box>
2196
+ )}
2197
+ </For>
2198
+ </box>
2199
+ </BlockTool>
2200
+ </Match>
2201
+ <Match when={true}>
2202
+ <InlineTool icon="→" pending="Asking questions..." complete={count()} part={props.part}>
2203
+ Asked {count()} question{count() !== 1 ? "s" : ""}
2204
+ </InlineTool>
2205
+ </Match>
2206
+ </Switch>
2207
+ )
2208
+ }
2209
+
2210
+ function Skill(props: ToolProps<typeof SkillTool>) {
2211
+ return (
2212
+ <InlineTool icon="→" pending="Loading skill..." complete={props.input.name} part={props.part}>
2213
+ Skill "{props.input.name}"
2214
+ </InlineTool>
2215
+ )
2216
+ }
2217
+
2218
+ function Diagnostics(props: { diagnostics?: Record<string, Record<string, any>[]>; filePath: string }) {
2219
+ const { theme } = useTheme()
2220
+ const errors = createMemo(() => {
2221
+ const normalized = Filesystem.normalizePath(props.filePath)
2222
+ const arr = props.diagnostics?.[normalized] ?? []
2223
+ return arr.filter((x) => x.severity === 1).slice(0, 3)
2224
+ })
2225
+
2226
+ return (
2227
+ <Show when={errors().length}>
2228
+ <box>
2229
+ <For each={errors()}>
2230
+ {(diagnostic) => (
2231
+ <text fg={theme.error}>
2232
+ Error [{diagnostic.range.start.line + 1}:{diagnostic.range.start.character + 1}] {diagnostic.message}
2233
+ </text>
2234
+ )}
2235
+ </For>
2236
+ </box>
2237
+ </Show>
2238
+ )
2239
+ }
2240
+
2241
+ function normalizePath(input?: string) {
2242
+ if (!input) return ""
2243
+
2244
+ const cwd = process.cwd()
2245
+ const absolute = path.isAbsolute(input) ? input : path.resolve(cwd, input)
2246
+ const relative = path.relative(cwd, absolute)
2247
+
2248
+ if (!relative) return "."
2249
+ if (!relative.startsWith("..")) return relative
2250
+
2251
+ // outside cwd - use absolute
2252
+ return absolute
2253
+ }
2254
+
2255
+ function input(input: Record<string, any>, omit?: string[]): string {
2256
+ const primitives = Object.entries(input).filter(([key, value]) => {
2257
+ if (omit?.includes(key)) return false
2258
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean"
2259
+ })
2260
+ if (primitives.length === 0) return ""
2261
+ return `[${primitives.map(([key, value]) => `${key}=${value}`).join(", ")}]`
2262
+ }
2263
+
2264
+ function filetype(input?: string) {
2265
+ if (!input) return "none"
2266
+ const ext = path.extname(input)
2267
+ const language = LANGUAGE_EXTENSIONS[ext]
2268
+ if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"
2269
+ return language
2270
+ }