pi-lens 3.8.73 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +2614 -12
  2. package/README.md +50 -21
  3. package/dist/clients/actionable-warnings.js +73 -18
  4. package/dist/clients/agent-behavior-client.js +21 -4
  5. package/dist/clients/ast-grep-client.js +68 -16
  6. package/dist/clients/ast-grep-types.js +0 -1
  7. package/dist/clients/ast-grep-yaml-synth.js +37 -10
  8. package/dist/clients/atomic-write-staging.js +63 -0
  9. package/dist/clients/atomic-write.js +116 -16
  10. package/dist/clients/bash-file-access.js +193 -23
  11. package/dist/clients/biome-client.js +29 -25
  12. package/dist/clients/bootstrap.js +11 -2
  13. package/dist/clients/bounded-cache.js +34 -0
  14. package/dist/clients/bounded-pid-file-lock.js +192 -0
  15. package/dist/clients/bus-events-logger.js +5 -1
  16. package/dist/clients/bus-publish.js +10 -3
  17. package/dist/clients/cache/rule-cache.js +89 -6
  18. package/dist/clients/cache-manager.js +97 -9
  19. package/dist/clients/cache-observability.js +498 -0
  20. package/dist/clients/call-graph.js +460 -108
  21. package/dist/clients/cascade-logger.js +5 -1
  22. package/dist/clients/child-unref.js +85 -0
  23. package/dist/clients/codebase-model.js +52 -23
  24. package/dist/clients/collateral-test-role.js +40 -0
  25. package/dist/clients/complexity-client.js +6 -8
  26. package/dist/clients/console-guard-install.js +14 -0
  27. package/dist/clients/cooperative-budget.js +42 -0
  28. package/dist/clients/dead-code-client.js +2 -1
  29. package/dist/clients/debug-handles.js +206 -0
  30. package/dist/clients/debug-heap.js +167 -0
  31. package/dist/clients/degradation-ledger.js +153 -0
  32. package/dist/clients/dependency-checker.js +466 -63
  33. package/dist/clients/diagnostic-dispositions.js +83 -13
  34. package/dist/clients/diagnostics-publish.js +10 -3
  35. package/dist/clients/dispatch/auxiliary-lsp.js +34 -0
  36. package/dist/clients/dispatch/dispatcher.js +71 -13
  37. package/dist/clients/dispatch/fact-store.js +11 -0
  38. package/dist/clients/dispatch/facts/function-facts.js +37 -7
  39. package/dist/clients/dispatch/facts/import-facts.js +108 -119
  40. package/dist/clients/dispatch/facts/tree-sitter-facts.js +12 -12
  41. package/dist/clients/dispatch/facts/try-catch-facts.js +13 -0
  42. package/dist/clients/dispatch/indent-detect.js +35 -0
  43. package/dist/clients/dispatch/inline-suppressions.js +17 -8
  44. package/dist/clients/dispatch/integration.js +1094 -611
  45. package/dist/clients/dispatch/lazy.js +14 -0
  46. package/dist/clients/dispatch/plan.js +11 -1
  47. package/dist/clients/dispatch/rule-id-normalize.js +50 -0
  48. package/dist/clients/dispatch/rule-policy.js +135 -0
  49. package/dist/clients/dispatch/rules/async-noise.js +1 -0
  50. package/dist/clients/dispatch/rules/unsafe-boundary.js +7 -0
  51. package/dist/clients/dispatch/runners/ast-grep-napi.js +47 -6
  52. package/dist/clients/dispatch/runners/biome-check.js +5 -9
  53. package/dist/clients/dispatch/runners/detekt.js +3 -2
  54. package/dist/clients/dispatch/runners/hadolint.js +2 -1
  55. package/dist/clients/dispatch/runners/helm-lint.js +154 -0
  56. package/dist/clients/dispatch/runners/htmlhint.js +3 -2
  57. package/dist/clients/dispatch/runners/index.js +5 -1
  58. package/dist/clients/dispatch/runners/lsp.js +14 -6
  59. package/dist/clients/dispatch/runners/markdownlint.js +4 -9
  60. package/dist/clients/dispatch/runners/psscriptanalyzer.js +10 -1
  61. package/dist/clients/dispatch/runners/pyright.js +9 -5
  62. package/dist/clients/dispatch/runners/ruff.js +4 -8
  63. package/dist/clients/dispatch/runners/shellcheck.js +2 -3
  64. package/dist/clients/dispatch/runners/shfmt.js +2 -3
  65. package/dist/clients/dispatch/runners/spotbugs.js +2 -1
  66. package/dist/clients/dispatch/runners/taplo.js +2 -1
  67. package/dist/clients/dispatch/runners/terragrunt.js +163 -0
  68. package/dist/clients/dispatch/runners/tflint.js +37 -5
  69. package/dist/clients/dispatch/runners/tree-sitter.js +155 -166
  70. package/dist/clients/dispatch/runners/trivy-config.js +13 -7
  71. package/dist/clients/dispatch/runners/utils/lazy-installer.js +3 -0
  72. package/dist/clients/dispatch/runners/utils/runner-helpers.js +284 -34
  73. package/dist/clients/dispatch/runners/utils/spawn-outcome.js +22 -0
  74. package/dist/clients/dispatch/runners/yaml-rule-parser.js +5 -4
  75. package/dist/clients/disposition-publish.js +10 -3
  76. package/dist/clients/durable-store.js +97 -0
  77. package/dist/clients/event-loop-monitor.js +94 -3
  78. package/dist/clients/extension-log.js +139 -0
  79. package/dist/clients/extension-mode.js +73 -0
  80. package/dist/clients/feature-hints.js +53 -7
  81. package/dist/clients/file-kinds.js +143 -31
  82. package/dist/clients/file-role.js +18 -3
  83. package/dist/clients/file-utils.js +56 -34
  84. package/dist/clients/fix-worklog.js +14 -2
  85. package/dist/clients/format-events-publish.js +16 -3
  86. package/dist/clients/format-service.js +24 -8
  87. package/dist/clients/formatters-lazy.js +8 -0
  88. package/dist/clients/formatters.js +358 -61
  89. package/dist/clients/generated-artifacts.js +169 -15
  90. package/dist/clients/git-guard.js +681 -11
  91. package/dist/clients/git-tracked-ignore.js +4 -0
  92. package/dist/clients/go-client.js +2 -1
  93. package/dist/clients/govulncheck-client.js +8 -0
  94. package/dist/clients/grammar-source.js +12 -4
  95. package/dist/clients/gzip-stage-write.js +102 -0
  96. package/dist/clients/host-ports.js +31 -0
  97. package/dist/clients/installer/index.js +733 -213
  98. package/dist/clients/instance-reaper.js +142 -172
  99. package/dist/clients/jscpd-client.js +31 -54
  100. package/dist/clients/knip-client.js +78 -36
  101. package/dist/clients/language-policy.js +14 -2
  102. package/dist/clients/language-profile.js +72 -77
  103. package/dist/clients/latency-logger.js +28 -16
  104. package/dist/clients/lens-config.js +140 -166
  105. package/dist/clients/lens-engine.js +124 -21
  106. package/dist/clients/lens-events.js +27 -4
  107. package/dist/clients/lens-flag-registry.js +293 -0
  108. package/dist/clients/lens-map.js +96 -26
  109. package/dist/clients/live-bus-emitter.js +30 -0
  110. package/dist/clients/log-cleanup.js +8 -18
  111. package/dist/clients/lsp/cascade-tier.js +23 -3
  112. package/dist/clients/lsp/client.js +566 -57
  113. package/dist/clients/lsp/config.js +74 -10
  114. package/dist/clients/lsp/diagnostic-binding.js +86 -0
  115. package/dist/clients/lsp/edits.js +1012 -121
  116. package/dist/clients/lsp/index.js +1840 -803
  117. package/dist/clients/lsp/language.js +4 -1
  118. package/dist/clients/lsp/launch.js +40 -32
  119. package/dist/clients/lsp/path-utils.js +1 -1
  120. package/dist/clients/lsp/ruby-drive-dirs.js +83 -0
  121. package/dist/clients/lsp/server.js +279 -60
  122. package/dist/clients/lsp/workspace-diagnostics-cache.js +28 -4
  123. package/dist/clients/lsp-document-symbols.js +112 -0
  124. package/dist/clients/lsp-lazy.js +8 -0
  125. package/dist/clients/lsp-mutation.js +248 -0
  126. package/dist/clients/mcp/analyze.js +128 -36
  127. package/dist/clients/mcp/ipc.js +157 -24
  128. package/dist/clients/mcp/review.js +36 -3
  129. package/dist/clients/mcp/session.js +216 -8
  130. package/dist/clients/memory-sampler.js +115 -0
  131. package/dist/clients/metrics-client.js +2 -1
  132. package/dist/clients/metrics-history.js +2 -1
  133. package/dist/clients/module-report-lsp.js +5 -0
  134. package/dist/clients/module-report.js +267 -82
  135. package/dist/clients/ndjson-logger.js +334 -103
  136. package/dist/clients/opengrep-client.js +1 -1
  137. package/dist/clients/partial-edit-apply.js +120 -5
  138. package/dist/clients/path-keyed-map.js +76 -0
  139. package/dist/clients/path-utils.js +141 -5
  140. package/dist/clients/performance-report.js +327 -0
  141. package/dist/clients/pipeline.js +54 -13
  142. package/dist/clients/print-mode.js +21 -0
  143. package/dist/clients/project-changes.js +117 -4
  144. package/dist/clients/project-diagnostics/cache.js +3 -2
  145. package/dist/clients/project-diagnostics/extractors.js +26 -115
  146. package/dist/clients/project-diagnostics/fresh-fetch.js +149 -19
  147. package/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +117 -0
  148. package/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +37 -5
  149. package/dist/clients/project-diagnostics/scanner.js +268 -128
  150. package/dist/clients/project-lens-config.js +138 -34
  151. package/dist/clients/project-report.js +64 -25
  152. package/dist/clients/project-scale.js +8 -10
  153. package/dist/clients/project-snapshot-persist-worker.js +6 -0
  154. package/dist/clients/project-snapshot.js +767 -8
  155. package/dist/clients/project-trust.js +181 -0
  156. package/dist/clients/quiet-window.js +27 -5
  157. package/dist/clients/read-bridge.js +147 -0
  158. package/dist/clients/read-expansion.js +22 -12
  159. package/dist/clients/read-guard-logger.js +159 -1
  160. package/dist/clients/read-guard-tool-lines.js +150 -29
  161. package/dist/clients/read-guard.js +262 -3
  162. package/dist/clients/redact/secrets.js +449 -0
  163. package/dist/clients/resource-sampler.js +144 -39
  164. package/dist/clients/reverse-deps.js +48 -0
  165. package/dist/clients/review-graph/builder.js +2570 -326
  166. package/dist/clients/review-graph/git-identity.js +2 -1
  167. package/dist/clients/review-graph/import-resolvers.js +21 -10
  168. package/dist/clients/review-graph/persist-worker.js +10 -0
  169. package/dist/clients/review-graph/query.js +5 -0
  170. package/dist/clients/review-graph/shared-extraction-ir.js +90 -0
  171. package/dist/clients/review-graph/symbol-id.js +46 -0
  172. package/dist/clients/review-graph/tsconfig-paths.js +57 -6
  173. package/dist/clients/review-graph/workspace-modules.js +51 -3
  174. package/dist/clients/review-graph-logger.js +53 -0
  175. package/dist/clients/ruff-client.js +27 -44
  176. package/dist/clients/runtime-agent-end.js +111 -75
  177. package/dist/clients/runtime-context.js +36 -12
  178. package/dist/clients/runtime-coordinator.js +76 -8
  179. package/dist/clients/runtime-session.js +799 -137
  180. package/dist/clients/runtime-tool-call.js +117 -62
  181. package/dist/clients/runtime-tool-result.js +218 -23
  182. package/dist/clients/runtime-turn.js +284 -40
  183. package/dist/clients/rust-client.js +2 -1
  184. package/dist/clients/safe-spawn.js +873 -71
  185. package/dist/clients/security-scan-client.js +2 -1
  186. package/dist/clients/session-start-observability.js +15 -0
  187. package/dist/clients/session-state-store.js +5 -3
  188. package/dist/clients/sessionstart-logger.js +18 -0
  189. package/dist/clients/sg-runner.js +284 -159
  190. package/dist/clients/slow-fs.js +2 -1
  191. package/dist/clients/smells-rollup.js +224 -0
  192. package/dist/clients/source-filter.js +231 -43
  193. package/dist/clients/source-walker.js +66 -10
  194. package/dist/clients/startup-scan.js +15 -16
  195. package/dist/clients/startup-timing.js +9 -0
  196. package/dist/clients/test-runner-client.js +38 -8
  197. package/dist/clients/todo-scanner.js +30 -3
  198. package/dist/clients/tool-event.js +35 -0
  199. package/dist/clients/tool-policy.js +388 -39
  200. package/dist/clients/tool-render.js +155 -0
  201. package/dist/clients/tree-sitter-cache.js +153 -140
  202. package/dist/clients/tree-sitter-client.js +1722 -80
  203. package/dist/clients/tree-sitter-logger.js +64 -1
  204. package/dist/clients/tree-sitter-query-loader.js +117 -12
  205. package/dist/clients/tree-sitter-shared.js +48 -19
  206. package/dist/clients/tree-sitter-symbol-extractor.js +115 -11
  207. package/dist/clients/user-notify.js +51 -0
  208. package/dist/clients/vanished-instance-marker.js +57 -0
  209. package/dist/clients/warm-attach.js +33 -13
  210. package/dist/clients/widget-state.js +342 -49
  211. package/dist/clients/word-index-logger.js +44 -0
  212. package/dist/clients/word-index.js +612 -68
  213. package/dist/clients/workspace-topology.js +100 -7
  214. package/dist/index.js +65923 -47161
  215. package/dist/mcp/analyze-cli.js +185 -29
  216. package/dist/mcp/cli.js +110 -0
  217. package/dist/mcp/server.js +272 -50
  218. package/dist/tools/ast-grep-search.js +93 -27
  219. package/dist/tools/lens-diagnostics.js +247 -41
  220. package/dist/tools/lsp-diagnostics.js +153 -40
  221. package/dist/tools/lsp-navigation.js +51 -31
  222. package/dist/tools/module-report.js +9 -0
  223. package/dist/tools/symbol-search.js +21 -2
  224. package/docs/agent-guide.md +247 -0
  225. package/docs/agent-tools.md +21 -10
  226. package/docs/analysisall.md +192 -0
  227. package/docs/api-ports-inventory.md +165 -0
  228. package/docs/ast-grep_rules_catalog.md +5 -2
  229. package/docs/astplayground.md +3 -4
  230. package/docs/audit1.md +5 -5
  231. package/docs/durable-store-audit-1202.md +32 -0
  232. package/docs/environment-variables.md +197 -11
  233. package/docs/fable.md +27 -0
  234. package/docs/features.md +35 -5
  235. package/docs/globalconfig.md +101 -5
  236. package/docs/language-coverage.md +6 -5
  237. package/docs/lsp-capability-matrix.md +2 -2
  238. package/docs/mcp.md +54 -20
  239. package/docs/servercapabilities.md +7 -4
  240. package/docs/settings.md +192 -0
  241. package/docs/tools.md +18 -1
  242. package/docs/tree-sitter_rules_catalog.md +11 -31
  243. package/docs/usage.md +31 -0
  244. package/package.json +139 -138
  245. package/rules/ast-grep-rules/rule-tests/hardcoded-url-js-test.yml +1 -0
  246. package/rules/ast-grep-rules/rule-tests/hardcoded-url-test.yml +2 -0
  247. package/rules/ast-grep-rules/rule-tests/no-bare-except-test.yml +49 -0
  248. package/rules/ast-grep-rules/rule-tests/no-bare-host-path-in-win32-branch-test.yml +87 -0
  249. package/rules/ast-grep-rules/rule-tests/no-case-declarations-js-test.yml +10 -0
  250. package/rules/ast-grep-rules/rule-tests/no-case-declarations-test.yml +10 -0
  251. package/rules/ast-grep-rules/rule-tests/no-javascript-url-js-test.yml +10 -0
  252. package/rules/ast-grep-rules/rule-tests/no-javascript-url-test.yml +10 -0
  253. package/rules/ast-grep-rules/rule-tests/no-nested-links-test.yml +11 -1
  254. package/rules/ast-grep-rules/rule-tests/no-raw-json-store-write-test.yml +17 -0
  255. package/rules/ast-grep-rules/rule-tests/no-win32-isabsolute-for-qualification-test.yml +16 -0
  256. package/rules/ast-grep-rules/rule-tests/strict-equality-js-test.yml +3 -0
  257. package/rules/ast-grep-rules/rule-tests/strict-equality-test.yml +3 -0
  258. package/rules/ast-grep-rules/rule-tests/strict-inequality-js-test.yml +3 -0
  259. package/rules/ast-grep-rules/rule-tests/strict-inequality-test.yml +4 -0
  260. package/rules/ast-grep-rules/rules/hardcoded-url-js.yml +22 -4
  261. package/rules/ast-grep-rules/rules/hardcoded-url.yml +22 -4
  262. package/rules/ast-grep-rules/rules/no-bare-except.yml +3 -15
  263. package/rules/ast-grep-rules/rules/no-bare-host-path-in-win32-branch.yml +25 -0
  264. package/rules/ast-grep-rules/rules/no-case-declarations-js.yml +4 -3
  265. package/rules/ast-grep-rules/rules/no-case-declarations.yml +4 -3
  266. package/rules/ast-grep-rules/rules/no-console-except-error-js.yml +10 -0
  267. package/rules/ast-grep-rules/rules/no-console-except-error.yml +10 -0
  268. package/rules/ast-grep-rules/rules/no-javascript-url-js.yml +42 -6
  269. package/rules/ast-grep-rules/rules/no-javascript-url.yml +42 -6
  270. package/rules/ast-grep-rules/rules/no-nested-links.yml +7 -0
  271. package/rules/ast-grep-rules/rules/no-raw-json-store-write.yml +30 -0
  272. package/rules/ast-grep-rules/rules/no-win32-isabsolute-for-qualification.yml +23 -0
  273. package/rules/ast-grep-rules/rules/strict-equality-js.yml +14 -1
  274. package/rules/ast-grep-rules/rules/strict-equality.yml +14 -1
  275. package/rules/ast-grep-rules/rules/strict-inequality-js.yml +14 -1
  276. package/rules/ast-grep-rules/rules/strict-inequality.yml +14 -1
  277. package/rules/tree-sitter-queries/cpp/no-memset-sensitive-data.yml +9 -3
  278. package/rules/tree-sitter-queries/cpp/no-scoped-lock-without-args.yml +6 -6
  279. package/rules/tree-sitter-queries/css/calc-spacing.yml +8 -6
  280. package/rules/tree-sitter-queries/go/go-mutex-copy.yml +21 -18
  281. package/rules/tree-sitter-queries/go/go-shared-map-write-goroutine.yml +3 -3
  282. package/rules/tree-sitter-queries/java/infinite-loop-java.yml +3 -3
  283. package/rules/tree-sitter-queries/java/junit-call-super.yml +6 -4
  284. package/rules/tree-sitter-queries/java/no-double-checked-locking.yml +10 -8
  285. package/rules/tree-sitter-queries/java/no-field-shadowing.yml +1 -1
  286. package/rules/tree-sitter-queries/java/prepared-statement-valid-indices.yml +2 -3
  287. package/rules/tree-sitter-queries/java/resources-closed.yml +2 -2
  288. package/rules/tree-sitter-queries/java/springboot-default-package.yml +6 -3
  289. package/rules/tree-sitter-queries/java/switch-fall-through.yml +6 -4
  290. package/rules/tree-sitter-queries/java/switch-non-case-labels.yml +4 -3
  291. package/rules/tree-sitter-queries/java/tests-include-assertions.yml +6 -5
  292. package/rules/tree-sitter-queries/javascript/switch-case-termination-js.yml +5 -8
  293. package/rules/tree-sitter-queries/javascript/switch-non-case-labels.yml +3 -2
  294. package/rules/tree-sitter-queries/kotlin/prepared-statement-indices.yml +9 -5
  295. package/rules/tree-sitter-queries/php/this-in-static-context.yml +5 -5
  296. package/rules/tree-sitter-queries/python/exit-signature-check.yml +2 -9
  297. package/rules/tree-sitter-queries/python/in-operator-unsupported.yml +3 -4
  298. package/rules/tree-sitter-queries/python/no-super-torchscript.yml +4 -8
  299. package/rules/tree-sitter-queries/python/notimplemented-boolean-context.yml +1 -5
  300. package/rules/tree-sitter-queries/python/python-empty-except.yml +1 -1
  301. package/rules/tree-sitter-queries/python/return-in-init.yml +0 -2
  302. package/rules/tree-sitter-queries/python/yield-return-outside-function.yml +0 -3
  303. package/rules/tree-sitter-queries/ruby/ruby-command-injection.yml +1 -12
  304. package/rules/tree-sitter-queries/ruby/ruby-eval.yml +1 -1
  305. package/rules/tree-sitter-queries/ruby/ruby-insecure-deserialization.yml +4 -4
  306. package/rules/tree-sitter-queries/ruby/ruby-insecure-random.yml +4 -11
  307. package/rules/tree-sitter-queries/ruby/ruby-open-struct.yml +1 -1
  308. package/rules/tree-sitter-queries/ruby/ruby-string-eval.yml +2 -3
  309. package/rules/tree-sitter-queries/ruby/ruby-weak-hash.yml +4 -4
  310. package/rules/tree-sitter-queries/rust/rust-lock-held-across-await.yml +4 -3
  311. package/rules/tree-sitter-queries/tsx/no-nested-links.yml +4 -6
  312. package/rules/tree-sitter-queries/typescript/console-statement.yml +11 -0
  313. package/rules/tree-sitter-queries/typescript/duplicate-function-arg.yml +4 -9
  314. package/rules/tree-sitter-queries/typescript/empty-switch-case.yml +13 -9
  315. package/rules/tree-sitter-queries/typescript/infinite-loop.yml +2 -2
  316. package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +10 -1
  317. package/rules/tree-sitter-queries/typescript/switch-case-termination.yml +5 -8
  318. package/rules/tree-sitter-queries/typescript/ts-insecure-random.yml +7 -10
  319. package/rules/tree-sitter-queries/typescript/unsafe-regex.yml +4 -2
  320. package/rules/typos/_typos.toml +17 -0
  321. package/scripts/analyze-pi-lens-logs.mjs +55 -2
  322. package/skills/pi-lens-write-tree-sitter-rule/SKILL.md +5 -0
  323. package/dist/clients/ast-grep-parser.js +0 -86
  324. package/dist/clients/config-enabled-shape.js +0 -39
  325. package/dist/clients/lsp/interactive-install.js +0 -367
  326. package/dist/clients/lsp/lsp-index.js +0 -10
  327. package/dist/clients/lsp/server-strategies.js +0 -5
  328. package/dist/clients/project-metadata.js +0 -690
  329. package/dist/clients/source-groups.js +0 -96
  330. package/dist/clients/types.js +0 -11
  331. package/docs/env_variables.md +0 -10
  332. package/rules/tree-sitter-queries/abap-disabled/delete-where.yml +0 -46
  333. package/rules/tree-sitter-queries/cpp/no-confused-move-forward.yml +0 -59
  334. package/rules/tree-sitter-queries/cpp/noexcept-functions.yml +0 -58
  335. package/rules/tree-sitter-queries/java/mockito-initialized.yml +0 -66
  336. package/rules/tree-sitter-queries/java/no-wait-notify-on-thread.yml +0 -58
  337. package/rules/tree-sitter-queries/java/short-circuit-logic.yml +0 -57
  338. package/rules/tree-sitter-queries/java/spring-session-attributes-setcomplete.yml +0 -75
  339. package/rules/tree-sitter-queries/plsql-disabled/delete-update-where.yml +0 -56
  340. package/rules/tree-sitter-queries/plsql-disabled/end-loop-semicolon.yml +0 -51
  341. package/rules/tree-sitter-queries/plsql-disabled/fetch-bulk-collect-limit.yml +0 -47
  342. package/rules/tree-sitter-queries/plsql-disabled/forallsave-exceptions.yml +0 -51
  343. package/rules/tree-sitter-queries/plsql-disabled/nchar-nvarchar2-bytes.yml +0 -54
  344. package/rules/tree-sitter-queries/plsql-disabled/not-null-initialization.yml +0 -59
  345. package/rules/tree-sitter-queries/plsql-disabled/raise-application-error-codes.yml +0 -50
  346. package/rules/tree-sitter-queries/typescript-disabled/ts-path-traversal.yml +0 -71
@@ -2,10 +2,12 @@ import * as path from "node:path";
2
2
  import { appendActionableWarningsHistory, buildActionableWarningsReport, formatActionableWarningsAdvisory, writeActionableWarningsReport, } from "./actionable-warnings.js";
3
3
  import { logActionableWarningsEvent } from "./actionable-warnings-logger.js";
4
4
  import { appendCodeQualityWarningsHistory, buildCodeQualityWarningsReport, formatCodeQualityWarningsAdvisory, writeCodeQualityWarningsReport, } from "./code-quality-warnings.js";
5
+ import { clearGitGuardTestFailure, mergeGitGuardTestFailure, writeGitGuardRecord, } from "./git-guard.js";
5
6
  import { logCascade } from "./cascade-logger.js";
6
7
  import { normalizeMapKey } from "./path-utils.js";
7
8
  import { resolveRunnerPath, toRunnerDisplayPath, } from "./dispatch/runner-context.js";
8
9
  import { getKnipIgnorePatterns } from "./file-utils.js";
10
+ import { isTestRoleCollateral } from "./collateral-test-role.js";
9
11
  import { dedupeSecretFindings, fromAstGrepWarnings, fromGitleaks, fromTrivySecrets, isSecretWarning, secretLocationKey, } from "./secret-findings.js";
10
12
  import { formatDeadCodeAdvisory } from "./dead-code-client.js";
11
13
  import { PROJECT_DIAGNOSTICS_CACHE_VERSION, writeProjectDiagnosticsDeltaReport, } from "./project-diagnostics/cache.js";
@@ -86,7 +88,7 @@ function capTurnEndMessage(content) {
86
88
  return out;
87
89
  }
88
90
  export async function handleTurnEnd(deps) {
89
- const { ctxCwd, getFlag, dbg, runtime, cacheManager, knipClient, deadCodeClients, depChecker, testRunnerClient, resetLSPService, resetFormatService, } = deps;
91
+ const { ctxCwd, getFlag, dbg, runtime, cacheManager, knipClient, deadCodeClients, depChecker, testRunnerClient, owner, resetLSPService, resetFormatService, } = deps;
90
92
  // #449 slice 1: piggyback the instance-registry heartbeat on this existing
91
93
  // per-turn touchpoint rather than adding a new timer/interval. Cheap (reads
92
94
  // process.memoryUsage().rss, one read-modify-write of instances.json) and
@@ -106,16 +108,40 @@ export async function handleTurnEnd(deps) {
106
108
  });
107
109
  const cwd = ctxCwd ?? process.cwd();
108
110
  let turnState = cacheManager.readTurnState(cwd);
109
- // Evict turn state written by a previous session — it carries stale file
110
- // ranges that no longer reflect the current editing context.
111
- if (turnState.sessionId &&
112
- turnState.sessionId !== runtime.telemetrySessionId) {
113
- dbg(`turn_end: evicting stale turn state (session ${turnState.sessionId} ≠ current ${runtime.telemetrySessionId})`);
114
- cacheManager.clearTurnState(cwd);
111
+ // A live foreign writer owns this worklist. Do not clear or consume another
112
+ // pi/MCP session's files; a dead/aged owner is safely evicted instead.
113
+ const currentOwner = owner ?? {
114
+ kind: "pi",
115
+ id: runtime.telemetrySessionId,
116
+ pid: process.pid,
117
+ lastSeen: new Date().toISOString(),
118
+ };
119
+ const access = cacheManager.getTurnStateAccess(cwd, currentOwner);
120
+ const sameProcessPiSessionHandoff = access === "foreign-live" &&
121
+ currentOwner.kind === "pi" &&
122
+ turnState.owner?.kind === "pi" &&
123
+ turnState.owner.pid === process.pid &&
124
+ turnState.owner.id !== currentOwner.id;
125
+ if (access === "foreign-live" && !sameProcessPiSessionHandoff) {
126
+ dbg(`turn_end: foreign live owner retained (${turnState.owner?.kind ?? "legacy"}:${turnState.owner?.id ?? turnState.sessionId})`);
127
+ return;
128
+ }
129
+ if (access === "available" && (turnState.files || turnState.owner || turnState.sessionId)) {
130
+ dbg("turn_end: evicting stale turn-state owner");
131
+ cacheManager.clearTurnState(cwd, currentOwner);
115
132
  turnState = cacheManager.readTurnState(cwd);
116
133
  }
117
134
  const files = Object.keys(turnState.files);
118
135
  if (files.length === 0) {
136
+ // A genuinely clean session must invalidate the persisted guard record.
137
+ // Blocker records are retained only while the runtime still reports one.
138
+ if (getFlag("lens-guard") && !runtime.gitGuardHasBlockers) {
139
+ const guardRecord = cacheManager.readCache("turn-end-findings", cwd)?.data;
140
+ if (guardRecord?.sessionId === runtime.telemetrySessionId &&
141
+ guardRecord.testFailures !== true) {
142
+ cacheManager.clearCache("turn-end-findings", cwd);
143
+ }
144
+ }
119
145
  // #713: subagent sessions use a shorter idle reset (60s) — a short-lived
120
146
  // task agent holding a warm fleet for 4 minutes after its last turn is
121
147
  // pure waste under fan-out. Classify ONCE here so every tick in this call
@@ -143,7 +169,7 @@ export async function handleTurnEnd(deps) {
143
169
  dbg(`turn_end: ${files.length} file(s) modified, cycles: ${turnState.turnCycles}/${turnState.maxCycles}`);
144
170
  if (cacheManager.isMaxCyclesExceeded(cwd)) {
145
171
  dbg("turn_end: max cycles exceeded, clearing state and forcing through");
146
- cacheManager.clearTurnState(cwd);
172
+ cacheManager.clearTurnState(cwd, currentOwner);
147
173
  runtime.fixedThisTurn.clear();
148
174
  resetFormatService();
149
175
  return;
@@ -155,7 +181,7 @@ export async function handleTurnEnd(deps) {
155
181
  const projectDiagnosticsSources = new Set();
156
182
  // Re-surface inline blockers from this turn that the agent didn't fix.
157
183
  // These were shown inline during write/edit but the agent moved on without resolving them.
158
- const unresolvedBlockers = runtime.consumeInlineBlockers();
184
+ const unresolvedBlockers = runtime.getInlineBlockersSnapshot();
159
185
  for (const { filePath: bPath, summary } of unresolvedBlockers) {
160
186
  const displayPath = toRunnerDisplayPath(cwd, bPath);
161
187
  blockerParts.push(`Unresolved from this turn — ${displayPath}:\n${summary}`);
@@ -180,7 +206,14 @@ export async function handleTurnEnd(deps) {
180
206
  // 2. Neighbor-level: each neighbor is claimed by the latest cascade result
181
207
  // that covers it — suppresses stale neighbor state from earlier writes.
182
208
  const t0 = Date.now();
183
- const cascadeRuns = runtime.consumeCascadeRuns();
209
+ const cascadeRuns = runtime.consumeCascadeRuns().filter((run) => {
210
+ const originSeq = run.origin?.projectSeq;
211
+ const originTurn = run.origin?.turnSeq;
212
+ // A deferred result from before a later write/turn is not current state.
213
+ // Old test fixtures without provenance remain accepted for compatibility.
214
+ return ((originSeq === undefined || originSeq === runtime.projectSeq) &&
215
+ (originTurn === undefined || originTurn === runtime.turnIndex));
216
+ });
184
217
  const cascadeResults = cascadeRuns.flatMap((r) => r.result ? [r.result] : []);
185
218
  if (cascadeResults.length > 0) {
186
219
  const seen = new Map();
@@ -237,11 +270,89 @@ export async function handleTurnEnd(deps) {
237
270
  },
238
271
  });
239
272
  }
273
+ // #1023: surface an HONEST note whenever a cascade run could not compute
274
+ // downstream impact (degraded/over-cap graph, missing node, or a thrown
275
+ // compute) — never a silent all-clear (#533). This goes to the ADVISORY tier,
276
+ // NOT the blocker tier: in an over-cap monorepo the graph is `skipped` on
277
+ // every edit, so a blocker would fire hard and never clear turn state every
278
+ // turn (over-escalation — the mirror of the silent-all-clear bug). Advisory
279
+ // still reaches the agent, just without the blocker mechanics. Keyed strictly
280
+ // off the `indeterminate` marker threaded by the compute; a healthy build
281
+ // with a genuinely empty dependent set carries no marker and stays silent
282
+ // (over-correction guard).
283
+ const indeterminateRuns = cascadeRuns.filter((r) => r.indeterminate);
284
+ if (indeterminateRuns.length > 0) {
285
+ // #1104 (review P3 on PR #1143, rides with the resultId main body): this
286
+ // preamble used to hardcode a graph-unavailability frame for EVERY
287
+ // indeterminate reason. That's accurate for `graph_degraded`/
288
+ // `missing_node`/`error` (the graph really couldn't produce a dependent
289
+ // set), but `lsp_binding_rejected` is a DIFFERENT failure shape — the
290
+ // graph WAS available and dependents WERE derived; only their LSP
291
+ // diagnostics display was withheld because a fallback snapshot's content
292
+ // binding didn't match current disk. Saying "the review graph was
293
+ // unavailable" for that case mis-attributes the cause. Bucket by reason
294
+ // family so each gets its own accurate frame.
295
+ const buildAdvisory = (runs, frame) => {
296
+ if (runs.length === 0)
297
+ return undefined;
298
+ const byDetail = new Map();
299
+ for (const r of runs) {
300
+ const detail = r.indeterminate?.detail ?? frame.fallbackDetail(r);
301
+ const files = byDetail.get(detail) ?? [];
302
+ files.push(toRunnerDisplayPath(cwd, r.filePath));
303
+ byDetail.set(detail, files);
304
+ }
305
+ const lines = [];
306
+ for (const [detail, filesRaw] of byDetail) {
307
+ const files = [...new Set(filesRaw)];
308
+ const shown = files.slice(0, 5).join(", ");
309
+ const more = files.length > 5 ? ` (+${files.length - 5} more)` : "";
310
+ lines.push(` â€ĸ ${detail}: ${shown}${more}`);
311
+ }
312
+ const fileCount = new Set(runs.map((r) => normalizeMapKey(r.filePath))).size;
313
+ const reasons = [...byDetail.keys()].join("; ");
314
+ return `${frame.lead(fileCount, reasons)}\n${lines.join("\n")}`;
315
+ };
316
+ const graphRuns = indeterminateRuns.filter((r) => r.indeterminate?.reason !== "lsp_binding_rejected");
317
+ const bindingRuns = indeterminateRuns.filter((r) => r.indeterminate?.reason === "lsp_binding_rejected");
318
+ // Factual/informational phrasing — the advisory tier wraps this with an
319
+ // "â„šī¸ Advisory — no action required this turn:" label, so an imperative
320
+ // ("review dependents manually") would contradict it. The #533 substance
321
+ // stays: a clean cascade result does NOT cover these files' dependents.
322
+ const graphAdvisory = buildAdvisory(graphRuns, {
323
+ lead: (fileCount, reasons) => `Cascade could not compute downstream impact for ${fileCount} edited file(s) this turn — ` +
324
+ `the review graph was unavailable (${reasons}), so their dependents were not ` +
325
+ `cascade-checked and a clean cascade result does not cover them.`,
326
+ fallbackDetail: (r) => r.indeterminate?.reason === "missing_node"
327
+ ? "changed file not in the review graph"
328
+ : "review graph unavailable",
329
+ });
330
+ if (graphAdvisory)
331
+ advisoryParts.push(graphAdvisory);
332
+ const bindingAdvisory = buildAdvisory(bindingRuns, {
333
+ lead: (fileCount, reasons) => `Cascade identified dependents for ${fileCount} edited file(s) this turn, but their ` +
334
+ `diagnostics could not be freshly confirmed (${reasons}) and were withheld — a clean ` +
335
+ `cascade result does not cover them.`,
336
+ fallbackDetail: () => "cascade diagnostics withheld (binding rejected)",
337
+ });
338
+ if (bindingAdvisory)
339
+ advisoryParts.push(bindingAdvisory);
340
+ const fileCount = new Set(indeterminateRuns.map((r) => normalizeMapKey(r.filePath))).size;
341
+ logCascade({
342
+ phase: "cascade_indeterminate",
343
+ filePath: files[0] ?? cwd,
344
+ metadata: {
345
+ fileCount,
346
+ reasons: indeterminateRuns.map((r) => r.indeterminate?.reason),
347
+ },
348
+ });
349
+ }
240
350
  const cascadeSkipped = {
241
351
  blockers: 0,
242
352
  non_code: 0,
243
353
  no_neighbors: 0,
244
354
  clean: 0,
355
+ indeterminate: 0,
245
356
  error: 0,
246
357
  };
247
358
  for (const r of cascadeRuns) {
@@ -468,13 +579,23 @@ export async function handleTurnEnd(deps) {
468
579
  advisoryParts.push(report);
469
580
  }
470
581
  const t3 = Date.now();
582
+ let madgeStats;
471
583
  if (await depChecker.ensureAvailable()) {
472
584
  const madgeFiles = cacheManager.getFilesForMadge(cwd);
473
585
  if (madgeFiles.length > 0) {
474
586
  dbg(`turn_end: madge checking ${madgeFiles.length} file(s) for circular deps`);
587
+ // Checked concurrently (bounded) rather than one `await` per file —
588
+ // the shared circular-dep state update is deferred/folded inside
589
+ // checkFilesBatch so concurrent spawns can't clobber each other (#766).
590
+ const absFiles = madgeFiles.map((file) => path.resolve(cwd, file));
591
+ const batch = await depChecker.checkFilesBatch(absFiles, cwd);
592
+ const depResults = batch.results;
593
+ madgeStats = batch.stats;
475
594
  for (const file of madgeFiles) {
476
595
  const absPath = path.resolve(cwd, file);
477
- const depResult = await depChecker.checkFile(absPath, cwd);
596
+ const depResult = depResults.get(absPath);
597
+ if (!depResult)
598
+ continue;
478
599
  if (depResult.localSkips && depResult.localSkips > 0) {
479
600
  // Not silent: a skipped LOCAL import means madge couldn't resolve
480
601
  // it into the graph, so a cycle through it would be missed.
@@ -495,6 +616,7 @@ export async function handleTurnEnd(deps) {
495
616
  filePath: cwd,
496
617
  phase: "madge",
497
618
  durationMs: Date.now() - t3,
619
+ ...(madgeStats && { metadata: madgeStats }),
498
620
  });
499
621
  // --- Test runner: fire once per turn after all edits are done ---
500
622
  // Runs for each unique test target across modified files; results appear
@@ -545,6 +667,7 @@ export async function handleTurnEnd(deps) {
545
667
  if (targets.length > 0) {
546
668
  dbg(`turn_end: firing ${targets.length} test target(s) async (non-blocking)`);
547
669
  const firedAtTurn = runtime.turnIndex;
670
+ const firedSessionId = runtime.telemetrySessionId;
548
671
  Promise.allSettled(targets.map((t) => testRunnerClient.runTestFileAsync(t.testFile, cwd, t.runner, t.config)))
549
672
  .then((results) => {
550
673
  // #628: the turn advancing while tests ran no longer means the
@@ -578,9 +701,20 @@ export async function handleTurnEnd(deps) {
578
701
  ? `[from a prior turn — the edit that triggered this run had already been superseded by the time results came back]\n\n${failures.join("\n\n")}`
579
702
  : failures.join("\n\n");
580
703
  cacheManager.writeCache("test-runner-findings", { content, stale, results: resultValues }, cwd);
704
+ if (getFlag("lens-guard") && firedSessionId === runtime.telemetrySessionId) {
705
+ clearGitGuardTestFailure(cacheManager, cwd, runtime, resultValues
706
+ .filter((value) => value.failed === 0)
707
+ .map((value) => value.file));
708
+ mergeGitGuardTestFailure(cacheManager, cwd, runtime, content, resultValues
709
+ .filter((value) => value.failed > 0)
710
+ .map((value) => value.file));
711
+ }
581
712
  dbg(`turn_end: ${failures.length} test failure(s) cached for next context injection${stale ? " (stale — turn advanced while tests ran)" : ""}`);
582
713
  }
583
714
  else if (results.length > 0) {
715
+ if (getFlag("lens-guard") && firedSessionId === runtime.telemetrySessionId) {
716
+ clearGitGuardTestFailure(cacheManager, cwd, runtime, resultValues.map((value) => value.file));
717
+ }
584
718
  dbg(`turn_end: all tests passed${stale ? " (stale — turn advanced while tests ran)" : ""}`);
585
719
  }
586
720
  })
@@ -596,6 +730,78 @@ export async function handleTurnEnd(deps) {
596
730
  }
597
731
  // Session summaries are intentionally suppressed at turn_end to avoid
598
732
  // distracting the agent with non-blocking telemetry.
733
+ // Call-graph impact analysis — surface WillBreak/MayBreak callers for modified
734
+ // symbols. MUST run BEFORE the writeProjectDiagnosticsDeltaReport serialization
735
+ // below: it is a delta contributor (like knip above), pushing into
736
+ // projectDiagnosticsDelta / projectDiagnosticsSources. If it ran after the
737
+ // single write, a call-graph-only turn would persist nothing and a mixed turn
738
+ // would drop the call-graph entries — so lens_diagnostics (which only reads the
739
+ // persisted report) would never surface the findings (#179/#533).
740
+ if (runtime.callGraph && files.length > 0) {
741
+ const coverage = runtime.callGraph.coverage;
742
+ if (!coverage || coverage.complete !== true) {
743
+ // An incomplete graph can still contain useful edges, but emitting them
744
+ // as ordinary impact findings would turn unsupported/partial extraction
745
+ // into an authoritative-looking clean result for the rest of the file.
746
+ // Keep the limitation visible and require a complete graph for this
747
+ // user-facing impact surface (#1070).
748
+ advisoryParts.push("Call-graph impact was not emitted because call-graph extraction coverage is incomplete; " +
749
+ "the affected files may have unreported callers.");
750
+ }
751
+ else {
752
+ try {
753
+ const { impact, formatImpact, parseSymbolKey } = await import("./call-graph.js");
754
+ const { callGraphImpactToProjectDiagnostics } = await import("./project-diagnostics/runner-adapters/call-graph-impact.js");
755
+ const impactLines = [];
756
+ const impactFindings = [];
757
+ for (const filePath of files.slice(0, 5)) {
758
+ // Turn-state files may be cwd-relative while graph keys are absolute,
759
+ // and persisted graphs can contain either slash style/casing. Compare
760
+ // through the shared normalized path seam; keep the original filePath
761
+ // only for display and diagnostics.
762
+ const changedFileKey = normalizeMapKey(resolveRunnerPath(cwd, filePath));
763
+ const fileCallerKeys = [...runtime.callGraph.callers.keys()].filter((k) => {
764
+ const graphFilePath = parseSymbolKey(k).filePath;
765
+ return normalizeMapKey(resolveRunnerPath(cwd, graphFilePath)) === changedFileKey;
766
+ });
767
+ for (const calleeKey of fileCallerKeys.slice(0, 3)) {
768
+ // #1080: drop KNOWN test-role callers BEFORE both the human advisory
769
+ // (formatImpact below) and the persisted delta (impactFindings →
770
+ // callGraphImpactToProjectDiagnostics) — the advisory is rendered
771
+ // first, so the filter must reach the shared `results` set that feeds
772
+ // both. A test caller supplied by an old/fixture/expanded graph must
773
+ // appear in neither surface. Fail-open: an unparseable/unclassifiable
774
+ // key is retained (the adapter re-applies the same predicate).
775
+ const results = impact(runtime.callGraph, calleeKey).filter((r) => {
776
+ const callerFile = parseSymbolKey(r.symbolKey).filePath;
777
+ return (!callerFile ||
778
+ !isTestRoleCollateral(resolveRunnerPath(cwd, callerFile)));
779
+ });
780
+ if (results.length > 0) {
781
+ impactFindings.push({ calleeKey, results });
782
+ const summary = formatImpact(results, cwd);
783
+ if (summary)
784
+ impactLines.push(` ${parseSymbolKey(calleeKey).symbolName ?? calleeKey}: ${summary}`);
785
+ }
786
+ }
787
+ }
788
+ if (impactLines.length > 0) {
789
+ advisoryParts.push(`📊 Call-graph impact (changed symbols have callers):\n${impactLines.join("\n")}`);
790
+ }
791
+ if (impactFindings.length > 0) {
792
+ const impactDiagnostics = callGraphImpactToProjectDiagnostics(cwd, impactFindings);
793
+ if (impactDiagnostics.length > 0) {
794
+ projectDiagnosticsDelta.push(...impactDiagnostics);
795
+ projectDiagnosticsSources.add("call-graph");
796
+ }
797
+ }
798
+ // Non-fatal — call graph is best-effort
799
+ }
800
+ catch {
801
+ // Non-fatal — call graph is best-effort
802
+ }
803
+ }
804
+ }
599
805
  if (projectDiagnosticsDelta.length > 0) {
600
806
  writeProjectDiagnosticsDeltaReport(cwd, {
601
807
  version: PROJECT_DIAGNOSTICS_CACHE_VERSION,
@@ -682,31 +888,6 @@ export async function handleTurnEnd(deps) {
682
888
  });
683
889
  }
684
890
  }
685
- // Call-graph impact analysis — surface WillBreak/MayBreak callers for modified symbols
686
- if (runtime.callGraph && files.length > 0) {
687
- try {
688
- const { impact, formatImpact } = await import("./call-graph.js");
689
- const impactLines = [];
690
- for (const filePath of files.slice(0, 5)) {
691
- // Find callee keys for this file in the call graph
692
- const fileCallerKeys = [...runtime.callGraph.callers.keys()].filter((k) => k.startsWith(`${filePath}:`));
693
- for (const calleeKey of fileCallerKeys.slice(0, 3)) {
694
- const results = impact(runtime.callGraph, calleeKey);
695
- if (results.length > 0) {
696
- const summary = formatImpact(results, cwd);
697
- if (summary)
698
- impactLines.push(` ${calleeKey.split(":").pop()}: ${summary}`);
699
- }
700
- }
701
- }
702
- if (impactLines.length > 0) {
703
- advisoryParts.push(`📊 Call-graph impact (changed symbols have callers):\n${impactLines.join("\n")}`);
704
- }
705
- }
706
- catch {
707
- // Non-fatal — call graph is best-effort
708
- }
709
- }
710
891
  const t5 = Date.now();
711
892
  try {
712
893
  const qualityReport = buildCodeQualityWarningsReport({
@@ -767,7 +948,7 @@ export async function handleTurnEnd(deps) {
767
948
  catch (err) {
768
949
  dbg(`turn_end: dead-code advisory failed: ${err}`);
769
950
  }
770
- cacheManager.incrementTurnCycle(cwd);
951
+ cacheManager.incrementTurnCycle(cwd, currentOwner);
771
952
  const labeledAdvisoryParts = advisoryParts.map((p) => `â„šī¸ Advisory — no action required this turn:\n${p}`);
772
953
  const findingParts = [...blockerParts, ...labeledAdvisoryParts];
773
954
  if (findingParts.length > 0) {
@@ -781,12 +962,68 @@ export async function handleTurnEnd(deps) {
781
962
  if (last?.data?.signature === signature &&
782
963
  last?.data?.sessionId === runtime.telemetrySessionId) {
783
964
  dbg("turn_end: duplicate findings detected (same session), suppressing re-prompt");
784
- cacheManager.clearTurnState(cwd);
965
+ if (getFlag("lens-guard")) {
966
+ const existingGuard = cacheManager.readCache("turn-end-findings", cwd)?.data;
967
+ if (existingGuard) {
968
+ writeGitGuardRecord(cacheManager, runtime, cwd, {
969
+ ...existingGuard,
970
+ content,
971
+ blockerContent: blockerParts.length > 0
972
+ ? capTurnEndMessage(blockerParts.join("\n\n"))
973
+ : undefined,
974
+ hasBlockers: blockerParts.length > 0 || existingGuard.testFailures === true,
975
+ blockingFiles: blockerParts.length > 0 ? existingGuard.affectedFiles : undefined,
976
+ projectSeqStart: runtime.turnStartProjectSeq,
977
+ projectSeqEnd: runtime.projectSeq,
978
+ fileSeqByPath: Object.fromEntries(runtime.getFileSeqEntries().map(([filePath, seq]) => [normalizeMapKey(path.resolve(filePath)), seq])),
979
+ fileContentHashes: {},
980
+ consumed: false,
981
+ });
982
+ }
983
+ }
984
+ cacheManager.clearTurnState(cwd, currentOwner);
785
985
  runtime.fixedThisTurn.clear();
786
986
  resetFormatService();
787
987
  return;
788
988
  }
789
- cacheManager.writeCache("turn-end-findings", { content }, cwd);
989
+ const fileSeqByPath = {};
990
+ for (const [filePath, seq] of runtime.getFileSeqEntries()) {
991
+ fileSeqByPath[normalizeMapKey(path.resolve(filePath))] = seq;
992
+ }
993
+ if (getFlag("lens-guard")) {
994
+ const existingGuard = cacheManager.readCache("turn-end-findings", cwd)?.data;
995
+ const blockingContent = blockerParts.length > 0
996
+ ? capTurnEndMessage(blockerParts.join("\n\n"))
997
+ : undefined;
998
+ const affectedFiles = [
999
+ ...(existingGuard?.affectedFiles ?? []),
1000
+ ...files.map((file) => resolveRunnerPath(cwd, file)),
1001
+ ...cascadeResults.flatMap((result) => result.neighbors
1002
+ .filter((neighbor) => neighbor.diagnostics.length > 0)
1003
+ .map((neighbor) => resolveRunnerPath(cwd, neighbor.filePath))),
1004
+ ];
1005
+ writeGitGuardRecord(cacheManager, runtime, cwd, {
1006
+ content: [content, existingGuard?.testFailureContent]
1007
+ .filter((value) => !!value)
1008
+ .join("\n\n"),
1009
+ blockerContent: blockingContent,
1010
+ blockingFiles: blockerParts.length > 0 ? affectedFiles : undefined,
1011
+ hasBlockers: !!blockingContent || existingGuard?.testFailures === true,
1012
+ affectedFiles,
1013
+ sessionId: runtime.telemetrySessionId,
1014
+ projectSeqStart: runtime.turnStartProjectSeq,
1015
+ projectSeqEnd: runtime.projectSeq,
1016
+ fileSeqByPath,
1017
+ fileContentHashes: {},
1018
+ consumed: false,
1019
+ testFailures: existingGuard?.testFailures,
1020
+ testFailureContent: existingGuard?.testFailureContent,
1021
+ testFailureFiles: existingGuard?.testFailureFiles,
1022
+ });
1023
+ }
1024
+ else {
1025
+ cacheManager.writeCache("turn-end-findings", { content }, cwd);
1026
+ }
790
1027
  cacheManager.writeCache("turn-end-findings-last", {
791
1028
  signature,
792
1029
  sessionId: runtime.telemetrySessionId,
@@ -804,7 +1041,14 @@ export async function handleTurnEnd(deps) {
804
1041
  });
805
1042
  }
806
1043
  if (blockerParts.length === 0) {
807
- cacheManager.clearTurnState(cwd);
1044
+ cacheManager.clearTurnState(cwd, currentOwner);
1045
+ if (getFlag("lens-guard") && advisoryParts.length === 0 && !runtime.gitGuardHasBlockers) {
1046
+ const guardRecord = cacheManager.readCache("turn-end-findings", cwd)?.data;
1047
+ if (guardRecord?.sessionId === runtime.telemetrySessionId &&
1048
+ guardRecord.testFailures !== true) {
1049
+ cacheManager.clearCache("turn-end-findings", cwd);
1050
+ }
1051
+ }
808
1052
  }
809
1053
  runtime.fixedThisTurn.clear();
810
1054
  runtime.clearActionableWarnings();
@@ -6,6 +6,7 @@
6
6
  * Requires: cargo (rustup)
7
7
  * Docs: https://doc.rust-lang.org/cargo/
8
8
  */
9
+ import { createSubsystemLogger } from "./extension-log.js";
9
10
  import * as fs from "node:fs";
10
11
  import * as path from "node:path";
11
12
  import { safeSpawnAsync } from "./safe-spawn.js";
@@ -28,7 +29,7 @@ export class RustClient {
28
29
  log;
29
30
  constructor(verbose = false) {
30
31
  this.log = verbose
31
- ? (msg) => console.error(`[rust] ${msg}`)
32
+ ? createSubsystemLogger("rust")
32
33
  : () => { };
33
34
  }
34
35
  /**