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,189 @@
|
|
|
1
|
+
/** ONE effort dial (core/types.ts ThinkingEffort: auto | off | low | medium | high), every wire it can reach.
|
|
2
|
+
* This module answers, for a model on a protocol, two questions the adapters and the humans both ask:
|
|
3
|
+
* which request fields carry the level, and — in one sentence — what the model will actually receive.
|
|
4
|
+
* stream.ts spreads `thinkingPlan(...).fields` into the body; /effort and `rovecode model show` print `says`.
|
|
5
|
+
*
|
|
6
|
+
* Rules (Berkay, 2026-09-04): `auto` sends NOTHING and leaves the endpoint's own default standing (the
|
|
7
|
+
* Claude 5 family reasons adaptively on its own; the old default "off" switched that off). `off` is an
|
|
8
|
+
* explicit disable where the API has one, otherwise nothing. A level maps onto the endpoint's own
|
|
9
|
+
* vocabulary; where the vocabulary has fewer steps, medium rounds UP (a rovecode "medium" asks for more
|
|
10
|
+
* than "low"). A model that always reasons, or has no reasoning mode, gets nothing — sending a dial such a
|
|
11
|
+
* model rejects is a 400, not a downgrade (grok-4, gpt-4-class on OpenAI proper).
|
|
12
|
+
*
|
|
13
|
+
* Dialects are matched by MODEL ID, provider-agnostic (the same GLM under kaesra, zai or openrouter is one
|
|
14
|
+
* family) — except OpenRouter, whose unified `reasoning` object wins for every model it fronts, and Groq's
|
|
15
|
+
* Qwen vocabulary. The catalog's word is stronger than any regex: a model models.dev lists WITHOUT a
|
|
16
|
+
* reasoning mode (ModelRef.reasoning === false, stamped by cli/runtime.ts buildDef) gets nothing.
|
|
17
|
+
*
|
|
18
|
+
* Only Anthropic and GLM-5.3 are measured live (stream.ts header, profiles.ts header). The other
|
|
19
|
+
* vocabularies are the vendors' published API docs as of 2026-09 — docs/thinking.md carries the matrix
|
|
20
|
+
* and marks each row measured or documented. */
|
|
21
|
+
|
|
22
|
+
import type { ModelRef, ThinkingEffort } from "../core/types.ts";
|
|
23
|
+
import { GLM_53_MODEL_RE, wireProfileFor } from "./profiles.ts";
|
|
24
|
+
|
|
25
|
+
export type WireProtocol = "openai" | "anthropic";
|
|
26
|
+
type Level = "low" | "medium" | "high";
|
|
27
|
+
type Setting = "auto" | "off" | Level;
|
|
28
|
+
|
|
29
|
+
export interface ThinkingPlan {
|
|
30
|
+
/** the dialect that answered (docs/thinking.md row) */
|
|
31
|
+
dialect: string;
|
|
32
|
+
/** spread into the request body */
|
|
33
|
+
fields: Record<string, unknown>;
|
|
34
|
+
/** one sentence for the human: the exact field, or why nothing goes */
|
|
35
|
+
says: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** undefined (a bare ModelRef) is auto — the runtime stamps every ref, but adapters must not care */
|
|
39
|
+
const setting = (e: ThinkingEffort | undefined): Setting => e ?? "auto";
|
|
40
|
+
const NOTHING_AUTO = "nothing — auto: the endpoint's own default stands";
|
|
41
|
+
|
|
42
|
+
// ------------------------------------------------------------------ Anthropic (Messages API), two shapes
|
|
43
|
+
|
|
44
|
+
/** Anthropic has TWO request shapes and no model exposes both — see the measured table in stream.ts.
|
|
45
|
+
* The shape is learned per provider+model from a wrong-shape 400 (stream.ts anthropicPost). */
|
|
46
|
+
export type AnthropicThinkingShape = "effort" | "budget";
|
|
47
|
+
|
|
48
|
+
/** The budget in tokens per level for the older `thinking.enabled` shape. Steps ~x4 apart so the
|
|
49
|
+
* levels are felt. The endpoint requires ≥1024 and max_tokens strictly greater (anthropicMaxTokens). */
|
|
50
|
+
export function thinkingBudget(effort: ThinkingEffort | undefined): number | null {
|
|
51
|
+
switch (effort) {
|
|
52
|
+
case "low": return 2_048;
|
|
53
|
+
case "medium": return 8_192;
|
|
54
|
+
case "high": return 24_576;
|
|
55
|
+
default: return null; // "off", "auto" and unset: no budget
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** the request fields that carry the effort, for one shape */
|
|
60
|
+
export function anthropicThinking(effort: ThinkingEffort | undefined, shape: AnthropicThinkingShape): Record<string, unknown> {
|
|
61
|
+
if (effort === undefined || effort === "auto") return {}; // unset / auto: leave the model's default alone (Claude 5: adaptive, high)
|
|
62
|
+
if (effort === "off") return { thinking: { type: "disabled" } }; // explicit, deliberate: opus-5 thinks unless told not to
|
|
63
|
+
if (shape === "effort") return { output_config: { effort } }; // low | medium | high (the API also has xhigh/max)
|
|
64
|
+
const budget = thinkingBudget(effort);
|
|
65
|
+
return budget === null ? {} : { thinking: { type: "enabled", budget_tokens: budget } };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function anthropicPlan(level: Setting, shape: AnthropicThinkingShape): ThinkingPlan {
|
|
69
|
+
const fields = anthropicThinking(level, shape);
|
|
70
|
+
const says = level === "auto" ? NOTHING_AUTO
|
|
71
|
+
: level === "off" ? 'thinking: { type: "disabled" } — an explicit off; Claude 5 reasons by default'
|
|
72
|
+
: `${JSON.stringify(fields).slice(1, -1).replace(/"(\w+)":/g, "$1: ").replace(/,/g, ", ")} (the ${shape} shape — learned from the endpoint, kept per model)`;
|
|
73
|
+
return { dialect: `anthropic/${shape}`, fields, says };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ------------------------------------------------------------------ OpenAI-compatible dialects
|
|
77
|
+
|
|
78
|
+
interface Dialect {
|
|
79
|
+
id: string;
|
|
80
|
+
matches(m: ModelRef): boolean;
|
|
81
|
+
/** never called with "auto" — that is answered centrally with nothing */
|
|
82
|
+
plan(level: "off" | Level, m: ModelRef): { fields: Record<string, unknown>; says: string };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const q = (s: string): string => JSON.stringify(s);
|
|
86
|
+
const nothing = (why: string): { fields: Record<string, unknown>; says: string } => ({ fields: {}, says: `nothing — ${why}` });
|
|
87
|
+
const word = (w: string, note = ""): { fields: Record<string, unknown>; says: string } => ({ fields: { reasoning_effort: w }, says: `reasoning_effort: ${q(w)}${note ? ` (${note})` : ""}` });
|
|
88
|
+
const onOff = (on: boolean, vendor: string): { fields: Record<string, unknown>; says: string } => ({
|
|
89
|
+
fields: { thinking: { type: on ? "enabled" : "disabled" } },
|
|
90
|
+
says: `thinking: { type: ${q(on ? "enabled" : "disabled")} } (${vendor} has an on/off switch, no levels)`,
|
|
91
|
+
});
|
|
92
|
+
const id = (re: RegExp) => (m: ModelRef): boolean => re.test(m.model);
|
|
93
|
+
|
|
94
|
+
const DIALECTS: readonly Dialect[] = [
|
|
95
|
+
// the catalog's word first: models.dev says this model has no reasoning mode — a dial would be rejected or ignored
|
|
96
|
+
{ id: "catalog: no reasoning mode", matches: (m) => m.reasoning === false,
|
|
97
|
+
plan: (_l, m) => nothing(`the catalog lists ${m.model} without a reasoning mode, so no dial is sent`) },
|
|
98
|
+
// OpenRouter normalizes every upstream behind one object; its own words (low|medium|high, enabled)
|
|
99
|
+
{ id: "openrouter", matches: (m) => m.provider === "openrouter",
|
|
100
|
+
plan: (l) => l === "off"
|
|
101
|
+
? { fields: { reasoning: { enabled: false } }, says: "reasoning: { enabled: false } (OpenRouter's unified field; a model that always reasons ignores it)" }
|
|
102
|
+
: { fields: { reasoning: { effort: l } }, says: `reasoning: { effort: ${q(l)} } (OpenRouter's unified field, translated per upstream)` } },
|
|
103
|
+
// GLM-5.3: measured (profiles.ts) — low|high|max, medium rounds up to high, cannot be switched off. The
|
|
104
|
+
// words come from the wire profile; ROVECODE_PROFILE=off means "no GLM tuning at all", so the plain
|
|
105
|
+
// OpenAI word goes instead (the A/B the off-switch exists for), and off sends nothing either way.
|
|
106
|
+
{ id: "glm-5.3", matches: id(GLM_53_MODEL_RE),
|
|
107
|
+
plan: (l, m) => {
|
|
108
|
+
if (l === "off") return nothing("GLM-5.3 cannot switch thinking off (Z.ai: thinking.type accepts enabled only); the endpoint default is max");
|
|
109
|
+
const profile = wireProfileFor(m);
|
|
110
|
+
if (profile === null) return word(l, "ROVECODE_PROFILE=off: the plain word, not GLM's low | high | max");
|
|
111
|
+
return word(profile.reasoningEffort(l)!, "GLM's words are low | high | max; medium rounds up");
|
|
112
|
+
} },
|
|
113
|
+
{ id: "glm", matches: id(/(^|[/:])glm-(4\.[5-9]|4\.\d{2,}|5(\.\d+)?)(?=[-:]|$)/i), plan: (l) => onOff(l !== "off", "GLM") },
|
|
114
|
+
{ id: "deepseek", matches: id(/deepseek/i),
|
|
115
|
+
plan: (l, m) => /reasoner|r1/i.test(m.model) ? nothing(`${m.model} always thinks — no dial`) : onOff(l !== "off", "DeepSeek") },
|
|
116
|
+
{ id: "qwen", matches: id(/(^|[/:])(qwen|qwq)/i),
|
|
117
|
+
plan: (l, m) => {
|
|
118
|
+
if (m.provider === "groq") return l === "off" ? word("none", "Groq's Qwen words are none | default") : word("default", "Groq's Qwen words are none | default");
|
|
119
|
+
if (l === "off") return { fields: { enable_thinking: false }, says: "enable_thinking: false (DashScope / most Qwen hosts; a vLLM host wants chat_template_kwargs instead and ignores this)" };
|
|
120
|
+
const budget = thinkingBudget(l)!;
|
|
121
|
+
return { fields: { enable_thinking: true, thinking_budget: budget }, says: `enable_thinking: true, thinking_budget: ${budget} (DashScope's fields; a host without them ignores both)` };
|
|
122
|
+
} },
|
|
123
|
+
{ id: "kimi", matches: id(/kimi|moonshot/i),
|
|
124
|
+
plan: (l, m) => /thinking/i.test(m.model) ? nothing(`${m.model} always thinks — no dial`)
|
|
125
|
+
: /k2[.-]5|k2\.5/i.test(m.model) ? onOff(l !== "off", "Moonshot K2.5") : nothing(`${m.model} has no thinking mode (the -thinking variant does)`) },
|
|
126
|
+
{ id: "gemini", matches: id(/gemini/i),
|
|
127
|
+
plan: (l, m) => l !== "off" ? word(l, "Google's OpenAI-compatible layer maps low | medium | high to a thinking budget")
|
|
128
|
+
: /flash/i.test(m.model) ? { fields: { extra_body: { google: { thinking_config: { thinking_budget: 0 } } } }, says: "extra_body.google.thinking_config.thinking_budget: 0 (Flash can switch thinking off; Pro cannot)" }
|
|
129
|
+
: nothing(`${m.model} cannot switch thinking off (Gemini Pro keeps a minimum budget)`) },
|
|
130
|
+
// xAI (docs.x.ai, fetched 2026-09-04): grok-4.3 / 4.5 / 4.6 / 4.20 take reasoning_effort none | low | medium | high;
|
|
131
|
+
// the retired grok-4-0709 / grok-4-fast slugs are served by grok-4.3 since 2026-05-15, so they take the same words
|
|
132
|
+
{ id: "grok", matches: id(/grok/i),
|
|
133
|
+
plan: (l, m) => /non-reasoning/i.test(m.model) ? nothing(`${m.model} has no reasoning mode`)
|
|
134
|
+
: /grok-3-mini/i.test(m.model) ? (l === "off" ? nothing("grok-3-mini cannot switch reasoning off") : word(l === "low" ? "low" : "high", "xAI's words for grok-3-mini are low | high; medium rounds up"))
|
|
135
|
+
: l === "off" ? word("none", "xAI's explicit off (grok-4.3 and later; retired grok-4 slugs are served by grok-4.3)") : word(l, "xAI's words are none | low | medium | high") },
|
|
136
|
+
{ id: "gpt-oss", matches: id(/gpt-oss/i), plan: (l) => l === "off" ? nothing("gpt-oss cannot switch reasoning off (low is the floor)") : word(l) },
|
|
137
|
+
{ id: "openai o-series", matches: id(/(^|[/:])o[134](-|$)/i), plan: (l, m) => l === "off" ? nothing(`${m.model} cannot switch reasoning off`) : word(l) },
|
|
138
|
+
{ id: "openai gpt-5", matches: id(/(^|[/:])gpt-5/i),
|
|
139
|
+
plan: (l, m) => l !== "off" ? word(l)
|
|
140
|
+
: /gpt-5\.[1-9]/i.test(m.model) ? word("none", "gpt-5.1 and later: the explicit off") : word("minimal", "gpt-5 has no off; minimal is its floor") },
|
|
141
|
+
{ id: "openai gpt-4 class", matches: id(/(^|[/:])(gpt-4|gpt-3\.5|chatgpt)/i), plan: (_l, m) => nothing(`${m.model} has no reasoning mode and OpenAI rejects reasoning_effort for it`) },
|
|
142
|
+
{ id: "mistral", matches: id(/magistral|mistral|codestral|ministral|pixtral/i),
|
|
143
|
+
plan: (_l, m) => /magistral/i.test(m.model) ? nothing("Magistral always reasons — no dial") : nothing(`${m.model} has no reasoning mode`) },
|
|
144
|
+
{ id: "minimax", matches: id(/minimax/i), plan: (_l, m) => nothing(`${m.model} always reasons — no dial`) },
|
|
145
|
+
// the floor for anything else: the OpenAI word; off sends nothing (no common explicit disable)
|
|
146
|
+
{ id: "openai-compatible default", matches: () => true,
|
|
147
|
+
plan: (l) => l === "off" ? nothing("off sends nothing here: no common explicit disable on OpenAI-compatible endpoints; a model without a reasoning mode ignores the word anyway")
|
|
148
|
+
: word(l, "the OpenAI word; a model without a reasoning mode ignores it") },
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
/** the dialect a model on the OpenAI-compatible wire speaks (for docs and the matrix) */
|
|
152
|
+
export function dialectFor(model: ModelRef): Dialect["id"] {
|
|
153
|
+
return DIALECTS.find((d) => d.matches(model))!.id;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** what goes on the wire for this model, on this protocol, at its effort — and the sentence that says so */
|
|
157
|
+
export function thinkingPlan(model: ModelRef, protocol: WireProtocol, opts: { shape?: AnthropicThinkingShape } = {}): ThinkingPlan {
|
|
158
|
+
const level = setting(model.effort);
|
|
159
|
+
if (protocol === "anthropic") return anthropicPlan(level, opts.shape ?? "effort");
|
|
160
|
+
const d = DIALECTS.find((x) => x.matches(model))!;
|
|
161
|
+
if (level === "auto") return { dialect: d.id, fields: {}, says: NOTHING_AUTO };
|
|
162
|
+
return { dialect: d.id, ...d.plan(level, model) };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** the five rows `rovecode model show` prints: level → what this model receives */
|
|
166
|
+
export function thinkingTable(model: ModelRef, protocol: WireProtocol, opts: { shape?: AnthropicThinkingShape } = {}): { level: ThinkingEffort; says: string }[] {
|
|
167
|
+
return (["auto", "off", "low", "medium", "high"] as const).map((level) => ({ level, says: thinkingPlan({ ...model, effort: level }, protocol, opts).says }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** the one line the /effort note appends: `<provider/model> receives: <says>` */
|
|
171
|
+
export function thinkingLine(model: ModelRef, protocol: WireProtocol, opts: { shape?: AnthropicThinkingShape } = {}): string {
|
|
172
|
+
return `${model.provider}/${model.model} receives: ${thinkingPlan(model, protocol, opts).says}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** `rovecode model show`: the model, its protocol and dialect, then every level with what it puts on the
|
|
176
|
+
* wire — the current level marked. `model.effort` is the current level. */
|
|
177
|
+
export function thinkingReport(model: ModelRef, protocol: WireProtocol, opts: { shape?: AnthropicThinkingShape; source?: string; catalog?: string } = {}): string[] {
|
|
178
|
+
const current = setting(model.effort);
|
|
179
|
+
const dialect = protocol === "anthropic" ? `anthropic (${opts.shape ?? "effort"} shape)` : dialectFor(model);
|
|
180
|
+
const lines = [
|
|
181
|
+
`${model.provider}/${model.model}${opts.source ? ` (${opts.source})` : ""}`,
|
|
182
|
+
` protocol ${protocol}`,
|
|
183
|
+
` dialect ${dialect}${model.reasoning === false ? " — the catalog lists no reasoning mode" : model.reasoning === true ? " — the catalog lists a reasoning mode" : ""}`,
|
|
184
|
+
...(opts.catalog ? [` prices ${opts.catalog}`] : []), // where the numbers /cost uses come from — models.dev, or rovecode's own table
|
|
185
|
+
` effort ${current} (ROVECODE_EFFORT / --effort / /effort)`,
|
|
186
|
+
];
|
|
187
|
+
for (const row of thinkingTable(model, protocol, opts)) lines.push(` ${row.level === current ? "*" : " "} ${row.level.padEnd(7)} ${row.says}`);
|
|
188
|
+
return lines;
|
|
189
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Wire message lowering (ADR-003 seam; extracted from stream.ts for the 400-line cap): harness
|
|
2
|
+
* Message[] → OpenAI chat-completions / Anthropic Messages request shapes. Text and tool shapes
|
|
3
|
+
* are byte-identical to the pre-#34 stream.ts lowering. Port #34 adds image parts:
|
|
4
|
+
* - vision model: a USER message carrying images becomes a content-block array in part order —
|
|
5
|
+
* OpenAI `{type:"image_url", image_url:{url:"data:<mime>;base64,<data>", detail:"auto"}}`,
|
|
6
|
+
* Anthropic `{type:"image", source:{type:"base64", media_type, data}}`; image-free messages
|
|
7
|
+
* keep their plain-string content, so nothing changes for existing histories;
|
|
8
|
+
* - no vision (`vision: false` — stream.ts asks the models.dev catalog): each image lowers to
|
|
9
|
+
* imagePlaceholder() text and the message stays a plain string. The session keeps the real
|
|
10
|
+
* image; only the request is substituted (cline media.ts:6-12 pattern, opencode
|
|
11
|
+
* provider/transform.ts:409-441 unsupportedParts);
|
|
12
|
+
* - a sidecar that cannot be read lowers to a placeholder too — a request body never throws.
|
|
13
|
+
* Images on assistant/tool messages are nothing this harness produces (tool results with images
|
|
14
|
+
* are out of scope for #34): an assistant message WITHOUT tool calls lowers them to placeholder
|
|
15
|
+
* text (lowerContent's non-user branch); a tool-role message emits its tool_result parts only and
|
|
16
|
+
* an assistant message WITH tool calls emits partsText + tool_calls, so image parts on those two
|
|
17
|
+
* shapes are dropped from the request — never turned into blocks. */
|
|
18
|
+
|
|
19
|
+
import type { Message, ImagePart } from "../core/types.ts";
|
|
20
|
+
import { partsText } from "../core/loop.ts";
|
|
21
|
+
import { anthropicImageBlock, openaiImageBlock, imagePlaceholder } from "../core/images.ts";
|
|
22
|
+
|
|
23
|
+
export interface WireOptions {
|
|
24
|
+
/** the target model accepts image input; default true (unknown models are given the image —
|
|
25
|
+
* a wrong guess fails loudly at the provider instead of silently dropping the user's image) */
|
|
26
|
+
vision?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Block = Record<string, unknown>;
|
|
30
|
+
|
|
31
|
+
/** Content for a non-tool message: the pre-#34 plain string when no image is present; blocks in
|
|
32
|
+
* part order for a user message the model can see; placeholder text otherwise (text parts glue
|
|
33
|
+
* with "" exactly as partsText does, each image is its own line). */
|
|
34
|
+
function lowerContent(m: Message, vision: boolean, toBlock: (p: ImagePart) => Block | undefined): string | Block[] {
|
|
35
|
+
if (!m.parts.some((p) => p.kind === "image")) return partsText(m.parts);
|
|
36
|
+
if (vision && m.role === "user") {
|
|
37
|
+
const blocks: Block[] = [];
|
|
38
|
+
for (const p of m.parts) {
|
|
39
|
+
if (p.kind === "text") { if (p.text) blocks.push({ type: "text", text: p.text }); }
|
|
40
|
+
else if (p.kind === "image") blocks.push(toBlock(p) ?? { type: "text", text: imagePlaceholder(p, "file unavailable") });
|
|
41
|
+
}
|
|
42
|
+
return blocks;
|
|
43
|
+
}
|
|
44
|
+
const pieces: string[] = [];
|
|
45
|
+
let text = "";
|
|
46
|
+
for (const p of m.parts) {
|
|
47
|
+
if (p.kind === "text") text += p.text;
|
|
48
|
+
else if (p.kind === "image") {
|
|
49
|
+
if (text) { pieces.push(text); text = ""; }
|
|
50
|
+
pieces.push(imagePlaceholder(p, vision ? "file unavailable" : undefined));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (text) pieces.push(text);
|
|
54
|
+
return pieces.join("\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function toOpenAiMessages(messages: Message[], opts: WireOptions = {}): Record<string, unknown>[] {
|
|
58
|
+
const vision = opts.vision ?? true;
|
|
59
|
+
const out: Record<string, unknown>[] = [];
|
|
60
|
+
for (const m of messages) {
|
|
61
|
+
const calls = m.parts.filter((p) => p.kind === "tool_call");
|
|
62
|
+
const results = m.parts.filter((p) => p.kind === "tool_result");
|
|
63
|
+
if (m.role === "tool") {
|
|
64
|
+
for (const r of results) {
|
|
65
|
+
if (r.kind === "tool_result") out.push({ role: "tool", tool_call_id: r.callId, content: r.output });
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (m.role === "assistant" && calls.length > 0) {
|
|
70
|
+
out.push({
|
|
71
|
+
role: "assistant",
|
|
72
|
+
content: partsText(m.parts) || null,
|
|
73
|
+
tool_calls: calls.map((c) => c.kind === "tool_call" ? {
|
|
74
|
+
id: c.id, type: "function", function: { name: c.tool, arguments: JSON.stringify(c.args) },
|
|
75
|
+
} : {}),
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
const content = lowerContent(m, vision, (p) => openaiImageBlock(p));
|
|
79
|
+
if (content.length > 0 || m.role === "system") out.push({ role: m.role, content });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** StreamOptions.tools carries bare ToolSchema entries (name/description/args) — that is what
|
|
86
|
+
* every call site (loop → adapters) passes. Tolerate a {schema} wrapper (a full Tool object)
|
|
87
|
+
* too, so a mis-passed registry entry degrades gracefully instead of throwing mid-request. */
|
|
88
|
+
export function asToolSchema(t: unknown): { name: string; description: string; args: Record<string, unknown> } {
|
|
89
|
+
const o = t as { name?: string; description?: string; args?: Record<string, unknown>; schema?: { name: string; description: string; args: Record<string, unknown> } };
|
|
90
|
+
return o.schema ?? { name: o.name ?? "unknown", description: o.description ?? "", args: o.args ?? {} };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function toOpenAiToolSchemas(tools: unknown[]): Record<string, unknown>[] {
|
|
94
|
+
return tools.map((t) => {
|
|
95
|
+
const s = asToolSchema(t);
|
|
96
|
+
return { type: "function", function: { name: s.name, description: s.description, parameters: s.args } };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function toAnthropicMessages(messages: Message[], opts: WireOptions = {}): Record<string, unknown>[] {
|
|
101
|
+
const vision = opts.vision ?? true;
|
|
102
|
+
const out: Record<string, unknown>[] = [];
|
|
103
|
+
for (const m of messages) {
|
|
104
|
+
if (m.role === "system") continue;
|
|
105
|
+
const calls = m.parts.filter((p) => p.kind === "tool_call");
|
|
106
|
+
const results = m.parts.filter((p) => p.kind === "tool_result");
|
|
107
|
+
if (m.role === "tool") {
|
|
108
|
+
for (const r of results) {
|
|
109
|
+
if (r.kind === "tool_result") {
|
|
110
|
+
out.push({ role: "user", content: [{ type: "tool_result", tool_use_id: r.callId, content: r.output, is_error: !r.ok }] });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (m.role === "assistant" && calls.length > 0) {
|
|
116
|
+
const text = partsText(m.parts);
|
|
117
|
+
const content: Block[] = [];
|
|
118
|
+
if (text) content.push({ type: "text", text });
|
|
119
|
+
for (const c of calls) {
|
|
120
|
+
if (c.kind === "tool_call") content.push({ type: "tool_use", id: c.id, name: c.tool, input: c.args });
|
|
121
|
+
}
|
|
122
|
+
out.push({ role: "assistant", content });
|
|
123
|
+
} else {
|
|
124
|
+
const content = lowerContent(m, vision, anthropicImageBlock);
|
|
125
|
+
if (content.length > 0) out.push({ role: m.role === "user" ? "user" : "assistant", content });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/** @rovecode/sdk — local-mode client (Faz F1, docs/design/sdk-blueprint.md §2-3).
|
|
2
|
+
*
|
|
3
|
+
* ONE interface over the harness core, two planned transports: "local" imports the core
|
|
4
|
+
* in-process (this file), "remote" will speak HTTP/SSE to `rovecode serve` against the same
|
|
5
|
+
* types. The client is render-only and loop-free: every run goes through the ONE agentLoop
|
|
6
|
+
* via bootRuntime (ADR-003), exactly like cmdRun — the SDK adds a contract, not a second engine.
|
|
7
|
+
*
|
|
8
|
+
* Event model: RunEvent stays untouched (session replay purity); the SDK unions it with
|
|
9
|
+
* `agent_tree_update`, synthesized from TaskManager.subscribe — the tree is derived state,
|
|
10
|
+
* not transcript, so it never enters the session JSONL. */
|
|
11
|
+
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import type { ApprovalFn, ModelRef, RunEvent, StreamFn } from "../core/types.ts";
|
|
14
|
+
import type { RunConfig } from "../core/types.ts";
|
|
15
|
+
import { agentLoop, SteeringQueue } from "../core/loop.ts";
|
|
16
|
+
import { listSessions, type SessionSummary } from "../core/session.ts";
|
|
17
|
+
import type { TaskId, TaskInfo, TaskStatus, WaitOptions } from "../core/tasks.ts";
|
|
18
|
+
import { bootRuntime, type Runtime } from "../cli/runtime.ts";
|
|
19
|
+
|
|
20
|
+
/** A node in the live subagent tree (TaskManager flattened, parent edge explicit). */
|
|
21
|
+
export interface AgentNode {
|
|
22
|
+
id: TaskId;
|
|
23
|
+
parent: TaskId | null;
|
|
24
|
+
label: string;
|
|
25
|
+
agent: string;
|
|
26
|
+
goal: string;
|
|
27
|
+
status: TaskStatus;
|
|
28
|
+
depth: number;
|
|
29
|
+
isolated: boolean;
|
|
30
|
+
createdAt: number;
|
|
31
|
+
startedAt?: number;
|
|
32
|
+
finishedAt?: number;
|
|
33
|
+
summary?: string;
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type SdkEvent = RunEvent | { type: "agent_tree_update"; sessionId: string; tree: AgentNode[] };
|
|
38
|
+
|
|
39
|
+
export interface ClientOptions {
|
|
40
|
+
cwd?: string;
|
|
41
|
+
/** test seam — injected stream wins over provider resolution; null forces "no provider" */
|
|
42
|
+
stream?: StreamFn | null;
|
|
43
|
+
/** permission level: true = "auto" (yolo). Default "ask" + the approval callback. */
|
|
44
|
+
yolo?: boolean;
|
|
45
|
+
/** the SDK's human-equivalent: a request the rules mark "prompt" lands here */
|
|
46
|
+
approval?: ApprovalFn;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface SessionHandle {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
/** Run one prompt; yields the loop's events verbatim plus agent_tree_update. */
|
|
52
|
+
prompt(goal: string, opts?: { signal?: AbortSignal }): AsyncGenerator<SdkEvent, void>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface RovecodeClient {
|
|
56
|
+
readonly cwd: string;
|
|
57
|
+
session: {
|
|
58
|
+
create(opts?: { id?: string }): Promise<SessionHandle>;
|
|
59
|
+
list(): SessionSummary[];
|
|
60
|
+
};
|
|
61
|
+
task: {
|
|
62
|
+
start(sessionId: string, req: { agent?: string; goal: string; label?: string; isolated?: boolean }): { ok: true; id: TaskId } | { ok: false; reason: string };
|
|
63
|
+
list(sessionId: string): TaskInfo[];
|
|
64
|
+
wait(sessionId: string, id: TaskId, opts?: WaitOptions): Promise<TaskInfo | undefined>;
|
|
65
|
+
cancel(sessionId: string, id: TaskId): boolean;
|
|
66
|
+
};
|
|
67
|
+
agent: { tree(sessionId: string): AgentNode[] };
|
|
68
|
+
events: { subscribe(fn: (e: SdkEvent) => void): () => void };
|
|
69
|
+
close(): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** tasks.ts TaskInfo → sdk AgentNode (parent edge: StartOptions.caller). */
|
|
73
|
+
export function agentTree(tasks: TaskInfo[]): AgentNode[] {
|
|
74
|
+
return tasks.map((t) => ({
|
|
75
|
+
id: t.id, parent: t.parent ?? null, label: t.label, agent: t.agent, goal: t.goal,
|
|
76
|
+
status: t.status, depth: t.depth, isolated: t.isolated, createdAt: t.createdAt,
|
|
77
|
+
...(t.startedAt !== undefined ? { startedAt: t.startedAt } : {}),
|
|
78
|
+
...(t.finishedAt !== undefined ? { finishedAt: t.finishedAt } : {}),
|
|
79
|
+
...(t.summary !== undefined ? { summary: t.summary } : {}),
|
|
80
|
+
...(t.error !== undefined ? { error: t.error } : {}),
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Push-queue: producers push, one consumer drains via async iteration. */
|
|
85
|
+
class EventQueue {
|
|
86
|
+
private buf: SdkEvent[] = [];
|
|
87
|
+
private wake: (() => void) | null = null;
|
|
88
|
+
private closed = false;
|
|
89
|
+
push(e: SdkEvent): void {
|
|
90
|
+
if (this.closed) return;
|
|
91
|
+
this.buf.push(e);
|
|
92
|
+
this.wake?.();
|
|
93
|
+
}
|
|
94
|
+
close(): void { this.closed = true; this.wake?.(); }
|
|
95
|
+
async *drain(): AsyncGenerator<SdkEvent, void> {
|
|
96
|
+
for (;;) {
|
|
97
|
+
const e = this.buf.shift();
|
|
98
|
+
if (e !== undefined) { yield e; continue; }
|
|
99
|
+
if (this.closed) return;
|
|
100
|
+
await new Promise<void>((r) => { this.wake = r; });
|
|
101
|
+
this.wake = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function createClient(opts: ClientOptions = {}): Promise<RovecodeClient> {
|
|
107
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
108
|
+
const sessionsRoot = join(cwd, ".rovecode", "sessions");
|
|
109
|
+
const runtimes = new Map<string, Runtime>();
|
|
110
|
+
const listeners = new Set<(e: SdkEvent) => void>();
|
|
111
|
+
const broadcast = (e: SdkEvent): void => { for (const fn of listeners) fn(e); };
|
|
112
|
+
|
|
113
|
+
async function runtimeFor(id: string): Promise<Runtime> {
|
|
114
|
+
const hit = runtimes.get(id);
|
|
115
|
+
if (hit) return hit;
|
|
116
|
+
const rtOpts = { cwd, sessionId: id, ...(opts.stream !== undefined ? { stream: opts.stream } : {}) };
|
|
117
|
+
const rt = await bootRuntime(rtOpts);
|
|
118
|
+
// background-task status flips become tree events, even between prompts
|
|
119
|
+
rt.tasks.subscribe(() => {
|
|
120
|
+
broadcast({ type: "agent_tree_update", sessionId: id, tree: agentTree(rt.tasks.list()) });
|
|
121
|
+
});
|
|
122
|
+
runtimes.set(id, rt);
|
|
123
|
+
return rt;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function requireRuntime(id: string): Runtime {
|
|
127
|
+
const rt = runtimes.get(id);
|
|
128
|
+
if (!rt) throw new Error(`unknown session '${id}' — session.create() it first (SDK v1 tracks live sessions only)`);
|
|
129
|
+
return rt;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
cwd,
|
|
134
|
+
session: {
|
|
135
|
+
async create(createOpts: { id?: string } = {}): Promise<SessionHandle> {
|
|
136
|
+
const id = createOpts.id ?? `sdk-${Date.now().toString(36)}`;
|
|
137
|
+
const rt = await runtimeFor(id);
|
|
138
|
+
const why = rt.noProviderReason();
|
|
139
|
+
if (why !== null && rt.stream === null) throw new Error(`no provider: ${why}`);
|
|
140
|
+
return {
|
|
141
|
+
id,
|
|
142
|
+
async *prompt(goal: string, pOpts: { signal?: AbortSignal } = {}): AsyncGenerator<SdkEvent, void> {
|
|
143
|
+
const stream = rt.stream;
|
|
144
|
+
if (stream === null) { yield { type: "run_end", status: "error", summary: rt.noProviderReason() ?? "no provider configured" }; return; }
|
|
145
|
+
const model: ModelRef = rt.provider
|
|
146
|
+
? { provider: rt.provider.id, model: process.env.ROVECODE_MODEL ?? rt.provider.defaultModel ?? "gpt-4o-mini" }
|
|
147
|
+
: { provider: "mock", model: "default" };
|
|
148
|
+
const ac = new AbortController();
|
|
149
|
+
const follow = (): void => ac.abort();
|
|
150
|
+
if (pOpts.signal?.aborted) ac.abort();
|
|
151
|
+
else pOpts.signal?.addEventListener("abort", follow, { once: true });
|
|
152
|
+
rt.tasks.bindRun(ac.signal);
|
|
153
|
+
const level = opts.yolo === true ? "auto" : "ask";
|
|
154
|
+
const cfg: RunConfig = rt.buildCfg(level, opts.approval);
|
|
155
|
+
const queue = new EventQueue();
|
|
156
|
+
// tree updates that land DURING the prompt join its stream, so a consumer
|
|
157
|
+
// of `for await (ev of session.prompt(…))` sees the whole picture
|
|
158
|
+
const unsub = rt.tasks.subscribe(() => {
|
|
159
|
+
queue.push({ type: "agent_tree_update", sessionId: id, tree: agentTree(rt.tasks.list()) });
|
|
160
|
+
});
|
|
161
|
+
// the loop runs CONCURRENTLY, pushing into the queue the generator drains:
|
|
162
|
+
// loop events and background tree updates interleave in real time. The queue
|
|
163
|
+
// is unbounded (events are small); the loop's own backpressure story is for
|
|
164
|
+
// the wire, not for a local consumer.
|
|
165
|
+
let failure: unknown;
|
|
166
|
+
const run = (async (): Promise<void> => {
|
|
167
|
+
try {
|
|
168
|
+
for await (const ev of agentLoop(rt.buildDef(model), goal, {}, cfg, {
|
|
169
|
+
stream, registry: rt.registry, store: rt.store,
|
|
170
|
+
tools: rt.registry.list().map((t) => t.schema),
|
|
171
|
+
guard: rt.guard, planReminder: rt.planReminder, cwd: rt.cwd,
|
|
172
|
+
signal: ac.signal, hooks: rt.hooks,
|
|
173
|
+
}, rt.steering)) {
|
|
174
|
+
broadcast(ev);
|
|
175
|
+
queue.push(ev);
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {
|
|
178
|
+
failure = e;
|
|
179
|
+
} finally {
|
|
180
|
+
queue.close();
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
183
|
+
try {
|
|
184
|
+
yield* queue.drain();
|
|
185
|
+
} finally {
|
|
186
|
+
unsub();
|
|
187
|
+
await run;
|
|
188
|
+
pOpts.signal?.removeEventListener("abort", follow);
|
|
189
|
+
}
|
|
190
|
+
if (failure !== undefined) throw failure;
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
list(): SessionSummary[] { return listSessions(sessionsRoot); },
|
|
195
|
+
},
|
|
196
|
+
task: {
|
|
197
|
+
start(sessionId, req) {
|
|
198
|
+
const rt = requireRuntime(sessionId);
|
|
199
|
+
return rt.tasks.start(
|
|
200
|
+
{ agent: req.agent ?? "default", goal: req.goal, isolated: req.isolated === true },
|
|
201
|
+
{ ...(req.label !== undefined ? { label: req.label } : {}) },
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
list(sessionId) { return requireRuntime(sessionId).tasks.list(); },
|
|
205
|
+
wait(sessionId, id, waitOpts) { return requireRuntime(sessionId).tasks.result(id, waitOpts); },
|
|
206
|
+
cancel(sessionId, id) { return requireRuntime(sessionId).tasks.cancel(id) !== undefined; },
|
|
207
|
+
},
|
|
208
|
+
agent: {
|
|
209
|
+
tree(sessionId) { return agentTree(requireRuntime(sessionId).tasks.list()); },
|
|
210
|
+
},
|
|
211
|
+
events: {
|
|
212
|
+
subscribe(fn) { listeners.add(fn); return () => { listeners.delete(fn); }; },
|
|
213
|
+
},
|
|
214
|
+
async close(): Promise<void> {
|
|
215
|
+
for (const rt of runtimes.values()) {
|
|
216
|
+
rt.tasks.cancelAll();
|
|
217
|
+
await rt.tasks.drain(2_000);
|
|
218
|
+
await rt.hooks.close();
|
|
219
|
+
await rt.mcp?.close().catch(() => {});
|
|
220
|
+
}
|
|
221
|
+
runtimes.clear();
|
|
222
|
+
listeners.clear();
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
package/src/sdk/index.ts
ADDED