nikcli 0.0.6

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