rovecode 0.4.0-beta.3 → 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.
- package/README.md +57 -72
- package/THIRD_PARTY_NOTICES.md +0 -44
- package/bin/rovecode.ts +21 -0
- package/package.json +16 -38
- package/src/account/keys.ts +97 -0
- package/src/account/login.ts +158 -0
- package/src/account/provision.ts +47 -0
- package/src/account/store.ts +63 -0
- package/src/acp/server.ts +373 -0
- package/src/cli/account-cmd.ts +116 -0
- package/src/cli/connect.ts +244 -0
- package/src/cli/context-cmd.ts +199 -0
- package/src/cli/dispatch.ts +109 -0
- package/src/cli/doctor.ts +324 -0
- package/src/cli/export.ts +278 -0
- package/src/cli/help.ts +240 -0
- package/src/cli/is-tui-invocation.ts +8 -0
- package/src/cli/main.ts +599 -0
- package/src/cli/market-cmd.ts +658 -0
- package/src/cli/mcp-market-cmd.ts +299 -0
- package/src/cli/output.ts +382 -0
- package/src/cli/repl.ts +172 -0
- package/src/cli/resume.ts +32 -0
- package/src/cli/run-limits.ts +78 -0
- package/src/cli/runtime.ts +792 -0
- package/src/cli/setup.ts +187 -0
- package/src/cli/update-cmd.ts +78 -0
- package/src/cli/workflow-cmd.ts +100 -0
- package/src/coding/checkpoints.ts +270 -0
- package/src/coding/diff.ts +136 -0
- package/src/coding/files.ts +339 -0
- package/src/coding/hashline.ts +319 -0
- package/src/coding/lsp.ts +406 -0
- package/src/coding/repomap-cache.ts +99 -0
- package/src/coding/repomap-files.ts +110 -0
- package/src/coding/repomap.ts +392 -0
- package/src/core/compaction.ts +399 -0
- package/src/core/config.ts +289 -0
- package/src/core/context-report.ts +228 -0
- package/src/core/context.ts +60 -0
- package/src/core/count-remote.ts +107 -0
- package/src/core/execpolicy-rules.ts +196 -0
- package/src/core/execpolicy.ts +385 -0
- package/src/core/executor.ts +397 -0
- package/src/core/guardrails.ts +400 -0
- package/src/core/hooks.ts +398 -0
- package/src/core/images.ts +230 -0
- package/src/core/intro.ts +236 -0
- package/src/core/loop.ts +621 -0
- package/src/core/modes.ts +372 -0
- package/src/core/orchestrator.ts +207 -0
- package/src/core/reflection.ts +165 -0
- package/src/core/sandbox-config.ts +167 -0
- package/src/core/session-images.ts +73 -0
- package/src/core/session.ts +398 -0
- package/src/core/settings.ts +98 -0
- package/src/core/stuck-detector.ts +273 -0
- package/src/core/tasks.ts +374 -0
- package/src/core/token-scale.ts +108 -0
- package/src/core/tool-output-budget.ts +166 -0
- package/src/core/tools.ts +288 -0
- package/src/core/types.ts +330 -0
- package/src/core/update-check.ts +171 -0
- package/src/core/update.ts +158 -0
- package/src/core/usage.ts +204 -0
- package/src/core/validate.ts +121 -0
- package/src/core/verify-gate.ts +159 -0
- package/src/core/verify.ts +237 -0
- package/src/core/voice.ts +158 -0
- package/src/core/win-job.ts +183 -0
- package/src/design/audit.ts +797 -0
- package/src/design/direction.ts +190 -0
- package/src/design/rules.ts +157 -0
- package/src/eval/bench.ts +150 -0
- package/src/eval/gauntlet-runner.ts +218 -0
- package/src/eval/gauntlet.ts +226 -0
- package/src/eval/grader.ts +186 -0
- package/src/eval/record.ts +202 -0
- package/src/eval/redact.ts +141 -0
- package/src/eval/replay.ts +147 -0
- package/src/eval/trajectory.ts +373 -0
- package/src/index.ts +17 -0
- package/src/market/catalogs/mcp-docs.json +111 -0
- package/src/market/catalogs/plugins.json +111 -0
- package/src/market/catalogs/skills.json +478 -0
- package/src/market/clone.ts +72 -0
- package/src/market/context-cost.ts +121 -0
- package/src/market/digest.ts +106 -0
- package/src/market/index.ts +22 -0
- package/src/market/install.ts +578 -0
- package/src/market/manifest.ts +187 -0
- package/src/market/prereq.ts +145 -0
- package/src/market/registry.ts +363 -0
- package/src/market/resolve.ts +111 -0
- package/src/market/types.ts +236 -0
- package/src/market/validate.ts +227 -0
- package/src/mcp/client.ts +431 -0
- package/src/mcp/config.ts +239 -0
- package/src/mcp/local-package.ts +211 -0
- package/src/mcp/market-catalog.ts +84 -0
- package/src/mcp/market-install.ts +289 -0
- package/src/mcp/market.ts +0 -0
- package/src/mcp/tools.ts +131 -0
- package/src/mcp/trust.ts +49 -0
- package/src/memory/blocks.ts +175 -0
- package/src/memory/recall.ts +355 -0
- package/src/memory/store.ts +105 -0
- package/src/memory/tools.ts +99 -0
- package/src/plugins/cli.ts +123 -0
- package/src/plugins/discover.ts +108 -0
- package/src/plugins/index.ts +50 -0
- package/src/plugins/init.ts +140 -0
- package/src/plugins/install.ts +184 -0
- package/src/plugins/load.ts +149 -0
- package/src/plugins/manifest.ts +106 -0
- package/src/plugins/state.ts +83 -0
- package/src/providers/auth.ts +293 -0
- package/src/providers/cache.ts +223 -0
- package/src/providers/catalog-local.ts +160 -0
- package/src/providers/catalog.ts +408 -0
- package/src/providers/middleware-context.ts +86 -0
- package/src/providers/middleware.ts +373 -0
- package/src/providers/profile-glm53.ts +111 -0
- package/src/providers/profile-sonnet5-persona.ts +65 -0
- package/src/providers/profile-sonnet5-voice.ts +23 -0
- package/src/providers/profiles.ts +156 -0
- package/src/providers/provider-config.ts +311 -0
- package/src/providers/registry.ts +302 -0
- package/src/providers/response-validation.ts +80 -0
- package/src/providers/retry.ts +234 -0
- package/src/providers/router.ts +294 -0
- package/src/providers/sse.ts +26 -0
- package/src/providers/stream-errors.ts +117 -0
- package/src/providers/stream.ts +569 -0
- package/src/providers/thinking.ts +189 -0
- package/src/providers/wire-messages.ts +129 -0
- package/src/sdk/client.ts +225 -0
- package/src/sdk/index.ts +3 -0
- package/src/server/dashboard.ts +144 -0
- package/src/server/http.ts +343 -0
- package/src/server/openapi.ts +246 -0
- package/src/sextant/card-hits.ts +102 -0
- package/src/sextant/card-keys.ts +55 -0
- package/src/sextant/context-source.ts +157 -0
- package/src/sextant/draw-agents.ts +273 -0
- package/src/sextant/draw-code.ts +388 -0
- package/src/sextant/draw-context.ts +222 -0
- package/src/sextant/draw-frame.ts +164 -0
- package/src/sextant/draw-market.ts +573 -0
- package/src/sextant/draw-messages.ts +386 -0
- package/src/sextant/draw-pet.ts +230 -0
- package/src/sextant/draw-plan.ts +159 -0
- package/src/sextant/draw-tabs.ts +85 -0
- package/src/sextant/draw-util.ts +65 -0
- package/src/sextant/engine.ts +230 -0
- package/src/sextant/frame-hits.ts +25 -0
- package/src/sextant/frame.ts +101 -0
- package/src/sextant/git-status.ts +197 -0
- package/src/sextant/grid.ts +59 -0
- package/src/sextant/input.ts +119 -0
- package/src/sextant/keys.ts +488 -0
- package/src/sextant/layout.ts +86 -0
- package/src/sextant/local-commands.ts +156 -0
- package/src/sextant/market-source.ts +287 -0
- package/src/sextant/mentions.ts +141 -0
- package/src/sextant/message-hits.ts +26 -0
- package/src/sextant/model.ts +387 -0
- package/src/sextant/overlays.ts +451 -0
- package/src/sextant/panel-hits.ts +38 -0
- package/src/sextant/pet.ts +399 -0
- package/src/sextant/screen.ts +324 -0
- package/src/sextant/scroll-hits.ts +66 -0
- package/src/sextant/scrollbar.ts +82 -0
- package/src/sextant/selection.ts +123 -0
- package/src/sextant/sextant-bridge.ts +174 -0
- package/src/sextant/sextant-cards.ts +142 -0
- package/src/sextant/sextant-diff-base.ts +63 -0
- package/src/sextant/sextant-files.ts +154 -0
- package/src/sextant/sextant-frame-loop.ts +314 -0
- package/src/sextant/sextant-renderer.ts +478 -0
- package/src/sextant/sextant-repo.ts +131 -0
- package/src/sextant/theme.ts +66 -0
- package/src/sextant/tool-rows.ts +189 -0
- package/src/sextant/types.ts +473 -0
- package/src/skills/index.ts +306 -0
- package/src/skills/tools.ts +69 -0
- package/src/skills/versioned.ts +227 -0
- package/src/telemetry/otel.ts +353 -0
- package/src/telemetry/otlp.ts +68 -0
- package/src/tools/ask-user.ts +156 -0
- package/src/tools/design.ts +151 -0
- package/src/tools/evalcell.ts +338 -0
- package/src/tools/html-text.ts +139 -0
- package/src/tools/provider.ts +149 -0
- package/src/tools/task.ts +216 -0
- package/src/tools/todo.ts +320 -0
- package/src/tools/webfetch.ts +331 -0
- package/src/tui/app.ts +608 -0
- package/src/tui/attach.ts +127 -0
- package/src/tui/checkpoints-cmd.ts +70 -0
- package/src/tui/clipboard-image.ts +81 -0
- package/src/tui/commands.ts +277 -0
- package/src/tui/cost.ts +108 -0
- package/src/tui/info-cmd.ts +144 -0
- package/src/tui/mcp-cmd.ts +128 -0
- package/src/tui/modes-cmd.ts +45 -0
- package/src/tui/overlays.ts +97 -0
- package/src/tui/pi-renderer.ts +424 -0
- package/src/tui/providers-cmd.ts +366 -0
- package/src/tui/renderer.ts +101 -0
- package/src/tui/replay-marker.ts +29 -0
- package/src/tui/session-cmd.ts +146 -0
- package/src/tui/sextant-attach.ts +68 -0
- package/src/tui/sextant-io.ts +184 -0
- package/src/tui/sextant-smoke.ts +110 -0
- package/src/tui/smoke.ts +72 -0
- package/src/tui/theme.ts +59 -0
- package/src/tui/todo-label.ts +7 -0
- package/src/workflow/engine.ts +266 -0
- package/tsconfig.json +30 -0
- package/vendor/pi-tui/LICENSE +21 -0
- package/vendor/pi-tui/PATCHES.md +12 -0
- package/vendor/pi-tui/PROVENANCE.md +12 -0
- package/vendor/pi-tui/README.upstream.md +854 -0
- package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
- package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
- package/vendor/pi-tui/src/alt-screen-search.ts +158 -0
- package/vendor/pi-tui/src/autocomplete.ts +827 -0
- package/vendor/pi-tui/src/components/alt-screen-flash.ts +52 -0
- package/vendor/pi-tui/src/components/box.ts +138 -0
- package/vendor/pi-tui/src/components/cancellable-loader.ts +41 -0
- package/vendor/pi-tui/src/components/editor.ts +2364 -0
- package/vendor/pi-tui/src/components/h-stack.ts +45 -0
- package/vendor/pi-tui/src/components/image.ts +128 -0
- package/vendor/pi-tui/src/components/input.ts +448 -0
- package/vendor/pi-tui/src/components/loader.ts +93 -0
- package/vendor/pi-tui/src/components/markdown.ts +1016 -0
- package/vendor/pi-tui/src/components/scroll-view.ts +217 -0
- package/vendor/pi-tui/src/components/select-list.ts +230 -0
- package/vendor/pi-tui/src/components/settings-list.ts +277 -0
- package/vendor/pi-tui/src/components/spacer.ts +29 -0
- package/vendor/pi-tui/src/components/stack.ts +155 -0
- package/vendor/pi-tui/src/components/text.ts +108 -0
- package/vendor/pi-tui/src/components/truncated-text.ts +66 -0
- package/vendor/pi-tui/src/components/v-stack.ts +34 -0
- package/vendor/pi-tui/src/editor-component.ts +75 -0
- package/vendor/pi-tui/src/fuzzy.ts +138 -0
- package/vendor/pi-tui/src/index.ts +149 -0
- package/vendor/pi-tui/src/keybindings.ts +321 -0
- package/vendor/pi-tui/src/keys.ts +1402 -0
- package/vendor/pi-tui/src/kill-ring.ts +47 -0
- package/vendor/pi-tui/src/latex.ts +1381 -0
- package/vendor/pi-tui/src/layout-node.ts +52 -0
- package/vendor/pi-tui/src/layout.ts +411 -0
- package/vendor/pi-tui/src/native-modifiers.ts +60 -0
- package/vendor/pi-tui/src/native-module-path.ts +32 -0
- package/vendor/pi-tui/src/stdin-buffer.ts +445 -0
- package/vendor/pi-tui/src/terminal-colors.ts +74 -0
- package/vendor/pi-tui/src/terminal-image.ts +701 -0
- package/vendor/pi-tui/src/terminal.ts +554 -0
- package/vendor/pi-tui/src/tui-alt-screen.ts +1379 -0
- package/vendor/pi-tui/src/tui-main-screen.ts +655 -0
- package/vendor/pi-tui/src/tui.ts +1264 -0
- package/vendor/pi-tui/src/undo-stack.ts +29 -0
- package/vendor/pi-tui/src/utils.ts +1327 -0
- package/vendor/pi-tui/src/word-navigation.ts +118 -0
- package/vendor/pi-tui/test/test-themes.ts +39 -0
- package/vendor/pi-tui/test/virtual-terminal.ts +219 -0
- package/CHANGELOG.md +0 -527
- package/bin/rovecode.js +0 -24
- package/dist/cli/app-j6gn14w3.js +0 -2
- package/dist/cli/ask-user-cwstt8fz.js +0 -2
- package/dist/cli/auth-login-9bbp9915.js +0 -2
- package/dist/cli/auth-m8p9grty.js +0 -2
- package/dist/cli/bench-16zqdms5.js +0 -9
- package/dist/cli/catalog-1xchffa4.js +0 -2
- package/dist/cli/cli-1n1zb64f.js +0 -2
- package/dist/cli/client-2t9gjkck.js +0 -2
- package/dist/cli/commands-exafvm2b.js +0 -2
- package/dist/cli/connect-6zde0kn3.js +0 -2
- package/dist/cli/context-cmd-5t43wgqt.js +0 -2
- package/dist/cli/context-report-kt01pw8y.js +0 -2
- package/dist/cli/count-remote-ap7x3vh6.js +0 -2
- package/dist/cli/design-ne5zszyh.js +0 -2
- package/dist/cli/dispatch-2r5myxye.js +0 -2
- package/dist/cli/doctor-ws4fh4tn.js +0 -3
- package/dist/cli/executor-bdrjn634.js +0 -2
- package/dist/cli/export-1mxb9g5p.js +0 -2
- package/dist/cli/files-g104xghh.js +0 -2
- package/dist/cli/gauntlet-07xrjpj7.js +0 -2
- package/dist/cli/gauntlet-runner-xvy64436.js +0 -10
- package/dist/cli/gauntlet-wave3-jm91yt5w.js +0 -5
- package/dist/cli/gauntlet-wave4-r13py7p1.js +0 -14
- package/dist/cli/hashline-znvrat11.js +0 -2
- package/dist/cli/http-xafw6fsh.js +0 -143
- package/dist/cli/index-1sgjm25y.js +0 -2
- package/dist/cli/init-g2m0tn4m.js +0 -51
- package/dist/cli/install-avaqjjqq.js +0 -2
- package/dist/cli/loop-mmpfft01.js +0 -2
- package/dist/cli/main-0904f6ps.js +0 -5
- package/dist/cli/main-0ab9fc26.js +0 -9
- package/dist/cli/main-0jys2ccn.js +0 -3
- package/dist/cli/main-0mtcdbs7.js +0 -3
- package/dist/cli/main-0z1w2zsg.js +0 -3
- package/dist/cli/main-1dchs7xv.js +0 -18
- package/dist/cli/main-1ereejm1.js +0 -3
- package/dist/cli/main-1k1kw6b5.js +0 -3
- package/dist/cli/main-27y4sm2k.js +0 -38
- package/dist/cli/main-2wwjex5j.js +0 -58
- package/dist/cli/main-2yeveeve.js +0 -6
- package/dist/cli/main-2yfck9b5.js +0 -3
- package/dist/cli/main-2zmzgkwh.js +0 -3
- package/dist/cli/main-351pz3z7.js +0 -7
- package/dist/cli/main-3gjqfh7a.js +0 -6
- package/dist/cli/main-3nf3kgve.js +0 -3
- package/dist/cli/main-3pjrb2hd.js +0 -3
- package/dist/cli/main-3rxcvgna.js +0 -19
- package/dist/cli/main-4b3jgy66.js +0 -19
- package/dist/cli/main-4wndhjdc.js +0 -7
- package/dist/cli/main-4xcmvxnk.js +0 -3
- package/dist/cli/main-5tbz0wbz.js +0 -4
- package/dist/cli/main-5ywnwthm.js +0 -3
- package/dist/cli/main-6b62vkz0.js +0 -14
- package/dist/cli/main-6dnk69vp.js +0 -3
- package/dist/cli/main-6genrmhs.js +0 -136
- package/dist/cli/main-73g7eff4.js +0 -15
- package/dist/cli/main-7c5thhjd.js +0 -5
- package/dist/cli/main-7rn6bqje.js +0 -3
- package/dist/cli/main-80haw7qk.js +0 -4
- package/dist/cli/main-875s60s2.js +0 -4
- package/dist/cli/main-8kjxbpw4.js +0 -8
- package/dist/cli/main-90ds1z4e.js +0 -10
- package/dist/cli/main-9etavkew.js +0 -3
- package/dist/cli/main-a9njrkk1.js +0 -3
- package/dist/cli/main-aecrjq2d.js +0 -12
- package/dist/cli/main-ck9asesq.js +0 -9
- package/dist/cli/main-cta9racd.js +0 -4
- package/dist/cli/main-ddv7j2ag.js +0 -3
- package/dist/cli/main-dfreez27.js +0 -10
- package/dist/cli/main-f7rw7des.js +0 -3
- package/dist/cli/main-ggcn7rd7.js +0 -5
- package/dist/cli/main-gzkmycnv.js +0 -3
- package/dist/cli/main-hq51jg8v.js +0 -18
- package/dist/cli/main-jft389w9.js +0 -8
- package/dist/cli/main-k1eqkg83.js +0 -3
- package/dist/cli/main-k2y8a2aw.js +0 -9
- package/dist/cli/main-kcpbykxz.js +0 -4
- package/dist/cli/main-kd488vje.js +0 -22
- package/dist/cli/main-kh32yvgk.js +0 -5
- package/dist/cli/main-kqxnqjnv.js +0 -25
- package/dist/cli/main-kyn0xnsg.js +0 -3
- package/dist/cli/main-m1kk6fp5.js +0 -21
- package/dist/cli/main-mv40pcr2.js +0 -4
- package/dist/cli/main-n0t3973w.js +0 -3
- package/dist/cli/main-nqveez48.js +0 -4
- package/dist/cli/main-pknhvrmj.js +0 -3
- package/dist/cli/main-pn1w7a7j.js +0 -3
- package/dist/cli/main-prxxs70n.js +0 -4
- package/dist/cli/main-q3vsesf9.js +0 -3
- package/dist/cli/main-qsevpgsv.js +0 -3
- package/dist/cli/main-rdgdw24b.js +0 -25
- package/dist/cli/main-rfth4tbm.js +0 -16
- package/dist/cli/main-rg0wn0xf.js +0 -5
- package/dist/cli/main-sdmxhtv8.js +0 -4
- package/dist/cli/main-skbp13js.js +0 -18
- package/dist/cli/main-t4xnd213.js +0 -7
- package/dist/cli/main-vqak588n.js +0 -4
- package/dist/cli/main-w2n1303f.js +0 -9
- package/dist/cli/main-wbrdspr2.js +0 -5
- package/dist/cli/main-wsrg79c1.js +0 -7
- package/dist/cli/main-x4r0fne4.js +0 -5
- package/dist/cli/main-xea2f3tn.js +0 -6
- package/dist/cli/main-xg704a3c.js +0 -3
- package/dist/cli/main-xvnrabfp.js +0 -16
- package/dist/cli/main-xy53xf0r.js +0 -4
- package/dist/cli/main-y1fqy60y.js +0 -3
- package/dist/cli/main-yn8cd281.js +0 -34
- package/dist/cli/main-yr0ksc0h.js +0 -4
- package/dist/cli/main-z2ex2vyf.js +0 -4
- package/dist/cli/main-z3aayzvq.js +0 -3
- package/dist/cli/main-zaqh35jg.js +0 -3
- package/dist/cli/main-zc2e8e46.js +0 -4
- package/dist/cli/main-zzrfw6cf.js +0 -13
- package/dist/cli/main.js +0 -280
- package/dist/cli/market-cmd-e14kmx9n.js +0 -5
- package/dist/cli/mcp-login-wq7ktdek.js +0 -2
- package/dist/cli/mcp-market-cmd-9mg3jecy.js +0 -2
- package/dist/cli/notify-b7qc0cjb.js +0 -2
- package/dist/cli/oauth-z8whcgfx.js +0 -2
- package/dist/cli/output-b3ewj3ps.js +0 -16
- package/dist/cli/profiles-6mr5he5e.js +0 -2
- package/dist/cli/provider-config-g7j42q8x.js +0 -2
- package/dist/cli/provider-jr1y8vvm.js +0 -2
- package/dist/cli/registry-s8yk86g0.js +0 -2
- package/dist/cli/registry-t6p8d4mn.js +0 -2
- package/dist/cli/repl-bajwe1mh.js +0 -11
- package/dist/cli/resume-rwn9nz7y.js +0 -2
- package/dist/cli/run-flags-nah7ndpt.js +0 -2
- package/dist/cli/runtime-n7gafzhb.js +0 -2
- package/dist/cli/sandbox-config-emdy18x4.js +0 -2
- package/dist/cli/server-b0nvs2bn.js +0 -5
- package/dist/cli/session-arg-y75wd4kj.js +0 -2
- package/dist/cli/session-j62evmjq.js +0 -2
- package/dist/cli/sessions-cmd-tsnwz0ns.js +0 -7
- package/dist/cli/settings-df10wfez.js +0 -2
- package/dist/cli/setup-jzvv72fg.js +0 -2
- package/dist/cli/sextant-smoke-37m81ke6.js +0 -5
- package/dist/cli/skills-cmd-gjxnxnhx.js +0 -2
- package/dist/cli/smoke-p7748apt.js +0 -8
- package/dist/cli/start-chat-s4st3mm0.js +0 -12
- package/dist/cli/stream-gmeyewds.js +0 -2
- package/dist/cli/task-gh0kkp3n.js +0 -2
- package/dist/cli/tasks-z1kfpe8e.js +0 -2
- package/dist/cli/thinking-0eqkrz6t.js +0 -2
- package/dist/cli/todo-5brcrt9m.js +0 -2
- package/dist/cli/tools-7pzm0vj9.js +0 -2
- package/dist/cli/tools-s635p6s8.js +0 -2
- package/dist/cli/trust-cmd-cjav8zgm.js +0 -2
- package/dist/cli/update-check-pt31bm2f.js +0 -2
- package/dist/cli/update-cmd-tk131s9t.js +0 -2
- package/dist/cli/voice-56nabd8d.js +0 -2
- package/dist/cli/webfetch-xd8q596m.js +0 -2
- package/dist/cli/websearch-5hkf98k1.js +0 -2
- package/dist/cli/workflow-cmd-cy3cvzjp.js +0 -4
- package/dist/cli/workspace-q10g5z3e.js +0 -2
- package/dist/lib/index.js +0 -62
- package/dist/lib/models-index.json +0 -1
- package/dist/lib/plugins.js +0 -55
- package/dist/lib/providers.js +0 -17
- package/dist/lib/public-api.js +0 -20
- package/dist/lib/sdk.js +0 -360
- /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
|
+
}
|