@herbertgao/pi-extensions 2026.8.13 → 2026.8.15

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 (263) hide show
  1. package/README.md +19 -14
  2. package/THIRD_PARTY_NOTICES.md +0 -1
  3. package/node_modules/@czottmann/pi-automode/CHANGELOG.md +19 -0
  4. package/node_modules/@czottmann/pi-automode/README.md +5 -1
  5. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/classifier.ts +126 -13
  6. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/config.ts +7 -3
  7. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/constants.ts +2 -0
  8. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/hard-deny.ts +134 -23
  9. package/node_modules/@czottmann/pi-automode/package.json +1 -1
  10. package/node_modules/@herbertgao/{pi-stash → pi-bark}/LICENSE +4 -5
  11. package/node_modules/@herbertgao/pi-bark/README.md +44 -0
  12. package/node_modules/@herbertgao/pi-bark/assets/pi-icon.png +0 -0
  13. package/node_modules/@herbertgao/pi-bark/package.json +53 -0
  14. package/node_modules/@herbertgao/pi-bark/src/index.ts +178 -0
  15. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +1 -1
  16. package/node_modules/@herbertgao/pi-cc-extensions/README.md +1 -1
  17. package/node_modules/@herbertgao/pi-cc-extensions/package.json +3 -3
  18. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  19. package/node_modules/@herbertgao/pi-subagents/package.json +2 -1
  20. package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +8 -1
  21. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
  22. package/node_modules/@narumitw/pi-btw/README.md +125 -88
  23. package/node_modules/@narumitw/pi-btw/dist/index.ts +140 -45
  24. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
  25. package/node_modules/@narumitw/pi-btw/package.json +5 -8
  26. package/node_modules/@narumitw/pi-btw/src/btw.ts +31 -26
  27. package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +106 -17
  28. package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
  29. package/node_modules/@narumitw/pi-btw/src/settings.ts +16 -0
  30. package/node_modules/@tifan/pi-handoff/README.md +36 -13
  31. package/node_modules/@tifan/pi-handoff/package.json +2 -2
  32. package/node_modules/@tifan/pi-handoff/src/index.ts +160 -4
  33. package/node_modules/@tifan/pi-preferred-thinking/README.md +1 -1
  34. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  35. package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +15 -2
  36. package/node_modules/@tifan/pi-recap/README.md +1 -1
  37. package/node_modules/@tifan/pi-recap/package.json +2 -2
  38. package/node_modules/@tifan/pi-recap/src/index.ts +15 -0
  39. package/node_modules/@tifan/pi-rename/README.md +42 -21
  40. package/node_modules/@tifan/pi-rename/package.json +1 -1
  41. package/node_modules/@tifan/pi-rename/src/index.ts +62 -11
  42. package/node_modules/@tifan/pi-rename/src/language.ts +18 -0
  43. package/node_modules/@tifan/pi-rename/src/models.ts +69 -13
  44. package/node_modules/@tifan/pi-rename/src/naming.ts +36 -7
  45. package/node_modules/@tifan/pi-rename/src/sanitize.ts +22 -14
  46. package/node_modules/pi-lens/CHANGELOG.md +320 -0
  47. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +79 -0
  48. package/node_modules/pi-lens/dist/clients/actionable-warnings-logger.js +16 -1
  49. package/node_modules/pi-lens/dist/clients/ast-grep-client.js +13 -6
  50. package/node_modules/pi-lens/dist/clients/availability-probe-flight.js +12 -0
  51. package/node_modules/pi-lens/dist/clients/biome-client.js +7 -0
  52. package/node_modules/pi-lens/dist/clients/blocker-freshness.js +20 -0
  53. package/node_modules/pi-lens/dist/clients/bounded-telemetry.js +56 -19
  54. package/node_modules/pi-lens/dist/clients/build-identity.js +95 -0
  55. package/node_modules/pi-lens/dist/clients/bus-publish.js +3 -0
  56. package/node_modules/pi-lens/dist/clients/cache/rule-cache.js +2 -1
  57. package/node_modules/pi-lens/dist/clients/cache-observability.js +2 -1
  58. package/node_modules/pi-lens/dist/clients/cascade-logger.js +15 -1
  59. package/node_modules/pi-lens/dist/clients/dead-code-client.js +14 -11
  60. package/node_modules/pi-lens/dist/clients/degradation-ledger.js +56 -4
  61. package/node_modules/pi-lens/dist/clients/demoted-finding-render.js +14 -0
  62. package/node_modules/pi-lens/dist/clients/dependency-checker.js +20 -3
  63. package/node_modules/pi-lens/dist/clients/deps/minimatch.js +1 -1
  64. package/node_modules/pi-lens/dist/clients/dispatch/collect-later-tier.js +39 -0
  65. package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +150 -9
  66. package/node_modules/pi-lens/dist/clients/dispatch/fact-store.js +231 -9
  67. package/node_modules/pi-lens/dist/clients/dispatch/integration.js +205 -100
  68. package/node_modules/pi-lens/dist/clients/dispatch/pending-runner-findings.js +87 -0
  69. package/node_modules/pi-lens/dist/clients/dispatch/plan.js +21 -5
  70. package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +174 -55
  71. package/node_modules/pi-lens/dist/clients/dispatch/runners/eslint.js +5 -1
  72. package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-lint.js +16 -3
  73. package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +54 -9
  74. package/node_modules/pi-lens/dist/clients/dispatch/runners/index.js +1 -3
  75. package/node_modules/pi-lens/dist/clients/dispatch/runners/lsp.js +37 -1
  76. package/node_modules/pi-lens/dist/clients/dispatch/runners/markdownlint.js +4 -1
  77. package/node_modules/pi-lens/dist/clients/dispatch/runners/oxlint.js +11 -4
  78. package/node_modules/pi-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +4 -0
  79. package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +8 -3
  80. package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +76 -25
  81. package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +4 -0
  82. package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/tool-failure.js +19 -7
  83. package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +7 -13
  84. package/node_modules/pi-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +51 -17
  85. package/node_modules/pi-lens/dist/clients/event-loop-monitor.js +66 -1
  86. package/node_modules/pi-lens/dist/clients/file-utils.js +157 -7
  87. package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +5 -0
  88. package/node_modules/pi-lens/dist/clients/formatters.js +28 -3
  89. package/node_modules/pi-lens/dist/clients/git-guard.js +197 -47
  90. package/node_modules/pi-lens/dist/clients/git-tracked-ignore.js +32 -1
  91. package/node_modules/pi-lens/dist/clients/govulncheck-client.js +5 -1
  92. package/node_modules/pi-lens/dist/clients/gzip-stage-write.js +7 -0
  93. package/node_modules/pi-lens/dist/clients/installer/index.js +131 -34
  94. package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh.js +3 -1
  95. package/node_modules/pi-lens/dist/clients/instance-reaper.js +4 -13
  96. package/node_modules/pi-lens/dist/clients/instance-registry-lock.js +145 -0
  97. package/node_modules/pi-lens/dist/clients/instance-registry.js +432 -122
  98. package/node_modules/pi-lens/dist/clients/jscpd-client.js +6 -1
  99. package/node_modules/pi-lens/dist/clients/language-profile.js +4 -2
  100. package/node_modules/pi-lens/dist/clients/latency-logger.js +19 -1
  101. package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +8 -0
  102. package/node_modules/pi-lens/dist/clients/lens-map.js +3 -1
  103. package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +4 -0
  104. package/node_modules/pi-lens/dist/clients/lsp/client.js +516 -31
  105. package/node_modules/pi-lens/dist/clients/lsp/config.js +25 -2
  106. package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +9 -4
  107. package/node_modules/pi-lens/dist/clients/lsp/index.js +509 -182
  108. package/node_modules/pi-lens/dist/clients/lsp/jvm-runtime.js +5 -0
  109. package/node_modules/pi-lens/dist/clients/lsp/launch.js +36 -8
  110. package/node_modules/pi-lens/dist/clients/lsp/pending-aux-coverage.js +116 -4
  111. package/node_modules/pi-lens/dist/clients/lsp/server.js +142 -13
  112. package/node_modules/pi-lens/dist/clients/lsp/session-roots.js +99 -0
  113. package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +16 -6
  114. package/node_modules/pi-lens/dist/clients/lsp/workspace-sweep-hold.js +32 -23
  115. package/node_modules/pi-lens/dist/clients/lsp-mutation.js +16 -2
  116. package/node_modules/pi-lens/dist/clients/mcp/analyze.js +12 -6
  117. package/node_modules/pi-lens/dist/clients/mcp/session.js +14 -1
  118. package/node_modules/pi-lens/dist/clients/memory-sampler.js +23 -1
  119. package/node_modules/pi-lens/dist/clients/message-end-attribution.js +30 -0
  120. package/node_modules/pi-lens/dist/clients/metrics-history.js +21 -4
  121. package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +232 -18
  122. package/node_modules/pi-lens/dist/clients/package-manager.js +6 -18
  123. package/node_modules/pi-lens/dist/clients/path-keyed-map.js +14 -1
  124. package/node_modules/pi-lens/dist/clients/path-utils.js +32 -0
  125. package/node_modules/pi-lens/dist/clients/pipeline.js +0 -8
  126. package/node_modules/pi-lens/dist/clients/process-singletons.js +210 -0
  127. package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +2 -1
  128. package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +10 -4
  129. package/node_modules/pi-lens/dist/clients/project-snapshot.js +33 -11
  130. package/node_modules/pi-lens/dist/clients/read-guard-logger.js +24 -2
  131. package/node_modules/pi-lens/dist/clients/read-guard.js +74 -7
  132. package/node_modules/pi-lens/dist/clients/recent-touches.js +17 -5
  133. package/node_modules/pi-lens/dist/clients/review-graph/builder.js +639 -62
  134. package/node_modules/pi-lens/dist/clients/review-graph/tsconfig-paths.js +5 -1
  135. package/node_modules/pi-lens/dist/clients/review-graph-logger.js +21 -1
  136. package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +68 -0
  137. package/node_modules/pi-lens/dist/clients/runtime-session.js +30 -12
  138. package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +15 -0
  139. package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +106 -7
  140. package/node_modules/pi-lens/dist/clients/runtime-turn.js +242 -27
  141. package/node_modules/pi-lens/dist/clients/safe-spawn.js +158 -18
  142. package/node_modules/pi-lens/dist/clients/security-scan-client.js +48 -17
  143. package/node_modules/pi-lens/dist/clients/session-lifecycle.js +238 -42
  144. package/node_modules/pi-lens/dist/clients/sg-runner.js +27 -15
  145. package/node_modules/pi-lens/dist/clients/shared-checkout-guard.js +338 -0
  146. package/node_modules/pi-lens/dist/clients/spawn-output-cap.js +37 -0
  147. package/node_modules/pi-lens/dist/clients/spawn-timeout-cooldown.js +15 -1
  148. package/node_modules/pi-lens/dist/clients/startup-scan.js +6 -7
  149. package/node_modules/pi-lens/dist/clients/startup-timing.js +69 -4
  150. package/node_modules/pi-lens/dist/clients/string-utils.js +20 -0
  151. package/node_modules/pi-lens/dist/clients/test-runner-client.js +419 -88
  152. package/node_modules/pi-lens/dist/clients/tool-policy.js +1 -1
  153. package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +11 -5
  154. package/node_modules/pi-lens/dist/clients/tree-sitter-logger.js +17 -1
  155. package/node_modules/pi-lens/dist/clients/warm-attach.js +8 -10
  156. package/node_modules/pi-lens/dist/clients/word-index-logger.js +13 -1
  157. package/node_modules/pi-lens/dist/clients/word-index-store.js +448 -0
  158. package/node_modules/pi-lens/dist/clients/word-index.js +582 -104
  159. package/node_modules/pi-lens/dist/clients/workspace-topology.js +17 -0
  160. package/node_modules/pi-lens/dist/clients/zizmor-config.js +26 -6
  161. package/node_modules/pi-lens/dist/index.js +11243 -6651
  162. package/node_modules/pi-lens/dist/mcp/build-staleness.js +8 -7
  163. package/node_modules/pi-lens/dist/mcp/cli.js +3 -1
  164. package/node_modules/pi-lens/dist/mcp/server.js +6 -1
  165. package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +4 -0
  166. package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +14 -5
  167. package/node_modules/pi-lens/dist/tools/lsp-navigation.js +3 -1
  168. package/node_modules/pi-lens/docs/agent-guide.md +4 -2
  169. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +41 -10
  170. package/node_modules/pi-lens/docs/astplayground.md +26 -17
  171. package/node_modules/pi-lens/package.json +5 -1
  172. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/c-no-malloc-free-test.yml +20 -0
  173. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-malloc-free-test.yml +25 -0
  174. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-printf-test.yml +19 -0
  175. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-fmt-println-test.yml +19 -0
  176. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-panic-in-lib-test.yml +17 -0
  177. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-underscore-func-name-test.yml +18 -0
  178. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-errors-is-test.yml +15 -0
  179. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-string-builder-test.yml +21 -0
  180. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/hyphenated-svg-attribute-test.yml +11 -0
  181. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-lateinit-test.yml +17 -0
  182. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-nullable-boolean-test.yml +15 -0
  183. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-println-test.yml +19 -0
  184. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unnecessary-let-test.yml +7 -0
  185. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unsafe-cast-test.yml +7 -0
  186. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-var-test.yml +7 -0
  187. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-data-class-test.yml +25 -0
  188. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-is-empty-test.yml +11 -0
  189. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-important-test.yml +21 -0
  190. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-raw-types-test.yml +30 -0
  191. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-string-concat-in-loop-test.yml +100 -0
  192. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-system-out-println-test.yml +7 -0
  193. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/prefer-string-is-empty-test.yml +7 -0
  194. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/python-optional-type-test.yml +9 -0
  195. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/reducible-list-comprehension-test.yml +11 -0
  196. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ruby-symbol-to-proc-candidate-test.yml +10 -0
  197. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/rust-no-chars-enumerate-test.yml +7 -0
  198. package/node_modules/pi-lens/rules/ast-grep-rules/rules/c-no-malloc-free.yml +39 -0
  199. package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-malloc-free.yml +45 -0
  200. package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-printf.yml +41 -0
  201. package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-fmt-println.yml +43 -0
  202. package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-panic-in-lib.yml +41 -0
  203. package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-underscore-func-name.yml +35 -0
  204. package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-errors-is.yml +40 -0
  205. package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-string-builder.yml +43 -0
  206. package/node_modules/pi-lens/rules/ast-grep-rules/rules/hyphenated-svg-attribute.yml +32 -0
  207. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-lateinit.yml +37 -0
  208. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-nullable-boolean.yml +33 -0
  209. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-println.yml +42 -0
  210. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unnecessary-let.yml +28 -0
  211. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unsafe-cast.yml +28 -0
  212. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-var.yml +35 -0
  213. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-data-class.yml +66 -0
  214. package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-is-empty.yml +35 -0
  215. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-important.yml +21 -0
  216. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-raw-types.yml +33 -0
  217. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-string-concat-in-loop.yml +90 -0
  218. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-system-out-println.yml +16 -0
  219. package/node_modules/pi-lens/rules/ast-grep-rules/rules/prefer-string-is-empty.yml +11 -0
  220. package/node_modules/pi-lens/rules/ast-grep-rules/rules/python-optional-type.yml +22 -0
  221. package/node_modules/pi-lens/rules/ast-grep-rules/rules/reducible-list-comprehension.yml +29 -0
  222. package/node_modules/pi-lens/rules/ast-grep-rules/rules/ruby-symbol-to-proc-candidate.yml +25 -0
  223. package/node_modules/pi-lens/rules/ast-grep-rules/rules/rust-no-chars-enumerate.yml +19 -0
  224. package/node_modules/pi-mcp-adapter/CHANGELOG.md +35 -0
  225. package/node_modules/pi-mcp-adapter/README.md +5 -2
  226. package/node_modules/pi-mcp-adapter/cli.js +4 -4
  227. package/node_modules/pi-mcp-adapter/commands.ts +1 -1
  228. package/node_modules/pi-mcp-adapter/config.ts +1 -0
  229. package/node_modules/pi-mcp-adapter/dist/config.js +1 -0
  230. package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
  231. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +24 -0
  232. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +336 -0
  233. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -0
  234. package/node_modules/pi-mcp-adapter/dist/types.d.ts +3 -1
  235. package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
  236. package/node_modules/pi-mcp-adapter/index.ts +90 -6
  237. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +124 -32
  238. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -2
  239. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +89 -0
  240. package/node_modules/pi-mcp-adapter/mcp-references.ts +9 -1
  241. package/node_modules/pi-mcp-adapter/package.json +1 -1
  242. package/node_modules/pi-mcp-adapter/proxy-modes.ts +62 -22
  243. package/node_modules/pi-mcp-adapter/request-headers-command.ts +1 -1
  244. package/node_modules/pi-mcp-adapter/server-manager.ts +6 -0
  245. package/node_modules/pi-mcp-adapter/types.ts +3 -1
  246. package/node_modules/pi-web-access/CHANGELOG.md +42 -0
  247. package/node_modules/pi-web-access/README.md +26 -10
  248. package/node_modules/pi-web-access/curator-page.ts +12 -3
  249. package/node_modules/pi-web-access/curator-server.ts +3 -1
  250. package/node_modules/pi-web-access/extract.ts +88 -13
  251. package/node_modules/pi-web-access/gemini-search.ts +10 -5
  252. package/node_modules/pi-web-access/github-extract.ts +47 -3
  253. package/node_modules/pi-web-access/index.ts +40 -40
  254. package/node_modules/pi-web-access/package.json +1 -1
  255. package/node_modules/pi-web-access/page-query.ts +61 -8
  256. package/node_modules/pi-web-access/xcrawl.ts +264 -0
  257. package/package.json +19 -22
  258. package/node_modules/@herbertgao/pi-stash/README.md +0 -34
  259. package/node_modules/@herbertgao/pi-stash/package.json +0 -51
  260. package/node_modules/@herbertgao/pi-stash/src/index.ts +0 -118
  261. package/node_modules/@tifan/pi-titlebar-spinner/README.md +0 -24
  262. package/node_modules/@tifan/pi-titlebar-spinner/package.json +0 -39
  263. package/node_modules/@tifan/pi-titlebar-spinner/src/index.ts +0 -49
@@ -17,6 +17,7 @@ import { logExtension } from "../extension-log.js";
17
17
  import * as fs from "node:fs";
18
18
  import * as path from "node:path";
19
19
  import { recordRunner } from "../widget-state.js";
20
+ import { incrementDegradationCount } from "../degradation-ledger.js";
20
21
  import { detectFileKind } from "../file-kinds.js";
21
22
  import { detectFileRole } from "../file-role.js";
22
23
  import { isTestFile } from "../file-utils.js";
@@ -24,19 +25,24 @@ import { getPrimaryDispatchGroup } from "../language-policy.js";
24
25
  import { resolveLanguageRootForFile } from "../language-profile.js";
25
26
  import { logLatency, phaseFinished, phaseStarted } from "../latency-logger.js";
26
27
  import { isSpawnableCommand } from "../installer/index.js";
27
- import { normalizeMapKey } from "../path-utils.js";
28
+ import { normalizeEphemeralMapKey, normalizeMapKey } from "../path-utils.js";
28
29
  import { loadPiLensProjectConfig } from "../project-lens-config.js";
29
30
  import { RUNTIME_CONFIG, getRunnerTimeoutFloorMs } from "../runtime-config.js";
30
31
  import { safeSpawnAsync } from "../safe-spawn.js";
31
32
  import { classifyDiagnostic } from "./diagnostic-taxonomy.js";
32
33
  import { classifyProbeFailure, logAvailabilityDecision, startHostStallSampler, transientRetryDelayMs, } from "./runners/utils/availability-policy.js";
34
+ import { recordAvailabilityProbeOverrun, getDispatchAvailabilityGeneration, } from "./runners/utils/runner-helpers.js";
35
+ import { createAvailabilityProbeFlight } from "../availability-probe-flight.js";
33
36
  import { applyDispositions } from "../diagnostic-dispositions.js";
34
37
  import { applyInlineSuppressions } from "./inline-suppressions.js";
35
38
  import { getToolPlan } from "./plan.js";
36
39
  import { resolveRunnerPath } from "./runner-context.js";
40
+ import { classifyObservedRunner, COLLECT_LATER_THRESHOLD_MS, observeRunnerLatency, } from "./collect-later-tier.js";
41
+ import { deferRunnerFindings } from "./pending-runner-findings.js";
37
42
  import { applyRulePolicy, rulePolicyMapFromConfig } from "./rule-policy.js";
38
43
  import { getToolProfile } from "./tool-profile.js";
39
44
  import { isRunnerSkipReason } from "./types.js";
45
+ const dispatcherProbeFlights = createAvailabilityProbeFlight({ generation: () => getDispatchAvailabilityGeneration() });
40
46
  import { formatDiagnostics } from "./utils/format-utils.js";
41
47
  // --- Runner Registry ---
42
48
  export class RunnerRegistry {
@@ -134,15 +140,19 @@ export async function checkToolAvailability(command, facts) {
134
140
  const startedAt = Date.now();
135
141
  let result;
136
142
  let hostStallMs;
143
+ let probeJoined = false;
137
144
  try {
138
- result = await safeSpawnAsync(command, ["--version"], {
145
+ const shared = dispatcherProbeFlights.run(`dispatcher:${key}`, () => safeSpawnAsync(command, ["--version"], {
139
146
  timeout: TOOL_PROBE_TIMEOUT_MS,
140
- });
147
+ }));
148
+ probeJoined = shared.joined;
149
+ result = await shared.promise;
141
150
  }
142
151
  finally {
143
152
  hostStallMs = sampler.stop();
144
153
  }
145
154
  const elapsedMs = Date.now() - startedAt;
155
+ recordAvailabilityProbeOverrun(command, key, elapsedMs, TOOL_PROBE_TIMEOUT_MS, result.failure);
146
156
  if (result.status === 0) {
147
157
  facts.setSessionFact(key, true);
148
158
  // The tool answered: retire the cooldown facts rather than leaving a
@@ -156,6 +166,7 @@ export async function checkToolAvailability(command, facts) {
156
166
  cause: "ok",
157
167
  elapsedMs,
158
168
  latched: true,
169
+ classifiedBy: probeJoined ? "joined" : "probe",
159
170
  hostStallMs,
160
171
  budgetMs: TOOL_PROBE_TIMEOUT_MS,
161
172
  });
@@ -188,7 +199,7 @@ export async function checkToolAvailability(command, facts) {
188
199
  hostStallMs,
189
200
  ...(retryAfterMs !== undefined && { retryAfterMs }),
190
201
  budgetMs: TOOL_PROBE_TIMEOUT_MS,
191
- classifiedBy: "probe",
202
+ classifiedBy: probeJoined ? "joined" : "probe",
192
203
  evidence,
193
204
  });
194
205
  return false;
@@ -419,13 +430,19 @@ function buildCoverageNotice(ctx, runnerLatencies) {
419
430
  // The marker describes this exact silent-scanner set. A scanner can
420
431
  // recover while another goes dark on the same file, so the set belongs
421
432
  // in the session dedupe identity rather than only kind and path.
433
+ // #2016: these are SCANNER IDS, not filesystem paths. `normalizeMapKey`
434
+ // would realpath each one; on Windows that fails, falls through to
435
+ // `resolveNonExisting`, and resolves the id against the CURRENT process
436
+ // cwd, so the dedupe key differed by platform and by cwd (the #2219
437
+ // non-path-sentinel class). The cheap syntactic fold is what this
438
+ // session-scoped dedupe key actually needs.
422
439
  const silentScannerSet = [...new Set(unconfirmedServerIds)]
423
- .map(normalizeMapKey)
440
+ .map(normalizeEphemeralMapKey)
424
441
  // Code-unit comparator: the sorted set is a dedupe KEY, so ordering
425
442
  // must be deterministic across locales — localeCompare is not.
426
443
  .sort((a, b) => Number(a > b) - Number(a < b))
427
444
  .join(",");
428
- const onceKey = `${ctx.kind}:${normalizeMapKey(ctx.filePath)}:${silentScannerSet}`;
445
+ const onceKey = `${ctx.kind}:${ctx.filePath}:${silentScannerSet}`;
429
446
  if (coverageNoticeSeen.has(onceKey))
430
447
  return undefined;
431
448
  coverageNoticeSeen.add(onceKey);
@@ -467,7 +484,7 @@ function buildCoverageNotice(ctx, runnerLatencies) {
467
484
  (r.status === "succeeded" || r.status === "failed"));
468
485
  if (anyLinterHasCoverage)
469
486
  return undefined;
470
- const onceKey = `${ctx.kind}:${normalizeMapKey(ctx.filePath)}`;
487
+ const onceKey = `${ctx.kind}:${ctx.filePath}`;
471
488
  if (coverageNoticeSeen.has(onceKey))
472
489
  return undefined;
473
490
  coverageNoticeSeen.add(onceKey);
@@ -603,10 +620,123 @@ async function runGroup(ctx, group, registry, onRunnerResult) {
603
620
  });
604
621
  continue;
605
622
  }
623
+ const projectRoot = ctx.projectRoot ?? ctx.cwd;
624
+ // Only post-write dispatches participate. Project scans and direct API
625
+ // callers must retain their existing synchronous semantics.
626
+ const observedTier = ctx.writeIndex === undefined
627
+ ? "inline"
628
+ : classifyObservedRunner(projectRoot, runner.id);
629
+ if (observedTier === "collect-later") {
630
+ const markedAtMs = Date.now();
631
+ const deferred = runRunner(ctx, runner, semantic).then((result) => {
632
+ const durationMs = Date.now() - markedAtMs;
633
+ const tier = observeRunnerLatency({
634
+ projectRoot,
635
+ runnerId: runner.id,
636
+ durationMs,
637
+ timedOut: result.failureKind === "timeout",
638
+ });
639
+ if (tier !== observedTier) {
640
+ logLatency({
641
+ type: "phase",
642
+ filePath: ctx.filePath,
643
+ phase: "runner_collect_later_tier_flip",
644
+ durationMs: 0,
645
+ metadata: {
646
+ runnerId: runner.id,
647
+ from: observedTier,
648
+ to: tier,
649
+ projectRoot,
650
+ },
651
+ });
652
+ }
653
+ if (tier === "collect-later") {
654
+ incrementDegradationCount({
655
+ kind: "runner-collect-later",
656
+ subject: `${projectRoot}:${runner.id}`,
657
+ reason: `observed ${durationMs}ms, threshold ${COLLECT_LATER_THRESHOLD_MS}ms`,
658
+ });
659
+ }
660
+ logLatency({
661
+ type: "runner",
662
+ filePath: ctx.filePath,
663
+ runnerId: runner.id,
664
+ startedAt: new Date(markedAtMs).toISOString(),
665
+ durationMs,
666
+ status: result.status,
667
+ diagnosticCount: result.diagnostics.length,
668
+ semantic: result.semantic ?? semantic,
669
+ metadata: { tier: "collect-later", delivered: "turn_end" },
670
+ });
671
+ return result;
672
+ });
673
+ deferRunnerFindings({
674
+ filePath: ctx.filePath,
675
+ cwd: ctx.cwd,
676
+ projectRoot,
677
+ runnerId: runner.id,
678
+ markedAtMs,
679
+ writeIndex: ctx.writeIndex,
680
+ promise: deferred,
681
+ });
682
+ // A deferred runner is still an observed runner. Keep it visible in
683
+ // both the edit latency report and the widget until its turn-end result
684
+ // replaces this pending state (#2122 F1).
685
+ latencies.push({
686
+ runnerId: runner.id,
687
+ startTime: runnerStart,
688
+ endTime: runnerStart,
689
+ durationMs: 0,
690
+ status: "pending",
691
+ diagnosticCount: 0,
692
+ semantic: semantic,
693
+ });
694
+ recordRunner(ctx.filePath, runner.id, "pending", 0, 0, ctx.writeIndex);
695
+ logLatency({
696
+ type: "runner",
697
+ filePath: ctx.filePath,
698
+ runnerId: runner.id,
699
+ durationMs: 0,
700
+ status: "pending",
701
+ diagnosticCount: 0,
702
+ semantic,
703
+ metadata: { tier: "collect-later", delivered: "turn_end" },
704
+ });
705
+ continue;
706
+ }
606
707
  const result = await runRunner(ctx, runner, semantic);
607
708
  onRunnerResult?.(runnerId, result);
608
709
  const runnerEnd = Date.now();
609
710
  const duration = runnerEnd - runnerStart;
711
+ const tier = ctx.writeIndex === undefined
712
+ ? "inline"
713
+ : observeRunnerLatency({
714
+ projectRoot,
715
+ runnerId: runner.id,
716
+ durationMs: duration,
717
+ timedOut: result.failureKind === "timeout",
718
+ });
719
+ if (tier !== observedTier) {
720
+ logLatency({
721
+ type: "phase",
722
+ filePath: ctx.filePath,
723
+ phase: "runner_collect_later_tier_flip",
724
+ durationMs: 0,
725
+ metadata: {
726
+ runnerId: runner.id,
727
+ from: observedTier,
728
+ to: tier,
729
+ projectRoot,
730
+ },
731
+ });
732
+ }
733
+ if (tier === "collect-later") {
734
+ incrementDegradationCount({
735
+ kind: "runner-collect-later",
736
+ subject: `${projectRoot}:${runner.id}`,
737
+ reason: `observed ${duration}ms, threshold ${COLLECT_LATER_THRESHOLD_MS}ms`,
738
+ });
739
+ }
610
740
  // Runner definitions are a typed API, but embedders/plugins can still
611
741
  // return untyped objects at runtime. Admit only the closed taxonomy and
612
742
  // only on actual skips so free text cannot enter durable latency metadata.
@@ -707,8 +837,13 @@ export async function dispatchForFile(ctx, groups, registry, onRunnerResult) {
707
837
  const groupResults = await Promise.all(groups.map((group) => runGroup(ctx, group, registry, onRunnerResult)));
708
838
  // Count baseline warnings before filtering (for delta count display)
709
839
  const relativeKey = path.relative(ctx.cwd, ctx.filePath).replace(/\\/g, "/");
710
- const baselineAbsKey = `session.baseline.${normalizeMapKey(ctx.filePath)}`;
711
- const baselineRelKey = `session.baseline.${normalizeMapKey(relativeKey)}`;
840
+ const baselineAbsKey = `session.baseline.${ctx.filePath}`;
841
+ // #2016: `relativeKey` is relative to `ctx.cwd`. `normalizeMapKey` resolved
842
+ // it against the process cwd instead, so on Windows this "relative" key
843
+ // became an absolute path anchored on the wrong root while POSIX left it
844
+ // relative. Both the read here and the write below use this const, so the
845
+ // key stays self-consistent within a session.
846
+ const baselineRelKey = `session.baseline.${normalizeEphemeralMapKey(relativeKey)}`;
712
847
  const previousBaseline = ctx.deltaMode
713
848
  ? (ctx.facts.getSessionFact(baselineAbsKey) ??
714
849
  ctx.facts.getSessionFact(baselineRelKey))
@@ -819,6 +954,12 @@ export async function dispatchForFile(ctx, groups, registry, onRunnerResult) {
819
954
  output += formatDiagnostics([coverageNotice], "warning", 1);
820
955
  warnings.push(coverageNotice);
821
956
  }
957
+ const pendingRunners = runnerLatencies
958
+ .filter((runner) => runner.status === "pending")
959
+ .map((runner) => runner.runnerId);
960
+ if (pendingRunners.length > 0) {
961
+ output += `\n⏳ Pending runners (reported at turn end): ${pendingRunners.join(", ")}\n`;
962
+ }
822
963
  // Generate and store latency report
823
964
  const overallEnd = Date.now();
824
965
  const latencyReport = {
@@ -1,20 +1,73 @@
1
1
  import { normalizeMapKey } from "../path-utils.js";
2
+ let capacityEvictionReporter;
3
+ export function setFactStoreEvictionReporter(reporter) {
4
+ capacityEvictionReporter = reporter;
5
+ }
6
+ export function getFactStoreEvictionReporter() {
7
+ return capacityEvictionReporter;
8
+ }
9
+ // #2240: the dispatch store is module-scope in integration.ts, so it lives for
10
+ // the whole process, and a review-graph project walk seeds facts for EVERY file
11
+ // it visits. Nothing removed an entry except the next dispatch of that same
12
+ // path, so a several-hundred-file batch retained one entry per distinct path
13
+ // until the heap ran out. Bound the record count the way widget-state.ts bounds
14
+ // its file records.
15
+ const MAX_FILE_FACT_RECORDS = 1024;
16
+ // Keep enough content for 1024 typical source files averaging 64 KiB, while
17
+ // preventing a small number of generated or vendored files from retaining
18
+ // hundreds of MiB for the process lifetime (#2247).
19
+ const MAX_FILE_FACT_CONTENT_BYTES = 64 * 1024 * 1024;
2
20
  export class FactStore {
21
+ subject;
22
+ // Insertion order is eviction order: the oldest-used record is evicted first.
3
23
  fileFacts = new Map();
4
24
  sessionFacts = new Map();
25
+ // Pin refcount per file. A file is exempt from capacity eviction while its
26
+ // count is > 0. Refcounted, not a Set, so two overlapping dispatches of the
27
+ // same file both hold the pin until BOTH settle (#2243 item 2).
28
+ pinnedFiles = new Map();
29
+ // Running UTF-8 byte total for file.content only. Maintaining it at every
30
+ // mutation keeps getFileFact/setFileFact O(1) amortized; never scan the map
31
+ // to decide whether the byte budget is exceeded.
32
+ retainedContentBytes = 0;
33
+ // Subset of retainedContentBytes held by currently pinned files (#2247
34
+ // review F2). Maintained incrementally the same way — a scan over
35
+ // `pinnedFiles` looks small in isolation, but `evictColdFileFacts` calls it
36
+ // on EVERY unpinned insert for as long as pinned bytes stay over budget, so
37
+ // a scan there would re-walk a large pinned file's full string on every
38
+ // single write admitted during that window. Keeping a running total avoids
39
+ // reintroducing exactly the scan `retainedContentBytes` exists to avoid.
40
+ pinnedContentBytesTotal = 0;
41
+ /**
42
+ * @param subject Discriminates this store's capacity-eviction telemetry
43
+ * from every other production FactStore's (#2243 review round 3, F1).
44
+ * Production callers pass a label naming the store (e.g. `"dispatch"`,
45
+ * `"runtime-session-call-graph"`); the default is only for call sites
46
+ * that never wired a reporter and tests that don't care.
47
+ */
48
+ constructor(subject = "session-fact-store") {
49
+ this.subject = subject;
50
+ }
5
51
  // All file-keyed methods normalize the path internally via normalizeMapKey().
6
52
  // Callers always pass raw/resolved paths — normalization is not their concern.
7
53
  getFileFact(filePath, factId) {
8
- return this.fileFacts.get(normalizeMapKey(filePath))?.get(factId);
54
+ return this.touchFileFacts(normalizeMapKey(filePath))?.get(factId);
9
55
  }
10
56
  setFileFact(filePath, factId, value) {
11
57
  const key = normalizeMapKey(filePath);
12
- let facts = this.fileFacts.get(key);
58
+ let facts = this.touchFileFacts(key);
13
59
  if (!facts) {
14
60
  facts = new Map();
15
61
  this.fileFacts.set(key, facts);
16
62
  }
63
+ if (factId === "file.content") {
64
+ const delta = this.contentBytes(value) - this.contentBytes(facts.get(factId));
65
+ this.retainedContentBytes += delta;
66
+ if (this.pinnedFiles.has(key))
67
+ this.pinnedContentBytesTotal += delta;
68
+ }
17
69
  facts.set(factId, value);
70
+ this.evictColdFileFacts();
18
71
  }
19
72
  hasFileFact(filePath, factId) {
20
73
  return this.fileFacts.get(normalizeMapKey(filePath))?.has(factId) ?? false;
@@ -26,20 +79,186 @@ export class FactStore {
26
79
  const facts = this.fileFacts.get(key);
27
80
  if (!facts)
28
81
  return;
82
+ if (factId === "file.content") {
83
+ const dropped = this.contentBytes(facts.get(factId));
84
+ this.retainedContentBytes -= dropped;
85
+ if (this.pinnedFiles.has(key))
86
+ this.pinnedContentBytesTotal -= dropped;
87
+ }
29
88
  facts.delete(factId);
30
89
  if (facts.size === 0)
31
90
  this.fileFacts.delete(key);
32
91
  }
33
- /** Clear facts for one specific file only. Use at the start of each per-file dispatch call.
92
+ /** Clear facts for one specific file only, and mark the file's dispatch as
93
+ * begun. Use at the start of each per-file dispatch call.
34
94
  * Preserves facts for other files computed in the same turn.
35
- * Normalizes filePath internally — callers pass raw paths. */
95
+ * Normalizes filePath internally — callers pass raw paths.
96
+ * Pins the file against capacity eviction until the matching
97
+ * {@link endDispatchFor} runs in the dispatch's settle path (#2243 item 2).
98
+ * Every `clearFileFactsFor` MUST be paired with an `endDispatchFor`. */
36
99
  clearFileFactsFor(filePath) {
37
- this.fileFacts.delete(normalizeMapKey(filePath));
100
+ const key = normalizeMapKey(filePath);
101
+ this.deleteFileFactsRecord(key);
102
+ this.pinFile(key);
38
103
  }
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();
104
+ /** Pin a file against capacity eviction for the duration of a dispatch,
105
+ * WITHOUT clearing its existing facts. Pairs with {@link endDispatchFor}
106
+ * exactly like {@link clearFileFactsFor} does.
107
+ *
108
+ * #2243 review round 3 (F5): `clearFileFactsFor`'s clear+re-derive is
109
+ * right for a dispatch driven by a fresh edit, but the debounced
110
+ * ast-grep warning scan runs ~2s AFTER the inline dispatch for that same
111
+ * edit already re-derived every fact for this exact file — a second
112
+ * clear there bought nothing but ~51ms of redundant re-parsing across
113
+ * all five providers (measured; a warm-cache read is ~1ms). Use this
114
+ * where the facts are very likely already fresh: `runProviders` still
115
+ * re-derives any fact this file is missing (a genuine miss, e.g. the
116
+ * fact was evicted meanwhile), so a read never depends on staleness. */
117
+ beginDispatchFor(filePath) {
118
+ this.pinFile(normalizeMapKey(filePath));
119
+ }
120
+ /** Release the pin a {@link clearFileFactsFor} or {@link beginDispatchFor}
121
+ * took for one file's dispatch. Call once per matching call, from the
122
+ * dispatch's finally/settle path, so the pin set tracks dispatches
123
+ * actually in flight rather than the last N files touched (#2243 item 2). */
124
+ endDispatchFor(filePath) {
125
+ this.unpinFile(normalizeMapKey(filePath));
126
+ this.evictColdFileFacts();
127
+ }
128
+ /** Clear one file's facts WITHOUT pinning. For sequential single-store scans
129
+ * (project-diagnostics) that own their store and race no concurrent walk:
130
+ * pinning there would exempt every scanned file from the capacity cap and
131
+ * defeat it. Normalizes filePath internally. */
132
+ dropFileFacts(filePath) {
133
+ this.deleteFileFactsRecord(normalizeMapKey(filePath));
134
+ }
135
+ /** LRU touch: re-inserting an existing record moves it to the end of the
136
+ * eviction order, so a record still in use is not the next victim. */
137
+ touchFileFacts(key) {
138
+ const facts = this.fileFacts.get(key);
139
+ if (!facts)
140
+ return undefined;
141
+ this.fileFacts.delete(key);
142
+ this.fileFacts.set(key, facts);
143
+ return facts;
144
+ }
145
+ pinFile(key) {
146
+ const count = this.pinnedFiles.get(key) ?? 0;
147
+ // Transition from unpinned to pinned: this file's content joins the
148
+ // pinned subset. A refcount bump past 1 (an already-pinned file, two
149
+ // overlapping dispatches) does not — it is already counted.
150
+ if (count === 0) {
151
+ this.pinnedContentBytesTotal += this.contentBytes(this.fileFacts.get(key)?.get("file.content"));
152
+ }
153
+ this.pinnedFiles.set(key, count + 1);
154
+ }
155
+ unpinFile(key) {
156
+ const count = this.pinnedFiles.get(key);
157
+ if (count === undefined)
158
+ return;
159
+ if (count <= 1) {
160
+ this.pinnedFiles.delete(key);
161
+ // Transition from pinned to unpinned: this file's content leaves the
162
+ // pinned subset.
163
+ this.pinnedContentBytesTotal -= this.contentBytes(this.fileFacts.get(key)?.get("file.content"));
164
+ }
165
+ else {
166
+ this.pinnedFiles.set(key, count - 1);
167
+ }
168
+ }
169
+ /** Drop least-recently-used records past either cap, skipping the files whose
170
+ * dispatch pinned them. Pinned content counts toward the byte total, but is
171
+ * never evicted before endDispatchFor. Pins survive until clearAll.
172
+ *
173
+ * #2247 review F2: a leaked (or several overlapping) pin(s) can put pinned
174
+ * bytes over budget ON THEIR OWN. Evicting every unpinned record can never
175
+ * bring the total back under budget in that state — before this guard, the
176
+ * loop below evicted each newly inserted unpinned record on the very next
177
+ * call (it was always the sole remaining unpinned key), so unpinned writes
178
+ * never retained anything: a silent, permanent collapse for the rest of
179
+ * the process. Once byte pressure is unpinned-bytes-driven-only, stop
180
+ * evicting and admit unpinned inserts as-is — best-effort under pin
181
+ * pressure — and record the state distinctly so it is visible instead of
182
+ * inferred from "the store stopped retaining anything". */
183
+ evictColdFileFacts() {
184
+ if (!this.overCapacity())
185
+ return;
186
+ for (const key of this.fileFacts.keys()) {
187
+ if (this.pinnedFiles.has(key))
188
+ continue;
189
+ const axis = this.capacityAxis();
190
+ if (axis === "bytes" &&
191
+ this.pinnedContentBytesTotal > MAX_FILE_FACT_CONTENT_BYTES) {
192
+ this.reportPinnedOverBudget();
193
+ return;
194
+ }
195
+ this.deleteFileFactsRecord(key);
196
+ this.reportCapacityEviction(key, axis);
197
+ if (!this.overCapacity())
198
+ return;
199
+ }
200
+ }
201
+ overCapacity() {
202
+ return (this.fileFacts.size > MAX_FILE_FACT_RECORDS ||
203
+ this.retainedContentBytes > MAX_FILE_FACT_CONTENT_BYTES);
204
+ }
205
+ capacityAxis() {
206
+ return this.fileFacts.size > MAX_FILE_FACT_RECORDS ? "count" : "bytes";
207
+ }
208
+ contentBytes(value) {
209
+ return typeof value === "string" ? Buffer.byteLength(value, "utf8") : 0;
210
+ }
211
+ deleteFileFactsRecord(key) {
212
+ const facts = this.fileFacts.get(key);
213
+ if (!facts)
214
+ return;
215
+ const dropped = this.contentBytes(facts.get("file.content"));
216
+ this.retainedContentBytes -= dropped;
217
+ if (this.pinnedFiles.has(key))
218
+ this.pinnedContentBytesTotal -= dropped;
219
+ this.fileFacts.delete(key);
220
+ }
221
+ // #2243 item 4: the cap silently drops a fact a live dispatch may read back
222
+ // as "" (dispatcher.ts reads `file.content` with `?? ""`). Emit through the
223
+ // injected reporter so the drop is visible in the ledger instead of being
224
+ // inferred from a downstream symptom. integration.ts routes this to
225
+ // `recordDegradationOnce` keyed on THIS store's `subject` (#2243 review
226
+ // round 3, F1), so the ledger's own per-kind+subject dedupe yields exactly
227
+ // ONE record per session PER STORE (re-arming at session_start when the
228
+ // ledger resets) — no latch or generation compare here, so fact-store
229
+ // keeps no session-scoped state to forget to re-arm.
230
+ reportCapacityEviction(evictedKey, axis) {
231
+ capacityEvictionReporter?.(this.subject, axis, axis === "count"
232
+ ? `file-fact store axis=count exceeded ${MAX_FILE_FACT_RECORDS} records; evicted least-recently-used fact for ${evictedKey}`
233
+ : `file-fact store axis=bytes exceeded ${MAX_FILE_FACT_CONTENT_BYTES} retained content bytes; evicted least-recently-used fact for ${evictedKey}`);
234
+ }
235
+ // #2247 review F2: pinned bytes alone exceeding budget is not an eviction —
236
+ // nothing is dropped — so it is reported through a distinct axis rather
237
+ // than reusing `reportCapacityEviction`'s "evicted least-recently-used
238
+ // fact for X" language, which would misdescribe what happened.
239
+ reportPinnedOverBudget() {
240
+ const pinnedBytes = this.pinnedContentBytesTotal;
241
+ capacityEvictionReporter?.(this.subject, "pinned-over-budget", `file-fact store pinned content bytes (${pinnedBytes}) exceed the ` +
242
+ `${MAX_FILE_FACT_CONTENT_BYTES}-byte budget; unpinned inserts are ` +
243
+ `admitted without eviction until a pin releases`);
244
+ }
245
+ /** Running UTF-8 byte total for retained `file.content` values. Exposed so
246
+ * tests can crosscheck it against a fresh sum over retained records
247
+ * (#2247 review F3) — the running total is maintained incrementally on
248
+ * every insert/delete path rather than recomputed, so a subtraction
249
+ * dropped from one of those paths would otherwise drift silently. */
250
+ getRetainedContentBytes() {
251
+ return this.retainedContentBytes;
252
+ }
253
+ /** Running UTF-8 byte total for the pinned SUBSET of retained
254
+ * `file.content` values. Exposed so tests can crosscheck it against a
255
+ * fresh sum over `pinnedFiles ∩ fileFacts` (#2247 review F4) — like
256
+ * `retainedContentBytes`, it is maintained incrementally on the pin
257
+ * 0→1 transition, the unpin 1→0 transition, content overwrite/delete,
258
+ * and `clearAll`, so a drop from any one of those paths would
259
+ * otherwise drift silently instead of failing loudly. */
260
+ getPinnedContentBytes() {
261
+ return this.pinnedContentBytesTotal;
43
262
  }
44
263
  getSessionFact(factId) {
45
264
  return this.sessionFacts.get(factId);
@@ -54,5 +273,8 @@ export class FactStore {
54
273
  clearAll() {
55
274
  this.fileFacts.clear();
56
275
  this.sessionFacts.clear();
276
+ this.pinnedFiles.clear();
277
+ this.retainedContentBytes = 0;
278
+ this.pinnedContentBytesTotal = 0;
57
279
  }
58
280
  }