pi-lens 4.4.4 → 4.4.5

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 (179) hide show
  1. package/CHANGELOG.md +440 -0
  2. package/README.md +13 -3
  3. package/config/dependency-cruiser-eager-allowlist.json +1 -0
  4. package/dist/chunk-22Y2BM7H.js +23 -0
  5. package/dist/{chunk-ATKJFDQN.js → chunk-27VWVB23.js} +12 -14
  6. package/dist/{chunk-S2HEXIWI.js → chunk-2FYKETQJ.js} +10 -6
  7. package/dist/{chunk-SRYEJNES.js → chunk-2LDMXL2M.js} +2 -2
  8. package/dist/{chunk-ZHH37KZL.js → chunk-2SDHYHHO.js} +17 -17
  9. package/dist/chunk-2Y6OJRSI.js +38 -0
  10. package/dist/chunk-3SNDVPOR.js +507 -0
  11. package/dist/{chunk-5OFV52AM.js → chunk-3WCEHYOI.js} +1 -1
  12. package/dist/chunk-44X7VIKR.js +73 -0
  13. package/dist/{chunk-DEL2U6CM.js → chunk-4FHUGDKU.js} +16 -14
  14. package/dist/{chunk-CT4MN5IU.js → chunk-4ODSZ35Z.js} +353 -359
  15. package/dist/{chunk-ZIVJBOO3.js → chunk-4U7GDSZQ.js} +2 -2
  16. package/dist/chunk-54NIOJJZ.js +25 -0
  17. package/dist/{chunk-N5FLEO7W.js → chunk-5DKE4HGX.js} +37 -37
  18. package/dist/{chunk-P63GXC37.js → chunk-5LRUKYFA.js} +31 -4
  19. package/dist/{chunk-HRNHZA3N.js → chunk-63NMUNYP.js} +12 -16
  20. package/dist/{chunk-HWCCCQNX.js → chunk-6XSESGWD.js} +13 -6
  21. package/dist/{chunk-UMS2MFPZ.js → chunk-72J27ICO.js} +2 -3
  22. package/dist/{chunk-ED36RF6Y.js → chunk-7FLRUH6B.js} +1 -1
  23. package/dist/chunk-7IYC4ENJ.js +297 -0
  24. package/dist/chunk-7WWQAW5P.js +30 -0
  25. package/dist/{chunk-3DA2JDOL.js → chunk-7ZS7MC24.js} +551 -203
  26. package/dist/{chunk-WMYE35PX.js → chunk-AHWA4AKM.js} +7 -5
  27. package/dist/{chunk-JW3YWBVB.js → chunk-AI3GP74G.js} +17 -19
  28. package/dist/{chunk-AGSS7277.js → chunk-APFJKOP6.js} +6 -23
  29. package/dist/{chunk-ZVUL7QYY.js → chunk-ASRAO7KG.js} +29 -32
  30. package/dist/{chunk-BW5KFIQC.js → chunk-AWQWXSW4.js} +1 -0
  31. package/dist/{chunk-TLX72JTG.js → chunk-CG5V25HX.js} +1 -1
  32. package/dist/chunk-CKEQFGLT.js +32 -0
  33. package/dist/{chunk-Y6GZHWSJ.js → chunk-COOUUC5W.js} +6 -6
  34. package/dist/{chunk-XTBDCR27.js → chunk-CPZ5JJW6.js} +4 -4
  35. package/dist/{chunk-RKKOYPRA.js → chunk-DS2USX5G.js} +13 -15
  36. package/dist/chunk-EA2ZRG44.js +27 -0
  37. package/dist/{chunk-GSLNCYGG.js → chunk-EDMLIW6W.js} +13 -14
  38. package/dist/{chunk-2EECBNC5.js → chunk-EIKRZ32J.js} +75 -0
  39. package/dist/chunk-EKNWOL2I.js +27 -0
  40. package/dist/{chunk-R3T7CLQ2.js → chunk-ELZRSR5N.js} +41 -41
  41. package/dist/{chunk-GMX5OS7B.js → chunk-EN5AM7PX.js} +11 -12
  42. package/dist/{chunk-3RKP3FMS.js → chunk-EWXXLS26.js} +226 -24
  43. package/dist/chunk-EX4EXBW7.js +37 -0
  44. package/dist/{chunk-XHJBS436.js → chunk-EXVXBSGN.js} +25 -25
  45. package/dist/{chunk-MZGQNL3Y.js → chunk-F7BO6FWH.js} +12 -13
  46. package/dist/{chunk-V35JG4JB.js → chunk-FEDWAYDS.js} +152 -334
  47. package/dist/{chunk-J64T55EI.js → chunk-FWZRGGGY.js} +73 -9
  48. package/dist/{chunk-T57LYLZT.js → chunk-G224FADB.js} +1 -1
  49. package/dist/chunk-G5UCJFT7.js +26 -0
  50. package/dist/{chunk-LLJNQKQW.js → chunk-GLW3YDZZ.js} +20 -13
  51. package/dist/{chunk-GXFV6MYU.js → chunk-GTDSYEA2.js} +72 -39
  52. package/dist/{chunk-DUO2TU77.js → chunk-GYRZ72R4.js} +10 -4
  53. package/dist/chunk-HYVXA3BB.js +49 -0
  54. package/dist/{chunk-W66O5E25.js → chunk-IEBJF3PN.js} +13 -15
  55. package/dist/{chunk-GAQ7OQG6.js → chunk-IL7K66ZQ.js} +83 -94
  56. package/dist/{chunk-T7FEBKXN.js → chunk-JWOVP5BL.js} +7 -9
  57. package/dist/{chunk-UBOQLVT2.js → chunk-K2GUZ4DN.js} +4 -4
  58. package/dist/{chunk-5VSF4UUQ.js → chunk-K4SZB56V.js} +34 -39
  59. package/dist/{chunk-7D6L4MTX.js → chunk-KCBRHV5E.js} +3 -3
  60. package/dist/{chunk-GSM5UU7A.js → chunk-KFXCL4OV.js} +38 -28
  61. package/dist/{chunk-J6MPGQTS.js → chunk-KJJAVH3X.js} +81 -15
  62. package/dist/{chunk-BWD5EPKO.js → chunk-KPVLQHCZ.js} +4 -6
  63. package/dist/{chunk-MPNJLASA.js → chunk-KX56K73G.js} +10 -13
  64. package/dist/{chunk-AWSCPCN2.js → chunk-LMCTHJ2H.js} +19 -19
  65. package/dist/{chunk-IWDLU6K3.js → chunk-MEFLGBCS.js} +4 -6
  66. package/dist/{chunk-TOY6QKOH.js → chunk-MKPCELNI.js} +17 -17
  67. package/dist/{chunk-POMLXPMY.js → chunk-N3PLNNCW.js} +1 -1
  68. package/dist/chunk-N5FBM25N.js +22 -0
  69. package/dist/{chunk-CYRKQRPM.js → chunk-NFNVDDGB.js} +2 -4
  70. package/dist/{chunk-RMLC67LF.js → chunk-NLIVE7L6.js} +2 -30
  71. package/dist/{chunk-24AKHFGP.js → chunk-OMJ3OFBJ.js} +6 -6
  72. package/dist/{chunk-IQWN5JCP.js → chunk-OZNCKLOX.js} +13 -14
  73. package/dist/chunk-P5XUGPIX.js +31 -0
  74. package/dist/{chunk-2KXTHF3M.js → chunk-PJXNTPB2.js} +253 -33
  75. package/dist/chunk-PKOXJIVT.js +88 -0
  76. package/dist/{chunk-DGUKIYSI.js → chunk-PP2A5V2T.js} +8 -10
  77. package/dist/{chunk-KAPJINKN.js → chunk-Q42LJANT.js} +2 -2
  78. package/dist/{chunk-UZ2XCLYS.js → chunk-Q4BKKOVC.js} +8 -8
  79. package/dist/{chunk-TIQ2PKDW.js → chunk-QT66NEYN.js} +4 -4
  80. package/dist/{chunk-U44DJXQP.js → chunk-RCHO5W7M.js} +15 -18
  81. package/dist/{chunk-YH5MVY2U.js → chunk-RG3MXTRI.js} +7 -7
  82. package/dist/chunk-RG7OODGM.js +57 -0
  83. package/dist/{chunk-OHKJ7PQF.js → chunk-RU34BA4D.js} +43 -39
  84. package/dist/{chunk-JMYYOTQG.js → chunk-S26LC76R.js} +13 -1
  85. package/dist/{chunk-XBJVAEEO.js → chunk-S55TEC7I.js} +3 -2
  86. package/dist/{chunk-RVK72CZX.js → chunk-SJHC3BCZ.js} +1397 -481
  87. package/dist/{chunk-IYNJ6YPZ.js → chunk-SNEUMLM7.js} +4 -4
  88. package/dist/{chunk-S67KYG37.js → chunk-T4NGVFYI.js} +2 -2
  89. package/dist/{chunk-YCWYO6TQ.js → chunk-THEXI2QO.js} +48 -45
  90. package/dist/{chunk-AMERCH6V.js → chunk-TL2TCJYL.js} +15 -16
  91. package/dist/{chunk-KUA4OJ5Y.js → chunk-TPYYEDP5.js} +823 -350
  92. package/dist/{chunk-YNE3RP52.js → chunk-TVZRLTG6.js} +8 -1
  93. package/dist/{chunk-ROYSX2S5.js → chunk-UCVMSOXF.js} +2 -2
  94. package/dist/chunk-UL5SXQVX.js +32 -0
  95. package/dist/{chunk-7HXE67BN.js → chunk-UO66IMVP.js} +2 -2
  96. package/dist/{chunk-VOOAPROD.js → chunk-UVY4TOJH.js} +3 -3
  97. package/dist/{chunk-RKBXZN3A.js → chunk-VIDEKABZ.js} +2 -2
  98. package/dist/{chunk-2FN63LPV.js → chunk-VITFDI3O.js} +13 -14
  99. package/dist/{chunk-6DLWKFEX.js → chunk-VUAVE3QC.js} +41 -42
  100. package/dist/{chunk-FM4RDMKT.js → chunk-WUY4BZEP.js} +10 -12
  101. package/dist/{chunk-SD4I7ZO4.js → chunk-X3UTCXAA.js} +43 -53
  102. package/dist/chunk-XHDBJODR.js +45 -0
  103. package/dist/{chunk-5IUSNGOC.js → chunk-XHLK33VM.js} +28 -21
  104. package/dist/{chunk-3KAZU3VR.js → chunk-XI34NWDI.js} +2 -2
  105. package/dist/{chunk-QBFBRV2B.js → chunk-XWFIHYCH.js} +4 -2
  106. package/dist/{chunk-JUKMK5Y4.js → chunk-Y2TPADJR.js} +10 -11
  107. package/dist/{chunk-EBC36LNN.js → chunk-Y5KTA2OB.js} +17 -17
  108. package/dist/{chunk-HYGZEMX6.js → chunk-YKVDBNPO.js} +11 -5
  109. package/dist/{chunk-KN35K52N.js → chunk-YSDPVDFC.js} +3 -3
  110. package/dist/chunk-YWNO5Q4R.js +44 -0
  111. package/dist/{chunk-US7ECLD7.js → chunk-YWWG4AQA.js} +119 -28
  112. package/dist/{chunk-O4NWQT6I.js → chunk-YXDCRUKQ.js} +4 -4
  113. package/dist/{chunk-XYURS6EN.js → chunk-YXGRRORB.js} +15 -17
  114. package/dist/{chunk-IUE7SSKV.js → chunk-ZAPSUBLU.js} +13 -7
  115. package/dist/{chunk-EUXZEFTV.js → chunk-ZPJM7DID.js} +3 -3
  116. package/dist/{chunk-5HSRT26B.js → chunk-ZSUX7KEM.js} +16 -15
  117. package/dist/index.js +37155 -32210
  118. package/dist/mcp/analyze-cli.js +11 -12
  119. package/dist/mcp/cli.js +46 -45
  120. package/dist/mcp/server.js +1210 -574
  121. package/dist/mcp/worker.js +65 -65
  122. package/dist/probes/installer.js +21 -23
  123. package/docs/adr/0010-trace-validation-session-lifecycle.md +390 -0
  124. package/docs/adr/README.md +1 -0
  125. package/docs/ast-grep_rules_catalog.md +5 -3
  126. package/docs/configuration.md +9 -0
  127. package/docs/engineering-principles.md +12 -0
  128. package/docs/environment-variables.md +20 -0
  129. package/docs/features.md +16 -1
  130. package/docs/globalconfig.md +37 -8
  131. package/docs/lsp-capability-matrix.md +105 -12
  132. package/docs/lsp-idle-eviction.md +37 -18
  133. package/docs/pi-lens-fixer.md +22 -1
  134. package/docs/pi-lens-investigator.md +14 -0
  135. package/docs/pi-lens-merge-policy.md +23 -10
  136. package/docs/pi-lens-monitor.md +64 -8
  137. package/docs/pi-lens-retro.md +2 -2
  138. package/docs/pi-lens-reviewer.md +48 -1
  139. package/docs/pi-lens-subagent.md +8 -1
  140. package/docs/release-qa-baseline.md +19 -7
  141. package/docs/servercapabilities.md +47 -47
  142. package/docs/settings.md +9 -5
  143. package/docs/subagent-compat.md +1 -1
  144. package/docs/usage.md +1 -0
  145. package/package.json +6 -4
  146. package/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
  147. package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
  148. package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
  149. package/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
  150. package/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
  151. package/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
  152. package/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
  153. package/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
  154. package/rules/rule-catalog.json +25 -1
  155. package/scripts/analyze-pi-lens-logs.mjs +15 -5
  156. package/scripts/lib/is-main-module.mjs +27 -0
  157. package/scripts/lib/scratch-home-env.mjs +21 -0
  158. package/scripts/rpc-load-check.mjs +4 -6
  159. package/scripts/warm-loader-cache.mjs +2 -5
  160. package/dist/chunk-3PTHXJXR.js +0 -28
  161. package/dist/chunk-3QED2P4V.js +0 -31
  162. package/dist/chunk-5WRPDP2A.js +0 -47
  163. package/dist/chunk-ABBOA7UD.js +0 -157
  164. package/dist/chunk-CUHSHSB6.js +0 -273
  165. package/dist/chunk-GL5LUMZE.js +0 -51
  166. package/dist/chunk-HAD7QRQI.js +0 -30
  167. package/dist/chunk-JORED7EX.js +0 -44
  168. package/dist/chunk-KYUB6QDC.js +0 -72
  169. package/dist/chunk-LZSEQW6A.js +0 -57
  170. package/dist/chunk-M2IFVFWU.js +0 -79
  171. package/dist/chunk-M2UD3LPU.js +0 -88
  172. package/dist/chunk-MBKQHGA7.js +0 -39
  173. package/dist/chunk-R7YOCSNV.js +0 -23
  174. package/dist/chunk-SKAMFC7A.js +0 -28
  175. package/dist/chunk-SYE6T2EB.js +0 -28
  176. package/dist/chunk-TRETHTQO.js +0 -26
  177. package/dist/chunk-UA7ZXYDR.js +0 -184
  178. package/dist/chunk-XTFDJI3T.js +0 -24
  179. package/dist/chunk-Z3CCVDUB.js +0 -76
@@ -17,6 +17,17 @@ valid:
17
17
  def handler():
18
18
  return 42
19
19
  yield
20
+ - |
21
+ # #4840: the yield belongs to the lambda, not to make().
22
+ def make():
23
+ f = lambda: (yield)
24
+ return f
25
+ - |
26
+ # #1806 shape: the only yield is in a nested def; return 2 is not a generator return.
27
+ def outer():
28
+ def inner():
29
+ yield 1
30
+ return 2
20
31
  invalid:
21
32
  - |
22
33
  def gen():
@@ -32,3 +43,9 @@ invalid:
32
43
  yield 1
33
44
  return 99
34
45
  return inner_gen
46
+ - |
47
+ # #4840: a lambda elsewhere in a real generator does not hide its yield.
48
+ def gen():
49
+ key = lambda x: x
50
+ yield key(1)
51
+ return 2
@@ -0,0 +1,86 @@
1
+ id: no-sql-in-code-execute-js
2
+ valid:
3
+ # `.query` belongs to `no-sql-in-code`; this rule holds the `.execute` arms.
4
+ - 'db.query("SELECT * FROM users WHERE id = " + id)'
5
+ # Constant SQL, the parameterized idiom, and a literal-only concatenation.
6
+ - 'db.execute("SELECT * FROM users")'
7
+ - 'db.execute("SELECT * FROM users WHERE id = ?", [id])'
8
+ - 'db.execute("SELECT * FROM " + "users")'
9
+ - 'db.execute(sql`SELECT * FROM users WHERE id = ${id}`)'
10
+ # The callee-name shapes #2909 reported: `execute` is also a task method.
11
+ - 'runner.execute("delete " + id)'
12
+ - 'queue.execute(`update ${id}`)'
13
+ - 'command.execute("update " + name)'
14
+ - 'task.execute("updated " + name)'
15
+ # Only the first argument is read.
16
+ - 'db.execute("id = " + id, "DELETE FROM t")'
17
+ - 'ui.execute("Please select an item from " + list)'
18
+ - 'ui.execute("Item " + n + " selected from list")'
19
+ - 'job.execute("update " + id, { set: true })'
20
+ - 'menu.execute("select " + item, { from: x })'
21
+ # `SELECT` and `WITH` are whole words.
22
+ - 'job.execute("selected from " + source)'
23
+ - 'ui.execute("Within the select list " + id)'
24
+ - 'ui.execute("Item " + n + " select from list")'
25
+ # \N is not an escape; JavaScript reads it as N.
26
+ - 'runner.execute("\NSELECT * FROM " + source)'
27
+ - 'runner.execute("-- note\NSELECT * FROM " + source)'
28
+ # A template with no substitution is constant SQL.
29
+ - 'db.execute(`SELECT * FROM users`)'
30
+ # The first argument must open with a quote or backtick.
31
+ - 'db.execute(update + " SET x = 1")'
32
+ # An escaped tab does not end a -- comment.
33
+ - 'db.execute("-- c\tSELECT * FROM t WHERE id = " + id)'
34
+ invalid:
35
+ - 'db.execute("SELECT * FROM users WHERE id = " + id)'
36
+ - 'db.execute("DELETE FROM sessions WHERE token = " + token, [])'
37
+ - 'db.execute(`SELECT * FROM users WHERE id = ${id}`)'
38
+ - 'db.execute("UPDATE users SET name = ''" + n + "''")'
39
+ - 'db.execute("DELETE FROM t WHERE id = " + id)'
40
+ - 'db.execute("SELECT*FROM t WHERE id=" + id)'
41
+ - 'db.execute(`SELECT pg_sleep(${n})`)'
42
+ - 'db.execute("INSERT INTO t (a) VALUES (''" + a + "'')")'
43
+ - |-
44
+ db.execute(`
45
+ SELECT *
46
+ FROM users
47
+ WHERE id = ${id}
48
+ `)
49
+ - 'db.execute("CREATE OR REPLACE VIEW v AS SELECT * FROM " + t)'
50
+ - 'db.execute("DROP TABLE " + table)'
51
+ - 'db.execute("ALTER TABLE " + table + " ADD COLUMN x int")'
52
+ - 'db.execute("GRANT SELECT ON " + table + " TO app")'
53
+ - 'db.execute("REVOKE ALL ON " + table + " FROM app")'
54
+ - 'db.execute("WITH u AS (SELECT * FROM users) SELECT * FROM u WHERE id = " + id)'
55
+ - 'db.execute("MERGE INTO t USING s ON t.id = " + id)'
56
+ - 'db.execute("TRUNCATE TABLE " + table)'
57
+ - 'db.execute("REPLACE INTO t VALUES (" + v + ")")'
58
+ - 'db.execute("/* by id */ SELECT * FROM t WHERE id = " + id)'
59
+ - |-
60
+ db.execute(`-- one user
61
+ SELECT * FROM users WHERE id = ${id}`)
62
+ - "db.execute('SELECT * FROM t WHERE id = ' + id)"
63
+ - 'db?.execute("SELECT * FROM t WHERE id = " + id)'
64
+ - 'db?.execute("DELETE FROM t WHERE id = " + id, [])'
65
+ # Escape sequences as written in source, not real whitespace.
66
+ - 'db.execute("\nSELECT * FROM users WHERE id = " + id)'
67
+ - 'db.execute("\tDELETE FROM t WHERE id = " + id)'
68
+ - 'db.execute("\r\nUPDATE users SET a = " + a)'
69
+ - 'db.execute("-- user lookup\nSELECT * FROM users WHERE id = " + id)'
70
+ - 'db.execute("-- c\rSELECT * FROM t WHERE id = " + id)'
71
+ # A comment before the first argument is a named child of `arguments`.
72
+ - |-
73
+ db.execute(
74
+ // by id
75
+ `SELECT * FROM users WHERE id = ${id}`)
76
+ - 'db.execute(/* by id */ "SELECT * FROM users WHERE id = " + id)'
77
+ # Not SQL, but it matches the sibling's `SELECT ... ${` arm;
78
+ # ts_sql_injection_sink flags the same template.
79
+ - 'queue.execute(`select ${id}`)'
80
+ # Statement-shaped English that the alternation still accepts (#4804
81
+ # review): pinned so a later narrowing has a red row to work against.
82
+ - 'acl.execute("grant " + role)'
83
+ - 'search.execute("create index " + field)'
84
+ - 'config.execute("merge into " + base)'
85
+ - 'runner.execute("delete from " + cacheKey)'
86
+ - 'ui.execute("select " + label + " from the list")'
@@ -0,0 +1,86 @@
1
+ id: no-sql-in-code-execute
2
+ valid:
3
+ # `.query` belongs to `no-sql-in-code`; this rule holds the `.execute` arms.
4
+ - 'db.query("SELECT * FROM users WHERE id = " + id)'
5
+ # Constant SQL, the parameterized idiom, and a literal-only concatenation.
6
+ - 'db.execute("SELECT * FROM users")'
7
+ - 'db.execute("SELECT * FROM users WHERE id = ?", [id])'
8
+ - 'db.execute("SELECT * FROM " + "users")'
9
+ - 'db.execute(sql`SELECT * FROM users WHERE id = ${id}`)'
10
+ # The callee-name shapes #2909 reported: `execute` is also a task method.
11
+ - 'runner.execute("delete " + id)'
12
+ - 'queue.execute(`update ${id}`)'
13
+ - 'command.execute("update " + name)'
14
+ - 'task.execute("updated " + name)'
15
+ # Only the first argument is read.
16
+ - 'db.execute("id = " + id, "DELETE FROM t")'
17
+ - 'ui.execute("Please select an item from " + list)'
18
+ - 'ui.execute("Item " + n + " selected from list")'
19
+ - 'job.execute("update " + id, { set: true })'
20
+ - 'menu.execute("select " + item, { from: x })'
21
+ # `SELECT` and `WITH` are whole words.
22
+ - 'job.execute("selected from " + source)'
23
+ - 'ui.execute("Within the select list " + id)'
24
+ - 'ui.execute("Item " + n + " select from list")'
25
+ # \N is not an escape; JavaScript reads it as N.
26
+ - 'runner.execute("\NSELECT * FROM " + source)'
27
+ - 'runner.execute("-- note\NSELECT * FROM " + source)'
28
+ # A template with no substitution is constant SQL.
29
+ - 'db.execute(`SELECT * FROM users`)'
30
+ # The first argument must open with a quote or backtick.
31
+ - 'db.execute(update + " SET x = 1")'
32
+ # An escaped tab does not end a -- comment.
33
+ - 'db.execute("-- c\tSELECT * FROM t WHERE id = " + id)'
34
+ invalid:
35
+ - 'db.execute("SELECT * FROM users WHERE id = " + id)'
36
+ - 'db.execute("DELETE FROM sessions WHERE token = " + token, [])'
37
+ - 'db.execute(`SELECT * FROM users WHERE id = ${id}`)'
38
+ - 'db.execute("UPDATE users SET name = ''" + n + "''")'
39
+ - 'db.execute("DELETE FROM t WHERE id = " + id)'
40
+ - 'db.execute("SELECT*FROM t WHERE id=" + id)'
41
+ - 'db.execute(`SELECT pg_sleep(${n})`)'
42
+ - 'db.execute("INSERT INTO t (a) VALUES (''" + a + "'')")'
43
+ - |-
44
+ db.execute(`
45
+ SELECT *
46
+ FROM users
47
+ WHERE id = ${id}
48
+ `)
49
+ - 'db.execute("CREATE OR REPLACE VIEW v AS SELECT * FROM " + t)'
50
+ - 'db.execute("DROP TABLE " + table)'
51
+ - 'db.execute("ALTER TABLE " + table + " ADD COLUMN x int")'
52
+ - 'db.execute("GRANT SELECT ON " + table + " TO app")'
53
+ - 'db.execute("REVOKE ALL ON " + table + " FROM app")'
54
+ - 'db.execute("WITH u AS (SELECT * FROM users) SELECT * FROM u WHERE id = " + id)'
55
+ - 'db.execute("MERGE INTO t USING s ON t.id = " + id)'
56
+ - 'db.execute("TRUNCATE TABLE " + table)'
57
+ - 'db.execute("REPLACE INTO t VALUES (" + v + ")")'
58
+ - 'db.execute("/* by id */ SELECT * FROM t WHERE id = " + id)'
59
+ - |-
60
+ db.execute(`-- one user
61
+ SELECT * FROM users WHERE id = ${id}`)
62
+ - "db.execute('SELECT * FROM t WHERE id = ' + id)"
63
+ - 'db?.execute("SELECT * FROM t WHERE id = " + id)'
64
+ - 'db?.execute("DELETE FROM t WHERE id = " + id, [])'
65
+ # Escape sequences as written in source, not real whitespace.
66
+ - 'db.execute("\nSELECT * FROM users WHERE id = " + id)'
67
+ - 'db.execute("\tDELETE FROM t WHERE id = " + id)'
68
+ - 'db.execute("\r\nUPDATE users SET a = " + a)'
69
+ - 'db.execute("-- user lookup\nSELECT * FROM users WHERE id = " + id)'
70
+ - 'db.execute("-- c\rSELECT * FROM t WHERE id = " + id)'
71
+ # A comment before the first argument is a named child of `arguments`.
72
+ - |-
73
+ db.execute(
74
+ // by id
75
+ `SELECT * FROM users WHERE id = ${id}`)
76
+ - 'db.execute(/* by id */ "SELECT * FROM users WHERE id = " + id)'
77
+ # Not SQL, but it matches the sibling's `SELECT ... ${` arm;
78
+ # ts_sql_injection_sink flags the same template.
79
+ - 'queue.execute(`select ${id}`)'
80
+ # Statement-shaped English that the alternation still accepts (#4804
81
+ # review): pinned so a later narrowing has a red row to work against.
82
+ - 'acl.execute("grant " + role)'
83
+ - 'search.execute("create index " + field)'
84
+ - 'config.execute("merge into " + base)'
85
+ - 'runner.execute("delete from " + cacheKey)'
86
+ - 'ui.execute("select " + label + " from the list")'
@@ -12,7 +12,22 @@ valid:
12
12
  g = int(s)
13
13
  except ValueError:
14
14
  pass
15
+ - |
16
+ # #4840: round() and len() already return numbers.
17
+ a = float(round(v, 3))
18
+ b = int(len(xs))
19
+ - |
20
+ # #4841 review F4: abs(), sum() and ord() raise TypeError, never ValueError,
21
+ # and return a number otherwise.
22
+ c = int(abs(v))
23
+ d = float(sum(xs))
24
+ e = int(ord(ch))
15
25
  invalid:
16
26
  - 'int("42")'
17
27
  - 'float("3.14")'
18
28
  - 'int(user_input)'
29
+ - 'int(s.strip())'
30
+ - 'float(round_trip(s))'
31
+ - |
32
+ # min() and max() return their argument's type, so a string can reach int().
33
+ int(min(parts))
@@ -12,9 +12,10 @@ note: |
12
12
 
13
13
  The rule matches a `function_definition` that contains BOTH a
14
14
  `yield` node AND a `return_statement` with a value (`return\s+\S`).
15
- Each `has:` uses `stopBy: {kind: function_definition}` (not the
16
- plain `stopBy: end` this rule shipped with originally) — it needs
17
- to search past the `block` wrapper (the function body isn't a
15
+ Each `has:` stops at a nested `function_definition` (not the
16
+ plain `stopBy: end` this rule shipped with originally); the `yield`
17
+ clause also stops at a `lambda`, since `lambda: (yield)` is its own
18
+ generator (#4840). The search has to go past the `block` wrapper (the function body isn't a
18
19
  direct child of `function_definition`), but must NOT cross into a
19
20
  nested `function_definition`. A bare `stopBy: end` searches every
20
21
  descendant regardless of depth, so a `yield` in an outer
@@ -38,8 +39,12 @@ rule:
38
39
  - kind: function_definition
39
40
  - has:
40
41
  kind: yield
42
+ # A nested def or a generator lambda (`lambda: (yield)`) is its own
43
+ # generator; its yield does not make the enclosing function one (#4840).
41
44
  stopBy:
42
- kind: function_definition
45
+ any:
46
+ - kind: function_definition
47
+ - kind: lambda
43
48
  - has:
44
49
  kind: return_statement
45
50
  regex: 'return\s+\S'
@@ -0,0 +1,119 @@
1
+ id: no-sql-in-code-execute-js
2
+ language: JavaScript
3
+ message: "Raw SQL string in code — use query builder or ORM"
4
+ severity: warning
5
+ note: |
6
+ Raw SQL strings built via concatenation or template substitution are
7
+ error-prone and open to injection. Use a query builder (knex, drizzle)
8
+ or ORM (prisma, typeorm), or pass the value as a bind parameter.
9
+
10
+ This rule holds only the `.execute` arms; `.query` stays in
11
+ `no-sql-in-code` / `no-sql-in-code-js` with master's keyword gate. Both
12
+ read `$SQL` the same way: a `binary_expression` (string concatenation,
13
+ e.g. `"SELECT ... " + id`) or a template string with at least one
14
+ `${...}` substitution — the shapes that interpolate a runtime value into
15
+ the query text. A plain string literal, including one with a `?`
16
+ placeholder passed beside a params array, is not flagged (#1806).
17
+
18
+ 2026-10-24 (#1828): `$DB.execute(...)` is the same sink as
19
+ `$DB.query(...)` (mysql2 and oracledb both take `execute(sql, params)`),
20
+ so it gets 1-arg and `, $$$REST` arms, plus their `?.` forms. `execute`
21
+ is also a common task, command and job method name, and the keyword
22
+ `has` on the `.query` arms matches a keyword anywhere in the call: the
23
+ callee-name false-positive class #2909 fixed in the tree-sitter
24
+ `sql-injection` rule. The `.execute` arms therefore use that fix's
25
+ prefix test instead (`ts_sql_injection_sink` in
26
+ clients/tree-sitter-client.ts): the first argument's text (the first
27
+ child of `arguments` that is not a comment) must start with a quote or
28
+ backtick, then optional whitespace and SQL comments, then a statement
29
+ from the sibling's alternation. The test reads the first argument only,
30
+ as the sibling reads only the template, so a later `{ set: ... }` or
31
+ `from` cannot complete an `UPDATE` or `SELECT`.
32
+
33
+ Severity is `warning`, not `error` (#4804 review): statement-shaped
34
+ English still matches, because the alternation accepts it and an
35
+ ast-grep rule has no receiver test. `acl.execute("grant " + role)`,
36
+ `search.execute("create index " + field)`,
37
+ `config.execute("merge into " + base)`, `"delete from " + cacheKey` and
38
+ `"select " + label + " from the list"` all flag. All five are pinned as
39
+ `invalid:` rows, so a later narrowing has a red row to work against.
40
+ Nothing here blocks an edit: this body measures 22 against
41
+ `MAX_BLOCKING_RULE_COMPLEXITY` (8) in
42
+ clients/dispatch/runners/yaml-rule-parser.ts, as master's `.query` body
43
+ already did at 15, so a per-edit dispatch skips the rule. These findings
44
+ arrive from the full-analysis path (`blockingOnly: false`, e.g.
45
+ `pilens_analyze`), where `error` used to present them as blockers.
46
+
47
+ Three edits diverge from the sibling's text
48
+ (clients/tree-sitter-client.ts:4703): a `\b` after `SELECT` and after
49
+ `WITH`, so `"selected from "` and `"Within the select list "` do not
50
+ open a statement; the skip also accepts exactly the `\n`, `\r` and `\t`
51
+ escapes as written in source, case-sensitively so that `\N` does not
52
+ count, which catches `"\nSELECT ..."`; and a `--` comment also ends at
53
+ an escaped `\n` or `\r`, as Postgres ends one at either, so
54
+ `"-- c\nSELECT ..."` is caught (the comment may also run on to a later
55
+ escape).
56
+
57
+ The two differences this leaves against the sibling are accepted
58
+ residuals of this change, not a planned follow-up: the sibling's
59
+ `SELECT` and `WITH` arms carry no word boundary, so
60
+ `job.execute("selected from " + source)` still flags there, and its
61
+ skip accepts real whitespace only, so an escaped `"\nSELECT ..."` is a
62
+ miss there. tests/config/sql-injection-alternation-drift.test.ts keeps
63
+ the rest of the alternation byte-identical to the sibling's copy.
64
+
65
+ Cost (#4804 review, measured on this head for the shared statement
66
+ test): 2.2 to 23.7 ms per scanned file, 231 to 468 of 2,687 JS/TS files
67
+ admitted by the literal prefilter, and 0.46 s to 11.7 s for a
68
+ full-tree scan. The per-file cost does not depend on file size, so it is
69
+ rule compilation per `findAll` call, not traversal; #4807 tracks it and
70
+ does not block this rule. A re-measurement of this split reproduces both
71
+ facts (0.9 to 1.6 ms per file for the `.query` rule, 11 to 12 ms for
72
+ this one, at 28 KiB and 155 KiB).
73
+
74
+ The sibling's other test is out of reach for an ast-grep rule: when the
75
+ prefix test fails, it still flags a template whose receiver it follows
76
+ through same-file declarations to an import from a known SQL package, so
77
+ that is a second way to flag, not a filter.
78
+
79
+ Not caught through `execute`: a statement split between its first two
80
+ tokens (`"DELETE " + "FROM t ..."`), SQL text that opens with `${...}`,
81
+ a parenthesized argument or one that starts with a variable, whitespace
82
+ written as `\u000a`, `\x0a` or a backslash line continuation, a
83
+ FROM-less SELECT built by concatenation (`"SELECT pg_sleep(" + n + ")"`),
84
+ and statements the alternation does not list (`INSERT IGNORE INTO`,
85
+ `INSERT OR REPLACE INTO`).
86
+ rule:
87
+ all:
88
+ - any:
89
+ - pattern: $DB.execute($SQL)
90
+ - pattern: $DB.execute($SQL, $$$REST)
91
+ - pattern: $DB?.execute($SQL)
92
+ - pattern: $DB?.execute($SQL, $$$REST)
93
+ - has:
94
+ field: arguments
95
+ has:
96
+ nthChild:
97
+ position: 1
98
+ ofRule:
99
+ not:
100
+ kind: comment
101
+ regex: >-
102
+ (?i)^["'`](?:\s|(?-i:\\[nrt])|/\*[\s\S]*?\*/|--[^\n]*(?:\n|(?-i:\\[nr])|$))*(?:SELECT\b[\s\S]*(?:\bFROM\b|\$\{)|INSERT\s+INTO\b|UPDATE\s+[\s\S]*\bSET\b|DELETE\s+FROM\b|CREATE\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|DROP\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|ALTER\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|GRANT\b|REVOKE\b|WITH\b[\s\S]*\bSELECT\b|MERGE\s+INTO\b|TRUNCATE\s+TABLE\b|REPLACE\s+INTO\b)
103
+ constraints:
104
+ SQL:
105
+ any:
106
+ - all:
107
+ - kind: binary_expression
108
+ - not:
109
+ all:
110
+ - has:
111
+ field: left
112
+ kind: string
113
+ - has:
114
+ field: right
115
+ kind: string
116
+ - all:
117
+ - kind: template_string
118
+ - has:
119
+ kind: template_substitution
@@ -0,0 +1,119 @@
1
+ id: no-sql-in-code-execute
2
+ language: TypeScript
3
+ message: "Raw SQL string in code — use query builder or ORM"
4
+ severity: warning
5
+ note: |
6
+ Raw SQL strings built via concatenation or template substitution are
7
+ error-prone and open to injection. Use a query builder (knex, drizzle)
8
+ or ORM (prisma, typeorm), or pass the value as a bind parameter.
9
+
10
+ This rule holds only the `.execute` arms; `.query` stays in
11
+ `no-sql-in-code` / `no-sql-in-code-js` with master's keyword gate. Both
12
+ read `$SQL` the same way: a `binary_expression` (string concatenation,
13
+ e.g. `"SELECT ... " + id`) or a template string with at least one
14
+ `${...}` substitution — the shapes that interpolate a runtime value into
15
+ the query text. A plain string literal, including one with a `?`
16
+ placeholder passed beside a params array, is not flagged (#1806).
17
+
18
+ 2026-10-24 (#1828): `$DB.execute(...)` is the same sink as
19
+ `$DB.query(...)` (mysql2 and oracledb both take `execute(sql, params)`),
20
+ so it gets 1-arg and `, $$$REST` arms, plus their `?.` forms. `execute`
21
+ is also a common task, command and job method name, and the keyword
22
+ `has` on the `.query` arms matches a keyword anywhere in the call: the
23
+ callee-name false-positive class #2909 fixed in the tree-sitter
24
+ `sql-injection` rule. The `.execute` arms therefore use that fix's
25
+ prefix test instead (`ts_sql_injection_sink` in
26
+ clients/tree-sitter-client.ts): the first argument's text (the first
27
+ child of `arguments` that is not a comment) must start with a quote or
28
+ backtick, then optional whitespace and SQL comments, then a statement
29
+ from the sibling's alternation. The test reads the first argument only,
30
+ as the sibling reads only the template, so a later `{ set: ... }` or
31
+ `from` cannot complete an `UPDATE` or `SELECT`.
32
+
33
+ Severity is `warning`, not `error` (#4804 review): statement-shaped
34
+ English still matches, because the alternation accepts it and an
35
+ ast-grep rule has no receiver test. `acl.execute("grant " + role)`,
36
+ `search.execute("create index " + field)`,
37
+ `config.execute("merge into " + base)`, `"delete from " + cacheKey` and
38
+ `"select " + label + " from the list"` all flag. All five are pinned as
39
+ `invalid:` rows, so a later narrowing has a red row to work against.
40
+ Nothing here blocks an edit: this body measures 22 against
41
+ `MAX_BLOCKING_RULE_COMPLEXITY` (8) in
42
+ clients/dispatch/runners/yaml-rule-parser.ts, as master's `.query` body
43
+ already did at 15, so a per-edit dispatch skips the rule. These findings
44
+ arrive from the full-analysis path (`blockingOnly: false`, e.g.
45
+ `pilens_analyze`), where `error` used to present them as blockers.
46
+
47
+ Three edits diverge from the sibling's text
48
+ (clients/tree-sitter-client.ts:4703): a `\b` after `SELECT` and after
49
+ `WITH`, so `"selected from "` and `"Within the select list "` do not
50
+ open a statement; the skip also accepts exactly the `\n`, `\r` and `\t`
51
+ escapes as written in source, case-sensitively so that `\N` does not
52
+ count, which catches `"\nSELECT ..."`; and a `--` comment also ends at
53
+ an escaped `\n` or `\r`, as Postgres ends one at either, so
54
+ `"-- c\nSELECT ..."` is caught (the comment may also run on to a later
55
+ escape).
56
+
57
+ The two differences this leaves against the sibling are accepted
58
+ residuals of this change, not a planned follow-up: the sibling's
59
+ `SELECT` and `WITH` arms carry no word boundary, so
60
+ `job.execute("selected from " + source)` still flags there, and its
61
+ skip accepts real whitespace only, so an escaped `"\nSELECT ..."` is a
62
+ miss there. tests/config/sql-injection-alternation-drift.test.ts keeps
63
+ the rest of the alternation byte-identical to the sibling's copy.
64
+
65
+ Cost (#4804 review, measured on this head for the shared statement
66
+ test): 2.2 to 23.7 ms per scanned file, 231 to 468 of 2,687 JS/TS files
67
+ admitted by the literal prefilter, and 0.46 s to 11.7 s for a
68
+ full-tree scan. The per-file cost does not depend on file size, so it is
69
+ rule compilation per `findAll` call, not traversal; #4807 tracks it and
70
+ does not block this rule. A re-measurement of this split reproduces both
71
+ facts (0.9 to 1.6 ms per file for the `.query` rule, 11 to 12 ms for
72
+ this one, at 28 KiB and 155 KiB).
73
+
74
+ The sibling's other test is out of reach for an ast-grep rule: when the
75
+ prefix test fails, it still flags a template whose receiver it follows
76
+ through same-file declarations to an import from a known SQL package, so
77
+ that is a second way to flag, not a filter.
78
+
79
+ Not caught through `execute`: a statement split between its first two
80
+ tokens (`"DELETE " + "FROM t ..."`), SQL text that opens with `${...}`,
81
+ a parenthesized argument or one that starts with a variable, whitespace
82
+ written as `\u000a`, `\x0a` or a backslash line continuation, a
83
+ FROM-less SELECT built by concatenation (`"SELECT pg_sleep(" + n + ")"`),
84
+ and statements the alternation does not list (`INSERT IGNORE INTO`,
85
+ `INSERT OR REPLACE INTO`).
86
+ rule:
87
+ all:
88
+ - any:
89
+ - pattern: $DB.execute($SQL)
90
+ - pattern: $DB.execute($SQL, $$$REST)
91
+ - pattern: $DB?.execute($SQL)
92
+ - pattern: $DB?.execute($SQL, $$$REST)
93
+ - has:
94
+ field: arguments
95
+ has:
96
+ nthChild:
97
+ position: 1
98
+ ofRule:
99
+ not:
100
+ kind: comment
101
+ regex: >-
102
+ (?i)^["'`](?:\s|(?-i:\\[nrt])|/\*[\s\S]*?\*/|--[^\n]*(?:\n|(?-i:\\[nr])|$))*(?:SELECT\b[\s\S]*(?:\bFROM\b|\$\{)|INSERT\s+INTO\b|UPDATE\s+[\s\S]*\bSET\b|DELETE\s+FROM\b|CREATE\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|DROP\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|ALTER\s+(?:OR\s+REPLACE\s+|TEMP(?:ORARY)?\s+|UNIQUE\s+|MATERIALIZED\s+)*(?:TABLE|INDEX|VIEW|SCHEMA|DATABASE|TRIGGER|FUNCTION|PROCEDURE|SEQUENCE|TYPE|EXTENSION)\b|GRANT\b|REVOKE\b|WITH\b[\s\S]*\bSELECT\b|MERGE\s+INTO\b|TRUNCATE\s+TABLE\b|REPLACE\s+INTO\b)
103
+ constraints:
104
+ SQL:
105
+ any:
106
+ - all:
107
+ - kind: binary_expression
108
+ - not:
109
+ all:
110
+ - has:
111
+ field: left
112
+ kind: string
113
+ - has:
114
+ field: right
115
+ kind: string
116
+ - all:
117
+ - kind: template_string
118
+ - has:
119
+ kind: template_substitution
@@ -10,9 +10,12 @@ note: |
10
10
  syntactically-certain `error`-level calls (open/json/os/shutil).
11
11
 
12
12
  Excluded as already-safe by construction: a numeric literal argument
13
- (`int(3.7)`), and an argument that is itself a call to `int()`/
13
+ (`int(3.7)`), an argument that is itself a call to `int()`/
14
14
  `float()`/`Decimal()` (already-converted, or a `Decimal` — which raises
15
- `decimal.InvalidOperation`, not `ValueError`, and is out of scope here).
15
+ `decimal.InvalidOperation`, not `ValueError`, and is out of scope here),
16
+ and a call to a builtin that returns a number or raises `TypeError`:
17
+ `round()`, `len()`, `abs()`, `sum()`, `ord()` (#4840). The match is by
18
+ name, so a local that shadows one of these names is exempt too.
16
19
 
17
20
  Residual, undecidable false positive: a call whose argument is a typed
18
21
  parameter already known to be numeric, e.g.
@@ -42,3 +45,11 @@ rule:
42
45
  - pattern: Decimal($$$)
43
46
  - pattern: int($$$)
44
47
  - pattern: float($$$)
48
+ # #4840: round() and len() always return a number; abs(), sum()
49
+ # and ord() too (#4841 review F4). min()/max() are not: they
50
+ # return their argument's type.
51
+ - pattern: round($$$)
52
+ - pattern: len($$$)
53
+ - pattern: abs($$$)
54
+ - pattern: sum($$$)
55
+ - pattern: ord($$$)
@@ -417,7 +417,8 @@
417
417
  "canonical_concept": "sql-in-code-literal",
418
418
  "severity_default": "warning",
419
419
  "confidence": "medium",
420
- "status": "active"
420
+ "status": "active",
421
+ "allow_overlap": true
421
422
  },
422
423
  {
423
424
  "rule_id": "no-sql-in-code-js",
@@ -428,6 +429,29 @@
428
429
  "canonical_concept": "sql-in-code-literal",
429
430
  "severity_default": "warning",
430
431
  "confidence": "medium",
432
+ "status": "active",
433
+ "allow_overlap": true
434
+ },
435
+ {
436
+ "rule_id": "no-sql-in-code-execute",
437
+ "engine": "ast-grep",
438
+ "language": "typescript",
439
+ "family": "security",
440
+ "scope": "file",
441
+ "canonical_concept": "sql-in-code-literal",
442
+ "severity_default": "warning",
443
+ "confidence": "medium",
444
+ "status": "active"
445
+ },
446
+ {
447
+ "rule_id": "no-sql-in-code-execute-js",
448
+ "engine": "ast-grep",
449
+ "language": "javascript",
450
+ "family": "security",
451
+ "scope": "file",
452
+ "canonical_concept": "sql-in-code-literal",
453
+ "severity_default": "warning",
454
+ "confidence": "medium",
431
455
  "status": "active"
432
456
  },
433
457
  {
@@ -19,7 +19,6 @@ import fs from "node:fs";
19
19
  import os from "node:os";
20
20
  import path from "node:path";
21
21
  import readline from "node:readline";
22
- import { fileURLToPath } from "node:url";
23
22
  import { minimatch } from "minimatch";
24
23
 
25
24
  const DEFAULT_ROOT = path.join(os.homedir(), ".pi-lens");
@@ -222,6 +221,7 @@ function createState(files) {
222
221
  toolResults: counter(),
223
222
  phaseCounts: counter(),
224
223
  phaseTimeouts: counter(),
224
+ skillsResolved: counter(),
225
225
  // D1: every latency row timestamp (ms) in window, for the coverage-gap
226
226
  // scan. Sorted after all files are read.
227
227
  rowTs: [],
@@ -475,6 +475,14 @@ async function analyzeLatency(files, state) {
475
475
  } else if (entry.type === "phase") {
476
476
  const phase = entry.phase ?? "unknown";
477
477
  state.latency.phaseCounts.inc(phase);
478
+ if (phase === "skills_resolved") {
479
+ // A non-string or empty status is malformed: count it as unknown rather
480
+ // than render a blank label or [object Object].
481
+ const status = entry.metadata?.status;
482
+ state.latency.skillsResolved.inc(
483
+ typeof status === "string" && status !== "" ? status : "unknown",
484
+ );
485
+ }
478
486
  if (phase.endsWith("_timeout")) state.latency.phaseTimeouts.inc(phase);
479
487
  if (phase === "test_runner_verdict_delivery") {
480
488
  const sessionId = entry.metadata?.sessionId ?? "unknown";
@@ -2631,6 +2639,7 @@ function buildReport(state) {
2631
2639
  toolResults: state.latency.toolResults.toJSON(),
2632
2640
  phaseCounts: state.latency.phaseCounts.top(limit),
2633
2641
  phaseTimeouts: state.latency.phaseTimeouts.toJSON(),
2642
+ skillsResolved: state.latency.skillsResolved.toJSON(),
2634
2643
  workspaceDiagnostics: {
2635
2644
  started: ws.started,
2636
2645
  completed: ws.completed,
@@ -2872,6 +2881,11 @@ function printReport(report) {
2872
2881
  report.diagnostics.byFile,
2873
2882
  (x) => `${x.count.toString().padStart(5)} ${x.key}`,
2874
2883
  );
2884
+ section(
2885
+ "Skills resolution",
2886
+ Object.entries(report.latency.skillsResolved),
2887
+ ([status, count]) => `${count.toString().padStart(5)} ${status}`,
2888
+ );
2875
2889
  section(
2876
2890
  "Runner statuses",
2877
2891
  report.latency.runnerStatus,
@@ -3025,7 +3039,3 @@ function formatExample(ex) {
3025
3039
  if (!bits.length && ex.key) bits.push(`${ex.count} × ${ex.key}`);
3026
3040
  return bits.join(" ");
3027
3041
  }
3028
-
3029
- if (process.argv[1] === fileURLToPath(import.meta.url) && args.help) {
3030
- printHelp();
3031
- }
@@ -0,0 +1,27 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ // Whether selfUrl (import.meta.url) is the process entry point. Resolve both
5
+ // paths: Node normally resolves the module URL but leaves argv[1] symlinked;
6
+ // --preserve-symlinks-main keeps the URL symlinked too (#4086, #4096).
7
+ // native realpath also canonicalises Windows casing and short-name spellings.
8
+ // An absent argv path means an import (node -e, stdin, or a removed launcher).
9
+ // An unresolvable module URL throws so a broken CLI cannot silently succeed.
10
+ export function isMainModule(
11
+ selfUrl,
12
+ { argv1 = process.argv[1], realpath = realpathSync.native } = {},
13
+ ) {
14
+ let invoked;
15
+ try {
16
+ invoked = realpath(argv1);
17
+ } catch {
18
+ return false;
19
+ }
20
+ try {
21
+ return invoked === realpath(fileURLToPath(selfUrl));
22
+ } catch (error) {
23
+ throw new Error(
24
+ `[is-main-module] cannot resolve the entry-point path of ${selfUrl}: ${error instanceof Error ? error.message : error}`,
25
+ );
26
+ }
27
+ }