pi-lens 3.8.73 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2614 -12
- package/README.md +50 -21
- package/dist/clients/actionable-warnings.js +73 -18
- package/dist/clients/agent-behavior-client.js +21 -4
- package/dist/clients/ast-grep-client.js +68 -16
- package/dist/clients/ast-grep-types.js +0 -1
- package/dist/clients/ast-grep-yaml-synth.js +37 -10
- package/dist/clients/atomic-write-staging.js +63 -0
- package/dist/clients/atomic-write.js +116 -16
- package/dist/clients/bash-file-access.js +193 -23
- package/dist/clients/biome-client.js +29 -25
- package/dist/clients/bootstrap.js +11 -2
- package/dist/clients/bounded-cache.js +34 -0
- package/dist/clients/bounded-pid-file-lock.js +192 -0
- package/dist/clients/bus-events-logger.js +5 -1
- package/dist/clients/bus-publish.js +10 -3
- package/dist/clients/cache/rule-cache.js +89 -6
- package/dist/clients/cache-manager.js +97 -9
- package/dist/clients/cache-observability.js +498 -0
- package/dist/clients/call-graph.js +460 -108
- package/dist/clients/cascade-logger.js +5 -1
- package/dist/clients/child-unref.js +85 -0
- package/dist/clients/codebase-model.js +52 -23
- package/dist/clients/collateral-test-role.js +40 -0
- package/dist/clients/complexity-client.js +6 -8
- package/dist/clients/console-guard-install.js +14 -0
- package/dist/clients/cooperative-budget.js +42 -0
- package/dist/clients/dead-code-client.js +2 -1
- package/dist/clients/debug-handles.js +206 -0
- package/dist/clients/debug-heap.js +167 -0
- package/dist/clients/degradation-ledger.js +153 -0
- package/dist/clients/dependency-checker.js +466 -63
- package/dist/clients/diagnostic-dispositions.js +83 -13
- package/dist/clients/diagnostics-publish.js +10 -3
- package/dist/clients/dispatch/auxiliary-lsp.js +34 -0
- package/dist/clients/dispatch/dispatcher.js +71 -13
- package/dist/clients/dispatch/fact-store.js +11 -0
- package/dist/clients/dispatch/facts/function-facts.js +37 -7
- package/dist/clients/dispatch/facts/import-facts.js +108 -119
- package/dist/clients/dispatch/facts/tree-sitter-facts.js +12 -12
- package/dist/clients/dispatch/facts/try-catch-facts.js +13 -0
- package/dist/clients/dispatch/indent-detect.js +35 -0
- package/dist/clients/dispatch/inline-suppressions.js +17 -8
- package/dist/clients/dispatch/integration.js +1094 -611
- package/dist/clients/dispatch/lazy.js +14 -0
- package/dist/clients/dispatch/plan.js +11 -1
- package/dist/clients/dispatch/rule-id-normalize.js +50 -0
- package/dist/clients/dispatch/rule-policy.js +135 -0
- package/dist/clients/dispatch/rules/async-noise.js +1 -0
- package/dist/clients/dispatch/rules/unsafe-boundary.js +7 -0
- package/dist/clients/dispatch/runners/ast-grep-napi.js +47 -6
- package/dist/clients/dispatch/runners/biome-check.js +5 -9
- package/dist/clients/dispatch/runners/detekt.js +3 -2
- package/dist/clients/dispatch/runners/hadolint.js +2 -1
- package/dist/clients/dispatch/runners/helm-lint.js +154 -0
- package/dist/clients/dispatch/runners/htmlhint.js +3 -2
- package/dist/clients/dispatch/runners/index.js +5 -1
- package/dist/clients/dispatch/runners/lsp.js +14 -6
- package/dist/clients/dispatch/runners/markdownlint.js +4 -9
- package/dist/clients/dispatch/runners/psscriptanalyzer.js +10 -1
- package/dist/clients/dispatch/runners/pyright.js +9 -5
- package/dist/clients/dispatch/runners/ruff.js +4 -8
- package/dist/clients/dispatch/runners/shellcheck.js +2 -3
- package/dist/clients/dispatch/runners/shfmt.js +2 -3
- package/dist/clients/dispatch/runners/spotbugs.js +2 -1
- package/dist/clients/dispatch/runners/taplo.js +2 -1
- package/dist/clients/dispatch/runners/terragrunt.js +163 -0
- package/dist/clients/dispatch/runners/tflint.js +37 -5
- package/dist/clients/dispatch/runners/tree-sitter.js +155 -166
- package/dist/clients/dispatch/runners/trivy-config.js +13 -7
- package/dist/clients/dispatch/runners/utils/lazy-installer.js +3 -0
- package/dist/clients/dispatch/runners/utils/runner-helpers.js +284 -34
- package/dist/clients/dispatch/runners/utils/spawn-outcome.js +22 -0
- package/dist/clients/dispatch/runners/yaml-rule-parser.js +5 -4
- package/dist/clients/disposition-publish.js +10 -3
- package/dist/clients/durable-store.js +97 -0
- package/dist/clients/event-loop-monitor.js +94 -3
- package/dist/clients/extension-log.js +139 -0
- package/dist/clients/extension-mode.js +73 -0
- package/dist/clients/feature-hints.js +53 -7
- package/dist/clients/file-kinds.js +143 -31
- package/dist/clients/file-role.js +18 -3
- package/dist/clients/file-utils.js +56 -34
- package/dist/clients/fix-worklog.js +14 -2
- package/dist/clients/format-events-publish.js +16 -3
- package/dist/clients/format-service.js +24 -8
- package/dist/clients/formatters-lazy.js +8 -0
- package/dist/clients/formatters.js +358 -61
- package/dist/clients/generated-artifacts.js +169 -15
- package/dist/clients/git-guard.js +681 -11
- package/dist/clients/git-tracked-ignore.js +4 -0
- package/dist/clients/go-client.js +2 -1
- package/dist/clients/govulncheck-client.js +8 -0
- package/dist/clients/grammar-source.js +12 -4
- package/dist/clients/gzip-stage-write.js +102 -0
- package/dist/clients/host-ports.js +31 -0
- package/dist/clients/installer/index.js +733 -213
- package/dist/clients/instance-reaper.js +142 -172
- package/dist/clients/jscpd-client.js +31 -54
- package/dist/clients/knip-client.js +78 -36
- package/dist/clients/language-policy.js +14 -2
- package/dist/clients/language-profile.js +72 -77
- package/dist/clients/latency-logger.js +28 -16
- package/dist/clients/lens-config.js +140 -166
- package/dist/clients/lens-engine.js +124 -21
- package/dist/clients/lens-events.js +27 -4
- package/dist/clients/lens-flag-registry.js +293 -0
- package/dist/clients/lens-map.js +96 -26
- package/dist/clients/live-bus-emitter.js +30 -0
- package/dist/clients/log-cleanup.js +8 -18
- package/dist/clients/lsp/cascade-tier.js +23 -3
- package/dist/clients/lsp/client.js +566 -57
- package/dist/clients/lsp/config.js +74 -10
- package/dist/clients/lsp/diagnostic-binding.js +86 -0
- package/dist/clients/lsp/edits.js +1012 -121
- package/dist/clients/lsp/index.js +1840 -803
- package/dist/clients/lsp/language.js +4 -1
- package/dist/clients/lsp/launch.js +40 -32
- package/dist/clients/lsp/path-utils.js +1 -1
- package/dist/clients/lsp/ruby-drive-dirs.js +83 -0
- package/dist/clients/lsp/server.js +279 -60
- package/dist/clients/lsp/workspace-diagnostics-cache.js +28 -4
- package/dist/clients/lsp-document-symbols.js +112 -0
- package/dist/clients/lsp-lazy.js +8 -0
- package/dist/clients/lsp-mutation.js +248 -0
- package/dist/clients/mcp/analyze.js +128 -36
- package/dist/clients/mcp/ipc.js +157 -24
- package/dist/clients/mcp/review.js +36 -3
- package/dist/clients/mcp/session.js +216 -8
- package/dist/clients/memory-sampler.js +115 -0
- package/dist/clients/metrics-client.js +2 -1
- package/dist/clients/metrics-history.js +2 -1
- package/dist/clients/module-report-lsp.js +5 -0
- package/dist/clients/module-report.js +267 -82
- package/dist/clients/ndjson-logger.js +334 -103
- package/dist/clients/opengrep-client.js +1 -1
- package/dist/clients/partial-edit-apply.js +120 -5
- package/dist/clients/path-keyed-map.js +76 -0
- package/dist/clients/path-utils.js +141 -5
- package/dist/clients/performance-report.js +327 -0
- package/dist/clients/pipeline.js +54 -13
- package/dist/clients/print-mode.js +21 -0
- package/dist/clients/project-changes.js +117 -4
- package/dist/clients/project-diagnostics/cache.js +3 -2
- package/dist/clients/project-diagnostics/extractors.js +26 -115
- package/dist/clients/project-diagnostics/fresh-fetch.js +149 -19
- package/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +117 -0
- package/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +37 -5
- package/dist/clients/project-diagnostics/scanner.js +268 -128
- package/dist/clients/project-lens-config.js +138 -34
- package/dist/clients/project-report.js +64 -25
- package/dist/clients/project-scale.js +8 -10
- package/dist/clients/project-snapshot-persist-worker.js +6 -0
- package/dist/clients/project-snapshot.js +767 -8
- package/dist/clients/project-trust.js +181 -0
- package/dist/clients/quiet-window.js +27 -5
- package/dist/clients/read-bridge.js +147 -0
- package/dist/clients/read-expansion.js +22 -12
- package/dist/clients/read-guard-logger.js +159 -1
- package/dist/clients/read-guard-tool-lines.js +150 -29
- package/dist/clients/read-guard.js +262 -3
- package/dist/clients/redact/secrets.js +449 -0
- package/dist/clients/resource-sampler.js +144 -39
- package/dist/clients/reverse-deps.js +48 -0
- package/dist/clients/review-graph/builder.js +2570 -326
- package/dist/clients/review-graph/git-identity.js +2 -1
- package/dist/clients/review-graph/import-resolvers.js +21 -10
- package/dist/clients/review-graph/persist-worker.js +10 -0
- package/dist/clients/review-graph/query.js +5 -0
- package/dist/clients/review-graph/shared-extraction-ir.js +90 -0
- package/dist/clients/review-graph/symbol-id.js +46 -0
- package/dist/clients/review-graph/tsconfig-paths.js +57 -6
- package/dist/clients/review-graph/workspace-modules.js +51 -3
- package/dist/clients/review-graph-logger.js +53 -0
- package/dist/clients/ruff-client.js +27 -44
- package/dist/clients/runtime-agent-end.js +111 -75
- package/dist/clients/runtime-context.js +36 -12
- package/dist/clients/runtime-coordinator.js +76 -8
- package/dist/clients/runtime-session.js +799 -137
- package/dist/clients/runtime-tool-call.js +117 -62
- package/dist/clients/runtime-tool-result.js +218 -23
- package/dist/clients/runtime-turn.js +284 -40
- package/dist/clients/rust-client.js +2 -1
- package/dist/clients/safe-spawn.js +873 -71
- package/dist/clients/security-scan-client.js +2 -1
- package/dist/clients/session-start-observability.js +15 -0
- package/dist/clients/session-state-store.js +5 -3
- package/dist/clients/sessionstart-logger.js +18 -0
- package/dist/clients/sg-runner.js +284 -159
- package/dist/clients/slow-fs.js +2 -1
- package/dist/clients/smells-rollup.js +224 -0
- package/dist/clients/source-filter.js +231 -43
- package/dist/clients/source-walker.js +66 -10
- package/dist/clients/startup-scan.js +15 -16
- package/dist/clients/startup-timing.js +9 -0
- package/dist/clients/test-runner-client.js +38 -8
- package/dist/clients/todo-scanner.js +30 -3
- package/dist/clients/tool-event.js +35 -0
- package/dist/clients/tool-policy.js +388 -39
- package/dist/clients/tool-render.js +155 -0
- package/dist/clients/tree-sitter-cache.js +153 -140
- package/dist/clients/tree-sitter-client.js +1722 -80
- package/dist/clients/tree-sitter-logger.js +64 -1
- package/dist/clients/tree-sitter-query-loader.js +117 -12
- package/dist/clients/tree-sitter-shared.js +48 -19
- package/dist/clients/tree-sitter-symbol-extractor.js +115 -11
- package/dist/clients/user-notify.js +51 -0
- package/dist/clients/vanished-instance-marker.js +57 -0
- package/dist/clients/warm-attach.js +33 -13
- package/dist/clients/widget-state.js +342 -49
- package/dist/clients/word-index-logger.js +44 -0
- package/dist/clients/word-index.js +612 -68
- package/dist/clients/workspace-topology.js +100 -7
- package/dist/index.js +65923 -47161
- package/dist/mcp/analyze-cli.js +185 -29
- package/dist/mcp/cli.js +110 -0
- package/dist/mcp/server.js +272 -50
- package/dist/tools/ast-grep-search.js +93 -27
- package/dist/tools/lens-diagnostics.js +247 -41
- package/dist/tools/lsp-diagnostics.js +153 -40
- package/dist/tools/lsp-navigation.js +51 -31
- package/dist/tools/module-report.js +9 -0
- package/dist/tools/symbol-search.js +21 -2
- package/docs/agent-guide.md +247 -0
- package/docs/agent-tools.md +21 -10
- package/docs/analysisall.md +192 -0
- package/docs/api-ports-inventory.md +165 -0
- package/docs/ast-grep_rules_catalog.md +5 -2
- package/docs/astplayground.md +3 -4
- package/docs/audit1.md +5 -5
- package/docs/durable-store-audit-1202.md +32 -0
- package/docs/environment-variables.md +197 -11
- package/docs/fable.md +27 -0
- package/docs/features.md +35 -5
- package/docs/globalconfig.md +101 -5
- package/docs/language-coverage.md +6 -5
- package/docs/lsp-capability-matrix.md +2 -2
- package/docs/mcp.md +54 -20
- package/docs/servercapabilities.md +7 -4
- package/docs/settings.md +192 -0
- package/docs/tools.md +18 -1
- package/docs/tree-sitter_rules_catalog.md +11 -31
- package/docs/usage.md +31 -0
- package/package.json +139 -138
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-js-test.yml +1 -0
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-test.yml +2 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-except-test.yml +49 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-host-path-in-win32-branch-test.yml +87 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-nested-links-test.yml +11 -1
- package/rules/ast-grep-rules/rule-tests/no-raw-json-store-write-test.yml +17 -0
- package/rules/ast-grep-rules/rule-tests/no-win32-isabsolute-for-qualification-test.yml +16 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-test.yml +4 -0
- package/rules/ast-grep-rules/rules/hardcoded-url-js.yml +22 -4
- package/rules/ast-grep-rules/rules/hardcoded-url.yml +22 -4
- package/rules/ast-grep-rules/rules/no-bare-except.yml +3 -15
- package/rules/ast-grep-rules/rules/no-bare-host-path-in-win32-branch.yml +25 -0
- package/rules/ast-grep-rules/rules/no-case-declarations-js.yml +4 -3
- package/rules/ast-grep-rules/rules/no-case-declarations.yml +4 -3
- package/rules/ast-grep-rules/rules/no-console-except-error-js.yml +10 -0
- package/rules/ast-grep-rules/rules/no-console-except-error.yml +10 -0
- package/rules/ast-grep-rules/rules/no-javascript-url-js.yml +42 -6
- package/rules/ast-grep-rules/rules/no-javascript-url.yml +42 -6
- package/rules/ast-grep-rules/rules/no-nested-links.yml +7 -0
- package/rules/ast-grep-rules/rules/no-raw-json-store-write.yml +30 -0
- package/rules/ast-grep-rules/rules/no-win32-isabsolute-for-qualification.yml +23 -0
- package/rules/ast-grep-rules/rules/strict-equality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-equality.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality.yml +14 -1
- package/rules/tree-sitter-queries/cpp/no-memset-sensitive-data.yml +9 -3
- package/rules/tree-sitter-queries/cpp/no-scoped-lock-without-args.yml +6 -6
- package/rules/tree-sitter-queries/css/calc-spacing.yml +8 -6
- package/rules/tree-sitter-queries/go/go-mutex-copy.yml +21 -18
- package/rules/tree-sitter-queries/go/go-shared-map-write-goroutine.yml +3 -3
- package/rules/tree-sitter-queries/java/infinite-loop-java.yml +3 -3
- package/rules/tree-sitter-queries/java/junit-call-super.yml +6 -4
- package/rules/tree-sitter-queries/java/no-double-checked-locking.yml +10 -8
- package/rules/tree-sitter-queries/java/no-field-shadowing.yml +1 -1
- package/rules/tree-sitter-queries/java/prepared-statement-valid-indices.yml +2 -3
- package/rules/tree-sitter-queries/java/resources-closed.yml +2 -2
- package/rules/tree-sitter-queries/java/springboot-default-package.yml +6 -3
- package/rules/tree-sitter-queries/java/switch-fall-through.yml +6 -4
- package/rules/tree-sitter-queries/java/switch-non-case-labels.yml +4 -3
- package/rules/tree-sitter-queries/java/tests-include-assertions.yml +6 -5
- package/rules/tree-sitter-queries/javascript/switch-case-termination-js.yml +5 -8
- package/rules/tree-sitter-queries/javascript/switch-non-case-labels.yml +3 -2
- package/rules/tree-sitter-queries/kotlin/prepared-statement-indices.yml +9 -5
- package/rules/tree-sitter-queries/php/this-in-static-context.yml +5 -5
- package/rules/tree-sitter-queries/python/exit-signature-check.yml +2 -9
- package/rules/tree-sitter-queries/python/in-operator-unsupported.yml +3 -4
- package/rules/tree-sitter-queries/python/no-super-torchscript.yml +4 -8
- package/rules/tree-sitter-queries/python/notimplemented-boolean-context.yml +1 -5
- package/rules/tree-sitter-queries/python/python-empty-except.yml +1 -1
- package/rules/tree-sitter-queries/python/return-in-init.yml +0 -2
- package/rules/tree-sitter-queries/python/yield-return-outside-function.yml +0 -3
- package/rules/tree-sitter-queries/ruby/ruby-command-injection.yml +1 -12
- package/rules/tree-sitter-queries/ruby/ruby-eval.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-insecure-deserialization.yml +4 -4
- package/rules/tree-sitter-queries/ruby/ruby-insecure-random.yml +4 -11
- package/rules/tree-sitter-queries/ruby/ruby-open-struct.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-string-eval.yml +2 -3
- package/rules/tree-sitter-queries/ruby/ruby-weak-hash.yml +4 -4
- package/rules/tree-sitter-queries/rust/rust-lock-held-across-await.yml +4 -3
- package/rules/tree-sitter-queries/tsx/no-nested-links.yml +4 -6
- package/rules/tree-sitter-queries/typescript/console-statement.yml +11 -0
- package/rules/tree-sitter-queries/typescript/duplicate-function-arg.yml +4 -9
- package/rules/tree-sitter-queries/typescript/empty-switch-case.yml +13 -9
- package/rules/tree-sitter-queries/typescript/infinite-loop.yml +2 -2
- package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +10 -1
- package/rules/tree-sitter-queries/typescript/switch-case-termination.yml +5 -8
- package/rules/tree-sitter-queries/typescript/ts-insecure-random.yml +7 -10
- package/rules/tree-sitter-queries/typescript/unsafe-regex.yml +4 -2
- package/rules/typos/_typos.toml +17 -0
- package/scripts/analyze-pi-lens-logs.mjs +55 -2
- package/skills/pi-lens-write-tree-sitter-rule/SKILL.md +5 -0
- package/dist/clients/ast-grep-parser.js +0 -86
- package/dist/clients/config-enabled-shape.js +0 -39
- package/dist/clients/lsp/interactive-install.js +0 -367
- package/dist/clients/lsp/lsp-index.js +0 -10
- package/dist/clients/lsp/server-strategies.js +0 -5
- package/dist/clients/project-metadata.js +0 -690
- package/dist/clients/source-groups.js +0 -96
- package/dist/clients/types.js +0 -11
- package/docs/env_variables.md +0 -10
- package/rules/tree-sitter-queries/abap-disabled/delete-where.yml +0 -46
- package/rules/tree-sitter-queries/cpp/no-confused-move-forward.yml +0 -59
- package/rules/tree-sitter-queries/cpp/noexcept-functions.yml +0 -58
- package/rules/tree-sitter-queries/java/mockito-initialized.yml +0 -66
- package/rules/tree-sitter-queries/java/no-wait-notify-on-thread.yml +0 -58
- package/rules/tree-sitter-queries/java/short-circuit-logic.yml +0 -57
- package/rules/tree-sitter-queries/java/spring-session-attributes-setcomplete.yml +0 -75
- package/rules/tree-sitter-queries/plsql-disabled/delete-update-where.yml +0 -56
- package/rules/tree-sitter-queries/plsql-disabled/end-loop-semicolon.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/fetch-bulk-collect-limit.yml +0 -47
- package/rules/tree-sitter-queries/plsql-disabled/forallsave-exceptions.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/nchar-nvarchar2-bytes.yml +0 -54
- package/rules/tree-sitter-queries/plsql-disabled/not-null-initialization.yml +0 -59
- package/rules/tree-sitter-queries/plsql-disabled/raise-application-error-codes.yml +0 -50
- package/rules/tree-sitter-queries/typescript-disabled/ts-path-traversal.yml +0 -71
|
@@ -14,6 +14,7 @@ import { primaryServerId } from "../clients/lsp/config.js";
|
|
|
14
14
|
import { combineAbortSignals, withDeadline } from "../clients/deadline-utils.js";
|
|
15
15
|
import { applyAuxiliarySuppressions, retagAuxiliaryDiagnostics, } from "../clients/dispatch/auxiliary-lsp.js";
|
|
16
16
|
import { detectFileRole } from "../clients/file-role.js";
|
|
17
|
+
import { hashDiagnosticContent, } from "../clients/lsp/diagnostic-binding.js";
|
|
17
18
|
import { classifyCascadeWaitTier } from "../clients/lsp/wait-policy/index.js";
|
|
18
19
|
import { attemptTsserverSyncDiagnostics, } from "../clients/lsp/tsserver-sync.js";
|
|
19
20
|
import { convertLspDiagnostics } from "../clients/dispatch/utils/lsp-diagnostics.js";
|
|
@@ -184,14 +185,30 @@ function projectIgnorePredicate(root) {
|
|
|
184
185
|
return () => false;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
/**
|
|
189
|
+
* #1137: async so a directory read never blocks the event loop (and pi's TUI).
|
|
190
|
+
*
|
|
191
|
+
* This walk was fully synchronous with NO yielding of any kind, bounded only by
|
|
192
|
+
* `maxFiles` *kept* — an ignored-heavy or cloud-backed (OneDrive/network) tree
|
|
193
|
+
* could traverse unboundedly many entries, and a single stalled `readdirSync`
|
|
194
|
+
* held the loop for the whole stall. It is also called once PER LANGUAGE in
|
|
195
|
+
* `runDirectoryDiagnostics`'s `LANG_EXTENSIONS` loop, so a directory-mode
|
|
196
|
+
* `lsp_diagnostics` could pay that cost several times over.
|
|
197
|
+
*
|
|
198
|
+
* The traversal is deliberately still **depth-first with immediate descent**
|
|
199
|
+
* (not the shared stack-based `walkTreeStackAsync`): the `maxFiles` cap makes
|
|
200
|
+
* traversal ORDER observable — a stack walk would keep a different subset of
|
|
201
|
+
* files on an over-large tree. Only scheduling changes here; the returned list
|
|
202
|
+
* is identical. Awaiting each directory read is itself the yield point.
|
|
203
|
+
*/
|
|
204
|
+
async function collectFiles(dir, extensions, maxFiles, isIgnored = () => false) {
|
|
188
205
|
const files = [];
|
|
189
|
-
function walk(current) {
|
|
206
|
+
async function walk(current) {
|
|
190
207
|
if (files.length >= maxFiles)
|
|
191
208
|
return;
|
|
192
209
|
let entries;
|
|
193
210
|
try {
|
|
194
|
-
entries = fs.
|
|
211
|
+
entries = await fs.promises.readdir(current, { withFileTypes: true });
|
|
195
212
|
}
|
|
196
213
|
catch {
|
|
197
214
|
return;
|
|
@@ -204,7 +221,7 @@ function collectFiles(dir, extensions, maxFiles, isIgnored = () => false) {
|
|
|
204
221
|
const full = path.join(current, entry.name);
|
|
205
222
|
if (entry.isDirectory()) {
|
|
206
223
|
if (!isExcludedDirName(entry.name) && !isIgnored(full, true))
|
|
207
|
-
walk(full);
|
|
224
|
+
await walk(full);
|
|
208
225
|
}
|
|
209
226
|
else if (entry.isFile() && extensions.includes(path.extname(full))) {
|
|
210
227
|
if (isIgnored(full, false))
|
|
@@ -213,15 +230,15 @@ function collectFiles(dir, extensions, maxFiles, isIgnored = () => false) {
|
|
|
213
230
|
}
|
|
214
231
|
}
|
|
215
232
|
}
|
|
216
|
-
walk(dir);
|
|
233
|
+
await walk(dir);
|
|
217
234
|
return files;
|
|
218
235
|
}
|
|
219
236
|
export function createLspDiagnosticsTool(
|
|
220
|
-
// #571: same shared write-ordering token source `lens_diagnostics`
|
|
221
|
-
// uses (index.ts injects `() => runtime.nextWriteIndex()`)
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
//
|
|
237
|
+
// #571/#1198: same shared write-ordering token source `lens_diagnostics`
|
|
238
|
+
// mode=full uses (index.ts injects `() => runtime.nextWriteIndex()`). A
|
|
239
|
+
// confirmed result reconciled into the footer reserves its token when the
|
|
240
|
+
// per-file check starts, so settlement order cannot make an older result look
|
|
241
|
+
// newer. Optional/undefined in tests.
|
|
225
242
|
nextWriteIndex) {
|
|
226
243
|
return {
|
|
227
244
|
name: "lsp_diagnostics",
|
|
@@ -419,19 +436,14 @@ nextWriteIndex) {
|
|
|
419
436
|
async function collectDiagnosticsForFile(absPath, lspService, waitMs, serverScope = "all") {
|
|
420
437
|
let timedOut = false;
|
|
421
438
|
let content;
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
// `serverScope: "primary"` never actually skipped the auxiliary scanners
|
|
431
|
-
// (getDiagnostics always queries every registered server for the file).
|
|
432
|
-
// `touched` is only undefined when touchFile itself couldn't produce a
|
|
433
|
-
// result (service destroyed, no clients resolved) — that's the one case
|
|
434
|
-
// that still needs the getDiagnostics() fallback below.
|
|
439
|
+
// `touchFile` is the authoritative collection boundary for every scope: it
|
|
440
|
+
// preserves per-touch timeout, content-binding, and silent-clean confirmation
|
|
441
|
+
// metadata while returning diagnostics from only the requested clients. The
|
|
442
|
+
// legacy openFile/getDiagnostics path remains only for an older/mock service
|
|
443
|
+
// without touchFile, or when touchFile cannot resolve any clients.
|
|
444
|
+
// #1179: the result is an explicit wrapper so side-channel fields survive
|
|
445
|
+
// array copies; confirmation was added when Marksman's lower-level clean verdict
|
|
446
|
+
// proved that a successful empty collection also needs explicit provenance.
|
|
435
447
|
let touched;
|
|
436
448
|
let usedTouch = false;
|
|
437
449
|
try {
|
|
@@ -447,12 +459,26 @@ async function collectDiagnosticsForFile(absPath, lspService, waitMs, serverScop
|
|
|
447
459
|
? attached.response.diagnostics.filter((item) => item.source === primaryServerId(absPath))
|
|
448
460
|
: attached.response.diagnostics;
|
|
449
461
|
const filtered = applyAuxiliarySuppressions(scopedDiagnostics, content, { fileRole: detectFileRole(absPath, content) });
|
|
450
|
-
return {
|
|
462
|
+
return {
|
|
463
|
+
diagnostics: filtered,
|
|
464
|
+
timedOut: false,
|
|
465
|
+
// #1253: the incumbent's touch carries the same confirmation
|
|
466
|
+
// provenance a local touch does (an `available: true` answer is
|
|
467
|
+
// already gated on `fresh && !inconclusive`, but that is NOT
|
|
468
|
+
// evidence a silent-on-clean server was confirmed — only the
|
|
469
|
+
// explicit flag is). The incumbent always touches with
|
|
470
|
+
// `clientScope: "with-auxiliary"`, so this is an AGGREGATE
|
|
471
|
+
// confirmation: it carries the same caveat all-scope local
|
|
472
|
+
// touches do, and classic TypeScript still needs the primary-only
|
|
473
|
+
// tsserver sync check below rather than this verdict.
|
|
474
|
+
confirmedByTouch: attached.response.confirmation === "confirmed" &&
|
|
475
|
+
primaryServerId(absPath) !== "typescript",
|
|
476
|
+
content,
|
|
477
|
+
};
|
|
451
478
|
}
|
|
452
479
|
}
|
|
453
480
|
const serviceWithTouch = lspService;
|
|
454
|
-
if (
|
|
455
|
-
typeof serviceWithTouch.touchFile === "function") {
|
|
481
|
+
if (typeof serviceWithTouch.touchFile === "function") {
|
|
456
482
|
usedTouch = true;
|
|
457
483
|
touched = await serviceWithTouch.touchFile(absPath, content, {
|
|
458
484
|
diagnostics: "document",
|
|
@@ -480,7 +506,7 @@ async function collectDiagnosticsForFile(absPath, lspService, waitMs, serverScop
|
|
|
480
506
|
// serverScope:"primary" actually skip auxiliary scanners and drops the
|
|
481
507
|
// common case back to a single LSP round trip instead of two.
|
|
482
508
|
const diagnostics = usedTouch && touched !== undefined
|
|
483
|
-
? touched
|
|
509
|
+
? touched.diags
|
|
484
510
|
: await lspService.getDiagnostics(absPath, waitMs !== undefined ? "document" : "full");
|
|
485
511
|
// #586: honor each auxiliary profile's native inline-suppression comment
|
|
486
512
|
// (e.g. opengrep's `// nosemgrep`, #441) the same way the per-edit dispatch
|
|
@@ -496,7 +522,18 @@ async function collectDiagnosticsForFile(absPath, lspService, waitMs, serverScop
|
|
|
496
522
|
fileRole: detectFileRole(absPath, content),
|
|
497
523
|
})
|
|
498
524
|
: diagnostics;
|
|
499
|
-
|
|
525
|
+
// #1095: surface the touch's content binding (only the touch path carries
|
|
526
|
+
// one; the openFile-only / getDiagnostics fallback leaves it undefined →
|
|
527
|
+
// "unknown", no demotion).
|
|
528
|
+
const binding = usedTouch ? touched?.binding : undefined;
|
|
529
|
+
const confirmedByTouch = usedTouch && touched?.confirmation === "confirmed";
|
|
530
|
+
return {
|
|
531
|
+
diagnostics: filtered,
|
|
532
|
+
timedOut,
|
|
533
|
+
confirmedByTouch,
|
|
534
|
+
content,
|
|
535
|
+
binding,
|
|
536
|
+
};
|
|
500
537
|
}
|
|
501
538
|
function diagnosticsToFileDiags(file, diagnostics) {
|
|
502
539
|
return diagnostics.map((d) => ({
|
|
@@ -567,6 +604,17 @@ async function resolveEmptyResult(file, lspService) {
|
|
|
567
604
|
return { confirmed: true, diagnostics: [] };
|
|
568
605
|
}
|
|
569
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* A primary-scope touch is authoritative because `touchFile` runs that
|
|
609
|
+
* primary's own confirmation path (including TypeScript's sync fallback). For
|
|
610
|
+
* all-scope TypeScript touches, the aggregate silent-clean gate can settle
|
|
611
|
+
* without that primary-only sync request, so preserve `resolveEmptyResult`'s
|
|
612
|
+
* existing tsserver fallback instead of accepting the aggregate verdict.
|
|
613
|
+
*/
|
|
614
|
+
function canTrustTouchConfirmation(file, serverScope, confirmedByTouch) {
|
|
615
|
+
return (confirmedByTouch &&
|
|
616
|
+
(serverScope === "primary" || primaryServerId(file) !== "typescript"));
|
|
617
|
+
}
|
|
570
618
|
/**
|
|
571
619
|
* #571: reconcile this tool's fresh LSP result into the footer cache
|
|
572
620
|
* (`widget-state.ts`'s `allDiagnostics`) — same shared choke point
|
|
@@ -574,6 +622,11 @@ async function resolveEmptyResult(file, lspService) {
|
|
|
574
622
|
* `reconcileScanDiagnostics`). A manual `lsp_diagnostics` check that proves a
|
|
575
623
|
* stale footer error is actually gone (the real-world case that surfaced
|
|
576
624
|
* #571) is exactly the kind of confirmed result that should correct it.
|
|
625
|
+
* Direct `lsp_diagnostics` deliberately does not perform a second disk read at
|
|
626
|
+
* this reconciliation seam: its collecting touch already read the content and
|
|
627
|
+
* supplies the binding verdict. `false` is unconfirmed and is never written;
|
|
628
|
+
* `true` is trusted, while an absent/`unknown` verdict preserves the legacy
|
|
629
|
+
* fail-open policy for servers that cannot bind their diagnostics to content.
|
|
577
630
|
*
|
|
578
631
|
* `rawDiags` (pre-severity-filter) is what gets written — the footer records
|
|
579
632
|
* the true known state, independent of this call's display-only severity
|
|
@@ -592,8 +645,22 @@ async function resolveEmptyResult(file, lspService) {
|
|
|
592
645
|
* /skipTestFiles-filtered at write time — an empty string here is then a safe
|
|
593
646
|
* no-op re-check, not a behavior gap).
|
|
594
647
|
*/
|
|
595
|
-
function reconcileWidgetFromLspResult(file, rawDiags, confirmation,
|
|
596
|
-
|
|
648
|
+
function reconcileWidgetFromLspResult(file, rawDiags, confirmation, writeIndex, cwd, content,
|
|
649
|
+
// #1095: true when the result's content binding demonstrably mismatches disk
|
|
650
|
+
// (boundToCurrentDisk === false). Such a result — even a NON-EMPTY one, which
|
|
651
|
+
// the pre-#1095 "non-empty is definitionally confirmed" doctrine would have
|
|
652
|
+
// written straight through — must NOT re-cement the footer with a stale view
|
|
653
|
+
// (#1092's window-1 transcript: 17 live-looking diagnostics while tsc exits
|
|
654
|
+
// 0). "unknown"/true bindings leave the doctrine unchanged (fallback preserved
|
|
655
|
+
// for servers that never bind a version).
|
|
656
|
+
boundMismatch = false,
|
|
657
|
+
// #1093: when these `rawDiags` were actually OBSERVED. Fresh touches observe
|
|
658
|
+
// now (`undefined` → `Date.now()`); a cache HIT replays diagnostics scanned
|
|
659
|
+
// earlier, so its caller passes the cache entry's `scannedAt` here so the
|
|
660
|
+
// footer's `touchedAt` isn't re-armed to now() and the mtime-staleness gate
|
|
661
|
+
// stays live (the #1092 re-arming defect).
|
|
662
|
+
observedAt) {
|
|
663
|
+
const confirmed = (rawDiags.length > 0 || confirmation !== "unconfirmed") && !boundMismatch;
|
|
597
664
|
if (!confirmed)
|
|
598
665
|
return;
|
|
599
666
|
try {
|
|
@@ -603,7 +670,7 @@ function reconcileWidgetFromLspResult(file, rawDiags, confirmation, nextWriteInd
|
|
|
603
670
|
scanOrigin: "lsp_diagnostics",
|
|
604
671
|
});
|
|
605
672
|
const retagged = retagAuxiliaryDiagnostics(diagnostics, rawDiags, content ?? "", { cwd, fileRole: detectFileRole(file, content) });
|
|
606
|
-
reconcileScanDiagnostics(file, retagged, true,
|
|
673
|
+
reconcileScanDiagnostics(file, retagged, true, writeIndex, observedAt);
|
|
607
674
|
}
|
|
608
675
|
catch {
|
|
609
676
|
// Never let a footer-reconciliation hiccup fail the diagnostics check.
|
|
@@ -621,6 +688,10 @@ cacheCtx, scopeKey,
|
|
|
621
688
|
// `process.cwd()` for any call site that predates this (there are none
|
|
622
689
|
// today besides the two below, both of which now pass it explicitly).
|
|
623
690
|
cwd = process.cwd()) {
|
|
691
|
+
// Reserve the ordering token when this diagnostic operation starts, not when
|
|
692
|
+
// its LSP promise settles. A slower old result must not receive a newer token
|
|
693
|
+
// merely because it completed later (#1198).
|
|
694
|
+
const writeIndex = nextWriteIndex?.();
|
|
624
695
|
let stat;
|
|
625
696
|
try {
|
|
626
697
|
stat = fs.statSync(file);
|
|
@@ -633,14 +704,27 @@ cwd = process.cwd()) {
|
|
|
633
704
|
}
|
|
634
705
|
if (cacheCtx && scopeKey !== undefined) {
|
|
635
706
|
const cached = cacheCtx.lookup(file, scopeKey);
|
|
636
|
-
|
|
707
|
+
// #1095: a cached entry whose content binding demonstrably mismatches disk
|
|
708
|
+
// (bytes changed without the mtime bump the freshness gate would catch) is
|
|
709
|
+
// NOT served — fall through to a fresh touch instead of replaying a stale
|
|
710
|
+
// cached result. "unknown"/true bindings serve as before.
|
|
711
|
+
if (cached && cached.binding.boundToCurrentDisk !== false) {
|
|
637
712
|
const filteredDiags = applySeverityFilter(cached.diagnostics, severity);
|
|
638
713
|
const confirmation = cached.diagnostics.length === 0 ? "clean" : undefined;
|
|
639
714
|
// #692: cached.diagnostics were already suppression-/skipTestFiles-
|
|
640
715
|
// filtered at write time (this same code path); no file content was
|
|
641
716
|
// cached alongside them, so `undefined` here is a safe re-check, not
|
|
642
717
|
// a gap.
|
|
643
|
-
|
|
718
|
+
// #1093: this is a CACHE HIT — a replay of an OLD observation. Stamp the
|
|
719
|
+
// footer's `touchedAt` with the cache entry's original `scannedAt`, NOT
|
|
720
|
+
// now(), or a repeat check that only re-serves the cache would keep
|
|
721
|
+
// re-arming the mtime-staleness gate and a resolved finding would render
|
|
722
|
+
// forever (the #1092 defect).
|
|
723
|
+
reconcileWidgetFromLspResult(file, cached.diagnostics, confirmation, writeIndex, cwd, undefined,
|
|
724
|
+
// This branch only runs when the cache binding is not a mismatch
|
|
725
|
+
// (guarded above), so boundMismatch is false; #1093's observedAt is
|
|
726
|
+
// the cache entry's original scan time.
|
|
727
|
+
false, cached.scannedAt);
|
|
644
728
|
return {
|
|
645
729
|
file,
|
|
646
730
|
diagnostics: diagnosticsToFileDiags(file, filteredDiags),
|
|
@@ -649,7 +733,7 @@ cwd = process.cwd()) {
|
|
|
649
733
|
};
|
|
650
734
|
}
|
|
651
735
|
}
|
|
652
|
-
const { diagnostics: rawDiags, timedOut, content: collectedContent, } = await collectDiagnosticsForFile(file, lspService, waitMs, serverScope);
|
|
736
|
+
const { diagnostics: rawDiags, timedOut, confirmedByTouch, content: collectedContent, binding, } = await collectDiagnosticsForFile(file, lspService, waitMs, serverScope);
|
|
653
737
|
const health = lspService.getDiagnosticsHealth?.(file);
|
|
654
738
|
// #570: a timed-out priming check is never a confirmed "clean" — treat it
|
|
655
739
|
// as unconfirmed without consulting the (unrelated) silent-tier
|
|
@@ -665,6 +749,11 @@ cwd = process.cwd()) {
|
|
|
665
749
|
confirmation = "unconfirmed";
|
|
666
750
|
}
|
|
667
751
|
}
|
|
752
|
+
else if (canTrustTouchConfirmation(file, serverScope, confirmedByTouch)) {
|
|
753
|
+
if (applySeverityFilter(rawDiags, severity).length === 0) {
|
|
754
|
+
confirmation = "clean";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
668
757
|
else if (rawDiags.length === 0) {
|
|
669
758
|
const resolved = await resolveEmptyResult(file, lspService);
|
|
670
759
|
effectiveRawDiags = resolved.diagnostics;
|
|
@@ -677,16 +766,26 @@ cwd = process.cwd()) {
|
|
|
677
766
|
else if (applySeverityFilter(rawDiags, severity).length === 0) {
|
|
678
767
|
confirmation = await classifyEmptyResult(file, lspService);
|
|
679
768
|
}
|
|
769
|
+
// #1095: a result whose content binding demonstrably mismatches disk is
|
|
770
|
+
// demoted to "unconfirmed" — it must neither confirm the footer nor be cached
|
|
771
|
+
// as clean, regardless of how many diagnostics it carries (the #1092
|
|
772
|
+
// re-cementing path). "unknown"/true bindings leave the verdict untouched.
|
|
773
|
+
const boundMismatch = binding?.boundToCurrentDisk === false;
|
|
774
|
+
if (boundMismatch)
|
|
775
|
+
confirmation = "unconfirmed";
|
|
680
776
|
const filteredDiags = applySeverityFilter(effectiveRawDiags, severity);
|
|
681
|
-
reconcileWidgetFromLspResult(file, effectiveRawDiags, confirmation,
|
|
777
|
+
reconcileWidgetFromLspResult(file, effectiveRawDiags, confirmation, writeIndex, cwd, collectedContent, boundMismatch);
|
|
682
778
|
// #671: only a CONFIRMED outcome ("clean", or a non-empty result — either
|
|
683
779
|
// is definitionally confirmed per this function's own doctrine above) is
|
|
684
780
|
// safe to cache; "unconfirmed" (timeout OR a silent-tier server's
|
|
685
781
|
// unescapable empty push) must never be persisted as a cacheable clean
|
|
686
782
|
// result — same false-clean bug class `runWorkspaceDiagnostics`'s cache
|
|
687
|
-
// wiring guards against.
|
|
783
|
+
// wiring guards against. #1095: the entry carries the content fingerprint so a
|
|
784
|
+
// later lookup can verify it against disk beyond the mtime proxy.
|
|
688
785
|
if (cacheCtx && scopeKey !== undefined && confirmation !== "unconfirmed") {
|
|
689
|
-
cacheCtx.record(file, scopeKey, effectiveRawDiags, stat.mtimeMs
|
|
786
|
+
cacheCtx.record(file, scopeKey, effectiveRawDiags, stat.mtimeMs, collectedContent !== undefined
|
|
787
|
+
? hashDiagnosticContent(collectedContent)
|
|
788
|
+
: undefined);
|
|
690
789
|
}
|
|
691
790
|
return {
|
|
692
791
|
file,
|
|
@@ -698,7 +797,10 @@ cwd = process.cwd()) {
|
|
|
698
797
|
};
|
|
699
798
|
}
|
|
700
799
|
async function runFileDiagnostics(absPath, severity, lspService, waitMs, nextWriteIndex, serverScope = "all", cwd = process.cwd()) {
|
|
701
|
-
|
|
800
|
+
// Reserve the token before awaiting this file's LSP result. The direct-file
|
|
801
|
+
// path performs its own confirmation/reconciliation below (#1198).
|
|
802
|
+
const writeIndex = nextWriteIndex?.();
|
|
803
|
+
const { diagnostics: rawDiags, timedOut, confirmedByTouch, content: collectedContent, binding, } = await collectDiagnosticsForFile(absPath, lspService, waitMs, serverScope);
|
|
702
804
|
const lspHealth = lspService.getDiagnosticsHealth?.(absPath);
|
|
703
805
|
const unavailable = lspUnavailableMessage(absPath, lspHealth);
|
|
704
806
|
// #533: an empty result needs a confirmed/unconfirmed verdict — a push-only,
|
|
@@ -717,6 +819,11 @@ async function runFileDiagnostics(absPath, severity, lspService, waitMs, nextWri
|
|
|
717
819
|
confirmation = "unconfirmed";
|
|
718
820
|
}
|
|
719
821
|
}
|
|
822
|
+
else if (canTrustTouchConfirmation(absPath, serverScope, confirmedByTouch)) {
|
|
823
|
+
if (applySeverityFilter(rawDiags, severity).length === 0) {
|
|
824
|
+
confirmation = "clean";
|
|
825
|
+
}
|
|
826
|
+
}
|
|
720
827
|
else if (rawDiags.length === 0) {
|
|
721
828
|
const resolved = await resolveEmptyResult(absPath, lspService);
|
|
722
829
|
effectiveRawDiags = resolved.diagnostics;
|
|
@@ -729,12 +836,18 @@ async function runFileDiagnostics(absPath, severity, lspService, waitMs, nextWri
|
|
|
729
836
|
else if (applySeverityFilter(rawDiags, severity).length === 0) {
|
|
730
837
|
confirmation = await classifyEmptyResult(absPath, lspService);
|
|
731
838
|
}
|
|
839
|
+
// #1095: demote a result whose content binding mismatches disk to
|
|
840
|
+
// "unconfirmed" (the #1092 re-cementing path) — a non-empty stale result is no
|
|
841
|
+
// longer "definitionally confirmed". "unknown"/true bindings are unchanged.
|
|
842
|
+
const boundMismatch = binding?.boundToCurrentDisk === false;
|
|
843
|
+
if (boundMismatch)
|
|
844
|
+
confirmation = "unconfirmed";
|
|
732
845
|
const filtered = applySeverityFilter(effectiveRawDiags, severity);
|
|
733
846
|
const total = filtered.length;
|
|
734
847
|
const truncated = total > MAX_DIAGNOSTICS;
|
|
735
848
|
const limited = truncated ? filtered.slice(0, MAX_DIAGNOSTICS) : filtered;
|
|
736
849
|
const unconfirmed = confirmation === "unconfirmed";
|
|
737
|
-
reconcileWidgetFromLspResult(absPath, effectiveRawDiags, confirmation,
|
|
850
|
+
reconcileWidgetFromLspResult(absPath, effectiveRawDiags, confirmation, writeIndex, cwd, collectedContent, boundMismatch);
|
|
738
851
|
const primaryId = primaryServerId(absPath);
|
|
739
852
|
const primaryDiags = limited.filter((d) => d.source === primaryId);
|
|
740
853
|
const auxiliaryDiags = limited.filter((d) => d.source !== primaryId);
|
|
@@ -1072,7 +1185,7 @@ async function runDirectoryDiagnostics(absPath, severity, lspService, options) {
|
|
|
1072
1185
|
let collectedFiles = [];
|
|
1073
1186
|
const isIgnored = projectIgnorePredicate(absPath);
|
|
1074
1187
|
for (const [ext, exts] of Object.entries(LANG_EXTENSIONS)) {
|
|
1075
|
-
collectedFiles = collectFiles(absPath, exts, MAX_FILES + 1, isIgnored);
|
|
1188
|
+
collectedFiles = await collectFiles(absPath, exts, MAX_FILES + 1, isIgnored);
|
|
1076
1189
|
if (collectedFiles.length > 0) {
|
|
1077
1190
|
extension = ext;
|
|
1078
1191
|
break;
|
|
@@ -8,10 +8,12 @@ import * as path from "node:path";
|
|
|
8
8
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
9
|
import { Type } from "../clients/deps/typebox.js";
|
|
10
10
|
import { logLatency } from "../clients/latency-logger.js";
|
|
11
|
+
import { newLspMutationCorrelationId, recordLspMutationOutcome, } from "../clients/lsp-mutation.js";
|
|
11
12
|
import { compactRenderResult } from "./render-compact.js";
|
|
12
13
|
import { applyWorkspaceEdit, summarizeWorkspaceEdit, } from "../clients/lsp/edits.js";
|
|
13
14
|
import { getLSPService } from "../clients/lsp/index.js";
|
|
14
15
|
import { buildLspNavigationEnvelope } from "./lsp-structured-output.js";
|
|
16
|
+
import { SYMBOL_KIND_NAMES } from "../clients/lsp-document-symbols.js";
|
|
15
17
|
const VALID_OPERATIONS = [
|
|
16
18
|
"definition",
|
|
17
19
|
"typeDefinition",
|
|
@@ -249,35 +251,11 @@ function tokenAtPosition(content, line1, char1) {
|
|
|
249
251
|
.trim();
|
|
250
252
|
return token.length > 0 ? token : undefined;
|
|
251
253
|
}
|
|
252
|
-
const SYMBOL_KIND_LABELS = {
|
|
253
|
-
2: "module",
|
|
254
|
-
3: "namespace",
|
|
255
|
-
4: "package",
|
|
256
|
-
5: "class",
|
|
257
|
-
6: "method",
|
|
258
|
-
7: "property",
|
|
259
|
-
8: "field",
|
|
260
|
-
9: "constructor",
|
|
261
|
-
10: "enum",
|
|
262
|
-
11: "interface",
|
|
263
|
-
12: "function",
|
|
264
|
-
13: "variable",
|
|
265
|
-
14: "constant",
|
|
266
|
-
15: "string",
|
|
267
|
-
16: "number",
|
|
268
|
-
17: "boolean",
|
|
269
|
-
18: "array",
|
|
270
|
-
19: "object",
|
|
271
|
-
20: "key",
|
|
272
|
-
21: "null",
|
|
273
|
-
22: "enumMember",
|
|
274
|
-
23: "struct",
|
|
275
|
-
24: "event",
|
|
276
|
-
25: "operator",
|
|
277
|
-
26: "typeParameter",
|
|
278
|
-
};
|
|
279
254
|
function symbolKindLabel(kind) {
|
|
280
|
-
|
|
255
|
+
// Single source of truth for LSP SymbolKind names (#883 doctrine; the
|
|
256
|
+
// Sonar-flagged duplicate table lived here). Navigation keeps its own
|
|
257
|
+
// "symbol" fallback for unknown kinds instead of the lsp-symbol-<n> form.
|
|
258
|
+
return kind == null ? "symbol" : (SYMBOL_KIND_NAMES[kind] ?? "symbol");
|
|
281
259
|
}
|
|
282
260
|
function rangeStart(range) {
|
|
283
261
|
const start = range?.start;
|
|
@@ -573,7 +551,7 @@ export function createLspNavigationTool(
|
|
|
573
551
|
* constructed in; callers that only have a single fixed project root (e.g.
|
|
574
552
|
* pi's own `getLensFlag`) may ignore the second argument.
|
|
575
553
|
*/
|
|
576
|
-
getFlag) {
|
|
554
|
+
getFlag, mutationDeps) {
|
|
577
555
|
return {
|
|
578
556
|
name: "lsp_navigation",
|
|
579
557
|
label: "LSP Navigate",
|
|
@@ -698,7 +676,15 @@ getFlag) {
|
|
|
698
676
|
let supported = null;
|
|
699
677
|
let diagnosticsMode = "unknown";
|
|
700
678
|
let columnResolution;
|
|
679
|
+
let mutationContext;
|
|
680
|
+
let requestedApply = false;
|
|
701
681
|
const finalize = (payload, meta) => {
|
|
682
|
+
if (payload.isError &&
|
|
683
|
+
requestedApply &&
|
|
684
|
+
mutationContext &&
|
|
685
|
+
["rename", "rename_file", "executeCommand"].includes(meta.operation)) {
|
|
686
|
+
recordLspMutationOutcome(mutationContext, "failed");
|
|
687
|
+
}
|
|
702
688
|
const normalizedFilePath = meta.filePath.replace(/\\/g, "/");
|
|
703
689
|
logLatency({
|
|
704
690
|
type: "phase",
|
|
@@ -782,6 +768,21 @@ getFlag) {
|
|
|
782
768
|
});
|
|
783
769
|
}
|
|
784
770
|
const operation = normalizedOperation;
|
|
771
|
+
requestedApply = apply === true;
|
|
772
|
+
if (requestedApply &&
|
|
773
|
+
["rename", "rename_file", "executeCommand"].includes(operation)) {
|
|
774
|
+
const cwd = ctx.cwd || ".";
|
|
775
|
+
mutationContext = {
|
|
776
|
+
cwd,
|
|
777
|
+
correlationId: newLspMutationCorrelationId(_toolCallId),
|
|
778
|
+
tool: "lsp_navigation",
|
|
779
|
+
source: "lsp-edit",
|
|
780
|
+
...mutationDeps,
|
|
781
|
+
readGuard: getFlag("no-read-guard", cwd)
|
|
782
|
+
? undefined
|
|
783
|
+
: mutationDeps?.readGuard,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
785
786
|
const isCallHierarchyTraversal = operation === "incomingCalls" || operation === "outgoingCalls";
|
|
786
787
|
const needsFilePath = operation !== "workspaceDiagnostics" &&
|
|
787
788
|
operation !== "workspaceSymbol" &&
|
|
@@ -1083,7 +1084,7 @@ getFlag) {
|
|
|
1083
1084
|
edit,
|
|
1084
1085
|
};
|
|
1085
1086
|
}
|
|
1086
|
-
const applied = await applyWorkspaceEdit(edit, ctx.cwd || ".");
|
|
1087
|
+
const applied = await applyWorkspaceEdit(edit, ctx.cwd || ".", { mutationContext });
|
|
1087
1088
|
for (const touchedFile of applied.files) {
|
|
1088
1089
|
try {
|
|
1089
1090
|
await openFileBestEffort(lspService, touchedFile, false);
|
|
@@ -1104,6 +1105,7 @@ getFlag) {
|
|
|
1104
1105
|
const result = await lspService.renameFile(filePath, resolvedNewFilePath, {
|
|
1105
1106
|
cwd: ctx.cwd || ".",
|
|
1106
1107
|
apply: apply ?? false,
|
|
1108
|
+
...(mutationContext ? { mutationContext } : {}),
|
|
1107
1109
|
});
|
|
1108
1110
|
if (result.applied) {
|
|
1109
1111
|
for (const touchedFile of result.files ?? []) {
|
|
@@ -1145,7 +1147,7 @@ getFlag) {
|
|
|
1145
1147
|
if (!isAdvertised) {
|
|
1146
1148
|
throw new Error(`__UNSUPPORTED__ command "${command}" is not advertised by the active LSP server (advertised: ${advertised.join(", ") || "none"})`);
|
|
1147
1149
|
}
|
|
1148
|
-
return lspService.executeCommand(rawPath ? filePath : undefined, command, commandArguments);
|
|
1150
|
+
return lspService.executeCommand(rawPath ? filePath : undefined, command, commandArguments, mutationContext);
|
|
1149
1151
|
}
|
|
1150
1152
|
case "incomingCalls": {
|
|
1151
1153
|
if (!callHierarchyItem) {
|
|
@@ -1200,6 +1202,24 @@ getFlag) {
|
|
|
1200
1202
|
}
|
|
1201
1203
|
}
|
|
1202
1204
|
}
|
|
1205
|
+
if (mutationContext &&
|
|
1206
|
+
requestedApply &&
|
|
1207
|
+
!mutationContext.summaryEmitted) {
|
|
1208
|
+
const outcome = operation === "rename_file" &&
|
|
1209
|
+
result &&
|
|
1210
|
+
typeof result === "object" &&
|
|
1211
|
+
"applied" in result &&
|
|
1212
|
+
result.applied === false
|
|
1213
|
+
? "failed"
|
|
1214
|
+
: operation === "executeCommand" &&
|
|
1215
|
+
result &&
|
|
1216
|
+
typeof result === "object" &&
|
|
1217
|
+
"executed" in result &&
|
|
1218
|
+
result.executed === false
|
|
1219
|
+
? "failed"
|
|
1220
|
+
: "skipped";
|
|
1221
|
+
recordLspMutationOutcome(mutationContext, outcome);
|
|
1222
|
+
}
|
|
1203
1223
|
}
|
|
1204
1224
|
catch (err) {
|
|
1205
1225
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -29,6 +29,7 @@ export function createModuleReportTool(getProjectRoot) {
|
|
|
29
29
|
description: "Structured, navigable overview of a source module — a token-efficient substitute for reading the whole file. Returns each symbol's name/kind/signature/line-range (plus a first-line `doc` summary when a doc comment is attached), important inline callbacks/closures/lambdas with stable handles, plus who-uses-this, risk flags, and ranked recommendedReads. To read a symbol's body: call read/read_symbol with offset=startLine, limit=endLine-startLine+1 on THIS report's `path` — those aren't repeated per symbol. Prefer this before a full read; then use read_symbol (or read) for the exact body you need.\n" +
|
|
30
30
|
"Single mode: language-uniform tree-sitter outline + review-graph who-uses-this + inline executable extraction; degrades to outline-only when no cached graph is available. `semantic.source` reports whether graph data was used.\n" +
|
|
31
31
|
'Pass `blastRadius: true` to also get the cross-file blast radius — the transitive dependents of this module aggregated to ranked file `read` args ("if you change this, verify these files"). Read-only over the cached graph; omitted on a cold cache. Supersedes the standalone impact query.\n' +
|
|
32
|
+
'Pass `callGraph: true` to include bounded derived callers/callees from the cached FunctionCallGraph; unavailable cache state is explicit and never reported as zero calls.\n' +
|
|
32
33
|
'`view: "compact"` returns a line-oriented text rendering (one line per symbol/callback, cheapest option) instead of JSON — same data, roughly a quarter of the token cost; use it for a quick skim. Default view returns JSON. An outline shows shape, not bodies — it does NOT count as having read a symbol\'s body for editing; use read_symbol for that.',
|
|
33
34
|
promptSnippet: "Navigable file outline — a cheap substitute for reading a whole file",
|
|
34
35
|
renderResult: compactRenderResult(({ details, args, isError }) => {
|
|
@@ -65,6 +66,12 @@ export function createModuleReportTool(getProjectRoot) {
|
|
|
65
66
|
blastRadiusDepth: Type.Optional(Type.Number({
|
|
66
67
|
description: "Max hops for the blast-radius walk (default 3). Only used with blastRadius.",
|
|
67
68
|
})),
|
|
69
|
+
callGraph: Type.Optional(Type.Boolean({
|
|
70
|
+
description: "Include bounded derived callers/callees from the cached FunctionCallGraph; cold or stale cache state is explicit.",
|
|
71
|
+
})),
|
|
72
|
+
maxCallGraphEntries: Type.Optional(Type.Number({
|
|
73
|
+
description: "Per-direction cap for call-graph relations (default 20).",
|
|
74
|
+
})),
|
|
68
75
|
}),
|
|
69
76
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
70
77
|
// Resolve the file against the agent's cwd (sibling-tool convention); build
|
|
@@ -79,6 +86,8 @@ export function createModuleReportTool(getProjectRoot) {
|
|
|
79
86
|
view: params.view,
|
|
80
87
|
blastRadius: params.blastRadius,
|
|
81
88
|
blastRadiusDepth: params.blastRadiusDepth,
|
|
89
|
+
callGraph: params.callGraph,
|
|
90
|
+
maxCallGraphEntries: params.maxCallGraphEntries,
|
|
82
91
|
});
|
|
83
92
|
}
|
|
84
93
|
catch (err) {
|
|
@@ -81,21 +81,38 @@ export function createSymbolSearchTool(getProjectRoot) {
|
|
|
81
81
|
available: false,
|
|
82
82
|
query: result.query,
|
|
83
83
|
hint: result.hint,
|
|
84
|
+
unavailableReason: result.unavailableReason,
|
|
84
85
|
},
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
if (result.results.length === 0) {
|
|
89
|
+
const coverageLine = result.coverage
|
|
90
|
+
? `Index covers ${result.coverage.files} files${result.coverage.truncated ? " (capped — results may be incomplete)" : ""}.`
|
|
91
|
+
: "";
|
|
88
92
|
return {
|
|
89
93
|
content: [
|
|
90
|
-
{
|
|
94
|
+
{
|
|
95
|
+
type: "text",
|
|
96
|
+
text: `No files matched "${params.query}".${coverageLine ? `\n${coverageLine}` : ""}`,
|
|
97
|
+
},
|
|
91
98
|
],
|
|
92
|
-
details: {
|
|
99
|
+
details: {
|
|
100
|
+
available: true,
|
|
101
|
+
query: result.query,
|
|
102
|
+
count: 0,
|
|
103
|
+
coverage: result.coverage,
|
|
104
|
+
},
|
|
93
105
|
};
|
|
94
106
|
}
|
|
95
107
|
const lines = [
|
|
96
108
|
`Top ${result.results.length} file(s) for "${result.query}":`,
|
|
97
109
|
...result.results.map((hit, i) => ` ${i + 1}. ${path.relative(cwd, hit.file)} ` +
|
|
98
110
|
`(score ${hit.score.toFixed(2)}, ${hit.hits} hit(s), line ${hit.startLine})`),
|
|
111
|
+
...(result.coverage
|
|
112
|
+
? [
|
|
113
|
+
`Index covers ${result.coverage.files} files${result.coverage.truncated ? " (capped — results may be incomplete)" : ""}.`,
|
|
114
|
+
]
|
|
115
|
+
: []),
|
|
99
116
|
];
|
|
100
117
|
// Compact (unindented) JSON payload, matching module_report/read_symbol
|
|
101
118
|
// (#517): path relative-to-cwd once per hit, no per-hit `read` block —
|
|
@@ -103,6 +120,7 @@ export function createSymbolSearchTool(getProjectRoot) {
|
|
|
103
120
|
const payload = {
|
|
104
121
|
available: true,
|
|
105
122
|
query: result.query,
|
|
123
|
+
coverage: result.coverage,
|
|
106
124
|
results: result.results.map((hit) => {
|
|
107
125
|
const relFile = path.relative(cwd, hit.file);
|
|
108
126
|
return {
|
|
@@ -124,6 +142,7 @@ export function createSymbolSearchTool(getProjectRoot) {
|
|
|
124
142
|
available: true,
|
|
125
143
|
query: result.query,
|
|
126
144
|
count: result.results.length,
|
|
145
|
+
coverage: result.coverage,
|
|
127
146
|
},
|
|
128
147
|
};
|
|
129
148
|
},
|