@duckmind/dm-darwin-x64 0.67.2 → 0.67.4
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 +2 -2
- package/dm +1 -1
- package/extensions/.dm-extensions.json +613 -15
- package/extensions/dm-lens/clients/dispatch/runners/utils/runner-helpers.js +1 -1
- package/extensions/dm-lens/dist/clients/actionable-warnings-logger.js +24 -0
- package/extensions/dm-lens/dist/clients/actionable-warnings.js +1066 -0
- package/extensions/dm-lens/dist/clients/advisory-provenance.js +388 -0
- package/extensions/dm-lens/dist/clients/agent-behavior-client.js +94 -0
- package/extensions/dm-lens/dist/clients/agent-nudge.js +253 -0
- package/extensions/dm-lens/dist/clients/analysed-root.js +1 -0
- package/extensions/dm-lens/dist/clients/analysis-root.js +133 -0
- package/extensions/dm-lens/dist/clients/ast-grep-client.js +587 -0
- package/extensions/dm-lens/dist/clients/ast-grep-rule-manager.js +137 -0
- package/extensions/dm-lens/dist/clients/ast-grep-tool-logger.js +85 -0
- package/extensions/dm-lens/dist/clients/ast-grep-types.js +1 -0
- package/extensions/dm-lens/dist/clients/ast-grep-yaml-synth.js +109 -0
- package/extensions/dm-lens/dist/clients/atomic-write-staging.js +66 -0
- package/extensions/dm-lens/dist/clients/atomic-write.js +37 -0
- package/extensions/dm-lens/dist/clients/availability-probe-flight.js +11 -0
- package/extensions/dm-lens/dist/clients/bash-file-access.js +1257 -0
- package/extensions/dm-lens/dist/clients/biome-client.js +223 -0
- package/extensions/dm-lens/dist/clients/blocker-freshness.js +553 -0
- package/extensions/dm-lens/dist/clients/blocker-past-eof.js +51 -0
- package/extensions/dm-lens/dist/clients/bootstrap.js +246 -0
- package/extensions/dm-lens/dist/clients/bounded-cache.js +105 -0
- package/extensions/dm-lens/dist/clients/bounded-pid-file-lock.js +275 -0
- package/extensions/dm-lens/dist/clients/bounded-telemetry.js +110 -0
- package/extensions/dm-lens/dist/clients/build-identity.js +45 -0
- package/extensions/dm-lens/dist/clients/bundled-resource-health.js +41 -0
- package/extensions/dm-lens/dist/clients/bus-events-logger.js +48 -0
- package/extensions/dm-lens/dist/clients/bus-publish.js +117 -0
- package/extensions/dm-lens/dist/clients/cache/rule-cache.js +87 -0
- package/extensions/dm-lens/dist/clients/cache-manager.js +449 -0
- package/extensions/dm-lens/dist/clients/cache-observability.js +1105 -0
- package/extensions/dm-lens/dist/clients/call-graph.js +628 -0
- package/extensions/dm-lens/dist/clients/cargo-manifest.js +167 -0
- package/extensions/dm-lens/dist/clients/cascade-budget.js +52 -0
- package/extensions/dm-lens/dist/clients/cascade-format.js +301 -0
- package/extensions/dm-lens/dist/clients/cascade-logger.js +22 -0
- package/extensions/dm-lens/dist/clients/cascade-types.js +1 -0
- package/extensions/dm-lens/dist/clients/child-unref.js +59 -0
- package/extensions/dm-lens/dist/clients/code-quality-warnings.js +192 -0
- package/extensions/dm-lens/dist/clients/codebase-model.js +110 -0
- package/extensions/dm-lens/dist/clients/collateral-test-role.js +8 -0
- package/extensions/dm-lens/dist/clients/complexity-client.js +398 -0
- package/extensions/dm-lens/dist/clients/config-core/deny.js +117 -0
- package/extensions/dm-lens/dist/clients/config-core/index.js +2 -0
- package/extensions/dm-lens/dist/clients/config-core/merge.js +228 -0
- package/extensions/dm-lens/dist/clients/config-core/normalize.js +226 -0
- package/extensions/dm-lens/dist/clients/config-core/process-spec.js +147 -0
- package/extensions/dm-lens/dist/clients/config-core/provenance.js +54 -0
- package/extensions/dm-lens/dist/clients/config-core/records.js +79 -0
- package/extensions/dm-lens/dist/clients/config-core/resolve.js +48 -0
- package/extensions/dm-lens/dist/clients/config-core/safe-object.js +22 -0
- package/extensions/dm-lens/dist/clients/config-core/schema.js +93 -0
- package/extensions/dm-lens/dist/clients/config-diagnostic-codes.js +90 -0
- package/extensions/dm-lens/dist/clients/config-locations.js +169 -0
- package/extensions/dm-lens/dist/clients/config-resolve.js +359 -0
- package/extensions/dm-lens/dist/clients/config-schema.js +230 -0
- package/extensions/dm-lens/dist/clients/config-warn.js +146 -0
- package/extensions/dm-lens/dist/clients/confirmed-delete.js +11 -0
- package/extensions/dm-lens/dist/clients/console-guard-install.js +4 -0
- package/extensions/dm-lens/dist/clients/content-stamp.js +16 -0
- package/extensions/dm-lens/dist/clients/context-injection-ledger.js +157 -0
- package/extensions/dm-lens/dist/clients/cooperative-budget.js +36 -0
- package/extensions/dm-lens/dist/clients/custom-rule-locations.js +28 -0
- package/extensions/dm-lens/dist/clients/dead-code-client.js +408 -0
- package/extensions/dm-lens/dist/clients/dead-code-logger.js +18 -0
- package/extensions/dm-lens/dist/clients/deadline-utils.js +117 -0
- package/extensions/dm-lens/dist/clients/debug-handles.js +121 -0
- package/extensions/dm-lens/dist/clients/debug-heap.js +80 -0
- package/extensions/dm-lens/dist/clients/deferred-lsp-work.js +33 -0
- package/extensions/dm-lens/dist/clients/deferred-runner-blockers.js +146 -0
- package/extensions/dm-lens/dist/clients/deferred-test-targets.js +31 -0
- package/extensions/dm-lens/dist/clients/degradation-ledger.js +306 -0
- package/extensions/dm-lens/dist/clients/demoted-finding-render.js +64 -0
- package/extensions/dm-lens/dist/clients/dependency-checker.js +534 -0
- package/extensions/dm-lens/dist/clients/deps/ast-grep-napi.js +27 -0
- package/extensions/dm-lens/dist/clients/deps/dm-host-deps.js +10 -0
- package/extensions/dm-lens/dist/clients/deps/dm-tui-compat.js +58 -0
- package/extensions/dm-lens/dist/clients/deps/js-yaml.js +7 -0
- package/extensions/dm-lens/dist/clients/deps/minimatch.js +6 -0
- package/extensions/dm-lens/dist/clients/deps/pidusage.js +5 -0
- package/extensions/dm-lens/dist/clients/deps/typebox.js +5 -0
- package/extensions/dm-lens/dist/clients/deps/vscode-jsonrpc.js +8 -0
- package/extensions/dm-lens/dist/clients/deps/web-tree-sitter.js +11 -0
- package/extensions/dm-lens/dist/clients/diagnostic-dispositions.js +334 -0
- package/extensions/dm-lens/dist/clients/diagnostic-line-freshness.js +142 -0
- package/extensions/dm-lens/dist/clients/diagnostic-logger.js +60 -0
- package/extensions/dm-lens/dist/clients/diagnostic-tracker.js +89 -0
- package/extensions/dm-lens/dist/clients/diagnostics-publish.js +134 -0
- package/extensions/dm-lens/dist/clients/disk-change-consumers.js +312 -0
- package/extensions/dm-lens/dist/clients/disk-change-subscribers.js +191 -0
- package/extensions/dm-lens/dist/clients/disk-changes.js +165 -0
- package/extensions/dm-lens/dist/clients/dispatch/adopted-root-runners.js +22 -0
- package/extensions/dm-lens/dist/clients/dispatch/ast-grep-catalog.js +16 -0
- package/extensions/dm-lens/dist/clients/dispatch/auxiliary-lsp.js +162 -0
- package/extensions/dm-lens/dist/clients/dispatch/collect-later-tier.js +25 -0
- package/extensions/dm-lens/dist/clients/dispatch/diagnostic-taxonomy.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/dispatcher.js +1240 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-provider-types.js +1 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-rule-runner.js +17 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-runner.js +18 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-scheduler.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-store.js +193 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/comment-facts.js +23 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/file-content.js +18 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/function-facts.js +274 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/import-facts.js +169 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/tree-sitter-facts.js +19 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/try-catch-facts.js +95 -0
- package/extensions/dm-lens/dist/clients/dispatch/finding-policy.js +188 -0
- package/extensions/dm-lens/dist/clients/dispatch/indent-detect.js +227 -0
- package/extensions/dm-lens/dist/clients/dispatch/inline-suppressions.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/integration.js +1698 -0
- package/extensions/dm-lens/dist/clients/dispatch/known-runner-ids.js +13 -0
- package/extensions/dm-lens/dist/clients/dispatch/lane-copies.js +23 -0
- package/extensions/dm-lens/dist/clients/dispatch/lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/dispatch/pending-runner-findings.js +133 -0
- package/extensions/dm-lens/dist/clients/dispatch/plan.js +284 -0
- package/extensions/dm-lens/dist/clients/dispatch/pre-edit-seed.js +57 -0
- package/extensions/dm-lens/dist/clients/dispatch/priorities.js +14 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-id-normalize.js +54 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-ignores.js +21 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-policy.js +102 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-noise.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-unnecessary-wrapper.js +27 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/cors-wildcard.js +35 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-obscuring.js +29 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-swallowing.js +29 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/framework-call-noise.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-complexity.js +41 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-fan-out.js +37 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-import-coupling.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/missing-error-propagation.js +45 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/no-commented-credentials.js +46 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/pass-through-wrappers.js +38 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/placeholder-comments.js +40 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/unsafe-boundary.js +101 -0
- package/extensions/dm-lens/dist/clients/dispatch/runner-context.js +41 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/actionlint.js +98 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-literal-anchors.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-napi.js +739 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/biome-check.js +196 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/cpp-check.js +190 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/credo.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/cue-vet.js +161 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/dart-analyze.js +151 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/detekt.js +158 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/dotnet-build.js +163 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/elixir-check.js +153 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/eslint.js +99 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/fact-rules.js +20 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/fish-indent.js +120 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/gleam-check.js +100 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/go-vet.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/golangci-lint.js +105 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/hadolint.js +83 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-lint.js +147 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-render.js +593 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/htmlhint.js +103 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/index.js +100 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/javac.js +82 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ktlint.js +115 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/lsp.js +275 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/markdownlint.js +129 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/mypy.js +70 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/oxlint.js +296 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/php-lint.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/phpstan.js +90 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/prisma-validate.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +307 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/pyright.js +118 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/rubocop.js +79 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ruff.js +69 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/rust-clippy.js +166 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/shellcheck.js +168 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/shfmt.js +92 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/spellcheck.js +74 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/spotbugs.js +208 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/sqlfluff.js +136 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/stylelint.js +118 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/swiftlint.js +143 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/taplo.js +109 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/terragrunt.js +110 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/tflint.js +104 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/tree-sitter.js +534 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/trivy-config.js +155 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/availability-policy.js +313 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +62 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/lazy-installer.js +130 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1143 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +40 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/tool-failure.js +110 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +88 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils.js +8 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/vale.js +92 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +170 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/yamllint.js +83 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/zig-check.js +72 -0
- package/extensions/dm-lens/dist/clients/dispatch/suppress-writer.js +57 -0
- package/extensions/dm-lens/dist/clients/dispatch/tool-profile.js +30 -0
- package/extensions/dm-lens/dist/clients/dispatch/types.js +72 -0
- package/extensions/dm-lens/dist/clients/dispatch/utils/format-utils.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/utils/lsp-diagnostics.js +32 -0
- package/extensions/dm-lens/dist/clients/disposition-logger.js +19 -0
- package/extensions/dm-lens/dist/clients/disposition-publish.js +88 -0
- package/extensions/dm-lens/dist/clients/durable-store.js +77 -0
- package/extensions/dm-lens/dist/clients/effective-config.js +170 -0
- package/extensions/dm-lens/dist/clients/env-utils.js +26 -0
- package/extensions/dm-lens/dist/clients/ephemeral-root.js +55 -0
- package/extensions/dm-lens/dist/clients/error-class.js +3 -0
- package/extensions/dm-lens/dist/clients/eval-timestamp.js +2 -0
- package/extensions/dm-lens/dist/clients/event-loop-hold.js +119 -0
- package/extensions/dm-lens/dist/clients/event-loop-monitor.js +84 -0
- package/extensions/dm-lens/dist/clients/extension-log.js +230 -0
- package/extensions/dm-lens/dist/clients/extension-mode.js +20 -0
- package/extensions/dm-lens/dist/clients/feature-hints.js +88 -0
- package/extensions/dm-lens/dist/clients/file-kinds.js +317 -0
- package/extensions/dm-lens/dist/clients/file-mutation-queue.js +91 -0
- package/extensions/dm-lens/dist/clients/file-role.js +50 -0
- package/extensions/dm-lens/dist/clients/file-time.js +112 -0
- package/extensions/dm-lens/dist/clients/file-utils.js +840 -0
- package/extensions/dm-lens/dist/clients/finding-delivery-gate.js +146 -0
- package/extensions/dm-lens/dist/clients/finding-identity.js +79 -0
- package/extensions/dm-lens/dist/clients/fix-run-restore.js +423 -0
- package/extensions/dm-lens/dist/clients/fix-worklog.js +75 -0
- package/extensions/dm-lens/dist/clients/format-events-publish.js +310 -0
- package/extensions/dm-lens/dist/clients/format-service.js +177 -0
- package/extensions/dm-lens/dist/clients/formatters-lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/formatters.js +1367 -0
- package/extensions/dm-lens/dist/clients/freshness-cadence.js +1 -0
- package/extensions/dm-lens/dist/clients/freshness.js +8 -0
- package/extensions/dm-lens/dist/clients/generated-artifacts.js +209 -0
- package/extensions/dm-lens/dist/clients/generation-guard.js +147 -0
- package/extensions/dm-lens/dist/clients/generation-lock.js +181 -0
- package/extensions/dm-lens/dist/clients/git-guard.js +1208 -0
- package/extensions/dm-lens/dist/clients/git-tracked-ignore.js +120 -0
- package/extensions/dm-lens/dist/clients/gitleaks-client.js +290 -0
- package/extensions/dm-lens/dist/clients/go-client.js +47 -0
- package/extensions/dm-lens/dist/clients/govulncheck-client.js +416 -0
- package/extensions/dm-lens/dist/clients/gradle-ktfmt-style.js +177 -0
- package/extensions/dm-lens/dist/clients/grammar-source.js +263 -0
- package/extensions/dm-lens/dist/clients/grammar-wasm-imports.js +48 -0
- package/extensions/dm-lens/dist/clients/gzip-stage-write.js +174 -0
- package/extensions/dm-lens/dist/clients/hard-failure-summary.js +28 -0
- package/extensions/dm-lens/dist/clients/hashline-anchor.js +222 -0
- package/extensions/dm-lens/dist/clients/hook-budgets.js +17 -0
- package/extensions/dm-lens/dist/clients/host-edit-normalize.js +87 -0
- package/extensions/dm-lens/dist/clients/host-ports.js +35 -0
- package/extensions/dm-lens/dist/clients/indent-retarget.js +102 -0
- package/extensions/dm-lens/dist/clients/inline-blocker-dispositions.js +103 -0
- package/extensions/dm-lens/dist/clients/inline-blocker-fields.js +8 -0
- package/extensions/dm-lens/dist/clients/install-diagnostics.js +135 -0
- package/extensions/dm-lens/dist/clients/installer/index.js +3928 -0
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh-session.js +17 -0
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh.js +721 -0
- package/extensions/dm-lens/dist/clients/instance-reaper-state.js +3 -0
- package/extensions/dm-lens/dist/clients/instance-reaper.js +693 -0
- package/extensions/dm-lens/dist/clients/instance-registry-lock.js +166 -0
- package/extensions/dm-lens/dist/clients/instance-registry-tail.js +17 -0
- package/extensions/dm-lens/dist/clients/instance-registry.js +607 -0
- package/extensions/dm-lens/dist/clients/io-bridge-contract.js +7 -0
- package/extensions/dm-lens/dist/clients/io-bridge.js +357 -0
- package/extensions/dm-lens/dist/clients/jscpd-client.js +311 -0
- package/extensions/dm-lens/dist/clients/json-cache-read.js +25 -0
- package/extensions/dm-lens/dist/clients/knip-client.js +534 -0
- package/extensions/dm-lens/dist/clients/knip-scan-roots.js +26 -0
- package/extensions/dm-lens/dist/clients/language-policy.js +244 -0
- package/extensions/dm-lens/dist/clients/language-profile.js +259 -0
- package/extensions/dm-lens/dist/clients/language-registry.js +468 -0
- package/extensions/dm-lens/dist/clients/latency-logger.js +210 -0
- package/extensions/dm-lens/dist/clients/lazy-import.js +14 -0
- package/extensions/dm-lens/dist/clients/ledger-bounds.js +21 -0
- package/extensions/dm-lens/dist/clients/lens-config.js +254 -0
- package/extensions/dm-lens/dist/clients/lens-engine.js +188 -0
- package/extensions/dm-lens/dist/clients/lens-events.js +105 -0
- package/extensions/dm-lens/dist/clients/lens-flag-registry.js +308 -0
- package/extensions/dm-lens/dist/clients/lens-map.js +980 -0
- package/extensions/dm-lens/dist/clients/line-alignment.js +200 -0
- package/extensions/dm-lens/dist/clients/live-bus-emitter.js +53 -0
- package/extensions/dm-lens/dist/clients/log-cleanup.js +138 -0
- package/extensions/dm-lens/dist/clients/lsp/aggregation.js +89 -0
- package/extensions/dm-lens/dist/clients/lsp/auxiliary-lifecycle.js +23 -0
- package/extensions/dm-lens/dist/clients/lsp/capabilities.js +94 -0
- package/extensions/dm-lens/dist/clients/lsp/cascade-tier.js +318 -0
- package/extensions/dm-lens/dist/clients/lsp/client-registry.js +877 -0
- package/extensions/dm-lens/dist/clients/lsp/client.js +3232 -0
- package/extensions/dm-lens/dist/clients/lsp/config.js +571 -0
- package/extensions/dm-lens/dist/clients/lsp/content-limits.js +21 -0
- package/extensions/dm-lens/dist/clients/lsp/content-scan.js +69 -0
- package/extensions/dm-lens/dist/clients/lsp/created-import-targets.js +134 -0
- package/extensions/dm-lens/dist/clients/lsp/diagnostic-binding.js +113 -0
- package/extensions/dm-lens/dist/clients/lsp/document-drift.js +372 -0
- package/extensions/dm-lens/dist/clients/lsp/edits.js +1060 -0
- package/extensions/dm-lens/dist/clients/lsp/environment-gap.js +186 -0
- package/extensions/dm-lens/dist/clients/lsp/file-server-match.js +26 -0
- package/extensions/dm-lens/dist/clients/lsp/grouping.js +38 -0
- package/extensions/dm-lens/dist/clients/lsp/implicit-scope.js +205 -0
- package/extensions/dm-lens/dist/clients/lsp/index.js +4292 -0
- package/extensions/dm-lens/dist/clients/lsp/inferred-project.js +140 -0
- package/extensions/dm-lens/dist/clients/lsp/jvm-runtime.js +200 -0
- package/extensions/dm-lens/dist/clients/lsp/language.js +26 -0
- package/extensions/dm-lens/dist/clients/lsp/launch.js +606 -0
- package/extensions/dm-lens/dist/clients/lsp/lombok.js +133 -0
- package/extensions/dm-lens/dist/clients/lsp/path-utils.js +1 -0
- package/extensions/dm-lens/dist/clients/lsp/pending-aux-coverage.js +120 -0
- package/extensions/dm-lens/dist/clients/lsp/position-encoding.js +21 -0
- package/extensions/dm-lens/dist/clients/lsp/resolved-config.js +183 -0
- package/extensions/dm-lens/dist/clients/lsp/ruby-drive-dirs.js +42 -0
- package/extensions/dm-lens/dist/clients/lsp/server-config-files.js +11 -0
- package/extensions/dm-lens/dist/clients/lsp/server-covers.js +8 -0
- package/extensions/dm-lens/dist/clients/lsp/server-traits.js +45 -0
- package/extensions/dm-lens/dist/clients/lsp/server.js +2827 -0
- package/extensions/dm-lens/dist/clients/lsp/service-singleton.js +59 -0
- package/extensions/dm-lens/dist/clients/lsp/session-roots.js +83 -0
- package/extensions/dm-lens/dist/clients/lsp/spawn-history.js +15 -0
- package/extensions/dm-lens/dist/clients/lsp/sync-kind.js +30 -0
- package/extensions/dm-lens/dist/clients/lsp/tsserver-sync.js +156 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/capability-snapshot.js +1 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/classification.js +37 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/index.js +3 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/strategies.js +276 -0
- package/extensions/dm-lens/dist/clients/lsp/watch-queue.js +61 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-cache.js +395 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-session.js +42 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-sweep-hold.js +93 -0
- package/extensions/dm-lens/dist/clients/lsp-budget.js +87 -0
- package/extensions/dm-lens/dist/clients/lsp-document-symbols.js +93 -0
- package/extensions/dm-lens/dist/clients/lsp-lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/lsp-mutation.js +309 -0
- package/extensions/dm-lens/dist/clients/lsp-status.js +35 -0
- package/extensions/dm-lens/dist/clients/map-with-concurrency.js +20 -0
- package/extensions/dm-lens/dist/clients/mcp/analyze.js +302 -0
- package/extensions/dm-lens/dist/clients/mcp/host-shim.js +14 -0
- package/extensions/dm-lens/dist/clients/mcp/ipc.js +344 -0
- package/extensions/dm-lens/dist/clients/mcp/review.js +137 -0
- package/extensions/dm-lens/dist/clients/mcp/session.js +300 -0
- package/extensions/dm-lens/dist/clients/memory-sampler.js +163 -0
- package/extensions/dm-lens/dist/clients/message-end-attribution.js +18 -0
- package/extensions/dm-lens/dist/clients/metrics-client.js +80 -0
- package/extensions/dm-lens/dist/clients/metrics-history.js +242 -0
- package/extensions/dm-lens/dist/clients/middle-man-analysis.js +161 -0
- package/extensions/dm-lens/dist/clients/model-provider.js +31 -0
- package/extensions/dm-lens/dist/clients/module-report-lsp.js +140 -0
- package/extensions/dm-lens/dist/clients/module-report.js +1648 -0
- package/extensions/dm-lens/dist/clients/mutating-tool.js +388 -0
- package/extensions/dm-lens/dist/clients/mutation-attribution.js +173 -0
- package/extensions/dm-lens/dist/clients/mutation-bridge.js +231 -0
- package/extensions/dm-lens/dist/clients/ndjson-logger.js +504 -0
- package/extensions/dm-lens/dist/clients/observed-mutation-sources.js +43 -0
- package/extensions/dm-lens/dist/clients/observed-mutation.js +735 -0
- package/extensions/dm-lens/dist/clients/oldtext-autopatch.js +100 -0
- package/extensions/dm-lens/dist/clients/opaque-mutation-scan.js +541 -0
- package/extensions/dm-lens/dist/clients/opengrep-client.js +224 -0
- package/extensions/dm-lens/dist/clients/opengrep-config.js +57 -0
- package/extensions/dm-lens/dist/clients/opengrep-rule-pack.js +19 -0
- package/extensions/dm-lens/dist/clients/out-of-band-changes.js +329 -0
- package/extensions/dm-lens/dist/clients/package-manager.js +332 -0
- package/extensions/dm-lens/dist/clients/package-root.js +21 -0
- package/extensions/dm-lens/dist/clients/partial-edit-apply.js +341 -0
- package/extensions/dm-lens/dist/clients/path-attribution-telemetry.js +31 -0
- package/extensions/dm-lens/dist/clients/path-birth.js +58 -0
- package/extensions/dm-lens/dist/clients/path-keyed-map.js +57 -0
- package/extensions/dm-lens/dist/clients/path-utils.js +654 -0
- package/extensions/dm-lens/dist/clients/performance-report.js +291 -0
- package/extensions/dm-lens/dist/clients/persist-debounce.js +37 -0
- package/extensions/dm-lens/dist/clients/persist-worker-stats.js +16 -0
- package/extensions/dm-lens/dist/clients/persistent-reverify.js +167 -0
- package/extensions/dm-lens/dist/clients/php-cs-fixer-config.js +15 -0
- package/extensions/dm-lens/dist/clients/pipeline.js +1473 -0
- package/extensions/dm-lens/dist/clients/post-autofix-notice.js +19 -0
- package/extensions/dm-lens/dist/clients/print-mode.js +3 -0
- package/extensions/dm-lens/dist/clients/probe-home-state.js +73 -0
- package/extensions/dm-lens/dist/clients/process-bridge.js +48 -0
- package/extensions/dm-lens/dist/clients/process-singletons.js +69 -0
- package/extensions/dm-lens/dist/clients/process-snapshot.js +130 -0
- package/extensions/dm-lens/dist/clients/project-changes.js +180 -0
- package/extensions/dm-lens/dist/clients/project-conventions.js +152 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/cache.js +91 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/extractors.js +53 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/fresh-fetch.js +413 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +64 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +38 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/gitleaks.js +21 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/govulncheck.js +23 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/jscpd.js +28 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/knip.js +45 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +34 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/opengrep.js +32 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +79 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/trivy.js +41 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/scanner.js +351 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/types.js +1 -0
- package/extensions/dm-lens/dist/clients/project-lens-config.js +462 -0
- package/extensions/dm-lens/dist/clients/project-report.js +527 -0
- package/extensions/dm-lens/dist/clients/project-root-markers.js +8 -0
- package/extensions/dm-lens/dist/clients/project-scale.js +60 -0
- package/extensions/dm-lens/dist/clients/project-scan-policy.js +4 -0
- package/extensions/dm-lens/dist/clients/project-snapshot-fingerprint.js +44 -0
- package/extensions/dm-lens/dist/clients/project-snapshot-persist-worker.js +31 -0
- package/extensions/dm-lens/dist/clients/project-snapshot.js +1355 -0
- package/extensions/dm-lens/dist/clients/project-trust.js +104 -0
- package/extensions/dm-lens/dist/clients/python-environment.js +388 -0
- package/extensions/dm-lens/dist/clients/python-provenance.js +551 -0
- package/extensions/dm-lens/dist/clients/quiet-window-config.js +16 -0
- package/extensions/dm-lens/dist/clients/quiet-window.js +129 -0
- package/extensions/dm-lens/dist/clients/read-bridge.js +53 -0
- package/extensions/dm-lens/dist/clients/read-expansion.js +218 -0
- package/extensions/dm-lens/dist/clients/read-guard-branch.js +126 -0
- package/extensions/dm-lens/dist/clients/read-guard-logger.js +186 -0
- package/extensions/dm-lens/dist/clients/read-guard-tool-lines.js +1044 -0
- package/extensions/dm-lens/dist/clients/read-guard.js +1517 -0
- package/extensions/dm-lens/dist/clients/recent-touches.js +126 -0
- package/extensions/dm-lens/dist/clients/redact/secrets.js +386 -0
- package/extensions/dm-lens/dist/clients/resource-sampler.js +344 -0
- package/extensions/dm-lens/dist/clients/reverse-deps.js +227 -0
- package/extensions/dm-lens/dist/clients/review-graph/builder.js +3780 -0
- package/extensions/dm-lens/dist/clients/review-graph/format.js +30 -0
- package/extensions/dm-lens/dist/clients/review-graph/git-identity.js +173 -0
- package/extensions/dm-lens/dist/clients/review-graph/import-resolvers.js +332 -0
- package/extensions/dm-lens/dist/clients/review-graph/persist-worker.js +8 -0
- package/extensions/dm-lens/dist/clients/review-graph/query.js +195 -0
- package/extensions/dm-lens/dist/clients/review-graph/revision-drift.js +3 -0
- package/extensions/dm-lens/dist/clients/review-graph/service.js +60 -0
- package/extensions/dm-lens/dist/clients/review-graph/shared-extraction-ir.js +54 -0
- package/extensions/dm-lens/dist/clients/review-graph/symbol-id.js +29 -0
- package/extensions/dm-lens/dist/clients/review-graph/tsconfig-paths.js +286 -0
- package/extensions/dm-lens/dist/clients/review-graph/types.js +1 -0
- package/extensions/dm-lens/dist/clients/review-graph/workspace-modules.js +374 -0
- package/extensions/dm-lens/dist/clients/review-graph-logger.js +51 -0
- package/extensions/dm-lens/dist/clients/ruff-client.js +107 -0
- package/extensions/dm-lens/dist/clients/rules-scanner.js +70 -0
- package/extensions/dm-lens/dist/clients/run-duration.js +9 -0
- package/extensions/dm-lens/dist/clients/runtime-agent-end.js +831 -0
- package/extensions/dm-lens/dist/clients/runtime-config.js +39 -0
- package/extensions/dm-lens/dist/clients/runtime-context.js +155 -0
- package/extensions/dm-lens/dist/clients/runtime-coordinator.js +1254 -0
- package/extensions/dm-lens/dist/clients/runtime-session.js +1806 -0
- package/extensions/dm-lens/dist/clients/runtime-tool-call.js +1026 -0
- package/extensions/dm-lens/dist/clients/runtime-tool-result.js +2068 -0
- package/extensions/dm-lens/dist/clients/runtime-turn.js +3198 -0
- package/extensions/dm-lens/dist/clients/rust-client.js +46 -0
- package/extensions/dm-lens/dist/clients/safe-spawn.js +1402 -0
- package/extensions/dm-lens/dist/clients/sanitize.js +5 -0
- package/extensions/dm-lens/dist/clients/scan-utils.js +7 -0
- package/extensions/dm-lens/dist/clients/scanner-temp-root.js +8 -0
- package/extensions/dm-lens/dist/clients/scratch-tree-policy.js +63 -0
- package/extensions/dm-lens/dist/clients/search-read-registration.js +76 -0
- package/extensions/dm-lens/dist/clients/secret-findings.js +69 -0
- package/extensions/dm-lens/dist/clients/security-scan-client.js +208 -0
- package/extensions/dm-lens/dist/clients/session-event-guard.js +111 -0
- package/extensions/dm-lens/dist/clients/session-lifecycle.js +309 -0
- package/extensions/dm-lens/dist/clients/session-repository.js +113 -0
- package/extensions/dm-lens/dist/clients/session-scope.js +451 -0
- package/extensions/dm-lens/dist/clients/session-start-observability.js +59 -0
- package/extensions/dm-lens/dist/clients/session-state-store.js +71 -0
- package/extensions/dm-lens/dist/clients/session-summary.js +8 -0
- package/extensions/dm-lens/dist/clients/sessionstart-logger.js +22 -0
- package/extensions/dm-lens/dist/clients/sg-runner.js +642 -0
- package/extensions/dm-lens/dist/clients/sgconfig.js +299 -0
- package/extensions/dm-lens/dist/clients/shared-checkout-guard.js +177 -0
- package/extensions/dm-lens/dist/clients/single-flight.js +53 -0
- package/extensions/dm-lens/dist/clients/situational-tool-telemetry.js +85 -0
- package/extensions/dm-lens/dist/clients/skills-resolver.js +38 -0
- package/extensions/dm-lens/dist/clients/slow-fs.js +77 -0
- package/extensions/dm-lens/dist/clients/smells-rollup.js +118 -0
- package/extensions/dm-lens/dist/clients/source-filter.js +323 -0
- package/extensions/dm-lens/dist/clients/source-walker.js +114 -0
- package/extensions/dm-lens/dist/clients/spawn-output-cap.js +35 -0
- package/extensions/dm-lens/dist/clients/spawn-timeout-cooldown.js +51 -0
- package/extensions/dm-lens/dist/clients/stale-marker.js +1 -0
- package/extensions/dm-lens/dist/clients/startup-scan.js +221 -0
- package/extensions/dm-lens/dist/clients/startup-timing.js +67 -0
- package/extensions/dm-lens/dist/clients/string-utils.js +6 -0
- package/extensions/dm-lens/dist/clients/subagent-mode.js +40 -0
- package/extensions/dm-lens/dist/clients/symbol-containment.js +16 -0
- package/extensions/dm-lens/dist/clients/symbol-types.js +1 -0
- package/extensions/dm-lens/dist/clients/test-runner-client.js +1686 -0
- package/extensions/dm-lens/dist/clients/test-runner-delivery.js +285 -0
- package/extensions/dm-lens/dist/clients/test-target-roots.js +17 -0
- package/extensions/dm-lens/dist/clients/todo-scanner.js +164 -0
- package/extensions/dm-lens/dist/clients/tool-agreement.js +640 -0
- package/extensions/dm-lens/dist/clients/tool-config.js +239 -0
- package/extensions/dm-lens/dist/clients/tool-cwd.js +236 -0
- package/extensions/dm-lens/dist/clients/tool-definition.js +22 -0
- package/extensions/dm-lens/dist/clients/tool-event.js +24 -0
- package/extensions/dm-lens/dist/clients/tool-policy.js +2386 -0
- package/extensions/dm-lens/dist/clients/tool-probe.js +13 -0
- package/extensions/dm-lens/dist/clients/tool-render.js +79 -0
- package/extensions/dm-lens/dist/clients/tool-set-policy.js +106 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-cache.js +206 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-client.js +3101 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-logger.js +77 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-navigator.js +198 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-query-loader.js +401 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-shared.js +87 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-symbol-extractor.js +984 -0
- package/extensions/dm-lens/dist/clients/trivy-client.js +335 -0
- package/extensions/dm-lens/dist/clients/tui-fit.js +26 -0
- package/extensions/dm-lens/dist/clients/turn-context.js +48 -0
- package/extensions/dm-lens/dist/clients/turn-end/delivery-holds.js +59 -0
- package/extensions/dm-lens/dist/clients/turn-end/lane.js +1 -0
- package/extensions/dm-lens/dist/clients/turn-end/lanes/govulncheck.js +54 -0
- package/extensions/dm-lens/dist/clients/turn-end/lanes/secrets.js +131 -0
- package/extensions/dm-lens/dist/clients/turn-summary-render.js +56 -0
- package/extensions/dm-lens/dist/clients/turn-summary.js +84 -0
- package/extensions/dm-lens/dist/clients/typos-config.js +9 -0
- package/extensions/dm-lens/dist/clients/user-notify.js +15 -0
- package/extensions/dm-lens/dist/clients/vanished-instance-marker.js +18 -0
- package/extensions/dm-lens/dist/clients/warm-attach.js +232 -0
- package/extensions/dm-lens/dist/clients/widget-state.js +1014 -0
- package/extensions/dm-lens/dist/clients/word-index-logger.js +24 -0
- package/extensions/dm-lens/dist/clients/word-index-store.js +222 -0
- package/extensions/dm-lens/dist/clients/word-index.js +1503 -0
- package/extensions/dm-lens/dist/clients/workspace-topology.js +274 -0
- package/extensions/dm-lens/dist/clients/write-ordering-guard.js +28 -0
- package/extensions/dm-lens/dist/clients/zizmor-config.js +160 -0
- package/extensions/dm-lens/dist/i18n.js +67 -0
- package/extensions/dm-lens/dist/index.js +2144 -0
- package/extensions/dm-lens/dist/mcp/analyze-cli.js +205 -0
- package/extensions/dm-lens/dist/mcp/build-staleness.js +55 -0
- package/extensions/dm-lens/dist/mcp/cli.js +96 -0
- package/extensions/dm-lens/dist/mcp/server.js +1241 -0
- package/extensions/dm-lens/dist/mcp/tool-arguments.js +134 -0
- package/extensions/dm-lens/dist/mcp/worker.js +41 -0
- package/extensions/dm-lens/dist/scripts/lib/process-scan.mjs +375 -0
- package/extensions/dm-lens/dist/scripts/lib/skills-predicate.mjs +53 -0
- package/extensions/dm-lens/dist/scripts/lib/web-tree-sitter-dir.mjs +51 -0
- package/extensions/dm-lens/dist/tools/activate-tools.js +63 -0
- package/extensions/dm-lens/dist/tools/ast-grep-outline.js +128 -0
- package/extensions/dm-lens/dist/tools/ast-grep-replace.js +234 -0
- package/extensions/dm-lens/dist/tools/ast-grep-search.js +690 -0
- package/extensions/dm-lens/dist/tools/effective-config.js +59 -0
- package/extensions/dm-lens/dist/tools/lens-diagnostic-mark.js +251 -0
- package/extensions/dm-lens/dist/tools/lens-diagnostics.js +1693 -0
- package/extensions/dm-lens/dist/tools/lsp-diagnostics.js +1397 -0
- package/extensions/dm-lens/dist/tools/lsp-navigation.js +1301 -0
- package/extensions/dm-lens/dist/tools/lsp-structured-output.js +277 -0
- package/extensions/dm-lens/dist/tools/module-report.js +333 -0
- package/extensions/dm-lens/dist/tools/project-report.js +72 -0
- package/extensions/dm-lens/dist/tools/render-compact.js +272 -0
- package/extensions/dm-lens/dist/tools/scan-progress.js +31 -0
- package/extensions/dm-lens/dist/tools/shared.js +46 -0
- package/extensions/dm-lens/dist/tools/symbol-search.js +133 -0
- package/extensions/dm-mcp-adapter/dist/abort.js +35 -0
- package/extensions/dm-mcp-adapter/dist/agent-dir.js +45 -0
- package/extensions/dm-mcp-adapter/dist/agent-plugin-loader.js +392 -0
- package/extensions/dm-mcp-adapter/dist/agent-plugin-provenance.js +26 -0
- package/extensions/dm-mcp-adapter/dist/bearer-command-resolver.js +184 -0
- package/extensions/dm-mcp-adapter/dist/claude-plugin-loader.js +350 -0
- package/extensions/dm-mcp-adapter/dist/config.js +1984 -0
- package/extensions/dm-mcp-adapter/dist/consent-manager.js +84 -0
- package/extensions/dm-mcp-adapter/dist/elicitation-handler.js +374 -0
- package/extensions/dm-mcp-adapter/dist/errors.js +225 -0
- package/extensions/dm-mcp-adapter/dist/extraction-settings.js +43 -0
- package/extensions/dm-mcp-adapter/dist/http-ca.js +75 -0
- package/extensions/dm-mcp-adapter/dist/jev-client.js +359 -0
- package/extensions/dm-mcp-adapter/dist/jev-contracts.js +1 -0
- package/extensions/dm-mcp-adapter/dist/jev-key-store.js +189 -0
- package/extensions/dm-mcp-adapter/dist/json-schema-validator.js +70 -0
- package/extensions/dm-mcp-adapter/dist/lifecycle.js +387 -0
- package/extensions/dm-mcp-adapter/dist/logger.js +115 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth-fetch.js +86 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth-flow.js +956 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth.js +998 -0
- package/extensions/dm-mcp-adapter/dist/mcp-bearer-store.js +182 -0
- package/extensions/dm-mcp-adapter/dist/mcp-callback-server.js +380 -0
- package/extensions/dm-mcp-adapter/dist/mcp-oauth-provider.js +525 -0
- package/extensions/dm-mcp-adapter/dist/mcp-probe.js +151 -0
- package/extensions/dm-mcp-adapter/dist/mcp-tasks.js +339 -0
- package/extensions/dm-mcp-adapter/dist/mcp-trace.js +220 -0
- package/extensions/dm-mcp-adapter/dist/metadata-cache.js +411 -0
- package/extensions/dm-mcp-adapter/dist/npx-resolver.js +465 -0
- package/extensions/dm-mcp-adapter/dist/output-shape.js +312 -0
- package/extensions/dm-mcp-adapter/dist/package-mcp-loader.js +144 -0
- package/extensions/dm-mcp-adapter/dist/project-server-trust.js +274 -0
- package/extensions/dm-mcp-adapter/dist/request-headers-command.js +310 -0
- package/extensions/dm-mcp-adapter/dist/resource-tools.js +7 -0
- package/extensions/dm-mcp-adapter/dist/runtime-owner.js +95 -0
- package/extensions/dm-mcp-adapter/dist/sampling-handler.js +219 -0
- package/extensions/dm-mcp-adapter/dist/script-tools.js +72 -0
- package/extensions/dm-mcp-adapter/dist/secure-keyring.js +191 -0
- package/extensions/dm-mcp-adapter/dist/semantic-settings.js +51 -0
- package/extensions/dm-mcp-adapter/dist/server-log.js +19 -0
- package/extensions/dm-mcp-adapter/dist/server-manager.js +1635 -0
- package/extensions/dm-mcp-adapter/dist/session-approvals.js +127 -0
- package/extensions/dm-mcp-adapter/dist/session-recovery.js +83 -0
- package/extensions/dm-mcp-adapter/dist/state.js +1 -0
- package/extensions/dm-mcp-adapter/dist/task-entries.js +60 -0
- package/extensions/dm-mcp-adapter/dist/task-jobs.js +259 -0
- package/extensions/dm-mcp-adapter/dist/ts-shape.js +157 -0
- package/extensions/dm-mcp-adapter/dist/types.js +293 -0
- package/extensions/dm-mcp-adapter/dist/ui-app-bridge-helpers.js +36 -0
- package/extensions/dm-mcp-adapter/dist/ui-resource-handler.js +204 -0
- package/extensions/dm-mcp-adapter/dist/ui-stream-types.js +58 -0
- package/extensions/dm-mcp-adapter/dist/ui-tool-visibility.js +26 -0
- package/extensions/dm-mcp-adapter/dist/unix-socket-transport.js +83 -0
- package/extensions/dm-mcp-adapter/dist/utils.js +444 -0
- package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-activate.js +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-instructions.js +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-mode-tracker.js +1 -1
- package/extensions/dm-subagents/src/runs/shared/child-session.js +5 -3
- package/package.json +1 -1
|
@@ -0,0 +1,2068 @@
|
|
|
1
|
+
import * as nodeFs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { noteAuthoritativeContentAttachment, queueAgentAdvisory } from "./agent-nudge.js";
|
|
4
|
+
import { addHeadDiscards, captureFileStats, diffFileContent, getOpaqueBaselineStore, headRecordKey, isGitWorktree, listGitHeadDelta, observeGitHead, opaqueBaselineSlot, opaquePrescanRoot, readGitHead, readSameHeadDiscards, recordOpaqueCaptureRefused, recoverOpaqueChangesViaGit, resolveOpaqueRecoveryRoots, serializeHeadLook, shouldRunOpaqueRecovery, takeHeadDiscards } from "./opaque-mutation-scan.js";
|
|
5
|
+
import { isUnderDir, normalizeMapKey, realpathOrResolve, resolveToolCallFilePath } from "./path-utils.js";
|
|
6
|
+
import { detectFileKind } from "./file-kinds.js";
|
|
7
|
+
import { isSessionBookkeepingRoot } from "./analysis-root.js";
|
|
8
|
+
import { extractReadPathsFromCommand, extractDeletedPathsFromCommand, extractGrepSearchReadsFromOutput, extractWrittenPathsFromCommand, tokenizeShellCommand } from "./bash-file-access.js";
|
|
9
|
+
import { registerSearchReads } from "./search-read-registration.js";
|
|
10
|
+
import { publishFormatQueued } from "./format-events-publish.js";
|
|
11
|
+
import { invalidateProjectIgnoreMatcherForPath, isDmLensInternalPath, isPathIgnoredByProject, isRecordableProjectPath } from "./file-utils.js";
|
|
12
|
+
import { invalidateFormatterCacheForPath } from "./formatters.js";
|
|
13
|
+
import { judgeConfirmedDelete } from "./confirmed-delete.js";
|
|
14
|
+
import { deliveredLineEvidence, scanFileLines } from "./read-guard.js";
|
|
15
|
+
import { expectationFromToolInput, noteAgentCallEnd, noteAgentMutation } from "./fix-run-restore.js";
|
|
16
|
+
import { getFormatService } from "./format-service.js";
|
|
17
|
+
import { isExternalOrVendorFile, isVendorPath, isOutsideProjectRoot, normalizeEphemeralMapKey, pathsEqual } from "./path-utils.js";
|
|
18
|
+
import { PathKeyedMap } from "./path-keyed-map.js";
|
|
19
|
+
import { resolveLanguageRootForFile } from "./language-profile.js";
|
|
20
|
+
import { logLatency } from "./latency-logger.js";
|
|
21
|
+
import { classifyMutatingTool, isBashDerivedReplay, readToolResultPathField, DM_LENS_SYNTHETIC_MUTATION_FIELD } from "./mutating-tool.js";
|
|
22
|
+
import { hasPendingObservation, noteMutationHandled, pendingObservationPaths, settleObservedMutation } from "./observed-mutation.js";
|
|
23
|
+
import { replayThroughMutationBridge, storedLineHashesFor } from "./observed-mutation-sources.js";
|
|
24
|
+
import { getAmbientAbortSignal } from "./safe-spawn.js";
|
|
25
|
+
import { resolveReadEvidenceCorrelationId, resolveToolCallCorrelationId } from "./tool-event.js";
|
|
26
|
+
import { boundedIndexesForCount, createReadGuardEditBatchSummary, getReadGuardCorrelationId, logReadGuardEvent } from "./read-guard-logger.js";
|
|
27
|
+
import { notifyExternalFileChange, peekLSPService } from "./lsp/capabilities.js";
|
|
28
|
+
import { runPipeline } from "./pipeline.js";
|
|
29
|
+
import { renderPostAutofixNotice } from "./post-autofix-notice.js";
|
|
30
|
+
import { EXPANSION_LIMIT_LINES } from "./read-expansion.js";
|
|
31
|
+
import { syncGitGuardRecord } from "./git-guard.js";
|
|
32
|
+
import { hashFileBytes } from "./content-stamp.js";
|
|
33
|
+
import { scheduleWordIndexPersist } from "./word-index.js";
|
|
34
|
+
import { RUNTIME_CONFIG } from "./runtime-config.js";
|
|
35
|
+
import { getActiveSessionId } from "./session-lifecycle.js";
|
|
36
|
+
import { recordDroppedRead, sessionFencedFixedThisTurn } from "./session-scope.js";
|
|
37
|
+
import { requestBootstrapClients } from "./bootstrap.js";
|
|
38
|
+
import { bounded } from "./deadline-utils.js";
|
|
39
|
+
import { DISK_CHANGE_MAX_RECORDED_PATHS, publishDiskChangeChunked } from "./disk-changes.js";
|
|
40
|
+
import { BASH_RECOVERY_DRIFT_SOURCE, BASH_WRITE_SOURCE, ensureDiskChangeSubscribers, readHeldDocumentsAnswer, SAME_HEAD_DISCARD_SOURCE } from "./disk-change-subscribers.js";
|
|
41
|
+
import { lookForOutOfBandChanges, oweDeclarationWalk } from "./out-of-band-changes.js";
|
|
42
|
+
import { HOOK_WALL_BUDGET_MS } from "./hook-budgets.js";
|
|
43
|
+
import { incrementDegradationCount, recordDegradationOnce } from "./degradation-ledger.js";
|
|
44
|
+
import { canWriteAnalysisRoot, classifyAnalysisRoot, resolveAnalysisRoot } from "./analysis-root.js";
|
|
45
|
+
const AUTHORITATIVE_CONTENT_MAX_BYTES = RUNTIME_CONFIG.pipeline.lspMaxFileBytes;
|
|
46
|
+
const OBSERVED_DISPATCH_MAX_PATHS = 32;
|
|
47
|
+
const GIT_INTEGRATION_SUBCOMMANDS = new Set([
|
|
48
|
+
"merge",
|
|
49
|
+
"rebase",
|
|
50
|
+
"cherry-pick",
|
|
51
|
+
"pull",
|
|
52
|
+
"revert",
|
|
53
|
+
"am"
|
|
54
|
+
]);
|
|
55
|
+
const GIT_GLOBAL_OPTIONS_WITH_VALUE = new Set([
|
|
56
|
+
"-C",
|
|
57
|
+
"-c",
|
|
58
|
+
"--config-env",
|
|
59
|
+
"--git-dir",
|
|
60
|
+
"--namespace",
|
|
61
|
+
"--work-tree"
|
|
62
|
+
]);
|
|
63
|
+
export function isFailedGitIntegrationCommand(command, isError) {
|
|
64
|
+
if (isError !== true)
|
|
65
|
+
return false;
|
|
66
|
+
return tokenizeShellCommand(command).some(({ tokens, unsupported }) => {
|
|
67
|
+
if (unsupported)
|
|
68
|
+
return false;
|
|
69
|
+
const executable = path.win32.basename(tokens[0] ?? "").toLowerCase().replace(/\.(?:cmd|exe)$/, "");
|
|
70
|
+
if (executable !== "git")
|
|
71
|
+
return false;
|
|
72
|
+
for (let index = 1;index < tokens.length; index += 1) {
|
|
73
|
+
const token = tokens[index] ?? "";
|
|
74
|
+
if (GIT_GLOBAL_OPTIONS_WITH_VALUE.has(token)) {
|
|
75
|
+
index += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (token.startsWith("-"))
|
|
79
|
+
continue;
|
|
80
|
+
return GIT_INTEGRATION_SUBCOMMANDS.has(token);
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const CLIENT_ROOT_LOOK_CAP = 4;
|
|
86
|
+
function liveClientRootsApartFrom(sessionRoot) {
|
|
87
|
+
const service = peekLSPService();
|
|
88
|
+
const roots = service?.livePrimaryClientRoots?.() ?? [];
|
|
89
|
+
if (roots.length === 0)
|
|
90
|
+
return [];
|
|
91
|
+
const sessionKey = normalizeMapKey(sessionRoot);
|
|
92
|
+
const seen = new Set([sessionKey]);
|
|
93
|
+
const out = [];
|
|
94
|
+
for (const entry of roots) {
|
|
95
|
+
const key = normalizeMapKey(entry.root);
|
|
96
|
+
if (seen.has(key))
|
|
97
|
+
continue;
|
|
98
|
+
seen.add(key);
|
|
99
|
+
out.push(entry);
|
|
100
|
+
}
|
|
101
|
+
if (out.length > CLIENT_ROOT_LOOK_CAP) {
|
|
102
|
+
recordDegradationOnce({
|
|
103
|
+
kind: "lsp-client-root-look-capped",
|
|
104
|
+
subject: "cap",
|
|
105
|
+
reason: `${out.length} live primary client root(s) outside the session root; the first ${CLIENT_ROOT_LOOK_CAP} got the install look, so an install in the rest is not seen until a tool call names one of their files`
|
|
106
|
+
});
|
|
107
|
+
return out.slice(0, CLIENT_ROOT_LOOK_CAP);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
export function resyncHeadMove(args) {
|
|
112
|
+
addHeadDiscards(args.key, args.discarded);
|
|
113
|
+
oweDeclarationWalk(args.root, args.trigger);
|
|
114
|
+
return serializeHeadLook(args.key, async () => {
|
|
115
|
+
try {
|
|
116
|
+
await lookForOutOfBandChanges(args.root, args.trigger, args.runtime);
|
|
117
|
+
} finally {
|
|
118
|
+
await lookAtHead(args);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function lookAtHead(args) {
|
|
123
|
+
const discarded = takeHeadDiscards(args.key);
|
|
124
|
+
if (!await isGitWorktree(args.root))
|
|
125
|
+
return;
|
|
126
|
+
const head = await readGitHead(args.root);
|
|
127
|
+
if (!head)
|
|
128
|
+
return;
|
|
129
|
+
const from = observeGitHead(args.key, head);
|
|
130
|
+
const moved = from !== undefined;
|
|
131
|
+
if (!moved && discarded.length === 0)
|
|
132
|
+
return;
|
|
133
|
+
const started = Date.now();
|
|
134
|
+
const delta = moved ? await listGitHeadDelta(args.root, from, head) : [];
|
|
135
|
+
const population = delta === undefined ? "unknown" : [...new Set([...delta, ...discarded])];
|
|
136
|
+
ensureDiskChangeSubscribers();
|
|
137
|
+
const published = await publishDiskChangeChunked({
|
|
138
|
+
root: args.root,
|
|
139
|
+
origin: "head-move",
|
|
140
|
+
kind: "inferred",
|
|
141
|
+
...discarded.length > 0 ? { sources: ["head-move", SAME_HEAD_DISCARD_SOURCE] } : {},
|
|
142
|
+
paths: population
|
|
143
|
+
});
|
|
144
|
+
const answers = published.map(({ results, failedSubscribers }) => readHeldDocumentsAnswer(results, args.root, failedSubscribers));
|
|
145
|
+
const targets = answers.flatMap((answer) => answer.targets);
|
|
146
|
+
const primary = answers.reduce((count, answer) => count + answer.primary, 0);
|
|
147
|
+
const unheld = answers.reduce((count, answer) => count + answer.unheld, 0);
|
|
148
|
+
const resyncFailed = answers.some((answer) => answer.failed);
|
|
149
|
+
const drained = answers.every((answer) => answer.drained);
|
|
150
|
+
const held = answers.reduce((count, answer) => count + answer.held, 0);
|
|
151
|
+
const drifts = answers.flatMap((answer) => answer.drift === undefined ? [] : [answer.drift]);
|
|
152
|
+
const unlistable = published[0]?.change.paths === "unknown";
|
|
153
|
+
const primaryMs = Date.now() - started;
|
|
154
|
+
const report = (dispositions, failed) => {
|
|
155
|
+
const outcomes = [...dispositions?.values() ?? []];
|
|
156
|
+
const count = (kind) => outcomes.filter((outcome) => outcome === kind).length;
|
|
157
|
+
logLatency({
|
|
158
|
+
type: "phase",
|
|
159
|
+
phase: "opaque_mutation_head_moved",
|
|
160
|
+
filePath: args.label.slice(0, 80),
|
|
161
|
+
durationMs: Date.now() - started,
|
|
162
|
+
result: failed ? "resync-failed" : delta === undefined ? "delta-unknown" : moved ? `changed:${population.length}` : `discarded:${population.length}`,
|
|
163
|
+
metadata: {
|
|
164
|
+
trigger: args.trigger,
|
|
165
|
+
from: from?.slice(0, 12) ?? "",
|
|
166
|
+
to: head.slice(0, 12),
|
|
167
|
+
changed: delta?.length ?? -1,
|
|
168
|
+
discarded: discarded.length,
|
|
169
|
+
held,
|
|
170
|
+
heldPopulation: unlistable ? "all-held" : "delta-held",
|
|
171
|
+
current: held - targets.length,
|
|
172
|
+
primary,
|
|
173
|
+
unheld,
|
|
174
|
+
primaryMs,
|
|
175
|
+
drained,
|
|
176
|
+
resynced: count("resynced"),
|
|
177
|
+
deferred: count("deferred"),
|
|
178
|
+
failed: count("failed")
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
if (targets.length === 0 || resyncFailed || drifts.length === 0) {
|
|
183
|
+
report(undefined, resyncFailed);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
Promise.all(drifts).then((maps) => report(mergeDispositions(maps), false), () => report(undefined, true));
|
|
187
|
+
}
|
|
188
|
+
async function publishDriftPass(root, paths, detector) {
|
|
189
|
+
const { noun, ...origin } = detector;
|
|
190
|
+
await publishDiskChangeChunked({ root, ...origin, paths }, undefined, undefined, async ({ results, failedSubscribers }, { index, total }) => {
|
|
191
|
+
try {
|
|
192
|
+
await readHeldDocumentsAnswer(results, root, failedSubscribers).drift;
|
|
193
|
+
} catch (cause) {
|
|
194
|
+
const dropped = Math.min(DISK_CHANGE_MAX_RECORDED_PATHS, paths.length - index * DISK_CHANGE_MAX_RECORDED_PATHS);
|
|
195
|
+
incrementDegradationCount({
|
|
196
|
+
kind: "disk-change-recovered-drift-failed",
|
|
197
|
+
subject: root,
|
|
198
|
+
reason: `chunk ${index + 1} of ${total} rejected, so its ${dropped} ${noun} path(s) were never republished to a server: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
const RECOVERED_DRIFT_PASS = {
|
|
204
|
+
origin: "bash-recovery",
|
|
205
|
+
sources: [BASH_RECOVERY_DRIFT_SOURCE],
|
|
206
|
+
kind: "inferred",
|
|
207
|
+
noun: "recovered"
|
|
208
|
+
};
|
|
209
|
+
export function publishSettledSweepDrift(root, found) {
|
|
210
|
+
const paths = [...new Set([...found.drifted, ...found.unverifiable])];
|
|
211
|
+
if (paths.length === 0)
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
ensureDiskChangeSubscribers();
|
|
214
|
+
return publishDriftPass(root, paths, {
|
|
215
|
+
origin: "settled-sweep",
|
|
216
|
+
kind: found.unverifiable.length > 0 ? "inferred" : "observed",
|
|
217
|
+
noun: "settled-sweep"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function mergeDispositions(maps) {
|
|
221
|
+
const merged = new Map;
|
|
222
|
+
for (const map of maps)
|
|
223
|
+
for (const [filePath, kind] of map)
|
|
224
|
+
merged.set(filePath, kind);
|
|
225
|
+
return merged;
|
|
226
|
+
}
|
|
227
|
+
function ensureToolResultClients(deps) {
|
|
228
|
+
if (deps.biomeClient && deps.ruffClient && deps.metricsClient)
|
|
229
|
+
return true;
|
|
230
|
+
const request = {
|
|
231
|
+
reason: "tool-result-analysis",
|
|
232
|
+
hook: "tool_result_edit",
|
|
233
|
+
timeoutMs: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
234
|
+
...deps.signal === undefined ? {} : { signal: deps.signal }
|
|
235
|
+
};
|
|
236
|
+
return bounded(requestBootstrapClients(request), {
|
|
237
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
238
|
+
signal: deps.signal,
|
|
239
|
+
hook: "tool_result_edit",
|
|
240
|
+
label: "tool-result-bootstrap-demand"
|
|
241
|
+
}).then((clients) => {
|
|
242
|
+
if (!clients)
|
|
243
|
+
return false;
|
|
244
|
+
deps.biomeClient = clients.biomeClient;
|
|
245
|
+
deps.ruffClient = clients.ruffClient;
|
|
246
|
+
deps.metricsClient = clients.metricsClient;
|
|
247
|
+
return true;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function parseDiffRanges(diff) {
|
|
251
|
+
const changedLines = [];
|
|
252
|
+
for (const line of diff.split(`
|
|
253
|
+
`)) {
|
|
254
|
+
const match = line.match(/^[+-]\s*(\d+)\s/);
|
|
255
|
+
if (match) {
|
|
256
|
+
changedLines.push(Number.parseInt(match[1], 10));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (changedLines.length === 0)
|
|
260
|
+
return [];
|
|
261
|
+
const sorted = [...new Set(changedLines)].sort((a, b) => a - b);
|
|
262
|
+
const ranges = [];
|
|
263
|
+
let rangeStart = sorted[0];
|
|
264
|
+
let rangeEnd = sorted[0];
|
|
265
|
+
for (const line of sorted.slice(1)) {
|
|
266
|
+
if (line <= rangeEnd + 1) {
|
|
267
|
+
rangeEnd = line;
|
|
268
|
+
} else {
|
|
269
|
+
ranges.push({ start: rangeStart, end: rangeEnd });
|
|
270
|
+
rangeStart = line;
|
|
271
|
+
rangeEnd = line;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
ranges.push({ start: rangeStart, end: rangeEnd });
|
|
275
|
+
return ranges;
|
|
276
|
+
}
|
|
277
|
+
const inFlightPipelines = new PathKeyedMap(normalizeEphemeralMapKey);
|
|
278
|
+
const lastAnalyzedStateByFile = new PathKeyedMap(normalizeEphemeralMapKey);
|
|
279
|
+
function inFlightKey(stateHash, authored) {
|
|
280
|
+
return authored ? stateHash : `${stateHash}#unauthored`;
|
|
281
|
+
}
|
|
282
|
+
export function clearLastAnalyzedStateCache() {
|
|
283
|
+
lastAnalyzedStateByFile.clear();
|
|
284
|
+
}
|
|
285
|
+
function registerInFlightPipeline(filePath, registryKey, pipeline) {
|
|
286
|
+
let filePipelines = inFlightPipelines.get(filePath);
|
|
287
|
+
if (!filePipelines) {
|
|
288
|
+
filePipelines = new Map;
|
|
289
|
+
inFlightPipelines.set(filePath, filePipelines);
|
|
290
|
+
}
|
|
291
|
+
filePipelines.set(registryKey, pipeline);
|
|
292
|
+
return filePipelines;
|
|
293
|
+
}
|
|
294
|
+
function releaseInFlightPipeline(filePath, registryKey, registered) {
|
|
295
|
+
registered.delete(registryKey);
|
|
296
|
+
if (registered.size === 0 && inFlightPipelines.get(filePath) === registered) {
|
|
297
|
+
inFlightPipelines.delete(filePath);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function claimPipelineDispatch(args) {
|
|
301
|
+
const { filePath, stateHash, turnIndex, authored, participantId, dbg } = args;
|
|
302
|
+
const filePipelines = inFlightPipelines.get(filePath);
|
|
303
|
+
const inFlight = filePipelines?.get(inFlightKey(stateHash, true)) ?? (authored ? undefined : filePipelines?.get(inFlightKey(stateHash, false)));
|
|
304
|
+
if (inFlight) {
|
|
305
|
+
dbg(`tool_result: skipping duplicate concurrent state for ${filePath}`);
|
|
306
|
+
if (inFlight.participantIds.length < 100) {
|
|
307
|
+
inFlight.participantIds.push(participantId);
|
|
308
|
+
}
|
|
309
|
+
inFlight.participantTotal += 1;
|
|
310
|
+
return { proceed: false, joined: inFlight.promise };
|
|
311
|
+
}
|
|
312
|
+
const lastAnalyzed = lastAnalyzedStateByFile.get(filePath);
|
|
313
|
+
if (lastAnalyzed?.turnIndex === turnIndex && lastAnalyzed.stateHash === stateHash && (lastAnalyzed.authored || !authored)) {
|
|
314
|
+
dbg(`tool_result: skipping already-analyzed file state this turn for ${filePath}`);
|
|
315
|
+
return { proceed: false, joined: undefined };
|
|
316
|
+
}
|
|
317
|
+
return { proceed: true };
|
|
318
|
+
}
|
|
319
|
+
const debouncedPipelines = new PathKeyedMap(normalizeEphemeralMapKey);
|
|
320
|
+
const DEFAULT_DEBOUNCE_MS = 0;
|
|
321
|
+
const MAX_DEBOUNCE_MS = 1000;
|
|
322
|
+
function getDebounceMs() {
|
|
323
|
+
const raw = Number(process.env.DM_LENS_TOOL_RESULT_DEBOUNCE_MS);
|
|
324
|
+
if (!Number.isFinite(raw) || raw < 0)
|
|
325
|
+
return DEFAULT_DEBOUNCE_MS;
|
|
326
|
+
return Math.min(raw, MAX_DEBOUNCE_MS);
|
|
327
|
+
}
|
|
328
|
+
export async function flushDebouncedToolResults(filePath) {
|
|
329
|
+
const entries = filePath ? debouncedPipelines.has(filePath) ? [
|
|
330
|
+
[
|
|
331
|
+
filePath,
|
|
332
|
+
debouncedPipelines.get(filePath)
|
|
333
|
+
]
|
|
334
|
+
] : [] : [...debouncedPipelines.entries()];
|
|
335
|
+
for (const [key, entry] of entries) {
|
|
336
|
+
clearTimeout(entry.timer);
|
|
337
|
+
debouncedPipelines.delete(key);
|
|
338
|
+
handleToolResult({ ...entry.latestDeps, _bypassDebounce: true }).then(entry.resolve, entry.reject);
|
|
339
|
+
}
|
|
340
|
+
if (entries.length > 0) {
|
|
341
|
+
await Promise.all(entries.map(([, entry]) => entry.promise.catch(() => {
|
|
342
|
+
return;
|
|
343
|
+
})));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function scheduleDebounced(filePath, debounceMs, deps) {
|
|
347
|
+
const existing = debouncedPipelines.get(filePath);
|
|
348
|
+
if (existing) {
|
|
349
|
+
clearTimeout(existing.timer);
|
|
350
|
+
const incomingId = deps._telemetryParticipantIds?.[0] ?? getReadGuardCorrelationId(deps.event);
|
|
351
|
+
const priorIds = existing.latestDeps._telemetryParticipantIds ?? [];
|
|
352
|
+
existing.latestDeps = {
|
|
353
|
+
...deps,
|
|
354
|
+
_telemetryParticipantIds: [...priorIds, incomingId].slice(0, 100),
|
|
355
|
+
_telemetryParticipantTotal: (existing.latestDeps._telemetryParticipantTotal ?? priorIds.length) + 1
|
|
356
|
+
};
|
|
357
|
+
existing.coalescedCount += 1;
|
|
358
|
+
existing.timer = setTimeout(() => {
|
|
359
|
+
debouncedPipelines.delete(filePath);
|
|
360
|
+
deps.dbg(`tool_result: debounce fired after ${existing.coalescedCount} coalesced calls for ${filePath}`);
|
|
361
|
+
handleToolResult({ ...existing.latestDeps, _bypassDebounce: true }).then(existing.resolve, existing.reject);
|
|
362
|
+
}, debounceMs);
|
|
363
|
+
deps.dbg(`tool_result: coalesced into pending debounce for ${filePath} (count=${existing.coalescedCount})`);
|
|
364
|
+
return existing.promise;
|
|
365
|
+
}
|
|
366
|
+
let resolveFn;
|
|
367
|
+
let rejectFn;
|
|
368
|
+
const promise = new Promise((res, rej) => {
|
|
369
|
+
resolveFn = res;
|
|
370
|
+
rejectFn = rej;
|
|
371
|
+
});
|
|
372
|
+
const initialParticipantIds = deps._telemetryParticipantIds ?? [
|
|
373
|
+
getReadGuardCorrelationId(deps.event)
|
|
374
|
+
];
|
|
375
|
+
const entry = {
|
|
376
|
+
timer: setTimeout(() => {
|
|
377
|
+
debouncedPipelines.delete(filePath);
|
|
378
|
+
handleToolResult({ ...entry.latestDeps, _bypassDebounce: true }).then(entry.resolve, entry.reject);
|
|
379
|
+
}, debounceMs),
|
|
380
|
+
promise,
|
|
381
|
+
resolve: resolveFn,
|
|
382
|
+
reject: rejectFn,
|
|
383
|
+
latestDeps: {
|
|
384
|
+
...deps,
|
|
385
|
+
_telemetryParticipantIds: initialParticipantIds.slice(0, 100),
|
|
386
|
+
_telemetryParticipantTotal: deps._telemetryParticipantTotal ?? initialParticipantIds.length
|
|
387
|
+
},
|
|
388
|
+
scheduledAt: Date.now(),
|
|
389
|
+
coalescedCount: 1
|
|
390
|
+
};
|
|
391
|
+
debouncedPipelines.set(filePath, entry);
|
|
392
|
+
return promise;
|
|
393
|
+
}
|
|
394
|
+
function lastByteIsNewline(filePath) {
|
|
395
|
+
const fd = nodeFs.openSync(filePath, "r");
|
|
396
|
+
try {
|
|
397
|
+
const size = nodeFs.fstatSync(fd).size;
|
|
398
|
+
const last = Buffer.alloc(1);
|
|
399
|
+
return nodeFs.readSync(fd, last, 0, 1, size - 1) === 1 && last[0] === 10;
|
|
400
|
+
} finally {
|
|
401
|
+
nodeFs.closeSync(fd);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function getFileStateHash(filePath) {
|
|
405
|
+
try {
|
|
406
|
+
return hashFileBytes(filePath);
|
|
407
|
+
} catch (err) {
|
|
408
|
+
const code = err.code ?? "unknown";
|
|
409
|
+
return `unreadable:${code}`;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function getRequestedEditCount(event, kind) {
|
|
413
|
+
if (kind === "write")
|
|
414
|
+
return 1;
|
|
415
|
+
const edits = event.input?.edits;
|
|
416
|
+
return Array.isArray(edits) && edits.length > 0 ? edits.length : 1;
|
|
417
|
+
}
|
|
418
|
+
function getRequestedEditIndexes(event, kind) {
|
|
419
|
+
return boundedIndexesForCount(getRequestedEditCount(event, kind));
|
|
420
|
+
}
|
|
421
|
+
function sourceForMutation(classification, details) {
|
|
422
|
+
if (details?.piLensPartialApply) {
|
|
423
|
+
return "partial-apply";
|
|
424
|
+
}
|
|
425
|
+
if (classification.provenance === "builtin" || classification.provenance === "bash-derived") {
|
|
426
|
+
return classification.kind === "write" ? "agent-write" : "agent-edit";
|
|
427
|
+
}
|
|
428
|
+
return `agent-tool:${classification.toolName}`;
|
|
429
|
+
}
|
|
430
|
+
function singleRange(ranges) {
|
|
431
|
+
return ranges?.length === 1 ? ranges[0] : undefined;
|
|
432
|
+
}
|
|
433
|
+
export function recordProjectChange(args) {
|
|
434
|
+
if (!canWriteAnalysisRoot(args.analysisRootMode))
|
|
435
|
+
return;
|
|
436
|
+
args.runtime.recordProjectMutation?.({
|
|
437
|
+
filePath: args.filePath,
|
|
438
|
+
source: args.source,
|
|
439
|
+
cwd: args.cwd,
|
|
440
|
+
changedRange: args.changedRange,
|
|
441
|
+
onAppendError: (err) => args.dbg(`project change log append failed for ${args.filePath}: ${err}`)
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
export function recordTurnSummary(args) {
|
|
445
|
+
if (!args.resultLive)
|
|
446
|
+
return;
|
|
447
|
+
if (!canWriteAnalysisRoot(args.analysisRootMode))
|
|
448
|
+
return;
|
|
449
|
+
if (!args.getFlag("lens-turn-summary"))
|
|
450
|
+
return;
|
|
451
|
+
if (args.result.diagnostics?.length) {
|
|
452
|
+
for (const d of args.result.diagnostics) {
|
|
453
|
+
args.runtime.turnSummary.recordDiagnostic(d.filePath || args.filePath, {
|
|
454
|
+
tool: d.tool,
|
|
455
|
+
ruleId: d.rule ?? d.code,
|
|
456
|
+
severity: d.severity,
|
|
457
|
+
line: d.line,
|
|
458
|
+
description: d.message
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (args.result.fixedCount && args.result.fixedCount > 0) {
|
|
463
|
+
for (const label of args.result.autofixTools ?? []) {
|
|
464
|
+
const [tool, countStr] = label.split(":");
|
|
465
|
+
const count = Number.parseInt(countStr ?? "", 10);
|
|
466
|
+
args.runtime.turnSummary.recordAutofix(args.filePath, {
|
|
467
|
+
tool: tool || label,
|
|
468
|
+
description: Number.isFinite(count) && count > 0 ? `${count} issue(s) fixed` : undefined
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (args.result.formattersUsed?.length) {
|
|
473
|
+
for (const tool of args.result.formattersUsed) {
|
|
474
|
+
args.runtime.turnSummary.recordFormat(args.filePath, { tool });
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function recordNativeAppliedPairs(args) {
|
|
479
|
+
const pairs = [];
|
|
480
|
+
if (args.kind !== "edit")
|
|
481
|
+
return pairs;
|
|
482
|
+
const appliedInput = args.input;
|
|
483
|
+
const record = (oldText, newText) => {
|
|
484
|
+
if (typeof oldText === "string" && oldText.length > 0) {
|
|
485
|
+
args.runtime.partialApplyRecords.record(args.filePath, oldText, newText, args.stateHash);
|
|
486
|
+
pairs.push({ oldText, newText });
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
if (Array.isArray(appliedInput.edits)) {
|
|
490
|
+
for (const edit of appliedInput.edits)
|
|
491
|
+
record(edit.oldText, edit.newText);
|
|
492
|
+
} else {
|
|
493
|
+
record(appliedInput.oldText, appliedInput.newText);
|
|
494
|
+
}
|
|
495
|
+
return pairs;
|
|
496
|
+
}
|
|
497
|
+
function refreshCachedExports(runtime, filePath) {
|
|
498
|
+
if (runtime.cachedExports.size === 0 || !nodeFs.existsSync(filePath))
|
|
499
|
+
return;
|
|
500
|
+
const exportRe = new RegExp("export\\s+(?:async\\s+)?(?:function|class|const|let|type|interface)\\s+(\\w+)", "g");
|
|
501
|
+
for (const [name, file] of runtime.cachedExports) {
|
|
502
|
+
if (path.resolve(file) === path.resolve(filePath)) {
|
|
503
|
+
runtime.cachedExports.delete(name);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
const freshContent = nodeFs.readFileSync(filePath, "utf-8");
|
|
508
|
+
for (const match of freshContent.matchAll(exportRe)) {
|
|
509
|
+
const name = match[1];
|
|
510
|
+
if (!runtime.cachedExports.has(name)) {
|
|
511
|
+
runtime.cachedExports.set(name, filePath);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
} catch {}
|
|
515
|
+
}
|
|
516
|
+
function publishInlineVerdict(args) {
|
|
517
|
+
const { runtime, cacheManager, filePath, result, writeSession, writeIndex, writeOrderTurn, authored, getFlag, turnStateCwd, analysisRootMode, sessionId } = args;
|
|
518
|
+
const resultLive = writeSession.guardedWrite(filePath, () => true) === true;
|
|
519
|
+
let inlineVerdictApplied;
|
|
520
|
+
let ownBlockerRetired = false;
|
|
521
|
+
const { inlineBlockerSummary } = result;
|
|
522
|
+
if (inlineBlockerSummary) {
|
|
523
|
+
inlineVerdictApplied = writeSession.guardedWrite(filePath, () => runtime.recordInlineBlockers(filePath, inlineBlockerSummary, result.writeIndex ?? writeIndex, result.inlineBlockerSources, result.inlineBlockerLines, result.inlineBlockerFileContent, result.inlineBlockerDiagnostics, result.orderTurn ?? writeOrderTurn, result.analysisReadAtMs, sessionId)) !== undefined;
|
|
524
|
+
} else {
|
|
525
|
+
const hadOwnBlocker = runtime.hasInlineBlocker?.(filePath) ?? false;
|
|
526
|
+
inlineVerdictApplied = writeSession.guardedWrite(filePath, () => runtime.clearInlineBlockers(filePath, result.writeIndex ?? writeIndex, result.orderTurn ?? writeOrderTurn, {
|
|
527
|
+
authored,
|
|
528
|
+
sha256: result.inlineBlockerFileContent?.sha256,
|
|
529
|
+
blocking: result.currentBlockerCount ?? 0
|
|
530
|
+
})) ?? false;
|
|
531
|
+
ownBlockerRetired = hadOwnBlocker && inlineVerdictApplied && !result.isError;
|
|
532
|
+
}
|
|
533
|
+
if (inlineVerdictApplied)
|
|
534
|
+
runtime.setAnalysisAnchor(filePath, result.analysisAnchor);
|
|
535
|
+
if (resultLive) {
|
|
536
|
+
runtime.updateGitGuardStatus(inlineVerdictApplied && result.hasBlockers, result.output);
|
|
537
|
+
if (getFlag("lens-guard")) {
|
|
538
|
+
const wholeFileClean = inlineVerdictApplied && !result.isError && !result.hasBlockers && result.currentBlockerCount === 0 && (result.preExistingBlockerCount ?? 0) === 0 && result.fileVerdictComplete === true;
|
|
539
|
+
syncGitGuardRecord(runtime, cacheManager, turnStateCwd, wholeFileClean || ownBlockerRetired ? filePath : undefined, analysisRootMode, wholeFileClean, sessionId);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
async function dispatchPipelineAnalysis(args) {
|
|
544
|
+
const { deps, runtime, filePath, dispatchCwd, turnStateCwd, analysisRootMode, autofixMode, modifiedRanges, writeIndex, writeOrderTurn, initialStateHash, readGuardCorrelationId, requestedEditIndexes, requestedEditTotal, isPartialApplyResult, toolResultStart, nativeAppliedPairs, allowAutonomousWriters, sessionGeneration, ownFileTimeStamp = true, preserveNativeAuthorship = false } = args;
|
|
545
|
+
const { event, getFlag, getFlagSource, dbg, biomeClient, ruffClient, metricsClient, resetLSPService } = deps;
|
|
546
|
+
const fixedThisTurn = sessionFencedFixedThisTurn(runtime.fixedThisTurn, sessionGeneration);
|
|
547
|
+
const pipelinePromise = runPipeline({
|
|
548
|
+
signal: deps.signal,
|
|
549
|
+
filePath,
|
|
550
|
+
cwd: dispatchCwd,
|
|
551
|
+
projectRoot: turnStateCwd,
|
|
552
|
+
analysisRootMode,
|
|
553
|
+
toolName: event.toolName,
|
|
554
|
+
autofixMode,
|
|
555
|
+
allowAutonomousWriters,
|
|
556
|
+
modifiedRanges,
|
|
557
|
+
priorInlineBlockers: () => runtime.getInlineBlockerDiagnostics(filePath),
|
|
558
|
+
priorAnalysisAnchor: () => runtime.getAnalysisAnchor(filePath),
|
|
559
|
+
telemetry: {
|
|
560
|
+
model: runtime.telemetryModel,
|
|
561
|
+
sessionId: runtime.telemetrySessionId,
|
|
562
|
+
turnIndex: runtime.turnIndex,
|
|
563
|
+
writeIndex,
|
|
564
|
+
orderTurn: writeOrderTurn,
|
|
565
|
+
modelId: runtime.telemetryModelId,
|
|
566
|
+
provider: runtime.telemetryProviderId
|
|
567
|
+
},
|
|
568
|
+
getFlag,
|
|
569
|
+
getFlagSource,
|
|
570
|
+
dbg,
|
|
571
|
+
seqState: {
|
|
572
|
+
projectSeq: () => runtime.projectSeq,
|
|
573
|
+
getFilesChangedSince: (seq) => runtime.getFilesChangedSince(seq)
|
|
574
|
+
},
|
|
575
|
+
turnEndCascadeSettleStart: () => runtime.getTurnEndCascadeSettleStart(),
|
|
576
|
+
wordIndex: runtime.wordIndex,
|
|
577
|
+
onWordIndexUpdated: (index) => {
|
|
578
|
+
scheduleWordIndexPersist(dispatchCwd, index, dbg);
|
|
579
|
+
},
|
|
580
|
+
sessionGeneration,
|
|
581
|
+
onFixRunLoss: (notice) => queueAgentAdvisory(notice, sessionGeneration),
|
|
582
|
+
nextWriteIndex: () => ({
|
|
583
|
+
turnIndex: runtime.turnIndex,
|
|
584
|
+
orderTurn: runtime.writeOrderTurn,
|
|
585
|
+
writeIndex: runtime.nextWriteIndex()
|
|
586
|
+
})
|
|
587
|
+
}, {
|
|
588
|
+
biomeClient,
|
|
589
|
+
ruffClient,
|
|
590
|
+
metricsClient,
|
|
591
|
+
getFormatService,
|
|
592
|
+
fixedThisTurn
|
|
593
|
+
});
|
|
594
|
+
const pipelineTelemetry = {
|
|
595
|
+
promise: pipelinePromise,
|
|
596
|
+
participantIds: [...new Set(args.participantIds)].slice(0, 100),
|
|
597
|
+
participantTotal: args.participantTotal
|
|
598
|
+
};
|
|
599
|
+
const registryKey = inFlightKey(initialStateHash, allowAutonomousWriters);
|
|
600
|
+
const registeredPipelines = registerInFlightPipeline(filePath, registryKey, pipelineTelemetry);
|
|
601
|
+
let result;
|
|
602
|
+
try {
|
|
603
|
+
result = await pipelinePromise;
|
|
604
|
+
} catch (pipelineErr) {
|
|
605
|
+
if (getFlag("lens-guard")) {
|
|
606
|
+
sessionGeneration.guardedWrite(filePath, () => runtime.markGitGuardDispatchUnanswered(filePath, "pipeline_crash"));
|
|
607
|
+
}
|
|
608
|
+
dbg(`runPipeline crashed: ${pipelineErr}`);
|
|
609
|
+
logReadGuardEvent({
|
|
610
|
+
event: "edit_post_edit_pipeline_failed",
|
|
611
|
+
correlationId: readGuardCorrelationId,
|
|
612
|
+
filePath,
|
|
613
|
+
metadata: {
|
|
614
|
+
tool: event.toolName,
|
|
615
|
+
commitStatus: "committed",
|
|
616
|
+
reasonCode: "pipeline_failed"
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
logReadGuardEvent({
|
|
620
|
+
event: "edit_batch_summary",
|
|
621
|
+
correlationId: readGuardCorrelationId,
|
|
622
|
+
filePath,
|
|
623
|
+
metadata: {
|
|
624
|
+
tool: event.toolName,
|
|
625
|
+
editBatchSummary: createReadGuardEditBatchSummary({
|
|
626
|
+
requestedIndexes: requestedEditIndexes,
|
|
627
|
+
requestedTotal: requestedEditTotal,
|
|
628
|
+
resolvedIndexes: requestedEditIndexes,
|
|
629
|
+
resolvedTotal: requestedEditTotal,
|
|
630
|
+
appliedIndexes: requestedEditIndexes,
|
|
631
|
+
appliedTotal: requestedEditTotal,
|
|
632
|
+
participantIds: pipelineTelemetry.participantIds,
|
|
633
|
+
participantTotal: pipelineTelemetry.participantTotal,
|
|
634
|
+
commitStatus: "committed",
|
|
635
|
+
postEditStatus: "failed",
|
|
636
|
+
terminalStatus: "failed",
|
|
637
|
+
durationMs: Date.now() - toolResultStart
|
|
638
|
+
})
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
dbg(`runPipeline crash stack: ${pipelineErr.stack}`);
|
|
642
|
+
const activePrimarySessionId = getActiveSessionId();
|
|
643
|
+
const crashBelongsToPrimary = activePrimarySessionId === undefined || activePrimarySessionId === runtime.telemetrySessionId;
|
|
644
|
+
if (!getFlag("no-lsp") && crashBelongsToPrimary) {
|
|
645
|
+
resetLSPService({ fast: true, reason: "pipeline_crash" });
|
|
646
|
+
}
|
|
647
|
+
logLatency({
|
|
648
|
+
type: "tool_result",
|
|
649
|
+
toolName: event.toolName,
|
|
650
|
+
filePath,
|
|
651
|
+
durationMs: Date.now() - toolResultStart,
|
|
652
|
+
result: "pipeline_crash"
|
|
653
|
+
});
|
|
654
|
+
const notice = runtime.formatPipelineCrashNotice(filePath, pipelineErr);
|
|
655
|
+
return {
|
|
656
|
+
crashed: true,
|
|
657
|
+
response: {
|
|
658
|
+
content: notice ? [...event.content, { type: "text", text: notice }] : event.content,
|
|
659
|
+
isError: true,
|
|
660
|
+
structuredContent: event.structuredContent
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
} finally {
|
|
664
|
+
releaseInFlightPipeline(filePath, registryKey, registeredPipelines);
|
|
665
|
+
}
|
|
666
|
+
if (getFlag("lens-guard")) {
|
|
667
|
+
sessionGeneration.guardedWrite(filePath, () => result.isError && !result.hasBlockers ? runtime.markGitGuardDispatchUnanswered(filePath, "pipeline_error") : runtime.answerGitGuardDispatch(filePath));
|
|
668
|
+
}
|
|
669
|
+
if (!isPartialApplyResult) {
|
|
670
|
+
const postEditStatus = result.isError ? "failed" : "succeeded";
|
|
671
|
+
if (result.isError) {
|
|
672
|
+
logReadGuardEvent({
|
|
673
|
+
event: "edit_post_edit_pipeline_failed",
|
|
674
|
+
correlationId: readGuardCorrelationId,
|
|
675
|
+
filePath,
|
|
676
|
+
metadata: {
|
|
677
|
+
tool: event.toolName,
|
|
678
|
+
commitStatus: "committed",
|
|
679
|
+
reasonCode: "pipeline_failed"
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
logReadGuardEvent({
|
|
684
|
+
event: "edit_batch_summary",
|
|
685
|
+
correlationId: readGuardCorrelationId,
|
|
686
|
+
filePath,
|
|
687
|
+
metadata: {
|
|
688
|
+
tool: event.toolName,
|
|
689
|
+
editBatchSummary: createReadGuardEditBatchSummary({
|
|
690
|
+
requestedIndexes: requestedEditIndexes,
|
|
691
|
+
requestedTotal: requestedEditTotal,
|
|
692
|
+
resolvedIndexes: requestedEditIndexes,
|
|
693
|
+
resolvedTotal: requestedEditTotal,
|
|
694
|
+
appliedIndexes: requestedEditIndexes,
|
|
695
|
+
appliedTotal: requestedEditTotal,
|
|
696
|
+
participantIds: pipelineTelemetry.participantIds,
|
|
697
|
+
participantTotal: pipelineTelemetry.participantTotal,
|
|
698
|
+
commitStatus: "committed",
|
|
699
|
+
postEditStatus,
|
|
700
|
+
terminalStatus: postEditStatus === "failed" ? "failed" : "success",
|
|
701
|
+
durationMs: Date.now() - toolResultStart
|
|
702
|
+
})
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
const pipelineOwnedWriteHash = result.fileModified ? result.postWriteStateHash : undefined;
|
|
707
|
+
const finalStateHash = pipelineOwnedWriteHash ?? initialStateHash;
|
|
708
|
+
if (!result.fileModified || pipelineOwnedWriteHash !== undefined) {
|
|
709
|
+
sessionGeneration.guardedWrite(filePath, () => lastAnalyzedStateByFile.set(filePath, {
|
|
710
|
+
turnIndex: runtime.turnIndex,
|
|
711
|
+
stateHash: finalStateHash,
|
|
712
|
+
authored: allowAutonomousWriters
|
|
713
|
+
}));
|
|
714
|
+
}
|
|
715
|
+
if (pipelineOwnedWriteHash !== undefined) {
|
|
716
|
+
for (const pair of nativeAppliedPairs) {
|
|
717
|
+
runtime.partialApplyRecords.noteAfterWriteHash(filePath, pair.oldText, pair.newText, finalStateHash);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (!getFlag("no-read-guard") && allowAutonomousWriters) {
|
|
721
|
+
const ownPath = path.resolve(filePath);
|
|
722
|
+
const changedForReadGuard = new Set([
|
|
723
|
+
ownPath,
|
|
724
|
+
...(result.changedFiles ?? []).map((changedFile) => path.resolve(changedFile))
|
|
725
|
+
]);
|
|
726
|
+
for (const changedFile of changedForReadGuard) {
|
|
727
|
+
if (changedFile === ownPath && pipelineOwnedWriteHash === undefined && preserveNativeAuthorship)
|
|
728
|
+
continue;
|
|
729
|
+
if (nodeFs.existsSync(changedFile)) {
|
|
730
|
+
deps.readGuard?.recordWritten(changedFile, {
|
|
731
|
+
authorship: "whole-file",
|
|
732
|
+
stampFileTime: ownFileTimeStamp || changedFile !== ownPath,
|
|
733
|
+
...changedFile === ownPath && (!result.fileModified || pipelineOwnedWriteHash !== undefined) && {
|
|
734
|
+
contentHash: finalStateHash
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return { crashed: false, result };
|
|
741
|
+
}
|
|
742
|
+
function singlePositionalEdit(input) {
|
|
743
|
+
const edits = input?.edits;
|
|
744
|
+
if (!Array.isArray(edits) || edits.length !== 1)
|
|
745
|
+
return;
|
|
746
|
+
const edit = edits[0];
|
|
747
|
+
const start = edit?.range?.start?.line;
|
|
748
|
+
return typeof start === "number" && typeof edit.newText === "string" ? { start, newText: edit.newText } : undefined;
|
|
749
|
+
}
|
|
750
|
+
function ownEditEvidence(filePath, edit) {
|
|
751
|
+
const full = deliveredLineEvidence(edit.newText, edit.start);
|
|
752
|
+
if (!edit.newText.endsWith(`
|
|
753
|
+
`))
|
|
754
|
+
return full;
|
|
755
|
+
const certain = deliveredLineEvidence(edit.newText.slice(0, -1), edit.start);
|
|
756
|
+
try {
|
|
757
|
+
const next = nodeFs.readFileSync(filePath, "utf-8").split(/\r?\n/)[edit.start + certain.lineCount - 1];
|
|
758
|
+
return next !== undefined && next.trim() === "" ? full : certain;
|
|
759
|
+
} catch {
|
|
760
|
+
return certain;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const PI_READ_NOTICE = /\n\n\[(?:Showing lines \d+-\d+ of \d+(?: \([^)\]]+ limit\))?|\d+ more lines in file)\. Use offset=\d+ to continue\.\]$/;
|
|
764
|
+
function piReadBody(text) {
|
|
765
|
+
return text.replace(PI_READ_NOTICE, "");
|
|
766
|
+
}
|
|
767
|
+
function logConversationRead(source, filePath, offset, evidence) {
|
|
768
|
+
logLatency({
|
|
769
|
+
type: "phase",
|
|
770
|
+
phase: "read_guard_conversation_read",
|
|
771
|
+
filePath,
|
|
772
|
+
durationMs: 0,
|
|
773
|
+
metadata: {
|
|
774
|
+
source,
|
|
775
|
+
offset,
|
|
776
|
+
lineCount: evidence.lineCount,
|
|
777
|
+
hashed: evidence.lineHashes !== undefined
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
function readWideningNote(widening) {
|
|
782
|
+
const { requested, shown, boundary } = widening;
|
|
783
|
+
const reason = "heading" in boundary ? `the Markdown section under the heading "${boundary.heading}" (heading boundary)` : `the enclosing ${boundary.symbol.kind} "${boundary.symbol.name}" (symbol boundary)`;
|
|
784
|
+
return `[dm-lens: read widened to ${reason}: you asked for lines ${requested.offset}-${requested.offset + requested.limit - 1}, this shows lines ${shown.offset}-${shown.offset + shown.limit - 1}. Re-request with limit > ${EXPANSION_LIMIT_LINES} for the exact range.]`;
|
|
785
|
+
}
|
|
786
|
+
export function handleToolExecutionEnd(event, readGuard) {
|
|
787
|
+
if (event?.isError !== true)
|
|
788
|
+
return false;
|
|
789
|
+
const toolCallId = resolveToolCallCorrelationId(event);
|
|
790
|
+
return toolCallId !== undefined ? readGuard.dropProvisionalReadByCall(toolCallId) : false;
|
|
791
|
+
}
|
|
792
|
+
export async function handleToolResult(deps) {
|
|
793
|
+
const { event, getFlag, dbg, runtime, cacheManager, agentBehaviorRecord, formatBehaviorWarnings } = deps;
|
|
794
|
+
const writeSession = deps._sessionGeneration ?? runtime.captureSessionGeneration();
|
|
795
|
+
const rawFilePath = readToolResultPathField(event);
|
|
796
|
+
const workspaceRoot = runtime.projectRoot || process.cwd();
|
|
797
|
+
let bashAuthorshipConfirmed = deps._allowAutonomousWriters ?? deps._readGuardAuthorship ?? event.toolName !== "bash";
|
|
798
|
+
const toolCallId = resolveToolCallCorrelationId(event);
|
|
799
|
+
const readEvidenceToolCallId = resolveReadEvidenceCorrelationId(event);
|
|
800
|
+
noteAgentCallEnd(toolCallId);
|
|
801
|
+
if (event.isError === true && toolCallId !== undefined)
|
|
802
|
+
deps.readGuard?.dropProvisionalReadByCall(toolCallId);
|
|
803
|
+
const bashCommand = event.toolName === "bash" && typeof event.input.command === "string" ? event.input.command : undefined;
|
|
804
|
+
const opaqueNonBash = event.toolName !== "bash" && toolCallId !== undefined && shouldRunOpaqueRecovery(event.toolName, workspaceRoot) && getOpaqueBaselineStore().has(opaqueBaselineSlot(opaquePrescanRoot(deps.cwd, workspaceRoot), runtime.sessionGeneration), toolCallId);
|
|
805
|
+
let unattributedOpaque = false;
|
|
806
|
+
const attribution = toolCallId !== undefined ? runtime.takeToolCallAttribution(toolCallId) : undefined;
|
|
807
|
+
const readWidening = event.toolName === "read" && toolCallId !== undefined ? runtime.takeReadWidening(toolCallId) : undefined;
|
|
808
|
+
const executedRead = event.input;
|
|
809
|
+
const notedWidening = readWidening && event.isError !== true && (rawFilePath ?? executedRead.filePath) === readWidening.inputPath && executedRead.offset === readWidening.shown.offset && executedRead.limit === readWidening.shown.limit ? readWidening : undefined;
|
|
810
|
+
const readNote = notedWidening ? [{ type: "text", text: readWideningNote(notedWidening) }] : [];
|
|
811
|
+
if (notedWidening) {
|
|
812
|
+
logLatency({
|
|
813
|
+
type: "phase",
|
|
814
|
+
phase: "read_widening_note",
|
|
815
|
+
toolName: event.toolName,
|
|
816
|
+
filePath: notedWidening.filePath,
|
|
817
|
+
durationMs: 0,
|
|
818
|
+
metadata: {
|
|
819
|
+
requested: notedWidening.requested,
|
|
820
|
+
shown: notedWidening.shown,
|
|
821
|
+
boundary: "heading" in notedWidening.boundary ? "heading" : "symbol"
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (deps.readGuard && event.isError !== true && !getFlag("no-read-guard")) {
|
|
826
|
+
const searchReads = [];
|
|
827
|
+
const detailSearchReads = event.details?.searchReads;
|
|
828
|
+
if (Array.isArray(detailSearchReads))
|
|
829
|
+
searchReads.push(...detailSearchReads);
|
|
830
|
+
if (event.toolName === "bash" && typeof event.input.command === "string") {
|
|
831
|
+
const command = event.input.command;
|
|
832
|
+
const output = event.content.map((part) => typeof part.text === "string" ? part.text : "").join(`
|
|
833
|
+
`);
|
|
834
|
+
searchReads.push(...extractGrepSearchReadsFromOutput(command, workspaceRoot, output));
|
|
835
|
+
}
|
|
836
|
+
if (searchReads.length > 0) {
|
|
837
|
+
registerSearchReads(deps.readGuard, searchReads, {
|
|
838
|
+
projectRoot: workspaceRoot,
|
|
839
|
+
turnIndex: runtime.turnIndex,
|
|
840
|
+
writeIndex: runtime.peekWriteIndex(),
|
|
841
|
+
...readEvidenceToolCallId !== undefined && {
|
|
842
|
+
toolCallId: readEvidenceToolCallId
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
let resolutionBasis;
|
|
848
|
+
if (attribution) {
|
|
849
|
+
resolutionBasis = attribution.originCwd;
|
|
850
|
+
} else if (toolCallId !== undefined && rawFilePath && !path.isAbsolute(rawFilePath)) {
|
|
851
|
+
const guessedPath = path.resolve(workspaceRoot, rawFilePath);
|
|
852
|
+
dbg(`path_attribution_missing: no recorded resolution basis for toolCallId=${toolCallId}, refusing relative path ${rawFilePath} (would have guessed ${guessedPath})`);
|
|
853
|
+
logLatency({
|
|
854
|
+
type: "phase",
|
|
855
|
+
toolName: event.toolName,
|
|
856
|
+
filePath: guessedPath,
|
|
857
|
+
phase: "path_attribution_missing",
|
|
858
|
+
durationMs: 0,
|
|
859
|
+
metadata: { toolCallId, rawFilePath, guessedPath }
|
|
860
|
+
});
|
|
861
|
+
if (!opaqueNonBash)
|
|
862
|
+
return readNote.length > 0 ? {
|
|
863
|
+
content: [...readNote, ...event.content],
|
|
864
|
+
structuredContent: event.structuredContent
|
|
865
|
+
} : undefined;
|
|
866
|
+
unattributedOpaque = true;
|
|
867
|
+
resolutionBasis = workspaceRoot;
|
|
868
|
+
} else {
|
|
869
|
+
resolutionBasis = workspaceRoot;
|
|
870
|
+
}
|
|
871
|
+
const filePath = unattributedOpaque ? undefined : rawFilePath && deps._pathAlreadyResolved ? rawFilePath : resolveToolCallFilePath(rawFilePath, resolutionBasis, workspaceRoot)?.path;
|
|
872
|
+
const analysisRoot = classifyAnalysisRoot(filePath ?? "", workspaceRoot);
|
|
873
|
+
const analysisRootMode = analysisRoot.mode;
|
|
874
|
+
if (filePath) {
|
|
875
|
+
invalidateProjectIgnoreMatcherForPath(filePath);
|
|
876
|
+
invalidateFormatterCacheForPath(filePath);
|
|
877
|
+
}
|
|
878
|
+
if (attribution?.skipped && filePath && attribution.resolvedPath && !pathsEqual(filePath, attribution.resolvedPath)) {
|
|
879
|
+
const message = `path_attribution_refused: call target ${attribution.resolvedPath} (originCwd=${attribution.originCwd}) vs tool_result resolved ${filePath}`;
|
|
880
|
+
dbg(message);
|
|
881
|
+
logLatency({
|
|
882
|
+
type: "phase",
|
|
883
|
+
toolName: event.toolName,
|
|
884
|
+
filePath,
|
|
885
|
+
phase: "path_attribution_refused",
|
|
886
|
+
durationMs: 0,
|
|
887
|
+
metadata: {
|
|
888
|
+
callTarget: attribution.resolvedPath,
|
|
889
|
+
resolvedPath: filePath,
|
|
890
|
+
originCwd: attribution.originCwd
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
const behaviorWarnings = isBashDerivedReplay(event) ? [] : agentBehaviorRecord(event.toolName, filePath);
|
|
895
|
+
const syntheticWriteContent = [];
|
|
896
|
+
const syntheticAttachmentBudget = {
|
|
897
|
+
remaining: AUTHORITATIVE_CONTENT_MAX_BYTES
|
|
898
|
+
};
|
|
899
|
+
if (bashCommand !== undefined || opaqueNonBash) {
|
|
900
|
+
const command = bashCommand ?? "";
|
|
901
|
+
const opaqueLabel = bashCommand ?? event.toolName;
|
|
902
|
+
const recognized = extractWrittenPathsFromCommand(command, workspaceRoot);
|
|
903
|
+
const scanRoot = opaquePrescanRoot(deps.cwd, workspaceRoot);
|
|
904
|
+
const recoveryScopes = resolveOpaqueRecoveryRoots(command, scanRoot);
|
|
905
|
+
const ownerRootOf = (file) => {
|
|
906
|
+
const abs = realpathOrResolve(file);
|
|
907
|
+
let owner;
|
|
908
|
+
for (const root of recoveryScopes.roots) {
|
|
909
|
+
if (!isUnderDir(abs, root))
|
|
910
|
+
continue;
|
|
911
|
+
if (owner === undefined || root.length > owner.length)
|
|
912
|
+
owner = root;
|
|
913
|
+
}
|
|
914
|
+
return owner;
|
|
915
|
+
};
|
|
916
|
+
const isRecordableBashWrite = (wp) => {
|
|
917
|
+
if (!canWriteAnalysisRoot(resolveAnalysisRoot(wp, workspaceRoot)))
|
|
918
|
+
return false;
|
|
919
|
+
if (isRecordableProjectPath(wp, workspaceRoot))
|
|
920
|
+
return true;
|
|
921
|
+
const owner = ownerRootOf(wp);
|
|
922
|
+
return owner !== undefined && owner !== scanRoot && isRecordableProjectPath(wp, owner);
|
|
923
|
+
};
|
|
924
|
+
let recognizedWritten = event.isError !== true ? recognized.filter(isRecordableBashWrite) : [];
|
|
925
|
+
let opaquePaths = [];
|
|
926
|
+
let observedOpaquePaths = [];
|
|
927
|
+
let hadOpaqueRecovery = false;
|
|
928
|
+
const recoveredByRoot = new Map;
|
|
929
|
+
let recognizedAuthored = [];
|
|
930
|
+
let dirtyBefore;
|
|
931
|
+
if (shouldRunOpaqueRecovery(event.toolName, workspaceRoot)) {
|
|
932
|
+
const started = Date.now();
|
|
933
|
+
const unknownRoots = new Set;
|
|
934
|
+
let unknownReason;
|
|
935
|
+
const baselines = recoveryScopes.roots.map((root) => ({
|
|
936
|
+
root,
|
|
937
|
+
pending: getOpaqueBaselineStore().take(opaqueBaselineSlot(root, runtime.sessionGeneration), toolCallId)
|
|
938
|
+
}));
|
|
939
|
+
dirtyBefore = baselines.find((entry) => entry.root === scanRoot)?.pending?.dirtyPaths;
|
|
940
|
+
const outcomes = await Promise.all(baselines.map(async ({ root, pending }) => {
|
|
941
|
+
if (!pending)
|
|
942
|
+
return {
|
|
943
|
+
root,
|
|
944
|
+
verdict: "unknown",
|
|
945
|
+
reason: recognized.length > 0 ? "partial-recognition-no-baseline" : "no-pending-snapshot"
|
|
946
|
+
};
|
|
947
|
+
if (pending.strategy === "git") {
|
|
948
|
+
const recovery = await recoverOpaqueChangesViaGit(root, pending.startedAt, {
|
|
949
|
+
excludeIndexOnlyWhenUnmerged: isFailedGitIntegrationCommand(command, event.isError)
|
|
950
|
+
});
|
|
951
|
+
if (recovery.verdict === "unknown")
|
|
952
|
+
return {
|
|
953
|
+
root,
|
|
954
|
+
verdict: "unknown",
|
|
955
|
+
reason: recovery.unknownReason ?? "git-failed"
|
|
956
|
+
};
|
|
957
|
+
return {
|
|
958
|
+
root,
|
|
959
|
+
verdict: "observed",
|
|
960
|
+
keys: recovery.verdict === "recovered" ? recovery.paths.filter((p) => isRecordableProjectPath(p, root)) : [],
|
|
961
|
+
excluded: recovery.excludedIncomingCount ?? 0,
|
|
962
|
+
unknownPairs: recovery.unknownStatusCount ?? 0
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
if (pending.stats) {
|
|
966
|
+
const outcome = await captureFileStats(root, {
|
|
967
|
+
withHashes: true,
|
|
968
|
+
...deps._opaqueCaptureOptions
|
|
969
|
+
});
|
|
970
|
+
if (!outcome.snapshot || outcome.unknownReason)
|
|
971
|
+
return {
|
|
972
|
+
root,
|
|
973
|
+
verdict: "unknown",
|
|
974
|
+
reason: outcome.unknownReason ?? pending.statsUnknownReason ?? "walk-failed"
|
|
975
|
+
};
|
|
976
|
+
return {
|
|
977
|
+
root,
|
|
978
|
+
verdict: "observed",
|
|
979
|
+
keys: diffFileContent(pending.stats, outcome.snapshot),
|
|
980
|
+
excluded: 0,
|
|
981
|
+
unknownPairs: 0
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
return {
|
|
985
|
+
root,
|
|
986
|
+
verdict: "unknown",
|
|
987
|
+
reason: pending.statsUnknownReason ?? "walk-failed"
|
|
988
|
+
};
|
|
989
|
+
}));
|
|
990
|
+
for (const outcome of outcomes) {
|
|
991
|
+
if (outcome.verdict === "unknown") {
|
|
992
|
+
if (bashCommand === undefined)
|
|
993
|
+
recordOpaqueCaptureRefused(outcome.reason, event.toolName);
|
|
994
|
+
unknownRoots.add(outcome.root);
|
|
995
|
+
unknownReason ??= outcome.reason;
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
recoveredByRoot.set(outcome.root, new Set(outcome.keys));
|
|
999
|
+
if (outcome.excluded > 0)
|
|
1000
|
+
logLatency({
|
|
1001
|
+
type: "phase",
|
|
1002
|
+
phase: "opaque_mutation_incoming_excluded",
|
|
1003
|
+
filePath: opaqueLabel.slice(0, 80),
|
|
1004
|
+
durationMs: Date.now() - started,
|
|
1005
|
+
result: `excluded:${outcome.excluded}`,
|
|
1006
|
+
metadata: { root: outcome.root }
|
|
1007
|
+
});
|
|
1008
|
+
if (outcome.unknownPairs > 0)
|
|
1009
|
+
logLatency({
|
|
1010
|
+
type: "phase",
|
|
1011
|
+
phase: "opaque_mutation_status_pair_unknown",
|
|
1012
|
+
filePath: opaqueLabel.slice(0, 80),
|
|
1013
|
+
durationMs: Date.now() - started,
|
|
1014
|
+
result: `kept:${outcome.unknownPairs}`,
|
|
1015
|
+
metadata: { root: outcome.root }
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
opaquePaths = recoveryScopes.roots.flatMap((root) => [
|
|
1019
|
+
...recoveredByRoot.get(root) ?? []
|
|
1020
|
+
]);
|
|
1021
|
+
if (opaquePaths.length > 0 && recognizedWritten.length > 0) {
|
|
1022
|
+
const survivingKeys = new Set(recognizedWritten.map((p) => normalizeMapKey(realpathOrResolve(p))));
|
|
1023
|
+
opaquePaths = opaquePaths.filter((p) => !survivingKeys.has(p));
|
|
1024
|
+
}
|
|
1025
|
+
if (opaquePaths.length > 0 && opaqueNonBash) {
|
|
1026
|
+
const observed = new Set(pendingObservationPaths(toolCallId, runtime.sessionGeneration).map((p) => normalizeMapKey(realpathOrResolve(p))));
|
|
1027
|
+
if (observed.size > 0) {
|
|
1028
|
+
for (const p of opaquePaths)
|
|
1029
|
+
if (observed.has(p))
|
|
1030
|
+
observedOpaquePaths.push(p);
|
|
1031
|
+
opaquePaths = opaquePaths.filter((p) => !observed.has(p));
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
hadOpaqueRecovery = opaquePaths.length > 0;
|
|
1035
|
+
if (recoveredByRoot.size > 0 || unknownRoots.size > 0) {
|
|
1036
|
+
const scanned = [];
|
|
1037
|
+
const unscanned = [];
|
|
1038
|
+
for (const file of recognizedWritten) {
|
|
1039
|
+
const owner = ownerRootOf(file);
|
|
1040
|
+
const observed = owner === undefined ? undefined : recoveredByRoot.get(owner);
|
|
1041
|
+
if (owner === undefined || observed === undefined)
|
|
1042
|
+
unscanned.push(file);
|
|
1043
|
+
else if (observed.has(normalizeMapKey(realpathOrResolve(file))))
|
|
1044
|
+
scanned.push(file);
|
|
1045
|
+
}
|
|
1046
|
+
recognizedAuthored = scanned;
|
|
1047
|
+
if (recognizedAuthored.length === 0 && unscanned.length === 0)
|
|
1048
|
+
recognizedWritten = [];
|
|
1049
|
+
}
|
|
1050
|
+
if (unknownReason) {
|
|
1051
|
+
logLatency({
|
|
1052
|
+
type: "phase",
|
|
1053
|
+
phase: "opaque_mutation_coverage_unknown",
|
|
1054
|
+
filePath: opaqueLabel.slice(0, 80),
|
|
1055
|
+
durationMs: Date.now() - started,
|
|
1056
|
+
result: unknownReason,
|
|
1057
|
+
metadata: {
|
|
1058
|
+
root: scanRoot,
|
|
1059
|
+
unknownRoots: unknownRoots.size
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
for (const root of recoveryScopes.roots) {
|
|
1064
|
+
const keys = recoveredByRoot.get(root);
|
|
1065
|
+
if (keys === undefined || keys.size === 0)
|
|
1066
|
+
continue;
|
|
1067
|
+
const listed = [...keys];
|
|
1068
|
+
listed.length = Math.min(listed.length, 5);
|
|
1069
|
+
logLatency({
|
|
1070
|
+
type: "phase",
|
|
1071
|
+
phase: "opaque_mutation_recovered",
|
|
1072
|
+
filePath: listed.join(","),
|
|
1073
|
+
durationMs: Date.now() - started,
|
|
1074
|
+
result: `changed:${keys.size}`,
|
|
1075
|
+
metadata: { root, roots: recoveryScopes.roots.length }
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
const headScanRoot = opaquePrescanRoot(deps.cwd, workspaceRoot);
|
|
1080
|
+
if (headScanRoot) {
|
|
1081
|
+
const headMoveSignal = deps.signal ?? undefined;
|
|
1082
|
+
const discarded = dirtyBefore === undefined ? undefined : await readSameHeadDiscards(headScanRoot, dirtyBefore);
|
|
1083
|
+
await bounded(resyncHeadMove({
|
|
1084
|
+
root: headScanRoot,
|
|
1085
|
+
key: headRecordKey(opaqueBaselineSlot(headScanRoot, runtime.sessionGeneration), deps.sessionId),
|
|
1086
|
+
trigger: "tool_result",
|
|
1087
|
+
label: opaqueLabel,
|
|
1088
|
+
...discarded ? { discarded } : {},
|
|
1089
|
+
runtime
|
|
1090
|
+
}), {
|
|
1091
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1092
|
+
signal: headMoveSignal,
|
|
1093
|
+
hook: "tool_result_edit",
|
|
1094
|
+
label: "head-move-resync"
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
const clientRoots = liveClientRootsApartFrom(headScanRoot);
|
|
1098
|
+
if (clientRoots.length > 0) {
|
|
1099
|
+
const lookSignal = deps.signal ?? undefined;
|
|
1100
|
+
await bounded(Promise.all(clientRoots.map((entry) => lookForOutOfBandChanges(entry.root, "tool_result", isSessionBookkeepingRoot(entry.root, headScanRoot) ? runtime : undefined, {
|
|
1101
|
+
since: entry.spawnedAt,
|
|
1102
|
+
walk: "interval"
|
|
1103
|
+
}).catch((cause) => {
|
|
1104
|
+
recordDegradationOnce({
|
|
1105
|
+
kind: "lsp-client-root-look-failed",
|
|
1106
|
+
subject: normalizeMapKey(entry.root),
|
|
1107
|
+
reason: `the install look at a live client root failed: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
1108
|
+
});
|
|
1109
|
+
}))), {
|
|
1110
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1111
|
+
signal: lookSignal,
|
|
1112
|
+
hook: "tool_result_edit",
|
|
1113
|
+
label: "client-root-install-look"
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
const opaqueSet = new Set(opaquePaths);
|
|
1117
|
+
const written = [...recognizedWritten, ...opaquePaths];
|
|
1118
|
+
const writtenRoots = new Set;
|
|
1119
|
+
for (const file of written)
|
|
1120
|
+
writtenRoots.add(ownerRootOf(file) ?? scanRoot);
|
|
1121
|
+
if (writtenRoots.size > 1)
|
|
1122
|
+
logLatency({
|
|
1123
|
+
type: "phase",
|
|
1124
|
+
phase: "opaque_mutation_multi_root",
|
|
1125
|
+
filePath: [...writtenRoots].join(",").slice(0, 300),
|
|
1126
|
+
durationMs: 0,
|
|
1127
|
+
result: `roots:${writtenRoots.size}`,
|
|
1128
|
+
metadata: { written: written.length }
|
|
1129
|
+
});
|
|
1130
|
+
const sentPopulation = [...written, ...observedOpaquePaths];
|
|
1131
|
+
if (workspaceRoot && sentPopulation.length > 0) {
|
|
1132
|
+
const primaryStarted = Date.now();
|
|
1133
|
+
ensureDiskChangeSubscribers();
|
|
1134
|
+
const sendsByRoot = new Map;
|
|
1135
|
+
for (const file of sentPopulation) {
|
|
1136
|
+
const owner = ownerRootOf(file) ?? (isUnderDir(path.resolve(file), scanRoot) ? scanRoot : workspaceRoot);
|
|
1137
|
+
const bucket = sendsByRoot.get(owner);
|
|
1138
|
+
if (bucket)
|
|
1139
|
+
bucket.push(file);
|
|
1140
|
+
else
|
|
1141
|
+
sendsByRoot.set(owner, [file]);
|
|
1142
|
+
}
|
|
1143
|
+
const publishes = Promise.all([...sendsByRoot].map(async ([root, files]) => ({
|
|
1144
|
+
root,
|
|
1145
|
+
published: await publishDiskChangeChunked({
|
|
1146
|
+
root,
|
|
1147
|
+
origin: "bash-recovery",
|
|
1148
|
+
sources: [BASH_WRITE_SOURCE],
|
|
1149
|
+
kind: "inferred",
|
|
1150
|
+
paths: files
|
|
1151
|
+
})
|
|
1152
|
+
})));
|
|
1153
|
+
const primaryPhase = publishes.then((groups) => {
|
|
1154
|
+
const answers = groups.flatMap(({ root, published }) => published.map(({ results, failedSubscribers }) => readHeldDocumentsAnswer(results, root, failedSubscribers)));
|
|
1155
|
+
return {
|
|
1156
|
+
targets: answers.flatMap((answer) => answer.targets),
|
|
1157
|
+
primary: answers.reduce((count, answer) => count + answer.primary, 0),
|
|
1158
|
+
failed: answers.some((answer) => answer.failed),
|
|
1159
|
+
drained: answers.every((answer) => answer.drained)
|
|
1160
|
+
};
|
|
1161
|
+
});
|
|
1162
|
+
const driftByRoot = new Map;
|
|
1163
|
+
for (const file of opaquePaths) {
|
|
1164
|
+
const root = ownerRootOf(file) ?? scanRoot;
|
|
1165
|
+
const bucket = driftByRoot.get(root);
|
|
1166
|
+
if (bucket)
|
|
1167
|
+
bucket.push(file);
|
|
1168
|
+
else
|
|
1169
|
+
driftByRoot.set(root, [file]);
|
|
1170
|
+
}
|
|
1171
|
+
if (driftByRoot.size > 0)
|
|
1172
|
+
primaryPhase.then(() => Promise.all([...driftByRoot].map(([root, paths]) => publishDriftPass(root, paths, RECOVERED_DRIFT_PASS)))).catch((err) => {
|
|
1173
|
+
dbg(`git-change LSP resync failed: ${err}`);
|
|
1174
|
+
});
|
|
1175
|
+
const primarySignal = deps.signal ?? undefined;
|
|
1176
|
+
const sent = await bounded(primaryPhase, {
|
|
1177
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1178
|
+
signal: primarySignal,
|
|
1179
|
+
hook: "tool_result_edit",
|
|
1180
|
+
label: "bash-write-primary-resync"
|
|
1181
|
+
});
|
|
1182
|
+
if (sent === undefined || sent.failed || sent.targets.length > 0)
|
|
1183
|
+
logLatency({
|
|
1184
|
+
type: "phase",
|
|
1185
|
+
phase: "bash_write_primary_resync",
|
|
1186
|
+
filePath: written.slice(0, 5).join(","),
|
|
1187
|
+
durationMs: Date.now() - primaryStarted,
|
|
1188
|
+
result: sent === undefined ? "cut" : sent.failed ? "failed" : sent.drained ? "sent" : "undrained",
|
|
1189
|
+
metadata: {
|
|
1190
|
+
written: written.length,
|
|
1191
|
+
opaque: opaquePaths.length,
|
|
1192
|
+
targets: sent?.targets.length ?? -1,
|
|
1193
|
+
primary: sent?.primary ?? 0
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
const recognizedAuthoredSet = new Set(recognizedAuthored);
|
|
1198
|
+
bashAuthorshipConfirmed = recognizedAuthored.length > 0;
|
|
1199
|
+
for (const wp of written) {
|
|
1200
|
+
const opaqueEvidence = hadOpaqueRecovery || opaqueSet.has(wp);
|
|
1201
|
+
if (!getFlag("no-read-guard") && recognizedAuthoredSet.has(wp))
|
|
1202
|
+
deps.readGuard?.recordWritten(wp, {
|
|
1203
|
+
authorship: opaqueEvidence ? "unknown" : "whole-file",
|
|
1204
|
+
...opaqueEvidence && { advanceAuthorship: false },
|
|
1205
|
+
stampFileTime: false,
|
|
1206
|
+
...toolCallId !== undefined && { toolCallId }
|
|
1207
|
+
});
|
|
1208
|
+
const receipt = runtime.recordMutationToolReceipt;
|
|
1209
|
+
const autofixMode = (receipt && writeSession.guardedWrite(wp, () => receipt.call(runtime, wp, "write"))?.autofixMode) ?? "immediate";
|
|
1210
|
+
const isOpaque = opaqueSet.has(wp);
|
|
1211
|
+
const syntheticEvent = {
|
|
1212
|
+
...event,
|
|
1213
|
+
toolName: "write",
|
|
1214
|
+
input: { path: wp },
|
|
1215
|
+
isError: false,
|
|
1216
|
+
[DM_LENS_SYNTHETIC_MUTATION_FIELD]: "bash"
|
|
1217
|
+
};
|
|
1218
|
+
const syntheticResult = await handleToolResult({
|
|
1219
|
+
...deps,
|
|
1220
|
+
event: syntheticEvent,
|
|
1221
|
+
_bypassDebounce: true,
|
|
1222
|
+
_ownerRoot: ownerRootOf(wp),
|
|
1223
|
+
_autofixMode: autofixMode,
|
|
1224
|
+
_attachmentBudget: syntheticAttachmentBudget,
|
|
1225
|
+
_mutationSourceOverride: isOpaque ? "opaque-script" : undefined,
|
|
1226
|
+
_readGuardAuthorship: recognizedAuthoredSet.has(wp),
|
|
1227
|
+
_pathAlreadyResolved: true,
|
|
1228
|
+
_ownWriteStamp: {
|
|
1229
|
+
stampFileTime: false,
|
|
1230
|
+
...toolCallId !== undefined && { toolCallId }
|
|
1231
|
+
},
|
|
1232
|
+
_allowAutonomousWriters: recognizedAuthoredSet.has(wp),
|
|
1233
|
+
_sessionGeneration: writeSession
|
|
1234
|
+
});
|
|
1235
|
+
if (syntheticResult) {
|
|
1236
|
+
syntheticWriteContent.push(...syntheticResult.content.slice(event.content.length));
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
if (event.isError !== true && !getFlag("no-read-guard")) {
|
|
1240
|
+
const truncation = event.details?.truncation;
|
|
1241
|
+
const clippedLines = truncation?.truncated === true && typeof truncation.outputLines === "number" ? truncation.outputLines : undefined;
|
|
1242
|
+
const clipped = clippedLines !== undefined;
|
|
1243
|
+
const parsedSpans = extractReadPathsFromCommand(command, workspaceRoot, clipped ? undefined : (candidate) => isRecordableProjectPath(candidate, workspaceRoot));
|
|
1244
|
+
let spans = parsedSpans;
|
|
1245
|
+
if (clipped) {
|
|
1246
|
+
if (parsedSpans.length === 1) {
|
|
1247
|
+
const span = parsedSpans[0];
|
|
1248
|
+
if (span) {
|
|
1249
|
+
const hasTrailingNewline = lastByteIsNewline(span.filePath);
|
|
1250
|
+
const spanLineCount = hasTrailingNewline ? Math.max(1, span.limit - 1) : span.limit;
|
|
1251
|
+
const shown = Math.min(clippedLines, spanLineCount);
|
|
1252
|
+
spans = shown > 0 ? [
|
|
1253
|
+
{
|
|
1254
|
+
...span,
|
|
1255
|
+
offset: span.offset + spanLineCount - shown,
|
|
1256
|
+
limit: shown
|
|
1257
|
+
}
|
|
1258
|
+
] : [];
|
|
1259
|
+
}
|
|
1260
|
+
} else if (parsedSpans.length > 1) {
|
|
1261
|
+
recordDegradationOnce({
|
|
1262
|
+
kind: "bash-view-clipped",
|
|
1263
|
+
subject: "multi-span",
|
|
1264
|
+
reason: "truncated bash view contained multiple spans"
|
|
1265
|
+
});
|
|
1266
|
+
spans = [];
|
|
1267
|
+
}
|
|
1268
|
+
if (parsedSpans.length === 1 && spans.length === 1 && (spans[0]?.offset !== parsedSpans[0]?.offset || spans[0]?.limit !== parsedSpans[0]?.limit)) {
|
|
1269
|
+
recordDegradationOnce({
|
|
1270
|
+
kind: "bash-view-clipped",
|
|
1271
|
+
subject: parsedSpans[0]?.filePath ?? "unknown",
|
|
1272
|
+
reason: "truncated bash view narrowed a single span"
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
for (const span of spans) {
|
|
1277
|
+
if (!isRecordableProjectPath(span.filePath, workspaceRoot))
|
|
1278
|
+
continue;
|
|
1279
|
+
deps.readGuard?.recordRead({
|
|
1280
|
+
filePath: span.filePath,
|
|
1281
|
+
requestedOffset: span.offset,
|
|
1282
|
+
requestedLimit: span.limit,
|
|
1283
|
+
effectiveOffset: span.offset,
|
|
1284
|
+
effectiveLimit: span.limit,
|
|
1285
|
+
expandedByLsp: false,
|
|
1286
|
+
turnIndex: runtime.turnIndex,
|
|
1287
|
+
writeIndex: runtime.peekWriteIndex(),
|
|
1288
|
+
timestamp: Date.now(),
|
|
1289
|
+
...readEvidenceToolCallId !== undefined && {
|
|
1290
|
+
toolCallId: readEvidenceToolCallId
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const readGuard = deps.readGuard;
|
|
1296
|
+
if (event.isError !== true && readGuard !== undefined && !getFlag("no-lsp") && !getFlag("no-read-guard")) {
|
|
1297
|
+
for (const dp of extractDeletedPathsFromCommand(command, workspaceRoot)) {
|
|
1298
|
+
const verdict = judgeConfirmedDelete(dp, {
|
|
1299
|
+
isExternalOrVendorFile: (p) => isExternalOrVendorFile(p, workspaceRoot),
|
|
1300
|
+
isPathIgnoredByProject: (p) => isPathIgnoredByProject(p, workspaceRoot, false),
|
|
1301
|
+
hasKnownPath: (p) => readGuard.hasKnownPath(p),
|
|
1302
|
+
existsSync: (p) => nodeFs.existsSync(p)
|
|
1303
|
+
});
|
|
1304
|
+
if (verdict !== "confirmed")
|
|
1305
|
+
continue;
|
|
1306
|
+
readGuard.forgetPath(dp);
|
|
1307
|
+
notifyExternalFileChange(dp, 3).catch((err) => {
|
|
1308
|
+
dbg(`tool_result: external-delete notify failed for ${dp}: ${err}`);
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (deps.readGuard && event.toolName === "read" && event.isError !== true && filePath && !getFlag("no-read-guard") && !isExternalOrVendorFile(filePath, workspaceRoot)) {
|
|
1314
|
+
const deliveredFilePath = attribution?.resolvedPath && nodeFs.existsSync(attribution.resolvedPath) ? attribution.resolvedPath : filePath;
|
|
1315
|
+
if (nodeFs.existsSync(deliveredFilePath)) {
|
|
1316
|
+
const input = event.input;
|
|
1317
|
+
const requestedOffset = Math.max(1, input.offset ?? 1);
|
|
1318
|
+
const requestedLimit = input.limit;
|
|
1319
|
+
const truncation = event.details?.truncation;
|
|
1320
|
+
const deliveredScan = scanFileLines(deliveredFilePath, [{ offset: requestedOffset, limit: Number.POSITIVE_INFINITY }], { count: true });
|
|
1321
|
+
const totalLines = deliveredScan?.totalLines ?? 1;
|
|
1322
|
+
const available = Math.max(0, totalLines - requestedOffset + 1);
|
|
1323
|
+
const deliveredLimit = Math.min(available, truncation?.outputLines ?? requestedLimit ?? available);
|
|
1324
|
+
if (deliveredLimit > 0) {
|
|
1325
|
+
if (truncation?.truncated === true && deliveredLimit < available) {
|
|
1326
|
+
recordDegradationOnce({
|
|
1327
|
+
kind: "native-read-clipped",
|
|
1328
|
+
subject: deliveredFilePath,
|
|
1329
|
+
reason: "native read result was clipped before delivery"
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
logReadGuardEvent({
|
|
1333
|
+
event: "read_pattern",
|
|
1334
|
+
sessionId: runtime.telemetrySessionId,
|
|
1335
|
+
filePath: deliveredFilePath,
|
|
1336
|
+
requestedOffset,
|
|
1337
|
+
requestedLimit: requestedLimit ?? deliveredLimit,
|
|
1338
|
+
effectiveOffset: requestedOffset,
|
|
1339
|
+
effectiveLimit: deliveredLimit,
|
|
1340
|
+
metadata: {
|
|
1341
|
+
totalLines,
|
|
1342
|
+
isPartial: deliveredLimit < available,
|
|
1343
|
+
fileKind: detectFileKind(deliveredFilePath) ?? "unknown",
|
|
1344
|
+
fractionRead: available > 0 ? Math.round(deliveredLimit / available * 100) / 100 : 1,
|
|
1345
|
+
expandedByTs: false
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
const raced = deps.readGuard.diskMovedSinceStamp(deliveredFilePath);
|
|
1349
|
+
const deliveredText = raced ? deliveredLineEvidence(piReadBody(event.content.map((part) => part.type === "text" ? part.text ?? "" : "").join(`
|
|
1350
|
+
`)), requestedOffset) : undefined;
|
|
1351
|
+
const capture = raced ? deps.readGuard.getReadHistory(deliveredFilePath).slice().reverse().find((candidate) => candidate.source === `native-read:${toolCallId}:provisional`) : undefined;
|
|
1352
|
+
const capturedLines = capture?.lineHashes ? Object.keys(capture.lineHashes).length : 0;
|
|
1353
|
+
const delivered = deliveredText && (truncation?.outputLines !== undefined ? deliveredText.lineCount <= truncation.outputLines : requestedLimit !== undefined && deliveredText.lineCount === capturedLines) ? deliveredText : undefined;
|
|
1354
|
+
const shownLimit = capture ? Math.min(capture.effectiveLimit, truncation?.outputLines ?? Number.POSITIVE_INFINITY, capturedLines) : 0;
|
|
1355
|
+
const captureEvidence = capture?.lineHashes && {
|
|
1356
|
+
effectiveOffset: capture.effectiveOffset,
|
|
1357
|
+
effectiveLimit: shownLimit,
|
|
1358
|
+
lineHashes: Object.fromEntries(Object.entries(capture.lineHashes).slice(0, shownLimit))
|
|
1359
|
+
};
|
|
1360
|
+
if (raced) {
|
|
1361
|
+
incrementDegradationCount({
|
|
1362
|
+
kind: "native-read-raced-writer",
|
|
1363
|
+
subject: deliveredFilePath,
|
|
1364
|
+
reason: delivered ? "the file changed between DM's read and its tool_result; the read is recorded from the delivered text" : captureEvidence ? "the file changed between DM's read and its tool_result; DM's line count does not vouch for the delivered text, so the tool_call's capture is the evidence" : "the file changed between DM's read and its tool_result; DM's line count does not vouch for the delivered text and there is no hashed tool_call capture, so the read is not recorded"
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
const evidence = raced && !delivered ? captureEvidence : {
|
|
1368
|
+
effectiveOffset: requestedOffset,
|
|
1369
|
+
effectiveLimit: delivered?.lineCount ?? deliveredLimit,
|
|
1370
|
+
lineHashes: raced ? delivered?.lineHashes : deliveredScan?.hashes(requestedOffset, deliveredLimit)
|
|
1371
|
+
};
|
|
1372
|
+
if (evidence) {
|
|
1373
|
+
const deliveredRecord = {
|
|
1374
|
+
filePath: deliveredFilePath,
|
|
1375
|
+
requestedOffset,
|
|
1376
|
+
requestedLimit: requestedLimit ?? deliveredLimit,
|
|
1377
|
+
effectiveOffset: evidence.effectiveOffset,
|
|
1378
|
+
effectiveLimit: evidence.effectiveLimit,
|
|
1379
|
+
expandedByLsp: false,
|
|
1380
|
+
...evidence.lineHashes && { lineHashes: evidence.lineHashes },
|
|
1381
|
+
turnIndex: runtime.turnIndex,
|
|
1382
|
+
writeIndex: runtime.peekWriteIndex(),
|
|
1383
|
+
timestamp: Date.now(),
|
|
1384
|
+
...readEvidenceToolCallId !== undefined && {
|
|
1385
|
+
toolCallId: readEvidenceToolCallId
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
deps.readGuard.recordRead(deliveredRecord, {
|
|
1389
|
+
...toolCallId && { supersedes: { toolCallId } },
|
|
1390
|
+
stampFileTime: !raced
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
const mutation = classifyMutatingTool(event, {
|
|
1397
|
+
filePath: filePath || undefined,
|
|
1398
|
+
sessionId: deps.sessionId,
|
|
1399
|
+
recognizeOnly: true
|
|
1400
|
+
});
|
|
1401
|
+
if (mutation && filePath && event.isError !== true) {
|
|
1402
|
+
noteAgentMutation(filePath, expectationFromToolInput(event.input, mutation.kind));
|
|
1403
|
+
}
|
|
1404
|
+
const observationPending = !getFlag("no-read-guard") && !isBashDerivedReplay(event) && hasPendingObservation(resolveToolCallCorrelationId(event));
|
|
1405
|
+
const preSettleStateHash = observationPending && filePath ? getFileStateHash(filePath) : undefined;
|
|
1406
|
+
let observedReplayed = 0;
|
|
1407
|
+
let observedChangedPaths = [];
|
|
1408
|
+
if (observationPending) {
|
|
1409
|
+
const observed = await settleObservedMutation({
|
|
1410
|
+
toolCallId: resolveToolCallCorrelationId(event),
|
|
1411
|
+
toolName: event.toolName,
|
|
1412
|
+
sessionGeneration: writeSession.scopeId,
|
|
1413
|
+
turnIndex: runtime.turnKey(deps.sessionId),
|
|
1414
|
+
signal: getAmbientAbortSignal(),
|
|
1415
|
+
record: (entry) => replayThroughMutationBridge({ ...entry, lineage: writeSession }),
|
|
1416
|
+
getStoredLineHashes: (candidate) => storedLineHashesFor(deps.readGuard, candidate),
|
|
1417
|
+
isRecordable: (candidate) => isRecordableProjectPath(candidate, workspaceRoot),
|
|
1418
|
+
dbg
|
|
1419
|
+
});
|
|
1420
|
+
observedReplayed = observed.replayed;
|
|
1421
|
+
observedChangedPaths = observed.changedPaths;
|
|
1422
|
+
if (observed.replayed > 0) {
|
|
1423
|
+
dbg(`tool_result: observed ${observed.replayed} mutation(s) from tool "${event.toolName}"`);
|
|
1424
|
+
} else if (observed.reason) {
|
|
1425
|
+
dbg(`tool_result: observation for "${event.toolName}" did not settle: ${observed.reason}`);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
const toolResultStart = Date.now();
|
|
1429
|
+
if (observedReplayed > 0) {
|
|
1430
|
+
if (!filePath || !isExternalOrVendorFile(filePath, workspaceRoot)) {
|
|
1431
|
+
const observedKind = mutation?.kind ?? "edit";
|
|
1432
|
+
const observedAppliedPairs = filePath ? recordNativeAppliedPairs({
|
|
1433
|
+
runtime,
|
|
1434
|
+
input: event.input,
|
|
1435
|
+
kind: observedKind,
|
|
1436
|
+
filePath,
|
|
1437
|
+
stateHash: preSettleStateHash ?? getFileStateHash(filePath)
|
|
1438
|
+
}) : [];
|
|
1439
|
+
const observedDispatchPaths = observedChangedPaths.filter((candidate) => {
|
|
1440
|
+
try {
|
|
1441
|
+
return !nodeFs.statSync(candidate).isDirectory();
|
|
1442
|
+
} catch {
|
|
1443
|
+
return false;
|
|
1444
|
+
}
|
|
1445
|
+
}).slice(0, OBSERVED_DISPATCH_MAX_PATHS);
|
|
1446
|
+
const observedDispatchDropped = observedChangedPaths.length - observedDispatchPaths.length;
|
|
1447
|
+
if (observedDispatchDropped > 0) {
|
|
1448
|
+
incrementDegradationCount({
|
|
1449
|
+
kind: "observed-mutation-dispatch-cap",
|
|
1450
|
+
subject: event.toolName,
|
|
1451
|
+
reason: `observed mutation dispatch capped at ${OBSERVED_DISPATCH_MAX_PATHS}; ${observedDispatchDropped} path(s) not dispatched`
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
const observedAutofixModes = new Map;
|
|
1455
|
+
for (const observedPath of observedChangedPaths)
|
|
1456
|
+
writeSession.guardedWrite(observedPath, () => {
|
|
1457
|
+
refreshCachedExports(runtime, observedPath);
|
|
1458
|
+
const receipt = runtime.recordMutationToolReceipt?.call(runtime, observedPath, observedKind);
|
|
1459
|
+
if (receipt)
|
|
1460
|
+
observedAutofixModes.set(observedPath, receipt.autofixMode);
|
|
1461
|
+
});
|
|
1462
|
+
if (observedDispatchPaths.length > 0) {
|
|
1463
|
+
const observedClients = ensureToolResultClients(deps);
|
|
1464
|
+
if (observedClients !== true && !await bounded(Promise.resolve(observedClients), {
|
|
1465
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1466
|
+
signal: deps.signal ?? undefined,
|
|
1467
|
+
hook: "tool_result_edit",
|
|
1468
|
+
label: "observed-tool-result-analysis"
|
|
1469
|
+
}))
|
|
1470
|
+
return;
|
|
1471
|
+
const observedReadGuardCorrelationId = getReadGuardCorrelationId(event);
|
|
1472
|
+
for (const observedPath of observedDispatchPaths) {
|
|
1473
|
+
if (writeSession.guardedWrite(observedPath, () => true) !== true)
|
|
1474
|
+
continue;
|
|
1475
|
+
const observedRootMode = classifyAnalysisRoot(observedPath, workspaceRoot).mode;
|
|
1476
|
+
const observedDispatchSignal = deps.signal;
|
|
1477
|
+
const observedJoinSignal = deps.signal;
|
|
1478
|
+
const observedStateHashForPath = getFileStateHash(observedPath);
|
|
1479
|
+
const observedClaim = claimPipelineDispatch({
|
|
1480
|
+
filePath: observedPath,
|
|
1481
|
+
stateHash: observedStateHashForPath,
|
|
1482
|
+
turnIndex: runtime.turnIndex,
|
|
1483
|
+
authored: true,
|
|
1484
|
+
participantId: observedReadGuardCorrelationId,
|
|
1485
|
+
dbg
|
|
1486
|
+
});
|
|
1487
|
+
if (!observedClaim.proceed) {
|
|
1488
|
+
if (observedClaim.joined) {
|
|
1489
|
+
await bounded(observedClaim.joined, {
|
|
1490
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1491
|
+
signal: observedJoinSignal,
|
|
1492
|
+
hook: "tool_result_edit",
|
|
1493
|
+
label: "observed-tool-result-join"
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
const observedWriteIndex = runtime.nextWriteIndex();
|
|
1499
|
+
const observedWriteOrderTurn = runtime.writeOrderTurn;
|
|
1500
|
+
const observedTurnStateCwd = path.resolve(workspaceRoot);
|
|
1501
|
+
const observedDispatchOutcome = await bounded(dispatchPipelineAnalysis({
|
|
1502
|
+
deps,
|
|
1503
|
+
runtime,
|
|
1504
|
+
filePath: observedPath,
|
|
1505
|
+
dispatchCwd: resolveLanguageRootForFile(observedPath, workspaceRoot),
|
|
1506
|
+
turnStateCwd: observedTurnStateCwd,
|
|
1507
|
+
analysisRootMode: observedRootMode,
|
|
1508
|
+
autofixMode: observedAutofixModes.get(observedPath) ?? (observedKind === "edit" ? "deferred" : "immediate"),
|
|
1509
|
+
modifiedRanges: undefined,
|
|
1510
|
+
writeIndex: observedWriteIndex,
|
|
1511
|
+
writeOrderTurn: observedWriteOrderTurn,
|
|
1512
|
+
initialStateHash: observedStateHashForPath,
|
|
1513
|
+
readGuardCorrelationId: observedReadGuardCorrelationId,
|
|
1514
|
+
requestedEditIndexes: getRequestedEditIndexes(event, observedKind),
|
|
1515
|
+
requestedEditTotal: getRequestedEditCount(event, observedKind),
|
|
1516
|
+
isPartialApplyResult: (event.details ?? {}).piLensPartialApply === true,
|
|
1517
|
+
participantIds: [observedReadGuardCorrelationId],
|
|
1518
|
+
participantTotal: 1,
|
|
1519
|
+
toolResultStart,
|
|
1520
|
+
nativeAppliedPairs: observedAppliedPairs,
|
|
1521
|
+
allowAutonomousWriters: true,
|
|
1522
|
+
sessionGeneration: writeSession,
|
|
1523
|
+
ownFileTimeStamp: false
|
|
1524
|
+
}), {
|
|
1525
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1526
|
+
signal: observedDispatchSignal,
|
|
1527
|
+
hook: "tool_result_edit",
|
|
1528
|
+
label: "observed-tool-result-analysis"
|
|
1529
|
+
});
|
|
1530
|
+
if (observedDispatchOutcome?.crashed) {
|
|
1531
|
+
dbg(`tool_result: pipeline analysis crashed for the observed mutation on ${observedPath}; the recorded edit stands, analysis did not run this turn`);
|
|
1532
|
+
return observedDispatchOutcome.response;
|
|
1533
|
+
}
|
|
1534
|
+
if (observedDispatchOutcome) {
|
|
1535
|
+
publishInlineVerdict({
|
|
1536
|
+
runtime,
|
|
1537
|
+
cacheManager,
|
|
1538
|
+
filePath: observedPath,
|
|
1539
|
+
result: observedDispatchOutcome.result,
|
|
1540
|
+
writeSession,
|
|
1541
|
+
writeIndex: observedWriteIndex,
|
|
1542
|
+
writeOrderTurn: observedWriteOrderTurn,
|
|
1543
|
+
authored: true,
|
|
1544
|
+
getFlag,
|
|
1545
|
+
turnStateCwd: observedTurnStateCwd,
|
|
1546
|
+
analysisRootMode: observedRootMode,
|
|
1547
|
+
sessionId: deps.sessionId
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
dbg(`tool_result: the observational settle already recorded ${observedReplayed} mutation(s) for "${event.toolName}"; kept the applied-edit records, mutation receipt, cachedExports refresh, and ran the pipeline dispatch (#2464); skipped the bridge-covered staleness stamp / turn-state ranges / change-log receipt / deferred autofix+format`);
|
|
1552
|
+
} else {
|
|
1553
|
+
dbg(`tool_result: the observational settle recorded ${observedReplayed} mutation(s) for "${event.toolName}", but no dispatchable changed paths remained`);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
return syntheticWriteContent.length > 0 ? {
|
|
1557
|
+
content: [...event.content, ...syntheticWriteContent],
|
|
1558
|
+
structuredContent: event.structuredContent
|
|
1559
|
+
} : undefined;
|
|
1560
|
+
}
|
|
1561
|
+
if (mutation === undefined) {
|
|
1562
|
+
dbg(`tool_result: skipped turn tracking - toolName="${event.toolName}" is not a classified mutation`);
|
|
1563
|
+
return syntheticWriteContent.length > 0 || readNote.length > 0 ? {
|
|
1564
|
+
content: [...readNote, ...event.content, ...syntheticWriteContent],
|
|
1565
|
+
structuredContent: event.structuredContent
|
|
1566
|
+
} : undefined;
|
|
1567
|
+
}
|
|
1568
|
+
if (!filePath) {
|
|
1569
|
+
dbg(`tool_result: skipped turn tracking - no filePath for toolName="${event.toolName}"`);
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
if (analysisRootMode === "none") {
|
|
1573
|
+
if (isOutsideProjectRoot(filePath, workspaceRoot) && !isVendorPath(filePath) && !isDmLensInternalPath(filePath, workspaceRoot)) {
|
|
1574
|
+
const firstOutsideRootEdit = recordDegradationOnce({
|
|
1575
|
+
kind: "tool-result-outside-project-root",
|
|
1576
|
+
subject: workspaceRoot,
|
|
1577
|
+
reason: `edit outside session root: ${filePath}`
|
|
1578
|
+
});
|
|
1579
|
+
if (firstOutsideRootEdit) {
|
|
1580
|
+
queueAgentAdvisory(`dm-lens skipped analysis for the edit at ${filePath} because it is outside the session root. Start DM in that directory or add it to the workspace to get analysis.`, writeSession);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
dbg(`tool_result: skipped pipeline - file outside project root or in node_modules: ${filePath}`);
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
if (analysisRootMode === "adopted") {
|
|
1587
|
+
const adoptedRoot = analysisRoot.root;
|
|
1588
|
+
if (adoptedRoot) {
|
|
1589
|
+
const firstAdoptedRoot = recordDegradationOnce({
|
|
1590
|
+
kind: "tool-result-adopted-project",
|
|
1591
|
+
subject: adoptedRoot,
|
|
1592
|
+
reason: `analysing ${adoptedRoot} as a separate project`
|
|
1593
|
+
});
|
|
1594
|
+
if (firstAdoptedRoot) {
|
|
1595
|
+
queueAgentAdvisory(`dm-lens is analysing ${adoptedRoot} as a separate project (LSP + global or managed php-lint/fish-indent; formatting, autofix, other dispatch runners, and automatic tests are off).`, writeSession);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
noteMutationHandled(filePath);
|
|
1600
|
+
const readGuardCorrelationId = getReadGuardCorrelationId(event);
|
|
1601
|
+
const resultDetails = event.details ?? {};
|
|
1602
|
+
const isPartialApplyResult = resultDetails.piLensPartialApply === true;
|
|
1603
|
+
const requestedEditIndexes = getRequestedEditIndexes(event, mutation.kind);
|
|
1604
|
+
const requestedEditTotal = getRequestedEditCount(event, mutation.kind);
|
|
1605
|
+
const participantIds = [
|
|
1606
|
+
...deps._telemetryParticipantIds ?? [],
|
|
1607
|
+
readGuardCorrelationId
|
|
1608
|
+
].slice(0, 100);
|
|
1609
|
+
const participantTotal = (deps._telemetryParticipantTotal ?? 0) + (deps._telemetryParticipantIds?.includes(readGuardCorrelationId) ? 0 : 1);
|
|
1610
|
+
const hostToolResultFailed = event.isError === true || resultDetails.isError === true;
|
|
1611
|
+
if (hostToolResultFailed) {
|
|
1612
|
+
logReadGuardEvent({
|
|
1613
|
+
event: "edit_batch_summary",
|
|
1614
|
+
correlationId: readGuardCorrelationId,
|
|
1615
|
+
filePath,
|
|
1616
|
+
metadata: {
|
|
1617
|
+
tool: event.toolName,
|
|
1618
|
+
source: "host_tool_result",
|
|
1619
|
+
editBatchSummary: createReadGuardEditBatchSummary({
|
|
1620
|
+
requestedIndexes: requestedEditIndexes,
|
|
1621
|
+
requestedTotal: requestedEditTotal,
|
|
1622
|
+
rejectedReasons: requestedEditIndexes.map((index) => ({
|
|
1623
|
+
index,
|
|
1624
|
+
code: "write_failed"
|
|
1625
|
+
})),
|
|
1626
|
+
rejectedTotal: requestedEditTotal,
|
|
1627
|
+
participantIds: [readGuardCorrelationId],
|
|
1628
|
+
participantTotal: 1,
|
|
1629
|
+
commitStatus: "failed",
|
|
1630
|
+
terminalStatus: "failed"
|
|
1631
|
+
})
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
return {
|
|
1635
|
+
content: event.content,
|
|
1636
|
+
isError: true,
|
|
1637
|
+
structuredContent: event.structuredContent
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
const postWriteStateHash = preSettleStateHash ?? getFileStateHash(filePath);
|
|
1641
|
+
const nativeAppliedPairs = recordNativeAppliedPairs({
|
|
1642
|
+
runtime,
|
|
1643
|
+
input: event.input,
|
|
1644
|
+
kind: mutation.kind,
|
|
1645
|
+
filePath,
|
|
1646
|
+
stateHash: postWriteStateHash
|
|
1647
|
+
});
|
|
1648
|
+
const ownEdit = attribution?.editInPlace ? singlePositionalEdit(event.input) : undefined;
|
|
1649
|
+
const nativeAuthoredRanges = mutation.kind === "edit" && ownEdit ? (() => {
|
|
1650
|
+
const evidence = ownEditEvidence(filePath, ownEdit);
|
|
1651
|
+
return [
|
|
1652
|
+
[ownEdit.start, ownEdit.start + evidence.lineCount - 1]
|
|
1653
|
+
];
|
|
1654
|
+
})() : undefined;
|
|
1655
|
+
if (ownEdit) {
|
|
1656
|
+
const evidence = ownEditEvidence(filePath, ownEdit);
|
|
1657
|
+
deps.readGuard?.recordRead({
|
|
1658
|
+
filePath,
|
|
1659
|
+
requestedOffset: ownEdit.start,
|
|
1660
|
+
requestedLimit: evidence.lineCount,
|
|
1661
|
+
effectiveOffset: ownEdit.start,
|
|
1662
|
+
effectiveLimit: evidence.lineCount,
|
|
1663
|
+
expandedByLsp: false,
|
|
1664
|
+
...evidence.lineHashes && { lineHashes: evidence.lineHashes },
|
|
1665
|
+
turnIndex: runtime.turnIndex,
|
|
1666
|
+
writeIndex: runtime.peekWriteIndex(),
|
|
1667
|
+
timestamp: Date.now(),
|
|
1668
|
+
source: "own-edit",
|
|
1669
|
+
...readEvidenceToolCallId !== undefined && {
|
|
1670
|
+
toolCallId: readEvidenceToolCallId
|
|
1671
|
+
}
|
|
1672
|
+
}, { stampFileTime: false });
|
|
1673
|
+
logConversationRead("own-edit", filePath, ownEdit.start, evidence);
|
|
1674
|
+
}
|
|
1675
|
+
const executedContent = event.input.content;
|
|
1676
|
+
const ownWriteStamp = deps._ownWriteStamp ?? {
|
|
1677
|
+
stampFileTime: attribution?.fileTimeStale !== true,
|
|
1678
|
+
...typeof executedContent === "string" && {
|
|
1679
|
+
writtenContent: executedContent
|
|
1680
|
+
},
|
|
1681
|
+
...toolCallId !== undefined && { toolCallId }
|
|
1682
|
+
};
|
|
1683
|
+
const receipt = runtime.recordMutationToolReceipt;
|
|
1684
|
+
const autofixMode = deps._bypassDebounce ? deps._autofixMode ?? (mutation.kind === "edit" ? "deferred" : "immediate") : (receipt && writeSession.guardedWrite(filePath, () => receipt.call(runtime, filePath, mutation.kind))?.autofixMode) ?? (mutation.kind === "edit" ? "deferred" : "immediate");
|
|
1685
|
+
if (!deps._bypassDebounce) {
|
|
1686
|
+
const debounceMs = getDebounceMs();
|
|
1687
|
+
if (debounceMs > 0) {
|
|
1688
|
+
return scheduleDebounced(filePath, debounceMs, {
|
|
1689
|
+
...deps,
|
|
1690
|
+
_sessionGeneration: writeSession,
|
|
1691
|
+
_autofixMode: autofixMode,
|
|
1692
|
+
_ownWriteStamp: ownWriteStamp,
|
|
1693
|
+
_telemetryParticipantIds: [readGuardCorrelationId],
|
|
1694
|
+
_telemetryParticipantTotal: 1
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (bashAuthorshipConfirmed)
|
|
1699
|
+
deps.readGuard?.recordWritten(filePath, {
|
|
1700
|
+
authorship: mutation.kind === "write" ? "whole-file" : nativeAuthoredRanges !== undefined ? "partial" : "unknown",
|
|
1701
|
+
...nativeAuthoredRanges !== undefined && {
|
|
1702
|
+
authoredRanges: nativeAuthoredRanges
|
|
1703
|
+
},
|
|
1704
|
+
...ownWriteStamp,
|
|
1705
|
+
contentHash: postWriteStateHash
|
|
1706
|
+
});
|
|
1707
|
+
refreshCachedExports(runtime, filePath);
|
|
1708
|
+
const initialStateHash = postWriteStateHash;
|
|
1709
|
+
const classifiedClients = ensureToolResultClients(deps);
|
|
1710
|
+
const classifiedClientsReady = classifiedClients === true || !!await bounded(Promise.resolve(classifiedClients), {
|
|
1711
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1712
|
+
signal: deps.signal,
|
|
1713
|
+
hook: "tool_result_edit",
|
|
1714
|
+
label: "classified-tool-result-analysis"
|
|
1715
|
+
});
|
|
1716
|
+
const classifiedClaim = claimPipelineDispatch({
|
|
1717
|
+
filePath,
|
|
1718
|
+
stateHash: initialStateHash,
|
|
1719
|
+
turnIndex: runtime.turnIndex,
|
|
1720
|
+
authored: bashAuthorshipConfirmed,
|
|
1721
|
+
participantId: readGuardCorrelationId,
|
|
1722
|
+
dbg
|
|
1723
|
+
});
|
|
1724
|
+
if (!classifiedClaim.proceed) {
|
|
1725
|
+
if (classifiedClaim.joined) {
|
|
1726
|
+
await classifiedClaim.joined;
|
|
1727
|
+
}
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
const entryLive = writeSession.guardedWrite(filePath, () => true) === true;
|
|
1731
|
+
if (!getFlag("no-read-guard") && bashAuthorshipConfirmed) {
|
|
1732
|
+
const readGuard = runtime.readGuard;
|
|
1733
|
+
if (entryLive)
|
|
1734
|
+
readGuard?.recordWritten?.(filePath, {
|
|
1735
|
+
authorship: mutation.kind === "write" ? "whole-file" : nativeAuthoredRanges !== undefined ? "partial" : "unknown",
|
|
1736
|
+
...nativeAuthoredRanges !== undefined && {
|
|
1737
|
+
authoredRanges: nativeAuthoredRanges
|
|
1738
|
+
},
|
|
1739
|
+
...ownWriteStamp,
|
|
1740
|
+
contentHash: postWriteStateHash
|
|
1741
|
+
});
|
|
1742
|
+
else
|
|
1743
|
+
recordDroppedRead(writeSession, "tool-result", writeSession.branchEpoch);
|
|
1744
|
+
}
|
|
1745
|
+
dbg(`tool_result: tracking turn state for ${event.toolName} on ${filePath}`);
|
|
1746
|
+
if (isPathIgnoredByProject(filePath, deps._ownerRoot ?? workspaceRoot, false)) {
|
|
1747
|
+
dbg(`tool_result: skipping gitignored file ${filePath}`);
|
|
1748
|
+
return;
|
|
1749
|
+
}
|
|
1750
|
+
const dispatchCwd = resolveLanguageRootForFile(filePath, workspaceRoot);
|
|
1751
|
+
const turnStateCwd = path.resolve(workspaceRoot);
|
|
1752
|
+
dbg(`tool_result: resolved dispatch cwd ${dispatchCwd} for ${filePath} (turnState cwd ${turnStateCwd})`);
|
|
1753
|
+
const writeIndex = runtime.nextWriteIndex();
|
|
1754
|
+
const writeOrderTurn = runtime.writeOrderTurn;
|
|
1755
|
+
let modifiedRanges;
|
|
1756
|
+
const adapterRanges = mutation.editRanges && mutation.editRanges.length > 0 ? mutation.editRanges.map(([start, end]) => ({ start, end })) : mutation.touchedLines ? [{ start: mutation.touchedLines[0], end: mutation.touchedLines[1] }] : undefined;
|
|
1757
|
+
const addTurnRange = (range, importsChanged) => {
|
|
1758
|
+
if (entryLive)
|
|
1759
|
+
cacheManager.addModifiedRange(filePath, range, importsChanged, turnStateCwd, deps.sessionId ?? runtime.telemetrySessionId, "pi", undefined, analysisRootMode);
|
|
1760
|
+
};
|
|
1761
|
+
try {
|
|
1762
|
+
const details = event.details;
|
|
1763
|
+
dbg(`tool_result: details.diff=${details?.diff ? "present" : "missing"}, details keys: ${Object.keys(event.details || {}).join(", ")}`);
|
|
1764
|
+
if (mutation.kind === "edit" && details?.diff) {
|
|
1765
|
+
const diff = details.diff;
|
|
1766
|
+
dbg(`tool_result: diff content (first 500 chars): ${diff.substring(0, 500)}`);
|
|
1767
|
+
const ranges = parseDiffRanges(diff);
|
|
1768
|
+
modifiedRanges = ranges;
|
|
1769
|
+
const importsChanged = /import\s/.test(diff) || /from\s+['"]/.test(diff);
|
|
1770
|
+
dbg(`tool_result: parsed ${ranges.length} ranges, importsChanged=${importsChanged}`);
|
|
1771
|
+
for (const range of ranges) {
|
|
1772
|
+
dbg(`tool_result: adding range ${range.start}-${range.end} for ${filePath}`);
|
|
1773
|
+
addTurnRange(range, importsChanged);
|
|
1774
|
+
}
|
|
1775
|
+
dbg(`tool_result: turn state after add: ${JSON.stringify(cacheManager.readTurnState(turnStateCwd))}`);
|
|
1776
|
+
} else if (mutation.kind === "edit" && adapterRanges && nodeFs.existsSync(filePath)) {
|
|
1777
|
+
const content = nodeFs.readFileSync(filePath, "utf-8");
|
|
1778
|
+
const importsChanged = /^import\s/m.test(content);
|
|
1779
|
+
modifiedRanges = adapterRanges;
|
|
1780
|
+
for (const range of adapterRanges)
|
|
1781
|
+
addTurnRange(range, importsChanged);
|
|
1782
|
+
} else if (mutation.kind === "edit" && mutation.provenance === "declared" && nodeFs.existsSync(filePath)) {
|
|
1783
|
+
const content = nodeFs.readFileSync(filePath, "utf-8");
|
|
1784
|
+
const lineCount = content.split(`
|
|
1785
|
+
`).length;
|
|
1786
|
+
const importsChanged = /^import\s/m.test(content);
|
|
1787
|
+
modifiedRanges = [{ start: 1, end: lineCount }];
|
|
1788
|
+
addTurnRange({ start: 1, end: lineCount }, importsChanged);
|
|
1789
|
+
} else if (mutation.kind === "write" && nodeFs.existsSync(filePath)) {
|
|
1790
|
+
const content = nodeFs.readFileSync(filePath, "utf-8");
|
|
1791
|
+
const lineCount = content.split(`
|
|
1792
|
+
`).length;
|
|
1793
|
+
const hasImports = /^import\s/m.test(content);
|
|
1794
|
+
modifiedRanges = [{ start: 1, end: lineCount }];
|
|
1795
|
+
addTurnRange({ start: 1, end: lineCount }, hasImports);
|
|
1796
|
+
}
|
|
1797
|
+
} catch (err) {
|
|
1798
|
+
dbg(`turn state tracking error: ${err}`);
|
|
1799
|
+
dbg(`turn state tracking error stack: ${err.stack}`);
|
|
1800
|
+
}
|
|
1801
|
+
recordProjectChange({
|
|
1802
|
+
runtime,
|
|
1803
|
+
cwd: turnStateCwd,
|
|
1804
|
+
analysisRootMode,
|
|
1805
|
+
filePath,
|
|
1806
|
+
source: deps._mutationSourceOverride ?? sourceForMutation(mutation, event.details),
|
|
1807
|
+
changedRange: singleRange(modifiedRanges),
|
|
1808
|
+
dbg
|
|
1809
|
+
});
|
|
1810
|
+
const turnStateMs = Date.now() - toolResultStart;
|
|
1811
|
+
logLatency({
|
|
1812
|
+
type: "phase",
|
|
1813
|
+
toolName: event.toolName,
|
|
1814
|
+
filePath,
|
|
1815
|
+
phase: "turn_state_tracking",
|
|
1816
|
+
durationMs: turnStateMs
|
|
1817
|
+
});
|
|
1818
|
+
dbg(`tool_result fired for: ${filePath} (turn_state: ${turnStateMs}ms)`);
|
|
1819
|
+
if (!classifiedClientsReady || !entryLive)
|
|
1820
|
+
return;
|
|
1821
|
+
const dispatchOutcome = await bounded(dispatchPipelineAnalysis({
|
|
1822
|
+
deps,
|
|
1823
|
+
runtime,
|
|
1824
|
+
filePath,
|
|
1825
|
+
dispatchCwd,
|
|
1826
|
+
turnStateCwd,
|
|
1827
|
+
analysisRootMode,
|
|
1828
|
+
autofixMode,
|
|
1829
|
+
modifiedRanges,
|
|
1830
|
+
writeIndex,
|
|
1831
|
+
writeOrderTurn,
|
|
1832
|
+
initialStateHash,
|
|
1833
|
+
readGuardCorrelationId,
|
|
1834
|
+
requestedEditIndexes,
|
|
1835
|
+
requestedEditTotal,
|
|
1836
|
+
isPartialApplyResult,
|
|
1837
|
+
participantIds,
|
|
1838
|
+
participantTotal,
|
|
1839
|
+
toolResultStart,
|
|
1840
|
+
nativeAppliedPairs,
|
|
1841
|
+
preserveNativeAuthorship: mutation.kind !== "write",
|
|
1842
|
+
allowAutonomousWriters: bashAuthorshipConfirmed,
|
|
1843
|
+
sessionGeneration: writeSession,
|
|
1844
|
+
ownFileTimeStamp: ownWriteStamp.stampFileTime
|
|
1845
|
+
}), {
|
|
1846
|
+
ms: HOOK_WALL_BUDGET_MS.tool_result_edit,
|
|
1847
|
+
signal: deps.signal || undefined,
|
|
1848
|
+
hook: "tool_result_edit",
|
|
1849
|
+
label: "pipeline-analysis"
|
|
1850
|
+
});
|
|
1851
|
+
if (!dispatchOutcome)
|
|
1852
|
+
return;
|
|
1853
|
+
if (dispatchOutcome.crashed) {
|
|
1854
|
+
return dispatchOutcome.response;
|
|
1855
|
+
}
|
|
1856
|
+
const result = dispatchOutcome.result;
|
|
1857
|
+
const resultLive = writeSession.guardedWrite(filePath, () => true) === true;
|
|
1858
|
+
let autofixNewlyQueued = false;
|
|
1859
|
+
if (resultLive && !result.isError && bashAuthorshipConfirmed && autofixMode === "deferred" && nodeFs.existsSync(filePath)) {
|
|
1860
|
+
autofixNewlyQueued = runtime.deferMutation?.call(runtime, filePath, dispatchCwd, event.toolName, turnStateCwd, "autofix", deps.sessionId, resolutionBasis, undefined, analysisRootMode) ?? false;
|
|
1861
|
+
dbg(`tool_result: queued deferred autofix for ${filePath}`);
|
|
1862
|
+
}
|
|
1863
|
+
let formatQueued = false;
|
|
1864
|
+
if (resultLive && !result.isError && bashAuthorshipConfirmed && !getFlag("no-autoformat", filePath) && (autofixMode === "deferred" || !getFlag("immediate-format")) && nodeFs.existsSync(filePath)) {
|
|
1865
|
+
const isNewlyQueued = runtime.deferFormat(filePath, dispatchCwd, event.toolName, turnStateCwd, deps.sessionId, resolutionBasis, analysisRootMode);
|
|
1866
|
+
formatQueued = true;
|
|
1867
|
+
dbg(`tool_result: queued deferred format for ${filePath}`);
|
|
1868
|
+
logLatency({
|
|
1869
|
+
type: "phase",
|
|
1870
|
+
toolName: event.toolName,
|
|
1871
|
+
filePath,
|
|
1872
|
+
phase: "deferred_format_queued",
|
|
1873
|
+
durationMs: 0,
|
|
1874
|
+
metadata: { cwd: dispatchCwd }
|
|
1875
|
+
});
|
|
1876
|
+
if (isNewlyQueued || autofixNewlyQueued) {
|
|
1877
|
+
const identity = runtime.deferredFormatIdentity?.(filePath);
|
|
1878
|
+
publishFormatQueued({
|
|
1879
|
+
filePath,
|
|
1880
|
+
cwd: dispatchCwd,
|
|
1881
|
+
tool: mutation.kind,
|
|
1882
|
+
dbg,
|
|
1883
|
+
kinds: autofixMode === "deferred" ? ["autofix", "format"] : ["format"],
|
|
1884
|
+
...identity === undefined ? {} : {
|
|
1885
|
+
...identity.ownerSessionId === undefined ? {} : { ownerSessionId: identity.ownerSessionId },
|
|
1886
|
+
turnIndex: identity.turnIndex,
|
|
1887
|
+
batchId: identity.batchId
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (autofixNewlyQueued && !formatQueued) {
|
|
1893
|
+
const identity = runtime.deferredFormatIdentity?.(filePath);
|
|
1894
|
+
publishFormatQueued({
|
|
1895
|
+
filePath,
|
|
1896
|
+
cwd: dispatchCwd,
|
|
1897
|
+
tool: mutation.kind,
|
|
1898
|
+
kinds: ["autofix"],
|
|
1899
|
+
...identity === undefined ? {} : {
|
|
1900
|
+
...identity.ownerSessionId === undefined ? {} : { ownerSessionId: identity.ownerSessionId },
|
|
1901
|
+
turnIndex: identity.turnIndex,
|
|
1902
|
+
batchId: identity.batchId
|
|
1903
|
+
},
|
|
1904
|
+
dbg
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
for (const changedFile of result.changedFiles ?? []) {
|
|
1908
|
+
const resolvedChanged = path.resolve(changedFile);
|
|
1909
|
+
invalidateFormatterCacheForPath(resolvedChanged);
|
|
1910
|
+
if (!nodeFs.existsSync(resolvedChanged))
|
|
1911
|
+
continue;
|
|
1912
|
+
recordProjectChange({
|
|
1913
|
+
runtime,
|
|
1914
|
+
cwd: turnStateCwd,
|
|
1915
|
+
analysisRootMode,
|
|
1916
|
+
filePath: resolvedChanged,
|
|
1917
|
+
source: "autofix",
|
|
1918
|
+
dbg
|
|
1919
|
+
});
|
|
1920
|
+
if (!resultLive)
|
|
1921
|
+
continue;
|
|
1922
|
+
if (pathsEqual(path.resolve(turnStateCwd, changedFile), path.resolve(filePath)))
|
|
1923
|
+
continue;
|
|
1924
|
+
try {
|
|
1925
|
+
const content = nodeFs.readFileSync(resolvedChanged, "utf-8");
|
|
1926
|
+
const lineCount = content.split(`
|
|
1927
|
+
`).length;
|
|
1928
|
+
const hasImports = /^import\s/m.test(content);
|
|
1929
|
+
cacheManager.addModifiedRange(resolvedChanged, { start: 1, end: lineCount }, hasImports, turnStateCwd, deps.sessionId ?? runtime.telemetrySessionId, "pi", undefined, analysisRootMode);
|
|
1930
|
+
dbg(`tool_result: tracking dm-lens side-effect change for ${resolvedChanged}`);
|
|
1931
|
+
} catch (err) {
|
|
1932
|
+
dbg(`tool_result: side-effect tracking failed for ${resolvedChanged}: ${err}`);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (result.cascadePromise) {
|
|
1936
|
+
runtime.appendCascadePromise(result.cascadePromise, writeSession, filePath, analysisRootMode);
|
|
1937
|
+
}
|
|
1938
|
+
const { actionableWarnings, codeQualityWarnings } = result;
|
|
1939
|
+
if (actionableWarnings?.length) {
|
|
1940
|
+
writeSession.guardedWrite(filePath, () => runtime.recordActionableWarnings(actionableWarnings, deps.sessionId));
|
|
1941
|
+
}
|
|
1942
|
+
if (codeQualityWarnings?.length) {
|
|
1943
|
+
writeSession.guardedWrite(filePath, () => runtime.recordCodeQualityWarnings(codeQualityWarnings, deps.sessionId));
|
|
1944
|
+
}
|
|
1945
|
+
recordTurnSummary({
|
|
1946
|
+
runtime,
|
|
1947
|
+
filePath,
|
|
1948
|
+
result,
|
|
1949
|
+
getFlag,
|
|
1950
|
+
resultLive,
|
|
1951
|
+
analysisRootMode
|
|
1952
|
+
});
|
|
1953
|
+
publishInlineVerdict({
|
|
1954
|
+
runtime,
|
|
1955
|
+
cacheManager,
|
|
1956
|
+
filePath,
|
|
1957
|
+
result,
|
|
1958
|
+
writeSession,
|
|
1959
|
+
writeIndex,
|
|
1960
|
+
writeOrderTurn,
|
|
1961
|
+
authored: bashAuthorshipConfirmed,
|
|
1962
|
+
getFlag,
|
|
1963
|
+
turnStateCwd,
|
|
1964
|
+
analysisRootMode,
|
|
1965
|
+
sessionId: deps.sessionId
|
|
1966
|
+
});
|
|
1967
|
+
if (resultLive && analysisRootMode === "linked-worktree") {
|
|
1968
|
+
const worktreeRoot = analysisRoot.root;
|
|
1969
|
+
if (worktreeRoot) {
|
|
1970
|
+
recordDegradationOnce({
|
|
1971
|
+
kind: "tool-result-linked-worktree",
|
|
1972
|
+
subject: worktreeRoot,
|
|
1973
|
+
reason: `analysed a linked worktree of this repository: ${worktreeRoot}`
|
|
1974
|
+
});
|
|
1975
|
+
if (result.checkedClean) {
|
|
1976
|
+
const firstSilentRun = recordDegradationOnce({
|
|
1977
|
+
kind: "tool-result-linked-worktree-clean",
|
|
1978
|
+
subject: worktreeRoot,
|
|
1979
|
+
reason: `a linked-worktree edit produced no finding: ${filePath}`
|
|
1980
|
+
});
|
|
1981
|
+
if (firstSilentRun) {
|
|
1982
|
+
queueAgentAdvisory(`dm-lens analysed the edit at ${filePath} in the linked worktree ${worktreeRoot} (full LSP, formatting, autofix and dispatch) and found nothing to report.`, writeSession);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
if (result.isError) {
|
|
1988
|
+
return {
|
|
1989
|
+
content: [...event.content, { type: "text", text: result.output }],
|
|
1990
|
+
isError: true,
|
|
1991
|
+
structuredContent: event.structuredContent
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
let output = result.output;
|
|
1995
|
+
if (behaviorWarnings.length > 0 && !result.hasBlockers) {
|
|
1996
|
+
output += `
|
|
1997
|
+
|
|
1998
|
+
${formatBehaviorWarnings(behaviorWarnings)}`;
|
|
1999
|
+
}
|
|
2000
|
+
const totalMs = Date.now() - toolResultStart;
|
|
2001
|
+
logLatency({
|
|
2002
|
+
type: "tool_result",
|
|
2003
|
+
toolName: event.toolName,
|
|
2004
|
+
filePath,
|
|
2005
|
+
durationMs: totalMs,
|
|
2006
|
+
result: output ? "completed" : "no_output"
|
|
2007
|
+
});
|
|
2008
|
+
runtime.reportedThisTurn.add(filePath);
|
|
2009
|
+
const postMutation = result.postMutation;
|
|
2010
|
+
const attachmentText = postMutation ? `dm-lens applied autofix to ${postMutation.filePath}. The following full content is authoritative for subsequent edits:
|
|
2011
|
+
|
|
2012
|
+
${postMutation.content}` : "";
|
|
2013
|
+
const contentBytes = postMutation ? Buffer.byteLength(postMutation.content, "utf-8") : 0;
|
|
2014
|
+
const withinPerFileCap = contentBytes <= AUTHORITATIVE_CONTENT_MAX_BYTES;
|
|
2015
|
+
const budget = deps._attachmentBudget;
|
|
2016
|
+
const withinSharedBudget = !budget || Buffer.byteLength(attachmentText, "utf-8") <= budget.remaining;
|
|
2017
|
+
const attachAuthoritativeContent = postMutation !== undefined && withinPerFileCap && withinSharedBudget;
|
|
2018
|
+
const attachmentDecision = !postMutation ? "none" : attachAuthoritativeContent ? "attached" : withinPerFileCap ? "aggregate-budget-degraded" : "size-capped";
|
|
2019
|
+
const notice = result.postAutofixNotice ?? (postMutation ? { targetPath: postMutation.filePath, changedFiles: [] } : undefined);
|
|
2020
|
+
if (postMutation && attachAuthoritativeContent && budget) {
|
|
2021
|
+
budget.remaining -= Buffer.byteLength(attachmentText, "utf-8");
|
|
2022
|
+
}
|
|
2023
|
+
if (postMutation || notice) {
|
|
2024
|
+
logLatency({
|
|
2025
|
+
type: "phase",
|
|
2026
|
+
phase: "authoritative_content_attachment_decision",
|
|
2027
|
+
filePath: postMutation?.filePath ?? filePath,
|
|
2028
|
+
durationMs: 0,
|
|
2029
|
+
metadata: {
|
|
2030
|
+
path: postMutation?.filePath ?? filePath,
|
|
2031
|
+
bytes: contentBytes,
|
|
2032
|
+
decision: attachmentDecision
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
if (postMutation) {
|
|
2037
|
+
noteAuthoritativeContentAttachment(postMutation.filePath, attachAuthoritativeContent);
|
|
2038
|
+
if (attachAuthoritativeContent && !getFlag("no-read-guard")) {
|
|
2039
|
+
const evidence = deliveredLineEvidence(postMutation.content, 1);
|
|
2040
|
+
deps.readGuard?.recordRead({
|
|
2041
|
+
filePath: postMutation.filePath,
|
|
2042
|
+
requestedOffset: 1,
|
|
2043
|
+
requestedLimit: evidence.lineCount,
|
|
2044
|
+
effectiveOffset: 1,
|
|
2045
|
+
effectiveLimit: evidence.lineCount,
|
|
2046
|
+
expandedByLsp: false,
|
|
2047
|
+
...evidence.lineHashes && { lineHashes: evidence.lineHashes },
|
|
2048
|
+
turnIndex: runtime.turnIndex,
|
|
2049
|
+
writeIndex: runtime.peekWriteIndex(),
|
|
2050
|
+
timestamp: Date.now(),
|
|
2051
|
+
source: "autofix-attachment"
|
|
2052
|
+
}, { stampFileTime: false });
|
|
2053
|
+
logConversationRead("autofix-attachment", postMutation.filePath, 1, evidence);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
const returnedContent = attachAuthoritativeContent ? [...event.content, { type: "text", text: attachmentText }] : event.content;
|
|
2057
|
+
if (notice) {
|
|
2058
|
+
output = `${output ? `${output}
|
|
2059
|
+
|
|
2060
|
+
` : ""}${renderPostAutofixNotice(notice, attachmentDecision)}`;
|
|
2061
|
+
}
|
|
2062
|
+
if (!output && !result.postMutation)
|
|
2063
|
+
return;
|
|
2064
|
+
return {
|
|
2065
|
+
content: output ? [...returnedContent, { type: "text", text: output }] : returnedContent,
|
|
2066
|
+
structuredContent: event.structuredContent
|
|
2067
|
+
};
|
|
2068
|
+
}
|