@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,895 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* helm render — rendered-manifest validation for Helm charts (#1283 Slice B).
|
|
3
|
+
*
|
|
4
|
+
* Slice A (`helm-lint`) checks the chart's SOURCE. This runner checks what the
|
|
5
|
+
* chart actually PRODUCES: it renders the chart with `helm template` and then
|
|
6
|
+
* validates the rendered manifests. Three defect classes only the rendered
|
|
7
|
+
* output can show:
|
|
8
|
+
*
|
|
9
|
+
* 1. **the render itself fails** — a missing `values` key, a nil pointer in a
|
|
10
|
+
* template expression, a dependency declared in `Chart.yaml` but absent
|
|
11
|
+
* from `charts/`. `helm lint` passes on plenty of charts that cannot be
|
|
12
|
+
* installed;
|
|
13
|
+
* 2. **the rendered document is not a Kubernetes object** — a conditional
|
|
14
|
+
* that produced an empty or headless document, so `apiVersion`/`kind` are
|
|
15
|
+
* missing. `helm template` does not require them;
|
|
16
|
+
* 3. **the rendered object is insecure** — privileged containers, missing
|
|
17
|
+
* resource limits, host-path mounts. Trivy's misconfiguration engine reads
|
|
18
|
+
* those off the manifest, and it has never been able to see them for a
|
|
19
|
+
* Helm chart because the manifest did not exist on disk.
|
|
20
|
+
*
|
|
21
|
+
* ## Opt-in, because rendering EXECUTES the chart
|
|
22
|
+
*
|
|
23
|
+
* `helm template` evaluates Go templates from the repository, and a chart can
|
|
24
|
+
* carry `lookup`, `getHostByName`, or arbitrary `tpl` expansion. That is a trust
|
|
25
|
+
* boundary, not a lint, so it is **off by default** and enabled per project:
|
|
26
|
+
*
|
|
27
|
+
* ```json
|
|
28
|
+
* { "helm": { "renderValidation": { "enabled": true } } }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* With the switch absent the runner never spawns anything at all.
|
|
32
|
+
*
|
|
33
|
+
* ## Two gates, because the switch ships INSIDE the repository
|
|
34
|
+
*
|
|
35
|
+
* `.pi-lens.json` is a tracked file, so a cloned repository can arrive with the
|
|
36
|
+
* switch already on — a malicious chart repo would authorize execution of its
|
|
37
|
+
* own templates just by containing the config that says so. Consent from the
|
|
38
|
+
* repo is therefore necessary but not sufficient: the render also requires
|
|
39
|
+
* PROJECT TRUST from the host (`getProjectTrustState()`), the same gate that
|
|
40
|
+
* governs LSP spawns and tool installs. In untrusted mode the runner refuses to
|
|
41
|
+
* spawn and says trust is the reason, rather than skipping silently.
|
|
42
|
+
*
|
|
43
|
+
* The consent lookup is keyed off the WORKSPACE ROOT whose chart is about to
|
|
44
|
+
* run, not `ctx.cwd`. Those differ, and keying on the cwd let an opt-in in one
|
|
45
|
+
* directory authorize rendering a chart belonging to a different project root.
|
|
46
|
+
*
|
|
47
|
+
* The Trivy pass keeps Trivy's OWN consent switch (`trivy.enabled`), because
|
|
48
|
+
* that is the switch that authorizes installing the binary. Opting into
|
|
49
|
+
* rendering therefore gets render + manifest-shape validation; the IaC pass
|
|
50
|
+
* needs both switches. When Trivy is opted in but unavailable, the runner says
|
|
51
|
+
* so as an `info` diagnostic — a missing pass must never read as a clean one.
|
|
52
|
+
*
|
|
53
|
+
* ## No repo writes
|
|
54
|
+
*
|
|
55
|
+
* Rendering goes to a scratch directory under `os.tmpdir()`, removed on every
|
|
56
|
+
* exit path. The chart directory is never touched, and `--dependency-update` is
|
|
57
|
+
* deliberately NOT passed: it would fetch archives into `charts/`. A missing
|
|
58
|
+
* dependency is reported as a finding instead.
|
|
59
|
+
*
|
|
60
|
+
* ## Source mapping
|
|
61
|
+
*
|
|
62
|
+
* A finding the agent cannot locate is noise. Rendered manifests carry helm's
|
|
63
|
+
* own `# Source: <chart>/templates/<file>` annotation, and `--output-dir` mirrors
|
|
64
|
+
* that layout on disk, so every rendered file maps back to the template that
|
|
65
|
+
* produced it. Lines do not survive rendering, so a mapped diagnostic sits at
|
|
66
|
+
* line 1 of the template and names the rendered file and line in its message.
|
|
67
|
+
* When mapping fails the diagnostic attaches to `Chart.yaml` with the rendered
|
|
68
|
+
* path in the message.
|
|
69
|
+
*
|
|
70
|
+
* Refs #1283
|
|
71
|
+
*/
|
|
72
|
+
import * as fs from "node:fs";
|
|
73
|
+
import * as os from "node:os";
|
|
74
|
+
import * as path from "node:path";
|
|
75
|
+
import { logLatency } from "../../latency-logger.js";
|
|
76
|
+
import { PathKeyedMap } from "../../path-keyed-map.js";
|
|
77
|
+
import { normalizeMapKey } from "../../path-utils.js";
|
|
78
|
+
import { loadPiLensProjectConfig } from "../../project-lens-config.js";
|
|
79
|
+
import { getProjectTrustState, projectTrustDenialReason, } from "../../project-trust.js";
|
|
80
|
+
import { safeSpawnAsync } from "../../safe-spawn.js";
|
|
81
|
+
import { isTrivyEnabled, resolveSeverityFloor } from "../../trivy-client.js";
|
|
82
|
+
import { findNearestDirWithMarker } from "../../workspace-topology.js";
|
|
83
|
+
import { PRIORITY } from "../priorities.js";
|
|
84
|
+
import { describeUnavailability } from "./utils/availability-policy.js";
|
|
85
|
+
import { createAvailabilityChecker, resolveAvailableOrInstall, } from "./utils/runner-helpers.js";
|
|
86
|
+
const helm = createAvailabilityChecker("helm", ".exe");
|
|
87
|
+
const trivy = createAvailabilityChecker("trivy", ".exe");
|
|
88
|
+
const inFlightByChartRoot = new PathKeyedMap(normalizeMapKey);
|
|
89
|
+
/**
|
|
90
|
+
* Budget, stated deliberately. Both spawns are sequential, so the runner's own
|
|
91
|
+
* ceiling is their sum plus slack — 85s, in the same band as the other heavy
|
|
92
|
+
* per-edit runners (detekt, golangci-lint, rust-clippy at 90s) rather than above
|
|
93
|
+
* them. The pass re-renders on every edit beneath a chart, with no freshness
|
|
94
|
+
* cache; that cost is the reason the feature is opt-in, and a chart-tree content
|
|
95
|
+
* stamp to skip an unchanged re-render is a tracked follow-up on #1283.
|
|
96
|
+
*/
|
|
97
|
+
const RENDER_TIMEOUT_MS = 30_000;
|
|
98
|
+
const TRIVY_TIMEOUT_MS = 45_000;
|
|
99
|
+
/** Rendered manifests we are willing to read back, so a chart cannot flood us. */
|
|
100
|
+
const MAX_RENDERED_FILES = 400;
|
|
101
|
+
/** Bytes of trivy report we retain. Truncation is reported, never parsed past. */
|
|
102
|
+
const MAX_REPORT_BYTES = 8 * 1024 * 1024;
|
|
103
|
+
const SKIPPED = {
|
|
104
|
+
status: "skipped",
|
|
105
|
+
diagnostics: [],
|
|
106
|
+
semantic: "none",
|
|
107
|
+
};
|
|
108
|
+
function isWithin(root, candidate) {
|
|
109
|
+
const relative = path.relative(normalizeMapKey(root), normalizeMapKey(candidate));
|
|
110
|
+
return (relative === "" ||
|
|
111
|
+
(!relative.startsWith(`..${path.sep}`) &&
|
|
112
|
+
relative !== ".." &&
|
|
113
|
+
!path.isAbsolute(relative)));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Explicit opt-in for rendering. Rendering runs chart-authored template code,
|
|
117
|
+
* so the default is OFF and only an explicit `helm.renderValidation.enabled`
|
|
118
|
+
* in `.pi-lens.json` (the loader walks up, so `~/.pi-lens.json` enables it for
|
|
119
|
+
* every project) turns it on. Exported for tests and gate-before-spawn callers.
|
|
120
|
+
*
|
|
121
|
+
* Pass the WORKSPACE ROOT of the chart about to render, not a process cwd: this
|
|
122
|
+
* answers "did THIS project consent", and reading it from an unrelated cwd let
|
|
123
|
+
* one directory's opt-in authorize another project root's chart.
|
|
124
|
+
*/
|
|
125
|
+
export function isHelmRenderEnabled(workspaceRoot) {
|
|
126
|
+
try {
|
|
127
|
+
const config = loadPiLensProjectConfig(workspaceRoot);
|
|
128
|
+
const helmConfig = config.raw?.helm;
|
|
129
|
+
return helmConfig?.renderValidation?.enabled === true;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Resolve a helm source reference (`<chartName>/templates/x.yaml`, as it appears
|
|
137
|
+
* in `# Source:` annotations and template error messages) to the template file
|
|
138
|
+
* on disk. Helm prefixes every reference with the chart NAME, which is not a
|
|
139
|
+
* directory under the chart root, so the first segment is dropped. Returns null
|
|
140
|
+
* when the result would not be a real file inside the chart.
|
|
141
|
+
*
|
|
142
|
+
* A `# Source:` annotation is content the CHART wrote, which is the same trust
|
|
143
|
+
* boundary the opt-in exists for, so containment has to hold on every OS. The
|
|
144
|
+
* textual `isWithin` fold is not enough on its own: `normalizeFilePath` only
|
|
145
|
+
* canonicalizes through `realpath` on win32, so on Linux and macOS a symlinked
|
|
146
|
+
* template passes the string test and is then followed by `stat`. Two checks
|
|
147
|
+
* close it, and BOTH are needed (recurring defect shape 2 — verify on the CI OS,
|
|
148
|
+
* not the host):
|
|
149
|
+
*
|
|
150
|
+
* * `lstat` for the LEAF: a symlink is not `isFile()`, so a linked template is
|
|
151
|
+
* rejected rather than followed;
|
|
152
|
+
* * `realpath` containment for the ANCESTORS: `lstat` says nothing about a
|
|
153
|
+
* symlinked directory mid-path, so `templates/` (or `charts/child/`) being a
|
|
154
|
+
* link out of the tree would still resolve to a regular file with a
|
|
155
|
+
* perfectly chart-relative textual path.
|
|
156
|
+
*
|
|
157
|
+
* `realChartRoot` lets a caller resolving many references for ONE chart hoist
|
|
158
|
+
* the root's canonicalization out of the loop: at the 400-manifest cap this
|
|
159
|
+
* function runs up to four times per manifest, and the root's realpath is the
|
|
160
|
+
* same answer every time. Omit it and the root is canonicalized per call.
|
|
161
|
+
*/
|
|
162
|
+
export function resolveTemplateSource(sourceRef, chartRoot, realChartRoot) {
|
|
163
|
+
const segments = sourceRef
|
|
164
|
+
.split(/[\\/]+/)
|
|
165
|
+
.filter((segment) => segment && segment !== ".");
|
|
166
|
+
if (segments.length < 2)
|
|
167
|
+
return null;
|
|
168
|
+
const candidate = path.resolve(chartRoot, ...segments.slice(1));
|
|
169
|
+
if (!isWithin(chartRoot, candidate))
|
|
170
|
+
return null;
|
|
171
|
+
try {
|
|
172
|
+
if (!fs.lstatSync(candidate).isFile())
|
|
173
|
+
return null;
|
|
174
|
+
// Canonicalize both sides: comparing a resolved path against an
|
|
175
|
+
// unresolved root would reject every chart that legitimately lives under
|
|
176
|
+
// a symlinked parent (a /tmp or /home symlink, or a linked worktree).
|
|
177
|
+
const root = realChartRoot ?? fs.realpathSync(chartRoot);
|
|
178
|
+
if (!isWithin(root, fs.realpathSync(candidate)))
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return candidate;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Canonicalize a chart root once per pass, for the `realChartRoot` argument
|
|
188
|
+
* above. Falls back to the uncanonicalized root when realpath fails, which
|
|
189
|
+
* keeps containment conservative rather than skipping the check.
|
|
190
|
+
*/
|
|
191
|
+
function canonicalChartRoot(chartRoot) {
|
|
192
|
+
try {
|
|
193
|
+
return fs.realpathSync(chartRoot);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return chartRoot;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function chartYaml(chartRoot) {
|
|
200
|
+
return path.join(chartRoot, "Chart.yaml");
|
|
201
|
+
}
|
|
202
|
+
const HELM_INSTALL_HINT = "https://helm.sh/docs/intro/install/";
|
|
203
|
+
const TRIVY_INSTALL_HINT = "https://trivy.dev/latest/getting-started/installation/";
|
|
204
|
+
/** Helm's own provenance comment, written into every rendered document. */
|
|
205
|
+
const SOURCE_ANNOTATION = /^#\s*Source:\s*(\S+)\s*$/m;
|
|
206
|
+
/** Template extensions a helm source reference can name. */
|
|
207
|
+
const TEMPLATE_EXTENSION = /\.(?:ya?ml|tpl)$/i;
|
|
208
|
+
/**
|
|
209
|
+
* Pull the first `<chart>/templates/x.yaml[:line]` reference out of one line of
|
|
210
|
+
* helm output. Tokenized rather than pattern-matched on purpose: the obvious
|
|
211
|
+
* regex for "a slashed path with an optional `:line`" nests two unbounded
|
|
212
|
+
* negated character classes and backtracks super-linearly on a long error line.
|
|
213
|
+
*/
|
|
214
|
+
export function extractTemplateRef(line) {
|
|
215
|
+
for (const token of line.split(/[\s(),<>"']+/)) {
|
|
216
|
+
const parts = token.split(":");
|
|
217
|
+
const ref = parts[0];
|
|
218
|
+
if (!ref.includes("/"))
|
|
219
|
+
continue;
|
|
220
|
+
if (!TEMPLATE_EXTENSION.test(ref))
|
|
221
|
+
continue;
|
|
222
|
+
const lineNumber = /^\d+$/.test(parts[1] ?? "")
|
|
223
|
+
? Number(parts[1])
|
|
224
|
+
: undefined;
|
|
225
|
+
return { ref, line: lineNumber };
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Where a rendered-manifest finding belongs. Prefer the `# Source:` annotation
|
|
231
|
+
* helm writes into the manifest; fall back to the `--output-dir` layout, which
|
|
232
|
+
* mirrors the same reference as a directory path; fall back to `Chart.yaml`
|
|
233
|
+
* with the rendered path named in the message.
|
|
234
|
+
*/
|
|
235
|
+
export function mapRenderedToSource(options) {
|
|
236
|
+
const { chartRoot, realChartRoot } = options;
|
|
237
|
+
const annotation = SOURCE_ANNOTATION.exec(options.renderedContent);
|
|
238
|
+
if (annotation) {
|
|
239
|
+
const resolved = resolveTemplateSource(annotation[1], chartRoot, realChartRoot);
|
|
240
|
+
if (resolved)
|
|
241
|
+
return { filePath: resolved, mapped: true };
|
|
242
|
+
}
|
|
243
|
+
const relative = path.relative(options.outputDir, options.renderedPath);
|
|
244
|
+
if (relative && !relative.startsWith("..")) {
|
|
245
|
+
const resolved = resolveTemplateSource(relative, chartRoot, realChartRoot);
|
|
246
|
+
if (resolved)
|
|
247
|
+
return { filePath: resolved, mapped: true };
|
|
248
|
+
}
|
|
249
|
+
return { filePath: chartYaml(chartRoot), mapped: false };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Turn a failed `helm template` into findings about the CHART. A render that
|
|
253
|
+
* exits non-zero is a real defect the user needs (#1487): the chart cannot be
|
|
254
|
+
* installed. It is NOT a runner failure — that distinction is made by the
|
|
255
|
+
* caller, on the spawn outcome, before this parser is reached.
|
|
256
|
+
*
|
|
257
|
+
* Helm reports template faults as
|
|
258
|
+
* `Error: template: <chart>/templates/x.yaml:12:9: executing ...` and parse
|
|
259
|
+
* faults as `Error: parse error at (<chart>/templates/x.yaml:5): ...`. Anything
|
|
260
|
+
* unrecognized still becomes one diagnostic on `Chart.yaml`, so a render that
|
|
261
|
+
* failed can never come back empty.
|
|
262
|
+
*/
|
|
263
|
+
export function parseHelmTemplateFailure(raw, chartRoot) {
|
|
264
|
+
const diagnostics = [];
|
|
265
|
+
const text = raw.trim();
|
|
266
|
+
const realRoot = canonicalChartRoot(chartRoot);
|
|
267
|
+
for (const line of text.split(/\r?\n/)) {
|
|
268
|
+
const trimmed = line.trim();
|
|
269
|
+
if (!trimmed.startsWith("Error:"))
|
|
270
|
+
continue;
|
|
271
|
+
const location = extractTemplateRef(trimmed);
|
|
272
|
+
const resolved = location
|
|
273
|
+
? resolveTemplateSource(location.ref, chartRoot, realRoot)
|
|
274
|
+
: null;
|
|
275
|
+
const chartName = path.basename(chartRoot);
|
|
276
|
+
diagnostics.push({
|
|
277
|
+
id: `helm-render-error-${diagnostics.length + 1}`,
|
|
278
|
+
message: resolved
|
|
279
|
+
? trimmed
|
|
280
|
+
: `${trimmed} (helm template failed for chart ${chartName})`,
|
|
281
|
+
filePath: resolved ?? chartYaml(chartRoot),
|
|
282
|
+
line: resolved ? (location?.line ?? 1) : 1,
|
|
283
|
+
column: 1,
|
|
284
|
+
severity: "error",
|
|
285
|
+
semantic: "blocking",
|
|
286
|
+
tool: "helm-render",
|
|
287
|
+
rule: "render-failed",
|
|
288
|
+
fixable: false,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (diagnostics.length === 0) {
|
|
292
|
+
diagnostics.push({
|
|
293
|
+
id: "helm-render-error-1",
|
|
294
|
+
message: `helm template failed: ${(text || "no output").slice(0, 400)}`,
|
|
295
|
+
filePath: chartYaml(chartRoot),
|
|
296
|
+
line: 1,
|
|
297
|
+
column: 1,
|
|
298
|
+
severity: "error",
|
|
299
|
+
semantic: "blocking",
|
|
300
|
+
tool: "helm-render",
|
|
301
|
+
rule: "render-failed",
|
|
302
|
+
fixable: false,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return diagnostics;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Every rendered YAML document must declare `apiVersion` and `kind`. `helm
|
|
309
|
+
* template` does not check this, and a conditional that renders a headless
|
|
310
|
+
* fragment (or nothing but whitespace under a `---`) installs as a no-op that
|
|
311
|
+
* silently drops the object the chart was supposed to create.
|
|
312
|
+
*
|
|
313
|
+
* This is the manifest-shape half of "schema validation". Full OpenAPI schema
|
|
314
|
+
* checking (kubeconform) needs another binary plus installer, availability and
|
|
315
|
+
* gate wiring, and is deliberately out of Slice B's scope.
|
|
316
|
+
*/
|
|
317
|
+
export function checkManifestShape(options) {
|
|
318
|
+
const diagnostics = [];
|
|
319
|
+
const documents = options.renderedContent.split(/^---\s*$/m);
|
|
320
|
+
documents.forEach((document, index) => {
|
|
321
|
+
const meaningful = document
|
|
322
|
+
.split(/\r?\n/)
|
|
323
|
+
.filter((line) => line.trim() && !line.trim().startsWith("#"));
|
|
324
|
+
if (meaningful.length === 0)
|
|
325
|
+
return;
|
|
326
|
+
const missing = [];
|
|
327
|
+
if (!/^apiVersion:\s*\S/m.test(document))
|
|
328
|
+
missing.push("apiVersion");
|
|
329
|
+
if (!/^kind:\s*\S/m.test(document))
|
|
330
|
+
missing.push("kind");
|
|
331
|
+
if (missing.length === 0)
|
|
332
|
+
return;
|
|
333
|
+
const where = options.sourceMapped
|
|
334
|
+
? `rendered ${options.renderedRelativePath}`
|
|
335
|
+
: `rendered ${options.renderedRelativePath} (source template could not be resolved)`;
|
|
336
|
+
diagnostics.push({
|
|
337
|
+
id: `helm-render-shape-${options.renderedRelativePath}-${index}`,
|
|
338
|
+
message: `Rendered document ${index + 1} is missing ${missing.join(" and ")} — it is not a Kubernetes object (${where}).`,
|
|
339
|
+
filePath: options.sourcePath,
|
|
340
|
+
line: 1,
|
|
341
|
+
column: 1,
|
|
342
|
+
severity: "warning",
|
|
343
|
+
semantic: "warning",
|
|
344
|
+
tool: "helm-render",
|
|
345
|
+
rule: "manifest-shape",
|
|
346
|
+
fixable: false,
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
return diagnostics;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Map `trivy config --format json` over the rendered tree onto source
|
|
353
|
+
* templates. Deliberately separate from `trivy-config.ts`'s parser: that one
|
|
354
|
+
* pins every finding to the single file it was handed, while this one has to
|
|
355
|
+
* read each result's `Target` and route it back through the render mapping —
|
|
356
|
+
* and it has to distinguish an unreadable report from an empty one.
|
|
357
|
+
*/
|
|
358
|
+
export function parseRenderedTrivyOutput(raw, locate) {
|
|
359
|
+
if (!raw.trim()) {
|
|
360
|
+
return { understood: false, diagnostics: [], problem: "empty report" };
|
|
361
|
+
}
|
|
362
|
+
let parsed;
|
|
363
|
+
try {
|
|
364
|
+
parsed = JSON.parse(raw);
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return {
|
|
368
|
+
understood: false,
|
|
369
|
+
diagnostics: [],
|
|
370
|
+
problem: "report was not valid JSON",
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
const results = parsed?.Results;
|
|
374
|
+
if (!Array.isArray(results)) {
|
|
375
|
+
return {
|
|
376
|
+
understood: false,
|
|
377
|
+
diagnostics: [],
|
|
378
|
+
problem: "report carried no Results array",
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const diagnostics = [];
|
|
382
|
+
for (const entry of results) {
|
|
383
|
+
if (!entry || typeof entry !== "object")
|
|
384
|
+
continue;
|
|
385
|
+
const target = entry.Target;
|
|
386
|
+
const rows = entry.Misconfigurations;
|
|
387
|
+
if (!Array.isArray(rows))
|
|
388
|
+
continue;
|
|
389
|
+
const located = locate(typeof target === "string" ? target : "");
|
|
390
|
+
for (const row of rows) {
|
|
391
|
+
if (!row || typeof row !== "object")
|
|
392
|
+
continue;
|
|
393
|
+
const misconfig = row;
|
|
394
|
+
const id = typeof misconfig.ID === "string" ? misconfig.ID : undefined;
|
|
395
|
+
if (!id)
|
|
396
|
+
continue;
|
|
397
|
+
const cause = (misconfig.CauseMetadata ?? {});
|
|
398
|
+
const renderedLine = typeof cause.StartLine === "number" && cause.StartLine > 0
|
|
399
|
+
? cause.StartLine
|
|
400
|
+
: undefined;
|
|
401
|
+
const severity = typeof misconfig.Severity === "string"
|
|
402
|
+
? misconfig.Severity.toUpperCase()
|
|
403
|
+
: "UNKNOWN";
|
|
404
|
+
const title = typeof misconfig.Title === "string" && misconfig.Title
|
|
405
|
+
? misconfig.Title
|
|
406
|
+
: id;
|
|
407
|
+
const resolution = typeof misconfig.Resolution === "string" && misconfig.Resolution
|
|
408
|
+
? ` ${misconfig.Resolution}`
|
|
409
|
+
: "";
|
|
410
|
+
const at = renderedLine
|
|
411
|
+
? `${located.detail}:${renderedLine}`
|
|
412
|
+
: located.detail;
|
|
413
|
+
diagnostics.push({
|
|
414
|
+
id: `helm-render-${id}-${diagnostics.length + 1}`,
|
|
415
|
+
message: `[${id}] ${title} (${severity}) in ${at}.${resolution}`.trim(),
|
|
416
|
+
filePath: located.filePath,
|
|
417
|
+
line: 1,
|
|
418
|
+
column: 1,
|
|
419
|
+
severity: severity === "CRITICAL" ? "error" : "warning",
|
|
420
|
+
semantic: severity === "CRITICAL" ? "blocking" : "warning",
|
|
421
|
+
defectClass: "safety",
|
|
422
|
+
tool: "helm-render",
|
|
423
|
+
rule: id,
|
|
424
|
+
fixable: false,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return { understood: true, diagnostics };
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* The runner could not start. Helm is the only tool that can reach this: an
|
|
432
|
+
* absent trivy leaves the render findings standing and is reported as a pass
|
|
433
|
+
* gap instead, so there is no second arm to generalize for.
|
|
434
|
+
*/
|
|
435
|
+
function helmUnavailableResult(cwd) {
|
|
436
|
+
const verdict = helm.getVerdict(cwd);
|
|
437
|
+
return {
|
|
438
|
+
status: "failed",
|
|
439
|
+
diagnostics: [],
|
|
440
|
+
semantic: "warning",
|
|
441
|
+
// One failureKind for both arms — a consumer must read this as "the runner
|
|
442
|
+
// could not start", never as a chart finding. Whether the absence is
|
|
443
|
+
// durable or a probe timeout is the MESSAGE's job, and the availability
|
|
444
|
+
// seam has already logged the decision with its honest cause.
|
|
445
|
+
failureKind: "unavailable",
|
|
446
|
+
failureMessage: describeUnavailability({
|
|
447
|
+
tool: "helm",
|
|
448
|
+
installHint: HELM_INSTALL_HINT,
|
|
449
|
+
outcome: verdict.outcome,
|
|
450
|
+
cause: verdict.cause,
|
|
451
|
+
elapsedMs: verdict.elapsedMs,
|
|
452
|
+
retryAfterMs: verdict.retryAtMs
|
|
453
|
+
? Math.max(0, verdict.retryAtMs - Date.now())
|
|
454
|
+
: undefined,
|
|
455
|
+
}).slice(0, 300),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function failedResult(kind, message) {
|
|
459
|
+
return {
|
|
460
|
+
status: "failed",
|
|
461
|
+
diagnostics: [],
|
|
462
|
+
semantic: "warning",
|
|
463
|
+
failureKind: kind,
|
|
464
|
+
failureMessage: message.slice(0, 200),
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The flags pi-lens itself puts on the command line. If helm complains about one
|
|
469
|
+
* of THESE, the complaint is about us, not about the chart.
|
|
470
|
+
*/
|
|
471
|
+
const OUR_RENDER_FLAGS = ["--output-dir"];
|
|
472
|
+
/**
|
|
473
|
+
* True when helm's output is a rejection of OUR invocation rather than a verdict
|
|
474
|
+
* on the chart: `unknown flag`, `unknown shorthand flag`, `flag provided but not
|
|
475
|
+
* defined`, or an `unknown command`, naming one of our own flags. helm v2 has no
|
|
476
|
+
* `template --output-dir` at all, and a wrapper shim can reject it too. Without
|
|
477
|
+
* this, a tooling mismatch is reported to the user as a broken chart — the #1487
|
|
478
|
+
* lesson inverted.
|
|
479
|
+
*
|
|
480
|
+
* Returns the matched flag (for the message) or null.
|
|
481
|
+
*/
|
|
482
|
+
export function rejectedOurInvocation(output) {
|
|
483
|
+
if (!output)
|
|
484
|
+
return null;
|
|
485
|
+
const complaint = /unknown flag|unknown shorthand flag|flag provided but not defined|unknown command|unrecognized (?:flag|option)/i.test(output);
|
|
486
|
+
if (!complaint)
|
|
487
|
+
return null;
|
|
488
|
+
for (const flag of OUR_RENDER_FLAGS) {
|
|
489
|
+
if (output.includes(flag))
|
|
490
|
+
return flag;
|
|
491
|
+
}
|
|
492
|
+
// A flag complaint that names none of our flags could still be ours (helm
|
|
493
|
+
// wording drift), but it could equally come from a chart's own hook or a
|
|
494
|
+
// plugin. Stay conservative: only OUR flag names buy the runner-error verdict.
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
/** Classify a spawn that never produced a verdict about the chart. */
|
|
498
|
+
function spawnFailureKind(result) {
|
|
499
|
+
const typed = result.spawnFailure?.kind;
|
|
500
|
+
if (typed === "tool-not-found")
|
|
501
|
+
return "unavailable";
|
|
502
|
+
if (typed === "timeout" || result.failure === "timeout")
|
|
503
|
+
return "timeout";
|
|
504
|
+
if (typed === "killed" || result.failure === "aborted")
|
|
505
|
+
return "aborted";
|
|
506
|
+
if (result.failure)
|
|
507
|
+
return "server_error";
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Walk the scratch tree for rendered manifests. `truncated` is load-bearing: a
|
|
512
|
+
* chart bigger than the cap is only PARTLY validated, and a partial pass that
|
|
513
|
+
* reports no findings would read as a clean one (recurring defect shape 10), so
|
|
514
|
+
* the caller turns the flag into a visible diagnostic.
|
|
515
|
+
*
|
|
516
|
+
* `withFileTypes` gives `lstat`-shaped entries, so a symlink is neither
|
|
517
|
+
* `isDirectory()` nor `isFile()` and the walk cannot be led out of the scratch
|
|
518
|
+
* directory. Keep it that way.
|
|
519
|
+
*/
|
|
520
|
+
function collectRenderedFiles(root) {
|
|
521
|
+
const files = [];
|
|
522
|
+
const stack = [root];
|
|
523
|
+
let truncated = false;
|
|
524
|
+
while (stack.length > 0 && !truncated) {
|
|
525
|
+
const dir = stack.pop();
|
|
526
|
+
let entries;
|
|
527
|
+
try {
|
|
528
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
for (const entry of entries) {
|
|
534
|
+
const full = path.join(dir, entry.name);
|
|
535
|
+
if (entry.isDirectory()) {
|
|
536
|
+
stack.push(full);
|
|
537
|
+
}
|
|
538
|
+
else if (entry.isFile() && /\.ya?ml$/i.test(entry.name)) {
|
|
539
|
+
if (files.length >= MAX_RENDERED_FILES) {
|
|
540
|
+
truncated = true;
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
files.push(full);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
files: files.sort((left, right) => left.localeCompare(right)),
|
|
549
|
+
truncated,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function summarize(diagnostics) {
|
|
553
|
+
let semantic = "none";
|
|
554
|
+
if (diagnostics.some((item) => item.severity === "error")) {
|
|
555
|
+
semantic = "blocking";
|
|
556
|
+
}
|
|
557
|
+
else if (diagnostics.length > 0) {
|
|
558
|
+
semantic = "warning";
|
|
559
|
+
}
|
|
560
|
+
return { status: "succeeded", diagnostics, semantic };
|
|
561
|
+
}
|
|
562
|
+
/** Read the rendered tree back and resolve each file to its source template. */
|
|
563
|
+
function readRenderedTree(outputDir, chartRoot) {
|
|
564
|
+
const manifests = [];
|
|
565
|
+
const walk = collectRenderedFiles(outputDir);
|
|
566
|
+
// Hoisted: the chart root's realpath is one answer for the whole pass, and
|
|
567
|
+
// the mapping below asks for it up to four times per manifest.
|
|
568
|
+
const realChartRoot = canonicalChartRoot(chartRoot);
|
|
569
|
+
let unreadable = 0;
|
|
570
|
+
for (const renderedPath of walk.files) {
|
|
571
|
+
let content;
|
|
572
|
+
try {
|
|
573
|
+
content = fs.readFileSync(renderedPath, "utf-8");
|
|
574
|
+
}
|
|
575
|
+
catch {
|
|
576
|
+
unreadable += 1;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const mapping = mapRenderedToSource({
|
|
580
|
+
renderedContent: content,
|
|
581
|
+
renderedPath,
|
|
582
|
+
outputDir,
|
|
583
|
+
chartRoot,
|
|
584
|
+
realChartRoot,
|
|
585
|
+
});
|
|
586
|
+
manifests.push({
|
|
587
|
+
renderedPath,
|
|
588
|
+
relativePath: path.relative(outputDir, renderedPath),
|
|
589
|
+
content,
|
|
590
|
+
sourcePath: mapping.filePath,
|
|
591
|
+
sourceMapped: mapping.mapped,
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
return { manifests, truncated: walk.truncated, unreadable };
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* One `info` diagnostic saying part of the pass did not happen. Zero findings
|
|
598
|
+
* from a pass that did not fully run must never read as a clean pass (recurring
|
|
599
|
+
* defect shape 10), and a silent exclusion needs a record (shape 8).
|
|
600
|
+
*/
|
|
601
|
+
function coverageGap(chartRoot, rule, message) {
|
|
602
|
+
return {
|
|
603
|
+
id: `helm-render-${rule}`,
|
|
604
|
+
message,
|
|
605
|
+
filePath: chartYaml(chartRoot),
|
|
606
|
+
line: 1,
|
|
607
|
+
column: 1,
|
|
608
|
+
severity: "info",
|
|
609
|
+
semantic: "warning",
|
|
610
|
+
tool: "helm-render",
|
|
611
|
+
rule,
|
|
612
|
+
fixable: false,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* The Trivy half of the pass. Returns the findings it produced, or a single gap
|
|
617
|
+
* diagnostic when it could not run — never an empty "clean" answer.
|
|
618
|
+
*
|
|
619
|
+
* Exported for a real-binary regression test (refs #1757) — this is the ONE
|
|
620
|
+
* seam that spawns `trivy config` for the rendered-manifest pass, so an
|
|
621
|
+
* integration test needs to call it directly rather than driving the whole
|
|
622
|
+
* chart-render pipeline (which additionally requires a real `helm` binary).
|
|
623
|
+
*/
|
|
624
|
+
export async function runIacPass(options) {
|
|
625
|
+
const { chartRoot, cwd, outputDir } = options;
|
|
626
|
+
const trivyCmd = await resolveAvailableOrInstall(trivy, "trivy", cwd);
|
|
627
|
+
if (!trivyCmd) {
|
|
628
|
+
const verdict = trivy.getVerdict(cwd);
|
|
629
|
+
return [
|
|
630
|
+
coverageGap(chartRoot, "iac-pass-unavailable", `Rendered-manifest IaC checks did not run: ${describeUnavailability({
|
|
631
|
+
tool: "trivy",
|
|
632
|
+
installHint: TRIVY_INSTALL_HINT,
|
|
633
|
+
outcome: verdict.outcome,
|
|
634
|
+
cause: verdict.cause,
|
|
635
|
+
elapsedMs: verdict.elapsedMs,
|
|
636
|
+
})}`),
|
|
637
|
+
];
|
|
638
|
+
}
|
|
639
|
+
const scan = await safeSpawnAsync(trivyCmd, [
|
|
640
|
+
"config",
|
|
641
|
+
// `--quiet` alone suppresses both the progress bar and log output.
|
|
642
|
+
// `--no-progress` is NOT a `config` subcommand flag (unlike `fs`,
|
|
643
|
+
// which does accept it) — trivy 0.73.0 exits 1 with 7662 bytes of
|
|
644
|
+
// usage text on stdout ("FATAL unknown flag: --no-progress") when
|
|
645
|
+
// it's passed here, which the exit-status check below now catches,
|
|
646
|
+
// but the flag itself made every real invocation of this pass fail
|
|
647
|
+
// before it ever scanned a rendered manifest (refs #1757; verified
|
|
648
|
+
// against the real installed binary, not assumed).
|
|
649
|
+
"--quiet",
|
|
650
|
+
"--format",
|
|
651
|
+
"json",
|
|
652
|
+
"--severity",
|
|
653
|
+
resolveSeverityFloor(cwd).join(","),
|
|
654
|
+
outputDir,
|
|
655
|
+
], {
|
|
656
|
+
cwd,
|
|
657
|
+
timeout: TRIVY_TIMEOUT_MS,
|
|
658
|
+
deadlineAt: Date.now() + TRIVY_TIMEOUT_MS,
|
|
659
|
+
resourceLabel: "helm-render-trivy",
|
|
660
|
+
// The report is the whole rendered tree's misconfigurations; cap what we
|
|
661
|
+
// hold in memory rather than trusting the chart's size (shape 9).
|
|
662
|
+
maxOutputBytes: MAX_REPORT_BYTES,
|
|
663
|
+
});
|
|
664
|
+
const scanFailure = spawnFailureKind(scan);
|
|
665
|
+
// `trivy config` is not given `--exit-code`, so it exits 0 whenever it
|
|
666
|
+
// completed. ANY nonzero status is therefore a real error, with or without
|
|
667
|
+
// something on stdout — the earlier "nonzero AND no output" gate let a
|
|
668
|
+
// half-written report through as a completed pass.
|
|
669
|
+
if (scanFailure || scan.status !== 0) {
|
|
670
|
+
const why = scanFailure ?? `exit ${scan.status}`;
|
|
671
|
+
const detail = (scan.stderr || scan.error?.message || "no output").slice(0, 200);
|
|
672
|
+
return [
|
|
673
|
+
coverageGap(chartRoot, "iac-pass-failed", `Rendered-manifest IaC checks failed to complete (${why}): ${detail}`),
|
|
674
|
+
];
|
|
675
|
+
}
|
|
676
|
+
if (scan.outputTruncated) {
|
|
677
|
+
return [
|
|
678
|
+
coverageGap(chartRoot, "iac-report-unreadable", `Rendered-manifest IaC checks did not run: the trivy report exceeded ${MAX_REPORT_BYTES} bytes and was truncated before parsing.`),
|
|
679
|
+
];
|
|
680
|
+
}
|
|
681
|
+
const sourceByRendered = new PathKeyedMap(normalizeMapKey);
|
|
682
|
+
for (const manifest of options.manifests) {
|
|
683
|
+
sourceByRendered.set(manifest.renderedPath, {
|
|
684
|
+
filePath: manifest.sourcePath,
|
|
685
|
+
detail: manifest.relativePath,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
const report = parseRenderedTrivyOutput(scan.stdout || "", (target) => {
|
|
689
|
+
const hit = sourceByRendered.get(path.resolve(outputDir, target));
|
|
690
|
+
return (hit ?? {
|
|
691
|
+
filePath: chartYaml(chartRoot),
|
|
692
|
+
detail: target || "rendered manifest",
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
if (!report.understood) {
|
|
696
|
+
// trivy exited 0 but we cannot read what it said. "No misconfigurations"
|
|
697
|
+
// and "unreadable report" are different answers (defect shape 10).
|
|
698
|
+
return [
|
|
699
|
+
coverageGap(chartRoot, "iac-report-unreadable", `Rendered-manifest IaC checks produced no readable result (${report.problem}), so the manifests are UNSCANNED rather than clean.`),
|
|
700
|
+
];
|
|
701
|
+
}
|
|
702
|
+
return report.diagnostics;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* One record per render pass, so what this runner did is answerable from
|
|
706
|
+
* latency.log rather than inferred: whether it rendered, how many manifests it
|
|
707
|
+
* validated, whether the walk was truncated, whether the IaC pass was asked
|
|
708
|
+
* for, and how many diagnostics came out. The availability seam logs its own
|
|
709
|
+
* decision, which covers only the tool-probe arm.
|
|
710
|
+
*/
|
|
711
|
+
function logRenderPass(filePath, chartRoot, startedAt, metadata) {
|
|
712
|
+
logLatency({
|
|
713
|
+
type: "phase",
|
|
714
|
+
phase: "helm_render_pass",
|
|
715
|
+
filePath,
|
|
716
|
+
durationMs: Date.now() - startedAt,
|
|
717
|
+
metadata: { chartRoot, ...metadata },
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Remove the scratch tree. Deliberately swallowing: a cleanup that throws out
|
|
722
|
+
* of a `finally` would DISCARD the result the caller was about to return, so a
|
|
723
|
+
* chart with a real blocking finding would be reported as a runner exception
|
|
724
|
+
* with zero diagnostics because temp-dir removal lost a race with an AV scanner
|
|
725
|
+
* (recurring defect shape 10, from the cleanup side). The leak is logged, and
|
|
726
|
+
* the OS reclaims the directory.
|
|
727
|
+
*/
|
|
728
|
+
export function discardScratchDir(outputDir, filePath, remove = (target) => fs.rmSync(target, { recursive: true, force: true })) {
|
|
729
|
+
try {
|
|
730
|
+
remove(outputDir);
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
logLatency({
|
|
734
|
+
type: "phase",
|
|
735
|
+
phase: "helm_render_scratch_leak",
|
|
736
|
+
filePath,
|
|
737
|
+
durationMs: 0,
|
|
738
|
+
metadata: {
|
|
739
|
+
outputDir,
|
|
740
|
+
error: error instanceof Error ? error.message : String(error),
|
|
741
|
+
},
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
async function renderAndValidate(chartRoot, cwd, filePath) {
|
|
746
|
+
const startedAt = Date.now();
|
|
747
|
+
const helmCmd = await resolveAvailableOrInstall(helm, "helm", cwd);
|
|
748
|
+
if (!helmCmd)
|
|
749
|
+
return helmUnavailableResult(cwd);
|
|
750
|
+
const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-lens-helm-render-"));
|
|
751
|
+
try {
|
|
752
|
+
const render = await safeSpawnAsync(helmCmd, ["template", "pi-lens-render", chartRoot, "--output-dir", outputDir], {
|
|
753
|
+
cwd,
|
|
754
|
+
timeout: RENDER_TIMEOUT_MS,
|
|
755
|
+
deadlineAt: Date.now() + RENDER_TIMEOUT_MS,
|
|
756
|
+
resourceLabel: "helm-render",
|
|
757
|
+
});
|
|
758
|
+
const startupFailure = spawnFailureKind(render);
|
|
759
|
+
if (startupFailure) {
|
|
760
|
+
// The runner never got a verdict about the chart. Reporting this as a
|
|
761
|
+
// chart finding would blame the user's chart for our own missing tool
|
|
762
|
+
// (#1487); reporting nothing would read as clean (defect shape 10).
|
|
763
|
+
logRenderPass(filePath, chartRoot, startedAt, {
|
|
764
|
+
outcome: "runner-failed",
|
|
765
|
+
failureKind: startupFailure,
|
|
766
|
+
});
|
|
767
|
+
return failedResult(startupFailure, render.error?.message || `helm template ${startupFailure}`);
|
|
768
|
+
}
|
|
769
|
+
const renderOutput = [render.stdout, render.stderr]
|
|
770
|
+
.filter(Boolean)
|
|
771
|
+
.join("\n");
|
|
772
|
+
if (render.status !== 0) {
|
|
773
|
+
// Before blaming the chart: did helm reject OUR OWN command line? An old
|
|
774
|
+
// helm (v2 has no `helm template --output-dir`) or a wrapper shim exits
|
|
775
|
+
// non-zero on the invocation, which says nothing about the chart.
|
|
776
|
+
// Reporting that as a chart finding is the #1487 inversion, upside down.
|
|
777
|
+
const ourFlag = rejectedOurInvocation(renderOutput);
|
|
778
|
+
if (ourFlag) {
|
|
779
|
+
logRenderPass(filePath, chartRoot, startedAt, {
|
|
780
|
+
outcome: "runner-failed",
|
|
781
|
+
failureKind: "invocation_rejected",
|
|
782
|
+
flag: ourFlag,
|
|
783
|
+
});
|
|
784
|
+
return failedResult("invocation_rejected", `helm rejected pi-lens's own invocation (${ourFlag}); this is a helm/pi-lens compatibility problem, not a chart defect: ${renderOutput.trim().slice(0, 160)}`);
|
|
785
|
+
}
|
|
786
|
+
// A failed RENDER is a real diagnostic: the chart cannot be installed.
|
|
787
|
+
const diagnostics = parseHelmTemplateFailure(renderOutput, chartRoot);
|
|
788
|
+
if (render.outputTruncated) {
|
|
789
|
+
diagnostics.push(coverageGap(chartRoot, "render-truncated", "helm template output was truncated, so this failure report may be incomplete."));
|
|
790
|
+
}
|
|
791
|
+
logRenderPass(filePath, chartRoot, startedAt, {
|
|
792
|
+
outcome: "render-failed",
|
|
793
|
+
diagnostics: diagnostics.length,
|
|
794
|
+
});
|
|
795
|
+
return summarize(diagnostics);
|
|
796
|
+
}
|
|
797
|
+
const tree = readRenderedTree(outputDir, chartRoot);
|
|
798
|
+
const diagnostics = [];
|
|
799
|
+
for (const manifest of tree.manifests) {
|
|
800
|
+
diagnostics.push(...checkManifestShape({
|
|
801
|
+
renderedContent: manifest.content,
|
|
802
|
+
renderedRelativePath: manifest.relativePath,
|
|
803
|
+
sourcePath: manifest.sourcePath,
|
|
804
|
+
sourceMapped: manifest.sourceMapped,
|
|
805
|
+
}));
|
|
806
|
+
}
|
|
807
|
+
if (tree.truncated) {
|
|
808
|
+
// A partly-validated chart reported as clean is the shape-10 trap.
|
|
809
|
+
diagnostics.push(coverageGap(chartRoot, "render-truncated", `This chart rendered more than ${MAX_RENDERED_FILES} manifests; only the first ${MAX_RENDERED_FILES} were validated, so the rest are UNCHECKED rather than clean.`));
|
|
810
|
+
}
|
|
811
|
+
if (tree.unreadable > 0) {
|
|
812
|
+
// Same asymmetry as truncation, one level down: a manifest we could not
|
|
813
|
+
// read back was not validated, so its silence is not evidence.
|
|
814
|
+
diagnostics.push(coverageGap(chartRoot, "rendered-file-unreadable", `${tree.unreadable} rendered manifest(s) could not be read back from the scratch directory and are UNCHECKED rather than clean.`));
|
|
815
|
+
}
|
|
816
|
+
if (tree.manifests.length === 0) {
|
|
817
|
+
// helm exited 0 and produced nothing readable. That is not a clean
|
|
818
|
+
// chart, it is an unknown one — an all-templates-disabled values file,
|
|
819
|
+
// a chart with no templates, or a scratch directory we failed to walk.
|
|
820
|
+
diagnostics.push(coverageGap(chartRoot, "render-empty", "helm template succeeded but produced no manifests to validate, so this chart is UNVALIDATED rather than clean. Check whether the chart's values disable every template."));
|
|
821
|
+
}
|
|
822
|
+
// The IaC pass keeps trivy's own consent switch — that switch authorizes
|
|
823
|
+
// installing the binary and pulling its policy bundle.
|
|
824
|
+
const iacRequested = isTrivyEnabled(cwd);
|
|
825
|
+
if (iacRequested) {
|
|
826
|
+
diagnostics.push(...(await runIacPass({
|
|
827
|
+
chartRoot,
|
|
828
|
+
cwd,
|
|
829
|
+
outputDir,
|
|
830
|
+
manifests: tree.manifests,
|
|
831
|
+
})));
|
|
832
|
+
}
|
|
833
|
+
logRenderPass(filePath, chartRoot, startedAt, {
|
|
834
|
+
outcome: "rendered",
|
|
835
|
+
manifests: tree.manifests.length,
|
|
836
|
+
truncated: tree.truncated,
|
|
837
|
+
unreadable: tree.unreadable,
|
|
838
|
+
iacRequested,
|
|
839
|
+
diagnostics: diagnostics.length,
|
|
840
|
+
});
|
|
841
|
+
return summarize(diagnostics);
|
|
842
|
+
}
|
|
843
|
+
finally {
|
|
844
|
+
discardScratchDir(outputDir, filePath);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
const helmRenderRunner = {
|
|
848
|
+
id: "helm-render",
|
|
849
|
+
appliesTo: ["yaml", "helm-template"],
|
|
850
|
+
priority: PRIORITY.GENERAL_ANALYSIS,
|
|
851
|
+
enabledByDefault: true,
|
|
852
|
+
skipTestFiles: false,
|
|
853
|
+
timeoutMs: RENDER_TIMEOUT_MS + TRIVY_TIMEOUT_MS + 10_000,
|
|
854
|
+
async run(ctx) {
|
|
855
|
+
const cwd = ctx.cwd || process.cwd();
|
|
856
|
+
const workspaceRoot = path.resolve(ctx.projectRoot ?? cwd);
|
|
857
|
+
// Gate 1 — consent, read from the project whose chart would run. Keying
|
|
858
|
+
// this on `cwd` let an opt-in in one directory authorize a DIFFERENT
|
|
859
|
+
// project root's chart.
|
|
860
|
+
if (!isHelmRenderEnabled(workspaceRoot))
|
|
861
|
+
return SKIPPED;
|
|
862
|
+
const startDir = path.dirname(path.resolve(ctx.filePath));
|
|
863
|
+
const discovered = findNearestDirWithMarker(startDir, "chartYamlPath");
|
|
864
|
+
if (!discovered)
|
|
865
|
+
return SKIPPED;
|
|
866
|
+
const chartRoot = path.resolve(discovered);
|
|
867
|
+
if (!isWithin(workspaceRoot, chartRoot))
|
|
868
|
+
return SKIPPED;
|
|
869
|
+
// Gate 2 — project trust. `.pi-lens.json` is a TRACKED file, so consent
|
|
870
|
+
// can arrive inside a cloned repository: a hostile chart repo would
|
|
871
|
+
// authorize execution of its own templates simply by shipping the switch.
|
|
872
|
+
// Trust is the host's answer, not the repo's, so it cannot be forged by
|
|
873
|
+
// content. Same gate as LSP spawns and tool installs.
|
|
874
|
+
if (getProjectTrustState() === "untrusted") {
|
|
875
|
+
// Not a silent skip: the user asked for this pass, and "no findings"
|
|
876
|
+
// must not be how they learn it never ran (defect shape 10).
|
|
877
|
+
logRenderPass(ctx.filePath, chartRoot, Date.now(), {
|
|
878
|
+
outcome: "refused-untrusted",
|
|
879
|
+
});
|
|
880
|
+
return summarize([
|
|
881
|
+
coverageGap(chartRoot, "render-untrusted", `Helm rendered-manifest validation did not run: ${projectTrustDenialReason() ?? "project trust denied"}. Rendering executes this chart's own templates, so it needs host trust in addition to the \`helm.renderValidation.enabled\` switch — and that switch is a tracked file a cloned repository can set for itself.`),
|
|
882
|
+
]);
|
|
883
|
+
}
|
|
884
|
+
const existing = inFlightByChartRoot.get(chartRoot);
|
|
885
|
+
if (existing)
|
|
886
|
+
return existing;
|
|
887
|
+
const promise = renderAndValidate(chartRoot, cwd, ctx.filePath).finally(() => {
|
|
888
|
+
if (inFlightByChartRoot.get(chartRoot) === promise)
|
|
889
|
+
inFlightByChartRoot.delete(chartRoot);
|
|
890
|
+
});
|
|
891
|
+
inFlightByChartRoot.set(chartRoot, promise);
|
|
892
|
+
return promise;
|
|
893
|
+
},
|
|
894
|
+
};
|
|
895
|
+
export default helmRenderRunner;
|