@herbertgao/pi-extensions 2026.8.6 → 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 +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +1 -1
- 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/renderer/compact-mode.ts +94 -77
- 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 +6 -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 +17 -13
- 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 +21 -6
- package/node_modules/@herbertgao/pi-subagents/src/usage.ts +129 -1
- package/node_modules/@herbertgao/pi-subagents/src/worktree.ts +20 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/README.md +1 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +26 -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 +2 -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 +120 -111
- 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 +10 -6
- package/node_modules/@narumitw/pi-btw/src/btw.ts +36 -40
- 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 +45 -2
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +136 -45
- package/node_modules/pi-lens/CHANGELOG.md +909 -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 +126 -13
- package/node_modules/pi-lens/dist/clients/agent-nudge.js +67 -11
- 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 +61 -30
- 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/cascade-budget.js +196 -0
- package/node_modules/pi-lens/dist/clients/cascade-format.js +20 -1
- 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/dead-code-client.js +123 -31
- 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 +25 -3
- package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +147 -33
- package/node_modules/pi-lens/dist/clients/diagnostic-line-freshness.js +298 -0
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +52 -2
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +256 -88
- 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 +60 -53
- 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 +275 -13
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +21 -6
- 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 +734 -64
- 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 +9 -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/event-loop-monitor.js +28 -5
- package/node_modules/pi-lens/dist/clients/extension-log.js +22 -1
- 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/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 +31 -0
- package/node_modules/pi-lens/dist/clients/gitleaks-client.js +181 -8
- package/node_modules/pi-lens/dist/clients/govulncheck-client.js +109 -9
- package/node_modules/pi-lens/dist/clients/grammar-source.js +333 -10
- package/node_modules/pi-lens/dist/clients/host-ports.js +8 -0
- package/node_modules/pi-lens/dist/clients/installer/index.js +1114 -100
- 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 +82 -6
- package/node_modules/pi-lens/dist/clients/knip-client.js +310 -10
- 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 +440 -11
- 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-flag-registry.js +8 -0
- package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +102 -7
- package/node_modules/pi-lens/dist/clients/lsp/client.js +1516 -159
- package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +83 -1
- package/node_modules/pi-lens/dist/clients/lsp/document-drift.js +389 -0
- package/node_modules/pi-lens/dist/clients/lsp/index.js +2274 -147
- 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 +277 -16
- 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 +79 -3
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/strategies.js +43 -0
- 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/session.js +10 -2
- 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 +154 -33
- 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 +84 -14
- 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/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 +52 -4
- package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +96 -7
- package/node_modules/pi-lens/dist/clients/runtime-context.js +8 -1
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +308 -45
- package/node_modules/pi-lens/dist/clients/runtime-session.js +332 -9
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +217 -22
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +212 -79
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +575 -67
- 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 +157 -24
- package/node_modules/pi-lens/dist/clients/sg-runner.js +116 -22
- package/node_modules/pi-lens/dist/clients/single-flight.js +158 -0
- package/node_modules/pi-lens/dist/clients/stale-marker.js +17 -0
- package/node_modules/pi-lens/dist/clients/startup-timing.js +19 -1
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +151 -16
- package/node_modules/pi-lens/dist/clients/tool-event.js +56 -5
- package/node_modules/pi-lens/dist/clients/tool-policy.js +125 -20
- 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/widget-state.js +336 -36
- package/node_modules/pi-lens/dist/clients/zizmor-config.js +214 -14
- package/node_modules/pi-lens/dist/index.js +67738 -55739
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +466 -54
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +132 -43
- package/node_modules/pi-lens/dist/tools/lsp-navigation.js +46 -7
- package/node_modules/pi-lens/docs/agent-guide.md +6 -1
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +515 -506
- package/node_modules/pi-lens/docs/dispositions.md +21 -0
- package/node_modules/pi-lens/docs/features.md +19 -5
- package/node_modules/pi-lens/docs/globalconfig.md +3 -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 +19 -1
- package/node_modules/pi-lens/docs/usage.md +1 -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 +15 -1
- 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-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 +2 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-apply-test.yml +2 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-get-js-test.yml +2 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-reflect-get-test.yml +2 -1
- 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-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 +57 -12
- 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-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 +22 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-apply.yml +23 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-get-js.yml +33 -5
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-reflect-get.yml +34 -8
- 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 +6 -1
- 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 +53 -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 +2 -0
- package/node_modules/pi-lens/skills/pi-lens-write-ast-grep-rule/SKILL.md +80 -3
- package/node_modules/pi-lens/skills/pi-lens-write-ast-grep-rule/reference.md +41 -0
- package/node_modules/pi-lens/vendor/grammars/tree-sitter-cue.wasm +0 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +36 -0
- package/node_modules/pi-mcp-adapter/README.md +47 -5
- package/node_modules/pi-mcp-adapter/cli.js +163 -1
- package/node_modules/pi-mcp-adapter/commands.ts +128 -22
- package/node_modules/pi-mcp-adapter/config.ts +25 -7
- package/node_modules/pi-mcp-adapter/direct-tools.ts +5 -4
- 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/metadata-cache.ts +32 -21
- package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +168 -0
- package/node_modules/pi-mcp-adapter/package.json +3 -1
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +5 -4
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +31 -37
- package/node_modules/pi-mcp-adapter/search-ranking.ts +92 -22
- package/node_modules/pi-mcp-adapter/server-manager.ts +140 -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-result-renderer.ts +44 -4
- package/node_modules/pi-mcp-adapter/types.ts +2 -0
- 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 +23 -0
- package/node_modules/pi-web-access/README.md +27 -9
- package/node_modules/pi-web-access/anysearch.ts +4 -2
- package/node_modules/pi-web-access/brave.ts +16 -4
- package/node_modules/pi-web-access/curator-page.ts +6 -3
- package/node_modules/pi-web-access/curator-server.ts +4 -1
- package/node_modules/pi-web-access/exa.ts +18 -7
- package/node_modules/pi-web-access/extract.ts +28 -3
- package/node_modules/pi-web-access/gemini-search.ts +16 -4
- package/node_modules/pi-web-access/index.ts +41 -57
- package/node_modules/pi-web-access/package.json +1 -1
- 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 +44 -22
- 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/package.json +13 -13
|
@@ -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
|
+
}
|
|
@@ -24,6 +24,14 @@ export function createDefaultHostPorts(overrides = {}) {
|
|
|
24
24
|
flags: { get: () => undefined },
|
|
25
25
|
tools: { has: async () => false, getActive: () => [], setActive: () => { } },
|
|
26
26
|
};
|
|
27
|
+
// SAFETY: `Object.fromEntries` is typed `Record<string, T>` — it cannot
|
|
28
|
+
// carry the key literals or the per-group value types through. The keys
|
|
29
|
+
// come from `Object.entries(defaults)`, and `defaults` is declared as a
|
|
30
|
+
// complete `HostPorts`, so every group is present; each value is that
|
|
31
|
+
// group's default spread-merged with the same group's override, so no
|
|
32
|
+
// group's member set shrinks. Add a group to `HostPorts` without adding it
|
|
33
|
+
// to `defaults` and this cast becomes a lie, which is why `defaults` is
|
|
34
|
+
// annotated rather than inferred.
|
|
27
35
|
return Object.fromEntries(Object.entries(defaults).map(([group, value]) => [
|
|
28
36
|
group,
|
|
29
37
|
{ ...value, ...(overrides[group] ?? {}) },
|