innocode 1.0.0 → 1.0.229

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