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.
- package/CHANGELOG.md +477 -0
- package/README.md +45 -3
- package/config/biome/core.jsonc +3 -3
- package/config/dependency-cruiser-eager-allowlist.json +1 -0
- package/dist/{chunk-UBOQLVT2.js → chunk-2DDDCJDL.js} +4 -4
- package/dist/{chunk-RKKOYPRA.js → chunk-2DMLM3ZO.js} +13 -15
- package/dist/chunk-2F47TQOA.js +73 -0
- package/dist/{chunk-O4NWQT6I.js → chunk-2PHMIAKO.js} +4 -4
- package/dist/{chunk-DGUKIYSI.js → chunk-2RLWJO5K.js} +8 -10
- package/dist/{chunk-S67KYG37.js → chunk-2X4VLOCC.js} +2 -2
- package/dist/{chunk-TIQ2PKDW.js → chunk-3MYEA7QD.js} +4 -4
- package/dist/{chunk-3DA2JDOL.js → chunk-3WEPUD2V.js} +551 -203
- package/dist/{chunk-AMERCH6V.js → chunk-4AVZ3TG7.js} +15 -16
- package/dist/{chunk-IYNJ6YPZ.js → chunk-4PCQCU47.js} +4 -4
- package/dist/chunk-4WX4CTUE.js +57 -0
- package/dist/{chunk-P63GXC37.js → chunk-5APMQ2IJ.js} +31 -4
- package/dist/{chunk-ZIVJBOO3.js → chunk-5CV5ITZF.js} +2 -2
- package/dist/{chunk-6DLWKFEX.js → chunk-5ZR3APIM.js} +41 -42
- package/dist/{chunk-XTBDCR27.js → chunk-63RIVFQI.js} +4 -4
- package/dist/{chunk-GSLNCYGG.js → chunk-75SY4F24.js} +13 -14
- package/dist/{chunk-U44DJXQP.js → chunk-7RQXA5GG.js} +15 -18
- package/dist/chunk-A3YNG5KP.js +45 -0
- package/dist/{chunk-5OFV52AM.js → chunk-AE37FEGH.js} +1 -1
- package/dist/{chunk-BWD5EPKO.js → chunk-AMXIUN2R.js} +4 -6
- package/dist/{chunk-3KAZU3VR.js → chunk-ARD426WI.js} +2 -2
- package/dist/{chunk-BW5KFIQC.js → chunk-AWQWXSW4.js} +1 -0
- package/dist/{chunk-YH5MVY2U.js → chunk-BHUWL2Y3.js} +7 -7
- package/dist/{chunk-CT4MN5IU.js → chunk-BI5LAQ3Y.js} +353 -359
- package/dist/{chunk-KAPJINKN.js → chunk-BM5GS6ZH.js} +2 -2
- package/dist/{chunk-TLX72JTG.js → chunk-BWYQUPOS.js} +1 -1
- package/dist/chunk-CFRQMBGP.js +49 -0
- package/dist/{chunk-RMLC67LF.js → chunk-CJYKEW2L.js} +2 -30
- package/dist/chunk-CKEQFGLT.js +32 -0
- package/dist/{chunk-IWDLU6K3.js → chunk-DC4CFXM5.js} +4 -6
- package/dist/{chunk-ZVUL7QYY.js → chunk-DMSLNKF7.js} +29 -32
- package/dist/{chunk-KN35K52N.js → chunk-DQXSPYRI.js} +3 -3
- package/dist/{chunk-HYGZEMX6.js → chunk-EVDGNG4F.js} +11 -5
- package/dist/{chunk-SRYEJNES.js → chunk-F5Z6URKM.js} +2 -2
- package/dist/{chunk-UMS2MFPZ.js → chunk-F6X3YJWD.js} +2 -3
- package/dist/{chunk-XYURS6EN.js → chunk-FA5LDARD.js} +15 -17
- package/dist/{chunk-24AKHFGP.js → chunk-FFL3A2VP.js} +6 -6
- package/dist/chunk-FJIVKLPH.js +31 -0
- package/dist/chunk-G2B7F6ZU.js +88 -0
- package/dist/{chunk-US7ECLD7.js → chunk-GAACZY6R.js} +131 -41
- package/dist/{chunk-MZGQNL3Y.js → chunk-GMTFDAOK.js} +12 -13
- package/dist/{chunk-VOOAPROD.js → chunk-GNSIWBAT.js} +3 -3
- package/dist/chunk-GTAI2J6U.js +27 -0
- package/dist/{chunk-RVK72CZX.js → chunk-GZE7WOI4.js} +1362 -459
- package/dist/{chunk-IUE7SSKV.js → chunk-H7HTEQUZ.js} +13 -7
- package/dist/{chunk-EUXZEFTV.js → chunk-HK6JVFZC.js} +3 -3
- package/dist/chunk-IPDG45G5.js +26 -0
- package/dist/{chunk-5HSRT26B.js → chunk-J6JP25XU.js} +16 -15
- package/dist/{chunk-HWCCCQNX.js → chunk-JL6CXUMW.js} +13 -6
- package/dist/{chunk-EBC36LNN.js → chunk-K2YGBXOA.js} +17 -17
- package/dist/{chunk-WMYE35PX.js → chunk-KLQVC3XC.js} +7 -5
- package/dist/{chunk-ATKJFDQN.js → chunk-KSR7RGQY.js} +12 -14
- package/dist/{chunk-POMLXPMY.js → chunk-KXF5R4UN.js} +1 -1
- package/dist/{chunk-LLJNQKQW.js → chunk-LEJOJDXL.js} +20 -13
- package/dist/{chunk-JUKMK5Y4.js → chunk-MA77RSFN.js} +10 -11
- package/dist/{chunk-GAQ7OQG6.js → chunk-MKVZQUEG.js} +85 -96
- package/dist/{chunk-2EECBNC5.js → chunk-MN7MHUXQ.js} +75 -0
- package/dist/{chunk-DEL2U6CM.js → chunk-MT6BVNFW.js} +16 -14
- package/dist/chunk-NDMCVUYK.js +507 -0
- package/dist/{chunk-HRNHZA3N.js → chunk-NIU2IPC5.js} +12 -16
- package/dist/{chunk-AGSS7277.js → chunk-NNKXDXXS.js} +7 -24
- package/dist/{chunk-V35JG4JB.js → chunk-OJLTLYHB.js} +152 -334
- package/dist/{chunk-J6MPGQTS.js → chunk-OLAWH5UQ.js} +81 -15
- package/dist/{chunk-T57LYLZT.js → chunk-OOU2WZZE.js} +1 -1
- package/dist/{chunk-CYRKQRPM.js → chunk-OSTKYB55.js} +2 -4
- package/dist/chunk-P4QNXS6I.js +27 -0
- package/dist/chunk-PKES3ISE.js +297 -0
- package/dist/{chunk-ROYSX2S5.js → chunk-PO45POGF.js} +2 -2
- package/dist/{chunk-T7FEBKXN.js → chunk-PPIBVH4R.js} +7 -9
- package/dist/{chunk-3RKP3FMS.js → chunk-PQJFG24Z.js} +295 -23
- package/dist/{chunk-KUA4OJ5Y.js → chunk-Q3UZHW6N.js} +846 -350
- package/dist/{chunk-N5FLEO7W.js → chunk-Q4EMRFNA.js} +37 -37
- package/dist/{chunk-5IUSNGOC.js → chunk-Q4FCYCRE.js} +28 -21
- package/dist/chunk-Q6D6VMI4.js +22 -0
- package/dist/{chunk-UZ2XCLYS.js → chunk-QGSTQH4D.js} +8 -8
- package/dist/{chunk-DUO2TU77.js → chunk-RZOXUSPC.js} +10 -4
- package/dist/{chunk-JMYYOTQG.js → chunk-S26LC76R.js} +13 -1
- package/dist/{chunk-GMX5OS7B.js → chunk-S67UJDGQ.js} +11 -12
- package/dist/chunk-SCIUNBPF.js +44 -0
- package/dist/{chunk-RKBXZN3A.js → chunk-SJJYRZB4.js} +2 -2
- package/dist/chunk-SXGD4ANG.js +25 -0
- package/dist/{chunk-YCWYO6TQ.js → chunk-T7FTXGS3.js} +48 -45
- package/dist/{chunk-FM4RDMKT.js → chunk-TIQJPRDD.js} +115 -61
- package/dist/{chunk-XHJBS436.js → chunk-TIYGSODX.js} +25 -25
- package/dist/{chunk-S2HEXIWI.js → chunk-U2SDMG7C.js} +10 -6
- package/dist/{chunk-2KXTHF3M.js → chunk-U6OC3QEM.js} +253 -33
- package/dist/{chunk-AWSCPCN2.js → chunk-UCGQT677.js} +19 -19
- package/dist/chunk-UHGF5UT5.js +32 -0
- package/dist/{chunk-JW3YWBVB.js → chunk-UN4TEBWN.js} +17 -19
- package/dist/{chunk-ZHH37KZL.js → chunk-V3APN3DY.js} +17 -17
- package/dist/{chunk-ED36RF6Y.js → chunk-V63BC55Q.js} +1 -1
- package/dist/{chunk-XBJVAEEO.js → chunk-VG5JS5SW.js} +3 -2
- package/dist/{chunk-W66O5E25.js → chunk-VPBIMOAQ.js} +13 -15
- package/dist/chunk-VQH24FIP.js +37 -0
- package/dist/{chunk-YNE3RP52.js → chunk-VSFLRN5Y.js} +8 -1
- package/dist/{chunk-7D6L4MTX.js → chunk-W2V54OCL.js} +3 -3
- package/dist/{chunk-2FN63LPV.js → chunk-W5LGKNET.js} +13 -14
- package/dist/{chunk-IQWN5JCP.js → chunk-W5R5SABV.js} +13 -14
- package/dist/{chunk-R3T7CLQ2.js → chunk-WIZWZR4C.js} +41 -41
- package/dist/{chunk-TOY6QKOH.js → chunk-WQOIR3QY.js} +17 -17
- package/dist/{chunk-Y6GZHWSJ.js → chunk-XAIT2YGS.js} +6 -6
- package/dist/chunk-XCUHKYCQ.js +23 -0
- package/dist/{chunk-GSM5UU7A.js → chunk-XQCSWV2G.js} +44 -35
- package/dist/{chunk-OHKJ7PQF.js → chunk-YBSONGSZ.js} +43 -39
- package/dist/{chunk-GXFV6MYU.js → chunk-YISME6ON.js} +72 -39
- package/dist/chunk-YRD4ISED.js +30 -0
- package/dist/{chunk-SD4I7ZO4.js → chunk-YSBHPOY6.js} +43 -53
- package/dist/{chunk-QBFBRV2B.js → chunk-Z2XAOKHK.js} +4 -2
- package/dist/{chunk-5VSF4UUQ.js → chunk-Z7IGUAXL.js} +34 -39
- package/dist/{chunk-MPNJLASA.js → chunk-ZKXQKGWZ.js} +10 -13
- package/dist/{chunk-J64T55EI.js → chunk-ZQ6NZZTB.js} +75 -9
- package/dist/chunk-ZUUI3ZSA.js +38 -0
- package/dist/{chunk-7HXE67BN.js → chunk-ZYNI26MI.js} +2 -2
- package/dist/index.js +32674 -27567
- package/dist/mcp/analyze-cli.js +11 -12
- package/dist/mcp/cli.js +46 -45
- package/dist/mcp/server.js +1210 -574
- package/dist/mcp/worker.js +65 -65
- package/dist/probes/installer.js +21 -23
- package/docs/adr/0010-trace-validation-session-lifecycle.md +390 -0
- package/docs/adr/README.md +1 -0
- package/docs/agent-tools.md +28 -7
- package/docs/ast-grep_rules_catalog.md +5 -3
- package/docs/configuration.md +12 -1
- package/docs/defect-shapes.md +738 -0
- package/docs/engineering-principles.md +12 -0
- package/docs/environment-variables.md +20 -0
- package/docs/features.md +16 -1
- package/docs/globalconfig.md +37 -8
- package/docs/invariants/caches-stores.md +30 -0
- package/docs/invariants/dispatch-runners.md +164 -0
- package/docs/invariants/git-guard-host.md +53 -0
- package/docs/invariants/language-config.md +31 -0
- package/docs/invariants/lsp-trust-exec.md +286 -0
- package/docs/invariants/paths-os.md +59 -0
- package/docs/invariants/session-telemetry.md +74 -0
- package/docs/lsp-capability-matrix.md +105 -12
- package/docs/lsp-idle-eviction.md +37 -18
- package/docs/pi-lens-fixer.md +24 -2
- package/docs/pi-lens-investigator.md +14 -0
- package/docs/pi-lens-merge-policy.md +32 -17
- package/docs/pi-lens-monitor.md +66 -10
- package/docs/pi-lens-orchestration.md +41 -0
- package/docs/pi-lens-release.md +20 -0
- package/docs/pi-lens-retro.md +5 -4
- package/docs/pi-lens-reviewer.md +54 -7
- package/docs/pi-lens-subagent.md +10 -3
- package/docs/release-qa-baseline.md +19 -7
- package/docs/servercapabilities.md +47 -47
- package/docs/settings.md +9 -5
- package/docs/subagent-compat.md +1 -1
- package/docs/usage.md +1 -0
- package/package.json +8 -5
- package/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
- package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
- package/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
- package/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
- package/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
- package/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
- package/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
- package/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
- package/rules/rule-catalog.json +25 -1
- package/scripts/analyze-pi-lens-logs.mjs +15 -5
- package/scripts/lib/is-main-module.mjs +27 -0
- package/scripts/lib/scratch-home-env.mjs +21 -0
- package/scripts/rpc-load-check.mjs +4 -6
- package/scripts/warm-loader-cache.mjs +2 -5
- package/dist/chunk-3PTHXJXR.js +0 -28
- package/dist/chunk-3QED2P4V.js +0 -31
- package/dist/chunk-5WRPDP2A.js +0 -47
- package/dist/chunk-ABBOA7UD.js +0 -157
- package/dist/chunk-CUHSHSB6.js +0 -273
- package/dist/chunk-GL5LUMZE.js +0 -51
- package/dist/chunk-HAD7QRQI.js +0 -30
- package/dist/chunk-JORED7EX.js +0 -44
- package/dist/chunk-KYUB6QDC.js +0 -72
- package/dist/chunk-LZSEQW6A.js +0 -57
- package/dist/chunk-M2IFVFWU.js +0 -79
- package/dist/chunk-M2UD3LPU.js +0 -88
- package/dist/chunk-MBKQHGA7.js +0 -39
- package/dist/chunk-R7YOCSNV.js +0 -23
- package/dist/chunk-SKAMFC7A.js +0 -28
- package/dist/chunk-SYE6T2EB.js +0 -28
- package/dist/chunk-TRETHTQO.js +0 -26
- package/dist/chunk-UA7ZXYDR.js +0 -184
- package/dist/chunk-XTFDJI3T.js +0 -24
- package/dist/chunk-Z3CCVDUB.js +0 -76
|
@@ -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:`
|
|
16
|
-
plain `stopBy: end` this rule shipped with originally)
|
|
17
|
-
|
|
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
|
-
|
|
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)`),
|
|
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($$$)
|
package/rules/rule-catalog.json
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The home pin an operator script or gate gives every child it spawns (#4789,
|
|
5
|
+
* AGENTS.md shape 82: one home variable pinned, the rest left at the real
|
|
6
|
+
* home). `home` becomes HOME and USERPROFILE (`os.homedir()`'s source on
|
|
7
|
+
* Windows), the three XDG base directories sit under it, and `lensHome` is
|
|
8
|
+
* PI_LENS_HOME (default: `home`). Pure: no I/O and no `process.env` reads, so
|
|
9
|
+
* the caller decides whether the pin lands in a child env object or in
|
|
10
|
+
* `process.env` itself.
|
|
11
|
+
*/
|
|
12
|
+
export function scratchHomeEnv(home, lensHome = home) {
|
|
13
|
+
return {
|
|
14
|
+
HOME: home,
|
|
15
|
+
USERPROFILE: home,
|
|
16
|
+
XDG_CONFIG_HOME: path.join(home, ".config"),
|
|
17
|
+
XDG_CACHE_HOME: path.join(home, ".cache"),
|
|
18
|
+
XDG_DATA_HOME: path.join(home, ".local", "share"),
|
|
19
|
+
PI_LENS_HOME: lensHome,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -55,7 +55,8 @@ import * as fs from "node:fs";
|
|
|
55
55
|
import * as http from "node:http";
|
|
56
56
|
import * as os from "node:os";
|
|
57
57
|
import * as path from "node:path";
|
|
58
|
-
import {
|
|
58
|
+
import { isMainModule } from "./lib/is-main-module.mjs";
|
|
59
|
+
import { scratchHomeEnv } from "./lib/scratch-home-env.mjs";
|
|
59
60
|
import {
|
|
60
61
|
parseNdjsonEntries,
|
|
61
62
|
phaseWasLogged,
|
|
@@ -367,7 +368,7 @@ export async function run(piBin, { extension, failWorker }) {
|
|
|
367
368
|
const env = {
|
|
368
369
|
...process.env,
|
|
369
370
|
PI_CODING_AGENT_DIR: agentDir,
|
|
370
|
-
|
|
371
|
+
...scratchHomeEnv(path.join(scratch, "home"), lensHome),
|
|
371
372
|
PI_OFFLINE: "1",
|
|
372
373
|
PI_SKIP_VERSION_CHECK: "1",
|
|
373
374
|
};
|
|
@@ -578,10 +579,7 @@ async function main(argv) {
|
|
|
578
579
|
return result.code;
|
|
579
580
|
}
|
|
580
581
|
|
|
581
|
-
if (
|
|
582
|
-
process.argv[1] &&
|
|
583
|
-
import.meta.url === pathToFileURL(process.argv[1]).href
|
|
584
|
-
) {
|
|
582
|
+
if (isMainModule(import.meta.url)) {
|
|
585
583
|
main(process.argv.slice(2)).then(
|
|
586
584
|
(code) => process.exit(code),
|
|
587
585
|
(err) => {
|
|
@@ -27,6 +27,7 @@ import * as os from "node:os";
|
|
|
27
27
|
import * as path from "node:path";
|
|
28
28
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
29
29
|
import { HOST_PROVIDED_PACKAGES } from "./lib/host-provided-deps.mjs";
|
|
30
|
+
import { isMainModule } from "./lib/is-main-module.mjs";
|
|
30
31
|
import {
|
|
31
32
|
appendBounded,
|
|
32
33
|
buildStubAliases,
|
|
@@ -226,10 +227,6 @@ export async function run(work = main) {
|
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
|
|
230
|
-
const invokedDirectly =
|
|
231
|
-
typeof invokedPath === "string" &&
|
|
232
|
-
pathToFileURL(path.resolve(invokedPath)).href === import.meta.url;
|
|
233
|
-
if (invokedDirectly) {
|
|
230
|
+
if (isMainModule(import.meta.url)) {
|
|
234
231
|
await run();
|
|
235
232
|
}
|
package/dist/chunk-3PTHXJXR.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
GovulncheckClient,
|
|
4
|
-
parseGovulncheckJson
|
|
5
|
-
} from "./chunk-IUE7SSKV.js";
|
|
6
|
-
import "./chunk-S67KYG37.js";
|
|
7
|
-
import "./chunk-TIQ2PKDW.js";
|
|
8
|
-
import "./chunk-3KAZU3VR.js";
|
|
9
|
-
import "./chunk-P63GXC37.js";
|
|
10
|
-
import "./chunk-KUA4OJ5Y.js";
|
|
11
|
-
import "./chunk-BW5KFIQC.js";
|
|
12
|
-
import "./chunk-J6MPGQTS.js";
|
|
13
|
-
import "./chunk-5HSRT26B.js";
|
|
14
|
-
import "./chunk-M2IFVFWU.js";
|
|
15
|
-
import "./chunk-2EECBNC5.js";
|
|
16
|
-
import "./chunk-J64T55EI.js";
|
|
17
|
-
import "./chunk-POMLXPMY.js";
|
|
18
|
-
import "./chunk-JMYYOTQG.js";
|
|
19
|
-
import "./chunk-QBFBRV2B.js";
|
|
20
|
-
import "./chunk-YNE3RP52.js";
|
|
21
|
-
import "./chunk-LJDODBBZ.js";
|
|
22
|
-
import "./chunk-ABBOA7UD.js";
|
|
23
|
-
import "./chunk-3RKP3FMS.js";
|
|
24
|
-
import "./chunk-NXL4FFQQ.js";
|
|
25
|
-
export {
|
|
26
|
-
GovulncheckClient,
|
|
27
|
-
parseGovulncheckJson
|
|
28
|
-
};
|
package/dist/chunk-3QED2P4V.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
calcCyclomaticComplexity,
|
|
4
|
-
functionFactProvider
|
|
5
|
-
} from "./chunk-EUXZEFTV.js";
|
|
6
|
-
import "./chunk-T57LYLZT.js";
|
|
7
|
-
import "./chunk-5W3R6LFT.js";
|
|
8
|
-
import "./chunk-US7ECLD7.js";
|
|
9
|
-
import "./chunk-Z54ZSOBZ.js";
|
|
10
|
-
import "./chunk-GXFV6MYU.js";
|
|
11
|
-
import "./chunk-FM4RDMKT.js";
|
|
12
|
-
import "./chunk-P63GXC37.js";
|
|
13
|
-
import "./chunk-KUA4OJ5Y.js";
|
|
14
|
-
import "./chunk-DUO2TU77.js";
|
|
15
|
-
import "./chunk-J6MPGQTS.js";
|
|
16
|
-
import "./chunk-5HSRT26B.js";
|
|
17
|
-
import "./chunk-M2IFVFWU.js";
|
|
18
|
-
import "./chunk-2EECBNC5.js";
|
|
19
|
-
import "./chunk-J64T55EI.js";
|
|
20
|
-
import "./chunk-POMLXPMY.js";
|
|
21
|
-
import "./chunk-JMYYOTQG.js";
|
|
22
|
-
import "./chunk-QBFBRV2B.js";
|
|
23
|
-
import "./chunk-YNE3RP52.js";
|
|
24
|
-
import "./chunk-LJDODBBZ.js";
|
|
25
|
-
import "./chunk-ABBOA7UD.js";
|
|
26
|
-
import "./chunk-3RKP3FMS.js";
|
|
27
|
-
import "./chunk-NXL4FFQQ.js";
|
|
28
|
-
export {
|
|
29
|
-
calcCyclomaticComplexity,
|
|
30
|
-
functionFactProvider
|
|
31
|
-
};
|