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