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
@@ -10,11 +10,50 @@
10
10
  * of how late the loop services its own timer, i.e. how long it was blocked —
11
11
  * with **no per-event JS overhead**. `max` ≈ the worst synchronous block since
12
12
  * the last reset.
13
+ *
14
+ * ## System-stall contamination (#1122 / #1123)
15
+ *
16
+ * `monitorEventLoopDelay` measures timer lag with the monotonic clock
17
+ * (`uv_hrtime`, backed by `QueryPerformanceCounter` on Windows). When the whole
18
+ * process is frozen or descheduled — machine sleep / Modern Standby, or paging
19
+ * thrash under commit-charge exhaustion — its next timer fires late by the
20
+ * *entire* wall-clock gap, and the histogram records that gap as a "block".
21
+ * Two distinct system stalls were confirmed against the Windows System event
22
+ * log: (1) a 290,179 ms block that lined up exactly with a 14:33:05Z→14:37:55Z
23
+ * Modern Standby window (Kernel-Power 506/507), reported byte-identical by two
24
+ * independent pids because the HDR histogram quantizes ~290 s into one bucket;
25
+ * (2) a later silent host exit with zero sleep events but twelve
26
+ * Resource-Exhaustion-Detector (id 2004) events at 97% commit charge — the
27
+ * process was paging, not sleeping. Both are machine artifacts, not pi-lens
28
+ * work; latency.log also held multi-*hour* "blocks" that can only be overnight
29
+ * sleep.
30
+ *
31
+ * Comparing a wall clock to a monotonic clock does NOT catch these: on Windows
32
+ * both advance across Modern Standby (the histogram's monotonic delta already
33
+ * equalled the wall gap). The reliable discriminator is **CPU consumption**: a
34
+ * genuine synchronous block of D ms burns ≈ D ms of main-thread CPU, so the
35
+ * window that contains it must have consumed at least ~D ms of CPU. A frozen or
36
+ * thrashing process consumes ~0 CPU across the gap, so when the worst block
37
+ * exceeds all the CPU the window could account for, it was a stall, not work.
38
+ * We window per turn (so the CPU accounting is bounded and each block is
39
+ * attributable to its turn) and tag system-stall-suspected samples instead of
40
+ * letting them poison the "worst real block" high-water.
13
41
  */
42
+ import { logExtension } from "./extension-log.js";
14
43
  import { monitorEventLoopDelay } from "node:perf_hooks";
15
44
  const NS_PER_MS = 1e6;
45
+ const US_PER_MS = 1e3;
16
46
  let histogram;
17
47
  let monitorUnavailable = false;
48
+ // Per-window (per-turn) baselines for CPU-vs-wall accounting. Captured when the
49
+ // monitor starts and re-captured on every reset, so each window's CPU budget is
50
+ // measured against exactly the histogram window it will be compared to.
51
+ let windowStartWallMs = 0;
52
+ let windowStartCpuMs = 0;
53
+ const cpuTotalMs = () => {
54
+ const c = process.cpuUsage();
55
+ return (c.user + c.system) / US_PER_MS;
56
+ };
18
57
  /**
19
58
  * Start the monitor (idempotent). Call once, as early as possible, so startup
20
59
  * blocks are captured. Cheap — the sampling is native; nothing runs per event.
@@ -32,26 +71,76 @@ export function startEventLoopMonitor(resolutionMs = 20) {
32
71
  const h = monitorEventLoopDelay({ resolution: resolutionMs });
33
72
  h.enable();
34
73
  histogram = h;
74
+ windowStartWallMs = Date.now();
75
+ windowStartCpuMs = cpuTotalMs();
35
76
  }
36
77
  catch (err) {
37
78
  monitorUnavailable = true;
38
- console.error(`[pi-lens] event-loop occupancy telemetry disabled (runtime lacks monitorEventLoopDelay): ${err?.message ?? String(err)}`);
79
+ logExtension({
80
+ subsystem: "event-loop-monitor",
81
+ message: `event-loop occupancy telemetry disabled (runtime lacks monitorEventLoopDelay): ${err?.message ?? String(err)}`,
82
+ });
39
83
  }
40
84
  }
41
85
  const safeMs = (ns) => Number.isFinite(ns) ? Math.round((ns / NS_PER_MS) * 10) / 10 : 0;
86
+ /**
87
+ * Classify a worst-block sample as genuine CPU work or a suspend/freeze
88
+ * artifact. Pure so the discrimination is testable without the (vitest-flaky)
89
+ * native histogram or a real machine sleep.
90
+ *
91
+ * A block is system-stall-suspected only when it is both (a) larger than any
92
+ * plausible synchronous pi-lens stall (`floorMs`, default 20 s — the real tier
93
+ * observed in latency.log tops out ~15 s) and (b) unaccounted for by the
94
+ * window's CPU budget (`windowCpuMs + slopMs < maxMs`). The floor keeps a real
95
+ * multi-second I/O-bound block (low CPU, but genuine) from being mislabeled,
96
+ * while a frozen or paging process — ~0 CPU across a minutes-to-hours gap —
97
+ * always trips. Sub-floor blocks are never auto-tagged, but the logged
98
+ * `windowCpuMs`/`windowWallMs` still expose the CPU-vs-wall ratio so a reviewer
99
+ * can spot a shorter paging stall by hand.
100
+ *
101
+ * KNOWN AMBIGUITY (honest, not fully resolvable from CPU alone): a genuine
102
+ * pi-lens block that is BLOCKED IN A SYSCALL for >20 s — e.g. a `readdirSync` /
103
+ * `statSync` stalled on a OneDrive/cloud-backed path fetching a dehydrated file,
104
+ * or an antivirus-throttled read — also consumes ~0 CPU while wall time
105
+ * advances, so it is CPU-indistinguishable from a suspend and WILL be tagged
106
+ * `suspectSystemStall` and excluded from the health high-waters. That is the
107
+ * conservative choice (a >20 s synchronous FS stall is itself a P0-worthy bug we
108
+ * do NOT want silently counted as normal), and it is not silenced: such a sample
109
+ * still re-logs every turn with its `lastPhase` attribution, which is the
110
+ * forensic breadcrumb for exactly this class. Sharper corroboration (a magnitude
111
+ * ceiling, a `maxMs`-vs-`windowWallMs` ratio) is tracked as a follow-up note on
112
+ * #1123, not decided here.
113
+ */
114
+ export function isSuspendSuspectedBlock(maxMs, windowCpuMs, floorMs = 20000, slopMs = 1000) {
115
+ if (maxMs < floorMs)
116
+ return false;
117
+ return windowCpuMs + slopMs < maxMs;
118
+ }
42
119
  /** Current occupancy stats, or undefined if the monitor was never started. */
43
120
  export function getEventLoopStats() {
44
121
  if (!histogram)
45
122
  return undefined;
123
+ const maxMs = safeMs(histogram.max);
124
+ const windowWallMs = Math.max(0, Date.now() - windowStartWallMs);
125
+ const windowCpuMs = Math.max(0, cpuTotalMs() - windowStartCpuMs);
46
126
  return {
47
- maxMs: safeMs(histogram.max),
127
+ maxMs,
48
128
  p99Ms: safeMs(histogram.percentile(99)),
49
129
  meanMs: safeMs(histogram.mean),
130
+ windowWallMs: Math.round(windowWallMs),
131
+ windowCpuMs: Math.round(windowCpuMs),
132
+ suspectSystemStall: isSuspendSuspectedBlock(maxMs, windowCpuMs),
50
133
  };
51
134
  }
52
- /** Reset the histogram — e.g. at session/turn boundaries for per-window stats. */
135
+ /**
136
+ * Reset the histogram and re-baseline the CPU/wall window — called at turn
137
+ * boundaries so each window's worst block is attributable to that turn and its
138
+ * CPU budget is measured over the same span (#192 intent, wired in #1122).
139
+ */
53
140
  export function resetEventLoopMonitor() {
54
141
  histogram?.reset();
142
+ windowStartWallMs = Date.now();
143
+ windowStartCpuMs = cpuTotalMs();
55
144
  }
56
145
  /**
57
146
  * Decide whether a freeze is worth persisting to `latency.log`. Pure so the
@@ -68,4 +157,6 @@ export function _stopEventLoopMonitorForTest() {
68
157
  histogram?.disable();
69
158
  histogram = undefined;
70
159
  monitorUnavailable = false;
160
+ windowStartWallMs = 0;
161
+ windowStartCpuMs = 0;
71
162
  }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Terminal-safe diagnostic sink for the in-pi extension path (#1333).
3
+ *
4
+ * pi owns the terminal: it runs the TTY in raw mode and repaints with
5
+ * cursor-addressed diffs, so ANY byte an extension writes to stdout/stderr
6
+ * lands mid-frame and desyncs pi's model of the screen — the layout stays
7
+ * broken until a full repaint. `clients/`, `tools/`, `index.ts` and `i18n.ts`
8
+ * are all reachable from the extension entry, so none of them may call
9
+ * `console.*` or `process.std*.write`. (`mcp/`, `scripts/` and `bin/` DO own
10
+ * their stdout contract and keep their writes.)
11
+ *
12
+ * This module is the general-purpose replacement sink: one `createNdjsonLogger`
13
+ * instance over `<global pi-lens dir>/extension.log`, per the single-writer
14
+ * invariant in AGENTS.md. Subsystems that already own a log (tree-sitter,
15
+ * review-graph, cascade, latency, sessionstart) route to THAT log instead —
16
+ * this file is for the areas that had no sink at all.
17
+ *
18
+ * Three-channels rule (#482/#484/#485): everything written here is
19
+ * LOG-audience. A genuinely user-facing degradation must ALSO reach the human
20
+ * through the host's own render path (`ctx.ui.notify` / a display-only session
21
+ * entry) — never a raw write.
22
+ */
23
+ import * as path from "node:path";
24
+ import { isTestMode } from "./env-utils.js";
25
+ import { getGlobalPiLensDir } from "./file-utils.js";
26
+ import { getMaxLogSizeMB } from "./log-cleanup.js";
27
+ import { createNdjsonLogger } from "./ndjson-logger.js";
28
+ export const EXTENSION_LOG_FILE = path.join(getGlobalPiLensDir(), "extension.log");
29
+ const writer = createNdjsonLogger({
30
+ filePath: EXTENSION_LOG_FILE,
31
+ maxBytes: getMaxLogSizeMB() * 1024 * 1024,
32
+ });
33
+ export function logExtension(entry) {
34
+ if (isTestMode())
35
+ return;
36
+ writer.log({
37
+ ts: new Date().toISOString(),
38
+ pid: process.pid,
39
+ level: entry.level ?? "error",
40
+ subsystem: entry.subsystem,
41
+ message: entry.message,
42
+ ...(entry.metadata ? { metadata: entry.metadata } : {}),
43
+ });
44
+ }
45
+ export function createSubsystemLogger(subsystem, defaultLevel = "debug") {
46
+ const at = (level) => (message, metadata) => {
47
+ logExtension({ subsystem, message, level, metadata });
48
+ };
49
+ const logger = at(defaultLevel);
50
+ logger.error = at("error");
51
+ logger.warn = at("warn");
52
+ logger.debug = at("debug");
53
+ return logger;
54
+ }
55
+ /** No-op with the `SubsystemLogger` shape, for the verbose-off branch. */
56
+ export function noopSubsystemLogger() {
57
+ const noop = (() => { });
58
+ noop.error = () => { };
59
+ noop.warn = () => { };
60
+ noop.debug = () => { };
61
+ return noop;
62
+ }
63
+ export function getExtensionLogPath() {
64
+ return EXTENSION_LOG_FILE;
65
+ }
66
+ /** Resolve once all enqueued extension-log writes are on disk (tests/shutdown). */
67
+ export function flushExtensionLog() {
68
+ return writer.flush();
69
+ }
70
+ /** Teardown-only: force queued entries to disk before the process exits. */
71
+ export function flushExtensionLogSync() {
72
+ writer.flushSync();
73
+ }
74
+ // --- Defense in depth: the console reroute -----------------------------------
75
+ const CONSOLE_METHODS = [
76
+ "log",
77
+ "info",
78
+ "warn",
79
+ "error",
80
+ "debug",
81
+ "trace",
82
+ "dir",
83
+ ];
84
+ let consoleGuardInstalled = false;
85
+ function formatConsoleArgs(args) {
86
+ return args
87
+ .map((arg) => {
88
+ if (typeof arg === "string")
89
+ return arg;
90
+ if (arg instanceof Error)
91
+ return arg.stack ?? arg.message;
92
+ try {
93
+ return JSON.stringify(arg) ?? String(arg);
94
+ }
95
+ catch {
96
+ return String(arg);
97
+ }
98
+ })
99
+ .join(" ");
100
+ }
101
+ /**
102
+ * Patch every console method on the extension entry path so a transitively
103
+ * loaded dependency cannot write raw bytes into pi's frame — the pi-side
104
+ * mirror of `mcp/server.ts`'s `console.log = console.error` guard, which
105
+ * protects the JSON-RPC stdout channel for the same structural reason.
106
+ *
107
+ * This is a NET, not the fix: pi-lens's own sites are migrated to real sinks
108
+ * with real schemas. Idempotent, and inert under test mode (vitest owns the
109
+ * console) and under `PI_LENS_CONSOLE_GUARD=0`.
110
+ *
111
+ * Returns true when the patch was applied by this call.
112
+ */
113
+ export function installConsoleGuard() {
114
+ if (consoleGuardInstalled)
115
+ return false;
116
+ if (isTestMode())
117
+ return false;
118
+ if (process.env.PI_LENS_CONSOLE_GUARD === "0")
119
+ return false;
120
+ consoleGuardInstalled = true;
121
+ const target = console;
122
+ for (const method of CONSOLE_METHODS) {
123
+ if (typeof target[method] !== "function")
124
+ continue;
125
+ target[method] = (...args) => {
126
+ logExtension({
127
+ subsystem: "console",
128
+ level: method === "warn" ? "warn" : method === "error" ? "error" : "debug",
129
+ message: formatConsoleArgs(args),
130
+ metadata: { method },
131
+ });
132
+ };
133
+ }
134
+ return true;
135
+ }
136
+ /** Test-only: forget that the guard was installed. */
137
+ export function _resetConsoleGuardForTests() {
138
+ consoleGuardInstalled = false;
139
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Host run-mode awareness (#1334 S2).
3
+ *
4
+ * pi tells every extension which mode it is running in — verified against the
5
+ * pinned host types (`@earendil-works/pi-coding-agent/dist/core/extensions/
6
+ * types.d.ts`):
7
+ *
8
+ * export type ExtensionMode = "tui" | "rpc" | "json" | "print"; // line 208
9
+ * interface ExtensionContext { mode: ExtensionMode; hasUI: boolean; … }
10
+ * // lines 212-215
11
+ *
12
+ * The host's own comment on `mode` is the contract this module encodes:
13
+ * *"Use `"tui"` to guard terminal-only UI such as custom components."*
14
+ *
15
+ * pi-lens previously derived terminal ownership from nothing at all — it
16
+ * mounted its widget and chattered through `ui.notify` in every mode, including
17
+ * `print` and `json`, where the process is a one-shot producing machine- or
18
+ * pipe-consumed output and there is no live TUI to render into.
19
+ *
20
+ * Two independent questions, deliberately NOT the same predicate:
21
+ *
22
+ * - *Is there a TUI to mount a custom component into?* Only `"tui"`. `rpc`
23
+ * has `hasUI: true` (dialogs work over the protocol) but no terminal
24
+ * component surface, so the widget must not mount there either.
25
+ * - *Should proactive chatter reach the human?* No in `print` and `json` —
26
+ * one-shot/machine output. Yes in `tui` and `rpc`.
27
+ *
28
+ * This is complementary to, and independent of, the #1338/#1333 console guard:
29
+ * that establishes "never write raw to the terminal"; this decides whether the
30
+ * HOST's own render path should be used at all in a given mode.
31
+ *
32
+ * Stateless by design: `mode` lives on the ctx pi hands to every event and
33
+ * command handler, so each call site reads it from the ctx it already has —
34
+ * no latched global to go stale across a session replacement.
35
+ */
36
+ const KNOWN_MODES = new Set(["tui", "rpc", "json", "print"]);
37
+ /**
38
+ * Feature-detected read of `ctx.mode`.
39
+ *
40
+ * Returns `"unknown"` for a host that predates the field, or for any value
41
+ * outside the four documented modes (a future pi may add one; treating an
42
+ * unrecognized mode as "unknown" keeps current behavior rather than guessing
43
+ * a suppression that could hide output).
44
+ */
45
+ export function readExtensionMode(ctx) {
46
+ try {
47
+ const mode = ctx?.mode;
48
+ if (typeof mode !== "string" || !KNOWN_MODES.has(mode))
49
+ return "unknown";
50
+ return mode;
51
+ }
52
+ catch {
53
+ return "unknown";
54
+ }
55
+ }
56
+ /**
57
+ * Whether a terminal-only custom component (the pi-lens diagnostics widget) can
58
+ * be mounted. `"unknown"` mounts — older hosts must behave exactly as before.
59
+ */
60
+ export function supportsTuiWidget(mode) {
61
+ return mode === "tui" || mode === "unknown";
62
+ }
63
+ /**
64
+ * Whether proactive `ui.notify` chatter should be suppressed (logged only).
65
+ * True only for the two non-interactive one-shot modes.
66
+ */
67
+ export function suppressesUserNotify(mode) {
68
+ return mode === "print" || mode === "json";
69
+ }
70
+ /** Short human-readable reason for a suppression, for the ndjson/debug log. */
71
+ export function modeSuppressionNote(mode) {
72
+ return `suppressed in "${mode}" mode (no interactive TUI)`;
73
+ }
@@ -1,5 +1,22 @@
1
1
  function normalizeHintInput(value) {
2
- return value.replace(/\\/g, "/").toLowerCase();
2
+ return value.replace(/\\/g, "/");
3
+ }
4
+ function hasHintToken(value, tokens) {
5
+ const escaped = tokens.map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
6
+ const alternatives = escaped.join("|");
7
+ // Path/word boundaries are deliberately explicit: a token must occupy a
8
+ // segment (or a dot/dash/underscore-separated word), never an arbitrary
9
+ // substring. The second expression preserves camelCase names such as
10
+ // authStore and DatabaseClient without making `adb` match `db`.
11
+ return (new RegExp(`(?:^|[/_.\\-\\s])(?:${alternatives})(?=[/_.\\-\\s]|$)`, "i").test(value) ||
12
+ new RegExp(`(?:^|(?<=[a-z0-9]))(?:${tokens
13
+ .flatMap((token) => [
14
+ token[0].toUpperCase() + token.slice(1),
15
+ ...(token === "openai" ? ["OpenAI"] : []),
16
+ ...(token === "github" ? ["GitHub"] : []),
17
+ ...(token === "gitlab" ? ["GitLab"] : []),
18
+ ])
19
+ .join("|")})(?=[A-Z]|[/_.\\-\\s]|$)`).test(value));
3
20
  }
4
21
  /**
5
22
  * Deterministic feature-kind hint derived from package/entity/file names.
@@ -7,10 +24,19 @@ function normalizeHintInput(value) {
7
24
  */
8
25
  export function inferFeatureKind(nameOrPath) {
9
26
  const normalized = normalizeHintInput(nameOrPath);
10
- if (/config|store|db|database|github|openai|sync|service/.test(normalized)) {
27
+ if (hasHintToken(normalized, [
28
+ "config",
29
+ "store",
30
+ "db",
31
+ "database",
32
+ "github",
33
+ "openai",
34
+ "sync",
35
+ "service",
36
+ ])) {
11
37
  return "service";
12
38
  }
13
- if (/(^|[/_.\-\s])(cli|command|bin)([/_.\-\s]|$)/.test(normalized)) {
39
+ if (/(^|[/_.\-\s])(cli|command|bin)([/_.\-\s]|$)/i.test(normalized)) {
14
40
  return "cli-command";
15
41
  }
16
42
  return "library";
@@ -22,20 +48,40 @@ export function inferFeatureKind(nameOrPath) {
22
48
  export function inferTrustBoundaries(nameOrPath) {
23
49
  const normalized = normalizeHintInput(nameOrPath);
24
50
  const boundaries = new Set();
25
- if (/config|store|db|database|repo|repository|model|migration/.test(normalized)) {
51
+ if (hasHintToken(normalized, [
52
+ "config",
53
+ "store",
54
+ "db",
55
+ "database",
56
+ "repo",
57
+ "repository",
58
+ "model",
59
+ "migration",
60
+ ])) {
26
61
  boundaries.add("filesystem");
27
62
  boundaries.add("database");
28
63
  }
29
- if (/github|gitlab|openai|anthropic|stripe|slack|sync|webhook|api|client/.test(normalized)) {
64
+ if (hasHintToken(normalized, [
65
+ "github",
66
+ "gitlab",
67
+ "openai",
68
+ "anthropic",
69
+ "stripe",
70
+ "slack",
71
+ "sync",
72
+ "webhook",
73
+ "api",
74
+ "client",
75
+ ])) {
30
76
  boundaries.add("network");
31
77
  boundaries.add("external-api");
32
78
  boundaries.add("serialization");
33
79
  }
34
- if (/(^|[/_.\-\s])(cli|command|bin|exec|spawn|process|shell)([/_.\-\s]|$)/.test(normalized)) {
80
+ if (/(^|[/_.\-\s])(cli|command|bin|exec|spawn|process|shell)([/_.\-\s]|$)/i.test(normalized)) {
35
81
  boundaries.add("user-input");
36
82
  boundaries.add("process-exec");
37
83
  }
38
- if (/auth|login|token|session|oauth|jwt/.test(normalized)) {
84
+ if (hasHintToken(normalized, ["auth", "login", "token", "session", "oauth", "jwt"])) {
39
85
  boundaries.add("auth");
40
86
  boundaries.add("user-input");
41
87
  }
@@ -88,6 +88,9 @@ export const KIND_EXTENSIONS = {
88
88
  ".hs",
89
89
  ".lhs",
90
90
  ],
91
+ "helm-template": [
92
+ ".tpl",
93
+ ],
91
94
  html: [
92
95
  ".htm",
93
96
  ".html",
@@ -169,6 +172,7 @@ export const KIND_EXTENSIONS = {
169
172
  ".tf",
170
173
  ".tfvars",
171
174
  ],
175
+ terragrunt: [],
172
176
  toml: [
173
177
  ".toml",
174
178
  ],
@@ -181,6 +185,68 @@ export const KIND_EXTENSIONS = {
181
185
  ".zon",
182
186
  ],
183
187
  };
188
+ /** Return whether a path has an extension registered for the given file kind. */
189
+ export function hasKindExtension(filePath, kind) {
190
+ const extension = extname(filePath).toLowerCase();
191
+ return KIND_EXTENSIONS[kind].some((candidate) => candidate === extension);
192
+ }
193
+ // Fact providers intentionally stay on the ordinary JS/TS source extensions.
194
+ // Vue/Svelte files are classified as jsts for project-wide discovery, but their
195
+ // embedded-language contents are not valid inputs for these tree-sitter facts.
196
+ // Keep that one policy decision here so the function and import providers agree.
197
+ const JSTS_FACT_EXTENSIONS = new Set(KIND_EXTENSIONS.jsts.filter((extension) => ![".vue", ".svelte"].includes(extension)));
198
+ /** Whether the JS/TS fact providers should parse this path. */
199
+ export function isJstsFactFile(filePath) {
200
+ return JSTS_FACT_EXTENSIONS.has(extname(filePath).toLowerCase());
201
+ }
202
+ // Bash access tracking also accepts common text/config files which do not have
203
+ // a semantic FileKind. Every source extension is derived from KIND_EXTENSIONS;
204
+ // only this explicit legacy text/config allowlist lives outside that registry.
205
+ const NON_KIND_READABLE_EXTENSIONS = new Set([
206
+ ".txt",
207
+ ".env",
208
+ ".cfg",
209
+ ".conf",
210
+ ".ini",
211
+ ".xml",
212
+ ]);
213
+ /** Whether bash file-access parsing should treat a path as source-like. */
214
+ export function isReadableSourceFile(filePath) {
215
+ const extension = extname(filePath).toLowerCase();
216
+ return (Object.keys(KIND_EXTENSIONS).some((kind) => hasKindExtension(filePath, kind)) || NON_KIND_READABLE_EXTENSIONS.has(extension));
217
+ }
218
+ // --- Shared Project Root Markers ---
219
+ /**
220
+ * .NET project/solution root-marker globs (refs #895). Single source of truth
221
+ * consumed by BOTH root-resolution subsystems — language-profile.ts
222
+ * (PROJECT_MARKERS_BY_KIND / ROOT_MARKERS_BY_KIND) and lsp/server.ts
223
+ * (CSharpServer / OmniSharpServer / FSharpServer root detectors) — following
224
+ * the KIND_EXTENSIONS pattern: never hand-copy these lists at a call site.
225
+ * tests/clients/dotnet-root-markers.test.ts asserts both subsystems recognize
226
+ * every marker here, so a call site drifting from this list fails CI.
227
+ */
228
+ export const DOTNET_CSHARP_ROOT_MARKERS = [
229
+ "*.csproj",
230
+ "*.sln",
231
+ "*.slnx",
232
+ ];
233
+ export const DOTNET_FSHARP_ROOT_MARKERS = [
234
+ "*.fsproj",
235
+ "*.sln",
236
+ ];
237
+ /**
238
+ * Terragrunt's unit/root entrypoint filenames, lowercase. Single source of truth
239
+ * for every subsystem that has to agree on what counts as a terragrunt file —
240
+ * SPECIAL_FILENAMES below, tool-policy.ts's linter and formatter policies,
241
+ * formatters.ts's terragruntHclFormatter, and language-profile.ts's project/root
242
+ * markers. Same rule as the .NET markers above: never hand-copy this list at a
243
+ * call site. tests/clients/terragrunt-filenames.test.ts asserts every consumer
244
+ * honors every name here, so a drifting call site fails CI.
245
+ */
246
+ export const TERRAGRUNT_FILENAMES = [
247
+ "terragrunt.hcl",
248
+ "root.hcl",
249
+ ];
184
250
  // Reverse map: extension → file kind (for fast lookup)
185
251
  const EXT_TO_KIND = new Map();
186
252
  for (const [kind, exts] of Object.entries(KIND_EXTENSIONS)) {
@@ -199,6 +265,10 @@ const SPECIAL_FILENAMES = [
199
265
  { pattern: /^CMakeLists\.txt$/i, kind: "cmake" },
200
266
  { pattern: /^Makefile$/i, kind: "shell" },
201
267
  { pattern: /^Dockerfile(\.\w+)?$/i, kind: "docker" },
268
+ ...TERRAGRUNT_FILENAMES.map((name) => ({
269
+ pattern: new RegExp(`^${name.replaceAll(".", "\\.")}$`, "i"),
270
+ kind: "terragrunt",
271
+ })),
202
272
  ];
203
273
  // --- Detection Functions ---
204
274
  /**
@@ -248,45 +318,83 @@ export function getFileKindsForExtension(ext) {
248
318
  const kind = EXT_TO_KIND.get(normalizedExt.toLowerCase());
249
319
  return kind ? [kind] : [];
250
320
  }
321
+ // --- Code vs non-code kind classification (#894 review) ---------------------
322
+ //
323
+ // Broadened enumeration made data/doc/markup kinds (json/yaml/markdown/…)
324
+ // visible to every project-wide walk. Those kinds must not outrank real
325
+ // program source wherever a capped budget or a "dominant language" ranking is
326
+ // involved: a TS repo with more .json/.yml than .ts files must still warm
327
+ // tsserver first (#203), and 2000 locale/fixture JSON files ahead of the code
328
+ // dirs must not exhaust a walk's file budget before any source file is seen.
329
+ // This partition is the single authority for that distinction — every FileKind
330
+ // MUST appear in exactly one of the two sets
331
+ // (tests/clients/scannable-extension-coverage.test.ts enforces it, so a newly
332
+ // registered kind cannot be silently unclassified).
333
+ /** Kinds that are hand-written program source — prioritized in capped walks
334
+ * and in the dominant-language LSP warm ranking. */
335
+ export const CODE_KINDS = new Set([
336
+ "clojure",
337
+ "cmake",
338
+ "csharp",
339
+ "cxx",
340
+ "dart",
341
+ "docker",
342
+ "elixir",
343
+ "fish",
344
+ "fsharp",
345
+ "gleam",
346
+ "go",
347
+ "haskell",
348
+ "helm-template",
349
+ "java",
350
+ "jsts",
351
+ "kotlin",
352
+ "lua",
353
+ "nix",
354
+ "ocaml",
355
+ "php",
356
+ "powershell",
357
+ "prisma",
358
+ "python",
359
+ "ruby",
360
+ "rust",
361
+ "shell",
362
+ "sql",
363
+ "swift",
364
+ "terraform",
365
+ "terragrunt",
366
+ "zig",
367
+ ]);
368
+ /** Data/doc/markup/config kinds — still enumerated (that's #894's point), but
369
+ * deprioritized against {@link CODE_KINDS} in budgeted walks and rankings. */
370
+ export const NON_CODE_KINDS = new Set([
371
+ "css",
372
+ "html",
373
+ "json",
374
+ "markdown",
375
+ "toml",
376
+ "yaml",
377
+ ]);
251
378
  /**
252
379
  * Check if a file kind represents a code file (not config/markdown).
253
380
  */
254
381
  export function isCodeKind(kind) {
255
- return [
256
- "jsts",
257
- "python",
258
- "go",
259
- "rust",
260
- "cxx",
261
- "fish",
262
- "shell",
263
- "ruby",
264
- "html",
265
- "php",
266
- "powershell",
267
- "prisma",
268
- "csharp",
269
- "fsharp",
270
- "java",
271
- "kotlin",
272
- "swift",
273
- "dart",
274
- "lua",
275
- "zig",
276
- "haskell",
277
- "elixir",
278
- "gleam",
279
- "ocaml",
280
- "clojure",
281
- "terraform",
282
- "nix",
283
- ].includes(kind);
382
+ return CODE_KINDS.has(kind);
284
383
  }
285
384
  /**
286
- * Check if a file kind represents a text/config file.
385
+ * Check if a file kind represents a text/config/doc/markup file.
287
386
  */
288
387
  export function isConfigKind(kind) {
289
- return ["json", "yaml", "markdown", "css", "sql", "docker", "cmake", "toml"].includes(kind);
388
+ return NON_CODE_KINDS.has(kind);
389
+ }
390
+ /**
391
+ * Check if a file path resolves to a {@link CODE_KINDS} kind. Undetectable
392
+ * files (unknown extension, e.g. `.coffee` from SOURCE_PRECEDENCE) are
393
+ * non-code.
394
+ */
395
+ export function isCodeKindFile(filePath) {
396
+ const kind = detectFileKind(filePath);
397
+ return kind !== undefined && CODE_KINDS.has(kind);
290
398
  }
291
399
  /**
292
400
  * Get human-readable description of a file kind.
@@ -321,11 +429,13 @@ export function getFileKindLabel(kind) {
321
429
  lua: "Lua",
322
430
  zig: "Zig",
323
431
  haskell: "Haskell",
432
+ "helm-template": "Helm template",
324
433
  elixir: "Elixir",
325
434
  gleam: "Gleam",
326
435
  ocaml: "OCaml",
327
436
  clojure: "Clojure",
328
437
  terraform: "Terraform",
438
+ terragrunt: "Terragrunt",
329
439
  nix: "Nix",
330
440
  toml: "TOML",
331
441
  };
@@ -389,11 +499,13 @@ export function getLanguageId(kind) {
389
499
  lua: "lua",
390
500
  zig: "zig",
391
501
  haskell: "haskell",
502
+ "helm-template": "helm",
392
503
  elixir: "elixir",
393
504
  gleam: "gleam",
394
505
  ocaml: "ocaml",
395
506
  clojure: "clojure",
396
507
  terraform: "terraform",
508
+ terragrunt: "terragrunt",
397
509
  nix: "nix",
398
510
  toml: "toml",
399
511
  };