@stonerzju/opencode 1.2.16-offline.1

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