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
@@ -0,0 +1,507 @@
1
+ import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
+ import {
3
+ parseJsonc
4
+ } from "./chunk-7IYC4ENJ.js";
5
+ import {
6
+ extractTomlTableSection,
7
+ hasTomlTable,
8
+ parseTomlScalarString,
9
+ parseTomlStringArray
10
+ } from "./chunk-KX56K73G.js";
11
+ import {
12
+ resolveLanguage
13
+ } from "./chunk-GTDSYEA2.js";
14
+ import {
15
+ getProjectTrustState
16
+ } from "./chunk-EIKRZ32J.js";
17
+ import {
18
+ incrementDegradationCount,
19
+ recordDegradationOnce
20
+ } from "./chunk-FWZRGGGY.js";
21
+ import {
22
+ logExtension
23
+ } from "./chunk-N3PLNNCW.js";
24
+ import {
25
+ logLatency
26
+ } from "./chunk-XWFIHYCH.js";
27
+ import {
28
+ UV_WORKSPACE_EXCLUDE_DIALECT,
29
+ UV_WORKSPACE_MEMBERS_DIALECT,
30
+ matchesWorkspaceMemberPattern,
31
+ realpathOrResolve,
32
+ toPosix,
33
+ walkUpDirs
34
+ } from "./chunk-EWXXLS26.js";
35
+
36
+ // dist/clients/bounded-telemetry.js
37
+ var MAX_TRACKED_TURN_CAPS = 64;
38
+ var turnCounts = /* @__PURE__ */ new Map();
39
+ var latestCountedTurnIndex;
40
+ var retiredThroughTurnIndex = Number.NEGATIVE_INFINITY;
41
+ function admitBounded(phase, identity, options = {}) {
42
+ try {
43
+ let isRisingEdge = true;
44
+ if (options.ledgerKind !== void 0) {
45
+ isRisingEdge = incrementDegradationCount({
46
+ kind: options.ledgerKind,
47
+ subject: identity,
48
+ reason: options.reason ?? phase
49
+ });
50
+ }
51
+ if (options.risingEdgePer !== void 0 && !isRisingEdge)
52
+ return false;
53
+ return admitAgainstTurnCap(phase, options.capPerTurn);
54
+ } catch {
55
+ return true;
56
+ }
57
+ }
58
+ function emitBounded(phase, identity, payload, options = {}) {
59
+ try {
60
+ if (!admitBounded(phase, identity, options))
61
+ return false;
62
+ logLatency({
63
+ ...payload,
64
+ type: payload.type ?? "phase",
65
+ phase,
66
+ // `filePath` is what existing latency.log queries filter on, so a site
67
+ // may keep a coarser one; `metadata.identity` below always carries the
68
+ // full discriminating identity. Aggregation that loses WHICH subject
69
+ // is stuck is the failure AGENTS.md names.
70
+ filePath: payload.filePath ?? identity,
71
+ metadata: { ...payload.metadata, identity }
72
+ });
73
+ return true;
74
+ } catch {
75
+ return false;
76
+ }
77
+ }
78
+ function admitAgainstTurnCap(phase, cap) {
79
+ if (cap === void 0)
80
+ return true;
81
+ if (cap.turnIndex <= retiredThroughTurnIndex)
82
+ return false;
83
+ let counts = turnCounts.get(cap.turnIndex);
84
+ if (!counts) {
85
+ if (turnCounts.size >= MAX_TRACKED_TURN_CAPS) {
86
+ const oldestTrackedTurn = Math.min(...turnCounts.keys());
87
+ if (cap.turnIndex < oldestTrackedTurn)
88
+ return false;
89
+ turnCounts.delete(oldestTrackedTurn);
90
+ retiredThroughTurnIndex = Math.max(retiredThroughTurnIndex, oldestTrackedTurn);
91
+ }
92
+ counts = /* @__PURE__ */ new Map();
93
+ turnCounts.set(cap.turnIndex, counts);
94
+ }
95
+ latestCountedTurnIndex = Math.max(latestCountedTurnIndex ?? cap.turnIndex, cap.turnIndex);
96
+ const used = counts.get(phase) ?? 0;
97
+ if (used >= cap.limit)
98
+ return false;
99
+ counts.set(phase, used + 1);
100
+ return true;
101
+ }
102
+ function resetBoundedTelemetry() {
103
+ turnCounts = /* @__PURE__ */ new Map();
104
+ latestCountedTurnIndex = void 0;
105
+ retiredThroughTurnIndex = Number.NEGATIVE_INFINITY;
106
+ }
107
+
108
+ // dist/clients/python-environment.js
109
+ import { access, readFile } from "node:fs/promises";
110
+ import os from "node:os";
111
+ import path, { dirname, join } from "node:path";
112
+ var UV_WORKSPACE_TABLE = "tool\\.uv\\.workspace";
113
+ async function findUvWorkspace(startDir, homeDir) {
114
+ let walkStart;
115
+ let nearestProject;
116
+ for (const dir of walkUpDirs(startDir, { homeDir })) {
117
+ walkStart ??= dir;
118
+ let content;
119
+ try {
120
+ content = await readFile(path.join(dir, "pyproject.toml"), "utf8");
121
+ } catch {
122
+ continue;
123
+ }
124
+ if (!nearestProject)
125
+ nearestProject = dir;
126
+ if (hasTomlTable(content, UV_WORKSPACE_TABLE)) {
127
+ const workspaceTable = extractTomlTableSection(content, UV_WORKSPACE_TABLE);
128
+ return {
129
+ root: dir,
130
+ explicit: true,
131
+ projectRoot: nearestProject,
132
+ isStartDir: nearestProject === walkStart,
133
+ members: parseTomlStringArray(workspaceTable, "members"),
134
+ exclude: parseTomlStringArray(workspaceTable, "exclude")
135
+ };
136
+ }
137
+ }
138
+ return nearestProject ? {
139
+ root: nearestProject,
140
+ explicit: false,
141
+ projectRoot: nearestProject,
142
+ isStartDir: nearestProject === walkStart,
143
+ members: [],
144
+ exclude: []
145
+ } : void 0;
146
+ }
147
+ function isUvWorkspaceMember(workspace, projectRoot) {
148
+ const relative = toPosix(path.relative(workspace.root, projectRoot));
149
+ if (relative.length === 0 || relative === ".." || relative.startsWith("../") || path.isAbsolute(relative)) {
150
+ return false;
151
+ }
152
+ const matches = (dialect) => (pattern) => matchesWorkspaceMemberPattern(pattern, relative, dialect, () => recordDegradationOnce({
153
+ kind: "workspace-glob-cap",
154
+ subject: String(pattern.length),
155
+ reason: "workspace glob matcher exceeded its memo-table cell cap"
156
+ }));
157
+ return !workspace.exclude.some(matches(UV_WORKSPACE_EXCLUDE_DIALECT)) && workspace.members.some(matches(UV_WORKSPACE_MEMBERS_DIALECT));
158
+ }
159
+ var PROJECT_SOURCED_PYTHON_SOURCES = /* @__PURE__ */ new Set([
160
+ "project-dot-venv",
161
+ "project-venv",
162
+ "uv-workspace"
163
+ ]);
164
+ var AMBIENT_ENVIRONMENT_VARIABLES = {
165
+ "uv-project-environment": "UV_PROJECT_ENVIRONMENT",
166
+ "virtual-env": "VIRTUAL_ENV",
167
+ conda: "CONDA_PREFIX"
168
+ };
169
+ function hasAmbientPythonEnvironment(env = process.env) {
170
+ return Object.values(AMBIENT_ENVIRONMENT_VARIABLES).some((name) => Boolean(env[name]));
171
+ }
172
+ async function detectPythonEnvironment(projectRoot, homeDir = os.homedir(), options = {}) {
173
+ const root = realpathOrResolve(projectRoot);
174
+ const uvWorkspace = await findUvWorkspace(root, homeDir);
175
+ const isProjectRoot = uvWorkspace?.isStartDir === true;
176
+ const memberWorkspaceRoot = isProjectRoot && uvWorkspace.explicit && isUvWorkspaceMember(uvWorkspace, root) ? uvWorkspace.root : void 0;
177
+ const uvEnvironmentRoot = isProjectRoot ? memberWorkspaceRoot ?? uvWorkspace.projectRoot : void 0;
178
+ const uvProjectEnvironment = process.env.UV_PROJECT_ENVIRONMENT;
179
+ const allowAmbient = options.allowAmbient ?? true;
180
+ const isWithinProjectRoot = (candidateRoot) => {
181
+ const relative = path.relative(root, realpathOrResolve(candidateRoot));
182
+ return relative !== ".." && !relative.startsWith(`..${path.sep}`) && // #3871 V1: another Windows drive has no relative path, so
183
+ // `path.relative` returns the absolute target: no `..`, not inside.
184
+ !path.isAbsolute(relative);
185
+ };
186
+ const candidates = [
187
+ ...uvEnvironmentRoot !== void 0 && uvProjectEnvironment ? [
188
+ {
189
+ // `path.resolve` leaves an absolute value untouched and
190
+ // anchors a relative one at the project's workspace root.
191
+ root: path.resolve(uvEnvironmentRoot, uvProjectEnvironment),
192
+ source: "uv-project-environment"
193
+ }
194
+ ] : [],
195
+ ...memberWorkspaceRoot !== void 0 ? [
196
+ {
197
+ root: path.join(memberWorkspaceRoot, ".venv"),
198
+ source: "uv-workspace"
199
+ }
200
+ ] : [],
201
+ { root: process.env.VIRTUAL_ENV, source: "virtual-env" },
202
+ { root: process.env.CONDA_PREFIX, source: "conda" },
203
+ { root: path.join(root, ".venv"), source: "project-dot-venv" },
204
+ { root: path.join(root, "venv"), source: "project-venv" }
205
+ ];
206
+ for (const candidate of candidates) {
207
+ if (!candidate.root)
208
+ continue;
209
+ if (!allowAmbient && candidate.source in AMBIENT_ENVIRONMENT_VARIABLES && !isWithinProjectRoot(candidate.root))
210
+ continue;
211
+ if (PROJECT_SOURCED_PYTHON_SOURCES.has(candidate.source) && getProjectTrustState() !== "trusted") {
212
+ if (recordDegradationOnce({
213
+ kind: "trust-refusal",
214
+ subject: `python-environment:${candidate.root}`,
215
+ reason: `project Python environment refused: pi project trust is ${getProjectTrustState()}`
216
+ })) {
217
+ logExtension({
218
+ subsystem: "project-trust",
219
+ level: "warn",
220
+ message: "project Python environment refused: mark the project trusted in pi or upgrade pi",
221
+ metadata: { source: candidate.source }
222
+ });
223
+ }
224
+ continue;
225
+ }
226
+ const binDir = path.join(candidate.root, process.platform === "win32" ? "Scripts" : "bin");
227
+ const pythonPath = path.join(binDir, process.platform === "win32" ? "python.exe" : "python");
228
+ try {
229
+ await access(pythonPath);
230
+ return {
231
+ root: candidate.root,
232
+ binDir,
233
+ pythonPath,
234
+ source: candidate.source
235
+ };
236
+ } catch {
237
+ }
238
+ }
239
+ return void 0;
240
+ }
241
+ function augmentPythonEnvironment(baseEnvironment, environment) {
242
+ if (!environment)
243
+ return baseEnvironment;
244
+ const inheritedPath = baseEnvironment.PATH ?? baseEnvironment.Path ?? baseEnvironment.path ?? "";
245
+ const augmentedPath = inheritedPath ? `${environment.binDir}${path.delimiter}${inheritedPath}` : environment.binDir;
246
+ const childEnvironment = {
247
+ ...baseEnvironment,
248
+ PATH: augmentedPath,
249
+ VIRTUAL_ENV: environment.root
250
+ };
251
+ if (process.platform === "win32")
252
+ childEnvironment.Path = augmentedPath;
253
+ return childEnvironment;
254
+ }
255
+ function pythonEnvironmentToolCandidates(environment, command) {
256
+ if (!environment)
257
+ return [];
258
+ if (process.platform !== "win32") {
259
+ return [path.join(environment.binDir, command)];
260
+ }
261
+ return [
262
+ path.join(environment.binDir, `${command}.exe`),
263
+ path.join(environment.binDir, `${command}.cmd`),
264
+ path.join(environment.binDir, command)
265
+ ];
266
+ }
267
+ var PYTHON_DECLARATION_CONCURRENCY = 8;
268
+ var PYTHON_COMPILE_VERDICT_SERVER_ID = "python-jedi";
269
+ var PYTHON_COMPILE_VERDICT_FLOOR = { major: 3, minor: 14 };
270
+ function isJediCompileVerdict(diagnostic) {
271
+ const server = diagnostic.serverId ?? diagnostic.tool;
272
+ const source = diagnostic.source ?? diagnostic.rule?.split(":")[0];
273
+ return server === PYTHON_COMPILE_VERDICT_SERVER_ID && source === "compile";
274
+ }
275
+ function isJediCompileVerdictOutranked(diagnostic, declared) {
276
+ if (declared === void 0)
277
+ return false;
278
+ if (!isJediCompileVerdict(diagnostic))
279
+ return false;
280
+ return declared.major > PYTHON_COMPILE_VERDICT_FLOOR.major || declared.major === PYTHON_COMPILE_VERDICT_FLOOR.major && declared.minor >= PYTHON_COMPILE_VERDICT_FLOOR.minor;
281
+ }
282
+ function partitionOutrankedPythonCompileVerdicts(diagnostics, declared) {
283
+ const kept = [];
284
+ let dropped = 0;
285
+ for (const diagnostic of diagnostics) {
286
+ if (isJediCompileVerdictOutranked(diagnostic, declared))
287
+ dropped += 1;
288
+ else
289
+ kept.push(diagnostic);
290
+ }
291
+ return { kept, dropped };
292
+ }
293
+ function recordPythonCompileVerdictDrop(file, declared, dropped) {
294
+ recordDegradationOnce({
295
+ kind: "python-compile-target-mismatch",
296
+ subject: file,
297
+ reason: `${dropped} jedi compile ${dropped === 1 ? "finding" : "findings"} dropped: declared Python ${declared.major}.${declared.minor} (${declared.source}) in ${declared.file}`,
298
+ metadata: {
299
+ declared: `${declared.major}.${declared.minor}`,
300
+ source: declared.source,
301
+ declarationFile: declared.file,
302
+ dropped
303
+ }
304
+ });
305
+ }
306
+ function describePythonCompileWithheld(count, declared) {
307
+ return `${count} python-jedi compile finding${count === 1 ? "" : "s"} withheld: the project declares Python ${declared.major}.${declared.minor} (${declared.source}) in ${declared.file}`;
308
+ }
309
+ var BARE_VERSION_PREFIX = /^v?(\d+)\.(\d+)/i;
310
+ var VERSION_SUFFIX = /^[-+._a-z0-9]*$/i;
311
+ var SPECIFIER_LOWER_BOUND = /^(?:>=|==|~=)\s*v?(\d+)\.(\d+)/;
312
+ var RUFF_LEVEL = /^py(\d)(\d+)$/i;
313
+ function reducePythonVersion(match) {
314
+ if (!match)
315
+ return void 0;
316
+ return { major: Number(match[1]), minor: Number(match[2]) };
317
+ }
318
+ function reduceBarePythonVersion(text) {
319
+ const trimmed = text.trim();
320
+ const prefix = BARE_VERSION_PREFIX.exec(trimmed);
321
+ if (!prefix)
322
+ return void 0;
323
+ if (!VERSION_SUFFIX.test(trimmed.slice(prefix[0].length)))
324
+ return void 0;
325
+ return reducePythonVersion(prefix);
326
+ }
327
+ function reducePythonSpecifier(text) {
328
+ let strongest;
329
+ for (const clause of text.split(",")) {
330
+ const lowerBound = reducePythonVersion(SPECIFIER_LOWER_BOUND.exec(clause.trim()));
331
+ if (!lowerBound)
332
+ continue;
333
+ if (!strongest || lowerBound.major > strongest.major || lowerBound.major === strongest.major && lowerBound.minor > strongest.minor) {
334
+ strongest = lowerBound;
335
+ }
336
+ }
337
+ return strongest ?? reduceBarePythonVersion(text);
338
+ }
339
+ function reduceRuffTargetVersion(text) {
340
+ return reducePythonVersion(RUFF_LEVEL.exec(text.trim()));
341
+ }
342
+ function withSource(level, source, file) {
343
+ return level ? { ...level, source, file } : void 0;
344
+ }
345
+ async function readDeclarationFile(filePath) {
346
+ try {
347
+ return await readFile(filePath, "utf-8");
348
+ } catch (err) {
349
+ const code = err.code;
350
+ if (code === "ENOENT" || code === "ENOTDIR") {
351
+ return void 0;
352
+ }
353
+ recordDegradationOnce({
354
+ kind: "python-target-version-unreadable",
355
+ subject: filePath,
356
+ reason: `Python syntax-level declaration could not be read: ${err instanceof Error ? err.message : String(err)}`
357
+ });
358
+ return void 0;
359
+ }
360
+ }
361
+ function parsePyrightJsonVersion(content) {
362
+ let parsed;
363
+ try {
364
+ parsed = parseJsonc(content);
365
+ } catch {
366
+ return void 0;
367
+ }
368
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
369
+ return void 0;
370
+ }
371
+ const value = parsed.pythonVersion;
372
+ return typeof value === "string" ? reduceBarePythonVersion(value) : void 0;
373
+ }
374
+ async function readRuffTier(dir, pyproject, pyprojectPath) {
375
+ let configPath;
376
+ let config;
377
+ for (const name of [".ruff.toml", "ruff.toml"]) {
378
+ const candidatePath = join(dir, name);
379
+ config = await readDeclarationFile(candidatePath);
380
+ if (config !== void 0) {
381
+ configPath = candidatePath;
382
+ break;
383
+ }
384
+ }
385
+ if (config === void 0) {
386
+ if (pyproject === void 0 || !hasTomlTable(pyproject, String.raw`tool\.ruff`)) {
387
+ return { declaration: void 0, owned: false };
388
+ }
389
+ configPath = pyprojectPath;
390
+ config = extractTomlTableSection(pyproject, String.raw`tool\.ruff`);
391
+ }
392
+ if (configPath === void 0 || config === void 0) {
393
+ return { declaration: void 0, owned: false };
394
+ }
395
+ const target = parseTomlScalarString(config, "target-version");
396
+ return {
397
+ declaration: withSource(target ? reduceRuffTargetVersion(target) : void 0, "ruff-target-version", configPath),
398
+ owned: true
399
+ };
400
+ }
401
+ async function readPyrightTier(dir, pyproject, pyprojectPath) {
402
+ const configPath = join(dir, "pyrightconfig.json");
403
+ const config = await readDeclarationFile(configPath);
404
+ if (config !== void 0) {
405
+ return {
406
+ declaration: withSource(parsePyrightJsonVersion(config), "pyright-python-version", configPath),
407
+ owned: true
408
+ };
409
+ }
410
+ if (pyproject === void 0)
411
+ return { declaration: void 0, owned: false };
412
+ const section = extractTomlTableSection(pyproject, String.raw`tool\.pyright`);
413
+ if (section === void 0)
414
+ return { declaration: void 0, owned: false };
415
+ const raw = parseTomlScalarString(section, "pythonVersion");
416
+ return {
417
+ declaration: withSource(raw ? reduceBarePythonVersion(raw) : void 0, "pyright-python-version", pyprojectPath),
418
+ owned: true
419
+ };
420
+ }
421
+ function readRequiresPythonTier(pyproject, pyprojectPath) {
422
+ if (pyproject === void 0)
423
+ return { declaration: void 0, owned: false };
424
+ const projectSection = extractTomlTableSection(pyproject, "project");
425
+ const raw = projectSection !== void 0 ? parseTomlScalarString(projectSection, "requires-python") : void 0;
426
+ return {
427
+ declaration: withSource(raw ? reducePythonSpecifier(raw) : void 0, "requires-python", pyprojectPath),
428
+ owned: raw !== void 0
429
+ };
430
+ }
431
+ async function readVersionFileTier(dir) {
432
+ const levelFilePath = join(dir, ".python-version");
433
+ const content = await readDeclarationFile(levelFilePath);
434
+ if (content === void 0)
435
+ return { declaration: void 0, owned: false };
436
+ const firstLine = (content.split(/\r?\n/, 1)[0] ?? "").trim();
437
+ return {
438
+ declaration: withSource(reduceBarePythonVersion(firstLine), "python-version-file", levelFilePath),
439
+ owned: true
440
+ };
441
+ }
442
+ var PYTHON_DECLARATION_SOURCES = [
443
+ "ruff-target-version",
444
+ "pyright-python-version",
445
+ "requires-python",
446
+ "python-version-file"
447
+ ];
448
+ async function readPythonDeclarationInDirectory(dir, open) {
449
+ const pyprojectPath = join(dir, "pyproject.toml");
450
+ const pyproject = await readDeclarationFile(pyprojectPath);
451
+ const tiers = [
452
+ ["ruff-target-version", () => readRuffTier(dir, pyproject, pyprojectPath)],
453
+ [
454
+ "pyright-python-version",
455
+ () => readPyrightTier(dir, pyproject, pyprojectPath)
456
+ ],
457
+ [
458
+ "requires-python",
459
+ async () => readRequiresPythonTier(pyproject, pyprojectPath)
460
+ ],
461
+ ["python-version-file", () => readVersionFileTier(dir)]
462
+ ];
463
+ const closed = [];
464
+ for (const [source, read] of tiers) {
465
+ if (!open.has(source))
466
+ continue;
467
+ const { declaration, owned } = await read();
468
+ if (declaration)
469
+ return { declaration, closed: [] };
470
+ if (owned)
471
+ closed.push(source);
472
+ }
473
+ return { declaration: void 0, closed };
474
+ }
475
+ async function detectPythonTargetVersion(filePath, homeDir = os.homedir()) {
476
+ if (resolveLanguage(filePath)?.id !== "python")
477
+ return void 0;
478
+ const open = new Set(PYTHON_DECLARATION_SOURCES);
479
+ for (const dir of walkUpDirs(dirname(realpathOrResolve(filePath)), {
480
+ homeDir
481
+ })) {
482
+ const { declaration, closed } = await readPythonDeclarationInDirectory(dir, open);
483
+ if (declaration)
484
+ return declaration;
485
+ for (const source of closed)
486
+ open.delete(source);
487
+ if (open.size === 0)
488
+ return void 0;
489
+ }
490
+ return void 0;
491
+ }
492
+
493
+ export {
494
+ emitBounded,
495
+ resetBoundedTelemetry,
496
+ hasAmbientPythonEnvironment,
497
+ detectPythonEnvironment,
498
+ augmentPythonEnvironment,
499
+ pythonEnvironmentToolCandidates,
500
+ PYTHON_DECLARATION_CONCURRENCY,
501
+ PYTHON_COMPILE_VERDICT_SERVER_ID,
502
+ isJediCompileVerdict,
503
+ partitionOutrankedPythonCompileVerdicts,
504
+ recordPythonCompileVerdictDrop,
505
+ describePythonCompileWithheld,
506
+ detectPythonTargetVersion
507
+ };
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
2
  import {
3
3
  detectFileRole
4
- } from "./chunk-J6MPGQTS.js";
4
+ } from "./chunk-KJJAVH3X.js";
5
5
 
6
6
  // dist/clients/collateral-test-role.js
7
7
  function isTestRoleCollateral(filePath) {
@@ -0,0 +1,73 @@
1
+ import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
+ import {
3
+ adaptLspService,
4
+ getLSPService,
5
+ groupFilesByPrimaryServer,
6
+ hasAuxiliaryLspPublishedForRoot,
7
+ notifyExternalFileChange,
8
+ peekLSPService,
9
+ resetLSPService,
10
+ resyncGitChangedFiles,
11
+ runPerServerGroups
12
+ } from "./chunk-SJHC3BCZ.js";
13
+ import "./chunk-MEFLGBCS.js";
14
+ import "./chunk-XIMYZ3JA.js";
15
+ import "./chunk-7ZS7MC24.js";
16
+ import "./chunk-6XSESGWD.js";
17
+ import "./chunk-3SNDVPOR.js";
18
+ import "./chunk-JWOVP5BL.js";
19
+ import "./chunk-2LDMXL2M.js";
20
+ import "./chunk-FEDWAYDS.js";
21
+ import "./chunk-CPZ5JJW6.js";
22
+ import "./chunk-7IYC4ENJ.js";
23
+ import "./chunk-KX56K73G.js";
24
+ import "./chunk-YWWG4AQA.js";
25
+ import "./chunk-Z54ZSOBZ.js";
26
+ import "./chunk-2Y6OJRSI.js";
27
+ import "./chunk-WUY4BZEP.js";
28
+ import "./chunk-GTDSYEA2.js";
29
+ import "./chunk-6HWVI6MI.js";
30
+ import "./chunk-UL5SXQVX.js";
31
+ import "./chunk-CKEQFGLT.js";
32
+ import "./chunk-NLIVE7L6.js";
33
+ import "./chunk-IEBJF3PN.js";
34
+ import "./chunk-UO66IMVP.js";
35
+ import "./chunk-Q42LJANT.js";
36
+ import "./chunk-APFJKOP6.js";
37
+ import "./chunk-2BEMIWEW.js";
38
+ import "./chunk-IJYGIDF4.js";
39
+ import "./chunk-IL7K66ZQ.js";
40
+ import "./chunk-4FHUGDKU.js";
41
+ import "./chunk-K4SZB56V.js";
42
+ import "./chunk-XI34NWDI.js";
43
+ import "./chunk-5LRUKYFA.js";
44
+ import "./chunk-63NMUNYP.js";
45
+ import "./chunk-CG5V25HX.js";
46
+ import "./chunk-PP2A5V2T.js";
47
+ import "./chunk-S55TEC7I.js";
48
+ import "./chunk-TPYYEDP5.js";
49
+ import "./chunk-AWQWXSW4.js";
50
+ import "./chunk-QYF5S6P6.js";
51
+ import "./chunk-GYRZ72R4.js";
52
+ import "./chunk-KJJAVH3X.js";
53
+ import "./chunk-ZSUX7KEM.js";
54
+ import "./chunk-EIKRZ32J.js";
55
+ import "./chunk-FWZRGGGY.js";
56
+ import "./chunk-N3PLNNCW.js";
57
+ import "./chunk-S26LC76R.js";
58
+ import "./chunk-XWFIHYCH.js";
59
+ import "./chunk-TVZRLTG6.js";
60
+ import "./chunk-LJDODBBZ.js";
61
+ import "./chunk-EWXXLS26.js";
62
+ import "./chunk-NXL4FFQQ.js";
63
+ export {
64
+ adaptLspService,
65
+ getLSPService,
66
+ groupFilesByPrimaryServer,
67
+ hasAuxiliaryLspPublishedForRoot,
68
+ notifyExternalFileChange,
69
+ peekLSPService,
70
+ resetLSPService,
71
+ resyncGitChangedFiles,
72
+ runPerServerGroups
73
+ };
@@ -1,26 +1,27 @@
1
1
  import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
2
2
  import {
3
3
  rootMarkersForFile
4
- } from "./chunk-HRNHZA3N.js";
4
+ } from "./chunk-63NMUNYP.js";
5
5
  import {
6
6
  createGenerationMap,
7
7
  createGenerationSource
8
- } from "./chunk-KUA4OJ5Y.js";
8
+ } from "./chunk-TPYYEDP5.js";
9
9
  import {
10
10
  getDegradationLedgerGeneration,
11
11
  recordDegradationOnce
12
- } from "./chunk-J64T55EI.js";
12
+ } from "./chunk-FWZRGGGY.js";
13
13
  import {
14
14
  logExtension
15
- } from "./chunk-POMLXPMY.js";
15
+ } from "./chunk-N3PLNNCW.js";
16
16
  import {
17
17
  isAtOrAboveHomeDir,
18
18
  isRealGitMarker,
19
19
  isUnderDir,
20
20
  isWindowsPath,
21
21
  nameMatchesMarkerGlob,
22
- normalizeEphemeralMapKey
23
- } from "./chunk-3RKP3FMS.js";
22
+ normalizeEphemeralMapKey,
23
+ realpathOrResolve
24
+ } from "./chunk-EWXXLS26.js";
24
25
 
25
26
  // dist/clients/tool-cwd.js
26
27
  import * as os from "node:os";
@@ -180,11 +181,6 @@ function logRunnerAdvisoryOnce(ctx, tool, root, message) {
180
181
  ctx.log(message, "debug");
181
182
  }
182
183
  function resolveToolCwd(kind, tool, file, ctx) {
183
- const dispatchRoot = path.resolve(ctx.cwd ?? process.cwd());
184
- const absoluteFile = path.resolve(file);
185
- const fileDir = path.dirname(absoluteFile);
186
- const homeDir = ctx.homeDir ?? os.homedir();
187
- const insideDispatch = isUnderDir(absoluteFile, dispatchRoot);
188
184
  if (ctx.serverRoot) {
189
185
  const rootPath = isWindowsPath(ctx.serverRoot) ? path.win32 : path;
190
186
  const serverRoot = rootPath.resolve(ctx.serverRoot);
@@ -192,8 +188,14 @@ function resolveToolCwd(kind, tool, file, ctx) {
192
188
  emitResolution(kind, tool, serverRoot, "server-root");
193
189
  return { cwd: serverRoot };
194
190
  }
191
+ const dispatchRoot = path.resolve(ctx.cwd ?? process.cwd());
192
+ const absoluteFile = realpathOrResolve(file);
193
+ const fileDir = path.dirname(absoluteFile);
194
+ const homeDir = ctx.homeDir ?? os.homedir();
195
+ const homeCeiling = realpathOrResolve(homeDir);
196
+ const insideDispatch = isUnderDir(absoluteFile, dispatchRoot);
195
197
  const markers = markersFor(kind, tool, absoluteFile, ctx);
196
- const markerResult = markers.length ? findMarkerRoot(fileDir, markers, ctx.allowHomeMarker ? path.parse(homeDir).root : homeDir) : { root: null };
198
+ const markerResult = markers.length ? findMarkerRoot(fileDir, markers, ctx.allowHomeMarker ? path.parse(homeCeiling).root : homeCeiling) : { root: null };
197
199
  const markerRoot = markerResult.root;
198
200
  if (markerRoot && (insideDispatch ? isUnderDir(markerRoot, dispatchRoot) : true)) {
199
201
  const finalReason = `marker:${markerResult.marker ?? markers[0]}`;
@@ -206,11 +208,11 @@ function resolveToolCwd(kind, tool, file, ctx) {
206
208
  }
207
209
  const memo = ctx.toolCwdMemo;
208
210
  if (memo && memo.gitRoot === void 0) {
209
- const gitResult = findMarkerRoot(fileDir, [".git"], homeDir);
211
+ const gitResult = findMarkerRoot(fileDir, [".git"], homeCeiling);
210
212
  memo.gitRoot = gitResult.root && isRealGitMarker(path.join(gitResult.root, ".git")) ? gitResult.root : null;
211
213
  }
212
214
  const gitRoot = memo && memo.gitRoot !== void 0 ? memo.gitRoot : (() => {
213
- const gitResult = findMarkerRoot(fileDir, [".git"], homeDir);
215
+ const gitResult = findMarkerRoot(fileDir, [".git"], homeCeiling);
214
216
  return gitResult.root && isRealGitMarker(path.join(gitResult.root, ".git")) ? gitResult.root : null;
215
217
  })();
216
218
  if (gitRoot && (insideDispatch ? isUnderDir(gitRoot, dispatchRoot) : true)) {