rovecode 0.4.0-beta.2 → 0.4.0

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 (428) hide show
  1. package/README.md +67 -69
  2. package/THIRD_PARTY_NOTICES.md +0 -44
  3. package/bin/rovecode.ts +21 -0
  4. package/package.json +16 -37
  5. package/src/account/keys.ts +97 -0
  6. package/src/account/login.ts +158 -0
  7. package/src/account/provision.ts +47 -0
  8. package/src/account/store.ts +63 -0
  9. package/src/acp/server.ts +373 -0
  10. package/src/cli/account-cmd.ts +116 -0
  11. package/src/cli/connect.ts +244 -0
  12. package/src/cli/context-cmd.ts +199 -0
  13. package/src/cli/dispatch.ts +109 -0
  14. package/src/cli/doctor.ts +324 -0
  15. package/src/cli/export.ts +278 -0
  16. package/src/cli/help.ts +240 -0
  17. package/src/cli/is-tui-invocation.ts +8 -0
  18. package/src/cli/main.ts +599 -0
  19. package/src/cli/market-cmd.ts +658 -0
  20. package/src/cli/mcp-market-cmd.ts +299 -0
  21. package/src/cli/output.ts +382 -0
  22. package/src/cli/repl.ts +172 -0
  23. package/src/cli/resume.ts +32 -0
  24. package/src/cli/run-limits.ts +78 -0
  25. package/src/cli/runtime.ts +792 -0
  26. package/src/cli/setup.ts +187 -0
  27. package/src/cli/update-cmd.ts +78 -0
  28. package/src/cli/workflow-cmd.ts +100 -0
  29. package/src/coding/checkpoints.ts +270 -0
  30. package/src/coding/diff.ts +136 -0
  31. package/src/coding/files.ts +339 -0
  32. package/src/coding/hashline.ts +319 -0
  33. package/src/coding/lsp.ts +406 -0
  34. package/src/coding/repomap-cache.ts +99 -0
  35. package/src/coding/repomap-files.ts +110 -0
  36. package/src/coding/repomap.ts +392 -0
  37. package/src/core/compaction.ts +399 -0
  38. package/src/core/config.ts +289 -0
  39. package/src/core/context-report.ts +228 -0
  40. package/src/core/context.ts +60 -0
  41. package/src/core/count-remote.ts +107 -0
  42. package/src/core/execpolicy-rules.ts +196 -0
  43. package/src/core/execpolicy.ts +385 -0
  44. package/src/core/executor.ts +397 -0
  45. package/src/core/guardrails.ts +400 -0
  46. package/src/core/hooks.ts +398 -0
  47. package/src/core/images.ts +230 -0
  48. package/src/core/intro.ts +236 -0
  49. package/src/core/loop.ts +621 -0
  50. package/src/core/modes.ts +372 -0
  51. package/src/core/orchestrator.ts +207 -0
  52. package/src/core/reflection.ts +165 -0
  53. package/src/core/sandbox-config.ts +167 -0
  54. package/src/core/session-images.ts +73 -0
  55. package/src/core/session.ts +398 -0
  56. package/src/core/settings.ts +98 -0
  57. package/src/core/stuck-detector.ts +273 -0
  58. package/src/core/tasks.ts +374 -0
  59. package/src/core/token-scale.ts +108 -0
  60. package/src/core/tool-output-budget.ts +166 -0
  61. package/src/core/tools.ts +288 -0
  62. package/src/core/types.ts +330 -0
  63. package/src/core/update-check.ts +171 -0
  64. package/src/core/update.ts +158 -0
  65. package/src/core/usage.ts +204 -0
  66. package/src/core/validate.ts +121 -0
  67. package/src/core/verify-gate.ts +159 -0
  68. package/src/core/verify.ts +237 -0
  69. package/src/core/voice.ts +158 -0
  70. package/src/core/win-job.ts +183 -0
  71. package/src/design/audit.ts +797 -0
  72. package/src/design/direction.ts +190 -0
  73. package/src/design/rules.ts +157 -0
  74. package/src/eval/bench.ts +150 -0
  75. package/src/eval/gauntlet-runner.ts +218 -0
  76. package/src/eval/gauntlet.ts +226 -0
  77. package/src/eval/grader.ts +186 -0
  78. package/src/eval/record.ts +202 -0
  79. package/src/eval/redact.ts +141 -0
  80. package/src/eval/replay.ts +147 -0
  81. package/src/eval/trajectory.ts +373 -0
  82. package/src/index.ts +17 -0
  83. package/src/market/catalogs/mcp-docs.json +111 -0
  84. package/src/market/catalogs/plugins.json +111 -0
  85. package/src/market/catalogs/skills.json +478 -0
  86. package/src/market/clone.ts +72 -0
  87. package/src/market/context-cost.ts +121 -0
  88. package/src/market/digest.ts +106 -0
  89. package/src/market/index.ts +22 -0
  90. package/src/market/install.ts +578 -0
  91. package/src/market/manifest.ts +187 -0
  92. package/src/market/prereq.ts +145 -0
  93. package/src/market/registry.ts +363 -0
  94. package/src/market/resolve.ts +111 -0
  95. package/src/market/types.ts +236 -0
  96. package/src/market/validate.ts +227 -0
  97. package/src/mcp/client.ts +431 -0
  98. package/src/mcp/config.ts +239 -0
  99. package/src/mcp/local-package.ts +211 -0
  100. package/src/mcp/market-catalog.ts +84 -0
  101. package/src/mcp/market-install.ts +289 -0
  102. package/src/mcp/market.ts +0 -0
  103. package/src/mcp/tools.ts +131 -0
  104. package/src/mcp/trust.ts +49 -0
  105. package/src/memory/blocks.ts +175 -0
  106. package/src/memory/recall.ts +355 -0
  107. package/src/memory/store.ts +105 -0
  108. package/src/memory/tools.ts +99 -0
  109. package/src/plugins/cli.ts +123 -0
  110. package/src/plugins/discover.ts +108 -0
  111. package/src/plugins/index.ts +50 -0
  112. package/src/plugins/init.ts +140 -0
  113. package/src/plugins/install.ts +184 -0
  114. package/src/plugins/load.ts +149 -0
  115. package/src/plugins/manifest.ts +106 -0
  116. package/src/plugins/state.ts +83 -0
  117. package/src/providers/auth.ts +293 -0
  118. package/src/providers/cache.ts +223 -0
  119. package/src/providers/catalog-local.ts +160 -0
  120. package/src/providers/catalog.ts +408 -0
  121. package/src/providers/middleware-context.ts +86 -0
  122. package/src/providers/middleware.ts +373 -0
  123. package/src/providers/profile-glm53.ts +111 -0
  124. package/src/providers/profile-sonnet5-persona.ts +65 -0
  125. package/src/providers/profile-sonnet5-voice.ts +23 -0
  126. package/src/providers/profiles.ts +156 -0
  127. package/src/providers/provider-config.ts +311 -0
  128. package/src/providers/registry.ts +302 -0
  129. package/src/providers/response-validation.ts +80 -0
  130. package/src/providers/retry.ts +234 -0
  131. package/src/providers/router.ts +294 -0
  132. package/src/providers/sse.ts +26 -0
  133. package/src/providers/stream-errors.ts +117 -0
  134. package/src/providers/stream.ts +569 -0
  135. package/src/providers/thinking.ts +189 -0
  136. package/src/providers/wire-messages.ts +129 -0
  137. package/src/sdk/client.ts +225 -0
  138. package/src/sdk/index.ts +3 -0
  139. package/src/server/dashboard.ts +144 -0
  140. package/src/server/http.ts +343 -0
  141. package/src/server/openapi.ts +246 -0
  142. package/src/sextant/card-hits.ts +102 -0
  143. package/src/sextant/card-keys.ts +55 -0
  144. package/src/sextant/context-source.ts +157 -0
  145. package/src/sextant/draw-agents.ts +273 -0
  146. package/src/sextant/draw-code.ts +388 -0
  147. package/src/sextant/draw-context.ts +222 -0
  148. package/src/sextant/draw-frame.ts +164 -0
  149. package/src/sextant/draw-market.ts +573 -0
  150. package/src/sextant/draw-messages.ts +386 -0
  151. package/src/sextant/draw-pet.ts +230 -0
  152. package/src/sextant/draw-plan.ts +159 -0
  153. package/src/sextant/draw-tabs.ts +85 -0
  154. package/src/sextant/draw-util.ts +65 -0
  155. package/src/sextant/engine.ts +230 -0
  156. package/src/sextant/frame-hits.ts +25 -0
  157. package/src/sextant/frame.ts +101 -0
  158. package/src/sextant/git-status.ts +197 -0
  159. package/src/sextant/grid.ts +59 -0
  160. package/src/sextant/input.ts +119 -0
  161. package/src/sextant/keys.ts +488 -0
  162. package/src/sextant/layout.ts +86 -0
  163. package/src/sextant/local-commands.ts +156 -0
  164. package/src/sextant/market-source.ts +287 -0
  165. package/src/sextant/mentions.ts +141 -0
  166. package/src/sextant/message-hits.ts +26 -0
  167. package/src/sextant/model.ts +387 -0
  168. package/src/sextant/overlays.ts +451 -0
  169. package/src/sextant/panel-hits.ts +38 -0
  170. package/src/sextant/pet.ts +399 -0
  171. package/src/sextant/screen.ts +324 -0
  172. package/src/sextant/scroll-hits.ts +66 -0
  173. package/src/sextant/scrollbar.ts +82 -0
  174. package/src/sextant/selection.ts +123 -0
  175. package/src/sextant/sextant-bridge.ts +174 -0
  176. package/src/sextant/sextant-cards.ts +142 -0
  177. package/src/sextant/sextant-diff-base.ts +63 -0
  178. package/src/sextant/sextant-files.ts +154 -0
  179. package/src/sextant/sextant-frame-loop.ts +314 -0
  180. package/src/sextant/sextant-renderer.ts +478 -0
  181. package/src/sextant/sextant-repo.ts +131 -0
  182. package/src/sextant/theme.ts +66 -0
  183. package/src/sextant/tool-rows.ts +189 -0
  184. package/src/sextant/types.ts +473 -0
  185. package/src/skills/index.ts +306 -0
  186. package/src/skills/tools.ts +69 -0
  187. package/src/skills/versioned.ts +227 -0
  188. package/src/telemetry/otel.ts +353 -0
  189. package/src/telemetry/otlp.ts +68 -0
  190. package/src/tools/ask-user.ts +156 -0
  191. package/src/tools/design.ts +151 -0
  192. package/src/tools/evalcell.ts +338 -0
  193. package/src/tools/html-text.ts +139 -0
  194. package/src/tools/provider.ts +149 -0
  195. package/src/tools/task.ts +216 -0
  196. package/src/tools/todo.ts +320 -0
  197. package/src/tools/webfetch.ts +331 -0
  198. package/src/tui/app.ts +608 -0
  199. package/src/tui/attach.ts +127 -0
  200. package/src/tui/checkpoints-cmd.ts +70 -0
  201. package/src/tui/clipboard-image.ts +81 -0
  202. package/src/tui/commands.ts +277 -0
  203. package/src/tui/cost.ts +108 -0
  204. package/src/tui/info-cmd.ts +144 -0
  205. package/src/tui/mcp-cmd.ts +128 -0
  206. package/src/tui/modes-cmd.ts +45 -0
  207. package/src/tui/overlays.ts +97 -0
  208. package/src/tui/pi-renderer.ts +424 -0
  209. package/src/tui/providers-cmd.ts +366 -0
  210. package/src/tui/renderer.ts +101 -0
  211. package/src/tui/replay-marker.ts +29 -0
  212. package/src/tui/session-cmd.ts +146 -0
  213. package/src/tui/sextant-attach.ts +68 -0
  214. package/src/tui/sextant-io.ts +184 -0
  215. package/src/tui/sextant-smoke.ts +110 -0
  216. package/src/tui/smoke.ts +72 -0
  217. package/src/tui/theme.ts +59 -0
  218. package/src/tui/todo-label.ts +7 -0
  219. package/src/workflow/engine.ts +266 -0
  220. package/tsconfig.json +30 -0
  221. package/vendor/pi-tui/LICENSE +21 -0
  222. package/vendor/pi-tui/PATCHES.md +12 -0
  223. package/vendor/pi-tui/PROVENANCE.md +12 -0
  224. package/vendor/pi-tui/README.upstream.md +854 -0
  225. package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  226. package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  227. package/vendor/pi-tui/src/alt-screen-search.ts +158 -0
  228. package/vendor/pi-tui/src/autocomplete.ts +827 -0
  229. package/vendor/pi-tui/src/components/alt-screen-flash.ts +52 -0
  230. package/vendor/pi-tui/src/components/box.ts +138 -0
  231. package/vendor/pi-tui/src/components/cancellable-loader.ts +41 -0
  232. package/vendor/pi-tui/src/components/editor.ts +2364 -0
  233. package/vendor/pi-tui/src/components/h-stack.ts +45 -0
  234. package/vendor/pi-tui/src/components/image.ts +128 -0
  235. package/vendor/pi-tui/src/components/input.ts +448 -0
  236. package/vendor/pi-tui/src/components/loader.ts +93 -0
  237. package/vendor/pi-tui/src/components/markdown.ts +1016 -0
  238. package/vendor/pi-tui/src/components/scroll-view.ts +217 -0
  239. package/vendor/pi-tui/src/components/select-list.ts +230 -0
  240. package/vendor/pi-tui/src/components/settings-list.ts +277 -0
  241. package/vendor/pi-tui/src/components/spacer.ts +29 -0
  242. package/vendor/pi-tui/src/components/stack.ts +155 -0
  243. package/vendor/pi-tui/src/components/text.ts +108 -0
  244. package/vendor/pi-tui/src/components/truncated-text.ts +66 -0
  245. package/vendor/pi-tui/src/components/v-stack.ts +34 -0
  246. package/vendor/pi-tui/src/editor-component.ts +75 -0
  247. package/vendor/pi-tui/src/fuzzy.ts +138 -0
  248. package/vendor/pi-tui/src/index.ts +149 -0
  249. package/vendor/pi-tui/src/keybindings.ts +321 -0
  250. package/vendor/pi-tui/src/keys.ts +1402 -0
  251. package/vendor/pi-tui/src/kill-ring.ts +47 -0
  252. package/vendor/pi-tui/src/latex.ts +1381 -0
  253. package/vendor/pi-tui/src/layout-node.ts +52 -0
  254. package/vendor/pi-tui/src/layout.ts +411 -0
  255. package/vendor/pi-tui/src/native-modifiers.ts +60 -0
  256. package/vendor/pi-tui/src/native-module-path.ts +32 -0
  257. package/vendor/pi-tui/src/stdin-buffer.ts +445 -0
  258. package/vendor/pi-tui/src/terminal-colors.ts +74 -0
  259. package/vendor/pi-tui/src/terminal-image.ts +701 -0
  260. package/vendor/pi-tui/src/terminal.ts +554 -0
  261. package/vendor/pi-tui/src/tui-alt-screen.ts +1379 -0
  262. package/vendor/pi-tui/src/tui-main-screen.ts +655 -0
  263. package/vendor/pi-tui/src/tui.ts +1264 -0
  264. package/vendor/pi-tui/src/undo-stack.ts +29 -0
  265. package/vendor/pi-tui/src/utils.ts +1327 -0
  266. package/vendor/pi-tui/src/word-navigation.ts +118 -0
  267. package/vendor/pi-tui/test/test-themes.ts +39 -0
  268. package/vendor/pi-tui/test/virtual-terminal.ts +219 -0
  269. package/CHANGELOG.md +0 -512
  270. package/bin/rovecode.js +0 -24
  271. package/dist/cli/app-dybnr56b.js +0 -2
  272. package/dist/cli/ask-user-p8hq4xgj.js +0 -2
  273. package/dist/cli/auth-login-ewpgw5sm.js +0 -2
  274. package/dist/cli/auth-m8p9grty.js +0 -2
  275. package/dist/cli/bench-xv3ypwev.js +0 -9
  276. package/dist/cli/catalog-737wb2s0.js +0 -2
  277. package/dist/cli/cli-arhg40m0.js +0 -2
  278. package/dist/cli/client-cf2pxx8q.js +0 -2
  279. package/dist/cli/commands-3p7e4xxs.js +0 -2
  280. package/dist/cli/connect-3q93d7cb.js +0 -2
  281. package/dist/cli/context-cmd-eqxmxhzq.js +0 -2
  282. package/dist/cli/context-report-hbw9zfes.js +0 -2
  283. package/dist/cli/count-remote-mby98cd0.js +0 -2
  284. package/dist/cli/design-122y0axd.js +0 -2
  285. package/dist/cli/dispatch-b4egzvvh.js +0 -2
  286. package/dist/cli/doctor-x4jkv72e.js +0 -3
  287. package/dist/cli/executor-ftvg6tsy.js +0 -2
  288. package/dist/cli/export-pdgdhkch.js +0 -2
  289. package/dist/cli/files-cez9a96p.js +0 -2
  290. package/dist/cli/gauntlet-r3xxaszc.js +0 -2
  291. package/dist/cli/gauntlet-runner-r515m7kk.js +0 -10
  292. package/dist/cli/gauntlet-wave3-bnkjk2v2.js +0 -5
  293. package/dist/cli/gauntlet-wave4-acs9s60q.js +0 -14
  294. package/dist/cli/hashline-ewg5hbe3.js +0 -2
  295. package/dist/cli/http-n0kehsk8.js +0 -5
  296. package/dist/cli/index-z5qt1s76.js +0 -2
  297. package/dist/cli/install-80mp63kx.js +0 -2
  298. package/dist/cli/loop-12twjcat.js +0 -2
  299. package/dist/cli/main-01pv9206.js +0 -4
  300. package/dist/cli/main-0jys2ccn.js +0 -3
  301. package/dist/cli/main-1ztz6fkj.js +0 -10
  302. package/dist/cli/main-23q7cmww.js +0 -9
  303. package/dist/cli/main-2rzbexn2.js +0 -3
  304. package/dist/cli/main-2wyax8k9.js +0 -9
  305. package/dist/cli/main-2yeveeve.js +0 -6
  306. package/dist/cli/main-2z3dek0b.js +0 -3
  307. package/dist/cli/main-2zgsknth.js +0 -3
  308. package/dist/cli/main-45ejth3a.js +0 -4
  309. package/dist/cli/main-45rn3trk.js +0 -22
  310. package/dist/cli/main-4p4e2w7x.js +0 -4
  311. package/dist/cli/main-4y0tnfpa.js +0 -16
  312. package/dist/cli/main-5py0rkmc.js +0 -4
  313. package/dist/cli/main-6dtqmbt6.js +0 -7
  314. package/dist/cli/main-6h9x282m.js +0 -4
  315. package/dist/cli/main-6vjeds42.js +0 -3
  316. package/dist/cli/main-78gq4bt9.js +0 -6
  317. package/dist/cli/main-7jd5vh3x.js +0 -4
  318. package/dist/cli/main-7kt6r53y.js +0 -4
  319. package/dist/cli/main-8c1tbazx.js +0 -58
  320. package/dist/cli/main-9a9rnh47.js +0 -19
  321. package/dist/cli/main-9ht36z12.js +0 -3
  322. package/dist/cli/main-a2yfvcy9.js +0 -7
  323. package/dist/cli/main-a3f51n0x.js +0 -5
  324. package/dist/cli/main-b8zq261k.js +0 -3
  325. package/dist/cli/main-bxtvnf6d.js +0 -13
  326. package/dist/cli/main-edxc3yzt.js +0 -4
  327. package/dist/cli/main-evgz4mp5.js +0 -21
  328. package/dist/cli/main-f33fc5je.js +0 -9
  329. package/dist/cli/main-fvnpq46y.js +0 -12
  330. package/dist/cli/main-gbbty4d4.js +0 -3
  331. package/dist/cli/main-gth53dnt.js +0 -25
  332. package/dist/cli/main-hqbz10aw.js +0 -9
  333. package/dist/cli/main-hrrvcfan.js +0 -38
  334. package/dist/cli/main-hzwtsb2m.js +0 -5
  335. package/dist/cli/main-j7ttv0sd.js +0 -34
  336. package/dist/cli/main-jak598k9.js +0 -5
  337. package/dist/cli/main-kba6zeyd.js +0 -6
  338. package/dist/cli/main-kwwsz6rq.js +0 -3
  339. package/dist/cli/main-m8vm17zq.js +0 -3
  340. package/dist/cli/main-mg4f96e1.js +0 -3
  341. package/dist/cli/main-mg9b20ac.js +0 -18
  342. package/dist/cli/main-mgb9ccnx.js +0 -3
  343. package/dist/cli/main-mjt2p7aj.js +0 -3
  344. package/dist/cli/main-n6qrdbmy.js +0 -3
  345. package/dist/cli/main-na7wse0x.js +0 -5
  346. package/dist/cli/main-nqveez48.js +0 -4
  347. package/dist/cli/main-ntqef02r.js +0 -10
  348. package/dist/cli/main-nvc3yjay.js +0 -136
  349. package/dist/cli/main-p0cfn6nr.js +0 -16
  350. package/dist/cli/main-qj2djy17.js +0 -19
  351. package/dist/cli/main-qsevpgsv.js +0 -3
  352. package/dist/cli/main-qvarybsp.js +0 -3
  353. package/dist/cli/main-rebtt91r.js +0 -5
  354. package/dist/cli/main-rpg7h8mb.js +0 -3
  355. package/dist/cli/main-rsy72qmw.js +0 -15
  356. package/dist/cli/main-rvetps99.js +0 -18
  357. package/dist/cli/main-s4bb0jav.js +0 -3
  358. package/dist/cli/main-s9v8k74e.js +0 -3
  359. package/dist/cli/main-tjvwmscs.js +0 -3
  360. package/dist/cli/main-tkgarpjj.js +0 -4
  361. package/dist/cli/main-v8y60bb2.js +0 -3
  362. package/dist/cli/main-vhrrq337.js +0 -3
  363. package/dist/cli/main-vp2dfb7s.js +0 -4
  364. package/dist/cli/main-vqbr22sz.js +0 -8
  365. package/dist/cli/main-vxnwe5xx.js +0 -18
  366. package/dist/cli/main-wgph00xf.js +0 -5
  367. package/dist/cli/main-wk2csfnj.js +0 -5
  368. package/dist/cli/main-wm997zjx.js +0 -3
  369. package/dist/cli/main-wpkyraxh.js +0 -3
  370. package/dist/cli/main-wqt32p5x.js +0 -4
  371. package/dist/cli/main-x9ct6y1a.js +0 -3
  372. package/dist/cli/main-xfekqh9m.js +0 -7
  373. package/dist/cli/main-xt9zc3n6.js +0 -7
  374. package/dist/cli/main-xx2z3zh5.js +0 -4
  375. package/dist/cli/main-y5c82rxr.js +0 -3
  376. package/dist/cli/main-yrjt2sqt.js +0 -14
  377. package/dist/cli/main-ys6zj3yr.js +0 -3
  378. package/dist/cli/main-ywbxshqc.js +0 -8
  379. package/dist/cli/main-z13755t8.js +0 -25
  380. package/dist/cli/main-zc7pyrbj.js +0 -4
  381. package/dist/cli/main.js +0 -279
  382. package/dist/cli/market-cmd-bm5xvn9f.js +0 -5
  383. package/dist/cli/mcp-login-bthtfpt7.js +0 -2
  384. package/dist/cli/mcp-market-cmd-mbeshfyd.js +0 -2
  385. package/dist/cli/notify-54v5z9dz.js +0 -2
  386. package/dist/cli/oauth-g5gme95c.js +0 -2
  387. package/dist/cli/output-satndjap.js +0 -16
  388. package/dist/cli/profiles-sfhpbq3m.js +0 -2
  389. package/dist/cli/provider-config-hv3xtdt4.js +0 -2
  390. package/dist/cli/provider-kwzq6g84.js +0 -2
  391. package/dist/cli/registry-fh0hdnyn.js +0 -2
  392. package/dist/cli/registry-y1y8e94r.js +0 -2
  393. package/dist/cli/repl-t4z03mqq.js +0 -11
  394. package/dist/cli/resume-fqt4chg8.js +0 -2
  395. package/dist/cli/run-flags-rysbag9t.js +0 -2
  396. package/dist/cli/runtime-j19fjbsa.js +0 -2
  397. package/dist/cli/sandbox-config-g4qxd7y5.js +0 -2
  398. package/dist/cli/server-r0b6bksk.js +0 -5
  399. package/dist/cli/session-arg-txmn5g4x.js +0 -2
  400. package/dist/cli/session-ed250d9j.js +0 -2
  401. package/dist/cli/sessions-cmd-adw7svfn.js +0 -7
  402. package/dist/cli/settings-y9rzcqx8.js +0 -2
  403. package/dist/cli/setup-jmbr11j0.js +0 -2
  404. package/dist/cli/sextant-smoke-tcth0vea.js +0 -5
  405. package/dist/cli/skills-cmd-zbdy99v6.js +0 -2
  406. package/dist/cli/smoke-1bg937kx.js +0 -8
  407. package/dist/cli/start-chat-p01cdks3.js +0 -12
  408. package/dist/cli/stream-4wmyaypz.js +0 -2
  409. package/dist/cli/task-eg4s093s.js +0 -2
  410. package/dist/cli/tasks-12v9rr9k.js +0 -2
  411. package/dist/cli/thinking-a5ngvqyh.js +0 -2
  412. package/dist/cli/todo-1wxpcecx.js +0 -2
  413. package/dist/cli/tools-2ftsya7w.js +0 -2
  414. package/dist/cli/tools-x1tj4fxm.js +0 -2
  415. package/dist/cli/trust-cmd-hccxehzb.js +0 -2
  416. package/dist/cli/update-check-ygt3vd7m.js +0 -2
  417. package/dist/cli/update-cmd-v23qhr8c.js +0 -2
  418. package/dist/cli/voice-g1gtck92.js +0 -2
  419. package/dist/cli/webfetch-0nnrjgb5.js +0 -2
  420. package/dist/cli/websearch-f0vr2p7d.js +0 -2
  421. package/dist/cli/workspace-9rq1w4ta.js +0 -2
  422. package/dist/lib/index.js +0 -62
  423. package/dist/lib/models-index.json +0 -1
  424. package/dist/lib/plugins.js +0 -6
  425. package/dist/lib/providers.js +0 -17
  426. package/dist/lib/public-api.js +0 -20
  427. package/dist/rovecode.exe +0 -4
  428. /package/{dist/cli → src/providers}/models-index.json +0 -0
@@ -0,0 +1,158 @@
1
+ /** RFC 8628 device authorization grant, client side — the half `rovecode login` runs.
2
+ *
3
+ * The CLI asks the site's API for a code, shows the human where to approve it, and polls until a token
4
+ * appears. `fetch`, `sleep` and `now` are injectable so the whole loop is unit-testable without a server
5
+ * or a real clock. */
6
+
7
+ import { loadOrCreateAccountKey, signProof, type AccountKey } from "./keys.ts";
8
+ import { saveAccount, type LinkedAccount } from "./store";
9
+
10
+ export interface DeviceCodeInfo {
11
+ userCode: string;
12
+ verificationUri: string;
13
+ expiresIn: number;
14
+ }
15
+
16
+ export interface DeviceLoginOptions {
17
+ apiBase: string;
18
+ clientId?: string;
19
+ scope?: string;
20
+ fetchImpl?: typeof fetch;
21
+ sleep?: (ms: number) => Promise<void>;
22
+ now?: () => number;
23
+ /** the machine's PoP key; defaults to ~/.rovecode/account-key.json (created on first use) */
24
+ keys?: AccountKey;
25
+ /** called once with the code and URL to show the human */
26
+ onCode?: (info: DeviceCodeInfo) => void;
27
+ }
28
+
29
+ export type LoginResult = { ok: true; account: LinkedAccount } | { ok: false; reason: "denied" | "expired" | "invalid" | "network" };
30
+
31
+ const defaultSleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
32
+
33
+ interface Probe {
34
+ status: number;
35
+ body: Record<string, unknown>;
36
+ }
37
+
38
+ async function postJson(doFetch: typeof fetch, url: string, body: unknown): Promise<Probe | null> {
39
+ try {
40
+ const res = await doFetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
41
+ return { status: res.status, body: await readJson(res) };
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ async function readJson(res: Response): Promise<Record<string, unknown>> {
48
+ try {
49
+ const text = await res.text();
50
+ return text.trim() ? (JSON.parse(text) as Record<string, unknown>) : {};
51
+ } catch {
52
+ return {};
53
+ }
54
+ }
55
+
56
+ export async function runDeviceLogin(opts: DeviceLoginOptions): Promise<LoginResult> {
57
+ const doFetch = opts.fetchImpl ?? fetch;
58
+ const sleep = opts.sleep ?? defaultSleep;
59
+ const now = opts.now ?? (() => Date.now());
60
+ const base = opts.apiBase.replace(/\/+$/, "");
61
+
62
+ const keys = opts.keys ?? loadOrCreateAccountKey();
63
+ const start = await postJson(doFetch, `${base}/api/auth/device/code`, {
64
+ client_id: opts.clientId ?? "rovecode-cli",
65
+ scope: opts.scope,
66
+ public_jwk: keys.publicJwk,
67
+ });
68
+ if (!start || start.status !== 200) return { ok: false, reason: "network" };
69
+ const deviceCode = typeof start.body.device_code === "string" ? start.body.device_code : "";
70
+ const userCode = typeof start.body.user_code === "string" ? start.body.user_code : "";
71
+ if (!deviceCode || !userCode) return { ok: false, reason: "network" };
72
+
73
+ const expiresIn = typeof start.body.expires_in === "number" ? start.body.expires_in : 600;
74
+ let interval = typeof start.body.interval === "number" ? start.body.interval : 5;
75
+ const verificationUri = typeof start.body.verification_uri === "string" ? start.body.verification_uri : `${base}/cli-auth`;
76
+ opts.onCode?.({ userCode, verificationUri, expiresIn });
77
+
78
+ const deadline = now() + expiresIn * 1000;
79
+ while (now() < deadline) {
80
+ await sleep(interval * 1000);
81
+ const poll = await postJson(doFetch, `${base}/api/auth/device/token`, { device_code: deviceCode });
82
+ if (!poll) return { ok: false, reason: "network" };
83
+
84
+ if (poll.status === 200) {
85
+ const token = typeof poll.body.access_token === "string" ? poll.body.access_token : "";
86
+ if (!token) return { ok: false, reason: "network" };
87
+ const user = (poll.body.user ?? {}) as { id?: unknown; email?: unknown; name?: unknown };
88
+ const apiKey = typeof poll.body.api_key === "string" ? poll.body.api_key : "";
89
+ const account: LinkedAccount = {
90
+ token,
91
+ userId: typeof user.id === "string" ? user.id : "",
92
+ email: typeof user.email === "string" ? user.email : "",
93
+ name: typeof user.name === "string" ? user.name : "",
94
+ apiBase: base,
95
+ linkedAt: new Date(now()).toISOString(),
96
+ ...(apiKey ? { apiKey } : {}),
97
+ };
98
+ saveAccount(account);
99
+ return { ok: true, account };
100
+ }
101
+
102
+ switch (poll.body.error) {
103
+ case "authorization_pending":
104
+ continue;
105
+ case "slow_down":
106
+ interval += 5;
107
+ continue;
108
+ case "access_denied":
109
+ return { ok: false, reason: "denied" };
110
+ case "expired_token":
111
+ return { ok: false, reason: "expired" };
112
+ case "invalid_grant":
113
+ return { ok: false, reason: "invalid" };
114
+ default:
115
+ return { ok: false, reason: "network" };
116
+ }
117
+ }
118
+ return { ok: false, reason: "expired" };
119
+ }
120
+
121
+ /** Verify a hand-pasted `rc_live_…` token against /api/auth/me. A proof signed with this machine's key goes
122
+ * along: a bound token answers only when the keys match (i.e. the token was issued to this machine); an
123
+ * unbound legacy token still passes on bearer alone — the documented fallback. */
124
+ export async function linkWithToken(
125
+ apiBase: string,
126
+ token: string,
127
+ fetchImpl: typeof fetch = fetch,
128
+ keys: AccountKey = loadOrCreateAccountKey(),
129
+ now: () => number = () => Date.now(),
130
+ ): Promise<LinkedAccount | null> {
131
+ const base = apiBase.replace(/\/+$/, "");
132
+ token = token.trim();
133
+ if (!token) return null;
134
+ const meUrl = `${base}/api/auth/me`;
135
+ try {
136
+ const res = await fetchImpl(meUrl, {
137
+ headers: {
138
+ authorization: `Bearer ${token}`,
139
+ dpop: signProof(keys, { htm: "GET", htu: meUrl, iat: Math.floor(now() / 1000), accessToken: token }),
140
+ },
141
+ });
142
+ if (!res.ok) return null;
143
+ const body = await readJson(res);
144
+ const user = (body.user ?? {}) as { id?: unknown; email?: unknown; name?: unknown };
145
+ const account: LinkedAccount = {
146
+ token,
147
+ userId: typeof user.id === "string" ? user.id : "",
148
+ email: typeof user.email === "string" ? user.email : "",
149
+ name: typeof user.name === "string" ? user.name : "",
150
+ apiBase: base,
151
+ linkedAt: new Date().toISOString(),
152
+ };
153
+ saveAccount(account);
154
+ return account;
155
+ } catch {
156
+ return null;
157
+ }
158
+ }
@@ -0,0 +1,47 @@
1
+ /** After a device login the CLI holds a rove_live_… inference key the site minted for it. This turns
2
+ * that key into a ready-to-use "rovecode" provider — registered, key stored, made the default when
3
+ * nothing else is — so `rovecode login` alone takes a fresh install to a working model. */
4
+
5
+ import { saveCredential } from "../providers/auth.ts";
6
+ import { ProviderRegistry } from "../providers/registry.ts";
7
+
8
+ export const ROVECODE_BASE_URL = "https://api.rovecode.dev/v1";
9
+ export const ROVECODE_KEY_ENV = "ROVECODE_API_KEY";
10
+ export const ROVECODE_DEFAULT_MODEL = "grok-4.7";
11
+
12
+ export interface ProvisionResult {
13
+ /** the provider entry was created now (false = it already existed) */
14
+ added: boolean;
15
+ keyStored: boolean;
16
+ /** it became the default model (false = the user already had a default — left untouched) */
17
+ defaulted: boolean;
18
+ error?: string;
19
+ }
20
+
21
+ export function ensureRovecodeProvider(apiKey: string, cwd: string = process.cwd()): ProvisionResult {
22
+ const reg = new ProviderRegistry(cwd);
23
+ let added = false;
24
+ if (reg.get("rovecode") === undefined) {
25
+ const r = reg.add(
26
+ {
27
+ id: "rovecode",
28
+ baseUrl: ROVECODE_BASE_URL,
29
+ protocol: "openai",
30
+ keyEnv: ROVECODE_KEY_ENV,
31
+ defaultModel: ROVECODE_DEFAULT_MODEL,
32
+ },
33
+ "user",
34
+ );
35
+ if ("error" in r) return { added: false, keyStored: false, defaulted: false, error: r.error };
36
+ added = true;
37
+ }
38
+ saveCredential("rovecode", apiKey, ROVECODE_KEY_ENV);
39
+ reg.refresh();
40
+
41
+ let defaulted = false;
42
+ if (reg.defaultRef() === null) {
43
+ const d = reg.setDefault(`rovecode/${ROVECODE_DEFAULT_MODEL}`, "user");
44
+ if (!("error" in d)) defaulted = true;
45
+ }
46
+ return { added, keyStored: true, defaulted };
47
+ }
@@ -0,0 +1,63 @@
1
+ /** The linked rovecode account (device-flow login): what `rovecode login` writes and `rovecode account`
2
+ * reads. Kept apart from providers/credentials.json on purpose — that file is the provider API keys the
3
+ * router resolves, and an account token is neither a provider nor a model key. */
4
+
5
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, chmodSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { rovecodeHome } from "../providers/auth.ts";
8
+
9
+ export interface LinkedAccount {
10
+ /** the rc_live_… access token the site's device API issued */
11
+ token: string;
12
+ userId: string;
13
+ email: string;
14
+ name: string;
15
+ /** the API base that issued it — a token is only valid there */
16
+ apiBase: string;
17
+ /** the rove_live_… inference key minted alongside the login — the CLI configures the rovecode
18
+ * provider with this so the user never touches the dashboard's key page */
19
+ apiKey?: string;
20
+ /** ISO 8601 */
21
+ linkedAt: string;
22
+ }
23
+
24
+ export function accountPath(): string {
25
+ return join(rovecodeHome(), "account.json");
26
+ }
27
+
28
+ export function loadAccount(): LinkedAccount | null {
29
+ try {
30
+ const parsed = JSON.parse(readFileSync(accountPath(), "utf8")) as Partial<LinkedAccount>;
31
+ if (typeof parsed.token !== "string" || parsed.token.length === 0) return null;
32
+ return {
33
+ token: parsed.token,
34
+ userId: typeof parsed.userId === "string" ? parsed.userId : "",
35
+ email: typeof parsed.email === "string" ? parsed.email : "",
36
+ name: typeof parsed.name === "string" ? parsed.name : "",
37
+ apiBase: typeof parsed.apiBase === "string" ? parsed.apiBase : "",
38
+ ...(typeof parsed.apiKey === "string" && parsed.apiKey.length > 0 ? { apiKey: parsed.apiKey } : {}),
39
+ linkedAt: typeof parsed.linkedAt === "string" ? parsed.linkedAt : "",
40
+ };
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ export function saveAccount(account: LinkedAccount): void {
47
+ mkdirSync(rovecodeHome(), { recursive: true, mode: 0o700 });
48
+ const path = accountPath();
49
+ writeFileSync(path, JSON.stringify(account, null, 2) + "\n", { mode: 0o600 });
50
+ try {
51
+ chmodSync(path, 0o600);
52
+ } catch {
53
+ /* best-effort, same Windows caveat as providers/auth.ts */
54
+ }
55
+ }
56
+
57
+ /** returns false when there was nothing to remove */
58
+ export function clearAccount(): boolean {
59
+ const path = accountPath();
60
+ if (!existsSync(path)) return false;
61
+ rmSync(path);
62
+ return true;
63
+ }
@@ -0,0 +1,373 @@
1
+ /** ACP agent endpoint (port #15): `rovecode acp` speaks Agent Client Protocol v1
2
+ * over stdio via the official SDK (@zed-industries/agent-client-protocol@0.4.5,
3
+ * Apache-2.0), mapped onto the ONE agentLoop (ADR-003).
4
+ *
5
+ * Mapping:
6
+ * initialize → protocol v1 + capabilities (no loadSession; text + image prompts, port #34)
7
+ * prompt image blocks → ImagePart via imageFromBase64 (the bytes decide the type; the TUI's
8
+ * per-image size cap and ≤8-per-message count cap apply), staged on the
9
+ * session store so the loop's user message carries them (no loop change);
10
+ * any bad block → JSON-RPC invalid params {error} before a run starts
11
+ * session/new → bootRuntime (same stores/tools/config as repl/tui); a sandbox
12
+ * misconfig / unavailable rung in the client's cwd (port #27)
13
+ * → JSON-RPC invalid params {cwd, error: one-line message}
14
+ * session/prompt → agentLoop run; RunEvents stream out as session/update
15
+ * message_update → agent_message_chunk
16
+ * tool_execution_* → tool_call / tool_call_update
17
+ * tool_call_failed → tool_call created directly in "failed" status
18
+ * approval (ADR-005) → session/request_permission; declined/cancelled/unsupported → deny
19
+ * run_end done/budget → stopReason end_turn / max_turn_requests
20
+ * run_end error → JSON-RPC error response (RequestError is the ACP error
21
+ * channel — the SDK converts it to a wire-level response,
22
+ * so the never-throw seam ends at this boundary by design)
23
+ * session/cancel → aborts the run's AbortController (kills the in-flight
24
+ * provider fetch and tool subprocesses mid-turn — port #21),
25
+ * races any outstanding permission ask to deny, then closes
26
+ * the generator → "cancelled"
27
+ */
28
+
29
+ import {
30
+ AgentSideConnection, RequestError, PROTOCOL_VERSION, ndJsonStream,
31
+ type Agent, type Stream,
32
+ type InitializeRequest, type InitializeResponse,
33
+ type AuthenticateRequest, type AuthenticateResponse,
34
+ type NewSessionRequest, type NewSessionResponse,
35
+ type PromptRequest, type PromptResponse, type CancelNotification,
36
+ type ContentBlock, type SessionNotification, type ToolCallContent,
37
+ type ToolKind as AcpToolKind,
38
+ } from "@zed-industries/agent-client-protocol";
39
+ import { basename } from "node:path";
40
+ import { noModelHint } from "../core/voice.ts";
41
+ import { Readable, Writable } from "node:stream";
42
+ import { agentLoop, SteeringQueue } from "../core/loop.ts";
43
+ import { bootRuntime, type Runtime } from "../cli/runtime.ts";
44
+ import { checkImageCount, imageFromBase64 } from "../core/images.ts";
45
+ import { SandboxConfigError } from "../core/sandbox-config.ts";
46
+ import type { ApprovalFn, ImagePart, RunEvent, StreamFn } from "../core/types.ts";
47
+
48
+ export interface AcpOptions {
49
+ /** test/dev override threaded into createRuntime; undefined = provider from env */
50
+ stream?: StreamFn | null;
51
+ /** allow-all permissions: no ACP permission round-trips (ROVECODE_YOLO parity) */
52
+ yolo?: boolean;
53
+ }
54
+
55
+ type SessionUpdate = SessionNotification["update"];
56
+ type RunStatus = "done" | "stopped" | "error" | "budget";
57
+
58
+ interface AcpSessionState {
59
+ rt: Runtime;
60
+ steering: SteeringQueue;
61
+ active: {
62
+ gen: AsyncGenerator<RunEvent>;
63
+ cancelled: boolean;
64
+ /** per-run controller (port #21): session/cancel aborts it, killing the
65
+ * in-flight provider fetch and every ToolContext.signal consumer */
66
+ abort: AbortController;
67
+ /** resolves null when session/cancel lands — raced against an outstanding
68
+ * request_permission so a hung client cannot wedge the session (HIGH-G2) */
69
+ onCancel: Promise<null>;
70
+ fireCancel: () => void;
71
+ } | null;
72
+ permSeq: number;
73
+ }
74
+
75
+ // ---------- translation helpers (RunEvent / house shapes → ACP shapes) ----------
76
+
77
+ export interface PromptParts {
78
+ /** the loop's goal text: text blocks, resource links, inlined embedded text resources */
79
+ goal: string;
80
+ /** port #34: decoded image blocks, in prompt order */
81
+ images: ImagePart[];
82
+ /** the FIRST problem (unsupported/mismatched mime, oversize, more than 8 images) — the caller
83
+ * rejects the whole prompt, nothing is half-sent */
84
+ error?: string;
85
+ }
86
+
87
+ /** Prompt content blocks → goal text + image parts. Baseline blocks (text, resource_link) per
88
+ * spec; embedded text resources are inlined; image blocks decode through imageFromBase64 (the
89
+ * bytes decide the type — a disagreeing mimeType is an error, like the TUI's loader) under the
90
+ * same per-image size cap and per-message count cap as /attach; audio stays unsupported. */
91
+ export function promptParts(blocks: ContentBlock[]): PromptParts {
92
+ const parts: string[] = [];
93
+ const images: ImagePart[] = [];
94
+ let error: string | undefined;
95
+ for (const b of blocks) {
96
+ if (b.type === "text") parts.push(b.text);
97
+ else if (b.type === "resource_link") parts.push(`[resource: ${b.uri}]`);
98
+ else if (b.type === "resource" && "text" in b.resource) {
99
+ parts.push(`<context uri="${b.resource.uri}">\n${b.resource.text}\n</context>`);
100
+ } else if (b.type === "image") {
101
+ const name = b.uri && !b.uri.startsWith("data:") ? basename(b.uri) : undefined; // display name: the file the client sent
102
+ const res = imageFromBase64(b.data, b.mimeType, name !== undefined ? { name } : {});
103
+ if ("error" in res) error ??= res.error; else images.push(res);
104
+ } else parts.push(`[unsupported ${b.type} content omitted]`);
105
+ }
106
+ error ??= checkImageCount(images.length);
107
+ const goal = parts.join("\n");
108
+ return error === undefined ? { goal, images } : { goal, images, error };
109
+ }
110
+
111
+ /** Text-only view of a prompt (image blocks travel separately — promptParts). */
112
+ export function promptText(blocks: ContentBlock[]): string { return promptParts(blocks).goal; }
113
+
114
+ const TOOL_KINDS: Record<string, AcpToolKind> = {
115
+ read: "read", edit: "edit", write: "edit", bash: "execute",
116
+ skill_view: "read", skills_list: "search", mcp_list: "search",
117
+ mcp_call: "other", memory_edit: "other", web_fetch: "fetch",
118
+ };
119
+
120
+ export function kindFor(tool: string): AcpToolKind {
121
+ return TOOL_KINDS[tool] ?? "other";
122
+ }
123
+
124
+ /** Human title for a tool call: name plus the most salient argument. */
125
+ export function titleFor(tool: string, args: unknown): string {
126
+ if (args && typeof args === "object") {
127
+ const a = args as Record<string, unknown>;
128
+ const salient = a.path ?? a.command ?? a.name ?? a.url;
129
+ if (salient !== undefined) return `${tool}: ${String(salient).slice(0, 120)}`;
130
+ }
131
+ return tool;
132
+ }
133
+
134
+ function asRawInput(args: unknown): Record<string, unknown> {
135
+ if (args && typeof args === "object" && !Array.isArray(args)) return args as Record<string, unknown>;
136
+ return args === undefined ? {} : { value: args };
137
+ }
138
+
139
+ function textContent(text: string): ToolCallContent[] {
140
+ return [{ type: "content", content: { type: "text", text } }];
141
+ }
142
+
143
+ /** RunEvent → session/update payload; null for events with no ACP counterpart
144
+ * (run_start, turn_start/end, steer, compaction — lifecycle stays house-side). */
145
+ export function updateForEvent(ev: RunEvent): SessionUpdate | null {
146
+ switch (ev.type) {
147
+ case "message_update":
148
+ return { sessionUpdate: "agent_message_chunk", content: { type: "text", text: ev.delta } };
149
+ case "tool_execution_start":
150
+ return {
151
+ sessionUpdate: "tool_call", toolCallId: ev.callId, title: titleFor(ev.tool, ev.args),
152
+ kind: kindFor(ev.tool), status: "in_progress", rawInput: asRawInput(ev.args),
153
+ };
154
+ case "tool_execution_update":
155
+ return { sessionUpdate: "tool_call_update", toolCallId: ev.callId, content: textContent(ev.note) };
156
+ case "tool_execution_end":
157
+ return {
158
+ sessionUpdate: "tool_call_update", toolCallId: ev.callId,
159
+ status: ev.ok ? "completed" : "failed",
160
+ content: textContent(ev.output), rawOutput: { output: ev.output },
161
+ };
162
+ case "tool_call_failed":
163
+ // calls rejected before execution (permission_denied / truncated / not_found /
164
+ // invalid_args) never got a tool_call create — create directly in failed status
165
+ return {
166
+ sessionUpdate: "tool_call", toolCallId: ev.callId, title: `tool call failed (${ev.reason})`,
167
+ kind: "other", status: "failed", content: textContent(ev.detail),
168
+ };
169
+ default:
170
+ return null;
171
+ }
172
+ }
173
+
174
+ // ---------- the ACP agent ----------
175
+
176
+ export class RovecodeAcpAgent implements Agent {
177
+ private readonly sessions = new Map<string, AcpSessionState>();
178
+
179
+ constructor(private readonly conn: AgentSideConnection, private readonly opts: AcpOptions = {}) {}
180
+
181
+ async initialize(_params: InitializeRequest): Promise<InitializeResponse> {
182
+ // we implement exactly v1: reply with our version; older clients disconnect (spec rule)
183
+ return {
184
+ protocolVersion: PROTOCOL_VERSION,
185
+ agentCapabilities: {
186
+ loadSession: false,
187
+ promptCapabilities: { image: true, audio: false, embeddedContext: true }, // image: port #34 (promptParts)
188
+ },
189
+ authMethods: [],
190
+ };
191
+ }
192
+
193
+ async authenticate(_params: AuthenticateRequest): Promise<AuthenticateResponse> {
194
+ return {}; // no auth methods advertised; provider credentials come from env
195
+ }
196
+
197
+ async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {
198
+ // v1 scope: params.mcpServers is not wired into the runtime — the runtime
199
+ // already loads project-level .rovecode/mcp.json + .mcp.json (port #3)
200
+ let rt: Runtime;
201
+ try {
202
+ rt = await bootRuntime({ cwd: params.cwd, stream: this.opts.stream });
203
+ } catch (e) {
204
+ // port #27: the client's cwd asked for a rung this machine cannot provide (or
205
+ // its sandbox.json is broken) — invalid params carrying the one-line message,
206
+ // the same shape as "unknown session" below (the parameter names something
207
+ // we cannot serve); the agent process stays up for the next session/new
208
+ if (e instanceof SandboxConfigError) throw RequestError.invalidParams({ cwd: params.cwd, error: e.message });
209
+ throw e;
210
+ }
211
+ // live registry: once the user runs `rovecode provider add` / `rovecode auth set`, the next
212
+ // session/new succeeds without restarting the agent process
213
+ const noProvider = rt.noProviderReason();
214
+ if (!rt.stream || noProvider !== null) {
215
+ throw RequestError.authRequired({
216
+ details: noProvider ?? noModelHint("cli"),
217
+ });
218
+ }
219
+ this.sessions.set(rt.sessionId, { rt, steering: rt.steering, active: null, permSeq: 0 }); // port #26: runtime queue → task notes reach the next prompt
220
+ return { sessionId: rt.sessionId };
221
+ }
222
+
223
+ async prompt(params: PromptRequest): Promise<PromptResponse> {
224
+ const s = this.sessions.get(params.sessionId);
225
+ if (!s) throw RequestError.invalidParams({ sessionId: params.sessionId, error: "unknown session" });
226
+ if (s.active) throw RequestError.invalidRequest({ error: "a prompt is already running for this session" });
227
+ const stream = s.rt.stream;
228
+ const noProvider = s.rt.noProviderReason();
229
+ if (!stream || noProvider !== null) throw RequestError.authRequired(noProvider !== null ? { details: noProvider } : undefined);
230
+
231
+ const { goal, images, error } = promptParts(params.prompt);
232
+ // port #34: a bad image block (not png/jpeg/gif/webp, mime disagrees with the bytes, oversize,
233
+ // 9+ images) rejects the prompt as invalid params BEFORE any run — same "nothing staged" outcome
234
+ // as the TUI's error note; the session stays usable for the corrected prompt
235
+ if (error !== undefined) throw RequestError.invalidParams({ error });
236
+ const model = { provider: s.rt.provider?.id ?? "mock", model: s.rt.defaultModel || "default" };
237
+ const def = s.rt.buildDef(model);
238
+ const cfg = s.rt.buildCfg(this.opts.yolo ?? false, this.approvalFor(params.sessionId, s));
239
+ const abort = new AbortController(); // port #21: one controller per run
240
+ s.rt.tasks.bindRun(abort.signal); // port #26: session/cancel also cancels the run's background tasks
241
+ const deps = {
242
+ stream, registry: s.rt.registry, store: s.rt.store,
243
+ tools: s.rt.registry.list().map((t) => t.schema), guard: s.rt.guard,
244
+ hooks: s.rt.hooks, // port #29: .rovecode/hooks.{ts,js} of the session cwd
245
+ cwd: s.rt.cwd, // HIGH-G1: the client's authoritative session cwd reaches ToolContext
246
+ signal: abort.signal, // port #21: session/cancel kills in-flight fetch/tools mid-turn
247
+ };
248
+
249
+ // port #34: the store folds the staged images into the loop's user message when it lands in
250
+ // append() — the same seam TUI /attach uses; the active guard above means no other user entry
251
+ // can slip in between (task steers drain AFTER the goal message, loop.ts)
252
+ if (images.length > 0) s.rt.store.stageAttachments(images);
253
+ const gen = agentLoop(def, goal, {}, cfg, deps, s.steering);
254
+ let fireCancel: () => void = () => {};
255
+ const onCancel = new Promise<null>((resolve) => { fireCancel = () => resolve(null); });
256
+ const active = { gen, cancelled: false, abort, onCancel, fireCancel };
257
+ s.active = active;
258
+ let end: { status: RunStatus; summary: string } | null = null;
259
+ try {
260
+ for await (const ev of gen) {
261
+ if (active.cancelled) break; // session/cancel landed; loop finally aborts tools
262
+ if (ev.type === "run_end") { end = { status: ev.status, summary: ev.summary }; break; }
263
+ const update = updateForEvent(ev);
264
+ if (update) await this.conn.sessionUpdate({ sessionId: params.sessionId, update });
265
+ }
266
+ } finally {
267
+ s.active = null;
268
+ }
269
+
270
+ if (active.cancelled || end === null) return { stopReason: "cancelled" };
271
+ switch (end.status) {
272
+ case "done": return { stopReason: "end_turn" };
273
+ case "budget": return { stopReason: "max_turn_requests" };
274
+ case "stopped": return { stopReason: "cancelled" };
275
+ case "error": throw RequestError.internalError({ details: end.summary });
276
+ }
277
+ }
278
+
279
+ async cancel(params: CancelNotification): Promise<void> {
280
+ const active = this.sessions.get(params.sessionId)?.active;
281
+ if (!active) return;
282
+ active.cancelled = true;
283
+ // port #21: abort the run's controller FIRST — the in-flight provider fetch
284
+ // dies and tool subprocesses are killed mid-turn, so the generator below
285
+ // reaches a settle point quickly instead of finishing the turn.
286
+ active.abort.abort();
287
+ // HIGH-G2: unblock an outstanding request_permission (→ deny) — without
288
+ // this a crashed client / closed popup leaves the run suspended inside the
289
+ // approval await forever and the session permanently "already running".
290
+ active.fireCancel();
291
+ // close the generator as the follow-through: runs the loop's finally blocks.
292
+ // Queues behind any pending next(), so the settle stays cooperative.
293
+ await active.gen.return(undefined as never).then(() => undefined, () => undefined);
294
+ }
295
+
296
+ /** MED-G3: close every session runtime's MCP children. runAcpStdio calls this
297
+ * when stdin closes — without it, `rovecode acp` in an MCP-configured project
298
+ * outlives the client (children keep running until the parent is killed). */
299
+ async shutdown(): Promise<void> {
300
+ const closing: Promise<unknown>[] = [];
301
+ for (const s of this.sessions.values()) {
302
+ s.rt.tasks.cancelAll(); // port #26: background children die with the agent, never after it
303
+ closing.push(s.rt.hooks.close()); // port #29: session_close per session runtime
304
+ if (s.rt.mcp) closing.push(s.rt.mcp.close().catch(() => {}));
305
+ }
306
+ await Promise.all(closing);
307
+ }
308
+
309
+ /** ADR-005 approval seam → session/request_permission. Deny is the safe default:
310
+ * declined, cancelled, unknown option, or a client that errors (unsupported). */
311
+ private approvalFor(sessionId: string, s: AcpSessionState): ApprovalFn {
312
+ return async (req) => {
313
+ const toolCallId = `perm-${++s.permSeq}`;
314
+ let outcome: { outcome: "cancelled" } | { outcome: "selected"; optionId: string };
315
+ try {
316
+ const ask = this.conn.requestPermission({
317
+ sessionId,
318
+ toolCall: {
319
+ toolCallId, title: titleFor(req.tool, req.revisedArgs), kind: kindFor(req.tool),
320
+ status: "pending", rawInput: asRawInput(req.revisedArgs),
321
+ },
322
+ options: [
323
+ { optionId: "allow-once", name: "Allow once", kind: "allow_once" },
324
+ { optionId: "allow-always", name: "Allow always", kind: "allow_always" },
325
+ { optionId: "reject-once", name: "Deny", kind: "reject_once" },
326
+ ],
327
+ });
328
+ void ask.then(() => undefined, () => undefined); // raced loser must not surface as unhandled
329
+ // HIGH-G2: session/cancel must be able to interrupt an outstanding ask
330
+ // (client crash / closed popup) — cancel wins the race and maps to deny
331
+ const resp = s.active ? await Promise.race([ask, s.active.onCancel]) : await ask;
332
+ if (resp === null) return "deny"; // cancelled mid-permission
333
+ outcome = resp.outcome;
334
+ } catch {
335
+ return "deny"; // client rejected the request itself → unsupported → deny
336
+ }
337
+ if (outcome.outcome !== "selected") return "deny";
338
+ if (outcome.optionId === "allow-once") return "once";
339
+ if (outcome.optionId === "allow-always") return "always";
340
+ return "deny";
341
+ };
342
+ }
343
+ }
344
+
345
+ // ---------- wiring ----------
346
+
347
+ /** Attach an ACP agent to a bidirectional message stream (tests use an
348
+ * in-process duplex; the CLI uses stdio via runAcpStdio). The agent handle is
349
+ * returned alongside the connection so callers can shutdown() its sessions. */
350
+ export function serveAcp(io: Stream, opts: AcpOptions = {}): { conn: AgentSideConnection; agent: RovecodeAcpAgent } {
351
+ let agent!: RovecodeAcpAgent; // the factory runs synchronously inside the ctor
352
+ const conn = new AgentSideConnection((c) => (agent = new RovecodeAcpAgent(c, opts)), io);
353
+ return { conn, agent };
354
+ }
355
+
356
+ /** `rovecode acp`: serve ACP v1 over stdio until the client closes stdin.
357
+ * stdout carries protocol frames only — nothing else may print there. */
358
+ export function runAcpStdio(opts: AcpOptions = {}): Promise<void> {
359
+ // node:stream/web and lib.dom stream types diverge on getReader() overloads;
360
+ // the runtime objects are the same web streams, so bridge via unknown
361
+ const io = ndJsonStream(
362
+ Writable.toWeb(process.stdout) as unknown as WritableStream<Uint8Array>,
363
+ Readable.toWeb(process.stdin) as unknown as ReadableStream<Uint8Array>,
364
+ );
365
+ const { agent } = serveAcp(io, opts);
366
+ return new Promise<void>((resolve) => {
367
+ // MED-G3: reap MCP children before resolving, or the process outlives a
368
+ // closed editor in MCP-configured projects (children hold the event loop)
369
+ const done = () => { void agent.shutdown().then(() => resolve(), () => resolve()); };
370
+ process.stdin.once("end", done);
371
+ process.stdin.once("close", done);
372
+ });
373
+ }