peachsim 0.1.730 → 0.1.746

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 (107) hide show
  1. package/cli/bridge-flow-runner.ts +15 -2
  2. package/cli/commands/control.ts +13 -3
  3. package/cli/commands/desktop.ts +1 -0
  4. package/cli/commands/electron.ts +12 -8
  5. package/cli/commands/flow.ts +1 -3
  6. package/cli/commands/install-desktop.ts +105 -66
  7. package/cli/commands/logout.ts +5 -1
  8. package/cli/commands/no-bridge-hint.ts +2 -2
  9. package/cli/commands/swift.ts +26 -9
  10. package/cli/desktop-companion.ts +36 -9
  11. package/cli/drivers/desktop.ts +65 -0
  12. package/cli/drivers/electron.ts +4 -66
  13. package/cli/drivers/index.ts +1 -0
  14. package/cli/drivers/playwright-sim-host.ts +2 -0
  15. package/cli/drivers/playwright.ts +3 -3
  16. package/cli/drivers/registry.ts +7 -2
  17. package/cli/drivers/types.ts +4 -3
  18. package/cli/maestro-js.ts +10 -0
  19. package/cli/outbound-endpoints.ts +2 -2
  20. package/dist-lib/agent-daemon-client.cjs +1 -1
  21. package/dist-lib/agent-events.cjs +1 -1
  22. package/dist-lib/agent-identity.cjs +1 -1
  23. package/dist-lib/agent-sessions.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +1 -1
  25. package/dist-lib/auth/shared-session.cjs +39 -9
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +1 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +1 -1
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +1 -1
  34. package/dist-lib/capture-contract.cjs +13 -19
  35. package/dist-lib/capture-contract.mjs +13 -19
  36. package/dist-lib/cli-constants.cjs +1 -1
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +1 -1
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +1 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +1 -1
  43. package/dist-lib/config.cjs +1 -1
  44. package/dist-lib/detox/index.cjs +117 -11
  45. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  46. package/dist-lib/home-paths.cjs +32 -1
  47. package/dist-lib/host/bridge-host.cjs +1741 -540
  48. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  49. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  50. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  51. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  52. package/dist-lib/host/websocket-proxy.cjs +1 -1
  53. package/dist-lib/index.cjs +17 -22
  54. package/dist-lib/jump-to-source-babel.cjs +1 -1
  55. package/dist-lib/jump-to-source-native.cjs +1 -1
  56. package/dist-lib/kotlin-host.cjs +1 -1
  57. package/dist-lib/menu.cjs +1 -1
  58. package/dist-lib/menu.mjs +1 -1
  59. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  60. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  61. package/dist-lib/metro-production-bundle.cjs +1 -1
  62. package/dist-lib/metro-production-bundle.mjs +1 -1
  63. package/dist-lib/metro.cjs +1 -1
  64. package/dist-lib/native-app-identity.cjs +1 -1
  65. package/dist-lib/native-app-identity.mjs +1 -1
  66. package/dist-lib/native-firebase-metadata.cjs +1 -1
  67. package/dist-lib/native-firebase-metadata.mjs +1 -1
  68. package/dist-lib/plist.cjs +1 -1
  69. package/dist-lib/plist.mjs +1 -1
  70. package/dist-lib/profiles.cjs +1 -1
  71. package/dist-lib/public-brand.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.cjs +1 -1
  73. package/dist-lib/react-native-host-modules.mjs +1 -1
  74. package/dist-lib/render-mode.cjs +1 -1
  75. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  76. package/dist-lib/sdk.cjs +2 -1
  77. package/dist-lib/sdk.mjs +2 -1
  78. package/dist-lib/skills.cjs +2431 -1075
  79. package/dist-lib/swift-compile.cjs +374 -65
  80. package/dist-lib/swift-compile.mjs +369 -66
  81. package/dist-lib/swift-package.cjs +146 -9
  82. package/dist-lib/swift-package.mjs +144 -9
  83. package/dist-lib/swift-submit.cjs +2 -2
  84. package/dist-lib/swift-submit.mjs +2 -2
  85. package/dist-lib/swift-toolchain.cjs +1 -1
  86. package/dist-lib/swift.cjs +1 -1
  87. package/dist-lib/vite-swift.cjs +1690 -233
  88. package/dist-lib/vite.cjs +4 -4
  89. package/package.json +1 -1
  90. package/skills/contrast/SKILL.md +1 -1
  91. package/src/auth/shared-session.ts +45 -9
  92. package/src/bridge-constants.ts +7 -7
  93. package/src/capture-contract.ts +18 -33
  94. package/src/desktop-host-delivery.ts +81 -0
  95. package/src/home-paths.ts +30 -0
  96. package/src/host/bridge-host.ts +11 -6
  97. package/src/native-seam-manifest.ts +0 -11
  98. package/src/sim-client.ts +1 -0
  99. package/src/swift-compile.ts +479 -76
  100. package/src/swift-distribution.lock.json +11 -11
  101. package/src/swift-host.ts +338 -45
  102. package/src/swift-package.ts +204 -19
  103. package/src/swift-remote-packages.ts +255 -0
  104. package/src/swift-submit.ts +4 -1
  105. package/src/vite-plugin-one.ts +2 -2
  106. package/src/vite-plugin.ts +29 -9
  107. package/src/xcode-project.ts +612 -0
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.730 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.746 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -60,9 +60,9 @@ function resolveContrastBackendOrigin(currentOrigin) {
60
60
  const origin = currentOrigin?.trim();
61
61
  if (!origin) return DEFAULT_CONTRAST_BACKEND_ORIGIN;
62
62
  try {
63
- const parsed = new URL(origin);
64
- if (isLoopbackHost(parsed.hostname) || isContrastBackendHost(parsed.hostname)) {
65
- return parsed.origin;
63
+ const parsed2 = new URL(origin);
64
+ if (isLoopbackHost(parsed2.hostname) || isContrastBackendHost(parsed2.hostname)) {
65
+ return parsed2.origin;
66
66
  }
67
67
  } catch {
68
68
  }
@@ -106,9 +106,9 @@ var require_parse = __commonJS({
106
106
  doc.documentElement.nodeName === "plist",
107
107
  "malformed document. First element should be <plist>"
108
108
  );
109
- var plist2 = parsePlistXML(doc.documentElement);
110
- if (plist2.length == 1) plist2 = plist2[0];
111
- return plist2;
109
+ var plist3 = parsePlistXML(doc.documentElement);
110
+ if (plist3.length == 1) plist3 = plist3[0];
111
+ return plist3;
112
112
  }
113
113
  function parsePlistXML(node) {
114
114
  var i, new_obj, key, val, new_arr, res, counter, type;
@@ -431,8 +431,8 @@ function configFilePath() {
431
431
  function readSharedConfig() {
432
432
  try {
433
433
  const raw2 = import_node_fs3.default.readFileSync(configFilePath(), "utf8");
434
- const parsed = JSON.parse(raw2);
435
- return parsed && typeof parsed === "object" ? parsed : {};
434
+ const parsed2 = JSON.parse(raw2);
435
+ return parsed2 && typeof parsed2 === "object" ? parsed2 : {};
436
436
  } catch {
437
437
  return {};
438
438
  }
@@ -500,9 +500,9 @@ function readDaemonLockfile() {
500
500
  const buf = Buffer.alloc(DAEMON_LOCKFILE_MAX_BYTES);
501
501
  const bytesRead = import_node_fs3.default.readSync(fd, buf, 0, DAEMON_LOCKFILE_MAX_BYTES, 0);
502
502
  const raw2 = buf.subarray(0, bytesRead).toString("utf8");
503
- const parsed = JSON.parse(raw2);
504
- if (parsed && parsed.schema === 1 && typeof parsed.pid === "number" && typeof parsed.bridgePort === "number" && typeof parsed.runtimePort === "number" && typeof parsed.startedAt === "number" && typeof parsed.heartbeatAt === "number" && (parsed.servedRuntimes === void 0 || Array.isArray(parsed.servedRuntimes) && parsed.servedRuntimes.every((version) => typeof version === "string"))) {
505
- return parsed;
503
+ const parsed2 = JSON.parse(raw2);
504
+ if (parsed2 && parsed2.schema === 1 && typeof parsed2.pid === "number" && typeof parsed2.bridgePort === "number" && typeof parsed2.runtimePort === "number" && typeof parsed2.startedAt === "number" && typeof parsed2.heartbeatAt === "number" && (parsed2.servedRuntimes === void 0 || Array.isArray(parsed2.servedRuntimes) && parsed2.servedRuntimes.every((version) => typeof version === "string"))) {
505
+ return parsed2;
506
506
  }
507
507
  return null;
508
508
  } finally {
@@ -514,9 +514,9 @@ function readDaemonLockfile() {
514
514
  }
515
515
  function parseDevBridgeLockfile(raw2) {
516
516
  try {
517
- const parsed = JSON.parse(raw2);
518
- if (parsed && parsed.schema === 1 && parsed.source === "vite-dev" && typeof parsed.pid === "number" && typeof parsed.bridgePort === "number" && typeof parsed.runtimePort === "number" && typeof parsed.cwd === "string" && typeof parsed.startedAt === "number" && typeof parsed.heartbeatAt === "number" && (parsed.shellPort === void 0 || typeof parsed.shellPort === "number") && (parsed.servedRuntimes === void 0 || Array.isArray(parsed.servedRuntimes) && parsed.servedRuntimes.every((version) => typeof version === "string"))) {
519
- return parsed;
517
+ const parsed2 = JSON.parse(raw2);
518
+ if (parsed2 && parsed2.schema === 1 && parsed2.source === "vite-dev" && typeof parsed2.pid === "number" && typeof parsed2.bridgePort === "number" && typeof parsed2.runtimePort === "number" && typeof parsed2.cwd === "string" && typeof parsed2.startedAt === "number" && typeof parsed2.heartbeatAt === "number" && (parsed2.shellPort === void 0 || typeof parsed2.shellPort === "number") && (parsed2.servedRuntimes === void 0 || Array.isArray(parsed2.servedRuntimes) && parsed2.servedRuntimes.every((version) => typeof version === "string"))) {
519
+ return parsed2;
520
520
  }
521
521
  return null;
522
522
  } catch {
@@ -832,8 +832,8 @@ function readSharedDesktopAuthSession() {
832
832
  const filepath = getSharedDesktopAuthFilePath();
833
833
  if (!(0, import_node_fs12.existsSync)(filepath)) return null;
834
834
  try {
835
- const parsed = JSON.parse((0, import_node_fs12.readFileSync)(filepath, "utf8"));
836
- const normalized = normalizeSession(parsed);
835
+ const parsed2 = JSON.parse((0, import_node_fs12.readFileSync)(filepath, "utf8"));
836
+ const normalized = normalizeSession(parsed2);
837
837
  if (!normalized) {
838
838
  (0, import_node_fs12.rmSync)(filepath, { force: true });
839
839
  return null;
@@ -2299,10 +2299,10 @@ function readStringArray(text, start, end) {
2299
2299
  for (; ; ) {
2300
2300
  cursor = skipTrivia(text, cursor, end);
2301
2301
  if (text[cursor] === "]") return { values, end: cursor + 1 };
2302
- const parsed = readQuoted(text, cursor, end);
2303
- if (!parsed) return null;
2304
- values.push(parsed.value);
2305
- cursor = skipTrivia(text, parsed.end, end);
2302
+ const parsed2 = readQuoted(text, cursor, end);
2303
+ if (!parsed2) return null;
2304
+ values.push(parsed2.value);
2305
+ cursor = skipTrivia(text, parsed2.end, end);
2306
2306
  if (text[cursor] === "]") return { values, end: cursor + 1 };
2307
2307
  if (text[cursor] !== ",") return null;
2308
2308
  cursor++;
@@ -2455,10 +2455,10 @@ function scanAssetDescriptorSites(bundle) {
2455
2455
  continue;
2456
2456
  }
2457
2457
  if (character === '"' || character === "'") {
2458
- const parsed = readQuoted(bundle, cursor, bundle.length);
2459
- const after = parsed?.end ?? quotedEnd(bundle, cursor, bundle.length);
2458
+ const parsed2 = readQuoted(bundle, cursor, bundle.length);
2459
+ const after = parsed2?.end ?? quotedEnd(bundle, cursor, bundle.length);
2460
2460
  const colon = skipTrivia(bundle, after, bundle.length);
2461
- if (parsed?.value === "__packager_asset" && bundle[colon] === ":" && objects.length > 0) {
2461
+ if (parsed2?.value === "__packager_asset" && bundle[colon] === ":" && objects.length > 0) {
2462
2462
  objects[objects.length - 1].hasAssetKey = true;
2463
2463
  }
2464
2464
  cursor = after;
@@ -2689,8 +2689,8 @@ function metroIosAssetDestRelatives(httpServerLocation, filename) {
2689
2689
  }
2690
2690
  const out = [];
2691
2691
  for (const dir of dirs) {
2692
- const path18 = `${dir}/${filename}`;
2693
- if (!out.includes(path18)) out.push(path18);
2692
+ const path20 = `${dir}/${filename}`;
2693
+ if (!out.includes(path20)) out.push(path20);
2694
2694
  }
2695
2695
  if (!out.includes(filename)) out.push(filename);
2696
2696
  return out;
@@ -3180,13 +3180,13 @@ async function parseRegistryBytes(args) {
3180
3180
  if (integrity !== args.expectedIntegrity) {
3181
3181
  throw new Error("RNX Metro fingerprint registry integrity mismatch");
3182
3182
  }
3183
- let parsed;
3183
+ let parsed2;
3184
3184
  try {
3185
- parsed = JSON.parse(new TextDecoder().decode(args.bytes));
3185
+ parsed2 = JSON.parse(new TextDecoder().decode(args.bytes));
3186
3186
  } catch {
3187
3187
  throw new Error("RNX Metro fingerprint registry is not valid JSON");
3188
3188
  }
3189
- const registry = (0, import_metro_fingerprint_registry.parseRNXMetroFingerprintRegistry)(parsed);
3189
+ const registry = (0, import_metro_fingerprint_registry.parseRNXMetroFingerprintRegistry)(parsed2);
3190
3190
  if (!registry) throw new Error("RNX Metro fingerprint registry is malformed");
3191
3191
  if (args.expectedRevision && registry.revision !== args.expectedRevision) {
3192
3192
  throw new Error("RNX Metro fingerprint registry revision does not match its pointer");
@@ -3241,13 +3241,13 @@ async function readPointer(response) {
3241
3241
  `RNX Metro fingerprint pointer exceeds ${import_metro_fingerprint_registry.RNX_METRO_FINGERPRINT_MAX_POINTER_BYTES} bytes`
3242
3242
  );
3243
3243
  }
3244
- let parsed;
3244
+ let parsed2;
3245
3245
  try {
3246
- parsed = JSON.parse(new TextDecoder().decode(bytes));
3246
+ parsed2 = JSON.parse(new TextDecoder().decode(bytes));
3247
3247
  } catch {
3248
3248
  throw new Error("RNX Metro fingerprint pointer is not valid JSON");
3249
3249
  }
3250
- const pointer = (0, import_metro_fingerprint_registry.parseRNXMetroFingerprintPointer)(parsed);
3250
+ const pointer = (0, import_metro_fingerprint_registry.parseRNXMetroFingerprintPointer)(parsed2);
3251
3251
  if (!pointer) throw new Error("RNX Metro fingerprint pointer is malformed");
3252
3252
  return pointer;
3253
3253
  }
@@ -3642,13 +3642,13 @@ function readFactoryStringLiterals(factory) {
3642
3642
  return literals;
3643
3643
  }
3644
3644
  function normalizeFingerprintLiteral(literal) {
3645
- const path18 = literal.replaceAll("\\\\", "/").replaceAll("\\/", "/");
3645
+ const path20 = literal.replaceAll("\\\\", "/").replaceAll("\\/", "/");
3646
3646
  const nodeModulesMarker = "/node_modules/";
3647
- const nodeModulesIndex = path18.lastIndexOf(nodeModulesMarker);
3647
+ const nodeModulesIndex = path20.lastIndexOf(nodeModulesMarker);
3648
3648
  if (nodeModulesIndex >= 0) {
3649
- return `node_modules/${path18.slice(nodeModulesIndex + nodeModulesMarker.length)}`;
3649
+ return `node_modules/${path20.slice(nodeModulesIndex + nodeModulesMarker.length)}`;
3650
3650
  }
3651
- if ((path18.startsWith("/") || /^[A-Za-z]:\//.test(path18) || path18.startsWith("file:/")) && /\.[cm]?[jt]sx?(?::\d+(?::\d+)?)?$/.test(path18)) {
3651
+ if ((path20.startsWith("/") || /^[A-Za-z]:\//.test(path20) || path20.startsWith("file:/")) && /\.[cm]?[jt]sx?(?::\d+(?::\d+)?)?$/.test(path20)) {
3652
3652
  return null;
3653
3653
  }
3654
3654
  return literal;
@@ -3676,16 +3676,16 @@ function canonicalFactoryForDigest(factory, tokens) {
3676
3676
  return cursor === 0 ? factory : canonical + factory.slice(cursor);
3677
3677
  }
3678
3678
  function readDependencyIds(source) {
3679
- let parsed;
3679
+ let parsed2;
3680
3680
  try {
3681
- parsed = JSON.parse(source);
3681
+ parsed2 = JSON.parse(source);
3682
3682
  } catch {
3683
3683
  throw new Error("Metro fingerprint analysis found a noncanonical dependency array");
3684
3684
  }
3685
- if (!Array.isArray(parsed) || !parsed.every((dependency) => dependency === null || Number.isSafeInteger(dependency))) {
3685
+ if (!Array.isArray(parsed2) || !parsed2.every((dependency) => dependency === null || Number.isSafeInteger(dependency))) {
3686
3686
  throw new Error("Metro fingerprint analysis found a noncanonical dependency array");
3687
3687
  }
3688
- return parsed;
3688
+ return parsed2;
3689
3689
  }
3690
3690
  function fnv1a64(value) {
3691
3691
  let hash = 0xcbf29ce484222325n;
@@ -3886,10 +3886,10 @@ function templateAssignment(template, embeddings) {
3886
3886
  if (existingNode !== void 0 && existingNode !== nodeIndex) return null;
3887
3887
  nodesByModuleId.set(moduleId, nodeIndex);
3888
3888
  const node = template.nodes[nodeIndex];
3889
- const path18 = node.landmarkPath ?? `node_modules/${template.packageName}/__rnx_inferred__/${moduleId}.js`;
3889
+ const path20 = node.landmarkPath ?? `node_modules/${template.packageName}/__rnx_inferred__/${moduleId}.js`;
3890
3890
  const existingPath = pathsByModuleId.get(moduleId);
3891
- if (existingPath !== void 0 && existingPath !== path18) return null;
3892
- pathsByModuleId.set(moduleId, path18);
3891
+ if (existingPath !== void 0 && existingPath !== path20) return null;
3892
+ pathsByModuleId.set(moduleId, path20);
3893
3893
  }
3894
3894
  }
3895
3895
  return {
@@ -4051,14 +4051,14 @@ async function inferMetroModuleIdentity(args) {
4051
4051
  const packageClaims = claimsByPackage.values().next().value;
4052
4052
  if (!packageClaims) continue;
4053
4053
  const exactClaims = packageClaims.filter((assignment2) => {
4054
- const path18 = assignment2.pathsByModuleId.get(moduleId);
4055
- return path18 !== void 0 && !path18.includes("/__rnx_inferred__/");
4054
+ const path20 = assignment2.pathsByModuleId.get(moduleId);
4055
+ return path20 !== void 0 && !path20.includes("/__rnx_inferred__/");
4056
4056
  });
4057
4057
  const preferredClaims = exactClaims.length > 0 ? exactClaims : packageClaims;
4058
4058
  const routes = new Set(
4059
4059
  preferredClaims.flatMap((assignment2) => {
4060
- const path18 = assignment2.pathsByModuleId.get(moduleId);
4061
- return path18 ? [metroFingerprintModuleClaimRoute(assignment2.packageName, path18)] : [];
4060
+ const path20 = assignment2.pathsByModuleId.get(moduleId);
4061
+ return path20 ? [metroFingerprintModuleClaimRoute(assignment2.packageName, path20)] : [];
4062
4062
  })
4063
4063
  );
4064
4064
  if (routes.size !== 1) continue;
@@ -4198,19 +4198,19 @@ var init_cloud_contract = __esm({
4198
4198
 
4199
4199
  // cli/cloud-session.ts
4200
4200
  function normalizeCloudOrigin(source) {
4201
- let parsed;
4201
+ let parsed2;
4202
4202
  try {
4203
- parsed = new URL(source);
4203
+ parsed2 = new URL(source);
4204
4204
  } catch {
4205
4205
  throw new Error(`invalid remote simulator origin: ${source}`);
4206
4206
  }
4207
- if (parsed.protocol !== "https:" && parsed.protocol !== "http:" || parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) {
4207
+ if (parsed2.protocol !== "https:" && parsed2.protocol !== "http:" || parsed2.username || parsed2.password || parsed2.pathname !== "/" || parsed2.search || parsed2.hash) {
4208
4208
  throw new Error(`remote simulator origin must be an HTTP(S) origin: ${source}`);
4209
4209
  }
4210
- if (parsed.protocol === "http:" && !isLoopbackHost(parsed.hostname)) {
4210
+ if (parsed2.protocol === "http:" && !isLoopbackHost(parsed2.hostname)) {
4211
4211
  throw new Error(`remote simulator origin requires HTTPS outside loopback: ${source}`);
4212
4212
  }
4213
- return parsed.origin;
4213
+ return parsed2.origin;
4214
4214
  }
4215
4215
  function createCloudSession(input) {
4216
4216
  const boxId = input.boxId?.trim() ?? "";
@@ -4258,8 +4258,8 @@ function detectFramework(deps) {
4258
4258
  return "unknown";
4259
4259
  }
4260
4260
  function detectProject(dir) {
4261
- const pkgPath = (0, import_node_path22.join)(dir, "package.json");
4262
- if (!(0, import_node_fs22.existsSync)(pkgPath)) return null;
4261
+ const pkgPath = (0, import_node_path24.join)(dir, "package.json");
4262
+ if (!(0, import_node_fs24.existsSync)(pkgPath)) return null;
4263
4263
  const pkg = readProjectManifest(dir);
4264
4264
  if (!pkg) return null;
4265
4265
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
@@ -4271,25 +4271,25 @@ function detectProject(dir) {
4271
4271
  if (framework === "unknown") return null;
4272
4272
  return {
4273
4273
  dir,
4274
- name: pkg.name || (0, import_node_path22.basename)(dir),
4274
+ name: pkg.name || (0, import_node_path24.basename)(dir),
4275
4275
  framework,
4276
4276
  // a config file is a config file whatever module system it declares. real
4277
4277
  // apps write .cjs as often as .js, and missing one reads as "this project
4278
4278
  // has no bundler config" and sends the user to create a second one.
4279
4279
  hasViteConfig: CONFIG_EXTENSIONS.some(
4280
- (ext) => (0, import_node_fs22.existsSync)((0, import_node_path22.join)(dir, `vite.config.${ext}`))
4280
+ (ext) => (0, import_node_fs24.existsSync)((0, import_node_path24.join)(dir, `vite.config.${ext}`))
4281
4281
  ),
4282
4282
  hasMetroConfig: CONFIG_EXTENSIONS.some(
4283
- (ext) => (0, import_node_fs22.existsSync)((0, import_node_path22.join)(dir, `metro.config.${ext}`))
4283
+ (ext) => (0, import_node_fs24.existsSync)((0, import_node_path24.join)(dir, `metro.config.${ext}`))
4284
4284
  ),
4285
4285
  devCommand: typeof devCommand === "string" ? devCommand : null
4286
4286
  };
4287
4287
  }
4288
- function readProjectMetadata(path18) {
4288
+ function readProjectMetadata(path20) {
4289
4289
  try {
4290
- const info = (0, import_node_fs22.lstatSync)(path18);
4290
+ const info = (0, import_node_fs24.lstatSync)(path20);
4291
4291
  if (!info.isFile() || info.size > 4 * 1024 * 1024) return null;
4292
- return (0, import_node_fs22.readFileSync)(path18, "utf8");
4292
+ return (0, import_node_fs24.readFileSync)(path20, "utf8");
4293
4293
  } catch {
4294
4294
  return null;
4295
4295
  }
@@ -4298,8 +4298,8 @@ function metadataValue(value, key) {
4298
4298
  if (!value || typeof value !== "object") return void 0;
4299
4299
  return Object.getOwnPropertyDescriptor(value, key)?.value;
4300
4300
  }
4301
- function readProjectJson(path18) {
4302
- const text = readProjectMetadata(path18);
4301
+ function readProjectJson(path20) {
4302
+ const text = readProjectMetadata(path20);
4303
4303
  if (text === null) return null;
4304
4304
  try {
4305
4305
  const value = JSON.parse(text);
@@ -4309,8 +4309,8 @@ function readProjectJson(path18) {
4309
4309
  }
4310
4310
  }
4311
4311
  function readProjectManifest(dir) {
4312
- const parsed = readProjectJson((0, import_node_path22.join)(dir, "package.json"));
4313
- if (!parsed || typeof parsed !== "object") return null;
4312
+ const parsed2 = readProjectJson((0, import_node_path24.join)(dir, "package.json"));
4313
+ if (!parsed2 || typeof parsed2 !== "object") return null;
4314
4314
  const record = (value) => {
4315
4315
  if (!value || typeof value !== "object") return {};
4316
4316
  return Object.fromEntries(
@@ -4319,19 +4319,19 @@ function readProjectManifest(dir) {
4319
4319
  )
4320
4320
  );
4321
4321
  };
4322
- const name2 = metadataValue(parsed, "name");
4322
+ const name2 = metadataValue(parsed2, "name");
4323
4323
  return {
4324
4324
  ...typeof name2 === "string" ? { name: name2 } : {},
4325
- dependencies: record(metadataValue(parsed, "dependencies")),
4326
- devDependencies: record(metadataValue(parsed, "devDependencies"))
4325
+ dependencies: record(metadataValue(parsed2, "dependencies")),
4326
+ devDependencies: record(metadataValue(parsed2, "devDependencies"))
4327
4327
  };
4328
4328
  }
4329
- var import_node_fs22, import_node_path22, import_json5, import_yaml, CONFIG_EXTENSIONS;
4329
+ var import_node_fs24, import_node_path24, import_json5, import_yaml, CONFIG_EXTENSIONS;
4330
4330
  var init_detect = __esm({
4331
4331
  "cli/commands/detect.ts"() {
4332
4332
  "use strict";
4333
- import_node_fs22 = require("node:fs");
4334
- import_node_path22 = require("node:path");
4333
+ import_node_fs24 = require("node:fs");
4334
+ import_node_path24 = require("node:path");
4335
4335
  import_json5 = __toESM(require("json5"), 1);
4336
4336
  import_yaml = require("yaml");
4337
4337
  CONFIG_EXTENSIONS = ["ts", "js", "cjs", "mjs", "mts", "cts"];
@@ -4340,24 +4340,24 @@ var init_detect = __esm({
4340
4340
 
4341
4341
  // cli/cloud-client.ts
4342
4342
  function failureSentence(text) {
4343
- let parsed;
4343
+ let parsed2;
4344
4344
  try {
4345
- parsed = JSON.parse(text);
4345
+ parsed2 = JSON.parse(text);
4346
4346
  } catch {
4347
4347
  return null;
4348
4348
  }
4349
- if (!isRecord2(parsed)) return null;
4350
- if (isRecord2(parsed.error) && typeof parsed.error.message === "string") {
4351
- const code = typeof parsed.error.code === "string" && parsed.error.code ? ` [${parsed.error.code}]` : "";
4352
- return `${parsed.error.message}${code}`;
4349
+ if (!isRecord2(parsed2)) return null;
4350
+ if (isRecord2(parsed2.error) && typeof parsed2.error.message === "string") {
4351
+ const code = typeof parsed2.error.code === "string" && parsed2.error.code ? ` [${parsed2.error.code}]` : "";
4352
+ return `${parsed2.error.message}${code}`;
4353
4353
  }
4354
- if (typeof parsed.message === "string") return parsed.message;
4355
- if (typeof parsed.error === "string") return parsed.error;
4354
+ if (typeof parsed2.message === "string") return parsed2.message;
4355
+ if (typeof parsed2.error === "string") return parsed2.error;
4356
4356
  return null;
4357
4357
  }
4358
4358
  function responseError(status, text) {
4359
- const parsed = text ? failureSentence(text) : null;
4360
- const sentence = parsed && ACCOUNT_CHOICE_REFUSALS.has(parsed) ? CHOOSE_ACCOUNT_HINT : parsed;
4359
+ const parsed2 = text ? failureSentence(text) : null;
4360
+ const sentence = parsed2 && ACCOUNT_CHOICE_REFUSALS.has(parsed2) ? CHOOSE_ACCOUNT_HINT : parsed2;
4361
4361
  return new Error(
4362
4362
  `remote simulator request failed (${status})${sentence ? `: ${sentence}` : text.trim() ? `: ${text.trim()}` : ""}`
4363
4363
  );
@@ -4368,21 +4368,21 @@ function resolveCloudOrigin(value) {
4368
4368
  return normalizeCloudOrigin(source);
4369
4369
  }
4370
4370
  function readImmutableBundleSource(bundlePath) {
4371
- const filepath = (0, import_node_path23.resolve)(bundlePath);
4372
- if ((0, import_node_path23.extname)(filepath) !== ".js") {
4371
+ const filepath = (0, import_node_path25.resolve)(bundlePath);
4372
+ if ((0, import_node_path25.extname)(filepath) !== ".js") {
4373
4373
  throw new Error(`${REMOTE_COMMAND} requires one local Metro .js bundle`);
4374
4374
  }
4375
- const descriptor = (0, import_node_fs23.openSync)(filepath, "r");
4375
+ const descriptor = (0, import_node_fs25.openSync)(filepath, "r");
4376
4376
  try {
4377
- const before = (0, import_node_fs23.fstatSync)(descriptor, { bigint: true });
4377
+ const before = (0, import_node_fs25.fstatSync)(descriptor, { bigint: true });
4378
4378
  if (!before.isFile()) {
4379
4379
  throw new Error(`${REMOTE_COMMAND} bundle must be a regular local file`);
4380
4380
  }
4381
4381
  if (before.size <= 0n) {
4382
4382
  throw new Error(`${REMOTE_COMMAND} bundle is empty`);
4383
4383
  }
4384
- const bytes = (0, import_node_fs23.readFileSync)(descriptor);
4385
- const after = (0, import_node_fs23.fstatSync)(descriptor, { bigint: true });
4384
+ const bytes = (0, import_node_fs25.readFileSync)(descriptor);
4385
+ const after = (0, import_node_fs25.fstatSync)(descriptor, { bigint: true });
4386
4386
  if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeNs !== after.mtimeNs || bytes.length !== Number(before.size)) {
4387
4387
  throw new Error(`${REMOTE_COMMAND} bundle changed while it was being read`);
4388
4388
  }
@@ -4397,7 +4397,7 @@ function readImmutableBundleSource(bundlePath) {
4397
4397
  }
4398
4398
  return source;
4399
4399
  } finally {
4400
- (0, import_node_fs23.closeSync)(descriptor);
4400
+ (0, import_node_fs25.closeSync)(descriptor);
4401
4401
  }
4402
4402
  }
4403
4403
  async function fetchBundleSource(bundleUrl) {
@@ -4444,15 +4444,15 @@ async function loadBundleSource(bundleInput) {
4444
4444
  return readImmutableBundleSource(bundleInput);
4445
4445
  }
4446
4446
  function listMetroAssetDest(assetsPath) {
4447
- const directory = (0, import_node_path23.resolve)(assetsPath);
4448
- if (!(0, import_node_fs23.existsSync)(directory)) return { directory, files: [], truncated: false };
4449
- const skipNested = (0, import_node_fs23.existsSync)((0, import_node_path23.join)(directory, "package.json"));
4447
+ const directory = (0, import_node_path25.resolve)(assetsPath);
4448
+ if (!(0, import_node_fs25.existsSync)(directory)) return { directory, files: [], truncated: false };
4449
+ const skipNested = (0, import_node_fs25.existsSync)((0, import_node_path25.join)(directory, "package.json"));
4450
4450
  const files = [];
4451
4451
  let truncated = false;
4452
- const walk = (dir, prefix) => {
4452
+ const walk2 = (dir, prefix) => {
4453
4453
  let entries;
4454
4454
  try {
4455
- entries = (0, import_node_fs23.readdirSync)(dir, { withFileTypes: true });
4455
+ entries = (0, import_node_fs25.readdirSync)(dir, { withFileTypes: true });
4456
4456
  } catch {
4457
4457
  return;
4458
4458
  }
@@ -4464,13 +4464,13 @@ function listMetroAssetDest(assetsPath) {
4464
4464
  if (entry.isDirectory()) {
4465
4465
  if (entry.name === ".git") continue;
4466
4466
  if (skipNested && PROJECT_ONLY_DIRECTORIES.has(entry.name)) continue;
4467
- walk((0, import_node_path23.join)(dir, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
4467
+ walk2((0, import_node_path25.join)(dir, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
4468
4468
  } else if (entry.isFile()) {
4469
4469
  files.push(prefix ? `${prefix}/${entry.name}` : entry.name);
4470
4470
  }
4471
4471
  }
4472
4472
  };
4473
- walk(directory, "");
4473
+ walk2(directory, "");
4474
4474
  return { directory, files, truncated };
4475
4475
  }
4476
4476
  function metroDescriptorHash(scaleBytes) {
@@ -4499,7 +4499,7 @@ function distinctByContent(directory, options) {
4499
4499
  for (const relative2 of options) {
4500
4500
  let bytes;
4501
4501
  try {
4502
- bytes = (0, import_node_fs23.readFileSync)((0, import_node_path23.join)(directory, relative2));
4502
+ bytes = (0, import_node_fs25.readFileSync)((0, import_node_path25.join)(directory, relative2));
4503
4503
  } catch {
4504
4504
  continue;
4505
4505
  }
@@ -4531,7 +4531,7 @@ function placeMetroDescriptor(listing, descriptor) {
4531
4531
  let bytes;
4532
4532
  try {
4533
4533
  bytes = combination.map(
4534
- (relative2) => (0, import_node_fs23.readFileSync)((0, import_node_path23.join)(listing.directory, relative2))
4534
+ (relative2) => (0, import_node_fs25.readFileSync)((0, import_node_path25.join)(listing.directory, relative2))
4535
4535
  );
4536
4536
  } catch {
4537
4537
  continue;
@@ -4557,26 +4557,26 @@ function placeMetroDescriptor(listing, descriptor) {
4557
4557
  }
4558
4558
  function unverifiedFileKey(dest) {
4559
4559
  return dest.placements.filter((placement) => !placement.verified).flatMap(
4560
- (placement) => [...placement.files.values()].map((relative2) => (0, import_node_path23.join)(dest.directory, relative2))
4560
+ (placement) => [...placement.files.values()].map((relative2) => (0, import_node_path25.join)(dest.directory, relative2))
4561
4561
  ).sort().join("\n");
4562
4562
  }
4563
4563
  function searchMetroAssetDest(bundlePath, descriptors) {
4564
- const bundleDirectory = (0, import_node_path23.dirname)((0, import_node_path23.resolve)(bundlePath));
4564
+ const bundleDirectory = (0, import_node_path25.dirname)((0, import_node_path25.resolve)(bundlePath));
4565
4565
  const candidates = [
4566
- (0, import_node_path23.join)(bundleDirectory, "assets"),
4566
+ (0, import_node_path25.join)(bundleDirectory, "assets"),
4567
4567
  bundleDirectory,
4568
- (0, import_node_path23.resolve)(bundleDirectory, "..", "assets")
4568
+ (0, import_node_path25.resolve)(bundleDirectory, "..", "assets")
4569
4569
  ];
4570
4570
  const cwd = process.cwd();
4571
4571
  let projectDirectory = null;
4572
4572
  for (const start of [bundleDirectory, cwd]) {
4573
- let directory = (0, import_node_path23.resolve)(start);
4573
+ let directory = (0, import_node_path25.resolve)(start);
4574
4574
  while (true) {
4575
4575
  if (detectProject(directory)?.hasMetroConfig) {
4576
4576
  projectDirectory = directory;
4577
4577
  break;
4578
4578
  }
4579
- const parent = (0, import_node_path23.dirname)(directory);
4579
+ const parent = (0, import_node_path25.dirname)(directory);
4580
4580
  if (parent === directory) break;
4581
4581
  directory = parent;
4582
4582
  }
@@ -4584,11 +4584,11 @@ function searchMetroAssetDest(bundlePath, descriptors) {
4584
4584
  }
4585
4585
  if (projectDirectory) {
4586
4586
  candidates.push(
4587
- (0, import_node_path23.join)(projectDirectory, "assets"),
4588
- (0, import_node_path23.join)(projectDirectory, "dist"),
4589
- (0, import_node_path23.join)(projectDirectory, "dist", "assets"),
4590
- (0, import_node_path23.join)(projectDirectory, "build"),
4591
- (0, import_node_path23.join)(projectDirectory, "build", "assets")
4587
+ (0, import_node_path25.join)(projectDirectory, "assets"),
4588
+ (0, import_node_path25.join)(projectDirectory, "dist"),
4589
+ (0, import_node_path25.join)(projectDirectory, "dist", "assets"),
4590
+ (0, import_node_path25.join)(projectDirectory, "build"),
4591
+ (0, import_node_path25.join)(projectDirectory, "build", "assets")
4592
4592
  );
4593
4593
  }
4594
4594
  const searched = [];
@@ -4596,7 +4596,7 @@ function searchMetroAssetDest(bundlePath, descriptors) {
4596
4596
  const stale = [];
4597
4597
  let truncated = false;
4598
4598
  for (const candidate of candidates) {
4599
- const directory = (0, import_node_path23.resolve)(candidate);
4599
+ const directory = (0, import_node_path25.resolve)(candidate);
4600
4600
  if (searched.includes(directory)) continue;
4601
4601
  searched.push(directory);
4602
4602
  const listing = listMetroAssetDest(directory);
@@ -4609,10 +4609,10 @@ function searchMetroAssetDest(bundlePath, descriptors) {
4609
4609
  stale.push(directory);
4610
4610
  continue;
4611
4611
  }
4612
- const verified2 = placements.filter((placement) => placement.verified).length;
4613
- if (verified2 === 0 && placements.every((placement) => placement.files.size === 0))
4612
+ const verified3 = placements.filter((placement) => placement.verified).length;
4613
+ if (verified3 === 0 && placements.every((placement) => placement.files.size === 0))
4614
4614
  continue;
4615
- holders.push({ dest: { directory, placements }, verified: verified2 });
4615
+ holders.push({ dest: { directory, placements }, verified: verified3 });
4616
4616
  }
4617
4617
  if (holders.length === 0) {
4618
4618
  if (stale.length > 0) {
@@ -4702,7 +4702,7 @@ async function embedBundleAssets(bundlePath, command, assetPolicy) {
4702
4702
  );
4703
4703
  }
4704
4704
  const relative2 = placement?.files.get(variant.scale);
4705
- if (relative2 && dest) return (0, import_node_fs23.readFileSync)((0, import_node_path23.join)(dest.directory, relative2));
4705
+ if (relative2 && dest) return (0, import_node_fs25.readFileSync)((0, import_node_path25.join)(dest.directory, relative2));
4706
4706
  if (placement && placement.files.size > 0) return null;
4707
4707
  if (placement && placement.ambiguous.length > 0 && dest) {
4708
4708
  throw new Error(
@@ -4731,7 +4731,7 @@ async function embedBundleAssets(bundlePath, command, assetPolicy) {
4731
4731
  );
4732
4732
  const classic = metroIosAssetDestRelatives(variant.descriptor.httpServerLocation, filename)[0] ?? filename;
4733
4733
  throw new Error(
4734
- `${command} could not read ${(0, import_node_path23.join)(dest?.directory ?? ".", classic)} for ${variant.descriptor.name}.${variant.descriptor.type} at scale ${variant.scale}, and has no stand-in for a .${variant.descriptor.type} asset. Rebuild with \`react-native bundle --assets-dest\`.`
4734
+ `${command} could not read ${(0, import_node_path25.join)(dest?.directory ?? ".", classic)} for ${variant.descriptor.name}.${variant.descriptor.type} at scale ${variant.scale}, and has no stand-in for a .${variant.descriptor.type} asset. Rebuild with \`react-native bundle --assets-dest\`.`
4735
4735
  );
4736
4736
  });
4737
4737
  return {
@@ -4848,13 +4848,13 @@ async function createCloudBox(options) {
4848
4848
  }
4849
4849
  const responseText = await response.text();
4850
4850
  if (!response.ok) throw responseError(response.status, responseText);
4851
- let parsed;
4851
+ let parsed2;
4852
4852
  try {
4853
- parsed = JSON.parse(responseText);
4853
+ parsed2 = JSON.parse(responseText);
4854
4854
  } catch {
4855
4855
  throw new Error("remote simulator create returned unreadable JSON");
4856
4856
  }
4857
- const created = readCreateResponse(parsed, artifact.bytes.length, artifact.sha256);
4857
+ const created = readCreateResponse(parsed2, artifact.bytes.length, artifact.sha256);
4858
4858
  const session = createCloudSession({
4859
4859
  boxId: created.receipt.boxId,
4860
4860
  boxToken: created.boxToken,
@@ -4877,13 +4877,13 @@ async function createCloudBox(options) {
4877
4877
  warnings: artifact.warnings
4878
4878
  };
4879
4879
  }
4880
- var import_node_crypto11, import_node_fs23, import_node_path23, DEFAULT_RNX_CLOUD_ORIGIN, MAX_RNX_CLOUD_BUNDLE_BYTES, REMOTE_COMMAND, MAX_ASSET_DEST_FILES, ACCOUNT_CHOICE_REFUSALS, PROJECT_ONLY_DIRECTORIES, MAX_PLACEMENT_COMBINATIONS;
4880
+ var import_node_crypto11, import_node_fs25, import_node_path25, DEFAULT_RNX_CLOUD_ORIGIN, MAX_RNX_CLOUD_BUNDLE_BYTES, REMOTE_COMMAND, MAX_ASSET_DEST_FILES, ACCOUNT_CHOICE_REFUSALS, PROJECT_ONLY_DIRECTORIES, MAX_PLACEMENT_COMBINATIONS;
4881
4881
  var init_cloud_client = __esm({
4882
4882
  "cli/cloud-client.ts"() {
4883
4883
  "use strict";
4884
4884
  import_node_crypto11 = require("node:crypto");
4885
- import_node_fs23 = require("node:fs");
4886
- import_node_path23 = require("node:path");
4885
+ import_node_fs25 = require("node:fs");
4886
+ import_node_path25 = require("node:path");
4887
4887
  init_metroAssetArtifact();
4888
4888
  init_metroCloudArtifact();
4889
4889
  init_metro_fingerprint_registry_client();
@@ -5169,13 +5169,13 @@ function hasPeachConfig(config) {
5169
5169
  return typeof config.runtimeVersion === "string" && config.runtimeVersion.length > 0 || hasOwnKeys(config.modules) || hasOwnKeys(config.turboModules) || hasOwnKeys(config.nativeModules) || hasOwnKeys(config.nativeViews) || hasOwnKeys(config.env) || hasOwnKeys(config.network?.remap) || hasOwnKeys(config.settings) || hasOwnKeys(config.initialState);
5170
5170
  }
5171
5171
  function applyPeachConfigToUrl(url, config) {
5172
- const parsed = new URL(url);
5172
+ const parsed2 = new URL(url);
5173
5173
  if (hasPeachConfig(config)) {
5174
- parsed.searchParams.set(PEACH_CONFIG_QUERY_PARAM, JSON.stringify(config));
5174
+ parsed2.searchParams.set(PEACH_CONFIG_QUERY_PARAM, JSON.stringify(config));
5175
5175
  } else {
5176
- parsed.searchParams.delete(PEACH_CONFIG_QUERY_PARAM);
5176
+ parsed2.searchParams.delete(PEACH_CONFIG_QUERY_PARAM);
5177
5177
  }
5178
- return parsed.toString();
5178
+ return parsed2.toString();
5179
5179
  }
5180
5180
 
5181
5181
  // src/native-dev-bundle-url.ts
@@ -5199,25 +5199,25 @@ function alignLoopbackBundleUrlWithProbe(bundleUrl, probeBaseUrl) {
5199
5199
  return bundleUrl;
5200
5200
  }
5201
5201
  }
5202
- function applyPreviewProdBundle(parsed) {
5202
+ function applyPreviewProdBundle(parsed2) {
5203
5203
  if (!process.env.SOOTSIM_PREVIEW_PROD_BUNDLE) return;
5204
- parsed.searchParams.set("dev", "false");
5205
- parsed.searchParams.set("minify", "true");
5206
- if (parsed.searchParams.has("hot")) parsed.searchParams.set("hot", "false");
5204
+ parsed2.searchParams.set("dev", "false");
5205
+ parsed2.searchParams.set("minify", "true");
5206
+ if (parsed2.searchParams.has("hot")) parsed2.searchParams.set("hot", "false");
5207
5207
  }
5208
5208
  function normalizeNativeDevBundleUrl(bundleUrl) {
5209
5209
  try {
5210
5210
  const isAbsolute2 = isAbsoluteHttpUrl(bundleUrl);
5211
- const parsed = new URL(bundleUrl, "http://sootsim.local");
5212
- parsed.pathname = parsed.pathname.replace(/\.\.bundle$/, ".bundle");
5213
- if (!isNativeDevBundlePath(parsed.pathname)) return bundleUrl;
5214
- parsed.searchParams.delete("transform.bytecode");
5215
- if (parsed.searchParams.get("lazy") === "true") {
5216
- parsed.searchParams.set("lazy", "false");
5217
- }
5218
- applyPreviewProdBundle(parsed);
5219
- if (isAbsolute2) return parsed.toString();
5220
- return `${parsed.pathname}${parsed.search}${parsed.hash}`;
5211
+ const parsed2 = new URL(bundleUrl, "http://sootsim.local");
5212
+ parsed2.pathname = parsed2.pathname.replace(/\.\.bundle$/, ".bundle");
5213
+ if (!isNativeDevBundlePath(parsed2.pathname)) return bundleUrl;
5214
+ parsed2.searchParams.delete("transform.bytecode");
5215
+ if (parsed2.searchParams.get("lazy") === "true") {
5216
+ parsed2.searchParams.set("lazy", "false");
5217
+ }
5218
+ applyPreviewProdBundle(parsed2);
5219
+ if (isAbsolute2) return parsed2.toString();
5220
+ return `${parsed2.pathname}${parsed2.search}${parsed2.hash}`;
5221
5221
  } catch {
5222
5222
  return bundleUrl;
5223
5223
  }
@@ -5315,9 +5315,9 @@ function safeChildPlistName(value) {
5315
5315
  name: file.toLowerCase().endsWith(".plist") ? file : `${file}.plist`
5316
5316
  };
5317
5317
  }
5318
- async function readableSettingsBundle(path18) {
5318
+ async function readableSettingsBundle(path20) {
5319
5319
  try {
5320
- const root = await (0, import_promises.stat)((0, import_node_path.join)(path18, "Root.plist"));
5320
+ const root = await (0, import_promises.stat)((0, import_node_path.join)(path20, "Root.plist"));
5321
5321
  return root.isFile() && root.size <= MAX_PLIST_BYTES;
5322
5322
  } catch {
5323
5323
  return false;
@@ -5362,13 +5362,13 @@ async function settingsBundleFingerprint(bundlePath) {
5362
5362
  return null;
5363
5363
  }
5364
5364
  }
5365
- async function parsePlistRecord(path18) {
5365
+ async function parsePlistRecord(path20) {
5366
5366
  try {
5367
- const metadata = await (0, import_promises.stat)(path18);
5367
+ const metadata = await (0, import_promises.stat)(path20);
5368
5368
  if (!metadata.isFile() || metadata.size > MAX_PLIST_BYTES) return null;
5369
- const source = await (0, import_promises.readFile)(path18, "utf8");
5370
- const parsed = parsePlistSource(source);
5371
- return isRecord(parsed) ? parsed : null;
5369
+ const source = await (0, import_promises.readFile)(path20, "utf8");
5370
+ const parsed2 = parsePlistSource(source);
5371
+ return isRecord(parsed2) ? parsed2 : null;
5372
5372
  } catch {
5373
5373
  return null;
5374
5374
  }
@@ -5628,7 +5628,7 @@ async function tcpPing(port, timeout = TCP_GATE_MS) {
5628
5628
  return null;
5629
5629
  }
5630
5630
  }
5631
- function httpGet(hostname, port, path18, method = "GET", timeout = TIMEOUT_MS, headers = {}) {
5631
+ function httpGet(hostname, port, path20, method = "GET", timeout = TIMEOUT_MS, headers = {}) {
5632
5632
  return new Promise((resolve5) => {
5633
5633
  let settled = false;
5634
5634
  let killing = false;
@@ -5637,7 +5637,7 @@ function httpGet(hostname, port, path18, method = "GET", timeout = TIMEOUT_MS, h
5637
5637
  settled = true;
5638
5638
  resolve5(value);
5639
5639
  };
5640
- const req = import_http.default.request({ hostname, port, path: path18, method, headers }, (res) => {
5640
+ const req = import_http.default.request({ hostname, port, path: path20, method, headers }, (res) => {
5641
5641
  let body = "";
5642
5642
  res.on("data", (c) => body += c.toString());
5643
5643
  const contentType = (() => {
@@ -5876,8 +5876,8 @@ function isDirectOneBundleUrl(bundleUrl) {
5876
5876
  }
5877
5877
  function safeParseManifest(body) {
5878
5878
  try {
5879
- const parsed = JSON.parse(body);
5880
- return parsed && typeof parsed === "object" ? parsed : null;
5879
+ const parsed2 = JSON.parse(body);
5880
+ return parsed2 && typeof parsed2 === "object" ? parsed2 : null;
5881
5881
  } catch {
5882
5882
  return null;
5883
5883
  }
@@ -5927,8 +5927,8 @@ function applyManifest(result, manifestRes, buildIconProxyUrl) {
5927
5927
  if (rawIcon.startsWith("http://") || rawIcon.startsWith("https://")) {
5928
5928
  let isLoopback = false;
5929
5929
  try {
5930
- const parsed = new URL(rawIcon);
5931
- isLoopback = isLoopbackHost(parsed.hostname);
5930
+ const parsed2 = new URL(rawIcon);
5931
+ isLoopback = isLoopbackHost(parsed2.hostname);
5932
5932
  } catch {
5933
5933
  }
5934
5934
  if (buildIconProxyUrl) {
@@ -6001,7 +6001,7 @@ async function fetchManifestEnrichment(result, buildIconProxyUrl) {
6001
6001
  }
6002
6002
  );
6003
6003
  if (!manifestRes || manifestRes.statusCode !== 200) return;
6004
- const parsed = applyManifest(
6004
+ const parsed2 = applyManifest(
6005
6005
  {
6006
6006
  port: result.port,
6007
6007
  framework: "one",
@@ -6011,12 +6011,12 @@ async function fetchManifestEnrichment(result, buildIconProxyUrl) {
6011
6011
  manifestRes,
6012
6012
  buildIconProxyUrl
6013
6013
  );
6014
- if (!parsed.projectName && !parsed.iconUrl) return;
6014
+ if (!parsed2.projectName && !parsed2.iconUrl) return;
6015
6015
  enrichmentCache.set(result.port, {
6016
- projectName: parsed.projectName,
6017
- iconUrl: parsed.iconUrl,
6018
- iconPath: parsed.iconPath,
6019
- bundleId: parsed.bundleId
6016
+ projectName: parsed2.projectName,
6017
+ iconUrl: parsed2.iconUrl,
6018
+ iconPath: parsed2.iconPath,
6019
+ bundleId: parsed2.bundleId
6020
6020
  });
6021
6021
  invalidatePortCache(result.port);
6022
6022
  }
@@ -6316,12 +6316,12 @@ function getCliVersion() {
6316
6316
  }
6317
6317
 
6318
6318
  // src/expo-swift-host.ts
6319
- var import_node_child_process6 = require("node:child_process");
6319
+ var import_node_child_process7 = require("node:child_process");
6320
6320
  var import_node_crypto6 = require("node:crypto");
6321
- var import_node_fs14 = __toESM(require("node:fs"), 1);
6321
+ var import_node_fs16 = __toESM(require("node:fs"), 1);
6322
6322
  var import_node_module = require("node:module");
6323
6323
  var import_node_os6 = __toESM(require("node:os"), 1);
6324
- var import_node_path14 = __toESM(require("node:path"), 1);
6324
+ var import_node_path16 = __toESM(require("node:path"), 1);
6325
6325
  var import_node_util3 = require("node:util");
6326
6326
 
6327
6327
  // cli/internal-child.ts
@@ -6508,14 +6508,24 @@ function swiftImplicitResourcePaths(paths) {
6508
6508
  ) || /(?:^|\/)[^/]+\.lproj\/[^/]+$/.test(file))
6509
6509
  ).sort();
6510
6510
  }
6511
- function swiftManifestTargets(manifest, resourcePaths = []) {
6512
- const implicitResources = swiftImplicitResourcePaths(resourcePaths);
6513
- const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
6514
- const targets = [];
6515
- const pattern = /\.(executableTarget|target)\s*\(/g;
6511
+ var MANIFEST_DECLARATIONS = [
6512
+ "executableTarget",
6513
+ "testTarget",
6514
+ "binaryTarget",
6515
+ "systemLibrary",
6516
+ "macro",
6517
+ "plugin",
6518
+ "target",
6519
+ "library",
6520
+ "executable",
6521
+ "package"
6522
+ ];
6523
+ function manifestCalls(manifest, kinds) {
6524
+ const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"])\/\/[^\n]*/g, "$1");
6525
+ const calls = [];
6526
+ const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join("|")})\\s*\\(`, "g");
6516
6527
  let match;
6517
6528
  while ((match = pattern.exec(code)) !== null) {
6518
- const executable = match[1] === "executableTarget";
6519
6529
  let depth = 1;
6520
6530
  const start = pattern.lastIndex;
6521
6531
  let i = start;
@@ -6543,18 +6553,141 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
6543
6553
  }
6544
6554
  i++;
6545
6555
  }
6556
+ if (kinds.includes(match[1]))
6557
+ calls.push({ kind: match[1], flat, call: code.slice(start, i) });
6558
+ pattern.lastIndex = i;
6559
+ }
6560
+ return calls;
6561
+ }
6562
+ var NAME = /\bname\s*:\s*"([^"]+)"/;
6563
+ function listArgument(call, label) {
6564
+ const start = new RegExp(`\\b${label}\\s*:\\s*\\[`).exec(call);
6565
+ if (!start) return [];
6566
+ const items = [];
6567
+ let depth = 0;
6568
+ let inString = false;
6569
+ let item = "";
6570
+ for (let i = start.index + start[0].length; i < call.length; i++) {
6571
+ const ch = call[i];
6572
+ if (inString) {
6573
+ item += ch;
6574
+ if (ch === '"' && call[i - 1] !== "\\") inString = false;
6575
+ continue;
6576
+ }
6577
+ if (ch === '"') inString = true;
6578
+ else if (ch === "(" || ch === "[") depth++;
6579
+ else if (ch === ")" || ch === "]") {
6580
+ if (depth === 0) break;
6581
+ depth--;
6582
+ } else if (ch === "," && depth === 0) {
6583
+ items.push(item.trim());
6584
+ item = "";
6585
+ continue;
6586
+ }
6587
+ item += ch;
6588
+ }
6589
+ if (item.trim()) items.push(item.trim());
6590
+ return items;
6591
+ }
6592
+ function swiftPackageIdentity(url) {
6593
+ return (url.split("/").pop() ?? url).replace(/\.git$/, "").toLowerCase();
6594
+ }
6595
+ function swiftManifestGraph(manifest) {
6596
+ const graph = {
6597
+ products: /* @__PURE__ */ new Map(),
6598
+ dependencies: /* @__PURE__ */ new Map(),
6599
+ binaryTargets: /* @__PURE__ */ new Set(),
6600
+ systemLibraries: /* @__PURE__ */ new Set(),
6601
+ packageURLs: /* @__PURE__ */ new Map(),
6602
+ packagePaths: []
6603
+ };
6604
+ for (const { kind, flat, call } of manifestCalls(manifest, [
6605
+ "library",
6606
+ "executableTarget",
6607
+ "target",
6608
+ "binaryTarget",
6609
+ "systemLibrary",
6610
+ "package"
6611
+ ])) {
6612
+ if (kind === "package") {
6613
+ const local = /\bpath\s*:\s*"([^"]+)"/.exec(flat)?.[1];
6614
+ if (local) graph.packagePaths.push(local);
6615
+ const url = /\burl\s*:\s*"([^"]+)"/.exec(flat)?.[1];
6616
+ if (!url) continue;
6617
+ graph.packageURLs.set(swiftPackageIdentity(url), url);
6618
+ const name3 = NAME.exec(flat)?.[1];
6619
+ if (name3) graph.packageURLs.set(name3.toLowerCase(), url);
6620
+ continue;
6621
+ }
6622
+ const name2 = NAME.exec(flat)?.[1];
6623
+ if (!name2) continue;
6624
+ if (kind === "library") {
6625
+ graph.products.set(
6626
+ name2,
6627
+ listArgument(call, "targets").flatMap(
6628
+ (item) => /^"([^"]+)"$/.exec(item)?.[1] ?? []
6629
+ )
6630
+ );
6631
+ continue;
6632
+ }
6633
+ if (kind === "binaryTarget") graph.binaryTargets.add(name2);
6634
+ if (kind === "systemLibrary") graph.systemLibraries.add(name2);
6635
+ const dependencies = [];
6636
+ for (const item of listArgument(call, "dependencies")) {
6637
+ const platforms = /condition\s*:\s*\.when\(\s*platforms\s*:\s*\[([^\]]*)\]/.exec(
6638
+ item
6639
+ )?.[1];
6640
+ if (platforms !== void 0 && !/\.iOS\b/.test(platforms)) continue;
6641
+ if (/condition\s*:\s*\.when\([^)]*\btraits\s*:/.test(item)) continue;
6642
+ const plain = /^"([^"]+)"$/.exec(item)?.[1];
6643
+ const product = /^\.product(?:Item)?\(\s*name\s*:\s*"([^"]+)"\s*,\s*package\s*:\s*"([^"]+)"/.exec(
6644
+ item
6645
+ );
6646
+ const target = /^\.(?:target|byName)(?:Item)?\(\s*name\s*:\s*"([^"]+)"/.exec(
6647
+ item
6648
+ )?.[1];
6649
+ if (plain) dependencies.push({ kind: "target", name: plain });
6650
+ else if (product)
6651
+ dependencies.push({
6652
+ kind: "product",
6653
+ name: product[1],
6654
+ package: product[2].toLowerCase()
6655
+ });
6656
+ else if (target) dependencies.push({ kind: "target", name: target });
6657
+ }
6658
+ graph.dependencies.set(name2, dependencies);
6659
+ }
6660
+ for (const dependencies of graph.dependencies.values()) {
6661
+ for (const [index, dependency] of dependencies.entries()) {
6662
+ if (dependency.kind === "target" && !graph.dependencies.has(dependency.name))
6663
+ dependencies[index] = {
6664
+ kind: "product",
6665
+ name: dependency.name,
6666
+ package: dependency.name.toLowerCase()
6667
+ };
6668
+ }
6669
+ }
6670
+ return graph;
6671
+ }
6672
+ function swiftManifestTargets(manifest, resourcePaths = []) {
6673
+ const implicitResources = swiftImplicitResourcePaths(resourcePaths);
6674
+ const targets = [];
6675
+ for (const { kind, flat, call } of manifestCalls(manifest, [
6676
+ "executableTarget",
6677
+ "target"
6678
+ ])) {
6679
+ const executable = kind === "executableTarget";
6546
6680
  const name2 = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
6547
6681
  if (!name2) continue;
6548
6682
  const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
6549
6683
  const targetPath = rawPath == null || rawPath === "" ? `Sources/${name2}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
6550
- const call = code.slice(start, i);
6551
6684
  const languageMode = Number(
6552
6685
  /\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
6553
6686
  );
6554
6687
  const mainActorIsolation = /\.defaultIsolation\(\s*MainActor\.self\s*\)/.test(call);
6555
6688
  const excluded = [
6556
6689
  ...(/\bexclude\s*:\s*\[([^\]]*)\]/.exec(flat)?.[1] ?? "").matchAll(/"([^"]+)"/g)
6557
- ].map((match2) => match2[1].replace(/^\.\//, "").replace(/\/+$/, ""));
6690
+ ].map((match) => match[1].replace(/^\.\//, "").replace(/\/+$/, ""));
6558
6691
  const prefix = targetPath === "." ? "" : `${targetPath}/`;
6559
6692
  const resources = /\bresources\s*:/.test(flat) || implicitResources.some((file) => {
6560
6693
  if (!file.startsWith(prefix)) return false;
@@ -6585,7 +6718,10 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
6585
6718
  var run2 = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
6586
6719
  var WASM_TRIPLE = "wasm32-unknown-wasip1";
6587
6720
  var cores = import_node_os2.default.availableParallelism();
6588
- var BUILD_ENV = { ...process.env, BINARYEN_CORES: String(Math.min(4, cores)) };
6721
+ var BUILD_ENV = {
6722
+ ...process.env,
6723
+ BINARYEN_CORES: String(Math.min(4, cores))
6724
+ };
6589
6725
  var BUILD_JOBS = String(Math.max(1, Math.floor(cores / 2)));
6590
6726
  function swiftDistributionAt(root) {
6591
6727
  const file = import_node_path7.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
@@ -6609,14 +6745,16 @@ function swiftModuleInputFiles(root) {
6609
6745
  "scripts/contrast-app-Package.swift",
6610
6746
  "toolchain.json"
6611
6747
  ];
6612
- const walk = (dir) => {
6613
- for (const entry of (0, import_node_fs7.readdirSync)(import_node_path7.default.join(root, dir), { withFileTypes: true })) {
6748
+ const walk2 = (dir) => {
6749
+ for (const entry of (0, import_node_fs7.readdirSync)(import_node_path7.default.join(root, dir), {
6750
+ withFileTypes: true
6751
+ })) {
6614
6752
  const relative2 = `${dir}/${entry.name}`;
6615
- if (entry.isDirectory()) walk(relative2);
6753
+ if (entry.isDirectory()) walk2(relative2);
6616
6754
  else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative2);
6617
6755
  }
6618
6756
  };
6619
- walk("Sources");
6757
+ walk2("Sources");
6620
6758
  return files.sort();
6621
6759
  }
6622
6760
  async function ensureMacroPlugins(moduleRoot, toolchainBin) {
@@ -6698,6 +6836,9 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
6698
6836
  CryptoKit: [],
6699
6837
  CommonCrypto: [],
6700
6838
  CoreText: [],
6839
+ Compression: ["PeachCodec"],
6840
+ zlib: ["PeachCodec"],
6841
+ PeachCodec: [],
6701
6842
  Security: ["CryptoKit"],
6702
6843
  TikTokBusinessSDK: [],
6703
6844
  nSure: [],
@@ -6708,6 +6849,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
6708
6849
  DatadogTrace: ["DatadogCore"]
6709
6850
  };
6710
6851
  var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
6852
+ var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
6853
+ function swiftImportNames(contents, unconditional = false) {
6854
+ const names = [];
6855
+ let depth = 0;
6856
+ for (const line of contents.split("\n")) {
6857
+ const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
6858
+ if (directive === "if") depth++;
6859
+ else if (directive === "endif") depth = Math.max(0, depth - 1);
6860
+ if (unconditional && depth > 0) continue;
6861
+ const name2 = SWIFT_IMPORT.exec(line)?.[1];
6862
+ if (name2) names.push(name2);
6863
+ }
6864
+ return names;
6865
+ }
6866
+ function swiftPeachModules(moduleRoot) {
6867
+ const distribution = swiftDistributionAt(moduleRoot);
6868
+ return distribution ? distribution.modules : [
6869
+ ...(0, import_node_fs7.readFileSync)(import_node_path7.default.join(moduleRoot, "Package.swift"), "utf8").matchAll(
6870
+ /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
6871
+ )
6872
+ ].map((match) => match[1]);
6873
+ }
6874
+ var availableModules = /* @__PURE__ */ new Map();
6875
+ function swiftAvailableModules(moduleRoot, toolchainBin) {
6876
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
6877
+ const key = `${moduleRoot}\0${sdk}`;
6878
+ const cached3 = availableModules.get(key);
6879
+ if (cached3) return cached3;
6880
+ const modules = new Set(swiftPeachModules(moduleRoot));
6881
+ const configuration = (0, import_node_child_process3.execFileSync)(
6882
+ import_node_path7.default.join(toolchainBin, "swift"),
6883
+ ["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
6884
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
6885
+ );
6886
+ const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
6887
+ if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
6888
+ for (const entry of (0, import_node_fs7.readdirSync)(import_node_path7.default.join(resources, "wasi"))) {
6889
+ if (entry.endsWith(".swiftmodule"))
6890
+ modules.add(entry.slice(0, -".swiftmodule".length));
6891
+ }
6892
+ for (const entry of (0, import_node_fs7.readdirSync)(resources)) {
6893
+ const map = import_node_path7.default.join(resources, entry, "module.modulemap");
6894
+ if (!(0, import_node_fs7.existsSync)(map)) continue;
6895
+ for (const match of (0, import_node_fs7.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
6896
+ modules.add(match[1]);
6897
+ }
6898
+ availableModules.set(key, modules);
6899
+ return modules;
6900
+ }
6901
+ function missingSwiftModules(files, available) {
6902
+ const missing = /* @__PURE__ */ new Map();
6903
+ for (const [file, contents] of Object.entries(files)) {
6904
+ if (!file.endsWith(".swift") || file === "Package.swift") continue;
6905
+ for (const name2 of new Set(swiftImportNames(contents, true))) {
6906
+ if (available.has(name2)) continue;
6907
+ missing.set(name2, [...missing.get(name2) ?? [], file]);
6908
+ }
6909
+ }
6910
+ return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
6911
+ }
6711
6912
  function swiftTargetDependencies(files, targets) {
6712
6913
  const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
6713
6914
  const siblings = /* @__PURE__ */ new Map();
@@ -6720,10 +6921,8 @@ function swiftTargetDependencies(files, targets) {
6720
6921
  (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
6721
6922
  ))
6722
6923
  continue;
6723
- for (const match of contents.matchAll(
6724
- /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/gm
6725
- )) {
6726
- if (names.has(match[1]) && match[1] !== target.name) deps.add(match[1]);
6924
+ for (const name2 of swiftImportNames(contents)) {
6925
+ if (names.has(name2) && name2 !== target.name) deps.add(name2);
6727
6926
  }
6728
6927
  }
6729
6928
  siblings.set(target.name, [...deps].sort());
@@ -6733,16 +6932,14 @@ function swiftTargetDependencies(files, targets) {
6733
6932
  var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
6734
6933
  var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
6735
6934
  var importsSpriteKit = (files) => Object.entries(files).some(
6736
- ([file, contents]) => file.endsWith(".swift") && /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?SpriteKit\b/m.test(
6737
- contents
6738
- )
6935
+ ([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
6739
6936
  );
6740
- var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
6937
+ var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking", "-Xfrontend", "-import-module", "-Xfrontend", "WASILibc", "-Xfrontend", "-import-module", "-Xfrontend", "wasi_pthread"';
6741
6938
  var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
6742
- var MULTI_MANIFEST_VERSION = 10;
6939
+ var MULTI_MANIFEST_VERSION = 11;
6743
6940
  function swiftArtifactHash(input, release, moduleRoot) {
6744
6941
  const hash = (0, import_node_crypto3.createHash)("sha256");
6745
- hash.update(`swift-compile/v14
6942
+ hash.update(`swift-compile/v16
6746
6943
  ${release}
6747
6944
  `);
6748
6945
  if (input.oneModule) hash.update("one-module\n");
@@ -6851,15 +7048,15 @@ function emitSwiftPackageManifest(args) {
6851
7048
  }
6852
7049
  function syncSwiftTree(base, files) {
6853
7050
  (0, import_node_fs7.mkdirSync)(base, { recursive: true });
6854
- const walk = (dir) => {
7051
+ const walk2 = (dir) => {
6855
7052
  for (const entry of (0, import_node_fs7.readdirSync)(dir, { withFileTypes: true })) {
6856
7053
  const full = import_node_path7.default.join(dir, entry.name);
6857
7054
  if (dir === base && entry.name === ".build") continue;
6858
- if (entry.isDirectory()) walk(full);
7055
+ if (entry.isDirectory()) walk2(full);
6859
7056
  else if (!files.has(full)) (0, import_node_fs7.rmSync)(full, { force: true });
6860
7057
  }
6861
7058
  };
6862
- walk(base);
7059
+ walk2(base);
6863
7060
  for (const [full, contents] of files) {
6864
7061
  if ((0, import_node_fs7.existsSync)(full) && (0, import_node_fs7.readFileSync)(full, "utf8") === contents) continue;
6865
7062
  (0, import_node_fs7.mkdirSync)(import_node_path7.default.dirname(full), { recursive: true });
@@ -6914,23 +7111,98 @@ function forwardedArguments(parameters) {
6914
7111
  }
6915
7112
  return args.join(", ");
6916
7113
  }
6917
- function liftExtensionOverrides(source) {
7114
+ function closingBrace(source, tokens, open) {
7115
+ let depth = 0;
7116
+ for (const at of tokens) {
7117
+ if (at < open) continue;
7118
+ if (source[at] === "{") depth++;
7119
+ else if (source[at] === "}" && --depth === 0) return at + 1;
7120
+ }
7121
+ return source.length;
7122
+ }
7123
+ function scanObjCExtensionMembers(source, tokens, records) {
7124
+ const masked = swiftCodeMask(source);
7125
+ const found = /* @__PURE__ */ new Map();
7126
+ const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
7127
+ for (const record of records) {
7128
+ const close = closingBrace(source, tokens, record.open);
7129
+ const body = masked.slice(record.open, close);
7130
+ member.lastIndex = 0;
7131
+ for (let match = member.exec(body); match; match = member.exec(body)) {
7132
+ const at = record.open + match.index + match[0].indexOf(match[1]);
7133
+ let depth = 0;
7134
+ for (const token of tokens) {
7135
+ if (token <= record.open) continue;
7136
+ if (token >= at) break;
7137
+ if (source[token] === "{") depth++;
7138
+ else if (source[token] === "}") depth--;
7139
+ }
7140
+ if (depth > 0) continue;
7141
+ const head = masked.slice(record.open, at);
7142
+ const bound = Math.max(
7143
+ head.lastIndexOf(";"),
7144
+ head.lastIndexOf("{"),
7145
+ head.lastIndexOf("}")
7146
+ );
7147
+ const prefix = head.slice(bound + 1);
7148
+ if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
7149
+ prefix
7150
+ ))
7151
+ continue;
7152
+ if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
7153
+ continue;
7154
+ const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
7155
+ members.add(match[2]);
7156
+ found.set(record.type, members);
7157
+ }
7158
+ }
7159
+ return found;
7160
+ }
7161
+ function objcExtensionMemberIndex(sources) {
7162
+ const index = /* @__PURE__ */ new Map();
7163
+ for (const source of sources) {
7164
+ const { tokens } = swiftCodeScan(source);
7165
+ const masked = swiftCodeMask(source);
7166
+ const records = [];
7167
+ let pending = null;
7168
+ for (const at of tokens) {
7169
+ const rest = source.slice(at, at + 600);
7170
+ if (rest.startsWith("{")) {
7171
+ if (pending) records.push({ ...pending, open: at });
7172
+ pending = null;
7173
+ continue;
7174
+ }
7175
+ if (rest.startsWith("}")) continue;
7176
+ const extended = EXTENSION_DECL.exec(rest);
7177
+ if (extended) {
7178
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
7179
+ pending = {
7180
+ type: extended[1].split(".").pop(),
7181
+ objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
7182
+ };
7183
+ }
7184
+ }
7185
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
7186
+ const into = index.get(type) ?? /* @__PURE__ */ new Set();
7187
+ for (const member of members) into.add(member);
7188
+ index.set(type, into);
7189
+ }
7190
+ }
7191
+ return index;
7192
+ }
7193
+ function liftExtensionOverrides(source, extraObjCExtensions) {
6918
7194
  const { tokens } = swiftCodeScan(source);
7195
+ const masked = swiftCodeMask(source);
6919
7196
  const stack = [];
6920
7197
  let pending = null;
6921
7198
  const classes = /* @__PURE__ */ new Map();
6922
7199
  let declaredBase = null;
6923
7200
  let declaredObjCMembers = false;
7201
+ const extensions = [];
7202
+ let declaredExtObjCMembers = false;
6924
7203
  const lifted = [];
6925
- const closing = (open) => {
6926
- let depth = 0;
6927
- for (const at of tokens) {
6928
- if (at < open) continue;
6929
- if (source[at] === "{") depth++;
6930
- else if (source[at] === "}" && --depth === 0) return at + 1;
6931
- }
6932
- return source.length;
6933
- };
7204
+ const overrides = [];
7205
+ const closing = (open) => closingBrace(source, tokens, open);
6934
7206
  for (const at of tokens) {
6935
7207
  const rest = source.slice(at, at + 600);
6936
7208
  if (rest.startsWith("{")) {
@@ -6941,6 +7213,12 @@ function liftExtensionOverrides(source) {
6941
7213
  base: declaredBase,
6942
7214
  objcMembers: declaredObjCMembers
6943
7215
  });
7216
+ if (frame.kind === "extension")
7217
+ extensions.push({
7218
+ type: frame.name,
7219
+ open: at,
7220
+ objcMembers: declaredExtObjCMembers
7221
+ });
6944
7222
  stack.push(frame);
6945
7223
  pending = null;
6946
7224
  continue;
@@ -6960,12 +7238,39 @@ function liftExtensionOverrides(source) {
6960
7238
  const extended = EXTENSION_DECL.exec(rest);
6961
7239
  if (extended) {
6962
7240
  pending = { kind: "extension", name: extended[1].split(".").pop() };
7241
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
7242
+ declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
6963
7243
  continue;
6964
7244
  }
6965
7245
  const top = stack.at(-1);
6966
- if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
7246
+ if (!rest.startsWith("override") || pending) continue;
6967
7247
  const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
6968
7248
  const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
7249
+ if (top?.kind === "class") {
7250
+ let member;
7251
+ let nameAt = 0;
7252
+ const direct = OVERRIDE_FUNC.exec(rest);
7253
+ if (direct) {
7254
+ member = direct[2];
7255
+ nameAt = at + rest.indexOf(
7256
+ member,
7257
+ rest.indexOf("func", "override".length + direct[1].length) + 4
7258
+ );
7259
+ } else {
7260
+ const property2 = OVERRIDE_VAR.exec(rest);
7261
+ if (property2) {
7262
+ const open = at + property2[0].length - 1;
7263
+ if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
7264
+ member = property2[2];
7265
+ nameAt = at + rest.indexOf(member, rest.indexOf("var"));
7266
+ }
7267
+ }
7268
+ }
7269
+ if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
7270
+ overrides.push({ type: top.name, member, at, nameAt });
7271
+ continue;
7272
+ }
7273
+ if (top?.kind !== "extension") continue;
6969
7274
  const func = OVERRIDE_FUNC.exec(rest);
6970
7275
  if (func) {
6971
7276
  const name2 = func[2];
@@ -6983,20 +7288,18 @@ function liftExtensionOverrides(source) {
6983
7288
  if (args === null) continue;
6984
7289
  const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name2}(${args})`;
6985
7290
  const signature = `func ${name2}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
7291
+ const nameAt = at + rest.indexOf(name2, rest.indexOf("func", "override".length + func[1].length) + 4);
6986
7292
  lifted.push({
6987
7293
  type: top.name,
6988
7294
  member: name2,
6989
- stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
7295
+ at,
7296
+ modifiers,
7297
+ decl: signature,
7298
+ forward: `{ ${call} };`,
7299
+ nameAt,
6990
7300
  edits: [
6991
7301
  [at, "override".length, " ".repeat("override".length)],
6992
- [
6993
- at + rest.indexOf(
6994
- name2,
6995
- rest.indexOf("func", "override".length + func[1].length) + 4
6996
- ),
6997
- 0,
6998
- "__peach_ext_"
6999
- ]
7302
+ [nameAt, 0, "__peach_ext_"]
7000
7303
  ]
7001
7304
  });
7002
7305
  continue;
@@ -7006,42 +7309,79 @@ function liftExtensionOverrides(source) {
7006
7309
  const open = at + property[0].length - 1;
7007
7310
  if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
7008
7311
  const name2 = property[2];
7312
+ const nameAt = at + rest.indexOf(name2, rest.indexOf("var"));
7009
7313
  lifted.push({
7010
7314
  type: top.name,
7011
7315
  member: name2,
7012
- stub: `${[...modifiers, "override"].join(" ")} var ${name2}: ${property[3].trim()} { __peach_ext_${name2} };`,
7316
+ at,
7317
+ modifiers,
7318
+ decl: `var ${name2}: ${property[3].trim()}`,
7319
+ forward: `{ __peach_ext_${name2} };`,
7320
+ nameAt,
7013
7321
  edits: [
7014
7322
  [at, "override".length, " ".repeat("override".length)],
7015
- [at + rest.indexOf(name2, rest.indexOf("var")), 0, "__peach_ext_"]
7323
+ [nameAt, 0, "__peach_ext_"]
7016
7324
  ]
7017
7325
  });
7018
7326
  }
7019
7327
  }
7020
- const overridesObjC = (type, member) => {
7328
+ const extIndex = /* @__PURE__ */ new Map();
7329
+ if (extraObjCExtensions)
7330
+ for (const [type, members] of extraObjCExtensions)
7331
+ extIndex.set(type, new Set(members));
7332
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
7333
+ const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
7334
+ for (const member of members) into.add(member);
7335
+ extIndex.set(type, into);
7336
+ }
7337
+ const overrideKind = (type, member) => {
7021
7338
  let base = classes.get(type)?.base ?? null;
7022
7339
  while (base !== null) {
7023
- if (APPLE_CLASS.test(base)) return true;
7024
7340
  const declaredClass = classes.get(base);
7025
- if (!declaredClass) return false;
7026
- const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
7027
- const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
7028
- if (found) {
7029
- const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
7030
- return declaredClass.objcMembers || /@objc\b/.test(line);
7031
- }
7032
- base = declaredClass.base;
7341
+ if (declaredClass) {
7342
+ const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
7343
+ const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
7344
+ if (found) {
7345
+ const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
7346
+ return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
7347
+ }
7348
+ if (extIndex.get(base)?.has(member)) return "ext";
7349
+ base = declaredClass.base;
7350
+ } else if (extIndex.get(base)?.has(member)) return "ext";
7351
+ else if (APPLE_CLASS.test(base)) return "apple";
7352
+ else return "unknown";
7033
7353
  }
7034
- return false;
7354
+ return "unknown";
7035
7355
  };
7356
+ const rename = (at, nameAt) => [
7357
+ [at, "override".length, " ".repeat("override".length)],
7358
+ [nameAt, 0, "__peach_ovr_"]
7359
+ ];
7036
7360
  const edits = [];
7037
7361
  const stubs = /* @__PURE__ */ new Map();
7038
7362
  for (const entry of lifted) {
7039
7363
  const brace = classes.get(entry.type)?.brace;
7040
- if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
7364
+ if (brace === void 0) continue;
7365
+ const kind = overrideKind(entry.type, entry.member);
7366
+ if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
7367
+ if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
7368
+ continue;
7369
+ if (kind === "ext") {
7370
+ edits.push(...rename(entry.at, entry.nameAt));
7371
+ continue;
7372
+ }
7041
7373
  edits.push(...entry.edits);
7042
- stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
7374
+ const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
7375
+ stubs.set(brace, [
7376
+ ...stubs.get(brace) ?? [],
7377
+ `${head} ${entry.decl} ${entry.forward}`
7378
+ ]);
7379
+ }
7380
+ for (const candidate of overrides) {
7381
+ if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
7382
+ edits.push(...rename(candidate.at, candidate.nameAt));
7043
7383
  }
7044
- for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
7384
+ for (const [brace, list2] of stubs) edits.push([brace + 1, 0, ` ${list2.join(" ")}`]);
7045
7385
  let out = source;
7046
7386
  for (const [at, remove, insert] of edits.sort((a, b) => b[0] - a[0]))
7047
7387
  out = out.slice(0, at) + insert + out.slice(at + remove);
@@ -7221,8 +7561,8 @@ function swiftCodeMask(source) {
7221
7561
  scanCode(0, false);
7222
7562
  return chars.join("");
7223
7563
  }
7224
- function swiftSourceAsIOS(original) {
7225
- const source = liftExtensionOverrides(original);
7564
+ function swiftSourceAsIOS(original, extraObjCExtensions) {
7565
+ const source = liftExtensionOverrides(original, extraObjCExtensions);
7226
7566
  const { lineStarts, tokens } = swiftCodeScan(source);
7227
7567
  let offset = 0;
7228
7568
  const conditioned = source.split("\n").map((line) => {
@@ -7237,9 +7577,14 @@ function swiftSourceAsIOS(original) {
7237
7577
  const reusableBodies = [];
7238
7578
  let depth = 0;
7239
7579
  let opensReusableBody = false;
7580
+ const sceneLifecycleBodies = /* @__PURE__ */ new Set();
7240
7581
  for (const at of tokens) {
7241
7582
  const rest = conditioned.slice(at, at + 400);
7242
7583
  if (rest.startsWith("{")) {
7584
+ if (sceneLifecycleBodies.has(at)) {
7585
+ out += conditioned.slice(copied, at + 1) + " public var _peachUsesSceneLifecycle: Bool { true };";
7586
+ copied = at + 1;
7587
+ }
7243
7588
  depth++;
7244
7589
  if (opensReusableBody) reusableBodies.push(depth);
7245
7590
  opensReusableBody = false;
@@ -7275,12 +7620,33 @@ function swiftSourceAsIOS(original) {
7275
7620
  opensReusableBody = true;
7276
7621
  }
7277
7622
  const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
7623
+ const delegateClass = DELEGATE_CLASS.exec(rest);
7624
+ if (delegateClass && /\bUIApplicationDelegate\b/.test(delegateClass[0])) {
7625
+ const body = at + delegateClass[0].lastIndexOf("{");
7626
+ let bodyDepth = 0;
7627
+ for (const token of tokens) {
7628
+ if (token < body) continue;
7629
+ if (conditioned[token] === "{") bodyDepth++;
7630
+ else if (conditioned[token] === "}" && --bodyDepth === 0) break;
7631
+ else if (bodyDepth === 1 && /^func\s+application\s*\([^{}]*\bconfigurationForConnecting\s+/.test(
7632
+ conditioned.slice(token, token + 600)
7633
+ )) {
7634
+ sceneLifecycleBodies.add(body);
7635
+ break;
7636
+ }
7637
+ }
7638
+ }
7278
7639
  if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
7279
7640
  out += `${conditioned.slice(copied, at)}final `;
7280
7641
  copied = at;
7281
7642
  }
7282
7643
  continue;
7283
7644
  }
7645
+ if (/^@UIApplicationMain\b/.test(rest)) {
7646
+ out += conditioned.slice(copied, at) + "@main".padEnd("@UIApplicationMain".length);
7647
+ copied = at + "@UIApplicationMain".length;
7648
+ continue;
7649
+ }
7284
7650
  const selector = SELECTOR.exec(rest);
7285
7651
  const match = selector ?? OBJC_ATTRIBUTE.exec(rest);
7286
7652
  if (!match) continue;
@@ -7379,7 +7745,7 @@ function swiftCodeScan(source) {
7379
7745
  else top.parens--;
7380
7746
  i++;
7381
7747
  } else {
7382
- const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
7748
+ const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("func", i) ? "func" : source.startsWith("UIApplicationMain", i) ? "UIApplicationMain" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
7383
7749
  if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
7384
7750
  tokens.push(i);
7385
7751
  i += keyword.length;
@@ -7391,7 +7757,7 @@ function swiftCodeScan(source) {
7391
7757
  }
7392
7758
  return { lineStarts: starts, tokens };
7393
7759
  }
7394
- var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
7760
+ var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
7395
7761
  function writeSwiftProject(layout, input, moduleRoot) {
7396
7762
  const resourceTargets = swiftManifestTargets(
7397
7763
  input.files["Package.swift"] ?? "",
@@ -7424,10 +7790,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
7424
7790
  // sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
7425
7791
  // resource accessors ${resourcePlan}
7426
7792
  `;
7793
+ const objcExtensions = objcExtensionMemberIndex(
7794
+ Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
7795
+ );
7427
7796
  if (targets.length === 0) {
7428
7797
  for (const [file, contents] of Object.entries(input.files)) {
7429
7798
  if (file === "Package.swift") continue;
7430
- files.set(import_node_path7.default.join(layout.sources, file), compiledSource(file, contents));
7799
+ files.set(
7800
+ import_node_path7.default.join(layout.sources, file),
7801
+ compiledSource(file, contents, objcExtensions)
7802
+ );
7431
7803
  }
7432
7804
  let manifest = (0, import_node_fs7.readFileSync)(
7433
7805
  import_node_path7.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
@@ -7473,7 +7845,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
7473
7845
  const base = layout.multi ? layout.root : layout.sources;
7474
7846
  for (const [file, contents] of Object.entries(input.files)) {
7475
7847
  if (file === "Package.swift") continue;
7476
- files.set(import_node_path7.default.join(base, file), compiledSource(file, contents));
7848
+ files.set(import_node_path7.default.join(base, file), compiledSource(file, contents, objcExtensions));
7477
7849
  }
7478
7850
  files.set(
7479
7851
  import_node_path7.default.join(layout.root, "Package.swift"),
@@ -7599,10 +7971,16 @@ function compileSwiftProjectUnit(input, options) {
7599
7971
  plugin
7600
7972
  ])
7601
7973
  ],
7602
- { env: BUILD_ENV, maxBuffer: 64 * 1024 * 1024, timeout: options.timeoutMs }
7974
+ {
7975
+ env: BUILD_ENV,
7976
+ maxBuffer: 64 * 1024 * 1024,
7977
+ timeout: options.timeoutMs
7978
+ }
7603
7979
  );
7604
7980
  } catch (error) {
7605
- throw new Error(projectDiagnostic(outputOf(error), layout), { cause: error });
7981
+ throw new Error(projectDiagnostic(outputOf(error), layout), {
7982
+ cause: error
7983
+ });
7606
7984
  }
7607
7985
  return {
7608
7986
  hash,
@@ -7668,10 +8046,10 @@ var DEFAULT_LOCAL_RUNTIME_RETENTION_COUNT = 2;
7668
8046
  function createRuntimeDelivery(product) {
7669
8047
  function readConfig() {
7670
8048
  try {
7671
- const parsed = JSON.parse(
8049
+ const parsed2 = JSON.parse(
7672
8050
  import_node_fs9.default.readFileSync(product.configFile(), "utf8")
7673
8051
  );
7674
- return parsed && typeof parsed === "object" ? parsed : {};
8052
+ return parsed2 && typeof parsed2 === "object" ? parsed2 : {};
7675
8053
  } catch {
7676
8054
  return {};
7677
8055
  }
@@ -7683,7 +8061,7 @@ function createRuntimeDelivery(product) {
7683
8061
  }
7684
8062
  function resolveChannel(input) {
7685
8063
  const config = readConfig();
7686
- return input || process.env[product.env.channel] || config.runtimeChannel || "stable";
8064
+ return input || process.env[product.env.channel] || config.runtimeChannel || product.defaultChannel || "stable";
7687
8065
  }
7688
8066
  function resolvePin() {
7689
8067
  if (!product.env.pin) return null;
@@ -7957,7 +8335,7 @@ function createRuntimeDelivery(product) {
7957
8335
  async function installVerifiedTarball(tarball) {
7958
8336
  const { url, digest, destDir, installedMarker, label } = tarball;
7959
8337
  const downloadDir = import_node_fs9.default.mkdtempSync(import_node_path9.default.join(import_node_os3.default.tmpdir(), "runtime-delivery-download-"));
7960
- const archivePath = import_node_path9.default.join(downloadDir, "archive.tar.gz");
8338
+ const archivePath = import_node_path9.default.join(downloadDir, "archive");
7961
8339
  import_node_fs9.default.mkdirSync(import_node_path9.default.dirname(destDir), { recursive: true });
7962
8340
  const tmpDir = import_node_fs9.default.mkdtempSync(
7963
8341
  import_node_path9.default.join(import_node_path9.default.dirname(destDir), `.installing-${import_node_path9.default.basename(destDir)}-`)
@@ -7970,7 +8348,8 @@ async function installVerifiedTarball(tarball) {
7970
8348
  `${digest.algorithm} mismatch for ${label}: expected ${digest.value}, actual ${actual}`
7971
8349
  );
7972
8350
  }
7973
- await extractTarball(archivePath, tmpDir, tarball.stripComponents ?? 0);
8351
+ if (new URL(url).pathname.endsWith(".zip")) await extractZip(archivePath, tmpDir);
8352
+ else await extractTarball(archivePath, tmpDir, tarball.stripComponents ?? 0);
7974
8353
  if (!import_node_fs9.default.existsSync(import_node_path9.default.join(tmpDir, installedMarker))) {
7975
8354
  throw new Error(`extracted tarball for ${label} is missing ${installedMarker}`);
7976
8355
  }
@@ -8032,17 +8411,23 @@ function digestFile(filePath, algorithm, encoding) {
8032
8411
  stream.on("end", () => resolve5(hash.digest(encoding)));
8033
8412
  });
8034
8413
  }
8414
+ function extractZip(zipPath, destDir) {
8415
+ return runExtractor("ditto", ["-x", "-k", zipPath, destDir]);
8416
+ }
8035
8417
  function extractTarball(tarPath, destDir, stripComponents) {
8418
+ const args = ["-xzf", tarPath, "-C", destDir];
8419
+ if (stripComponents > 0) args.push(`--strip-components=${stripComponents}`);
8420
+ return runExtractor("tar", args);
8421
+ }
8422
+ function runExtractor(command, args) {
8036
8423
  return new Promise((resolve5, reject) => {
8037
- const args = ["-xzf", tarPath, "-C", destDir];
8038
- if (stripComponents > 0) args.push(`--strip-components=${stripComponents}`);
8039
- const child = (0, import_node_child_process4.spawn)("tar", args, {
8424
+ const child = (0, import_node_child_process4.spawn)(command, args, {
8040
8425
  stdio: ["ignore", "inherit", "inherit"]
8041
8426
  });
8042
8427
  child.on("error", reject);
8043
8428
  child.on("exit", (code) => {
8044
8429
  if (code === 0) resolve5();
8045
- else reject(new Error(`tar exited with code ${code}`));
8430
+ else reject(new Error(`${command} exited with code ${code}`));
8046
8431
  });
8047
8432
  });
8048
8433
  }
@@ -8052,24 +8437,24 @@ init_home_paths();
8052
8437
 
8053
8438
  // src/swift-distribution.lock.json
8054
8439
  var swift_distribution_lock_default = {
8055
- id: "42c53105b2e06d39",
8440
+ id: "d27a9b6d2aee64d4",
8056
8441
  release: "swift-6.3-RELEASE",
8057
- wasmSdkId: "swift-6.3-RELEASE_wasm-peach-728c7263",
8058
- wasmSdkUrl: "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-728c7263.artifactbundle.tar.gz",
8059
- wasmSdkChecksum: "5df8ab7be805d67d69d8dcd3ef7eec940b4eb1f3261410eba09d891ee170c559",
8060
- source: "d8c4bd1a0ffb45a9cad3fd15de02bc0d93e459fc",
8442
+ wasmSdkId: "swift-6.3-RELEASE_wasm-peach-41921598-peach-26be2317",
8443
+ wasmSdkUrl: "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-41921598-peach-26be2317.artifactbundle.tar.gz",
8444
+ wasmSdkChecksum: "f34f29d9426f42b04d1c38585d61cf38ecb5357f4287c4843870bec63de6b08c",
8445
+ source: "8f9873608a950d832ec49cf4bbc32fb65689e5f7",
8061
8446
  hosts: {
8062
8447
  "darwin-arm64": {
8063
- sha256: "d58abb1193369130460267e9cc57330f13de28e7a3aa404aeb7b9323cbd29384",
8064
- size: 7115901
8448
+ sha256: "b7fa68565ae1be6ee7964390b4d07949228894ac4a06fe7f58e4238dd0650197",
8449
+ size: 19319227
8065
8450
  },
8066
8451
  "linux-x64": {
8067
- sha256: "1cdd181fdd228e9f928367820cd39db2e703a7af47a819f7d26ed77b96839309",
8068
- size: 7121403
8452
+ sha256: "733ebee3a16142c97575532daf49990df57171ede17de6530a9c5906471d96ca",
8453
+ size: 19324099
8069
8454
  },
8070
8455
  "linux-arm64": {
8071
- sha256: "288e3ff43c881a63ec201856a61a90de323e8aa01714d47be65e8cac98af1738",
8072
- size: 7120448
8456
+ sha256: "84b258d95a71536392f25d2afb8c40835df771594a2c0e42049ee33781ce78ad",
8457
+ size: 19323438
8073
8458
  }
8074
8459
  }
8075
8460
  };
@@ -8194,10 +8579,10 @@ function swiftDistributionRoot() {
8194
8579
  return pending;
8195
8580
  }
8196
8581
  async function resolveSwiftModule() {
8197
- const checkout = import_node_path11.default.resolve(import_meta2.dirname, "../../sootsim-swift");
8198
- if (import_node_fs11.default.existsSync(import_node_path11.default.join(checkout, "toolchain.json"))) {
8582
+ const checkout2 = import_node_path11.default.resolve(import_meta2.dirname, "../../sootsim-swift");
8583
+ if (import_node_fs11.default.existsSync(import_node_path11.default.join(checkout2, "toolchain.json"))) {
8199
8584
  try {
8200
- return { root: checkout, ...swiftModuleToolchain(checkout) };
8585
+ return { root: checkout2, ...swiftModuleToolchain(checkout2) };
8201
8586
  } catch {
8202
8587
  return null;
8203
8588
  }
@@ -8215,9 +8600,9 @@ function swiftModuleToolchain(root) {
8215
8600
 
8216
8601
  // src/swift-host.ts
8217
8602
  var import_node_crypto5 = require("node:crypto");
8218
- var import_node_fs13 = __toESM(require("node:fs"), 1);
8603
+ var import_node_fs15 = __toESM(require("node:fs"), 1);
8219
8604
  var import_node_os5 = __toESM(require("node:os"), 1);
8220
- var import_node_path13 = __toESM(require("node:path"), 1);
8605
+ var import_node_path15 = __toESM(require("node:path"), 1);
8221
8606
 
8222
8607
  // ../sootsim-swift/src/bundleAssets.ts
8223
8608
  var import_svgpath = __toESM(require("svgpath"), 1);
@@ -8251,15 +8636,15 @@ function pickImagesetFile(images) {
8251
8636
  scale: pick.scale === "2x" ? 2 : pick.scale === "3x" ? 3 : 1
8252
8637
  };
8253
8638
  }
8254
- function flatScale(path18) {
8255
- const match = /@([23])x\.[^./]+$/.exec(path18);
8639
+ function flatScale(path20) {
8640
+ const match = /@([23])x\.[^./]+$/.exec(path20);
8256
8641
  return match ? Number(match[1]) : 1;
8257
8642
  }
8258
8643
  function providesNamespace(text) {
8259
8644
  if (text === null) return false;
8260
8645
  try {
8261
- const parsed = JSON.parse(text);
8262
- return parsed?.properties?.["provides-namespace"] === true;
8646
+ const parsed2 = JSON.parse(text);
8647
+ return parsed2?.properties?.["provides-namespace"] === true;
8263
8648
  } catch {
8264
8649
  return false;
8265
8650
  }
@@ -8279,25 +8664,25 @@ function catalogEntryName(contentsPath, kind, readText) {
8279
8664
  }
8280
8665
  return segments.join("/");
8281
8666
  }
8282
- function isFlatResourceImage(path18) {
8283
- return path18.split("/").includes("Resources") && RASTER_EXTENSIONS.has(extOf(path18));
8667
+ function isFlatResourceImage(path20) {
8668
+ return path20.split("/").includes("Resources") && RASTER_EXTENSIONS.has(extOf(path20));
8284
8669
  }
8285
8670
  function enumerateBundleImages(paths, readText) {
8286
8671
  const table = [];
8287
8672
  const seen = /* @__PURE__ */ new Set();
8288
- const catalogs = paths.filter((path18) => baseOf(path18) === "Contents.json");
8673
+ const catalogs = paths.filter((path20) => baseOf(path20) === "Contents.json");
8289
8674
  for (const contentsPath of catalogs) {
8290
8675
  const name2 = catalogEntryName(contentsPath, ".imageset", readText);
8291
8676
  if (name2 === null || seen.has(name2)) continue;
8292
- let parsed;
8677
+ let parsed2;
8293
8678
  try {
8294
8679
  const text = readText(contentsPath);
8295
8680
  if (text === null) continue;
8296
- parsed = JSON.parse(text);
8681
+ parsed2 = JSON.parse(text);
8297
8682
  } catch {
8298
8683
  continue;
8299
8684
  }
8300
- const images = parsed?.images;
8685
+ const images = parsed2?.images;
8301
8686
  if (!Array.isArray(images)) continue;
8302
8687
  const dir = contentsPath.split("/").slice(0, -1).join("/");
8303
8688
  const pick = pickImagesetFile(images);
@@ -8306,19 +8691,19 @@ function enumerateBundleImages(paths, readText) {
8306
8691
  seen.add(name2);
8307
8692
  table.push({ name: name2, file: `${dir}/${pick.filename}`, scale: pick.scale });
8308
8693
  }
8309
- for (const path18 of paths) {
8310
- if (!isFlatResourceImage(path18)) continue;
8311
- const name2 = baseOf(path18).slice(0, -extOf(path18).length);
8694
+ for (const path20 of paths) {
8695
+ if (!isFlatResourceImage(path20)) continue;
8696
+ const name2 = baseOf(path20).slice(0, -extOf(path20).length);
8312
8697
  if (name2 === "" || seen.has(name2)) continue;
8313
8698
  seen.add(name2);
8314
- table.push({ name: name2, file: path18, scale: flatScale(path18) });
8699
+ table.push({ name: name2, file: path20, scale: flatScale(path20) });
8315
8700
  }
8316
8701
  return table;
8317
8702
  }
8318
8703
  function colorComponent(value) {
8319
8704
  if (typeof value !== "string") return null;
8320
- const parsed = value.startsWith("0x") ? Number.parseInt(value.slice(2), 16) / 255 : value.includes(".") ? Number.parseFloat(value) : Number.parseInt(value, 10) / 255;
8321
- return Number.isFinite(parsed) ? parsed : null;
8705
+ const parsed2 = value.startsWith("0x") ? Number.parseInt(value.slice(2), 16) / 255 : value.includes(".") ? Number.parseFloat(value) : Number.parseInt(value, 10) / 255;
8706
+ return Number.isFinite(parsed2) ? parsed2 : null;
8322
8707
  }
8323
8708
  function colorsetValue(color) {
8324
8709
  if (typeof color !== "object" || color === null) return null;
@@ -8340,7 +8725,7 @@ function colorsetValue(color) {
8340
8725
  }
8341
8726
  function enumerateBundleColors(paths, readText) {
8342
8727
  const table = {};
8343
- for (const contentsPath of paths.filter((path18) => baseOf(path18) === "Contents.json")) {
8728
+ for (const contentsPath of paths.filter((path20) => baseOf(path20) === "Contents.json")) {
8344
8729
  const name2 = catalogEntryName(contentsPath, ".colorset", readText);
8345
8730
  if (name2 === null || name2 in table) continue;
8346
8731
  let colors;
@@ -8359,12 +8744,12 @@ function enumerateBundleColors(paths, readText) {
8359
8744
  const idiom = Reflect.get(entry, "idiom");
8360
8745
  if (idiom !== "universal" && idiom !== "iphone") continue;
8361
8746
  const appearances = Reflect.get(entry, "appearances");
8362
- const list = Array.isArray(appearances) ? appearances : [];
8363
- if (list.some((item) => Reflect.get(item, "appearance") === "contrast")) continue;
8364
- const isDark = list.some(
8747
+ const list2 = Array.isArray(appearances) ? appearances : [];
8748
+ if (list2.some((item) => Reflect.get(item, "appearance") === "contrast")) continue;
8749
+ const isDark = list2.some(
8365
8750
  (item) => Reflect.get(item, "appearance") === "luminosity" && Reflect.get(item, "value") === "dark"
8366
8751
  );
8367
- if (list.length > 0 && !isDark) continue;
8752
+ if (list2.length > 0 && !isDark) continue;
8368
8753
  const value = colorsetValue(Reflect.get(entry, "color"));
8369
8754
  if (value === null) continue;
8370
8755
  if (isDark) dark = value;
@@ -8405,8 +8790,8 @@ function axisExtremes(points) {
8405
8790
  function pathBounds(d) {
8406
8791
  const xs = [];
8407
8792
  const ys = [];
8408
- for (const path18 of d)
8409
- (0, import_svgpath.default)(path18).abs().unshort().unarc().iterate((segment, _index, x, y) => {
8793
+ for (const path20 of d)
8794
+ (0, import_svgpath.default)(path20).abs().unshort().unarc().iterate((segment, _index, x, y) => {
8410
8795
  const [command, ...args] = segment;
8411
8796
  if (command === "M" || command === "L") {
8412
8797
  xs.push(Number(args[0]));
@@ -8433,7 +8818,7 @@ function guide(svg, id, axis) {
8433
8818
  }
8434
8819
  function enumerateBundleSymbols(paths, readText) {
8435
8820
  const table = {};
8436
- for (const contentsPath of paths.filter((path18) => baseOf(path18) === "Contents.json")) {
8821
+ for (const contentsPath of paths.filter((path20) => baseOf(path20) === "Contents.json")) {
8437
8822
  const name2 = catalogEntryName(contentsPath, ".symbolset", readText);
8438
8823
  if (name2 === null || name2 in table) continue;
8439
8824
  let symbols;
@@ -8466,8 +8851,8 @@ function enumerateBundleSymbols(paths, readText) {
8466
8851
  viewBox: "0 0 24 24",
8467
8852
  advance,
8468
8853
  box: [12 - advance / 2, 12 - tall / 2, advance, tall],
8469
- layers: d.map((path18) => ({
8470
- d: (0, import_svgpath.default)(path18).abs().scale(scale).translate(translateX, translateY).round(3).toString()
8854
+ layers: d.map((path20) => ({
8855
+ d: (0, import_svgpath.default)(path20).abs().scale(scale).translate(translateX, translateY).round(3).toString()
8471
8856
  }))
8472
8857
  };
8473
8858
  }
@@ -8477,7 +8862,7 @@ function enumerateBundleJson(paths) {
8477
8862
  const found = [];
8478
8863
  const seen = /* @__PURE__ */ new Set();
8479
8864
  const ordered = [...paths].filter(
8480
- (path18) => path18.split("/").includes("Resources") && path18.split("/").every((segment) => segment !== "" && segment !== "..") && (extOf(path18) === ".json" || extOf(path18) === ".xcstrings")
8865
+ (path20) => path20.split("/").includes("Resources") && path20.split("/").every((segment) => segment !== "" && segment !== "..") && (extOf(path20) === ".json" || extOf(path20) === ".xcstrings")
8481
8866
  ).sort((a, b) => {
8482
8867
  const aDepth = a.split("/").length;
8483
8868
  const bDepth = b.split("/").length;
@@ -8496,6 +8881,190 @@ function enumerateBundleJson(paths) {
8496
8881
  init_auth();
8497
8882
  init_backend_origin();
8498
8883
 
8884
+ // src/swift-remote-packages.ts
8885
+ var import_node_child_process6 = require("node:child_process");
8886
+ var import_node_fs13 = __toESM(require("node:fs"), 1);
8887
+ var import_node_path13 = __toESM(require("node:path"), 1);
8888
+ var REMOTE_CHECKOUTS = import_node_path13.default.join(".build", "peach", "checkouts");
8889
+ var C_FAMILY = /\.(c|cc|cpp|cxx|m|mm|s|S)$/;
8890
+ function readPins(resolved) {
8891
+ const data = JSON.parse(import_node_fs13.default.readFileSync(resolved, "utf8"));
8892
+ const pins = data && typeof data === "object" && "pins" in data && Array.isArray(data.pins) ? data.pins : null;
8893
+ if (!pins)
8894
+ throw new Error(`${resolved} has no pins; resolve packages in a current Xcode`);
8895
+ const out = /* @__PURE__ */ new Map();
8896
+ for (const pin of pins) {
8897
+ const identity = pin?.identity;
8898
+ const location2 = pin?.location;
8899
+ const revision = pin?.state?.revision;
8900
+ if (typeof identity === "string" && typeof location2 === "string" && typeof revision === "string")
8901
+ out.set(identity, { location: location2, revision });
8902
+ }
8903
+ return out;
8904
+ }
8905
+ function walk(dir) {
8906
+ if (!import_node_fs13.default.existsSync(dir)) return [];
8907
+ const out = [];
8908
+ for (const entry of import_node_fs13.default.readdirSync(dir, { withFileTypes: true })) {
8909
+ if (entry.name.startsWith(".")) continue;
8910
+ const full = import_node_path13.default.join(dir, entry.name);
8911
+ if (entry.isDirectory()) out.push(...walk(full));
8912
+ else if (entry.isFile()) out.push(full);
8913
+ }
8914
+ return out.sort();
8915
+ }
8916
+ var verified2 = /* @__PURE__ */ new Set();
8917
+ function checkout(checkouts, identity, pin) {
8918
+ const dir = import_node_path13.default.join(checkouts, identity);
8919
+ const key = `${dir}\0${pin.revision}`;
8920
+ if (verified2.has(key)) return dir;
8921
+ const git = (...args) => (0, import_node_child_process6.execFileSync)("git", ["-C", dir, ...args], {
8922
+ encoding: "utf8",
8923
+ stdio: ["ignore", "pipe", "pipe"]
8924
+ }).trim();
8925
+ const current = import_node_fs13.default.existsSync(import_node_path13.default.join(dir, ".git")) ? git("rev-parse", "HEAD") : "";
8926
+ if (current !== pin.revision) {
8927
+ import_node_fs13.default.rmSync(dir, { recursive: true, force: true });
8928
+ import_node_fs13.default.mkdirSync(dir, { recursive: true });
8929
+ try {
8930
+ git("init", "-q");
8931
+ git("fetch", "-q", "--depth", "1", pin.location, pin.revision);
8932
+ git("checkout", "-q", "FETCH_HEAD");
8933
+ } catch (error) {
8934
+ import_node_fs13.default.rmSync(dir, { recursive: true, force: true });
8935
+ const stderr = error instanceof Error && "stderr" in error ? String(error.stderr).trim() : "";
8936
+ throw new Error(
8937
+ `could not fetch ${pin.location} at ${pin.revision}${stderr ? `: ${stderr}` : ""}`
8938
+ );
8939
+ }
8940
+ }
8941
+ verified2.add(key);
8942
+ return dir;
8943
+ }
8944
+ function resolveRemotePackages(projectDir, resolved, products, provided) {
8945
+ const result = { targets: [], unavailable: /* @__PURE__ */ new Map() };
8946
+ const wanted = products.filter((entry) => !provided.has(entry.product));
8947
+ if (wanted.length === 0) return result;
8948
+ if (!resolved) {
8949
+ for (const entry of wanted)
8950
+ result.unavailable.set(entry.product, {
8951
+ repositoryURL: entry.repositoryURL,
8952
+ reason: "no Package.resolved pins it; resolve packages in Xcode once"
8953
+ });
8954
+ return result;
8955
+ }
8956
+ const pins = readPins(resolved);
8957
+ const checkouts = import_node_path13.default.join(projectDir, REMOTE_CHECKOUTS);
8958
+ import_node_fs13.default.mkdirSync(checkouts, { recursive: true });
8959
+ import_node_fs13.default.writeFileSync(import_node_path13.default.join(import_node_path13.default.dirname(checkouts), ".gitignore"), "*\n");
8960
+ const packages = /* @__PURE__ */ new Map();
8961
+ const load2 = (identity) => {
8962
+ const cached3 = packages.get(identity);
8963
+ if (cached3) return cached3;
8964
+ const pin = pins.get(identity);
8965
+ if (!pin) return null;
8966
+ const dir = checkout(checkouts, identity, pin);
8967
+ const manifest = import_node_fs13.default.readFileSync(import_node_path13.default.join(dir, "Package.swift"), "utf8");
8968
+ const loaded = { dir, manifest, graph: swiftManifestGraph(manifest) };
8969
+ packages.set(identity, loaded);
8970
+ return loaded;
8971
+ };
8972
+ const targets = /* @__PURE__ */ new Map();
8973
+ const outcomes = /* @__PURE__ */ new Map();
8974
+ const resolveProduct = (identity, product) => {
8975
+ const key = `${identity}\0${product}`;
8976
+ if (outcomes.has(key)) return outcomes.get(key);
8977
+ outcomes.set(key, null);
8978
+ const pkg = load2(identity);
8979
+ if (!pkg) {
8980
+ outcomes.set(key, `package ${identity} is not pinned in Package.resolved`);
8981
+ return outcomes.get(key);
8982
+ }
8983
+ const roots = pkg.graph.products.get(product);
8984
+ if (!roots) {
8985
+ outcomes.set(key, `package ${identity} has no library ${product}`);
8986
+ return outcomes.get(key);
8987
+ }
8988
+ const declared = new Map(
8989
+ swiftManifestTargets(pkg.manifest).map((target) => [target.name, target])
8990
+ );
8991
+ const reached = [];
8992
+ const seen = /* @__PURE__ */ new Set();
8993
+ const pending = [...roots];
8994
+ let reason = null;
8995
+ while (pending.length > 0 && !reason) {
8996
+ const name2 = pending.pop();
8997
+ if (seen.has(name2) || provided.has(name2)) continue;
8998
+ seen.add(name2);
8999
+ if (pkg.graph.binaryTargets.has(name2)) {
9000
+ reason = `${name2} is a binary framework`;
9001
+ break;
9002
+ }
9003
+ if (pkg.graph.systemLibraries.has(name2)) {
9004
+ reason = `${name2} is a system C library`;
9005
+ break;
9006
+ }
9007
+ const target = declared.get(name2);
9008
+ if (!target) {
9009
+ reason = `${identity} declares no target ${name2}`;
9010
+ break;
9011
+ }
9012
+ const files = walk(import_node_path13.default.join(pkg.dir, target.path));
9013
+ if (files.some((file) => C_FAMILY.test(file))) {
9014
+ reason = `${name2} is a C or Objective-C target`;
9015
+ break;
9016
+ }
9017
+ reached.push(target);
9018
+ for (const dependency of pkg.graph.dependencies.get(name2) ?? []) {
9019
+ if (dependency.kind === "target") pending.push(dependency.name);
9020
+ else if (!provided.has(dependency.name)) {
9021
+ const url = pkg.graph.packageURLs.get(dependency.package);
9022
+ const nested = resolveProduct(
9023
+ url ? swiftPackageIdentity(url) : dependency.package,
9024
+ dependency.name
9025
+ );
9026
+ if (nested) reason = `${dependency.name}: ${nested}`;
9027
+ }
9028
+ }
9029
+ }
9030
+ if (reason) {
9031
+ outcomes.set(key, reason);
9032
+ return reason;
9033
+ }
9034
+ const relative2 = reached.flatMap(
9035
+ (target) => walk(import_node_path13.default.join(pkg.dir, target.path)).map(
9036
+ (file) => import_node_path13.default.relative(pkg.dir, file).split(import_node_path13.default.sep).join(import_node_path13.default.posix.sep)
9037
+ )
9038
+ );
9039
+ const withResources = new Map(
9040
+ swiftManifestTargets(pkg.manifest, relative2).map((target) => [target.name, target])
9041
+ );
9042
+ for (const target of reached) {
9043
+ const dir = import_node_path13.default.join(pkg.dir, target.path);
9044
+ targets.set(target.name, {
9045
+ ...withResources.get(target.name) ?? target,
9046
+ executable: false,
9047
+ dir,
9048
+ files: walk(dir)
9049
+ });
9050
+ }
9051
+ return null;
9052
+ };
9053
+ for (const entry of wanted) {
9054
+ const reason = resolveProduct(
9055
+ swiftPackageIdentity(entry.repositoryURL),
9056
+ entry.product
9057
+ );
9058
+ if (reason)
9059
+ result.unavailable.set(entry.product, {
9060
+ repositoryURL: entry.repositoryURL,
9061
+ reason
9062
+ });
9063
+ }
9064
+ result.targets = [...targets.values()];
9065
+ return result;
9066
+ }
9067
+
8499
9068
  // src/swift-submit.ts
8500
9069
  var SWIFT_COMPILE_PATH = "/api/swift-compile";
8501
9070
  var MAX_SWIFT_COMPILE_FILES = 256;
@@ -8506,7 +9075,7 @@ var MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES = 8 * 1024 * 1024;
8506
9075
  var MAX_SWIFT_COMPILE_IMAGES = 128;
8507
9076
  var MAX_SWIFT_COMPILE_IMAGE_BYTES = 4 * 1024 * 1024;
8508
9077
  var MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024;
8509
- var SWIFT_HOST_ABI = 21;
9078
+ var SWIFT_HOST_ABI = 24;
8510
9079
  var POLL_INTERVAL_MS = 1500;
8511
9080
  function httpSwiftCompileSubmit(context) {
8512
9081
  const { assetReadToken, authorization, endpoint } = context;
@@ -8622,6 +9191,445 @@ async function compileSwiftProject(submit, work, origin, signal) {
8622
9191
  }
8623
9192
  }
8624
9193
 
9194
+ // src/xcode-project.ts
9195
+ var import_node_fs14 = __toESM(require("node:fs"), 1);
9196
+ var import_node_path14 = __toESM(require("node:path"), 1);
9197
+ var import_plist3 = __toESM(require_plist(), 1);
9198
+ function parseOpenStepPlist(text) {
9199
+ let i = 0;
9200
+ const fail = (message) => {
9201
+ const line = text.slice(0, i).split("\n").length;
9202
+ throw new Error(`project.pbxproj line ${line}: ${message}`);
9203
+ };
9204
+ const skip = () => {
9205
+ for (; ; ) {
9206
+ const ch = text[i];
9207
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r") i++;
9208
+ else if (ch === "/" && text[i + 1] === "*") {
9209
+ const end = text.indexOf("*/", i + 2);
9210
+ if (end < 0) fail("unterminated comment");
9211
+ i = end + 2;
9212
+ } else if (ch === "/" && text[i + 1] === "/") {
9213
+ const end = text.indexOf("\n", i);
9214
+ i = end < 0 ? text.length : end + 1;
9215
+ } else return;
9216
+ }
9217
+ };
9218
+ const quoted = () => {
9219
+ i++;
9220
+ let out = "";
9221
+ for (; ; ) {
9222
+ const ch = text[i++];
9223
+ if (ch === void 0) fail("unterminated string");
9224
+ if (ch === '"') return out;
9225
+ if (ch !== "\\") {
9226
+ out += ch;
9227
+ continue;
9228
+ }
9229
+ const next = text[i++];
9230
+ if (next === "n") out += "\n";
9231
+ else if (next === "t") out += " ";
9232
+ else if (next === "r") out += "\r";
9233
+ else if (next === "U") {
9234
+ out += String.fromCharCode(parseInt(text.slice(i, i + 4), 16));
9235
+ i += 4;
9236
+ } else out += next;
9237
+ }
9238
+ };
9239
+ const value = () => {
9240
+ skip();
9241
+ const ch = text[i];
9242
+ if (ch === "{") {
9243
+ i++;
9244
+ const dict = {};
9245
+ for (; ; ) {
9246
+ skip();
9247
+ if (text[i] === "}") {
9248
+ i++;
9249
+ return dict;
9250
+ }
9251
+ const key = value();
9252
+ if (typeof key !== "string") fail("dictionary key is not a string");
9253
+ skip();
9254
+ if (text[i++] !== "=") fail("expected =");
9255
+ dict[key] = value();
9256
+ skip();
9257
+ if (text[i++] !== ";") fail("expected ;");
9258
+ }
9259
+ }
9260
+ if (ch === "(") {
9261
+ i++;
9262
+ const list2 = [];
9263
+ for (; ; ) {
9264
+ skip();
9265
+ if (text[i] === ")") {
9266
+ i++;
9267
+ return list2;
9268
+ }
9269
+ list2.push(value());
9270
+ skip();
9271
+ if (text[i] === ",") i++;
9272
+ else if (text[i] !== ")") fail("expected , or )");
9273
+ }
9274
+ }
9275
+ if (ch === '"') return quoted();
9276
+ const start = i;
9277
+ while (i < text.length && /[A-Za-z0-9_$+/:.\-<>]/.test(text[i])) i++;
9278
+ if (i === start) fail(`unexpected ${JSON.stringify(ch ?? "end of file")}`);
9279
+ return text.slice(start, i);
9280
+ };
9281
+ if (text.startsWith("// !$*UTF8*$!")) i = text.indexOf("\n") + 1;
9282
+ const root = value();
9283
+ skip();
9284
+ if (i !== text.length) fail("trailing content");
9285
+ return root;
9286
+ }
9287
+ var isDict = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9288
+ var str = (value) => typeof value === "string" ? value : void 0;
9289
+ var list = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
9290
+ var APPLICATION = "com.apple.product-type.application";
9291
+ var NEVER_MEMBER = /(?:^|\/)(?:Info\.plist|[^/]+\.entitlements|[^/]+\.xcconfig|\.DS_Store)$/;
9292
+ var BUNDLE_DIR = /\.(xcassets|bundle|lproj|xcdatamodeld|scnassets|spriteatlas|rcproject|storyboardc|icon)$/;
9293
+ function walkFiles(dir) {
9294
+ if (!import_node_fs14.default.existsSync(dir)) return [];
9295
+ const out = [];
9296
+ for (const entry of import_node_fs14.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
9297
+ if (entry.name.startsWith(".")) continue;
9298
+ const full = import_node_path14.default.join(dir, entry.name);
9299
+ if (entry.isDirectory()) out.push(...walkFiles(full));
9300
+ else if (entry.isFile()) out.push(full);
9301
+ }
9302
+ return out;
9303
+ }
9304
+ function readXcconfig(file, seen = /* @__PURE__ */ new Set()) {
9305
+ if (seen.has(file) || !import_node_fs14.default.existsSync(file)) return {};
9306
+ seen.add(file);
9307
+ const settings = {};
9308
+ for (const raw2 of import_node_fs14.default.readFileSync(file, "utf8").split("\n")) {
9309
+ const line = raw2.replace(/\/\/.*$/, "").trim();
9310
+ const include = /^#include\??\s+"([^"]+)"/.exec(line);
9311
+ if (include) {
9312
+ Object.assign(
9313
+ settings,
9314
+ readXcconfig(import_node_path14.default.resolve(import_node_path14.default.dirname(file), include[1]), seen)
9315
+ );
9316
+ continue;
9317
+ }
9318
+ const setting = /^([A-Z_][A-Z0-9_]*)(?:\[[^\]]*\])?\s*=\s*(.*)$/.exec(line);
9319
+ if (setting) settings[setting[1]] = setting[2].trim();
9320
+ }
9321
+ return settings;
9322
+ }
9323
+ function c99Identifier(name2) {
9324
+ const id = name2.replace(/[^A-Za-z0-9_]/g, "_");
9325
+ return /^[0-9]/.test(id) ? `_${id}` : id;
9326
+ }
9327
+ var parsed = /* @__PURE__ */ new Map();
9328
+ function readProject(pbxproj) {
9329
+ const mtimeMs = import_node_fs14.default.statSync(pbxproj).mtimeMs;
9330
+ const cached3 = parsed.get(pbxproj);
9331
+ if (cached3?.mtimeMs === mtimeMs) return cached3.root;
9332
+ const root = parseOpenStepPlist(import_node_fs14.default.readFileSync(pbxproj, "utf8"));
9333
+ if (!isDict(root) || !isDict(root.objects)) {
9334
+ throw new Error(`${pbxproj} has no objects table`);
9335
+ }
9336
+ parsed.set(pbxproj, { mtimeMs, root });
9337
+ return root;
9338
+ }
9339
+ function readXcodeAppTarget(xcodeproj, targetName) {
9340
+ const pbxproj = import_node_path14.default.join(xcodeproj, "project.pbxproj");
9341
+ if (!import_node_fs14.default.existsSync(pbxproj)) throw new Error(`${xcodeproj} has no project.pbxproj`);
9342
+ const root = readProject(pbxproj);
9343
+ const objects = root.objects;
9344
+ const object = (id) => {
9345
+ const found = id === void 0 ? void 0 : objects[id];
9346
+ return isDict(found) ? found : void 0;
9347
+ };
9348
+ const project = object(str(root.rootObject));
9349
+ if (!project || project.isa !== "PBXProject") {
9350
+ throw new Error(`${pbxproj} has no PBXProject root`);
9351
+ }
9352
+ const projectDir = import_node_fs14.default.realpathSync(
9353
+ import_node_path14.default.resolve(import_node_path14.default.dirname(xcodeproj), str(project.projectDirPath) ?? "")
9354
+ );
9355
+ const parent = /* @__PURE__ */ new Map();
9356
+ for (const [id, entry] of Object.entries(objects)) {
9357
+ if (!isDict(entry)) continue;
9358
+ if (entry.isa === "PBXGroup" || entry.isa === "PBXVariantGroup") {
9359
+ for (const child of list(entry.children)) parent.set(child, id);
9360
+ }
9361
+ }
9362
+ const resolvedPaths = /* @__PURE__ */ new Map();
9363
+ const resolvePath = (id) => {
9364
+ if (resolvedPaths.has(id)) return resolvedPaths.get(id);
9365
+ const entry = object(id);
9366
+ let result = null;
9367
+ if (entry) {
9368
+ const own = str(entry.path) ?? "";
9369
+ const tree = str(entry.sourceTree) ?? "<group>";
9370
+ if (tree === "<absolute>") result = own;
9371
+ else if (tree === "SOURCE_ROOT") result = import_node_path14.default.join(projectDir, own);
9372
+ else if (tree === "<group>") {
9373
+ const up = parent.get(id);
9374
+ const base = up ? resolvePath(up) : projectDir;
9375
+ result = base === null ? null : import_node_path14.default.join(base, own);
9376
+ }
9377
+ }
9378
+ resolvedPaths.set(id, result);
9379
+ return result;
9380
+ };
9381
+ const targets = list(project.targets).map((id) => ({ id, target: object(id) })).filter(
9382
+ (entry) => entry.target?.isa === "PBXNativeTarget"
9383
+ );
9384
+ const appTargets = targets.filter((entry) => entry.target.productType === APPLICATION);
9385
+ const appTargetNames = appTargets.map((entry) => str(entry.target.name) ?? entry.id);
9386
+ const chosen = targetName ? appTargets.find((entry) => entry.target.name === targetName) : appTargets.length === 1 ? appTargets[0] : void 0;
9387
+ if (!chosen) {
9388
+ throw new Error(
9389
+ targetName ? `${import_node_path14.default.basename(xcodeproj)} has no application target ${targetName}; it has ${appTargetNames.join(", ") || "none"}` : `${import_node_path14.default.basename(xcodeproj)} has ${appTargetNames.length} application targets (${appTargetNames.join(", ") || "none"}); pass --target`
9390
+ );
9391
+ }
9392
+ const { id: targetId, target } = chosen;
9393
+ const configSettings = (listId) => {
9394
+ const configs = list(object(listId)?.buildConfigurations).map(object);
9395
+ const config = configs.find((entry) => entry?.name === "Debug") ?? configs.find(Boolean);
9396
+ if (!config) return {};
9397
+ const base = str(config.baseConfigurationReference);
9398
+ const fromFile = base ? readXcconfig(resolvePath(base) ?? "") : {};
9399
+ const own = isDict(config.buildSettings) ? config.buildSettings : {};
9400
+ return {
9401
+ ...fromFile,
9402
+ ...Object.fromEntries(
9403
+ Object.entries(own).flatMap(
9404
+ ([key, value]) => typeof value === "string" ? [[key, value]] : []
9405
+ )
9406
+ )
9407
+ };
9408
+ };
9409
+ const settings = {
9410
+ ...configSettings(str(project.buildConfigurationList)),
9411
+ ...configSettings(str(target.buildConfigurationList))
9412
+ };
9413
+ const name2 = str(target.name) ?? targetId;
9414
+ const productName = (settings.PRODUCT_NAME ?? "$(TARGET_NAME)").replaceAll("$(TARGET_NAME)", name2).replaceAll("${TARGET_NAME}", name2);
9415
+ const moduleName = c99Identifier(
9416
+ settings.PRODUCT_MODULE_NAME && !settings.PRODUCT_MODULE_NAME.includes("$(") ? settings.PRODUCT_MODULE_NAME : productName
9417
+ );
9418
+ const variables = {
9419
+ ...settings,
9420
+ EXECUTABLE_NAME: settings.EXECUTABLE_NAME ?? productName,
9421
+ DEVELOPMENT_LANGUAGE: settings.DEVELOPMENT_LANGUAGE ?? str(project.developmentRegion) ?? "en",
9422
+ TARGET_NAME: name2,
9423
+ PRODUCT_NAME: productName,
9424
+ PRODUCT_MODULE_NAME: moduleName,
9425
+ SRCROOT: projectDir,
9426
+ SOURCE_ROOT: projectDir
9427
+ };
9428
+ const expand = (value) => {
9429
+ const seen = /* @__PURE__ */ new Set();
9430
+ while (/\$[({][A-Za-z_][A-Za-z0-9_]*[)}]/.test(value)) {
9431
+ if (seen.has(value)) throw new Error(`${name2} has cyclic Info.plist build settings`);
9432
+ seen.add(value);
9433
+ value = value.replace(
9434
+ /\$[({]([A-Za-z_][A-Za-z0-9_]*)[)}]/g,
9435
+ (match, key) => {
9436
+ const replacement = Object.entries(variables).find(
9437
+ ([name3]) => name3 === key
9438
+ )?.[1];
9439
+ if (replacement === void 0)
9440
+ throw new Error(`${name2} Info.plist has unresolved setting ${match}`);
9441
+ return replacement;
9442
+ }
9443
+ );
9444
+ }
9445
+ return value;
9446
+ };
9447
+ const expandValue = (value) => {
9448
+ if (typeof value === "string") return expand(value);
9449
+ if (Array.isArray(value)) return value.map(expandValue);
9450
+ if (typeof value === "object" && !(value instanceof Date) && !Buffer.isBuffer(value)) {
9451
+ return Object.fromEntries(
9452
+ Object.entries(value).map(([key, value2]) => [key, expandValue(value2)])
9453
+ );
9454
+ }
9455
+ return value;
9456
+ };
9457
+ const infoPlistFile = settings.INFOPLIST_FILE ? import_node_path14.default.resolve(projectDir, expand(settings.INFOPLIST_FILE)) : null;
9458
+ const sourceInfo = infoPlistFile ? import_plist3.default.parse(import_node_fs14.default.readFileSync(infoPlistFile, "utf8")) : {};
9459
+ if (!sourceInfo || typeof sourceInfo !== "object" || Array.isArray(sourceInfo) || sourceInfo instanceof Date || Buffer.isBuffer(sourceInfo)) {
9460
+ throw new Error(`${name2} Info.plist must contain a dictionary`);
9461
+ }
9462
+ const info = {};
9463
+ for (const [key, value] of Object.entries(sourceInfo)) info[key] = expandValue(value);
9464
+ for (const [key, value] of Object.entries(settings)) {
9465
+ if (!key.startsWith("INFOPLIST_KEY_") || key.endsWith("_Generation")) continue;
9466
+ info[key.slice("INFOPLIST_KEY_".length)] = value === "YES" ? true : value === "NO" ? false : expand(value);
9467
+ }
9468
+ if (settings.INFOPLIST_KEY_UIApplicationSceneManifest_Generation === "YES" && info.UIApplicationSceneManifest === void 0) {
9469
+ info.UIApplicationSceneManifest = {
9470
+ UIApplicationSupportsMultipleScenes: true,
9471
+ UISceneConfigurations: {}
9472
+ };
9473
+ }
9474
+ const sources = /* @__PURE__ */ new Set();
9475
+ const resources = /* @__PURE__ */ new Set();
9476
+ const addResource = (file) => {
9477
+ if (import_node_fs14.default.existsSync(file) && import_node_fs14.default.statSync(file).isDirectory()) {
9478
+ for (const inner of walkFiles(file)) resources.add(inner);
9479
+ } else if (import_node_fs14.default.existsSync(file)) resources.add(file);
9480
+ };
9481
+ const fileRefPaths = (refId) => {
9482
+ const ref = object(refId);
9483
+ if (!ref) return [];
9484
+ if (ref.isa === "PBXVariantGroup") {
9485
+ return list(ref.children).flatMap((child) => {
9486
+ const resolved2 = resolvePath(child);
9487
+ return resolved2 ? [resolved2] : [];
9488
+ });
9489
+ }
9490
+ const resolved = resolvePath(refId);
9491
+ return resolved ? [resolved] : [];
9492
+ };
9493
+ for (const phaseId of list(target.buildPhases)) {
9494
+ const phase = object(phaseId);
9495
+ if (phase?.isa !== "PBXSourcesBuildPhase" && phase?.isa !== "PBXResourcesBuildPhase")
9496
+ continue;
9497
+ for (const buildFileId of list(phase.files)) {
9498
+ for (const file of fileRefPaths(str(object(buildFileId)?.fileRef) ?? "")) {
9499
+ if (phase.isa === "PBXSourcesBuildPhase" && file.endsWith(".swift")) {
9500
+ if (import_node_fs14.default.existsSync(file)) sources.add(file);
9501
+ } else if (phase.isa === "PBXResourcesBuildPhase") addResource(file);
9502
+ }
9503
+ }
9504
+ }
9505
+ const addSynchronized = (folder, relative2) => {
9506
+ const file = import_node_path14.default.join(folder, relative2);
9507
+ if (NEVER_MEMBER.test(relative2)) return;
9508
+ if (file.endsWith(".swift")) {
9509
+ if (!relative2.split("/").some((segment) => BUNDLE_DIR.test(segment)))
9510
+ sources.add(file);
9511
+ } else if (/\.(h|m|mm|c|cpp|metal)$/.test(file)) {
9512
+ return;
9513
+ } else resources.add(file);
9514
+ };
9515
+ const owned = new Set(list(target.fileSystemSynchronizedGroups));
9516
+ for (const [groupId, group] of Object.entries(objects)) {
9517
+ if (!isDict(group) || group.isa !== "PBXFileSystemSynchronizedRootGroup") continue;
9518
+ const folder = resolvePath(groupId);
9519
+ if (!folder) continue;
9520
+ const exceptions = /* @__PURE__ */ new Set();
9521
+ for (const exceptionId of list(group.exceptions)) {
9522
+ const exception = object(exceptionId);
9523
+ if (exception?.target !== targetId) continue;
9524
+ for (const relative2 of list(exception.membershipExceptions))
9525
+ exceptions.add(relative2);
9526
+ }
9527
+ if (owned.has(groupId)) {
9528
+ for (const file of walkFiles(folder)) {
9529
+ const relative2 = import_node_path14.default.relative(folder, file).split(import_node_path14.default.sep).join("/");
9530
+ if ([...exceptions].some(
9531
+ (exception) => relative2 === exception || relative2.startsWith(`${exception}/`)
9532
+ ))
9533
+ continue;
9534
+ addSynchronized(folder, relative2);
9535
+ }
9536
+ } else {
9537
+ for (const relative2 of exceptions) {
9538
+ const file = import_node_path14.default.join(folder, relative2);
9539
+ if (import_node_fs14.default.existsSync(file) && import_node_fs14.default.statSync(file).isDirectory()) {
9540
+ for (const inner of walkFiles(file))
9541
+ addSynchronized(
9542
+ folder,
9543
+ import_node_path14.default.relative(folder, inner).split(import_node_path14.default.sep).join("/")
9544
+ );
9545
+ } else if (import_node_fs14.default.existsSync(file)) addSynchronized(folder, relative2);
9546
+ }
9547
+ }
9548
+ }
9549
+ const localPackageDirs = Object.entries(objects).flatMap(([id, entry]) => {
9550
+ if (!isDict(entry)) return [];
9551
+ const candidate = entry.isa === "XCLocalSwiftPackageReference" ? import_node_path14.default.resolve(projectDir, str(entry.relativePath) ?? "") : entry.isa === "PBXFileReference" && entry.lastKnownFileType === "wrapper" ? resolvePath(id) : null;
9552
+ return candidate && import_node_fs14.default.existsSync(import_node_path14.default.join(candidate, "Package.swift")) ? [candidate] : [];
9553
+ });
9554
+ const graphs = /* @__PURE__ */ new Map();
9555
+ const graphOf = (dir) => {
9556
+ const cached3 = graphs.get(dir);
9557
+ if (cached3) return cached3;
9558
+ const graph = swiftManifestGraph(
9559
+ import_node_fs14.default.readFileSync(import_node_path14.default.join(dir, "Package.swift"), "utf8")
9560
+ );
9561
+ graphs.set(dir, graph);
9562
+ return graph;
9563
+ };
9564
+ const localProducts = /* @__PURE__ */ new Map();
9565
+ for (const dir of localPackageDirs) {
9566
+ for (const product of graphOf(dir).products.keys()) localProducts.set(product, dir);
9567
+ }
9568
+ const localPackages = /* @__PURE__ */ new Set();
9569
+ const remoteProducts = [];
9570
+ const unresolvedProducts = [];
9571
+ for (const dependencyId of list(target.packageProductDependencies)) {
9572
+ const dependency = object(dependencyId);
9573
+ const product = str(dependency?.productName);
9574
+ if (!dependency || !product) continue;
9575
+ const reference = object(str(dependency.package));
9576
+ if (reference?.isa === "XCRemoteSwiftPackageReference") {
9577
+ remoteProducts.push({
9578
+ product,
9579
+ repositoryURL: str(reference.repositoryURL) ?? ""
9580
+ });
9581
+ } else if (reference?.isa === "XCLocalSwiftPackageReference") {
9582
+ localPackages.add(import_node_path14.default.resolve(projectDir, str(reference.relativePath) ?? ""));
9583
+ } else if (localProducts.has(product)) {
9584
+ localPackages.add(localProducts.get(product));
9585
+ } else unresolvedProducts.push(product);
9586
+ }
9587
+ const pending = [...localPackages];
9588
+ while (pending.length > 0) {
9589
+ const dir = pending.pop();
9590
+ const graph = graphOf(dir);
9591
+ for (const relative2 of graph.packagePaths) {
9592
+ const next = import_node_path14.default.resolve(dir, relative2);
9593
+ if (localPackages.has(next) || !import_node_fs14.default.existsSync(import_node_path14.default.join(next, "Package.swift")))
9594
+ continue;
9595
+ localPackages.add(next);
9596
+ pending.push(next);
9597
+ }
9598
+ for (const dependencies of graph.dependencies.values()) {
9599
+ for (const dependency of dependencies) {
9600
+ if (dependency.kind !== "product") continue;
9601
+ const url = graph.packageURLs.get(dependency.package);
9602
+ if (url && !remoteProducts.some((entry) => entry.product === dependency.name))
9603
+ remoteProducts.push({ product: dependency.name, repositoryURL: url });
9604
+ }
9605
+ }
9606
+ }
9607
+ const packageResolved = [
9608
+ import_node_path14.default.join(xcodeproj, "project.xcworkspace"),
9609
+ ...import_node_fs14.default.readdirSync(projectDir).filter((entry) => entry.endsWith(".xcworkspace")).map((entry) => import_node_path14.default.join(projectDir, entry))
9610
+ ].map(
9611
+ (workspace) => import_node_path14.default.join(workspace, "xcshareddata", "swiftpm", "Package.resolved")
9612
+ ).find((file) => import_node_fs14.default.existsSync(file)) ?? null;
9613
+ const swiftVersion = Number.parseFloat(settings.SWIFT_VERSION ?? "5");
9614
+ return {
9615
+ projectDir,
9616
+ pbxproj,
9617
+ name: name2,
9618
+ moduleName,
9619
+ sources: [...sources].sort(),
9620
+ resources: [...resources].sort(),
9621
+ infoPlist: import_plist3.default.build(info),
9622
+ infoPlistFile,
9623
+ languageMode: swiftVersion >= 6 ? 6 : 5,
9624
+ mainActorIsolation: settings.SWIFT_DEFAULT_ACTOR_ISOLATION === "MainActor",
9625
+ localPackages: [...localPackages].sort(),
9626
+ remoteProducts,
9627
+ packageResolved,
9628
+ unresolvedProducts,
9629
+ appTargets: appTargetNames
9630
+ };
9631
+ }
9632
+
8625
9633
  // src/swift-host.ts
8626
9634
  var ARTIFACT_PATH = "/__peach/swift/";
8627
9635
  var RESOURCE_PATH = "/__peach/swift-res/";
@@ -8637,17 +9645,17 @@ var SKIP_SOURCE_DIRS = /* @__PURE__ */ new Set([
8637
9645
  var NATIVE_DESCRIPTOR = ".one-native-source.json";
8638
9646
  var NATIVE_GLUE = ".one-native-source.swift.txt";
8639
9647
  function swiftPackageId(packagePath) {
8640
- return import_node_path13.default.basename(packagePath).replace(/[^A-Za-z0-9_]/g, "_").replace(/^(\d)/, "_$1");
9648
+ return import_node_path15.default.basename(packagePath).replace(/[^A-Za-z0-9_]/g, "_").replace(/^(\d)/, "_$1");
8641
9649
  }
8642
9650
  function nativeSourceDescriptor(packagePath) {
8643
- packagePath = import_node_fs13.default.realpathSync(packagePath);
8644
- const file = import_node_path13.default.join(packagePath, NATIVE_DESCRIPTOR);
8645
- if (!import_node_fs13.default.existsSync(file)) return null;
9651
+ packagePath = import_node_fs15.default.realpathSync(packagePath);
9652
+ const file = import_node_path15.default.join(packagePath, NATIVE_DESCRIPTOR);
9653
+ if (!import_node_fs15.default.existsSync(file)) return null;
8646
9654
  const value = JSON.parse(
8647
9655
  readPackageFile(packagePath, file, MAX_SWIFT_COMPILE_SOURCE_BYTES).toString("utf8")
8648
9656
  );
8649
9657
  const invalid = () => new Error(`${file}: invalid One native source descriptor; run one typegen`);
8650
- if (!value || typeof value !== "object" || Reflect.get(value, "generatedBy") !== "one typegen" || !import_node_fs13.default.existsSync(import_node_path13.default.join(packagePath, NATIVE_GLUE))) {
9658
+ if (!value || typeof value !== "object" || Reflect.get(value, "generatedBy") !== "one typegen" || !import_node_fs15.default.existsSync(import_node_path15.default.join(packagePath, NATIVE_GLUE))) {
8651
9659
  throw invalid();
8652
9660
  }
8653
9661
  if (!isSwiftNativeModules(value) || value.packageId !== swiftPackageId(packagePath)) {
@@ -8657,7 +9665,7 @@ function nativeSourceDescriptor(packagePath) {
8657
9665
  }
8658
9666
  var projects = /* @__PURE__ */ new Map();
8659
9667
  function projectFor(packagePath, hosted) {
8660
- packagePath = import_node_fs13.default.realpathSync(packagePath);
9668
+ packagePath = import_node_fs15.default.realpathSync(packagePath);
8661
9669
  const existing = projects.get(packagePath);
8662
9670
  if (existing) {
8663
9671
  if (hosted && !existing.hosted) {
@@ -8677,52 +9685,136 @@ function projectFor(packagePath, hosted) {
8677
9685
  projects.set(packagePath, created);
8678
9686
  return created;
8679
9687
  }
9688
+ var xcodeProjects = /* @__PURE__ */ new Map();
9689
+ function remotePackages(entry, app) {
9690
+ if (!entry.provided) return { targets: [], unavailable: /* @__PURE__ */ new Map() };
9691
+ const key = JSON.stringify([
9692
+ app.remoteProducts,
9693
+ app.packageResolved,
9694
+ app.packageResolved ? import_node_fs15.default.statSync(app.packageResolved).mtimeMs : 0
9695
+ ]);
9696
+ if (entry.remote?.key !== key) {
9697
+ entry.remote = {
9698
+ key,
9699
+ packages: resolveRemotePackages(
9700
+ import_node_fs15.default.realpathSync(app.projectDir),
9701
+ app.packageResolved,
9702
+ app.remoteProducts,
9703
+ entry.provided
9704
+ )
9705
+ };
9706
+ }
9707
+ return entry.remote.packages;
9708
+ }
9709
+ var XCODE_APP_DIR = "__app__";
9710
+ var XCODE_PACKAGES_DIR = "__packages__";
9711
+ var CHECKOUTS_PREFIX = `${REMOTE_CHECKOUTS.split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)}/`;
9712
+ function xcodeInputKey(appSources, file, relative2) {
9713
+ if (appSources.has(file)) return import_node_path15.default.posix.join(XCODE_APP_DIR, relative2);
9714
+ return relative2.startsWith(CHECKOUTS_PREFIX) ? import_node_path15.default.posix.join(XCODE_PACKAGES_DIR, relative2.slice(CHECKOUTS_PREFIX.length)) : relative2;
9715
+ }
9716
+ function xcodeLayout(root) {
9717
+ const registered = xcodeProjects.get(root);
9718
+ if (!registered) return null;
9719
+ const app = readXcodeAppTarget(registered.xcodeproj, registered.target);
9720
+ const files = /* @__PURE__ */ new Set([app.pbxproj, ...app.sources, ...app.resources]);
9721
+ if (app.infoPlistFile) files.add(app.infoPlistFile);
9722
+ const targets = [];
9723
+ for (const dir of app.localPackages) {
9724
+ const manifest = import_node_path15.default.join(dir, "Package.swift");
9725
+ files.add(manifest);
9726
+ const prefix = import_node_path15.default.relative(root, dir).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep);
9727
+ const all = packageFiles(dir).map(
9728
+ (file) => import_node_path15.default.relative(dir, file).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)
9729
+ );
9730
+ for (const target of swiftManifestTargets(import_node_fs15.default.readFileSync(manifest, "utf8"), all)) {
9731
+ if (target.executable) continue;
9732
+ targets.push({ ...target, path: import_node_path15.default.posix.join(prefix, target.path) });
9733
+ for (const relative2 of all) {
9734
+ if (relative2.startsWith(`${target.path}/`)) files.add(import_node_path15.default.join(dir, relative2));
9735
+ }
9736
+ }
9737
+ }
9738
+ const remote = remotePackages(registered, app);
9739
+ for (const target of remote.targets) {
9740
+ targets.push({
9741
+ ...target,
9742
+ path: import_node_path15.default.posix.join(
9743
+ XCODE_PACKAGES_DIR,
9744
+ import_node_path15.default.relative(import_node_path15.default.join(root, REMOTE_CHECKOUTS), target.dir).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)
9745
+ )
9746
+ });
9747
+ for (const file of target.files) files.add(file);
9748
+ }
9749
+ return {
9750
+ app,
9751
+ targets,
9752
+ unavailable: remote.unavailable,
9753
+ files: [...files].sort()
9754
+ };
9755
+ }
9756
+ function xcodeManifest(layout) {
9757
+ const settings = (mode, mainActor) => `swiftSettings: [.swiftLanguageMode(.v${mode})${mainActor ? ", .defaultIsolation(MainActor.self)" : ""}]`;
9758
+ return [
9759
+ "// swift-tools-version: 6.2",
9760
+ "import PackageDescription",
9761
+ 'let package = Package(name: "app", targets: [',
9762
+ ` .executableTarget(name: "${layout.app.moduleName}", path: "${XCODE_APP_DIR}", ${settings(layout.app.languageMode, layout.app.mainActorIsolation)}),`,
9763
+ ...layout.targets.map(
9764
+ (target) => ` .target(name: "${target.name}", path: "${target.path}", ${target.resources ? "resources: [], " : ""}${settings(target.languageMode, target.mainActorIsolation)}),`
9765
+ ),
9766
+ "])",
9767
+ ""
9768
+ ].join("\n");
9769
+ }
8680
9770
  function packageFiles(root) {
8681
- const canonicalRoot = import_node_fs13.default.realpathSync(root);
9771
+ const canonicalRoot = import_node_fs15.default.realpathSync(root);
9772
+ const xcode = xcodeLayout(canonicalRoot);
9773
+ if (xcode) return xcode.files;
8682
9774
  const found = [];
8683
- const walk = (dir) => {
8684
- for (const entry of import_node_fs13.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
9775
+ const walk2 = (dir) => {
9776
+ for (const entry of import_node_fs15.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
8685
9777
  if (entry.name.startsWith(".") && entry.name !== NATIVE_DESCRIPTOR && entry.name !== NATIVE_GLUE || SKIP_SOURCE_DIRS.has(entry.name))
8686
9778
  continue;
8687
- const full = import_node_path13.default.join(dir, entry.name);
9779
+ const full = import_node_path15.default.join(dir, entry.name);
8688
9780
  if (entry.isSymbolicLink()) throw new Error(`swift input is a symlink: ${full}`);
8689
- const real = import_node_fs13.default.realpathSync(full);
8690
- const relative2 = import_node_path13.default.relative(canonicalRoot, real);
8691
- if (relative2.startsWith(`..${import_node_path13.default.sep}`) || relative2 === ".." || import_node_path13.default.isAbsolute(relative2)) {
9781
+ const real = import_node_fs15.default.realpathSync(full);
9782
+ const relative2 = import_node_path15.default.relative(canonicalRoot, real);
9783
+ if (relative2.startsWith(`..${import_node_path15.default.sep}`) || relative2 === ".." || import_node_path15.default.isAbsolute(relative2)) {
8692
9784
  throw new Error(`swift input escapes the selected package: ${full}`);
8693
9785
  }
8694
9786
  if (entry.isDirectory()) {
8695
- if (import_node_fs13.default.existsSync(import_node_path13.default.join(full, "Package.swift"))) continue;
8696
- walk(full);
9787
+ if (import_node_fs15.default.existsSync(import_node_path15.default.join(full, "Package.swift"))) continue;
9788
+ walk2(full);
8697
9789
  } else if (entry.isFile()) {
8698
9790
  found.push(full);
8699
9791
  if (found.length > 4096) throw new Error("swift package exceeds 4096 input files");
8700
9792
  }
8701
9793
  }
8702
9794
  };
8703
- walk(canonicalRoot);
9795
+ walk2(canonicalRoot);
8704
9796
  return found;
8705
9797
  }
8706
9798
  function readPackageFile(root, file, maxBytes) {
8707
- const canonicalRoot = import_node_fs13.default.realpathSync(root);
8708
- const relative2 = import_node_path13.default.relative(canonicalRoot, import_node_fs13.default.realpathSync(file));
8709
- if (relative2 === ".." || relative2.startsWith(`..${import_node_path13.default.sep}`) || import_node_path13.default.isAbsolute(relative2)) {
9799
+ const canonicalRoot = import_node_fs15.default.realpathSync(root);
9800
+ const relative2 = import_node_path15.default.relative(canonicalRoot, import_node_fs15.default.realpathSync(file));
9801
+ if (relative2 === ".." || relative2.startsWith(`..${import_node_path15.default.sep}`) || import_node_path15.default.isAbsolute(relative2)) {
8710
9802
  throw new Error(`swift input escapes the selected package: ${file}`);
8711
9803
  }
8712
- let ancestor = import_node_path13.default.resolve(file);
9804
+ let ancestor = import_node_path15.default.resolve(file);
8713
9805
  while (ancestor !== canonicalRoot) {
8714
- if (import_node_fs13.default.lstatSync(ancestor).isSymbolicLink()) {
9806
+ if (import_node_fs15.default.lstatSync(ancestor).isSymbolicLink()) {
8715
9807
  throw new Error(`swift input is a symlink: ${ancestor}`);
8716
9808
  }
8717
- const parent = import_node_path13.default.dirname(ancestor);
9809
+ const parent = import_node_path15.default.dirname(ancestor);
8718
9810
  if (parent === ancestor)
8719
9811
  throw new Error(`swift input escapes the selected package: ${file}`);
8720
9812
  ancestor = parent;
8721
9813
  }
8722
- const expected = import_node_fs13.default.statSync(file);
8723
- const fd = import_node_fs13.default.openSync(file, import_node_fs13.default.constants.O_RDONLY | import_node_fs13.default.constants.O_NOFOLLOW);
9814
+ const expected = import_node_fs15.default.statSync(file);
9815
+ const fd = import_node_fs15.default.openSync(file, import_node_fs15.default.constants.O_RDONLY | import_node_fs15.default.constants.O_NOFOLLOW);
8724
9816
  try {
8725
- const stat2 = import_node_fs13.default.fstatSync(fd);
9817
+ const stat2 = import_node_fs15.default.fstatSync(fd);
8726
9818
  if (stat2.dev !== expected.dev || stat2.ino !== expected.ino) {
8727
9819
  throw new Error(`swift input changed while opening: ${file}`);
8728
9820
  }
@@ -8732,28 +9824,43 @@ function readPackageFile(root, file, maxBytes) {
8732
9824
  const bytes = Buffer.alloc(stat2.size + 1);
8733
9825
  let offset = 0;
8734
9826
  while (offset < bytes.length) {
8735
- const count = import_node_fs13.default.readSync(fd, bytes, offset, bytes.length - offset, null);
9827
+ const count = import_node_fs15.default.readSync(fd, bytes, offset, bytes.length - offset, null);
8736
9828
  if (count === 0) break;
8737
9829
  offset += count;
8738
9830
  }
8739
- if (offset !== stat2.size || import_node_fs13.default.fstatSync(fd).size !== stat2.size) {
9831
+ if (offset !== stat2.size || import_node_fs15.default.fstatSync(fd).size !== stat2.size) {
8740
9832
  throw new Error(`swift input changed while reading: ${file}`);
8741
9833
  }
8742
9834
  return bytes.subarray(0, offset);
8743
9835
  } finally {
8744
- import_node_fs13.default.closeSync(fd);
9836
+ import_node_fs15.default.closeSync(fd);
8745
9837
  }
8746
9838
  }
8747
9839
  function sourceFiles(root) {
8748
- const files = packageFiles(root).filter((file) => file.endsWith(".swift"));
8749
- if (files.length > MAX_SWIFT_COMPILE_FILES || files.reduce((total, file) => total + import_node_fs13.default.statSync(file).size, 0) > MAX_SWIFT_COMPILE_SOURCE_BYTES) {
8750
- throw new Error("swift sources exceed the compile service caps");
8751
- }
8752
- return files;
9840
+ return packageFiles(root).filter((file) => file.endsWith(".swift"));
8753
9841
  }
8754
9842
  function resourceCandidateFiles(root) {
8755
- return packageFiles(root).filter((file) => !file.endsWith(".swift"));
9843
+ return packageFiles(root).filter(
9844
+ (file) => !file.endsWith(".swift") && import_node_path15.default.basename(file) !== "project.pbxproj"
9845
+ );
8756
9846
  }
9847
+ var HOSTED_LIMITS = {
9848
+ resources: MAX_SWIFT_COMPILE_RESOURCES,
9849
+ resourceBytes: MAX_SWIFT_COMPILE_RESOURCE_BYTES,
9850
+ resourceTotalBytes: MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES,
9851
+ images: MAX_SWIFT_COMPILE_IMAGES,
9852
+ imageBytes: MAX_SWIFT_COMPILE_IMAGE_BYTES,
9853
+ imageTotalBytes: MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES
9854
+ };
9855
+ var LOCAL_LIMITS = {
9856
+ resources: Infinity,
9857
+ resourceBytes: Infinity,
9858
+ resourceTotalBytes: Infinity,
9859
+ images: Infinity,
9860
+ imageBytes: Infinity,
9861
+ imageTotalBytes: Infinity
9862
+ };
9863
+ var inputLimits = (hosted) => hosted ? HOSTED_LIMITS : LOCAL_LIMITS;
8757
9864
  var RESOURCE_CONTENT_TYPES = {
8758
9865
  ".avif": "image/avif",
8759
9866
  ".bmp": "image/bmp",
@@ -8765,20 +9872,19 @@ var RESOURCE_CONTENT_TYPES = {
8765
9872
  ".webp": "image/webp"
8766
9873
  };
8767
9874
  function buildSwiftResourceTable(project, baseUrl) {
9875
+ const limits = inputLimits(Boolean(project.hosted));
8768
9876
  const absolute = resourceCandidateFiles(project.packagePath);
8769
9877
  const relative2 = absolute.map(
8770
- (file) => import_node_path13.default.relative(project.packagePath, file).split(import_node_path13.default.sep).join(import_node_path13.default.posix.sep)
9878
+ (file) => import_node_path15.default.relative(project.packagePath, file).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)
8771
9879
  );
8772
9880
  const byRelative = new Map(absolute.map((file, index) => [relative2[index], file]));
8773
9881
  const readContents = (candidate) => {
8774
9882
  const file = byRelative.get(candidate);
8775
9883
  if (!file || !/(^|\/)Contents\.json$|\.symbolset\/[^/]+\.svg$/.test(candidate))
8776
9884
  return null;
8777
- return readPackageFile(
8778
- project.packagePath,
8779
- file,
8780
- MAX_SWIFT_COMPILE_RESOURCE_BYTES
8781
- ).toString("utf8");
9885
+ return readPackageFile(project.packagePath, file, limits.resourceBytes).toString(
9886
+ "utf8"
9887
+ );
8782
9888
  };
8783
9889
  const found = enumerateBundleImages(relative2, readContents);
8784
9890
  const colors = enumerateBundleColors(relative2, readContents);
@@ -8791,20 +9897,16 @@ function buildSwiftResourceTable(project, baseUrl) {
8791
9897
  for (const { name: name2, file, scale } of found) {
8792
9898
  const disk = byRelative.get(file);
8793
9899
  if (!disk) continue;
8794
- if (Object.keys(images).length >= MAX_SWIFT_COMPILE_IMAGES || imageBytes + import_node_fs13.default.statSync(disk).size > MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES) {
9900
+ if (Object.keys(images).length >= limits.images || imageBytes + import_node_fs15.default.statSync(disk).size > limits.imageTotalBytes) {
8795
9901
  throw new Error("swift image pack exceeds the compile service caps");
8796
9902
  }
8797
- const bytes = readPackageFile(
8798
- project.packagePath,
8799
- disk,
8800
- MAX_SWIFT_COMPILE_IMAGE_BYTES
8801
- );
9903
+ const bytes = readPackageFile(project.packagePath, disk, limits.imageBytes);
8802
9904
  imageBytes += bytes.length;
8803
9905
  const hash = (0, import_node_crypto5.createHash)("sha256").update(bytes).digest("hex").slice(0, 16);
8804
- const ext = import_node_path13.default.posix.extname(file).toLowerCase();
9906
+ const ext = import_node_path15.default.posix.extname(file).toLowerCase();
8805
9907
  table[name2] = { uri: `${baseUrl}${RESOURCE_PATH}${hash}${ext}`, scale };
8806
9908
  images[name2] = {
8807
- file: import_node_path13.default.posix.basename(file),
9909
+ file: import_node_path15.default.posix.basename(file),
8808
9910
  data: bytes.toString("base64")
8809
9911
  };
8810
9912
  watched.push(file);
@@ -8827,26 +9929,36 @@ function buildSwiftResourceTable(project, baseUrl) {
8827
9929
  }
8828
9930
  return { table, images, colors, symbols, watched };
8829
9931
  }
8830
- var BUNDLE_MAX_FILES = MAX_SWIFT_COMPILE_RESOURCES;
8831
- var BUNDLE_MAX_FILE_BYTES = MAX_SWIFT_COMPILE_RESOURCE_BYTES;
8832
- var BUNDLE_MAX_TOTAL_BYTES = MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES;
8833
- function buildSwiftBundleFiles(packagePath) {
8834
- packagePath = import_node_fs13.default.realpathSync(packagePath);
9932
+ function buildSwiftBundleFiles(packagePath, hosted) {
9933
+ packagePath = import_node_fs15.default.realpathSync(packagePath);
9934
+ const limits = inputLimits(hosted);
8835
9935
  const relative2 = resourceCandidateFiles(packagePath).map(
8836
- (file) => import_node_path13.default.relative(packagePath, file).split(import_node_path13.default.sep).join(import_node_path13.default.posix.sep)
9936
+ (file) => import_node_path15.default.relative(packagePath, file).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)
8837
9937
  );
8838
9938
  const files = {};
8839
9939
  const watched = [];
8840
9940
  let total = 0;
9941
+ const xcode = xcodeLayout(packagePath);
9942
+ if (xcode) {
9943
+ const bytes = Buffer.from(xcode.app.infoPlist);
9944
+ if (bytes.length > limits.resourceBytes || bytes.length > limits.resourceTotalBytes)
9945
+ throw new Error("swift launch Info.plist exceeds bundle resource limits");
9946
+ files["Info.plist"] = bytes.toString("base64");
9947
+ total += bytes.length;
9948
+ if (xcode.app.infoPlistFile)
9949
+ watched.push(
9950
+ import_node_path15.default.relative(packagePath, xcode.app.infoPlistFile).split(import_node_path15.default.sep).join("/")
9951
+ );
9952
+ }
8841
9953
  for (const { base, file } of enumerateBundleJson(relative2)) {
8842
9954
  watched.push(file);
8843
- const disk = import_node_path13.default.join(packagePath, ...file.split("/"));
8844
- if (Object.keys(files).length >= BUNDLE_MAX_FILES || total + import_node_fs13.default.statSync(disk).size > BUNDLE_MAX_TOTAL_BYTES) {
9955
+ const disk = import_node_path15.default.join(packagePath, ...file.split("/"));
9956
+ if (Object.keys(files).length >= limits.resources || total + import_node_fs15.default.statSync(disk).size > limits.resourceTotalBytes) {
8845
9957
  throw new Error(
8846
- `swift bundle pack exceeds ${BUNDLE_MAX_FILES} files / ${BUNDLE_MAX_TOTAL_BYTES} bytes`
9958
+ `swift bundle pack exceeds ${limits.resources} files / ${limits.resourceTotalBytes} bytes`
8847
9959
  );
8848
9960
  }
8849
- const bytes = readPackageFile(packagePath, disk, BUNDLE_MAX_FILE_BYTES);
9961
+ const bytes = readPackageFile(packagePath, disk, limits.resourceBytes);
8850
9962
  files[base] = bytes.toString("base64");
8851
9963
  total += bytes.length;
8852
9964
  }
@@ -8856,12 +9968,12 @@ function serveSwiftResource(project, key) {
8856
9968
  return project.resourceFiles.get(key) ?? project.resourcesPrevious.get(key) ?? null;
8857
9969
  }
8858
9970
  function linkedModuleRoots(packagePath) {
8859
- packagePath = import_node_fs13.default.realpathSync(packagePath);
9971
+ packagePath = import_node_fs15.default.realpathSync(packagePath);
8860
9972
  let manifest;
8861
9973
  try {
8862
9974
  manifest = readPackageFile(
8863
9975
  packagePath,
8864
- import_node_path13.default.join(packagePath, "Package.swift"),
9976
+ import_node_path15.default.join(packagePath, "Package.swift"),
8865
9977
  MAX_SWIFT_COMPILE_SOURCE_BYTES
8866
9978
  ).toString("utf8");
8867
9979
  } catch {
@@ -8870,8 +9982,8 @@ function linkedModuleRoots(packagePath) {
8870
9982
  const roots = /* @__PURE__ */ new Set();
8871
9983
  const dependency = /\.package\(\s*path:\s*"([^"]+)"\s*\)/g;
8872
9984
  for (const match of manifest.replace(/^\s*\/\/.*$/gm, "").matchAll(dependency)) {
8873
- const root = import_node_path13.default.resolve(packagePath, match[1]);
8874
- if (import_node_fs13.default.existsSync(import_node_path13.default.join(root, "Package.swift"))) roots.add(root);
9985
+ const root = import_node_path15.default.resolve(packagePath, match[1]);
9986
+ if (import_node_fs15.default.existsSync(import_node_path15.default.join(root, "Package.swift"))) roots.add(root);
8875
9987
  }
8876
9988
  return [...roots].sort();
8877
9989
  }
@@ -8880,18 +9992,18 @@ function sourceStamp(packagePath, moduleRootOverride, hosted = false) {
8880
9992
  hash.update(packagePath);
8881
9993
  const projectInputs = new Set(packageFiles(packagePath));
8882
9994
  for (const file of [...projectInputs].sort()) {
8883
- hash.update(import_node_path13.default.relative(packagePath, file));
8884
- const stat2 = import_node_fs13.default.statSync(file);
9995
+ hash.update(import_node_path15.default.relative(packagePath, file));
9996
+ const stat2 = import_node_fs15.default.statSync(file);
8885
9997
  hash.update(`${stat2.mtimeMs}/${stat2.ctimeMs}/${stat2.size}`);
8886
9998
  }
8887
9999
  const moduleRoot = hosted ? void 0 : moduleRootOverride ?? linkedModuleRoots(packagePath).find(
8888
- (root) => import_node_fs13.default.existsSync(import_node_path13.default.join(root, "toolchain.json"))
10000
+ (root) => import_node_fs15.default.existsSync(import_node_path15.default.join(root, "toolchain.json"))
8889
10001
  );
8890
10002
  if (moduleRoot) {
8891
10003
  hash.update(moduleRoot);
8892
10004
  for (const relative2 of swiftModuleInputFiles(moduleRoot)) {
8893
10005
  hash.update(relative2);
8894
- hash.update(String(import_node_fs13.default.statSync(import_node_path13.default.join(moduleRoot, relative2)).mtimeMs));
10006
+ hash.update(String(import_node_fs15.default.statSync(import_node_path15.default.join(moduleRoot, relative2)).mtimeMs));
8895
10007
  }
8896
10008
  }
8897
10009
  return hash.digest("hex").slice(0, 16);
@@ -8900,22 +10012,19 @@ function icuUrl(origin, artifact) {
8900
10012
  return "url" in artifact.icu ? artifact.icu.url : `${origin}${ICU_PATH}${artifact.icu.sha256}`;
8901
10013
  }
8902
10014
  function packageSources(packagePath) {
8903
- const sources = sourceFiles(packagePath);
8904
- if (sources.length > MAX_SWIFT_COMPILE_FILES)
8905
- throw new Error("swift source file cap exceeded");
8906
- let total = 0;
8907
- for (const file of sources) total += import_node_fs13.default.statSync(file).size;
8908
- if (total > MAX_SWIFT_COMPILE_SOURCE_BYTES)
8909
- throw new Error("swift source byte cap exceeded");
10015
+ const xcode = xcodeLayout(packagePath);
10016
+ const appSources = new Set(xcode?.app.sources);
8910
10017
  const files = {};
8911
- for (const file of sources) {
8912
- const relative2 = import_node_path13.default.relative(packagePath, file).split(import_node_path13.default.sep).join(import_node_path13.default.posix.sep);
8913
- files[relative2] = readPackageFile(
10018
+ for (const file of sourceFiles(packagePath)) {
10019
+ const relative2 = import_node_path15.default.relative(packagePath, file).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep);
10020
+ if (xcode && import_node_path15.default.basename(file) === "Package.swift") continue;
10021
+ files[xcode ? xcodeInputKey(appSources, file, relative2) : relative2] = readPackageFile(
8914
10022
  packagePath,
8915
10023
  file,
8916
10024
  MAX_SWIFT_COMPILE_SOURCE_BYTES
8917
10025
  ).toString("utf8");
8918
10026
  }
10027
+ if (xcode) files["Package.swift"] = xcodeManifest(xcode);
8919
10028
  return files;
8920
10029
  }
8921
10030
  function packageSnapshot(project) {
@@ -8925,16 +10034,16 @@ function packageSnapshot(project) {
8925
10034
  files,
8926
10035
  resourcePaths: swiftImplicitResourcePaths(
8927
10036
  resourceCandidateFiles(project.packagePath).map(
8928
- (file) => import_node_path13.default.relative(project.packagePath, file).split(import_node_path13.default.sep).join(import_node_path13.default.posix.sep)
10037
+ (file) => import_node_path15.default.relative(project.packagePath, file).split(import_node_path15.default.sep).join(import_node_path15.default.posix.sep)
8929
10038
  )
8930
10039
  ),
8931
10040
  resources: buildSwiftResourceTable(project, ""),
8932
- bundleFiles: buildSwiftBundleFiles(project.packagePath),
10041
+ bundleFiles: buildSwiftBundleFiles(project.packagePath, Boolean(project.hosted)),
8933
10042
  native,
8934
10043
  ...native ? {
8935
10044
  glue: readPackageFile(
8936
10045
  project.packagePath,
8937
- import_node_path13.default.join(project.packagePath, NATIVE_GLUE),
10046
+ import_node_path15.default.join(project.packagePath, NATIVE_GLUE),
8938
10047
  MAX_SWIFT_COMPILE_SOURCE_BYTES
8939
10048
  ).toString("utf8")
8940
10049
  } : {}
@@ -8970,7 +10079,7 @@ async function compile(packagePath, entry, stamp, moduleRootOverride, hosted, sn
8970
10079
  package: content
8971
10080
  };
8972
10081
  const moduleRoot = moduleRootOverride ?? linkedModuleRoots(packagePath).find(
8973
- (root) => import_node_fs13.default.existsSync(import_node_path13.default.join(root, "toolchain.json"))
10082
+ (root) => import_node_fs15.default.existsSync(import_node_path15.default.join(root, "toolchain.json"))
8974
10083
  ) ?? await swiftDistributionRoot();
8975
10084
  if (!moduleRoot)
8976
10085
  return {
@@ -8979,27 +10088,112 @@ async function compile(packagePath, entry, stamp, moduleRootOverride, hosted, sn
8979
10088
  package: content
8980
10089
  };
8981
10090
  const toolchain = swiftModuleToolchain(moduleRoot);
8982
- const artifact = await compileSwiftProjectUnit(snapshotCompileInput(snapshot, entry), {
10091
+ const input = snapshotCompileInput(snapshot, entry);
10092
+ const targets = compileTargets(input).map((target) => target.name);
10093
+ const missing = missingSwiftModules(
10094
+ input.files,
10095
+ /* @__PURE__ */ new Set([
10096
+ ...swiftAvailableModules(moduleRoot, toolchain.toolchainBin),
10097
+ // a project without a manifest compiles as the template's one App target
10098
+ ...targets.length > 0 ? targets : ["App"]
10099
+ ])
10100
+ );
10101
+ if (missing.size > 0) throw new Error(missingModulesMessage(packagePath, missing));
10102
+ const artifact = await compileSwiftProjectUnit(input, {
8983
10103
  // the compile rewrites Sources/App in its root before swiftpm builds, and
8984
10104
  // its lock orders one process only: two vites on one root (a lane's dev
8985
10105
  // server and a capture, or two checkouts) build each other's sources. so
8986
10106
  // each app and module checkout gets its own root, which keeps the same
8987
10107
  // app's incremental build across restarts.
8988
- buildRoot: process.env.CONTRAST_SWIFT_BUILD_ROOT ?? import_node_path13.default.join(
10108
+ buildRoot: process.env.CONTRAST_SWIFT_BUILD_ROOT ?? import_node_path15.default.join(
8989
10109
  import_node_os5.default.tmpdir(),
8990
10110
  "contrast-swift-build",
8991
- (0, import_node_crypto5.createHash)("sha256").update(`${moduleRoot}\0${import_node_path13.default.resolve(packagePath)}`).digest("hex").slice(0, 16)
10111
+ (0, import_node_crypto5.createHash)("sha256").update(`${moduleRoot}\0${import_node_path15.default.resolve(packagePath)}`).digest("hex").slice(0, 16)
8992
10112
  ),
8993
10113
  moduleRoot,
8994
10114
  ...toolchain
10115
+ }).catch((error) => {
10116
+ const report = error instanceof Error ? swiftApiGapReport(error.message) : null;
10117
+ throw report ? new Error(`${error instanceof Error ? error.message : ""}
10118
+
10119
+ ${report}`, {
10120
+ cause: error
10121
+ }) : error;
8995
10122
  });
8996
10123
  return { ...artifact, stamp, package: content };
8997
10124
  }
10125
+ var API_GAP_PATTERNS = [
10126
+ [/^cannot find (?:type )?'([^']+)' in scope/, (match) => match[1]],
10127
+ // a typealias reports its aliased type after `aka`, which is the api's owner
10128
+ [
10129
+ /^(?:value of )?type '([^']+)'(?: \(aka '([^']+)'\))? has no member '([^']+)'/,
10130
+ (match) => `${(match[2] ?? match[1]).replace(/^Optional<(.+)>$/, "$1").replace(/\?$/, "")}.${match[3]}`
10131
+ ],
10132
+ [
10133
+ /^module '([^']+)' has no member named '([^']+)'/,
10134
+ (match) => `${match[1]}.${match[2]}`
10135
+ ],
10136
+ [/^'([^']+)' is unavailable/, (match) => match[1]],
10137
+ [/^no such module '([^']+)'/, (match) => `module ${match[1]}`]
10138
+ ];
10139
+ function swiftApiGapReport(output) {
10140
+ const gaps = /* @__PURE__ */ new Map();
10141
+ const other = /* @__PURE__ */ new Map();
10142
+ const seen = /* @__PURE__ */ new Set();
10143
+ for (const line of output.split("\n")) {
10144
+ const diagnostic = /^(\S[^:]*\.swift):(\d+):(\d+): error: (.+)$/.exec(line);
10145
+ if (!diagnostic || seen.has(line)) continue;
10146
+ seen.add(line);
10147
+ const file = diagnostic[1].replace(new RegExp(`^${XCODE_APP_DIR}/`), "").replace(new RegExp(`^${XCODE_PACKAGES_DIR}/`), "");
10148
+ const message = diagnostic[4];
10149
+ const rule = API_GAP_PATTERNS.find(([pattern]) => pattern.test(message));
10150
+ const key = rule ? rule[1](rule[0].exec(message)) : message;
10151
+ const table = rule ? gaps : other;
10152
+ const entry = table.get(key) ?? { errors: 0, files: /* @__PURE__ */ new Set() };
10153
+ entry.errors++;
10154
+ entry.files.add(file);
10155
+ table.set(key, entry);
10156
+ }
10157
+ if (gaps.size === 0) return null;
10158
+ const rows = (table) => {
10159
+ const sorted = [...table].sort(
10160
+ ([left, a], [right, b]) => b.errors - a.errors || left.localeCompare(right)
10161
+ );
10162
+ const width = Math.min(48, Math.max(...sorted.map(([key]) => key.length)));
10163
+ return sorted.map(
10164
+ ([key, entry]) => ` ${key.padEnd(width)} ${String(entry.errors).padStart(3)} error${entry.errors === 1 ? " " : "s"} ${[...entry.files].sort().join(", ")}`
10165
+ );
10166
+ };
10167
+ const errors = [...gaps.values()].reduce((sum, entry) => sum + entry.errors, 0);
10168
+ return [
10169
+ `Peach lacks ${gaps.size} API${gaps.size === 1 ? "" : "s"} this app uses (${errors} error${errors === 1 ? "" : "s"}):`,
10170
+ ...rows(gaps),
10171
+ ...other.size > 0 ? ["other errors, often caused by the ones above:", ...rows(other)] : []
10172
+ ].join("\n");
10173
+ }
10174
+ function missingModulesMessage(packagePath, missing) {
10175
+ const layout = xcodeLayout(packagePath);
10176
+ const remote = new Map(
10177
+ (layout?.app.remoteProducts ?? []).map((entry) => [
10178
+ entry.product,
10179
+ entry.repositoryURL
10180
+ ])
10181
+ );
10182
+ const width = Math.max(...[...missing.keys()].map((name2) => name2.length));
10183
+ return [
10184
+ `Peach does not provide ${missing.size} module${missing.size === 1 ? "" : "s"} this app imports:`,
10185
+ ...[...missing].map(([name2, files]) => {
10186
+ const source = remote.get(name2);
10187
+ const reason = layout?.unavailable.get(name2)?.reason;
10188
+ return ` ${name2.padEnd(width)} ${files.length} file${files.length === 1 ? "" : "s"}${source ? `, package ${source}` : ""}${reason ? ` (${reason})` : ""}`;
10189
+ })
10190
+ ].join("\n");
10191
+ }
8998
10192
  async function compileRemote(packagePath, entry, snapshot, hosted) {
8999
10193
  const auth = hosted ? null : resolveCliAuth();
9000
10194
  if (!hosted && (!auth || auth.kind === "github")) {
9001
10195
  throw new Error(
9002
- `compiling ${import_node_path13.default.basename(packagePath)} for Peach needs \`peach login\` or PEACH_API_KEY: this peachsim has no local SwiftUI module, so Contrast compiles it`
10196
+ `compiling ${import_node_path15.default.basename(packagePath)} for Peach needs \`peach login\` or PEACH_API_KEY: this peachsim has no local SwiftUI module, so Contrast compiles it`
9003
10197
  );
9004
10198
  }
9005
10199
  const origin = hosted?.origin ?? resolveContrastBackendOrigin(auth?.kind === "session" ? auth.origin : null);
@@ -9014,6 +10208,13 @@ async function compileRemote(packagePath, entry, snapshot, hosted) {
9014
10208
  signal
9015
10209
  });
9016
10210
  if (!submit) throw new Error("swift compile: no credential to submit with");
10211
+ const sources = Object.values(snapshot.files);
10212
+ const bytes = sources.reduce((total2, text) => total2 + Buffer.byteLength(text), 0);
10213
+ if (sources.length > MAX_SWIFT_COMPILE_FILES || bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES) {
10214
+ throw new Error(
10215
+ `${import_node_path15.default.basename(packagePath)} has ${sources.length} Swift files (${bytes} bytes), over Contrast's compile limits of ${MAX_SWIFT_COMPILE_FILES} files and ${MAX_SWIFT_COMPILE_SOURCE_BYTES} bytes; compile it on this machine with the Swift distribution instead`
10216
+ );
10217
+ }
9017
10218
  const descriptor = snapshot.native;
9018
10219
  const address = await compileSwiftProject(
9019
10220
  submit,
@@ -9030,7 +10231,7 @@ async function compileRemote(packagePath, entry, snapshot, hosted) {
9030
10231
  );
9031
10232
  if (descriptor && address.native?.hash !== descriptor.hash) {
9032
10233
  throw new Error(
9033
- `${import_node_path13.default.basename(packagePath)}: Contrast compiled native contract ${address.native?.hash ?? "none"} but one typegen wrote ${descriptor.hash}; the app's One and the compile host's differ, or the compile host is older than this peachsim`
10234
+ `${import_node_path15.default.basename(packagePath)}: Contrast compiled native contract ${address.native?.hash ?? "none"} but one typegen wrote ${descriptor.hash}; the app's One and the compile host's differ, or the compile host is older than this peachsim`
9034
10235
  );
9035
10236
  }
9036
10237
  const response = await fetch(address.url, { signal });
@@ -9149,13 +10350,13 @@ function serveSwiftPackageAsset(pathname, res) {
9149
10350
  }
9150
10351
 
9151
10352
  // src/expo-swift-host.ts
9152
- var run3 = (0, import_node_util3.promisify)(import_node_child_process6.execFile);
10353
+ var run3 = (0, import_node_util3.promisify)(import_node_child_process7.execFile);
9153
10354
  var scriptEnv = { ...process.env, [RNX_FORKED_SCRIPT_ENV]: "1" };
9154
10355
  var EXPO_SWIFT_ROUTE = "/__peach/expo-swift";
9155
10356
  var EXPO_SWIFT_ENTRY = "Sources/PeachExpoApp/PeachExpoEntry.swift";
9156
10357
  async function collectExpoSwiftSources(appRoot) {
9157
- appRoot = import_node_fs14.default.realpathSync(appRoot);
9158
- const appRequire = (0, import_node_module.createRequire)(import_node_path14.default.join(appRoot, "package.json"));
10358
+ appRoot = import_node_fs16.default.realpathSync(appRoot);
10359
+ const appRequire = (0, import_node_module.createRequire)(import_node_path16.default.join(appRoot, "package.json"));
9159
10360
  let autolinker;
9160
10361
  try {
9161
10362
  autolinker = appRequire.resolve("expo-modules-autolinking/package.json");
@@ -9169,7 +10370,7 @@ async function collectExpoSwiftSources(appRoot) {
9169
10370
  (command) => run3(
9170
10371
  process.execPath,
9171
10372
  [
9172
- import_node_path14.default.join(import_node_path14.default.dirname(autolinker), "bin/expo-modules-autolinking.js"),
10373
+ import_node_path16.default.join(import_node_path16.default.dirname(autolinker), "bin/expo-modules-autolinking.js"),
9173
10374
  command,
9174
10375
  "--platform",
9175
10376
  "apple",
@@ -9200,8 +10401,8 @@ async function collectExpoSwiftSources(appRoot) {
9200
10401
  const sourceRoot = Reflect.get(entry, "path");
9201
10402
  if (typeof sourceRoot !== "string")
9202
10403
  throw new Error("Expo autolinking entry has no path");
9203
- const canonical = import_node_fs14.default.realpathSync(sourceRoot);
9204
- if (canonical.split(import_node_path14.default.sep).includes("node_modules")) continue;
10404
+ const canonical = import_node_fs16.default.realpathSync(sourceRoot);
10405
+ if (canonical.split(import_node_path16.default.sep).includes("node_modules")) continue;
9205
10406
  const resolution = resolutions.find(
9206
10407
  (candidate) => candidate && typeof candidate === "object" && Reflect.get(candidate, "packageName") === Reflect.get(entry, "name")
9207
10408
  );
@@ -9227,29 +10428,29 @@ async function collectExpoSwiftSources(appRoot) {
9227
10428
  `(${className.includes(".") ? className : `${namespace}.${className}`}.self, ${name2 === null ? "nil" : JSON.stringify(name2)})`
9228
10429
  );
9229
10430
  }
9230
- const ios = import_node_path14.default.join(canonical, "ios");
9231
- if (import_node_fs14.default.lstatSync(ios).isSymbolicLink())
10431
+ const ios = import_node_path16.default.join(canonical, "ios");
10432
+ if (import_node_fs16.default.lstatSync(ios).isSymbolicLink())
9232
10433
  throw new Error(`Expo Swift source directory is a symlink: ${ios}`);
9233
- const walk = (dir) => {
9234
- for (const child of import_node_fs14.default.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
9235
- const file = import_node_path14.default.join(dir, child.name);
10434
+ const walk2 = (dir) => {
10435
+ for (const child of import_node_fs16.default.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
10436
+ const file = import_node_path16.default.join(dir, child.name);
9236
10437
  if (child.isSymbolicLink())
9237
10438
  throw new Error(`Expo Swift source is a symlink: ${file}`);
9238
10439
  if (child.isDirectory()) {
9239
- if (!child.name.startsWith(".") && child.name !== "build") walk(file);
10440
+ if (!child.name.startsWith(".") && child.name !== "build") walk2(file);
9240
10441
  continue;
9241
10442
  }
9242
10443
  if (!child.name.endsWith(".swift")) continue;
9243
- const size = import_node_fs14.default.statSync(file).size;
10444
+ const size = import_node_fs16.default.statSync(file).size;
9244
10445
  bytes += size;
9245
10446
  fileCount++;
9246
10447
  if (fileCount > MAX_SWIFT_COMPILE_FILES - 2 || bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES)
9247
10448
  throw new Error("Expo Swift sources exceed compile service caps");
9248
- files[`Sources/${namespace}/${import_node_path14.default.relative(ios, file).split(import_node_path14.default.sep).join("/")}`] = `#sourceLocation(file: ${JSON.stringify(file)}, line: 1)
9249
- ${import_node_fs14.default.readFileSync(file, "utf8")}`;
10449
+ files[`Sources/${namespace}/${import_node_path16.default.relative(ios, file).split(import_node_path16.default.sep).join("/")}`] = `#sourceLocation(file: ${JSON.stringify(file)}, line: 1)
10450
+ ${import_node_fs16.default.readFileSync(file, "utf8")}`;
9250
10451
  }
9251
10452
  };
9252
- walk(ios);
10453
+ walk2(ios);
9253
10454
  const unit = { namespace, classes, files };
9254
10455
  files[EXPO_SWIFT_ENTRY] = expoEntry([unit]);
9255
10456
  units.push(unit);
@@ -9331,7 +10532,7 @@ async function handleExpoSwiftRequest(req, res) {
9331
10532
  return true;
9332
10533
  }
9333
10534
  const root = url.searchParams.get("root");
9334
- if (!root || !import_node_path14.default.isAbsolute(root)) {
10535
+ if (!root || !import_node_path16.default.isAbsolute(root)) {
9335
10536
  res.writeHead(400);
9336
10537
  res.end("missing absolute app root");
9337
10538
  return true;
@@ -9348,7 +10549,7 @@ async function handleExpoSwiftRequest(req, res) {
9348
10549
  modules: [],
9349
10550
  failures: []
9350
10551
  };
9351
- const key = (0, import_node_crypto6.createHash)("sha256").update(import_node_fs14.default.realpathSync(root)).digest("hex");
10552
+ const key = (0, import_node_crypto6.createHash)("sha256").update(import_node_fs16.default.realpathSync(root)).digest("hex");
9352
10553
  const host2 = req.headers.host;
9353
10554
  if (!host2) throw new Error("Expo Swift request has no host");
9354
10555
  const base = `http://${host2}`;
@@ -9362,7 +10563,7 @@ async function handleExpoSwiftRequest(req, res) {
9362
10563
  continue;
9363
10564
  }
9364
10565
  try {
9365
- const packagePath = import_node_path14.default.join(
10566
+ const packagePath = import_node_path16.default.join(
9366
10567
  import_node_os6.default.tmpdir(),
9367
10568
  "peach-expo-swift",
9368
10569
  key,
@@ -9372,7 +10573,7 @@ async function handleExpoSwiftRequest(req, res) {
9372
10573
  packagePath,
9373
10574
  new Map(
9374
10575
  Object.entries(unit.files).map(([name2, source]) => [
9375
- import_node_path14.default.join(packagePath, name2),
10576
+ import_node_path16.default.join(packagePath, name2),
9376
10577
  source
9377
10578
  ])
9378
10579
  )
@@ -9423,7 +10624,7 @@ async function handleExpoSwiftRequest(req, res) {
9423
10624
  import PackageDescription
9424
10625
  let package = Package(name: "PeachExpo", targets: [${targets.map((name2) => `.target(name: ${JSON.stringify(name2)}, path: ${JSON.stringify(`Sources/${name2}`)})`).join(", ")}, .executableTarget(name: "PeachExpoApp", path: "Sources/PeachExpoApp")])
9425
10626
  `;
9426
- const packagePath = import_node_path14.default.join(
10627
+ const packagePath = import_node_path16.default.join(
9427
10628
  import_node_os6.default.tmpdir(),
9428
10629
  "peach-expo-swift",
9429
10630
  key,
@@ -9433,7 +10634,7 @@ let package = Package(name: "PeachExpo", targets: [${targets.map((name2) => `.ta
9433
10634
  packagePath,
9434
10635
  new Map(
9435
10636
  Object.entries(files).map(([name2, source]) => [
9436
- import_node_path14.default.join(packagePath, name2),
10637
+ import_node_path16.default.join(packagePath, name2),
9437
10638
  source
9438
10639
  ])
9439
10640
  )
@@ -9607,19 +10808,19 @@ var rnxRuntime = createRuntimeDelivery(RNX_RUNTIME_PRODUCT);
9607
10808
 
9608
10809
  // src/host/agent-host.ts
9609
10810
  var import_node_crypto9 = require("node:crypto");
9610
- var import_node_fs18 = __toESM(require("node:fs"), 1);
9611
- var import_node_path18 = __toESM(require("node:path"), 1);
10811
+ var import_node_fs20 = __toESM(require("node:fs"), 1);
10812
+ var import_node_path20 = __toESM(require("node:path"), 1);
9612
10813
 
9613
10814
  // src/agent-sessions.ts
9614
- var import_node_child_process7 = require("node:child_process");
10815
+ var import_node_child_process8 = require("node:child_process");
9615
10816
  var import_node_crypto8 = require("node:crypto");
9616
- var import_node_fs17 = __toESM(require("node:fs"), 1);
9617
- var import_node_path17 = __toESM(require("node:path"), 1);
10817
+ var import_node_fs19 = __toESM(require("node:fs"), 1);
10818
+ var import_node_path19 = __toESM(require("node:path"), 1);
9618
10819
  var import_node_readline = __toESM(require("node:readline"), 1);
9619
10820
 
9620
10821
  // cli/self-invocation.ts
9621
- var import_node_fs15 = require("node:fs");
9622
- var import_node_path15 = require("node:path");
10822
+ var import_node_fs17 = require("node:fs");
10823
+ var import_node_path17 = require("node:path");
9623
10824
  var import_node_url3 = require("node:url");
9624
10825
  init_public_brand();
9625
10826
 
@@ -9629,14 +10830,14 @@ var IS_STANDALONE = typeof __SOOTSIM_STANDALONE__ !== "undefined" && __SOOTSIM_S
9629
10830
  // cli/self-invocation.ts
9630
10831
  function sourceEntryPath() {
9631
10832
  try {
9632
- const candidate = (0, import_node_path15.join)((0, import_node_path15.dirname)((0, import_node_url3.fileURLToPath)(__sootsim_import_meta_url)), "bin.ts");
9633
- return (0, import_node_fs15.existsSync)(candidate) ? candidate : null;
10833
+ const candidate = (0, import_node_path17.join)((0, import_node_path17.dirname)((0, import_node_url3.fileURLToPath)(__sootsim_import_meta_url)), "bin.ts");
10834
+ return (0, import_node_fs17.existsSync)(candidate) ? candidate : null;
9634
10835
  } catch {
9635
10836
  return null;
9636
10837
  }
9637
10838
  }
9638
- function isCliEntry(path18) {
9639
- const name2 = (0, import_node_path15.basename)(path18);
10839
+ function isCliEntry(path20) {
10840
+ const name2 = (0, import_node_path17.basename)(path20);
9640
10841
  return name2 === "bin.ts" || name2 === "bin.js";
9641
10842
  }
9642
10843
  function rnxSelfInvocation() {
@@ -9665,8 +10866,8 @@ function parseAgentEventLine(line) {
9665
10866
  const trimmed = line.trim();
9666
10867
  if (!trimmed) return null;
9667
10868
  try {
9668
- const parsed = JSON.parse(trimmed);
9669
- return isAgentEvent(parsed) ? parsed : null;
10869
+ const parsed2 = JSON.parse(trimmed);
10870
+ return isAgentEvent(parsed2) ? parsed2 : null;
9670
10871
  } catch {
9671
10872
  return null;
9672
10873
  }
@@ -9696,8 +10897,8 @@ function encodeAgentPromptEnvelope(input) {
9696
10897
 
9697
10898
  // src/attached-projects.ts
9698
10899
  var import_node_crypto7 = require("node:crypto");
9699
- var import_node_fs16 = __toESM(require("node:fs"), 1);
9700
- var import_node_path16 = __toESM(require("node:path"), 1);
10900
+ var import_node_fs18 = __toESM(require("node:fs"), 1);
10901
+ var import_node_path18 = __toESM(require("node:path"), 1);
9701
10902
  init_home_paths();
9702
10903
  var overrideDir = null;
9703
10904
  function userDataDir() {
@@ -9710,7 +10911,7 @@ function getUserDataDir() {
9710
10911
  return userDataDir();
9711
10912
  }
9712
10913
  function storeFile() {
9713
- return import_node_path16.default.join(userDataDir(), "attached-projects.json");
10914
+ return import_node_path18.default.join(userDataDir(), "attached-projects.json");
9714
10915
  }
9715
10916
  function cloneEmpty() {
9716
10917
  return {
@@ -9724,24 +10925,24 @@ function loadStore() {
9724
10925
  const file = storeFile();
9725
10926
  let raw2;
9726
10927
  try {
9727
- raw2 = import_node_fs16.default.readFileSync(file, "utf8");
10928
+ raw2 = import_node_fs18.default.readFileSync(file, "utf8");
9728
10929
  } catch (err) {
9729
10930
  if (err.code === "ENOENT") return cloneEmpty();
9730
10931
  throw err;
9731
10932
  }
9732
10933
  try {
9733
- const parsed = JSON.parse(raw2);
9734
- if (!parsed || typeof parsed !== "object") throw new Error("not an object");
10934
+ const parsed2 = JSON.parse(raw2);
10935
+ if (!parsed2 || typeof parsed2 !== "object") throw new Error("not an object");
9735
10936
  return {
9736
10937
  version: 1,
9737
- attachedProjects: Array.isArray(parsed.attachedProjects) ? parsed.attachedProjects : [],
9738
- previewAttachments: Array.isArray(parsed.previewAttachments) ? parsed.previewAttachments : [],
9739
- agentSessions: Array.isArray(parsed.agentSessions) ? parsed.agentSessions : []
10938
+ attachedProjects: Array.isArray(parsed2.attachedProjects) ? parsed2.attachedProjects : [],
10939
+ previewAttachments: Array.isArray(parsed2.previewAttachments) ? parsed2.previewAttachments : [],
10940
+ agentSessions: Array.isArray(parsed2.agentSessions) ? parsed2.agentSessions : []
9740
10941
  };
9741
10942
  } catch (err) {
9742
10943
  const quarantine = `${file}.corrupt-${Date.now()}`;
9743
10944
  try {
9744
- import_node_fs16.default.renameSync(file, quarantine);
10945
+ import_node_fs18.default.renameSync(file, quarantine);
9745
10946
  console.warn(
9746
10947
  `[sootsim] attached-projects.json was unparseable; quarantined to ${quarantine}. original error: ${err.message}`
9747
10948
  );
@@ -9752,16 +10953,16 @@ function loadStore() {
9752
10953
  }
9753
10954
  function writeStore(store) {
9754
10955
  const file = storeFile();
9755
- import_node_fs16.default.mkdirSync(import_node_path16.default.dirname(file), { recursive: true });
10956
+ import_node_fs18.default.mkdirSync(import_node_path18.default.dirname(file), { recursive: true });
9756
10957
  const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
9757
- const fd = import_node_fs16.default.openSync(tmp, "w", 384);
10958
+ const fd = import_node_fs18.default.openSync(tmp, "w", 384);
9758
10959
  try {
9759
- import_node_fs16.default.writeFileSync(fd, JSON.stringify(store, null, 2));
9760
- import_node_fs16.default.fsyncSync(fd);
10960
+ import_node_fs18.default.writeFileSync(fd, JSON.stringify(store, null, 2));
10961
+ import_node_fs18.default.fsyncSync(fd);
9761
10962
  } finally {
9762
- import_node_fs16.default.closeSync(fd);
10963
+ import_node_fs18.default.closeSync(fd);
9763
10964
  }
9764
- import_node_fs16.default.renameSync(tmp, file);
10965
+ import_node_fs18.default.renameSync(tmp, file);
9765
10966
  }
9766
10967
  function mutateStore(fn) {
9767
10968
  const store = loadStore();
@@ -9770,13 +10971,13 @@ function mutateStore(fn) {
9770
10971
  return store;
9771
10972
  }
9772
10973
  function projectIdForCwd(cwd) {
9773
- return (0, import_node_crypto7.createHash)("sha256").update(import_node_path16.default.resolve(cwd)).digest("hex").slice(0, 16);
10974
+ return (0, import_node_crypto7.createHash)("sha256").update(import_node_path18.default.resolve(cwd)).digest("hex").slice(0, 16);
9774
10975
  }
9775
10976
  function newSessionId() {
9776
10977
  return `s_${(0, import_node_crypto7.randomBytes)(10).toString("hex")}`;
9777
10978
  }
9778
10979
  function upsertProject(input) {
9779
- const cwd = import_node_path16.default.resolve(input.cwd);
10980
+ const cwd = import_node_path18.default.resolve(input.cwd);
9780
10981
  const id = projectIdForCwd(cwd);
9781
10982
  let result;
9782
10983
  mutateStore((store) => {
@@ -9802,7 +11003,7 @@ function upsertProject(input) {
9802
11003
  const now = Date.now();
9803
11004
  const created = {
9804
11005
  id,
9805
- name: input.name ?? import_node_path16.default.basename(cwd),
11006
+ name: input.name ?? import_node_path18.default.basename(cwd),
9806
11007
  cwd,
9807
11008
  repoRoot: input.repoRoot,
9808
11009
  sourceRoots: input.sourceRoots ?? [cwd],
@@ -9948,8 +11149,8 @@ async function seedFromDemoAppRegistry() {
9948
11149
  if (apps.length === 0) return;
9949
11150
  mutateStore((store) => {
9950
11151
  for (const app of apps) {
9951
- if (!import_node_fs16.default.existsSync(app.dir)) continue;
9952
- const cwd = import_node_path16.default.resolve(app.dir);
11152
+ if (!import_node_fs18.default.existsSync(app.dir)) continue;
11153
+ const cwd = import_node_path18.default.resolve(app.dir);
9953
11154
  const id = projectIdForCwd(cwd);
9954
11155
  if (store.attachedProjects.some((p) => p.id === id)) continue;
9955
11156
  const now = Date.now();
@@ -9974,16 +11175,16 @@ async function seedFromDemoAppRegistry() {
9974
11175
  // src/agent-sessions.ts
9975
11176
  init_public_brand();
9976
11177
  function sessionDir(sessionId) {
9977
- return import_node_path17.default.join(getUserDataDir(), "sessions", sessionId);
11178
+ return import_node_path19.default.join(getUserDataDir(), "sessions", sessionId);
9978
11179
  }
9979
11180
  function promptFifoPath(sessionId) {
9980
- return import_node_path17.default.join(sessionDir(sessionId), "prompt.in");
11181
+ return import_node_path19.default.join(sessionDir(sessionId), "prompt.in");
9981
11182
  }
9982
11183
  function eventsFifoPath(sessionId) {
9983
- return import_node_path17.default.join(sessionDir(sessionId), "events.out");
11184
+ return import_node_path19.default.join(sessionDir(sessionId), "events.out");
9984
11185
  }
9985
11186
  function transcriptPath(sessionId) {
9986
- return import_node_path17.default.join(getUserDataDir(), "transcripts", `${sessionId}.log`);
11187
+ return import_node_path19.default.join(getUserDataDir(), "transcripts", `${sessionId}.log`);
9987
11188
  }
9988
11189
  function pidIsAlive(pid, sessionId) {
9989
11190
  if (!pid) return false;
@@ -9993,7 +11194,7 @@ function pidIsAlive(pid, sessionId) {
9993
11194
  return false;
9994
11195
  }
9995
11196
  if (sessionId) {
9996
- if (!import_node_fs17.default.existsSync(sessionDir(sessionId))) return false;
11197
+ if (!import_node_fs19.default.existsSync(sessionDir(sessionId))) return false;
9997
11198
  }
9998
11199
  return true;
9999
11200
  }
@@ -10006,11 +11207,11 @@ function resolveSootsimInvocation() {
10006
11207
  const resourcesPath = process.resourcesPath;
10007
11208
  if (resourcesPath) {
10008
11209
  const candidates = [
10009
- import_node_path17.default.join(resourcesPath, "bin", "sootsim"),
10010
- import_node_path17.default.join(resourcesPath, "bin", `sootsim-${process.platform}-${process.arch}`)
11210
+ import_node_path19.default.join(resourcesPath, "bin", "sootsim"),
11211
+ import_node_path19.default.join(resourcesPath, "bin", `sootsim-${process.platform}-${process.arch}`)
10011
11212
  ];
10012
11213
  for (const c of candidates) {
10013
- if (import_node_fs17.default.existsSync(c)) return { executable: c, prefixArgs: [] };
11214
+ if (import_node_fs19.default.existsSync(c)) return { executable: c, prefixArgs: [] };
10014
11215
  }
10015
11216
  }
10016
11217
  }
@@ -10029,15 +11230,15 @@ function tryWorkspaceSootsim() {
10029
11230
  const sootsimDir = resolveSootsimPackageDir();
10030
11231
  if (!sootsimDir) return null;
10031
11232
  const binaryName = `peach-${process.platform === "win32" ? "windows" : process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`;
10032
- const distBinary = import_node_path17.default.join(sootsimDir, "dist-bin", binaryName);
10033
- if (import_node_fs17.default.existsSync(distBinary)) return { executable: distBinary, prefixArgs: [] };
10034
- const distBin = import_node_path17.default.join(sootsimDir, "dist-cli", "bin.js");
10035
- if (import_node_fs17.default.existsSync(distBin)) {
11233
+ const distBinary = import_node_path19.default.join(sootsimDir, "dist-bin", binaryName);
11234
+ if (import_node_fs19.default.existsSync(distBinary)) return { executable: distBinary, prefixArgs: [] };
11235
+ const distBin = import_node_path19.default.join(sootsimDir, "dist-cli", "bin.js");
11236
+ if (import_node_fs19.default.existsSync(distBin)) {
10036
11237
  try {
10037
- const src = import_node_path17.default.join(sootsimDir, "cli", "commands", "agent-wrapper.ts");
10038
- if (import_node_fs17.default.existsSync(src)) {
10039
- const srcMtime = import_node_fs17.default.statSync(src).mtimeMs;
10040
- const buildMtime = import_node_fs17.default.statSync(distBin).mtimeMs;
11238
+ const src = import_node_path19.default.join(sootsimDir, "cli", "commands", "agent-wrapper.ts");
11239
+ if (import_node_fs19.default.existsSync(src)) {
11240
+ const srcMtime = import_node_fs19.default.statSync(src).mtimeMs;
11241
+ const buildMtime = import_node_fs19.default.statSync(distBin).mtimeMs;
10041
11242
  if (buildMtime < srcMtime) {
10042
11243
  console.warn(
10043
11244
  `[peach] dist-cli/bin.js is older than agent-wrapper.ts \u2014 rebuild with \`bun run --cwd packages/peachsim build:cli\`.`
@@ -10056,22 +11257,22 @@ function tryWorkspaceSootsim() {
10056
11257
  function resolveSootsimPackageDir() {
10057
11258
  try {
10058
11259
  const resolved = require.resolve(`${rnxPublicBrand.packageName}/package.json`);
10059
- return import_node_path17.default.dirname(resolved);
11260
+ return import_node_path19.default.dirname(resolved);
10060
11261
  } catch {
10061
11262
  }
10062
11263
  const here = fileFromImportMeta();
10063
11264
  if (!here) return null;
10064
- let cur = import_node_path17.default.dirname(here);
11265
+ let cur = import_node_path19.default.dirname(here);
10065
11266
  for (let i = 0; i < 8; i++) {
10066
- const pkg = import_node_path17.default.join(cur, "package.json");
11267
+ const pkg = import_node_path19.default.join(cur, "package.json");
10067
11268
  try {
10068
- if (import_node_fs17.default.existsSync(pkg)) {
10069
- const parsed = JSON.parse(import_node_fs17.default.readFileSync(pkg, "utf8"));
10070
- if (parsed.name === rnxPublicBrand.packageName) return cur;
11269
+ if (import_node_fs19.default.existsSync(pkg)) {
11270
+ const parsed2 = JSON.parse(import_node_fs19.default.readFileSync(pkg, "utf8"));
11271
+ if (parsed2.name === rnxPublicBrand.packageName) return cur;
10071
11272
  }
10072
11273
  } catch {
10073
11274
  }
10074
- const parent = import_node_path17.default.dirname(cur);
11275
+ const parent = import_node_path19.default.dirname(cur);
10075
11276
  if (parent === cur) break;
10076
11277
  cur = parent;
10077
11278
  }
@@ -10087,28 +11288,28 @@ function fileFromImportMeta() {
10087
11288
  }
10088
11289
  }
10089
11290
  async function withStartLock(projectId, provider, fn) {
10090
- const lockDir = import_node_path17.default.join(getUserDataDir(), "locks");
10091
- import_node_fs17.default.mkdirSync(lockDir, { recursive: true });
11291
+ const lockDir = import_node_path19.default.join(getUserDataDir(), "locks");
11292
+ import_node_fs19.default.mkdirSync(lockDir, { recursive: true });
10092
11293
  try {
10093
- import_node_fs17.default.chmodSync(lockDir, 448);
11294
+ import_node_fs19.default.chmodSync(lockDir, 448);
10094
11295
  } catch {
10095
11296
  }
10096
- const lockPath = import_node_path17.default.join(lockDir, `start-${projectId}-${provider}.lock`);
11297
+ const lockPath = import_node_path19.default.join(lockDir, `start-${projectId}-${provider}.lock`);
10097
11298
  const deadline = Date.now() + 4e3;
10098
11299
  let fd = null;
10099
11300
  while (fd === null) {
10100
11301
  try {
10101
- fd = import_node_fs17.default.openSync(
11302
+ fd = import_node_fs19.default.openSync(
10102
11303
  lockPath,
10103
- import_node_fs17.constants.O_WRONLY | import_node_fs17.constants.O_CREAT | import_node_fs17.constants.O_EXCL,
11304
+ import_node_fs19.constants.O_WRONLY | import_node_fs19.constants.O_CREAT | import_node_fs19.constants.O_EXCL,
10104
11305
  384
10105
11306
  );
10106
11307
  } catch (err) {
10107
11308
  if (err.code !== "EEXIST") throw err;
10108
11309
  try {
10109
- const stale = Number(import_node_fs17.default.readFileSync(lockPath, "utf8").trim());
11310
+ const stale = Number(import_node_fs19.default.readFileSync(lockPath, "utf8").trim());
10110
11311
  if (stale && !isProcessAlive(stale)) {
10111
- import_node_fs17.default.unlinkSync(lockPath);
11312
+ import_node_fs19.default.unlinkSync(lockPath);
10112
11313
  continue;
10113
11314
  }
10114
11315
  } catch {
@@ -10122,15 +11323,15 @@ async function withStartLock(projectId, provider, fn) {
10122
11323
  }
10123
11324
  }
10124
11325
  try {
10125
- import_node_fs17.default.writeFileSync(fd, String(process.pid));
11326
+ import_node_fs19.default.writeFileSync(fd, String(process.pid));
10126
11327
  return await fn();
10127
11328
  } finally {
10128
11329
  try {
10129
- import_node_fs17.default.closeSync(fd);
11330
+ import_node_fs19.default.closeSync(fd);
10130
11331
  } catch {
10131
11332
  }
10132
11333
  try {
10133
- import_node_fs17.default.unlinkSync(lockPath);
11334
+ import_node_fs19.default.unlinkSync(lockPath);
10134
11335
  } catch {
10135
11336
  }
10136
11337
  }
@@ -10144,28 +11345,28 @@ function isProcessAlive(pid) {
10144
11345
  }
10145
11346
  }
10146
11347
  function mkfifoSync(p) {
10147
- const parent = import_node_path17.default.dirname(p);
10148
- import_node_fs17.default.mkdirSync(parent, { recursive: true });
11348
+ const parent = import_node_path19.default.dirname(p);
11349
+ import_node_fs19.default.mkdirSync(parent, { recursive: true });
10149
11350
  try {
10150
- import_node_fs17.default.chmodSync(parent, 448);
11351
+ import_node_fs19.default.chmodSync(parent, 448);
10151
11352
  } catch {
10152
11353
  }
10153
- if (import_node_fs17.default.existsSync(p)) {
11354
+ if (import_node_fs19.default.existsSync(p)) {
10154
11355
  try {
10155
- const stat2 = import_node_fs17.default.statSync(p);
11356
+ const stat2 = import_node_fs19.default.statSync(p);
10156
11357
  if (stat2.isFIFO()) {
10157
11358
  try {
10158
- import_node_fs17.default.chmodSync(p, 384);
11359
+ import_node_fs19.default.chmodSync(p, 384);
10159
11360
  } catch {
10160
11361
  }
10161
11362
  return;
10162
11363
  }
10163
- import_node_fs17.default.unlinkSync(p);
11364
+ import_node_fs19.default.unlinkSync(p);
10164
11365
  } catch {
10165
- import_node_fs17.default.unlinkSync(p);
11366
+ import_node_fs19.default.unlinkSync(p);
10166
11367
  }
10167
11368
  }
10168
- const result = (0, import_node_child_process7.spawnSync)("mkfifo", ["-m", "600", p]);
11369
+ const result = (0, import_node_child_process8.spawnSync)("mkfifo", ["-m", "600", p]);
10169
11370
  if (result.status !== 0) {
10170
11371
  throw new Error(
10171
11372
  `mkfifo(${p}) failed: ${result.stderr?.toString().trim() || "unknown error"}`
@@ -10209,10 +11410,10 @@ async function startSession(opts) {
10209
11410
  const transcript = transcriptPath(session.id);
10210
11411
  mkfifoSync(promptIn);
10211
11412
  mkfifoSync(eventsOut);
10212
- const transcriptDir = import_node_path17.default.dirname(transcript);
10213
- import_node_fs17.default.mkdirSync(transcriptDir, { recursive: true });
11413
+ const transcriptDir = import_node_path19.default.dirname(transcript);
11414
+ import_node_fs19.default.mkdirSync(transcriptDir, { recursive: true });
10214
11415
  try {
10215
- import_node_fs17.default.chmodSync(transcriptDir, 448);
11416
+ import_node_fs19.default.chmodSync(transcriptDir, 448);
10216
11417
  } catch {
10217
11418
  }
10218
11419
  const { executable, prefixArgs } = resolveSootsimInvocation();
@@ -10240,7 +11441,7 @@ async function startSession(opts) {
10240
11441
  if (claudeSessionUuid) {
10241
11442
  wrapperArgs.push("--claude-session-uuid", claudeSessionUuid);
10242
11443
  }
10243
- const child = (0, import_node_child_process7.spawn)(executable, wrapperArgs, {
11444
+ const child = (0, import_node_child_process8.spawn)(executable, wrapperArgs, {
10244
11445
  detached: true,
10245
11446
  stdio: "ignore",
10246
11447
  env: {
@@ -10263,7 +11464,7 @@ async function startSession(opts) {
10263
11464
  }
10264
11465
  }
10265
11466
  try {
10266
- import_node_fs17.default.rmSync(sessionDir(session.id), { recursive: true, force: true });
11467
+ import_node_fs19.default.rmSync(sessionDir(session.id), { recursive: true, force: true });
10267
11468
  } catch {
10268
11469
  }
10269
11470
  updateSessionStatus(session.id, { status: "ended" });
@@ -10291,18 +11492,18 @@ async function sendPrompt(sessionId, prompt) {
10291
11492
  );
10292
11493
  }
10293
11494
  const fifo = promptFifoPath(sessionId);
10294
- if (!import_node_fs17.default.existsSync(fifo)) {
11495
+ if (!import_node_fs19.default.existsSync(fifo)) {
10295
11496
  throw new AgentSessionError("NO_FIFO", `prompt FIFO missing: ${fifo}`);
10296
11497
  }
10297
- const fd = import_node_fs17.default.openSync(fifo, import_node_fs17.constants.O_WRONLY);
11498
+ const fd = import_node_fs19.default.openSync(fifo, import_node_fs19.constants.O_WRONLY);
10298
11499
  try {
10299
11500
  const wireText = encodeAgentPromptEnvelope(prompt);
10300
11501
  if (!wireText) {
10301
11502
  throw new AgentSessionError("EMPTY_PROMPT", "prompt text is empty");
10302
11503
  }
10303
- import_node_fs17.default.writeSync(fd, wireText + "\n");
11504
+ import_node_fs19.default.writeSync(fd, wireText + "\n");
10304
11505
  } finally {
10305
- import_node_fs17.default.closeSync(fd);
11506
+ import_node_fs19.default.closeSync(fd);
10306
11507
  }
10307
11508
  updateSessionStatus(sessionId, {
10308
11509
  lastPrompt: prompt.displayText ?? prompt.text,
@@ -10324,7 +11525,7 @@ async function endSession(sessionId) {
10324
11525
  const base = getUserDataDir();
10325
11526
  if (dir.startsWith(base)) {
10326
11527
  try {
10327
- import_node_fs17.default.rmSync(dir, { recursive: true, force: true });
11528
+ import_node_fs19.default.rmSync(dir, { recursive: true, force: true });
10328
11529
  } catch {
10329
11530
  }
10330
11531
  }
@@ -10332,11 +11533,11 @@ async function endSession(sessionId) {
10332
11533
  }
10333
11534
  function subscribeEvents(sessionId, onEvent) {
10334
11535
  const fifo = eventsFifoPath(sessionId);
10335
- if (!import_node_fs17.default.existsSync(fifo)) {
11536
+ if (!import_node_fs19.default.existsSync(fifo)) {
10336
11537
  throw new AgentSessionError("NO_FIFO", `events FIFO missing: ${fifo}`);
10337
11538
  }
10338
- const fd = import_node_fs17.default.openSync(fifo, import_node_fs17.constants.O_RDWR);
10339
- const stream = import_node_fs17.default.createReadStream("", { fd, autoClose: true });
11539
+ const fd = import_node_fs19.default.openSync(fifo, import_node_fs19.constants.O_RDWR);
11540
+ const stream = import_node_fs19.default.createReadStream("", { fd, autoClose: true });
10340
11541
  const rl = import_node_readline.default.createInterface({ input: stream, crlfDelay: Infinity });
10341
11542
  rl.on("line", (line) => {
10342
11543
  const event = parseAgentEventLine(line);
@@ -10347,7 +11548,7 @@ function subscribeEvents(sessionId, onEvent) {
10347
11548
  if (closed) return;
10348
11549
  closed = true;
10349
11550
  try {
10350
- import_node_fs17.default.writeSync(fd, "\n");
11551
+ import_node_fs19.default.writeSync(fd, "\n");
10351
11552
  } catch {
10352
11553
  }
10353
11554
  try {
@@ -10361,7 +11562,7 @@ function subscribeEvents(sessionId, onEvent) {
10361
11562
  };
10362
11563
  }
10363
11564
  async function waitForFirstEvent(fifo, predicate, timeoutMs) {
10364
- const fd = import_node_fs17.default.openSync(fifo, import_node_fs17.constants.O_RDWR | import_node_fs17.constants.O_NONBLOCK);
11565
+ const fd = import_node_fs19.default.openSync(fifo, import_node_fs19.constants.O_RDWR | import_node_fs19.constants.O_NONBLOCK);
10365
11566
  const buf = Buffer.alloc(8192);
10366
11567
  let leftover = "";
10367
11568
  const deadline = Date.now() + timeoutMs;
@@ -10369,7 +11570,7 @@ async function waitForFirstEvent(fifo, predicate, timeoutMs) {
10369
11570
  while (Date.now() < deadline) {
10370
11571
  let n = 0;
10371
11572
  try {
10372
- n = import_node_fs17.default.readSync(fd, buf, 0, buf.length, null);
11573
+ n = import_node_fs19.default.readSync(fd, buf, 0, buf.length, null);
10373
11574
  } catch (err) {
10374
11575
  if (err.code !== "EAGAIN") throw err;
10375
11576
  n = 0;
@@ -10389,7 +11590,7 @@ async function waitForFirstEvent(fifo, predicate, timeoutMs) {
10389
11590
  }
10390
11591
  return null;
10391
11592
  } finally {
10392
- import_node_fs17.default.closeSync(fd);
11593
+ import_node_fs19.default.closeSync(fd);
10393
11594
  }
10394
11595
  }
10395
11596
 
@@ -10643,7 +11844,7 @@ var AgentHost = class {
10643
11844
  );
10644
11845
  const project = upsertProject({
10645
11846
  cwd: match.cwd,
10646
- name: match.projectName ?? import_node_path18.default.basename(match.cwd),
11847
+ name: match.projectName ?? import_node_path20.default.basename(match.cwd),
10647
11848
  preferredProvider: input.provider ?? existing?.preferredProvider,
10648
11849
  sourceRoots: existing?.sourceRoots ?? [match.cwd],
10649
11850
  knownBundleUrls,
@@ -10654,18 +11855,18 @@ var AgentHost = class {
10654
11855
  }
10655
11856
  getTranscript(sessionId) {
10656
11857
  const p = transcriptPath(sessionId);
10657
- if (!import_node_fs18.default.existsSync(p)) {
11858
+ if (!import_node_fs20.default.existsSync(p)) {
10658
11859
  return { error: "transcript not found", code: "NO_TRANSCRIPT" };
10659
11860
  }
10660
- return import_node_fs18.default.readFileSync(p, "utf8");
11861
+ return import_node_fs20.default.readFileSync(p, "utf8");
10661
11862
  }
10662
11863
  getPaths() {
10663
11864
  const dir = getUserDataDir();
10664
11865
  return {
10665
11866
  userDataDir: dir,
10666
- storeFile: import_node_path18.default.join(dir, "attached-projects.json"),
10667
- sessionsDir: import_node_path18.default.join(dir, "sessions"),
10668
- transcriptsDir: import_node_path18.default.join(dir, "transcripts")
11867
+ storeFile: import_node_path20.default.join(dir, "attached-projects.json"),
11868
+ sessionsDir: import_node_path20.default.join(dir, "sessions"),
11869
+ transcriptsDir: import_node_path20.default.join(dir, "transcripts")
10669
11870
  };
10670
11871
  }
10671
11872
  // --- subscription management ---
@@ -11301,9 +12502,9 @@ function handleAppApiRequest(req, res) {
11301
12502
  let targetPath = "";
11302
12503
  let targetOrigin = "";
11303
12504
  if (reqUrl.startsWith("/__app-api?")) {
11304
- const parsed = new URL(reqUrl, "http://sootsim.local");
11305
- targetPath = parsed.searchParams.get("path") || "";
11306
- targetOrigin = parsed.searchParams.get("origin")?.trim() || "";
12505
+ const parsed2 = new URL(reqUrl, "http://sootsim.local");
12506
+ targetPath = parsed2.searchParams.get("path") || "";
12507
+ targetOrigin = parsed2.searchParams.get("origin")?.trim() || "";
11307
12508
  } else if (reqUrl.startsWith("/__app-api/")) {
11308
12509
  targetPath = reqUrl.slice("/__app-api".length);
11309
12510
  } else {
@@ -11508,8 +12709,8 @@ async function openUrl(url, options = {}) {
11508
12709
  }
11509
12710
 
11510
12711
  // src/host/plane-host.ts
11511
- var import_node_fs20 = __toESM(require("node:fs"), 1);
11512
- var import_node_path20 = __toESM(require("node:path"), 1);
12712
+ var import_node_fs22 = __toESM(require("node:fs"), 1);
12713
+ var import_node_path22 = __toESM(require("node:path"), 1);
11513
12714
 
11514
12715
  // ../peach-box/src/planeProtocol.ts
11515
12716
  var PLANE_FLAG_READ_ONLY = 1;
@@ -11588,9 +12789,9 @@ async function dispatchPlaneCommand(plane, type, msg, mutationOptions) {
11588
12789
  }
11589
12790
 
11590
12791
  // cli/commands/box/checkout-plane.ts
11591
- var import_node_child_process8 = require("node:child_process");
11592
- var import_node_fs19 = __toESM(require("node:fs"), 1);
11593
- var import_node_path19 = __toESM(require("node:path"), 1);
12792
+ var import_node_child_process9 = require("node:child_process");
12793
+ var import_node_fs21 = __toESM(require("node:fs"), 1);
12794
+ var import_node_path21 = __toESM(require("node:path"), 1);
11594
12795
  var CheckoutRequiresGitError = class extends Error {
11595
12796
  };
11596
12797
  var BINARY_SNIFF_BYTES = 8192;
@@ -11601,14 +12802,14 @@ function looksBinary(filePath, size) {
11601
12802
  if (size === 0) return false;
11602
12803
  let fd;
11603
12804
  try {
11604
- fd = import_node_fs19.default.openSync(filePath, "r");
12805
+ fd = import_node_fs21.default.openSync(filePath, "r");
11605
12806
  const buffer = Buffer.alloc(Math.min(BINARY_SNIFF_BYTES, size));
11606
- const read = import_node_fs19.default.readSync(fd, buffer, 0, buffer.length, 0);
12807
+ const read = import_node_fs21.default.readSync(fd, buffer, 0, buffer.length, 0);
11607
12808
  return buffer.subarray(0, read).includes(0);
11608
12809
  } catch {
11609
12810
  return false;
11610
12811
  } finally {
11611
- if (fd !== void 0) import_node_fs19.default.closeSync(fd);
12812
+ if (fd !== void 0) import_node_fs21.default.closeSync(fd);
11612
12813
  }
11613
12814
  }
11614
12815
  var CheckoutFilePlane = class {
@@ -11621,7 +12822,7 @@ var CheckoutFilePlane = class {
11621
12822
  listTimeoutMs;
11622
12823
  trackedOnly;
11623
12824
  constructor(root, options = {}) {
11624
- this.root = import_node_path19.default.resolve(root);
12825
+ this.root = import_node_path21.default.resolve(root);
11625
12826
  this.listTimeoutMs = options.listTimeoutMs ?? LIST_FILES_TIMEOUT_MS;
11626
12827
  this.trackedOnly = options.trackedOnly ?? false;
11627
12828
  }
@@ -11630,7 +12831,7 @@ var CheckoutFilePlane = class {
11630
12831
  }
11631
12832
  listFiles() {
11632
12833
  const args = this.trackedOnly ? ["ls-files", "-z"] : ["ls-files", "-co", "--exclude-standard", "-z"];
11633
- const stdout = (0, import_node_child_process8.execFileSync)("git", args, {
12834
+ const stdout = (0, import_node_child_process9.execFileSync)("git", args, {
11634
12835
  cwd: this.root,
11635
12836
  encoding: "utf8",
11636
12837
  maxBuffer: 64 * 1024 * 1024,
@@ -11683,13 +12884,13 @@ var CheckoutFilePlane = class {
11683
12884
  if (!relative2) continue;
11684
12885
  let stat2;
11685
12886
  try {
11686
- stat2 = import_node_fs19.default.statSync(import_node_path19.default.join(this.root, relative2));
12887
+ stat2 = import_node_fs21.default.statSync(import_node_path21.default.join(this.root, relative2));
11687
12888
  } catch {
11688
12889
  continue;
11689
12890
  }
11690
12891
  if (!stat2.isFile()) continue;
11691
12892
  const seen = this.sniffed.get(relative2);
11692
- const binary = seen && seen.size === stat2.size && seen.mtimeMs === stat2.mtimeMs ? seen.binary : looksBinary(import_node_path19.default.join(this.root, relative2), stat2.size);
12893
+ const binary = seen && seen.size === stat2.size && seen.mtimeMs === stat2.mtimeMs ? seen.binary : looksBinary(import_node_path21.default.join(this.root, relative2), stat2.size);
11693
12894
  nextSniffed.set(relative2, { size: stat2.size, mtimeMs: stat2.mtimeMs, binary });
11694
12895
  next.set(relative2, {
11695
12896
  size: stat2.size,
@@ -11703,22 +12904,22 @@ var CheckoutFilePlane = class {
11703
12904
  this.sniffed = nextSniffed;
11704
12905
  }
11705
12906
  absolute(planePath) {
11706
- const resolved = import_node_path19.default.resolve(this.root, planePath);
11707
- if (resolved !== this.root && !resolved.startsWith(`${this.root}${import_node_path19.default.sep}`)) {
12907
+ const resolved = import_node_path21.default.resolve(this.root, planePath);
12908
+ if (resolved !== this.root && !resolved.startsWith(`${this.root}${import_node_path21.default.sep}`)) {
11708
12909
  throw new Error(`path escapes the project: ${planePath}`);
11709
12910
  }
11710
12911
  return resolved;
11711
12912
  }
11712
12913
  async read(planePath) {
11713
- return import_node_fs19.default.promises.readFile(this.absolute(planePath), "utf8");
12914
+ return import_node_fs21.default.promises.readFile(this.absolute(planePath), "utf8");
11714
12915
  }
11715
12916
  async readBytes(planePath) {
11716
- return import_node_fs19.default.promises.readFile(this.absolute(planePath));
12917
+ return import_node_fs21.default.promises.readFile(this.absolute(planePath));
11717
12918
  }
11718
12919
  async write(planePath, content) {
11719
12920
  const absolute = this.absolute(planePath);
11720
- await import_node_fs19.default.promises.mkdir(import_node_path19.default.dirname(absolute), { recursive: true });
11721
- await import_node_fs19.default.promises.writeFile(absolute, content);
12921
+ await import_node_fs21.default.promises.mkdir(import_node_path21.default.dirname(absolute), { recursive: true });
12922
+ await import_node_fs21.default.promises.writeFile(absolute, content);
11722
12923
  this.entries.set(planePath, {
11723
12924
  size: content.byteLength,
11724
12925
  readOnly: false,
@@ -11727,7 +12928,7 @@ var CheckoutFilePlane = class {
11727
12928
  });
11728
12929
  }
11729
12930
  async delete(planePath) {
11730
- await import_node_fs19.default.promises.rm(this.absolute(planePath), { force: true });
12931
+ await import_node_fs21.default.promises.rm(this.absolute(planePath), { force: true });
11731
12932
  this.entries.delete(planePath);
11732
12933
  }
11733
12934
  };
@@ -11853,14 +13054,14 @@ var PlaneHost = class {
11853
13054
  // root and an opened one cannot disagree about the same directory.
11854
13055
  realRoot(root) {
11855
13056
  if (!root) throw new Error("root is required");
11856
- const resolved = import_node_path20.default.resolve(root);
13057
+ const resolved = import_node_path22.default.resolve(root);
11857
13058
  let real;
11858
13059
  try {
11859
- real = import_node_fs20.default.realpathSync(resolved);
13060
+ real = import_node_fs22.default.realpathSync(resolved);
11860
13061
  } catch {
11861
13062
  throw new Error(`no such directory: ${resolved}`);
11862
13063
  }
11863
- if (!import_node_fs20.default.statSync(real).isDirectory()) throw new Error(`not a directory: ${real}`);
13064
+ if (!import_node_fs22.default.statSync(real).isDirectory()) throw new Error(`not a directory: ${real}`);
11864
13065
  return real;
11865
13066
  }
11866
13067
  respond(ws, id, result) {
@@ -11880,9 +13081,9 @@ var PlaneHost = class {
11880
13081
  };
11881
13082
 
11882
13083
  // src/host/replacement-module-handler.ts
11883
- var import_node_fs21 = require("node:fs");
13084
+ var import_node_fs23 = require("node:fs");
11884
13085
  var import_promises5 = __toESM(require("node:fs/promises"), 1);
11885
- var import_node_path21 = __toESM(require("node:path"), 1);
13086
+ var import_node_path23 = __toESM(require("node:path"), 1);
11886
13087
 
11887
13088
  // ../contrast-bundler/src/replacementModule.ts
11888
13089
  var import_dist = require("sucrase/dist/index.js");
@@ -11948,7 +13149,7 @@ function dirname4(p) {
11948
13149
  if (idx === 0) return "/";
11949
13150
  return p.slice(0, idx);
11950
13151
  }
11951
- function basename3(p, ext) {
13152
+ function basename4(p, ext) {
11952
13153
  const idx = p.lastIndexOf("/");
11953
13154
  const base = idx < 0 ? p : p.slice(idx + 1);
11954
13155
  if (ext != null && ext.length < base.length && base.endsWith(ext)) {
@@ -11957,7 +13158,7 @@ function basename3(p, ext) {
11957
13158
  return base;
11958
13159
  }
11959
13160
  function extname(p) {
11960
- const base = basename3(p);
13161
+ const base = basename4(p);
11961
13162
  const idx = base.lastIndexOf(".");
11962
13163
  if (idx <= 0) return "";
11963
13164
  return base.slice(idx);
@@ -11981,7 +13182,7 @@ var posix = {
11981
13182
  join: join6,
11982
13183
  resolve: resolve3,
11983
13184
  dirname: dirname4,
11984
- basename: basename3,
13185
+ basename: basename4,
11985
13186
  extname,
11986
13187
  relative
11987
13188
  };
@@ -12207,16 +13408,16 @@ function sendJavaScript(req, res, source) {
12207
13408
  res.end(req.method === "HEAD" ? void 0 : source);
12208
13409
  }
12209
13410
  function resolveLocalImport(fromFile, specifier) {
12210
- const base = import_node_path21.default.resolve(import_node_path21.default.dirname(fromFile), specifier);
13411
+ const base = import_node_path23.default.resolve(import_node_path23.default.dirname(fromFile), specifier);
12211
13412
  const candidates = [
12212
13413
  ...REPLACEMENT_MODULE_EXTENSIONS.some(
12213
- (ext) => ext === import_node_path21.default.extname(base).toLowerCase()
13414
+ (ext) => ext === import_node_path23.default.extname(base).toLowerCase()
12214
13415
  ) ? [base] : [],
12215
13416
  ...REPLACEMENT_MODULE_EXTENSIONS.map((ext) => base + ext),
12216
- ...REPLACEMENT_MODULE_EXTENSIONS.map((ext) => import_node_path21.default.join(base, `index${ext}`))
13417
+ ...REPLACEMENT_MODULE_EXTENSIONS.map((ext) => import_node_path23.default.join(base, `index${ext}`))
12217
13418
  ];
12218
13419
  const found = candidates.find(
12219
- (candidate) => (0, import_node_fs21.statSync)(candidate, { throwIfNoEntry: false })?.isFile()
13420
+ (candidate) => (0, import_node_fs23.statSync)(candidate, { throwIfNoEntry: false })?.isFile()
12220
13421
  );
12221
13422
  if (!found) {
12222
13423
  throw new Error(
@@ -12271,13 +13472,13 @@ async function handleReplacementModuleRequest(req, res, options = {}) {
12271
13472
  res.end("missing path param");
12272
13473
  return true;
12273
13474
  }
12274
- const extension = import_node_path21.default.extname(targetPath).toLowerCase();
13475
+ const extension = import_node_path23.default.extname(targetPath).toLowerCase();
12275
13476
  if (!REPLACEMENT_MODULE_EXTENSIONS.some((allowed) => allowed === extension)) {
12276
13477
  res.writeHead(400, { "Content-Type": "text/plain; charset=utf-8" });
12277
13478
  res.end(`replacement files must be ${REPLACEMENT_MODULE_EXTENSIONS.join(", ")}`);
12278
13479
  return true;
12279
13480
  }
12280
- if (!import_node_path21.default.isAbsolute(targetPath)) {
13481
+ if (!import_node_path23.default.isAbsolute(targetPath)) {
12281
13482
  res.writeHead(400, { "Content-Type": "text/plain; charset=utf-8" });
12282
13483
  res.end("replacement file path must be absolute");
12283
13484
  return true;
@@ -12285,10 +13486,10 @@ async function handleReplacementModuleRequest(req, res, options = {}) {
12285
13486
  const runtimePackages = new Set(url.searchParams.getAll("runtimePackage"));
12286
13487
  let resolvedProjectRoot;
12287
13488
  if (options.projectRoot) {
12288
- const lexicalProjectRoot = import_node_path21.default.resolve(options.projectRoot);
13489
+ const lexicalProjectRoot = import_node_path23.default.resolve(options.projectRoot);
12289
13490
  resolvedProjectRoot = await import_promises5.default.realpath(options.projectRoot);
12290
- const lexicalTarget = import_node_path21.default.relative(lexicalProjectRoot, targetPath);
12291
- if (lexicalTarget.startsWith("..") || import_node_path21.default.isAbsolute(lexicalTarget)) {
13491
+ const lexicalTarget = import_node_path23.default.relative(lexicalProjectRoot, targetPath);
13492
+ if (lexicalTarget.startsWith("..") || import_node_path23.default.isAbsolute(lexicalTarget)) {
12292
13493
  res.writeHead(403, { "Content-Type": "text/plain; charset=utf-8" });
12293
13494
  res.end("replacement file must be inside the project root");
12294
13495
  return true;
@@ -12304,8 +13505,8 @@ async function handleReplacementModuleRequest(req, res, options = {}) {
12304
13505
  return true;
12305
13506
  }
12306
13507
  if (resolvedProjectRoot) {
12307
- const relativeTarget = import_node_path21.default.relative(resolvedProjectRoot, resolvedTargetPath);
12308
- if (relativeTarget.startsWith("..") || import_node_path21.default.isAbsolute(relativeTarget)) {
13508
+ const relativeTarget = import_node_path23.default.relative(resolvedProjectRoot, resolvedTargetPath);
13509
+ if (relativeTarget.startsWith("..") || import_node_path23.default.isAbsolute(relativeTarget)) {
12309
13510
  res.writeHead(403, { "Content-Type": "text/plain; charset=utf-8" });
12310
13511
  res.end("replacement file must be inside the project root");
12311
13512
  return true;
@@ -12430,10 +13631,10 @@ function decodeProxyHeaders(encoded) {
12430
13631
  if (!encoded) return {};
12431
13632
  const base64 = encoded.replace(/-/g, "+").replace(/_/g, "/");
12432
13633
  const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
12433
- const parsed = JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
12434
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
13634
+ const parsed2 = JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
13635
+ if (!parsed2 || typeof parsed2 !== "object" || Array.isArray(parsed2)) return {};
12435
13636
  const headers = {};
12436
- for (const [key, value] of Object.entries(parsed)) {
13637
+ for (const [key, value] of Object.entries(parsed2)) {
12437
13638
  if (value == null) continue;
12438
13639
  if (STRIP_UPSTREAM_HEADERS.has(key.toLowerCase())) continue;
12439
13640
  headers[key] = Array.isArray(value) ? value.join(", ") : String(value);
@@ -13016,7 +14217,7 @@ var SootSimBridgeHost = class _SootSimBridgeHost {
13016
14217
  this.updateUserActivity(sim);
13017
14218
  return;
13018
14219
  }
13019
- if (msg.type === "bridge:capture-active" && sim) {
14220
+ if ((msg.type === "bridge:user-present" || msg.type === "bridge:capture-active") && sim) {
13020
14221
  sim.lastActiveAt = Date.now();
13021
14222
  return;
13022
14223
  }
@@ -13709,12 +14910,12 @@ var SootSimBridgeHost = class _SootSimBridgeHost {
13709
14910
  }
13710
14911
  chunks.push(buffer);
13711
14912
  }
13712
- const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
13713
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
14913
+ const parsed2 = JSON.parse(Buffer.concat(chunks).toString("utf8"));
14914
+ if (!parsed2 || typeof parsed2 !== "object" || Array.isArray(parsed2)) {
13714
14915
  throw new Error("shared config patch must be an object");
13715
14916
  }
13716
14917
  const patch = Object.fromEntries(
13717
- Object.entries(parsed)
14918
+ Object.entries(parsed2)
13718
14919
  );
13719
14920
  const next = this.writeAndBroadcastSharedConfig(patch);
13720
14921
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -13753,11 +14954,11 @@ var SootSimBridgeHost = class _SootSimBridgeHost {
13753
14954
  chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
13754
14955
  }
13755
14956
  const text = Buffer.concat(chunks).toString("utf8").trim();
13756
- const parsed = text ? JSON.parse(text) : {};
13757
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
14957
+ const parsed2 = text ? JSON.parse(text) : {};
14958
+ if (!parsed2 || typeof parsed2 !== "object" || Array.isArray(parsed2)) {
13758
14959
  throw new Error("send to box needs a json object body");
13759
14960
  }
13760
- const body = { ...parsed };
14961
+ const body = { ...parsed2 };
13761
14962
  const { CHOOSE_ACCOUNT_HINT: CHOOSE_ACCOUNT_HINT2, resolveCliAuth: resolveCliAuth2, authHeaderValue: authHeaderValue2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
13762
14963
  const auth = resolveCliAuth2();
13763
14964
  if (!auth) {