peachsim 0.1.2438 → 0.1.2439

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 (175) hide show
  1. package/README.md +30 -98
  2. package/cli/app-catalog.ts +4 -73
  3. package/cli/catalog/content.ts +1 -1
  4. package/cli/cloud-box-artifact.ts +26 -39
  5. package/cli/cloud-client.ts +69 -117
  6. package/cli/cloud-session.ts +2 -9
  7. package/cli/commands/box.ts +6 -6
  8. package/cli/commands/control.ts +4 -11
  9. package/cli/commands/flow.ts +5 -9
  10. package/cli/commands/kotlin.ts +2 -1
  11. package/cli/commands/platform.ts +21 -39
  12. package/cli/commands/record-three.ts +1 -1
  13. package/cli/commands/shell-url.ts +29 -23
  14. package/cli/dev-build-freshness.ts +4 -3
  15. package/cli/native-input.ts +2 -2
  16. package/cli/outbound-endpoints.ts +20 -45
  17. package/cli/remote-project-bundle.ts +8 -14
  18. package/cli/remote-simulators.ts +1 -1
  19. package/cli/send-to-box.ts +2 -1
  20. package/detox/jest-preset.cjs +1 -1
  21. package/detox/jest-transform.cjs +40 -2
  22. package/dist-lib/agent-daemon-client.cjs +34 -24
  23. package/dist-lib/agent-events.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +19 -17
  25. package/dist-lib/auth/shared-session.cjs +18 -16
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +2 -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 +20 -583
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +17 -99
  34. package/dist-lib/bundle-channel.cjs +8718 -5552
  35. package/dist-lib/capture-contract.cjs +1 -1
  36. package/dist-lib/capture-contract.mjs +13 -363
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +34 -155
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +2 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +26 -155
  43. package/dist-lib/config.cjs +1 -4
  44. package/dist-lib/config.mjs +11 -30
  45. package/dist-lib/detox/index.cjs +2554 -230
  46. package/dist-lib/detox/jest-preset.cjs +1 -1
  47. package/dist-lib/detox/jest-transform.cjs +40 -2
  48. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  49. package/dist-lib/esm-chunks/acorn-FGE4PYDJ.mjs +50 -0
  50. package/dist-lib/esm-chunks/chunk-2EUHEBIJ.mjs +664 -0
  51. package/dist-lib/esm-chunks/chunk-2NPABFPN.mjs +5719 -0
  52. package/dist-lib/esm-chunks/chunk-4ZFNH7TU.mjs +10 -0
  53. package/dist-lib/esm-chunks/chunk-5T4XBUJP.mjs +1353 -0
  54. package/dist-lib/esm-chunks/chunk-6VY6HTJC.mjs +18951 -0
  55. package/dist-lib/esm-chunks/chunk-7HANEMO4.mjs +188 -0
  56. package/dist-lib/esm-chunks/chunk-C3WBGYP6.mjs +186 -0
  57. package/dist-lib/esm-chunks/chunk-CVGDRROP.mjs +57 -0
  58. package/dist-lib/esm-chunks/chunk-DADGQELM.mjs +375 -0
  59. package/dist-lib/esm-chunks/chunk-DEGYKHN7.mjs +12 -0
  60. package/dist-lib/esm-chunks/chunk-HIDNO3RP.mjs +10992 -0
  61. package/dist-lib/esm-chunks/chunk-HSADZOVN.mjs +30 -0
  62. package/dist-lib/esm-chunks/chunk-IWJUYJQO.mjs +42 -0
  63. package/dist-lib/esm-chunks/chunk-JCKI3VZ6.mjs +10 -0
  64. package/dist-lib/esm-chunks/chunk-KSQ5KM5Y.mjs +17 -0
  65. package/dist-lib/esm-chunks/chunk-KVTIDLBK.mjs +598 -0
  66. package/dist-lib/esm-chunks/chunk-MIQSRBVU.mjs +10 -0
  67. package/dist-lib/esm-chunks/chunk-YB27R6JG.mjs +115 -0
  68. package/dist-lib/esm-chunks/metro-layout-parser-MVUAXRUJ.mjs +58 -0
  69. package/dist-lib/expo-swift-bundle.cjs +7856 -4707
  70. package/dist-lib/expo-swift-metadata.cjs +1 -1
  71. package/dist-lib/expo-swift-metadata.mjs +16 -165
  72. package/dist-lib/home-paths.cjs +1 -1
  73. package/dist-lib/host/bridge-host.cjs +15658 -11404
  74. package/dist-lib/host/fetch-proxy-handler.cjs +3927 -342
  75. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  76. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -1
  77. package/dist-lib/host/replacement-module-handler.cjs +4 -4
  78. package/dist-lib/host/websocket-proxy.cjs +1 -1
  79. package/dist-lib/index.cjs +9145 -32150
  80. package/dist-lib/jump-to-source-babel.cjs +1 -1
  81. package/dist-lib/jump-to-source-native.cjs +2 -2
  82. package/dist-lib/kotlin-host.cjs +260 -253
  83. package/dist-lib/menu.cjs +1 -1
  84. package/dist-lib/menu.mjs +5 -13
  85. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  86. package/dist-lib/metro-fingerprint-registry.mjs +5 -6
  87. package/dist-lib/metro-production-bundle.cjs +22 -3
  88. package/dist-lib/metro-production-bundle.mjs +26 -92
  89. package/dist-lib/native-app-identity-project.cjs +663 -451
  90. package/dist-lib/native-app-identity-project.mjs +509 -2318
  91. package/dist-lib/native-app-identity.cjs +1 -1
  92. package/dist-lib/native-app-identity.mjs +27 -1340
  93. package/dist-lib/native-firebase-metadata.cjs +1 -1
  94. package/dist-lib/native-firebase-metadata.mjs +5 -18
  95. package/dist-lib/pdfium-raster.cjs +1 -1
  96. package/dist-lib/pdfium-raster.mjs +2 -1
  97. package/dist-lib/plist.cjs +2 -2
  98. package/dist-lib/plist.mjs +5 -7
  99. package/dist-lib/profiles.cjs +2 -1
  100. package/dist-lib/public-brand.cjs +1 -1
  101. package/dist-lib/public-origins-lib-esm.json +246 -187
  102. package/dist-lib/public-origins-lib-static.json +1 -1
  103. package/dist-lib/public-origins-lib.json +1059 -1238
  104. package/dist-lib/react-native-host-modules.cjs +1 -1
  105. package/dist-lib/react-native-host-modules.mjs +2 -1
  106. package/dist-lib/reap-browser.cjs +18 -7
  107. package/dist-lib/scripts/dev-server-scanner.cjs +6 -230
  108. package/dist-lib/sdk.cjs +1 -1
  109. package/dist-lib/sdk.mjs +22 -78
  110. package/dist-lib/skills.cjs +21657 -17374
  111. package/dist-lib/swift-compile.cjs +1343 -1318
  112. package/dist-lib/swift-compile.mjs +68 -19013
  113. package/dist-lib/swift-package.cjs +1 -1
  114. package/dist-lib/swift-package.mjs +35 -630
  115. package/dist-lib/swift-submit.cjs +1 -1
  116. package/dist-lib/swift-submit.mjs +9 -24
  117. package/dist-lib/swift-toolchain.cjs +1 -1
  118. package/dist-lib/swift.cjs +1 -1
  119. package/dist-lib/vendor/@peculiar/x509.cjs +18061 -0
  120. package/dist-lib/vendor/acorn.cjs +5699 -0
  121. package/dist-lib/vendor/bplist-parser.cjs +1589 -0
  122. package/dist-lib/vendor/ignore.cjs +455 -0
  123. package/dist-lib/vendor/magic-string.cjs +1693 -0
  124. package/dist-lib/vendor/plist.cjs +10978 -0
  125. package/dist-lib/vendor/smol-toml.cjs +768 -0
  126. package/dist-lib/vendor/stream-json.cjs +1997 -0
  127. package/dist-lib/vendor/sucrase/dist/index.js.cjs +23593 -0
  128. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +15750 -0
  129. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +11316 -0
  130. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +482 -0
  131. package/dist-lib/vendor/sucrase.cjs +23593 -0
  132. package/dist-lib/vendor/terser.cjs +36874 -0
  133. package/dist-lib/vendor/valibot.cjs +6253 -0
  134. package/dist-lib/vendor/zod.cjs +23262 -0
  135. package/dist-lib/worklet-executable.cjs +3 -3
  136. package/dist-lib/worklet-executable.mjs +11 -16
  137. package/dist-types/packages/peach-engine/src/config.d.ts +1 -1
  138. package/kotlin/fork/NOTICE +3 -0
  139. package/kotlin/sdk.tar.gz +0 -0
  140. package/kotlin/toolchain.json +6 -6
  141. package/package.json +17 -121
  142. package/runtime-companion.json +1 -1
  143. package/scripts/dev-server-scanner.ts +13 -223
  144. package/src/android-autolinking.ts +2 -2
  145. package/src/bundle-channel.mjs +3 -15
  146. package/src/cloud-contract.ts +3 -4
  147. package/src/config.ts +0 -5
  148. package/src/host/bridge-host.ts +19 -1
  149. package/src/host/server-scan-handler.ts +1 -9
  150. package/src/index.ts +0 -2
  151. package/src/kotlin-host.ts +1 -2
  152. package/src/kotlinDiscoveryContract.ts +1 -0
  153. package/src/metro-production-bundle.ts +28 -6
  154. package/src/native-seam-manifest.ts +0 -13
  155. package/src/one-native-app-catalog.ts +8 -27
  156. package/src/one-native-app-config.ts +95 -0
  157. package/src/one-native-source.ts +250 -0
  158. package/src/one-widget-metadata.ts +45 -126
  159. package/src/oneWidgetContract.ts +80 -117
  160. package/src/serverDiscoveryContract.ts +0 -1
  161. package/src/simulator-route.ts +8 -0
  162. package/src/vite-plugin.ts +2 -2
  163. package/src/xcode-project.ts +1 -1
  164. package/dist-lib/metro.cjs +0 -27984
  165. package/dist-lib/vite-swift.cjs +0 -43376
  166. package/dist-lib/vite.cjs +0 -21456
  167. package/src/androidAutolinkingContract.ts +0 -48
  168. package/src/androidRootModuleContract.ts +0 -39
  169. package/src/dev-server-open.ts +0 -92
  170. package/src/metro-plugin.ts +0 -578
  171. package/src/one-widget-discovery.ts +0 -23
  172. package/src/swift-vite-lifetime.ts +0 -42
  173. package/src/vite-plugin-one.ts +0 -746
  174. package/src/vite-plugin-swift.ts +0 -225
  175. package/src/vite.d.ts +0 -10
@@ -9,6 +9,10 @@ import {
9
9
  } from 'node:fs'
10
10
  import { dirname, extname, join, resolve } from 'node:path'
11
11
  import { Script } from 'node:vm'
12
+ import {
13
+ insertPackageVersionsFooter,
14
+ readPackageVersionsFooter,
15
+ } from '@peach/globals/package-versions'
12
16
  import {
13
17
  embedMetroAssetFiles,
14
18
  extractAssetDescriptors,
@@ -40,12 +44,14 @@ import {
40
44
  type RnxCloudSimInstance,
41
45
  type RnxCloudSimView,
42
46
  } from '../src/cloud-contract.ts'
47
+ import { readInstalledNativePackageVersionsAsync } from '../src/installed-package-versions'
43
48
  import { isRecord } from '../src/is-record'
44
49
  import {
45
50
  RNX_METRO_MODULE_IDENTITY_VERSION,
46
51
  type RNXMetroModuleIdentityMetadata,
47
52
  } from '../src/metro-production-bundle.ts'
48
53
  import { rnxPublicBrand } from '../src/public-brand.ts'
54
+ import { cloudSimulatorPath } from '../src/simulator-route.ts'
49
55
  import { StorageSnapshot } from '../src/storageSnapshotContract.ts'
50
56
  import { CHOOSE_ACCOUNT_HINT, resolveCliAuth } from './auth.ts'
51
57
  import {
@@ -748,7 +754,7 @@ async function inferCloudModuleIdentity(
748
754
  throw new Error(
749
755
  `${command} could not load the Metro fingerprint registry needed to identify this bundle: ${
750
756
  error instanceof Error ? error.message : String(error)
751
- }. Build it through the published Metro plugin: withPeach(config).`,
757
+ }.`,
752
758
  )
753
759
  }
754
760
  try {
@@ -767,7 +773,7 @@ async function inferCloudModuleIdentity(
767
773
  throw new Error(
768
774
  `${command} could not infer module identity for this Metro bundle: ${
769
775
  error instanceof Error ? error.message : String(error)
770
- }. Build it through the published Metro plugin: withPeach(config).`,
776
+ }.`,
771
777
  )
772
778
  }
773
779
  }
@@ -777,7 +783,7 @@ async function inferCloudModuleIdentity(
777
783
  * the runner executes: every asset scale is read from the asset graph and
778
784
  * embedded, module identity is normalized, and the JavaScript is minified.
779
785
  * an ordinary unannotated Metro production bundle is identified through the
780
- * published fingerprint registry; a withPeach footer remains the fast path.
786
+ * published fingerprint registry; an identity footer remains the fast path.
781
787
  */
782
788
  export interface CloudArtifactProduction {
783
789
  bytes: Buffer
@@ -842,25 +848,66 @@ export async function producePreviewArtifact(bundlePath: string) {
842
848
  }
843
849
  }
844
850
 
851
+ // the app a local bundle was built from: the nearest directory above it whose
852
+ // package.json depends on react-native, as `expo export:embed` and
853
+ // `react-native bundle` write into the project.
854
+ function bundleAppProject(bundlePath: string): string | null {
855
+ if (isRemoteBundleInput(bundlePath)) return null
856
+ for (let dir = dirname(resolve(bundlePath)); ; dir = dirname(dir)) {
857
+ const manifest = join(dir, 'package.json')
858
+ if (existsSync(manifest)) {
859
+ const json: unknown = JSON.parse(readFileSync(manifest, 'utf8'))
860
+ if (
861
+ isRecord(json) &&
862
+ [json.dependencies, json.devDependencies].some(
863
+ (dependencies) => isRecord(dependencies) && 'react-native' in dependencies,
864
+ )
865
+ )
866
+ return dir
867
+ }
868
+ if (dirname(dir) === dir) return null
869
+ }
870
+ }
871
+
845
872
  export async function embedBundleAssets(
846
873
  bundlePath: string,
847
874
  command: string,
848
875
  assetPolicy: 'allow-placeholders' | 'require-assets',
849
876
  assetsDirectory?: string,
850
877
  assetServer?: URL,
878
+ nativeProjectDir?: string,
851
879
  ): Promise<{
852
880
  source: string
853
881
  code: string
854
882
  search: MetroAssetSearch
855
883
  dest: MetroAssetDest | null
856
884
  substituted: string[]
885
+ /** the app project the bundle was built from, when one is known. */
886
+ project: string | null
857
887
  }> {
858
- const source = await loadBundleSource(bundlePath, command)
888
+ const project = nativeProjectDir
889
+ ? resolve(nativeProjectDir)
890
+ : bundleAppProject(bundlePath)
891
+ const loaded = await loadBundleSource(bundlePath, command)
892
+ // native seams follow the app's installed versions; a bundle that does not
893
+ // record them takes the install of its app project.
894
+ const source =
895
+ project && !readPackageVersionsFooter(loaded)?.['react-native']
896
+ ? insertPackageVersionsFooter(
897
+ loaded,
898
+ await readInstalledNativePackageVersionsAsync(project),
899
+ )
900
+ : loaded
901
+ if (!readPackageVersionsFooter(source)?.['react-native'])
902
+ throw new Error(
903
+ `${command} needs the app's installed react-native version: the bundle does not record it, and no app project with react-native was found above it.`,
904
+ )
859
905
  const descriptors = extractAssetDescriptors(source).filter(
860
906
  (descriptor) => !isEmbeddedAssetDescriptor(descriptor),
861
907
  )
862
908
  if (descriptors.length === 0) {
863
909
  return {
910
+ project,
864
911
  source,
865
912
  code: source,
866
913
  search: { dest: null, searched: [], truncated: false, unconfirmed: false },
@@ -957,6 +1004,7 @@ export async function embedBundleAssets(
957
1004
  )
958
1005
  })
959
1006
  return {
1007
+ project,
960
1008
  source,
961
1009
  code: embedded.code,
962
1010
  search,
@@ -1183,6 +1231,7 @@ function readSimCreateResponse(
1183
1231
  value: unknown,
1184
1232
  expectedBytes: number,
1185
1233
  expectedSha256: string,
1234
+ apiOrigin: string,
1186
1235
  ): RnxCloudSimCreateResponse {
1187
1236
  if (!isRecord(value)) throw new Error('remote simulator create returned invalid JSON')
1188
1237
  const artifactId = `sha256:${expectedSha256}` as const
@@ -1201,8 +1250,7 @@ function readSimCreateResponse(
1201
1250
  typeof value.token !== 'string' ||
1202
1251
  !value.token ||
1203
1252
  typeof value.status !== 'string' ||
1204
- !isRnxCloudSimStatus(value.status) ||
1205
- (value.streamUrl !== null && typeof value.streamUrl !== 'string')
1253
+ !isRnxCloudSimStatus(value.status)
1206
1254
  ) {
1207
1255
  throw new Error('remote simulator create returned an invalid receipt')
1208
1256
  }
@@ -1213,7 +1261,7 @@ function readSimCreateResponse(
1213
1261
  token: value.token,
1214
1262
  status: value.status,
1215
1263
  labels: readStringMap(value.labels),
1216
- streamUrl: value.streamUrl,
1264
+ streamUrl: new URL(cloudSimulatorPath(value.simId), apiOrigin).href,
1217
1265
  }
1218
1266
  }
1219
1267
 
@@ -1272,13 +1320,17 @@ export async function createRemoteSim(options: CreateRemoteSimOptions): Promise<
1272
1320
  } catch {
1273
1321
  throw new Error('remote simulator create returned unreadable JSON')
1274
1322
  }
1275
- const receipt = readSimCreateResponse(parsed, artifact.bytes.length, artifact.sha256)
1323
+ const receipt = readSimCreateResponse(
1324
+ parsed,
1325
+ artifact.bytes.length,
1326
+ artifact.sha256,
1327
+ apiOrigin,
1328
+ )
1276
1329
  const session = createCloudSession({
1277
1330
  simId: receipt.simId,
1278
1331
  apiOrigin,
1279
1332
  claimId: receipt.claim.id,
1280
1333
  token: receipt.token,
1281
- streamUrl: receipt.streamUrl,
1282
1334
  platform: options.platform,
1283
1335
  device: options.device,
1284
1336
  artifact: {
@@ -1384,10 +1436,7 @@ export async function listRemoteSims(options: {
1384
1436
  return parsed.sims.map(readSimView)
1385
1437
  }
1386
1438
 
1387
- // one simulator reread by id: the reattach liveness probe, and the fresh
1388
- // watch url an api-key caller mints with it. a simulator this account no
1389
- // longer runs reads back as missing rather than forbidden, so 404 is null
1390
- // and anything else refused throws.
1439
+ // one simulator reread by id to check whether it can be reattached.
1391
1440
  export async function getRemoteSim(options: {
1392
1441
  apiOrigin?: string
1393
1442
  simId: string
@@ -1419,13 +1468,9 @@ export async function getRemoteSim(options: {
1419
1468
  throw new Error('remote simulator read returned invalid JSON')
1420
1469
  }
1421
1470
  const view = readSimView(parsed.sim)
1422
- const streamUrl = parsed.sim.streamUrl
1423
- if (streamUrl !== null && streamUrl !== undefined && typeof streamUrl !== 'string') {
1424
- throw new Error('remote simulator read returned an invalid watch url')
1425
- }
1426
1471
  return {
1427
1472
  ...view,
1428
- streamUrl: typeof streamUrl === 'string' ? streamUrl : null,
1473
+ streamUrl: new URL(cloudSimulatorPath(view.simId), apiOrigin).href,
1429
1474
  }
1430
1475
  }
1431
1476
 
@@ -1769,19 +1814,14 @@ export class BoxBootFailedError extends Error {
1769
1814
  }
1770
1815
  }
1771
1816
 
1772
- // how long `peach remote` waits for a fresh box's page to attach its simulator
1773
- // before giving up on the watch url. the page boots the bundle after the
1774
- // browser is up, and a large bundle takes a while to parse.
1775
- const BOX_DISPLAY_GRANT_WAIT_MS = 180_000
1776
- const BOX_DISPLAY_GRANT_RETRY_MS = 2_000
1817
+ const BOX_BOOT_WAIT_MS = 180_000
1818
+ const BOX_BOOT_READ_INTERVAL_MS = 2_000
1777
1819
 
1778
- // a box's lifecycle as the page's runtime receipts and lost browser
1779
- // generations record it.
1780
1820
  async function readBoxLifecycle(options: {
1781
1821
  apiOrigin: string
1782
1822
  boxId: string
1783
1823
  boxToken: string
1784
- }): Promise<{ generation: unknown; receipts: unknown[]; lostGenerations: number }> {
1824
+ }): Promise<{ generation: unknown; receipts: unknown[] }> {
1785
1825
  const response = await fetch(
1786
1826
  `${options.apiOrigin}/v1/boxes/${encodeURIComponent(options.boxId)}/lifecycle`,
1787
1827
  { headers: { authorization: `Bearer ${options.boxToken}` } },
@@ -1789,11 +1829,10 @@ async function readBoxLifecycle(options: {
1789
1829
  const text = await response.text()
1790
1830
  if (!response.ok) throw responseError(response.status, text)
1791
1831
  const status: unknown = JSON.parse(text)
1792
- if (!isRecord(status)) return { generation: null, receipts: [], lostGenerations: 0 }
1832
+ if (!isRecord(status)) return { generation: null, receipts: [] }
1793
1833
  return {
1794
1834
  generation: isRecord(status.browser) ? status.browser.browserGeneration : null,
1795
1835
  receipts: Array.isArray(status.runtimeReceipts) ? status.runtimeReceipts : [],
1796
- lostGenerations: Array.isArray(status.recoveries) ? status.recoveries.length : 0,
1797
1836
  }
1798
1837
  }
1799
1838
 
@@ -1823,7 +1862,7 @@ export async function awaitBoxBoot(options: {
1823
1862
  boxToken: string
1824
1863
  }): Promise<void> {
1825
1864
  const started = Date.now()
1826
- while (Date.now() - started < BOX_DISPLAY_GRANT_WAIT_MS) {
1865
+ while (Date.now() - started < BOX_BOOT_WAIT_MS) {
1827
1866
  const { generation, receipts } = await readBoxLifecycle(options)
1828
1867
  const outcome = bootOutcome(
1829
1868
  receipts,
@@ -1831,97 +1870,10 @@ export async function awaitBoxBoot(options: {
1831
1870
  )
1832
1871
  if (outcome?.loaded) return
1833
1872
  if (outcome) throw new BoxBootFailedError(options.boxId, outcome.error)
1834
- await new Promise((resolve) => setTimeout(resolve, BOX_DISPLAY_GRANT_RETRY_MS))
1835
- }
1836
- }
1837
-
1838
- // mints a watch-only display grant from the box and returns the watch url the
1839
- // box service built for it. the service puts it on the deploy that serves the
1840
- // box page, so the viewer runs the same engine build, and display wire, as the
1841
- // page hosting the simulator. the box token stays in this process; only the
1842
- // grant travels, in the url's fragment.
1843
- export async function requestBoxWatchUrl(options: {
1844
- apiOrigin: string
1845
- boxId: string
1846
- boxToken: string
1847
- }): Promise<string> {
1848
- const started = Date.now()
1849
- for (;;) {
1850
- let response: Response
1851
- try {
1852
- response = await fetch(
1853
- `${options.apiOrigin}/v1/boxes/${encodeURIComponent(options.boxId)}/display-grant`,
1854
- {
1855
- method: 'POST',
1856
- headers: {
1857
- authorization: `Bearer ${options.boxToken}`,
1858
- 'content-type': 'application/json',
1859
- },
1860
- body: '{}',
1861
- },
1862
- )
1863
- } catch (error) {
1864
- throw new Error(
1865
- `could not reach box ${options.boxId} at ${options.apiOrigin}: ${
1866
- error instanceof Error ? error.message : String(error)
1867
- }`,
1868
- )
1869
- }
1870
- const text = await response.text()
1871
- if (
1872
- response.status === 409 &&
1873
- failureSentence(text) === 'no simulator is hosting this box'
1874
- ) {
1875
- // the page has not attached its simulator yet. this is the normal state
1876
- // right after a create, so wait rather than refusing, unless a page of
1877
- // any browser generation already reported that the app cannot boot.
1878
- const lifecycle = await readBoxLifecycle(options)
1879
- const outcome = bootOutcome(lifecycle.receipts, () => true)
1880
- if (outcome && !outcome.loaded)
1881
- throw new BoxBootFailedError(options.boxId, outcome.error)
1882
- if (Date.now() - started >= BOX_DISPLAY_GRANT_WAIT_MS) {
1883
- throw new Error(
1884
- lifecycle.lostGenerations > 0
1885
- ? `box ${options.boxId} has no simulator hosting it: its page's browser was lost ${lifecycle.lostGenerations} time(s) before the app reported loading or failing`
1886
- : `box ${options.boxId} has no simulator hosting it yet; try again once its page has booted`,
1887
- )
1888
- }
1889
- await new Promise((resolve) => setTimeout(resolve, BOX_DISPLAY_GRANT_RETRY_MS))
1890
- continue
1891
- }
1892
- if (!response.ok) throw responseError(response.status, text)
1893
- let parsed: unknown
1894
- try {
1895
- parsed = JSON.parse(text)
1896
- } catch {
1897
- throw new Error('box display-grant returned unreadable JSON')
1898
- }
1899
- if (!isRecord(parsed) || typeof parsed.watchUrl !== 'string' || !parsed.watchUrl)
1900
- throw new Error('box display-grant returned no watch url')
1901
- return parsed.watchUrl
1873
+ await new Promise((resolve) => setTimeout(resolve, BOX_BOOT_READ_INTERVAL_MS))
1902
1874
  }
1903
1875
  }
1904
1876
 
1905
- // the short peachsim.com link a person opens for a watch url. the link lives
1906
- // as long as the grant in the url's fragment, so it is minted per grant.
1907
- export async function shortWatchUrl(options: {
1908
- apiOrigin: string
1909
- authHeader: string
1910
- watchUrl: string
1911
- }): Promise<string> {
1912
- const response = await fetch(`${options.apiOrigin}/api/v1/watch-links`, {
1913
- method: 'POST',
1914
- headers: { authorization: options.authHeader, 'content-type': 'application/json' },
1915
- body: JSON.stringify({ url: options.watchUrl }),
1916
- })
1917
- const text = await response.text()
1918
- if (!response.ok) throw responseError(response.status, text)
1919
- const parsed: unknown = JSON.parse(text)
1920
- if (!isRecord(parsed) || typeof parsed.url !== 'string')
1921
- throw new Error('watch link returned no url')
1922
- return parsed.url
1923
- }
1924
-
1925
1877
  function readClaimResponse(value: unknown): { id: string; expiresAt: number } {
1926
1878
  const claim = isRecord(value) ? value.claim : null
1927
1879
  if (
@@ -35,10 +35,8 @@ export interface CloudSessionArtifactIdentity {
35
35
  }
36
36
 
37
37
  /**
38
- * one remote simulator and the claim ordinary commands drive it with. the
39
- * watch URL the create returned rides along so a reattach reopens the same
40
- * simulator. a nano-box simulator keeps the box that hosts it; an instance
41
- * API simulator has no box.
38
+ * one remote simulator and the claim ordinary commands drive it with.
39
+ * a nano-box simulator keeps the box that hosts it.
42
40
  */
43
41
  export interface CloudSimSession {
44
42
  version: 3
@@ -47,7 +45,6 @@ export interface CloudSimSession {
47
45
  apiOrigin: string
48
46
  claimId: string
49
47
  token: string
50
- streamUrl?: string | null
51
48
  platform?: RemotePlatform
52
49
  device?: string
53
50
  artifact?: CloudSessionArtifactIdentity
@@ -102,7 +99,6 @@ export function createCloudSession(input: {
102
99
  apiOrigin: string
103
100
  claimId: string
104
101
  token: string
105
- streamUrl?: string | null
106
102
  platform?: RemotePlatform
107
103
  device?: string
108
104
  artifact?: CloudSessionArtifactIdentity
@@ -121,7 +117,6 @@ export function createCloudSession(input: {
121
117
  apiOrigin: normalizeCloudOrigin(input.apiOrigin.trim()),
122
118
  claimId: input.claimId.trim(),
123
119
  token: input.token,
124
- ...(input.streamUrl ? { streamUrl: input.streamUrl } : {}),
125
120
  ...(input.platform ? { platform: input.platform } : {}),
126
121
  ...(input.device?.trim() ? { device: input.device.trim() } : {}),
127
122
  ...(input.artifact ? { artifact: input.artifact } : {}),
@@ -213,7 +208,6 @@ export function parseCloudSession(encoded: string): CloudSession {
213
208
  typeof parsed.artifact.bytes === 'number' ? parsed.artifact.bytes : undefined,
214
209
  }
215
210
  : undefined
216
- const streamUrl = typeof parsed.streamUrl === 'string' ? parsed.streamUrl : undefined
217
211
  const boxId = typeof parsed.boxId === 'string' ? parsed.boxId : undefined
218
212
  const boxToken = typeof parsed.boxToken === 'string' ? parsed.boxToken : undefined
219
213
  try {
@@ -250,7 +244,6 @@ export function parseCloudSession(encoded: string): CloudSession {
250
244
  apiOrigin,
251
245
  claimId,
252
246
  token,
253
- streamUrl,
254
247
  platform,
255
248
  device,
256
249
  artifact,
@@ -14,6 +14,12 @@ import fs from 'node:fs'
14
14
  import path from 'node:path'
15
15
  import { createInterface } from 'node:readline'
16
16
  import { BoxClientError, createBoxClient } from '@peach/box/client'
17
+ import {
18
+ cloudBoxConnectUrl,
19
+ createCloudBoxProvider,
20
+ ensureCloudBoxBrowser,
21
+ resolveCloudBoxReference,
22
+ } from '@peach/box/cloud-client'
17
23
  import { createBoxHostProvider } from '@peach/box/host'
18
24
  import { PROJECT_MOUNT } from '@peach/box/shell'
19
25
  import { terminalBoxStack } from '@peach/box/stack'
@@ -23,12 +29,6 @@ import {
23
29
  sourceControlBoxTemplate,
24
30
  terminalBoxTemplate,
25
31
  } from '@peach/box/template'
26
- import {
27
- cloudBoxConnectUrl,
28
- createCloudBoxProvider,
29
- ensureCloudBoxBrowser,
30
- resolveCloudBoxReference,
31
- } from 'peach-cloud-box/client'
32
32
  import { getCliRuntime } from '../../src/cli-runtime.ts'
33
33
  import { isDeviceModel } from '../../src/device-catalog.ts'
34
34
  import { readDefaultBox, writeDefaultBox } from '../../src/home-paths'
@@ -7,13 +7,14 @@ import os from 'node:os'
7
7
  import path from 'node:path'
8
8
  import { compareSemver } from '@contrast/runtime-delivery'
9
9
  import { PEACH_FINAL_LAUNCH_GLOBAL, type SystemPermissionBootSeed } from '@peach/globals'
10
+ import { ANDROID_AUTOLINKED_QUERY_PARAM } from '@peach/globals/android-autolinking'
11
+ import { ANDROID_ROOT_MODULE_QUERY_PARAM } from '@peach/globals/android-root-module'
10
12
  import { WebSocket } from 'ws'
11
13
  import { formatLockOwner } from '../../../peach-kit/src/agent-identity'
12
14
  import { buildPermissionSeedScript } from '../../detox/launch-permissions'
13
- import { ANDROID_ROOT_MODULE_QUERY_PARAM } from '../../src/androidRootModuleContract'
14
15
  import { loadRNXAppConfig } from '../../src/app-config'
15
16
  import { isAppDeepLinkTarget, openAppUrl } from '../../src/app-url'
16
- import { isLoopbackHost, loopbackOriginOf } from '../../src/backend-origin'
17
+ import { isLoopbackHost } from '../../src/backend-origin'
17
18
  import { ensureCliCompanion, getCliRuntime } from '../../src/cli-runtime.ts'
18
19
  import { getCliVersion } from '../../src/cli-version'
19
20
  import {
@@ -62,7 +63,6 @@ import {
62
63
  } from '../../src/runtime-assets'
63
64
  import { rnxRuntime } from '../../src/runtime-delivery'
64
65
  import { sleep } from '../../src/sleep'
65
- import { fetchOneNativeAppCatalogDeclaration } from '../app-catalog'
66
66
  import { appNameFromPath, findExpoAppConfig, resolveAppProject } from '../app-project'
67
67
  import { discoverOneNativeAppSplash } from '../app-splash'
68
68
  import { extractAppBinaryBundle, isAppBinaryPath } from '../binary-sidecar'
@@ -906,6 +906,7 @@ function deriveCurrentSimBaseUrl(
906
906
  url.searchParams.delete('packageVersions')
907
907
  url.searchParams.delete('nativeAppIdentity')
908
908
  url.searchParams.delete(ANDROID_ROOT_MODULE_QUERY_PARAM)
909
+ url.searchParams.delete(ANDROID_AUTOLINKED_QUERY_PARAM)
909
910
  url.searchParams.delete(LAUNCH_METADATA_QUERY_PARAM)
910
911
  url.searchParams.delete('expoSwift')
911
912
  url.searchParams.delete('expoWidgets')
@@ -1831,13 +1832,6 @@ async function openSim(
1831
1832
  resolvedBundle && project && !findExpoAppConfig(project.appDir)
1832
1833
  ? discoverOneNativeAppSplash(resolvedBundle.bundleUrl)
1833
1834
  : undefined
1834
- const oneAppCatalogOrigin =
1835
- resolvedBundle && project && !findExpoAppConfig(project.appDir)
1836
- ? loopbackOriginOf(resolvedBundle.bundleUrl)
1837
- : null
1838
- const oneAppCatalog = oneAppCatalogOrigin
1839
- ? fetchOneNativeAppCatalogDeclaration(oneAppCatalogOrigin)
1840
- : undefined
1841
1835
  const explicitBaseUrl = args.find((_, i) => args[i - 1] === '--base-url')
1842
1836
  const baseUrlConfig = explicitBaseUrl
1843
1837
  ? readPeachConfigFromSearchParams(new URL(explicitBaseUrl).searchParams)
@@ -2114,7 +2108,6 @@ async function openSim(
2114
2108
  resolvedBundle,
2115
2109
  project,
2116
2110
  oneAppSplash,
2117
- oneAppCatalog,
2118
2111
  proof: args.includes('--proof'),
2119
2112
  ephemeral: ephemeralProfile,
2120
2113
  env: envArgs.length ? envArgs : undefined,
@@ -226,14 +226,10 @@ export async function resolveAppFrontmatterTarget(
226
226
  return { target: trimmed }
227
227
  }
228
228
 
229
- // discover a peach shell URL from running dev servers, preferring patched ones.
230
- export async function discoverSootsimUrl(): Promise<string | null> {
231
- const servers = await scanDevServers()
232
- const patched = servers.find((s) => s.patched)
233
- if (patched) return `http://localhost:${patched.port}/__peachsim/`
234
- const any = servers[0]
235
- if (any) return `http://localhost:${any.port}/__peachsim/`
236
- return null
229
+ // the first running dev server, which `peach open` launches by its port.
230
+ async function discoverDevServerTarget(): Promise<string | null> {
231
+ const [server] = await scanDevServers()
232
+ return server ? String(server.port) : null
237
233
  }
238
234
 
239
235
  export async function runFlowPlayback(
@@ -620,7 +616,7 @@ flow extension:
620
616
  !reuseActivePrimary &&
621
617
  (effectiveOpenInNewSim || parsedBridgeArgs.simIdSource === 'none')
622
618
  ) {
623
- const discovered = await discoverSootsimUrl()
619
+ const discovered = await discoverDevServerTarget()
624
620
  if (!discovered) {
625
621
  console.error(' error: no current sim and no peach target found')
626
622
  peachExit(1)
@@ -13,6 +13,7 @@ import { peachKotlinModuleRoot } from '../../src/kotlin-module'
13
13
  import {
14
14
  KOTLIN_DISCOVERY_PATH,
15
15
  KOTLIN_GUEST_PATH,
16
+ KOTLIN_PACKAGE_PATH,
16
17
  type KotlinHostDiscovery,
17
18
  } from '../../src/kotlinDiscoveryContract'
18
19
  import { PeachExit } from '../run-rnx'
@@ -149,7 +150,7 @@ export async function runKotlin(
149
150
  res.end(kotlinGuestBundle())
150
151
  return
151
152
  }
152
- if (pathname === host.KOTLIN_PACKAGE_PATH) {
153
+ if (pathname === KOTLIN_PACKAGE_PATH) {
153
154
  if (!artifact) {
154
155
  res.statusCode = 503
155
156
  res.end(compileError)
@@ -18,6 +18,7 @@ import {
18
18
  import { isRecord } from '../../src/is-record'
19
19
  import { toPeachDevelopmentBundleUrl } from '../../src/metro-production-bundle'
20
20
  import { rnxPublicBrand } from '../../src/public-brand'
21
+ import { cloudBoxSimulatorId, cloudSimulatorPath } from '../../src/simulator-route'
21
22
  import { appNameFromPath } from '../app-project'
22
23
  import { UnsupportedRemoteHostError } from '../cloud-client'
23
24
  import { resolveCheckoutRepo } from '../run-registry'
@@ -363,9 +364,6 @@ async function runRemoteCreate(
363
364
  existingSession.platform === platform &&
364
365
  existingSession.artifact?.sha256 === artifact.sha256
365
366
  ) {
366
- // an api key reads the simulator back through the account, which mints a
367
- // fresh watch url with the read. any other credential rereads with the
368
- // simulator's own token and keeps the stored watch url.
369
367
  const live = await getRemoteSim({
370
368
  apiOrigin: existingSession.apiOrigin,
371
369
  simId: existingSession.simId,
@@ -373,17 +371,16 @@ async function runRemoteCreate(
373
371
  })
374
372
  if (live && (live.status === 'open' || live.status === 'hibernated')) {
375
373
  const claimed = await claimCloudSimulator(existingSession)
376
- const streamUrl = live.streamUrl ?? existingSession.streamUrl ?? null
377
374
  const session = createCloudSession({
378
375
  ...existingSession,
379
376
  claimId: claimed.claim.id,
380
- ...(streamUrl ? { streamUrl } : {}),
381
377
  })
382
378
  publishCloudSession(session, descriptor)
383
379
  console.log(
384
380
  ` reconnected to remote simulator: ${existingSession.simId} (${platform})`,
385
381
  )
386
382
  console.log(` claim expires: ${claimed.claim.expiresAt}`)
383
+ console.log(` open ${live.streamUrl}`)
387
384
  console.log(REMOTE_COMMANDS_HELP)
388
385
  return 0
389
386
  }
@@ -431,11 +428,8 @@ async function runRemoteCreate(
431
428
  console.log(` claim expires: ${receipt.claim.expiresAt}`)
432
429
  console.log(REMOTE_COMMANDS_HELP)
433
430
  for (const warning of created.warnings) console.warn(` warning: ${warning}`)
434
- if (!created.session.streamUrl) {
435
- console.log(' the service minted no watch url for this simulator')
436
- return 0
437
- }
438
- return openInBrowser(created.session.streamUrl)
431
+ console.log(` open ${receipt.streamUrl}`)
432
+ return openInBrowser(receipt.streamUrl)
439
433
  }
440
434
 
441
435
  /**
@@ -450,9 +444,8 @@ async function runRemoteCreate(
450
444
  * either way: the box holds the bundle in parts, so the single-message ceiling
451
445
  * a nano upload answers to does not apply.
452
446
  *
453
- * a box created from the already-built app boots it in its own page, and this
454
- * opens the watch url the box service mints with its display grant, on the
455
- * deploy that serves that page, as the nano service mints one on its own.
447
+ * a box created from the already-built app boots it in its own page. the
448
+ * simulator page loads the viewer that matches the box host.
456
449
  */
457
450
  async function runRemoteBox(
458
451
  platform: RuntimePlatform,
@@ -468,8 +461,6 @@ async function runRemoteBox(
468
461
  closeCloudBox,
469
462
  closeCloudSession,
470
463
  awaitBoxBoot,
471
- requestBoxWatchUrl,
472
- shortWatchUrl,
473
464
  },
474
465
  box,
475
466
  { cloudBoxConnectUrl, ensureCloudBoxBrowser, readCloudBoxSession },
@@ -486,7 +477,7 @@ async function runRemoteBox(
486
477
  ] = await Promise.all([
487
478
  import('../cloud-client'),
488
479
  import('./box'),
489
- import('peach-cloud-box/client'),
480
+ import('@peach/box/cloud-client'),
490
481
  import('../auth'),
491
482
  import('../cloud-session'),
492
483
  import('../cloud-box-artifact.ts'),
@@ -495,12 +486,9 @@ async function runRemoteBox(
495
486
  const { openInBrowser } = box
496
487
  // an app that cannot boot never gets a simulator, so the box ends with the
497
488
  // error instead of billing until someone finds it.
498
- const closeBoxOnBootFailure = async <T>(
499
- session: CloudBoxSession,
500
- work: () => Promise<T>,
501
- ): Promise<T> => {
489
+ const awaitBootOrClose = async (session: CloudBoxSession): Promise<void> => {
502
490
  try {
503
- return await work()
491
+ await awaitBoxBoot(session)
504
492
  } catch (error) {
505
493
  if (error instanceof BoxBootFailedError) {
506
494
  await closeCloudBox(session)
@@ -524,6 +512,8 @@ async function runRemoteBox(
524
512
  const { auth, header } = authHeaderOrExit(command)
525
513
  const accountId = cloudAccountIdOrExit(auth)
526
514
  const apiOrigin = box.cloudBoxApiOrigin(args, auth)
515
+ const siteOrigin =
516
+ getCliRuntime().preview_presigned_upload.canonicalPublicPreviewOrigin(apiOrigin)
527
517
  const covered = await fetch(`${apiOrigin}/api/v1/rnx/sessions`, {
528
518
  method: 'POST',
529
519
  headers: { authorization: header, 'content-type': 'application/json' },
@@ -598,16 +588,11 @@ async function runRemoteBox(
598
588
  })
599
589
  // a lapsed tab reboots the app, so a reconnect reads that boot's outcome
600
590
  // before waiting on a simulator a throwing app never attaches.
601
- await closeBoxOnBootFailure(existingSession, () => awaitBoxBoot(existingSession))
602
- // grants are short-lived, so a reconnect mints a fresh one rather than
603
- // reopening whatever url the create printed.
604
- const watchUrl = await shortWatchUrl({
605
- apiOrigin,
606
- authHeader: header,
607
- watchUrl: await closeBoxOnBootFailure(existingSession, () =>
608
- requestBoxWatchUrl(existingSession),
609
- ),
610
- })
591
+ await awaitBootOrClose(existingSession)
592
+ const watchUrl = new URL(
593
+ cloudSimulatorPath(cloudBoxSimulatorId(existingSession.boxId)),
594
+ siteOrigin,
595
+ ).href
611
596
  console.log(
612
597
  ` reconnected to remote simulator: ${existingSession.boxId} (${platform})`,
613
598
  )
@@ -685,14 +670,11 @@ async function runRemoteBox(
685
670
  if (artifact.nativeProject) console.log(` native modules: ${artifact.nativeProject}`)
686
671
  for (const warning of artifact.warnings) console.warn(` warning: ${warning}`)
687
672
  console.log(REMOTE_COMMANDS_HELP)
688
- // the session is published before the grant is minted, so a grant that never
689
- // arrives still leaves the box addressable: re-running this command mints it.
690
- const watchUrl = await shortWatchUrl({
691
- apiOrigin,
692
- authHeader: header,
693
- watchUrl: await closeBoxOnBootFailure(session, () => requestBoxWatchUrl(session)),
694
- })
695
- await closeBoxOnBootFailure(session, () => awaitBoxBoot(session))
673
+ await awaitBootOrClose(session)
674
+ const watchUrl = new URL(
675
+ cloudSimulatorPath(cloudBoxSimulatorId(session.boxId)),
676
+ siteOrigin,
677
+ ).href
696
678
  console.log(` open ${watchUrl}`)
697
679
  const opened = await openInBrowser(watchUrl)
698
680
  if (!input.watch || opened !== 0) return opened
@@ -167,7 +167,7 @@ examples:
167
167
  )
168
168
  if (!started) {
169
169
  throw new Error(
170
- 'record --three: engine recording store did not start (is @peach/plugin-recording installed?)',
170
+ 'record --three: engine recording store did not start (is peach-engine/recording installed?)',
171
171
  )
172
172
  }
173
173
  t0 = Date.now()