@herbertgao/pi-extensions 2026.8.6 → 2026.8.8
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 +8 -6
- 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 +320 -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 +79 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/hover.ts +27 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +66 -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 +5 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +174 -100
- 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 +5 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +10 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/localization.md +10 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/tool-schema.md +11 -5
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/en.json +5 -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 +140 -97
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +63 -28
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/projections.ts +22 -15
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +11 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +14 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/response-envelope.ts +11 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/types.ts +11 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/multi-select-view.ts +31 -17
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +15 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/wrapping-select.ts +15 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +86 -38
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +76 -9
- 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-plugins/fast-mode/dist/index.mjs +44 -1856
- package/node_modules/@pi-plugins/fast-mode/dist/index.mjs.map +1 -1
- package/node_modules/@pi-plugins/fast-mode/package.json +4 -6
- package/node_modules/pi-lens/CHANGELOG.md +999 -0
- package/node_modules/pi-lens/README.md +117 -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 +381 -13
- 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 +129 -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 +206 -0
- package/node_modules/pi-lens/dist/clients/cache-observability.js +353 -76
- 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 +84 -14
- package/node_modules/pi-lens/dist/clients/demoted-finding-render.js +155 -0
- package/node_modules/pi-lens/dist/clients/dependency-checker.js +25 -3
- package/node_modules/pi-lens/dist/clients/deps/pi-tui.js +8 -2
- package/node_modules/pi-lens/dist/clients/deps/typebox.js +8 -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/detekt.js +9 -6
- 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/hadolint.js +9 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +895 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/htmlhint.js +8 -6
- 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 -2
- package/node_modules/pi-lens/dist/clients/dispatch/runners/mypy.js +25 -2
- package/node_modules/pi-lens/dist/clients/dispatch/runners/oxlint.js +20 -5
- package/node_modules/pi-lens/dist/clients/dispatch/runners/phpstan.js +44 -11
- 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 +17 -8
- package/node_modules/pi-lens/dist/clients/dispatch/runners/sqlfluff.js +32 -4
- package/node_modules/pi-lens/dist/clients/dispatch/runners/stylelint.js +47 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/swiftlint.js +14 -4
- package/node_modules/pi-lens/dist/clients/dispatch/runners/taplo.js +127 -28
- package/node_modules/pi-lens/dist/clients/dispatch/runners/tflint.js +12 -7
- 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 +188 -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 +21 -10
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yamllint.js +18 -2
- 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 +316 -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 +87 -8
- 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 +9 -2
- 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 +128 -8
- package/node_modules/pi-lens/dist/clients/lsp/client.js +1660 -164
- 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 +2423 -151
- 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 +22 -1
- package/node_modules/pi-lens/dist/clients/ndjson-logger.js +114 -23
- 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 +23 -9
- package/node_modules/pi-lens/dist/clients/project-lens-config.js +3 -0
- package/node_modules/pi-lens/dist/clients/project-report.js +62 -27
- 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 +8 -3
- package/node_modules/pi-lens/dist/clients/read-guard.js +253 -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/builder.js +194 -31
- package/node_modules/pi-lens/dist/clients/review-graph/query.js +52 -4
- package/node_modules/pi-lens/dist/clients/review-graph/revision-drift.js +21 -0
- package/node_modules/pi-lens/dist/clients/review-graph/workspace-modules.js +6 -3
- 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 +352 -45
- package/node_modules/pi-lens/dist/clients/runtime-session.js +373 -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 +620 -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/session-event-guard.js +184 -0
- 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/source-filter.js +6 -2
- package/node_modules/pi-lens/dist/clients/stale-marker.js +17 -0
- package/node_modules/pi-lens/dist/clients/startup-scan.js +5 -2
- 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-logger.js +1 -0
- 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 +61407 -48577
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +476 -57
- 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 +27 -10
- 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/scripts/install-selftest.mjs +99 -11
- package/node_modules/pi-lens/scripts/lib/host-provided-deps.mjs +75 -0
- package/node_modules/pi-lens/scripts/lib/warm-loader-cache.mjs +285 -0
- package/node_modules/pi-lens/scripts/warm-loader-cache.mjs +233 -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 +37 -0
- package/node_modules/pi-web-access/README.md +32 -13
- 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/chrome-cookies.ts +86 -15
- 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/data-uri-sanitize.ts +406 -0
- package/node_modules/pi-web-access/exa.ts +18 -7
- package/node_modules/pi-web-access/extract.ts +40 -5
- package/node_modules/pi-web-access/firecrawl.ts +18 -2
- package/node_modules/pi-web-access/gemini-search.ts +16 -4
- package/node_modules/pi-web-access/github-extract.ts +65 -36
- package/node_modules/pi-web-access/index.ts +60 -61
- package/node_modules/pi-web-access/openai-search.ts +17 -6
- 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/pdf-extract.ts +18 -5
- 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/ssrf-protection.ts +12 -2
- 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 +14 -14
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Periodic version refresh for pi-lens's managed tools (#1730, #1747).
|
|
3
|
+
*
|
|
4
|
+
* #1730 covered the npm strategy. #1747 extends the SAME cadence, stamp file,
|
|
5
|
+
* session budget and degradation kind to the other five rather than building a
|
|
6
|
+
* second mechanism: github (27 entries), pip (6), archive (4), maven (1) and
|
|
7
|
+
* gem (1) were all frozen at whatever the installer resolved on day one,
|
|
8
|
+
* because `installTool` only runs when the tool is ABSENT. The only per-
|
|
9
|
+
* strategy difference is the re-resolution step, which lives in
|
|
10
|
+
* `installer/index.ts`'s `refreshManagedTool`.
|
|
11
|
+
*
|
|
12
|
+
* `~/.pi-lens/tools/package.json` records ranges, not versions — `npm install
|
|
13
|
+
* knip` writes `"knip": "^6.4.1"` and a lockfile pinning 6.4.1. Nothing ever
|
|
14
|
+
* re-resolved that range, so the managed copy stayed on the version present at
|
|
15
|
+
* first install for the life of the machine. A managed knip 28 minors behind
|
|
16
|
+
* produced 62 unused-export findings on a tree the same project's own knip
|
|
17
|
+
* reported clean, and acting on those findings deletes live code. Every managed
|
|
18
|
+
* npm tool drifts the same way; a stale pyright or biome is the same wrong
|
|
19
|
+
* verdict, quieter.
|
|
20
|
+
*
|
|
21
|
+
* The policy, and the constraints each part answers:
|
|
22
|
+
*
|
|
23
|
+
* - Bounded. At most `maxPerSession` tools (default 1) are refreshed per
|
|
24
|
+
* session, and each tool is eligible again only once per `intervalMs`
|
|
25
|
+
* (default 7 days). A managed tools tree with 22 entries therefore costs at
|
|
26
|
+
* most one `npm update` spawn per session, never one per run and never a
|
|
27
|
+
* 22-package burst.
|
|
28
|
+
* - Off the hot path. `runManagedToolRefresh` is never awaited by a caller
|
|
29
|
+
* that serves a user request; `runtime-session.ts` schedules it on an
|
|
30
|
+
* unref'd background timer after `session_start` has already returned.
|
|
31
|
+
* - Non-blocking for availability. A refresh failure never removes or hides
|
|
32
|
+
* the installed copy. `npm update` leaves the existing tree in place, and
|
|
33
|
+
* this module never touches `node_modules` itself, so the current version
|
|
34
|
+
* keeps serving.
|
|
35
|
+
* - Re-armed per session, not per process. The per-session budget is keyed to
|
|
36
|
+
* the degradation ledger's session generation, so a long-lived process that
|
|
37
|
+
* serves many `/new` sessions re-checks eligibility each time — and the
|
|
38
|
+
* REAL cooldown lives in the persisted stamp, not in process memory, so a
|
|
39
|
+
* restart loop cannot turn a 7-day cadence into an every-launch one.
|
|
40
|
+
* - Empty is not the same as errored. A missing stamp file means "never
|
|
41
|
+
* refreshed" and makes every tool eligible. An UNREADABLE stamp file means
|
|
42
|
+
* the cadence is unknown; the session degrades once and refreshes nothing,
|
|
43
|
+
* rather than treating unknown as fresh (drift forever) or as stale (a
|
|
44
|
+
* 22-package burst on every session).
|
|
45
|
+
*/
|
|
46
|
+
import * as fs from "node:fs/promises";
|
|
47
|
+
import * as path from "node:path";
|
|
48
|
+
import { recordDegradationOnce } from "../degradation-ledger.js";
|
|
49
|
+
import { commitDurableStoreAsync } from "../durable-store.js";
|
|
50
|
+
import { pmBinary, resolveNodePackageManager, updateArgs, } from "../package-manager.js";
|
|
51
|
+
import { safeSpawnAsync } from "../safe-spawn.js";
|
|
52
|
+
import { logSessionStart } from "../sessionstart-logger.js";
|
|
53
|
+
import { acquireManagedInstallGate, getManagedToolsDir, getRefreshableManagedTools, invalidateManagedToolResolution, isManagedToolPresent, npmToolNeedsPostinstall, refreshManagedTool, resolveManagedNpmBinPath, verifyToolBinary, } from "./index.js";
|
|
54
|
+
import { releaseManagedToolRefreshSlot, reserveManagedToolRefreshSlot, } from "./managed-tool-refresh-session.js";
|
|
55
|
+
const STATE_FILENAME = ".refresh-state.json";
|
|
56
|
+
const STATE_VERSION = 1;
|
|
57
|
+
/** Default per-tool refresh cadence: once a week. */
|
|
58
|
+
const DEFAULT_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
59
|
+
/**
|
|
60
|
+
* Cooldown after a FAILED refresh. Shorter than the success cadence — a failure
|
|
61
|
+
* is usually a transient network or registry problem worth retrying sooner —
|
|
62
|
+
* but still a real cooldown, so a permanently offline machine spawns at most
|
|
63
|
+
* one `npm update` per tool per day rather than one per session.
|
|
64
|
+
*/
|
|
65
|
+
const DEFAULT_RETRY_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
66
|
+
const DEFAULT_MAX_PER_SESSION = 1;
|
|
67
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
68
|
+
function numericEnv(name, fallback) {
|
|
69
|
+
const raw = process.env[name];
|
|
70
|
+
if (raw === undefined)
|
|
71
|
+
return fallback;
|
|
72
|
+
const parsed = Number(raw);
|
|
73
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
74
|
+
}
|
|
75
|
+
function refreshIntervalMs() {
|
|
76
|
+
return numericEnv("PI_LENS_TOOL_REFRESH_INTERVAL_MS", DEFAULT_INTERVAL_MS);
|
|
77
|
+
}
|
|
78
|
+
function retryIntervalMs() {
|
|
79
|
+
return numericEnv("PI_LENS_TOOL_REFRESH_RETRY_MS", DEFAULT_RETRY_INTERVAL_MS);
|
|
80
|
+
}
|
|
81
|
+
function maxPerSession() {
|
|
82
|
+
return numericEnv("PI_LENS_TOOL_REFRESH_MAX_PER_SESSION", DEFAULT_MAX_PER_SESSION);
|
|
83
|
+
}
|
|
84
|
+
function refreshTimeoutMs() {
|
|
85
|
+
return numericEnv("PI_LENS_INSTALL_TIMEOUT_MS", DEFAULT_TIMEOUT_MS);
|
|
86
|
+
}
|
|
87
|
+
function emptyState() {
|
|
88
|
+
return { version: STATE_VERSION, tools: {} };
|
|
89
|
+
}
|
|
90
|
+
export function getManagedToolRefreshStatePath() {
|
|
91
|
+
return path.join(getManagedToolsDir(), STATE_FILENAME);
|
|
92
|
+
}
|
|
93
|
+
/** Coerce one parsed entry, dropping anything whose shape we cannot trust. */
|
|
94
|
+
function parseEntry(value) {
|
|
95
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
const candidate = value;
|
|
99
|
+
if (typeof candidate.checkedAt !== "number")
|
|
100
|
+
return undefined;
|
|
101
|
+
if (!Number.isFinite(candidate.checkedAt))
|
|
102
|
+
return undefined;
|
|
103
|
+
return {
|
|
104
|
+
checkedAt: candidate.checkedAt,
|
|
105
|
+
...(typeof candidate.version === "string" && {
|
|
106
|
+
version: candidate.version,
|
|
107
|
+
}),
|
|
108
|
+
...(typeof candidate.resolutionId === "string" && {
|
|
109
|
+
resolutionId: candidate.resolutionId,
|
|
110
|
+
}),
|
|
111
|
+
...(typeof candidate.etag === "string" && { etag: candidate.etag }),
|
|
112
|
+
...(candidate.failed === true && { failed: true }),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function parseState(contents) {
|
|
116
|
+
const parsed = JSON.parse(contents);
|
|
117
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
118
|
+
throw new Error("refresh-state root is not an object");
|
|
119
|
+
}
|
|
120
|
+
const rawTools = parsed.tools;
|
|
121
|
+
if (!rawTools || typeof rawTools !== "object" || Array.isArray(rawTools)) {
|
|
122
|
+
throw new Error("refresh-state.tools is not an object");
|
|
123
|
+
}
|
|
124
|
+
const tools = {};
|
|
125
|
+
for (const [toolId, value] of Object.entries(rawTools)) {
|
|
126
|
+
const entry = parseEntry(value);
|
|
127
|
+
if (entry)
|
|
128
|
+
tools[toolId] = entry;
|
|
129
|
+
}
|
|
130
|
+
return { version: STATE_VERSION, tools };
|
|
131
|
+
}
|
|
132
|
+
export async function readManagedToolRefreshState() {
|
|
133
|
+
let contents;
|
|
134
|
+
try {
|
|
135
|
+
contents = await fs.readFile(getManagedToolRefreshStatePath(), "utf-8");
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
const code = err.code;
|
|
139
|
+
// ENOENT is the honest "never refreshed" answer. A permission error or a
|
|
140
|
+
// directory in the file's place is NOT — that is unknown cadence.
|
|
141
|
+
if (code === "ENOENT")
|
|
142
|
+
return { status: "empty", state: emptyState() };
|
|
143
|
+
return { status: "unreadable", reason: code ?? "read error" };
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
return { status: "ok", state: parseState(contents) };
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
return { status: "unreadable", reason: err.message };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Commit one tool's stamp under the durable-store lock, merging against
|
|
154
|
+
* whatever a sibling pi-lens process wrote since this process read.
|
|
155
|
+
*
|
|
156
|
+
* A torn or corrupt file is recovered as empty HERE (rather than thrown) so a
|
|
157
|
+
* later commit can replace it. The read path above still reports `unreadable`,
|
|
158
|
+
* which is what suppresses the refresh; this side only has to make sure the
|
|
159
|
+
* file becomes valid again instead of staying corrupt forever.
|
|
160
|
+
*/
|
|
161
|
+
async function writeRefreshStamp(toolId, entry) {
|
|
162
|
+
try {
|
|
163
|
+
await fs.mkdir(getManagedToolsDir(), { recursive: true });
|
|
164
|
+
await commitDurableStoreAsync({
|
|
165
|
+
path: getManagedToolRefreshStatePath(),
|
|
166
|
+
deserialize: (contents) => {
|
|
167
|
+
if (contents === undefined)
|
|
168
|
+
return emptyState();
|
|
169
|
+
try {
|
|
170
|
+
return parseState(contents);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return emptyState();
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
merge: (disk) => {
|
|
177
|
+
disk.tools[toolId] = entry;
|
|
178
|
+
return disk;
|
|
179
|
+
},
|
|
180
|
+
serialize: (disk) => JSON.stringify(disk, null, 2),
|
|
181
|
+
waitMs: 2000,
|
|
182
|
+
retryMs: 25,
|
|
183
|
+
staleMs: 60_000,
|
|
184
|
+
timeoutMessage: "Timed out waiting for managed-tool refresh-state lock",
|
|
185
|
+
onContention: "skip-log",
|
|
186
|
+
logContention: () => {
|
|
187
|
+
logSessionStart(`managed-tool-refresh ${toolId}: stamp deferred because another process owns the lock`);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
// A stamp that cannot be written means this tool is eligible again next
|
|
193
|
+
// session. That is noisier than intended but never wrong, so it degrades
|
|
194
|
+
// rather than throwing into the background timer.
|
|
195
|
+
recordDegradationOnce({
|
|
196
|
+
kind: "managed-tool-refresh",
|
|
197
|
+
subject: toolId,
|
|
198
|
+
reason: `stamp write failed: ${err.message}`,
|
|
199
|
+
});
|
|
200
|
+
logSessionStart(`managed-tool-refresh ${toolId}: stamp write failed (${err.message})`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Record that a tool was just INSTALLED, so the cadence starts from the install
|
|
205
|
+
* (#1747).
|
|
206
|
+
*
|
|
207
|
+
* An install has performed the freshest possible resolution, so leaving the
|
|
208
|
+
* stamp absent would make the refresh treat a brand-new tool as never checked
|
|
209
|
+
* and re-resolve it the moment the timer next fired. Recording the resolution
|
|
210
|
+
* identity here is also what spares the archive and maven entries a redundant
|
|
211
|
+
* re-download: their refresh compares the recorded pin against the registry's,
|
|
212
|
+
* and an install writes exactly the pin it used.
|
|
213
|
+
*
|
|
214
|
+
* Called from `installer/index.ts`'s `finishInstallAttempt` for every strategy
|
|
215
|
+
* EXCEPT npm — npm stamps itself via `stampManagedToolInstalled` below, which
|
|
216
|
+
* also captures the installed version; this funnel would otherwise overwrite
|
|
217
|
+
* that version-bearing stamp with a version-less one milliseconds later.
|
|
218
|
+
*/
|
|
219
|
+
export async function stampManagedToolInstall(toolId, resolutionId, now = Date.now()) {
|
|
220
|
+
await writeRefreshStamp(toolId, {
|
|
221
|
+
checkedAt: now,
|
|
222
|
+
...(resolutionId !== undefined && { resolutionId }),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Stamp a tool as freshly resolved, without refreshing it.
|
|
227
|
+
*
|
|
228
|
+
* Called right after a successful managed npm install (#1746 review F4). An
|
|
229
|
+
* install already resolved the range against the registry seconds ago, so the
|
|
230
|
+
* tool is by definition current. Without this stamp a fresh machine that
|
|
231
|
+
* installs 22 tools on day one has 22 tools with no stamp, and then burns the
|
|
232
|
+
* next 22 sessions running `npm update` on packages installed minutes earlier.
|
|
233
|
+
*
|
|
234
|
+
* Best-effort by design: a missing stamp costs one wasted update, never a
|
|
235
|
+
* wrong version, so it must not fail an install.
|
|
236
|
+
*/
|
|
237
|
+
export async function stampManagedToolInstalled(toolId, packageName, now = Date.now()) {
|
|
238
|
+
const version = await readInstalledVersion(packageName);
|
|
239
|
+
await writeRefreshStamp(toolId, {
|
|
240
|
+
checkedAt: now,
|
|
241
|
+
...(version !== undefined && { version }),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Registry entries that are BOTH refreshable and actually installed where
|
|
246
|
+
* pi-lens installs. An entry pi-lens has never installed has no version to
|
|
247
|
+
* move, and `npm update`, `pip install -U` or a release download on one would
|
|
248
|
+
* turn a refresh into an unrequested install.
|
|
249
|
+
*
|
|
250
|
+
* The presence check is filesystem-only for every strategy (#1747), so scanning
|
|
251
|
+
* all 60-odd registry entries on a background timer costs no spawn and no
|
|
252
|
+
* network.
|
|
253
|
+
*/
|
|
254
|
+
async function installedRefreshCandidates() {
|
|
255
|
+
const candidates = [];
|
|
256
|
+
for (const tool of getRefreshableManagedTools()) {
|
|
257
|
+
if (!(await isManagedToolPresent(tool.toolId)))
|
|
258
|
+
continue;
|
|
259
|
+
candidates.push({
|
|
260
|
+
toolId: tool.toolId,
|
|
261
|
+
strategy: tool.strategy,
|
|
262
|
+
...(tool.packageName !== undefined && { packageName: tool.packageName }),
|
|
263
|
+
...(tool.binaryName !== undefined && { binaryName: tool.binaryName }),
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return candidates;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Which candidates are due, oldest stamp first. A tool with no stamp sorts
|
|
270
|
+
* first (it has never been refreshed); ties break on toolId so the selection
|
|
271
|
+
* is deterministic and a starved tool eventually reaches the front.
|
|
272
|
+
*/
|
|
273
|
+
export function selectStaleTools(candidates, state, now) {
|
|
274
|
+
const interval = refreshIntervalMs();
|
|
275
|
+
const retry = retryIntervalMs();
|
|
276
|
+
const due = candidates.filter((candidate) => {
|
|
277
|
+
const entry = state.tools[candidate.toolId];
|
|
278
|
+
if (!entry)
|
|
279
|
+
return true;
|
|
280
|
+
const cooldown = entry.failed ? retry : interval;
|
|
281
|
+
return now - entry.checkedAt >= cooldown;
|
|
282
|
+
});
|
|
283
|
+
return due.sort((a, b) => {
|
|
284
|
+
const aAt = state.tools[a.toolId]?.checkedAt ?? 0;
|
|
285
|
+
const bAt = state.tools[b.toolId]?.checkedAt ?? 0;
|
|
286
|
+
return aAt !== bAt ? aAt - bAt : a.toolId.localeCompare(b.toolId);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
// --- Refresh ---
|
|
290
|
+
/** Version recorded in an installed package's own `package.json`, if readable. */
|
|
291
|
+
async function readInstalledVersion(packageName) {
|
|
292
|
+
try {
|
|
293
|
+
const raw = await fs.readFile(path.join(getManagedToolsDir(), "node_modules", packageName, "package.json"), "utf-8");
|
|
294
|
+
const parsed = JSON.parse(raw);
|
|
295
|
+
const version = parsed?.version;
|
|
296
|
+
return typeof version === "string" ? version : undefined;
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Refresh one tool, choosing the mechanism its install strategy needs (#1747).
|
|
304
|
+
*
|
|
305
|
+
* npm stays here because it needs the package-manager resolver; every other
|
|
306
|
+
* strategy delegates to `refreshManagedTool` in the installer, which owns the
|
|
307
|
+
* GitHub release query, the `pip install -U` ladder, `gem install`, and the
|
|
308
|
+
* pinned-coordinate comparison for maven/archive. Both halves share ONE budget,
|
|
309
|
+
* ONE stamp file and ONE degradation kind, so adding five strategies does not
|
|
310
|
+
* turn one spawn per session into six.
|
|
311
|
+
*/
|
|
312
|
+
async function refreshOne(candidate, entry, now) {
|
|
313
|
+
return candidate.strategy === "npm"
|
|
314
|
+
? refreshNpmOne(candidate, now)
|
|
315
|
+
: refreshNonNpmOne(candidate, entry, now);
|
|
316
|
+
}
|
|
317
|
+
async function refreshNonNpmOne(candidate, entry, now) {
|
|
318
|
+
const previousVersion = entry?.version;
|
|
319
|
+
const startedAt = Date.now();
|
|
320
|
+
const attempt = await refreshManagedTool(candidate.toolId, {
|
|
321
|
+
...(entry?.resolutionId !== undefined && {
|
|
322
|
+
resolutionId: entry.resolutionId,
|
|
323
|
+
}),
|
|
324
|
+
...(entry?.etag !== undefined && { etag: entry.etag }),
|
|
325
|
+
...(previousVersion !== undefined && { version: previousVersion }),
|
|
326
|
+
});
|
|
327
|
+
const elapsedMs = Date.now() - startedAt;
|
|
328
|
+
if (!attempt.ok) {
|
|
329
|
+
if (attempt.declined) {
|
|
330
|
+
// #1759 review F2: the kill switch or the project-trust gate refused
|
|
331
|
+
// BEFORE any strategy ran — nothing was touched, so this is not a
|
|
332
|
+
// failure. No degradation, and deliberately NO stamp: writing one would
|
|
333
|
+
// apply the 24h retry cooldown to a refusal that has nothing to do with
|
|
334
|
+
// the tool, delaying its next real attempt after the block lifts.
|
|
335
|
+
logSessionStart(`managed-tool-refresh ${candidate.toolId}: ${candidate.strategy} refresh declined after ${elapsedMs}ms (${attempt.reason ?? "unknown"}) — no stamp written, retried next session`);
|
|
336
|
+
return {
|
|
337
|
+
toolId: candidate.toolId,
|
|
338
|
+
strategy: candidate.strategy,
|
|
339
|
+
...(candidate.packageName !== undefined && {
|
|
340
|
+
packageName: candidate.packageName,
|
|
341
|
+
}),
|
|
342
|
+
previousVersion,
|
|
343
|
+
currentVersion: previousVersion,
|
|
344
|
+
changed: false,
|
|
345
|
+
verified: false,
|
|
346
|
+
ok: false,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
// A real failure may have left a stale cached path or probe entry behind
|
|
350
|
+
// (e.g. a partially-cleared install), so the next resolution has to
|
|
351
|
+
// re-probe rather than trust what it had before this attempt (#1759
|
|
352
|
+
// review F1 — the npm path already does this on its own failure branch).
|
|
353
|
+
invalidateManagedToolResolution(candidate.toolId);
|
|
354
|
+
recordDegradationOnce({
|
|
355
|
+
kind: "managed-tool-refresh",
|
|
356
|
+
subject: candidate.toolId,
|
|
357
|
+
reason: `${candidate.strategy} refresh failed: ${attempt.reason ?? "unknown"}`,
|
|
358
|
+
});
|
|
359
|
+
logSessionStart(`managed-tool-refresh ${candidate.toolId}: ${candidate.strategy} refresh failed after ${elapsedMs}ms — keeping ${previousVersion ?? "installed"} (${attempt.reason ?? "unknown"})`);
|
|
360
|
+
await writeRefreshStamp(candidate.toolId, {
|
|
361
|
+
checkedAt: now,
|
|
362
|
+
failed: true,
|
|
363
|
+
...(previousVersion !== undefined && { version: previousVersion }),
|
|
364
|
+
...(entry?.resolutionId !== undefined && {
|
|
365
|
+
resolutionId: entry.resolutionId,
|
|
366
|
+
}),
|
|
367
|
+
// Deliberately NOT carrying `entry.etag` forward: a stamp that replays
|
|
368
|
+
// the validator of a run whose download failed would get a 304 next
|
|
369
|
+
// time and skip the install that never happened.
|
|
370
|
+
});
|
|
371
|
+
return {
|
|
372
|
+
toolId: candidate.toolId,
|
|
373
|
+
strategy: candidate.strategy,
|
|
374
|
+
...(candidate.packageName !== undefined && {
|
|
375
|
+
packageName: candidate.packageName,
|
|
376
|
+
}),
|
|
377
|
+
previousVersion,
|
|
378
|
+
currentVersion: previousVersion,
|
|
379
|
+
changed: false,
|
|
380
|
+
// No spawn to verify for the non-npm strategies — a failed refresh never
|
|
381
|
+
// touched the installed copy, so there is nothing new to check.
|
|
382
|
+
verified: false,
|
|
383
|
+
ok: false,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const currentVersion = attempt.version;
|
|
387
|
+
const changed = !attempt.unchanged;
|
|
388
|
+
await writeRefreshStamp(candidate.toolId, {
|
|
389
|
+
checkedAt: now,
|
|
390
|
+
...(currentVersion !== undefined && { version: currentVersion }),
|
|
391
|
+
...(attempt.resolutionId !== undefined && {
|
|
392
|
+
resolutionId: attempt.resolutionId,
|
|
393
|
+
}),
|
|
394
|
+
...(attempt.etag !== undefined && { etag: attempt.etag }),
|
|
395
|
+
});
|
|
396
|
+
logSessionStart(changed
|
|
397
|
+
? `managed-tool-refresh ${candidate.toolId}: ${previousVersion ?? "unknown"} → ${currentVersion ?? "unknown"} via ${candidate.strategy} (${elapsedMs}ms)`
|
|
398
|
+
: `managed-tool-refresh ${candidate.toolId}: unchanged at ${currentVersion ?? previousVersion ?? "unknown"} via ${candidate.strategy} (${elapsedMs}ms)`);
|
|
399
|
+
return {
|
|
400
|
+
toolId: candidate.toolId,
|
|
401
|
+
strategy: candidate.strategy,
|
|
402
|
+
...(candidate.packageName !== undefined && {
|
|
403
|
+
packageName: candidate.packageName,
|
|
404
|
+
}),
|
|
405
|
+
previousVersion,
|
|
406
|
+
currentVersion,
|
|
407
|
+
changed,
|
|
408
|
+
// `refreshManagedTool` already verifies the artifact it just wrote
|
|
409
|
+
// (`verifyRefreshedArtifact` for github/archive/maven, the `--version`
|
|
410
|
+
// probe for pip/gem) — `ok: true` here already means "and it runs".
|
|
411
|
+
verified: true,
|
|
412
|
+
ok: true,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
async function refreshNpmOne(candidate, now) {
|
|
416
|
+
// Every npm candidate carries a packageName; `getRefreshableManagedTools`
|
|
417
|
+
// drops the ones that do not.
|
|
418
|
+
const packageName = candidate.packageName;
|
|
419
|
+
// #1759 review R2: npm used to spawn `npm update` directly, with none of
|
|
420
|
+
// the kill-switch/trust-gate/lock checks the five other strategies pass
|
|
421
|
+
// through `refreshManagedTool`. Same primitive, same declined-no-op
|
|
422
|
+
// semantics as `refreshNonNpmOne`'s `attempt.declined` branch below: a
|
|
423
|
+
// refusal writes no stamp and records no degradation, so it does not burn
|
|
424
|
+
// the tool's retry cooldown on a block that has nothing to do with it.
|
|
425
|
+
const gateStartedAt = Date.now();
|
|
426
|
+
const gate = await acquireManagedInstallGate(`managed tool refresh: ${candidate.toolId}`);
|
|
427
|
+
if (!gate.ok) {
|
|
428
|
+
logSessionStart(`managed-tool-refresh ${candidate.toolId}: npm refresh declined after ${Date.now() - gateStartedAt}ms (${gate.reason ?? "unknown"}) — no stamp written, retried next session`);
|
|
429
|
+
return {
|
|
430
|
+
toolId: candidate.toolId,
|
|
431
|
+
strategy: "npm",
|
|
432
|
+
packageName,
|
|
433
|
+
changed: false,
|
|
434
|
+
verified: false,
|
|
435
|
+
ok: false,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
return await performNpmRefresh(candidate, packageName, now);
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
await gate.release?.();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
async function performNpmRefresh(candidate, packageName, now) {
|
|
446
|
+
const toolsDir = getManagedToolsDir();
|
|
447
|
+
const previousVersion = await readInstalledVersion(packageName);
|
|
448
|
+
const pm = await resolveNodePackageManager(toolsDir);
|
|
449
|
+
const testNpmScript = process.env.PI_LENS_TEST_MODE === "1"
|
|
450
|
+
? process.env.PI_LENS_TEST_NPM_SCRIPT
|
|
451
|
+
: undefined;
|
|
452
|
+
const command = testNpmScript ? process.execPath : pmBinary(pm);
|
|
453
|
+
const args = [
|
|
454
|
+
...(testNpmScript ? [testNpmScript] : []),
|
|
455
|
+
...updateArgs(pm, packageName, {
|
|
456
|
+
ignoreScripts: !npmToolNeedsPostinstall(packageName),
|
|
457
|
+
}),
|
|
458
|
+
];
|
|
459
|
+
const startedAt = Date.now();
|
|
460
|
+
const spawned = await safeSpawnAsync(command, args, {
|
|
461
|
+
cwd: toolsDir,
|
|
462
|
+
timeout: refreshTimeoutMs(),
|
|
463
|
+
ignoreAmbientSignal: true,
|
|
464
|
+
lifetimeCoupled: true,
|
|
465
|
+
});
|
|
466
|
+
const elapsedMs = Date.now() - startedAt;
|
|
467
|
+
if (spawned.status !== 0 || spawned.error) {
|
|
468
|
+
const reason = (spawned.error?.message ?? spawned.stderr ?? "").slice(0, 200);
|
|
469
|
+
// "Keeping <old version>" would be an unchecked assertion (#1746 review
|
|
470
|
+
// F2). The spawn budget kills the package manager where it stands, which
|
|
471
|
+
// can be mid-write: the tree may hold a new version, a half-written one,
|
|
472
|
+
// or the old one. So report the version that is actually on disk now, and
|
|
473
|
+
// drop the cached resolution either way — a killed package manager can
|
|
474
|
+
// rewrite `.bin` shims without moving the version in `package.json`.
|
|
475
|
+
const onDisk = await readInstalledVersion(packageName);
|
|
476
|
+
invalidateManagedToolResolution(candidate.toolId);
|
|
477
|
+
recordDegradationOnce({
|
|
478
|
+
kind: "managed-tool-refresh",
|
|
479
|
+
subject: candidate.toolId,
|
|
480
|
+
reason: `${pm} update failed: ${reason || "non-zero exit"}`,
|
|
481
|
+
});
|
|
482
|
+
logSessionStart(`managed-tool-refresh ${candidate.toolId}: ${pm} update failed after ${elapsedMs}ms — on disk now ${onDisk ?? "unreadable"} (was ${previousVersion ?? "unknown"}); resolution cache cleared for re-probe (${reason || "non-zero exit"})`);
|
|
483
|
+
await writeRefreshStamp(candidate.toolId, {
|
|
484
|
+
checkedAt: now,
|
|
485
|
+
failed: true,
|
|
486
|
+
...(onDisk !== undefined && { version: onDisk }),
|
|
487
|
+
});
|
|
488
|
+
return {
|
|
489
|
+
toolId: candidate.toolId,
|
|
490
|
+
strategy: "npm",
|
|
491
|
+
packageName,
|
|
492
|
+
previousVersion,
|
|
493
|
+
currentVersion: onDisk,
|
|
494
|
+
changed: onDisk !== undefined && onDisk !== previousVersion,
|
|
495
|
+
verified: false,
|
|
496
|
+
ok: false,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
const currentVersion = await readInstalledVersion(packageName);
|
|
500
|
+
const changed = currentVersion !== undefined && currentVersion !== previousVersion;
|
|
501
|
+
// The update rewrote `node_modules`, so every cached claim about where this
|
|
502
|
+
// tool resolves — the in-memory path cache and the 24h probe cache — is now
|
|
503
|
+
// an assertion about a tree that no longer exists. Drop it BEFORE verifying,
|
|
504
|
+
// so a caller arriving mid-verify re-probes rather than reading the stale
|
|
505
|
+
// entry (#1746 review F2).
|
|
506
|
+
invalidateManagedToolResolution(candidate.toolId);
|
|
507
|
+
// `installNpmTool` treats verification as mandatory: an install that cannot
|
|
508
|
+
// run its own binary is not an install. An UPDATE that leaves an unrunnable
|
|
509
|
+
// binary is the same failure, and it used to pass silently — the version row
|
|
510
|
+
// was written from `package.json` alone, which a half-written tree still
|
|
511
|
+
// answers.
|
|
512
|
+
// Every npm candidate carries a binaryName; `getRefreshableManagedTools`
|
|
513
|
+
// drops npm entries that do not.
|
|
514
|
+
const binaryName = candidate.binaryName;
|
|
515
|
+
const binPath = resolveManagedNpmBinPath(binaryName);
|
|
516
|
+
const verified = await verifyToolBinary(binPath);
|
|
517
|
+
if (!verified) {
|
|
518
|
+
recordDegradationOnce({
|
|
519
|
+
kind: "managed-tool-refresh",
|
|
520
|
+
subject: candidate.toolId,
|
|
521
|
+
reason: `binary failed verification after ${pm} update (${previousVersion ?? "unknown"} → ${currentVersion ?? "unknown"})`,
|
|
522
|
+
});
|
|
523
|
+
// Deliberately NOT removed. `installNpmTool` deletes a freshly installed
|
|
524
|
+
// package that fails verification because nothing was working before it;
|
|
525
|
+
// here a working tool existed a moment ago, and deleting the tree takes it
|
|
526
|
+
// offline for certain rather than probably. The cache invalidation above is
|
|
527
|
+
// what lets `ensureTool`'s own probe-and-repair path see the breakage and
|
|
528
|
+
// reinstall. Stamped as failed so the shorter retry cooldown applies.
|
|
529
|
+
logSessionStart(`managed-tool-refresh ${candidate.toolId}: ${pm} update ran but ${binPath} failed verification — resolution cache cleared for re-probe (${elapsedMs}ms)`);
|
|
530
|
+
await writeRefreshStamp(candidate.toolId, {
|
|
531
|
+
checkedAt: now,
|
|
532
|
+
failed: true,
|
|
533
|
+
...(currentVersion !== undefined && { version: currentVersion }),
|
|
534
|
+
});
|
|
535
|
+
return {
|
|
536
|
+
toolId: candidate.toolId,
|
|
537
|
+
strategy: "npm",
|
|
538
|
+
packageName: candidate.packageName,
|
|
539
|
+
previousVersion,
|
|
540
|
+
currentVersion,
|
|
541
|
+
changed,
|
|
542
|
+
verified: false,
|
|
543
|
+
ok: false,
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
await writeRefreshStamp(candidate.toolId, {
|
|
547
|
+
checkedAt: now,
|
|
548
|
+
...(currentVersion !== undefined && { version: currentVersion }),
|
|
549
|
+
});
|
|
550
|
+
// The observability row #1730 asks for: a wrong verdict from a managed tool
|
|
551
|
+
// can be traced to the version that produced it, and to the moment it moved.
|
|
552
|
+
logSessionStart(changed
|
|
553
|
+
? `managed-tool-refresh ${candidate.toolId}: ${previousVersion ?? "unknown"} → ${currentVersion} via ${pm} update, verified (${elapsedMs}ms)`
|
|
554
|
+
: `managed-tool-refresh ${candidate.toolId}: unchanged at ${currentVersion ?? previousVersion ?? "unknown"} (${elapsedMs}ms)`);
|
|
555
|
+
return {
|
|
556
|
+
toolId: candidate.toolId,
|
|
557
|
+
strategy: "npm",
|
|
558
|
+
packageName,
|
|
559
|
+
previousVersion,
|
|
560
|
+
currentVersion,
|
|
561
|
+
changed,
|
|
562
|
+
verified: true,
|
|
563
|
+
ok: true,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* The refresh currently running in this process, so a second caller joins it
|
|
568
|
+
* instead of starting a rival one.
|
|
569
|
+
*
|
|
570
|
+
* #1746 review F1: `scheduleManagedToolRefresh` arms on EVERY
|
|
571
|
+
* `handleSessionStart`, and an `npm update` can easily outlive the 30s gap to
|
|
572
|
+
* the next session. Without this, two runs raced through the budget check and
|
|
573
|
+
* both spawned a package manager into the same unlocked managed
|
|
574
|
+
* `node_modules`. The join is the same shape `ensureTool` uses for its own
|
|
575
|
+
* duplicate startup requests (`clients/installer/index.ts:4175-4182`, cleared
|
|
576
|
+
* at `:4314-4318`).
|
|
577
|
+
*
|
|
578
|
+
* This is the local form of the single-flight primitive #1753 proposes. When
|
|
579
|
+
* that lands, this is one of its callers.
|
|
580
|
+
*/
|
|
581
|
+
let refreshInFlight = null;
|
|
582
|
+
const noopTap = () => { };
|
|
583
|
+
/**
|
|
584
|
+
* Run one session's worth of managed-tool refresh. Never throws: the caller is
|
|
585
|
+
* a background timer with no one to report to.
|
|
586
|
+
*
|
|
587
|
+
* Concurrent callers share one run. The guard is only process-wide; two pi
|
|
588
|
+
* processes can still refresh at the same time, which the per-tool stamp
|
|
589
|
+
* narrows but does not close. See the PR body for that limit stated plainly.
|
|
590
|
+
*/
|
|
591
|
+
export function runManagedToolRefresh(now = Date.now()) {
|
|
592
|
+
const joined = refreshInFlight;
|
|
593
|
+
if (joined) {
|
|
594
|
+
logSessionStart("managed-tool-refresh: joining the refresh already in flight");
|
|
595
|
+
return joined;
|
|
596
|
+
}
|
|
597
|
+
// No `await` between starting the run and publishing it, so no third caller
|
|
598
|
+
// can slip through and start a second one.
|
|
599
|
+
//
|
|
600
|
+
// The clear is unconditional. An identity check (`if (refreshInFlight ===
|
|
601
|
+
// run)`) is the usual companion to this pattern — `package-manager.ts:225`
|
|
602
|
+
// needs one because its map entry can be replaced by a later caller while an
|
|
603
|
+
// older probe is still settling. This slot cannot: the line below is its only
|
|
604
|
+
// writer, and every other caller returns early while it is non-null, so when
|
|
605
|
+
// this `finally` runs the slot still holds `run`. #1746 review round 2 proved
|
|
606
|
+
// that branch unreachable (mutating it to an unconditional clear failed no
|
|
607
|
+
// test), and a branch no input can take is not a guard.
|
|
608
|
+
const run = executeManagedToolRefresh(now, noopTap).finally(() => {
|
|
609
|
+
refreshInFlight = null;
|
|
610
|
+
});
|
|
611
|
+
refreshInFlight = run;
|
|
612
|
+
return run;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Test-only entry point for `tests/support/reset-explorer.ts`. Calls
|
|
616
|
+
* `executeManagedToolRefresh` directly, bypassing the `refreshInFlight`
|
|
617
|
+
* singleton above — the explorer runs one walk per await point and each must
|
|
618
|
+
* be independent, not coalesced into the previous one. Never call this from
|
|
619
|
+
* production code; production always goes through `runManagedToolRefresh`.
|
|
620
|
+
*/
|
|
621
|
+
export function runManagedToolRefreshForExploration(now, tap) {
|
|
622
|
+
return executeManagedToolRefresh(now, tap);
|
|
623
|
+
}
|
|
624
|
+
async function executeManagedToolRefresh(now, tap = noopTap) {
|
|
625
|
+
if (process.env.PI_LENS_DISABLE_TOOL_REFRESH === "1") {
|
|
626
|
+
return { skipped: "disabled", refreshed: [] };
|
|
627
|
+
}
|
|
628
|
+
// Reserve BEFORE any await. Reading the budget here and spending it after
|
|
629
|
+
// the two reads below is the F1 race; `reserveManagedToolRefreshSlot`
|
|
630
|
+
// checks and takes in one synchronous step, and a run that turns out to
|
|
631
|
+
// have nothing to do hands the slot straight back.
|
|
632
|
+
if (!reserveManagedToolRefreshSlot(maxPerSession())) {
|
|
633
|
+
return { skipped: "session-budget", refreshed: [] };
|
|
634
|
+
}
|
|
635
|
+
// Slots this run HOLDS and has not yet spent. Held slots are given back on
|
|
636
|
+
// every exit that never reached a spawn; a spent slot is gone for good.
|
|
637
|
+
let held = 1;
|
|
638
|
+
const releaseReservation = () => {
|
|
639
|
+
while (held > 0) {
|
|
640
|
+
releaseManagedToolRefreshSlot();
|
|
641
|
+
held -= 1;
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
try {
|
|
645
|
+
const candidates = await installedRefreshCandidates();
|
|
646
|
+
await tap();
|
|
647
|
+
if (candidates.length === 0) {
|
|
648
|
+
releaseReservation();
|
|
649
|
+
return { skipped: "no-candidates", refreshed: [] };
|
|
650
|
+
}
|
|
651
|
+
const read = await readManagedToolRefreshState();
|
|
652
|
+
await tap();
|
|
653
|
+
if (read.status === "unreadable") {
|
|
654
|
+
// Unknown cadence. Refreshing nothing is the only answer that neither
|
|
655
|
+
// drifts forever nor bursts every session; the ledger row is what makes
|
|
656
|
+
// the suppressed cadence visible instead of silent.
|
|
657
|
+
releaseReservation();
|
|
658
|
+
recordDegradationOnce({
|
|
659
|
+
kind: "managed-tool-refresh",
|
|
660
|
+
subject: "refresh-state",
|
|
661
|
+
reason: `refresh state unreadable (${read.reason}); skipping refresh this session`,
|
|
662
|
+
});
|
|
663
|
+
logSessionStart(`managed-tool-refresh: state unreadable (${read.reason}) — no tool refreshed this session`);
|
|
664
|
+
return { skipped: "state-unreadable", refreshed: [] };
|
|
665
|
+
}
|
|
666
|
+
const stale = selectStaleTools(candidates, read.state, now);
|
|
667
|
+
if (stale.length === 0) {
|
|
668
|
+
releaseReservation();
|
|
669
|
+
return { skipped: "nothing-due", refreshed: [] };
|
|
670
|
+
}
|
|
671
|
+
// Top the reservation up to cover this run's whole walk, in ONE
|
|
672
|
+
// synchronous block, and capture the total LOCALLY.
|
|
673
|
+
//
|
|
674
|
+
// #1746 review round 2 (R2-F1): the loop used to call
|
|
675
|
+
// `reserveManagedToolRefreshSlot` again for each tool after the previous
|
|
676
|
+
// tool's awaited refresh. `handleSessionStart` zeroes the global counter,
|
|
677
|
+
// and a session start landing inside a 120s `npm update` therefore re-armed
|
|
678
|
+
// the budget the running loop was still spending. Each further session
|
|
679
|
+
// start bought the same loop another tool, so a long update plus a few
|
|
680
|
+
// `/new` calls walked the entire 22-tool stale list. A local allowance
|
|
681
|
+
// cannot be re-armed by anyone: a mid-run reset restores the SESSION's
|
|
682
|
+
// right to start a new run, which is correct, without extending this one.
|
|
683
|
+
const want = Math.min(maxPerSession(), stale.length);
|
|
684
|
+
while (held < want && reserveManagedToolRefreshSlot(maxPerSession())) {
|
|
685
|
+
held += 1;
|
|
686
|
+
}
|
|
687
|
+
let allowance = held;
|
|
688
|
+
const refreshed = [];
|
|
689
|
+
for (const candidate of stale) {
|
|
690
|
+
// Once a spawn happens the slot is spent for good — a failing tool must
|
|
691
|
+
// not hand its slot to the next candidate and turn a budget of one into
|
|
692
|
+
// 22 spawns.
|
|
693
|
+
if (allowance <= 0)
|
|
694
|
+
break;
|
|
695
|
+
allowance -= 1;
|
|
696
|
+
held -= 1;
|
|
697
|
+
try {
|
|
698
|
+
refreshed.push(await refreshOne(candidate, read.state.tools[candidate.toolId], now));
|
|
699
|
+
await tap();
|
|
700
|
+
}
|
|
701
|
+
catch (err) {
|
|
702
|
+
recordDegradationOnce({
|
|
703
|
+
kind: "managed-tool-refresh",
|
|
704
|
+
subject: candidate.toolId,
|
|
705
|
+
reason: `refresh threw: ${err.message}`,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return { refreshed };
|
|
710
|
+
}
|
|
711
|
+
finally {
|
|
712
|
+
// A throw before any spawn must not leak the reservation.
|
|
713
|
+
releaseReservation();
|
|
714
|
+
}
|
|
715
|
+
}
|