chad-code 1.3.1 → 1.3.2

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