pi-lens 4.4.4 → 4.4.6

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 (191) hide show
  1. package/CHANGELOG.md +477 -0
  2. package/README.md +45 -3
  3. package/config/biome/core.jsonc +3 -3
  4. package/config/dependency-cruiser-eager-allowlist.json +1 -0
  5. package/dist/{chunk-UBOQLVT2.js → chunk-2DDDCJDL.js} +4 -4
  6. package/dist/{chunk-RKKOYPRA.js → chunk-2DMLM3ZO.js} +13 -15
  7. package/dist/chunk-2F47TQOA.js +73 -0
  8. package/dist/{chunk-O4NWQT6I.js → chunk-2PHMIAKO.js} +4 -4
  9. package/dist/{chunk-DGUKIYSI.js → chunk-2RLWJO5K.js} +8 -10
  10. package/dist/{chunk-S67KYG37.js → chunk-2X4VLOCC.js} +2 -2
  11. package/dist/{chunk-TIQ2PKDW.js → chunk-3MYEA7QD.js} +4 -4
  12. package/dist/{chunk-3DA2JDOL.js → chunk-3WEPUD2V.js} +551 -203
  13. package/dist/{chunk-AMERCH6V.js → chunk-4AVZ3TG7.js} +15 -16
  14. package/dist/{chunk-IYNJ6YPZ.js → chunk-4PCQCU47.js} +4 -4
  15. package/dist/chunk-4WX4CTUE.js +57 -0
  16. package/dist/{chunk-P63GXC37.js → chunk-5APMQ2IJ.js} +31 -4
  17. package/dist/{chunk-ZIVJBOO3.js → chunk-5CV5ITZF.js} +2 -2
  18. package/dist/{chunk-6DLWKFEX.js → chunk-5ZR3APIM.js} +41 -42
  19. package/dist/{chunk-XTBDCR27.js → chunk-63RIVFQI.js} +4 -4
  20. package/dist/{chunk-GSLNCYGG.js → chunk-75SY4F24.js} +13 -14
  21. package/dist/{chunk-U44DJXQP.js → chunk-7RQXA5GG.js} +15 -18
  22. package/dist/chunk-A3YNG5KP.js +45 -0
  23. package/dist/{chunk-5OFV52AM.js → chunk-AE37FEGH.js} +1 -1
  24. package/dist/{chunk-BWD5EPKO.js → chunk-AMXIUN2R.js} +4 -6
  25. package/dist/{chunk-3KAZU3VR.js → chunk-ARD426WI.js} +2 -2
  26. package/dist/{chunk-BW5KFIQC.js → chunk-AWQWXSW4.js} +1 -0
  27. package/dist/{chunk-YH5MVY2U.js → chunk-BHUWL2Y3.js} +7 -7
  28. package/dist/{chunk-CT4MN5IU.js → chunk-BI5LAQ3Y.js} +353 -359
  29. package/dist/{chunk-KAPJINKN.js → chunk-BM5GS6ZH.js} +2 -2
  30. package/dist/{chunk-TLX72JTG.js → chunk-BWYQUPOS.js} +1 -1
  31. package/dist/chunk-CFRQMBGP.js +49 -0
  32. package/dist/{chunk-RMLC67LF.js → chunk-CJYKEW2L.js} +2 -30
  33. package/dist/chunk-CKEQFGLT.js +32 -0
  34. package/dist/{chunk-IWDLU6K3.js → chunk-DC4CFXM5.js} +4 -6
  35. package/dist/{chunk-ZVUL7QYY.js → chunk-DMSLNKF7.js} +29 -32
  36. package/dist/{chunk-KN35K52N.js → chunk-DQXSPYRI.js} +3 -3
  37. package/dist/{chunk-HYGZEMX6.js → chunk-EVDGNG4F.js} +11 -5
  38. package/dist/{chunk-SRYEJNES.js → chunk-F5Z6URKM.js} +2 -2
  39. package/dist/{chunk-UMS2MFPZ.js → chunk-F6X3YJWD.js} +2 -3
  40. package/dist/{chunk-XYURS6EN.js → chunk-FA5LDARD.js} +15 -17
  41. package/dist/{chunk-24AKHFGP.js → chunk-FFL3A2VP.js} +6 -6
  42. package/dist/chunk-FJIVKLPH.js +31 -0
  43. package/dist/chunk-G2B7F6ZU.js +88 -0
  44. package/dist/{chunk-US7ECLD7.js → chunk-GAACZY6R.js} +131 -41
  45. package/dist/{chunk-MZGQNL3Y.js → chunk-GMTFDAOK.js} +12 -13
  46. package/dist/{chunk-VOOAPROD.js → chunk-GNSIWBAT.js} +3 -3
  47. package/dist/chunk-GTAI2J6U.js +27 -0
  48. package/dist/{chunk-RVK72CZX.js → chunk-GZE7WOI4.js} +1362 -459
  49. package/dist/{chunk-IUE7SSKV.js → chunk-H7HTEQUZ.js} +13 -7
  50. package/dist/{chunk-EUXZEFTV.js → chunk-HK6JVFZC.js} +3 -3
  51. package/dist/chunk-IPDG45G5.js +26 -0
  52. package/dist/{chunk-5HSRT26B.js → chunk-J6JP25XU.js} +16 -15
  53. package/dist/{chunk-HWCCCQNX.js → chunk-JL6CXUMW.js} +13 -6
  54. package/dist/{chunk-EBC36LNN.js → chunk-K2YGBXOA.js} +17 -17
  55. package/dist/{chunk-WMYE35PX.js → chunk-KLQVC3XC.js} +7 -5
  56. package/dist/{chunk-ATKJFDQN.js → chunk-KSR7RGQY.js} +12 -14
  57. package/dist/{chunk-POMLXPMY.js → chunk-KXF5R4UN.js} +1 -1
  58. package/dist/{chunk-LLJNQKQW.js → chunk-LEJOJDXL.js} +20 -13
  59. package/dist/{chunk-JUKMK5Y4.js → chunk-MA77RSFN.js} +10 -11
  60. package/dist/{chunk-GAQ7OQG6.js → chunk-MKVZQUEG.js} +85 -96
  61. package/dist/{chunk-2EECBNC5.js → chunk-MN7MHUXQ.js} +75 -0
  62. package/dist/{chunk-DEL2U6CM.js → chunk-MT6BVNFW.js} +16 -14
  63. package/dist/chunk-NDMCVUYK.js +507 -0
  64. package/dist/{chunk-HRNHZA3N.js → chunk-NIU2IPC5.js} +12 -16
  65. package/dist/{chunk-AGSS7277.js → chunk-NNKXDXXS.js} +7 -24
  66. package/dist/{chunk-V35JG4JB.js → chunk-OJLTLYHB.js} +152 -334
  67. package/dist/{chunk-J6MPGQTS.js → chunk-OLAWH5UQ.js} +81 -15
  68. package/dist/{chunk-T57LYLZT.js → chunk-OOU2WZZE.js} +1 -1
  69. package/dist/{chunk-CYRKQRPM.js → chunk-OSTKYB55.js} +2 -4
  70. package/dist/chunk-P4QNXS6I.js +27 -0
  71. package/dist/chunk-PKES3ISE.js +297 -0
  72. package/dist/{chunk-ROYSX2S5.js → chunk-PO45POGF.js} +2 -2
  73. package/dist/{chunk-T7FEBKXN.js → chunk-PPIBVH4R.js} +7 -9
  74. package/dist/{chunk-3RKP3FMS.js → chunk-PQJFG24Z.js} +295 -23
  75. package/dist/{chunk-KUA4OJ5Y.js → chunk-Q3UZHW6N.js} +846 -350
  76. package/dist/{chunk-N5FLEO7W.js → chunk-Q4EMRFNA.js} +37 -37
  77. package/dist/{chunk-5IUSNGOC.js → chunk-Q4FCYCRE.js} +28 -21
  78. package/dist/chunk-Q6D6VMI4.js +22 -0
  79. package/dist/{chunk-UZ2XCLYS.js → chunk-QGSTQH4D.js} +8 -8
  80. package/dist/{chunk-DUO2TU77.js → chunk-RZOXUSPC.js} +10 -4
  81. package/dist/{chunk-JMYYOTQG.js → chunk-S26LC76R.js} +13 -1
  82. package/dist/{chunk-GMX5OS7B.js → chunk-S67UJDGQ.js} +11 -12
  83. package/dist/chunk-SCIUNBPF.js +44 -0
  84. package/dist/{chunk-RKBXZN3A.js → chunk-SJJYRZB4.js} +2 -2
  85. package/dist/chunk-SXGD4ANG.js +25 -0
  86. package/dist/{chunk-YCWYO6TQ.js → chunk-T7FTXGS3.js} +48 -45
  87. package/dist/{chunk-FM4RDMKT.js → chunk-TIQJPRDD.js} +115 -61
  88. package/dist/{chunk-XHJBS436.js → chunk-TIYGSODX.js} +25 -25
  89. package/dist/{chunk-S2HEXIWI.js → chunk-U2SDMG7C.js} +10 -6
  90. package/dist/{chunk-2KXTHF3M.js → chunk-U6OC3QEM.js} +253 -33
  91. package/dist/{chunk-AWSCPCN2.js → chunk-UCGQT677.js} +19 -19
  92. package/dist/chunk-UHGF5UT5.js +32 -0
  93. package/dist/{chunk-JW3YWBVB.js → chunk-UN4TEBWN.js} +17 -19
  94. package/dist/{chunk-ZHH37KZL.js → chunk-V3APN3DY.js} +17 -17
  95. package/dist/{chunk-ED36RF6Y.js → chunk-V63BC55Q.js} +1 -1
  96. package/dist/{chunk-XBJVAEEO.js → chunk-VG5JS5SW.js} +3 -2
  97. package/dist/{chunk-W66O5E25.js → chunk-VPBIMOAQ.js} +13 -15
  98. package/dist/chunk-VQH24FIP.js +37 -0
  99. package/dist/{chunk-YNE3RP52.js → chunk-VSFLRN5Y.js} +8 -1
  100. package/dist/{chunk-7D6L4MTX.js → chunk-W2V54OCL.js} +3 -3
  101. package/dist/{chunk-2FN63LPV.js → chunk-W5LGKNET.js} +13 -14
  102. package/dist/{chunk-IQWN5JCP.js → chunk-W5R5SABV.js} +13 -14
  103. package/dist/{chunk-R3T7CLQ2.js → chunk-WIZWZR4C.js} +41 -41
  104. package/dist/{chunk-TOY6QKOH.js → chunk-WQOIR3QY.js} +17 -17
  105. package/dist/{chunk-Y6GZHWSJ.js → chunk-XAIT2YGS.js} +6 -6
  106. package/dist/chunk-XCUHKYCQ.js +23 -0
  107. package/dist/{chunk-GSM5UU7A.js → chunk-XQCSWV2G.js} +44 -35
  108. package/dist/{chunk-OHKJ7PQF.js → chunk-YBSONGSZ.js} +43 -39
  109. package/dist/{chunk-GXFV6MYU.js → chunk-YISME6ON.js} +72 -39
  110. package/dist/chunk-YRD4ISED.js +30 -0
  111. package/dist/{chunk-SD4I7ZO4.js → chunk-YSBHPOY6.js} +43 -53
  112. package/dist/{chunk-QBFBRV2B.js → chunk-Z2XAOKHK.js} +4 -2
  113. package/dist/{chunk-5VSF4UUQ.js → chunk-Z7IGUAXL.js} +34 -39
  114. package/dist/{chunk-MPNJLASA.js → chunk-ZKXQKGWZ.js} +10 -13
  115. package/dist/{chunk-J64T55EI.js → chunk-ZQ6NZZTB.js} +75 -9
  116. package/dist/chunk-ZUUI3ZSA.js +38 -0
  117. package/dist/{chunk-7HXE67BN.js → chunk-ZYNI26MI.js} +2 -2
  118. package/dist/index.js +32674 -27567
  119. package/dist/mcp/analyze-cli.js +11 -12
  120. package/dist/mcp/cli.js +46 -45
  121. package/dist/mcp/server.js +1210 -574
  122. package/dist/mcp/worker.js +65 -65
  123. package/dist/probes/installer.js +21 -23
  124. package/docs/adr/0010-trace-validation-session-lifecycle.md +390 -0
  125. package/docs/adr/README.md +1 -0
  126. package/docs/agent-tools.md +28 -7
  127. package/docs/ast-grep_rules_catalog.md +5 -3
  128. package/docs/configuration.md +12 -1
  129. package/docs/defect-shapes.md +738 -0
  130. package/docs/engineering-principles.md +12 -0
  131. package/docs/environment-variables.md +20 -0
  132. package/docs/features.md +16 -1
  133. package/docs/globalconfig.md +37 -8
  134. package/docs/invariants/caches-stores.md +30 -0
  135. package/docs/invariants/dispatch-runners.md +164 -0
  136. package/docs/invariants/git-guard-host.md +53 -0
  137. package/docs/invariants/language-config.md +31 -0
  138. package/docs/invariants/lsp-trust-exec.md +286 -0
  139. package/docs/invariants/paths-os.md +59 -0
  140. package/docs/invariants/session-telemetry.md +74 -0
  141. package/docs/lsp-capability-matrix.md +105 -12
  142. package/docs/lsp-idle-eviction.md +37 -18
  143. package/docs/pi-lens-fixer.md +24 -2
  144. package/docs/pi-lens-investigator.md +14 -0
  145. package/docs/pi-lens-merge-policy.md +32 -17
  146. package/docs/pi-lens-monitor.md +66 -10
  147. package/docs/pi-lens-orchestration.md +41 -0
  148. package/docs/pi-lens-release.md +20 -0
  149. package/docs/pi-lens-retro.md +5 -4
  150. package/docs/pi-lens-reviewer.md +54 -7
  151. package/docs/pi-lens-subagent.md +10 -3
  152. package/docs/release-qa-baseline.md +19 -7
  153. package/docs/servercapabilities.md +47 -47
  154. package/docs/settings.md +9 -5
  155. package/docs/subagent-compat.md +1 -1
  156. package/docs/usage.md +1 -0
  157. package/package.json +8 -5
  158. package/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
  159. package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
  160. package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
  161. package/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
  162. package/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
  163. package/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
  164. package/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
  165. package/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
  166. package/rules/rule-catalog.json +25 -1
  167. package/scripts/analyze-pi-lens-logs.mjs +15 -5
  168. package/scripts/lib/is-main-module.mjs +27 -0
  169. package/scripts/lib/scratch-home-env.mjs +21 -0
  170. package/scripts/rpc-load-check.mjs +4 -6
  171. package/scripts/warm-loader-cache.mjs +2 -5
  172. package/dist/chunk-3PTHXJXR.js +0 -28
  173. package/dist/chunk-3QED2P4V.js +0 -31
  174. package/dist/chunk-5WRPDP2A.js +0 -47
  175. package/dist/chunk-ABBOA7UD.js +0 -157
  176. package/dist/chunk-CUHSHSB6.js +0 -273
  177. package/dist/chunk-GL5LUMZE.js +0 -51
  178. package/dist/chunk-HAD7QRQI.js +0 -30
  179. package/dist/chunk-JORED7EX.js +0 -44
  180. package/dist/chunk-KYUB6QDC.js +0 -72
  181. package/dist/chunk-LZSEQW6A.js +0 -57
  182. package/dist/chunk-M2IFVFWU.js +0 -79
  183. package/dist/chunk-M2UD3LPU.js +0 -88
  184. package/dist/chunk-MBKQHGA7.js +0 -39
  185. package/dist/chunk-R7YOCSNV.js +0 -23
  186. package/dist/chunk-SKAMFC7A.js +0 -28
  187. package/dist/chunk-SYE6T2EB.js +0 -28
  188. package/dist/chunk-TRETHTQO.js +0 -26
  189. package/dist/chunk-UA7ZXYDR.js +0 -184
  190. package/dist/chunk-XTFDJI3T.js +0 -24
  191. package/dist/chunk-Z3CCVDUB.js +0 -76
@@ -4,12 +4,22 @@ import {
4
4
  reserveManagedToolRefreshSlot
5
5
  } from "./chunk-UXVNL3D7.js";
6
6
  import {
7
- HOOK_WALL_BUDGET_MS,
7
+ stripAnsi
8
+ } from "./chunk-6HWVI6MI.js";
9
+ import {
10
+ OPENGREP_REGISTRY_PACK_URL,
11
+ cachedOpengrepPackPath
12
+ } from "./chunk-UHGF5UT5.js";
13
+ import {
14
+ HOOK_WALL_BUDGET_MS
15
+ } from "./chunk-CKEQFGLT.js";
16
+ import {
8
17
  bounded
9
- } from "./chunk-RMLC67LF.js";
18
+ } from "./chunk-CJYKEW2L.js";
10
19
  import {
11
20
  acquireManagedInstallGate,
12
21
  commitDurableStoreAsync,
22
+ findManagedToolBinary,
13
23
  getManagedToolsDir,
14
24
  getRefreshableManagedTools,
15
25
  invalidateManagedToolResolution,
@@ -19,42 +29,45 @@ import {
19
29
  refreshManagedTool,
20
30
  resolveManagedNpmBinPath,
21
31
  verifyToolBinary
22
- } from "./chunk-GAQ7OQG6.js";
23
- import "./chunk-DEL2U6CM.js";
32
+ } from "./chunk-MKVZQUEG.js";
33
+ import "./chunk-MT6BVNFW.js";
24
34
  import {
25
35
  pmBinary,
26
36
  resolveNodePackageManager,
27
37
  updateArgs
28
- } from "./chunk-5VSF4UUQ.js";
29
- import "./chunk-3KAZU3VR.js";
30
- import "./chunk-P63GXC37.js";
31
- import "./chunk-HRNHZA3N.js";
32
- import "./chunk-TLX72JTG.js";
33
- import "./chunk-DGUKIYSI.js";
34
- import "./chunk-XBJVAEEO.js";
38
+ } from "./chunk-Z7IGUAXL.js";
39
+ import "./chunk-ARD426WI.js";
40
+ import "./chunk-5APMQ2IJ.js";
41
+ import "./chunk-NIU2IPC5.js";
42
+ import "./chunk-BWYQUPOS.js";
43
+ import "./chunk-2RLWJO5K.js";
44
+ import "./chunk-VG5JS5SW.js";
35
45
  import {
36
46
  safeSpawnAsync
37
- } from "./chunk-KUA4OJ5Y.js";
38
- import "./chunk-BW5KFIQC.js";
47
+ } from "./chunk-Q3UZHW6N.js";
48
+ import "./chunk-AWQWXSW4.js";
39
49
  import "./chunk-QYF5S6P6.js";
40
- import "./chunk-DUO2TU77.js";
41
- import "./chunk-J6MPGQTS.js";
42
- import "./chunk-5HSRT26B.js";
43
- import "./chunk-M2IFVFWU.js";
44
- import "./chunk-2EECBNC5.js";
50
+ import "./chunk-RZOXUSPC.js";
51
+ import "./chunk-OLAWH5UQ.js";
52
+ import "./chunk-J6JP25XU.js";
53
+ import {
54
+ writeFileAtomicAsync
55
+ } from "./chunk-MN7MHUXQ.js";
45
56
  import {
46
57
  recordDegradationOnce
47
- } from "./chunk-J64T55EI.js";
48
- import "./chunk-POMLXPMY.js";
49
- import "./chunk-JMYYOTQG.js";
50
- import "./chunk-QBFBRV2B.js";
51
- import "./chunk-YNE3RP52.js";
58
+ } from "./chunk-ZQ6NZZTB.js";
59
+ import "./chunk-KXF5R4UN.js";
60
+ import "./chunk-S26LC76R.js";
61
+ import "./chunk-Z2XAOKHK.js";
62
+ import {
63
+ isTestMode
64
+ } from "./chunk-VSFLRN5Y.js";
52
65
  import "./chunk-LJDODBBZ.js";
53
- import "./chunk-ABBOA7UD.js";
54
- import "./chunk-3RKP3FMS.js";
66
+ import "./chunk-PQJFG24Z.js";
55
67
  import "./chunk-NXL4FFQQ.js";
56
68
 
57
69
  // dist/clients/installer/managed-tool-refresh.js
70
+ import * as crypto from "node:crypto";
58
71
  import * as fs from "node:fs/promises";
59
72
  import * as path from "node:path";
60
73
  var STATE_FILENAME = ".refresh-state.json";
@@ -142,10 +155,10 @@ async function readManagedToolRefreshState() {
142
155
  return { status: "unreadable", reason: err.message };
143
156
  }
144
157
  }
145
- async function writeRefreshStamp(toolId, entry) {
158
+ async function writeRefreshStamp(toolId, entry, options = {}) {
146
159
  try {
147
160
  await fs.mkdir(getManagedToolsDir(), { recursive: true });
148
- await commitDurableStoreAsync({
161
+ const committed = await commitDurableStoreAsync({
149
162
  path: getManagedToolRefreshStatePath(),
150
163
  deserialize: (contents) => {
151
164
  if (contents === void 0)
@@ -157,6 +170,10 @@ async function writeRefreshStamp(toolId, entry) {
157
170
  }
158
171
  },
159
172
  merge: (disk) => {
173
+ const current = disk.tools[toolId];
174
+ if (options.retainNewerSuccess === true && entry.failed === true && current !== void 0 && current.failed !== true && current.checkedAt >= entry.checkedAt) {
175
+ return disk;
176
+ }
160
177
  disk.tools[toolId] = entry;
161
178
  return disk;
162
179
  },
@@ -170,6 +187,9 @@ async function writeRefreshStamp(toolId, entry) {
170
187
  logSessionStart(`managed-tool-refresh ${toolId}: stamp deferred because another process owns the lock`);
171
188
  }
172
189
  });
190
+ if (committed !== void 0 && committed.tools[toolId] !== entry) {
191
+ logSessionStart(`managed-tool-refresh ${toolId}: kept a newer successful stamp (checkedAt ${committed.tools[toolId]?.checkedAt ?? "unknown"}) \u2014 this failure does not replace it`);
192
+ }
173
193
  } catch (err) {
174
194
  recordDegradationOnce({
175
195
  kind: "managed-tool-refresh",
@@ -303,7 +323,7 @@ async function refreshNonNpmOne(candidate, entry, now) {
303
323
  // Deliberately NOT carrying `entry.etag` forward: a stamp that replays
304
324
  // the validator of a run whose download failed would get a 304 next
305
325
  // time and skip the install that never happened.
306
- });
326
+ }, { retainNewerSuccess: true });
307
327
  return {
308
328
  toolId: candidate.toolId,
309
329
  strategy: candidate.strategy,
@@ -405,7 +425,7 @@ async function performNpmRefresh(candidate, packageName, now) {
405
425
  checkedAt: now,
406
426
  failed: true,
407
427
  ...onDisk !== void 0 && { version: onDisk }
408
- });
428
+ }, { retainNewerSuccess: true });
409
429
  return {
410
430
  toolId: candidate.toolId,
411
431
  strategy: "npm",
@@ -446,7 +466,7 @@ async function performNpmRefresh(candidate, packageName, now) {
446
466
  checkedAt: now,
447
467
  failed: true,
448
468
  ...currentVersion !== void 0 && { version: currentVersion }
449
- });
469
+ }, { retainNewerSuccess: true });
450
470
  return {
451
471
  toolId: candidate.toolId,
452
472
  strategy: "npm",
@@ -479,13 +499,17 @@ async function performNpmRefresh(candidate, packageName, now) {
479
499
  var refreshInFlight = null;
480
500
  var noopTap = () => {
481
501
  };
482
- function runManagedToolRefresh(now = Date.now()) {
502
+ function runManagedToolRefresh(now = Date.now(), options = {}) {
483
503
  const joined = refreshInFlight;
484
504
  if (joined) {
485
505
  logSessionStart("managed-tool-refresh: joining the refresh already in flight");
486
506
  return joined;
487
507
  }
488
- const run = executeManagedToolRefresh(now, noopTap).finally(() => {
508
+ const run = executeManagedToolRefresh(now, noopTap).then(async (outcome) => {
509
+ if (options.rulePack !== false)
510
+ await refreshOpengrepRulePack(now);
511
+ return outcome;
512
+ }).finally(() => {
489
513
  refreshInFlight = null;
490
514
  });
491
515
  refreshInFlight = run;
@@ -565,7 +589,7 @@ async function executeManagedToolRefresh(now, tap = noopTap) {
565
589
  version: result.currentVersion
566
590
  },
567
591
  ...result.ok ? {} : { failed: true }
568
- }), {
592
+ }, { retainNewerSuccess: true }), {
569
593
  ms: HOOK_WALL_BUDGET_MS.session_start,
570
594
  // The unref'd timer runs after session_start returns, so no
571
595
  // live turn signal belongs to this background refresh.
@@ -589,9 +613,205 @@ async function executeManagedToolRefresh(now, tap = noopTap) {
589
613
  releaseReservation();
590
614
  }
591
615
  }
616
+ var OPENGREP_PACK_STAMP_ID = "opengrep-rules";
617
+ var PACK_FETCH_TIMEOUT_MS = 6e4;
618
+ var PACK_VALIDATE_TIMEOUT_MS = 18e4;
619
+ var PACK_MAX_BYTES = 16 * 1024 * 1024;
620
+ var PACK_MIN_RULES = 100;
621
+ function opengrepPackUrl() {
622
+ if (isTestMode()) {
623
+ return process.env.PI_LENS_TEST_OPENGREP_PACK_URL;
624
+ }
625
+ return OPENGREP_REGISTRY_PACK_URL;
626
+ }
627
+ async function downloadOpengrepPack(url) {
628
+ const res = await fetch(url, {
629
+ signal: AbortSignal.timeout(PACK_FETCH_TIMEOUT_MS),
630
+ // `identity` is load-bearing: semgrep.dev/c/auto answers a client that
631
+ // accepts gzip (Node's fetch does by default) with the rule set as JSON,
632
+ // and one that does not with YAML (measured 2026-10-23). The CLI loads
633
+ // either from a `.yaml` file; the language server loads the JSON as zero
634
+ // rules and publishes empty diagnostics, which would turn a cached pack
635
+ // into a silent clean scan.
636
+ headers: { "User-Agent": "pi-lens/1.0", "Accept-Encoding": "identity" }
637
+ });
638
+ if (!res.ok)
639
+ throw new Error(`HTTP ${res.status}`);
640
+ if (!res.body)
641
+ throw new Error("empty response body");
642
+ const chunks = [];
643
+ let total = 0;
644
+ const reader = res.body.getReader();
645
+ for (; ; ) {
646
+ const { done, value } = await reader.read();
647
+ if (done)
648
+ break;
649
+ total += value.byteLength;
650
+ if (total > PACK_MAX_BYTES) {
651
+ await reader.cancel();
652
+ throw new Error(`body exceeds ${PACK_MAX_BYTES} bytes`);
653
+ }
654
+ chunks.push(value);
655
+ }
656
+ const bytes = Buffer.concat(chunks);
657
+ if (bytes.toString("utf-8", 0, 64).trimStart().startsWith("{"))
658
+ throw new Error("registry answered JSON, not the YAML rule file");
659
+ return bytes;
660
+ }
661
+ async function validateOpengrepPack(binary, candidate) {
662
+ const spawned = await safeSpawnAsync(binary, ["scan", "--validate", "--config", candidate, "--disable-version-check"], {
663
+ cwd: path.dirname(candidate),
664
+ timeout: PACK_VALIDATE_TIMEOUT_MS,
665
+ ignoreAmbientSignal: true,
666
+ lifetimeCoupled: true
667
+ });
668
+ if (spawned.status !== 0) {
669
+ const detail = spawned.stderr.trim() || spawned.failure || `exit ${spawned.status}`;
670
+ return `opengrep --validate failed: ${detail}`.slice(0, 240);
671
+ }
672
+ const count = /(\d+) rule\(s\)/.exec(stripAnsi(`${spawned.stdout}
673
+ ${spawned.stderr}`));
674
+ const rules = count ? Number(count[1]) : 0;
675
+ if (rules < PACK_MIN_RULES) {
676
+ return `opengrep --validate reported ${count ? rules : "no"} rules (floor ${PACK_MIN_RULES})`;
677
+ }
678
+ return void 0;
679
+ }
680
+ var PACK_CANDIDATE_MAX_AGE_MS = 60 * 60 * 1e3;
681
+ async function sweepStaleCandidates(finalPath) {
682
+ const dir = path.dirname(finalPath);
683
+ const prefix = `${path.basename(finalPath)}.candidate-`;
684
+ try {
685
+ for (const name of await fs.readdir(dir)) {
686
+ if (!name.startsWith(prefix))
687
+ continue;
688
+ const file = path.join(dir, name);
689
+ const { mtimeMs } = await fs.stat(file);
690
+ if (Date.now() - mtimeMs > PACK_CANDIDATE_MAX_AGE_MS)
691
+ await fs.rm(file, { force: true });
692
+ }
693
+ } catch (err) {
694
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: could not sweep stale candidates (${err.message})`);
695
+ }
696
+ }
697
+ async function refreshOpengrepRulePack(now = Date.now()) {
698
+ try {
699
+ if (process.env.PI_LENS_DISABLE_TOOL_REFRESH === "1")
700
+ return "skipped";
701
+ const url = opengrepPackUrl();
702
+ if (!url)
703
+ return "skipped";
704
+ const binary = await findManagedToolBinary("opengrep");
705
+ if (!binary)
706
+ return "skipped";
707
+ const read = await readManagedToolRefreshState();
708
+ if (read.status === "unreadable") {
709
+ recordDegradationOnce({
710
+ kind: "managed-tool-refresh",
711
+ subject: "refresh-state",
712
+ reason: `refresh state unreadable (${read.reason}); skipping refresh this session`
713
+ });
714
+ return "skipped";
715
+ }
716
+ const entry = read.state.tools[OPENGREP_PACK_STAMP_ID];
717
+ if (entry && now - entry.checkedAt < (entry.failed ? retryIntervalMs() : refreshIntervalMs())) {
718
+ return "skipped";
719
+ }
720
+ const declined = async (phase) => {
721
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: declined (${phase}) \u2014 no stamp written, retried next session`);
722
+ return "declined";
723
+ };
724
+ const pre = await acquireManagedInstallGate(`managed tool refresh: ${OPENGREP_PACK_STAMP_ID}`);
725
+ if (!pre.ok)
726
+ return declined(pre.reason ?? "unknown");
727
+ await pre.release?.();
728
+ const finalPath = cachedOpengrepPackPath();
729
+ const candidate = `${finalPath}.candidate-${process.pid}-${crypto.randomBytes(4).toString("hex")}`;
730
+ const startedAt = Date.now();
731
+ try {
732
+ await fs.mkdir(path.dirname(finalPath), { recursive: true });
733
+ await sweepStaleCandidates(finalPath);
734
+ const bytes = await downloadOpengrepPack(url);
735
+ const digest = crypto.createHash("sha256").update(bytes).digest("hex");
736
+ let current;
737
+ try {
738
+ current = await fs.readFile(finalPath);
739
+ } catch (err) {
740
+ if (err.code !== "ENOENT")
741
+ throw err;
742
+ }
743
+ if (current && crypto.createHash("sha256").update(current).digest("hex") === digest) {
744
+ await writeRefreshStamp(OPENGREP_PACK_STAMP_ID, {
745
+ checkedAt: now,
746
+ version: digest.slice(0, 12)
747
+ });
748
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: unchanged at ${digest.slice(0, 12)} (${Date.now() - startedAt}ms)`);
749
+ return "unchanged";
750
+ }
751
+ await writeFileAtomicAsync(candidate, bytes, { bestEffort: false });
752
+ const rejected = await validateOpengrepPack(binary, candidate);
753
+ if (rejected)
754
+ throw new Error(rejected);
755
+ const swap = await acquireManagedInstallGate(`managed tool refresh: ${OPENGREP_PACK_STAMP_ID} (swap)`);
756
+ if (!swap.ok)
757
+ return await declined(swap.reason ?? "unknown");
758
+ try {
759
+ const after = await readManagedToolRefreshState();
760
+ const latest = after.status === "ok" ? after.state.tools[OPENGREP_PACK_STAMP_ID] : void 0;
761
+ if (latest && !latest.failed && latest.checkedAt !== entry?.checkedAt) {
762
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: another process refreshed first \u2014 keeping its pack`);
763
+ return "skipped";
764
+ }
765
+ await fs.rename(candidate, finalPath);
766
+ await writeRefreshStamp(OPENGREP_PACK_STAMP_ID, {
767
+ checkedAt: now,
768
+ version: digest.slice(0, 12)
769
+ });
770
+ } finally {
771
+ await swap.release?.();
772
+ }
773
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: cached pack now ${digest.slice(0, 12)} (${bytes.byteLength} bytes, ${Date.now() - startedAt}ms)`);
774
+ return "refreshed";
775
+ } catch (err) {
776
+ const reason = err.message;
777
+ recordDegradationOnce({
778
+ kind: "managed-tool-refresh",
779
+ subject: OPENGREP_PACK_STAMP_ID,
780
+ reason: `rule pack refresh failed: ${reason}`
781
+ });
782
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: refresh failed after ${Date.now() - startedAt}ms \u2014 keeping the current pack (${reason})`);
783
+ await writeRefreshStamp(
784
+ OPENGREP_PACK_STAMP_ID,
785
+ {
786
+ checkedAt: now,
787
+ failed: true,
788
+ ...entry?.version !== void 0 && { version: entry.version }
789
+ },
790
+ // A winner that stamped while this attempt was validating keeps its
791
+ // `{checkedAt, version}` and its weekly cadence (shape 21).
792
+ { retainNewerSuccess: true }
793
+ );
794
+ return "failed";
795
+ } finally {
796
+ try {
797
+ await fs.rm(candidate, { force: true });
798
+ } catch (err) {
799
+ logSessionStart(`managed-tool-refresh ${OPENGREP_PACK_STAMP_ID}: could not remove ${candidate} (${err.message})`);
800
+ }
801
+ }
802
+ } catch (err) {
803
+ recordDegradationOnce({
804
+ kind: "managed-tool-refresh",
805
+ subject: OPENGREP_PACK_STAMP_ID,
806
+ reason: `rule pack refresh threw: ${err.message}`
807
+ });
808
+ return "failed";
809
+ }
810
+ }
592
811
  export {
593
812
  getManagedToolRefreshStatePath,
594
813
  readManagedToolRefreshState,
814
+ refreshOpengrepRulePack,
595
815
  runManagedToolRefresh,
596
816
  runManagedToolRefreshForExploration,
597
817
  selectStaleTools,
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
2
  import {
3
3
  calcCyclomaticComplexity
4
- } from "./chunk-EUXZEFTV.js";
5
- import "./chunk-T57LYLZT.js";
4
+ } from "./chunk-HK6JVFZC.js";
5
+ import "./chunk-OOU2WZZE.js";
6
6
  import "./chunk-5W3R6LFT.js";
7
7
  import {
8
8
  firstChildOfType,
@@ -11,27 +11,27 @@ import {
11
11
  resolveTreeSitterLanguage,
12
12
  walk,
13
13
  withTreeSitterRoot
14
- } from "./chunk-US7ECLD7.js";
14
+ } from "./chunk-GAACZY6R.js";
15
15
  import "./chunk-Z54ZSOBZ.js";
16
- import "./chunk-GXFV6MYU.js";
17
- import "./chunk-FM4RDMKT.js";
18
- import "./chunk-P63GXC37.js";
19
- import "./chunk-KUA4OJ5Y.js";
20
- import "./chunk-DUO2TU77.js";
21
- import "./chunk-J6MPGQTS.js";
22
- import "./chunk-5HSRT26B.js";
23
- import "./chunk-M2IFVFWU.js";
24
- import "./chunk-2EECBNC5.js";
25
- import "./chunk-J64T55EI.js";
16
+ import "./chunk-ZUUI3ZSA.js";
17
+ import "./chunk-TIQJPRDD.js";
18
+ import "./chunk-YISME6ON.js";
19
+ import "./chunk-CJYKEW2L.js";
20
+ import "./chunk-5APMQ2IJ.js";
21
+ import "./chunk-Q3UZHW6N.js";
22
+ import "./chunk-RZOXUSPC.js";
23
+ import "./chunk-OLAWH5UQ.js";
24
+ import "./chunk-J6JP25XU.js";
25
+ import "./chunk-MN7MHUXQ.js";
26
+ import "./chunk-ZQ6NZZTB.js";
26
27
  import {
27
28
  createSubsystemLogger
28
- } from "./chunk-POMLXPMY.js";
29
- import "./chunk-JMYYOTQG.js";
30
- import "./chunk-QBFBRV2B.js";
31
- import "./chunk-YNE3RP52.js";
29
+ } from "./chunk-KXF5R4UN.js";
30
+ import "./chunk-S26LC76R.js";
31
+ import "./chunk-Z2XAOKHK.js";
32
+ import "./chunk-VSFLRN5Y.js";
32
33
  import "./chunk-LJDODBBZ.js";
33
- import "./chunk-ABBOA7UD.js";
34
- import "./chunk-3RKP3FMS.js";
34
+ import "./chunk-PQJFG24Z.js";
35
35
  import "./chunk-NXL4FFQQ.js";
36
36
 
37
37
  // dist/clients/complexity-client.js
@@ -0,0 +1,32 @@
1
+ import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
+ import {
3
+ getGlobalPiLensDir
4
+ } from "./chunk-Q3UZHW6N.js";
5
+
6
+ // dist/clients/opengrep-rule-pack.js
7
+ import * as fs from "node:fs";
8
+ import * as path from "node:path";
9
+ var OPENGREP_REGISTRY_PACK_URL = "https://semgrep.dev/c/auto";
10
+ function cachedOpengrepPackPath() {
11
+ return path.join(getGlobalPiLensDir(), "rules", "opengrep-registry.yaml");
12
+ }
13
+ function resolveOpengrepRulePack() {
14
+ const cached = cachedOpengrepPackPath();
15
+ try {
16
+ if (fs.statSync(cached).size > 0)
17
+ return cached;
18
+ } catch {
19
+ }
20
+ return void 0;
21
+ }
22
+ function stripPackRuleIdPrefix(checkId, packPath) {
23
+ const prefix = `${path.dirname(packPath).replace(/^[\\/]+/, "").replace(/[\\/:]+/g, ".")}.`;
24
+ return checkId.startsWith(prefix) ? checkId.slice(prefix.length) : checkId;
25
+ }
26
+
27
+ export {
28
+ OPENGREP_REGISTRY_PACK_URL,
29
+ cachedOpengrepPackPath,
30
+ resolveOpengrepRulePack,
31
+ stripPackRuleIdPrefix
32
+ };
@@ -9,26 +9,24 @@ import {
9
9
  resolveSeverityFloor,
10
10
  shouldScanTrivy,
11
11
  worktreeSkipDirs
12
- } from "./chunk-YH5MVY2U.js";
13
- import "./chunk-ED36RF6Y.js";
14
- import "./chunk-BWD5EPKO.js";
15
- import "./chunk-TIQ2PKDW.js";
16
- import "./chunk-UA7ZXYDR.js";
17
- import "./chunk-3KAZU3VR.js";
18
- import "./chunk-P63GXC37.js";
19
- import "./chunk-KUA4OJ5Y.js";
20
- import "./chunk-BW5KFIQC.js";
21
- import "./chunk-J6MPGQTS.js";
22
- import "./chunk-5HSRT26B.js";
23
- import "./chunk-2EECBNC5.js";
24
- import "./chunk-J64T55EI.js";
25
- import "./chunk-POMLXPMY.js";
26
- import "./chunk-JMYYOTQG.js";
27
- import "./chunk-QBFBRV2B.js";
28
- import "./chunk-YNE3RP52.js";
12
+ } from "./chunk-BHUWL2Y3.js";
13
+ import "./chunk-V63BC55Q.js";
14
+ import "./chunk-AMXIUN2R.js";
15
+ import "./chunk-3MYEA7QD.js";
16
+ import "./chunk-ARD426WI.js";
17
+ import "./chunk-5APMQ2IJ.js";
18
+ import "./chunk-Q3UZHW6N.js";
19
+ import "./chunk-AWQWXSW4.js";
20
+ import "./chunk-OLAWH5UQ.js";
21
+ import "./chunk-J6JP25XU.js";
22
+ import "./chunk-MN7MHUXQ.js";
23
+ import "./chunk-ZQ6NZZTB.js";
24
+ import "./chunk-KXF5R4UN.js";
25
+ import "./chunk-S26LC76R.js";
26
+ import "./chunk-Z2XAOKHK.js";
27
+ import "./chunk-VSFLRN5Y.js";
29
28
  import "./chunk-LJDODBBZ.js";
30
- import "./chunk-ABBOA7UD.js";
31
- import "./chunk-3RKP3FMS.js";
29
+ import "./chunk-PQJFG24Z.js";
32
30
  import "./chunk-NXL4FFQQ.js";
33
31
  export {
34
32
  TrivyClient,
@@ -2,19 +2,16 @@ import { createRequire as __pilensCreateRequire } from "node:module"; const requ
2
2
  import {
3
3
  getToolCommandSpec,
4
4
  shouldAutoInstallTool
5
- } from "./chunk-Y6GZHWSJ.js";
5
+ } from "./chunk-XAIT2YGS.js";
6
6
  import {
7
7
  BUILTIN_SERVER_RUNNER_COVERS,
8
8
  getServersForFileWithConfig,
9
9
  isAuxiliary,
10
10
  resolveAnalysisRootPath
11
- } from "./chunk-3DA2JDOL.js";
11
+ } from "./chunk-3WEPUD2V.js";
12
12
  import {
13
13
  emitBounded
14
- } from "./chunk-CUHSHSB6.js";
15
- import {
16
- PathKeyedMap
17
- } from "./chunk-Z3CCVDUB.js";
14
+ } from "./chunk-NDMCVUYK.js";
18
15
  import {
19
16
  ensureTool,
20
17
  findManagedToolBinary,
@@ -24,22 +21,20 @@ import {
24
21
  isSpawnableCommand,
25
22
  logSessionStart,
26
23
  resetPathWalkMemo
27
- } from "./chunk-GAQ7OQG6.js";
24
+ } from "./chunk-MKVZQUEG.js";
28
25
  import {
29
26
  resolveToolCwd
30
- } from "./chunk-DEL2U6CM.js";
27
+ } from "./chunk-MT6BVNFW.js";
31
28
  import {
32
- VENDOR_BIN_DIRS,
33
- VENV_BIN_DIRS,
34
29
  findGlobalBinary,
35
30
  findLocalBinAt,
36
31
  findLocalBinUpwards,
37
32
  localBinPath
38
- } from "./chunk-5VSF4UUQ.js";
33
+ } from "./chunk-Z7IGUAXL.js";
39
34
  import {
40
35
  createAvailabilityProbeFlight,
41
36
  probeToolAsync
42
- } from "./chunk-3KAZU3VR.js";
37
+ } from "./chunk-ARD426WI.js";
43
38
  import {
44
39
  classifyProbeFailure,
45
40
  createAvailabilityLatch,
@@ -49,26 +44,31 @@ import {
49
44
  logAvailabilityDecision,
50
45
  startHostStallSampler,
51
46
  transientRetryDelayMs
52
- } from "./chunk-P63GXC37.js";
47
+ } from "./chunk-5APMQ2IJ.js";
53
48
  import {
49
+ VENDOR_BIN_DIRS,
50
+ VENV_BIN_DIRS,
54
51
  createGenerationSource,
55
52
  getGlobalPiLensDir,
56
53
  isInSpawnTimeoutCooldown,
57
54
  resolveWindowsCommandForEnvironment,
58
55
  safeSpawnAsync
59
- } from "./chunk-KUA4OJ5Y.js";
56
+ } from "./chunk-Q3UZHW6N.js";
57
+ import {
58
+ PathKeyedMap
59
+ } from "./chunk-OLAWH5UQ.js";
60
60
  import {
61
61
  getProjectTrustState
62
- } from "./chunk-M2IFVFWU.js";
62
+ } from "./chunk-MN7MHUXQ.js";
63
63
  import {
64
64
  compareOrdinal,
65
65
  incrementDegradationCount
66
- } from "./chunk-J64T55EI.js";
66
+ } from "./chunk-ZQ6NZZTB.js";
67
67
  import {
68
68
  isUnderDir,
69
69
  normalizeEphemeralMapKey,
70
70
  normalizeMapKey
71
- } from "./chunk-3RKP3FMS.js";
71
+ } from "./chunk-PQJFG24Z.js";
72
72
 
73
73
  // dist/clients/dispatch/runners/utils/runner-helpers.js
74
74
  import * as fs from "node:fs";
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
2
  import {
3
3
  isTestMode
4
- } from "./chunk-YNE3RP52.js";
4
+ } from "./chunk-VSFLRN5Y.js";
5
5
 
6
6
  // dist/clients/scanner-temp-root.js
7
7
  import * as os from "node:os";
@@ -1,14 +1,14 @@
1
1
  import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
2
  import {
3
3
  isExcludedDirName
4
- } from "./chunk-KUA4OJ5Y.js";
4
+ } from "./chunk-Q3UZHW6N.js";
5
5
  import {
6
6
  createDeadline,
7
7
  yieldIfOverBudget
8
8
  } from "./chunk-QYF5S6P6.js";
9
9
  import {
10
10
  isGeneratedArtifactDirectoryName
11
- } from "./chunk-J6MPGQTS.js";
11
+ } from "./chunk-OLAWH5UQ.js";
12
12
 
13
13
  // dist/clients/source-walker.js
14
14
  import * as fs from "node:fs";
@@ -134,6 +134,7 @@ function walkTreeRecursiveSync(rootDir, visit) {
134
134
 
135
135
  export {
136
136
  readDirEntriesSafe,
137
+ readDirEntriesSafeAsync,
137
138
  shouldRecurseIntoDir,
138
139
  walkTreeStackSync,
139
140
  walkTreeStackAsync,