@opencode/browse 0.0.15-dev.106 → 0.0.15-dev.108

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  opencodeBrowserVersion2,
3
3
  opencodeBrowserBuildId2
4
- } from "./main-js2skwv0.mjs";
4
+ } from "./main-ph9p60em.mjs";
5
5
  import {
6
6
  defaultRoots,
7
7
  configRoot2,
@@ -25,7 +25,7 @@ import {
25
25
  setStoredMode,
26
26
  autoUpdateStatus,
27
27
  createAutoUpdater
28
- } from "./main-w1tpmn40.mjs";
28
+ } from "./main-8x0vchk6.mjs";
29
29
  import {
30
30
  extensionProtocolVersion,
31
31
  minExtensionProtocolVersion,
@@ -101,7 +101,7 @@ import {
101
101
  isRestrictedTarget2,
102
102
  isRestrictedUrl2,
103
103
  dataUrlDocument2
104
- } from "./main-8v745bnc.mjs";
104
+ } from "./main-kcdhjma5.mjs";
105
105
  import {
106
106
  context,
107
107
  pendingPairingCodeKeys,
@@ -119,7 +119,7 @@ import {
119
119
  pairingSessionKey,
120
120
  sessionProof,
121
121
  wrapToken
122
- } from "./main-meb93fb6.mjs";
122
+ } from "./main-01m4wrg2.mjs";
123
123
  import {
124
124
  makeUnsafe,
125
125
  SettingsInputError,
@@ -147,22 +147,22 @@ import {
147
147
  checkNavigationUrl,
148
148
  readSecret,
149
149
  secretText
150
- } from "./main-fc8x53gp.mjs";
150
+ } from "./main-48f4pr78.mjs";
151
151
  import {
152
152
  defaultJournalBaseDir,
153
153
  makeJournalEntry,
154
154
  appendJournalEntry,
155
155
  startJournalRetention
156
- } from "./main-djba9n9x.mjs";
156
+ } from "./main-aqgb3jf8.mjs";
157
157
  import {
158
158
  createUpdateWatcher2
159
- } from "./main-y8pf1913.mjs";
159
+ } from "./main-w01bz8hg.mjs";
160
160
  import {
161
161
  relayHostname,
162
162
  isLocalPeer,
163
163
  installedDevExtension,
164
164
  syncDevExtension
165
- } from "./main-xh68g601.mjs";
165
+ } from "./main-gwch0y7g.mjs";
166
166
  import {
167
167
  legacyRoots
168
168
  } from "./main-ckssvk4c.mjs";
@@ -278,7 +278,7 @@ import {
278
278
  relayToken,
279
279
  secretsEqual,
280
280
  ensurePrivateDirectory
281
- } from "./main-q3b9mgev.mjs";
281
+ } from "./main-92gwpbpf.mjs";
282
282
  import {
283
283
  isString,
284
284
  isNumber,
@@ -292,7 +292,7 @@ import {
292
292
 
293
293
  // src/relay.ts
294
294
  import crypto10 from "node:crypto";
295
- import path14 from "node:path";
295
+ import path15 from "node:path";
296
296
 
297
297
  // src/relay/browser-links.ts
298
298
  import dns from "node:dns/promises";
@@ -2296,23 +2296,454 @@ function challengeWarning(outcome) {
2296
2296
  }
2297
2297
 
2298
2298
  // src/execute-realm.ts
2299
- import buffer2 from "node:buffer";
2299
+ import buffer3 from "node:buffer";
2300
2300
  import crypto5 from "node:crypto";
2301
- import util4 from "node:util";
2301
+ import util6 from "node:util";
2302
2302
  import vm3 from "node:vm";
2303
2303
 
2304
2304
  // src/execute-realm/file-roots.ts
2305
- import buffer from "node:buffer";
2305
+ import buffer2 from "node:buffer";
2306
2306
  import crypto3 from "node:crypto";
2307
2307
  import events from "node:events";
2308
- import fs2 from "node:fs";
2308
+ import fs3 from "node:fs";
2309
2309
  import fsPromises from "node:fs/promises";
2310
2310
  import os2 from "node:os";
2311
- import path2 from "node:path";
2311
+ import path3 from "node:path";
2312
2312
  import stream from "node:stream";
2313
2313
  import url from "node:url";
2314
- import util from "node:util";
2314
+ import util3 from "node:util";
2315
2315
  import zlib from "node:zlib";
2316
+
2317
+ // src/execute-realm/cdp-send.ts
2318
+ import util from "node:util";
2319
+
2320
+ // src/execute-realm/errors.ts
2321
+ class ExecuteFileAccessError extends Error {
2322
+ name = "ExecuteFileAccessError";
2323
+ }
2324
+
2325
+ // src/execute-realm/cdp-send.ts
2326
+ var cdpMethodPattern = /^[A-Z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]*$/;
2327
+ function isCdpMethodName(value) {
2328
+ return cdpMethodPattern.test(value);
2329
+ }
2330
+ function isCdpSession(receiver) {
2331
+ if (receiver === null || typeof receiver !== "object" || util.types.isProxy(receiver))
2332
+ return false;
2333
+ try {
2334
+ const prototype = Object.getPrototypeOf(receiver);
2335
+ const name = prototype?.constructor?.name;
2336
+ if (typeof name === "string" && name.replace(/\d+$/, "") === "CDPSession")
2337
+ return true;
2338
+ return typeof Reflect.get(receiver, "detach") === "function" && typeof Reflect.get(receiver, "send") === "function";
2339
+ } catch {
2340
+ return false;
2341
+ }
2342
+ }
2343
+ function invalidCdpParameters(operation, why) {
2344
+ return new ExecuteFileAccessError(`${operation}: CDP parameters must be plain JSON data, ${why}`);
2345
+ }
2346
+ function copyCdpParameters(value, operation) {
2347
+ return copyJsonValue(value, operation, new Set);
2348
+ }
2349
+ function copyJsonValue(value, operation, stack) {
2350
+ if (value === null)
2351
+ return null;
2352
+ if (typeof value === "string" || typeof value === "boolean")
2353
+ return value;
2354
+ if (typeof value === "number") {
2355
+ if (!Number.isFinite(value))
2356
+ throw invalidCdpParameters(operation, "which cannot contain non-finite numbers");
2357
+ return value;
2358
+ }
2359
+ if (typeof value !== "object")
2360
+ throw invalidCdpParameters(operation, "which cannot contain functions, symbols or undefined values");
2361
+ if (util.types.isProxy(value))
2362
+ throw invalidCdpParameters(operation, "which cannot contain proxies");
2363
+ if (stack.has(value))
2364
+ throw invalidCdpParameters(operation, "which cannot be cyclical");
2365
+ stack.add(value);
2366
+ try {
2367
+ if (Array.isArray(value))
2368
+ return copyJsonArray(value, operation, stack);
2369
+ const prototype = Object.getPrototypeOf(value);
2370
+ if (prototype !== Object.prototype && prototype !== null) {
2371
+ throw invalidCdpParameters(operation, "which cannot contain class instances, dates, maps or other host objects");
2372
+ }
2373
+ const copy = {};
2374
+ for (const key of Reflect.ownKeys(value)) {
2375
+ if (typeof key !== "string")
2376
+ throw invalidCdpParameters(operation, "which cannot contain symbol keys");
2377
+ const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
2378
+ if (descriptor === undefined || !("value" in descriptor) || descriptor.enumerable !== true) {
2379
+ throw invalidCdpParameters(operation, "which cannot contain getters, setters or non-enumerable properties");
2380
+ }
2381
+ if (descriptor.value === undefined)
2382
+ continue;
2383
+ Object.defineProperty(copy, key, {
2384
+ value: copyJsonValue(descriptor.value, operation, stack),
2385
+ writable: true,
2386
+ enumerable: true,
2387
+ configurable: true
2388
+ });
2389
+ }
2390
+ if (typeof Reflect.get(value, "toJSON") === "function")
2391
+ throw invalidCdpParameters(operation, "which cannot contain toJSON");
2392
+ return copy;
2393
+ } finally {
2394
+ stack.delete(value);
2395
+ }
2396
+ }
2397
+ function copyJsonArray(value, operation, stack) {
2398
+ const copy = new Array(value.length);
2399
+ let count = 0;
2400
+ for (const key of Reflect.ownKeys(value)) {
2401
+ if (key === "length")
2402
+ continue;
2403
+ if (typeof key !== "string" || !/^(0|[1-9]\d*)$/.test(key) || Number(key) >= value.length) {
2404
+ throw invalidCdpParameters(operation, "whose arrays cannot have extra properties");
2405
+ }
2406
+ const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
2407
+ if (descriptor === undefined || !("value" in descriptor) || descriptor.enumerable !== true) {
2408
+ throw invalidCdpParameters(operation, "which cannot contain getters, setters or non-enumerable properties");
2409
+ }
2410
+ if (descriptor.value === undefined) {
2411
+ throw new ExecuteFileAccessError(`${operation}: CDP parameters must be plain JSON data; arrays cannot contain undefined, use null`);
2412
+ }
2413
+ copy[Number(key)] = copyJsonValue(descriptor.value, operation, stack);
2414
+ count += 1;
2415
+ }
2416
+ if (count !== value.length)
2417
+ throw invalidCdpParameters(operation, "whose arrays cannot have holes");
2418
+ if (typeof Reflect.get(value, "toJSON") === "function")
2419
+ throw invalidCdpParameters(operation, "which cannot contain toJSON");
2420
+ return copy;
2421
+ }
2422
+ var cdpFileInputMethods = new Set(["DOM.setFileInputFiles", "PWA.launchFilesInApp"]);
2423
+ var cdpDownloadPathMethods = new Set(["Browser.setDownloadBehavior", "Page.setDownloadBehavior"]);
2424
+ var cdpRefusedMethods = new Map([
2425
+ ["PWA.install", "installing a web app"],
2426
+ ["DOM.getFileInfo", "revealing local file paths"],
2427
+ ["Target.sendMessageToTarget", "forwarding a raw CDP message would bypass these file checks"],
2428
+ ["Target.exposeDevToolsProtocol", "exposing raw CDP to page script would bypass these file checks"]
2429
+ ]);
2430
+ function isPlainRecord(value) {
2431
+ if (value === null || typeof value !== "object" || Array.isArray(value))
2432
+ return false;
2433
+ const prototype = Object.getPrototypeOf(value);
2434
+ return prototype === Object.prototype || prototype === null;
2435
+ }
2436
+ function requireParamsObject(method, value) {
2437
+ if (!isPlainRecord(value))
2438
+ throw new ExecuteFileAccessError(`${method}: params must be an object`);
2439
+ return value;
2440
+ }
2441
+ function checkCdpFiles(container, key, method, check) {
2442
+ if (!Object.hasOwn(container, key))
2443
+ return;
2444
+ const files = container[key];
2445
+ if (!Array.isArray(files) || !files.every((file) => typeof file === "string")) {
2446
+ throw new ExecuteFileAccessError(`${method}: ${key} must be an array of file paths`);
2447
+ }
2448
+ const resolved = files.map((file) => check.fileInput(file, `${method}({ ${key} })`));
2449
+ Reflect.set(container, key, resolved);
2450
+ }
2451
+ function checkCdpSend(method, params, check) {
2452
+ if (method.startsWith("Extensions.")) {
2453
+ throw new ExecuteFileAccessError(`${method}: extension control is not available in execute code`);
2454
+ }
2455
+ const refusal = cdpRefusedMethods.get(method);
2456
+ if (refusal !== undefined)
2457
+ throw new ExecuteFileAccessError(`${method}: ${refusal}, so it is not available in execute code`);
2458
+ if (cdpFileInputMethods.has(method)) {
2459
+ checkCdpFiles(requireParamsObject(method, params), "files", method, check);
2460
+ return {};
2461
+ }
2462
+ if (method === "Input.dispatchDragEvent") {
2463
+ const object = requireParamsObject(method, params);
2464
+ if (Object.hasOwn(object, "data")) {
2465
+ const data = object.data;
2466
+ if (!isPlainRecord(data))
2467
+ throw new ExecuteFileAccessError(`${method}: data must be an object`);
2468
+ checkCdpFiles(data, "files", method, check);
2469
+ }
2470
+ return {};
2471
+ }
2472
+ if (!cdpDownloadPathMethods.has(method))
2473
+ return {};
2474
+ const object = requireParamsObject(method, params);
2475
+ const behavior = object.behavior;
2476
+ const downloadPath = object.downloadPath;
2477
+ if (downloadPath !== undefined && typeof downloadPath !== "string") {
2478
+ throw new ExecuteFileAccessError(`${method}: downloadPath must be a string`);
2479
+ }
2480
+ if (behavior === "default") {
2481
+ throw new ExecuteFileAccessError(`${method}: default downloads go outside the execute file roots; use behavior "allow" with a downloadPath`);
2482
+ }
2483
+ if (behavior !== "allow" && behavior !== "allowAndName" && behavior !== "deny") {
2484
+ throw new ExecuteFileAccessError(`${method}: behavior must be allow, allowAndName or deny in execute code`);
2485
+ }
2486
+ if (downloadPath === undefined) {
2487
+ if (behavior !== "deny")
2488
+ throw new ExecuteFileAccessError(`${method}: behavior ${behavior} requires a downloadPath`);
2489
+ return {};
2490
+ }
2491
+ const resolved = check.downloadDirectory(downloadPath, `${method}({ downloadPath })`);
2492
+ Reflect.set(object, "downloadPath", resolved);
2493
+ return behavior === "deny" ? {} : { downloadDirectory: resolved };
2494
+ }
2495
+
2496
+ // src/execute-realm/directory-uploads.ts
2497
+ import fs2 from "node:fs";
2498
+ import path2 from "node:path";
2499
+
2500
+ // src/execute-realm/file-options.ts
2501
+ import buffer from "node:buffer";
2502
+ import util2 from "node:util";
2503
+ var fileOptionMethods = new Set([
2504
+ "screenshot",
2505
+ "pdf",
2506
+ "storageState",
2507
+ "start",
2508
+ "stop",
2509
+ "startChunk",
2510
+ "stopChunk",
2511
+ "startTracing",
2512
+ "stopTracing",
2513
+ "addScriptTag",
2514
+ "addStyleTag",
2515
+ "addInitScript",
2516
+ "fulfill",
2517
+ "newContext",
2518
+ "newPage",
2519
+ "routeFromHAR",
2520
+ "screenshotWithLabels",
2521
+ "screenshotDiff"
2522
+ ]);
2523
+ var fileOptionKeys = new Set(["path", "dir", "har", "storageState"]);
2524
+ var alwaysFileOptionKeys = new Set(["outputPath", "baseline", "certPath", "keyPath", "pfxPath", "tracesDir", "downloadsPath"]);
2525
+ var forbiddenOptionKeys = new Set(["executablePath", "recordHar", "recordVideo"]);
2526
+ var allFileOptionKeys = new Set([...fileOptionKeys, ...alwaysFileOptionKeys, ...forbiddenOptionKeys]);
2527
+ var fileOutputMethods = new Set(["screenshot", "pdf", "storageState", "stop", "stopChunk", "screenshotWithLabels", "screenshotDiff"]);
2528
+ var isFileOutputOption = (method, key) => key === "path" && fileOutputMethods.has(method) || key === "outputPath" && method === "stop";
2529
+ var clientCertificatePathKeys = new Set(["certPath", "keyPath", "pfxPath"]);
2530
+ function isPlainRecord2(value) {
2531
+ if (value === null || typeof value !== "object" || Array.isArray(value) || util2.types.isProxy(value))
2532
+ return false;
2533
+ const prototype = Object.getPrototypeOf(value);
2534
+ return prototype === Object.prototype || prototype === null;
2535
+ }
2536
+ function checkClientCertificates(value, method) {
2537
+ if (!Array.isArray(value) || util2.types.isProxy(value)) {
2538
+ throw new ExecuteFileAccessError(`${method}: clientCertificates must be an array of plain objects`);
2539
+ }
2540
+ const copy = new Array(value.length);
2541
+ let count = 0;
2542
+ for (const key of Reflect.ownKeys(value)) {
2543
+ if (key === "length" || typeof key !== "string" || !/^(0|[1-9]\d*)$/.test(key))
2544
+ continue;
2545
+ const index = Number(key);
2546
+ if (index >= value.length)
2547
+ continue;
2548
+ const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
2549
+ if (!("value" in descriptor)) {
2550
+ throw new ExecuteFileAccessError(`${method}: clientCertificates entries must be own data properties`);
2551
+ }
2552
+ copy[index] = descriptor.value;
2553
+ count += 1;
2554
+ }
2555
+ if (count !== value.length)
2556
+ throw new ExecuteFileAccessError(`${method}: clientCertificates must be a dense array`);
2557
+ for (const item of copy) {
2558
+ if (item === null || typeof item !== "object" || Array.isArray(item) || util2.types.isProxy(item)) {
2559
+ throw new ExecuteFileAccessError(`${method}: clientCertificates entries must be plain objects`);
2560
+ }
2561
+ const prototype = Object.getPrototypeOf(item);
2562
+ if (prototype !== Object.prototype && prototype !== null) {
2563
+ throw new ExecuteFileAccessError(`${method}: clientCertificates entries must be plain objects`);
2564
+ }
2565
+ for (const key of Reflect.ownKeys(item)) {
2566
+ if (typeof key !== "string")
2567
+ throw new ExecuteFileAccessError(`${method}: clientCertificates entries cannot have symbol properties`);
2568
+ const descriptor = Reflect.getOwnPropertyDescriptor(item, key);
2569
+ if (descriptor === undefined || !("value" in descriptor) || descriptor.enumerable !== true) {
2570
+ throw new ExecuteFileAccessError(`${method}: clientCertificates entries must have own enumerable data properties`);
2571
+ }
2572
+ if (clientCertificatePathKeys.has(key)) {
2573
+ const path = descriptor.value;
2574
+ if (path !== undefined && path !== null && typeof path !== "string") {
2575
+ throw new ExecuteFileAccessError(`${method}: clientCertificates ${key} must be a string`);
2576
+ }
2577
+ }
2578
+ }
2579
+ }
2580
+ return copy;
2581
+ }
2582
+ function checkFileStrings(value, method, checkPath) {
2583
+ if (value === undefined || value === null)
2584
+ return;
2585
+ if (typeof value === "string")
2586
+ return checkPath(value, method);
2587
+ if (Array.isArray(value)) {
2588
+ for (const item of value) {
2589
+ if (item === undefined || item === null)
2590
+ continue;
2591
+ if (typeof item !== "string")
2592
+ throw new ExecuteFileAccessError(`${method}: file paths must be strings`);
2593
+ checkPath(item, method);
2594
+ }
2595
+ return;
2596
+ }
2597
+ throw new ExecuteFileAccessError(`${method}: file paths must be strings`);
2598
+ }
2599
+ function checkFileOptions(value, method, includeMethodKeys, candidates, checkPath, depth = 0) {
2600
+ if (typeof value === "function") {
2601
+ if (depth === 0 && includeMethodKeys && method !== "addInitScript") {
2602
+ throw new ExecuteFileAccessError(`${method}: function arguments cannot be used as options`);
2603
+ }
2604
+ for (const key of allFileOptionKeys) {
2605
+ if (key in value || Reflect.get(value, key) !== undefined) {
2606
+ throw new ExecuteFileAccessError(`${method}: function arguments cannot carry the ${key} file option`);
2607
+ }
2608
+ }
2609
+ return;
2610
+ }
2611
+ if (depth > 4 || value === null || typeof value !== "object")
2612
+ return;
2613
+ if (Array.isArray(value)) {
2614
+ for (const item of value)
2615
+ checkFileOptions(item, method, includeMethodKeys, candidates, checkPath, depth + 1);
2616
+ return;
2617
+ }
2618
+ const prototype = Object.getPrototypeOf(value);
2619
+ if (prototype !== Object.prototype && prototype !== null)
2620
+ return;
2621
+ for (const [key, entry] of Object.entries(value)) {
2622
+ let item = entry;
2623
+ if (key === "clientCertificates" && includeMethodKeys && depth === 0 && item !== undefined && item !== null) {
2624
+ item = checkClientCertificates(item, method);
2625
+ if (!Reflect.set(value, key, item))
2626
+ throw new ExecuteFileAccessError(`${method}: could not store clientCertificates`);
2627
+ }
2628
+ if (forbiddenOptionKeys.has(key))
2629
+ throw new ExecuteFileAccessError(`${method}: the ${key} option is not available in execute code`);
2630
+ if (method === "fulfill" && depth === 0 && key === "json") {
2631
+ checkFileOptions(item, method, false, candidates, checkPath, depth + 1);
2632
+ continue;
2633
+ }
2634
+ if (alwaysFileOptionKeys.has(key) || includeMethodKeys && fileOptionKeys.has(key)) {
2635
+ if (item === undefined || item === null)
2636
+ continue;
2637
+ if (typeof item === "string") {
2638
+ const resolved = checkPath(item, `${method}({ ${key} })`);
2639
+ if (depth === 0 && isFileOutputOption(method, key))
2640
+ candidates.push({ path: resolved });
2641
+ Reflect.set(value, key, resolved);
2642
+ continue;
2643
+ }
2644
+ if (includeMethodKeys && depth === 0) {
2645
+ if (key === "baseline" && buffer.Buffer.isBuffer(item))
2646
+ continue;
2647
+ if (key === "storageState" && isPlainRecord2(item)) {
2648
+ checkFileOptions(item, method, false, candidates, checkPath, depth + 1);
2649
+ continue;
2650
+ }
2651
+ const allowed = key === "storageState" ? "a path string or inline state object" : key === "baseline" ? "a path string or Buffer" : "a path string";
2652
+ throw new ExecuteFileAccessError(`${method}: ${key} must be ${allowed}`);
2653
+ }
2654
+ }
2655
+ checkFileOptions(item, method, includeMethodKeys, candidates, checkPath, depth + 1);
2656
+ }
2657
+ }
2658
+
2659
+ // src/execute-realm/directory-uploads.ts
2660
+ var maxDirectoryUploadEntries = 1000;
2661
+ function checkDirectoryUpload(root, operation, check, budget) {
2662
+ let rootStat;
2663
+ try {
2664
+ rootStat = fs2.lstatSync(root);
2665
+ } catch (error) {
2666
+ if (error.code === "ENOENT")
2667
+ return;
2668
+ throw error;
2669
+ }
2670
+ if (rootStat.isSymbolicLink()) {
2671
+ throw new ExecuteFileAccessError(`${operation}: ${root} is a symlink; directory uploads cannot follow symlinks`);
2672
+ }
2673
+ if (!rootStat.isDirectory())
2674
+ return;
2675
+ const pending = [root];
2676
+ while (pending.length > 0) {
2677
+ const directory = pending.pop();
2678
+ for (const entry of fs2.readdirSync(directory, { withFileTypes: true })) {
2679
+ budget.entries += 1;
2680
+ if (budget.entries > maxDirectoryUploadEntries) {
2681
+ throw new ExecuteFileAccessError(`${operation}: folder uploads are limited to ${maxDirectoryUploadEntries} files and subfolders`);
2682
+ }
2683
+ const child = path2.join(directory, entry.name);
2684
+ if (entry.isSymbolicLink()) {
2685
+ throw new ExecuteFileAccessError(`${operation}: ${child} is a symlink; directory uploads cannot follow symlinks`);
2686
+ }
2687
+ const resolved = check(child, operation);
2688
+ const stat = fs2.lstatSync(resolved);
2689
+ if (stat.isSymbolicLink()) {
2690
+ throw new ExecuteFileAccessError(`${operation}: ${resolved} is a symlink; directory uploads cannot follow symlinks`);
2691
+ }
2692
+ if (stat.isDirectory())
2693
+ pending.push(resolved);
2694
+ }
2695
+ }
2696
+ }
2697
+ function checkFileInputValue(value, method, assertPath, checkEntry) {
2698
+ const budget = { entries: 0 };
2699
+ const check = (target) => {
2700
+ const resolved = assertPath(target, method);
2701
+ checkDirectoryUpload(resolved, method, checkEntry, budget);
2702
+ return resolved;
2703
+ };
2704
+ const checkValue = (item) => {
2705
+ if (typeof item === "string")
2706
+ return check(item);
2707
+ if (isPlainRecord2(item))
2708
+ return item;
2709
+ throw new ExecuteFileAccessError(`${method}: file inputs must be strings or file payload objects`);
2710
+ };
2711
+ if (Array.isArray(value))
2712
+ return value.map(checkValue);
2713
+ return checkValue(value);
2714
+ }
2715
+
2716
+ // src/execute-realm/drop-payload.ts
2717
+ function checkDropFile(value, checkFile) {
2718
+ if (typeof value === "string")
2719
+ return checkFile(value, "drop");
2720
+ if (isPlainRecord2(value))
2721
+ return value;
2722
+ throw new ExecuteFileAccessError("drop: files must be strings or file payload objects");
2723
+ }
2724
+ function checkDropFiles(value, checkFile) {
2725
+ if (Array.isArray(value))
2726
+ return value.map((item) => checkDropFile(item, checkFile));
2727
+ return checkDropFile(value, checkFile);
2728
+ }
2729
+ function checkDropPayload(value, checkFile) {
2730
+ if (!isPlainRecord2(value))
2731
+ throw new ExecuteFileAccessError("drop: the payload must be a plain object");
2732
+ const object = value;
2733
+ const files = Object.getOwnPropertyDescriptor(object, "files");
2734
+ if (files === undefined && "files" in object) {
2735
+ throw new ExecuteFileAccessError("drop: files must be an own property of the payload");
2736
+ }
2737
+ if (files !== undefined && !("value" in files)) {
2738
+ throw new ExecuteFileAccessError("drop: files must be a data property");
2739
+ }
2740
+ const copy = { ...object };
2741
+ if (files !== undefined && files.value !== undefined)
2742
+ copy.files = checkDropFiles(files.value, checkFile);
2743
+ return copy;
2744
+ }
2745
+
2746
+ // src/execute-realm/file-roots.ts
2316
2747
  var allowNodeEnvironmentVariable = "OPENCODE_BROWSER_ALLOW_NODE";
2317
2748
  var allowForegroundEnvironmentVariable = "OPENCODE_BROWSER_ALLOW_FOREGROUND";
2318
2749
  var fileRootsEnvironmentVariable = "OPENCODE_BROWSER_FILE_ROOTS";
@@ -2324,24 +2755,24 @@ function executeSliceMs() {
2324
2755
  var executeAllowsNode = () => process.env[allowNodeEnvironmentVariable] === "1";
2325
2756
  var executeAllowsForeground = () => process.env[allowForegroundEnvironmentVariable] === "1";
2326
2757
  var bringToFrontBlockedMessage = "page.bringToFront() is blocked: it raises the user's browser window over their work. Use handoff(message) when the user needs to act in the tab, or set OPENCODE_BROWSER_ALLOW_FOREGROUND=1 for the relay to allow it.";
2327
- var sandboxModules = { path: path2, url, util, crypto: crypto3, buffer, zlib, events, stream };
2758
+ var sandboxModules = { path: path3, url, util: util3, crypto: crypto3, buffer: buffer2, zlib, events, stream };
2328
2759
  var filesDirectoryPrefix = "opencode-browser-files-";
2329
2760
  var filesDirectoryPattern = /^opencode-browser-files-(\d+)-[A-Za-z0-9]{6}$/;
2330
2761
  var filesDirectory;
2331
2762
  var filesDirectoryExitHook = false;
2332
2763
  function executeFilesDirectory() {
2333
2764
  if (filesDirectory === undefined) {
2334
- filesDirectory = fs2.mkdtempSync(path2.join(os2.tmpdir(), `${filesDirectoryPrefix}${process.pid}-`));
2765
+ filesDirectory = fs3.mkdtempSync(path3.join(os2.tmpdir(), `${filesDirectoryPrefix}${process.pid}-`));
2335
2766
  if (!filesDirectoryExitHook) {
2336
2767
  filesDirectoryExitHook = true;
2337
2768
  process.once("exit", removeExecuteFilesDirectory);
2338
2769
  }
2339
2770
  }
2340
- const stat = fs2.lstatSync(filesDirectory);
2771
+ const stat = fs3.lstatSync(filesDirectory);
2341
2772
  if (!stat.isDirectory() || stat.isSymbolicLink() || process.getuid && (stat.uid !== process.getuid() || (stat.mode & 511) !== 448)) {
2342
2773
  throw new ExecuteFileAccessError("files.dir must be an owned, private directory, not a symlink");
2343
2774
  }
2344
- return fs2.realpathSync(filesDirectory);
2775
+ return fs3.realpathSync(filesDirectory);
2345
2776
  }
2346
2777
  function removeExecuteFilesDirectory() {
2347
2778
  const directory = filesDirectory;
@@ -2349,10 +2780,10 @@ function removeExecuteFilesDirectory() {
2349
2780
  if (directory === undefined)
2350
2781
  return;
2351
2782
  try {
2352
- const stat = fs2.lstatSync(directory);
2783
+ const stat = fs3.lstatSync(directory);
2353
2784
  if (!stat.isDirectory() || stat.isSymbolicLink())
2354
2785
  return;
2355
- fs2.rmSync(directory, { recursive: true, force: true });
2786
+ fs3.rmSync(directory, { recursive: true, force: true });
2356
2787
  } catch {}
2357
2788
  }
2358
2789
  var processAlive = (pid) => {
@@ -2367,7 +2798,7 @@ function pruneStaleExecuteFilesDirectories(tmp = os2.tmpdir()) {
2367
2798
  const removed = [];
2368
2799
  let entries;
2369
2800
  try {
2370
- entries = fs2.readdirSync(tmp);
2801
+ entries = fs3.readdirSync(tmp);
2371
2802
  } catch {
2372
2803
  return removed;
2373
2804
  }
@@ -2378,14 +2809,14 @@ function pruneStaleExecuteFilesDirectories(tmp = os2.tmpdir()) {
2378
2809
  const pid = Number(match[1]);
2379
2810
  if (!Number.isSafeInteger(pid) || pid <= 0 || pid === process.pid || processAlive(pid))
2380
2811
  continue;
2381
- const directory = path2.join(tmp, entry);
2812
+ const directory = path3.join(tmp, entry);
2382
2813
  try {
2383
- const stat = fs2.lstatSync(directory);
2814
+ const stat = fs3.lstatSync(directory);
2384
2815
  if (!stat.isDirectory() || stat.isSymbolicLink())
2385
2816
  continue;
2386
2817
  if (process.getuid && stat.uid !== process.getuid())
2387
2818
  continue;
2388
- fs2.rmSync(directory, { recursive: true, force: true });
2819
+ fs3.rmSync(directory, { recursive: true, force: true });
2389
2820
  removed.push(directory);
2390
2821
  } catch {}
2391
2822
  }
@@ -2393,17 +2824,17 @@ function pruneStaleExecuteFilesDirectories(tmp = os2.tmpdir()) {
2393
2824
  }
2394
2825
  function realpathOrSelf(target) {
2395
2826
  try {
2396
- return fs2.realpathSync(target);
2827
+ return fs3.realpathSync(target);
2397
2828
  } catch {
2398
- return path2.resolve(target);
2829
+ return path3.resolve(target);
2399
2830
  }
2400
2831
  }
2401
2832
  function executeFileRoots() {
2402
- const extra = (process.env[fileRootsEnvironmentVariable] ?? "").split(path2.delimiter).filter((entry) => path2.isAbsolute(entry));
2833
+ const extra = (process.env[fileRootsEnvironmentVariable] ?? "").split(path3.delimiter).filter((entry) => path3.isAbsolute(entry));
2403
2834
  const roots = [os2.tmpdir(), ...process.platform === "win32" ? [] : ["/tmp"], ...extra];
2404
2835
  return [...new Set(roots.map(realpathOrSelf))];
2405
2836
  }
2406
- var pathFlavor = (platform) => platform === "win32" ? path2.win32 : path2.posix;
2837
+ var pathFlavor = (platform) => platform === "win32" ? path3.win32 : path3.posix;
2407
2838
  var foldCase = (value, platform) => platform === "win32" || platform === "darwin" ? value.toLowerCase() : value;
2408
2839
  function isInside(child, parent, platform = process.platform) {
2409
2840
  const paths = pathFlavor(platform);
@@ -2414,24 +2845,20 @@ function isSamePath(a, b) {
2414
2845
  return isInside(a, b) && isInside(b, a);
2415
2846
  }
2416
2847
  function realTarget(target) {
2417
- let current = path2.resolve(target);
2848
+ let current = path3.resolve(target);
2418
2849
  const rest = [];
2419
2850
  for (;; ) {
2420
2851
  try {
2421
- return path2.join(fs2.realpathSync(current), ...rest.reverse());
2852
+ return path3.join(fs3.realpathSync(current), ...rest.reverse());
2422
2853
  } catch {
2423
- const parent = path2.dirname(current);
2854
+ const parent = path3.dirname(current);
2424
2855
  if (parent === current)
2425
- return path2.join(current, ...rest.reverse());
2426
- rest.push(path2.basename(current));
2856
+ return path3.join(current, ...rest.reverse());
2857
+ rest.push(path3.basename(current));
2427
2858
  current = parent;
2428
2859
  }
2429
2860
  }
2430
2861
  }
2431
-
2432
- class ExecuteFileAccessError extends Error {
2433
- name = "ExecuteFileAccessError";
2434
- }
2435
2862
  function browseDirectories() {
2436
2863
  return [...new Set([
2437
2864
  configRoot2(),
@@ -2457,41 +2884,44 @@ function isInstallSibling(target, binary, platform = process.platform) {
2457
2884
  }
2458
2885
  function isBinaryOrStaging(target, binary, platform) {
2459
2886
  const resolved = realTarget(binary);
2460
- const stagedAt = path2.join(realTarget(path2.dirname(binary)), path2.basename(binary));
2887
+ const stagedAt = path3.join(realTarget(path3.dirname(binary)), path3.basename(binary));
2461
2888
  return isInside(target, resolved, platform) || isInside(target, stagedAt, platform) || isInstallSibling(target, resolved, platform) || isInstallSibling(target, stagedAt, platform);
2462
2889
  }
2463
- function isBrowseOwned(target, platform = process.platform) {
2464
- if (browseDirectories().some((root) => isInside(target, realTarget(root), platform)))
2890
+ function browseOwnedDirectories() {
2891
+ return browseDirectories().map((root) => realTarget(root));
2892
+ }
2893
+ function isBrowseOwned(target, platform = process.platform, browse = browseOwnedDirectories()) {
2894
+ if (browse.some((root) => isInside(target, root, platform)))
2465
2895
  return true;
2466
2896
  return [installedBinaryPath(), installerBinaryPath()].some((binary) => isBinaryOrStaging(target, binary, platform));
2467
2897
  }
2468
- function assertExecuteFilePath(target, operation) {
2898
+ function assertExecuteFilePath(target, operation, options = {}) {
2469
2899
  if (typeof target !== "string" || target.length === 0) {
2470
2900
  throw new ExecuteFileAccessError(`${operation}: file paths must be non-empty strings`);
2471
2901
  }
2472
- const roots = executeFileRoots();
2902
+ const roots = options.roots ?? executeFileRoots();
2473
2903
  const describeRoots = () => `${roots.join(", ")} (add more with ${fileRootsEnvironmentVariable})`;
2474
- if (!path2.isAbsolute(target)) {
2904
+ if (!path3.isAbsolute(target)) {
2475
2905
  throw new ExecuteFileAccessError(`${operation}: use an absolute path inside ${describeRoots()}, for example files.path("name.png")`);
2476
2906
  }
2477
2907
  const resolved = realTarget(target);
2478
- if (isBrowseOwned(resolved)) {
2908
+ if (isBrowseOwned(resolved, process.platform, options.browseOwned)) {
2479
2909
  throw new ExecuteFileAccessError(`${operation}: ${target} is inside browse's own files, which execute code cannot access`);
2480
2910
  }
2481
2911
  if (!roots.some((root) => isInside(resolved, root))) {
2482
2912
  throw new ExecuteFileAccessError(`${operation}: ${target} is outside the execute file roots ${describeRoots()}. Set ${allowNodeEnvironmentVariable}=1 for unrestricted file access.`);
2483
2913
  }
2484
2914
  const root = roots.filter((root) => isInside(resolved, root)).sort((a, b) => b.length - a.length)[0];
2485
- const rootStat = fs2.statSync(root);
2915
+ const rootStat = fs3.statSync(root);
2486
2916
  if (process.getuid && (rootStat.mode & 18) !== 0 && (rootStat.mode & 512) === 0) {
2487
2917
  throw new ExecuteFileAccessError(`${operation}: shared writable roots must have the sticky bit set`);
2488
2918
  }
2489
- let spelling = path2.resolve(target);
2919
+ let spelling = path3.resolve(target);
2490
2920
  for (;; ) {
2491
2921
  try {
2492
- const stat = fs2.lstatSync(spelling);
2922
+ const stat = fs3.lstatSync(spelling);
2493
2923
  if (stat.isSymbolicLink()) {
2494
- const real = fs2.realpathSync(spelling);
2924
+ const real = fs3.realpathSync(spelling);
2495
2925
  if (stat.uid !== 0 || !roots.some((root) => isInside(root, real))) {
2496
2926
  throw new ExecuteFileAccessError(`${operation}: symlink paths are not available in execute code`);
2497
2927
  }
@@ -2500,7 +2930,7 @@ function assertExecuteFilePath(target, operation) {
2500
2930
  if (error.code !== "ENOENT")
2501
2931
  throw error;
2502
2932
  }
2503
- const parent = path2.dirname(spelling);
2933
+ const parent = path3.dirname(spelling);
2504
2934
  if (parent === spelling)
2505
2935
  break;
2506
2936
  spelling = parent;
@@ -2509,7 +2939,7 @@ function assertExecuteFilePath(target, operation) {
2509
2939
  while (isInside(current, root)) {
2510
2940
  let stat;
2511
2941
  try {
2512
- stat = fs2.lstatSync(current);
2942
+ stat = fs3.lstatSync(current);
2513
2943
  } catch (error) {
2514
2944
  if (error.code !== "ENOENT")
2515
2945
  throw error;
@@ -2524,24 +2954,88 @@ function assertExecuteFilePath(target, operation) {
2524
2954
  }
2525
2955
  if (current === root)
2526
2956
  break;
2527
- current = path2.dirname(current);
2957
+ current = path3.dirname(current);
2528
2958
  }
2529
- const parent = path2.dirname(resolved);
2530
- if (parent === root && process.getuid) {
2531
- const stat = fs2.statSync(parent);
2959
+ const parent = path3.dirname(resolved);
2960
+ const isFilesDirectory = options.directory === true && isSamePath(resolved, executeFilesDirectory());
2961
+ if (parent === root && process.getuid && !isFilesDirectory) {
2962
+ const stat = fs3.statSync(parent);
2532
2963
  if (stat.uid !== process.getuid() || (stat.mode & 18) !== 0) {
2533
2964
  throw new ExecuteFileAccessError(`${operation}: use a private subdirectory such as files.dir, not a shared temporary directory`);
2534
2965
  }
2535
2966
  }
2536
2967
  return resolved;
2537
2968
  }
2969
+ function executeFileRootOf(resolved, roots = executeFileRoots()) {
2970
+ return roots.find((root) => isSamePath(resolved, root));
2971
+ }
2972
+ function assertExecuteFilePathNotRoot(target, operation, options = {}) {
2973
+ const resolved = assertExecuteFilePath(target, operation, options);
2974
+ if (executeFileRootOf(resolved, options.roots) !== undefined) {
2975
+ throw new ExecuteFileAccessError(`${operation}: ${target} is an execute file root; use a path inside it`);
2976
+ }
2977
+ return resolved;
2978
+ }
2979
+ function checkUploadValue(value, method) {
2980
+ const options = { roots: executeFileRoots(), browseOwned: browseOwnedDirectories() };
2981
+ const assertPath = (target, operation) => assertExecuteFilePathNotRoot(target, operation, options);
2982
+ const checkEntry = (target, operation) => assertExecuteFilePath(target, operation, options);
2983
+ return checkFileInputValue(value, method, assertPath, checkEntry);
2984
+ }
2985
+ function isStreamReceiver(receiver) {
2986
+ try {
2987
+ return receiver instanceof stream.Stream;
2988
+ } catch {
2989
+ return false;
2990
+ }
2991
+ }
2992
+ function isIteratorReceiver(receiver) {
2993
+ try {
2994
+ const Iterator = globalThis.Iterator;
2995
+ return typeof Iterator === "function" && receiver instanceof Iterator;
2996
+ } catch {
2997
+ return false;
2998
+ }
2999
+ }
3000
+ function isBrowserReceiver(receiver) {
3001
+ if (receiver === null || typeof receiver !== "object" || util3.types.isProxy(receiver))
3002
+ return false;
3003
+ try {
3004
+ const prototype = Object.getPrototypeOf(receiver);
3005
+ const name = prototype?.constructor?.name;
3006
+ return typeof name === "string" && name.replace(/\d+$/, "") === "Browser";
3007
+ } catch {
3008
+ return false;
3009
+ }
3010
+ }
3011
+ function assertExecuteFileInputPath(target, operation) {
3012
+ const resolved = assertExecuteFilePathNotRoot(target, operation);
3013
+ let stat;
3014
+ try {
3015
+ stat = fs3.lstatSync(resolved);
3016
+ } catch (error) {
3017
+ if (error.code !== "ENOENT")
3018
+ throw error;
3019
+ }
3020
+ if (stat?.isDirectory()) {
3021
+ throw new ExecuteFileAccessError(`${operation}: ${target} is a directory; use a file inside the execute file roots`);
3022
+ }
3023
+ return resolved;
3024
+ }
3025
+ function assertExecuteDownloadDirectory(target, operation) {
3026
+ const resolved = assertExecuteFilePath(target, operation, { directory: true });
3027
+ if (executeFileRootOf(resolved) !== undefined) {
3028
+ throw new ExecuteFileAccessError(`${operation}: ${target} is an execute file root; use a subfolder such as files.path("downloads")`);
3029
+ }
3030
+ return resolved;
3031
+ }
2538
3032
  async function openExecuteFile(target, write) {
2539
3033
  const operation = write ? "files.write" : "files.read";
2540
3034
  const resolved = assertExecuteFilePath(target, operation);
2541
3035
  if (write)
2542
- await fsPromises.mkdir(path2.dirname(resolved), { recursive: true, mode: 448 });
3036
+ await fsPromises.mkdir(path3.dirname(resolved), { recursive: true, mode: 448 });
2543
3037
  assertExecuteFilePath(resolved, operation);
2544
- const handle = await fsPromises.open(resolved, fs2.constants.O_NOFOLLOW | fs2.constants.O_NONBLOCK | (write ? fs2.constants.O_WRONLY | fs2.constants.O_CREAT : fs2.constants.O_RDONLY), 384);
3038
+ const handle = await fsPromises.open(resolved, fs3.constants.O_NOFOLLOW | fs3.constants.O_NONBLOCK | (write ? fs3.constants.O_WRONLY | fs3.constants.O_CREAT : fs3.constants.O_RDONLY), 384);
2545
3039
  try {
2546
3040
  const stat = await handle.stat();
2547
3041
  const current = await fsPromises.lstat(resolved);
@@ -2559,7 +3053,7 @@ async function openExecuteFile(target, write) {
2559
3053
  }
2560
3054
  function createExecuteFiles() {
2561
3055
  const dir = executeFilesDirectory();
2562
- const resolveTarget = (target) => path2.isAbsolute(target) ? target : path2.join(dir, target);
3056
+ const resolveTarget = (target) => path3.isAbsolute(target) ? target : path3.join(dir, target);
2563
3057
  return {
2564
3058
  dir,
2565
3059
  roots: executeFileRoots(),
@@ -2590,36 +3084,11 @@ function createExecuteFiles() {
2590
3084
  }
2591
3085
  };
2592
3086
  }
2593
- var fileOptionMethods = new Set([
2594
- "screenshot",
2595
- "pdf",
2596
- "storageState",
2597
- "start",
2598
- "stop",
2599
- "startChunk",
2600
- "stopChunk",
2601
- "startTracing",
2602
- "stopTracing",
2603
- "addScriptTag",
2604
- "addStyleTag",
2605
- "addInitScript",
2606
- "fulfill",
2607
- "newContext",
2608
- "newPage",
2609
- "routeFromHAR",
2610
- "screenshotWithLabels",
2611
- "screenshotDiff"
2612
- ]);
2613
- var fileOptionKeys = new Set(["path", "dir", "har", "storageState"]);
2614
- var alwaysFileOptionKeys = new Set(["outputPath", "baseline", "certPath", "keyPath", "pfxPath", "tracesDir", "downloadsPath"]);
2615
- var forbiddenOptionKeys = new Set(["executablePath", "recordHar", "recordVideo"]);
2616
- var fileOutputMethods = new Set(["screenshot", "pdf", "storageState", "stop", "stopChunk", "screenshotWithLabels", "screenshotDiff"]);
2617
- var isFileOutputOption = (method, key) => key === "path" && fileOutputMethods.has(method) || key === "outputPath" && method === "stop";
2618
3087
  var startedTraces = new WeakMap;
2619
3088
  var isObject2 = (value) => value !== null && typeof value === "object";
2620
3089
  function fileExists(target) {
2621
3090
  try {
2622
- fs2.lstatSync(target);
3091
+ fs3.lstatSync(target);
2623
3092
  return true;
2624
3093
  } catch (error) {
2625
3094
  if (error.code === "ENOENT")
@@ -2631,21 +3100,21 @@ function outputDirectoryError(directory) {
2631
3100
  return new ExecuteFileAccessError(`file outputs must use real, owned directories without group/world write access, not ${directory}`);
2632
3101
  }
2633
3102
  function pinPrivateDirectory(directory, uid) {
2634
- const descriptor = fs2.openSync(directory, fs2.constants.O_RDONLY | fs2.constants.O_DIRECTORY | fs2.constants.O_NOFOLLOW);
3103
+ const descriptor = fs3.openSync(directory, fs3.constants.O_RDONLY | fs3.constants.O_DIRECTORY | fs3.constants.O_NOFOLLOW);
2635
3104
  try {
2636
- const opened = fs2.fstatSync(descriptor);
2637
- const current = fs2.lstatSync(directory);
3105
+ const opened = fs3.fstatSync(descriptor);
3106
+ const current = fs3.lstatSync(directory);
2638
3107
  if (!opened.isDirectory() || opened.uid !== uid || current.isSymbolicLink() || current.dev !== opened.dev || current.ino !== opened.ino) {
2639
3108
  throw outputDirectoryError(directory);
2640
3109
  }
2641
3110
  if ((opened.mode & 511) !== 448)
2642
- fs2.fchmodSync(descriptor, 448);
3111
+ fs3.fchmodSync(descriptor, 448);
2643
3112
  } finally {
2644
- fs2.closeSync(descriptor);
3113
+ fs3.closeSync(descriptor);
2645
3114
  }
2646
3115
  }
2647
3116
  function ensureExecuteOutputDirectory(directory) {
2648
- const resolved = path2.resolve(directory);
3117
+ const resolved = path3.resolve(directory);
2649
3118
  const roots = executeFileRoots();
2650
3119
  const root = roots.filter((candidate) => isInside(resolved, candidate)).sort((a, b) => b.length - a.length)[0];
2651
3120
  if (root === undefined)
@@ -2656,7 +3125,7 @@ function ensureExecuteOutputDirectory(directory) {
2656
3125
  for (;; ) {
2657
3126
  let stat;
2658
3127
  try {
2659
- stat = fs2.lstatSync(current);
3128
+ stat = fs3.lstatSync(current);
2660
3129
  } catch (error) {
2661
3130
  if (error.code !== "ENOENT")
2662
3131
  throw error;
@@ -2673,7 +3142,7 @@ function ensureExecuteOutputDirectory(directory) {
2673
3142
  }
2674
3143
  if (isSamePath(current, root))
2675
3144
  break;
2676
- const parent = path2.dirname(current);
3145
+ const parent = path3.dirname(current);
2677
3146
  if (parent === current)
2678
3147
  throw outputDirectoryError(current);
2679
3148
  current = parent;
@@ -2681,7 +3150,7 @@ function ensureExecuteOutputDirectory(directory) {
2681
3150
  for (const step of missing.reverse()) {
2682
3151
  let created = false;
2683
3152
  try {
2684
- fs2.mkdirSync(step, { mode: 448 });
3153
+ fs3.mkdirSync(step, { mode: 448 });
2685
3154
  created = true;
2686
3155
  } catch (error) {
2687
3156
  if (error.code !== "EEXIST")
@@ -2689,7 +3158,7 @@ function ensureExecuteOutputDirectory(directory) {
2689
3158
  }
2690
3159
  if (created && uid !== undefined && process.platform !== "win32")
2691
3160
  pinPrivateDirectory(step, uid);
2692
- const stat = fs2.lstatSync(step);
3161
+ const stat = fs3.lstatSync(step);
2693
3162
  if (!stat.isDirectory() || stat.isSymbolicLink() || uid !== undefined && (stat.uid !== uid || (stat.mode & 18) !== 0)) {
2694
3163
  throw outputDirectoryError(step);
2695
3164
  }
@@ -2704,22 +3173,22 @@ function secureExecuteFileOutputs(outputs) {
2704
3173
  if (output.existed)
2705
3174
  continue;
2706
3175
  try {
2707
- const before = fs2.lstatSync(output.path);
3176
+ const before = fs3.lstatSync(output.path);
2708
3177
  if (!before.isFile() || before.uid !== uid || before.nlink !== 1)
2709
3178
  continue;
2710
- const descriptor = fs2.openSync(output.path, fs2.constants.O_RDONLY | fs2.constants.O_NOFOLLOW | fs2.constants.O_NONBLOCK);
3179
+ const descriptor = fs3.openSync(output.path, fs3.constants.O_RDONLY | fs3.constants.O_NOFOLLOW | fs3.constants.O_NONBLOCK);
2711
3180
  try {
2712
- const opened = fs2.fstatSync(descriptor);
2713
- const current = fs2.lstatSync(output.path);
3181
+ const opened = fs3.fstatSync(descriptor);
3182
+ const current = fs3.lstatSync(output.path);
2714
3183
  if (!opened.isFile() || opened.uid !== uid || opened.nlink !== 1 || current.isSymbolicLink() || current.dev !== opened.dev || current.ino !== opened.ino)
2715
3184
  continue;
2716
- assertExecuteFilePath(path2.join(path2.dirname(output.path), `.execute-output-${crypto3.randomUUID()}`), operation);
2717
- fs2.fchmodSync(descriptor, 384);
3185
+ assertExecuteFilePath(path3.join(path3.dirname(output.path), `.execute-output-${crypto3.randomUUID()}`), operation);
3186
+ fs3.fchmodSync(descriptor, 384);
2718
3187
  assertExecuteFilePath(output.path, operation);
2719
3188
  if (process.platform === "linux")
2720
- assertExecuteFilePath(fs2.realpathSync(`/proc/self/fd/${descriptor}`), operation);
3189
+ assertExecuteFilePath(fs3.realpathSync(`/proc/self/fd/${descriptor}`), operation);
2721
3190
  } finally {
2722
- fs2.closeSync(descriptor);
3191
+ fs3.closeSync(descriptor);
2723
3192
  }
2724
3193
  } catch {}
2725
3194
  }
@@ -2734,9 +3203,11 @@ function prepareExecuteFileOutputs(call) {
2734
3203
  }
2735
3204
  const outputs = [];
2736
3205
  for (const candidate of call.outputs) {
2737
- assertExecuteFilePath(candidate.path, "execute file output");
2738
- ensureExecuteOutputDirectory(path2.dirname(candidate.path));
2739
- const resolved = assertExecuteFilePath(candidate.path, "execute file output");
3206
+ assertExecuteFilePath(candidate.path, "execute file output", { directory: candidate.directory === true });
3207
+ ensureExecuteOutputDirectory(candidate.directory === true ? candidate.path : path3.dirname(candidate.path));
3208
+ const resolved = assertExecuteFilePath(candidate.path, "execute file output", { directory: candidate.directory === true });
3209
+ if (candidate.directory === true)
3210
+ continue;
2740
3211
  outputs.push({ path: resolved, existed: fileExists(resolved) });
2741
3212
  }
2742
3213
  const stop = call.traceStop;
@@ -2750,7 +3221,7 @@ function completeExecuteFileOutputs(result, prepared) {
2750
3221
  };
2751
3222
  if (prepared.outputs.length === 0 && prepared.forgetTrace === undefined)
2752
3223
  return result;
2753
- if (!util.types.isPromise(result)) {
3224
+ if (!util3.types.isPromise(result)) {
2754
3225
  settle(true);
2755
3226
  return result;
2756
3227
  }
@@ -2762,46 +3233,17 @@ function completeExecuteFileOutputs(result, prepared) {
2762
3233
  throw error;
2763
3234
  });
2764
3235
  }
2765
- function checkFileOptions(value, method, includeMethodKeys, candidates, depth = 0) {
2766
- if (depth > 4 || value === null || typeof value !== "object")
2767
- return;
2768
- if (Array.isArray(value)) {
2769
- for (const item of value)
2770
- checkFileOptions(item, method, includeMethodKeys, candidates, depth + 1);
2771
- return;
2772
- }
2773
- const prototype = Object.getPrototypeOf(value);
2774
- if (prototype !== Object.prototype && prototype !== null)
2775
- return;
2776
- for (const [key, item] of Object.entries(value)) {
2777
- if (forbiddenOptionKeys.has(key))
2778
- throw new ExecuteFileAccessError(`${method}: the ${key} option is not available in execute code`);
2779
- if (typeof item === "string" && (alwaysFileOptionKeys.has(key) || includeMethodKeys && fileOptionKeys.has(key))) {
2780
- const resolved = assertExecuteFilePath(item, `${method}({ ${key} })`);
2781
- if (depth === 0 && isFileOutputOption(method, key))
2782
- candidates.push({ path: resolved });
2783
- Reflect.set(value, key, resolved);
2784
- } else {
2785
- checkFileOptions(item, method, includeMethodKeys, candidates, depth + 1);
2786
- }
2787
- }
2788
- }
2789
- function checkFileStrings(value, method) {
2790
- if (typeof value === "string")
2791
- return assertExecuteFilePath(value, method);
2792
- if (Array.isArray(value)) {
2793
- for (const item of value)
2794
- if (typeof item === "string")
2795
- assertExecuteFilePath(item, method);
2796
- }
2797
- return;
2798
- }
2799
- var promiseReturningNames = new Set([...fileOptionMethods, "setInputFiles", "setFiles", "saveAs", "bringToFront", "send"]);
3236
+ var promiseReturningNames = new Set([...fileOptionMethods, "setInputFiles", "setFiles", "saveAs", "bringToFront"]);
2800
3237
  function returnsPromise(fn) {
2801
- return util.types.isAsyncFunction(fn) || promiseReturningNames.has(typeof fn.name === "string" ? fn.name.replace(/^bound /, "") : "");
3238
+ return util3.types.isAsyncFunction(fn) || promiseReturningNames.has(typeof fn.name === "string" ? fn.name.replace(/^bound /, "") : "");
2802
3239
  }
2803
3240
  function checkHostCall(fn, receiver, args) {
2804
3241
  const name = typeof fn.name === "string" ? fn.name.replace(/^bound /, "") : "";
3242
+ const setArgument = (index, value) => {
3243
+ args[index] = value;
3244
+ };
3245
+ const sendMethod = name === "send" ? args[0] : undefined;
3246
+ const cdpSessionSend = name === "send" && isCdpSession(receiver);
2805
3247
  if (receiver !== null && typeof receiver === "object") {
2806
3248
  const constructor = Reflect.getOwnPropertyDescriptor(receiver, "constructor")?.value;
2807
3249
  if (typeof constructor === "function" && constructor.prototype === receiver) {
@@ -2811,23 +3253,69 @@ function checkHostCall(fn, receiver, args) {
2811
3253
  if (name === "fetch" || name === "routeFromHAR" || name === "fulfill" && args.some((arg) => arg !== null && typeof arg === "object" && ("response" in arg))) {
2812
3254
  throw new Error(`${name}: Node-side requests and response/HAR replay are not available in execute code; use browser requests or route.fulfill({ body })`);
2813
3255
  }
2814
- if ((name === "bringToFront" || name === "send" && args[0] === "Page.bringToFront") && !executeAllowsForeground()) {
3256
+ if (name === "bind" && isBrowserReceiver(receiver)) {
3257
+ throw new ExecuteFileAccessError("bind: starting a browser server is not available in execute code");
3258
+ }
3259
+ if ((name === "bringToFront" || name === "send" && sendMethod === "Page.bringToFront") && !executeAllowsForeground()) {
2815
3260
  throw new Error(bringToFrontBlockedMessage);
2816
3261
  }
2817
3262
  const candidates = [];
2818
- if (name === "setInputFiles") {
3263
+ if (name === "send") {
3264
+ const bufferMessage = buffer2.Buffer.isBuffer(sendMethod) || util3.types.isUint8Array(sendMethod);
3265
+ if (typeof sendMethod !== "string" && (cdpSessionSend || !bufferMessage)) {
3266
+ throw new ExecuteFileAccessError(cdpSessionSend ? "CDPSession.send: the method must be a primitive string" : "send: the message must be a string or Buffer");
3267
+ }
3268
+ let method;
3269
+ if (typeof sendMethod === "string") {
3270
+ if (cdpSessionSend) {
3271
+ if (!isCdpMethodName(sendMethod))
3272
+ throw new ExecuteFileAccessError(`CDPSession.send: ${JSON.stringify(sendMethod)} is not a CDP method name`);
3273
+ method = sendMethod;
3274
+ } else if (isCdpMethodName(sendMethod)) {
3275
+ method = sendMethod;
3276
+ }
3277
+ }
3278
+ if (method !== undefined) {
3279
+ const sendParams = args.length > 1 ? args[1] : undefined;
3280
+ const params = sendParams === undefined ? undefined : copyCdpParameters(sendParams, method);
3281
+ if (params !== undefined)
3282
+ setArgument(1, params);
3283
+ const checked = checkCdpSend(method, params, { fileInput: assertExecuteFileInputPath, downloadDirectory: assertExecuteDownloadDirectory });
3284
+ if (checked.downloadDirectory !== undefined)
3285
+ candidates.push({ path: checked.downloadDirectory, directory: true });
3286
+ }
3287
+ } else if (name === "setInputFiles") {
2819
3288
  const isFrameLike = receiver !== null && typeof receiver === "object" && typeof receiver.goto === "function";
2820
- checkFileStrings(isFrameLike ? args[1] : args[0], "setInputFiles");
3289
+ if (isFrameLike)
3290
+ setArgument(1, checkUploadValue(args[1], "setInputFiles"));
3291
+ else
3292
+ setArgument(0, checkUploadValue(args[0], "setInputFiles"));
3293
+ } else if (name === "setFiles") {
3294
+ setArgument(0, checkUploadValue(args[0], name));
3295
+ } else if (name === "drop") {
3296
+ const payload = args[0];
3297
+ if (payload !== undefined && !isStreamReceiver(receiver) && !isIteratorReceiver(receiver)) {
3298
+ setArgument(0, checkDropPayload(payload, assertExecuteFileInputPath));
3299
+ }
3300
+ } else if (name === "setStorageState") {
3301
+ const value = args[0];
3302
+ if (typeof value === "string")
3303
+ setArgument(0, assertExecuteFilePathNotRoot(value, name));
3304
+ else if (value !== undefined && value !== null && !isPlainRecord2(value)) {
3305
+ throw new ExecuteFileAccessError(`${name}: storage state must be a path string or a plain object`);
3306
+ }
2821
3307
  } else if (name === "saveAs") {
2822
- const target = checkFileStrings(args[0], name);
3308
+ const target = checkFileStrings(args[0], name, assertExecuteFilePath);
2823
3309
  if (target !== undefined)
2824
3310
  candidates.push({ path: target });
2825
- } else if (name === "setFiles" || name === "routeFromHAR") {
2826
- checkFileStrings(args[0], name);
3311
+ } else if (name === "routeFromHAR") {
3312
+ checkFileStrings(args[0], name, assertExecuteFilePath);
2827
3313
  }
2828
3314
  const includeMethodKeys = fileOptionMethods.has(name);
2829
- for (const arg of args)
2830
- checkFileOptions(arg, name || "call", includeMethodKeys, candidates);
3315
+ for (let index = 0;index < args.length; index += 1) {
3316
+ const methodKeys = includeMethodKeys && !(name === "addInitScript" && index === 1 && typeof args[0] === "function");
3317
+ checkFileOptions(args[index], name || "call", methodKeys, candidates, assertExecuteFilePath);
3318
+ }
2831
3319
  if (name === "startTracing" && isObject2(receiver)) {
2832
3320
  const path = isObject2(args[1]) ? Reflect.get(args[1], "path") : undefined;
2833
3321
  const trace = typeof path === "string" ? assertExecuteFilePath(path, "startTracing({ path })") : undefined;
@@ -2877,7 +3365,7 @@ import crypto4 from "node:crypto";
2877
3365
  import dgram from "node:dgram";
2878
3366
  import dns2 from "node:dns";
2879
3367
  import events2 from "node:events";
2880
- import fs3 from "node:fs";
3368
+ import fs4 from "node:fs";
2881
3369
  import fsPromises2 from "node:fs/promises";
2882
3370
  import http from "node:http";
2883
3371
  import http2 from "node:http2";
@@ -2888,14 +3376,14 @@ import net from "node:net";
2888
3376
  import os3 from "node:os";
2889
3377
  import { AsyncLocalStorage } from "node:async_hooks";
2890
3378
  import tls from "node:tls";
2891
- import util3 from "node:util";
3379
+ import util5 from "node:util";
2892
3380
  import v8 from "node:v8";
2893
3381
  import vm from "node:vm";
2894
3382
  import workerThreads from "node:worker_threads";
2895
3383
  import * as acorn from "acorn";
2896
3384
 
2897
3385
  // src/execute-realm/rejection-text.ts
2898
- import util2 from "node:util";
3386
+ import util4 from "node:util";
2899
3387
  var placeholder = "reason not shown";
2900
3388
  var nativeStackGetter = Object.getOwnPropertyDescriptor(new Error, "stack")?.get;
2901
3389
  function safeErrorMessage(value, maxLength = 300) {
@@ -2927,7 +3415,7 @@ function safeErrorStack(value) {
2927
3415
  }
2928
3416
  }
2929
3417
  function isSafeNativeError(value) {
2930
- return typeof value === "object" && value !== null && !util2.types.isProxy(value) && util2.types.isNativeError(value);
3418
+ return typeof value === "object" && value !== null && !util4.types.isProxy(value) && util4.types.isNativeError(value);
2931
3419
  }
2932
3420
  function isSafeHostError(value) {
2933
3421
  if (!isSafeNativeError(value))
@@ -2936,7 +3424,7 @@ function isSafeHostError(value) {
2936
3424
  for (let depth = 0;prototype !== null && depth < 32; depth += 1) {
2937
3425
  if (prototype === Error.prototype)
2938
3426
  return true;
2939
- if (util2.types.isProxy(prototype))
3427
+ if (util4.types.isProxy(prototype))
2940
3428
  return false;
2941
3429
  prototype = Object.getPrototypeOf(prototype);
2942
3430
  }
@@ -2951,9 +3439,9 @@ function ownDataProperty(value, key) {
2951
3439
  var deniedHostValues = new Map([
2952
3440
  [process, "process"],
2953
3441
  [globalThis, "the relay's global object"],
2954
- [fs3, "fs"],
3442
+ [fs4, "fs"],
2955
3443
  [fsPromises2, "fs/promises"],
2956
- [fs3.promises, "fs/promises"],
3444
+ [fs4.promises, "fs/promises"],
2957
3445
  [childProcess, "child_process"],
2958
3446
  [cluster, "cluster"],
2959
3447
  [dgram, "dgram"],
@@ -2971,9 +3459,9 @@ var deniedHostValues = new Map([
2971
3459
  [workerThreads, "worker_threads"],
2972
3460
  [globalThis.fetch, "Node fetch"],
2973
3461
  [eval, "eval"],
2974
- [util3.inspect, "host object inspection"],
2975
- [util3.format, "host object formatting"],
2976
- [util3.formatWithOptions, "host object formatting"],
3462
+ [util5.inspect, "host object inspection"],
3463
+ [util5.format, "host object formatting"],
3464
+ [util5.formatWithOptions, "host object formatting"],
2977
3465
  [crypto4.setEngine, "loading native crypto engines"],
2978
3466
  [events2.setMaxListeners, "changing shared event-emitter defaults or prototypes"],
2979
3467
  ...[crypto4.pbkdf2Sync, crypto4.scryptSync, crypto4.hkdfSync, crypto4.generateKeyPairSync, crypto4.generateKeySync, crypto4.generatePrimeSync, crypto4.checkPrimeSync].map((fn) => [fn, `crypto.${fn.name} (blocks the relay; use the async version)`])
@@ -3471,7 +3959,7 @@ class ExecuteRealm {
3471
3959
  toSandbox(value, seen = new Map) {
3472
3960
  if (!isObjectLike(value))
3473
3961
  return value;
3474
- if (value === Buffer.allocUnsafe || value === Buffer.allocUnsafeSlow || value === buffer2.SlowBuffer)
3962
+ if (value === Buffer.allocUnsafe || value === Buffer.allocUnsafeSlow || value === buffer3.SlowBuffer)
3475
3963
  return this.toSandbox(Buffer.alloc);
3476
3964
  if (this.hostBySandboxProxy.has(value))
3477
3965
  return value;
@@ -3491,7 +3979,7 @@ class ExecuteRealm {
3491
3979
  throw this.sandboxError(`${denied} is not available in execute code. Set ${allowNodeEnvironmentVariable}=1 for full Node access.`);
3492
3980
  if (this.isSandboxNative(value))
3493
3981
  return value;
3494
- if (util4.types.isPromise(value))
3982
+ if (util6.types.isPromise(value))
3495
3983
  return this.toSandboxPromise(value);
3496
3984
  if (Buffer.isBuffer(value)) {
3497
3985
  const copy = Buffer.alloc(value.length);
@@ -3500,11 +3988,11 @@ class ExecuteRealm {
3500
3988
  this.sandboxProxyByHost.set(value, proxy);
3501
3989
  return proxy;
3502
3990
  }
3503
- if (util4.types.isArrayBuffer(value)) {
3991
+ if (util6.types.isArrayBuffer(value)) {
3504
3992
  const SandboxUint8Array = this.sandboxIntrinsics.Uint8Array;
3505
3993
  return new SandboxUint8Array(new Uint8Array(value)).buffer;
3506
3994
  }
3507
- if (util4.types.isTypedArray(value) && !Buffer.isBuffer(value)) {
3995
+ if (util6.types.isTypedArray(value) && !Buffer.isBuffer(value)) {
3508
3996
  const name = Object.prototype.toString.call(value).slice(8, -1);
3509
3997
  const Constructor = this.sandboxIntrinsics[name] ?? this.sandboxIntrinsics.Uint8Array;
3510
3998
  return new Constructor(value);
@@ -3514,7 +4002,7 @@ class ExecuteRealm {
3514
4002
  throw this.sandboxError(deniedClass);
3515
4003
  if (!this.forceProxy.has(value) && typeof value === "object") {
3516
4004
  const prototype = Reflect.getPrototypeOf(value);
3517
- if (Array.isArray(value) && prototype === Array.prototype || util4.types.isArgumentsObject(value)) {
4005
+ if (Array.isArray(value) && prototype === Array.prototype || util6.types.isArgumentsObject(value)) {
3518
4006
  const output = [];
3519
4007
  Reflect.setPrototypeOf(output, this.sandboxArrayPrototype);
3520
4008
  seen.set(value, output);
@@ -3523,7 +4011,7 @@ class ExecuteRealm {
3523
4011
  output[index] = this.toSandbox(array[index], seen);
3524
4012
  return output;
3525
4013
  }
3526
- if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !util4.types.isProxy(value)) {
4014
+ if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !util6.types.isProxy(value)) {
3527
4015
  const output = Object.create(prototype === null ? null : this.sandboxObjectPrototype);
3528
4016
  seen.set(value, output);
3529
4017
  for (const key of Object.keys(value)) {
@@ -3776,16 +4264,16 @@ class ExecuteRealm {
3776
4264
  }
3777
4265
  }
3778
4266
  copyToHost(value, seen) {
3779
- if (util4.types.isPromise(value))
4267
+ if (util6.types.isPromise(value))
3780
4268
  return this.toHostPromise(value);
3781
- if (util4.types.isDate(value))
4269
+ if (util6.types.isDate(value))
3782
4270
  return new Date(Date.prototype.getTime.call(value));
3783
- if (util4.types.isRegExp(value)) {
4271
+ if (util6.types.isRegExp(value)) {
3784
4272
  const source = Reflect.get(value, "source");
3785
4273
  const flags = Reflect.get(value, "flags");
3786
4274
  return new RegExp(String(source), String(flags));
3787
4275
  }
3788
- if (util4.types.isNativeError(value) || value instanceof this.SandboxError) {
4276
+ if (util6.types.isNativeError(value) || value instanceof this.SandboxError) {
3789
4277
  const name = String(Reflect.get(value, "name") ?? "Error");
3790
4278
  const output = new Error(String(Reflect.get(value, "message") ?? ""));
3791
4279
  seen.set(value, output);
@@ -3803,26 +4291,26 @@ class ExecuteRealm {
3803
4291
  Object.defineProperty(output, "cause", { value: this.toHost(cause, seen), configurable: true, writable: true });
3804
4292
  return output;
3805
4293
  }
3806
- if (util4.types.isMap(value)) {
4294
+ if (util6.types.isMap(value)) {
3807
4295
  const output = new Map;
3808
4296
  seen.set(value, output);
3809
4297
  Map.prototype.forEach.call(value, (item, key) => output.set(this.toHost(key, seen), this.toHost(item, seen)));
3810
4298
  return output;
3811
4299
  }
3812
- if (util4.types.isSet(value)) {
4300
+ if (util6.types.isSet(value)) {
3813
4301
  const output = new Set;
3814
4302
  seen.set(value, output);
3815
4303
  Set.prototype.forEach.call(value, (item) => output.add(this.toHost(item, seen)));
3816
4304
  return output;
3817
4305
  }
3818
- if (util4.types.isArrayBuffer(value))
4306
+ if (util6.types.isArrayBuffer(value))
3819
4307
  return new Uint8Array(new Uint8Array(value)).buffer;
3820
- if (util4.types.isTypedArray(value)) {
4308
+ if (util6.types.isTypedArray(value)) {
3821
4309
  const name = Object.prototype.toString.call(value).slice(8, -1);
3822
4310
  const Constructor = globalThis[name] ?? Uint8Array;
3823
4311
  return new Constructor(value);
3824
4312
  }
3825
- if (Array.isArray(value) || util4.types.isArgumentsObject(value)) {
4313
+ if (Array.isArray(value) || util6.types.isArgumentsObject(value)) {
3826
4314
  const output = [];
3827
4315
  seen.set(value, output);
3828
4316
  const array = value;
@@ -3947,7 +4435,7 @@ class ExecuteRealm {
3947
4435
  }
3948
4436
 
3949
4437
  // src/execute/code-runner.ts
3950
- import fs4 from "node:fs";
4438
+ import fs5 from "node:fs";
3951
4439
  import http3 from "node:http";
3952
4440
  import https2 from "node:https";
3953
4441
  import os4 from "node:os";
@@ -4052,7 +4540,7 @@ function describe(arg) {
4052
4540
  }
4053
4541
 
4054
4542
  // src/execute/log-capture.ts
4055
- import util5 from "node:util";
4543
+ import util7 from "node:util";
4056
4544
  var maxCapturedPageLogs = 50;
4057
4545
  var maxCapturedScriptLogs = 100;
4058
4546
  function createExecuteLogCapture(limits = {}) {
@@ -4241,7 +4729,7 @@ function formatLogValue(value) {
4241
4729
  if (isString(value)) {
4242
4730
  return value;
4243
4731
  }
4244
- return util5.inspect(value, { depth: 4, colors: false, maxArrayLength: 100, maxStringLength: 1000 });
4732
+ return util7.inspect(value, { depth: 4, colors: false, maxArrayLength: 100, maxStringLength: 1000 });
4245
4733
  }
4246
4734
 
4247
4735
  // src/execute/target-selection.ts
@@ -4631,7 +5119,7 @@ function installClosedPageReplacementGuard(page, clearRecreatedFromClosedUrl) {
4631
5119
  }
4632
5120
 
4633
5121
  // src/execute/code-runner.ts
4634
- var nodeModules = { ...sandboxModules, fs: fs4, os: os4, http: http3, https: https2 };
5122
+ var nodeModules = { ...sandboxModules, fs: fs5, os: os4, http: http3, https: https2 };
4635
5123
 
4636
5124
  class ExecuteCodeError extends Error {
4637
5125
  originalError;
@@ -5241,7 +5729,7 @@ class DefaultPageHost {
5241
5729
  }
5242
5730
 
5243
5731
  // src/execute/result-formatting.ts
5244
- import util6 from "node:util";
5732
+ import util8 from "node:util";
5245
5733
  var maxExecuteResultChars = 1e5;
5246
5734
  function boundExecuteResult(text, value, hasValue) {
5247
5735
  const valueChars = hasValue && value !== null && typeof value === "object" ? safeJsonStringify(value)?.length ?? 0 : typeof value === "string" ? value.length : 0;
@@ -5263,7 +5751,7 @@ function stringifyResult(result) {
5263
5751
  if (result === undefined) {
5264
5752
  return "undefined";
5265
5753
  }
5266
- return util6.inspect(result, { depth: 3, colors: false, maxArrayLength: 50, maxStringLength: 4000 });
5754
+ return util8.inspect(result, { depth: 3, colors: false, maxArrayLength: 50, maxStringLength: 4000 });
5267
5755
  }
5268
5756
  var maxJsonSafeDepth = 8;
5269
5757
  var maxJsonSafeBytes = 32 * 1024;
@@ -7003,8 +7491,8 @@ function parseButton(value2) {
7003
7491
  }
7004
7492
 
7005
7493
  // src/snapshot/screenshot-diff.ts
7006
- import fs5 from "node:fs/promises";
7007
- import path3 from "node:path";
7494
+ import fs6 from "node:fs/promises";
7495
+ import path4 from "node:path";
7008
7496
  import pixelmatch from "pixelmatch";
7009
7497
  import { PNG } from "pngjs";
7010
7498
  var maxImageBytes = 32 * 1024 * 1024;
@@ -7013,7 +7501,7 @@ var pngSignature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
7013
7501
  function createScreenshotDiff(page) {
7014
7502
  return async (options) => {
7015
7503
  const threshold = validateThreshold(options.threshold ?? 0.1);
7016
- if (options.path !== undefined && (!path3.isAbsolute(options.path) || path3.extname(options.path).toLowerCase() !== ".png")) {
7504
+ if (options.path !== undefined && (!path4.isAbsolute(options.path) || path4.extname(options.path).toLowerCase() !== ".png")) {
7017
7505
  throw new Error("screenshotDiff output path must be an absolute .png path");
7018
7506
  }
7019
7507
  const baseline = isString(options.baseline) ? await readBaseline(options.baseline) : options.baseline;
@@ -7031,7 +7519,7 @@ function createScreenshotDiff(page) {
7031
7519
  const image = PNG.sync.write(diff);
7032
7520
  const totalPixels = before.width * before.height;
7033
7521
  if (options.path)
7034
- await fs5.writeFile(options.path, image, { flag: "wx", mode: 384 });
7522
+ await fs6.writeFile(options.path, image, { flag: "wx", mode: 384 });
7035
7523
  return {
7036
7524
  matches: changedPixels === 0,
7037
7525
  width: before.width,
@@ -7045,9 +7533,9 @@ function createScreenshotDiff(page) {
7045
7533
  };
7046
7534
  }
7047
7535
  async function readBaseline(filename) {
7048
- if (!path3.isAbsolute(filename))
7536
+ if (!path4.isAbsolute(filename))
7049
7537
  throw new Error("screenshotDiff baseline path must be absolute");
7050
- const file = await fs5.open(filename, "r");
7538
+ const file = await fs6.open(filename, "r");
7051
7539
  try {
7052
7540
  const stat = await file.stat();
7053
7541
  if (!stat.isFile() || stat.size > maxImageBytes)
@@ -8311,14 +8799,14 @@ async function fillInputs(page, fields) {
8311
8799
  }
8312
8800
  }
8313
8801
  // src/snapshot/screenshot-labels.ts
8314
- import fs6 from "node:fs/promises";
8315
- import path4 from "node:path";
8802
+ import fs7 from "node:fs/promises";
8803
+ import path5 from "node:path";
8316
8804
  import { PNG as PNG2 } from "pngjs";
8317
8805
  async function screenshotWithLabels(options = {}) {
8318
8806
  if (!options.page) {
8319
8807
  throw new Error("screenshotWithLabels requires a page");
8320
8808
  }
8321
- if (options.path !== undefined && !path4.isAbsolute(options.path)) {
8809
+ if (options.path !== undefined && !path5.isAbsolute(options.path)) {
8322
8810
  throw new Error("screenshotWithLabels requires an absolute path");
8323
8811
  }
8324
8812
  const page = options.page;
@@ -8348,7 +8836,7 @@ async function screenshotWithLabels(options = {}) {
8348
8836
  try {
8349
8837
  const screenshot = offPage ? drawScreenshotLabels(await page.screenshot(), labels, viewportWidth) : await page.screenshot(options.path ? { path: options.path } : {});
8350
8838
  if (offPage && options.path)
8351
- await fs6.writeFile(options.path, screenshot);
8839
+ await fs7.writeFile(options.path, screenshot);
8352
8840
  return {
8353
8841
  ...options.path ? { path: options.path } : { image: screenshot },
8354
8842
  size: screenshot.byteLength,
@@ -9371,10 +9859,10 @@ class ExecuteSecretsBridge {
9371
9859
  }
9372
9860
 
9373
9861
  // src/network-capture.ts
9374
- import path6 from "node:path";
9862
+ import path7 from "node:path";
9375
9863
 
9376
9864
  // src/network-capture/har-redaction.ts
9377
- import path5 from "node:path";
9865
+ import path6 from "node:path";
9378
9866
 
9379
9867
  // src/network-capture/types.ts
9380
9868
  var defaultNetworkCaptureMaxDurationMs = 30 * 60000;
@@ -9706,7 +10194,7 @@ function toHarEntry(entry) {
9706
10194
  }
9707
10195
  function writeArtifact(outputPath, value) {
9708
10196
  return tryPromise({
9709
- try: () => writeJsonFileAtomically(path5.resolve(outputPath), value),
10197
+ try: () => writeJsonFileAtomically(path6.resolve(outputPath), value),
9710
10198
  catch: (cause) => new NetworkCaptureError({ message: `Could not write network capture: ${outputPath}`, operation: "write", reason: "persistence-failed", cause })
9711
10199
  });
9712
10200
  }
@@ -9945,7 +10433,7 @@ class Recorder {
9945
10433
  truncatedBodyCount: finalStatus.truncatedBodyCount + finished.redactionOmissionCount,
9946
10434
  active: false,
9947
10435
  stoppedAt: new Date().toISOString(),
9948
- ...options.outputPath ? { outputPath: path6.resolve(options.outputPath) } : {},
10436
+ ...options.outputPath ? { outputPath: path7.resolve(options.outputPath) } : {},
9949
10437
  ...finished.authProfile ? { authProfile: finished.authProfile } : {},
9950
10438
  updatedSecretRefs: finished.updatedSecretRefs,
9951
10439
  observedSecretRefs: finished.observedSecretRefs,
@@ -10177,25 +10665,25 @@ class Recorder {
10177
10665
  }
10178
10666
 
10179
10667
  // src/relay/log.ts
10180
- import fs7 from "node:fs";
10668
+ import fs8 from "node:fs";
10181
10669
  import os5 from "node:os";
10182
- import path7 from "node:path";
10670
+ import path8 from "node:path";
10183
10671
  var maxLogBytes = 1e6;
10184
10672
  var maxEntryCharacters = 64000;
10185
10673
  function managedRelayLogPath(home = os5.homedir()) {
10186
- return path7.join(stateRoot(home), "logs", "relay.log");
10674
+ return path8.join(stateRoot(home), "logs", "relay.log");
10187
10675
  }
10188
10676
  function appendManagedRelayProcessLog(message, home = os5.homedir()) {
10189
10677
  try {
10190
10678
  const logPath = managedRelayLogPath(home);
10191
- ensurePrivateDirectorySync(path7.dirname(logPath));
10679
+ ensurePrivateDirectorySync(path8.dirname(logPath));
10192
10680
  const entry = `${new Date().toISOString()} ${message.slice(0, maxEntryCharacters)}
10193
10681
  `;
10194
- const stat = fs7.statSync(logPath, { throwIfNoEntry: false });
10682
+ const stat = fs8.statSync(logPath, { throwIfNoEntry: false });
10195
10683
  if (stat && stat.size + Buffer.byteLength(entry) > maxLogBytes)
10196
- fs7.renameSync(logPath, `${logPath}.1`);
10197
- fs7.appendFileSync(logPath, entry, { encoding: "utf8", mode: 384 });
10198
- fs7.chmodSync(logPath, 384);
10684
+ fs8.renameSync(logPath, `${logPath}.1`);
10685
+ fs8.appendFileSync(logPath, entry, { encoding: "utf8", mode: 384 });
10686
+ fs8.chmodSync(logPath, 384);
10199
10687
  } catch {}
10200
10688
  }
10201
10689
  function relayLog(event, fields = {}) {
@@ -10665,15 +11153,15 @@ class ExecuteSandbox extends DefaultPageHost {
10665
11153
  }
10666
11154
 
10667
11155
  // src/recording-relay/flight-recorder.ts
10668
- import fs9 from "node:fs/promises";
10669
- import path9 from "node:path";
11156
+ import fs10 from "node:fs/promises";
11157
+ import path10 from "node:path";
10670
11158
  import { performance as performance3 } from "node:perf_hooks";
10671
11159
 
10672
11160
  // src/recording-relay/ffmpeg-encoder.ts
10673
11161
  import { execFile, spawn } from "node:child_process";
10674
11162
  import crypto6 from "node:crypto";
10675
11163
  import { once } from "node:events";
10676
- import fs8 from "node:fs/promises";
11164
+ import fs9 from "node:fs/promises";
10677
11165
 
10678
11166
  // src/recording-relay/mjpeg-matroska.ts
10679
11167
  var ebml = Buffer.from("1A45DFA3", "hex");
@@ -10790,7 +11278,7 @@ function mjpegMatroskaFrame(timestampMs, durationMs, frameLength) {
10790
11278
  import { performance as performance2 } from "node:perf_hooks";
10791
11279
 
10792
11280
  // src/recording-relay/types.ts
10793
- import path8 from "node:path";
11281
+ import path9 from "node:path";
10794
11282
  var defaultMaxDurationMs = 15 * 60 * 1000;
10795
11283
  var defaultCdpFrameRate = 60;
10796
11284
  var maxRecordingFrameRate = 60;
@@ -10886,7 +11374,7 @@ function findByRecordingTarget(map, target, ambiguousMessage) {
10886
11374
  return map.values().next().value;
10887
11375
  }
10888
11376
  function cdpArtifactType(outputPath) {
10889
- const extension = path8.extname(outputPath).toLowerCase();
11377
+ const extension = path9.extname(outputPath).toLowerCase();
10890
11378
  if (extension === ".webm")
10891
11379
  return "webm";
10892
11380
  if (extension === ".mp4")
@@ -11081,7 +11569,7 @@ async function createFfmpegVideoEncoder(options) {
11081
11569
  await writeStreamChunk(child.stdin, mjpegMatroskaHeader(options.width, options.height));
11082
11570
  } catch (error) {
11083
11571
  await exit;
11084
- await fs8.rm(temporaryOutputPath, { force: true });
11572
+ await fs9.rm(temporaryOutputPath, { force: true });
11085
11573
  throw error;
11086
11574
  }
11087
11575
  let completed = false;
@@ -11121,10 +11609,10 @@ async function createFfmpegVideoEncoder(options) {
11121
11609
  const error = await exit;
11122
11610
  if (error)
11123
11611
  throw error;
11124
- await fs8.rename(temporaryOutputPath, options.outputPath);
11612
+ await fs9.rename(temporaryOutputPath, options.outputPath);
11125
11613
  completed = true;
11126
11614
  })().catch(async (error) => {
11127
- await fs8.rm(temporaryOutputPath, { force: true });
11615
+ await fs9.rm(temporaryOutputPath, { force: true });
11128
11616
  throw error;
11129
11617
  });
11130
11618
  return finishingPromise;
@@ -11136,7 +11624,7 @@ async function createFfmpegVideoEncoder(options) {
11136
11624
  return cancelPromise;
11137
11625
  cancelPromise = (async () => {
11138
11626
  await terminate();
11139
- await fs8.rm(temporaryOutputPath, { force: true });
11627
+ await fs9.rm(temporaryOutputPath, { force: true });
11140
11628
  })();
11141
11629
  return cancelPromise;
11142
11630
  }
@@ -11300,7 +11788,7 @@ class FlightRecorderRelay {
11300
11788
  const startAt = frames[0].receivedAt;
11301
11789
  const endAt = frames.at(-1).receivedAt;
11302
11790
  const durationMs = Math.max(1, endAt - startAt);
11303
- await fs9.mkdir(path9.dirname(target.outputPath), { recursive: true });
11791
+ await fs10.mkdir(path10.dirname(target.outputPath), { recursive: true });
11304
11792
  let encoder;
11305
11793
  try {
11306
11794
  encoder = await (this.options.startVideoEncoder ?? startFfmpegVideoEncoder)({
@@ -11324,7 +11812,7 @@ class FlightRecorderRelay {
11324
11812
  sourceFrameCount: recorder.sourceFrameCount,
11325
11813
  droppedFrameCount: recorder.droppedFrameCount
11326
11814
  };
11327
- await fs9.writeFile(`${target.outputPath}.json`, `${JSON.stringify({ ...receipt, savedAt: new Date(this.now()).toISOString(), retainedDurationMs: this.retainedDuration(recorder) }, null, 2)}
11815
+ await fs10.writeFile(`${target.outputPath}.json`, `${JSON.stringify({ ...receipt, savedAt: new Date(this.now()).toISOString(), retainedDurationMs: this.retainedDuration(recorder) }, null, 2)}
11328
11816
  `, "utf8");
11329
11817
  return receipt;
11330
11818
  } catch (error) {
@@ -11425,7 +11913,7 @@ class FlightRecorderRelay {
11425
11913
  }
11426
11914
  async function assertOutputAvailable(filePath) {
11427
11915
  try {
11428
- await fs9.stat(filePath);
11916
+ await fs10.stat(filePath);
11429
11917
  } catch (error) {
11430
11918
  if (error instanceof Error && "code" in error && error.code === "ENOENT")
11431
11919
  return;
@@ -11618,8 +12106,8 @@ function resolveExactHandoffTarget(options) {
11618
12106
  }
11619
12107
 
11620
12108
  // src/relay/lifecycle-log.ts
11621
- import fs10 from "node:fs";
11622
- import path10 from "node:path";
12109
+ import fs11 from "node:fs";
12110
+ import path11 from "node:path";
11623
12111
  var requestFields = {
11624
12112
  instanceId: RelayShutdownRequest.fields.instanceId,
11625
12113
  requestId: RelayShutdownRequest.fields.requestId,
@@ -11637,30 +12125,30 @@ var RelayLifecycleEvent = TaggedUnion({
11637
12125
  }
11638
12126
  });
11639
12127
  function appendRelayLifecycleEvent(filePath, event) {
11640
- const directory = path10.dirname(filePath);
12128
+ const directory = path11.dirname(filePath);
11641
12129
  ensurePrivateDirectorySync(directory);
11642
12130
  const entry = `${JSON.stringify({ ...encodeSync(RelayLifecycleEvent)(event), timestamp: new Date().toISOString() })}
11643
12131
  `;
11644
- const file = fs10.openSync(filePath, "a+", 384);
12132
+ const file = fs11.openSync(filePath, "a+", 384);
11645
12133
  try {
11646
- fs10.fchmodSync(file, 384);
11647
- if (fs10.fstatSync(file).size + Buffer.byteLength(entry) > 256000)
11648
- fs10.ftruncateSync(file, 0);
11649
- fs10.writeFileSync(file, entry);
11650
- fs10.fsyncSync(file);
12134
+ fs11.fchmodSync(file, 384);
12135
+ if (fs11.fstatSync(file).size + Buffer.byteLength(entry) > 256000)
12136
+ fs11.ftruncateSync(file, 0);
12137
+ fs11.writeFileSync(file, entry);
12138
+ fs11.fsyncSync(file);
11651
12139
  } finally {
11652
- fs10.closeSync(file);
12140
+ fs11.closeSync(file);
11653
12141
  }
11654
- const parent = fs10.openSync(directory, "r");
12142
+ const parent = fs11.openSync(directory, "r");
11655
12143
  try {
11656
12144
  try {
11657
- fs10.fsyncSync(parent);
12145
+ fs11.fsyncSync(parent);
11658
12146
  } catch (error) {
11659
12147
  if (!isUnsupportedDirectorySyncError(error))
11660
12148
  throw error;
11661
12149
  }
11662
12150
  } finally {
11663
- fs10.closeSync(parent);
12151
+ fs11.closeSync(parent);
11664
12152
  }
11665
12153
  }
11666
12154
 
@@ -13065,8 +13553,8 @@ function sendNotFound(response) {
13065
13553
 
13066
13554
  // src/recording-relay.ts
13067
13555
  import crypto7 from "node:crypto";
13068
- import fs12 from "node:fs/promises";
13069
- import path12 from "node:path";
13556
+ import fs13 from "node:fs/promises";
13557
+ import path13 from "node:path";
13070
13558
  import { performance as performance4 } from "node:perf_hooks";
13071
13559
 
13072
13560
  // src/recording-relay/protocol.ts
@@ -13134,8 +13622,8 @@ function validateUint32(value, field, positive) {
13134
13622
  }
13135
13623
 
13136
13624
  // src/recording-relay/cdp-capture.ts
13137
- import fs11 from "node:fs/promises";
13138
- import path11 from "node:path";
13625
+ import fs12 from "node:fs/promises";
13626
+ import path12 from "node:path";
13139
13627
  function handleCdpScreencastFrame(context, recording, options) {
13140
13628
  const frame = parseScreencastFrame(options.params);
13141
13629
  acknowledgeScreencastFrame({
@@ -13200,7 +13688,7 @@ async function startCdpRecording(context, options, starting) {
13200
13688
  if (!artifactType) {
13201
13689
  return { success: false, error: "CDP recording output path must end in .webm or .mp4" };
13202
13690
  }
13203
- await fs11.mkdir(path11.dirname(options.outputPath), { recursive: true });
13691
+ await fs12.mkdir(path12.dirname(options.outputPath), { recursive: true });
13204
13692
  if (starting.cancelled)
13205
13693
  return cancelledResult();
13206
13694
  const frameRate = options.frameRate ?? defaultCdpFrameRate;
@@ -13339,7 +13827,7 @@ async function finishCdpRecording(context, recording) {
13339
13827
  await writeSourceFrame(recording, recording.lastFrame, endFrameNumber);
13340
13828
  recording.frameCount = endFrameNumber;
13341
13829
  await recording.encoder.finish();
13342
- const stat = await fs11.stat(recording.outputPath);
13830
+ const stat = await fs12.stat(recording.outputPath);
13343
13831
  const quality = recordingQuality(recording, durationMs);
13344
13832
  const metadata = {
13345
13833
  mode: "cdp",
@@ -13353,7 +13841,7 @@ async function finishCdpRecording(context, recording) {
13353
13841
  ...quality,
13354
13842
  mimeType: recording.artifactType === "mp4" ? "video/mp4" : "video/webm"
13355
13843
  };
13356
- await fs11.writeFile(`${recording.outputPath}.json`, `${JSON.stringify(metadata, null, 2)}
13844
+ await fs12.writeFile(`${recording.outputPath}.json`, `${JSON.stringify(metadata, null, 2)}
13357
13845
  `, "utf8");
13358
13846
  return {
13359
13847
  success: true,
@@ -13717,7 +14205,7 @@ class RecordingRelay {
13717
14205
  throw new Error("No tab capture data was received");
13718
14206
  await recording.file.sync();
13719
14207
  await recording.file.close();
13720
- await fs12.rename(recording.temporaryPath, recording.outputPath);
14208
+ await fs13.rename(recording.temporaryPath, recording.outputPath);
13721
14209
  recording.finalized = true;
13722
14210
  recording.resolveStop?.({
13723
14211
  success: true,
@@ -13763,7 +14251,7 @@ class RecordingRelay {
13763
14251
  await recording.writePromise.catch(() => {});
13764
14252
  await recording.file.close().catch(() => {});
13765
14253
  if (!recording.finalized)
13766
- await fs12.rm(recording.temporaryPath, { force: true }).catch(() => {});
14254
+ await fs13.rm(recording.temporaryPath, { force: true }).catch(() => {});
13767
14255
  if (this.activeRecordings.get(recording.tabId) === recording) {
13768
14256
  this.activeRecordings.delete(recording.tabId);
13769
14257
  this.recordingChanged(recording.tabId);
@@ -13787,11 +14275,11 @@ class RecordingRelay {
13787
14275
  if (cdpArtifactType(options.outputPath) !== "webm") {
13788
14276
  return { success: false, error: "tabCapture recording output path must end in .webm; use --mode cdp for MP4" };
13789
14277
  }
13790
- await fs12.mkdir(path12.dirname(options.outputPath), { recursive: true });
14278
+ await fs13.mkdir(path13.dirname(options.outputPath), { recursive: true });
13791
14279
  if (starting.cancelled)
13792
14280
  return { success: false, error: "Recording was cancelled while starting" };
13793
14281
  const temporaryPath = `${options.outputPath}.partial-${process.pid}-${crypto7.randomUUID()}`;
13794
- const file = await fs12.open(temporaryPath, "wx", 384);
14282
+ const file = await fs13.open(temporaryPath, "wx", 384);
13795
14283
  const recording = {
13796
14284
  tabId: options.tabId,
13797
14285
  ...options.sessionId ? { sessionId: options.sessionId } : {},
@@ -16095,7 +16583,7 @@ function createExtensionEventHandler(options) {
16095
16583
 
16096
16584
  // src/relay/extension-handshake.ts
16097
16585
  import crypto8 from "node:crypto";
16098
- import fs13 from "node:fs";
16586
+ import fs14 from "node:fs";
16099
16587
  import { WebSocket as WebSocket3 } from "ws";
16100
16588
  var maxPreAuthMessageBytes = 64 * 1024;
16101
16589
  var preAuthHandshakeTimeoutMs = 1e4;
@@ -16117,7 +16605,7 @@ class ExtensionHandshake {
16117
16605
  this.options = options;
16118
16606
  }
16119
16607
  rejectedProtocol() {
16120
- return this.mismatch ?? (fs13.existsSync(oldStoreMarker()) ? extensionProtocolCompatibility(2) : undefined);
16608
+ return this.mismatch ?? (fs14.existsSync(oldStoreMarker()) ? extensionProtocolCompatibility(2) : undefined);
16121
16609
  }
16122
16610
  mismatchAdvice(version) {
16123
16611
  return extensionProtocolAdvice(version, { install: installCommand() }, !this.mismatch || this.mismatch.origin === `chrome-extension://${this.options.storeId}` ? "store" : this.mismatch.origin === stableUnpackedExtensionOrigin2 ? "unpacked" : undefined);
@@ -16272,8 +16760,8 @@ class ExtensionHandshake {
16272
16760
  return;
16273
16761
  }
16274
16762
  this.mismatch = undefined;
16275
- if (fs13.existsSync(oldStoreMarker()))
16276
- fs13.rmSync(oldStoreMarker(), { force: true });
16763
+ if (fs14.existsSync(oldStoreMarker()))
16764
+ fs14.rmSync(oldStoreMarker(), { force: true });
16277
16765
  if (message.method === "protocol") {
16278
16766
  if (message.params?.unpaired === true) {
16279
16767
  this.lastUnpaired = Date.now();
@@ -17485,9 +17973,9 @@ class RootTargetLifecycle {
17485
17973
  }
17486
17974
 
17487
17975
  // src/session-manager/catalog.ts
17488
- import fs14 from "node:fs/promises";
17976
+ import fs15 from "node:fs/promises";
17489
17977
  import os6 from "node:os";
17490
- import path13 from "node:path";
17978
+ import path14 from "node:path";
17491
17979
  import crypto9 from "node:crypto";
17492
17980
  var PersistedSession = Struct({
17493
17981
  id: String3,
@@ -17508,7 +17996,7 @@ var Catalog = Struct({
17508
17996
  sessions: ArraySchema(PersistedSession)
17509
17997
  });
17510
17998
  function defaultSessionCatalogPath(port, home = os6.homedir()) {
17511
- return path13.join(dataRoot(home), "relays", String(port), "sessions.json");
17999
+ return path14.join(dataRoot(home), "relays", String(port), "sessions.json");
17512
18000
  }
17513
18001
 
17514
18002
  class SessionCatalog {
@@ -17519,7 +18007,7 @@ class SessionCatalog {
17519
18007
  async load() {
17520
18008
  let text;
17521
18009
  try {
17522
- text = await fs14.readFile(this.filePath, "utf8");
18010
+ text = await fs15.readFile(this.filePath, "utf8");
17523
18011
  } catch (error) {
17524
18012
  if (isNodeError(error) && error.code === "ENOENT")
17525
18013
  return [];
@@ -17535,7 +18023,7 @@ class SessionCatalog {
17535
18023
  const detail = error instanceof Error && error.message ? `: ${error.message}` : "";
17536
18024
  const corruptPath = `${this.filePath}.corrupt-${Date.now()}`;
17537
18025
  try {
17538
- await fs14.rename(this.filePath, corruptPath);
18026
+ await fs15.rename(this.filePath, corruptPath);
17539
18027
  console.error(`Browse session catalog at ${this.filePath} was unreadable${detail}; moved it to ${corruptPath} and started with no saved sessions`);
17540
18028
  } catch (moveError) {
17541
18029
  console.error(`Browse session catalog at ${this.filePath} was unreadable${detail}; could not move it aside (${moveError instanceof Error ? moveError.message : String(moveError)}), starting with no saved sessions`);
@@ -17544,21 +18032,21 @@ class SessionCatalog {
17544
18032
  }
17545
18033
  }
17546
18034
  async save(sessions) {
17547
- const directory = path13.dirname(this.filePath);
18035
+ const directory = path14.dirname(this.filePath);
17548
18036
  const temporaryPath = `${this.filePath}.${process.pid}.${crypto9.randomUUID()}.tmp`;
17549
18037
  const contents = `${JSON.stringify({ version: 1, sessions }, null, 2)}
17550
18038
  `;
17551
18039
  let temporaryFile;
17552
18040
  try {
17553
- await fs14.mkdir(directory, { recursive: true, mode: 448 });
17554
- await fs14.chmod(directory, 448);
17555
- temporaryFile = await fs14.open(temporaryPath, "wx", 384);
18041
+ await fs15.mkdir(directory, { recursive: true, mode: 448 });
18042
+ await fs15.chmod(directory, 448);
18043
+ temporaryFile = await fs15.open(temporaryPath, "wx", 384);
17556
18044
  await temporaryFile.writeFile(contents, "utf8");
17557
18045
  await temporaryFile.sync();
17558
18046
  await temporaryFile.close();
17559
18047
  temporaryFile = undefined;
17560
- await fs14.rename(temporaryPath, this.filePath);
17561
- const directoryHandle = await fs14.open(directory, "r");
18048
+ await fs15.rename(temporaryPath, this.filePath);
18049
+ const directoryHandle = await fs15.open(directory, "r");
17562
18050
  try {
17563
18051
  try {
17564
18052
  await directoryHandle.sync();
@@ -17574,7 +18062,7 @@ class SessionCatalog {
17574
18062
  await temporaryFile?.close();
17575
18063
  } catch {}
17576
18064
  try {
17577
- await fs14.rm(temporaryPath, { force: true });
18065
+ await fs15.rm(temporaryPath, { force: true });
17578
18066
  } catch {}
17579
18067
  throw new Error(`Could not write browse session catalog at ${this.filePath}`, { cause: error });
17580
18068
  }
@@ -18065,7 +18553,7 @@ var makeRelay = fnUntraced(function* (options = {}) {
18065
18553
  const restartTimeoutMs = yield* Int("OPENCODE_BROWSER_RESTART_TIMEOUT_MS").pipe(withDefault(1e4));
18066
18554
  const clientGoneGraceMs = yield* Int("OPENCODE_BROWSER_CLIENT_GONE_GRACE_MS").pipe(withDefault(60000));
18067
18555
  const restartRequestId = yield* option(String2("OPENCODE_BROWSER_RESTART_REQUEST_ID"));
18068
- const lifecycleLogPath = path14.join(stateRoot(), "relays", String(port), "lifecycle.jsonl");
18556
+ const lifecycleLogPath = path15.join(stateRoot(), "relays", String(port), "lifecycle.jsonl");
18069
18557
  const audit = (event) => try_(() => appendRelayLifecycleEvent(lifecycleLogPath, event));
18070
18558
  function setProtectedUi(tabId, protectedUi) {
18071
18559
  const changed = registry.markRootTargetProtectedUi(tabId, protectedUi);