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,406 @@
|
|
|
1
|
+
/** LSP diagnostics gate (PORT #13): minimal LSP-over-stdio JSON-RPC client.
|
|
2
|
+
* initialize → didOpen/didChange → collect publishDiagnostics; after a successful
|
|
3
|
+
* edit/write, diagnostics for the touched file are gathered within a bounded settle
|
|
4
|
+
* window (≤2s) and errors are appended to the tool output as a gate note.
|
|
5
|
+
*
|
|
6
|
+
* Ported from opencode packages/opencode/src/lsp/ (client.ts, server.ts, diagnostic.ts):
|
|
7
|
+
* handshake+didOpen/didChange shapes from client.ts:211-255,554-621; publish caching and
|
|
8
|
+
* 150ms rearming debounce from client.ts:13-16,160-172,464-497; errors-only formatter from
|
|
9
|
+
* diagnostic.ts:5-27; PATH probe + `--stdio` spawn from server.ts:115-142; swallow-all gate
|
|
10
|
+
* errors from lsp.ts:360; never-retry broken servers from lsp.ts:224-241. Framing is
|
|
11
|
+
* hand-rolled (rovecode adds no deps here; oh-my-pi client.ts hand-rolls the same reader). */
|
|
12
|
+
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { extname, isAbsolute, join, resolve } from "node:path";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import type { Tool, ToolOutput } from "../core/types.ts";
|
|
17
|
+
|
|
18
|
+
// ---------- wire framing (LSP base protocol, hand-rolled Content-Length) ----------
|
|
19
|
+
|
|
20
|
+
export function encodeFrame(msg: unknown): Uint8Array {
|
|
21
|
+
const body = Buffer.from(JSON.stringify(msg), "utf8");
|
|
22
|
+
return Buffer.concat([Buffer.from(`Content-Length: ${body.byteLength}\r\n\r\n`, "latin1"), body]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Incremental Content-Length frame parser: push raw bytes, get decoded JSON messages. */
|
|
26
|
+
export class FrameParser {
|
|
27
|
+
private buf: Buffer = Buffer.alloc(0);
|
|
28
|
+
push(chunk: Uint8Array): unknown[] {
|
|
29
|
+
this.buf = Buffer.concat([this.buf, Buffer.from(chunk)]);
|
|
30
|
+
const out: unknown[] = [];
|
|
31
|
+
for (;;) {
|
|
32
|
+
const headerEnd = this.buf.indexOf("\r\n\r\n");
|
|
33
|
+
if (headerEnd < 0) return out;
|
|
34
|
+
const header = this.buf.subarray(0, headerEnd).toString("latin1");
|
|
35
|
+
const len = Number(/Content-Length:\s*(\d+)/i.exec(header)?.[1]);
|
|
36
|
+
const start = headerEnd + 4;
|
|
37
|
+
if (!Number.isFinite(len) || len < 0) { this.buf = this.buf.subarray(start); continue; } // malformed header: skip
|
|
38
|
+
if (this.buf.byteLength < start + len) return out; // body incomplete: wait for more bytes
|
|
39
|
+
const body = this.buf.subarray(start, start + len).toString("utf8");
|
|
40
|
+
this.buf = this.buf.subarray(start + len);
|
|
41
|
+
try { out.push(JSON.parse(body)); } catch { /* malformed body: skip frame */ }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------- protocol subset ----------
|
|
47
|
+
|
|
48
|
+
export interface DiagPosition { line: number; character: number }
|
|
49
|
+
export interface Diagnostic {
|
|
50
|
+
range: { start: DiagPosition; end: DiagPosition };
|
|
51
|
+
severity?: number; // 1=Error 2=Warning 3=Info 4=Hint
|
|
52
|
+
code?: number | string;
|
|
53
|
+
source?: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}
|
|
56
|
+
interface RpcMessage {
|
|
57
|
+
jsonrpc: "2.0";
|
|
58
|
+
id?: number;
|
|
59
|
+
method?: string;
|
|
60
|
+
params?: unknown;
|
|
61
|
+
result?: unknown;
|
|
62
|
+
error?: { code: number; message: string };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** opencode language.ts extension table, TS/JS slice (the only server we probe for). */
|
|
66
|
+
const TS_EXTENSIONS: Record<string, string> = {
|
|
67
|
+
".ts": "typescript", ".mts": "typescript", ".cts": "typescript", ".tsx": "typescriptreact",
|
|
68
|
+
".js": "javascript", ".mjs": "javascript", ".cjs": "javascript", ".jsx": "javascriptreact",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ---------- client ----------
|
|
72
|
+
|
|
73
|
+
export interface LspClientOptions {
|
|
74
|
+
cmd: string[]; // argv, e.g. ["typescript-language-server", "--stdio"]
|
|
75
|
+
root: string; // workspace root → rootUri
|
|
76
|
+
initTimeoutMs?: number; // hard cap on initialize; exceeded → kill + dead (default 8000)
|
|
77
|
+
settleMs?: number; // per-touch publishDiagnostics wait, clamped ≤2000 (default 1500)
|
|
78
|
+
debounceMs?: number; // follow-up publish grace, opencode's 150ms (client.ts:13)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type LspState = "idle" | "starting" | "ready" | "dead";
|
|
82
|
+
|
|
83
|
+
export class LspClient {
|
|
84
|
+
private readonly opts: Required<LspClientOptions>;
|
|
85
|
+
private proc: Bun.Subprocess<"pipe", "pipe", "ignore"> | null = null;
|
|
86
|
+
private parser = new FrameParser();
|
|
87
|
+
private nextId = 1;
|
|
88
|
+
private pending = new Map<number, (r: RpcMessage) => void>();
|
|
89
|
+
private versions = new Map<string, number>(); // uri → document version
|
|
90
|
+
private diags = new Map<string, Diagnostic[]>(); // uri → last published diagnostics
|
|
91
|
+
private gen = new Map<string, number>(); // uri → publish generation counter
|
|
92
|
+
private pubVer = new Map<string, number>(); // uri → version carried by the last publish (absent: none)
|
|
93
|
+
private waiters = new Map<string, Set<() => void>>();
|
|
94
|
+
private stateVal: LspState = "idle";
|
|
95
|
+
private initPromise: Promise<void> | null = null;
|
|
96
|
+
|
|
97
|
+
constructor(opts: LspClientOptions) {
|
|
98
|
+
this.opts = {
|
|
99
|
+
cmd: opts.cmd,
|
|
100
|
+
root: opts.root,
|
|
101
|
+
initTimeoutMs: opts.initTimeoutMs ?? 8000,
|
|
102
|
+
settleMs: Math.min(opts.settleMs ?? 1500, 2000),
|
|
103
|
+
debounceMs: opts.debounceMs ?? 150,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get state(): LspState { return this.stateVal; }
|
|
108
|
+
/** resolves when the child process exits (test hook for the kill path) */
|
|
109
|
+
get exited(): Promise<number> | null { return this.proc?.exited ?? null; }
|
|
110
|
+
|
|
111
|
+
/** didOpen (first touch) / didChange (later touches) for absPath, then wait ≤settleMs
|
|
112
|
+
* for fresh publishDiagnostics. Throws only before ready; a dead server yields []. */
|
|
113
|
+
async touch(absPath: string): Promise<Diagnostic[]> {
|
|
114
|
+
if (this.stateVal === "dead") return [];
|
|
115
|
+
this.initPromise ??= this.start().catch((e: unknown) => { this.becomeDead(); throw e; });
|
|
116
|
+
await this.initPromise;
|
|
117
|
+
if (this.stateVal !== "ready") return [];
|
|
118
|
+
const uri = pathToFileURL(absPath).href;
|
|
119
|
+
const text = readFileSync(absPath, "utf8");
|
|
120
|
+
const genBefore = this.gen.get(uri) ?? 0;
|
|
121
|
+
const prev = this.versions.get(uri);
|
|
122
|
+
const sentVer = prev === undefined ? 0 : prev + 1; // the version THIS edit is published under
|
|
123
|
+
this.versions.set(uri, sentVer);
|
|
124
|
+
if (prev === undefined) {
|
|
125
|
+
// opencode client.ts:611-619 — didOpen {uri, languageId, version: 0, text}
|
|
126
|
+
const languageId = TS_EXTENSIONS[extname(absPath).toLowerCase()] ?? "plaintext";
|
|
127
|
+
this.notify("textDocument/didOpen", { textDocument: { uri, languageId, version: sentVer, text } });
|
|
128
|
+
} else {
|
|
129
|
+
// opencode client.ts:577-597 — didChange version+1, full-text contentChanges
|
|
130
|
+
this.notify("textDocument/didChange", { textDocument: { uri, version: sentVer }, contentChanges: [{ text }] });
|
|
131
|
+
}
|
|
132
|
+
const deadline = Date.now() + this.opts.settleMs;
|
|
133
|
+
if (!(await this.waitPublish(uri, genBefore, deadline, sentVer))) return [];
|
|
134
|
+
// rearming debounce: absorb follow-up publishes, capped by the settle deadline
|
|
135
|
+
// (opencode waitForFreshPush, client.ts:464-497)
|
|
136
|
+
let g = this.gen.get(uri) ?? 0;
|
|
137
|
+
while (Date.now() + this.opts.debounceMs <= deadline) {
|
|
138
|
+
if (!(await this.waitPublish(uri, g, Math.min(deadline, Date.now() + this.opts.debounceMs), sentVer))) break;
|
|
139
|
+
g = this.gen.get(uri) ?? 0;
|
|
140
|
+
}
|
|
141
|
+
return this.diags.get(uri) ?? [];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
kill(): void { this.becomeDead(); }
|
|
145
|
+
|
|
146
|
+
private async start(): Promise<void> {
|
|
147
|
+
this.stateVal = "starting";
|
|
148
|
+
this.proc = Bun.spawn(this.opts.cmd, { cwd: this.opts.root, stdin: "pipe", stdout: "pipe", stderr: "ignore" });
|
|
149
|
+
// unref: a live server must never keep the host process alive. Paired with the
|
|
150
|
+
// mandatory ref-after-kill in becomeDead() — see the comment there before touching this.
|
|
151
|
+
this.proc.unref();
|
|
152
|
+
void this.pump();
|
|
153
|
+
void this.proc.exited.then(() => this.becomeDead());
|
|
154
|
+
// opencode client.ts:211-255 — rootUri/processId/capabilities; :260 initialized
|
|
155
|
+
const r = await this.request("initialize", {
|
|
156
|
+
processId: process.pid,
|
|
157
|
+
rootUri: pathToFileURL(this.opts.root).href,
|
|
158
|
+
capabilities: {
|
|
159
|
+
textDocument: { synchronization: { didOpen: true, didChange: true }, publishDiagnostics: { versionSupport: false } },
|
|
160
|
+
},
|
|
161
|
+
workspaceFolders: null,
|
|
162
|
+
}, this.opts.initTimeoutMs);
|
|
163
|
+
if (r.error) throw new Error(`lsp initialize failed: ${r.error.message}`);
|
|
164
|
+
this.notify("initialized", {});
|
|
165
|
+
this.stateVal = "ready";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async pump(): Promise<void> {
|
|
169
|
+
const proc = this.proc;
|
|
170
|
+
if (!proc) return;
|
|
171
|
+
try {
|
|
172
|
+
for await (const chunk of proc.stdout) {
|
|
173
|
+
// per-message guard: one malformed frame must never abort the reader loop — an
|
|
174
|
+
// unguarded throw here silently discarded ALL later server output while "ready"
|
|
175
|
+
for (const msg of this.parser.push(chunk)) {
|
|
176
|
+
try { this.dispatch(msg); } catch { /* skip poisoned frame, keep reading */ }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch { /* stream torn down with the process */ }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private dispatch(raw: unknown): void {
|
|
183
|
+
if (!raw || typeof raw !== "object") return; // `null`/scalar bodies are valid JSON but not messages
|
|
184
|
+
const msg = raw as RpcMessage;
|
|
185
|
+
if (typeof msg.id === "number" && msg.method === undefined) {
|
|
186
|
+
const cb = this.pending.get(msg.id);
|
|
187
|
+
if (cb) { this.pending.delete(msg.id); cb(msg); }
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (msg.method === "textDocument/publishDiagnostics") {
|
|
191
|
+
// opencode client.ts:160-172 — cache per uri (+ published version, :165), signal listeners
|
|
192
|
+
const p = msg.params as { uri?: unknown; version?: unknown; diagnostics?: unknown } | null;
|
|
193
|
+
if (!p || typeof p !== "object" || typeof p.uri !== "string") return; // shape guard
|
|
194
|
+
this.diags.set(p.uri, Array.isArray(p.diagnostics) ? (p.diagnostics as Diagnostic[]) : []);
|
|
195
|
+
if (typeof p.version === "number") this.pubVer.set(p.uri, p.version);
|
|
196
|
+
else this.pubVer.delete(p.uri);
|
|
197
|
+
this.gen.set(p.uri, (this.gen.get(p.uri) ?? 0) + 1);
|
|
198
|
+
for (const w of [...(this.waiters.get(p.uri) ?? [])]) w();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// server→client request (e.g. workspace/configuration): answer null so the server never stalls
|
|
202
|
+
if (typeof msg.id === "number") this.send({ jsonrpc: "2.0", id: msg.id, result: null });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private request(method: string, params: unknown, timeoutMs: number): Promise<RpcMessage> {
|
|
206
|
+
const id = this.nextId++;
|
|
207
|
+
this.send({ jsonrpc: "2.0", id, method, params });
|
|
208
|
+
return new Promise<RpcMessage>((resolve, reject) => {
|
|
209
|
+
const t = setTimeout(() => {
|
|
210
|
+
this.pending.delete(id);
|
|
211
|
+
reject(new Error(`lsp request ${method} timed out after ${timeoutMs}ms`));
|
|
212
|
+
}, timeoutMs);
|
|
213
|
+
this.pending.set(id, (r) => { clearTimeout(t); resolve(r); });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private notify(method: string, params: unknown): void {
|
|
218
|
+
this.send({ jsonrpc: "2.0", method, params });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private send(msg: unknown): void {
|
|
222
|
+
const stdin = this.proc?.stdin;
|
|
223
|
+
if (!stdin || this.stateVal === "dead") return;
|
|
224
|
+
try { stdin.write(encodeFrame(msg)); void stdin.flush(); } catch { this.becomeDead(); }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** resolves true once a publish newer than genAfter AND belonging to sentVer lands for uri;
|
|
228
|
+
* a publish carrying another version is a different edit's (laggy servers re-publish the
|
|
229
|
+
* previous version — opencode client.ts:483-485 rejects those; versionless always matches).
|
|
230
|
+
* Resolves false at deadline/death. */
|
|
231
|
+
private waitPublish(uri: string, genAfter: number, deadlineTs: number, sentVer: number): Promise<boolean> {
|
|
232
|
+
const fresh = (): boolean => {
|
|
233
|
+
if ((this.gen.get(uri) ?? 0) <= genAfter) return false;
|
|
234
|
+
const pv = this.pubVer.get(uri);
|
|
235
|
+
return pv === undefined || pv === sentVer;
|
|
236
|
+
};
|
|
237
|
+
if (fresh()) return Promise.resolve(true);
|
|
238
|
+
if (this.stateVal === "dead" || deadlineTs <= Date.now()) return Promise.resolve(false);
|
|
239
|
+
return new Promise((resolve) => {
|
|
240
|
+
const set = this.waiters.get(uri) ?? new Set<() => void>();
|
|
241
|
+
this.waiters.set(uri, set);
|
|
242
|
+
const done = (): void => { clearTimeout(t); set.delete(cb); resolve(fresh()); };
|
|
243
|
+
const cb = (): void => { if (fresh() || this.stateVal === "dead") done(); };
|
|
244
|
+
const t = setTimeout(done, deadlineTs - Date.now());
|
|
245
|
+
set.add(cb);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** wedged/broken server: mark dead (never retried, opencode lsp.ts:224-241), kill, release waiters */
|
|
250
|
+
private becomeDead(): void {
|
|
251
|
+
if (this.stateVal === "dead") return;
|
|
252
|
+
this.stateVal = "dead";
|
|
253
|
+
for (const [id, cb] of [...this.pending]) {
|
|
254
|
+
this.pending.delete(id);
|
|
255
|
+
cb({ jsonrpc: "2.0", id, error: { code: -1, message: "lsp server dead" } });
|
|
256
|
+
}
|
|
257
|
+
for (const set of this.waiters.values()) for (const w of [...set]) w();
|
|
258
|
+
try { this.proc?.kill(); } catch { /* already gone */ }
|
|
259
|
+
// ref-after-kill (Bun 1.3/Windows): an unref'd subprocess's exit is only observed while
|
|
260
|
+
// other ref'd work keeps the event loop turning; on an idle loop `exited` never settles,
|
|
261
|
+
// which froze the entire `bun test` run. Re-ref once dying so exit is always delivered.
|
|
262
|
+
try { this.proc?.ref(); } catch { /* already gone */ }
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ---------- gate note formatting (opencode diagnostic.ts:5-27 + tool/edit.ts:197-201) ----------
|
|
267
|
+
|
|
268
|
+
const MAX_PER_FILE = 20; // opencode diagnostic.ts MAX_PER_FILE
|
|
269
|
+
|
|
270
|
+
export function formatGateNote(absPath: string, diags: Diagnostic[], server = "typescript-language-server"): string {
|
|
271
|
+
const errors = diags.filter((d) => d.severity === 1); // errors only — warnings/hints never reach the model
|
|
272
|
+
if (errors.length === 0) return "";
|
|
273
|
+
const shown = errors
|
|
274
|
+
.slice(0, MAX_PER_FILE)
|
|
275
|
+
.map((d) => `ERROR [${d.range.start.line + 1}:${d.range.start.character + 1}] ${d.message}`); // 1-based
|
|
276
|
+
const suffix = errors.length > MAX_PER_FILE ? `\n... and ${errors.length - MAX_PER_FILE} more` : "";
|
|
277
|
+
return `\n\nlsp-gate (${server}): ${errors.length} error(s) in ${absPath} — fix before proceeding:\n${shown.join("\n")}${suffix}`;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ---------- gate: discovery + bounded note ----------
|
|
281
|
+
|
|
282
|
+
export interface GateOptions {
|
|
283
|
+
root?: string; // workspace root (default process.cwd())
|
|
284
|
+
serverName?: string; // PATH probe target (default "typescript-language-server")
|
|
285
|
+
cmd?: string[]; // explicit server argv — bypasses the probe (tests)
|
|
286
|
+
settleMs?: number; // diagnostics settle window, clamped ≤2000
|
|
287
|
+
hardDeadlineMs?: number; // absolute cap per note() call, clamped ≤2000 (default 2000)
|
|
288
|
+
initTimeoutMs?: number; // background initialize cap before kill (default 8000)
|
|
289
|
+
debounceMs?: number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface LspGate {
|
|
293
|
+
/** "" when feature off / no errors / timed out; otherwise "\n\nlsp-gate ..." */
|
|
294
|
+
note(absPath: string): Promise<string>;
|
|
295
|
+
dispose(): void;
|
|
296
|
+
readonly client: LspClient | null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** One startup line when the gate CANNOT run here, or null when there is nothing to say.
|
|
300
|
+
*
|
|
301
|
+
* The gate is silent by design when the server is missing (the note below is "" and the edit succeeds as
|
|
302
|
+
* it should) — and that silence let everyone credit a diagnostics loop that was not running: on the
|
|
303
|
+
* machine this was written on, typescript-language-server was not on PATH and no edit had ever been
|
|
304
|
+
* type-checked. Silence is right for the TOOL RESULT (the model has nothing to act on); it is wrong for
|
|
305
|
+
* the person, who was promised the loop. So the absence is said once, at boot, next to the other "this is
|
|
306
|
+
* off" notes. Only for a TypeScript project (a tsconfig.json at the root): elsewhere nothing was promised. */
|
|
307
|
+
export function lspAvailabilityNote(root: string, which: (name: string) => string | null = (n) => Bun.which(n), serverName = "typescript-language-server"): string | null {
|
|
308
|
+
if (!existsSync(join(root, "tsconfig.json"))) return null;
|
|
309
|
+
if (which(serverName) !== null) return null;
|
|
310
|
+
return `lsp: ${serverName} is not on PATH — edits and writes are NOT type-checked, and the model gets no diagnostics after them (npm i -g typescript-language-server typescript)`;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** PATH probe (opencode server.ts:139 — Npm.which then spawn with --stdio). */
|
|
314
|
+
function probe(serverName: string): string[] | null {
|
|
315
|
+
const bin = Bun.which(serverName);
|
|
316
|
+
return bin ? [bin, "--stdio"] : null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function createLspGate(opts: GateOptions = {}): LspGate {
|
|
320
|
+
const root = opts.root ?? process.cwd();
|
|
321
|
+
const serverName = opts.serverName ?? "typescript-language-server";
|
|
322
|
+
const hard = Math.min(opts.hardDeadlineMs ?? 2000, 2000);
|
|
323
|
+
let client: LspClient | null | undefined; // undefined = not probed yet, null = feature off
|
|
324
|
+
return {
|
|
325
|
+
get client(): LspClient | null { return client ?? null; },
|
|
326
|
+
async note(absPath: string): Promise<string> {
|
|
327
|
+
if (!(extname(absPath).toLowerCase() in TS_EXTENSIONS)) return "";
|
|
328
|
+
if (client === undefined) {
|
|
329
|
+
const cmd = opts.cmd ?? probe(serverName);
|
|
330
|
+
client = cmd === null ? null : new LspClient({
|
|
331
|
+
cmd, root,
|
|
332
|
+
...(opts.settleMs !== undefined ? { settleMs: opts.settleMs } : {}),
|
|
333
|
+
...(opts.initTimeoutMs !== undefined ? { initTimeoutMs: opts.initTimeoutMs } : {}),
|
|
334
|
+
...(opts.debounceMs !== undefined ? { debounceMs: opts.debounceMs } : {}),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
if (client === null || client.state === "dead") return ""; // absent/broken → silently off
|
|
338
|
+
// hard deadline: a cold or wedged server can never block the loop; the swallowed touch
|
|
339
|
+
// continues (or gets killed by initTimeout) in the background (opencode lsp.ts:360).
|
|
340
|
+
// The deadline timer is cleared when touch settles first — a stray ref'd timer would
|
|
341
|
+
// hold the host's event loop open for up to 2s after every edit.
|
|
342
|
+
const c = client;
|
|
343
|
+
const diags = await new Promise<Diagnostic[] | null>((resolve) => {
|
|
344
|
+
const t = setTimeout(() => resolve(null), hard);
|
|
345
|
+
c.touch(absPath).then(
|
|
346
|
+
(d) => { clearTimeout(t); resolve(d); },
|
|
347
|
+
() => { clearTimeout(t); resolve(null); },
|
|
348
|
+
);
|
|
349
|
+
});
|
|
350
|
+
return diags === null ? "" : formatGateNote(absPath, diags, serverName);
|
|
351
|
+
},
|
|
352
|
+
dispose(): void { if (client) client.kill(); },
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// ---------- default gates (one per root) + tool wiring ----------
|
|
357
|
+
|
|
358
|
+
/** acp/http build per-session runtimes with per-caller cwds, so a single module-level gate
|
|
359
|
+
* bound the FIRST caller's root for the process lifetime and later sessions diagnosed
|
|
360
|
+
* against the wrong project (wrong tsconfig/paths). Keyed by resolved root; bounded LRU,
|
|
361
|
+
* since every live entry owns a server process. */
|
|
362
|
+
const MAX_DEFAULT_GATES = 4;
|
|
363
|
+
const defaultGates = new Map<string, LspGate>(); // insertion order doubles as LRU order
|
|
364
|
+
|
|
365
|
+
/** Post-edit hook for hashline's lint-gate point: await and append to successful tool output.
|
|
366
|
+
* `opts` (test hook) applies only when the root's gate is first constructed. */
|
|
367
|
+
export function lspGateNote(absPath: string, root?: string, opts?: Omit<GateOptions, "root">): Promise<string> {
|
|
368
|
+
const key = resolve(root ?? process.cwd());
|
|
369
|
+
let gate = defaultGates.get(key);
|
|
370
|
+
if (gate !== undefined) {
|
|
371
|
+
defaultGates.delete(key); // refresh LRU position
|
|
372
|
+
} else {
|
|
373
|
+
gate = createLspGate({ ...opts, root: key });
|
|
374
|
+
if (defaultGates.size >= MAX_DEFAULT_GATES) {
|
|
375
|
+
for (const [k, g] of defaultGates) { defaultGates.delete(k); g.dispose(); break; } // evict oldest
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
defaultGates.set(key, gate);
|
|
379
|
+
return gate.note(absPath);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** dispose every default gate and forget it (test hook); returns them so exits can be awaited */
|
|
383
|
+
export function disposeDefaultGates(): LspGate[] {
|
|
384
|
+
const gates = [...defaultGates.values()];
|
|
385
|
+
defaultGates.clear();
|
|
386
|
+
for (const g of gates) g.dispose();
|
|
387
|
+
return gates;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** Zero-touch alternative: wrap a write-kind tool (hashline editTool/writeTool) so every
|
|
391
|
+
* successful execution gets the diagnostics gate note appended to its output. */
|
|
392
|
+
export function withLspGate(tool: Tool, gate: (absPath: string) => Promise<string> = lspGateNote): Tool {
|
|
393
|
+
if (tool.kind !== "write") return tool;
|
|
394
|
+
return {
|
|
395
|
+
...tool,
|
|
396
|
+
async execute(args: unknown, ctx): Promise<ToolOutput> {
|
|
397
|
+
const out = await tool.execute(args, ctx);
|
|
398
|
+
const rel = (args as { path?: unknown }).path;
|
|
399
|
+
if (!out.ok || typeof rel !== "string") return out;
|
|
400
|
+
const abs = isAbsolute(rel) ? rel : join(ctx.cwd, rel);
|
|
401
|
+
if (!existsSync(abs)) return out;
|
|
402
|
+
const note = await gate(abs);
|
|
403
|
+
return note === "" ? out : { ...out, output: out.output + note };
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Persistent per-file tags cache (PORT #12, round-2 F1): aider persists its
|
|
2
|
+
* tags cache to disk via diskcache (.aider.tags.cache.v4, repomap.py
|
|
3
|
+
* L217-222) so extraction "only happens once" ACROSS launches, not per
|
|
4
|
+
* process. JSON equivalent under <root>/.rovecode/cache/repomap.json, keyed by
|
|
5
|
+
* absolute path. mtime+size mismatch, a missing file, or corrupt JSON simply
|
|
6
|
+
* miss (aider recreates the cache on SQLITE errors, L241-264). Strictly
|
|
7
|
+
* advisory: every failure path degrades to re-extraction, never to a crash.
|
|
8
|
+
*
|
|
9
|
+
* On-disk shape (version 2): each entry carries its two path strings ONCE and its
|
|
10
|
+
* tags as [line, name, kind] tuples. Version 1 stored every Tag whole — the relative
|
|
11
|
+
* and the absolute path repeated on each of ~75k tags — and this repository's cache
|
|
12
|
+
* was 13.3 MB, 78 ms to read and parse on every session's first prompt, +44 MB of
|
|
13
|
+
* resident memory once parsed (measured 2026-09-06, scripts/probe-turn.ts). A file of
|
|
14
|
+
* another version is treated as absent: the map re-extracts and the save overwrites
|
|
15
|
+
* it in the current shape. */
|
|
16
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import type { Tag } from "./repomap.ts";
|
|
19
|
+
|
|
20
|
+
interface CacheEntry { mtimeMs: number; size: number; tags: Tag[] }
|
|
21
|
+
/** the v2 line: [line, name, kind] with kind 0 = def, 1 = ref */
|
|
22
|
+
type TagTuple = [number, string, 0 | 1];
|
|
23
|
+
interface DiskEntry { m: number; s: number; rel: string; abs: string; t: TagTuple[] }
|
|
24
|
+
interface DiskFile { version: number; entries: Record<string, DiskEntry> }
|
|
25
|
+
|
|
26
|
+
/** bump to invalidate wholesale on tag-shape/extraction changes (aider's .v4 suffix) */
|
|
27
|
+
export const CACHE_VERSION = 2;
|
|
28
|
+
|
|
29
|
+
const toDisk = (e: CacheEntry): DiskEntry | null => {
|
|
30
|
+
const first = e.tags[0];
|
|
31
|
+
// a file with no tags has no path strings to carry; store it with the entry key's paths unknown →
|
|
32
|
+
// keep both empty, the reader falls back to the key for the absolute path
|
|
33
|
+
return {
|
|
34
|
+
m: e.mtimeMs, s: e.size,
|
|
35
|
+
rel: first?.relFname ?? "", abs: first?.fname ?? "",
|
|
36
|
+
t: e.tags.map((t) => [t.line, t.name, t.kind === "def" ? 0 : 1] as TagTuple),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const fromDisk = (fname: string, d: DiskEntry): CacheEntry | null => {
|
|
41
|
+
if (typeof d?.m !== "number" || typeof d?.s !== "number" || !Array.isArray(d?.t)) return null;
|
|
42
|
+
const relFname = typeof d.rel === "string" ? d.rel : "";
|
|
43
|
+
const abs = typeof d.abs === "string" && d.abs.length > 0 ? d.abs : fname;
|
|
44
|
+
const tags: Tag[] = [];
|
|
45
|
+
for (const tu of d.t) {
|
|
46
|
+
if (!Array.isArray(tu) || typeof tu[0] !== "number" || typeof tu[1] !== "string" || (tu[2] !== 0 && tu[2] !== 1)) return null; // a torn entry misses whole
|
|
47
|
+
tags.push({ relFname, fname: abs, line: tu[0], name: tu[1], kind: tu[2] === 0 ? "def" : "ref" });
|
|
48
|
+
}
|
|
49
|
+
return { mtimeMs: d.m, size: d.s, tags };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export class TagsDiskCache {
|
|
53
|
+
readonly path: string;
|
|
54
|
+
private entries = new Map<string, CacheEntry>();
|
|
55
|
+
private dirty = false;
|
|
56
|
+
|
|
57
|
+
constructor(root: string) {
|
|
58
|
+
this.path = join(root, ".rovecode", "cache", "repomap.json");
|
|
59
|
+
try {
|
|
60
|
+
const raw = JSON.parse(readFileSync(this.path, "utf8")) as Partial<DiskFile> | null;
|
|
61
|
+
if (raw?.version === CACHE_VERSION && raw.entries && typeof raw.entries === "object") {
|
|
62
|
+
for (const [fname, d] of Object.entries(raw.entries)) {
|
|
63
|
+
const e = fromDisk(fname, d);
|
|
64
|
+
if (e) this.entries.set(fname, e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// any other version (older, newer, missing): cold — the next save writes this version
|
|
68
|
+
} catch { /* absent or corrupt -> cold cache */ }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** hit only when BOTH mtimeMs and size match the live stat */
|
|
72
|
+
get(fname: string, mtimeMs: number, size: number): Tag[] | undefined {
|
|
73
|
+
const e = this.entries.get(fname);
|
|
74
|
+
return e && e.mtimeMs === mtimeMs && e.size === size ? e.tags : undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
set(fname: string, mtimeMs: number, size: number, tags: Tag[]): void {
|
|
78
|
+
this.entries.set(fname, { mtimeMs, size, tags });
|
|
79
|
+
this.dirty = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Write-if-dirty: a fully-warm run rewrites nothing. Atomic-ish tmp+rename
|
|
83
|
+
* (pid-suffixed) so a crash or a racing process never leaves torn JSON. */
|
|
84
|
+
save(): void {
|
|
85
|
+
if (!this.dirty) return;
|
|
86
|
+
const tmp = `${this.path}.${process.pid}.tmp`;
|
|
87
|
+
try {
|
|
88
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
89
|
+
const entries: Record<string, DiskEntry> = {};
|
|
90
|
+
for (const [fname, e] of this.entries) { const d = toDisk(e); if (d) entries[fname] = d; }
|
|
91
|
+
const file: DiskFile = { version: CACHE_VERSION, entries };
|
|
92
|
+
writeFileSync(tmp, JSON.stringify(file));
|
|
93
|
+
renameSync(tmp, this.path);
|
|
94
|
+
this.dirty = false;
|
|
95
|
+
} catch {
|
|
96
|
+
try { rmSync(tmp, { force: true }); } catch { /* best effort */ }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Repo-map source enumeration (PORT #12). aider maps git-tracked files only
|
|
2
|
+
* (find_src_files feeds repo.get_tracked_files output, repomap.py L787-795);
|
|
3
|
+
* we prefer `git ls-files` — tracked + untracked-unignored, so .gitignore is
|
|
4
|
+
* honored and enumeration is O(index), not O(walk) — and fall back to a
|
|
5
|
+
* BOUNDED directory walk for non-repos: at most MAX_SRC_FILES files, files
|
|
6
|
+
* over MAX_SRC_BYTES skipped (a 1.5MB minified bundle costs seconds of parse
|
|
7
|
+
* for a handful of map tokens). Both paths stay deterministic. */
|
|
8
|
+
|
|
9
|
+
import { readdirSync, statSync } from "node:fs";
|
|
10
|
+
import { join, extname } from "node:path";
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { Lang } from "@ast-grep/napi";
|
|
13
|
+
|
|
14
|
+
/** extensions extractTags can parse; also gates enumeration + special-file filtering */
|
|
15
|
+
export const LANG_BY_EXT: Record<string, Lang> = {
|
|
16
|
+
".ts": Lang.TypeScript, ".mts": Lang.TypeScript, ".cts": Lang.TypeScript,
|
|
17
|
+
".tsx": Lang.Tsx,
|
|
18
|
+
".js": Lang.JavaScript, ".mjs": Lang.JavaScript, ".cjs": Lang.JavaScript, ".jsx": Lang.JavaScript,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", ".rovecode", "dist", "build", "out", "coverage", ".cache"]);
|
|
22
|
+
/** hard bounds (round-2 F2): enumeration/parse cost is O(cap), not O(repo) */
|
|
23
|
+
export const MAX_SRC_FILES = 2000;
|
|
24
|
+
export const MAX_SRC_BYTES = 256 * 1024;
|
|
25
|
+
|
|
26
|
+
export interface SrcScanStats {
|
|
27
|
+
/** true when the MAX_SRC_FILES cap dropped candidates */
|
|
28
|
+
capped: boolean;
|
|
29
|
+
/** enumerated via `git ls-files` (gitignore honored) instead of the walk */
|
|
30
|
+
viaGit: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `git ls-files -z --cached --others --exclude-standard` under rootDir:
|
|
34
|
+
* tracked + untracked-but-not-ignored, NUL-separated, forward slashes.
|
|
35
|
+
* Bounded timeout; ANY failure (no git binary, not a repo, timeout, output
|
|
36
|
+
* overflow) returns null and the caller walks instead.
|
|
37
|
+
* Exported for the port #22 glob/grep tools (files.ts) — same gitignore seam. */
|
|
38
|
+
export function gitListFiles(rootDir: string): string[] | null {
|
|
39
|
+
try {
|
|
40
|
+
const res = spawnSync("git", ["-C", rootDir, "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
41
|
+
{ timeout: 5000, maxBuffer: 64 * 1024 * 1024, encoding: "utf8", windowsHide: true });
|
|
42
|
+
if (res.error || res.status !== 0 || typeof res.stdout !== "string") return null;
|
|
43
|
+
return res.stdout.split("\0").filter((p) => p.length > 0);
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** keep = regular file within the size bound (stat failure = tracked-but-deleted etc.) */
|
|
50
|
+
function keepFile(full: string): boolean {
|
|
51
|
+
try {
|
|
52
|
+
const st = statSync(full);
|
|
53
|
+
return st.isFile() && st.size <= MAX_SRC_BYTES;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Source files under root, capped and size-bounded. Git path: sorted
|
|
60
|
+
* candidates, first `maxFiles` valid ones. Walk path: per-dir sorted DFS
|
|
61
|
+
* (deterministic) that STOPS as soon as the cap is exceeded, skipping
|
|
62
|
+
* SKIP_DIRS and dot-dirs like before. `stats` reports capping + which path
|
|
63
|
+
* ran; `maxFiles` is overridable for tests only. */
|
|
64
|
+
export function findSrcFiles(rootDir: string, stats?: SrcScanStats, maxFiles = MAX_SRC_FILES): string[] {
|
|
65
|
+
const out: string[] = [];
|
|
66
|
+
const fromGit = gitListFiles(rootDir);
|
|
67
|
+
if (fromGit) {
|
|
68
|
+
if (stats) stats.viaGit = true;
|
|
69
|
+
const candidates = fromGit
|
|
70
|
+
.filter((p) => LANG_BY_EXT[extname(p).toLowerCase()] !== undefined)
|
|
71
|
+
// mirror the walk's dir rules on path segments (vendored node_modules, dot-dirs)
|
|
72
|
+
.filter((p) => !p.split("/").slice(0, -1).some((seg) => SKIP_DIRS.has(seg) || seg.startsWith(".")))
|
|
73
|
+
.sort();
|
|
74
|
+
for (const p of candidates) {
|
|
75
|
+
if (out.length > maxFiles) break; // one extra collected to detect capping
|
|
76
|
+
const full = join(rootDir, p);
|
|
77
|
+
if (keepFile(full)) out.push(full);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const walk = (dir: string) => {
|
|
81
|
+
let names: string[];
|
|
82
|
+
try {
|
|
83
|
+
names = readdirSync(dir);
|
|
84
|
+
} catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const name of names.sort()) {
|
|
88
|
+
if (out.length > maxFiles) return; // cap exceeded — unwind the whole DFS
|
|
89
|
+
const full = join(dir, name);
|
|
90
|
+
let st;
|
|
91
|
+
try {
|
|
92
|
+
st = statSync(full);
|
|
93
|
+
} catch {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (st.isDirectory()) {
|
|
97
|
+
if (!SKIP_DIRS.has(name) && !name.startsWith(".")) walk(full);
|
|
98
|
+
} else if (LANG_BY_EXT[extname(name).toLowerCase()] !== undefined && st.size <= MAX_SRC_BYTES) {
|
|
99
|
+
out.push(full);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
walk(rootDir);
|
|
104
|
+
}
|
|
105
|
+
if (out.length > maxFiles) {
|
|
106
|
+
if (stats) stats.capped = true;
|
|
107
|
+
out.pop();
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|