@epoch-ai/cli 2.2.5 → 2.2.7

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 (711) hide show
  1. package/.artifacts/unit/junit.xml +2823 -0
  2. package/.project-map/backups/20260530_223453/.project-map.json +90101 -0
  3. package/.project-map/backups/20260530_223507/.project-map.json +90101 -0
  4. package/.project-map/backups/20260530_223512/.project-map.json +90101 -0
  5. package/.project-map/backups/20260530_223512/map.toon +666 -0
  6. package/.project-map/backups/20260530_223516/.project-map.json +90101 -0
  7. package/.project-map/backups/20260530_223516/map.toon +666 -0
  8. package/.project-map/backups/20260530_223520/.project-map.json +90101 -0
  9. package/.project-map/backups/20260530_223520/map.toon +666 -0
  10. package/AGENTS.md +47 -0
  11. package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
  12. package/Dockerfile +18 -0
  13. package/README.md +15 -0
  14. package/bunfig.toml +7 -0
  15. package/drizzle.config.ts +10 -0
  16. package/git +0 -0
  17. package/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
  18. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
  19. package/migration/20260211171708_add_project_commands/migration.sql +1 -0
  20. package/migration/20260211171708_add_project_commands/snapshot.json +806 -0
  21. package/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
  22. package/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
  23. package/migration/20260225215848_workspace/migration.sql +7 -0
  24. package/migration/20260225215848_workspace/snapshot.json +959 -0
  25. package/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
  26. package/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
  27. package/migration/20260228203230_blue_harpoon/migration.sql +17 -0
  28. package/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
  29. package/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
  30. package/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
  31. package/migration/20260309230000_move_org_to_state/migration.sql +3 -0
  32. package/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
  33. package/migration/20260312043431_session_message_cursor/migration.sql +4 -0
  34. package/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
  35. package/migration/20260323234822_events/migration.sql +13 -0
  36. package/migration/20260323234822_events/snapshot.json +1271 -0
  37. package/migration/20260418092949_add_yolo_to_session/migration.sql +2 -0
  38. package/migration/20260418092949_add_yolo_to_session/snapshot.json +1199 -0
  39. package/migration/20260419120000_add_intervention_to_session/migration.sql +2 -0
  40. package/package.json +179 -18
  41. package/parsers-config.ts +290 -0
  42. package/script/build-node.ts +71 -0
  43. package/script/build.ts +255 -0
  44. package/script/check-migrations.ts +16 -0
  45. package/script/fix-node-pty.ts +28 -0
  46. package/script/publish.ts +182 -0
  47. package/script/schema.ts +63 -0
  48. package/script/seed-e2e.ts +60 -0
  49. package/script/upgrade-opentui.ts +64 -0
  50. package/specs/effect-migration.md +310 -0
  51. package/specs/tui-plugins.md +436 -0
  52. package/specs/v2.md +14 -0
  53. package/src/account/account.sql.ts +39 -0
  54. package/src/account/index.ts +465 -0
  55. package/src/account/repo.ts +163 -0
  56. package/src/account/schema.ts +91 -0
  57. package/src/acp/README.md +174 -0
  58. package/src/acp/agent.ts +1847 -0
  59. package/src/acp/session.ts +116 -0
  60. package/src/acp/types.ts +24 -0
  61. package/src/agent/agent.ts +445 -0
  62. package/src/agent/generate.txt +75 -0
  63. package/src/agent/prompt/compaction.txt +15 -0
  64. package/src/agent/prompt/explore.txt +9 -0
  65. package/src/agent/prompt/summary.txt +11 -0
  66. package/src/agent/prompt/title.txt +44 -0
  67. package/src/auth/index.ts +110 -0
  68. package/src/bus/bus-event.ts +40 -0
  69. package/src/bus/global.ts +10 -0
  70. package/src/bus/index.ts +232 -0
  71. package/src/cli/bootstrap.ts +17 -0
  72. package/src/cli/cmd/account.ts +257 -0
  73. package/src/cli/cmd/acp.ts +70 -0
  74. package/src/cli/cmd/agent.ts +245 -0
  75. package/src/cli/cmd/cmd.ts +7 -0
  76. package/src/cli/cmd/db.ts +119 -0
  77. package/src/cli/cmd/debug/agent.ts +167 -0
  78. package/src/cli/cmd/debug/config.ts +16 -0
  79. package/src/cli/cmd/debug/file.ts +97 -0
  80. package/src/cli/cmd/debug/index.ts +48 -0
  81. package/src/cli/cmd/debug/lsp.ts +53 -0
  82. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  83. package/src/cli/cmd/debug/scrap.ts +16 -0
  84. package/src/cli/cmd/debug/skill.ts +16 -0
  85. package/src/cli/cmd/debug/snapshot.ts +52 -0
  86. package/src/cli/cmd/export.ts +89 -0
  87. package/src/cli/cmd/generate.ts +38 -0
  88. package/src/cli/cmd/github.ts +1639 -0
  89. package/src/cli/cmd/import.ts +169 -0
  90. package/src/cli/cmd/mcp.ts +754 -0
  91. package/src/cli/cmd/models.ts +78 -0
  92. package/src/cli/cmd/plug.ts +233 -0
  93. package/src/cli/cmd/pr.ts +127 -0
  94. package/src/cli/cmd/providers.ts +478 -0
  95. package/src/cli/cmd/run.ts +681 -0
  96. package/src/cli/cmd/serve.ts +24 -0
  97. package/src/cli/cmd/session.ts +159 -0
  98. package/src/cli/cmd/stats.ts +410 -0
  99. package/src/cli/cmd/tui/app.tsx +945 -0
  100. package/src/cli/cmd/tui/attach.ts +88 -0
  101. package/src/cli/cmd/tui/component/border.tsx +21 -0
  102. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  103. package/src/cli/cmd/tui/component/dialog-command.tsx +171 -0
  104. package/src/cli/cmd/tui/component/dialog-console-org.tsx +103 -0
  105. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  106. package/src/cli/cmd/tui/component/dialog-model.tsx +190 -0
  107. package/src/cli/cmd/tui/component/dialog-provider.tsx +364 -0
  108. package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
  109. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  110. package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
  111. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  112. package/src/cli/cmd/tui/component/dialog-status.tsx +168 -0
  113. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  114. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  115. package/src/cli/cmd/tui/component/dialog-variant.tsx +39 -0
  116. package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +320 -0
  117. package/src/cli/cmd/tui/component/error-component.tsx +92 -0
  118. package/src/cli/cmd/tui/component/logo.tsx +85 -0
  119. package/src/cli/cmd/tui/component/plugin-route-missing.tsx +14 -0
  120. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +672 -0
  121. package/src/cli/cmd/tui/component/prompt/frecency.tsx +90 -0
  122. package/src/cli/cmd/tui/component/prompt/history.tsx +109 -0
  123. package/src/cli/cmd/tui/component/prompt/index.tsx +1348 -0
  124. package/src/cli/cmd/tui/component/prompt/part.ts +16 -0
  125. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  126. package/src/cli/cmd/tui/component/spinner.tsx +24 -0
  127. package/src/cli/cmd/tui/component/startup-loading.tsx +63 -0
  128. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  129. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  130. package/src/cli/cmd/tui/component/workspace/dialog-session-list.tsx +151 -0
  131. package/src/cli/cmd/tui/context/args.tsx +15 -0
  132. package/src/cli/cmd/tui/context/directory.ts +13 -0
  133. package/src/cli/cmd/tui/context/exit.tsx +60 -0
  134. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  135. package/src/cli/cmd/tui/context/keybind.tsx +105 -0
  136. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  137. package/src/cli/cmd/tui/context/local.tsx +456 -0
  138. package/src/cli/cmd/tui/context/plugin-keybinds.ts +41 -0
  139. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  140. package/src/cli/cmd/tui/context/route.tsx +52 -0
  141. package/src/cli/cmd/tui/context/sdk.tsx +115 -0
  142. package/src/cli/cmd/tui/context/sync.tsx +516 -0
  143. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  144. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  145. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  146. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  147. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  148. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  149. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  150. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  151. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  152. package/src/cli/cmd/tui/context/theme/epochcli.json +245 -0
  153. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  154. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  155. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  156. package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  157. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  158. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  159. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  160. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  161. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  162. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  163. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  164. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  165. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  166. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  167. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  168. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  169. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  170. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  171. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  172. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  173. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  174. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  175. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  176. package/src/cli/cmd/tui/context/theme.tsx +1236 -0
  177. package/src/cli/cmd/tui/context/tui-config.tsx +9 -0
  178. package/src/cli/cmd/tui/event.ts +48 -0
  179. package/src/cli/cmd/tui/feature-plugins/home/footer.tsx +93 -0
  180. package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +145 -0
  181. package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +50 -0
  182. package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +82 -0
  183. package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +62 -0
  184. package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +93 -0
  185. package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +66 -0
  186. package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +96 -0
  187. package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +48 -0
  188. package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +270 -0
  189. package/src/cli/cmd/tui/plugin/api.tsx +397 -0
  190. package/src/cli/cmd/tui/plugin/index.ts +3 -0
  191. package/src/cli/cmd/tui/plugin/internal.ts +27 -0
  192. package/src/cli/cmd/tui/plugin/runtime.ts +1031 -0
  193. package/src/cli/cmd/tui/plugin/slots.tsx +60 -0
  194. package/src/cli/cmd/tui/routes/home.tsx +94 -0
  195. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +65 -0
  196. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +110 -0
  197. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  198. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  199. package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  200. package/src/cli/cmd/tui/routes/session/index.tsx +2161 -0
  201. package/src/cli/cmd/tui/routes/session/permission.tsx +691 -0
  202. package/src/cli/cmd/tui/routes/session/question.tsx +468 -0
  203. package/src/cli/cmd/tui/routes/session/sidebar.tsx +70 -0
  204. package/src/cli/cmd/tui/routes/session/subagent-footer.tsx +131 -0
  205. package/src/cli/cmd/tui/thread.ts +241 -0
  206. package/src/cli/cmd/tui/ui/dialog-alert.tsx +59 -0
  207. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +89 -0
  208. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +211 -0
  209. package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
  210. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +115 -0
  211. package/src/cli/cmd/tui/ui/dialog-select.tsx +417 -0
  212. package/src/cli/cmd/tui/ui/dialog.tsx +192 -0
  213. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  214. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  215. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  216. package/src/cli/cmd/tui/util/clipboard.ts +192 -0
  217. package/src/cli/cmd/tui/util/editor.ts +37 -0
  218. package/src/cli/cmd/tui/util/model.ts +23 -0
  219. package/src/cli/cmd/tui/util/provider-origin.ts +20 -0
  220. package/src/cli/cmd/tui/util/scroll.ts +23 -0
  221. package/src/cli/cmd/tui/util/selection.ts +25 -0
  222. package/src/cli/cmd/tui/util/signal.ts +7 -0
  223. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  224. package/src/cli/cmd/tui/util/transcript.ts +112 -0
  225. package/src/cli/cmd/tui/win32.ts +129 -0
  226. package/src/cli/cmd/tui/worker.ts +195 -0
  227. package/src/cli/cmd/uninstall.ts +353 -0
  228. package/src/cli/cmd/upgrade.ts +73 -0
  229. package/src/cli/cmd/web.ts +81 -0
  230. package/src/cli/effect/prompt.ts +25 -0
  231. package/src/cli/error.ts +46 -0
  232. package/src/cli/heap.ts +59 -0
  233. package/src/cli/logo.ts +6 -0
  234. package/src/cli/network.ts +60 -0
  235. package/src/cli/ui.ts +133 -0
  236. package/src/cli/upgrade.ts +31 -0
  237. package/src/command/index.ts +197 -0
  238. package/src/command/template/initialize.txt +66 -0
  239. package/src/command/template/review.txt +101 -0
  240. package/src/config/config.ts +1610 -0
  241. package/src/config/console-state.ts +15 -0
  242. package/src/config/markdown.ts +99 -0
  243. package/src/config/paths.ts +167 -0
  244. package/src/config/tui-migrate.ts +155 -0
  245. package/src/config/tui-schema.ts +37 -0
  246. package/src/config/tui.ts +179 -0
  247. package/src/config/validator.ts +52 -0
  248. package/src/control-plane/adaptors/index.ts +20 -0
  249. package/src/control-plane/adaptors/worktree.ts +42 -0
  250. package/src/control-plane/schema.ts +17 -0
  251. package/src/control-plane/sse.ts +66 -0
  252. package/src/control-plane/types.ts +32 -0
  253. package/src/control-plane/workspace.sql.ts +17 -0
  254. package/src/control-plane/workspace.ts +168 -0
  255. package/src/effect/cross-spawn-spawner.ts +502 -0
  256. package/src/effect/instance-ref.ts +6 -0
  257. package/src/effect/instance-registry.ts +12 -0
  258. package/src/effect/instance-state.ts +82 -0
  259. package/src/effect/run-service.ts +33 -0
  260. package/src/effect/runner.ts +216 -0
  261. package/src/env/index.ts +28 -0
  262. package/src/file/ignore.ts +82 -0
  263. package/src/file/index.ts +686 -0
  264. package/src/file/protected.ts +59 -0
  265. package/src/file/ripgrep.ts +376 -0
  266. package/src/file/time.ts +133 -0
  267. package/src/file/watcher.ts +172 -0
  268. package/src/filesystem/index.ts +236 -0
  269. package/src/flag/flag.ts +157 -0
  270. package/src/format/formatter.ts +413 -0
  271. package/src/format/index.ts +203 -0
  272. package/src/git/index.ts +303 -0
  273. package/src/global/index.ts +54 -0
  274. package/src/id/id.ts +85 -0
  275. package/src/ide/index.ts +74 -0
  276. package/src/index.ts +253 -0
  277. package/src/installation/index.ts +355 -0
  278. package/src/installation/meta.ts +7 -0
  279. package/src/lsp/client.ts +256 -0
  280. package/src/lsp/index.ts +558 -0
  281. package/src/lsp/language.ts +120 -0
  282. package/src/lsp/launch.ts +21 -0
  283. package/src/lsp/server.ts +1968 -0
  284. package/src/mcp/auth.ts +173 -0
  285. package/src/mcp/index.ts +1250 -0
  286. package/src/mcp/oauth-callback.ts +216 -0
  287. package/src/mcp/oauth-provider.ts +185 -0
  288. package/src/mcp/schema-loader.ts +82 -0
  289. package/src/node.ts +1 -0
  290. package/src/npm/index.ts +188 -0
  291. package/src/patch/index.ts +680 -0
  292. package/src/permission/arity.ts +163 -0
  293. package/src/permission/evaluate.ts +15 -0
  294. package/src/permission/index.ts +323 -0
  295. package/src/permission/schema.ts +17 -0
  296. package/src/plugin/cloudflare.ts +67 -0
  297. package/src/plugin/codex.ts +608 -0
  298. package/src/plugin/github-copilot/copilot.ts +361 -0
  299. package/src/plugin/github-copilot/models.ts +144 -0
  300. package/src/plugin/index.ts +288 -0
  301. package/src/plugin/install.ts +439 -0
  302. package/src/plugin/loader.ts +174 -0
  303. package/src/plugin/meta.ts +188 -0
  304. package/src/plugin/shared.ts +323 -0
  305. package/src/project/bootstrap.ts +35 -0
  306. package/src/project/init-files.ts +328 -0
  307. package/src/project/instance.ts +175 -0
  308. package/src/project/project.sql.ts +16 -0
  309. package/src/project/project.ts +519 -0
  310. package/src/project/schema.ts +16 -0
  311. package/src/project/state.ts +70 -0
  312. package/src/project/vcs.ts +240 -0
  313. package/src/provider/auth.ts +253 -0
  314. package/src/provider/error.ts +297 -0
  315. package/src/provider/models.ts +162 -0
  316. package/src/provider/provider.ts +1776 -0
  317. package/src/provider/schema.ts +38 -0
  318. package/src/provider/sdk/copilot/README.md +5 -0
  319. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
  320. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  321. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
  322. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  323. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +814 -0
  324. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  325. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  326. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +83 -0
  327. package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  328. package/src/provider/sdk/copilot/index.ts +2 -0
  329. package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  330. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
  331. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  332. package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  333. package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  334. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
  335. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1769 -0
  336. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
  337. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  338. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
  339. package/src/provider/sdk/copilot/responses/tool/file-search.ts +127 -0
  340. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +114 -0
  341. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +64 -0
  342. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
  343. package/src/provider/sdk/copilot/responses/tool/web-search.ts +102 -0
  344. package/src/provider/transform.ts +1124 -0
  345. package/src/pty/index.ts +397 -0
  346. package/src/pty/pty.bun.ts +26 -0
  347. package/src/pty/pty.node.ts +27 -0
  348. package/src/pty/pty.ts +25 -0
  349. package/src/pty/schema.ts +17 -0
  350. package/src/question/index.ts +224 -0
  351. package/src/question/schema.ts +17 -0
  352. package/src/server/error.ts +36 -0
  353. package/src/server/event.ts +7 -0
  354. package/src/server/instance.ts +315 -0
  355. package/src/server/mdns.ts +60 -0
  356. package/src/server/middleware.ts +33 -0
  357. package/src/server/projectors.ts +28 -0
  358. package/src/server/proxy.ts +130 -0
  359. package/src/server/router.ts +105 -0
  360. package/src/server/routes/config.ts +92 -0
  361. package/src/server/routes/event.ts +83 -0
  362. package/src/server/routes/experimental.ts +374 -0
  363. package/src/server/routes/file.ts +197 -0
  364. package/src/server/routes/global.ts +312 -0
  365. package/src/server/routes/mcp.ts +225 -0
  366. package/src/server/routes/permission.ts +69 -0
  367. package/src/server/routes/project.ts +118 -0
  368. package/src/server/routes/provider.ts +171 -0
  369. package/src/server/routes/pty.ts +210 -0
  370. package/src/server/routes/question.ts +99 -0
  371. package/src/server/routes/session.ts +984 -0
  372. package/src/server/routes/tui.ts +378 -0
  373. package/src/server/routes/workspace.ts +94 -0
  374. package/src/server/server.ts +353 -0
  375. package/src/session/compaction.ts +86 -0
  376. package/src/session/index.ts +904 -0
  377. package/src/session/instruction.ts +261 -0
  378. package/src/session/llm/monitor.ts +87 -0
  379. package/src/session/llm.ts +1676 -0
  380. package/src/session/message-v2.ts +1082 -0
  381. package/src/session/message.ts +191 -0
  382. package/src/session/overflow.ts +34 -0
  383. package/src/session/processor.ts +635 -0
  384. package/src/session/projectors.ts +136 -0
  385. package/src/session/prompt/build-switch.txt +5 -0
  386. package/src/session/prompt/builder.ts +135 -0
  387. package/src/session/prompt/default.txt +11 -0
  388. package/src/session/prompt/engine.ts +1072 -0
  389. package/src/session/prompt/gemma4.txt +1 -0
  390. package/src/session/prompt/max-steps.txt +16 -0
  391. package/src/session/prompt/orchestrator.ts +426 -0
  392. package/src/session/prompt/plan.txt +28 -0
  393. package/src/session/prompt/qwen.txt +19 -0
  394. package/src/session/prompt/resolver.ts +670 -0
  395. package/src/session/prompt/router.ts +197 -0
  396. package/src/session/prompt/state.ts +96 -0
  397. package/src/session/prompt/types.ts +115 -0
  398. package/src/session/prompt/utils.ts +15 -0
  399. package/src/session/prompt.ts +362 -0
  400. package/src/session/retry.ts +106 -0
  401. package/src/session/revert.ts +176 -0
  402. package/src/session/sanitizer.ts +125 -0
  403. package/src/session/schema.ts +38 -0
  404. package/src/session/session.sql.ts +106 -0
  405. package/src/session/status.ts +102 -0
  406. package/src/session/summary.ts +183 -0
  407. package/src/session/system.ts +79 -0
  408. package/src/session/todo.ts +166 -0
  409. package/src/session/worker.ts +382 -0
  410. package/src/shell/shell.ts +110 -0
  411. package/src/skill/discovery.ts +116 -0
  412. package/src/skill/index.ts +287 -0
  413. package/src/snapshot/index.ts +726 -0
  414. package/src/sql.d.ts +4 -0
  415. package/src/storage/db.bun.ts +8 -0
  416. package/src/storage/db.node.ts +8 -0
  417. package/src/storage/db.ts +174 -0
  418. package/src/storage/json-migration.ts +387 -0
  419. package/src/storage/schema.sql.ts +10 -0
  420. package/src/storage/schema.ts +4 -0
  421. package/src/storage/storage.ts +353 -0
  422. package/src/sync/README.md +179 -0
  423. package/src/sync/event.sql.ts +16 -0
  424. package/src/sync/index.ts +263 -0
  425. package/src/sync/schema.ts +14 -0
  426. package/src/tool/apply_patch.ts +281 -0
  427. package/src/tool/apply_patch.txt +1 -0
  428. package/src/tool/arbitration.txt +5 -0
  429. package/src/tool/bash.ts +494 -0
  430. package/src/tool/bash.txt +2 -0
  431. package/src/tool/batch.ts +183 -0
  432. package/src/tool/batch.txt +1 -0
  433. package/src/tool/codesearch.ts +132 -0
  434. package/src/tool/codesearch.txt +1 -0
  435. package/src/tool/edit.ts +734 -0
  436. package/src/tool/edit.txt +1 -0
  437. package/src/tool/external-directory.ts +46 -0
  438. package/src/tool/glob.ts +73 -0
  439. package/src/tool/glob.txt +2 -0
  440. package/src/tool/grep.ts +156 -0
  441. package/src/tool/grep.txt +2 -0
  442. package/src/tool/invalid.ts +20 -0
  443. package/src/tool/ls.ts +121 -0
  444. package/src/tool/ls.txt +1 -0
  445. package/src/tool/lsp.ts +97 -0
  446. package/src/tool/lsp.txt +1 -0
  447. package/src/tool/multiedit.ts +46 -0
  448. package/src/tool/multiedit.txt +1 -0
  449. package/src/tool/plan-enter.txt +14 -0
  450. package/src/tool/plan-exit.txt +13 -0
  451. package/src/tool/plan.ts +131 -0
  452. package/src/tool/question.ts +46 -0
  453. package/src/tool/question.txt +10 -0
  454. package/src/tool/read.ts +332 -0
  455. package/src/tool/read.txt +1 -0
  456. package/src/tool/registry.ts +288 -0
  457. package/src/tool/revert.ts +37 -0
  458. package/src/tool/schema.ts +17 -0
  459. package/src/tool/skill.ts +105 -0
  460. package/src/tool/task.ts +150 -0
  461. package/src/tool/task.txt +3 -0
  462. package/src/tool/task_complete.ts +21 -0
  463. package/src/tool/tool.ts +112 -0
  464. package/src/tool/truncate.ts +144 -0
  465. package/src/tool/truncation-dir.ts +4 -0
  466. package/src/tool/webfetch.ts +206 -0
  467. package/src/tool/webfetch.txt +1 -0
  468. package/src/tool/websearch.ts +150 -0
  469. package/src/tool/websearch.txt +1 -0
  470. package/src/tool/write.ts +101 -0
  471. package/src/tool/write.txt +1 -0
  472. package/src/util/abort.ts +35 -0
  473. package/src/util/ai-sdk.ts +59 -0
  474. package/src/util/archive.ts +17 -0
  475. package/src/util/color.ts +19 -0
  476. package/src/util/context.ts +25 -0
  477. package/src/util/data-url.ts +9 -0
  478. package/src/util/defer.ts +12 -0
  479. package/src/util/effect-http-client.ts +11 -0
  480. package/src/util/effect-zod.ts +98 -0
  481. package/src/util/error.ts +77 -0
  482. package/src/util/filesystem.ts +245 -0
  483. package/src/util/flock.ts +333 -0
  484. package/src/util/fn.ts +21 -0
  485. package/src/util/format.ts +20 -0
  486. package/src/util/glob.ts +34 -0
  487. package/src/util/hash.ts +7 -0
  488. package/src/util/iife.ts +3 -0
  489. package/src/util/keybind.ts +103 -0
  490. package/src/util/lazy.ts +23 -0
  491. package/src/util/locale.ts +81 -0
  492. package/src/util/lock.ts +98 -0
  493. package/src/util/log-parser.ts +114 -0
  494. package/src/util/log.ts +250 -0
  495. package/src/util/network.ts +23 -0
  496. package/src/util/process.ts +176 -0
  497. package/src/util/queue.ts +32 -0
  498. package/src/util/record.ts +3 -0
  499. package/src/util/rpc.ts +66 -0
  500. package/src/util/schema.ts +53 -0
  501. package/src/util/scrap.ts +10 -0
  502. package/src/util/session-analyzer.ts +331 -0
  503. package/src/util/session-telemetry.ts +91 -0
  504. package/src/util/signal.ts +12 -0
  505. package/src/util/timeout.ts +14 -0
  506. package/src/util/token.ts +7 -0
  507. package/src/util/tokenizer.ts +50 -0
  508. package/src/util/toon.ts +45 -0
  509. package/src/util/update-schema.ts +13 -0
  510. package/src/util/which.ts +14 -0
  511. package/src/util/wildcard.ts +59 -0
  512. package/src/worktree/index.ts +612 -0
  513. package/sst-env.d.ts +10 -0
  514. package/test/AGENTS.md +81 -0
  515. package/test/account/repo.test.ts +326 -0
  516. package/test/account/service.test.ts +393 -0
  517. package/test/acp/agent-interface.test.ts +51 -0
  518. package/test/acp/event-subscription.test.ts +685 -0
  519. package/test/agent/agent.test.ts +716 -0
  520. package/test/auth/auth.test.ts +58 -0
  521. package/test/bus/bus-effect.test.ts +164 -0
  522. package/test/bus/bus-integration.test.ts +87 -0
  523. package/test/bus/bus.test.ts +219 -0
  524. package/test/cli/account.test.ts +26 -0
  525. package/test/cli/cmd/tui/prompt-part.test.ts +47 -0
  526. package/test/cli/github-action.test.ts +198 -0
  527. package/test/cli/github-remote.test.ts +80 -0
  528. package/test/cli/plugin-auth-picker.test.ts +120 -0
  529. package/test/cli/tui/keybind-plugin.test.ts +90 -0
  530. package/test/cli/tui/plugin-add.test.ts +107 -0
  531. package/test/cli/tui/plugin-install.test.ts +89 -0
  532. package/test/cli/tui/plugin-lifecycle.test.ts +225 -0
  533. package/test/cli/tui/plugin-loader-entrypoint.test.ts +492 -0
  534. package/test/cli/tui/plugin-loader-pure.test.ts +72 -0
  535. package/test/cli/tui/plugin-loader.test.ts +752 -0
  536. package/test/cli/tui/plugin-toggle.test.ts +159 -0
  537. package/test/cli/tui/slot-replace.test.tsx +47 -0
  538. package/test/cli/tui/theme-store.test.ts +51 -0
  539. package/test/cli/tui/thread.test.ts +128 -0
  540. package/test/cli/tui/transcript.test.ts +426 -0
  541. package/test/config/agent-color.test.ts +71 -0
  542. package/test/config/config.test.ts +2337 -0
  543. package/test/config/fixtures/empty-frontmatter.md +4 -0
  544. package/test/config/fixtures/frontmatter.md +28 -0
  545. package/test/config/fixtures/markdown-header.md +11 -0
  546. package/test/config/fixtures/no-frontmatter.md +1 -0
  547. package/test/config/fixtures/weird-model-id.md +13 -0
  548. package/test/config/markdown.test.ts +228 -0
  549. package/test/config/tui.test.ts +800 -0
  550. package/test/control-plane/sse.test.ts +56 -0
  551. package/test/effect/cross-spawn-spawner.test.ts +412 -0
  552. package/test/effect/instance-state.test.ts +482 -0
  553. package/test/effect/run-service.test.ts +46 -0
  554. package/test/effect/runner.test.ts +523 -0
  555. package/test/fake/provider.ts +82 -0
  556. package/test/file/fsmonitor.test.ts +62 -0
  557. package/test/file/ignore.test.ts +10 -0
  558. package/test/file/index.test.ts +946 -0
  559. package/test/file/path-traversal.test.ts +198 -0
  560. package/test/file/ripgrep.test.ts +54 -0
  561. package/test/file/time.test.ts +445 -0
  562. package/test/file/watcher.test.ts +247 -0
  563. package/test/filesystem/filesystem.test.ts +319 -0
  564. package/test/fixture/db.ts +11 -0
  565. package/test/fixture/fixture.test.ts +26 -0
  566. package/test/fixture/fixture.ts +172 -0
  567. package/test/fixture/flock-worker.ts +72 -0
  568. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  569. package/test/fixture/plug-worker.ts +93 -0
  570. package/test/fixture/plugin-meta-worker.ts +26 -0
  571. package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
  572. package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
  573. package/test/fixture/skills/cloudflare/SKILL.md +211 -0
  574. package/test/fixture/skills/index.json +6 -0
  575. package/test/fixture/tui-plugin.ts +328 -0
  576. package/test/fixture/tui-runtime.ts +27 -0
  577. package/test/format/format.test.ts +171 -0
  578. package/test/git/git.test.ts +128 -0
  579. package/test/ide/ide.test.ts +82 -0
  580. package/test/installation/installation.test.ts +152 -0
  581. package/test/keybind.test.ts +421 -0
  582. package/test/lib/effect.ts +53 -0
  583. package/test/lib/filesystem.ts +10 -0
  584. package/test/lib/llm-server.ts +794 -0
  585. package/test/lsp/client.test.ts +95 -0
  586. package/test/lsp/index.test.ts +133 -0
  587. package/test/lsp/launch.test.ts +22 -0
  588. package/test/lsp/lifecycle.test.ts +147 -0
  589. package/test/mcp/headers.test.ts +153 -0
  590. package/test/mcp/lifecycle.test.ts +750 -0
  591. package/test/mcp/oauth-auto-connect.test.ts +199 -0
  592. package/test/mcp/oauth-browser.test.ts +249 -0
  593. package/test/mcp/sc-approve-validator.test.ts +431 -0
  594. package/test/memory/abort-leak.test.ts +137 -0
  595. package/test/npm.test.ts +18 -0
  596. package/test/patch/patch.test.ts +348 -0
  597. package/test/permission/arity.test.ts +33 -0
  598. package/test/permission/next.test.ts +1123 -0
  599. package/test/permission-task.test.ts +323 -0
  600. package/test/plugin/auth-override.test.ts +74 -0
  601. package/test/plugin/codex.test.ts +123 -0
  602. package/test/plugin/github-copilot-models.test.ts +117 -0
  603. package/test/plugin/install-concurrency.test.ts +140 -0
  604. package/test/plugin/install.test.ts +570 -0
  605. package/test/plugin/loader-shared.test.ts +1136 -0
  606. package/test/plugin/meta.test.ts +137 -0
  607. package/test/plugin/shared.test.ts +88 -0
  608. package/test/plugin/trigger.test.ts +111 -0
  609. package/test/preload.ts +90 -0
  610. package/test/project/migrate-global.test.ts +140 -0
  611. package/test/project/project.test.ts +459 -0
  612. package/test/project/state.test.ts +115 -0
  613. package/test/project/vcs.test.ts +228 -0
  614. package/test/project/worktree-remove.test.ts +96 -0
  615. package/test/project/worktree.test.ts +173 -0
  616. package/test/provider/amazon-bedrock.test.ts +447 -0
  617. package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
  618. package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
  619. package/test/provider/error.test.ts +49 -0
  620. package/test/provider/gitlab-duo.test.ts +412 -0
  621. package/test/provider/provider.test.ts +2494 -0
  622. package/test/provider/transform.test.ts +2944 -0
  623. package/test/pty/pty-output-isolation.test.ts +141 -0
  624. package/test/pty/pty-session.test.ts +92 -0
  625. package/test/pty/pty-shell.test.ts +59 -0
  626. package/test/question/question.test.ts +453 -0
  627. package/test/server/global-session-list.test.ts +89 -0
  628. package/test/server/project-init-git.test.ts +121 -0
  629. package/test/server/session-actions.test.ts +83 -0
  630. package/test/server/session-list.test.ts +98 -0
  631. package/test/server/session-messages.test.ts +159 -0
  632. package/test/server/session-select.test.ts +84 -0
  633. package/test/session/compaction.test.ts +683 -0
  634. package/test/session/continuity-handover.test.ts +620 -0
  635. package/test/session/deterministic-handover.test.ts +328 -0
  636. package/test/session/doom-protection.test.ts +247 -0
  637. package/test/session/hard-reset.test.ts +179 -0
  638. package/test/session/instruction.test.ts +286 -0
  639. package/test/session/llm/monitor.test.ts +53 -0
  640. package/test/session/llm-sanitizer.test.ts +90 -0
  641. package/test/session/llm-zones-e2e.test.ts +61 -0
  642. package/test/session/llm.test.ts +1308 -0
  643. package/test/session/mcpx-normalization.test.ts +86 -0
  644. package/test/session/mcpx-syntax-recovery.test.ts +28 -0
  645. package/test/session/message-v2.test.ts +957 -0
  646. package/test/session/messages-pagination.test.ts +885 -0
  647. package/test/session/processor-effect.test.ts +805 -0
  648. package/test/session/prompt/builder.test.ts +71 -0
  649. package/test/session/prompt/engine-loop.test.ts +80 -0
  650. package/test/session/prompt/orchestrator.test.ts +108 -0
  651. package/test/session/prompt/resolver.test.ts +211 -0
  652. package/test/session/prompt/router.test.ts +84 -0
  653. package/test/session/prompt/state.test.ts +57 -0
  654. package/test/session/prompt-effect.test.ts +1241 -0
  655. package/test/session/prompt.test.ts +522 -0
  656. package/test/session/refactor-system-zones.test.ts +241 -0
  657. package/test/session/retry.test.ts +232 -0
  658. package/test/session/revert-compact.test.ts +621 -0
  659. package/test/session/sanitizer.test.ts +61 -0
  660. package/test/session/session.test.ts +142 -0
  661. package/test/session/snapshot-tool-race.test.ts +242 -0
  662. package/test/session/structured-output-integration.test.ts +233 -0
  663. package/test/session/structured-output.test.ts +391 -0
  664. package/test/session/system.test.ts +59 -0
  665. package/test/session/telemetry.test.ts +35 -0
  666. package/test/shell/shell.test.ts +73 -0
  667. package/test/skill/discovery.test.ts +116 -0
  668. package/test/skill/skill.test.ts +392 -0
  669. package/test/snapshot/snapshot.test.ts +1404 -0
  670. package/test/storage/db.test.ts +14 -0
  671. package/test/storage/json-migration.test.ts +791 -0
  672. package/test/storage/storage.test.ts +295 -0
  673. package/test/sync/index.test.ts +191 -0
  674. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  675. package/test/tool/apply_patch.test.ts +567 -0
  676. package/test/tool/bash.test.ts +1099 -0
  677. package/test/tool/edit.test.ts +681 -0
  678. package/test/tool/external-directory.test.ts +198 -0
  679. package/test/tool/fixtures/large-image.png +0 -0
  680. package/test/tool/fixtures/models-api.json +65179 -0
  681. package/test/tool/grep.test.ts +111 -0
  682. package/test/tool/question.test.ts +126 -0
  683. package/test/tool/read.test.ts +468 -0
  684. package/test/tool/registry.test.ts +126 -0
  685. package/test/tool/skill.test.ts +167 -0
  686. package/test/tool/task.test.ts +49 -0
  687. package/test/tool/tool-define.test.ts +101 -0
  688. package/test/tool/truncation.test.ts +161 -0
  689. package/test/tool/webfetch.test.ts +101 -0
  690. package/test/tool/write.test.ts +354 -0
  691. package/test/util/data-url.test.ts +14 -0
  692. package/test/util/effect-zod.test.ts +61 -0
  693. package/test/util/error.test.ts +38 -0
  694. package/test/util/filesystem.test.ts +656 -0
  695. package/test/util/flock.test.ts +383 -0
  696. package/test/util/format.test.ts +59 -0
  697. package/test/util/glob.test.ts +164 -0
  698. package/test/util/iife.test.ts +36 -0
  699. package/test/util/lazy.test.ts +50 -0
  700. package/test/util/lock.test.ts +72 -0
  701. package/test/util/log-parser.test.ts +61 -0
  702. package/test/util/module.test.ts +59 -0
  703. package/test/util/process.test.ts +128 -0
  704. package/test/util/telemetry-integration.test.ts +104 -0
  705. package/test/util/timeout.test.ts +21 -0
  706. package/test/util/which.test.ts +100 -0
  707. package/test/util/wildcard.test.ts +90 -0
  708. package/test-regex.js +50 -0
  709. package/tsconfig.json +23 -0
  710. package/LICENSE +0 -21
  711. /package/{postinstall.mjs → script/postinstall.mjs} +0 -0
@@ -0,0 +1,1348 @@
1
+ import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, decodePasteBytes, t, dim, fg } from "@opentui/core"
2
+ import { createEffect, createMemo, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js"
3
+ import "opentui-spinner/solid"
4
+ import path from "path"
5
+ import { fileURLToPath } from "url"
6
+ import { Filesystem } from "@/util/filesystem"
7
+ import { useLocal } from "@tui/context/local"
8
+ import { useTheme } from "@tui/context/theme"
9
+ import { EmptyBorder, SplitBorder } from "@tui/component/border"
10
+ import { useSDK } from "@tui/context/sdk"
11
+ import { useRoute } from "@tui/context/route"
12
+ import { useSync } from "@tui/context/sync"
13
+ import { MessageID, PartID } from "@/session/schema"
14
+ import { createStore, produce } from "solid-js/store"
15
+ import { useKeybind } from "@tui/context/keybind"
16
+ import { usePromptHistory, type PromptInfo } from "./history"
17
+ import { assign } from "./part"
18
+ import { usePromptStash } from "./stash"
19
+ import { DialogStash } from "../dialog-stash"
20
+ import { type AutocompleteRef, Autocomplete } from "./autocomplete"
21
+ import { useCommandDialog } from "../dialog-command"
22
+ import { useRenderer, type JSX } from "@opentui/solid"
23
+ import { Editor } from "@tui/util/editor"
24
+ import { useExit } from "../../context/exit"
25
+ import { Clipboard } from "../../util/clipboard"
26
+ import type { AssistantMessage, FilePart, UserMessage } from "@epoch-ai/sdk/v2"
27
+ import { TuiEvent } from "../../event"
28
+ import { iife } from "@/util/iife"
29
+ import { Locale } from "@/util/locale"
30
+ import { formatDuration } from "@/util/format"
31
+ import { createColors, createFrames } from "../../ui/spinner.ts"
32
+ import { useDialog } from "@tui/ui/dialog"
33
+ import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
34
+ import { DialogAlert } from "../../ui/dialog-alert"
35
+ import { useToast } from "../../ui/toast"
36
+ import { useKV } from "../../context/kv"
37
+ import { useTextareaKeybindings } from "../textarea-keybindings"
38
+ import { DialogSkill } from "../dialog-skill"
39
+ import { CONSOLE_MANAGED_ICON, consoleManagedProviderLabel } from "@tui/util/provider-origin"
40
+
41
+ export type PromptProps = {
42
+ sessionID?: string
43
+ workspaceID?: string
44
+ visible?: boolean
45
+ disabled?: boolean
46
+ onSubmit?: () => void
47
+ ref?: (ref: PromptRef | undefined) => void
48
+ hint?: JSX.Element
49
+ right?: JSX.Element
50
+ showPlaceholder?: boolean
51
+ placeholders?: {
52
+ normal?: string[]
53
+ shell?: string[]
54
+ }
55
+ }
56
+
57
+ export type PromptRef = {
58
+ focused: boolean
59
+ current: PromptInfo
60
+ set(prompt: PromptInfo): void
61
+ reset(): void
62
+ blur(): void
63
+ focus(): void
64
+ submit(): void
65
+ }
66
+
67
+ const money = new Intl.NumberFormat("en-US", {
68
+ style: "currency",
69
+ currency: "USD",
70
+ })
71
+
72
+ function randomIndex(count: number) {
73
+ if (count <= 0) return 0
74
+ return Math.floor(Math.random() * count)
75
+ }
76
+
77
+ export function Prompt(props: PromptProps) {
78
+ let input: TextareaRenderable
79
+ let anchor: BoxRenderable
80
+ let autocomplete: AutocompleteRef
81
+
82
+ const keybind = useKeybind()
83
+ const local = useLocal()
84
+ const sdk = useSDK()
85
+ const route = useRoute()
86
+ const sync = useSync()
87
+ const dialog = useDialog()
88
+ const toast = useToast()
89
+ const status = createMemo(() => sync.data.session_status?.[props.sessionID ?? ""] ?? { type: "idle" })
90
+ const history = usePromptHistory()
91
+ const stash = usePromptStash()
92
+ const command = useCommandDialog()
93
+ const renderer = useRenderer()
94
+ const { theme, syntax } = useTheme()
95
+ const kv = useKV()
96
+ const list = createMemo(() => props.placeholders?.normal ?? [])
97
+ const shell = createMemo(() => props.placeholders?.shell ?? [])
98
+ const [auto, setAuto] = createSignal<AutocompleteRef>()
99
+ const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
100
+ const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
101
+ const currentProviderLabel = createMemo(() => {
102
+ const current = local.model.current()
103
+ const provider = local.model.parsed().provider
104
+ if (!current) return provider
105
+ return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, current.providerID, provider)
106
+ })
107
+ const clerkModelName = createMemo(() => {
108
+ const sideProvider = sync.data.provider.find((p) => p.id === "local-side")
109
+ if (!sideProvider) return null
110
+ const firstModel = Object.values(sideProvider.models)[0]
111
+ return firstModel ? firstModel.name : null
112
+ })
113
+ const hasRightContent = createMemo(() => Boolean(props.right || activeOrgName()))
114
+
115
+ function promptModelWarning() {
116
+ toast.show({
117
+ variant: "warning",
118
+ message: "Connect a provider to send prompts",
119
+ duration: 3000,
120
+ })
121
+ if (sync.data.provider.length === 0) {
122
+ dialog.replace(() => <DialogProviderConnect />)
123
+ }
124
+ }
125
+
126
+ const textareaKeybindings = useTextareaKeybindings()
127
+
128
+ const fileStyleId = syntax().getStyleId("extmark.file")!
129
+ const agentStyleId = syntax().getStyleId("extmark.agent")!
130
+ const pasteStyleId = syntax().getStyleId("extmark.paste")!
131
+ let promptPartTypeId = 0
132
+
133
+ sdk.event.on(TuiEvent.PromptAppend.type, (evt) => {
134
+ if (!input || input.isDestroyed) return
135
+ input.insertText(evt.properties.text)
136
+ // @ts-ignore cursorContext is omitted from the generated OpenAPI schema due to z.any()
137
+ if (evt.properties.cursorContext) {
138
+ // @ts-ignore
139
+ setStore("prompt", "cursorContext", evt.properties.cursorContext)
140
+ }
141
+ setTimeout(() => {
142
+ // setTimeout is a workaround and needs to be addressed properly
143
+ if (!input || input.isDestroyed) return
144
+ input.getLayoutNode().markDirty()
145
+ input.gotoBufferEnd()
146
+ renderer.requestRender()
147
+ }, 0)
148
+ })
149
+
150
+ createEffect(() => {
151
+ if (props.disabled) input.cursorColor = theme.backgroundElement
152
+ if (!props.disabled) input.cursorColor = theme.text
153
+ })
154
+
155
+ const lastUserMessage = createMemo(() => {
156
+ if (!props.sessionID) return undefined
157
+ const messages = sync.data.message[props.sessionID]
158
+ if (!messages) return undefined
159
+ return messages.findLast((m): m is UserMessage => m.role === "user")
160
+ })
161
+
162
+ const usage = createMemo(() => {
163
+ if (!props.sessionID) return
164
+ const msg = sync.data.message[props.sessionID] ?? []
165
+ const last = msg.findLast((item): item is AssistantMessage => item.role === "assistant" && item.tokens.output > 0)
166
+ if (!last) return
167
+
168
+ const tokens =
169
+ last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
170
+ if (tokens <= 0) return
171
+
172
+ const model = sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
173
+ const pct = model?.limit.context ? `${Math.round((tokens / model.limit.context) * 100)}%` : undefined
174
+ const cost = msg.reduce((sum, item) => sum + (item.role === "assistant" ? item.cost : 0), 0)
175
+ return {
176
+ context: pct ? `${Locale.number(tokens)} (${pct})` : Locale.number(tokens),
177
+ cost: cost > 0 ? money.format(cost) : undefined,
178
+ }
179
+ })
180
+
181
+ const [store, setStore] = createStore<{
182
+ prompt: PromptInfo
183
+ mode: "normal" | "shell"
184
+ extmarkToPartIndex: Map<number, number>
185
+ interrupt: number
186
+ placeholder: number
187
+ }>({
188
+ placeholder: randomIndex(list().length),
189
+ prompt: {
190
+ input: "",
191
+ parts: [],
192
+ },
193
+ mode: "normal",
194
+ extmarkToPartIndex: new Map(),
195
+ interrupt: 0,
196
+ })
197
+
198
+ createEffect(
199
+ on(
200
+ () => props.sessionID,
201
+ () => {
202
+ setStore("placeholder", randomIndex(list().length))
203
+ },
204
+ { defer: true },
205
+ ),
206
+ )
207
+
208
+ // Initialize agent/model/variant from last user message when session changes
209
+ let syncedSessionID: string | undefined
210
+ createEffect(() => {
211
+ const sessionID = props.sessionID
212
+ const msg = lastUserMessage()
213
+
214
+ if (sessionID !== syncedSessionID) {
215
+ if (!sessionID || !msg) return
216
+
217
+ syncedSessionID = sessionID
218
+
219
+ // Only set agent if it's a primary agent (not a subagent)
220
+ const isPrimaryAgent = local.agent.list().some((x) => x.name === msg.agent)
221
+ if (msg.agent && isPrimaryAgent) {
222
+ local.agent.set(msg.agent)
223
+ if (msg.model) {
224
+ local.model.set(msg.model)
225
+ local.model.variant.set(msg.model.variant)
226
+ }
227
+ }
228
+ }
229
+ })
230
+
231
+ command.register(() => {
232
+ return [
233
+ {
234
+ title: "Clear prompt",
235
+ value: "prompt.clear",
236
+ category: "Prompt",
237
+ hidden: true,
238
+ onSelect: (dialog) => {
239
+ input.extmarks.clear()
240
+ input.clear()
241
+ dialog.clear()
242
+ },
243
+ },
244
+ {
245
+ title: "Submit prompt",
246
+ value: "prompt.submit",
247
+ keybind: "input_submit",
248
+ category: "Prompt",
249
+ hidden: true,
250
+ onSelect: (dialog) => {
251
+ if (!input.focused) return
252
+ submit()
253
+ dialog.clear()
254
+ },
255
+ },
256
+ {
257
+ title: "Paste",
258
+ value: "prompt.paste",
259
+ keybind: "input_paste",
260
+ category: "Prompt",
261
+ hidden: true,
262
+ onSelect: async () => {
263
+ const content = await Clipboard.read()
264
+ if (content?.mime.startsWith("image/")) {
265
+ await pasteAttachment({
266
+ filename: "clipboard",
267
+ mime: content.mime,
268
+ content: content.data,
269
+ })
270
+ }
271
+ },
272
+ },
273
+ {
274
+ title: "Interrupt session",
275
+ value: "session.interrupt",
276
+ keybind: "session_interrupt",
277
+ category: "Session",
278
+ hidden: true,
279
+ enabled: status().type !== "idle",
280
+ onSelect: (dialog) => {
281
+ if (autocomplete.visible) return
282
+ if (!input.focused) return
283
+ // TODO: this should be its own command
284
+ if (store.mode === "shell") {
285
+ setStore("mode", "normal")
286
+ return
287
+ }
288
+ if (!props.sessionID) return
289
+
290
+ setStore("interrupt", store.interrupt + 1)
291
+
292
+ setTimeout(() => {
293
+ setStore("interrupt", 0)
294
+ }, 5000)
295
+
296
+ if (store.interrupt >= 2) {
297
+ sdk.client.session.abort({
298
+ sessionID: props.sessionID,
299
+ })
300
+ setStore("interrupt", 0)
301
+ }
302
+ dialog.clear()
303
+ },
304
+ },
305
+ {
306
+ title: "Open editor",
307
+ category: "Session",
308
+ keybind: "editor_open",
309
+ value: "prompt.editor",
310
+ slash: {
311
+ name: "editor",
312
+ },
313
+ onSelect: async (dialog) => {
314
+ dialog.clear()
315
+
316
+ // replace summarized text parts with the actual text
317
+ const text = store.prompt.parts
318
+ .filter((p) => p.type === "text")
319
+ .reduce((acc, p) => {
320
+ if (!p.source) return acc
321
+ return acc.replace(p.source.text.value, p.text)
322
+ }, store.prompt.input)
323
+
324
+ const nonTextParts = store.prompt.parts.filter((p) => p.type !== "text")
325
+
326
+ const value = text
327
+ const content = await Editor.open({ value, renderer })
328
+ if (!content) return
329
+
330
+ input.setText(content)
331
+
332
+ // Update positions for nonTextParts based on their location in new content
333
+ // Filter out parts whose virtual text was deleted
334
+ // this handles a case where the user edits the text in the editor
335
+ // such that the virtual text moves around or is deleted
336
+ const updatedNonTextParts = nonTextParts
337
+ .map((part) => {
338
+ let virtualText = ""
339
+ if (part.type === "file" && part.source?.text) {
340
+ virtualText = part.source.text.value
341
+ } else if (part.type === "agent" && part.source) {
342
+ virtualText = part.source.value
343
+ }
344
+
345
+ if (!virtualText) return part
346
+
347
+ const newStart = content.indexOf(virtualText)
348
+ // if the virtual text is deleted, remove the part
349
+ if (newStart === -1) return null
350
+
351
+ const newEnd = newStart + virtualText.length
352
+
353
+ if (part.type === "file" && part.source?.text) {
354
+ return {
355
+ ...part,
356
+ source: {
357
+ ...part.source,
358
+ text: {
359
+ ...part.source.text,
360
+ start: newStart,
361
+ end: newEnd,
362
+ },
363
+ },
364
+ }
365
+ }
366
+
367
+ if (part.type === "agent" && part.source) {
368
+ return {
369
+ ...part,
370
+ source: {
371
+ ...part.source,
372
+ start: newStart,
373
+ end: newEnd,
374
+ },
375
+ }
376
+ }
377
+
378
+ return part
379
+ })
380
+ .filter((part) => part !== null)
381
+
382
+ setStore("prompt", {
383
+ input: content,
384
+ // keep only the non-text parts because the text parts were
385
+ // already expanded inline
386
+ parts: updatedNonTextParts,
387
+ })
388
+ restoreExtmarksFromParts(updatedNonTextParts)
389
+ input.cursorOffset = Bun.stringWidth(content)
390
+ },
391
+ },
392
+ {
393
+ title: "Skills",
394
+ value: "prompt.skills",
395
+ category: "Prompt",
396
+ slash: {
397
+ name: "skills",
398
+ },
399
+ onSelect: () => {
400
+ dialog.replace(() => (
401
+ <DialogSkill
402
+ onSelect={(skill) => {
403
+ input.setText(`/${skill} `)
404
+ setStore("prompt", {
405
+ input: `/${skill} `,
406
+ parts: [],
407
+ })
408
+ input.gotoBufferEnd()
409
+ }}
410
+ />
411
+ ))
412
+ },
413
+ },
414
+ ]
415
+ })
416
+
417
+ const ref: PromptRef = {
418
+ get focused() {
419
+ return input.focused
420
+ },
421
+ get current() {
422
+ return store.prompt
423
+ },
424
+ focus() {
425
+ input.focus()
426
+ },
427
+ blur() {
428
+ input.blur()
429
+ },
430
+ set(prompt) {
431
+ input.setText(prompt.input)
432
+ setStore("prompt", prompt)
433
+ restoreExtmarksFromParts(prompt.parts)
434
+ input.gotoBufferEnd()
435
+ },
436
+ reset() {
437
+ input.clear()
438
+ input.extmarks.clear()
439
+ setStore("prompt", {
440
+ input: "",
441
+ parts: [],
442
+ })
443
+ setStore("extmarkToPartIndex", new Map())
444
+ },
445
+ submit() {
446
+ submit()
447
+ },
448
+ }
449
+
450
+ onCleanup(() => {
451
+ props.ref?.(undefined)
452
+ })
453
+
454
+ createEffect(() => {
455
+ if (!input || input.isDestroyed) return
456
+ if (props.visible === false || dialog.stack.length > 0) {
457
+ input.blur()
458
+ return
459
+ }
460
+
461
+ // Slot/plugin updates can remount the background prompt while a dialog is open.
462
+ // Keep focus with the dialog and let the prompt reclaim it after the dialog closes.
463
+ input.focus()
464
+ })
465
+
466
+ createEffect(() => {
467
+ if (!input || input.isDestroyed) return
468
+ input.traits = {
469
+ capture: auto()?.visible ? ["escape", "navigate", "submit", "tab"] : undefined,
470
+ suspend: !!props.disabled || store.mode === "shell",
471
+ status: store.mode === "shell" ? "SHELL" : undefined,
472
+ }
473
+ })
474
+
475
+ function restoreExtmarksFromParts(parts: PromptInfo["parts"]) {
476
+ input.extmarks.clear()
477
+ setStore("extmarkToPartIndex", new Map())
478
+
479
+ parts.forEach((part, partIndex) => {
480
+ let start = 0
481
+ let end = 0
482
+ let virtualText = ""
483
+ let styleId: number | undefined
484
+
485
+ if (part.type === "file" && part.source?.text) {
486
+ start = part.source.text.start
487
+ end = part.source.text.end
488
+ virtualText = part.source.text.value
489
+ styleId = fileStyleId
490
+ } else if (part.type === "agent" && part.source) {
491
+ start = part.source.start
492
+ end = part.source.end
493
+ virtualText = part.source.value
494
+ styleId = agentStyleId
495
+ } else if (part.type === "text" && part.source?.text) {
496
+ start = part.source.text.start
497
+ end = part.source.text.end
498
+ virtualText = part.source.text.value
499
+ styleId = pasteStyleId
500
+ }
501
+
502
+ if (virtualText) {
503
+ const extmarkId = input.extmarks.create({
504
+ start,
505
+ end,
506
+ virtual: true,
507
+ styleId,
508
+ typeId: promptPartTypeId,
509
+ })
510
+ setStore("extmarkToPartIndex", (map: Map<number, number>) => {
511
+ const newMap = new Map(map)
512
+ newMap.set(extmarkId, partIndex)
513
+ return newMap
514
+ })
515
+ }
516
+ })
517
+ }
518
+
519
+ function syncExtmarksWithPromptParts() {
520
+ const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
521
+ setStore(
522
+ produce((draft) => {
523
+ const newMap = new Map<number, number>()
524
+ const newParts: typeof draft.prompt.parts = []
525
+
526
+ for (const extmark of allExtmarks) {
527
+ const partIndex = draft.extmarkToPartIndex.get(extmark.id)
528
+ if (partIndex !== undefined) {
529
+ const part = draft.prompt.parts[partIndex]
530
+ if (part) {
531
+ if (part.type === "agent" && part.source) {
532
+ part.source.start = extmark.start
533
+ part.source.end = extmark.end
534
+ } else if (part.type === "file" && part.source?.text) {
535
+ part.source.text.start = extmark.start
536
+ part.source.text.end = extmark.end
537
+ } else if (part.type === "text" && part.source?.text) {
538
+ part.source.text.start = extmark.start
539
+ part.source.text.end = extmark.end
540
+ }
541
+ newMap.set(extmark.id, newParts.length)
542
+ newParts.push(part)
543
+ }
544
+ }
545
+ }
546
+
547
+ draft.extmarkToPartIndex = newMap
548
+ draft.prompt.parts = newParts
549
+ }),
550
+ )
551
+ }
552
+
553
+ command.register(() => [
554
+ {
555
+ title: "Stash prompt",
556
+ value: "prompt.stash",
557
+ category: "Prompt",
558
+ enabled: !!store.prompt.input,
559
+ onSelect: (dialog) => {
560
+ if (!store.prompt.input) return
561
+ stash.push({
562
+ input: store.prompt.input,
563
+ parts: store.prompt.parts,
564
+ })
565
+ input.extmarks.clear()
566
+ input.clear()
567
+ setStore("prompt", { input: "", parts: [] })
568
+ setStore("extmarkToPartIndex", new Map())
569
+ dialog.clear()
570
+ },
571
+ },
572
+ {
573
+ title: "Stash pop",
574
+ value: "prompt.stash.pop",
575
+ category: "Prompt",
576
+ enabled: stash.list().length > 0,
577
+ onSelect: (dialog) => {
578
+ const entry = stash.pop()
579
+ if (entry) {
580
+ input.setText(entry.input)
581
+ setStore("prompt", { input: entry.input, parts: entry.parts })
582
+ restoreExtmarksFromParts(entry.parts)
583
+ input.gotoBufferEnd()
584
+ }
585
+ dialog.clear()
586
+ },
587
+ },
588
+ {
589
+ title: "Stash list",
590
+ value: "prompt.stash.list",
591
+ category: "Prompt",
592
+ enabled: stash.list().length > 0,
593
+ onSelect: (dialog) => {
594
+ dialog.replace(() => (
595
+ <DialogStash
596
+ onSelect={(entry) => {
597
+ input.setText(entry.input)
598
+ setStore("prompt", { input: entry.input, parts: entry.parts })
599
+ restoreExtmarksFromParts(entry.parts)
600
+ input.gotoBufferEnd()
601
+ }}
602
+ />
603
+ ))
604
+ },
605
+ },
606
+ ])
607
+
608
+ async function submit() {
609
+ if (props.disabled) return
610
+ if (autocomplete?.visible) return
611
+ if (!store.prompt.input) return
612
+ const trimmed = store.prompt.input.trim()
613
+ if (trimmed === "exit" || trimmed === "quit" || trimmed === ":q") {
614
+ exit()
615
+ return
616
+ }
617
+ const selectedModel = local.model.current()
618
+ if (!selectedModel) {
619
+ promptModelWarning()
620
+ return
621
+ }
622
+
623
+ let sessionID = props.sessionID
624
+ if (sessionID == null) {
625
+ const res = await sdk.client.session.create({
626
+ workspaceID: props.workspaceID,
627
+ })
628
+
629
+ if (res.error) {
630
+ console.log("Creating a session failed:", res.error)
631
+
632
+ toast.show({
633
+ message: "Creating a session failed. Open console for more details.",
634
+ variant: "error",
635
+ })
636
+
637
+ return
638
+ }
639
+
640
+ sessionID = res.data.id
641
+ }
642
+
643
+ const messageID = MessageID.ascending()
644
+ let inputText = store.prompt.input
645
+
646
+ // Expand pasted text inline before submitting
647
+ const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
648
+ const sortedExtmarks = allExtmarks.sort((a: { start: number }, b: { start: number }) => b.start - a.start)
649
+
650
+ for (const extmark of sortedExtmarks) {
651
+ const partIndex = store.extmarkToPartIndex.get(extmark.id)
652
+ if (partIndex !== undefined) {
653
+ const part = store.prompt.parts[partIndex]
654
+ if (part?.type === "text" && part.text) {
655
+ const before = inputText.slice(0, extmark.start)
656
+ const after = inputText.slice(extmark.end)
657
+ inputText = before + part.text + after
658
+ }
659
+ }
660
+ }
661
+
662
+ // Filter out text parts (pasted content) since they're now expanded inline
663
+ const nonTextParts = store.prompt.parts.filter((part) => part.type !== "text")
664
+
665
+ // Capture mode before it gets reset
666
+ const currentMode = store.mode
667
+ const variant = local.model.variant.current()
668
+
669
+ if (store.mode === "shell") {
670
+ sdk.client.session.shell({
671
+ sessionID,
672
+ agent: local.agent.current().name,
673
+ model: {
674
+ providerID: selectedModel.providerID,
675
+ modelID: selectedModel.modelID,
676
+ },
677
+ command: inputText,
678
+ })
679
+ setStore("mode", "normal")
680
+ } else if (
681
+ inputText.startsWith("/") &&
682
+ iife(() => {
683
+ const firstLine = inputText.split("\n")[0]
684
+ const command = firstLine.split(" ")[0].slice(1)
685
+ return sync.data.command.some((x) => x.name === command)
686
+ })
687
+ ) {
688
+ // Parse command from first line, preserve multi-line content in arguments
689
+ const firstLineEnd = inputText.indexOf("\n")
690
+ const firstLine = firstLineEnd === -1 ? inputText : inputText.slice(0, firstLineEnd)
691
+ const [command, ...firstLineArgs] = firstLine.split(" ")
692
+ const restOfInput = firstLineEnd === -1 ? "" : inputText.slice(firstLineEnd + 1)
693
+ const args = firstLineArgs.join(" ") + (restOfInput ? "\n" + restOfInput : "")
694
+
695
+ sdk.client.session.command({
696
+ sessionID,
697
+ command: command.slice(1),
698
+ arguments: args,
699
+ agent: local.agent.current().name,
700
+ model: `${selectedModel.providerID}/${selectedModel.modelID}`,
701
+ messageID,
702
+ variant,
703
+ parts: nonTextParts
704
+ .filter((x) => x.type === "file")
705
+ .map((x) => ({
706
+ id: PartID.ascending(),
707
+ ...x,
708
+ })),
709
+ })
710
+ } else {
711
+ sdk.client.session
712
+ .prompt({
713
+ sessionID,
714
+ ...selectedModel,
715
+ messageID,
716
+ agent: local.agent.current().name,
717
+ model: selectedModel,
718
+ variant,
719
+ yolo: local.yolo.current(),
720
+ // @ts-ignore
721
+ cursorContext: store.prompt.cursorContext,
722
+ parts: [
723
+ {
724
+ id: PartID.ascending(),
725
+ type: "text",
726
+ text: inputText,
727
+ },
728
+ ...nonTextParts.map(assign),
729
+ ],
730
+ } as any)
731
+ .catch(() => {})
732
+ }
733
+ history.append({
734
+ ...store.prompt,
735
+ mode: currentMode,
736
+ })
737
+ input.extmarks.clear()
738
+ setStore("prompt", {
739
+ input: "",
740
+ parts: [],
741
+ })
742
+ setStore("extmarkToPartIndex", new Map())
743
+ props.onSubmit?.()
744
+
745
+ // temporary hack to make sure the message is sent
746
+ if (!props.sessionID)
747
+ setTimeout(() => {
748
+ route.navigate({
749
+ type: "session",
750
+ sessionID,
751
+ })
752
+ }, 50)
753
+ input.clear()
754
+ }
755
+ const exit = useExit()
756
+
757
+ function pasteText(text: string, virtualText: string) {
758
+ const currentOffset = input.visualCursor.offset
759
+ const extmarkStart = currentOffset
760
+ const extmarkEnd = extmarkStart + virtualText.length
761
+
762
+ input.insertText(virtualText + " ")
763
+
764
+ const extmarkId = input.extmarks.create({
765
+ start: extmarkStart,
766
+ end: extmarkEnd,
767
+ virtual: true,
768
+ styleId: pasteStyleId,
769
+ typeId: promptPartTypeId,
770
+ })
771
+
772
+ setStore(
773
+ produce((draft) => {
774
+ const partIndex = draft.prompt.parts.length
775
+ draft.prompt.parts.push({
776
+ type: "text" as const,
777
+ text,
778
+ source: {
779
+ text: {
780
+ start: extmarkStart,
781
+ end: extmarkEnd,
782
+ value: virtualText,
783
+ },
784
+ },
785
+ })
786
+ draft.extmarkToPartIndex.set(extmarkId, partIndex)
787
+ }),
788
+ )
789
+ }
790
+
791
+ async function pasteAttachment(file: { filename?: string; filepath?: string; content: string; mime: string }) {
792
+ const currentOffset = input.visualCursor.offset
793
+ const extmarkStart = currentOffset
794
+ const pdf = file.mime === "application/pdf"
795
+ const count = store.prompt.parts.filter((x) => {
796
+ if (x.type !== "file") return false
797
+ if (pdf) return x.mime === "application/pdf"
798
+ return x.mime.startsWith("image/")
799
+ }).length
800
+ const virtualText = pdf ? `[PDF ${count + 1}]` : `[Image ${count + 1}]`
801
+ const extmarkEnd = extmarkStart + virtualText.length
802
+ const textToInsert = virtualText + " "
803
+
804
+ input.insertText(textToInsert)
805
+
806
+ const extmarkId = input.extmarks.create({
807
+ start: extmarkStart,
808
+ end: extmarkEnd,
809
+ virtual: true,
810
+ styleId: pasteStyleId,
811
+ typeId: promptPartTypeId,
812
+ })
813
+
814
+ const part: Omit<FilePart, "id" | "messageID" | "sessionID"> = {
815
+ type: "file" as const,
816
+ mime: file.mime,
817
+ filename: file.filename,
818
+ url: `data:${file.mime};base64,${file.content}`,
819
+ source: {
820
+ type: "file",
821
+ path: file.filepath ?? file.filename ?? "",
822
+ text: {
823
+ start: extmarkStart,
824
+ end: extmarkEnd,
825
+ value: virtualText,
826
+ },
827
+ },
828
+ }
829
+ setStore(
830
+ produce((draft) => {
831
+ const partIndex = draft.prompt.parts.length
832
+ draft.prompt.parts.push(part)
833
+ draft.extmarkToPartIndex.set(extmarkId, partIndex)
834
+ }),
835
+ )
836
+ return
837
+ }
838
+
839
+ const highlight = createMemo(() => {
840
+ if (keybind.leader) return theme.border
841
+ if (store.mode === "shell") return theme.primary
842
+ return local.agent.color(local.agent.current().name)
843
+ })
844
+
845
+ const showVariant = createMemo(() => {
846
+ const variants = local.model.variant.list()
847
+ if (variants.length === 0) return false
848
+ const current = local.model.variant.current()
849
+ return !!current
850
+ })
851
+
852
+ const placeholderText = createMemo(() => {
853
+ if (props.showPlaceholder === false) return undefined
854
+ if (store.mode === "shell") {
855
+ if (!shell().length) return undefined
856
+ const example = shell()[store.placeholder % shell().length]
857
+ return `Run a command... "${example}"`
858
+ }
859
+ if (!list().length) return undefined
860
+ return `Ask anything... "${list()[store.placeholder % list().length]}"`
861
+ })
862
+
863
+ const spinnerDef = createMemo(() => {
864
+ const color = local.agent.color(local.agent.current().name)
865
+ return {
866
+ frames: createFrames({
867
+ color,
868
+ style: "blocks",
869
+ inactiveFactor: 0.6,
870
+ // enableFading: false,
871
+ minAlpha: 0.3,
872
+ }),
873
+ color: createColors({
874
+ color,
875
+ style: "blocks",
876
+ inactiveFactor: 0.6,
877
+ // enableFading: false,
878
+ minAlpha: 0.3,
879
+ }),
880
+ }
881
+ })
882
+
883
+ return (
884
+ <>
885
+ <Autocomplete
886
+ sessionID={props.sessionID}
887
+ ref={(r) => {
888
+ autocomplete = r
889
+ setAuto(() => r)
890
+ }}
891
+ anchor={() => anchor}
892
+ input={() => input}
893
+ setPrompt={(cb) => {
894
+ setStore("prompt", produce(cb))
895
+ }}
896
+ setExtmark={(partIndex, extmarkId) => {
897
+ setStore("extmarkToPartIndex", (map: Map<number, number>) => {
898
+ const newMap = new Map(map)
899
+ newMap.set(extmarkId, partIndex)
900
+ return newMap
901
+ })
902
+ }}
903
+ value={store.prompt.input}
904
+ fileStyleId={fileStyleId}
905
+ agentStyleId={agentStyleId}
906
+ promptPartTypeId={() => promptPartTypeId}
907
+ />
908
+ <box ref={(r) => (anchor = r)} visible={props.visible !== false}>
909
+ <box
910
+ border={["left"]}
911
+ borderColor={highlight()}
912
+ customBorderChars={{
913
+ ...SplitBorder.customBorderChars,
914
+ bottomLeft: "╹",
915
+ }}
916
+ >
917
+ <box
918
+ paddingLeft={2}
919
+ paddingRight={2}
920
+ paddingTop={1}
921
+ flexShrink={0}
922
+ backgroundColor={theme.backgroundElement}
923
+ flexGrow={1}
924
+ >
925
+ <textarea
926
+ placeholder={placeholderText()}
927
+ placeholderColor={theme.textMuted}
928
+ textColor={keybind.leader ? theme.textMuted : theme.text}
929
+ focusedTextColor={keybind.leader ? theme.textMuted : theme.text}
930
+ minHeight={1}
931
+ maxHeight={6}
932
+ onContentChange={() => {
933
+ const value = input.plainText
934
+ setStore("prompt", "input", value)
935
+ autocomplete.onInput(value)
936
+ syncExtmarksWithPromptParts()
937
+ }}
938
+ keyBindings={textareaKeybindings()}
939
+ onKeyDown={async (e) => {
940
+ if (props.disabled) {
941
+ e.preventDefault()
942
+ return
943
+ }
944
+ // Check clipboard for images before terminal-handled paste runs.
945
+ // This helps terminals that forward Ctrl+V to the app; Windows
946
+ // Terminal 1.25+ usually handles Ctrl+V before this path.
947
+ if (keybind.match("input_paste", e)) {
948
+ const content = await Clipboard.read()
949
+ if (content?.mime.startsWith("image/")) {
950
+ e.preventDefault()
951
+ await pasteAttachment({
952
+ filename: "clipboard",
953
+ mime: content.mime,
954
+ content: content.data,
955
+ })
956
+ return
957
+ }
958
+ // If no image, let the default paste behavior continue
959
+ }
960
+ if (keybind.match("input_clear", e) && store.prompt.input !== "") {
961
+ input.clear()
962
+ input.extmarks.clear()
963
+ setStore("prompt", {
964
+ input: "",
965
+ parts: [],
966
+ })
967
+ setStore("extmarkToPartIndex", new Map())
968
+ return
969
+ }
970
+ if (keybind.match("app_exit", e)) {
971
+ if (store.prompt.input === "") {
972
+ await exit()
973
+ // Don't preventDefault - let textarea potentially handle the event
974
+ e.preventDefault()
975
+ return
976
+ }
977
+ }
978
+ if (e.name === "!" && input.visualCursor.offset === 0) {
979
+ setStore("placeholder", randomIndex(shell().length))
980
+ setStore("mode", "shell")
981
+ e.preventDefault()
982
+ return
983
+ }
984
+ if (store.mode === "shell") {
985
+ if ((e.name === "backspace" && input.visualCursor.offset === 0) || e.name === "escape") {
986
+ setStore("mode", "normal")
987
+ e.preventDefault()
988
+ return
989
+ }
990
+ }
991
+ if (store.mode === "normal") autocomplete.onKeyDown(e)
992
+ if (!autocomplete.visible) {
993
+ if (
994
+ (keybind.match("history_previous", e) && input.cursorOffset === 0) ||
995
+ (keybind.match("history_next", e) && input.cursorOffset === input.plainText.length)
996
+ ) {
997
+ const direction = keybind.match("history_previous", e) ? -1 : 1
998
+ const item = history.move(direction, input.plainText)
999
+
1000
+ if (item) {
1001
+ input.setText(item.input)
1002
+ setStore("prompt", item)
1003
+ setStore("mode", item.mode ?? "normal")
1004
+ restoreExtmarksFromParts(item.parts)
1005
+ e.preventDefault()
1006
+ if (direction === -1) input.cursorOffset = 0
1007
+ if (direction === 1) input.cursorOffset = input.plainText.length
1008
+ }
1009
+ return
1010
+ }
1011
+
1012
+ if (keybind.match("history_previous", e) && input.visualCursor.visualRow === 0) input.cursorOffset = 0
1013
+ if (keybind.match("history_next", e) && input.visualCursor.visualRow === input.height - 1)
1014
+ input.cursorOffset = input.plainText.length
1015
+ }
1016
+ }}
1017
+ onSubmit={submit}
1018
+ onPaste={async (event: PasteEvent) => {
1019
+ if (props.disabled) {
1020
+ event.preventDefault()
1021
+ return
1022
+ }
1023
+
1024
+ // Normalize line endings at the boundary
1025
+ // Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste
1026
+ // Replace CRLF first, then any remaining CR
1027
+ const normalizedText = decodePasteBytes(event.bytes).replace(/\r\n/g, "\n").replace(/\r/g, "\n")
1028
+ const pastedContent = normalizedText.trim()
1029
+
1030
+ // Windows Terminal <1.25 can surface image-only clipboard as an
1031
+ // empty bracketed paste. Windows Terminal 1.25+ does not.
1032
+ if (!pastedContent) {
1033
+ command.trigger("prompt.paste")
1034
+ return
1035
+ }
1036
+
1037
+ const filepath = iife(() => {
1038
+ const raw = pastedContent.replace(/^['"]+|['"]+$/g, "")
1039
+ if (raw.startsWith("file://")) {
1040
+ try {
1041
+ return fileURLToPath(raw)
1042
+ } catch {}
1043
+ }
1044
+ if (process.platform === "win32") return raw
1045
+ return raw.replace(/\\(.)/g, "$1")
1046
+ })
1047
+ const isUrl = /^(https?):\/\//.test(filepath)
1048
+ if (!isUrl) {
1049
+ try {
1050
+ const mime = Filesystem.mimeType(filepath)
1051
+ const filename = path.basename(filepath)
1052
+ // Handle SVG as raw text content, not as base64 image
1053
+ if (mime === "image/svg+xml") {
1054
+ event.preventDefault()
1055
+ const content = await Filesystem.readText(filepath).catch(() => {})
1056
+ if (content) {
1057
+ pasteText(content, `[SVG: ${filename ?? "image"}]`)
1058
+ return
1059
+ }
1060
+ }
1061
+ if (mime.startsWith("image/") || mime === "application/pdf") {
1062
+ event.preventDefault()
1063
+ const content = await Filesystem.readArrayBuffer(filepath)
1064
+ .then((buffer) => Buffer.from(buffer).toString("base64"))
1065
+ .catch(() => {})
1066
+ if (content) {
1067
+ await pasteAttachment({
1068
+ filename,
1069
+ filepath,
1070
+ mime,
1071
+ content,
1072
+ })
1073
+ return
1074
+ }
1075
+ }
1076
+ } catch {}
1077
+ }
1078
+
1079
+ const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
1080
+ if (
1081
+ (lineCount >= 3 || pastedContent.length > 150) &&
1082
+ !sync.data.config.experimental?.disable_paste_summary
1083
+ ) {
1084
+ event.preventDefault()
1085
+ pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
1086
+ return
1087
+ }
1088
+
1089
+ // Force layout update and render for the pasted content
1090
+ setTimeout(() => {
1091
+ // setTimeout is a workaround and needs to be addressed properly
1092
+ if (!input || input.isDestroyed) return
1093
+ input.getLayoutNode().markDirty()
1094
+ renderer.requestRender()
1095
+ }, 0)
1096
+ }}
1097
+ ref={(r: TextareaRenderable) => {
1098
+ input = r
1099
+ if (promptPartTypeId === 0) {
1100
+ promptPartTypeId = input.extmarks.registerType("prompt-part")
1101
+ }
1102
+ props.ref?.(ref)
1103
+ setTimeout(() => {
1104
+ // setTimeout is a workaround and needs to be addressed properly
1105
+ if (!input || input.isDestroyed) return
1106
+ input.cursorColor = theme.text
1107
+ }, 0)
1108
+ }}
1109
+ onMouseDown={(r: MouseEvent) => r.target?.focus()}
1110
+ focusedBackgroundColor={theme.backgroundElement}
1111
+ cursorColor={theme.text}
1112
+ syntaxStyle={syntax()}
1113
+ />
1114
+ <box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between">
1115
+ <box flexDirection="row" gap={4}>
1116
+ <box flexDirection="column">
1117
+ <Show when={store.mode === "shell"}>
1118
+ <text fg={highlight()}>Shell</text>
1119
+ </Show>
1120
+ <Show when={store.mode === "normal"}>
1121
+ <box flexDirection="row" gap={1}>
1122
+ <text fg={theme.success}>•</text>
1123
+ <text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
1124
+ Coder: {local.model.parsed().model}
1125
+ </text>
1126
+ <text fg={theme.textMuted}>{currentProviderLabel()}</text>
1127
+ <Show when={showVariant()}>
1128
+ <text fg={theme.textMuted}>·</text>
1129
+ <text>
1130
+ <span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span>
1131
+ </text>
1132
+ </Show>
1133
+ </box>
1134
+ <Show when={clerkModelName()}>
1135
+ <box flexDirection="row" gap={1}>
1136
+ <text fg={theme.success}>•</text>
1137
+ <text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
1138
+ Clerk: {clerkModelName()}
1139
+ </text>
1140
+ </box>
1141
+ </Show>
1142
+ <box flexDirection="row" gap={1}>
1143
+ <Show
1144
+ when={local.yolo.current()}
1145
+ fallback={
1146
+ <box flexDirection="row" gap={1}>
1147
+ <text fg={theme.textMuted}>•</text>
1148
+ <text fg={theme.textMuted}>Interactive</text>
1149
+ </box>
1150
+ }
1151
+ >
1152
+ <Show when={status().type === "busy"} fallback={<text fg={theme.warning}>•</text>}>
1153
+ <spinner
1154
+ frames={createFrames({ color: theme.warning })}
1155
+ color={createColors({ color: theme.warning })}
1156
+ />
1157
+ </Show>
1158
+ <text fg={theme.warning}>{status().type === "busy" ? "Autonomous Mode" : "YOLO"}</text>
1159
+ </Show>
1160
+ </box>
1161
+ </Show>
1162
+ </box>
1163
+ <Show when={store.mode === "normal"}>
1164
+ <box flexDirection="column">
1165
+ {["spec", "map", "ground"].map((server) => (
1166
+ <box flexDirection="row" gap={1}>
1167
+ <text fg={sync.data.mcp[server]?.status === "connected" ? theme.success : theme.error}>
1168
+ {sync.data.mcp[server]?.status === "connected" ? "●" : "○"}
1169
+ </text>
1170
+ <text fg={theme.textMuted}>{server}</text>
1171
+ </box>
1172
+ ))}
1173
+ </box>
1174
+ </Show>
1175
+ </box>
1176
+ <Show when={hasRightContent()}>
1177
+ <box flexDirection="row" gap={1} alignItems="center">
1178
+ {props.right}
1179
+ <Show when={activeOrgName()}>
1180
+ <text
1181
+ fg={theme.textMuted}
1182
+ onMouseUp={() => {
1183
+ if (!canSwitchOrgs()) return
1184
+ command.trigger("console.org.switch")
1185
+ }}
1186
+ >
1187
+ {`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
1188
+ </text>
1189
+ </Show>
1190
+ </box>
1191
+ </Show>
1192
+ </box>
1193
+ </box>
1194
+ </box>
1195
+ <box
1196
+ height={1}
1197
+ border={["left"]}
1198
+ borderColor={highlight()}
1199
+ customBorderChars={{
1200
+ ...EmptyBorder,
1201
+ vertical: theme.backgroundElement.a !== 0 ? "╹" : " ",
1202
+ }}
1203
+ >
1204
+ <box
1205
+ height={1}
1206
+ border={["bottom"]}
1207
+ borderColor={theme.backgroundElement}
1208
+ customBorderChars={
1209
+ theme.backgroundElement.a !== 0
1210
+ ? {
1211
+ ...EmptyBorder,
1212
+ horizontal: "▀",
1213
+ }
1214
+ : {
1215
+ ...EmptyBorder,
1216
+ horizontal: " ",
1217
+ }
1218
+ }
1219
+ />
1220
+ </box>
1221
+ <box flexDirection="row" justifyContent="space-between">
1222
+ <Show
1223
+ when={status().type !== "idle"}
1224
+ fallback={
1225
+ <box flexDirection="row" gap={2}>
1226
+ {props.hint ?? <text />}
1227
+ <Show when={store.mode === "normal"}>
1228
+ <text fg={theme.text}>
1229
+ {keybind.print("yolo_toggle")} <span style={{ fg: theme.textMuted }}>mode</span>
1230
+ </text>
1231
+ </Show>
1232
+ </box>
1233
+ }
1234
+ >
1235
+ <box
1236
+ flexDirection="row"
1237
+ gap={1}
1238
+ flexGrow={1}
1239
+ justifyContent={status().type === "retry" ? "space-between" : "flex-start"}
1240
+ >
1241
+ <box flexShrink={0} flexDirection="row" gap={1}>
1242
+ <box marginLeft={1}>
1243
+ <Show when={kv.get("animations_enabled", true)} fallback={<text fg={theme.textMuted}>[⋯]</text>}>
1244
+ <spinner color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
1245
+ </Show>
1246
+ </box>
1247
+ <box flexDirection="row" gap={1} flexShrink={0}>
1248
+ {(() => {
1249
+ const retry = createMemo(() => {
1250
+ const s = status()
1251
+ if (s.type !== "retry") return
1252
+ return s
1253
+ })
1254
+ const message = createMemo(() => {
1255
+ const r = retry()
1256
+ if (!r) return
1257
+ if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
1258
+ return "gemini is way too hot right now"
1259
+ if (r.message.length > 80) return r.message.slice(0, 80) + "..."
1260
+ return r.message
1261
+ })
1262
+ const isTruncated = createMemo(() => {
1263
+ const r = retry()
1264
+ if (!r) return false
1265
+ return r.message.length > 120
1266
+ })
1267
+ const [seconds, setSeconds] = createSignal(0)
1268
+ onMount(() => {
1269
+ const timer = setInterval(() => {
1270
+ const next = retry()?.next
1271
+ if (next) setSeconds(Math.round((next - Date.now()) / 1000))
1272
+ }, 1000)
1273
+
1274
+ onCleanup(() => {
1275
+ clearInterval(timer)
1276
+ })
1277
+ })
1278
+ const handleMessageClick = () => {
1279
+ const r = retry()
1280
+ if (!r) return
1281
+ if (isTruncated()) {
1282
+ DialogAlert.show(dialog, "Retry Error", r.message)
1283
+ }
1284
+ }
1285
+
1286
+ const retryText = () => {
1287
+ const r = retry()
1288
+ if (!r) return ""
1289
+ const baseMessage = message()
1290
+ const truncatedHint = isTruncated() ? " (click to expand)" : ""
1291
+ const duration = formatDuration(seconds())
1292
+ const retryInfo = ` [retrying ${duration ? `in ${duration} ` : ""}attempt #${r.attempt}]`
1293
+ return baseMessage + truncatedHint + retryInfo
1294
+ }
1295
+
1296
+ return (
1297
+ <Show when={retry()}>
1298
+ <box onMouseUp={handleMessageClick}>
1299
+ <text fg={theme.error}>{retryText()}</text>
1300
+ </box>
1301
+ </Show>
1302
+ )
1303
+ })()}
1304
+ </box>
1305
+ </box>
1306
+ <text fg={store.interrupt > 0 ? theme.primary : theme.text}>
1307
+ esc{" "}
1308
+ <span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
1309
+ {store.interrupt > 0 ? "again to interrupt" : "interrupt"}
1310
+ </span>
1311
+ </text>
1312
+ </box>
1313
+ </Show>
1314
+ <Show when={status().type !== "retry"}>
1315
+ <box gap={2} flexDirection="row">
1316
+ <Switch>
1317
+ <Match when={store.mode === "normal"}>
1318
+ <Switch>
1319
+ <Match when={usage()}>
1320
+ {(item) => (
1321
+ <text fg={theme.textMuted} wrapMode="none">
1322
+ {item().context}
1323
+ </text>
1324
+ )}
1325
+ </Match>
1326
+ <Match when={true}>
1327
+ <text fg={theme.text}>
1328
+ {keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>agents</span>
1329
+ </text>
1330
+ </Match>
1331
+ </Switch>
1332
+ <text fg={theme.text}>
1333
+ {keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
1334
+ </text>
1335
+ </Match>
1336
+ <Match when={store.mode === "shell"}>
1337
+ <text fg={theme.text}>
1338
+ esc <span style={{ fg: theme.textMuted }}>exit shell mode</span>
1339
+ </text>
1340
+ </Match>
1341
+ </Switch>
1342
+ </box>
1343
+ </Show>
1344
+ </box>
1345
+ </box>
1346
+ </>
1347
+ )
1348
+ }