easc-cli 1.1.28

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