bincode-cli 1.0.1

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