rovecode 0.4.0-beta.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -69
- package/THIRD_PARTY_NOTICES.md +0 -44
- package/bin/rovecode.ts +21 -0
- package/package.json +16 -37
- 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 -512
- package/bin/rovecode.js +0 -24
- package/dist/cli/app-dybnr56b.js +0 -2
- package/dist/cli/ask-user-p8hq4xgj.js +0 -2
- package/dist/cli/auth-login-ewpgw5sm.js +0 -2
- package/dist/cli/auth-m8p9grty.js +0 -2
- package/dist/cli/bench-xv3ypwev.js +0 -9
- package/dist/cli/catalog-737wb2s0.js +0 -2
- package/dist/cli/cli-arhg40m0.js +0 -2
- package/dist/cli/client-cf2pxx8q.js +0 -2
- package/dist/cli/commands-3p7e4xxs.js +0 -2
- package/dist/cli/connect-3q93d7cb.js +0 -2
- package/dist/cli/context-cmd-eqxmxhzq.js +0 -2
- package/dist/cli/context-report-hbw9zfes.js +0 -2
- package/dist/cli/count-remote-mby98cd0.js +0 -2
- package/dist/cli/design-122y0axd.js +0 -2
- package/dist/cli/dispatch-b4egzvvh.js +0 -2
- package/dist/cli/doctor-x4jkv72e.js +0 -3
- package/dist/cli/executor-ftvg6tsy.js +0 -2
- package/dist/cli/export-pdgdhkch.js +0 -2
- package/dist/cli/files-cez9a96p.js +0 -2
- package/dist/cli/gauntlet-r3xxaszc.js +0 -2
- package/dist/cli/gauntlet-runner-r515m7kk.js +0 -10
- package/dist/cli/gauntlet-wave3-bnkjk2v2.js +0 -5
- package/dist/cli/gauntlet-wave4-acs9s60q.js +0 -14
- package/dist/cli/hashline-ewg5hbe3.js +0 -2
- package/dist/cli/http-n0kehsk8.js +0 -5
- package/dist/cli/index-z5qt1s76.js +0 -2
- package/dist/cli/install-80mp63kx.js +0 -2
- package/dist/cli/loop-12twjcat.js +0 -2
- package/dist/cli/main-01pv9206.js +0 -4
- package/dist/cli/main-0jys2ccn.js +0 -3
- package/dist/cli/main-1ztz6fkj.js +0 -10
- package/dist/cli/main-23q7cmww.js +0 -9
- package/dist/cli/main-2rzbexn2.js +0 -3
- package/dist/cli/main-2wyax8k9.js +0 -9
- package/dist/cli/main-2yeveeve.js +0 -6
- package/dist/cli/main-2z3dek0b.js +0 -3
- package/dist/cli/main-2zgsknth.js +0 -3
- package/dist/cli/main-45ejth3a.js +0 -4
- package/dist/cli/main-45rn3trk.js +0 -22
- package/dist/cli/main-4p4e2w7x.js +0 -4
- package/dist/cli/main-4y0tnfpa.js +0 -16
- package/dist/cli/main-5py0rkmc.js +0 -4
- package/dist/cli/main-6dtqmbt6.js +0 -7
- package/dist/cli/main-6h9x282m.js +0 -4
- package/dist/cli/main-6vjeds42.js +0 -3
- package/dist/cli/main-78gq4bt9.js +0 -6
- package/dist/cli/main-7jd5vh3x.js +0 -4
- package/dist/cli/main-7kt6r53y.js +0 -4
- package/dist/cli/main-8c1tbazx.js +0 -58
- package/dist/cli/main-9a9rnh47.js +0 -19
- package/dist/cli/main-9ht36z12.js +0 -3
- package/dist/cli/main-a2yfvcy9.js +0 -7
- package/dist/cli/main-a3f51n0x.js +0 -5
- package/dist/cli/main-b8zq261k.js +0 -3
- package/dist/cli/main-bxtvnf6d.js +0 -13
- package/dist/cli/main-edxc3yzt.js +0 -4
- package/dist/cli/main-evgz4mp5.js +0 -21
- package/dist/cli/main-f33fc5je.js +0 -9
- package/dist/cli/main-fvnpq46y.js +0 -12
- package/dist/cli/main-gbbty4d4.js +0 -3
- package/dist/cli/main-gth53dnt.js +0 -25
- package/dist/cli/main-hqbz10aw.js +0 -9
- package/dist/cli/main-hrrvcfan.js +0 -38
- package/dist/cli/main-hzwtsb2m.js +0 -5
- package/dist/cli/main-j7ttv0sd.js +0 -34
- package/dist/cli/main-jak598k9.js +0 -5
- package/dist/cli/main-kba6zeyd.js +0 -6
- package/dist/cli/main-kwwsz6rq.js +0 -3
- package/dist/cli/main-m8vm17zq.js +0 -3
- package/dist/cli/main-mg4f96e1.js +0 -3
- package/dist/cli/main-mg9b20ac.js +0 -18
- package/dist/cli/main-mgb9ccnx.js +0 -3
- package/dist/cli/main-mjt2p7aj.js +0 -3
- package/dist/cli/main-n6qrdbmy.js +0 -3
- package/dist/cli/main-na7wse0x.js +0 -5
- package/dist/cli/main-nqveez48.js +0 -4
- package/dist/cli/main-ntqef02r.js +0 -10
- package/dist/cli/main-nvc3yjay.js +0 -136
- package/dist/cli/main-p0cfn6nr.js +0 -16
- package/dist/cli/main-qj2djy17.js +0 -19
- package/dist/cli/main-qsevpgsv.js +0 -3
- package/dist/cli/main-qvarybsp.js +0 -3
- package/dist/cli/main-rebtt91r.js +0 -5
- package/dist/cli/main-rpg7h8mb.js +0 -3
- package/dist/cli/main-rsy72qmw.js +0 -15
- package/dist/cli/main-rvetps99.js +0 -18
- package/dist/cli/main-s4bb0jav.js +0 -3
- package/dist/cli/main-s9v8k74e.js +0 -3
- package/dist/cli/main-tjvwmscs.js +0 -3
- package/dist/cli/main-tkgarpjj.js +0 -4
- package/dist/cli/main-v8y60bb2.js +0 -3
- package/dist/cli/main-vhrrq337.js +0 -3
- package/dist/cli/main-vp2dfb7s.js +0 -4
- package/dist/cli/main-vqbr22sz.js +0 -8
- package/dist/cli/main-vxnwe5xx.js +0 -18
- package/dist/cli/main-wgph00xf.js +0 -5
- package/dist/cli/main-wk2csfnj.js +0 -5
- package/dist/cli/main-wm997zjx.js +0 -3
- package/dist/cli/main-wpkyraxh.js +0 -3
- package/dist/cli/main-wqt32p5x.js +0 -4
- package/dist/cli/main-x9ct6y1a.js +0 -3
- package/dist/cli/main-xfekqh9m.js +0 -7
- package/dist/cli/main-xt9zc3n6.js +0 -7
- package/dist/cli/main-xx2z3zh5.js +0 -4
- package/dist/cli/main-y5c82rxr.js +0 -3
- package/dist/cli/main-yrjt2sqt.js +0 -14
- package/dist/cli/main-ys6zj3yr.js +0 -3
- package/dist/cli/main-ywbxshqc.js +0 -8
- package/dist/cli/main-z13755t8.js +0 -25
- package/dist/cli/main-zc7pyrbj.js +0 -4
- package/dist/cli/main.js +0 -279
- package/dist/cli/market-cmd-bm5xvn9f.js +0 -5
- package/dist/cli/mcp-login-bthtfpt7.js +0 -2
- package/dist/cli/mcp-market-cmd-mbeshfyd.js +0 -2
- package/dist/cli/notify-54v5z9dz.js +0 -2
- package/dist/cli/oauth-g5gme95c.js +0 -2
- package/dist/cli/output-satndjap.js +0 -16
- package/dist/cli/profiles-sfhpbq3m.js +0 -2
- package/dist/cli/provider-config-hv3xtdt4.js +0 -2
- package/dist/cli/provider-kwzq6g84.js +0 -2
- package/dist/cli/registry-fh0hdnyn.js +0 -2
- package/dist/cli/registry-y1y8e94r.js +0 -2
- package/dist/cli/repl-t4z03mqq.js +0 -11
- package/dist/cli/resume-fqt4chg8.js +0 -2
- package/dist/cli/run-flags-rysbag9t.js +0 -2
- package/dist/cli/runtime-j19fjbsa.js +0 -2
- package/dist/cli/sandbox-config-g4qxd7y5.js +0 -2
- package/dist/cli/server-r0b6bksk.js +0 -5
- package/dist/cli/session-arg-txmn5g4x.js +0 -2
- package/dist/cli/session-ed250d9j.js +0 -2
- package/dist/cli/sessions-cmd-adw7svfn.js +0 -7
- package/dist/cli/settings-y9rzcqx8.js +0 -2
- package/dist/cli/setup-jmbr11j0.js +0 -2
- package/dist/cli/sextant-smoke-tcth0vea.js +0 -5
- package/dist/cli/skills-cmd-zbdy99v6.js +0 -2
- package/dist/cli/smoke-1bg937kx.js +0 -8
- package/dist/cli/start-chat-p01cdks3.js +0 -12
- package/dist/cli/stream-4wmyaypz.js +0 -2
- package/dist/cli/task-eg4s093s.js +0 -2
- package/dist/cli/tasks-12v9rr9k.js +0 -2
- package/dist/cli/thinking-a5ngvqyh.js +0 -2
- package/dist/cli/todo-1wxpcecx.js +0 -2
- package/dist/cli/tools-2ftsya7w.js +0 -2
- package/dist/cli/tools-x1tj4fxm.js +0 -2
- package/dist/cli/trust-cmd-hccxehzb.js +0 -2
- package/dist/cli/update-check-ygt3vd7m.js +0 -2
- package/dist/cli/update-cmd-v23qhr8c.js +0 -2
- package/dist/cli/voice-g1gtck92.js +0 -2
- package/dist/cli/webfetch-0nnrjgb5.js +0 -2
- package/dist/cli/websearch-f0vr2p7d.js +0 -2
- package/dist/cli/workspace-9rq1w4ta.js +0 -2
- package/dist/lib/index.js +0 -62
- package/dist/lib/models-index.json +0 -1
- package/dist/lib/plugins.js +0 -6
- package/dist/lib/providers.js +0 -17
- package/dist/lib/public-api.js +0 -20
- package/dist/rovecode.exe +0 -4
- /package/{dist/cli → src/providers}/models-index.json +0 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/** Rovecode core type contracts. Single source of truth for the runtime. */
|
|
2
|
+
|
|
3
|
+
import type { ContextChunk } from "./context.ts";
|
|
4
|
+
import type { CompactionStrategy, CompactionTrigger, PruneConfig } from "./compaction.ts";
|
|
5
|
+
import type { OutputBudgetOptions } from "./tool-output-budget.ts";
|
|
6
|
+
|
|
7
|
+
// ---------- Messages (harness-level; converted to provider form only at the seam) ----------
|
|
8
|
+
|
|
9
|
+
export type Role = "system" | "user" | "assistant" | "tool";
|
|
10
|
+
|
|
11
|
+
export interface TextPart { kind: "text"; text: string }
|
|
12
|
+
export interface ToolCallPart { kind: "tool_call"; id: string; tool: string; args: unknown }
|
|
13
|
+
export interface ToolResultPart { kind: "tool_result"; callId: string; ok: boolean; output: string }
|
|
14
|
+
/** The four raster types both wire protocols accept (Anthropic image source media_type;
|
|
15
|
+
* OpenAI image_url data URL) — decided by magic bytes, never by file extension (core/images.ts). */
|
|
16
|
+
export type ImageMime = "image/png" | "image/jpeg" | "image/gif" | "image/webp";
|
|
17
|
+
/** port #34: an image attached to a user message. Exactly one carrier is set — `bytes` (base64,
|
|
18
|
+
* the in-memory / transport form: TUI /attach, ACP image blocks) or `path` (the sidecar file the
|
|
19
|
+
* session store wrote under `<session>/attachments/`; session-relative in entries.jsonl,
|
|
20
|
+
* resolved to absolute on load). Adapters read either through core/images.ts imageData(). */
|
|
21
|
+
export interface ImagePart {
|
|
22
|
+
kind: "image";
|
|
23
|
+
mime: ImageMime;
|
|
24
|
+
bytes?: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
/** display name (the attached file's basename) — transcript chip + non-vision placeholder */
|
|
29
|
+
name?: string;
|
|
30
|
+
}
|
|
31
|
+
export type MessagePart = TextPart | ToolCallPart | ToolResultPart | ImagePart;
|
|
32
|
+
|
|
33
|
+
export interface Message {
|
|
34
|
+
id: string;
|
|
35
|
+
role: Role;
|
|
36
|
+
parts: MessagePart[];
|
|
37
|
+
parentId: string | null;
|
|
38
|
+
createdAt: number;
|
|
39
|
+
/** provider+model that produced this message, when applicable */
|
|
40
|
+
origin?: { provider: string; model: string };
|
|
41
|
+
usage?: TokenUsage;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface TokenUsage { input: number; output: number; cacheRead?: number; cacheWrite?: number; costUsd?: number }
|
|
45
|
+
|
|
46
|
+
// ---------- Provider seam (ADR-003: never throws; errors are stopReasons) ----------
|
|
47
|
+
|
|
48
|
+
export type StopReason =
|
|
49
|
+
| "end_turn" | "tool_use" | "length" | "aborted" | "error" | "budget";
|
|
50
|
+
|
|
51
|
+
export interface AssistantTurn {
|
|
52
|
+
parts: MessagePart[];
|
|
53
|
+
stopReason: StopReason;
|
|
54
|
+
usage: TokenUsage;
|
|
55
|
+
error?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface StreamOptions {
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
/** the run's wall-clock deadline (epoch ms, RunConfig.maxSeconds) — a retry backoff that would end past it
|
|
61
|
+
* is not taken (providers/retry.ts); unset = no clock */
|
|
62
|
+
deadlineAt?: number;
|
|
63
|
+
/** tool schemas advertised to the provider for native function calling */
|
|
64
|
+
tools?: ToolSchema[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface StreamFn {
|
|
68
|
+
(model: ModelRef, messages: Message[], options?: StreamOptions): AsyncIterable<StreamEvent>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type StreamEvent =
|
|
72
|
+
| { type: "text_delta"; text: string }
|
|
73
|
+
/** a slice of the model's reasoning (Anthropic thinking_delta): counted for the live status
|
|
74
|
+
* line, never part of the answer — the terminal turn's parts carry text and tool calls only */
|
|
75
|
+
| { type: "reasoning_delta"; text: string }
|
|
76
|
+
| { type: "tool_call_delta"; id: string; tool: string; argsDelta: string }
|
|
77
|
+
| { type: "turn"; turn: AssistantTurn };
|
|
78
|
+
|
|
79
|
+
/** How hard the model is asked to think before it answers. `off` is the plain request; the three
|
|
80
|
+
* levels map to each protocol's own dial — an Anthropic thinking budget in tokens, an OpenAI
|
|
81
|
+
* `reasoning_effort` string (providers/stream.ts thinkingBudget). A model with no reasoning mode
|
|
82
|
+
* ignores it: the field is sent, the endpoint drops it. */
|
|
83
|
+
/** `auto` = send NO thinking field and let the provider's own default stand — for the Claude 5 family
|
|
84
|
+
* that is adaptive thinking at high effort. It is the runtime default: the old default `off` sent an
|
|
85
|
+
* explicit `thinking: disabled`, which switched OFF the reasoning Opus 5 and Sonnet 5 do on their own
|
|
86
|
+
* and was a large part of "the model is not performing" (Berkay, 2026-09-04). `off` stays as the
|
|
87
|
+
* explicit, deliberate choice. */
|
|
88
|
+
export type ThinkingEffort = "auto" | "off" | "low" | "medium" | "high";
|
|
89
|
+
export const THINKING_EFFORTS: readonly ThinkingEffort[] = ["auto", "off", "low", "medium", "high"];
|
|
90
|
+
|
|
91
|
+
/** a level from a flag/env word; undefined when it names nothing (the caller keeps its default,
|
|
92
|
+
* rather than silently reading a typo as "off") */
|
|
93
|
+
export function parseEffort(v: string | undefined): ThinkingEffort | undefined {
|
|
94
|
+
const w = (v ?? "").trim().toLowerCase();
|
|
95
|
+
return (THINKING_EFFORTS as readonly string[]).includes(w) ? (w as ThinkingEffort) : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ModelRef {
|
|
99
|
+
provider: string;
|
|
100
|
+
model: string;
|
|
101
|
+
maxTokens?: number;
|
|
102
|
+
effort?: ThinkingEffort;
|
|
103
|
+
/** the catalog's word on whether the model has a reasoning mode (models.dev `reasoning`), stamped by
|
|
104
|
+
* cli/runtime.ts buildDef; `false` means no thinking field is ever sent (providers/thinking.ts).
|
|
105
|
+
* Unset = unknown: the dial goes out in the endpoint's dialect and a model that cannot reason ignores it. */
|
|
106
|
+
reasoning?: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------- Tools (ADR-005: validate → revise → policy → approve → sandbox → execute) ----------
|
|
110
|
+
|
|
111
|
+
export interface ToolSchema {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
/** JSON Schema for args */
|
|
115
|
+
args: Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type ToolKind = "read" | "write" | "execute" | "spawn" | "memory" | "network" | "custom";
|
|
119
|
+
|
|
120
|
+
export interface ToolContext {
|
|
121
|
+
sessionId: string;
|
|
122
|
+
cwd: string;
|
|
123
|
+
signal: AbortSignal;
|
|
124
|
+
/** port #29: the run this call belongs to (hook ctx, tracing); unset for bare registry use */
|
|
125
|
+
runId?: string;
|
|
126
|
+
/** emit progress updates surfaced as tool_execution_update events */
|
|
127
|
+
onUpdate?: (note: string) => void;
|
|
128
|
+
/** spawn a child agent (multi-agent path) */
|
|
129
|
+
spawn?: (req: SpawnRequest) => Promise<SpawnResult>;
|
|
130
|
+
permissions: PermissionDecision;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Tool {
|
|
134
|
+
schema: ToolSchema;
|
|
135
|
+
kind: ToolKind;
|
|
136
|
+
/** false → run concurrently with siblings in the same batch */
|
|
137
|
+
sequential?: boolean;
|
|
138
|
+
interruptible?: boolean;
|
|
139
|
+
/** Policy resource for a tool whose modes differ in what they are ALLOWED to do, where neither a
|
|
140
|
+
* path, a command nor a URL says which mode this call is. Without it the resource falls back to the
|
|
141
|
+
* tool NAME, so one rule has to cover every mode — which is how a read-only `design_direction
|
|
142
|
+
* {"action":"get"}` came to raise an approval card (2026-09-04): it writes nothing, but it shares a
|
|
143
|
+
* rule with `set`, and a human trained to allow the read hits allow on the write too. Return a short
|
|
144
|
+
* stable word; a rule then targets it (`tool.design_direction get -> allow`). Never derive it from a
|
|
145
|
+
* value the model can vary freely — the point is that a rule can name the mode, not that the model
|
|
146
|
+
* can name its own permissions. */
|
|
147
|
+
resource?(args: unknown): string;
|
|
148
|
+
execute(args: unknown, ctx: ToolContext): Promise<ToolOutput>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface ToolOutput { ok: boolean; output: string; data?: unknown }
|
|
152
|
+
|
|
153
|
+
// ---------- Permissions ----------
|
|
154
|
+
|
|
155
|
+
export type PermissionEffect = "allow" | "deny" | "prompt";
|
|
156
|
+
|
|
157
|
+
export interface PermissionRule {
|
|
158
|
+
action: string; // e.g. "file.write", "shell.exec", "spawn", "*"
|
|
159
|
+
resource: string; // glob, e.g. "src/**", "rm *", "*"
|
|
160
|
+
effect: PermissionEffect;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type PermissionDecision =
|
|
164
|
+
| { effect: "allow" }
|
|
165
|
+
| { effect: "deny"; reason: string }
|
|
166
|
+
| { effect: "prompt"; prompt: string };
|
|
167
|
+
|
|
168
|
+
export type ApprovalFn = (req: ApprovalRequest) => Promise<"once" | "always" | "deny">;
|
|
169
|
+
|
|
170
|
+
/** How much the human is asked. `ask` prompts for every write, command and subagent; `accept-edits`
|
|
171
|
+
* stops asking for writes INSIDE the workspace (shell, spawn, network and writes outside it still
|
|
172
|
+
* ask); `auto` never asks. Deny rules, plan mode and the execpolicy forbidden-argv stop hold at
|
|
173
|
+
* every level — this dial only moves the prompt branch. */
|
|
174
|
+
export type PermissionLevel = "ask" | "accept-edits" | "auto";
|
|
175
|
+
|
|
176
|
+
export interface ApprovalRequest {
|
|
177
|
+
tool: string;
|
|
178
|
+
args: unknown;
|
|
179
|
+
revisedArgs: unknown;
|
|
180
|
+
reason: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ---------- Events (loop output; also the durability + observability unit) ----------
|
|
184
|
+
|
|
185
|
+
export type RunEvent =
|
|
186
|
+
| { type: "run_start"; runId: string; sessionId: string; goal: string }
|
|
187
|
+
| { type: "turn_start"; turn: number }
|
|
188
|
+
| { type: "message_update"; messageId: string; delta: string }
|
|
189
|
+
/** the provider turn is reasoning: `tokens` = estimated reasoning tokens so far this turn,
|
|
190
|
+
* CUMULATIVE (a dropped event costs nothing). Only the count leaves the loop — the reasoning text
|
|
191
|
+
* is not the answer and neither the transcript nor a client should carry it. */
|
|
192
|
+
| { type: "reasoning_update"; messageId: string; tokens: number }
|
|
193
|
+
| { type: "tool_execution_start"; callId: string; tool: string; args: unknown }
|
|
194
|
+
| { type: "tool_execution_update"; callId: string; note: string }
|
|
195
|
+
| { type: "tool_execution_end"; callId: string; ok: boolean; output: string; durationMs: number }
|
|
196
|
+
| { type: "tool_call_failed"; callId: string; reason: "truncated" | "invalid_args" | "permission_denied" | "not_found"; detail: string }
|
|
197
|
+
/** strategy = the one that RAN (core/compaction.ts seam, or "context-drop" for ADR-007 chunk
|
|
198
|
+
* eviction); trigger (port #25) is set on history compactions only: "speculative" = estimate
|
|
199
|
+
* crossed the threshold, "emergency" = the provider rejected the request as an overflow */
|
|
200
|
+
| { type: "compaction"; strategy: string; trigger?: CompactionTrigger; tokensBefore: number; tokensAfter: number }
|
|
201
|
+
| { type: "turn_end"; turn: number; stopReason: StopReason }
|
|
202
|
+
| { type: "steer"; text: string }
|
|
203
|
+
/** the verify gate is running the project's check / has finished it (core/verify-gate.ts); `detail` is one line */
|
|
204
|
+
| { type: "verify"; command: string; state: "running" | "passed" | "failed" | "timeout"; ms?: number; detail?: string }
|
|
205
|
+
/** `outstanding` (status "done" only): what the run left behind when the model stopped talking — absent
|
|
206
|
+
* when nothing is notable AND at least one file was written, so a clean run's event is exactly what it
|
|
207
|
+
* always was. "done" alone means "the model produced a turn with no tool call"; this field is how a
|
|
208
|
+
* surface tells that from "the work is complete" (core/loop.ts assessOutstanding). */
|
|
209
|
+
| { type: "run_end"; status: "done" | "stopped" | "error" | "budget"; summary: string; outstanding?: RunOutstanding };
|
|
210
|
+
|
|
211
|
+
/** What a run that ended as "done" left behind. Every field is a fact read from the transcript or the
|
|
212
|
+
* session's own todo list — never an interpretation of the model's words. */
|
|
213
|
+
export interface RunOutstanding {
|
|
214
|
+
/** tool calls of the LAST turn that had any, which failed: `write: Write rejected: …` (first line) */
|
|
215
|
+
failed: string[];
|
|
216
|
+
/** that last turn asked the user something and got no answer (headless, declined, or aborted) */
|
|
217
|
+
unansweredAsk: boolean;
|
|
218
|
+
/** successful `edit` + `write` calls over the whole run. `bash` may have changed files too; this counts only the two file tools */
|
|
219
|
+
writes: number;
|
|
220
|
+
/** the model's own todo list, when it kept one: items not completed / all items */
|
|
221
|
+
todosOpen?: number;
|
|
222
|
+
todosTotal?: number;
|
|
223
|
+
/** the finish check (core/loop.ts) asked once for the work to be finished; this run_end is the answer it got */
|
|
224
|
+
nudged: boolean;
|
|
225
|
+
/** the verify gate (core/verify-gate.ts), present when the run wrote files and a gate was wired: did the
|
|
226
|
+
* project's own check pass after the changes, fail (with the failing part), time out, or was there no check to
|
|
227
|
+
* run. Absent when nothing was written — and when files changed only through `bash`, which `writes` cannot see. */
|
|
228
|
+
verify?: VerifyState;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** `refused`: what the resolver (core/verify.ts) saw and deliberately did not run, each with its reason — the
|
|
232
|
+
* argument for trusting the gate. `reason` (unconfigured): why there is nothing to run, in the resolver's words. */
|
|
233
|
+
export type VerifyState =
|
|
234
|
+
| { state: "unconfigured"; reason?: string; refused?: string[] }
|
|
235
|
+
| { state: "passed"; command: string; ms: number; refused?: string[] }
|
|
236
|
+
| { state: "failed"; command: string; code: number; failure: string; refused?: string[] }
|
|
237
|
+
| { state: "timeout"; command: string; seconds: number; refused?: string[] };
|
|
238
|
+
|
|
239
|
+
/** RunConfig.verify — wired by the runtime, consumed by the loop's "done" exit. `resolution` is what
|
|
240
|
+
* core/verify.ts decided (null / no commands = nothing to run → run_end says "not verified"); `run` executes it
|
|
241
|
+
* bounded by `timeoutMs` and the run's abort (core/verify-gate.ts runVerify). */
|
|
242
|
+
export interface VerifyGate {
|
|
243
|
+
resolution: { commands: string[]; refused?: string[]; source?: string; reason?: string } | null;
|
|
244
|
+
timeoutMs: number;
|
|
245
|
+
run: (signal: AbortSignal) => Promise<{ command: string; ok: boolean; code: number; timedOut: boolean; ms: number; failure: string; ran: number }>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---------- Agent ----------
|
|
249
|
+
|
|
250
|
+
export interface AgentDefinition {
|
|
251
|
+
name: string;
|
|
252
|
+
systemPrompt: string | ((ctx: AgentVars) => string);
|
|
253
|
+
tools: string[]; // tool names; "*" = all allowed by policy
|
|
254
|
+
model?: ModelRef;
|
|
255
|
+
maxTurns?: number; // finite always (reject swarm's infinity)
|
|
256
|
+
spawns?: "none" | "siblings" | "subtasks";
|
|
257
|
+
memory?: { task?: boolean; episodic?: boolean; semantic?: boolean };
|
|
258
|
+
/** extra non-history ADR-007 chunks (port #8: harvested project config,
|
|
259
|
+
* name "config", priority 70) folded into the system message via
|
|
260
|
+
* assembleContext — droppable under budget pressure, unlike systemPrompt */
|
|
261
|
+
contextChunks?: ContextChunk[];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface AgentVars { [key: string]: unknown }
|
|
265
|
+
|
|
266
|
+
export interface SpawnRequest {
|
|
267
|
+
agent: string;
|
|
268
|
+
goal: string;
|
|
269
|
+
vars?: AgentVars;
|
|
270
|
+
isolated?: boolean; // COW/git worktree when writing
|
|
271
|
+
background?: boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface SpawnResult { agent: string; ok: boolean; summary: string; usage: TokenUsage; patch?: string }
|
|
275
|
+
|
|
276
|
+
// ---------- Run configuration ----------
|
|
277
|
+
|
|
278
|
+
export interface RunConfig {
|
|
279
|
+
maxTurns: number;
|
|
280
|
+
/** wall-clock ceiling for one run, in seconds; checked at every turn boundary (core/loop.ts), so a
|
|
281
|
+
* verification spiral of many short turns ends in a clean run_end "budget" with what was done so far.
|
|
282
|
+
* Unset = no clock. `rovecode run` defaults it to 20 minutes; ROVECODE_MAX_SECONDS / --max-seconds set it. */
|
|
283
|
+
maxSeconds?: number;
|
|
284
|
+
/** a spend ceiling for one run, in US dollars, checked at every turn boundary like maxSeconds: the run ends
|
|
285
|
+
* with status "budget" and what was done so far. Only turns `priceUsd` can price count; an unpriced turn
|
|
286
|
+
* (a model the catalog does not know) adds nothing and the summary says how many there were. Unset = no cap.
|
|
287
|
+
* `rovecode run --max-cost D`, ROVECODE_MAX_COST on every surface. */
|
|
288
|
+
maxCostUsd?: number;
|
|
289
|
+
/** what one turn cost, from its usage and the model that SERVED it (router fallback may differ from the one
|
|
290
|
+
* asked for) — undefined when the catalog has no price. The runtime binds this to its catalog; without it
|
|
291
|
+
* maxCostUsd can never trip, which is why buildCfg always sets both together. */
|
|
292
|
+
priceUsd?: (usage: TokenUsage, origin: ModelRef) => number | undefined;
|
|
293
|
+
/** The finish check (core/loop.ts, at the "done" exit): when the model stops talking right after a failed
|
|
294
|
+
* tool call or an unanswered question to the user, ONE continuation turn names what is outstanding and asks
|
|
295
|
+
* it to finish or say what is left. Default on; `false` (ROVECODE_FINISH_CHECK=0) turns it off. The
|
|
296
|
+
* representation on run_end (`outstanding`) is unconditional — turning this off only stops the nudge. */
|
|
297
|
+
finishCheck?: boolean;
|
|
298
|
+
/** the model's own todo list for this session, read at the exit: open / total, or null when it kept none.
|
|
299
|
+
* Represented on run_end; it is NOT a nudge trigger (no session on this machine has ever written one). */
|
|
300
|
+
todoState?: () => { open: number; total: number } | null;
|
|
301
|
+
/** The verify gate (core/verify-gate.ts): after a run that wrote files, run the project's own check before
|
|
302
|
+
* "done"; a failure goes back to the model ONCE (sharing the finish check's one-nudge budget), then run_end
|
|
303
|
+
* says how it ended. Absent = off (ROVECODE_VERIFY=0, plan mode, or a surface that wired none): nothing runs,
|
|
304
|
+
* nothing is added, a run's event is byte-identical to one without the gate. */
|
|
305
|
+
verify?: VerifyGate;
|
|
306
|
+
contextBudgetTokens: number;
|
|
307
|
+
compactionThreshold: number; // fraction of budget triggering compaction
|
|
308
|
+
/** port #25: history compaction strategy (core/compaction.ts; env ROVECODE_COMPACTION); default head-summarize */
|
|
309
|
+
compactionStrategy?: CompactionStrategy;
|
|
310
|
+
/** port #25 keep-window: user turns kept BEFORE the current one (default 2; an emergency keeps 0) */
|
|
311
|
+
compactionKeepTurns?: number;
|
|
312
|
+
/** P0-2: view-only prune of old tool outputs before each provider call (core/compaction.ts
|
|
313
|
+
* pruneToolOutputs). The session record is NEVER rewritten — only the wire view is stubbed;
|
|
314
|
+
* a `compaction` event with strategy "prune" is yielded (not persisted, same precedent as
|
|
315
|
+
* "context-drop"). undefined = DEFAULT_PRUNE_CONFIG; false = off. */
|
|
316
|
+
prune?: PruneConfig | false;
|
|
317
|
+
/** P0-3: unified tool-output ceiling with UTF-8-safe head+tail truncation
|
|
318
|
+
* (core/tool-output-budget.ts), applied by the loop to the persisted/next-request results.
|
|
319
|
+
* undefined = the default ceiling; false = off (tool-side caps still apply). */
|
|
320
|
+
outputBudget?: OutputBudgetOptions | false;
|
|
321
|
+
/** P0-4: compaction thrash guard (core/compaction.ts CompactionPace). A compaction within this
|
|
322
|
+
* many turns of the previous one earns one strike; one that fails to shrink the wire by ≥5%
|
|
323
|
+
* earns another; COOLDOWN_STRIKES (3) stop compacting for the run, and an emergency arriving
|
|
324
|
+
* during cooldown ends the run in error instead of re-driving. 0 = off.
|
|
325
|
+
* Default DEFAULT_RAPID_WINDOW_TURNS (2). */
|
|
326
|
+
compactionRapidTurns?: number;
|
|
327
|
+
parallelTools: boolean;
|
|
328
|
+
permissionRules: PermissionRule[];
|
|
329
|
+
approval?: ApprovalFn;
|
|
330
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/** Is there a newer rovecode than the one running?
|
|
2
|
+
*
|
|
3
|
+
* The release channel is GitHub Releases on 9Code-Labs/rovecode (Berkay's call, 2026-09-06). That
|
|
4
|
+
* repository is private, so the check needs a token — and the honest consequence is written into the
|
|
5
|
+
* result rather than hidden: with no token the answer is "unknown, and here is why", never "you are up
|
|
6
|
+
* to date". A version check that reports "current" when it could not look is worse than no check, since
|
|
7
|
+
* it is indistinguishable from a real answer.
|
|
8
|
+
*
|
|
9
|
+
* Three rules, because this runs at startup:
|
|
10
|
+
* - **It never blocks.** The caller fires it and paints; the answer arrives or it does not.
|
|
11
|
+
* - **It never throws.** Offline, rate-limited, no token, a repository that has no releases yet — each
|
|
12
|
+
* is a reason string, and the surface can decide whether to say anything.
|
|
13
|
+
* - **It asks rarely.** The answer is cached in ~/.rovecode/update-check.json for six hours, so opening
|
|
14
|
+
* the terminal twenty times in an afternoon is one request. A cache that cannot be read or written is
|
|
15
|
+
* not an error either; it just means asking again. */
|
|
16
|
+
|
|
17
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
18
|
+
import { execFile } from "node:child_process";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { rovecodeHome } from "../providers/auth.ts";
|
|
21
|
+
|
|
22
|
+
export interface UpdateStatus {
|
|
23
|
+
/** the version this process is */
|
|
24
|
+
current: string;
|
|
25
|
+
/** the newest release, when one could be read */
|
|
26
|
+
latest?: string;
|
|
27
|
+
/** true only when `latest` is genuinely newer than `current` */
|
|
28
|
+
newer: boolean;
|
|
29
|
+
/** why there is no `latest` — absent when the check succeeded */
|
|
30
|
+
reason?: string;
|
|
31
|
+
/** where the answer came from, so a stale line can be explained */
|
|
32
|
+
from: "network" | "cache";
|
|
33
|
+
/** the release page, for a surface that wants to point at it */
|
|
34
|
+
url?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UpdateCheckOptions {
|
|
38
|
+
repo?: string;
|
|
39
|
+
token?: string | undefined;
|
|
40
|
+
fetchFn?: typeof fetch;
|
|
41
|
+
/** overridden in tests; production caches under rovecodeHome() */
|
|
42
|
+
cacheFile?: string;
|
|
43
|
+
ttlMs?: number;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
now?: () => number;
|
|
46
|
+
/** answer from the cache or not at all — never open a socket. `rovecode --version` uses this: a courtesy
|
|
47
|
+
* line must not make a command scripts call wait on a network round-trip (measured 3.2 s on a cold
|
|
48
|
+
* cache before this existed, against 84–103 ms for everything else the command does). */
|
|
49
|
+
cacheOnly?: boolean;
|
|
50
|
+
/** last-resort token source; the default asks the gh CLI. Injected in tests so no process is spawned. */
|
|
51
|
+
ghToken?: () => Promise<string | undefined>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const REPO = "9Code-Labs/rovecode";
|
|
55
|
+
const TTL_MS = 6 * 60 * 60 * 1000;
|
|
56
|
+
// 8s, not the 3s this started with. Nothing waits on this — the card is already painted and the notice
|
|
57
|
+
// arrives when it arrives — so the only thing a short timeout buys is the wrong answer on exactly the run
|
|
58
|
+
// that matters: measured cold on this machine the first api.github.com request took 12.7s and the next
|
|
59
|
+
// 0.36s, which a 3s cap turns into "the check timed out" every single first start of the day.
|
|
60
|
+
const TIMEOUT_MS = 8_000;
|
|
61
|
+
|
|
62
|
+
/** semver-ish compare, tolerant of a leading v and of extra dot-parts; prerelease suffixes lose to the
|
|
63
|
+
* same version without one, which is the conservative direction — it never invents an update. */
|
|
64
|
+
export function isNewer(latest: string, current: string): boolean {
|
|
65
|
+
const parts = (v: string): { nums: number[]; pre: boolean } => {
|
|
66
|
+
const clean = v.trim().replace(/^v/i, "");
|
|
67
|
+
const [core = "", ...rest] = clean.split("-");
|
|
68
|
+
return { nums: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: rest.length > 0 };
|
|
69
|
+
};
|
|
70
|
+
const a = parts(latest), b = parts(current);
|
|
71
|
+
const len = Math.max(a.nums.length, b.nums.length);
|
|
72
|
+
for (let i = 0; i < len; i++) {
|
|
73
|
+
const x = a.nums[i] ?? 0, y = b.nums[i] ?? 0;
|
|
74
|
+
if (x !== y) return x > y;
|
|
75
|
+
}
|
|
76
|
+
// same numbers: a prerelease is not newer than the release, and never newer than itself
|
|
77
|
+
return b.pre && !a.pre;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readCache(file: string, ttlMs: number, now: number): UpdateStatus | null {
|
|
81
|
+
try {
|
|
82
|
+
const raw = JSON.parse(readFileSync(file, "utf8")) as { at?: number; status?: UpdateStatus };
|
|
83
|
+
if (typeof raw.at !== "number" || !raw.status) return null;
|
|
84
|
+
if (now - raw.at > ttlMs) return null;
|
|
85
|
+
return { ...raw.status, from: "cache" };
|
|
86
|
+
} catch {
|
|
87
|
+
return null; // unreadable, missing, or written by an older shape — ask again
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function writeCache(file: string, status: UpdateStatus, now: number): void {
|
|
92
|
+
try {
|
|
93
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
94
|
+
writeFileSync(file, JSON.stringify({ at: now, status: { ...status, from: "network" } }));
|
|
95
|
+
} catch {
|
|
96
|
+
/* a read-only home must not turn a successful check into a failure */
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `gh auth token`, or undefined for every way that can fail — no gh, not logged in, slow, noisy. This is
|
|
101
|
+
* a convenience, so it is never allowed to become a reason the terminal waits. */
|
|
102
|
+
function ghAuthToken(): Promise<string | undefined> {
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
try {
|
|
105
|
+
execFile("gh", ["auth", "token"], { timeout: 1_500, windowsHide: true }, (err, stdout) => {
|
|
106
|
+
const t = typeof stdout === "string" ? stdout.trim() : "";
|
|
107
|
+
resolve(err !== null || t.length === 0 ? undefined : t);
|
|
108
|
+
});
|
|
109
|
+
} catch { resolve(undefined); }
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function checkForUpdate(current: string, opts: UpdateCheckOptions = {}): Promise<UpdateStatus> {
|
|
114
|
+
const now = (opts.now ?? Date.now)();
|
|
115
|
+
const cacheFile = opts.cacheFile ?? join(rovecodeHome(), "update-check.json");
|
|
116
|
+
const ttl = opts.ttlMs ?? TTL_MS;
|
|
117
|
+
|
|
118
|
+
const cached = readCache(cacheFile, ttl, now);
|
|
119
|
+
if (cached) return { ...cached, current, newer: cached.latest !== undefined && isNewer(cached.latest, current) };
|
|
120
|
+
|
|
121
|
+
// GITHUB_TOKEN, then GH_TOKEN, then whatever `gh auth login` already stored — most people who can read
|
|
122
|
+
// a private repository at all have the CLI logged in, and making them export a variable to be told about
|
|
123
|
+
// an update is a step they will not take. The token is used and dropped: it never enters the cache.
|
|
124
|
+
if (opts.cacheOnly === true) {
|
|
125
|
+
return { current, newer: false, from: "cache", reason: "not asked yet — rovecode checks at startup, at most once every six hours" };
|
|
126
|
+
}
|
|
127
|
+
const token = opts.token ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? await (opts.ghToken ?? ghAuthToken)();
|
|
128
|
+
if (!token) {
|
|
129
|
+
// not cached: a token may appear before the next start, and caching "no token" would hide it
|
|
130
|
+
return { current, newer: false, from: "network", reason: "the release repository is private and no GITHUB_TOKEN is set (or `gh auth login`)" };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const ac = new AbortController();
|
|
134
|
+
const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? TIMEOUT_MS);
|
|
135
|
+
try {
|
|
136
|
+
const res = await (opts.fetchFn ?? fetch)(`https://api.github.com/repos/${opts.repo ?? REPO}/releases/latest`, {
|
|
137
|
+
headers: { accept: "application/vnd.github+json", authorization: `Bearer ${token}`, "user-agent": "rovecode" },
|
|
138
|
+
signal: ac.signal,
|
|
139
|
+
});
|
|
140
|
+
if (res.status === 404) {
|
|
141
|
+
const status: UpdateStatus = { current, newer: false, from: "network", reason: "no release published yet" };
|
|
142
|
+
writeCache(cacheFile, status, now); // worth caching: it will stay true until someone publishes
|
|
143
|
+
return status;
|
|
144
|
+
}
|
|
145
|
+
if (!res.ok) return { current, newer: false, from: "network", reason: `GitHub answered ${res.status}` };
|
|
146
|
+
const body = (await res.json().catch(() => null)) as { tag_name?: string; html_url?: string } | null;
|
|
147
|
+
const tag = typeof body?.tag_name === "string" ? body.tag_name : undefined;
|
|
148
|
+
if (!tag) return { current, newer: false, from: "network", reason: "the release carries no tag name" };
|
|
149
|
+
const status: UpdateStatus = {
|
|
150
|
+
current, latest: tag.replace(/^v/i, ""), newer: isNewer(tag, current), from: "network",
|
|
151
|
+
...(typeof body?.html_url === "string" ? { url: body.html_url } : {}),
|
|
152
|
+
};
|
|
153
|
+
writeCache(cacheFile, status, now);
|
|
154
|
+
return status;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
157
|
+
return { current, newer: false, from: "network", reason: ac.signal.aborted ? "the check timed out" : msg };
|
|
158
|
+
} finally {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The one line a surface shows, or null when there is nothing worth saying. Deliberately silent for
|
|
164
|
+
* "up to date" and for every failure: a startup screen that reports its own plumbing every time trains
|
|
165
|
+
* people to stop reading it. `verbose` is for `rovecode --version`, where asking WAS the point. */
|
|
166
|
+
export function updateLine(s: UpdateStatus, verbose = false): string | null {
|
|
167
|
+
if (s.newer && s.latest !== undefined) return `update available: ${s.current} → ${s.latest}${s.url ? ` · ${s.url}` : ""}`;
|
|
168
|
+
if (!verbose) return null;
|
|
169
|
+
if (s.reason !== undefined) return `update check: ${s.reason}`;
|
|
170
|
+
return `up to date (${s.current})${s.from === "cache" ? " · cached" : ""}`;
|
|
171
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/** Self-update: how THIS installation gets to the newer release the update-check named.
|
|
2
|
+
*
|
|
3
|
+
* Rovecode ships three ways and each updates differently, so the first job is honest detection
|
|
4
|
+
* (core/update.ts detectInstallMode): an npm install (the published tarball — `npm install -g
|
|
5
|
+
* rovecode@<channel>`), a source checkout (git pull + bun install, and build:cli when a dist was
|
|
6
|
+
* built), or a compiled single binary (no self-swap yet: the release page's artifact is the answer,
|
|
7
|
+
* said plainly rather than attempted and half-done). Detection is path arithmetic, injected and
|
|
8
|
+
* testable; nothing here guesses from the version string alone.
|
|
9
|
+
*
|
|
10
|
+
* The channel follows the running version unless told otherwise: a prerelease (0.4.0-beta.1) stays
|
|
11
|
+
* on `beta`, a release stays on `latest` — an auto-update must never silently move someone between
|
|
12
|
+
* channels.
|
|
13
|
+
*
|
|
14
|
+
* `autoUpdate` (settings.json / ROVECODE_AUTO_UPDATE=1) runs the plan in the BACKGROUND at TUI
|
|
15
|
+
* boot when the cached update-check says a newer version exists. It never blocks the session and
|
|
16
|
+
* never swaps the running process: on Windows a live executable's files are being replaced under
|
|
17
|
+
* it, so the honest promise is "updated — restart to run it", which is what the note says. */
|
|
18
|
+
|
|
19
|
+
import { existsSync } from "node:fs";
|
|
20
|
+
import { join, sep } from "node:path";
|
|
21
|
+
|
|
22
|
+
export type InstallMode = "npm" | "source" | "binary" | "unknown";
|
|
23
|
+
export type UpdateChannel = "beta" | "latest";
|
|
24
|
+
|
|
25
|
+
export interface DetectedInstall {
|
|
26
|
+
mode: InstallMode;
|
|
27
|
+
/** the package root (npm: the rovecode dir under node_modules; source: the repo root) when known */
|
|
28
|
+
root?: string;
|
|
29
|
+
/** npm: the install sits under npm's global prefix (decides -g) */
|
|
30
|
+
npmGlobal?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** bun's compiled binaries run their modules from a virtual FS whose path starts with this */
|
|
34
|
+
const BUNFS = "/$bunfs/";
|
|
35
|
+
|
|
36
|
+
/** Where does the running entry live? `entry` is the main module's path (import.meta.path of the
|
|
37
|
+
* CLI entry), `exec` the runtime's own (process.execPath), `npmGlobalPrefix` the answer of
|
|
38
|
+
* `npm prefix -g` when the caller already has it (undefined = decide later, at run time). */
|
|
39
|
+
export function detectInstallMode(paths: { entry: string; exec?: string; npmGlobalPrefix?: string }): DetectedInstall {
|
|
40
|
+
const entry = paths.entry.replace(/\\/g, "/");
|
|
41
|
+
if (entry.includes(BUNFS) || (paths.exec !== undefined && paths.exec.replace(/\\/g, "/").includes(BUNFS))) {
|
|
42
|
+
return { mode: "binary" };
|
|
43
|
+
}
|
|
44
|
+
const nm = entry.lastIndexOf("/node_modules/");
|
|
45
|
+
if (nm >= 0) {
|
|
46
|
+
// the package root is node_modules/<name> (a scoped name adds one segment)
|
|
47
|
+
const after = entry.slice(nm + "/node_modules/".length);
|
|
48
|
+
const segs = after.split("/");
|
|
49
|
+
const pkgSegs = after.startsWith("@") ? segs.slice(0, 2) : segs.slice(0, 1);
|
|
50
|
+
const root = entry.slice(0, nm) + "/node_modules/" + pkgSegs.join("/");
|
|
51
|
+
const prefix = paths.npmGlobalPrefix?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
52
|
+
const npmGlobal = prefix !== undefined
|
|
53
|
+
? root.toLowerCase().startsWith((prefix + "/node_modules/").toLowerCase())
|
|
54
|
+
: undefined;
|
|
55
|
+
return { mode: "npm", root, ...(npmGlobal !== undefined ? { npmGlobal } : {}) };
|
|
56
|
+
}
|
|
57
|
+
// a source checkout: the entry is src/cli/main.ts (or bin/…) inside a git repo
|
|
58
|
+
for (const cand of sourceRootCandidates(paths.entry)) {
|
|
59
|
+
if (existsSync(join(cand, ".git"))) return { mode: "source", root: cand };
|
|
60
|
+
}
|
|
61
|
+
return { mode: "unknown" };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** walk up from the entry file to the plausible repo roots (bounded: an entry deep in a monorepo) */
|
|
65
|
+
function sourceRootCandidates(entry: string): string[] {
|
|
66
|
+
const out: string[] = [];
|
|
67
|
+
let dir = entry.includes(sep) || entry.includes("/") ? entry.replace(/\\/g, "/").split("/").slice(0, -1).join("/") : ".";
|
|
68
|
+
for (let i = 0; i < 6 && dir.length > 0; i++) {
|
|
69
|
+
out.push(dir.replace(/\//g, sep));
|
|
70
|
+
const up = dir.split("/").slice(0, -1).join("/");
|
|
71
|
+
if (up === dir) break;
|
|
72
|
+
dir = up;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface UpdatePlan {
|
|
78
|
+
mode: InstallMode;
|
|
79
|
+
channel: UpdateChannel;
|
|
80
|
+
/** the commands to run, in order; empty for binary/unknown (manual carries the words) */
|
|
81
|
+
commands: string[][];
|
|
82
|
+
cwd?: string;
|
|
83
|
+
/** what a human does when there is no command to run */
|
|
84
|
+
manual?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The channel: explicit wins; otherwise a prerelease stays on beta, a release stays on latest. */
|
|
88
|
+
export function channelFor(currentVersion: string, explicit?: UpdateChannel | "auto"): UpdateChannel {
|
|
89
|
+
if (explicit === "beta" || explicit === "latest") return explicit;
|
|
90
|
+
return currentVersion.includes("-") ? "beta" : "latest";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function planUpdate(install: DetectedInstall, opts: { currentVersion: string; channel?: UpdateChannel | "auto"; distBuilt?: boolean }): UpdatePlan {
|
|
94
|
+
const channel = channelFor(opts.currentVersion, opts.channel);
|
|
95
|
+
switch (install.mode) {
|
|
96
|
+
case "npm": {
|
|
97
|
+
const spec = `rovecode@${channel}`;
|
|
98
|
+
// -g when the install is global; a local (project) install updates in its project root.
|
|
99
|
+
// npmGlobal undefined = the caller did not resolve `npm prefix -g` yet: runUpdate decides.
|
|
100
|
+
if (install.npmGlobal === false && install.root) {
|
|
101
|
+
const root = install.root.replace(/\\/g, "/");
|
|
102
|
+
const i = root.lastIndexOf("/node_modules/");
|
|
103
|
+
const project = i > 0 ? root.slice(0, i).replace(/\//g, sep) : undefined;
|
|
104
|
+
return { mode: "npm", channel, commands: [["npm", "install", spec]], ...(project ? { cwd: project } : {}) };
|
|
105
|
+
}
|
|
106
|
+
return { mode: "npm", channel, commands: [["npm", "install", "-g", spec]] };
|
|
107
|
+
}
|
|
108
|
+
case "source": {
|
|
109
|
+
const cmds: string[][] = [["git", "pull", "--ff-only"], ["bun", "install"]];
|
|
110
|
+
if (opts.distBuilt === true) cmds.push(["bun", "run", "build:cli"]);
|
|
111
|
+
return { mode: "source", channel, commands: cmds, ...(install.root ? { cwd: install.root } : {}) };
|
|
112
|
+
}
|
|
113
|
+
case "binary":
|
|
114
|
+
return { mode: "binary", channel, commands: [], manual: "a compiled binary does not replace itself yet — download the new artifact from the releases page (https://github.com/9Code-Labs/rovecode-community/releases) and swap the file" };
|
|
115
|
+
default:
|
|
116
|
+
return { mode: "unknown", channel, commands: [], manual: "cannot tell how this copy was installed — update it the way you installed it (npm: `npm install -g rovecode@" + channel + "`; source: `git pull && bun install`)" };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface RunUpdateDeps {
|
|
121
|
+
/** run one command, stream-free: returns the exit code and the merged tail of its output */
|
|
122
|
+
spawn(cmd: string[], cwd?: string): Promise<{ code: number; out: string }>;
|
|
123
|
+
/** npm only, and only when the plan did not pre-decide: resolve `npm prefix -g` */
|
|
124
|
+
npmGlobalPrefix?(): Promise<string | undefined>;
|
|
125
|
+
log?(line: string): void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface UpdateResult { ok: boolean; detail: string; ran: string[] }
|
|
129
|
+
|
|
130
|
+
/** Run the plan's commands in order; the first failure stops and reports. Never throws. */
|
|
131
|
+
export async function runUpdate(plan: UpdatePlan, install: DetectedInstall, deps: RunUpdateDeps): Promise<UpdateResult> {
|
|
132
|
+
const ran: string[] = [];
|
|
133
|
+
if (plan.commands.length === 0) return { ok: false, detail: plan.manual ?? "nothing to run", ran };
|
|
134
|
+
let commands = plan.commands;
|
|
135
|
+
// an npm plan whose -g question was left open: answer it now, once, from `npm prefix -g`
|
|
136
|
+
if (plan.mode === "npm" && install.npmGlobal === undefined && install.root && deps.npmGlobalPrefix) {
|
|
137
|
+
const prefix = (await deps.npmGlobalPrefix())?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
138
|
+
if (prefix) {
|
|
139
|
+
const global = install.root.replace(/\\/g, "/").toLowerCase().startsWith((prefix + "/node_modules/").toLowerCase());
|
|
140
|
+
const spec = plan.commands[0]![plan.commands[0]!.length - 1]!;
|
|
141
|
+
commands = global ? [["npm", "install", "-g", spec]] : [["npm", "install", spec]];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const cmd of commands) {
|
|
145
|
+
deps.log?.(`$ ${cmd.join(" ")}`);
|
|
146
|
+
let r: { code: number; out: string };
|
|
147
|
+
try { r = await deps.spawn(cmd, plan.cwd); }
|
|
148
|
+
catch (e) { return { ok: false, detail: `${cmd[0]} failed to start: ${e instanceof Error ? e.message : String(e)}`, ran }; }
|
|
149
|
+
ran.push(cmd.join(" "));
|
|
150
|
+
if (r.code !== 0) return { ok: false, detail: `${cmd.join(" ")} exited ${r.code}: ${tail(r.out)}`, ran };
|
|
151
|
+
}
|
|
152
|
+
return { ok: true, detail: "updated — restart rovecode to run the new version", ran };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function tail(s: string, max = 400): string {
|
|
156
|
+
const t = s.trim();
|
|
157
|
+
return t.length > max ? "…" + t.slice(-max) : t;
|
|
158
|
+
}
|