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,174 @@
|
|
|
1
|
+
/** Sextant bridge (port #44): pure helpers between rovecode's app/Renderer seam and the surface state —
|
|
2
|
+
* a user line → row (image chips split off), a replayed tool card → row, how many duplicate app
|
|
3
|
+
* notes a RunEvent triggers (the #41 reducer already produced the row), and the RunEvent / TaskInfo
|
|
4
|
+
* → rovecode forwarding table (#45's report: start/read/edit/write/remove/run/glob/plan/spawn/
|
|
5
|
+
* permission/fetch/crew/tinker on starts — every tool says its specific thing, a risky command gets
|
|
6
|
+
* the risk line — + observe over written content and edit newLines; grep's count, tool_fail/pass/fail + a fail-line
|
|
7
|
+
* reaction on tool ends; denied on a permission refusal; done/stopped/error at run_end; laneDone /
|
|
8
|
+
* laneFail from the task manager). Pure: `now` is a parameter, no I/O, no timers. */
|
|
9
|
+
|
|
10
|
+
import type { RunEvent } from "../core/types.ts";
|
|
11
|
+
import type { TaskInfo } from "../core/tasks.ts";
|
|
12
|
+
import type { Pet, PetEventData } from "./pet.ts";
|
|
13
|
+
import { baseName, describeCall, relPath } from "./tool-rows.ts";
|
|
14
|
+
import { splitAttached } from "./mentions.ts";
|
|
15
|
+
import type { MessageRow, ToolRow } from "./types.ts";
|
|
16
|
+
|
|
17
|
+
type UserRow = Extract<MessageRow, { kind: "user" }>;
|
|
18
|
+
const CHIP_RE = /\[image: ([^\]]*)\]/g;
|
|
19
|
+
const TEST_CMD = /\b(tests?|vitest|jest|pytest|mocha|spec)\b/i;
|
|
20
|
+
/** commands worth a second look before they run: recursive deletes, force pushes, history rewrites,
|
|
21
|
+
* world-writable modes, piping the network into a shell, dropping tables */
|
|
22
|
+
const RISKY_CMD = /\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r)\b|--force\b|\bpush\s+-f\b|\breset\s+--hard\b|\bchmod\s+777\b|\bcurl\b[^|]*\|\s*(ba|z)?sh\b|\bdrop\s+(table|database)\b/i;
|
|
23
|
+
const RUN_TOOLS = new Set(["bash", "shell", "run"]);
|
|
24
|
+
const REMOVE_TOOLS = new Set(["remove", "rm", "delete", "unlink"]);
|
|
25
|
+
|
|
26
|
+
const rec = (v: unknown): Record<string, unknown> => (v && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : {});
|
|
27
|
+
const str = (v: unknown): string => (typeof v === "string" ? v : "");
|
|
28
|
+
const oneLine = (s: string, max = 40): string => s.replace(/\s+/g, " ").trim().slice(0, max);
|
|
29
|
+
|
|
30
|
+
/** tui/attach.ts userTurnLine: the text, then ONE line of `[image: name]` chips (or chips alone) */
|
|
31
|
+
export function userRow(line: string, now: number): UserRow {
|
|
32
|
+
const lines = line.split("\n");
|
|
33
|
+
const last = lines[lines.length - 1] ?? "";
|
|
34
|
+
const chips = [...last.matchAll(CHIP_RE)].map((m) => m[1]!);
|
|
35
|
+
const chipLine = chips.length > 0 && last.replace(CHIP_RE, "").trim() === "";
|
|
36
|
+
// `@file` read blocks (mentions.ts) stay out of the panel: the typed text and one chip per file
|
|
37
|
+
const { text, files } = splitAttached((chipLine ? lines.slice(0, -1) : lines).join("\n"));
|
|
38
|
+
const row: UserRow = { kind: "user", text, at: now };
|
|
39
|
+
if (chipLine) row.images = chips;
|
|
40
|
+
if (files.length > 0) row.files = files;
|
|
41
|
+
return row;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** args for a replayed tool card: session-cmd replayTranscript hands the renderer a ≤120-char JSON
|
|
45
|
+
* slice — the whole object when it still parses, else the path/command/pattern/url/question/label
|
|
46
|
+
* fields recovered from the intact prefix (a truncated escape yields nothing for that key) */
|
|
47
|
+
export function argsFromPreview(preview: string): Record<string, unknown> {
|
|
48
|
+
try {
|
|
49
|
+
const v: unknown = JSON.parse(preview);
|
|
50
|
+
if (v && typeof v === "object" && !Array.isArray(v)) return v as Record<string, unknown>;
|
|
51
|
+
} catch { /* truncated — fall through */ }
|
|
52
|
+
const out: Record<string, unknown> = {};
|
|
53
|
+
for (const k of ["path", "command", "pattern", "url", "question", "label"]) {
|
|
54
|
+
const m = new RegExp(`"${k}":"((?:[^"\\\\]|\\\\.)*)"`).exec(preview);
|
|
55
|
+
if (!m) continue;
|
|
56
|
+
try { out[k] = JSON.parse(`"${m[1]}"`); } catch { /* unterminated escape */ }
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** a replayed tool card (the renderer is NOT busy: session history) → a settled row; toolEnd fills ok/detail */
|
|
62
|
+
export function replayToolRow(callId: string, tool: string, argsPreview: string, cwd: string): ToolRow {
|
|
63
|
+
const d = describeCall(tool, argsFromPreview(argsPreview), cwd);
|
|
64
|
+
const row: ToolRow = { kind: "tool", callId, tool, verb: d.verb, label: d.label, running: false };
|
|
65
|
+
if (d.path) row.path = d.path;
|
|
66
|
+
if (d.verb === "edit" || d.verb === "write") { row.add = d.add; row.del = d.del; }
|
|
67
|
+
return row;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** how many addSystemNote calls app.ts makes for this event that duplicate a reducer row: the
|
|
71
|
+
* compaction note, "↪ steering applied", and the run_end error/warn line (none for `done`) — the
|
|
72
|
+
* renderer drops exactly that many, and only those */
|
|
73
|
+
export function duplicateNotes(ev: RunEvent): number {
|
|
74
|
+
if (ev.type === "compaction" || ev.type === "steer") return 1;
|
|
75
|
+
if (ev.type === "run_end") return ev.status === "done" ? 0 : 1;
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** what the renderer remembers per live call so the end event can find its tool/command */
|
|
80
|
+
export interface LiveCall { tool: string; cmd: string }
|
|
81
|
+
|
|
82
|
+
/** RunEvent → rovecode (see the header table) */
|
|
83
|
+
export function petOnEvent(pet: Pet, ev: RunEvent, calls: Map<string, LiveCall>, cwd: string, now: number): void {
|
|
84
|
+
switch (ev.type) {
|
|
85
|
+
case "run_start": pet.event("start", undefined, now); break;
|
|
86
|
+
case "tool_execution_start": {
|
|
87
|
+
const a = rec(ev.args), f = baseName(relPath(cwd, str(a.path))) || "file";
|
|
88
|
+
calls.set(ev.callId, { tool: ev.tool, cmd: str(a.command) || str(a.cmd) });
|
|
89
|
+
petOnStart(pet, ev.tool, a, f, now);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "tool_execution_end": {
|
|
93
|
+
const c = calls.get(ev.callId);
|
|
94
|
+
calls.delete(ev.callId);
|
|
95
|
+
petOnEnd(pet, c, ev.ok, ev.output, now);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "tool_call_failed":
|
|
99
|
+
calls.delete(ev.callId);
|
|
100
|
+
pet.event(ev.reason === "permission_denied" ? "denied" : "tool_fail", undefined, now);
|
|
101
|
+
break;
|
|
102
|
+
case "run_end":
|
|
103
|
+
calls.clear();
|
|
104
|
+
pet.event(ev.status === "done" ? "done" : ev.status === "error" ? "error" : "stopped", undefined, now);
|
|
105
|
+
break;
|
|
106
|
+
default: break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** the host of a URL for the fetch quip; a bare or broken URL keeps its first 30 chars */
|
|
111
|
+
const hostOf = (u: string): string => { try { return new URL(u).host || oneLine(u, 30); } catch { return oneLine(u, 30) || "the web"; } };
|
|
112
|
+
|
|
113
|
+
/** Every tool the agent has says something SPECIFIC — the file, the pattern, the host, the child,
|
|
114
|
+
* the thing being tinkered with — because a bubble that only says "working" is worse than silence.
|
|
115
|
+
* Kinds are the existing ones where they fit (a directory listing is a read, an ask is a permission,
|
|
116
|
+
* a search start is glob's line with the pattern); fetch / crew / tinker are the three acts that
|
|
117
|
+
* had none. Unknown tools (an MCP server's own, a future one) fall to tinker with their name. */
|
|
118
|
+
function petOnStart(pet: Pet, tool: string, a: Record<string, unknown>, f: string, now: number): void {
|
|
119
|
+
const data: PetEventData = { f };
|
|
120
|
+
if (tool === "read") pet.event("read", data, now);
|
|
121
|
+
else if (tool === "edit") {
|
|
122
|
+
pet.event("edit", data, now);
|
|
123
|
+
const lines = (Array.isArray(a.edits) ? a.edits : []).flatMap((e) => { const nl = rec(e).newLines; return Array.isArray(nl) ? nl.map(String) : []; });
|
|
124
|
+
if (lines.length) pet.observe(lines.join("\n"), "ins", now);
|
|
125
|
+
} else if (tool === "write") { pet.event("write", data, now); if (str(a.content)) pet.observe(str(a.content), "ins", now); }
|
|
126
|
+
else if (REMOVE_TOOLS.has(tool)) pet.event("remove", data, now);
|
|
127
|
+
else if (RUN_TOOLS.has(tool)) {
|
|
128
|
+
// a destructive-looking command gets the risk line instead of "thunder time" — keyed off the
|
|
129
|
+
// command text the agent asked for, never off an error message (the validator owns those)
|
|
130
|
+
const cmd = str(a.command) || str(a.cmd);
|
|
131
|
+
if (RISKY_CMD.test(cmd)) pet.react("risk", now); else pet.event("run", undefined, now);
|
|
132
|
+
}
|
|
133
|
+
else if (tool === "glob" || tool === "grep") pet.event("glob", { q: oneLine(str(a.pattern), 24) || "it" }, now);
|
|
134
|
+
else if (tool === "ls") pet.event("read", { f: (baseName(str(a.path)) || ".") + "/" }, now);
|
|
135
|
+
else if (tool === "web_fetch") pet.event("fetch", { f: hostOf(str(a.url)) }, now);
|
|
136
|
+
else if (tool === "todo_write") { const n = Array.isArray(a.todos) ? a.todos.length : 0; if (n) pet.event("plan", { n }, now); }
|
|
137
|
+
else if (tool === "todo_read") pet.event("read", { f: "the plan" }, now);
|
|
138
|
+
else if (tool === "ask_user") pet.event("permission", undefined, now);
|
|
139
|
+
else if (tool === "task") pet.event("spawn", { a: oneLine(str(a.label) || str(a.agent) || "a worker", 20) }, now);
|
|
140
|
+
else if (tool === "task_status") pet.event("crew", { a: str(a.action) === "list" ? "the crew" : oneLine(str(a.id), 20) || "the crew" }, now);
|
|
141
|
+
else pet.event("tinker", { f: tinkerTarget(tool, a) }, now);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** what the housekeeping tools are about, by name: `providers`, `skills`, `memory`, `notes`, `search/issues` */
|
|
145
|
+
function tinkerTarget(tool: string, a: Record<string, unknown>): string {
|
|
146
|
+
if (tool.startsWith("provider_")) return str(a.action) === "use" && str(a.selector) ? oneLine(str(a.selector), 24) : "providers";
|
|
147
|
+
if (tool === "skill_view") return oneLine(str(a.name) || str(a.skill), 24) || "a skill";
|
|
148
|
+
if (tool === "skills_list") return "the skills";
|
|
149
|
+
if (tool === "memory_edit") return "memory";
|
|
150
|
+
if (tool === "recall") return oneLine(str(a.query), 24) ? `notes on ${oneLine(str(a.query), 24)}` : "the notes";
|
|
151
|
+
if (tool === "eval_cell") return "a scratch cell";
|
|
152
|
+
if (tool === "mcp_call" || tool === "mcp_list") return [str(a.server), str(a.tool)].filter(Boolean).map((s) => oneLine(s, 16)).join(" ") || "mcp";
|
|
153
|
+
return oneLine(tool, 24);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function petOnEnd(pet: Pet, c: LiveCall | undefined, ok: boolean, output: string, now: number): void {
|
|
157
|
+
if (c && RUN_TOOLS.has(c.tool)) {
|
|
158
|
+
const lines = output.replace(/^exit=-?\d+\r?\n?/, "").split(/\r?\n/).filter((l) => l.trim());
|
|
159
|
+
const r = oneLine(lines[lines.length - 1] ?? "");
|
|
160
|
+
if (TEST_CMD.test(c.cmd)) pet.event(ok ? "pass" : "fail", { r }, now);
|
|
161
|
+
else if (!ok) pet.event("tool_fail", undefined, now);
|
|
162
|
+
if (lines.some((l) => /^\s*FAIL\b/.test(l))) pet.react("fail-line", now);
|
|
163
|
+
else if (ok && lines.some((l) => /^\s*PASS\b/.test(l))) pet.react("pass-line", now);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!ok) { pet.event("tool_fail", undefined, now); return; }
|
|
167
|
+
if (c?.tool === "grep") pet.event("grep", { n: output.split(/\r?\n/).filter((l) => l.trim() && !l.startsWith("(")).length }, now);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** TaskManager status transitions → laneDone / laneFail quips (queued/running/cancelled say nothing) */
|
|
171
|
+
export function petOnTask(pet: Pet, t: TaskInfo, now: number): void {
|
|
172
|
+
if (t.status === "done") pet.event("laneDone", { a: oneLine(t.label, 20), r: oneLine(t.summary ?? "done") }, now);
|
|
173
|
+
else if (t.status === "failed") pet.event("laneFail", { a: oneLine(t.label, 20), r: oneLine(t.error ?? "failed") }, now);
|
|
174
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Sextant cards (port #44): the modal seams of the Renderer — the approval card (once / always /
|
|
2
|
+
* deny), the ask_user question card (options / free text / skip, dismissed by the run's abort signal)
|
|
3
|
+
* and the pickOne picker (the #43 palette with `pick:<value>` rows: Enter resolves the fuzzy-selected
|
|
4
|
+
* row, Esc / ⌃k / ⌃p / a click outside resolves null). ONE card at a time: a second approval waits
|
|
5
|
+
* for the first to settle, a second concurrent question is rejected (renderer.ts contract), a new
|
|
6
|
+
* picker cancels the previous one; settleAll() (renderer stop) resolves everything with deny / null so
|
|
7
|
+
* no awaiting caller is ever pinned. keys.ts owns the key handling (onCardKey / onPaletteKey) and
|
|
8
|
+
* nulls s.card before calling resolve — this class only owns the promises and the state hand-off. */
|
|
9
|
+
|
|
10
|
+
import type { ApprovalAnswer, PickItem, QuestionAnswer, QuestionPrompt } from "../tui/renderer.ts";
|
|
11
|
+
import { fuzzy } from "./engine.ts";
|
|
12
|
+
import { closePalette, openPalette, paletteVisible } from "./overlays.ts";
|
|
13
|
+
import type { CardState, InputEvent, SextantState } from "./types.ts";
|
|
14
|
+
import { notify } from "./model.ts";
|
|
15
|
+
|
|
16
|
+
/** palette action prefix of a picker row; the value follows verbatim (it may contain ":") */
|
|
17
|
+
export const PICK = "pick:";
|
|
18
|
+
|
|
19
|
+
export interface CardHostDeps {
|
|
20
|
+
state: SextantState;
|
|
21
|
+
/** request a repaint */
|
|
22
|
+
dirty(): void;
|
|
23
|
+
/** the renderer stopped: a card opened now resolves its fallback at once */
|
|
24
|
+
stopped(): boolean;
|
|
25
|
+
/** an approval card opened / was allowed (the pet's permission / allowed quips) */
|
|
26
|
+
onApprovalOpen?(): void;
|
|
27
|
+
onAllowed?(): void;
|
|
28
|
+
/** the surface clock, for the "needs you" notice a card raises (model.ts notify); Date.now() when absent */
|
|
29
|
+
clock?(): number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** tools whose approval card offers the accept-edits door */
|
|
33
|
+
const EDIT_TOOLS = new Set(["edit", "write"]);
|
|
34
|
+
|
|
35
|
+
export class CardHost {
|
|
36
|
+
/** cancel thunks of every open or queued card and the picker */
|
|
37
|
+
private readonly pending = new Set<() => void>();
|
|
38
|
+
private queue: Promise<void> = Promise.resolve();
|
|
39
|
+
private picker: ((v: string | null) => void) | null = null;
|
|
40
|
+
|
|
41
|
+
constructor(private readonly d: CardHostDeps) {}
|
|
42
|
+
|
|
43
|
+
/** settle everything with its fallback (deny / null) */
|
|
44
|
+
settleAll(): void { for (const cancel of [...this.pending]) cancel(); }
|
|
45
|
+
get pickerOpen(): boolean { return this.picker !== null; }
|
|
46
|
+
|
|
47
|
+
approval(tool: string, argsPreview: string, detail: string | undefined): Promise<ApprovalAnswer> {
|
|
48
|
+
return this.enqueue<ApprovalAnswer>("deny", (settle) => {
|
|
49
|
+
this.d.onApprovalOpen?.();
|
|
50
|
+
// the `all edits` door is offered only where it means something: a write/edit card. On a bash or
|
|
51
|
+
// a network card it would read as "allow everything", which is what auto mode is for.
|
|
52
|
+
const verdicts: readonly ApprovalAnswer[] = EDIT_TOOLS.has(tool)
|
|
53
|
+
? ["once", "always", "all-edits", "deny"]
|
|
54
|
+
: ["once", "always", "deny"];
|
|
55
|
+
const card: CardState = { kind: "approval", tool, argsPreview, verdicts, selected: 0, resolve: (a) => { if (a !== "deny") this.d.onAllowed?.(); settle(a); } };
|
|
56
|
+
if (detail) card.detail = detail;
|
|
57
|
+
return card;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** cards open ONE at a time: the next waits for the current to settle */
|
|
62
|
+
private enqueue<T>(fallback: T, make: (settle: (v: T) => void) => CardState): Promise<T> {
|
|
63
|
+
return new Promise<T>((resolve) => {
|
|
64
|
+
const open = (): Promise<void> => new Promise<void>((done) => {
|
|
65
|
+
if (this.d.stopped()) { resolve(fallback); done(); return; }
|
|
66
|
+
let card: CardState | null = null, settled = false;
|
|
67
|
+
const settle = (v: T): void => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true; this.pending.delete(cancel);
|
|
70
|
+
if (card && this.d.state.card === card) this.d.state.card = null;
|
|
71
|
+
this.d.dirty(); resolve(v); done();
|
|
72
|
+
};
|
|
73
|
+
const cancel = (): void => settle(fallback);
|
|
74
|
+
this.pending.add(cancel);
|
|
75
|
+
card = make(settle);
|
|
76
|
+
this.d.state.card = card; notify(this.d.state, "tool" in card ? `needs you: ${card.tool}` : "needs you: a question", this.d.clock?.() ?? Date.now(), "warn", "approval"); this.d.dirty();
|
|
77
|
+
});
|
|
78
|
+
this.queue = this.queue.then(open, open);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** the question card; `signal` abort dismisses it (null); a SECOND concurrent ask is rejected */
|
|
83
|
+
question(q: QuestionPrompt, signal?: AbortSignal): Promise<QuestionAnswer | null> {
|
|
84
|
+
if (this.d.stopped() || signal?.aborted) return Promise.resolve(null);
|
|
85
|
+
if (this.d.state.card) return Promise.reject(new Error("a question or approval card is already open"));
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
let settled = false;
|
|
88
|
+
const settle = (a: QuestionAnswer | null): void => {
|
|
89
|
+
if (settled) return;
|
|
90
|
+
settled = true; this.pending.delete(cancel); signal?.removeEventListener("abort", cancel);
|
|
91
|
+
if (this.d.state.card === card) this.d.state.card = null;
|
|
92
|
+
this.d.dirty(); resolve(a);
|
|
93
|
+
};
|
|
94
|
+
const cancel = (): void => settle(null);
|
|
95
|
+
const card: CardState = {
|
|
96
|
+
kind: "question", prompt: q, selected: 0, freeText: "",
|
|
97
|
+
resolve: (a) => settle(a === null ? null : a.kind === "option" ? { choice: a.index, label: q.options?.[a.index] } : { text: a.text }),
|
|
98
|
+
};
|
|
99
|
+
this.pending.add(cancel); signal?.addEventListener("abort", cancel, { once: true });
|
|
100
|
+
this.d.state.card = card; notify(this.d.state, "tool" in card ? `needs you: ${card.tool}` : "needs you: a question", this.d.clock?.() ?? Date.now(), "warn", "approval"); this.d.dirty();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** the palette as a picker: items become `pick:<value>` rows under `title` */
|
|
105
|
+
pick(items: PickItem[], title?: string): Promise<string | null> {
|
|
106
|
+
if (this.d.stopped() || items.length === 0) return Promise.resolve(null);
|
|
107
|
+
this.picker?.(null);
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const s = this.d.state;
|
|
110
|
+
// the title is the BOX's, not a group row: as a group it was painted unclipped inside the list
|
|
111
|
+
// and ran past the border. Rows keep one short group so the list has no repeated header.
|
|
112
|
+
openPalette(s, items.map((i) => ({
|
|
113
|
+
label: i.description ? `${i.label} · ${i.description}` : i.label, group: "", action: PICK + i.value,
|
|
114
|
+
...(i.description !== undefined ? { hint: i.description } : {}),
|
|
115
|
+
})), title ?? "pick one");
|
|
116
|
+
const settle = (v: string | null): void => {
|
|
117
|
+
if (this.picker !== settle) return;
|
|
118
|
+
this.picker = null; this.pending.delete(cancel);
|
|
119
|
+
if (s.palette?.items.some((it) => it.action.startsWith(PICK))) closePalette(s);
|
|
120
|
+
this.d.dirty(); resolve(v);
|
|
121
|
+
};
|
|
122
|
+
const cancel = (): void => settle(null);
|
|
123
|
+
this.picker = settle; this.pending.add(cancel); this.d.dirty();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Enter / Esc while the picker's palette is open — true = swallowed (keys.ts must not see them) */
|
|
128
|
+
interceptKey(ev: InputEvent): boolean {
|
|
129
|
+
const s = this.d.state;
|
|
130
|
+
if (!this.picker || !s.palette || ev.type !== "key" || ev.ctrl) return false;
|
|
131
|
+
if (ev.name === "enter") {
|
|
132
|
+
const it = paletteVisible(s.palette, fuzzy)[s.palette.sel];
|
|
133
|
+
this.picker(it && it.action.startsWith(PICK) ? it.action.slice(PICK.length) : null);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (ev.name === "escape") { this.picker(null); return true; }
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** after keys.handleInput: ⌃k / ⌃p / a click outside closed the palette → the picker resolves null */
|
|
141
|
+
afterKey(): void { if (this.picker && !this.d.state.palette) this.picker(null); }
|
|
142
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Sextant diff base (port #44 fix wave): the PRE-EDIT content of a file the agent edited without a
|
|
2
|
+
* gate (yolo, `always`, an auto-allowed rule), rebuilt after the fact. Why after: the renderer sees
|
|
3
|
+
* tool_execution_start only when the loop's event pump flushes (core/loop.ts pumps every 5 ms), and
|
|
4
|
+
* rovecode's edit/write tools have already written synchronously by then (core/tools.ts: emit → await
|
|
5
|
+
* execute, whose first statements are the fs calls) — a disk snapshot taken at the start event IS the
|
|
6
|
+
* post-edit file. What the ops carry is enough to walk the edit back: each hashline op replaced ONE
|
|
7
|
+
* anchored line (anchorLine in the original, verified by lineHash) with newLines, applied bottom-up
|
|
8
|
+
* (coding/hashline.ts applyEditsToContent), so undoing them top-down puts every new block at
|
|
9
|
+
* anchorLine − 1 of the partially restored file. The only unknown per op is the replaced line's text;
|
|
10
|
+
* any line whose lineHash equals the anchor — in git HEAD, or elsewhere in the file — is a candidate,
|
|
11
|
+
* and the file TAG the ops carry (fileTag of the content the model read) proves a rebuild right or
|
|
12
|
+
* rejects it. Pure: no I/O, no clock. */
|
|
13
|
+
|
|
14
|
+
import { fileTag, lineHash, type EditOp } from "../coding/hashline.ts";
|
|
15
|
+
|
|
16
|
+
export type HashlineOp = Pick<EditOp, "tag" | "anchorLine" | "anchorHash" | "newLines">;
|
|
17
|
+
|
|
18
|
+
/** candidate combinations tried before giving up (whitespace variants of one line share a hash) */
|
|
19
|
+
const MAX_TRIES = 8;
|
|
20
|
+
|
|
21
|
+
/** the hashline ops of an edit call's args (tool_execution_start.args); [] when any op is malformed */
|
|
22
|
+
export function editOpsOf(args: unknown): HashlineOp[] {
|
|
23
|
+
const a = args && typeof args === "object" && !Array.isArray(args) ? (args as { edits?: unknown }) : {};
|
|
24
|
+
if (!Array.isArray(a.edits)) return [];
|
|
25
|
+
const out: HashlineOp[] = [];
|
|
26
|
+
for (const e of a.edits) {
|
|
27
|
+
const r = e && typeof e === "object" && !Array.isArray(e) ? (e as Record<string, unknown>) : {};
|
|
28
|
+
const lines = Array.isArray(r.newLines) && r.newLines.every((l) => typeof l === "string") ? (r.newLines as string[]) : null;
|
|
29
|
+
if (typeof r.tag !== "string" || typeof r.anchorLine !== "number" || !Number.isInteger(r.anchorLine) || typeof r.anchorHash !== "string" || !lines) return [];
|
|
30
|
+
out.push({ tag: r.tag, anchorLine: r.anchorLine, anchorHash: r.anchorHash, newLines: lines });
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The content before `ops` were applied to it, given the file on disk NOW (`disk`) and the committed
|
|
36
|
+
* content when git has one (`head`) — or null when it cannot be proven: no op, ops that disagree on the
|
|
37
|
+
* TAG or share a line, a block on disk that is not its op's newLines, an anchor no known line hashes to,
|
|
38
|
+
* or no candidate combination that reproduces the TAG. Null means "no pre-edit base" — never a guess. */
|
|
39
|
+
export function reconstructBefore(disk: string, ops: readonly HashlineOp[], head: string | null): string | null {
|
|
40
|
+
if (!ops.length) return null;
|
|
41
|
+
const tag = ops[0]!.tag;
|
|
42
|
+
if (ops.some((o) => o.tag !== tag)) return null;
|
|
43
|
+
const sorted = [...ops].sort((a, b) => a.anchorLine - b.anchorLine);
|
|
44
|
+
if (sorted.some((o, i) => i > 0 && o.anchorLine === sorted[i - 1]!.anchorLine)) return null;
|
|
45
|
+
const post = disk.split("\n");
|
|
46
|
+
// HEAD lines first: the replaced line is most likely intact there; then the file itself (an unchanged twin)
|
|
47
|
+
const pool = [...(head ?? "").split("\n"), ...post];
|
|
48
|
+
const candidates = sorted.map((o) => [...new Set(pool.filter((l) => lineHash(l) === o.anchorHash))]);
|
|
49
|
+
if (candidates.some((c) => c.length === 0)) return null;
|
|
50
|
+
let tries = 0;
|
|
51
|
+
const attempt = (i: number, lines: string[]): string | null => {
|
|
52
|
+
if (i === sorted.length) { const text = lines.join("\n"); return fileTag(text) === tag ? text : null; }
|
|
53
|
+
const o = sorted[i]!, at = o.anchorLine - 1, n = o.newLines.length;
|
|
54
|
+
if (at < 0 || at > lines.length || o.newLines.some((l, k) => lines[at + k] !== l)) return null;
|
|
55
|
+
for (const text of candidates[i]!) {
|
|
56
|
+
if (++tries > MAX_TRIES) return null;
|
|
57
|
+
const r = attempt(i + 1, [...lines.slice(0, at), text, ...lines.slice(at + n)]);
|
|
58
|
+
if (r !== null) return r;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
return attempt(0, post);
|
|
63
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** Sextant repo I/O (port #44): the files-panel list, git statuses + branch, bounded file reads for
|
|
2
|
+
* the code panel and the hunks the diff view shows. Together with git-status.ts this is the ONLY I/O
|
|
3
|
+
* behind the surface, and the renderer runs it OFF the frame loop (sextant-repo.ts: a setTimeout(0)
|
|
4
|
+
* scheduled from the tick, then the `…Async` forms here so git runs beside the loop — a spawnSync
|
|
5
|
+
* must not stall a half-painted frame). The file list is `git ls-files -z --cached --others
|
|
6
|
+
* --exclude-standard` (the coding/repomap-files.ts gitListFiles command, issued through the injectable
|
|
7
|
+
* sextant GitRunner so tests never spawn) or a bounded deterministic walk when git cannot answer.
|
|
8
|
+
* Nothing here throws: null/[] instead. The sync forms stay for synchronous callers and as the parity
|
|
9
|
+
* oracle of the async ones. */
|
|
10
|
+
|
|
11
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { buildHunks, diffOps, opStats, toDiffHunk } from "./engine.ts";
|
|
14
|
+
import {
|
|
15
|
+
gitBranch, gitBranchAsync, gitHeadContent, gitHeadContentAsync, gitPorcelain, gitPorcelainAsync, spawnGit, spawnGitAsync,
|
|
16
|
+
type GitRunner, type GitRunnerAsync,
|
|
17
|
+
} from "./git-status.ts";
|
|
18
|
+
import { reconstructBefore, type HashlineOp } from "./sextant-diff-base.ts";
|
|
19
|
+
import type { DiffHunk, FileStatus } from "./types.ts";
|
|
20
|
+
|
|
21
|
+
/** walk bound (coding/repomap-files.ts MAX_SRC_FILES) */
|
|
22
|
+
export const MAX_FILES = 2000;
|
|
23
|
+
/** a file larger than this is not shown in the code panel (`cannot read`) */
|
|
24
|
+
export const MAX_FILE_BYTES = 512 * 1024;
|
|
25
|
+
/** git's binary heuristic: a NUL within the first 8000 bytes */
|
|
26
|
+
const BINARY_SNIFF = 8000;
|
|
27
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", ".rovecode", "dist", "build", "out", "coverage", ".cache"]);
|
|
28
|
+
const DIFF_CONTEXT = 3;
|
|
29
|
+
|
|
30
|
+
export interface RepoSnapshot {
|
|
31
|
+
/** cwd-relative posix paths (tracked + untracked-unignored, or the walk) */
|
|
32
|
+
paths: string[];
|
|
33
|
+
/** porcelain M/A/D; null = no git */
|
|
34
|
+
statuses: Map<string, FileStatus> | null;
|
|
35
|
+
branch: string | null;
|
|
36
|
+
/** the list came from git (a non-repo walks and never polls statuses) */
|
|
37
|
+
git: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const LS_FILES: readonly string[] = ["ls-files", "-z", "--cached", "--others", "--exclude-standard"];
|
|
41
|
+
const splitZ = (r: { status: number | null; stdout: string } | null): string[] | null => (!r || r.status !== 0 ? null : r.stdout.split("\0").filter((p) => p.length > 0));
|
|
42
|
+
|
|
43
|
+
/** tracked + untracked-but-not-ignored paths; null when git cannot run, the cwd is not a repo or the call fails */
|
|
44
|
+
export function gitFiles(cwd: string, run: GitRunner = spawnGit): string[] | null {
|
|
45
|
+
try { return splitZ(run(LS_FILES, cwd)); } catch { return null; }
|
|
46
|
+
}
|
|
47
|
+
/** gitFiles, awaited */
|
|
48
|
+
export async function gitFilesAsync(cwd: string, run: GitRunnerAsync = spawnGitAsync): Promise<string[] | null> {
|
|
49
|
+
try { return splitZ(await run(LS_FILES, cwd)); } catch { return null; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** bounded deterministic walk for non-repos: per-dir sorted DFS, SKIP_DIRS and dot-dirs skipped, at most `max` files */
|
|
53
|
+
export function walkFiles(cwd: string, max = MAX_FILES): string[] {
|
|
54
|
+
const out: string[] = [];
|
|
55
|
+
const walk = (dir: string, rel: string): void => {
|
|
56
|
+
let names: string[];
|
|
57
|
+
try { names = readdirSync(dir); } catch { return; }
|
|
58
|
+
for (const name of names.sort()) {
|
|
59
|
+
if (out.length >= max) return;
|
|
60
|
+
const full = join(dir, name), r = rel ? `${rel}/${name}` : name;
|
|
61
|
+
let st;
|
|
62
|
+
try { st = statSync(full); } catch { continue; }
|
|
63
|
+
if (st.isDirectory()) { if (!SKIP_DIRS.has(name) && !name.startsWith(".")) walk(full, r); }
|
|
64
|
+
else if (st.isFile()) out.push(r);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
walk(cwd, "");
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** the full snapshot: list (git or walk) + statuses + branch — three spawns, so the renderer calls it
|
|
72
|
+
* at start and after a write/edit/bash; the idle poll uses statusOnly() */
|
|
73
|
+
export function scanRepo(cwd: string, run: GitRunner = spawnGit): RepoSnapshot {
|
|
74
|
+
const fromGit = gitFiles(cwd, run);
|
|
75
|
+
return { paths: fromGit ?? walkFiles(cwd), statuses: gitPorcelain(cwd, run), branch: gitBranch(cwd, run), git: fromGit !== null };
|
|
76
|
+
}
|
|
77
|
+
/** scanRepo, awaited — the three read-only git calls run concurrently */
|
|
78
|
+
export async function scanRepoAsync(cwd: string, run: GitRunnerAsync = spawnGitAsync): Promise<RepoSnapshot> {
|
|
79
|
+
const [fromGit, statuses, branch] = await Promise.all([gitFilesAsync(cwd, run), gitPorcelainAsync(cwd, run), gitBranchAsync(cwd, run)]);
|
|
80
|
+
return { paths: fromGit ?? walkFiles(cwd), statuses, branch, git: fromGit !== null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** the cheap idle refresh: porcelain only (new untracked files show up as A through the statuses) */
|
|
84
|
+
export function statusOnly(cwd: string, run: GitRunner = spawnGit): Map<string, FileStatus> | null {
|
|
85
|
+
return gitPorcelain(cwd, run);
|
|
86
|
+
}
|
|
87
|
+
/** statusOnly, awaited */
|
|
88
|
+
export const statusOnlyAsync = (cwd: string, run: GitRunnerAsync = spawnGitAsync): Promise<Map<string, FileStatus> | null> => gitPorcelainAsync(cwd, run);
|
|
89
|
+
|
|
90
|
+
/** utf8 content of a cwd-relative path; null when missing, not a file, binary or over `maxBytes` */
|
|
91
|
+
export function readFileBounded(cwd: string, rel: string, maxBytes = MAX_FILE_BYTES): string | null {
|
|
92
|
+
try {
|
|
93
|
+
const full = join(cwd, rel);
|
|
94
|
+
const st = statSync(full);
|
|
95
|
+
if (!st.isFile() || st.size > maxBytes) return null;
|
|
96
|
+
const buf = readFileSync(full);
|
|
97
|
+
const n = Math.min(buf.length, BINARY_SNIFF);
|
|
98
|
+
for (let i = 0; i < n; i++) if (buf[i] === 0) return null;
|
|
99
|
+
return buf.toString("utf8");
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface HeadDiff {
|
|
106
|
+
hunks: DiffHunk[]; add: number; del: number;
|
|
107
|
+
/** present when the base is git HEAD (no pre-edit content captured or rebuilt): the hunks are
|
|
108
|
+
* cumulative — every uncommitted change of the file, not just the edit that landed */
|
|
109
|
+
base?: "head";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The base an edit/write is diffed against, best first: the pre-edit content the renderer captured at
|
|
113
|
+
* approval (`before`; null = the file did not exist → all adds); the pre-edit content REBUILT from the
|
|
114
|
+
* hashline ops when the call was not gated (yolo / always — sextant-diff-base.ts, TAG-verified); the
|
|
115
|
+
* HEAD content (cumulative, flagged); null when only the repo question is left (the caller answers it:
|
|
116
|
+
* "" flagged head for a file HEAD never saw, no base at all outside git). */
|
|
117
|
+
function chooseBase(before: string | null | undefined, ops: readonly HashlineOp[] | undefined, disk: string | null, head: string | null): { base: string; head: boolean } | null {
|
|
118
|
+
if (before !== undefined) return { base: before ?? "", head: false };
|
|
119
|
+
const rebuilt = ops?.length && disk !== null ? reconstructBefore(disk, ops, head) : null;
|
|
120
|
+
if (rebuilt !== null) return { base: rebuilt, head: false };
|
|
121
|
+
return head !== null ? { base: head, head: true } : null;
|
|
122
|
+
}
|
|
123
|
+
const NEW_IN_REPO = { base: "", head: true };
|
|
124
|
+
|
|
125
|
+
/** hunks (3 context lines, jsdiff Myers through engine.ts) of `disk` over `base`; null when both are nothing */
|
|
126
|
+
function diffAgainst(b: { base: string; head: boolean }, disk: string | null): HeadDiff | null {
|
|
127
|
+
if (b.base === "" && disk === null) return null;
|
|
128
|
+
const ops = diffOps(b.base, disk ?? "");
|
|
129
|
+
const { a, d } = opStats(ops);
|
|
130
|
+
const out: HeadDiff = { hunks: buildHunks(ops, DIFF_CONTEXT).map(toDiffHunk), add: a, del: d };
|
|
131
|
+
if (b.head) out.base = "head";
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The diff view's hunks for a cwd-relative path that an edit/write just changed: the disk content
|
|
136
|
+
* against chooseBase() — the captured or rebuilt pre-edit content (edit-only, so a dirty file shows
|
|
137
|
+
* the ONE change that landed), else HEAD (`base: "head"`), else "" inside a repo whose HEAD never saw
|
|
138
|
+
* the file (all adds, flagged). null outside git with nothing captured, or when nothing can be read.
|
|
139
|
+
* A deleted file diffs as all deletes. `ops` = the edit call's hashline ops (editOpsOf). */
|
|
140
|
+
export function fileDiff(cwd: string, rel: string, before: string | null | undefined, run: GitRunner = spawnGit, ops?: readonly HashlineOp[]): HeadDiff | null {
|
|
141
|
+
const disk = readFileBounded(cwd, rel);
|
|
142
|
+
const b = chooseBase(before, ops, disk, gitHeadContent(cwd, rel, run)) ?? (gitBranch(cwd, run) !== null ? NEW_IN_REPO : null);
|
|
143
|
+
return b ? diffAgainst(b, disk) : null;
|
|
144
|
+
}
|
|
145
|
+
/** fileDiff, awaited (the renderer's path — sextant-repo.ts) */
|
|
146
|
+
export async function fileDiffAsync(cwd: string, rel: string, before: string | null | undefined, run: GitRunnerAsync = spawnGitAsync, ops?: readonly HashlineOp[]): Promise<HeadDiff | null> {
|
|
147
|
+
const disk = readFileBounded(cwd, rel);
|
|
148
|
+
const b = chooseBase(before, ops, disk, await gitHeadContentAsync(cwd, rel, run)) ?? ((await gitBranchAsync(cwd, run)) !== null ? NEW_IN_REPO : null);
|
|
149
|
+
return b ? diffAgainst(b, disk) : null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** the /diff view: HEAD-vs-disk (nothing captured to fall back on), so always `base: "head"` */
|
|
153
|
+
export const headDiff = (cwd: string, rel: string, run: GitRunner = spawnGit): HeadDiff | null => fileDiff(cwd, rel, undefined, run);
|
|
154
|
+
export const headDiffAsync = (cwd: string, rel: string, run: GitRunnerAsync = spawnGitAsync): Promise<HeadDiff | null> => fileDiffAsync(cwd, rel, undefined, run);
|