rird 1.0.200

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