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