@cydm/pie 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +51 -27
  2. package/dist/builtin/extensions/ask-user/index.js +4 -4
  3. package/dist/builtin/extensions/cron/index.js +906 -158
  4. package/dist/builtin/extensions/im-forward/README.md +4 -2
  5. package/dist/builtin/extensions/im-forward/index.js +6822 -3951
  6. package/dist/builtin/extensions/memory/index.js +76 -28
  7. package/dist/builtin/extensions/pie-ipc/README.md +2 -2
  8. package/dist/builtin/extensions/pie-ipc/index.js +282 -58
  9. package/dist/builtin/extensions/pie-proc/README.md +7 -7
  10. package/dist/builtin/extensions/pie-proc/index.js +227 -75
  11. package/dist/builtin/extensions/plan-mode/index.js +5 -5
  12. package/dist/builtin/extensions/subagent/index.js +8 -8
  13. package/dist/builtin/extensions/todo/index.js +4 -4
  14. package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +26 -24
  15. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +199 -121
  16. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  17. package/dist/builtin/skills/chrome-devtools-axi/chunk-HAUDUMDO.js +795 -0
  18. package/dist/builtin/skills/chrome-devtools-axi/{cli-ZE754CTH.js → cli-K7ESY3XD.js} +433 -255
  19. package/dist/builtin/skills/computer-use-axi/SKILL.md +25 -8
  20. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +293 -64
  21. package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +2 -2
  22. package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +451 -43
  23. package/dist/chunks/{chunk-3W3SXVPB.js → chunk-4UIUMTHG.js} +993 -371
  24. package/dist/chunks/chunk-6WKBQZWM.js +19 -0
  25. package/dist/chunks/{chunk-5KI4Y4LA.js → chunk-BA4Z27XT.js} +4 -3
  26. package/dist/chunks/{chunk-BLDI2GRF.js → chunk-DBDU3RRN.js} +1364 -446
  27. package/dist/chunks/{chunk-LAJXWOKS.js → chunk-EEC5PJTC.js} +11 -9
  28. package/dist/chunks/chunk-IZKHSUNQ.js +30 -0
  29. package/dist/chunks/{chunk-Y3I2UV5Y.js → chunk-LRHNAG4V.js} +349 -288
  30. package/dist/chunks/chunk-OU33ROFD.js +717 -0
  31. package/dist/chunks/{chunk-Z2FKA2ZH.js → chunk-PN6B54VT.js} +104 -22
  32. package/dist/chunks/{chunk-NHV2CALB.js → chunk-WYXUF4MP.js} +388 -32
  33. package/dist/chunks/{chunk-4PR34UZF.js → chunk-Z5KL6AO2.js} +159 -145
  34. package/dist/chunks/{host-image-fallback-N7RHNPYN.js → host-image-fallback-RASJSVZY.js} +1 -1
  35. package/dist/chunks/{manager-cli-NEZA46M5.js → manager-cli-Y6HM3MHA.js} +5 -5
  36. package/dist/chunks/{model-registry-3XAHXXTA.js → model-registry-5TLYILYR.js} +2 -2
  37. package/dist/chunks/{read-file-understanding-FMPXR6EJ.js → read-file-understanding-VPKDBV23.js} +5 -5
  38. package/dist/chunks/{src-B44QWSGM.js → src-2XI5P62J.js} +2 -2
  39. package/dist/chunks/{src-EGXFJ3WA.js → src-6QGGDHIW.js} +3 -3
  40. package/dist/chunks/{src-Q7LU27C2.js → src-CCEENRKC.js} +31 -1
  41. package/dist/chunks/{src-CLE5ILN4.js → src-DI4MCAGT.js} +20 -4
  42. package/dist/chunks/{test-stream-OR3EJBNF.js → test-stream-SYVWIPPW.js} +2 -2
  43. package/dist/cli.js +1890 -1489
  44. package/models.schema.json +271 -0
  45. package/package.json +2 -2
  46. package/dist/builtin/skills/chrome-devtools-axi/chunk-Z2A5LA5A.js +0 -407
  47. package/dist/chunks/chunk-EGZ5TZRM.js +0 -1444
  48. package/dist/chunks/{chunk-CGSFBWOM.js → chunk-WBL73KRI.js} +3 -3
  49. package/dist/chunks/{manager-upgrade-CTU3ISCW.js → manager-upgrade-LSTOHBUV.js} +3 -3
@@ -0,0 +1,795 @@
1
+ import { createRequire as __axiRequire } from "node:module"; const require = __axiRequire(import.meta.url);
2
+
3
+ // vendor/chrome-devtools-axi/src/pages.ts
4
+ var PAGE_SCOPED_TOOLS = /* @__PURE__ */ new Set([
5
+ "click",
6
+ "drag",
7
+ "emulate",
8
+ "evaluate_script",
9
+ "fill",
10
+ "fill_form",
11
+ "get_console_message",
12
+ "get_network_request",
13
+ "handle_dialog",
14
+ "hover",
15
+ "lighthouse_audit",
16
+ "list_console_messages",
17
+ "list_network_requests",
18
+ "navigate_page",
19
+ "performance_analyze_insight",
20
+ "performance_start_trace",
21
+ "performance_stop_trace",
22
+ "press_key",
23
+ "resize_page",
24
+ "take_heapsnapshot",
25
+ "take_screenshot",
26
+ "take_snapshot",
27
+ "type_text",
28
+ "upload_file",
29
+ "wait_for"
30
+ ]);
31
+ function needsPageId(name, args = {}) {
32
+ if (typeof args.pageId === "number") return false;
33
+ if (name === "evaluate_script" && typeof args.serviceWorkerId === "string" && args.serviceWorkerId.length > 0) {
34
+ return false;
35
+ }
36
+ return PAGE_SCOPED_TOOLS.has(name);
37
+ }
38
+ var GENERIC_SCHEME_SLASH_URL = /^[a-z][a-z0-9+.-]*:\/\//i;
39
+ var COLON_ONLY_SCHEME_URL = /^(?:about:|data:|view-source:|blob:)/i;
40
+ function isPageSchemeUrl(label) {
41
+ return GENERIC_SCHEME_SLASH_URL.test(label) || COLON_ONLY_SCHEME_URL.test(label);
42
+ }
43
+ var MCP_SECTION_HEADER = /^##\s+(Pages|Extension Pages|Extension Service Workers|Third-party developer tools|WebMCP tools)$/;
44
+ var PAGE_ID_LINE = /^\d+:(?:\s+|$)/;
45
+ var OPEN_DIALOG_HEADER = /^# Open dialog$/;
46
+ var HANDLE_DIALOG_FOOTER = /^Call handle_dialog to handle it before continuing\.$/;
47
+ function stripTrailingIsolatedContext(label) {
48
+ const match = label.match(/^(.*)\s+isolatedContext=.*$/);
49
+ if (!match) return label;
50
+ const before = match[1];
51
+ const withoutSelected = before.replace(/\s*\[selected\]\s*$/, "").trimEnd();
52
+ if (matchTrailingUrl(withoutSelected) !== null) return before;
53
+ if (isPageSchemeUrl(withoutSelected)) return before;
54
+ return label;
55
+ }
56
+ function stripPageSuffixes(rest) {
57
+ let label = stripTrailingIsolatedContext(rest);
58
+ if (/(?:^|\s)\[selected\]\s*$/.test(label)) {
59
+ label = label.replace(/\s*\[selected\]\s*$/, "").trimEnd();
60
+ }
61
+ return label;
62
+ }
63
+ function matchTrailingUrl(label) {
64
+ const trimmed = label.trimEnd();
65
+ if (!trimmed.endsWith(")")) return null;
66
+ const close = trimmed.length - 1;
67
+ let from = close;
68
+ while (from > 0) {
69
+ const open = trimmed.lastIndexOf(" (", from - 1);
70
+ if (open === -1) return null;
71
+ const url = trimmed.slice(open + 2, close);
72
+ if (isPageSchemeUrl(url)) {
73
+ return { title: trimmed.slice(0, open), url };
74
+ }
75
+ from = open;
76
+ }
77
+ return null;
78
+ }
79
+ function hasSchemeUrl(label) {
80
+ const rest = stripPageSuffixes(label);
81
+ return matchTrailingUrl(rest) !== null || isPageSchemeUrl(rest);
82
+ }
83
+ function isCompletePageRow(row) {
84
+ return hasSchemeUrl(row.replace(/^\d+:\s*/, ""));
85
+ }
86
+ function isTitleContinuationLine(line) {
87
+ const m = line.match(/^(\d+):\s+(.+)$/);
88
+ if (!m) return false;
89
+ const rest = stripPageSuffixes(m[2]);
90
+ if (matchTrailingUrl(rest) !== null) return false;
91
+ if (isPageSchemeUrl(rest)) return false;
92
+ return /(?:^|\s)\[selected\]\s*$/.test(stripTrailingIsolatedContext(m[2]));
93
+ }
94
+ function extractPageUrl(label) {
95
+ const match = matchTrailingUrl(label);
96
+ return match ? match.url : label.trim();
97
+ }
98
+ function pageRowRest(row) {
99
+ return stripPageSuffixes(row.replace(/^\d+:\s*/, ""));
100
+ }
101
+ function stripDialogPreamble(text) {
102
+ const lines = text.split(/\r?\n/);
103
+ const kept = [];
104
+ for (let i = 0; i < lines.length; ) {
105
+ if (OPEN_DIALOG_HEADER.test(lines[i].trim())) {
106
+ let end = -1;
107
+ for (let idx = i + 1; idx < lines.length; idx++) {
108
+ if (HANDLE_DIALOG_FOOTER.test(lines[idx].trim())) end = idx;
109
+ }
110
+ if (end !== -1) {
111
+ i = end + 1;
112
+ continue;
113
+ }
114
+ }
115
+ kept.push(lines[i]);
116
+ i++;
117
+ }
118
+ return kept.join("\n");
119
+ }
120
+ function followingLinesCompleteTitle(rawLines, headerIndex, currentRow) {
121
+ let acc = `${currentRow} ## Pages`;
122
+ for (let i = headerIndex + 1; i < rawLines.length; i++) {
123
+ const next = rawLines[i].trim();
124
+ if (next.length === 0) continue;
125
+ if (next.match(MCP_SECTION_HEADER) !== null) return false;
126
+ if (PAGE_ID_LINE.test(next)) {
127
+ const rest = stripPageSuffixes(next.replace(/^\d+:\s*/, ""));
128
+ if (isPageSchemeUrl(rest) && matchTrailingUrl(rest) === null) {
129
+ return false;
130
+ }
131
+ }
132
+ acc += ` ${next}`;
133
+ if (matchTrailingUrl(pageRowRest(acc)) !== null) return true;
134
+ }
135
+ return false;
136
+ }
137
+ function collapsePageRows(text) {
138
+ const rows = [];
139
+ let inPageBlock = false;
140
+ const rawLines = stripDialogPreamble(text).split(/\r?\n/);
141
+ for (let index = 0; index < rawLines.length; index++) {
142
+ const line = rawLines[index].trim();
143
+ if (line.length === 0) continue;
144
+ const section = line.match(MCP_SECTION_HEADER)?.[1];
145
+ if (section !== void 0) {
146
+ const prev = rows[rows.length - 1];
147
+ if (section === "Pages" && inPageBlock && prev !== void 0 && !isCompletePageRow(prev) && followingLinesCompleteTitle(rawLines, index, prev)) {
148
+ rows[rows.length - 1] += ` ${line}`;
149
+ continue;
150
+ }
151
+ if (section === "Pages") {
152
+ rows.length = 0;
153
+ inPageBlock = true;
154
+ } else if (section === "Extension Pages") {
155
+ inPageBlock = true;
156
+ } else {
157
+ inPageBlock = false;
158
+ }
159
+ continue;
160
+ }
161
+ if (!inPageBlock) continue;
162
+ if (PAGE_ID_LINE.test(line)) {
163
+ const prev = rows[rows.length - 1];
164
+ if (prev !== void 0 && (!isCompletePageRow(prev) || isTitleContinuationLine(line))) {
165
+ rows[rows.length - 1] += ` ${line}`;
166
+ } else {
167
+ rows.push(line);
168
+ }
169
+ continue;
170
+ }
171
+ if (rows.length > 0) {
172
+ rows[rows.length - 1] += ` ${line}`;
173
+ }
174
+ }
175
+ return rows.map((row) => row.replace(/\s+/g, " "));
176
+ }
177
+ function parsePagesList(text) {
178
+ const pages = [];
179
+ for (const line of collapsePageRows(text)) {
180
+ const m = line.match(/^(\d+):\s+(.+)$/);
181
+ if (!m) continue;
182
+ const id = Number.parseInt(m[1], 10);
183
+ let rest = stripTrailingIsolatedContext(m[2]);
184
+ const selected = /(?:^|\s)\[selected\]\s*$/.test(rest);
185
+ if (selected) {
186
+ rest = rest.replace(/\s*\[selected\]\s*$/, "").trimEnd();
187
+ }
188
+ const url = extractPageUrl(rest);
189
+ pages.push({ id, url, selected });
190
+ }
191
+ return pages;
192
+ }
193
+
194
+ // vendor/chrome-devtools-axi/src/selected-page.ts
195
+ import {
196
+ existsSync as existsSync2,
197
+ mkdirSync as mkdirSync2,
198
+ readFileSync as readFileSync2,
199
+ unlinkSync as unlinkSync2,
200
+ writeFileSync as writeFileSync2
201
+ } from "node:fs";
202
+ import { dirname as dirname2, join as join2 } from "node:path";
203
+
204
+ // vendor/chrome-devtools-axi/src/sessions.ts
205
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
206
+ import { dirname, join } from "node:path";
207
+ import { homedir } from "node:os";
208
+ var DEFAULT_SESSION_NAME = "default";
209
+ var DEFAULT_BASE_PORT = 9224;
210
+ var SESSION_PORT_RANGE = 1e3;
211
+ var STATE_DIR_NAME = ".chrome-devtools-axi";
212
+ function resolveSessionName() {
213
+ const raw = process.env.CHROME_DEVTOOLS_AXI_SESSION?.trim();
214
+ const name = raw && raw.length > 0 ? raw : DEFAULT_SESSION_NAME;
215
+ validateSessionName(name);
216
+ return name;
217
+ }
218
+ function validateSessionName(name) {
219
+ if (name === DEFAULT_SESSION_NAME) return;
220
+ if (!/^[A-Za-z0-9._-]{1,64}$/.test(name)) {
221
+ throw new Error(
222
+ `Invalid CHROME_DEVTOOLS_AXI_SESSION "${name}": use 1-64 chars from [A-Za-z0-9._-]`
223
+ );
224
+ }
225
+ if (/^\.+$/.test(name)) {
226
+ throw new Error(
227
+ `Invalid CHROME_DEVTOOLS_AXI_SESSION "${name}": a name made only of dots would collapse onto the default session's state directory`
228
+ );
229
+ }
230
+ }
231
+ function defaultPortForSession(name) {
232
+ if (name === DEFAULT_SESSION_NAME) return DEFAULT_BASE_PORT;
233
+ let hash = 2166136261;
234
+ for (let i = 0; i < name.length; i++) {
235
+ hash ^= name.charCodeAt(i);
236
+ hash = Math.imul(hash, 16777619);
237
+ }
238
+ return DEFAULT_BASE_PORT + Math.abs(hash) % SESSION_PORT_RANGE + 1;
239
+ }
240
+ function parseStrictPort(raw, envVarName = "CHROME_DEVTOOLS_AXI_PORT") {
241
+ const trimmed = raw.trim();
242
+ if (!/^\d+$/.test(trimmed)) {
243
+ throw new Error(
244
+ `Invalid ${envVarName} "${raw}": must be a whole integer port between 1 and 65535`
245
+ );
246
+ }
247
+ const parsed = Number(trimmed);
248
+ if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 65535) {
249
+ throw new Error(
250
+ `Invalid ${envVarName} "${raw}": must be a whole integer port between 1 and 65535`
251
+ );
252
+ }
253
+ return parsed;
254
+ }
255
+ function resolveSessionAllocatedPortFile(name = resolveSessionName()) {
256
+ return join(resolveSessionStateDir(name), "bridge.port");
257
+ }
258
+ function readAllocatedSessionPort(name = resolveSessionName()) {
259
+ if (name === DEFAULT_SESSION_NAME) return null;
260
+ const file = resolveSessionAllocatedPortFile(name);
261
+ if (!existsSync(file)) return null;
262
+ try {
263
+ const raw = readFileSync(file, "utf-8").trim();
264
+ if (!/^\d+$/.test(raw)) return null;
265
+ const port = Number(raw);
266
+ return Number.isSafeInteger(port) && port >= 1 && port <= 65535 ? port : null;
267
+ } catch {
268
+ return null;
269
+ }
270
+ }
271
+ function writeAllocatedSessionPort(name, port) {
272
+ if (name === DEFAULT_SESSION_NAME) return;
273
+ const file = resolveSessionAllocatedPortFile(name);
274
+ mkdirSync(dirname(file), { recursive: true });
275
+ writeFileSync(file, `${port}
276
+ `, "utf-8");
277
+ }
278
+ function clearAllocatedSessionPort(name = resolveSessionName()) {
279
+ if (name === DEFAULT_SESSION_NAME) return;
280
+ const file = resolveSessionAllocatedPortFile(name);
281
+ try {
282
+ if (existsSync(file)) unlinkSync(file);
283
+ } catch {
284
+ }
285
+ }
286
+ function resolveSessionPort(name = resolveSessionName()) {
287
+ const explicit = process.env.CHROME_DEVTOOLS_AXI_PORT;
288
+ if (explicit !== void 0 && explicit.trim().length > 0) {
289
+ return parseStrictPort(explicit, "CHROME_DEVTOOLS_AXI_PORT");
290
+ }
291
+ return readAllocatedSessionPort(name) ?? defaultPortForSession(name);
292
+ }
293
+ function resolveSessionStateDir(name = resolveSessionName()) {
294
+ const base = join(homedir(), STATE_DIR_NAME);
295
+ return name === DEFAULT_SESSION_NAME ? base : join(base, "sessions", name);
296
+ }
297
+ function resolveSessionPidFile(name = resolveSessionName()) {
298
+ return join(resolveSessionStateDir(name), "bridge.pid");
299
+ }
300
+ function resolveSessionLogFile(name = resolveSessionName()) {
301
+ return join(resolveSessionStateDir(name), "bridge.log");
302
+ }
303
+ function resolveSessionStartLockFile(name = resolveSessionName()) {
304
+ return join(resolveSessionStateDir(name), "bridge.start.lock");
305
+ }
306
+
307
+ // vendor/chrome-devtools-axi/src/selected-page.ts
308
+ function selectedPageFile() {
309
+ return join2(resolveSessionStateDir(), "selected-page-id");
310
+ }
311
+ function getSelectedPageId() {
312
+ const file = selectedPageFile();
313
+ try {
314
+ if (!existsSync2(file)) return null;
315
+ const parsed = Number.parseInt(readFileSync2(file, "utf-8").trim(), 10);
316
+ return Number.isInteger(parsed) && parsed >= 0 ? parsed : null;
317
+ } catch {
318
+ return null;
319
+ }
320
+ }
321
+ function setSelectedPageId(pageId) {
322
+ const file = selectedPageFile();
323
+ try {
324
+ mkdirSync2(dirname2(file), { recursive: true });
325
+ writeFileSync2(file, String(pageId));
326
+ } catch {
327
+ }
328
+ }
329
+ function clearSelectedPageId() {
330
+ const hadSelection = getSelectedPageId() !== null;
331
+ const file = selectedPageFile();
332
+ try {
333
+ if (existsSync2(file)) unlinkSync2(file);
334
+ } catch {
335
+ }
336
+ return hadSelection && getSelectedPageId() === null;
337
+ }
338
+ function overlaySessionSelected(pages, selectedId = getSelectedPageId()) {
339
+ return pages.map((page) => ({
340
+ ...page,
341
+ selected: selectedId !== null && page.id === selectedId
342
+ }));
343
+ }
344
+ function rememberToolRouting(name, args) {
345
+ if (name === "select_page" && typeof args.pageId === "number") {
346
+ setSelectedPageId(args.pageId);
347
+ return;
348
+ }
349
+ if (name === "close_page" && typeof args.pageId === "number") {
350
+ if (getSelectedPageId() === args.pageId) clearSelectedPageId();
351
+ }
352
+ }
353
+ function createdPageIdFromPageLists(beforeText, afterText) {
354
+ const beforeIds = new Set(parsePagesList(beforeText).map((page) => page.id));
355
+ const createdIds = parsePagesList(afterText).filter((page) => !beforeIds.has(page.id)).map((page) => page.id);
356
+ return createdIds.length === 1 ? createdIds[0] : null;
357
+ }
358
+
359
+ // vendor/chrome-devtools-axi/src/bridge-script.ts
360
+ import { existsSync as existsSync3 } from "node:fs";
361
+ import { resolve } from "node:path";
362
+ function resolveBridgeScript(importMetaDir) {
363
+ const bundled = resolve(importMetaDir, "chrome-devtools-axi-bridge.js");
364
+ if (existsSync3(bundled)) return bundled;
365
+ const builtScript = resolve(
366
+ importMetaDir,
367
+ "../bin/chrome-devtools-axi-bridge.js"
368
+ );
369
+ const sourceScript = builtScript.replace(/\.js$/, ".ts");
370
+ return existsSync3(sourceScript) ? sourceScript : builtScript;
371
+ }
372
+ var BRIDGE_PORT_IN_USE_EXIT_CODE = 48;
373
+ var PAGE_IDENTITY_CHANGED_ERROR = "The browser reconnected and every page id changed, so this call did not target the page you selected";
374
+ function isAutoConnectMode() {
375
+ const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
376
+ if (freshInstance) return false;
377
+ if (process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim()) return false;
378
+ return process.env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT === "1" || process.env.CHROME_DEVTOOLS_AXI_ATTACH === "1";
379
+ }
380
+ function isAttachTransportMode() {
381
+ const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
382
+ if (freshInstance) return false;
383
+ if (process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim()) return false;
384
+ const browserUrl = process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL?.trim();
385
+ return isAutoConnectMode() || !!browserUrl;
386
+ }
387
+ function isManagedIsolatedMode() {
388
+ const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
389
+ if (freshInstance) return true;
390
+ if (process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim()) return false;
391
+ if (isAutoConnectMode()) return false;
392
+ if (process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL?.trim()) return false;
393
+ if (process.env.CHROME_DEVTOOLS_AXI_USER_DATA_DIR?.trim()) return false;
394
+ return true;
395
+ }
396
+ function computeTransportModeFingerprint() {
397
+ const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
398
+ const headed = process.env.CHROME_DEVTOOLS_AXI_HEADED === "1";
399
+ if (freshInstance) {
400
+ return headed ? "isolated-headed" : "isolated-headless";
401
+ }
402
+ const sharedUrl = process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim();
403
+ if (sharedUrl) {
404
+ const proxy = Boolean(process.env.CHROME_DEVTOOLS_AXI_MCP_PATH?.trim());
405
+ return `${proxy ? "shared-proxy" : "shared-direct"}:${sharedUrl}`;
406
+ }
407
+ if (isAutoConnectMode()) {
408
+ const channel = process.env.CHROME_DEVTOOLS_AXI_CHANNEL?.trim() || "stable";
409
+ return `attach-autoconnect:${channel}`;
410
+ }
411
+ const browserUrl = process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL?.trim();
412
+ if (browserUrl) {
413
+ return `attach-url:${browserUrl}`;
414
+ }
415
+ const userDataDir = process.env.CHROME_DEVTOOLS_AXI_USER_DATA_DIR?.trim();
416
+ if (userDataDir) {
417
+ return `${headed ? "profile-headed" : "profile-headless"}:${resolve(userDataDir)}`;
418
+ }
419
+ return headed ? "isolated-headed" : "isolated-headless";
420
+ }
421
+
422
+ // vendor/chrome-devtools-axi/src/process-identity.ts
423
+ import { execFileSync } from "node:child_process";
424
+ function inspectProcessIdentity(pid) {
425
+ if (!Number.isInteger(pid) || pid <= 0) return {};
426
+ if (process.platform === "win32") {
427
+ try {
428
+ const output = execFileSync(
429
+ "powershell",
430
+ [
431
+ "-NoProfile",
432
+ "-NonInteractive",
433
+ "-Command",
434
+ `$p = Get-CimInstance Win32_Process -Filter "ProcessId=<pid>"; if ($p) { $p.CommandLine; $p.CreationDate.ToString('o') }`.replace("<pid>", String(pid))
435
+ ],
436
+ // Cold PowerShell+CIM startup can exceed four seconds on Windows,
437
+ // even for an owned live child. Keep a finite query budget without
438
+ // treating an unreadable identity as permission to signal that pid.
439
+ { encoding: "utf-8", timeout: 1e4, windowsHide: true }
440
+ );
441
+ const lines = output.split(/\r?\n/).filter((line) => line.length > 0);
442
+ if (lines.length === 0) return {};
443
+ const startTime = lines.length >= 2 ? lines[lines.length - 1] : void 0;
444
+ return { command: lines.slice(0, lines.length - 1).join("\n"), startTime };
445
+ } catch {
446
+ return {};
447
+ }
448
+ }
449
+ try {
450
+ const psEnv = { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" };
451
+ const output = execFileSync(
452
+ "ps",
453
+ ["-p", String(pid), "-o", "lstart=", "-o", "command="],
454
+ { encoding: "utf-8", timeout: 1e3, env: psEnv }
455
+ );
456
+ const firstNewline = output.indexOf("\n");
457
+ const firstLine = firstNewline === -1 ? output : output.slice(0, firstNewline);
458
+ const lstart = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{1,2}\s+\d{1,2}:\d{2}:\d{2}\s+\d{4}\s+/.exec(firstLine);
459
+ if (lstart) {
460
+ return { startTime: lstart[0].trimEnd(), command: output.slice(lstart[0].length) };
461
+ }
462
+ try {
463
+ const command = execFileSync("ps", ["-p", String(pid), "-o", "command="], {
464
+ encoding: "utf-8",
465
+ timeout: 1e3,
466
+ env: psEnv
467
+ });
468
+ return { command };
469
+ } catch {
470
+ return {};
471
+ }
472
+ } catch {
473
+ return {};
474
+ }
475
+ }
476
+ function readProcessStartTime(pid) {
477
+ return inspectProcessIdentity(pid).startTime;
478
+ }
479
+ function readSelfStartTime() {
480
+ return readProcessStartTime(process.pid);
481
+ }
482
+
483
+ // vendor/chrome-devtools-axi/src/supervisor-anchor-shared.ts
484
+ var SUPERVISOR_PID_ENV = "PIE_SUPERVISOR_PID";
485
+ var SUPERVISOR_START_TIME_ENV = "PIE_SUPERVISOR_START_TIME";
486
+ function parseSupervisorAnchor(env = process.env) {
487
+ const pidText = env[SUPERVISOR_PID_ENV]?.trim();
488
+ if (!pidText || !/^\d+$/.test(pidText)) return void 0;
489
+ const pid = Number(pidText);
490
+ if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
491
+ const startTime = env[SUPERVISOR_START_TIME_ENV]?.trim();
492
+ return startTime ? { pid, startTime } : { pid };
493
+ }
494
+ function isSupervisorGone(anchor, readIdentity) {
495
+ try {
496
+ process.kill(anchor.pid, 0);
497
+ } catch (error) {
498
+ return error.code === "ESRCH";
499
+ }
500
+ let identity;
501
+ try {
502
+ identity = readIdentity(anchor.pid);
503
+ } catch {
504
+ return false;
505
+ }
506
+ if (identity.startTime === void 0) return false;
507
+ if (anchor.startTime === void 0) return false;
508
+ return identity.startTime !== anchor.startTime;
509
+ }
510
+
511
+ // vendor/chrome-devtools-axi/src/profile-reaper.ts
512
+ import { execFile } from "node:child_process";
513
+ import { randomBytes } from "node:crypto";
514
+ import {
515
+ existsSync as existsSync4,
516
+ mkdirSync as mkdirSync3,
517
+ readdirSync,
518
+ readFileSync as readFileSync3,
519
+ rmSync,
520
+ unlinkSync as unlinkSync3,
521
+ writeFileSync as writeFileSync3
522
+ } from "node:fs";
523
+ import { join as join3, resolve as resolve2 } from "node:path";
524
+ function escapeEre(value) {
525
+ return value.replace(/[\\^$.|?*+()[{]/g, (ch) => `\\${ch}`);
526
+ }
527
+ function profilesRootForSession(sessionStateDir) {
528
+ return join3(sessionStateDir, "profiles");
529
+ }
530
+ function manifestPathForProfileDir(profileDir) {
531
+ return `${profileDir}.manifest.json`;
532
+ }
533
+ function allocateOwnedProfileDir(sessionStateDir, bridgePid = process.pid) {
534
+ const root = profilesRootForSession(sessionStateDir);
535
+ mkdirSync3(root, { recursive: true, mode: 448 });
536
+ const runId = `run-${bridgePid}-${randomBytes(6).toString("hex")}`;
537
+ const profileDir = resolve2(join3(root, runId));
538
+ mkdirSync3(profileDir, { recursive: true, mode: 448 });
539
+ const manifestPath = manifestPathForProfileDir(profileDir);
540
+ const manifest = {
541
+ bridgePid,
542
+ ...readSelfStartTime() ? { bridgeStartTime: readSelfStartTime() } : {},
543
+ profileDir,
544
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
545
+ };
546
+ writeFileSync3(manifestPath, JSON.stringify(manifest), { mode: 384 });
547
+ return { profileDir, manifestPath };
548
+ }
549
+ function commandLineMatchesProfile(cmdline, profileDir) {
550
+ const escaped = profileDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
551
+ const patterns = [
552
+ // Whole-argument double-quoted: "--user-data-dir=C:\Jane Doe\..."
553
+ new RegExp(`(?:^|\\s)"--user-data-dir=${escaped}"(?:\\s|$)`),
554
+ // Whole-argument single-quoted: '--user-data-dir=/path with spaces'
555
+ new RegExp(`(?:^|\\s)'--user-data-dir=${escaped}'(?:\\s|$)`),
556
+ // Value-only double-quoted: --user-data-dir="C:\Jane Doe\..."
557
+ new RegExp(`(?:^|\\s)--user-data-dir="${escaped}"(?:\\s|$)`),
558
+ // Value-only single-quoted: --user-data-dir='/path with spaces'
559
+ new RegExp(`(?:^|\\s)--user-data-dir='${escaped}'(?:\\s|$)`),
560
+ // Unquoted token: --user-data-dir=/path/without/spaces
561
+ new RegExp(`(?:^|\\s)--user-data-dir=${escaped}(?:\\s|$)`)
562
+ ];
563
+ return patterns.some((re) => re.test(cmdline));
564
+ }
565
+ function pidStillAlive(pid) {
566
+ try {
567
+ process.kill(pid, 0);
568
+ return true;
569
+ } catch (error) {
570
+ return error.code === "EPERM";
571
+ }
572
+ }
573
+ async function scanProfileHolders(profileDir) {
574
+ if (process.platform === "win32") {
575
+ return await new Promise((resolveScan) => {
576
+ execFile(
577
+ "powershell.exe",
578
+ [
579
+ "-NoProfile",
580
+ "-NonInteractive",
581
+ "-Command",
582
+ "Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($env:PIE_AXI_TARGET_PROFILE) } | Select-Object -ExpandProperty ProcessId"
583
+ ],
584
+ {
585
+ timeout: 3e3,
586
+ windowsHide: true,
587
+ env: { ...process.env, PIE_AXI_TARGET_PROFILE: profileDir }
588
+ },
589
+ (error, stdout) => {
590
+ if (error) {
591
+ resolveScan({ kind: "unknown" });
592
+ return;
593
+ }
594
+ const pids = String(stdout ?? "").split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n > 0 && n !== process.pid);
595
+ resolveScan(pids.length > 0 ? { kind: "ok", pids } : { kind: "none" });
596
+ }
597
+ );
598
+ });
599
+ }
600
+ const pattern = `user-data-dir=${escapeEre(profileDir)}([[:space:]"']|$)`;
601
+ return await new Promise((resolveScan) => {
602
+ execFile("pgrep", ["-f", pattern], { timeout: 1500 }, (error, stdout) => {
603
+ if (!error) {
604
+ const pids = String(stdout ?? "").split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n > 0 && n !== process.pid);
605
+ resolveScan(pids.length > 0 ? { kind: "ok", pids } : { kind: "none" });
606
+ return;
607
+ }
608
+ const code = error.code;
609
+ if (code === 1) {
610
+ resolveScan({ kind: "none" });
611
+ return;
612
+ }
613
+ resolveScan({ kind: "unknown" });
614
+ });
615
+ });
616
+ }
617
+ async function verifyProfileHolderDetailed(pid, profileDir) {
618
+ if (process.platform === "win32") {
619
+ return await new Promise((resolveVerify) => {
620
+ execFile(
621
+ "powershell.exe",
622
+ [
623
+ "-NoProfile",
624
+ "-NonInteractive",
625
+ "-Command",
626
+ `Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" | Select-Object -ExpandProperty CommandLine`
627
+ ],
628
+ { timeout: 2500, windowsHide: true },
629
+ (error, stdout) => {
630
+ if (error) {
631
+ resolveVerify(pidStillAlive(pid) ? "unknown" : "no_match");
632
+ return;
633
+ }
634
+ const cmd = String(stdout ?? "").trim();
635
+ if (!cmd) {
636
+ resolveVerify(pidStillAlive(pid) ? "unknown" : "no_match");
637
+ return;
638
+ }
639
+ resolveVerify(commandLineMatchesProfile(cmd, profileDir) ? "match" : "no_match");
640
+ }
641
+ );
642
+ });
643
+ }
644
+ return await new Promise((resolveVerify) => {
645
+ execFile("ps", ["-p", String(pid), "-o", "command="], { timeout: 1500 }, (error, stdout) => {
646
+ if (error) {
647
+ resolveVerify(pidStillAlive(pid) ? "unknown" : "no_match");
648
+ return;
649
+ }
650
+ const cmd = String(stdout ?? "").trim();
651
+ if (!cmd) {
652
+ resolveVerify(pidStillAlive(pid) ? "unknown" : "no_match");
653
+ return;
654
+ }
655
+ resolveVerify(commandLineMatchesProfile(cmd, profileDir) ? "match" : "no_match");
656
+ });
657
+ });
658
+ }
659
+ async function sleep(ms) {
660
+ await new Promise((r) => setTimeout(r, ms));
661
+ }
662
+ async function waitUntilAllDead(pids, timeoutMs) {
663
+ const deadline = Date.now() + timeoutMs;
664
+ let alive = pids.filter(pidStillAlive);
665
+ while (alive.length > 0 && Date.now() < deadline) {
666
+ await sleep(100);
667
+ alive = alive.filter(pidStillAlive);
668
+ }
669
+ return alive;
670
+ }
671
+ async function cleanupOwnedProfileDir(profileDir, manifestPath = manifestPathForProfileDir(profileDir)) {
672
+ const normalized = resolve2(profileDir);
673
+ const firstScan = await scanProfileHolders(normalized);
674
+ if (firstScan.kind === "unknown") {
675
+ return { clean: false, remainingPids: [] };
676
+ }
677
+ if (firstScan.kind === "ok") {
678
+ const verified = [];
679
+ let anyUnknown = false;
680
+ for (const pid of firstScan.pids) {
681
+ const verdict = await verifyProfileHolderDetailed(pid, normalized);
682
+ if (verdict === "match") verified.push(pid);
683
+ else if (verdict === "unknown") anyUnknown = true;
684
+ }
685
+ for (const pid of verified) {
686
+ try {
687
+ process.kill(pid, "SIGTERM");
688
+ } catch {
689
+ }
690
+ }
691
+ const afterTerm = await waitUntilAllDead(verified, 1500);
692
+ for (const pid of afterTerm) {
693
+ const recheck = await verifyProfileHolderDetailed(pid, normalized);
694
+ if (recheck === "match") {
695
+ try {
696
+ process.kill(pid, "SIGKILL");
697
+ } catch {
698
+ }
699
+ } else if (recheck === "unknown") {
700
+ anyUnknown = true;
701
+ }
702
+ }
703
+ if (afterTerm.length > 0) {
704
+ await waitUntilAllDead(afterTerm, 1e3);
705
+ }
706
+ if (anyUnknown) {
707
+ return { clean: false, remainingPids: afterTerm.filter(pidStillAlive) };
708
+ }
709
+ }
710
+ const finalScan = await scanProfileHolders(normalized);
711
+ if (finalScan.kind !== "none") {
712
+ return {
713
+ clean: false,
714
+ remainingPids: finalScan.kind === "ok" ? finalScan.pids : []
715
+ };
716
+ }
717
+ try {
718
+ rmSync(normalized, { recursive: true, force: true });
719
+ } catch {
720
+ }
721
+ try {
722
+ if (existsSync4(manifestPath)) unlinkSync3(manifestPath);
723
+ } catch {
724
+ }
725
+ return { clean: true, remainingPids: [] };
726
+ }
727
+ async function reapStaleOwnedProfiles(sessionStateDir, activeBridgePid) {
728
+ const root = profilesRootForSession(sessionStateDir);
729
+ if (!existsSync4(root)) return;
730
+ let entries;
731
+ try {
732
+ entries = readdirSync(root).filter((f) => f.endsWith(".manifest.json"));
733
+ } catch {
734
+ return;
735
+ }
736
+ for (const file of entries) {
737
+ const manifestPath = join3(root, file);
738
+ let manifest;
739
+ try {
740
+ const parsed = JSON.parse(readFileSync3(manifestPath, "utf-8"));
741
+ if (typeof parsed.bridgePid !== "number" || !Number.isInteger(parsed.bridgePid) || parsed.bridgePid <= 0 || typeof parsed.profileDir !== "string" || parsed.profileDir.trim().length === 0) {
742
+ continue;
743
+ }
744
+ manifest = parsed;
745
+ } catch {
746
+ continue;
747
+ }
748
+ if (activeBridgePid !== void 0 && manifest.bridgePid === activeBridgePid) {
749
+ continue;
750
+ }
751
+ const gone = isSupervisorGone(
752
+ {
753
+ pid: manifest.bridgePid,
754
+ ...manifest.bridgeStartTime ? { startTime: manifest.bridgeStartTime } : {}
755
+ },
756
+ inspectProcessIdentity
757
+ );
758
+ if (!gone) continue;
759
+ await cleanupOwnedProfileDir(manifest.profileDir, manifestPath);
760
+ }
761
+ }
762
+
763
+ export {
764
+ resolveBridgeScript,
765
+ BRIDGE_PORT_IN_USE_EXIT_CODE,
766
+ PAGE_IDENTITY_CHANGED_ERROR,
767
+ isAutoConnectMode,
768
+ isAttachTransportMode,
769
+ isManagedIsolatedMode,
770
+ computeTransportModeFingerprint,
771
+ needsPageId,
772
+ parsePagesList,
773
+ inspectProcessIdentity,
774
+ readSelfStartTime,
775
+ parseSupervisorAnchor,
776
+ isSupervisorGone,
777
+ allocateOwnedProfileDir,
778
+ cleanupOwnedProfileDir,
779
+ reapStaleOwnedProfiles,
780
+ DEFAULT_SESSION_NAME,
781
+ resolveSessionName,
782
+ writeAllocatedSessionPort,
783
+ clearAllocatedSessionPort,
784
+ resolveSessionPort,
785
+ resolveSessionStateDir,
786
+ resolveSessionPidFile,
787
+ resolveSessionLogFile,
788
+ resolveSessionStartLockFile,
789
+ getSelectedPageId,
790
+ setSelectedPageId,
791
+ clearSelectedPageId,
792
+ overlaySessionSelected,
793
+ rememberToolRouting,
794
+ createdPageIdFromPageLists
795
+ };