pi-lens 4.1.2 → 4.1.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.
Files changed (359) hide show
  1. package/CHANGELOG.md +1308 -0
  2. package/README.md +3 -0
  3. package/config/biome/core.jsonc +11 -2
  4. package/config/dependency-cruiser-eager-allowlist.json +91 -0
  5. package/dist/clients/actionable-warnings-logger.js +18 -3
  6. package/dist/clients/actionable-warnings.js +927 -80
  7. package/dist/clients/agent-behavior-client.js +13 -4
  8. package/dist/clients/ast-grep-client.js +136 -9
  9. package/dist/clients/ast-grep-rule-manager.js +60 -5
  10. package/dist/clients/ast-grep-tool-logger.js +2 -2
  11. package/dist/clients/availability-probe-flight.js +12 -0
  12. package/dist/clients/bash-file-access.js +1 -3
  13. package/dist/clients/biome-client.js +16 -2
  14. package/dist/clients/blocker-freshness.js +34 -0
  15. package/dist/clients/bootstrap.js +509 -73
  16. package/dist/clients/bounded-cache.js +152 -12
  17. package/dist/clients/bounded-telemetry.js +115 -23
  18. package/dist/clients/build-identity.js +95 -0
  19. package/dist/clients/bundled-resource-health.js +113 -0
  20. package/dist/clients/bus-events-logger.js +2 -2
  21. package/dist/clients/bus-publish.js +3 -0
  22. package/dist/clients/cache/rule-cache.js +33 -5
  23. package/dist/clients/cache-manager.js +105 -6
  24. package/dist/clients/cache-observability.js +46 -19
  25. package/dist/clients/cargo-manifest.js +422 -0
  26. package/dist/clients/cascade-logger.js +17 -3
  27. package/dist/clients/code-quality-warnings.js +13 -3
  28. package/dist/clients/complexity-client.js +16 -5
  29. package/dist/clients/config-core/deny.js +221 -0
  30. package/dist/clients/config-core/index.js +47 -0
  31. package/dist/clients/config-core/merge.js +357 -0
  32. package/dist/clients/config-core/normalize.js +340 -0
  33. package/dist/clients/config-core/process-spec.js +248 -0
  34. package/dist/clients/config-core/provenance.js +171 -0
  35. package/dist/clients/config-core/records.js +218 -0
  36. package/dist/clients/config-core/resolve.js +125 -0
  37. package/dist/clients/config-core/safe-object.js +78 -0
  38. package/dist/clients/config-core/schema.js +167 -0
  39. package/dist/clients/config-diagnostic-codes.js +281 -0
  40. package/dist/clients/config-locations.js +160 -0
  41. package/dist/clients/config-resolve.js +789 -0
  42. package/dist/clients/config-schema.js +197 -0
  43. package/dist/clients/config-warn.js +407 -0
  44. package/dist/clients/dead-code-client.js +33 -25
  45. package/dist/clients/dead-code-logger.js +2 -2
  46. package/dist/clients/deadline-utils.js +178 -0
  47. package/dist/clients/debug-handles.js +2 -2
  48. package/dist/clients/debug-heap.js +3 -3
  49. package/dist/clients/deferred-lsp-work.js +106 -0
  50. package/dist/clients/degradation-ledger.js +166 -8
  51. package/dist/clients/demoted-finding-render.js +14 -0
  52. package/dist/clients/dependency-checker.js +28 -22
  53. package/dist/clients/deps/minimatch.js +1 -1
  54. package/dist/clients/diagnostic-line-freshness.js +12 -9
  55. package/dist/clients/diagnostic-logger.js +14 -4
  56. package/dist/clients/dispatch/collect-later-tier.js +39 -0
  57. package/dist/clients/dispatch/dispatcher.js +304 -19
  58. package/dist/clients/dispatch/fact-store.js +328 -9
  59. package/dist/clients/dispatch/integration.js +214 -107
  60. package/dist/clients/dispatch/pending-runner-findings.js +87 -0
  61. package/dist/clients/dispatch/plan.js +21 -5
  62. package/dist/clients/dispatch/runners/actionlint.js +0 -1
  63. package/dist/clients/dispatch/runners/ast-grep-napi.js +550 -77
  64. package/dist/clients/dispatch/runners/biome-check.js +0 -1
  65. package/dist/clients/dispatch/runners/cpp-check.js +0 -1
  66. package/dist/clients/dispatch/runners/credo.js +0 -1
  67. package/dist/clients/dispatch/runners/cue-vet.js +0 -1
  68. package/dist/clients/dispatch/runners/dart-analyze.js +0 -1
  69. package/dist/clients/dispatch/runners/detekt.js +0 -1
  70. package/dist/clients/dispatch/runners/dotnet-build.js +0 -1
  71. package/dist/clients/dispatch/runners/elixir-check.js +0 -1
  72. package/dist/clients/dispatch/runners/eslint.js +5 -2
  73. package/dist/clients/dispatch/runners/fact-rules.js +0 -1
  74. package/dist/clients/dispatch/runners/fish-indent.js +0 -1
  75. package/dist/clients/dispatch/runners/gleam-check.js +0 -1
  76. package/dist/clients/dispatch/runners/go-vet.js +1 -3
  77. package/dist/clients/dispatch/runners/golangci-lint.js +0 -1
  78. package/dist/clients/dispatch/runners/hadolint.js +0 -1
  79. package/dist/clients/dispatch/runners/helm-lint.js +16 -4
  80. package/dist/clients/dispatch/runners/helm-render.js +54 -10
  81. package/dist/clients/dispatch/runners/htmlhint.js +0 -1
  82. package/dist/clients/dispatch/runners/index.js +1 -3
  83. package/dist/clients/dispatch/runners/javac.js +0 -1
  84. package/dist/clients/dispatch/runners/ktlint.js +0 -1
  85. package/dist/clients/dispatch/runners/lsp.js +37 -2
  86. package/dist/clients/dispatch/runners/markdownlint.js +4 -2
  87. package/dist/clients/dispatch/runners/mypy.js +0 -1
  88. package/dist/clients/dispatch/runners/oxlint.js +24 -22
  89. package/dist/clients/dispatch/runners/php-lint.js +0 -1
  90. package/dist/clients/dispatch/runners/phpstan.js +0 -1
  91. package/dist/clients/dispatch/runners/prisma-validate.js +0 -1
  92. package/dist/clients/dispatch/runners/psscriptanalyzer.js +4 -1
  93. package/dist/clients/dispatch/runners/pyright.js +7 -4
  94. package/dist/clients/dispatch/runners/rubocop.js +0 -1
  95. package/dist/clients/dispatch/runners/ruff.js +0 -1
  96. package/dist/clients/dispatch/runners/rust-clippy.js +9 -6
  97. package/dist/clients/dispatch/runners/shellcheck.js +0 -1
  98. package/dist/clients/dispatch/runners/shfmt.js +0 -1
  99. package/dist/clients/dispatch/runners/spellcheck.js +0 -1
  100. package/dist/clients/dispatch/runners/spotbugs.js +0 -1
  101. package/dist/clients/dispatch/runners/sqlfluff.js +0 -1
  102. package/dist/clients/dispatch/runners/stylelint.js +0 -1
  103. package/dist/clients/dispatch/runners/swiftlint.js +0 -1
  104. package/dist/clients/dispatch/runners/taplo.js +0 -1
  105. package/dist/clients/dispatch/runners/terragrunt.js +0 -1
  106. package/dist/clients/dispatch/runners/tflint.js +0 -1
  107. package/dist/clients/dispatch/runners/tree-sitter.js +0 -1
  108. package/dist/clients/dispatch/runners/trivy-config.js +0 -1
  109. package/dist/clients/dispatch/runners/utils/availability-policy.js +3 -0
  110. package/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +3 -4
  111. package/dist/clients/dispatch/runners/utils/runner-helpers.js +270 -105
  112. package/dist/clients/dispatch/runners/utils/spawn-outcome.js +4 -0
  113. package/dist/clients/dispatch/runners/utils/tool-failure.js +19 -7
  114. package/dist/clients/dispatch/runners/utils/toolchain-availability.js +89 -26
  115. package/dist/clients/dispatch/runners/vale.js +0 -1
  116. package/dist/clients/dispatch/runners/yaml-rule-parser.js +51 -17
  117. package/dist/clients/dispatch/runners/yamllint.js +0 -1
  118. package/dist/clients/dispatch/runners/zig-check.js +0 -1
  119. package/dist/clients/disposition-logger.js +3 -3
  120. package/dist/clients/effective-config.js +403 -0
  121. package/dist/clients/error-class.js +23 -0
  122. package/dist/clients/event-loop-hold.js +274 -0
  123. package/dist/clients/event-loop-monitor.js +66 -1
  124. package/dist/clients/extension-log.js +2 -2
  125. package/dist/clients/feature-hints.js +2 -1
  126. package/dist/clients/file-time.js +6 -1
  127. package/dist/clients/file-utils.js +266 -13
  128. package/dist/clients/finding-delivery-gate.js +55 -13
  129. package/dist/clients/format-service.js +6 -1
  130. package/dist/clients/formatters.js +303 -104
  131. package/dist/clients/freshness-cadence.js +17 -0
  132. package/dist/clients/generated-artifacts.js +114 -19
  133. package/dist/clients/generation-guard.js +4 -9
  134. package/dist/clients/git-guard.js +198 -48
  135. package/dist/clients/git-tracked-ignore.js +32 -1
  136. package/dist/clients/go-client.js +39 -0
  137. package/dist/clients/govulncheck-client.js +5 -1
  138. package/dist/clients/gradle-ktfmt-style.js +252 -0
  139. package/dist/clients/gzip-stage-write.js +7 -0
  140. package/dist/clients/hashline-anchor.js +424 -0
  141. package/dist/clients/hook-budgets.js +76 -0
  142. package/dist/clients/host-edit-normalize.js +5 -2
  143. package/dist/clients/host-ports.js +1 -1
  144. package/dist/clients/installer/index.js +200 -84
  145. package/dist/clients/installer/managed-tool-refresh.js +3 -1
  146. package/dist/clients/instance-reaper.js +108 -243
  147. package/dist/clients/instance-registry-lock.js +145 -0
  148. package/dist/clients/instance-registry.js +435 -122
  149. package/dist/clients/jscpd-client.js +6 -1
  150. package/dist/clients/language-profile.js +4 -2
  151. package/dist/clients/language-registry.js +595 -0
  152. package/dist/clients/latency-logger.js +179 -3
  153. package/dist/clients/ledger-bounds.js +13 -0
  154. package/dist/clients/lens-config.js +141 -30
  155. package/dist/clients/lens-engine.js +30 -37
  156. package/dist/clients/lens-flag-registry.js +67 -6
  157. package/dist/clients/lens-map.js +3 -1
  158. package/dist/clients/log-cleanup.js +2 -2
  159. package/dist/clients/lsp/aggregation.js +3 -1
  160. package/dist/clients/lsp/cascade-tier.js +4 -0
  161. package/dist/clients/lsp/client.js +672 -49
  162. package/dist/clients/lsp/config.js +504 -156
  163. package/dist/clients/lsp/diagnostic-binding.js +10 -5
  164. package/dist/clients/lsp/edits.js +15 -2
  165. package/dist/clients/lsp/index.js +1179 -247
  166. package/dist/clients/lsp/jvm-runtime.js +5 -0
  167. package/dist/clients/lsp/language.js +18 -169
  168. package/dist/clients/lsp/launch.js +38 -9
  169. package/dist/clients/lsp/pending-aux-coverage.js +113 -12
  170. package/dist/clients/lsp/server.js +426 -160
  171. package/dist/clients/lsp/session-roots.js +192 -0
  172. package/dist/clients/lsp/spawn-history.js +2 -7
  173. package/dist/clients/lsp/tsserver-sync.js +9 -2
  174. package/dist/clients/lsp/workspace-diagnostics-cache.js +17 -7
  175. package/dist/clients/lsp/workspace-sweep-hold.js +32 -23
  176. package/dist/clients/lsp-mutation.js +179 -23
  177. package/dist/clients/map-with-concurrency.js +36 -0
  178. package/dist/clients/mcp/analyze.js +45 -10
  179. package/dist/clients/mcp/session.js +19 -17
  180. package/dist/clients/memory-sampler.js +28 -1
  181. package/dist/clients/message-end-attribution.js +30 -0
  182. package/dist/clients/metrics-history.js +21 -4
  183. package/dist/clients/middle-man-analysis.js +2 -4
  184. package/dist/clients/module-report.js +20 -45
  185. package/dist/clients/mutating-tool.js +651 -0
  186. package/dist/clients/mutation-attribution.js +368 -0
  187. package/dist/clients/mutation-bridge.js +240 -0
  188. package/dist/clients/ndjson-logger.js +247 -20
  189. package/dist/clients/observed-mutation-sources.js +101 -0
  190. package/dist/clients/observed-mutation.js +1215 -0
  191. package/dist/clients/opaque-mutation-scan.js +300 -40
  192. package/dist/clients/opengrep-config.js +4 -0
  193. package/dist/clients/package-manager.js +201 -44
  194. package/dist/clients/partial-edit-apply.js +359 -80
  195. package/dist/clients/path-attribution-telemetry.js +23 -7
  196. package/dist/clients/path-keyed-map.js +35 -3
  197. package/dist/clients/path-utils.js +460 -13
  198. package/dist/clients/persist-debounce.js +8 -1
  199. package/dist/clients/php-cs-fixer-config.js +114 -0
  200. package/dist/clients/pipeline.js +77 -24
  201. package/dist/clients/probe-home-state.js +228 -0
  202. package/dist/clients/process-bridge.js +66 -0
  203. package/dist/clients/process-singletons.js +210 -0
  204. package/dist/clients/process-snapshot.js +68 -0
  205. package/dist/clients/project-diagnostics/fresh-fetch.js +4 -3
  206. package/dist/clients/project-diagnostics/runner-adapters/madge.js +2 -1
  207. package/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +27 -3
  208. package/dist/clients/project-diagnostics/scanner.js +61 -24
  209. package/dist/clients/project-lens-config.js +393 -122
  210. package/dist/clients/project-snapshot.js +85 -35
  211. package/dist/clients/python-environment.js +217 -0
  212. package/dist/clients/python-provenance.js +639 -0
  213. package/dist/clients/quiet-window.js +6 -1
  214. package/dist/clients/read-bridge.js +13 -21
  215. package/dist/clients/read-expansion.js +9 -46
  216. package/dist/clients/read-guard-logger.js +39 -6
  217. package/dist/clients/read-guard-tool-lines.js +364 -212
  218. package/dist/clients/read-guard.js +95 -7
  219. package/dist/clients/recent-touches.js +17 -5
  220. package/dist/clients/resource-sampler.js +195 -96
  221. package/dist/clients/review-graph/builder.js +752 -132
  222. package/dist/clients/review-graph/service.js +55 -3
  223. package/dist/clients/review-graph/shared-extraction-ir.js +7 -15
  224. package/dist/clients/review-graph/tsconfig-paths.js +5 -1
  225. package/dist/clients/review-graph/workspace-modules.js +10 -74
  226. package/dist/clients/review-graph-logger.js +30 -4
  227. package/dist/clients/runtime-agent-end.js +18 -2
  228. package/dist/clients/runtime-context.js +49 -16
  229. package/dist/clients/runtime-coordinator.js +93 -6
  230. package/dist/clients/runtime-session.js +169 -34
  231. package/dist/clients/runtime-tool-call.js +183 -35
  232. package/dist/clients/runtime-tool-result.js +894 -241
  233. package/dist/clients/runtime-turn.js +1264 -74
  234. package/dist/clients/rust-client.js +31 -0
  235. package/dist/clients/safe-spawn.js +191 -28
  236. package/dist/clients/sanitize.js +7 -1
  237. package/dist/clients/scratch-tree-policy.js +1 -3
  238. package/dist/clients/security-scan-client.js +51 -17
  239. package/dist/clients/session-lifecycle.js +238 -42
  240. package/dist/clients/session-start-observability.js +79 -0
  241. package/dist/clients/sessionstart-logger.js +12 -3
  242. package/dist/clients/sg-runner.js +27 -15
  243. package/dist/clients/sgconfig.js +6 -1
  244. package/dist/clients/shared-checkout-guard.js +338 -0
  245. package/dist/clients/skills-resolver.js +105 -0
  246. package/dist/clients/smells-rollup.js +2 -2
  247. package/dist/clients/spawn-output-cap.js +37 -0
  248. package/dist/clients/spawn-timeout-cooldown.js +15 -1
  249. package/dist/clients/startup-scan.js +6 -7
  250. package/dist/clients/startup-timing.js +69 -4
  251. package/dist/clients/string-utils.js +33 -0
  252. package/dist/clients/subagent-mode.js +17 -4
  253. package/dist/clients/test-runner-client.js +586 -118
  254. package/dist/clients/test-runner-delivery.js +239 -0
  255. package/dist/clients/tool-definition.js +41 -1
  256. package/dist/clients/tool-policy.js +92 -22
  257. package/dist/clients/tree-sitter-cache.js +40 -40
  258. package/dist/clients/tree-sitter-client.js +97 -53
  259. package/dist/clients/tree-sitter-logger.js +19 -3
  260. package/dist/clients/tree-sitter-query-loader.js +81 -1
  261. package/dist/clients/tree-sitter-shared.js +51 -46
  262. package/dist/clients/tree-sitter-symbol-extractor.js +28 -0
  263. package/dist/clients/typos-config.js +5 -0
  264. package/dist/clients/user-notify.js +6 -2
  265. package/dist/clients/warm-attach.js +8 -10
  266. package/dist/clients/widget-state.js +191 -26
  267. package/dist/clients/word-index-logger.js +15 -3
  268. package/dist/clients/word-index-store.js +463 -0
  269. package/dist/clients/word-index.js +815 -125
  270. package/dist/clients/workspace-topology.js +25 -1
  271. package/dist/clients/zizmor-config.js +29 -6
  272. package/dist/index.js +68577 -53950
  273. package/dist/mcp/analyze-cli.js +3 -1
  274. package/dist/mcp/build-staleness.js +8 -7
  275. package/dist/mcp/cli.js +3 -1
  276. package/dist/mcp/server.js +133 -6
  277. package/dist/scripts/lib/process-scan.mjs +583 -0
  278. package/dist/scripts/lib/skills-predicate.mjs +129 -0
  279. package/dist/tools/effective-config.js +89 -0
  280. package/dist/tools/lens-diagnostics.js +99 -24
  281. package/dist/tools/lsp-diagnostics.js +81 -85
  282. package/dist/tools/lsp-navigation.js +40 -17
  283. package/dist/tools/shared.js +0 -1
  284. package/docs/agent-guide.md +68 -3
  285. package/docs/ast-grep_rules_catalog.md +41 -10
  286. package/docs/astplayground.md +26 -17
  287. package/docs/configuration.md +222 -0
  288. package/docs/dependencies.md +3 -3
  289. package/docs/features.md +44 -5
  290. package/docs/language-coverage.md +2 -2
  291. package/docs/pi-lens-fixer.md +25 -0
  292. package/docs/pi-lens-investigator.md +25 -0
  293. package/docs/pi-lens-reviewer.md +27 -0
  294. package/docs/pi-lens-subagent.md +38 -0
  295. package/docs/pi-lens-warden.md +55 -0
  296. package/docs/public-api-stability.md +359 -0
  297. package/docs/release-qa-baseline.md +182 -0
  298. package/docs/subagent-compat.md +110 -30
  299. package/docs/tree-sitter_rules_catalog.md +2 -2
  300. package/package.json +17 -21
  301. package/rules/ast-grep-rules/rule-tests/c-no-malloc-free-test.yml +20 -0
  302. package/rules/ast-grep-rules/rule-tests/cpp-no-malloc-free-test.yml +25 -0
  303. package/rules/ast-grep-rules/rule-tests/cpp-no-printf-test.yml +19 -0
  304. package/rules/ast-grep-rules/rule-tests/go-no-fmt-println-test.yml +19 -0
  305. package/rules/ast-grep-rules/rule-tests/go-no-panic-in-lib-test.yml +17 -0
  306. package/rules/ast-grep-rules/rule-tests/go-no-underscore-func-name-test.yml +18 -0
  307. package/rules/ast-grep-rules/rule-tests/go-prefer-errors-is-test.yml +15 -0
  308. package/rules/ast-grep-rules/rule-tests/go-prefer-string-builder-test.yml +21 -0
  309. package/rules/ast-grep-rules/rule-tests/hyphenated-svg-attribute-test.yml +11 -0
  310. package/rules/ast-grep-rules/rule-tests/kotlin-no-lateinit-test.yml +17 -0
  311. package/rules/ast-grep-rules/rule-tests/kotlin-no-nullable-boolean-test.yml +15 -0
  312. package/rules/ast-grep-rules/rule-tests/kotlin-no-println-test.yml +19 -0
  313. package/rules/ast-grep-rules/rule-tests/kotlin-no-unnecessary-let-test.yml +7 -0
  314. package/rules/ast-grep-rules/rule-tests/kotlin-no-unsafe-cast-test.yml +7 -0
  315. package/rules/ast-grep-rules/rule-tests/kotlin-no-var-test.yml +7 -0
  316. package/rules/ast-grep-rules/rule-tests/kotlin-prefer-data-class-test.yml +25 -0
  317. package/rules/ast-grep-rules/rule-tests/kotlin-prefer-is-empty-test.yml +11 -0
  318. package/rules/ast-grep-rules/rule-tests/no-important-test.yml +21 -0
  319. package/rules/ast-grep-rules/rule-tests/no-raw-types-test.yml +30 -0
  320. package/rules/ast-grep-rules/rule-tests/no-string-concat-in-loop-test.yml +100 -0
  321. package/rules/ast-grep-rules/rule-tests/no-system-out-println-test.yml +7 -0
  322. package/rules/ast-grep-rules/rule-tests/prefer-string-is-empty-test.yml +7 -0
  323. package/rules/ast-grep-rules/rule-tests/python-optional-type-test.yml +9 -0
  324. package/rules/ast-grep-rules/rule-tests/reducible-list-comprehension-test.yml +11 -0
  325. package/rules/ast-grep-rules/rule-tests/ruby-symbol-to-proc-candidate-test.yml +10 -0
  326. package/rules/ast-grep-rules/rule-tests/rust-no-chars-enumerate-test.yml +7 -0
  327. package/rules/ast-grep-rules/rules/c-no-malloc-free.yml +39 -0
  328. package/rules/ast-grep-rules/rules/cpp-no-malloc-free.yml +45 -0
  329. package/rules/ast-grep-rules/rules/cpp-no-printf.yml +41 -0
  330. package/rules/ast-grep-rules/rules/go-no-fmt-println.yml +43 -0
  331. package/rules/ast-grep-rules/rules/go-no-panic-in-lib.yml +41 -0
  332. package/rules/ast-grep-rules/rules/go-no-underscore-func-name.yml +35 -0
  333. package/rules/ast-grep-rules/rules/go-prefer-errors-is.yml +40 -0
  334. package/rules/ast-grep-rules/rules/go-prefer-string-builder.yml +43 -0
  335. package/rules/ast-grep-rules/rules/hyphenated-svg-attribute.yml +32 -0
  336. package/rules/ast-grep-rules/rules/kotlin-no-lateinit.yml +37 -0
  337. package/rules/ast-grep-rules/rules/kotlin-no-nullable-boolean.yml +33 -0
  338. package/rules/ast-grep-rules/rules/kotlin-no-println.yml +42 -0
  339. package/rules/ast-grep-rules/rules/kotlin-no-unnecessary-let.yml +28 -0
  340. package/rules/ast-grep-rules/rules/kotlin-no-unsafe-cast.yml +28 -0
  341. package/rules/ast-grep-rules/rules/kotlin-no-var.yml +35 -0
  342. package/rules/ast-grep-rules/rules/kotlin-prefer-data-class.yml +66 -0
  343. package/rules/ast-grep-rules/rules/kotlin-prefer-is-empty.yml +35 -0
  344. package/rules/ast-grep-rules/rules/no-important.yml +21 -0
  345. package/rules/ast-grep-rules/rules/no-raw-types.yml +33 -0
  346. package/rules/ast-grep-rules/rules/no-string-concat-in-loop.yml +90 -0
  347. package/rules/ast-grep-rules/rules/no-system-out-println.yml +16 -0
  348. package/rules/ast-grep-rules/rules/prefer-string-is-empty.yml +11 -0
  349. package/rules/ast-grep-rules/rules/python-optional-type.yml +22 -0
  350. package/rules/ast-grep-rules/rules/reducible-list-comprehension.yml +29 -0
  351. package/rules/ast-grep-rules/rules/ruby-symbol-to-proc-candidate.yml +25 -0
  352. package/rules/ast-grep-rules/rules/rust-no-chars-enumerate.yml +19 -0
  353. package/rules/tree-sitter-queries/python/python-cross-language-method.yml +3 -3
  354. package/rules/tree-sitter-queries/python/python-hallucinated-import.yml +2 -2
  355. package/rules/tree-sitter-queries/python/python-sql-injection.yml +12 -2
  356. package/scripts/analyze-pi-lens-logs.mjs +192 -1
  357. package/scripts/install-selftest.mjs +58 -2
  358. package/scripts/lib/skills-predicate.mjs +129 -0
  359. package/scripts/rpc-load-check.mjs +3 -1
@@ -1,20 +1,123 @@
1
+ import { BoundedLruCache } from "../bounded-cache.js";
1
2
  import { normalizeMapKey } from "../path-utils.js";
3
+ let capacityEvictionReporter;
4
+ export function setFactStoreEvictionReporter(reporter) {
5
+ capacityEvictionReporter = reporter;
6
+ }
7
+ export function getFactStoreEvictionReporter() {
8
+ return capacityEvictionReporter;
9
+ }
10
+ // #2240: the dispatch store is module-scope in integration.ts, so it lives for
11
+ // the whole process, and a review-graph project walk seeds facts for EVERY file
12
+ // it visits. Nothing removed an entry except the next dispatch of that same
13
+ // path, so a several-hundred-file batch retained one entry per distinct path
14
+ // until the heap ran out. Bound the record count the way widget-state.ts bounds
15
+ // its file records.
16
+ const MAX_FILE_FACT_RECORDS = 1024;
17
+ // Keep enough content for 1024 typical source files averaging 64 KiB, while
18
+ // preventing a small number of generated or vendored files from retaining
19
+ // hundreds of MiB for the process lifetime (#2247).
20
+ const MAX_FILE_FACT_CONTENT_BYTES = 64 * 1024 * 1024;
21
+ // Pinned records are exempt from capacity eviction. A dispatch reads its
22
+ // file's facts back after the runner groups settle (`file.content` misses read as
23
+ // empty content, not as "re-derive"), and the fire-and-forget blast-radius
24
+ // build runs a whole-project walk against the SAME store meanwhile — plain LRU
25
+ // recency would let that walk evict the file being dispatched. Every other holder
26
+ // re-derives an evicted fact from disk.
27
+ //
28
+ // #2243 item 2: a dispatch pins its file at start (`clearFileFactsFor`) and
29
+ // releases it at completion (`endDispatchFor`, in the dispatch's finally). The
30
+ // pin set therefore tracks dispatches actually IN FLIGHT, not the last N files
31
+ // touched.
32
+ // #2282: `sessionFacts` below is a flat `Map<factId, value>` shared by two
33
+ // unrelated fact shapes — a small FIXED vocabulary (tool availability keyed by
34
+ // command, the singleton "session.reviewGraph") and PER-FILE families that
35
+ // mint one key per file touched (session baseline, cascade baseline, review-
36
+ // graph entity snapshots) and never shrink. Only the second shape grows with
37
+ // batch size, so only it gets a bound; the fixed vocabulary stays on the plain
38
+ // map, unbounded, because its cardinality is small and stable. Per-file
39
+ // session facts opt into `boundedSessionFacts` instead, reusing fileFacts'
40
+ // LRU-count-cap-and-report discipline rather than adding a third mechanism.
41
+ // No pin exemption here (unlike fileFacts): every current per-file session
42
+ // fact is read once near dispatch start and written once at dispatch end, so
43
+ // nothing re-reads its OWN key later in the same dispatch the way a runner
44
+ // re-reads `file.content` — an eviction mid-batch only means the next dispatch
45
+ // of that path sees no previous baseline, the same safe state as its first
46
+ // ever dispatch this session.
47
+ //
48
+ // That equivalence holds only where an absent baseline means "report
49
+ // everything", which is true for the diagnostic baselines and false for the
50
+ // review-graph entity snapshot: there, an absent snapshot read as an empty one
51
+ // puts every symbol in `added` and drives a blast-radius run for a file that
52
+ // did not change. So an eviction leaves a tombstone, and a reader that needs
53
+ // the distinction asks `wasBoundedSessionFactEvicted`. Tombstones are keys
54
+ // only, and carry the same cap, so the coldest of them fall off in turn and
55
+ // that key reverts to first-dispatch semantics.
56
+ //
57
+ // Four per-file keys are minted per dispatched file today (diagnostic
58
+ // baseline, cascade baseline, entity snapshot, changed symbols), so 4096
59
+ // records covers roughly 1024 distinct files before the coldest file's
60
+ // baseline starts degrading.
61
+ const MAX_SESSION_FACT_RECORDS = 4096;
2
62
  export class FactStore {
63
+ subject;
64
+ // Insertion order is eviction order: the oldest-used record is evicted first.
3
65
  fileFacts = new Map();
4
66
  sessionFacts = new Map();
67
+ // Bounded sibling of `sessionFacts` for per-file-keyed session facts (#2282).
68
+ // True LRU: every fetch (get or create, see getBoundedSessionFact) refreshes
69
+ // recency, so the oldest-UNUSED record is evicted first, not merely the
70
+ // oldest-inserted.
71
+ boundedSessionFacts = new BoundedLruCache(MAX_SESSION_FACT_RECORDS);
72
+ // Keys evicted from `boundedSessionFacts` and not written since, so a reader
73
+ // can tell "evicted" from "never seen" (#2282). Same cap, same FIFO order.
74
+ evictedSessionFactKeys = new Set();
75
+ // Pin refcount per file. A file is exempt from capacity eviction while its
76
+ // count is > 0. Refcounted, not a Set, so two overlapping dispatches of the
77
+ // same file both hold the pin until BOTH settle (#2243 item 2).
78
+ pinnedFiles = new Map();
79
+ // Running UTF-8 byte total for file.content only. Maintaining it at every
80
+ // mutation keeps getFileFact/setFileFact O(1) amortized; never scan the map
81
+ // to decide whether the byte budget is exceeded.
82
+ retainedContentBytes = 0;
83
+ // Subset of retainedContentBytes held by currently pinned files (#2247
84
+ // review F2). Maintained incrementally the same way — a scan over
85
+ // `pinnedFiles` looks small in isolation, but `evictColdFileFacts` calls it
86
+ // on EVERY unpinned insert for as long as pinned bytes stay over budget, so
87
+ // a scan there would re-walk a large pinned file's full string on every
88
+ // single write admitted during that window. Keeping a running total avoids
89
+ // reintroducing exactly the scan `retainedContentBytes` exists to avoid.
90
+ pinnedContentBytesTotal = 0;
91
+ /**
92
+ * @param subject Discriminates this store's capacity-eviction telemetry
93
+ * from every other production FactStore's (#2243 review round 3, F1).
94
+ * Production callers pass a label naming the store (e.g. `"dispatch"`,
95
+ * `"runtime-session-call-graph"`); the default is only for call sites
96
+ * that never wired a reporter and tests that don't care.
97
+ */
98
+ constructor(subject = "session-fact-store") {
99
+ this.subject = subject;
100
+ }
5
101
  // All file-keyed methods normalize the path internally via normalizeMapKey().
6
102
  // Callers always pass raw/resolved paths — normalization is not their concern.
7
103
  getFileFact(filePath, factId) {
8
- return this.fileFacts.get(normalizeMapKey(filePath))?.get(factId);
104
+ return this.touchFileFacts(normalizeMapKey(filePath))?.get(factId);
9
105
  }
10
106
  setFileFact(filePath, factId, value) {
11
107
  const key = normalizeMapKey(filePath);
12
- let facts = this.fileFacts.get(key);
108
+ let facts = this.touchFileFacts(key);
13
109
  if (!facts) {
14
110
  facts = new Map();
15
111
  this.fileFacts.set(key, facts);
16
112
  }
113
+ if (factId === "file.content") {
114
+ const delta = this.contentBytes(value) - this.contentBytes(facts.get(factId));
115
+ this.retainedContentBytes += delta;
116
+ if (this.pinnedFiles.has(key))
117
+ this.pinnedContentBytesTotal += delta;
118
+ }
17
119
  facts.set(factId, value);
120
+ this.evictColdFileFacts();
18
121
  }
19
122
  hasFileFact(filePath, factId) {
20
123
  return this.fileFacts.get(normalizeMapKey(filePath))?.has(factId) ?? false;
@@ -26,20 +129,186 @@ export class FactStore {
26
129
  const facts = this.fileFacts.get(key);
27
130
  if (!facts)
28
131
  return;
132
+ if (factId === "file.content") {
133
+ const dropped = this.contentBytes(facts.get(factId));
134
+ this.retainedContentBytes -= dropped;
135
+ if (this.pinnedFiles.has(key))
136
+ this.pinnedContentBytesTotal -= dropped;
137
+ }
29
138
  facts.delete(factId);
30
139
  if (facts.size === 0)
31
140
  this.fileFacts.delete(key);
32
141
  }
33
- /** Clear facts for one specific file only. Use at the start of each per-file dispatch call.
142
+ /** Clear facts for one specific file only, and mark the file's dispatch as
143
+ * begun. Use at the start of each per-file dispatch call.
34
144
  * Preserves facts for other files computed in the same turn.
35
- * Normalizes filePath internally — callers pass raw paths. */
145
+ * Normalizes filePath internally — callers pass raw paths.
146
+ * Pins the file against capacity eviction until the matching
147
+ * {@link endDispatchFor} runs in the dispatch's settle path (#2243 item 2).
148
+ * Every `clearFileFactsFor` MUST be paired with an `endDispatchFor`. */
36
149
  clearFileFactsFor(filePath) {
37
- this.fileFacts.delete(normalizeMapKey(filePath));
150
+ const key = normalizeMapKey(filePath);
151
+ this.deleteFileFactsRecord(key);
152
+ this.pinFile(key);
38
153
  }
39
- /** Clear all file facts across all paths. Reserve for explicit full resets only —
40
- * do NOT use in the normal per-file dispatch path. */
41
- clearFileFacts() {
42
- this.fileFacts.clear();
154
+ /** Pin a file against capacity eviction for the duration of a dispatch,
155
+ * WITHOUT clearing its existing facts. Pairs with {@link endDispatchFor}
156
+ * exactly like {@link clearFileFactsFor} does.
157
+ *
158
+ * #2243 review round 3 (F5): `clearFileFactsFor`'s clear+re-derive is
159
+ * right for a dispatch driven by a fresh edit, but the debounced
160
+ * ast-grep warning scan runs ~2s AFTER the inline dispatch for that same
161
+ * edit already re-derived every fact for this exact file — a second
162
+ * clear there bought nothing but ~51ms of redundant re-parsing across
163
+ * all five providers (measured; a warm-cache read is ~1ms). Use this
164
+ * where the facts are very likely already fresh: `runProviders` still
165
+ * re-derives any fact this file is missing (a genuine miss, e.g. the
166
+ * fact was evicted meanwhile), so a read never depends on staleness. */
167
+ beginDispatchFor(filePath) {
168
+ this.pinFile(normalizeMapKey(filePath));
169
+ }
170
+ /** Release the pin a {@link clearFileFactsFor} or {@link beginDispatchFor}
171
+ * took for one file's dispatch. Call once per matching call, from the
172
+ * dispatch's finally/settle path, so the pin set tracks dispatches
173
+ * actually in flight rather than the last N files touched (#2243 item 2). */
174
+ endDispatchFor(filePath) {
175
+ this.unpinFile(normalizeMapKey(filePath));
176
+ this.evictColdFileFacts();
177
+ }
178
+ /** Clear one file's facts WITHOUT pinning. For sequential single-store scans
179
+ * (project-diagnostics) that own their store and race no concurrent walk:
180
+ * pinning there would exempt every scanned file from the capacity cap and
181
+ * defeat it. Normalizes filePath internally. */
182
+ dropFileFacts(filePath) {
183
+ this.deleteFileFactsRecord(normalizeMapKey(filePath));
184
+ }
185
+ /** LRU touch: re-inserting an existing record moves it to the end of the
186
+ * eviction order, so a record still in use is not the next victim. */
187
+ touchFileFacts(key) {
188
+ const facts = this.fileFacts.get(key);
189
+ if (!facts)
190
+ return undefined;
191
+ this.fileFacts.delete(key);
192
+ this.fileFacts.set(key, facts);
193
+ return facts;
194
+ }
195
+ pinFile(key) {
196
+ const count = this.pinnedFiles.get(key) ?? 0;
197
+ // Transition from unpinned to pinned: this file's content joins the
198
+ // pinned subset. A refcount bump past 1 (an already-pinned file, two
199
+ // overlapping dispatches) does not — it is already counted.
200
+ if (count === 0) {
201
+ this.pinnedContentBytesTotal += this.contentBytes(this.fileFacts.get(key)?.get("file.content"));
202
+ }
203
+ this.pinnedFiles.set(key, count + 1);
204
+ }
205
+ unpinFile(key) {
206
+ const count = this.pinnedFiles.get(key);
207
+ if (count === undefined)
208
+ return;
209
+ if (count <= 1) {
210
+ this.pinnedFiles.delete(key);
211
+ // Transition from pinned to unpinned: this file's content leaves the
212
+ // pinned subset.
213
+ this.pinnedContentBytesTotal -= this.contentBytes(this.fileFacts.get(key)?.get("file.content"));
214
+ }
215
+ else {
216
+ this.pinnedFiles.set(key, count - 1);
217
+ }
218
+ }
219
+ /** Drop least-recently-used records past either cap, skipping the files whose
220
+ * dispatch pinned them. Pinned content counts toward the byte total, but is
221
+ * never evicted before endDispatchFor. Pins survive until clearAll.
222
+ *
223
+ * #2247 review F2: a leaked (or several overlapping) pin(s) can put pinned
224
+ * bytes over budget ON THEIR OWN. Evicting every unpinned record can never
225
+ * bring the total back under budget in that state — before this guard, the
226
+ * loop below evicted each newly inserted unpinned record on the very next
227
+ * call (it was always the sole remaining unpinned key), so unpinned writes
228
+ * never retained anything: a silent, permanent collapse for the rest of
229
+ * the process. Once byte pressure is unpinned-bytes-driven-only, stop
230
+ * evicting and admit unpinned inserts as-is — best-effort under pin
231
+ * pressure — and record the state distinctly so it is visible instead of
232
+ * inferred from "the store stopped retaining anything". */
233
+ evictColdFileFacts() {
234
+ if (!this.overCapacity())
235
+ return;
236
+ for (const key of this.fileFacts.keys()) {
237
+ if (this.pinnedFiles.has(key))
238
+ continue;
239
+ const axis = this.capacityAxis();
240
+ if (axis === "bytes" &&
241
+ this.pinnedContentBytesTotal > MAX_FILE_FACT_CONTENT_BYTES) {
242
+ this.reportPinnedOverBudget();
243
+ return;
244
+ }
245
+ this.deleteFileFactsRecord(key);
246
+ this.reportCapacityEviction(key, axis);
247
+ if (!this.overCapacity())
248
+ return;
249
+ }
250
+ }
251
+ overCapacity() {
252
+ return (this.fileFacts.size > MAX_FILE_FACT_RECORDS ||
253
+ this.retainedContentBytes > MAX_FILE_FACT_CONTENT_BYTES);
254
+ }
255
+ capacityAxis() {
256
+ return this.fileFacts.size > MAX_FILE_FACT_RECORDS ? "count" : "bytes";
257
+ }
258
+ contentBytes(value) {
259
+ return typeof value === "string" ? Buffer.byteLength(value, "utf8") : 0;
260
+ }
261
+ deleteFileFactsRecord(key) {
262
+ const facts = this.fileFacts.get(key);
263
+ if (!facts)
264
+ return;
265
+ const dropped = this.contentBytes(facts.get("file.content"));
266
+ this.retainedContentBytes -= dropped;
267
+ if (this.pinnedFiles.has(key))
268
+ this.pinnedContentBytesTotal -= dropped;
269
+ this.fileFacts.delete(key);
270
+ }
271
+ // #2243 item 4: the cap silently drops a fact a live dispatch may read back
272
+ // as "" (dispatcher.ts reads `file.content` with `?? ""`). Emit through the
273
+ // injected reporter so the drop is visible in the ledger instead of being
274
+ // inferred from a downstream symptom. integration.ts routes this to
275
+ // `recordDegradationOnce` keyed on THIS store's `subject` (#2243 review
276
+ // round 3, F1), so the ledger's own per-kind+subject dedupe yields exactly
277
+ // ONE record per session PER STORE (re-arming at session_start when the
278
+ // ledger resets) — no latch or generation compare here, so fact-store
279
+ // keeps no session-scoped state to forget to re-arm.
280
+ reportCapacityEviction(evictedKey, axis) {
281
+ capacityEvictionReporter?.(this.subject, axis, axis === "count"
282
+ ? `file-fact store axis=count exceeded ${MAX_FILE_FACT_RECORDS} records; evicted least-recently-used fact for ${evictedKey}`
283
+ : `file-fact store axis=bytes exceeded ${MAX_FILE_FACT_CONTENT_BYTES} retained content bytes; evicted least-recently-used fact for ${evictedKey}`);
284
+ }
285
+ // #2247 review F2: pinned bytes alone exceeding budget is not an eviction —
286
+ // nothing is dropped — so it is reported through a distinct axis rather
287
+ // than reusing `reportCapacityEviction`'s "evicted least-recently-used
288
+ // fact for X" language, which would misdescribe what happened.
289
+ reportPinnedOverBudget() {
290
+ const pinnedBytes = this.pinnedContentBytesTotal;
291
+ capacityEvictionReporter?.(this.subject, "pinned-over-budget", `file-fact store pinned content bytes (${pinnedBytes}) exceed the ` +
292
+ `${MAX_FILE_FACT_CONTENT_BYTES}-byte budget; unpinned inserts are ` +
293
+ `admitted without eviction until a pin releases`);
294
+ }
295
+ /** Running UTF-8 byte total for retained `file.content` values. Exposed so
296
+ * tests can crosscheck it against a fresh sum over retained records
297
+ * (#2247 review F3) — the running total is maintained incrementally on
298
+ * every insert/delete path rather than recomputed, so a subtraction
299
+ * dropped from one of those paths would otherwise drift silently. */
300
+ getRetainedContentBytes() {
301
+ return this.retainedContentBytes;
302
+ }
303
+ /** Running UTF-8 byte total for the pinned SUBSET of retained
304
+ * `file.content` values. Exposed so tests can crosscheck it against a
305
+ * fresh sum over `pinnedFiles ∩ fileFacts` (#2247 review F4) — like
306
+ * `retainedContentBytes`, it is maintained incrementally on the pin
307
+ * 0→1 transition, the unpin 1→0 transition, content overwrite/delete,
308
+ * and `clearAll`, so a drop from any one of those paths would
309
+ * otherwise drift silently instead of failing loudly. */
310
+ getPinnedContentBytes() {
311
+ return this.pinnedContentBytesTotal;
43
312
  }
44
313
  getSessionFact(factId) {
45
314
  return this.sessionFacts.get(factId);
@@ -50,9 +319,59 @@ export class FactStore {
50
319
  hasSessionFact(factId) {
51
320
  return this.sessionFacts.has(factId);
52
321
  }
322
+ /** Bounded counterpart to {@link getSessionFact} for per-file-keyed session
323
+ * facts (#2282) — session baselines, cascade baselines, review-graph entity
324
+ * snapshots. LRU touch: a read moves the record off the eviction end. */
325
+ getBoundedSessionFact(factId) {
326
+ if (!this.boundedSessionFacts.has(factId))
327
+ return undefined;
328
+ return this.boundedSessionFacts.get(factId);
329
+ }
330
+ /** Bounded counterpart to {@link setSessionFact}. Callers use this instead
331
+ * of `setSessionFact` for any family that mints one key per file/entity
332
+ * touched, so the store's count stays bounded across a large batch instead
333
+ * of retaining one entry per distinct path for the process lifetime. */
334
+ setBoundedSessionFact(factId, value) {
335
+ this.evictedSessionFactKeys.delete(factId);
336
+ const evicted = this.boundedSessionFacts.set(factId, value);
337
+ for (const [oldestKey] of evicted) {
338
+ this.evictedSessionFactKeys.add(oldestKey);
339
+ while (this.evictedSessionFactKeys.size > MAX_SESSION_FACT_RECORDS) {
340
+ const oldestTombstone = this.evictedSessionFactKeys
341
+ .values()
342
+ .next().value;
343
+ if (oldestTombstone === undefined)
344
+ break;
345
+ this.evictedSessionFactKeys.delete(oldestTombstone);
346
+ }
347
+ capacityEvictionReporter?.(this.subject, "session-count", `session-fact store axis=count exceeded ${MAX_SESSION_FACT_RECORDS} records; evicted least-recently-used fact for ${oldestKey}`);
348
+ }
349
+ }
350
+ hasBoundedSessionFact(factId) {
351
+ return this.boundedSessionFacts.has(factId);
352
+ }
353
+ /** True when this key held a bounded session fact that capacity eviction
354
+ * dropped and nothing has rewritten since (#2282). Readers whose "absent"
355
+ * branch is not a safe default — the review-graph entity snapshot, where
356
+ * absent would read as "every symbol is new" — use this to tell an evicted
357
+ * key from one this session has never seen. */
358
+ wasBoundedSessionFactEvicted(factId) {
359
+ return this.evictedSessionFactKeys.has(factId);
360
+ }
361
+ /** O(1) entry count for memory-attribution sampling (#2282 Observability):
362
+ * the fixed-vocabulary map plus the bounded per-file map, so a caller gets
363
+ * this store's whole `sessionFacts` footprint in one number. */
364
+ getSessionFactEntryCount() {
365
+ return this.sessionFacts.size + this.boundedSessionFacts.size;
366
+ }
53
367
  /** Call on session reset only. Clears everything including tool cache and baselines. */
54
368
  clearAll() {
55
369
  this.fileFacts.clear();
56
370
  this.sessionFacts.clear();
371
+ this.boundedSessionFacts.clear();
372
+ this.evictedSessionFactKeys.clear();
373
+ this.pinnedFiles.clear();
374
+ this.retainedContentBytes = 0;
375
+ this.pinnedContentBytesTotal = 0;
57
376
  }
58
377
  }