nuwaxcode 1.1.34 → 1.1.45

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 (398) hide show
  1. package/bin/nuwaxcode +19 -1
  2. package/package.json +15 -117
  3. package/{script/postinstall.mjs → postinstall.mjs} +18 -6
  4. package/AGENTS.md +0 -27
  5. package/Dockerfile +0 -18
  6. package/README.md +0 -15
  7. package/bunfig.toml +0 -7
  8. package/parsers-config.ts +0 -253
  9. package/script/build.ts +0 -172
  10. package/script/publish-registries.ts +0 -187
  11. package/script/publish.ts +0 -70
  12. package/script/schema.ts +0 -47
  13. package/src/acp/README.md +0 -164
  14. package/src/acp/agent.ts +0 -1280
  15. package/src/acp/session.ts +0 -111
  16. package/src/acp/types.ts +0 -24
  17. package/src/agent/agent.ts +0 -332
  18. package/src/agent/generate.txt +0 -75
  19. package/src/agent/prompt/compaction.txt +0 -12
  20. package/src/agent/prompt/explore.txt +0 -18
  21. package/src/agent/prompt/summary.txt +0 -11
  22. package/src/agent/prompt/title.txt +0 -43
  23. package/src/auth/index.ts +0 -73
  24. package/src/bun/index.ts +0 -134
  25. package/src/bus/bus-event.ts +0 -43
  26. package/src/bus/global.ts +0 -10
  27. package/src/bus/index.ts +0 -105
  28. package/src/cli/bootstrap.ts +0 -17
  29. package/src/cli/cmd/acp.ts +0 -69
  30. package/src/cli/cmd/agent.ts +0 -257
  31. package/src/cli/cmd/auth.ts +0 -400
  32. package/src/cli/cmd/cmd.ts +0 -7
  33. package/src/cli/cmd/debug/agent.ts +0 -166
  34. package/src/cli/cmd/debug/config.ts +0 -16
  35. package/src/cli/cmd/debug/file.ts +0 -97
  36. package/src/cli/cmd/debug/index.ts +0 -48
  37. package/src/cli/cmd/debug/lsp.ts +0 -52
  38. package/src/cli/cmd/debug/ripgrep.ts +0 -87
  39. package/src/cli/cmd/debug/scrap.ts +0 -16
  40. package/src/cli/cmd/debug/skill.ts +0 -16
  41. package/src/cli/cmd/debug/snapshot.ts +0 -52
  42. package/src/cli/cmd/export.ts +0 -88
  43. package/src/cli/cmd/generate.ts +0 -38
  44. package/src/cli/cmd/github.ts +0 -1548
  45. package/src/cli/cmd/import.ts +0 -98
  46. package/src/cli/cmd/mcp.ts +0 -755
  47. package/src/cli/cmd/models.ts +0 -77
  48. package/src/cli/cmd/pr.ts +0 -112
  49. package/src/cli/cmd/run.ts +0 -395
  50. package/src/cli/cmd/serve.ts +0 -20
  51. package/src/cli/cmd/session.ts +0 -135
  52. package/src/cli/cmd/stats.ts +0 -402
  53. package/src/cli/cmd/tui/app.tsx +0 -761
  54. package/src/cli/cmd/tui/attach.ts +0 -31
  55. package/src/cli/cmd/tui/component/border.tsx +0 -21
  56. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  57. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
  58. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  59. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -234
  60. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -256
  61. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -114
  62. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  63. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -164
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  67. package/src/cli/cmd/tui/component/logo.tsx +0 -88
  68. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -632
  69. package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
  70. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  71. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1096
  72. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  73. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  74. package/src/cli/cmd/tui/component/tips.tsx +0 -153
  75. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  76. package/src/cli/cmd/tui/context/args.tsx +0 -14
  77. package/src/cli/cmd/tui/context/directory.ts +0 -13
  78. package/src/cli/cmd/tui/context/exit.tsx +0 -23
  79. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  80. package/src/cli/cmd/tui/context/keybind.tsx +0 -101
  81. package/src/cli/cmd/tui/context/kv.tsx +0 -52
  82. package/src/cli/cmd/tui/context/local.tsx +0 -402
  83. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  84. package/src/cli/cmd/tui/context/route.tsx +0 -46
  85. package/src/cli/cmd/tui/context/sdk.tsx +0 -94
  86. package/src/cli/cmd/tui/context/sync.tsx +0 -427
  87. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  88. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  89. package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
  90. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  91. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  92. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  93. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  94. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  95. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  96. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  97. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  98. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  99. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
  100. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  101. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
  102. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  103. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  104. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  105. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  106. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  107. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  108. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  109. package/src/cli/cmd/tui/context/theme/orng.json +0 -249
  110. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  111. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  112. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  113. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  114. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  115. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  116. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  117. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  118. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  119. package/src/cli/cmd/tui/context/theme.tsx +0 -1152
  120. package/src/cli/cmd/tui/event.ts +0 -48
  121. package/src/cli/cmd/tui/routes/home.tsx +0 -140
  122. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
  123. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
  124. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  125. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  126. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
  127. package/src/cli/cmd/tui/routes/session/header.tsx +0 -136
  128. package/src/cli/cmd/tui/routes/session/index.tsx +0 -2050
  129. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -495
  130. package/src/cli/cmd/tui/routes/session/question.tsx +0 -435
  131. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -312
  132. package/src/cli/cmd/tui/thread.ts +0 -165
  133. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
  134. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
  135. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
  136. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
  137. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
  138. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -354
  139. package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
  140. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  141. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  142. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  143. package/src/cli/cmd/tui/util/clipboard.ts +0 -160
  144. package/src/cli/cmd/tui/util/editor.ts +0 -32
  145. package/src/cli/cmd/tui/util/signal.ts +0 -7
  146. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  147. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  148. package/src/cli/cmd/tui/worker.ts +0 -152
  149. package/src/cli/cmd/uninstall.ts +0 -357
  150. package/src/cli/cmd/upgrade.ts +0 -73
  151. package/src/cli/cmd/web.ts +0 -81
  152. package/src/cli/error.ts +0 -57
  153. package/src/cli/network.ts +0 -53
  154. package/src/cli/ui.ts +0 -84
  155. package/src/cli/upgrade.ts +0 -25
  156. package/src/command/index.ts +0 -131
  157. package/src/command/template/initialize.txt +0 -10
  158. package/src/command/template/review.txt +0 -99
  159. package/src/config/config.ts +0 -1255
  160. package/src/config/markdown.ts +0 -93
  161. package/src/env/index.ts +0 -26
  162. package/src/file/ignore.ts +0 -83
  163. package/src/file/index.ts +0 -411
  164. package/src/file/ripgrep.ts +0 -409
  165. package/src/file/time.ts +0 -64
  166. package/src/file/watcher.ts +0 -118
  167. package/src/flag/flag.ts +0 -54
  168. package/src/format/formatter.ts +0 -359
  169. package/src/format/index.ts +0 -137
  170. package/src/global/index.ts +0 -55
  171. package/src/id/id.ts +0 -83
  172. package/src/ide/index.ts +0 -76
  173. package/src/index.ts +0 -159
  174. package/src/installation/index.ts +0 -246
  175. package/src/lsp/client.ts +0 -252
  176. package/src/lsp/index.ts +0 -485
  177. package/src/lsp/language.ts +0 -119
  178. package/src/lsp/server.ts +0 -2046
  179. package/src/mcp/auth.ts +0 -135
  180. package/src/mcp/index.ts +0 -926
  181. package/src/mcp/oauth-callback.ts +0 -200
  182. package/src/mcp/oauth-provider.ts +0 -154
  183. package/src/patch/index.ts +0 -680
  184. package/src/permission/arity.ts +0 -163
  185. package/src/permission/index.ts +0 -210
  186. package/src/permission/next.ts +0 -269
  187. package/src/plugin/codex.ts +0 -493
  188. package/src/plugin/copilot.ts +0 -269
  189. package/src/plugin/index.ts +0 -135
  190. package/src/project/bootstrap.ts +0 -35
  191. package/src/project/instance.ts +0 -91
  192. package/src/project/project.ts +0 -320
  193. package/src/project/state.ts +0 -66
  194. package/src/project/vcs.ts +0 -76
  195. package/src/provider/auth.ts +0 -147
  196. package/src/provider/models-macro.ts +0 -11
  197. package/src/provider/models.ts +0 -112
  198. package/src/provider/provider.ts +0 -1219
  199. package/src/provider/sdk/openai-compatible/src/README.md +0 -5
  200. package/src/provider/sdk/openai-compatible/src/index.ts +0 -2
  201. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +0 -100
  202. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +0 -303
  203. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +0 -22
  204. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +0 -18
  205. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +0 -22
  206. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +0 -207
  207. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +0 -1732
  208. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +0 -177
  209. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +0 -1
  210. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +0 -88
  211. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +0 -128
  212. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +0 -115
  213. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +0 -65
  214. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +0 -104
  215. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +0 -103
  216. package/src/provider/transform.ts +0 -724
  217. package/src/pty/index.ts +0 -229
  218. package/src/question/index.ts +0 -171
  219. package/src/scheduler/index.ts +0 -61
  220. package/src/server/error.ts +0 -36
  221. package/src/server/mdns.ts +0 -59
  222. package/src/server/routes/config.ts +0 -92
  223. package/src/server/routes/experimental.ts +0 -157
  224. package/src/server/routes/file.ts +0 -197
  225. package/src/server/routes/global.ts +0 -135
  226. package/src/server/routes/mcp.ts +0 -225
  227. package/src/server/routes/permission.ts +0 -68
  228. package/src/server/routes/project.ts +0 -82
  229. package/src/server/routes/provider.ts +0 -165
  230. package/src/server/routes/pty.ts +0 -169
  231. package/src/server/routes/question.ts +0 -98
  232. package/src/server/routes/session.ts +0 -935
  233. package/src/server/routes/tui.ts +0 -379
  234. package/src/server/server.ts +0 -578
  235. package/src/session/compaction.ts +0 -225
  236. package/src/session/index.ts +0 -488
  237. package/src/session/llm.ts +0 -279
  238. package/src/session/message-v2.ts +0 -702
  239. package/src/session/message.ts +0 -189
  240. package/src/session/processor.ts +0 -406
  241. package/src/session/prompt/anthropic-20250930.txt +0 -166
  242. package/src/session/prompt/anthropic.txt +0 -105
  243. package/src/session/prompt/anthropic_spoof.txt +0 -1
  244. package/src/session/prompt/beast.txt +0 -147
  245. package/src/session/prompt/build-switch.txt +0 -5
  246. package/src/session/prompt/codex.txt +0 -73
  247. package/src/session/prompt/codex_header.txt +0 -72
  248. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  249. package/src/session/prompt/gemini.txt +0 -155
  250. package/src/session/prompt/max-steps.txt +0 -16
  251. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  252. package/src/session/prompt/plan.txt +0 -26
  253. package/src/session/prompt/qwen.txt +0 -109
  254. package/src/session/prompt.ts +0 -1805
  255. package/src/session/retry.ts +0 -90
  256. package/src/session/revert.ts +0 -108
  257. package/src/session/status.ts +0 -76
  258. package/src/session/summary.ts +0 -150
  259. package/src/session/system.ts +0 -138
  260. package/src/session/todo.ts +0 -37
  261. package/src/share/share-next.ts +0 -194
  262. package/src/share/share.ts +0 -87
  263. package/src/shell/shell.ts +0 -67
  264. package/src/skill/index.ts +0 -1
  265. package/src/skill/skill.ts +0 -136
  266. package/src/snapshot/index.ts +0 -236
  267. package/src/storage/storage.ts +0 -227
  268. package/src/tool/apply_patch.ts +0 -277
  269. package/src/tool/apply_patch.txt +0 -1
  270. package/src/tool/bash.ts +0 -258
  271. package/src/tool/bash.txt +0 -115
  272. package/src/tool/batch.ts +0 -175
  273. package/src/tool/batch.txt +0 -24
  274. package/src/tool/codesearch.ts +0 -132
  275. package/src/tool/codesearch.txt +0 -12
  276. package/src/tool/edit.ts +0 -645
  277. package/src/tool/edit.txt +0 -10
  278. package/src/tool/external-directory.ts +0 -32
  279. package/src/tool/glob.ts +0 -77
  280. package/src/tool/glob.txt +0 -6
  281. package/src/tool/grep.ts +0 -154
  282. package/src/tool/grep.txt +0 -8
  283. package/src/tool/invalid.ts +0 -17
  284. package/src/tool/ls.ts +0 -121
  285. package/src/tool/ls.txt +0 -1
  286. package/src/tool/lsp.ts +0 -96
  287. package/src/tool/lsp.txt +0 -19
  288. package/src/tool/multiedit.ts +0 -46
  289. package/src/tool/multiedit.txt +0 -41
  290. package/src/tool/plan-enter.txt +0 -14
  291. package/src/tool/plan-exit.txt +0 -13
  292. package/src/tool/plan.ts +0 -130
  293. package/src/tool/question.ts +0 -33
  294. package/src/tool/question.txt +0 -10
  295. package/src/tool/read.ts +0 -202
  296. package/src/tool/read.txt +0 -12
  297. package/src/tool/registry.ts +0 -158
  298. package/src/tool/skill.ts +0 -75
  299. package/src/tool/task.ts +0 -188
  300. package/src/tool/task.txt +0 -60
  301. package/src/tool/todo.ts +0 -53
  302. package/src/tool/todoread.txt +0 -14
  303. package/src/tool/todowrite.txt +0 -167
  304. package/src/tool/tool.ts +0 -88
  305. package/src/tool/truncation.ts +0 -106
  306. package/src/tool/webfetch.ts +0 -182
  307. package/src/tool/webfetch.txt +0 -13
  308. package/src/tool/websearch.ts +0 -150
  309. package/src/tool/websearch.txt +0 -14
  310. package/src/tool/write.ts +0 -80
  311. package/src/tool/write.txt +0 -8
  312. package/src/util/archive.ts +0 -16
  313. package/src/util/color.ts +0 -19
  314. package/src/util/context.ts +0 -25
  315. package/src/util/defer.ts +0 -12
  316. package/src/util/eventloop.ts +0 -20
  317. package/src/util/filesystem.ts +0 -93
  318. package/src/util/fn.ts +0 -11
  319. package/src/util/format.ts +0 -20
  320. package/src/util/iife.ts +0 -3
  321. package/src/util/keybind.ts +0 -103
  322. package/src/util/lazy.ts +0 -18
  323. package/src/util/locale.ts +0 -81
  324. package/src/util/lock.ts +0 -98
  325. package/src/util/log.ts +0 -180
  326. package/src/util/queue.ts +0 -32
  327. package/src/util/rpc.ts +0 -66
  328. package/src/util/scrap.ts +0 -10
  329. package/src/util/signal.ts +0 -12
  330. package/src/util/timeout.ts +0 -14
  331. package/src/util/token.ts +0 -7
  332. package/src/util/wildcard.ts +0 -56
  333. package/src/worktree/index.ts +0 -217
  334. package/sst-env.d.ts +0 -9
  335. package/test/acp/event-subscription.test.ts +0 -436
  336. package/test/acp/system-prompt.test.ts +0 -262
  337. package/test/agent/agent.test.ts +0 -638
  338. package/test/bun.test.ts +0 -53
  339. package/test/cli/github-action.test.ts +0 -129
  340. package/test/cli/github-remote.test.ts +0 -80
  341. package/test/cli/tui/transcript.test.ts +0 -297
  342. package/test/config/agent-color.test.ts +0 -66
  343. package/test/config/config.test.ts +0 -1414
  344. package/test/config/fixtures/empty-frontmatter.md +0 -4
  345. package/test/config/fixtures/frontmatter.md +0 -28
  346. package/test/config/fixtures/no-frontmatter.md +0 -1
  347. package/test/config/markdown.test.ts +0 -192
  348. package/test/file/ignore.test.ts +0 -10
  349. package/test/file/path-traversal.test.ts +0 -198
  350. package/test/fixture/fixture.ts +0 -45
  351. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  352. package/test/ide/ide.test.ts +0 -82
  353. package/test/keybind.test.ts +0 -421
  354. package/test/lsp/client.test.ts +0 -95
  355. package/test/mcp/headers.test.ts +0 -153
  356. package/test/mcp/oauth-browser.test.ts +0 -261
  357. package/test/patch/patch.test.ts +0 -348
  358. package/test/permission/arity.test.ts +0 -33
  359. package/test/permission/next.test.ts +0 -652
  360. package/test/permission-task.test.ts +0 -319
  361. package/test/plugin/codex.test.ts +0 -123
  362. package/test/preload.ts +0 -65
  363. package/test/project/project.test.ts +0 -120
  364. package/test/provider/amazon-bedrock.test.ts +0 -268
  365. package/test/provider/gitlab-duo.test.ts +0 -286
  366. package/test/provider/provider.test.ts +0 -2149
  367. package/test/provider/transform.test.ts +0 -1596
  368. package/test/question/question.test.ts +0 -300
  369. package/test/scheduler.test.ts +0 -73
  370. package/test/server/session-list.test.ts +0 -39
  371. package/test/server/session-select.test.ts +0 -78
  372. package/test/session/compaction.test.ts +0 -293
  373. package/test/session/llm.test.ts +0 -90
  374. package/test/session/message-v2.test.ts +0 -662
  375. package/test/session/retry.test.ts +0 -131
  376. package/test/session/revert-compact.test.ts +0 -285
  377. package/test/session/session.test.ts +0 -71
  378. package/test/skill/skill.test.ts +0 -185
  379. package/test/snapshot/snapshot.test.ts +0 -939
  380. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  381. package/test/tool/apply_patch.test.ts +0 -515
  382. package/test/tool/bash.test.ts +0 -320
  383. package/test/tool/external-directory.test.ts +0 -126
  384. package/test/tool/fixtures/large-image.png +0 -0
  385. package/test/tool/fixtures/models-api.json +0 -33453
  386. package/test/tool/grep.test.ts +0 -109
  387. package/test/tool/question.test.ts +0 -105
  388. package/test/tool/read.test.ts +0 -332
  389. package/test/tool/registry.test.ts +0 -76
  390. package/test/tool/truncation.test.ts +0 -159
  391. package/test/util/filesystem.test.ts +0 -39
  392. package/test/util/format.test.ts +0 -59
  393. package/test/util/iife.test.ts +0 -36
  394. package/test/util/lazy.test.ts +0 -50
  395. package/test/util/lock.test.ts +0 -72
  396. package/test/util/timeout.test.ts +0 -21
  397. package/test/util/wildcard.test.ts +0 -75
  398. package/tsconfig.json +0 -16
@@ -1,1096 +0,0 @@
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
- }