peachsim 0.1.2408 → 0.1.2409

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 (92) hide show
  1. package/cli/cloud-client.ts +8 -3
  2. package/cli/command-agent.ts +122 -0
  3. package/cli/ws-bridge.ts +4 -1
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +1 -1
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +1 -1
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +1 -1
  16. package/dist-lib/bundle-channel.cjs +9 -7
  17. package/dist-lib/capture-contract.cjs +1 -1
  18. package/dist-lib/capture-contract.mjs +1 -1
  19. package/dist-lib/cloud-contract.cjs +20 -1
  20. package/dist-lib/cloud-contract.mjs +18 -1
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +1 -1
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +1 -1
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/config.mjs +1 -1
  27. package/dist-lib/detox/index.cjs +1630 -1513
  28. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  29. package/dist-lib/expo-swift-bundle.cjs +7 -5
  30. package/dist-lib/expo-swift-metadata.cjs +1 -1
  31. package/dist-lib/expo-swift-metadata.mjs +1 -1
  32. package/dist-lib/home-paths.cjs +1 -1
  33. package/dist-lib/host/bridge-host.cjs +43 -7
  34. package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
  35. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  36. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  37. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  38. package/dist-lib/host/websocket-proxy.cjs +1 -1
  39. package/dist-lib/index.cjs +391 -271
  40. package/dist-lib/jump-to-source-babel.cjs +1 -1
  41. package/dist-lib/jump-to-source-native.cjs +1 -1
  42. package/dist-lib/kotlin-host.cjs +1 -1
  43. package/dist-lib/menu.cjs +1 -1
  44. package/dist-lib/menu.mjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  47. package/dist-lib/metro-production-bundle.cjs +1 -1
  48. package/dist-lib/metro-production-bundle.mjs +1 -1
  49. package/dist-lib/metro.cjs +4 -4
  50. package/dist-lib/native-app-identity-project.cjs +2 -2
  51. package/dist-lib/native-app-identity-project.mjs +2 -2
  52. package/dist-lib/native-app-identity.cjs +1 -1
  53. package/dist-lib/native-app-identity.mjs +1 -1
  54. package/dist-lib/native-firebase-metadata.cjs +1 -1
  55. package/dist-lib/native-firebase-metadata.mjs +1 -1
  56. package/dist-lib/pdfium-raster.cjs +1 -1
  57. package/dist-lib/pdfium-raster.mjs +1 -1
  58. package/dist-lib/plist.cjs +1 -1
  59. package/dist-lib/plist.mjs +1 -1
  60. package/dist-lib/profiles.cjs +1 -1
  61. package/dist-lib/public-brand.cjs +1 -1
  62. package/dist-lib/public-origins-lib-esm.json +24 -24
  63. package/dist-lib/public-origins-lib.json +67 -58
  64. package/dist-lib/react-native-host-modules.cjs +1 -1
  65. package/dist-lib/react-native-host-modules.mjs +1 -1
  66. package/dist-lib/reap-browser.cjs +1 -1
  67. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  68. package/dist-lib/sdk.cjs +1 -1
  69. package/dist-lib/sdk.mjs +1 -1
  70. package/dist-lib/skills.cjs +837 -720
  71. package/dist-lib/swift-compile.cjs +4 -3
  72. package/dist-lib/swift-compile.mjs +4 -3
  73. package/dist-lib/swift-package.cjs +1 -1
  74. package/dist-lib/swift-package.mjs +1 -1
  75. package/dist-lib/swift-submit.cjs +1 -1
  76. package/dist-lib/swift-submit.mjs +1 -1
  77. package/dist-lib/swift-toolchain.cjs +1 -1
  78. package/dist-lib/swift.cjs +1 -1
  79. package/dist-lib/vite-swift.cjs +18 -4
  80. package/dist-lib/vite.cjs +4 -4
  81. package/dist-lib/worklet-executable.cjs +1 -1
  82. package/dist-lib/worklet-executable.mjs +1 -1
  83. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  84. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  85. package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +7 -0
  86. package/kotlin/sdk.tar.gz +0 -0
  87. package/package.json +1 -1
  88. package/runtime-companion.json +1 -1
  89. package/src/bridge-contract.ts +4 -0
  90. package/src/cloud-contract.ts +30 -0
  91. package/src/swift-packages.ts +1 -0
  92. package/src/swift-shared-sdk.ts +2 -1
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2408 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2409 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1173,7 +1173,7 @@ var init_src = __esm({
1173
1173
  var runtime_companion_default;
1174
1174
  var init_runtime_companion = __esm({
1175
1175
  "runtime-companion.json"() {
1176
- runtime_companion_default = { abi: 1, sha256: "7e162f525497b8964ff8f7274ce8219416ec01ac8fc6986a80d2df90a54c71c4", file: "node/cli-7e162f525497b8964ff8f7274ce8219416ec01ac8fc6986a80d2df90a54c71c4.cjs" };
1176
+ runtime_companion_default = { abi: 1, sha256: "f0ebf18540275693f13d5f0638e9e6e2afd2b8a2fa10c6d5c1190341feaa430b", file: "node/cli-f0ebf18540275693f13d5f0638e9e6e2afd2b8a2fa10c6d5c1190341feaa430b.cjs" };
1177
1177
  }
1178
1178
  });
1179
1179
 
@@ -1395,12 +1395,12 @@ function resolveActiveRuntimeRoot() {
1395
1395
  if (!import_fs.default.existsSync(import_path.default.join(dir, "index.html"))) return null;
1396
1396
  return dir;
1397
1397
  }
1398
- function isRuntimeVersionHostname(hostname) {
1399
- return hostname.toLowerCase().endsWith(RUNTIME_VERSION_HOSTNAME_SUFFIX);
1398
+ function isRuntimeVersionHostname(hostname2) {
1399
+ return hostname2.toLowerCase().endsWith(RUNTIME_VERSION_HOSTNAME_SUFFIX);
1400
1400
  }
1401
- function runtimeVersionFromHostname(hostname) {
1402
- if (!isRuntimeVersionHostname(hostname)) return null;
1403
- const labels = hostname.slice(0, -RUNTIME_VERSION_HOSTNAME_SUFFIX.length).split(".");
1401
+ function runtimeVersionFromHostname(hostname2) {
1402
+ if (!isRuntimeVersionHostname(hostname2)) return null;
1403
+ const labels = hostname2.slice(0, -RUNTIME_VERSION_HOSTNAME_SUFFIX.length).split(".");
1404
1404
  if (labels.length === 0 || labels.some((label) => !/^[0-9a-f]{1,60}$/i.test(label))) {
1405
1405
  return null;
1406
1406
  }
@@ -1418,9 +1418,9 @@ function resolveInstalledRuntimeRoot(version) {
1418
1418
  if (!import_fs.default.existsSync(import_path.default.join(dir, "index.html"))) return null;
1419
1419
  return dir;
1420
1420
  }
1421
- function resolveRuntimeRootForHostname(hostname) {
1422
- if (!isRuntimeVersionHostname(hostname)) return resolveActiveRuntimeRoot();
1423
- const version = runtimeVersionFromHostname(hostname);
1421
+ function resolveRuntimeRootForHostname(hostname2) {
1422
+ if (!isRuntimeVersionHostname(hostname2)) return resolveActiveRuntimeRoot();
1423
+ const version = runtimeVersionFromHostname(hostname2);
1424
1424
  return version ? resolveInstalledRuntimeRoot(version) : null;
1425
1425
  }
1426
1426
  function resolveRuntimeRootForRequestHost(host2) {
@@ -1685,19 +1685,19 @@ var init_cli_runtime = __esm({
1685
1685
  });
1686
1686
 
1687
1687
  // src/backend-origin.ts
1688
- function normalizeHostname(hostname) {
1689
- return hostname.replace(/^\[|\]$/g, "").toLowerCase();
1688
+ function normalizeHostname(hostname2) {
1689
+ return hostname2.replace(/^\[|\]$/g, "").toLowerCase();
1690
1690
  }
1691
- function isLoopbackHost(hostname) {
1692
- const normalized = normalizeHostname(hostname);
1691
+ function isLoopbackHost(hostname2) {
1692
+ const normalized = normalizeHostname(hostname2);
1693
1693
  return normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "0.0.0.0" || normalized === "::1" || /^127(?:\.\d{1,3}){3}$/.test(normalized);
1694
1694
  }
1695
1695
  function isTrustedBridgeRequest(headers) {
1696
1696
  const origin = headers.origin;
1697
1697
  if (origin === void 0) return true;
1698
1698
  try {
1699
- const { hostname, host: host2 } = new NativeURL(String(origin));
1700
- return isLoopbackHost(hostname) || [headers.host, headers[":authority"], headers["x-forwarded-host"]].some(
1699
+ const { hostname: hostname2, host: host2 } = new NativeURL(String(origin));
1700
+ return isLoopbackHost(hostname2) || [headers.host, headers[":authority"], headers["x-forwarded-host"]].some(
1701
1701
  (value) => typeof value === "string" && value.toLowerCase() === host2
1702
1702
  );
1703
1703
  } catch {
@@ -7926,7 +7926,7 @@ var STANDIN_SOURCE_DIGEST;
7926
7926
  var init_swift_standin_digest = __esm({
7927
7927
  "src/swift-standin-digest.ts"() {
7928
7928
  "use strict";
7929
- STANDIN_SOURCE_DIGEST = true ? "80b89d414ee068d747a0859811608daad7d3c46ca66f7bf589cc5c82b820de93" : standinSourceDigest();
7929
+ STANDIN_SOURCE_DIGEST = true ? "f2b2c9a5d56b4cc06d8934ce5600587dcf7893acdf17158203975d997dbd387e" : standinSourceDigest();
7930
7930
  }
7931
7931
  });
7932
7932
 
@@ -8174,14 +8174,14 @@ function canonicalLabel(label, from) {
8174
8174
  const { repo, pkg } = splitLabel(from);
8175
8175
  return `${repo ? `@@${repo}` : ""}//${pkg}:${label.replace(/^:/, "")}`;
8176
8176
  }
8177
- function readBazelAppTarget(buildFile, targetName, configurationName, options = {}) {
8178
- if (!targetName)
8177
+ function readBazelAppTarget(buildFile, targetName2, configurationName, options = {}) {
8178
+ if (!targetName2)
8179
8179
  throw new Error(
8180
8180
  `${buildFile}: pass --target with the ios_application the bazel package builds`
8181
8181
  );
8182
8182
  const root = import_node_fs20.default.realpathSync.native(workspaceRoot(import_node_fs20.default.realpathSync.native(buildFile)));
8183
8183
  const pkg = import_node_path19.default.relative(root, import_node_path19.default.dirname(import_node_fs20.default.realpathSync.native(buildFile)));
8184
- const label = `//${pkg.split(import_node_path19.default.sep).join("/")}:${targetName}`;
8184
+ const label = `//${pkg.split(import_node_path19.default.sep).join("/")}:${targetName2}`;
8185
8185
  const configuration = configurationName ?? "Debug";
8186
8186
  const graph = bazelGraph(root, label, configuration);
8187
8187
  const files = new BazelFiles(graph, root);
@@ -8417,7 +8417,7 @@ ${published.map(
8417
8417
  const appModule = {
8418
8418
  ...named,
8419
8419
  id: idOf(graph.app),
8420
- name: targetName,
8420
+ name: targetName2,
8421
8421
  targetIdentity: graph.app.label,
8422
8422
  targetDependencies: [
8423
8423
  ...new Set(appParts.flatMap(({ module: module2 }) => module2.targetDependencies))
@@ -8706,7 +8706,7 @@ ${published.map(
8706
8706
  {
8707
8707
  id: appModule.id,
8708
8708
  sourceTarget: appModule.moduleName,
8709
- productName: `${targetName}.app`,
8709
+ productName: `${targetName2}.app`,
8710
8710
  productType: "com.apple.product-type.application",
8711
8711
  installName: null,
8712
8712
  buildVersion: { platform: "iphonesimulator", minimumOS, sdk: null },
@@ -8750,7 +8750,7 @@ ${published.map(
8750
8750
  binaryFrameworks,
8751
8751
  sdkFrameworks,
8752
8752
  packageResolved: [],
8753
- appTargets: [targetName],
8753
+ appTargets: [targetName2],
8754
8754
  configuration,
8755
8755
  settings: (key) => key === "PRODUCT_MODULE_NAME" ? appModule.moduleName : key === "IPHONEOS_DEPLOYMENT_TARGET" ? minimumOS : key === "PRODUCT_BUNDLE_IDENTIFIER" ? graph.app.attrs.get("bundle_id")?.value ?? "" : "",
8756
8756
  cocoapods: null
@@ -9845,7 +9845,7 @@ function parseBuildSettings(block) {
9845
9845
  }
9846
9846
  return settings;
9847
9847
  }
9848
- function appTargetReleaseSettings(pbxproj, targetName, infoPlistRelativePath) {
9848
+ function appTargetReleaseSettings(pbxproj, targetName2, infoPlistRelativePath) {
9849
9849
  const configurationPattern = /\/\* (Release|Debug) \*\/ = \{/g;
9850
9850
  const candidates = [];
9851
9851
  let match;
@@ -9866,7 +9866,7 @@ function appTargetReleaseSettings(pbxproj, targetName, infoPlistRelativePath) {
9866
9866
  const normalized = plist5.replace(/^"|"$/g, "");
9867
9867
  return normalized === infoPlistRelativePath || infoPlistRelativePath.endsWith(`/${normalized}`) || normalized.endsWith(`/${infoPlistRelativePath}`);
9868
9868
  };
9869
- const named = (settings) => resolveBuildSetting(settings.PRODUCT_NAME ?? "", settings) === targetName;
9869
+ const named = (settings) => resolveBuildSetting(settings.PRODUCT_NAME ?? "", settings) === targetName2;
9870
9870
  return candidates.find(
9871
9871
  (candidate) => candidate.name === "Release" && plistMatch(candidate.settings)
9872
9872
  )?.settings ?? candidates.find(
@@ -9910,31 +9910,31 @@ function nativeAppIdentityFromIos(files, parseInfoPlist, iosTarget, resourceUri)
9910
9910
  applicationTargetNames.add(match[1]);
9911
9911
  }
9912
9912
  }
9913
- let targetName = null;
9913
+ let targetName2 = null;
9914
9914
  if (iosTarget) {
9915
9915
  if (applicationTargetNames.has(iosTarget)) {
9916
- targetName = iosTarget;
9916
+ targetName2 = iosTarget;
9917
9917
  } else {
9918
9918
  return null;
9919
9919
  }
9920
9920
  } else if (applicationTargetNames.size === 1) {
9921
- targetName = [...applicationTargetNames][0];
9921
+ targetName2 = [...applicationTargetNames][0];
9922
9922
  } else if (applicationTargetNames.size > 1) {
9923
9923
  const delegateTargets = Object.keys(files).filter((path37) => !path37.includes("/Pods/")).map((path37) => path37.match(APP_DELEGATE_PATH_RE)?.[1]).filter(
9924
9924
  (name2) => typeof name2 === "string" && applicationTargetNames.has(name2)
9925
9925
  );
9926
9926
  if (delegateTargets.length === 1) {
9927
- targetName = delegateTargets[0];
9927
+ targetName2 = delegateTargets[0];
9928
9928
  } else {
9929
9929
  return null;
9930
9930
  }
9931
9931
  } else {
9932
9932
  return null;
9933
9933
  }
9934
- const selectedTarget = targets.find((t) => t.name === targetName);
9934
+ const selectedTarget = targets.find((t) => t.name === targetName2);
9935
9935
  const settings = {
9936
- TARGET_NAME: targetName,
9937
- PRODUCT_NAME: targetName
9936
+ TARGET_NAME: targetName2,
9937
+ PRODUCT_NAME: targetName2
9938
9938
  };
9939
9939
  for (const obj of Object.values(objects)) {
9940
9940
  if (isRecord(obj) && obj.isa === "PBXProject" && typeof obj.buildConfigurationList === "string") {
@@ -9970,8 +9970,8 @@ function nativeAppIdentityFromIos(files, parseInfoPlist, iosTarget, resourceUri)
9970
9970
  } else {
9971
9971
  const legacy = appTargetReleaseSettings(
9972
9972
  pbxproj,
9973
- targetName,
9974
- `${targetName}/Info.plist`
9973
+ targetName2,
9974
+ `${targetName2}/Info.plist`
9975
9975
  );
9976
9976
  if (legacy) Object.assign(settings, legacy);
9977
9977
  }
@@ -9982,7 +9982,7 @@ function nativeAppIdentityFromIos(files, parseInfoPlist, iosTarget, resourceUri)
9982
9982
  plist5 = files[`ios/${normalized}`] ?? files[normalized] ?? Object.entries(files).find(([k]) => k.endsWith(`/${normalized}`))?.[1];
9983
9983
  }
9984
9984
  if (!plist5) {
9985
- plist5 = files[`ios/${targetName}/Info.plist`] ?? files[`${targetName}/Info.plist`] ?? Object.entries(files).find(([k]) => k.endsWith(`/${targetName}/Info.plist`))?.[1];
9985
+ plist5 = files[`ios/${targetName2}/Info.plist`] ?? files[`${targetName2}/Info.plist`] ?? Object.entries(files).find(([k]) => k.endsWith(`/${targetName2}/Info.plist`))?.[1];
9986
9986
  }
9987
9987
  if (!plist5) return null;
9988
9988
  const bundleIdentifier = identityFieldFrom(
@@ -10006,7 +10006,7 @@ function nativeAppIdentityFromIos(files, parseInfoPlist, iosTarget, resourceUri)
10006
10006
  settings,
10007
10007
  plistString(plist5, "CFBundleName"),
10008
10008
  settings.PRODUCT_NAME
10009
- ) ?? resolvedIdentityField(resolveBuildSetting(settings.PRODUCT_NAME ?? "", settings)) ?? resolvedIdentityField(targetName);
10009
+ ) ?? resolvedIdentityField(resolveBuildSetting(settings.PRODUCT_NAME ?? "", settings)) ?? resolvedIdentityField(targetName2);
10010
10010
  if (!bundleName) return null;
10011
10011
  const applicationName = identityFieldFrom(settings, plistString(plist5, "CFBundleDisplayName"), void 0) ?? bundleName;
10012
10012
  const dictionary = parseInfoPlist(plist5);
@@ -10172,7 +10172,7 @@ function nativeAppIdentityFromIos(files, parseInfoPlist, iosTarget, resourceUri)
10172
10172
  }
10173
10173
  const rootModuleName = readRootModuleName(
10174
10174
  Object.entries(files).filter(
10175
- ([path37]) => !path37.includes("/Pods/") && (/(?:^|\/)(?:ios\/)?AppDelegate\.(?:swift|mm|m)$/.test(path37) || path37.match(APP_DELEGATE_PATH_RE)?.[1] === targetName)
10175
+ ([path37]) => !path37.includes("/Pods/") && (/(?:^|\/)(?:ios\/)?AppDelegate\.(?:swift|mm|m)$/.test(path37) || path37.match(APP_DELEGATE_PATH_RE)?.[1] === targetName2)
10176
10176
  ).map(([, source]) => source)
10177
10177
  );
10178
10178
  return {
@@ -11693,7 +11693,7 @@ var init_swift_compile = __esm({
11693
11693
  FOUNDATION_IMPLICIT_FLAGS = FOUNDATION_IMPLICIT_MODULES.map(
11694
11694
  (module2) => `, "-Xfrontend", "-import-module", "-Xfrontend", "${module2}"`
11695
11695
  ).join("");
11696
- compilerSourceDigest = true ? "36b1496faf39a688e5ab3ee63bdab89a3afde2b9c6355443c3162f4b1e3b9144" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
11696
+ compilerSourceDigest = true ? "d287f3ad479477c70004707c1336f37c9baeb81aef1880544a5ca236e088ca16" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
11697
11697
  C_WORDS = new Set(
11698
11698
  "auto bool break case char const continue default do double else enum extern false float for goto if inline int long register restrict return short signed sizeof static struct switch true typedef union unsigned void volatile while YES NO NULL nil Nil id self super instancetype".split(
11699
11699
  " "
@@ -12168,10 +12168,10 @@ function readXcodeJsonProject(xcodeproj, source) {
12168
12168
  phases.set(`id:${phaseId}`, phaseId);
12169
12169
  }
12170
12170
  }
12171
- const phaseFiles = (reference, targetName) => {
12171
+ const phaseFiles = (reference, targetName2) => {
12172
12172
  const value = text2(reference);
12173
12173
  if (value === void 0) return null;
12174
- const key = value.startsWith("id:") || !targetName ? value : `${targetName}/${value}`;
12174
+ const key = value.startsWith("id:") || !targetName2 ? value : `${targetName2}/${value}`;
12175
12175
  const phase = objects[phases.get(key) ?? ""];
12176
12176
  return phase && typeof phase === "object" && !Array.isArray(phase) && Array.isArray(phase.files) ? phase.files : null;
12177
12177
  };
@@ -12753,7 +12753,7 @@ function fileListEntries(file, absolute) {
12753
12753
  }
12754
12754
  function targetMembers(ref, settings, options, settingKeys, projectInputs) {
12755
12755
  const { project, target, id: targetId } = ref;
12756
- const targetName = str(target.name) ?? targetId;
12756
+ const targetName2 = str(target.name) ?? targetId;
12757
12757
  const sources = /* @__PURE__ */ new Set();
12758
12758
  const allSources = /* @__PURE__ */ new Set();
12759
12759
  const headers = /* @__PURE__ */ new Set();
@@ -12826,7 +12826,7 @@ function targetMembers(ref, settings, options, settingKeys, projectInputs) {
12826
12826
  for (const { file } of lists)
12827
12827
  if (!import_node_fs23.default.existsSync(file))
12828
12828
  throw new Error(
12829
- `${targetName}: Run Script "${script}" missing file list ${file}`
12829
+ `${targetName2}: Run Script "${script}" missing file list ${file}`
12830
12830
  );
12831
12831
  const env = {
12832
12832
  ...process.env,
@@ -12922,7 +12922,7 @@ function targetMembers(ref, settings, options, settingKeys, projectInputs) {
12922
12922
  const output2 = error instanceof Error ? `${error.message}
12923
12923
  ${"stdout" in error ? String(error.stdout) : ""}${"stderr" in error ? String(error.stderr) : ""}` : String(error);
12924
12924
  throw new Error(
12925
- `${targetName}: Run Script "${script}" failed preparing generated outputs:
12925
+ `${targetName2}: Run Script "${script}" failed preparing generated outputs:
12926
12926
  ${output2}`
12927
12927
  );
12928
12928
  }
@@ -12931,7 +12931,7 @@ ${output2}`
12931
12931
  );
12932
12932
  if (missing2.length > 0)
12933
12933
  throw new Error(
12934
- `${targetName}: Run Script "${script}" did not produce ${missing2.join(", ")}`
12934
+ `${targetName2}: Run Script "${script}" did not produce ${missing2.join(", ")}`
12935
12935
  );
12936
12936
  preparedSourcePhases.set(key, stamp);
12937
12937
  preparedXcodePhase(
@@ -12963,7 +12963,7 @@ ${output2}`
12963
12963
  if (options.requireSources === false) return;
12964
12964
  const script = scriptForOutput.get(import_node_path25.default.normalize(file));
12965
12965
  throw new Error(
12966
- script ? `${targetName}: missing generated source ${file} (Run Script "${script}" declares it in outputPaths; run the script or check in its output)` : `${targetName}: missing source ${file}`
12966
+ script ? `${targetName2}: missing generated source ${file} (Run Script "${script}" declares it in outputPaths; run the script or check in its output)` : `${targetName2}: missing source ${file}`
12967
12967
  );
12968
12968
  }
12969
12969
  allSources.add(file);
@@ -12986,7 +12986,7 @@ ${output2}`
12986
12986
  );
12987
12987
  if (runtimeInterfaceFiles.length > 0)
12988
12988
  throw new Error(
12989
- `${targetName}: Interface Builder compilation requires macOS and Xcode`
12989
+ `${targetName2}: Interface Builder compilation requires macOS and Xcode`
12990
12990
  );
12991
12991
  for (const file of interfaceFiles) resources.delete(file);
12992
12992
  interfaceFiles.length = 0;
@@ -13002,7 +13002,7 @@ ${output2}`
13002
13002
  import_node_path25.default.basename(file, import_node_path25.default.extname(file)) + extension
13003
13003
  );
13004
13004
  if (interfaceOutputs.has(output2))
13005
- throw new Error(`${targetName}: duplicate Interface Builder output ${output2}`);
13005
+ throw new Error(`${targetName2}: duplicate Interface Builder output ${output2}`);
13006
13006
  interfaceOutputs.add(output2);
13007
13007
  const args = [
13008
13008
  "ibtool",
@@ -13044,7 +13044,7 @@ ${output2}`
13044
13044
  );
13045
13045
  if (definitions.length > 0 && process.platform !== "darwin")
13046
13046
  throw new Error(
13047
- `${targetName}: intent definition code generation requires macOS and Xcode`
13047
+ `${targetName2}: intent definition code generation requires macOS and Xcode`
13048
13048
  );
13049
13049
  for (const definition of definitions) {
13050
13050
  const configuredLanguage = settings("INTENTS_CODEGEN_LANGUAGE");
@@ -13289,8 +13289,8 @@ function readXcodeScheme(xcodeprojOrWorkspace, scheme) {
13289
13289
  if (!name2) {
13290
13290
  const declared = (project ? [project] : projects).flatMap(
13291
13291
  (candidate) => projectTargets(candidate).flatMap((ref) => {
13292
- const targetName = str(ref.target.name);
13293
- return targetName ? [targetName] : [];
13292
+ const targetName2 = str(ref.target.name);
13293
+ return targetName2 ? [targetName2] : [];
13294
13294
  })
13295
13295
  );
13296
13296
  throw new Error(
@@ -13375,9 +13375,9 @@ function selectIosAppTarget(projectRoot, iosTarget) {
13375
13375
  );
13376
13376
  return { xcodeproj, target, workspace: project.workspace };
13377
13377
  }
13378
- function readXcodeAppTarget(input, targetName, configurationName, options = {}) {
13378
+ function readXcodeAppTarget(input, targetName2, configurationName, options = {}) {
13379
13379
  if (isBazelPackage(input))
13380
- return readBazelAppTarget(input, targetName, configurationName, options);
13380
+ return readBazelAppTarget(input, targetName2, configurationName, options);
13381
13381
  const xcodeprojOrWorkspace = import_node_fs23.default.realpathSync.native(input);
13382
13382
  const workspace = xcodeprojOrWorkspace.endsWith(".xcworkspace") ? xcodeprojOrWorkspace : null;
13383
13383
  const { listed, projects, projectAt, cocoapods } = workspaceProjects(
@@ -13386,18 +13386,18 @@ function readXcodeAppTarget(input, targetName, configurationName, options = {})
13386
13386
  );
13387
13387
  const allTargets = projects.flatMap(projectTargets);
13388
13388
  const appTargets = allTargets.filter(
13389
- (ref) => isIosAppTarget(ref, options) || targetName !== void 0 && ref.target.name === targetName && ref.target.productType === APP_EXTENSION
13389
+ (ref) => isIosAppTarget(ref, options) || targetName2 !== void 0 && ref.target.name === targetName2 && ref.target.productType === APP_EXTENSION
13390
13390
  );
13391
13391
  const appTargetNames = appTargets.map((ref) => str(ref.target.name) ?? ref.id);
13392
13392
  const container = import_node_path25.default.basename(xcodeprojOrWorkspace);
13393
- const named = targetName ? appTargets.filter((ref) => ref.target.name === targetName) : appTargets;
13393
+ const named = targetName2 ? appTargets.filter((ref) => ref.target.name === targetName2) : appTargets;
13394
13394
  if (named.length !== 1) {
13395
13395
  if (appTargets.length === 0)
13396
13396
  throw new Error(
13397
13397
  `${container} has no application targets; open a project or workspace that contains one`
13398
13398
  );
13399
13399
  throw new Error(
13400
- targetName && named.length === 0 ? `${container} has no application target ${targetName}; it has ${appTargetNames.join(", ") || "none"}` : targetName ? `${container} has ${named.length} application targets named ${targetName}; open its .xcodeproj` : `${container} has ${appTargetNames.length} application targets (${appTargetNames.join(", ")}); pass --target`
13400
+ targetName2 && named.length === 0 ? `${container} has no application target ${targetName2}; it has ${appTargetNames.join(", ") || "none"}` : targetName2 ? `${container} has ${named.length} application targets named ${targetName2}; open its .xcodeproj` : `${container} has ${appTargetNames.length} application targets (${appTargetNames.join(", ")}); pass --target`
13401
13401
  );
13402
13402
  }
13403
13403
  const app = named[0];
@@ -16416,6 +16416,7 @@ init_backend_origin();
16416
16416
  init_cli_runtime();
16417
16417
 
16418
16418
  // src/cloud-contract.ts
16419
+ var AGENT_IDENTITY_MAX_CHARS = 200;
16419
16420
  var RNX_CLOUD_DESIGN_MAX_STORAGE_BYTES = 1024 * 1024;
16420
16421
  var RNX_CLOUD_COMMAND_SCOPES = {
16421
16422
  state: "read",
@@ -16734,218 +16735,21 @@ function readCloudSession() {
16734
16735
  return parseCloudSession(saved.session);
16735
16736
  }
16736
16737
 
16737
- // cli/cloud-client.ts
16738
- init_detect();
16739
- var DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin;
16740
- function failureSentence(text3) {
16741
- let parsed;
16742
- try {
16743
- parsed = JSON.parse(text3);
16744
- } catch {
16745
- return null;
16746
- }
16747
- if (!isRecord(parsed)) return null;
16748
- if (isRecord(parsed.error) && typeof parsed.error.message === "string") {
16749
- const code = typeof parsed.error.code === "string" && parsed.error.code ? ` [${parsed.error.code}]` : "";
16750
- return `${parsed.error.message}${code}`;
16751
- }
16752
- if (typeof parsed.message === "string") return parsed.message;
16753
- if (typeof parsed.error === "string") return parsed.error;
16754
- return null;
16755
- }
16756
- var ACCOUNT_CHOICE_REFUSALS = /* @__PURE__ */ new Set([
16757
- "accountId is required",
16758
- "you do not have access to this account"
16759
- ]);
16760
- function responseError(status, text3) {
16761
- const parsed = text3 ? failureSentence(text3) : null;
16762
- const sentence = parsed && ACCOUNT_CHOICE_REFUSALS.has(parsed) ? CHOOSE_ACCOUNT_HINT : parsed;
16763
- const hint = parsed?.endsWith(" requires the debug scope") ? "; this command needs debug access, which a remote simulator does not grant, so run it against a local sim" : "";
16764
- return new Error(
16765
- `remote simulator request failed (${status})${sentence ? `: ${sentence}${hint}` : text3.trim() ? `: ${text3.trim()}` : ""}`
16766
- );
16767
- }
16768
- function resolveCloudSessionForParsed(parsed) {
16769
- const session = readCloudSession();
16770
- if (!session) return null;
16771
- if (session.service === "box") {
16772
- if (parsed.simIdSource === "flag" && parsed.simId !== session.boxId) {
16773
- throw new Error(
16774
- `this shell is connected to box ${session.boxId}; ${parsed.simId ? `--sim ${parsed.simId}` : "the requested simulator"} is not available in this shell`
16775
- );
16776
- }
16777
- return session;
16778
- }
16779
- if (parsed.simIdSource === "flag" && parsed.simId !== session.simId) {
16780
- throw new Error(
16781
- `this shell is connected to remote simulator ${session.simId}; ${parsed.simId ? `--sim ${parsed.simId}` : "the requested simulator"} is not available in this shell`
16782
- );
16783
- }
16784
- return session;
16785
- }
16786
- function cloudCommand(command) {
16787
- const clean = {};
16788
- for (const [key, value] of Object.entries(command)) {
16789
- if (key !== "id" && key !== "simId") clean[key] = value;
16790
- }
16791
- if (!isRnxCloudCommandType(command.type)) {
16792
- throw new Error(
16793
- `a remote simulator does not support bridge command type ${command.type}`
16794
- );
16795
- }
16796
- if (!rnxCloudScopesAllowCommand(RNX_CLOUD_TOKEN_SCOPES, command.type)) {
16797
- throw new Error(
16798
- `a remote simulator command ${command.type} requires the ${rnxCloudCommandScope(command.type)} scope`
16799
- );
16800
- }
16801
- return clean;
16802
- }
16803
- var REMOTE_HAS_NO_LOCAL_SIMS = "Peach commands here go to your remote simulator, which has no local simulators; run `peach close` to end it, or run this from another folder";
16804
- var CloudBridge = class {
16805
- constructor(session, explicitTimeoutMs) {
16806
- this.session = session;
16807
- this.explicitTimeoutMs = explicitTimeoutMs;
16808
- }
16809
- plane = "cloud";
16810
- async send(command, options) {
16811
- const timeoutMs = options?.timeoutMs ?? this.explicitTimeoutMs ?? options?.defaultTimeoutMs;
16812
- const body = {
16813
- id: (0, import_node_crypto5.randomUUID)(),
16814
- claimId: this.session.claimId,
16815
- command: cloudCommand(command)
16816
- };
16817
- let response;
16818
- try {
16819
- response = await fetch(
16820
- `${this.session.apiOrigin}/v1/sims/${encodeURIComponent(this.session.simId)}/commands`,
16821
- {
16822
- method: "POST",
16823
- headers: {
16824
- authorization: `Bearer ${this.session.token}`,
16825
- "content-type": "application/json"
16826
- },
16827
- body: JSON.stringify(body),
16828
- ...timeoutMs ? { signal: AbortSignal.timeout(timeoutMs) } : {}
16829
- }
16830
- );
16831
- } catch (error) {
16832
- throw new Error(
16833
- `could not reach the remote simulator at ${this.session.apiOrigin}: ${error instanceof Error ? error.message : String(error)}`
16834
- );
16835
- }
16836
- const text3 = await response.text();
16837
- if (!response.ok) throw responseError(response.status, text3);
16838
- let parsed;
16839
- try {
16840
- parsed = JSON.parse(text3);
16841
- } catch {
16842
- throw new Error("remote simulator command returned unreadable JSON");
16843
- }
16844
- if (!isRecord(parsed) || parsed.id !== body.id) {
16845
- throw new Error("remote simulator command returned an invalid command receipt");
16846
- }
16847
- if (typeof parsed.error === "string" && parsed.error) throw new Error(parsed.error);
16848
- if (!Object.hasOwn(parsed, "result")) {
16849
- throw new Error("remote simulator command receipt has no result");
16850
- }
16851
- return parsed.result;
16852
- }
16853
- listSims() {
16854
- return Promise.reject(new Error(REMOTE_HAS_NO_LOCAL_SIMS));
16855
- }
16856
- focusSim() {
16857
- return Promise.reject(new Error("remote simulators have no browser window to focus"));
16858
- }
16859
- resolveReloadedSim() {
16860
- return Promise.resolve(null);
16861
- }
16862
- closeSim() {
16863
- return Promise.reject(
16864
- new Error("remote simulator close uses the simulator DELETE route")
16865
- );
16866
- }
16867
- claim() {
16868
- return Promise.reject(
16869
- new Error("remote simulator claim uses the simulator claim route")
16870
- );
16871
- }
16872
- close() {
16873
- }
16874
- };
16875
- var CloudBoxBridge = class {
16876
- constructor(session, explicitTimeoutMs) {
16877
- this.session = session;
16878
- this.explicitTimeoutMs = explicitTimeoutMs;
16879
- }
16880
- plane = "cloud";
16881
- async send(command, options) {
16882
- const timeoutMs = options?.timeoutMs ?? this.explicitTimeoutMs ?? options?.defaultTimeoutMs;
16883
- const id = (0, import_node_crypto5.randomUUID)();
16884
- const payload = {};
16885
- for (const [key, value] of Object.entries(command)) {
16886
- if (key !== "id" && key !== "simId") payload[key] = value;
16887
- }
16888
- let response;
16889
- try {
16890
- response = await fetch(
16891
- `${this.session.apiOrigin}/v1/boxes/${encodeURIComponent(this.session.boxId)}/commands`,
16892
- {
16893
- method: "POST",
16894
- headers: {
16895
- authorization: `Bearer ${this.session.boxToken}`,
16896
- "content-type": "application/json"
16897
- },
16898
- body: JSON.stringify({ id, command: payload }),
16899
- ...timeoutMs ? { signal: AbortSignal.timeout(timeoutMs) } : {}
16900
- }
16901
- );
16902
- } catch (error) {
16903
- throw new Error(
16904
- `could not reach box ${this.session.boxId} at ${this.session.apiOrigin}: ${error instanceof Error ? error.message : String(error)}`
16905
- );
16906
- }
16907
- const text3 = await response.text();
16908
- if (!response.ok) throw responseError(response.status, text3);
16909
- let parsed;
16910
- try {
16911
- parsed = JSON.parse(text3);
16912
- } catch {
16913
- throw new Error("box command returned unreadable JSON");
16914
- }
16915
- if (!isRecord(parsed) || parsed.id !== id) {
16916
- throw new Error("box command returned an invalid command receipt");
16917
- }
16918
- if (typeof parsed.error === "string" && parsed.error) throw new Error(parsed.error);
16919
- if (!Object.hasOwn(parsed, "result")) {
16920
- throw new Error("box command receipt has no result");
16921
- }
16922
- return parsed.result;
16923
- }
16924
- listSims() {
16925
- return Promise.reject(new Error(REMOTE_HAS_NO_LOCAL_SIMS));
16926
- }
16927
- focusSim() {
16928
- return Promise.reject(new Error("a box simulator has no browser window to focus"));
16929
- }
16930
- resolveReloadedSim() {
16931
- return Promise.resolve(null);
16932
- }
16933
- closeSim() {
16934
- return Promise.reject(new Error("close a box simulator with peach box stop"));
16935
- }
16936
- claim() {
16937
- return Promise.reject(
16938
- new Error("a box simulator is held by its Box page and has nothing to claim")
16939
- );
16940
- }
16941
- close() {
16738
+ // cli/command-agent.ts
16739
+ var import_os2 = require("os");
16740
+
16741
+ // ../peach-kit/src/agent-identity.ts
16742
+ function formatLockOwner(owner) {
16743
+ const colon = owner.indexOf(":");
16744
+ if (colon <= 0) return owner.length > 24 ? `${owner.slice(0, 21)}\u2026` : owner;
16745
+ const source = owner.slice(0, colon);
16746
+ const value = owner.slice(colon + 1);
16747
+ if (source === "PEACH_CLI_IDENTITY" && value) return value;
16748
+ const short = value.length > 12 ? `${value.slice(0, 8)}\u2026` : value;
16749
+ if (source === "CLAUDE_CODE_SESSION_ID" || source === "CODEX_THREAD_ID") {
16750
+ return `agent ${short}`;
16942
16751
  }
16943
- };
16944
- function createCloudBridgeForParsed(parsed) {
16945
- const session = resolveCloudSessionForParsed(parsed);
16946
- if (!session) return null;
16947
- const timeoutMs = parsed.explicitTimeout ? parsed.commandTimeoutMs : void 0;
16948
- return session.service === "box" ? new CloudBoxBridge(session, timeoutMs) : new CloudBridge(session, timeoutMs);
16752
+ return `${source} ${short}`;
16949
16753
  }
16950
16754
 
16951
16755
  // cli/current-sim.ts
@@ -17342,6 +17146,320 @@ function isOpenPending() {
17342
17146
  }
17343
17147
  }
17344
17148
 
17149
+ // cli/command-agent.ts
17150
+ function clip(text3) {
17151
+ return text3.length > AGENT_IDENTITY_MAX_CHARS ? `${text3.slice(0, AGENT_IDENTITY_MAX_CHARS - 1)}\u2026` : text3;
17152
+ }
17153
+ function targetName(target) {
17154
+ const name2 = target?.text?.trim() || target?.testID?.trim() || target?.id?.trim();
17155
+ return name2 ? name2.replace(/\s+/g, " ") : null;
17156
+ }
17157
+ function verb(action, target) {
17158
+ return target ? `${action} ${target}` : action;
17159
+ }
17160
+ function describeStep(step) {
17161
+ switch (step.type) {
17162
+ case "tap":
17163
+ return verb("Tapping", targetName(step.target));
17164
+ case "tapId":
17165
+ return verb("Tapping", step.id);
17166
+ case "doubleTap":
17167
+ return "Double tapping";
17168
+ case "longPress":
17169
+ return verb("Long pressing", targetName(step.target));
17170
+ case "drag":
17171
+ return "Dragging";
17172
+ case "pinch":
17173
+ return "Pinching";
17174
+ case "scroll":
17175
+ return verb("Scrolling", step.id);
17176
+ case "touchDown":
17177
+ case "touchMove":
17178
+ case "touchUp":
17179
+ case "touchCancel":
17180
+ return "Touching the screen";
17181
+ case "type":
17182
+ case "typeInto":
17183
+ case "setElementValue":
17184
+ return "Typing";
17185
+ case "key":
17186
+ case "keyDown":
17187
+ case "keyUp":
17188
+ return "Pressing a key";
17189
+ case "dismissKeyboard":
17190
+ case "toggleKeyboard":
17191
+ return "Using the keyboard";
17192
+ case "openUrl":
17193
+ return "Opening a link";
17194
+ case "setOrientation":
17195
+ return `Rotating to ${step.orientation}`;
17196
+ case "incrementElement":
17197
+ case "decrementElement":
17198
+ return verb("Adjusting", step.id);
17199
+ case "buttonDown":
17200
+ case "buttonUp":
17201
+ case "wait":
17202
+ case "waitFor":
17203
+ case "deviceInfo":
17204
+ case "discoverStoreKitConfig":
17205
+ case "clearStoreKitConfig":
17206
+ return null;
17207
+ }
17208
+ }
17209
+ function describeCommand(command) {
17210
+ switch (command.type) {
17211
+ case "tap":
17212
+ return verb("Tapping", targetName(command.target));
17213
+ case "longPress":
17214
+ return verb("Long pressing", targetName(command.target));
17215
+ case "keyboard":
17216
+ return command.action === "dismiss" ? "Dismissing the keyboard" : command.action === "press" || command.action === "dispatchKey" ? "Pressing a key" : "Typing";
17217
+ case "screenshot":
17218
+ return "Taking a screenshot";
17219
+ case "perform": {
17220
+ const labels = (command.steps ?? []).flatMap((step) => describeStep(step) ?? []);
17221
+ const [first] = labels;
17222
+ if (!first) return null;
17223
+ return labels.length === 1 ? first : `${first}, then ${labels.length - 1} more`;
17224
+ }
17225
+ default:
17226
+ return null;
17227
+ }
17228
+ }
17229
+ function commandAgent(command) {
17230
+ const step = describeCommand(command);
17231
+ if (!step) return void 0;
17232
+ const identity2 = getCliIdentity();
17233
+ if (!identity2.stable) return void 0;
17234
+ const machine = (0, import_os2.hostname)().split(".")[0];
17235
+ if (!machine) return void 0;
17236
+ return {
17237
+ id: clip(identity2.key),
17238
+ name: clip(
17239
+ readAgentId() ?? (process.env.PEACH_AGENT_ID?.trim() || formatLockOwner(identity2.key))
17240
+ ),
17241
+ machine: clip(machine),
17242
+ step: clip(step)
17243
+ };
17244
+ }
17245
+
17246
+ // cli/cloud-client.ts
17247
+ init_detect();
17248
+ var DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin;
17249
+ function failureSentence(text3) {
17250
+ let parsed;
17251
+ try {
17252
+ parsed = JSON.parse(text3);
17253
+ } catch {
17254
+ return null;
17255
+ }
17256
+ if (!isRecord(parsed)) return null;
17257
+ if (isRecord(parsed.error) && typeof parsed.error.message === "string") {
17258
+ const code = typeof parsed.error.code === "string" && parsed.error.code ? ` [${parsed.error.code}]` : "";
17259
+ return `${parsed.error.message}${code}`;
17260
+ }
17261
+ if (typeof parsed.message === "string") return parsed.message;
17262
+ if (typeof parsed.error === "string") return parsed.error;
17263
+ return null;
17264
+ }
17265
+ var ACCOUNT_CHOICE_REFUSALS = /* @__PURE__ */ new Set([
17266
+ "accountId is required",
17267
+ "you do not have access to this account"
17268
+ ]);
17269
+ function responseError(status, text3) {
17270
+ const parsed = text3 ? failureSentence(text3) : null;
17271
+ const sentence = parsed && ACCOUNT_CHOICE_REFUSALS.has(parsed) ? CHOOSE_ACCOUNT_HINT : parsed;
17272
+ const hint = parsed?.endsWith(" requires the debug scope") ? "; this command needs debug access, which a remote simulator does not grant, so run it against a local sim" : "";
17273
+ return new Error(
17274
+ `remote simulator request failed (${status})${sentence ? `: ${sentence}${hint}` : text3.trim() ? `: ${text3.trim()}` : ""}`
17275
+ );
17276
+ }
17277
+ function resolveCloudSessionForParsed(parsed) {
17278
+ const session = readCloudSession();
17279
+ if (!session) return null;
17280
+ if (session.service === "box") {
17281
+ if (parsed.simIdSource === "flag" && parsed.simId !== session.boxId) {
17282
+ throw new Error(
17283
+ `this shell is connected to box ${session.boxId}; ${parsed.simId ? `--sim ${parsed.simId}` : "the requested simulator"} is not available in this shell`
17284
+ );
17285
+ }
17286
+ return session;
17287
+ }
17288
+ if (parsed.simIdSource === "flag" && parsed.simId !== session.simId) {
17289
+ throw new Error(
17290
+ `this shell is connected to remote simulator ${session.simId}; ${parsed.simId ? `--sim ${parsed.simId}` : "the requested simulator"} is not available in this shell`
17291
+ );
17292
+ }
17293
+ return session;
17294
+ }
17295
+ function cloudCommand(command) {
17296
+ const clean = {};
17297
+ for (const [key, value] of Object.entries(command)) {
17298
+ if (key !== "id" && key !== "simId") clean[key] = value;
17299
+ }
17300
+ if (!isRnxCloudCommandType(command.type)) {
17301
+ throw new Error(
17302
+ `a remote simulator does not support bridge command type ${command.type}`
17303
+ );
17304
+ }
17305
+ if (!rnxCloudScopesAllowCommand(RNX_CLOUD_TOKEN_SCOPES, command.type)) {
17306
+ throw new Error(
17307
+ `a remote simulator command ${command.type} requires the ${rnxCloudCommandScope(command.type)} scope`
17308
+ );
17309
+ }
17310
+ return clean;
17311
+ }
17312
+ var REMOTE_HAS_NO_LOCAL_SIMS = "Peach commands here go to your remote simulator, which has no local simulators; run `peach close` to end it, or run this from another folder";
17313
+ var CloudBridge = class {
17314
+ constructor(session, explicitTimeoutMs) {
17315
+ this.session = session;
17316
+ this.explicitTimeoutMs = explicitTimeoutMs;
17317
+ }
17318
+ plane = "cloud";
17319
+ async send(command, options) {
17320
+ const timeoutMs = options?.timeoutMs ?? this.explicitTimeoutMs ?? options?.defaultTimeoutMs;
17321
+ const agent = commandAgent(command);
17322
+ const body = {
17323
+ id: (0, import_node_crypto5.randomUUID)(),
17324
+ claimId: this.session.claimId,
17325
+ command: cloudCommand(agent ? { ...command, agent } : command)
17326
+ };
17327
+ let response;
17328
+ try {
17329
+ response = await fetch(
17330
+ `${this.session.apiOrigin}/v1/sims/${encodeURIComponent(this.session.simId)}/commands`,
17331
+ {
17332
+ method: "POST",
17333
+ headers: {
17334
+ authorization: `Bearer ${this.session.token}`,
17335
+ "content-type": "application/json"
17336
+ },
17337
+ body: JSON.stringify(body),
17338
+ ...timeoutMs ? { signal: AbortSignal.timeout(timeoutMs) } : {}
17339
+ }
17340
+ );
17341
+ } catch (error) {
17342
+ throw new Error(
17343
+ `could not reach the remote simulator at ${this.session.apiOrigin}: ${error instanceof Error ? error.message : String(error)}`
17344
+ );
17345
+ }
17346
+ const text3 = await response.text();
17347
+ if (!response.ok) throw responseError(response.status, text3);
17348
+ let parsed;
17349
+ try {
17350
+ parsed = JSON.parse(text3);
17351
+ } catch {
17352
+ throw new Error("remote simulator command returned unreadable JSON");
17353
+ }
17354
+ if (!isRecord(parsed) || parsed.id !== body.id) {
17355
+ throw new Error("remote simulator command returned an invalid command receipt");
17356
+ }
17357
+ if (typeof parsed.error === "string" && parsed.error) throw new Error(parsed.error);
17358
+ if (!Object.hasOwn(parsed, "result")) {
17359
+ throw new Error("remote simulator command receipt has no result");
17360
+ }
17361
+ return parsed.result;
17362
+ }
17363
+ listSims() {
17364
+ return Promise.reject(new Error(REMOTE_HAS_NO_LOCAL_SIMS));
17365
+ }
17366
+ focusSim() {
17367
+ return Promise.reject(new Error("remote simulators have no browser window to focus"));
17368
+ }
17369
+ resolveReloadedSim() {
17370
+ return Promise.resolve(null);
17371
+ }
17372
+ closeSim() {
17373
+ return Promise.reject(
17374
+ new Error("remote simulator close uses the simulator DELETE route")
17375
+ );
17376
+ }
17377
+ claim() {
17378
+ return Promise.reject(
17379
+ new Error("remote simulator claim uses the simulator claim route")
17380
+ );
17381
+ }
17382
+ close() {
17383
+ }
17384
+ };
17385
+ var CloudBoxBridge = class {
17386
+ constructor(session, explicitTimeoutMs) {
17387
+ this.session = session;
17388
+ this.explicitTimeoutMs = explicitTimeoutMs;
17389
+ }
17390
+ plane = "cloud";
17391
+ async send(command, options) {
17392
+ const timeoutMs = options?.timeoutMs ?? this.explicitTimeoutMs ?? options?.defaultTimeoutMs;
17393
+ const id = (0, import_node_crypto5.randomUUID)();
17394
+ const payload = {};
17395
+ for (const [key, value] of Object.entries(command)) {
17396
+ if (key !== "id" && key !== "simId") payload[key] = value;
17397
+ }
17398
+ const agent = commandAgent(command);
17399
+ if (agent) payload.agent = agent;
17400
+ let response;
17401
+ try {
17402
+ response = await fetch(
17403
+ `${this.session.apiOrigin}/v1/boxes/${encodeURIComponent(this.session.boxId)}/commands`,
17404
+ {
17405
+ method: "POST",
17406
+ headers: {
17407
+ authorization: `Bearer ${this.session.boxToken}`,
17408
+ "content-type": "application/json"
17409
+ },
17410
+ body: JSON.stringify({ id, command: payload }),
17411
+ ...timeoutMs ? { signal: AbortSignal.timeout(timeoutMs) } : {}
17412
+ }
17413
+ );
17414
+ } catch (error) {
17415
+ throw new Error(
17416
+ `could not reach box ${this.session.boxId} at ${this.session.apiOrigin}: ${error instanceof Error ? error.message : String(error)}`
17417
+ );
17418
+ }
17419
+ const text3 = await response.text();
17420
+ if (!response.ok) throw responseError(response.status, text3);
17421
+ let parsed;
17422
+ try {
17423
+ parsed = JSON.parse(text3);
17424
+ } catch {
17425
+ throw new Error("box command returned unreadable JSON");
17426
+ }
17427
+ if (!isRecord(parsed) || parsed.id !== id) {
17428
+ throw new Error("box command returned an invalid command receipt");
17429
+ }
17430
+ if (typeof parsed.error === "string" && parsed.error) throw new Error(parsed.error);
17431
+ if (!Object.hasOwn(parsed, "result")) {
17432
+ throw new Error("box command receipt has no result");
17433
+ }
17434
+ return parsed.result;
17435
+ }
17436
+ listSims() {
17437
+ return Promise.reject(new Error(REMOTE_HAS_NO_LOCAL_SIMS));
17438
+ }
17439
+ focusSim() {
17440
+ return Promise.reject(new Error("a box simulator has no browser window to focus"));
17441
+ }
17442
+ resolveReloadedSim() {
17443
+ return Promise.resolve(null);
17444
+ }
17445
+ closeSim() {
17446
+ return Promise.reject(new Error("close a box simulator with peach box stop"));
17447
+ }
17448
+ claim() {
17449
+ return Promise.reject(
17450
+ new Error("a box simulator is held by its Box page and has nothing to claim")
17451
+ );
17452
+ }
17453
+ close() {
17454
+ }
17455
+ };
17456
+ function createCloudBridgeForParsed(parsed) {
17457
+ const session = resolveCloudSessionForParsed(parsed);
17458
+ if (!session) return null;
17459
+ const timeoutMs = parsed.explicitTimeout ? parsed.commandTimeoutMs : void 0;
17460
+ return session.service === "box" ? new CloudBoxBridge(session, timeoutMs) : new CloudBridge(session, timeoutMs);
17461
+ }
17462
+
17345
17463
  // cli/ws-bridge.ts
17346
17464
  var import_node_fs12 = __toESM(require("node:fs"), 1);
17347
17465
  var import_node_path10 = __toESM(require("node:path"), 1);
@@ -17844,12 +17962,14 @@ function createBridge(wsPort, opts = {}) {
17844
17962
  plane: "local",
17845
17963
  async send(cmd, callOpts) {
17846
17964
  const effectiveTimeoutMs = callOpts?.timeoutMs ?? (opts.explicitTimeout ? commandTimeoutMs : callOpts?.defaultTimeoutMs) ?? commandTimeoutMs;
17965
+ const agent = commandAgent(cmd);
17966
+ const sent = agent ? { ...cmd, agent } : cmd;
17847
17967
  const sendOnce = async (defaultSimId, cmdOverride) => {
17848
17968
  await ready;
17849
17969
  if (terminalError) throw terminalError;
17850
17970
  const id = nextId++;
17851
17971
  return new Promise((resolve5, reject) => {
17852
- const payload = { ...cmdOverride ?? cmd, id };
17972
+ const payload = { ...cmdOverride ?? sent, id };
17853
17973
  if (payload.simId === void 0 && defaultSimId) {
17854
17974
  payload.simId = defaultSimId;
17855
17975
  }
@@ -25913,8 +26033,8 @@ var HOST_HEADER_OVERRIDES = [
25913
26033
  }
25914
26034
  }
25915
26035
  ];
25916
- function headerOverridesFor(hostname) {
25917
- const host2 = hostname.toLowerCase();
26036
+ function headerOverridesFor(hostname2) {
26037
+ const host2 = hostname2.toLowerCase();
25918
26038
  for (const override of HOST_HEADER_OVERRIDES) {
25919
26039
  if (host2 === override.hostSuffix || host2.endsWith(`.${override.hostSuffix}`)) {
25920
26040
  return override;
@@ -26214,8 +26334,8 @@ for (const pair of process.env.PEACH_LOOPBACK_PORTS?.split(",").filter(Boolean)
26214
26334
  }
26215
26335
  LOOPBACK_PORTS.set(from, to);
26216
26336
  }
26217
- function projectLoopbackPort(hostname, port) {
26218
- return isLoopbackHost(hostname) ? LOOPBACK_PORTS.get(port) ?? port : port;
26337
+ function projectLoopbackPort(hostname2, port) {
26338
+ return isLoopbackHost(hostname2) ? LOOPBACK_PORTS.get(port) ?? port : port;
26219
26339
  }
26220
26340
  function projectLoopbackUrl(value) {
26221
26341
  if (LOOPBACK_PORTS.size === 0) return value;