@bloxystudios/bloxycode 1.0.2 → 1.0.5

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