@herbertgao/pi-extensions 2026.8.5 → 2026.8.7
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 +5 -5
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +19 -7
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +30 -9
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +272 -22
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +74 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +94 -77
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +48 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/message-display.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/hover.ts +14 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +55 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/layout.ts +41 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-renderer.ts +75 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/types.ts +7 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +64 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +3 -3
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +16 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +30 -22
- package/node_modules/@herbertgao/pi-subagents/examples/agent-tool-description.md +5 -5
- package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +7 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +48 -19
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +22 -15
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +26 -2
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +219 -40
- package/node_modules/@herbertgao/pi-subagents/src/invocation-config.ts +101 -3
- package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +18 -4
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +99 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +22 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +51 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +20 -2
- package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +34 -10
- package/node_modules/@herbertgao/pi-subagents/src/usage.ts +129 -1
- package/node_modules/@herbertgao/pi-subagents/src/worktree.ts +29 -5
- package/node_modules/@juicesharp/rpiv-ask-user-question/README.md +3 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +46 -10
- package/node_modules/@juicesharp/rpiv-ask-user-question/config.ts +25 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/configuration.md +13 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/hosts.md +8 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/localization.md +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/en.json +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/zh.json +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +3 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +10 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +30 -7
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +14 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +30 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +26 -5
- package/node_modules/@narumitw/pi-btw/README.md +119 -103
- package/node_modules/@narumitw/pi-btw/dist/index.ts +2898 -0
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +7 -0
- package/node_modules/@narumitw/pi-btw/package.json +13 -9
- package/node_modules/@narumitw/pi-btw/src/btw.ts +40 -42
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +55 -10
- package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +390 -0
- package/node_modules/@narumitw/pi-btw/src/menu.ts +78 -15
- package/node_modules/@narumitw/pi-btw/src/settings.ts +22 -2
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +136 -45
- package/node_modules/pi-lens/CHANGELOG.md +1004 -0
- package/node_modules/pi-lens/README.md +11 -3
- package/node_modules/pi-lens/config/ruff/core.toml +42 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings.js +130 -27
- package/node_modules/pi-lens/dist/clients/advisory-provenance.js +427 -0
- package/node_modules/pi-lens/dist/clients/agent-nudge.js +79 -16
- package/node_modules/pi-lens/dist/clients/ast-grep-client.js +9 -3
- package/node_modules/pi-lens/dist/clients/atomic-write.js +9 -3
- package/node_modules/pi-lens/dist/clients/bash-file-access.js +285 -8
- package/node_modules/pi-lens/dist/clients/biome-client.js +176 -37
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +428 -0
- package/node_modules/pi-lens/dist/clients/blocker-past-eof.js +119 -0
- package/node_modules/pi-lens/dist/clients/bootstrap.js +12 -1
- package/node_modules/pi-lens/dist/clients/bounded-pid-file-lock.js +12 -3
- package/node_modules/pi-lens/dist/clients/bounded-telemetry.js +192 -0
- package/node_modules/pi-lens/dist/clients/bus-events-logger.js +62 -6
- package/node_modules/pi-lens/dist/clients/bus-publish.js +11 -3
- package/node_modules/pi-lens/dist/clients/cascade-budget.js +196 -0
- package/node_modules/pi-lens/dist/clients/cascade-format.js +76 -2
- package/node_modules/pi-lens/dist/clients/cascade-types.js +9 -1
- package/node_modules/pi-lens/dist/clients/child-unref.js +54 -6
- package/node_modules/pi-lens/dist/clients/code-quality-warnings.js +76 -24
- package/node_modules/pi-lens/dist/clients/console-guard-install.js +16 -4
- package/node_modules/pi-lens/dist/clients/dead-code-client.js +249 -52
- package/node_modules/pi-lens/dist/clients/deadline-utils.js +8 -1
- package/node_modules/pi-lens/dist/clients/debug-handles.js +5 -0
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +62 -13
- package/node_modules/pi-lens/dist/clients/dependency-checker.js +43 -9
- package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +153 -37
- package/node_modules/pi-lens/dist/clients/diagnostic-line-freshness.js +298 -0
- package/node_modules/pi-lens/dist/clients/diagnostics-publish.js +10 -3
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +165 -11
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +325 -72
- package/node_modules/pi-lens/dist/clients/dispatch/lazy.js +7 -4
- package/node_modules/pi-lens/dist/clients/dispatch/plan.js +5 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +234 -18
- package/node_modules/pi-lens/dist/clients/dispatch/runners/biome-check.js +187 -19
- package/node_modules/pi-lens/dist/clients/dispatch/runners/cpp-check.js +6 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/credo.js +11 -9
- package/node_modules/pi-lens/dist/clients/dispatch/runners/cue-vet.js +398 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/elixir-check.js +11 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/eslint.js +12 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/go-vet.js +18 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +895 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/index.js +4 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/javac.js +16 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/lsp.js +81 -41
- package/node_modules/pi-lens/dist/clients/dispatch/runners/markdownlint.js +16 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/mypy.js +23 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +331 -55
- package/node_modules/pi-lens/dist/clients/dispatch/runners/pyright.js +38 -5
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +97 -19
- package/node_modules/pi-lens/dist/clients/dispatch/runners/spellcheck.js +14 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/sqlfluff.js +20 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/stylelint.js +22 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/swiftlint.js +10 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/taplo.js +18 -6
- package/node_modules/pi-lens/dist/clients/dispatch/runners/trivy-config.js +73 -12
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/availability-policy.js +488 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +84 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/lazy-installer.js +260 -27
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +943 -93
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +86 -11
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/tool-failure.js +72 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +106 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/vale.js +9 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yamllint.js +18 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/zig-check.js +4 -2
- package/node_modules/pi-lens/dist/clients/disposition-publish.js +10 -3
- package/node_modules/pi-lens/dist/clients/eval-timestamp.js +17 -0
- package/node_modules/pi-lens/dist/clients/event-loop-monitor.js +28 -5
- package/node_modules/pi-lens/dist/clients/extension-log.js +317 -3
- package/node_modules/pi-lens/dist/clients/file-kinds.js +8 -2
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +294 -0
- package/node_modules/pi-lens/dist/clients/finding-identity.js +88 -0
- package/node_modules/pi-lens/dist/clients/fix-worklog.js +5 -1
- package/node_modules/pi-lens/dist/clients/format-events-publish.js +39 -8
- package/node_modules/pi-lens/dist/clients/formatters-lazy.js +3 -2
- package/node_modules/pi-lens/dist/clients/formatters.js +500 -115
- package/node_modules/pi-lens/dist/clients/generation-guard.js +216 -0
- package/node_modules/pi-lens/dist/clients/git-guard.js +49 -21
- package/node_modules/pi-lens/dist/clients/gitleaks-client.js +181 -8
- package/node_modules/pi-lens/dist/clients/go-client.js +21 -39
- package/node_modules/pi-lens/dist/clients/govulncheck-client.js +219 -10
- package/node_modules/pi-lens/dist/clients/grammar-source.js +333 -10
- package/node_modules/pi-lens/dist/clients/host-ports.js +9 -1
- package/node_modules/pi-lens/dist/clients/installer/index.js +1119 -101
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh-session.js +58 -0
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh.js +715 -0
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +643 -97
- package/node_modules/pi-lens/dist/clients/instance-registry.js +87 -17
- package/node_modules/pi-lens/dist/clients/jscpd-client.js +86 -15
- package/node_modules/pi-lens/dist/clients/knip-client.js +361 -24
- package/node_modules/pi-lens/dist/clients/language-policy.js +8 -2
- package/node_modules/pi-lens/dist/clients/language-profile.js +2 -0
- package/node_modules/pi-lens/dist/clients/latency-logger.js +487 -9
- package/node_modules/pi-lens/dist/clients/lazy-import.js +21 -0
- package/node_modules/pi-lens/dist/clients/ledger-bounds.js +21 -0
- package/node_modules/pi-lens/dist/clients/lens-events.js +56 -25
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +16 -0
- package/node_modules/pi-lens/dist/clients/live-bus-emitter.js +45 -2
- package/node_modules/pi-lens/dist/clients/lsp/aggregation.js +30 -4
- package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +160 -20
- package/node_modules/pi-lens/dist/clients/lsp/client.js +1666 -148
- package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +111 -0
- package/node_modules/pi-lens/dist/clients/lsp/document-drift.js +389 -0
- package/node_modules/pi-lens/dist/clients/lsp/index.js +2496 -171
- package/node_modules/pi-lens/dist/clients/lsp/inferred-project.js +215 -0
- package/node_modules/pi-lens/dist/clients/lsp/jvm-runtime.js +146 -14
- package/node_modules/pi-lens/dist/clients/lsp/language.js +48 -4
- package/node_modules/pi-lens/dist/clients/lsp/server.js +517 -69
- package/node_modules/pi-lens/dist/clients/lsp/spawn-history.js +22 -0
- package/node_modules/pi-lens/dist/clients/lsp/sync-kind.js +43 -0
- package/node_modules/pi-lens/dist/clients/lsp/tsserver-sync.js +172 -0
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/classification.js +21 -5
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/strategies.js +61 -3
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +422 -28
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-session.js +30 -0
- package/node_modules/pi-lens/dist/clients/lsp/workspace-sweep-hold.js +175 -0
- package/node_modules/pi-lens/dist/clients/lsp-lazy.js +3 -2
- package/node_modules/pi-lens/dist/clients/mcp/analyze.js +4 -0
- package/node_modules/pi-lens/dist/clients/mcp/session.js +39 -18
- package/node_modules/pi-lens/dist/clients/model-provider.js +53 -0
- package/node_modules/pi-lens/dist/clients/module-report.js +8 -0
- package/node_modules/pi-lens/dist/clients/opengrep-client.js +15 -1
- package/node_modules/pi-lens/dist/clients/package-manager.js +170 -14
- package/node_modules/pi-lens/dist/clients/path-attribution-telemetry.js +27 -0
- package/node_modules/pi-lens/dist/clients/path-utils.js +160 -0
- package/node_modules/pi-lens/dist/clients/pipeline.js +178 -30
- package/node_modules/pi-lens/dist/clients/post-autofix-notice.js +37 -0
- package/node_modules/pi-lens/dist/clients/project-diagnostics/cache.js +17 -3
- package/node_modules/pi-lens/dist/clients/project-diagnostics/extractors.js +89 -22
- package/node_modules/pi-lens/dist/clients/project-diagnostics/fresh-fetch.js +85 -15
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/gitleaks.js +15 -3
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +23 -2
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/trivy.js +50 -2
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +5 -0
- package/node_modules/pi-lens/dist/clients/project-lens-config.js +3 -0
- package/node_modules/pi-lens/dist/clients/project-snapshot.js +299 -0
- package/node_modules/pi-lens/dist/clients/quiet-window-config.js +47 -0
- package/node_modules/pi-lens/dist/clients/quiet-window.js +11 -25
- package/node_modules/pi-lens/dist/clients/read-guard-logger.js +1 -1
- package/node_modules/pi-lens/dist/clients/read-guard.js +184 -10
- package/node_modules/pi-lens/dist/clients/resource-sampler.js +49 -17
- package/node_modules/pi-lens/dist/clients/reverse-deps.js +50 -11
- package/node_modules/pi-lens/dist/clients/review-graph/query.js +76 -4
- package/node_modules/pi-lens/dist/clients/run-duration.js +55 -0
- package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +248 -13
- package/node_modules/pi-lens/dist/clients/runtime-context.js +112 -12
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +472 -61
- package/node_modules/pi-lens/dist/clients/runtime-session.js +359 -13
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +217 -22
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +269 -22
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +948 -87
- package/node_modules/pi-lens/dist/clients/rust-client.js +21 -37
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +220 -7
- package/node_modules/pi-lens/dist/clients/scratch-tree-policy.js +161 -0
- package/node_modules/pi-lens/dist/clients/search-read-registration.js +34 -6
- package/node_modules/pi-lens/dist/clients/security-scan-client.js +224 -8
- package/node_modules/pi-lens/dist/clients/sg-runner.js +249 -37
- package/node_modules/pi-lens/dist/clients/single-flight.js +158 -0
- package/node_modules/pi-lens/dist/clients/smells-rollup.js +18 -11
- package/node_modules/pi-lens/dist/clients/stale-marker.js +17 -0
- package/node_modules/pi-lens/dist/clients/startup-timing.js +26 -2
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +574 -32
- package/node_modules/pi-lens/dist/clients/tool-event.js +56 -5
- package/node_modules/pi-lens/dist/clients/tool-policy.js +127 -20
- package/node_modules/pi-lens/dist/clients/tool-set-policy.js +76 -0
- package/node_modules/pi-lens/dist/clients/tree-sitter-cache.js +75 -1
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +769 -64
- package/node_modules/pi-lens/dist/clients/tree-sitter-shared.js +11 -0
- package/node_modules/pi-lens/dist/clients/tree-sitter-symbol-extractor.js +90 -0
- package/node_modules/pi-lens/dist/clients/trivy-client.js +19 -1
- package/node_modules/pi-lens/dist/clients/warm-attach.js +17 -0
- package/node_modules/pi-lens/dist/clients/widget-state.js +336 -36
- package/node_modules/pi-lens/dist/clients/word-index.js +305 -33
- package/node_modules/pi-lens/dist/clients/zizmor-config.js +214 -14
- package/node_modules/pi-lens/dist/index.js +64677 -49484
- package/node_modules/pi-lens/dist/mcp/server.js +8 -2
- package/node_modules/pi-lens/dist/tools/activate-tools.js +17 -5
- package/node_modules/pi-lens/dist/tools/ast-grep-replace.js +9 -4
- package/node_modules/pi-lens/dist/tools/lens-diagnostic-mark.js +5 -2
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +469 -56
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +190 -46
- package/node_modules/pi-lens/dist/tools/lsp-navigation.js +46 -7
- package/node_modules/pi-lens/dist/tools/symbol-search.js +1 -1
- package/node_modules/pi-lens/docs/agent-guide.md +44 -14
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +518 -501
- package/node_modules/pi-lens/docs/dispositions.md +21 -0
- package/node_modules/pi-lens/docs/features.md +33 -6
- package/node_modules/pi-lens/docs/globalconfig.md +14 -0
- package/node_modules/pi-lens/docs/language-coverage.md +71 -5
- package/node_modules/pi-lens/docs/mcp.md +2 -2
- package/node_modules/pi-lens/docs/servercapabilities.md +4 -1
- package/node_modules/pi-lens/docs/settings.md +25 -1
- package/node_modules/pi-lens/docs/usage.md +24 -5
- package/node_modules/pi-lens/docs/word-index.md +35 -0
- package/node_modules/pi-lens/package.json +10 -6
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/__snapshots__/no-reflect-get-js-snapshot.yml +23 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/__snapshots__/no-reflect-get-snapshot.yml +23 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/__snapshots__/ts-void-zero-snapshot.yml +23 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-bare-object-param-test.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-chained-type-assertions-test.yml +22 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-compile-call-test.yml +29 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-conditional-empty-object-spread-js-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-conditional-empty-object-spread-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-dupe-class-members-test.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-inner-html-js-test.yml +7 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-inner-html-test.yml +7 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-known-value-widening-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-non-null-assertion-test.yml +216 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-apply-js-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-apply-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-get-js-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-get-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +12 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-runtime-typeof-test.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-server-bind-wildcard-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-shape-in-symbol-names-test.yml +13 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-js-test.yml +5 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-test.yml +5 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-unknown-laundering-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-unknown-parameters-test.yml +12 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-unknown-returns-test.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-unsafe-dictionary-any-test.yml +10 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-unsafe-dictionary-unknown-test.yml +8 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/redundant-unsafe-function-test.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/require-safety-comment-for-as-unknown-as-test.yml +177 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ts-void-zero-test.yml +1 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-await-expression-member-js.yml +13 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-await-expression-member.yml +13 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-bare-host-path-in-win32-branch.yml +2 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-bare-object-param.yml +60 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-chained-type-assertions.yml +66 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-compile-call.yml +63 -5
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-conditional-empty-object-spread-js.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-conditional-empty-object-spread.yml +29 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-dupe-class-members.yml +52 -8
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-inner-html-js.yml +27 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-inner-html.yml +27 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-known-value-widening.yml +71 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-non-null-assertion.yml +316 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-raw-json-store-write.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-apply-js.yml +29 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-apply.yml +30 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-get-js.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-get.yml +42 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +22 -5
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-runtime-typeof.yml +121 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-server-bind-wildcard.yml +23 -7
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-shape-in-symbol-names.yml +68 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-js.yml +41 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code.yml +41 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-unknown-laundering.yml +32 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-unknown-parameters.yml +67 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-unknown-returns.yml +106 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-unsafe-dictionary-any.yml +50 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-unsafe-dictionary-unknown.yml +56 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-win32-isabsolute-for-qualification.yml +2 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/redundant-unsafe-function.yml +32 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/require-safety-comment-for-as-unknown-as.yml +184 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/ts-void-zero.yml +5 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/self-scan-baseline.json +5 -0
- package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +132 -1
- package/node_modules/pi-lens/scripts/download-grammars.js +25 -0
- package/node_modules/pi-lens/scripts/grammars.lock.json +9 -0
- package/node_modules/pi-lens/skills/pi-lens-ast-grep/SKILL.md +12 -11
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +22 -22
- package/node_modules/pi-lens/skills/pi-lens-write-ast-grep-rule/SKILL.md +87 -116
- package/node_modules/pi-lens/skills/pi-lens-write-ast-grep-rule/reference.md +170 -0
- package/node_modules/pi-lens/skills/pi-lens-write-tree-sitter-rule/SKILL.md +3 -1
- package/node_modules/pi-lens/vendor/grammars/tree-sitter-cue.wasm +0 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +49 -0
- package/node_modules/pi-mcp-adapter/README.md +51 -6
- package/node_modules/pi-mcp-adapter/agent-dir.ts +12 -4
- package/node_modules/pi-mcp-adapter/cli.js +188 -5
- package/node_modules/pi-mcp-adapter/commands.ts +128 -22
- package/node_modules/pi-mcp-adapter/config.ts +28 -10
- package/node_modules/pi-mcp-adapter/direct-tools.ts +23 -19
- package/node_modules/pi-mcp-adapter/index.ts +219 -32
- package/node_modules/pi-mcp-adapter/init.ts +36 -4
- package/node_modules/pi-mcp-adapter/lifecycle.ts +315 -24
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +39 -6
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +387 -0
- package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +27 -3
- package/node_modules/pi-mcp-adapter/mcp-code.ts +4 -0
- package/node_modules/pi-mcp-adapter/mcp-panel.ts +42 -13
- package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +2 -1
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +46 -25
- package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +168 -0
- package/node_modules/pi-mcp-adapter/package.json +4 -1
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +5 -4
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +330 -0
- package/node_modules/pi-mcp-adapter/search-ranking.ts +92 -22
- package/node_modules/pi-mcp-adapter/server-manager.ts +145 -2
- package/node_modules/pi-mcp-adapter/session-recovery.ts +7 -0
- package/node_modules/pi-mcp-adapter/tool-approval.ts +15 -2
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +38 -18
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +44 -4
- package/node_modules/pi-mcp-adapter/types.ts +95 -10
- package/node_modules/pi-mcp-adapter/ui-server.ts +18 -16
- package/node_modules/pi-mcp-adapter/utils.ts +70 -0
- package/node_modules/pi-web-access/CHANGELOG.md +37 -0
- package/node_modules/pi-web-access/README.md +38 -14
- package/node_modules/pi-web-access/anysearch.ts +4 -2
- package/node_modules/pi-web-access/auth-fetch.ts +148 -0
- package/node_modules/pi-web-access/brave.ts +16 -4
- package/node_modules/pi-web-access/chrome-cookies.ts +110 -23
- package/node_modules/pi-web-access/curator-page.ts +8 -3
- package/node_modules/pi-web-access/curator-server.ts +5 -1
- package/node_modules/pi-web-access/exa.ts +18 -7
- package/node_modules/pi-web-access/extract.ts +134 -37
- package/node_modules/pi-web-access/fetch-params.ts +17 -3
- package/node_modules/pi-web-access/firecrawl.ts +172 -12
- package/node_modules/pi-web-access/gemini-search.ts +33 -7
- package/node_modules/pi-web-access/index.ts +160 -104
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/pi-web-access/page-query.ts +4 -2
- package/node_modules/pi-web-access/parallel-mcp.ts +249 -0
- package/node_modules/pi-web-access/parallel.ts +2 -2
- package/node_modules/pi-web-access/query-rewrite.ts +51 -0
- package/node_modules/pi-web-access/serper.ts +211 -0
- package/node_modules/pi-web-access/summary-model-scope.ts +12 -4
- package/node_modules/pi-web-access/summary-review.ts +51 -23
- package/node_modules/pi-web-access/tavily.ts +16 -4
- package/node_modules/pi-web-access/utils.ts +87 -0
- package/node_modules/pi-web-access/valyu.ts +199 -0
- package/node_modules/pi-web-access/youtube-extract.ts +2 -2
- package/package.json +13 -13
|
@@ -22,11 +22,15 @@ import * as path from "node:path";
|
|
|
22
22
|
import { safeSpawnAsync } from "./safe-spawn.js";
|
|
23
23
|
import { assertInstallAllowed } from "./project-trust.js";
|
|
24
24
|
import { SecurityScanClient } from "./security-scan-client.js";
|
|
25
|
+
import { classifyProbeFailure, describeProbeEvidence, INSTALL_TRANSIENT_MAX_ATTEMPTS, logAvailabilityDecision, startHostStallSampler, } from "./dispatch/runners/utils/availability-policy.js";
|
|
26
|
+
import { recordDegradationOnce } from "./degradation-ledger.js";
|
|
25
27
|
const EMPTY_RESULT = {
|
|
26
28
|
success: false,
|
|
27
29
|
findings: [],
|
|
28
30
|
};
|
|
29
31
|
const SCAN_TIMEOUT_MS = 120_000;
|
|
32
|
+
/** Budget for the `go install` auto-install, ms. */
|
|
33
|
+
const INSTALL_TIMEOUT_MS = 60_000;
|
|
30
34
|
// --- Client ---
|
|
31
35
|
export class GovulncheckClient extends SecurityScanClient {
|
|
32
36
|
constructor(verbose = false) {
|
|
@@ -54,6 +58,16 @@ export class GovulncheckClient extends SecurityScanClient {
|
|
|
54
58
|
this.available = true;
|
|
55
59
|
return true;
|
|
56
60
|
}
|
|
61
|
+
if (this.probeWasTransient()) {
|
|
62
|
+
// #1467: a timed-out/killed probe says nothing about whether
|
|
63
|
+
// govulncheck is on PATH. Latching `false` here disabled it for the
|
|
64
|
+
// life of the process; a `go install` here would be a heavyweight
|
|
65
|
+
// reaction to a host hiccup. probeVersion has already recorded the
|
|
66
|
+
// expiring verdict and its retry schedule (#1501) — re-marking it
|
|
67
|
+
// here would double-escalate the cooldown. Retry later.
|
|
68
|
+
this.log("govulncheck probe timed out; retrying later (not installing)");
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
57
71
|
if (!assertInstallAllowed("govulncheck go install")) {
|
|
58
72
|
// Deliberately NOT latching `available = false` (#1350 delta review):
|
|
59
73
|
// trust denial is policy, not tool absence -- a later trust grant
|
|
@@ -67,30 +81,172 @@ export class GovulncheckClient extends SecurityScanClient {
|
|
|
67
81
|
// project has a go.mod the user has the Go toolchain by definition.
|
|
68
82
|
// Same shape as rust-clippy / cargo: lean on the language's own
|
|
69
83
|
// install mechanism rather than adding a new installer strategy.
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
const goProbeStartedAt = Date.now();
|
|
85
|
+
const goSampler = startHostStallSampler();
|
|
86
|
+
let goOnPath;
|
|
87
|
+
let goHostStallMs;
|
|
88
|
+
try {
|
|
89
|
+
goOnPath = await safeSpawnAsync("go", ["version"], {
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
goHostStallMs = goSampler.stop();
|
|
95
|
+
}
|
|
73
96
|
if (goOnPath.error || goOnPath.status !== 0) {
|
|
97
|
+
const { outcome, cause } = classifyProbeFailure(goOnPath, {
|
|
98
|
+
hostStallMs: goHostStallMs,
|
|
99
|
+
});
|
|
100
|
+
if (outcome === "transient") {
|
|
101
|
+
this.log("`go version` probe timed out; retrying govulncheck later");
|
|
102
|
+
const retryAfterMs = this.markTransientlyUnavailable(cause);
|
|
103
|
+
logAvailabilityDecision({
|
|
104
|
+
tool: "govulncheck",
|
|
105
|
+
verdict: "unavailable",
|
|
106
|
+
outcome,
|
|
107
|
+
cause,
|
|
108
|
+
elapsedMs: Date.now() - goProbeStartedAt,
|
|
109
|
+
latched: false,
|
|
110
|
+
hostStallMs: goHostStallMs,
|
|
111
|
+
...(retryAfterMs > 0 && { retryAfterMs }),
|
|
112
|
+
budgetMs: 5000,
|
|
113
|
+
});
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
74
116
|
this.log("go binary not on PATH — cannot auto-install govulncheck");
|
|
75
|
-
|
|
117
|
+
// Derived from the `go version` probe above, and recorded with it: a
|
|
118
|
+
// reader can see WHY govulncheck went quiet without re-running it (#1500).
|
|
119
|
+
// The evidence names `go`, because that is what was spawned — a row that
|
|
120
|
+
// carried go's errno unlabelled under `tool: "govulncheck"` invited the
|
|
121
|
+
// exact misreading the field exists to prevent.
|
|
122
|
+
this.noteDurableAbsence({
|
|
123
|
+
...describeProbeEvidence(goOnPath, "go"),
|
|
124
|
+
install: "not-attempted",
|
|
125
|
+
});
|
|
76
126
|
return false;
|
|
77
127
|
}
|
|
78
128
|
this.log("govulncheck not found, attempting auto-install via go install");
|
|
79
|
-
const
|
|
129
|
+
const installStartedAt = Date.now();
|
|
130
|
+
const installSampler = startHostStallSampler();
|
|
131
|
+
let install;
|
|
132
|
+
let installHostStallMs;
|
|
133
|
+
try {
|
|
134
|
+
install = await safeSpawnAsync("go", ["install", "golang.org/x/vuln/cmd/govulncheck@latest"], { timeout: INSTALL_TIMEOUT_MS });
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
installHostStallMs = installSampler.stop();
|
|
138
|
+
}
|
|
80
139
|
if (install.error || install.status !== 0) {
|
|
81
140
|
this.log(`govulncheck auto-install failed: ${(install.stderr ?? "").slice(0, 200)}`);
|
|
82
|
-
|
|
141
|
+
// #1476: `go install` runs against a 60 s budget over the network. A
|
|
142
|
+
// timed-out or killed install says nothing about whether govulncheck
|
|
143
|
+
// can ever be installed here, so it must not latch the durable
|
|
144
|
+
// "tool is not installed" verdict the way a real install refusal does.
|
|
145
|
+
// A non-zero exit (module not found, compile error) still latches:
|
|
146
|
+
// that IS evidence about this machine, and retrying it every turn
|
|
147
|
+
// would be a `go install` storm.
|
|
148
|
+
const { outcome, cause } = classifyProbeFailure(install, {
|
|
149
|
+
hostStallMs: installHostStallMs,
|
|
150
|
+
});
|
|
151
|
+
if (outcome === "transient") {
|
|
152
|
+
// #1497: the retried operation here is a ≤60s network compile,
|
|
153
|
+
// not a cheap probe, so it escalates on the install-class
|
|
154
|
+
// schedule and latches at the attempt ceiling instead of
|
|
155
|
+
// re-compiling every few minutes forever.
|
|
156
|
+
const retryAfterMs = this.markTransientlyUnavailable(cause, {
|
|
157
|
+
operationClass: "install",
|
|
158
|
+
});
|
|
159
|
+
const exhausted = retryAfterMs === 0;
|
|
160
|
+
const ceilingReason = `go install timed out ${INSTALL_TRANSIENT_MAX_ATTEMPTS} times; install retries disabled until the next session`;
|
|
161
|
+
if (exhausted) {
|
|
162
|
+
// The symptom a user notices is an unexplained busy core, not a
|
|
163
|
+
// missing tool — so the terminal verdict gets the louder record.
|
|
164
|
+
// Once per session, matching the latch's own lifetime: both re-arm
|
|
165
|
+
// at `session_start` (review F3).
|
|
166
|
+
recordDegradationOnce({
|
|
167
|
+
kind: "install-retry-exhausted",
|
|
168
|
+
subject: "govulncheck",
|
|
169
|
+
reason: ceilingReason,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// One record per decision, so an install that keeps timing out is
|
|
173
|
+
// readable in latency.log the same day (#1467's forensic trail).
|
|
174
|
+
logAvailabilityDecision({
|
|
175
|
+
tool: "govulncheck",
|
|
176
|
+
verdict: "unavailable",
|
|
177
|
+
outcome,
|
|
178
|
+
// At the ceiling the latch rewrote the cause; a row still saying
|
|
179
|
+
// `probe-timeout` would read as "cooling down" (#1497 review F5).
|
|
180
|
+
cause: exhausted ? (this.latchedCause() ?? cause) : cause,
|
|
181
|
+
elapsedMs: Date.now() - installStartedAt,
|
|
182
|
+
latched: exhausted,
|
|
183
|
+
hostStallMs: installHostStallMs,
|
|
184
|
+
...(retryAfterMs > 0 && { retryAfterMs }),
|
|
185
|
+
budgetMs: INSTALL_TIMEOUT_MS,
|
|
186
|
+
// The ceiling verdict is an ASSERTION by this call site, not a
|
|
187
|
+
// classification of one spawn, and #1534's convention is that such a
|
|
188
|
+
// row says so and carries the install facts behind it. Every retry
|
|
189
|
+
// DID run a `go install` that failed, so `install: "failed"` is
|
|
190
|
+
// earned, and the reason names the ceiling rather than the spawn.
|
|
191
|
+
...(exhausted && {
|
|
192
|
+
classifiedBy: "caller",
|
|
193
|
+
evidence: {
|
|
194
|
+
...describeProbeEvidence(install, "go install"),
|
|
195
|
+
install: "failed",
|
|
196
|
+
installReason: ceilingReason,
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
// A non-transient install failure (module not found, compile error) IS
|
|
203
|
+
// evidence about this machine, so it latches — but the row says the
|
|
204
|
+
// install was tried and failed, which a plain absence never does (#1500).
|
|
205
|
+
this.noteDurableAbsence({
|
|
206
|
+
...describeProbeEvidence(install, "go install"),
|
|
207
|
+
install: "failed",
|
|
208
|
+
}, { elapsedMs: Date.now() - installStartedAt });
|
|
83
209
|
return false;
|
|
84
210
|
}
|
|
85
211
|
// `go install` writes to `$GOBIN` or `$GOPATH/bin`. The user may not
|
|
86
212
|
// have that on `$PATH`. Re-probe by name (works when it is on PATH)
|
|
87
213
|
// then fall back to the canonical bin dirs.
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
214
|
+
const reprobeStartedAt = Date.now();
|
|
215
|
+
const reprobeSampler = startHostStallSampler();
|
|
216
|
+
let reprobe;
|
|
217
|
+
let reprobeHostStallMs;
|
|
218
|
+
try {
|
|
219
|
+
reprobe = await safeSpawnAsync("govulncheck", ["-version"], {
|
|
220
|
+
timeout: 5000,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
reprobeHostStallMs = reprobeSampler.stop();
|
|
225
|
+
}
|
|
91
226
|
if (!reprobe.error && reprobe.status === 0) {
|
|
92
227
|
this.log("govulncheck auto-installed and found on PATH");
|
|
93
228
|
this.available = true;
|
|
229
|
+
// The initial PATH probe already wrote a latched `unavailable` row
|
|
230
|
+
// (#1500's own assertion doesn't fire here — the reprobe SUCCEEDED —
|
|
231
|
+
// but that first probe's verdict still logged, before `go install`
|
|
232
|
+
// ever ran). Without a compensating row here, the durable record says
|
|
233
|
+
// govulncheck is off when `go install` just put it on PATH (#1606).
|
|
234
|
+
logAvailabilityDecision({
|
|
235
|
+
tool: "govulncheck",
|
|
236
|
+
verdict: "available",
|
|
237
|
+
outcome: "success",
|
|
238
|
+
cause: "ok",
|
|
239
|
+
elapsedMs: Date.now() - reprobeStartedAt,
|
|
240
|
+
latched: true,
|
|
241
|
+
hostStallMs: reprobeHostStallMs,
|
|
242
|
+
budgetMs: 5000,
|
|
243
|
+
classifiedBy: "caller",
|
|
244
|
+
evidence: {
|
|
245
|
+
install: "succeeded",
|
|
246
|
+
binary: "govulncheck",
|
|
247
|
+
source: "go-install",
|
|
248
|
+
},
|
|
249
|
+
});
|
|
94
250
|
return true;
|
|
95
251
|
}
|
|
96
252
|
// Look in the canonical install locations and remember the absolute
|
|
@@ -111,6 +267,24 @@ export class GovulncheckClient extends SecurityScanClient {
|
|
|
111
267
|
this.binaryPath = candidate;
|
|
112
268
|
this.available = true;
|
|
113
269
|
this.log(`govulncheck auto-installed at ${candidate}`);
|
|
270
|
+
// Same compensating row as the on-PATH reprobe arm above (#1606):
|
|
271
|
+
// the initial probe already latched `unavailable`, and this arm
|
|
272
|
+
// is the OTHER way to recover — the canonical $GOBIN/$GOPATH walk
|
|
273
|
+
// found it after the on-PATH reprobe missed.
|
|
274
|
+
logAvailabilityDecision({
|
|
275
|
+
tool: "govulncheck",
|
|
276
|
+
verdict: "available",
|
|
277
|
+
outcome: "success",
|
|
278
|
+
cause: "ok",
|
|
279
|
+
elapsedMs: Date.now() - installStartedAt,
|
|
280
|
+
latched: true,
|
|
281
|
+
classifiedBy: "caller",
|
|
282
|
+
evidence: {
|
|
283
|
+
install: "succeeded",
|
|
284
|
+
binary: path.basename(candidate),
|
|
285
|
+
source: "go-install",
|
|
286
|
+
},
|
|
287
|
+
});
|
|
114
288
|
return true;
|
|
115
289
|
}
|
|
116
290
|
}
|
|
@@ -118,8 +292,43 @@ export class GovulncheckClient extends SecurityScanClient {
|
|
|
118
292
|
// fall through to next candidate
|
|
119
293
|
}
|
|
120
294
|
}
|
|
295
|
+
// The install SUCCEEDED, so the tool is on this machine somewhere. If the
|
|
296
|
+
// re-probe merely timed out, latching "not installed" would be the #1467
|
|
297
|
+
// mistake one step later in the same function (#1476).
|
|
298
|
+
const { outcome, cause } = classifyProbeFailure(reprobe, {
|
|
299
|
+
hostStallMs: reprobeHostStallMs,
|
|
300
|
+
});
|
|
301
|
+
if (outcome === "transient") {
|
|
302
|
+
this.log("govulncheck installed but the re-probe timed out; retrying later");
|
|
303
|
+
const retryAfterMs = this.markTransientlyUnavailable(cause);
|
|
304
|
+
logAvailabilityDecision({
|
|
305
|
+
tool: "govulncheck",
|
|
306
|
+
verdict: "unavailable",
|
|
307
|
+
outcome,
|
|
308
|
+
cause,
|
|
309
|
+
// The re-probe's own wall time. A hard-coded 0 here was the #1474
|
|
310
|
+
// defect verbatim: a duration field that measures nothing.
|
|
311
|
+
elapsedMs: Date.now() - reprobeStartedAt,
|
|
312
|
+
latched: false,
|
|
313
|
+
hostStallMs: reprobeHostStallMs,
|
|
314
|
+
...(retryAfterMs > 0 && { retryAfterMs }),
|
|
315
|
+
budgetMs: 5000,
|
|
316
|
+
});
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
// The third silent arm (#1500 review): the install SUCCEEDED and the binary
|
|
320
|
+
// is nowhere the re-probe or the canonical bin dirs could find it. That is a
|
|
321
|
+
// durable, actionable fact — and until now it latched with no record at all,
|
|
322
|
+
// so a $GOBIN misconfiguration was indistinguishable from govulncheck simply
|
|
323
|
+
// not being installed. `install: "succeeded"` also appears on the two success
|
|
324
|
+
// arms above (#1606's compensating `available` rows) — this is the durable
|
|
325
|
+
// FAILURE counterpart, an install that worked but left nothing locatable.
|
|
121
326
|
this.log("govulncheck auto-install succeeded but binary not locatable — check $GOBIN / $GOPATH");
|
|
122
|
-
this.
|
|
327
|
+
this.noteDurableAbsence({
|
|
328
|
+
...describeProbeEvidence(reprobe, "govulncheck"),
|
|
329
|
+
install: "succeeded",
|
|
330
|
+
installReason: "installed binary not found on PATH, $GOBIN or $GOPATH/bin",
|
|
331
|
+
}, { elapsedMs: Date.now() - reprobeStartedAt });
|
|
123
332
|
return false;
|
|
124
333
|
}
|
|
125
334
|
/**
|
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
* import this compiled module (it runs before the TS build), so it keeps a
|
|
10
10
|
* mirror — guarded against drift by `tests/clients/grammar-source.test.ts`.
|
|
11
11
|
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
12
13
|
import * as fs from "node:fs";
|
|
13
14
|
import * as path from "node:path";
|
|
14
15
|
import { writeFileAtomic } from "./atomic-write.js";
|
|
16
|
+
import { recordDegradationOnce } from "./degradation-ledger.js";
|
|
17
|
+
import { getPackageRoot } from "./package-root.js";
|
|
15
18
|
/** tree-sitter-wasms release the grammars are pulled from. */
|
|
16
19
|
export const TREE_SITTER_WASMS_VERSION = "0.1.13";
|
|
17
20
|
/** unpkg mirror of the tree-sitter-wasms artifacts. */
|
|
@@ -32,6 +35,59 @@ export const GRAMMAR_SOURCE_OVERRIDES = {
|
|
|
32
35
|
export function grammarSourceUrl(filename) {
|
|
33
36
|
return GRAMMAR_SOURCE_OVERRIDES[filename]?.url ?? `${GRAMMAR_CDN_BASE}/${filename}`;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Grammars built in-house and committed to `vendor/grammars/`.
|
|
40
|
+
*
|
|
41
|
+
* tree-sitter-cue: CUE has no published wasm anywhere — not on npm
|
|
42
|
+
* (`tree-sitter-cue` there is a native binding only), not in the
|
|
43
|
+
* `tree-sitter-wasms` aggregator, and upstream cuts no releases (#1522).
|
|
44
|
+
* Building it ourselves, with a modern `dylink.0` section, is the only way to
|
|
45
|
+
* give `.cue` structural analysis, so the artifact is committed and pinned
|
|
46
|
+
* rather than fetched. Mirrored by `VENDORED_GRAMMARS` in
|
|
47
|
+
* scripts/download-grammars.
|
|
48
|
+
*/
|
|
49
|
+
export const VENDORED_GRAMMARS = {
|
|
50
|
+
"tree-sitter-cue.wasm": {
|
|
51
|
+
repo: "https://github.com/eonpatapon/tree-sitter-cue",
|
|
52
|
+
commit: "dd7b90e0770ff18070c515937ba3c3d6d93db00e",
|
|
53
|
+
license: "MIT",
|
|
54
|
+
buildCommand: "npx tree-sitter-cli build --wasm",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/** Is `filename` built in-house rather than fetched from a CDN? */
|
|
58
|
+
export function isVendoredGrammar(filename) {
|
|
59
|
+
return Object.hasOwn(VENDORED_GRAMMARS, filename);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The verdict for a vendored grammar that isn't on disk. It ships in
|
|
63
|
+
* `vendor/grammars/`, which the resolve path searches first, so needing to
|
|
64
|
+
* "fetch" one means the committed file is missing from the install: a
|
|
65
|
+
* packaging fault, not a network one. No retry, no cooldown ladder, and above
|
|
66
|
+
* all no fetch of a CDN URL that would 404 forever. Non-retryable is the
|
|
67
|
+
* honest verdict precisely because a later attempt cannot change it.
|
|
68
|
+
*
|
|
69
|
+
* Shared so that every caller answers identically. `tree-sitter-client.ts`'s
|
|
70
|
+
* `fetchGrammar` has to consult this BEFORE it resolves a write directory:
|
|
71
|
+
* that resolution can fail on its own (web-tree-sitter not locatable yet) and
|
|
72
|
+
* would otherwise return the generic RETRYABLE environment verdict, hiding a
|
|
73
|
+
* missing vendored asset behind a transient-looking download failure.
|
|
74
|
+
*/
|
|
75
|
+
export function vendoredGrammarRefusal(filename) {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
retryable: false,
|
|
79
|
+
reason: `${filename} is built in-house and ships in vendor/grammars/; it has no ` +
|
|
80
|
+
`download source, so a missing copy means the install is incomplete.`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Absolute path to the committed `vendor/grammars` directory. Resolved from the
|
|
85
|
+
* package root for the same reason `grammarManifestPath` is (#1564): an
|
|
86
|
+
* `import.meta.url` offset collapses once `dist/index.js` is bundled.
|
|
87
|
+
*/
|
|
88
|
+
export function vendoredGrammarsDir() {
|
|
89
|
+
return path.join(getPackageRoot(import.meta.url), "vendor", "grammars");
|
|
90
|
+
}
|
|
35
91
|
/** Language id → grammar wasm filename. */
|
|
36
92
|
export const LANGUAGE_TO_GRAMMAR = {
|
|
37
93
|
typescript: "tree-sitter-typescript.wasm",
|
|
@@ -60,6 +116,7 @@ export const LANGUAGE_TO_GRAMMAR = {
|
|
|
60
116
|
vue: "tree-sitter-vue.wasm",
|
|
61
117
|
yaml: "tree-sitter-yaml.wasm",
|
|
62
118
|
zig: "tree-sitter-zig.wasm",
|
|
119
|
+
cue: "tree-sitter-cue.wasm",
|
|
63
120
|
};
|
|
64
121
|
/** The full set of grammar wasm filenames (deduped). */
|
|
65
122
|
export const GRAMMAR_FILES = [
|
|
@@ -110,13 +167,216 @@ export function grammarBlockReason(filename, rt = currentGrammarRuntime()) {
|
|
|
110
167
|
const block = BLOCKED_GRAMMARS[filename];
|
|
111
168
|
return block?.blocked(rt) ? block.reason : null;
|
|
112
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The four-byte WebAssembly module preamble, `\0asm` — the first bytes of
|
|
172
|
+
* every valid `.wasm` file. Single source of truth for the #1548 validation:
|
|
173
|
+
* both the download path (validate before writing) and the on-disk path
|
|
174
|
+
* (`fileHasWasmMagic`, for a file poisoned before this shipped) key off it.
|
|
175
|
+
*/
|
|
176
|
+
export const WASM_MAGIC = [0x00, 0x61, 0x73, 0x6d];
|
|
177
|
+
/** Do `bytes` start with the wasm magic number? */
|
|
178
|
+
export function hasWasmMagic(bytes) {
|
|
179
|
+
if (bytes.length < WASM_MAGIC.length)
|
|
180
|
+
return false;
|
|
181
|
+
return WASM_MAGIC.every((byte, i) => bytes[i] === byte);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Does the file at `filePath` start with the wasm magic number? `false` if it
|
|
185
|
+
* doesn't, is shorter than four bytes, or cannot be read at all — every one of
|
|
186
|
+
* those means "do not hand this path to `Language.load`".
|
|
187
|
+
*
|
|
188
|
+
* Reads four bytes, so it is cheap enough to run on a resolve path; callers
|
|
189
|
+
* that resolve repeatedly should still memoize the positive answer.
|
|
190
|
+
*/
|
|
191
|
+
export function fileHasWasmMagic(filePath) {
|
|
192
|
+
let fd;
|
|
193
|
+
try {
|
|
194
|
+
fd = fs.openSync(filePath, "r");
|
|
195
|
+
const head = Buffer.alloc(WASM_MAGIC.length);
|
|
196
|
+
const read = fs.readSync(fd, head, 0, head.length, 0);
|
|
197
|
+
return read === head.length && hasWasmMagic(head);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
if (fd !== undefined) {
|
|
204
|
+
try {
|
|
205
|
+
fs.closeSync(fd);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
/* nothing useful to do */
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const HTML_PREFIXES = ["<!doctype html", "<html", "<head", "<?xml"];
|
|
214
|
+
/**
|
|
215
|
+
* A short, log-safe sentence naming what arrived instead of a wasm module
|
|
216
|
+
* (#1548). Never echoes the body — only its shape, byte count and the first
|
|
217
|
+
* four bytes in hex — so a proxy's login page cannot smuggle content into a
|
|
218
|
+
* user-facing notification.
|
|
219
|
+
*/
|
|
220
|
+
export function describeNonWasmBody(bytes) {
|
|
221
|
+
if (bytes.length === 0) {
|
|
222
|
+
return "The download returned an empty body (0 bytes) instead of a wasm module.";
|
|
223
|
+
}
|
|
224
|
+
const head = Buffer.from(bytes.subarray(0, Math.min(16, bytes.length))).toString("latin1");
|
|
225
|
+
const lead = head.trimStart().toLowerCase();
|
|
226
|
+
const shape = HTML_PREFIXES.some((prefix) => lead.startsWith(prefix))
|
|
227
|
+
? "an HTML page (a captive portal or proxy intercepted the request)"
|
|
228
|
+
: "non-wasm data";
|
|
229
|
+
const magic = Buffer.from(bytes.subarray(0, WASM_MAGIC.length))
|
|
230
|
+
.toString("hex")
|
|
231
|
+
.replace(/../g, "$& ")
|
|
232
|
+
.trim();
|
|
233
|
+
// Kept short on purpose: this is spliced into a user notification and into
|
|
234
|
+
// the degradation ledger, whose fields truncate at 200 characters.
|
|
235
|
+
return (`The download returned ${shape} — ` +
|
|
236
|
+
`${bytes.length} bytes starting ${magic}, not a wasm module.`);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Override applied for tests only (`_setGrammarManifestForTests`): `undefined`
|
|
240
|
+
* means "no override — use the real cached/loaded manifest", so `null` is a
|
|
241
|
+
* distinct, deliberate value (simulates a missing/corrupt lock file).
|
|
242
|
+
*/
|
|
243
|
+
let manifestOverride;
|
|
244
|
+
let cachedManifest;
|
|
245
|
+
/**
|
|
246
|
+
* `scripts/grammars.lock.json`'s absolute path, resolved from the installed
|
|
247
|
+
* PACKAGE ROOT rather than a fixed relative offset from this module (#1564).
|
|
248
|
+
* `import.meta.url` collapses to the bundle's own file once `dist/index.js`
|
|
249
|
+
* is esbuild-bundled (every merged module reports the bundle's URL, not its
|
|
250
|
+
* own), so a `join(dirname(fileURLToPath(import.meta.url)), "../scripts/...")`
|
|
251
|
+
* offset — correct in the unbundled repo/`npm run build` layout — resolves to
|
|
252
|
+
* the wrong directory once bundled. `getPackageRoot` instead walks up from
|
|
253
|
+
* wherever this module actually loaded from until it finds `package.json`,
|
|
254
|
+
* which lands on the package root under both layouts; `scripts/grammars.lock.json`
|
|
255
|
+
* is committed and shipped there (see `files` in package.json), so both the
|
|
256
|
+
* repo checkout and an installed npm package resolve it correctly.
|
|
257
|
+
*/
|
|
258
|
+
function grammarManifestPath() {
|
|
259
|
+
return path.join(getPackageRoot(import.meta.url), "scripts", "grammars.lock.json");
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The manifest, without the missing-manifest degradation report — split out
|
|
263
|
+
* so `loadGrammarManifest` can report on every `null` return (cached misses
|
|
264
|
+
* included), while this half stays a pure cache lookup.
|
|
265
|
+
*/
|
|
266
|
+
function resolveGrammarManifest() {
|
|
267
|
+
if (manifestOverride !== undefined)
|
|
268
|
+
return manifestOverride;
|
|
269
|
+
if (cachedManifest !== undefined)
|
|
270
|
+
return cachedManifest;
|
|
271
|
+
try {
|
|
272
|
+
const raw = fs.readFileSync(grammarManifestPath(), "utf-8");
|
|
273
|
+
cachedManifest = JSON.parse(raw);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
cachedManifest = null;
|
|
277
|
+
}
|
|
278
|
+
return cachedManifest;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Load + cache `scripts/grammars.lock.json`. Returns `null` (never throws) if
|
|
282
|
+
* the file is missing or malformed — an installed package predating this fix,
|
|
283
|
+
* or a corrupted lock file, degrades to the Content-Length check
|
|
284
|
+
* (`downloadGrammarDetailed`) instead of blocking every runtime grammar
|
|
285
|
+
* fetch. That fallback is silent to the CALLER by design (it's not a fetch
|
|
286
|
+
* failure), so it would otherwise never reach the record a bug report shows —
|
|
287
|
+
* report once per session that the STRONGEST check (sha256) is being skipped
|
|
288
|
+
* repo-wide, so a downgrade to the weaker Content-Length-only path is on the
|
|
289
|
+
* record rather than invisible.
|
|
290
|
+
*/
|
|
291
|
+
function loadGrammarManifest() {
|
|
292
|
+
const manifest = resolveGrammarManifest();
|
|
293
|
+
if (manifest === null) {
|
|
294
|
+
recordDegradationOnce({
|
|
295
|
+
kind: "grammar-blocked",
|
|
296
|
+
subject: "grammars.lock.json",
|
|
297
|
+
reason: "the pinned sha256 manifest is unavailable — runtime grammar downloads " +
|
|
298
|
+
"fall back to the weaker Content-Length check (or no integrity check at " +
|
|
299
|
+
"all for a source with neither).",
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return manifest;
|
|
303
|
+
}
|
|
304
|
+
/** Test-only manifest injection — see `manifestOverride` above. */
|
|
305
|
+
export function _setGrammarManifestForTests(manifest) {
|
|
306
|
+
manifestOverride = manifest;
|
|
307
|
+
}
|
|
308
|
+
/** `sha256:<hex>` digest of `data`, matching the manifest's format. */
|
|
309
|
+
function sha256Hex(data) {
|
|
310
|
+
return `sha256:${createHash("sha256").update(data).digest("hex")}`;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Pinned sha256 for `filename` from `scripts/grammars.lock.json`, or
|
|
314
|
+
* `undefined` when the manifest is unavailable or has no entry for it — the
|
|
315
|
+
* same "can't verify" fallback `downloadGrammarDetailed`'s own hash check
|
|
316
|
+
* already applies. `manifest.grammars[filename]` is keyed by filename
|
|
317
|
+
* regardless of a `GRAMMAR_SOURCE_OVERRIDES` entry (see the comment on that
|
|
318
|
+
* check), so a single lookup covers both the aggregator and override cases.
|
|
319
|
+
*
|
|
320
|
+
* This is the single source of truth a version bump (`TREE_SITTER_WASMS_VERSION`,
|
|
321
|
+
* or a `SOURCE_OVERRIDES` entry) reaches through: `--write-manifest` regenerates
|
|
322
|
+
* the pinned hash for the new build, so a cached file's sha256 no longer
|
|
323
|
+
* matching this value IS the version-changed signal — no separate "which
|
|
324
|
+
* version produced this file" bookkeeping is needed (#1760).
|
|
325
|
+
*/
|
|
326
|
+
export function pinnedGrammarHash(filename) {
|
|
327
|
+
return loadGrammarManifest()?.grammars[filename];
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* sha256 of the file at `filePath`, or `undefined` if it cannot be read (does
|
|
331
|
+
* not exist, a directory, a permission error). Callers that cannot verify
|
|
332
|
+
* must treat that the same as "no pinned hash" — never as a mismatch, which
|
|
333
|
+
* would force an unbounded refetch loop against an unreadable path.
|
|
334
|
+
*/
|
|
335
|
+
export function grammarFileSha256(filePath) {
|
|
336
|
+
try {
|
|
337
|
+
return sha256Hex(fs.readFileSync(filePath));
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* First 12 hex characters of a `sha256:<hex>` digest, for log/ledger/
|
|
345
|
+
* notification strings. Printing the full 64-hex digest on BOTH sides of a
|
|
346
|
+
* mismatch overran the degradation ledger's 200-character field cap (the
|
|
347
|
+
* truncation `describeNonWasmBody` above already designs around) and left
|
|
348
|
+
* the user notification — 579 characters, almost entirely hex — clipping the
|
|
349
|
+
* more diagnostic PINNED hash mid-string before a reader ever saw it. 12 hex
|
|
350
|
+
* characters (48 bits) is more than enough to tell "genuinely the wrong
|
|
351
|
+
* file" from a coincidence in a log line; it is not a security boundary.
|
|
352
|
+
*/
|
|
353
|
+
function shortHash(hash) {
|
|
354
|
+
const hex = hash.startsWith("sha256:") ? hash.slice("sha256:".length) : hash;
|
|
355
|
+
return `sha256:${hex.slice(0, 12)}…`;
|
|
356
|
+
}
|
|
113
357
|
/**
|
|
114
358
|
* Fetch one grammar wasm into `destDir`, staged and renamed via
|
|
115
|
-
* `atomic-write.ts` so a reader never sees a half-written wasm.
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
359
|
+
* `atomic-write.ts` so a reader never sees a half-written wasm. Never
|
|
360
|
+
* throws — a failed fetch (offline, 4xx) degrades to "grammar unavailable"
|
|
361
|
+
* so callers can decide how to handle it.
|
|
362
|
+
*
|
|
363
|
+
* #1548: the response BODY is validated against the wasm magic number before
|
|
364
|
+
* anything is written, so a 200-with-HTML from a captive portal is a failed
|
|
365
|
+
* (retryable) download rather than a poisoned file on disk. A grammar that
|
|
366
|
+
* crashes the runtime
|
|
367
|
+
* is protected at LOAD time (BLOCKED_GRAMMARS / grammarBlockReason), not by
|
|
368
|
+
* refusing to download it.
|
|
369
|
+
*
|
|
370
|
+
* #1564: the magic-number check alone lets a TRUNCATED-but-genuine wasm body
|
|
371
|
+
* through — a connection dropped mid-transfer still starts with `\0asm`. Two
|
|
372
|
+
* further checks close that: (1) when the pinned manifest
|
|
373
|
+
* (`scripts/grammars.lock.json`, already trusted by the postinstall path) has
|
|
374
|
+
* a sha256 for this grammar, the full body must match it; (2) when the
|
|
375
|
+
* response reports `Content-Length`, the received byte count must match it —
|
|
376
|
+
* cheaper, and the only check available when no pinned hash exists (an
|
|
377
|
+
* override not yet in the manifest, or a future grammar added before
|
|
378
|
+
* `--write-manifest` is re-run). Both are retryable failures, same shape as a
|
|
379
|
+
* captive portal: the CDN answered, but the bytes are not trustworthy.
|
|
120
380
|
*
|
|
121
381
|
* #1217: the staging name used to be hand-rolled `.${filename}.${pid}.tmp` —
|
|
122
382
|
* per-process, so two concurrent fetches of one grammar shared a staging inode
|
|
@@ -124,19 +384,82 @@ export function grammarBlockReason(filename, rt = currentGrammarRuntime()) {
|
|
|
124
384
|
* which made that hard to reach through the runtime path but did not cover
|
|
125
385
|
* direct callers.
|
|
126
386
|
*/
|
|
127
|
-
export async function
|
|
387
|
+
export async function downloadGrammarDetailed(destDir, filename) {
|
|
388
|
+
if (isVendoredGrammar(filename))
|
|
389
|
+
return vendoredGrammarRefusal(filename);
|
|
128
390
|
try {
|
|
129
391
|
fs.mkdirSync(destDir, { recursive: true });
|
|
130
392
|
const res = await fetch(grammarSourceUrl(filename));
|
|
131
|
-
if (!res.ok)
|
|
132
|
-
|
|
393
|
+
if (!res.ok) {
|
|
394
|
+
// 404/410: the CDN has authoritatively answered "this wasm does not
|
|
395
|
+
// exist at this URL" — a retry hits the same answer. Every other
|
|
396
|
+
// non-ok status (429, 5xx) is retryable. A captive portal answers
|
|
397
|
+
// 200, so it never reaches here; the magic-number check below is
|
|
398
|
+
// what catches it (#1548).
|
|
399
|
+
const retryable = res.status !== 404 && res.status !== 410;
|
|
400
|
+
return { ok: false, retryable };
|
|
401
|
+
}
|
|
133
402
|
const data = Buffer.from(await res.arrayBuffer());
|
|
403
|
+
// #1548: `res.ok` says the transport succeeded, NOT that the body is a
|
|
404
|
+
// grammar. A captive portal (airport wifi, corporate proxy) answers 200
|
|
405
|
+
// with its own login page; writing that to disk as tree-sitter-<lang>.wasm
|
|
406
|
+
// poisons the path permanently, because every later resolve finds the
|
|
407
|
+
// (garbage) file and reports the grammar as available while
|
|
408
|
+
// `Language.load` fails on every parse. Validate the wasm preamble BEFORE
|
|
409
|
+
// writing, and classify a non-wasm body as a retryable failure — the same
|
|
410
|
+
// shape as an offline fetch, so it flows through #1536's cooldown ladder.
|
|
411
|
+
if (!hasWasmMagic(data)) {
|
|
412
|
+
return { ok: false, retryable: true, reason: describeNonWasmBody(data) };
|
|
413
|
+
}
|
|
414
|
+
// #1564 cheap check: a body shorter (or longer) than the server's own
|
|
415
|
+
// declared Content-Length is a truncated/corrupted transfer, regardless
|
|
416
|
+
// of whether a pinned hash exists for this grammar.
|
|
417
|
+
const declaredLength = res.headers.get("content-length");
|
|
418
|
+
if (declaredLength !== null) {
|
|
419
|
+
const expectedBytes = Number.parseInt(declaredLength, 10);
|
|
420
|
+
if (Number.isFinite(expectedBytes) && expectedBytes !== data.length) {
|
|
421
|
+
return {
|
|
422
|
+
ok: false,
|
|
423
|
+
retryable: true,
|
|
424
|
+
reason: `The download reported Content-Length: ${expectedBytes} but only ` +
|
|
425
|
+
`${data.length} bytes arrived — a truncated transfer.`,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// #1564 primary check: verify the full body against the pinned sha256,
|
|
430
|
+
// closing the gap Content-Length can't (a proxy that sets a matching
|
|
431
|
+
// Content-Length on a truncated body, or a chunked response with none at
|
|
432
|
+
// all). `manifest.grammars[filename]` is keyed by filename regardless of
|
|
433
|
+
// override — an overridden grammar's hash was generated against the
|
|
434
|
+
// override's own URL (`scripts/download-grammars.ts --write-manifest`
|
|
435
|
+
// fetches via the same `SOURCE_OVERRIDES` map), so no extra alignment is
|
|
436
|
+
// needed here. No entry (manifest missing, or a grammar added before the
|
|
437
|
+
// manifest was regenerated) falls back to the Content-Length check above.
|
|
438
|
+
const expectedHash = loadGrammarManifest()?.grammars[filename];
|
|
439
|
+
if (expectedHash) {
|
|
440
|
+
const actualHash = sha256Hex(data);
|
|
441
|
+
if (actualHash !== expectedHash) {
|
|
442
|
+
return {
|
|
443
|
+
ok: false,
|
|
444
|
+
retryable: true,
|
|
445
|
+
reason: `The download's sha256 (${shortHash(actualHash)}) does not match the ` +
|
|
446
|
+
`pinned manifest (${shortHash(expectedHash)}) — a corrupt or truncated transfer.`,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
134
450
|
// bestEffort: false — a swallowed write failure would return true for a
|
|
135
451
|
// grammar that never landed.
|
|
136
452
|
writeFileAtomic(path.join(destDir, filename), data, { bestEffort: false });
|
|
137
|
-
return true;
|
|
453
|
+
return { ok: true, retryable: true };
|
|
138
454
|
}
|
|
139
455
|
catch {
|
|
140
|
-
|
|
456
|
+
// A thrown fetch (offline, DNS failure, aborted, ECONNRESET) or a write
|
|
457
|
+
// failure is transient by construction — the CDN never got to answer.
|
|
458
|
+
return { ok: false, retryable: true };
|
|
141
459
|
}
|
|
142
460
|
}
|
|
461
|
+
/** Back-compat boolean-only wrapper for callers that only need pass/fail
|
|
462
|
+
* (the postinstall script, prewarm-grammars test helper). */
|
|
463
|
+
export async function downloadGrammar(destDir, filename) {
|
|
464
|
+
return (await downloadGrammarDetailed(destDir, filename)).ok;
|
|
465
|
+
}
|