cerebras-cli 1.0.0

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 (314) hide show
  1. package/AGENTS.md +27 -0
  2. package/Dockerfile +10 -0
  3. package/README.md +15 -0
  4. package/bin/opencode +84 -0
  5. package/bunfig.toml +4 -0
  6. package/package.json +128 -0
  7. package/parsers-config.ts +239 -0
  8. package/script/build.ts +151 -0
  9. package/script/postinstall.mjs +122 -0
  10. package/script/publish.ts +256 -0
  11. package/script/schema.ts +47 -0
  12. package/src/acp/README.md +164 -0
  13. package/src/acp/agent.ts +812 -0
  14. package/src/acp/session.ts +70 -0
  15. package/src/acp/types.ts +22 -0
  16. package/src/agent/agent.ts +310 -0
  17. package/src/agent/generate.txt +75 -0
  18. package/src/auth/index.ts +70 -0
  19. package/src/bun/index.ts +152 -0
  20. package/src/bus/global.ts +10 -0
  21. package/src/bus/index.ts +142 -0
  22. package/src/cli/bootstrap.ts +17 -0
  23. package/src/cli/cmd/acp.ts +88 -0
  24. package/src/cli/cmd/agent.ts +165 -0
  25. package/src/cli/cmd/auth.ts +369 -0
  26. package/src/cli/cmd/cmd.ts +7 -0
  27. package/src/cli/cmd/debug/config.ts +15 -0
  28. package/src/cli/cmd/debug/file.ts +91 -0
  29. package/src/cli/cmd/debug/index.ts +41 -0
  30. package/src/cli/cmd/debug/lsp.ts +47 -0
  31. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  32. package/src/cli/cmd/debug/scrap.ts +15 -0
  33. package/src/cli/cmd/debug/snapshot.ts +48 -0
  34. package/src/cli/cmd/export.ts +88 -0
  35. package/src/cli/cmd/generate.ts +38 -0
  36. package/src/cli/cmd/github.ts +1200 -0
  37. package/src/cli/cmd/import.ts +98 -0
  38. package/src/cli/cmd/mcp.ts +400 -0
  39. package/src/cli/cmd/models.ts +77 -0
  40. package/src/cli/cmd/pr.ts +112 -0
  41. package/src/cli/cmd/run.ts +342 -0
  42. package/src/cli/cmd/serve.ts +31 -0
  43. package/src/cli/cmd/session.ts +106 -0
  44. package/src/cli/cmd/stats.ts +298 -0
  45. package/src/cli/cmd/tui/app.tsx +732 -0
  46. package/src/cli/cmd/tui/attach.ts +25 -0
  47. package/src/cli/cmd/tui/component/border.tsx +21 -0
  48. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  49. package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
  50. package/src/cli/cmd/tui/component/dialog-feedback.tsx +160 -0
  51. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  52. package/src/cli/cmd/tui/component/dialog-model.tsx +223 -0
  53. package/src/cli/cmd/tui/component/dialog-notification.tsx +78 -0
  54. package/src/cli/cmd/tui/component/dialog-provider.tsx +222 -0
  55. package/src/cli/cmd/tui/component/dialog-session-list.tsx +97 -0
  56. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  57. package/src/cli/cmd/tui/component/dialog-status.tsx +114 -0
  58. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  59. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  60. package/src/cli/cmd/tui/component/logo.tsx +37 -0
  61. package/src/cli/cmd/tui/component/notification-banner.tsx +58 -0
  62. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +530 -0
  63. package/src/cli/cmd/tui/component/prompt/history.tsx +107 -0
  64. package/src/cli/cmd/tui/component/prompt/index.tsx +931 -0
  65. package/src/cli/cmd/tui/context/args.tsx +14 -0
  66. package/src/cli/cmd/tui/context/directory.ts +12 -0
  67. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  68. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  69. package/src/cli/cmd/tui/context/keybind.tsx +111 -0
  70. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  71. package/src/cli/cmd/tui/context/local.tsx +339 -0
  72. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  73. package/src/cli/cmd/tui/context/route.tsx +45 -0
  74. package/src/cli/cmd/tui/context/sdk.tsx +75 -0
  75. package/src/cli/cmd/tui/context/sync.tsx +374 -0
  76. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  77. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  78. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  79. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  80. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  81. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  82. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  83. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  84. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  85. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  86. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  87. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  88. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  89. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  90. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  91. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  92. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  93. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  94. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  95. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  96. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  97. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  98. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  99. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  100. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  101. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  102. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  103. package/src/cli/cmd/tui/context/theme.tsx +1077 -0
  104. package/src/cli/cmd/tui/event.ts +39 -0
  105. package/src/cli/cmd/tui/routes/home.tsx +104 -0
  106. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +93 -0
  107. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +37 -0
  108. package/src/cli/cmd/tui/routes/session/footer.tsx +76 -0
  109. package/src/cli/cmd/tui/routes/session/header.tsx +183 -0
  110. package/src/cli/cmd/tui/routes/session/index.tsx +1703 -0
  111. package/src/cli/cmd/tui/routes/session/sidebar.tsx +586 -0
  112. package/src/cli/cmd/tui/spawn.ts +60 -0
  113. package/src/cli/cmd/tui/thread.ts +120 -0
  114. package/src/cli/cmd/tui/ui/dialog-alert.tsx +55 -0
  115. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +81 -0
  116. package/src/cli/cmd/tui/ui/dialog-help.tsx +36 -0
  117. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +75 -0
  118. package/src/cli/cmd/tui/ui/dialog-select.tsx +317 -0
  119. package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
  120. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  121. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  122. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  123. package/src/cli/cmd/tui/util/editor.ts +32 -0
  124. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  125. package/src/cli/cmd/tui/worker.ts +63 -0
  126. package/src/cli/cmd/uninstall.ts +344 -0
  127. package/src/cli/cmd/upgrade.ts +67 -0
  128. package/src/cli/cmd/web.ts +84 -0
  129. package/src/cli/error.ts +55 -0
  130. package/src/cli/ui.ts +84 -0
  131. package/src/cli/upgrade.ts +25 -0
  132. package/src/command/index.ts +79 -0
  133. package/src/command/template/initialize.txt +10 -0
  134. package/src/command/template/review.txt +73 -0
  135. package/src/config/config.ts +886 -0
  136. package/src/config/markdown.ts +41 -0
  137. package/src/env/index.ts +26 -0
  138. package/src/file/fzf.ts +124 -0
  139. package/src/file/ignore.ts +83 -0
  140. package/src/file/index.ts +326 -0
  141. package/src/file/ripgrep.ts +391 -0
  142. package/src/file/time.ts +38 -0
  143. package/src/file/watcher.ts +89 -0
  144. package/src/flag/flag.ts +28 -0
  145. package/src/format/formatter.ts +277 -0
  146. package/src/format/index.ts +137 -0
  147. package/src/global/index.ts +52 -0
  148. package/src/id/id.ts +73 -0
  149. package/src/ide/index.ts +75 -0
  150. package/src/index.ts +158 -0
  151. package/src/installation/index.ts +194 -0
  152. package/src/lsp/client.ts +215 -0
  153. package/src/lsp/index.ts +370 -0
  154. package/src/lsp/language.ts +111 -0
  155. package/src/lsp/server.ts +1327 -0
  156. package/src/mcp/auth.ts +82 -0
  157. package/src/mcp/index.ts +576 -0
  158. package/src/mcp/oauth-callback.ts +203 -0
  159. package/src/mcp/oauth-provider.ts +132 -0
  160. package/src/notification/index.ts +101 -0
  161. package/src/patch/index.ts +622 -0
  162. package/src/permission/index.ts +198 -0
  163. package/src/plugin/index.ts +95 -0
  164. package/src/project/bootstrap.ts +31 -0
  165. package/src/project/instance.ts +68 -0
  166. package/src/project/project.ts +133 -0
  167. package/src/project/state.ts +65 -0
  168. package/src/project/vcs.ts +77 -0
  169. package/src/provider/auth.ts +143 -0
  170. package/src/provider/models-macro.ts +11 -0
  171. package/src/provider/models.ts +93 -0
  172. package/src/provider/provider.ts +996 -0
  173. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  174. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  175. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  176. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  177. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +27 -0
  178. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  179. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  180. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  181. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  182. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  183. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  184. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  185. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  186. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  187. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  188. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  189. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  190. package/src/provider/transform.ts +406 -0
  191. package/src/pty/index.ts +226 -0
  192. package/src/ratelimit/index.ts +185 -0
  193. package/src/server/error.ts +36 -0
  194. package/src/server/project.ts +50 -0
  195. package/src/server/server.ts +2463 -0
  196. package/src/server/tui.ts +71 -0
  197. package/src/session/compaction.ts +257 -0
  198. package/src/session/index.ts +470 -0
  199. package/src/session/message-v2.ts +641 -0
  200. package/src/session/message.ts +189 -0
  201. package/src/session/processor.ts +443 -0
  202. package/src/session/prompt/anthropic-20250930.txt +166 -0
  203. package/src/session/prompt/anthropic.txt +105 -0
  204. package/src/session/prompt/anthropic_spoof.txt +1 -0
  205. package/src/session/prompt/beast.txt +147 -0
  206. package/src/session/prompt/build-switch.txt +5 -0
  207. package/src/session/prompt/codex.txt +318 -0
  208. package/src/session/prompt/compaction.txt +12 -0
  209. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  210. package/src/session/prompt/gemini.txt +155 -0
  211. package/src/session/prompt/max-steps.txt +16 -0
  212. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  213. package/src/session/prompt/plan.txt +26 -0
  214. package/src/session/prompt/polaris.txt +107 -0
  215. package/src/session/prompt/qwen.txt +109 -0
  216. package/src/session/prompt/summarize.txt +4 -0
  217. package/src/session/prompt/title.txt +36 -0
  218. package/src/session/prompt.ts +1541 -0
  219. package/src/session/retry.ts +82 -0
  220. package/src/session/revert.ts +108 -0
  221. package/src/session/status.ts +75 -0
  222. package/src/session/summary.ts +203 -0
  223. package/src/session/system.ts +148 -0
  224. package/src/session/todo.ts +36 -0
  225. package/src/share/share-next.ts +195 -0
  226. package/src/share/share.ts +87 -0
  227. package/src/snapshot/index.ts +197 -0
  228. package/src/storage/storage.ts +226 -0
  229. package/src/telemetry/index.ts +232 -0
  230. package/src/tool/bash.ts +365 -0
  231. package/src/tool/bash.txt +128 -0
  232. package/src/tool/batch.ts +173 -0
  233. package/src/tool/batch.txt +28 -0
  234. package/src/tool/codesearch.ts +138 -0
  235. package/src/tool/codesearch.txt +12 -0
  236. package/src/tool/edit.ts +674 -0
  237. package/src/tool/edit.txt +10 -0
  238. package/src/tool/glob.ts +65 -0
  239. package/src/tool/glob.txt +6 -0
  240. package/src/tool/grep.ts +120 -0
  241. package/src/tool/grep.txt +8 -0
  242. package/src/tool/invalid.ts +17 -0
  243. package/src/tool/ls.ts +110 -0
  244. package/src/tool/ls.txt +1 -0
  245. package/src/tool/lsp-diagnostics.ts +26 -0
  246. package/src/tool/lsp-diagnostics.txt +1 -0
  247. package/src/tool/lsp-hover.ts +31 -0
  248. package/src/tool/lsp-hover.txt +1 -0
  249. package/src/tool/multiedit.ts +46 -0
  250. package/src/tool/multiedit.txt +41 -0
  251. package/src/tool/patch.ts +233 -0
  252. package/src/tool/patch.txt +1 -0
  253. package/src/tool/read.ts +217 -0
  254. package/src/tool/read.txt +12 -0
  255. package/src/tool/registry.ts +148 -0
  256. package/src/tool/task.ts +135 -0
  257. package/src/tool/task.txt +60 -0
  258. package/src/tool/todo.ts +39 -0
  259. package/src/tool/todoread.txt +14 -0
  260. package/src/tool/todowrite.txt +167 -0
  261. package/src/tool/tool.ts +66 -0
  262. package/src/tool/webfetch.ts +187 -0
  263. package/src/tool/webfetch.txt +14 -0
  264. package/src/tool/websearch.ts +150 -0
  265. package/src/tool/websearch.txt +11 -0
  266. package/src/tool/write.ts +99 -0
  267. package/src/tool/write.txt +8 -0
  268. package/src/types/shims.d.ts +3 -0
  269. package/src/util/color.ts +19 -0
  270. package/src/util/context.ts +25 -0
  271. package/src/util/defer.ts +12 -0
  272. package/src/util/eventloop.ts +20 -0
  273. package/src/util/filesystem.ts +69 -0
  274. package/src/util/fn.ts +11 -0
  275. package/src/util/iife.ts +3 -0
  276. package/src/util/keybind.ts +79 -0
  277. package/src/util/lazy.ts +11 -0
  278. package/src/util/locale.ts +81 -0
  279. package/src/util/lock.ts +98 -0
  280. package/src/util/log.ts +177 -0
  281. package/src/util/queue.ts +32 -0
  282. package/src/util/rpc.ts +42 -0
  283. package/src/util/scrap.ts +10 -0
  284. package/src/util/signal.ts +12 -0
  285. package/src/util/timeout.ts +14 -0
  286. package/src/util/token.ts +7 -0
  287. package/src/util/wildcard.ts +54 -0
  288. package/sst-env.d.ts +9 -0
  289. package/test/bun.test.ts +53 -0
  290. package/test/config/agent-color.test.ts +66 -0
  291. package/test/config/config.test.ts +503 -0
  292. package/test/config/markdown.test.ts +89 -0
  293. package/test/file/ignore.test.ts +10 -0
  294. package/test/fixture/fixture.ts +28 -0
  295. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  296. package/test/ide/ide.test.ts +82 -0
  297. package/test/keybind.test.ts +317 -0
  298. package/test/lsp/client.test.ts +95 -0
  299. package/test/patch/patch.test.ts +348 -0
  300. package/test/preload.ts +38 -0
  301. package/test/project/project.test.ts +42 -0
  302. package/test/provider/provider.test.ts +1809 -0
  303. package/test/provider/transform.test.ts +305 -0
  304. package/test/session/retry.test.ts +61 -0
  305. package/test/session/session.test.ts +71 -0
  306. package/test/snapshot/snapshot.test.ts +939 -0
  307. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  308. package/test/tool/bash.test.ts +55 -0
  309. package/test/tool/patch.test.ts +259 -0
  310. package/test/util/iife.test.ts +36 -0
  311. package/test/util/lazy.test.ts +50 -0
  312. package/test/util/timeout.test.ts +21 -0
  313. package/test/util/wildcard.test.ts +55 -0
  314. package/tsconfig.json +17 -0
@@ -0,0 +1,931 @@
1
+ import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, t, dim, fg, type KeyBinding } from "@opentui/core"
2
+ import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, Show, Switch, Match } from "solid-js"
3
+ import "opentui-spinner/solid"
4
+ import { useLocal } from "@tui/context/local"
5
+ import { useTheme } from "@tui/context/theme"
6
+ import { EmptyBorder } from "@tui/component/border"
7
+ import { useSDK } from "@tui/context/sdk"
8
+ import { useRoute } from "@tui/context/route"
9
+ import { useSync } from "@tui/context/sync"
10
+ import { Identifier } from "@/id/id"
11
+ import { createStore, produce } from "solid-js/store"
12
+ import { useKeybind } from "@tui/context/keybind"
13
+ import { usePromptHistory, type PromptInfo } from "./history"
14
+ import { type AutocompleteRef, Autocomplete } from "./autocomplete"
15
+ import { useCommandDialog } from "../dialog-command"
16
+ import { useRenderer } from "@opentui/solid"
17
+ import { Editor } from "@tui/util/editor"
18
+ import { useExit } from "../../context/exit"
19
+ import { Clipboard } from "../../util/clipboard"
20
+ import type { FilePart } from "@opencode-ai/sdk/v2"
21
+ import { TuiEvent } from "../../event"
22
+ import { iife } from "@/util/iife"
23
+ import { Locale } from "@/util/locale"
24
+ import { createColors, createFrames } from "../../ui/spinner.ts"
25
+ import { useDialog } from "@tui/ui/dialog"
26
+ import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
27
+ import { useToast } from "../../ui/toast"
28
+
29
+ export type PromptProps = {
30
+ sessionID?: string
31
+ disabled?: boolean
32
+ onSubmit?: () => void
33
+ ref?: (ref: PromptRef) => void
34
+ hint?: JSX.Element
35
+ showPlaceholder?: boolean
36
+ }
37
+
38
+ export type PromptRef = {
39
+ focused: boolean
40
+ current: PromptInfo
41
+ set(prompt: PromptInfo): void
42
+ reset(): void
43
+ blur(): void
44
+ focus(): void
45
+ }
46
+
47
+ const PLACEHOLDERS = ["Fix a TODO in the codebase", "What is the tech stack of this project?", "Fix broken tests"]
48
+
49
+ export function Prompt(props: PromptProps) {
50
+ let input: TextareaRenderable
51
+ let anchor: BoxRenderable
52
+ let autocomplete: AutocompleteRef
53
+
54
+ const keybind = useKeybind()
55
+ const local = useLocal()
56
+ const sdk = useSDK()
57
+ const route = useRoute()
58
+ const sync = useSync()
59
+ const dialog = useDialog()
60
+ const toast = useToast()
61
+ const status = createMemo(() => sync.data.session_status[props.sessionID ?? ""] ?? { type: "idle" })
62
+ const history = usePromptHistory()
63
+ const command = useCommandDialog()
64
+ const renderer = useRenderer()
65
+ const { theme, syntax } = useTheme()
66
+
67
+ function promptModelWarning() {
68
+ toast.show({
69
+ variant: "warning",
70
+ message: "Connect a provider to send prompts",
71
+ duration: 3000,
72
+ })
73
+ if (sync.data.provider.length === 0) {
74
+ dialog.replace(() => <DialogProviderConnect />)
75
+ }
76
+ }
77
+
78
+ const textareaKeybindings = createMemo(() => {
79
+ const newlineBindings = keybind.all.input_newline || []
80
+ const submitBindings = keybind.all.input_submit || []
81
+
82
+ return [
83
+ { name: "return", action: "submit" },
84
+ { name: "return", meta: true, action: "newline" },
85
+ ...newlineBindings.map((binding) => ({
86
+ name: binding.name,
87
+ ctrl: binding.ctrl || undefined,
88
+ meta: binding.meta || undefined,
89
+ shift: binding.shift || undefined,
90
+ action: "newline" as const,
91
+ })),
92
+ ...submitBindings.map((binding) => ({
93
+ name: binding.name,
94
+ ctrl: binding.ctrl || undefined,
95
+ meta: binding.meta || undefined,
96
+ shift: binding.shift || undefined,
97
+ action: "submit" as const,
98
+ })),
99
+ ] satisfies KeyBinding[]
100
+ })
101
+
102
+ const fileStyleId = syntax().getStyleId("extmark.file")!
103
+ const agentStyleId = syntax().getStyleId("extmark.agent")!
104
+ const pasteStyleId = syntax().getStyleId("extmark.paste")!
105
+ let promptPartTypeId: number
106
+
107
+ command.register(() => {
108
+ return [
109
+ {
110
+ title: "Clear prompt",
111
+ value: "prompt.clear",
112
+ category: "Prompt",
113
+ disabled: true,
114
+ onSelect: (dialog) => {
115
+ input.extmarks.clear()
116
+ input.clear()
117
+ dialog.clear()
118
+ },
119
+ },
120
+ {
121
+ title: "Submit prompt",
122
+ value: "prompt.submit",
123
+ disabled: true,
124
+ keybind: "input_submit",
125
+ category: "Prompt",
126
+ onSelect: (dialog) => {
127
+ if (!input.focused) return
128
+ submit()
129
+ dialog.clear()
130
+ },
131
+ },
132
+ {
133
+ title: "Paste",
134
+ value: "prompt.paste",
135
+ disabled: true,
136
+ keybind: "input_paste",
137
+ category: "Prompt",
138
+ onSelect: async () => {
139
+ const content = await Clipboard.read()
140
+ if (content?.mime.startsWith("image/")) {
141
+ await pasteImage({
142
+ filename: "clipboard",
143
+ mime: content.mime,
144
+ content: content.data,
145
+ })
146
+ }
147
+ },
148
+ },
149
+ {
150
+ title: "Interrupt session",
151
+ value: "session.interrupt",
152
+ keybind: "session_interrupt",
153
+ disabled: status().type === "idle",
154
+ category: "Session",
155
+ onSelect: (dialog) => {
156
+ if (autocomplete.visible) return
157
+ if (!input.focused) return
158
+ // TODO: this should be its own command
159
+ if (store.mode === "shell") {
160
+ setStore("mode", "normal")
161
+ return
162
+ }
163
+ if (!props.sessionID) return
164
+
165
+ setStore("interrupt", store.interrupt + 1)
166
+
167
+ setTimeout(() => {
168
+ setStore("interrupt", 0)
169
+ }, 5000)
170
+
171
+ if (store.interrupt >= 2) {
172
+ sdk.client.session.abort({
173
+ sessionID: props.sessionID,
174
+ })
175
+ setStore("interrupt", 0)
176
+ }
177
+ dialog.clear()
178
+ },
179
+ },
180
+ {
181
+ title: "Open editor",
182
+ category: "Session",
183
+ keybind: "editor_open",
184
+ value: "prompt.editor",
185
+ onSelect: async (dialog, trigger) => {
186
+ dialog.clear()
187
+
188
+ // replace summarized text parts with the actual text
189
+ const text = store.prompt.parts
190
+ .filter((p) => p.type === "text")
191
+ .reduce((acc, p) => {
192
+ if (!p.source) return acc
193
+ return acc.replace(p.source.text.value, p.text)
194
+ }, store.prompt.input)
195
+
196
+ const nonTextParts = store.prompt.parts.filter((p) => p.type !== "text")
197
+
198
+ const value = trigger === "prompt" ? "" : text
199
+ const content = await Editor.open({ value, renderer })
200
+ if (!content) return
201
+
202
+ input.setText(content, { history: false })
203
+
204
+ // Update positions for nonTextParts based on their location in new content
205
+ // Filter out parts whose virtual text was deleted
206
+ // this handles a case where the user edits the text in the editor
207
+ // such that the virtual text moves around or is deleted
208
+ const updatedNonTextParts = nonTextParts
209
+ .map((part) => {
210
+ let virtualText = ""
211
+ if (part.type === "file" && part.source?.text) {
212
+ virtualText = part.source.text.value
213
+ } else if (part.type === "agent" && part.source) {
214
+ virtualText = part.source.value
215
+ }
216
+
217
+ if (!virtualText) return part
218
+
219
+ const newStart = content.indexOf(virtualText)
220
+ // if the virtual text is deleted, remove the part
221
+ if (newStart === -1) return null
222
+
223
+ const newEnd = newStart + virtualText.length
224
+
225
+ if (part.type === "file" && part.source?.text) {
226
+ return {
227
+ ...part,
228
+ source: {
229
+ ...part.source,
230
+ text: {
231
+ ...part.source.text,
232
+ start: newStart,
233
+ end: newEnd,
234
+ },
235
+ },
236
+ }
237
+ }
238
+
239
+ if (part.type === "agent" && part.source) {
240
+ return {
241
+ ...part,
242
+ source: {
243
+ ...part.source,
244
+ start: newStart,
245
+ end: newEnd,
246
+ },
247
+ }
248
+ }
249
+
250
+ return part
251
+ })
252
+ .filter((part) => part !== null)
253
+
254
+ setStore("prompt", {
255
+ input: content,
256
+ // keep only the non-text parts because the text parts were
257
+ // already expanded inline
258
+ parts: updatedNonTextParts,
259
+ })
260
+ restoreExtmarksFromParts(updatedNonTextParts)
261
+ input.cursorOffset = Bun.stringWidth(content)
262
+ },
263
+ },
264
+ ]
265
+ })
266
+
267
+ sdk.event.on(TuiEvent.PromptAppend.type, (evt) => {
268
+ input.insertText(evt.properties.text)
269
+ })
270
+
271
+ createEffect(() => {
272
+ if (props.disabled) input.cursorColor = theme.backgroundElement
273
+ if (!props.disabled) input.cursorColor = theme.text
274
+ })
275
+
276
+ const [store, setStore] = createStore<{
277
+ prompt: PromptInfo
278
+ mode: "normal" | "shell"
279
+ extmarkToPartIndex: Map<number, number>
280
+ interrupt: number
281
+ placeholder: number
282
+ }>({
283
+ placeholder: Math.floor(Math.random() * PLACEHOLDERS.length),
284
+ prompt: {
285
+ input: "",
286
+ parts: [],
287
+ },
288
+ mode: "normal",
289
+ extmarkToPartIndex: new Map(),
290
+ interrupt: 0,
291
+ })
292
+
293
+ createEffect(() => {
294
+ input.focus()
295
+ })
296
+
297
+ onMount(() => {
298
+ promptPartTypeId = input.extmarks.registerType("prompt-part")
299
+ })
300
+
301
+ function restoreExtmarksFromParts(parts: PromptInfo["parts"]) {
302
+ input.extmarks.clear()
303
+ setStore("extmarkToPartIndex", new Map())
304
+
305
+ parts.forEach((part, partIndex) => {
306
+ let start = 0
307
+ let end = 0
308
+ let virtualText = ""
309
+ let styleId: number | undefined
310
+
311
+ if (part.type === "file" && part.source?.text) {
312
+ start = part.source.text.start
313
+ end = part.source.text.end
314
+ virtualText = part.source.text.value
315
+ styleId = fileStyleId
316
+ } else if (part.type === "agent" && part.source) {
317
+ start = part.source.start
318
+ end = part.source.end
319
+ virtualText = part.source.value
320
+ styleId = agentStyleId
321
+ } else if (part.type === "text" && part.source?.text) {
322
+ start = part.source.text.start
323
+ end = part.source.text.end
324
+ virtualText = part.source.text.value
325
+ styleId = pasteStyleId
326
+ }
327
+
328
+ if (virtualText) {
329
+ const extmarkId = input.extmarks.create({
330
+ start,
331
+ end,
332
+ virtual: true,
333
+ styleId,
334
+ typeId: promptPartTypeId,
335
+ })
336
+ setStore("extmarkToPartIndex", (map: Map<number, number>) => {
337
+ const newMap = new Map(map)
338
+ newMap.set(extmarkId, partIndex)
339
+ return newMap
340
+ })
341
+ }
342
+ })
343
+ }
344
+
345
+ function syncExtmarksWithPromptParts() {
346
+ const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
347
+ setStore(
348
+ produce((draft) => {
349
+ const newMap = new Map<number, number>()
350
+ const newParts: typeof draft.prompt.parts = []
351
+
352
+ for (const extmark of allExtmarks) {
353
+ const partIndex = draft.extmarkToPartIndex.get(extmark.id)
354
+ if (partIndex !== undefined) {
355
+ const part = draft.prompt.parts[partIndex]
356
+ if (part) {
357
+ if (part.type === "agent" && part.source) {
358
+ part.source.start = extmark.start
359
+ part.source.end = extmark.end
360
+ } else if (part.type === "file" && part.source?.text) {
361
+ part.source.text.start = extmark.start
362
+ part.source.text.end = extmark.end
363
+ } else if (part.type === "text" && part.source?.text) {
364
+ part.source.text.start = extmark.start
365
+ part.source.text.end = extmark.end
366
+ }
367
+ newMap.set(extmark.id, newParts.length)
368
+ newParts.push(part)
369
+ }
370
+ }
371
+ }
372
+
373
+ draft.extmarkToPartIndex = newMap
374
+ draft.prompt.parts = newParts
375
+ }),
376
+ )
377
+ }
378
+
379
+ props.ref?.({
380
+ get focused() {
381
+ return input.focused
382
+ },
383
+ get current() {
384
+ return store.prompt
385
+ },
386
+ focus() {
387
+ input.focus()
388
+ },
389
+ blur() {
390
+ input.blur()
391
+ },
392
+ set(prompt) {
393
+ input.setText(prompt.input, { history: false })
394
+ setStore("prompt", prompt)
395
+ restoreExtmarksFromParts(prompt.parts)
396
+ input.gotoBufferEnd()
397
+ },
398
+ reset() {
399
+ input.clear()
400
+ input.extmarks.clear()
401
+ setStore("prompt", {
402
+ input: "",
403
+ parts: [],
404
+ })
405
+ setStore("extmarkToPartIndex", new Map())
406
+ },
407
+ })
408
+
409
+ async function submit() {
410
+ if (props.disabled) return
411
+ if (autocomplete.visible) return
412
+ if (!store.prompt.input) return
413
+ const selectedModel = local.model.current()
414
+ if (!selectedModel) {
415
+ promptModelWarning()
416
+ return
417
+ }
418
+ const sessionID = props.sessionID
419
+ ? props.sessionID
420
+ : await (async () => {
421
+ const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
422
+ return sessionID
423
+ })()
424
+ const messageID = Identifier.ascending("message")
425
+ let inputText = store.prompt.input
426
+
427
+ // Expand pasted text inline before submitting
428
+ const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
429
+ const sortedExtmarks = allExtmarks.sort((a: { start: number }, b: { start: number }) => b.start - a.start)
430
+
431
+ for (const extmark of sortedExtmarks) {
432
+ const partIndex = store.extmarkToPartIndex.get(extmark.id)
433
+ if (partIndex !== undefined) {
434
+ const part = store.prompt.parts[partIndex]
435
+ if (part?.type === "text" && part.text) {
436
+ const before = inputText.slice(0, extmark.start)
437
+ const after = inputText.slice(extmark.end)
438
+ inputText = before + part.text + after
439
+ }
440
+ }
441
+ }
442
+
443
+ // Filter out text parts (pasted content) since they're now expanded inline
444
+ const nonTextParts = store.prompt.parts.filter((part) => part.type !== "text")
445
+
446
+ if (store.mode === "shell") {
447
+ sdk.client.session.shell({
448
+ sessionID,
449
+ agent: local.agent.current().name,
450
+ model: {
451
+ providerID: selectedModel.providerID,
452
+ modelID: selectedModel.modelID,
453
+ },
454
+ command: inputText,
455
+ })
456
+ setStore("mode", "normal")
457
+ } else if (
458
+ inputText.startsWith("/") &&
459
+ iife(() => {
460
+ const command = inputText.split(" ")[0].slice(1)
461
+ console.log(command)
462
+ return sync.data.command.some((x) => x.name === command)
463
+ })
464
+ ) {
465
+ let [command, ...args] = inputText.split(" ")
466
+ sdk.client.session.command({
467
+ sessionID,
468
+ command: command.slice(1),
469
+ arguments: args.join(" "),
470
+ agent: local.agent.current().name,
471
+ model: `${selectedModel.providerID}/${selectedModel.modelID}`,
472
+ messageID,
473
+ })
474
+ } else {
475
+ sdk.client.session.prompt({
476
+ sessionID,
477
+ ...selectedModel,
478
+ messageID,
479
+ agent: local.agent.current().name,
480
+ model: selectedModel,
481
+ parts: [
482
+ {
483
+ id: Identifier.ascending("part"),
484
+ type: "text",
485
+ text: inputText,
486
+ },
487
+ ...nonTextParts.map((x) => ({
488
+ id: Identifier.ascending("part"),
489
+ ...x,
490
+ })),
491
+ ],
492
+ })
493
+ }
494
+ history.append(store.prompt)
495
+ input.extmarks.clear()
496
+ setStore("prompt", {
497
+ input: "",
498
+ parts: [],
499
+ })
500
+ setStore("extmarkToPartIndex", new Map())
501
+ props.onSubmit?.()
502
+
503
+ // temporary hack to make sure the message is sent
504
+ if (!props.sessionID)
505
+ setTimeout(() => {
506
+ route.navigate({
507
+ type: "session",
508
+ sessionID,
509
+ })
510
+ }, 50)
511
+ input.clear()
512
+ }
513
+ const exit = useExit()
514
+
515
+ function pasteText(text: string, virtualText: string) {
516
+ const currentOffset = input.visualCursor.offset
517
+ const extmarkStart = currentOffset
518
+ const extmarkEnd = extmarkStart + virtualText.length
519
+
520
+ input.insertText(virtualText + " ")
521
+
522
+ const extmarkId = input.extmarks.create({
523
+ start: extmarkStart,
524
+ end: extmarkEnd,
525
+ virtual: true,
526
+ styleId: pasteStyleId,
527
+ typeId: promptPartTypeId,
528
+ })
529
+
530
+ setStore(
531
+ produce((draft) => {
532
+ const partIndex = draft.prompt.parts.length
533
+ draft.prompt.parts.push({
534
+ type: "text" as const,
535
+ text,
536
+ source: {
537
+ text: {
538
+ start: extmarkStart,
539
+ end: extmarkEnd,
540
+ value: virtualText,
541
+ },
542
+ },
543
+ })
544
+ draft.extmarkToPartIndex.set(extmarkId, partIndex)
545
+ }),
546
+ )
547
+ }
548
+
549
+ async function pasteImage(file: { filename?: string; content: string; mime: string }) {
550
+ const currentOffset = input.visualCursor.offset
551
+ const extmarkStart = currentOffset
552
+ const count = store.prompt.parts.filter((x) => x.type === "file").length
553
+ const virtualText = `[Image ${count + 1}]`
554
+ const extmarkEnd = extmarkStart + virtualText.length
555
+ const textToInsert = virtualText + " "
556
+
557
+ input.insertText(textToInsert)
558
+
559
+ const extmarkId = input.extmarks.create({
560
+ start: extmarkStart,
561
+ end: extmarkEnd,
562
+ virtual: true,
563
+ styleId: pasteStyleId,
564
+ typeId: promptPartTypeId,
565
+ })
566
+
567
+ const part: Omit<FilePart, "id" | "messageID" | "sessionID"> = {
568
+ type: "file" as const,
569
+ mime: file.mime,
570
+ filename: file.filename,
571
+ url: `data:${file.mime};base64,${file.content}`,
572
+ source: {
573
+ type: "file",
574
+ path: file.filename ?? "",
575
+ text: {
576
+ start: extmarkStart,
577
+ end: extmarkEnd,
578
+ value: virtualText,
579
+ },
580
+ },
581
+ }
582
+ setStore(
583
+ produce((draft) => {
584
+ const partIndex = draft.prompt.parts.length
585
+ draft.prompt.parts.push(part)
586
+ draft.extmarkToPartIndex.set(extmarkId, partIndex)
587
+ }),
588
+ )
589
+ return
590
+ }
591
+
592
+ const highlight = createMemo(() => {
593
+ if (keybind.leader) return theme.border
594
+ if (store.mode === "shell") return theme.primary
595
+ return local.agent.color(local.agent.current().name)
596
+ })
597
+
598
+ const spinnerDef = createMemo(() => {
599
+ const color = local.agent.color(local.agent.current().name)
600
+ return {
601
+ frames: createFrames({
602
+ color,
603
+ style: "blocks",
604
+ inactiveFactor: 0.6,
605
+ // enableFading: false,
606
+ minAlpha: 0.3,
607
+ }),
608
+ color: createColors({
609
+ color,
610
+ style: "blocks",
611
+ inactiveFactor: 0.6,
612
+ // enableFading: false,
613
+ minAlpha: 0.3,
614
+ }),
615
+ }
616
+ })
617
+
618
+ return (
619
+ <>
620
+ <Autocomplete
621
+ sessionID={props.sessionID}
622
+ ref={(r) => (autocomplete = r)}
623
+ anchor={() => anchor}
624
+ input={() => input}
625
+ setPrompt={(cb) => {
626
+ setStore("prompt", produce(cb))
627
+ }}
628
+ setExtmark={(partIndex, extmarkId) => {
629
+ setStore("extmarkToPartIndex", (map: Map<number, number>) => {
630
+ const newMap = new Map(map)
631
+ newMap.set(extmarkId, partIndex)
632
+ return newMap
633
+ })
634
+ }}
635
+ value={store.prompt.input}
636
+ fileStyleId={fileStyleId}
637
+ agentStyleId={agentStyleId}
638
+ promptPartTypeId={() => promptPartTypeId}
639
+ />
640
+ <box ref={(r) => (anchor = r)}>
641
+ <box
642
+ border={["left"]}
643
+ borderColor={highlight()}
644
+ customBorderChars={{
645
+ ...EmptyBorder,
646
+ vertical: "┃",
647
+ bottomLeft: "╹",
648
+ }}
649
+ >
650
+ <box
651
+ paddingLeft={2}
652
+ paddingRight={1}
653
+ paddingTop={1}
654
+ flexShrink={0}
655
+ backgroundColor={theme.backgroundElement}
656
+ flexGrow={1}
657
+ >
658
+ <textarea
659
+ placeholder={props.sessionID ? undefined : `Ask anything... "${PLACEHOLDERS[store.placeholder]}"`}
660
+ textColor={theme.text}
661
+ focusedTextColor={theme.text}
662
+ minHeight={1}
663
+ maxHeight={6}
664
+ onContentChange={() => {
665
+ const value = input.plainText
666
+ setStore("prompt", "input", value)
667
+ autocomplete.onInput(value)
668
+ syncExtmarksWithPromptParts()
669
+ }}
670
+ keyBindings={textareaKeybindings()}
671
+ onKeyDown={async (e) => {
672
+ if (props.disabled) {
673
+ e.preventDefault()
674
+ return
675
+ }
676
+ if (keybind.match("input_clear", e) && store.prompt.input !== "") {
677
+ input.clear()
678
+ input.extmarks.clear()
679
+ setStore("prompt", {
680
+ input: "",
681
+ parts: [],
682
+ })
683
+ setStore("extmarkToPartIndex", new Map())
684
+ return
685
+ }
686
+ if (keybind.match("input_forward_delete", e) && store.prompt.input !== "") {
687
+ const cursorOffset = input.cursorOffset
688
+ if (cursorOffset < input.plainText.length) {
689
+ const text = input.plainText
690
+ const newText = text.slice(0, cursorOffset) + text.slice(cursorOffset + 1)
691
+ input.setText(newText)
692
+ input.cursorOffset = cursorOffset
693
+ }
694
+ e.preventDefault()
695
+ return
696
+ }
697
+ if (keybind.match("app_exit", e)) {
698
+ await exit()
699
+ return
700
+ }
701
+ if (e.name === "!" && input.visualCursor.offset === 0) {
702
+ setStore("mode", "shell")
703
+ e.preventDefault()
704
+ return
705
+ }
706
+ if (store.mode === "shell") {
707
+ if ((e.name === "backspace" && input.visualCursor.offset === 0) || e.name === "escape") {
708
+ setStore("mode", "normal")
709
+ e.preventDefault()
710
+ return
711
+ }
712
+ }
713
+ if (store.mode === "normal") autocomplete.onKeyDown(e)
714
+ if (!autocomplete.visible) {
715
+ if (
716
+ (keybind.match("history_previous", e) && input.cursorOffset === 0) ||
717
+ (keybind.match("history_next", e) && input.cursorOffset === input.plainText.length)
718
+ ) {
719
+ const direction = keybind.match("history_previous", e) ? -1 : 1
720
+ const item = history.move(direction, input.plainText)
721
+
722
+ if (item) {
723
+ input.setText(item.input, { history: false })
724
+ setStore("prompt", item)
725
+ restoreExtmarksFromParts(item.parts)
726
+ e.preventDefault()
727
+ if (direction === -1) input.cursorOffset = 0
728
+ if (direction === 1) input.cursorOffset = input.plainText.length
729
+ }
730
+ return
731
+ }
732
+
733
+ if (keybind.match("history_previous", e) && input.visualCursor.visualRow === 0) input.cursorOffset = 0
734
+ if (keybind.match("history_next", e) && input.visualCursor.visualRow === input.height - 1)
735
+ input.cursorOffset = input.plainText.length
736
+ }
737
+ }}
738
+ onSubmit={submit}
739
+ onPaste={async (event: PasteEvent) => {
740
+ if (props.disabled) {
741
+ event.preventDefault()
742
+ return
743
+ }
744
+
745
+ // Normalize line endings at the boundary
746
+ // Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste
747
+ // Replace CRLF first, then any remaining CR
748
+ const normalizedText = event.text.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
749
+ const pastedContent = normalizedText.trim()
750
+ if (!pastedContent) {
751
+ command.trigger("prompt.paste")
752
+ return
753
+ }
754
+
755
+ // trim ' from the beginning and end of the pasted content. just
756
+ // ' and nothing else
757
+ const filepath = pastedContent.replace(/^'+|'+$/g, "").replace(/\\ /g, " ")
758
+ const isUrl = /^(https?):\/\//.test(filepath)
759
+ if (!isUrl) {
760
+ try {
761
+ const file = Bun.file(filepath)
762
+ // Handle SVG as raw text content, not as base64 image
763
+ if (file.type === "image/svg+xml") {
764
+ event.preventDefault()
765
+ const content = await file.text().catch(() => {})
766
+ if (content) {
767
+ pasteText(content, `[SVG: ${file.name ?? "image"}]`)
768
+ return
769
+ }
770
+ }
771
+ if (file.type.startsWith("image/")) {
772
+ event.preventDefault()
773
+ const content = await file
774
+ .arrayBuffer()
775
+ .then((buffer) => Buffer.from(buffer).toString("base64"))
776
+ .catch(() => {})
777
+ if (content) {
778
+ await pasteImage({
779
+ filename: file.name,
780
+ mime: file.type,
781
+ content,
782
+ })
783
+ return
784
+ }
785
+ }
786
+ } catch {}
787
+ }
788
+
789
+ const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
790
+ if (
791
+ (lineCount >= 3 || pastedContent.length > 150) &&
792
+ !sync.data.config.experimental?.disable_paste_summary
793
+ ) {
794
+ event.preventDefault()
795
+ pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
796
+ return
797
+ }
798
+ }}
799
+ ref={(r: TextareaRenderable) => {
800
+ input = r
801
+ setTimeout(() => {
802
+ input.cursorColor = theme.text
803
+ }, 0)
804
+ }}
805
+ onMouseDown={(r: MouseEvent) => r.target?.focus()}
806
+ focusedBackgroundColor={theme.backgroundElement}
807
+ cursorColor={theme.text}
808
+ syntaxStyle={syntax()}
809
+ />
810
+ <box flexDirection="row" flexShrink={0} paddingTop={1} gap={1}>
811
+ <text fg={highlight()}>
812
+ {store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "}
813
+ </text>
814
+ <Show when={store.mode === "normal"}>
815
+ <box flexDirection="row" gap={1}>
816
+ <text fg={theme.textMuted}>{local.model.parsed().provider}</text>
817
+ <text flexShrink={0} fg={theme.text}>
818
+ {local.model.parsed().model}
819
+ </text>
820
+ </box>
821
+ </Show>
822
+ </box>
823
+ </box>
824
+ </box>
825
+ <box
826
+ height={1}
827
+ border={["left"]}
828
+ borderColor={highlight()}
829
+ customBorderChars={{
830
+ ...EmptyBorder,
831
+ // when the background is transparent, don't draw the vertical line
832
+ vertical: theme.background.a != 0 ? "╹" : " ",
833
+ }}
834
+ >
835
+ <box
836
+ height={1}
837
+ border={["bottom"]}
838
+ borderColor={theme.backgroundElement}
839
+ customBorderChars={
840
+ theme.background.a != 0
841
+ ? {
842
+ ...EmptyBorder,
843
+ horizontal: "▀",
844
+ }
845
+ : {
846
+ ...EmptyBorder,
847
+ horizontal: " ",
848
+ }
849
+ }
850
+ />
851
+ </box>
852
+ <box flexDirection="row" justifyContent="space-between">
853
+ <Show when={status().type !== "idle"} fallback={<text />}>
854
+ <box
855
+ flexDirection="row"
856
+ gap={1}
857
+ flexGrow={1}
858
+ justifyContent={status().type === "retry" ? "space-between" : "flex-start"}
859
+ >
860
+ <box flexShrink={0} flexDirection="row" gap={1}>
861
+ {/* @ts-ignore // SpinnerOptions doesn't support marginLeft */}
862
+ <spinner marginLeft={1} color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
863
+ <box flexDirection="row" gap={1} flexShrink={0}>
864
+ {(() => {
865
+ const retry = createMemo(() => {
866
+ const s = status()
867
+ if (s.type !== "retry") return
868
+ return s
869
+ })
870
+ const message = createMemo(() => {
871
+ const r = retry()
872
+ if (!r) return
873
+ if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
874
+ return "gemini is way too hot right now"
875
+ if (r.message.length > 50) return r.message.slice(0, 50) + "..."
876
+ return r.message
877
+ })
878
+ const [seconds, setSeconds] = createSignal(0)
879
+ onMount(() => {
880
+ const timer = setInterval(() => {
881
+ const next = retry()?.next
882
+ if (next) setSeconds(Math.round((next - Date.now()) / 1000))
883
+ }, 1000)
884
+
885
+ onCleanup(() => {
886
+ clearInterval(timer)
887
+ })
888
+ })
889
+ return (
890
+ <Show when={retry()}>
891
+ <text fg={theme.error}>
892
+ {message()} [retrying {seconds() > 0 ? `in ${seconds()}s ` : ""}
893
+ attempt #{retry()!.attempt}]
894
+ </text>
895
+ </Show>
896
+ )
897
+ })()}
898
+ </box>
899
+ </box>
900
+ <text fg={store.interrupt > 0 ? theme.primary : theme.text}>
901
+ esc{" "}
902
+ <span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
903
+ {store.interrupt > 0 ? "again to interrupt" : "interrupt"}
904
+ </span>
905
+ </text>
906
+ </box>
907
+ </Show>
908
+ <Show when={status().type !== "retry"}>
909
+ <box gap={2} flexDirection="row">
910
+ <Switch>
911
+ <Match when={store.mode === "normal"}>
912
+ <text fg={theme.text}>
913
+ {keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>switch agent</span>
914
+ </text>
915
+ <text fg={theme.text}>
916
+ {keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
917
+ </text>
918
+ </Match>
919
+ <Match when={store.mode === "shell"}>
920
+ <text fg={theme.text}>
921
+ esc <span style={{ fg: theme.textMuted }}>exit shell mode</span>
922
+ </text>
923
+ </Match>
924
+ </Switch>
925
+ </box>
926
+ </Show>
927
+ </box>
928
+ </box>
929
+ </>
930
+ )
931
+ }