nuwaxcode 1.1.25

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