peachsim 0.1.686 → 0.1.688

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 (116) hide show
  1. package/cli/cloud-client.ts +3 -3
  2. package/cli/command-registry.ts +2 -0
  3. package/cli/commands/control.ts +1 -0
  4. package/cli/commands/debug.ts +10 -33
  5. package/cli/commands/do-chain.ts +56 -6
  6. package/cli/commands/inspect/core.ts +2 -0
  7. package/cli/commands/inspect/list.ts +2 -1
  8. package/cli/commands/inspect/settling.ts +17 -3
  9. package/cli/commands/inspect/shared.ts +2 -0
  10. package/cli/commands/inspect/wait-idle.ts +2 -2
  11. package/cli/commands/inspect/wait-ready.ts +3 -3
  12. package/cli/commands/inspect.ts +33 -7
  13. package/cli/commands/location.ts +164 -0
  14. package/cli/commands/platform.ts +1 -1
  15. package/cli/drivers/playwright-sim-host.ts +46 -25
  16. package/cli/main.ts +6 -0
  17. package/detox/index.ts +13 -8
  18. package/dist-lib/agent-daemon-client.cjs +1 -1
  19. package/dist-lib/agent-events.cjs +1 -1
  20. package/dist-lib/agent-identity.cjs +1 -1
  21. package/dist-lib/agent-sessions.cjs +1 -1
  22. package/dist-lib/attached-projects.cjs +1 -1
  23. package/dist-lib/auth/shared-session.cjs +1 -1
  24. package/dist-lib/backend-origin.cjs +1 -1
  25. package/dist-lib/beta.cjs +1 -1
  26. package/dist-lib/beta.mjs +1 -1
  27. package/dist-lib/bridge-constants.cjs +4 -3
  28. package/dist-lib/bridge-contract-input.cjs +12 -1
  29. package/dist-lib/bridge-contract-input.mjs +12 -1
  30. package/dist-lib/bridge-contract.cjs +4 -3
  31. package/dist-lib/bridge-contract.mjs +4 -3
  32. package/dist-lib/capture-contract.cjs +1 -1
  33. package/dist-lib/capture-contract.mjs +1 -1
  34. package/dist-lib/cli-constants.cjs +1 -1
  35. package/dist-lib/cloud-contract.cjs +2 -1
  36. package/dist-lib/cloud-contract.mjs +2 -1
  37. package/dist-lib/cloud-test-args.cjs +1 -1
  38. package/dist-lib/cloud-test-args.mjs +1 -1
  39. package/dist-lib/cloud.cjs +2 -1
  40. package/dist-lib/cloud.mjs +2 -1
  41. package/dist-lib/config.cjs +1 -1
  42. package/dist-lib/detox/index.cjs +1197 -65
  43. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  44. package/dist-lib/home-paths.cjs +1 -1
  45. package/dist-lib/host/bridge-host.cjs +402 -113
  46. package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
  47. package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
  48. package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
  49. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  50. package/dist-lib/host/websocket-proxy.cjs +1 -1
  51. package/dist-lib/index.cjs +29 -11
  52. package/dist-lib/jump-to-source-babel.cjs +1 -1
  53. package/dist-lib/jump-to-source-native.cjs +1 -1
  54. package/dist-lib/kotlin-host.cjs +89 -13
  55. package/dist-lib/menu.cjs +1 -1
  56. package/dist-lib/menu.mjs +1 -1
  57. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  58. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  59. package/dist-lib/metro-production-bundle.cjs +1 -1
  60. package/dist-lib/metro-production-bundle.mjs +1 -1
  61. package/dist-lib/metro.cjs +5 -3
  62. package/dist-lib/native-app-identity.cjs +8 -3
  63. package/dist-lib/native-app-identity.mjs +8 -3
  64. package/dist-lib/native-firebase-metadata.cjs +1 -1
  65. package/dist-lib/native-firebase-metadata.mjs +1 -1
  66. package/dist-lib/plist.cjs +1 -1
  67. package/dist-lib/plist.mjs +1 -1
  68. package/dist-lib/profiles.cjs +1 -1
  69. package/dist-lib/public-brand.cjs +1 -1
  70. package/dist-lib/react-native-host-modules.cjs +1 -1
  71. package/dist-lib/react-native-host-modules.mjs +1 -1
  72. package/dist-lib/render-mode.cjs +1 -1
  73. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  74. package/dist-lib/sdk.cjs +21 -6
  75. package/dist-lib/sdk.mjs +21 -6
  76. package/dist-lib/skills.cjs +441 -135
  77. package/dist-lib/swift-compile.cjs +317 -27
  78. package/dist-lib/swift-compile.mjs +315 -27
  79. package/dist-lib/swift-package.cjs +1 -1
  80. package/dist-lib/swift-package.mjs +1 -1
  81. package/dist-lib/swift-submit.cjs +2 -2
  82. package/dist-lib/swift-submit.mjs +2 -2
  83. package/dist-lib/swift-toolchain.cjs +10 -10
  84. package/dist-lib/swift.cjs +1 -1
  85. package/dist-lib/vite-swift.cjs +320 -49
  86. package/dist-lib/vite.cjs +1 -1
  87. package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
  88. package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
  89. package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
  90. package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
  91. package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
  92. package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
  93. package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
  94. package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
  95. package/package.json +2 -2
  96. package/scripts/dev-server-scanner.ts +3 -1
  97. package/skills/contrast/SKILL.md +1 -0
  98. package/src/android-drawables.ts +315 -0
  99. package/src/android-theme.ts +9 -0
  100. package/src/bridge-constants.ts +3 -2
  101. package/src/bridge-contract-input.ts +11 -0
  102. package/src/bridge-contract.ts +45 -3
  103. package/src/cloud-contract.ts +1 -0
  104. package/src/host/fetch-proxy-handler.ts +13 -49
  105. package/src/host/fetch-proxy-overrides.ts +69 -12
  106. package/src/kotlin-app.ts +6 -0
  107. package/src/kotlin-host.ts +103 -15
  108. package/src/native-app-identity.ts +16 -3
  109. package/src/swift-compile.ts +426 -29
  110. package/src/swift-distribution-contract.ts +11 -4
  111. package/src/swift-distribution.lock.json +11 -9
  112. package/src/swift-distribution.ts +4 -4
  113. package/src/swift-icu.ts +8 -11
  114. package/src/swift-submit.ts +13 -1
  115. package/src/swift-toolchain.ts +17 -9
  116. package/src/vite-plugin.ts +86 -34
@@ -0,0 +1,315 @@
1
+ // an Android module's drawables as painterResource loads them on the device:
2
+ // every name, with files under the platform versions the device meets, each with
3
+ // the density it was drawn for, for the device to choose between. a vector
4
+ // XML is the ImageVector.Builder calls compose's XmlVectorParser makes from
5
+ // it (attribute defaults, group and clip-path nesting, colors resolved for
6
+ // day and night), any other XML drawable the non-vector XML painterResource
7
+ // refuses. a qualifier Peach does not resolve, or an attribute value it does
8
+ // not read (a theme attribute, a dimension resource, a gradient), is rejected
9
+ // by name.
10
+ import fs from 'node:fs'
11
+ import path from 'node:path'
12
+ import { attributeColor, type ThemeSources } from './android-theme'
13
+ import { parseXml, type XmlElement } from './android-xml'
14
+
15
+ export interface DayNight {
16
+ day: number
17
+ night: number
18
+ }
19
+
20
+ export type VectorCall =
21
+ | {
22
+ call: 'path'
23
+ name: string
24
+ pathData: string
25
+ fillType: 'NonZero' | 'EvenOdd'
26
+ fill: DayNight
27
+ fillAlpha: number
28
+ stroke: DayNight
29
+ strokeAlpha: number
30
+ strokeWidth: number
31
+ cap: 'Butt' | 'Round' | 'Square'
32
+ join: 'Miter' | 'Round' | 'Bevel'
33
+ miter: number
34
+ trimStart: number
35
+ trimEnd: number
36
+ trimOffset: number
37
+ }
38
+ | {
39
+ call: 'group'
40
+ name: string
41
+ rotate: number
42
+ pivotX: number
43
+ pivotY: number
44
+ scaleX: number
45
+ scaleY: number
46
+ translateX: number
47
+ translateY: number
48
+ }
49
+ | { call: 'clip'; name: string; pathData: string }
50
+ | { call: 'clear' }
51
+
52
+ export interface VectorDrawable {
53
+ width: number
54
+ height: number
55
+ viewportWidth: number
56
+ viewportHeight: number
57
+ // null when unset or a theme attribute, which XmlVectorParser ignores
58
+ tint: DayNight | null
59
+ tintMode: 'SrcOver' | 'SrcIn' | 'SrcAtop' | 'Modulate' | 'Screen' | 'Plus'
60
+ autoMirror: boolean
61
+ calls: VectorCall[]
62
+ }
63
+
64
+ // one file a drawable name resolves to under a density and platform version
65
+ export type DrawableFile = { file: string; density: number; version: number } & (
66
+ | { kind: 'vector'; vector: VectorDrawable }
67
+ | { kind: 'xml' }
68
+ | { kind: 'bitmap'; ninePatch: boolean }
69
+ )
70
+
71
+ // a name's files; the device picks one for its display density at runtime
72
+ export interface AndroidDrawable {
73
+ name: string
74
+ files: DrawableFile[]
75
+ }
76
+
77
+ // the device the oracle measures runs API 37
78
+ const DEVICE_API = 37
79
+ // ResTable_config's density values, as the resource table records them
80
+ const BUCKETS: Record<string, number> = {
81
+ ldpi: 120,
82
+ mdpi: 160,
83
+ tvdpi: 213,
84
+ hdpi: 240,
85
+ xhdpi: 320,
86
+ xxhdpi: 480,
87
+ xxxhdpi: 640,
88
+ anydpi: 0xfffe,
89
+ nodpi: 0xffff,
90
+ }
91
+ const DRAWABLE_DIR = /^drawable(?:-([a-z]+|\d+dpi))?(?:-v(\d+))?$/
92
+ const BITMAP = /\.(?:9\.png|png|jpe?g|webp|gif)$/
93
+
94
+ export function readAndroidDrawables(
95
+ moduleDir: string,
96
+ sources: { day: ThemeSources; night: ThemeSources },
97
+ ): AndroidDrawable[] {
98
+ const res = path.join(moduleDir, 'src/main/res')
99
+ const byName = new Map<string, DrawableFile[]>()
100
+ for (const dir of fs.existsSync(res) ? fs.readdirSync(res).sort() : []) {
101
+ if (!dir.startsWith('drawable')) continue
102
+ const match = DRAWABLE_DIR.exec(dir)
103
+ const qualifier = match?.[1]
104
+ // an unqualified directory is the default density, 0
105
+ const density =
106
+ qualifier === undefined
107
+ ? 0
108
+ : (BUCKETS[qualifier] ??
109
+ (/^\d+dpi$/.test(qualifier) ? Number.parseInt(qualifier, 10) : -1))
110
+ if (!match || density === -1)
111
+ throw new Error(
112
+ `${res}/${dir}: drawables under this qualifier are not resolved by peach kotlin yet`,
113
+ )
114
+ const version = Number(match[2] ?? 0)
115
+ for (const entry of fs.readdirSync(path.join(res, dir)).sort()) {
116
+ if (!entry.endsWith('.xml') && !BITMAP.test(entry)) continue
117
+ const name = entry.replace(BITMAP, '').replace(/\.xml$/, '')
118
+ const file = path.join(res, dir, entry)
119
+ const files = byName.get(name) ?? []
120
+ // aapt retains the identifier even when no file matches the device.
121
+ byName.set(name, files)
122
+ if (version > DEVICE_API) continue
123
+ if (BITMAP.test(entry))
124
+ files.push({
125
+ file,
126
+ density,
127
+ version,
128
+ kind: 'bitmap',
129
+ ninePatch: entry.endsWith('.9.png'),
130
+ })
131
+ else {
132
+ const root = parseXml(fs.readFileSync(file, 'utf8'), file).children[0]
133
+ files.push(
134
+ root?.name === 'vector'
135
+ ? {
136
+ file,
137
+ density,
138
+ version,
139
+ kind: 'vector',
140
+ vector: readVector(root, file, sources),
141
+ }
142
+ : { file, density, version, kind: 'xml' },
143
+ )
144
+ }
145
+ }
146
+ }
147
+ return [...byName.entries()]
148
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
149
+ .map(([name, files]) => ({ name, files }))
150
+ }
151
+
152
+ function readVector(
153
+ root: XmlElement,
154
+ file: string,
155
+ sources: { day: ThemeSources; night: ThemeSources },
156
+ ): VectorDrawable {
157
+ const read = (element: XmlElement) => {
158
+ for (const child of element.children)
159
+ if (child.name.startsWith('aapt:'))
160
+ throw new Error(
161
+ `${file}: <${element.name}> has an inline ${child.name} (a gradient), not resolved by peach kotlin yet`,
162
+ )
163
+ const raw = (key: string) => element.attributes[`android:${key}`]
164
+ const reference = (key: string, value: string) => {
165
+ if (/^[@?]/.test(value))
166
+ throw new Error(
167
+ `${file}: <${element.name}> ${key}="${value}" is a reference, not resolved by peach kotlin yet`,
168
+ )
169
+ }
170
+ const float = (key: string, fallback: number) => {
171
+ const value = raw(key)
172
+ if (value === undefined) return fallback
173
+ reference(key, value)
174
+ const number = Number(value)
175
+ if (!Number.isFinite(number))
176
+ throw new Error(`${file}: <${element.name}> ${key}="${value}" is not a number`)
177
+ return number
178
+ }
179
+ const dimension = (key: string) => {
180
+ const value = raw(key)
181
+ if (value === undefined) return 0
182
+ reference(key, value)
183
+ const match = /^(-?[\d.]+)(?:dp|dip)$/.exec(value)
184
+ if (!match)
185
+ throw new Error(
186
+ `${file}: <${element.name}> ${key}="${value}" is not in dp, the unit peach kotlin reads`,
187
+ )
188
+ return Number(match[1])
189
+ }
190
+ const choice = <Value extends string>(
191
+ key: string,
192
+ values: Record<string, Value>,
193
+ fallback: Value,
194
+ ) => {
195
+ const value = raw(key)
196
+ if (value === undefined) return fallback
197
+ const chosen = values[value]
198
+ if (!chosen)
199
+ throw new Error(
200
+ `${file}: <${element.name}> ${key}="${value}" is not one of ${Object.keys(values).join(', ')}`,
201
+ )
202
+ return chosen
203
+ }
204
+ const color = (key: string): DayNight => {
205
+ const value = raw(key)
206
+ if (value === undefined) return { day: 0, night: 0 }
207
+ if (value.startsWith('?'))
208
+ throw new Error(
209
+ `${file}: <${element.name}> ${key}="${value}" is a theme attribute, not resolved by peach kotlin yet`,
210
+ )
211
+ return {
212
+ day: attributeColor(value, sources.day),
213
+ night: attributeColor(value, sources.night),
214
+ }
215
+ }
216
+ return { raw, float, dimension, choice, color }
217
+ }
218
+ const vector = read(root)
219
+ const viewportWidth = vector.float('viewportWidth', 0)
220
+ const viewportHeight = vector.float('viewportHeight', 0)
221
+ if (viewportWidth <= 0) throw new Error(`${file}: <vector> requires viewportWidth > 0`)
222
+ if (viewportHeight <= 0)
223
+ throw new Error(`${file}: <vector> requires viewportHeight > 0`)
224
+ const tint = vector.raw('tint')
225
+ const calls: VectorCall[] = []
226
+ // parseCurrentVectorNode: a clip-path opens a group closed with its
227
+ // enclosing group, so each group end clears its clip-path groups too
228
+ const walk = (element: XmlElement, nested: number): number => {
229
+ const node = read(element)
230
+ if (element.name === 'path') {
231
+ const pathData = node.raw('pathData')
232
+ if (pathData === undefined) throw new Error(`${file}: <path> has no pathData`)
233
+ calls.push({
234
+ call: 'path',
235
+ name: node.raw('name') ?? '',
236
+ pathData,
237
+ fillType: node.choice(
238
+ 'fillType',
239
+ { nonZero: 'NonZero', evenOdd: 'EvenOdd' },
240
+ 'NonZero',
241
+ ),
242
+ fill: node.color('fillColor'),
243
+ fillAlpha: node.float('fillAlpha', 1),
244
+ stroke: node.color('strokeColor'),
245
+ strokeAlpha: node.float('strokeAlpha', 1),
246
+ strokeWidth: node.float('strokeWidth', 1),
247
+ cap: node.choice(
248
+ 'strokeLineCap',
249
+ { butt: 'Butt', round: 'Round', square: 'Square' },
250
+ 'Butt',
251
+ ),
252
+ join: node.choice(
253
+ 'strokeLineJoin',
254
+ { miter: 'Miter', round: 'Round', bevel: 'Bevel' },
255
+ 'Miter',
256
+ ),
257
+ miter: node.float('strokeMiterLimit', 4),
258
+ trimStart: node.float('trimPathStart', 0),
259
+ trimEnd: node.float('trimPathEnd', 1),
260
+ trimOffset: node.float('trimPathOffset', 0),
261
+ })
262
+ return nested
263
+ }
264
+ if (element.name === 'clip-path') {
265
+ calls.push({
266
+ call: 'clip',
267
+ name: node.raw('name') ?? '',
268
+ pathData: node.raw('pathData') ?? '',
269
+ })
270
+ return nested + 1
271
+ }
272
+ if (element.name === 'group') {
273
+ calls.push({
274
+ call: 'group',
275
+ name: node.raw('name') ?? '',
276
+ rotate: node.float('rotation', 0),
277
+ pivotX: node.float('pivotX', 0),
278
+ pivotY: node.float('pivotY', 0),
279
+ scaleX: node.float('scaleX', 1),
280
+ scaleY: node.float('scaleY', 1),
281
+ translateX: node.float('translateX', 0),
282
+ translateY: node.float('translateY', 0),
283
+ })
284
+ let inner = 0
285
+ for (const child of element.children) inner = walk(child, inner)
286
+ for (let index = 0; index <= inner; index++) calls.push({ call: 'clear' })
287
+ return nested
288
+ }
289
+ // the pull parser still reaches the children of a tag it ignores
290
+ return element.children.reduce((inner, child) => walk(child, inner), nested)
291
+ }
292
+ // clip-path groups left open at the root close in build()
293
+ root.children.reduce((nested, child) => walk(child, nested), 0)
294
+ return {
295
+ width: vector.dimension('width'),
296
+ height: vector.dimension('height'),
297
+ viewportWidth,
298
+ viewportHeight,
299
+ tint: tint === undefined || tint.startsWith('?') ? null : vector.color('tint'),
300
+ tintMode: vector.choice(
301
+ 'tintMode',
302
+ {
303
+ src_over: 'SrcOver',
304
+ src_in: 'SrcIn',
305
+ src_atop: 'SrcAtop',
306
+ multiply: 'Modulate',
307
+ screen: 'Screen',
308
+ add: 'Plus',
309
+ },
310
+ 'SrcIn',
311
+ ),
312
+ autoMirror: vector.raw('autoMirrored') === 'true',
313
+ calls,
314
+ }
315
+ }
@@ -195,3 +195,12 @@ export function resourceColor(
195
195
  ref = { namespace: nextNamespace, name: next[2] }
196
196
  }
197
197
  }
198
+
199
+ // a color an app XML attribute writes directly: a hex literal or a reference
200
+ // to an app or framework color resource
201
+ export function attributeColor(value: string, sources: ThemeSources): number {
202
+ if (value.startsWith('#')) return color(value)
203
+ const ref = /^@(?:(android):)?color\/(.+)$/.exec(value)
204
+ if (!ref?.[2]) throw new Error(`the color ${value} is not resolved by peach kotlin yet`)
205
+ return resourceColor(ref[1] ? 'android' : 'app', ref[2], sources)
206
+ }
@@ -97,8 +97,9 @@ export function resolveSootsimBridgePortForRuntimeLocation(
97
97
  const hrefUrl = parseHrefUrl(input.href)
98
98
  const httpPort = parsePort(input.httpPort) ?? parsePort(hrefUrl?.port)
99
99
  if (httpPort === null) return DEFAULT_SOOTSIM_BRIDGE_PORT
100
+ const hostedShell = hrefUrl && /^\/(?:simulator|sootsim)(?:\/|$)/.test(hrefUrl.pathname)
100
101
  if (
101
- hrefUrl?.pathname.startsWith('/sootsim') &&
102
+ hostedShell &&
102
103
  (hrefUrl.searchParams.has('embed') || hrefUrl.searchParams.has('nativePreview'))
103
104
  ) {
104
105
  return resolveSootsimBridgePortForHttpPort({
@@ -107,7 +108,7 @@ export function resolveSootsimBridgePortForRuntimeLocation(
107
108
  })
108
109
  }
109
110
  if (
110
- hrefUrl?.pathname.startsWith('/sootsim') &&
111
+ hostedShell &&
111
112
  httpPort >= SOOTSIM_SITE_DEV_HTTP_BASE_PORT &&
112
113
  httpPort <= SOOTSIM_SITE_DEV_HTTP_BASE_PORT + MAX_LOCAL_DEV_PORT_OFFSET
113
114
  ) {
@@ -192,6 +192,17 @@ export function parsePerformStep(value: unknown, index: number): SimPerformStep
192
192
  }
193
193
  case 'type':
194
194
  return { type, text: stringValue(step.text, `${path}.text`) }
195
+ case 'typeInto': {
196
+ const nodeId = numberValue(step.nodeId, `${path}.nodeId`)
197
+ if (!Number.isSafeInteger(nodeId) || nodeId === 0) {
198
+ validationFailure(`${path}.nodeId`, 'must be a nonzero safe integer')
199
+ }
200
+ return {
201
+ type,
202
+ text: stringValue(step.text, `${path}.text`),
203
+ nodeId,
204
+ }
205
+ }
195
206
  case 'key':
196
207
  return { type, key: stringValue(step.key, `${path}.key`) }
197
208
  case 'dismissKeyboard':
@@ -40,6 +40,7 @@ export type BridgeCommandType =
40
40
  | 'resolve'
41
41
  | 'reset'
42
42
  | 'camera'
43
+ | 'location'
43
44
  | 'diagnostics'
44
45
  | 'storageSnapshot'
45
46
 
@@ -109,6 +110,8 @@ export interface WsCommand {
109
110
  resetOptions?: ResetOptions
110
111
  // camera — fixture injection into the host camera pipeline
111
112
  camera?: CameraCommand
113
+ // location — the simulated device location (simctl location equivalent)
114
+ location?: LocationCommand
112
115
  // diagnostics — read-only engine debug state: channel recording, the sheet /
113
116
  // portal / boundary finders, and the recent event ring.
114
117
  diagnostics?: DiagnosticsOptions
@@ -172,6 +175,7 @@ export type PerformStep =
172
175
  }
173
176
  | { type: 'scroll'; id: string; x?: number; y?: number; animated?: boolean }
174
177
  | { type: 'type'; text: string }
178
+ | { type: 'typeInto'; text: string; nodeId: number }
175
179
  | { type: 'key'; key: string }
176
180
  | { type: 'dismissKeyboard' }
177
181
  | { type: 'wait'; ms: number }
@@ -289,6 +293,7 @@ export function performStepRefusal(type: PerformStep['type']): string | null {
289
293
  case 'pinch':
290
294
  case 'scroll':
291
295
  case 'type':
296
+ case 'typeInto':
292
297
  case 'key':
293
298
  case 'dismissKeyboard':
294
299
  case 'setElementValue':
@@ -348,6 +353,7 @@ export interface SemanticReadyProbe {
348
353
  nodes: number
349
354
  targets: number
350
355
  liveFrameActive: boolean
356
+ browserSurfaceCount: number
351
357
  liveFrameChannels: number
352
358
  liveFramePublishes: number
353
359
  errors: number
@@ -373,9 +379,10 @@ export const HEADLESS_TENANT_FETCH_HUNG_MARKER = 'headless tenant fetch hung'
373
379
 
374
380
  export function readyProbeHasContent(
375
381
  probe: Pick<SemanticReadyProbe, 'nodes' | 'targets'> &
376
- Partial<Pick<SemanticReadyProbe, 'liveFrameActive'>>,
382
+ Partial<Pick<SemanticReadyProbe, 'liveFrameActive' | 'browserSurfaceCount'>>,
377
383
  ): boolean {
378
384
  return (
385
+ (probe.browserSurfaceCount ?? 0) > 0 ||
379
386
  probe.liveFrameActive ||
380
387
  probe.targets > 0 ||
381
388
  probe.nodes >= SEMANTIC_READY_CONTENT_NODE_FLOOR
@@ -384,9 +391,11 @@ export function readyProbeHasContent(
384
391
 
385
392
  export function readyProbeHasTargetContent(
386
393
  probe: Pick<SemanticReadyProbe, 'targets'> &
387
- Partial<Pick<SemanticReadyProbe, 'liveFrameActive'>>,
394
+ Partial<Pick<SemanticReadyProbe, 'liveFrameActive' | 'browserSurfaceCount'>>,
388
395
  ): boolean {
389
- return probe.liveFrameActive || probe.targets > 0
396
+ return (
397
+ (probe.browserSurfaceCount ?? 0) > 0 || probe.liveFrameActive || probe.targets > 0
398
+ )
390
399
  }
391
400
 
392
401
  // one probe shows a ready app: it has said so with content behind it, or it
@@ -605,3 +614,36 @@ export interface CameraResult {
605
614
  rate?: number
606
615
  error?: string
607
616
  }
617
+
618
+ // ---------------------------------------------------------------------------
619
+ // location — simulated device location (simctl location equivalent)
620
+ // ---------------------------------------------------------------------------
621
+
622
+ // the host thread owns the simulated location, matching iOS: a device has one
623
+ // current location regardless of how many apps watch it. tenant and shell
624
+ // workers reach it through the same host-service geolocation seam that used
625
+ // to forward to the host browser's real navigator.geolocation (leaking the
626
+ // operator's real position). a cleared device reports iOS's own default, not
627
+ // an empty/pending state invented here.
628
+ export interface LocationFix {
629
+ latitude: number
630
+ longitude: number
631
+ altitude?: number
632
+ accuracy?: number
633
+ heading?: number
634
+ speed?: number
635
+ }
636
+
637
+ export type LocationCommand =
638
+ | ({ action: 'set' } & LocationFix)
639
+ | { action: 'clear' }
640
+ | { action: 'get' }
641
+
642
+ export interface LocationResult {
643
+ ok: boolean
644
+ // 'custom' = an app or `peach location set` chose this fix, 'default' = iOS's
645
+ // own un-set simulator location
646
+ source: 'custom' | 'default'
647
+ fix?: LocationFix
648
+ error?: string
649
+ }
@@ -77,6 +77,7 @@ export const RNX_CLOUD_COMMAND_SCOPES = {
77
77
  flowStatus: 'drive',
78
78
  reset: 'reset',
79
79
  camera: 'media',
80
+ location: 'media',
80
81
  // string evaluation and arbitrary bridge calls are maestro's boundary: the
81
82
  // customer sdk never carries this scope, and the service grants it only to
82
83
  // the account api key caller. close rides along, since ending the page ends
@@ -28,8 +28,8 @@ import https from 'https'
28
28
  import { finished, pipeline } from 'stream/promises'
29
29
  import { isLoopbackHost, normalizeHostname } from '../backend-origin.ts'
30
30
  import {
31
- FETCH_PROXY_NATIVE_USER_AGENT_HEADER,
32
- getFetchProxyTargetHeaders,
31
+ buildFetchProxyUpstreamHeaders,
32
+ nodeRequestHeaderEntries,
33
33
  resolveFetchProxyTargetUrl,
34
34
  } from './fetch-proxy-overrides.ts'
35
35
 
@@ -50,27 +50,6 @@ function fetchProxyAgentFor(targetUrl: URL): http.Agent | https.Agent {
50
50
  return targetUrl.protocol === 'https:' ? fetchProxyHttpsAgent : fetchProxyHttpAgent
51
51
  }
52
52
 
53
- const STRIP_FETCH_PROXY_HEADERS = new Set([
54
- 'host',
55
- 'origin',
56
- 'referer',
57
- 'user-agent',
58
- 'accept-encoding',
59
- 'cookie',
60
- 'connection',
61
- 'keep-alive',
62
- 'transfer-encoding',
63
- 'upgrade',
64
- 'content-length',
65
- 'sec-fetch-site',
66
- 'sec-fetch-mode',
67
- 'sec-fetch-dest',
68
- 'sec-ch-ua',
69
- 'sec-ch-ua-mobile',
70
- 'sec-ch-ua-platform',
71
- FETCH_PROXY_NATIVE_USER_AGENT_HEADER,
72
- ])
73
-
74
53
  const FETCH_PROXY_CORS_HEADERS: Record<string, string> = {
75
54
  'access-control-allow-origin': '*',
76
55
  'access-control-allow-methods': 'GET,POST,PUT,DELETE,PATCH,OPTIONS',
@@ -108,21 +87,7 @@ export function buildFetchProxyHeaders(
108
87
  reqHeaders: Record<string, string | string[] | undefined>,
109
88
  targetUrl?: URL,
110
89
  ): Record<string, string> {
111
- const headers: Record<string, string> = {}
112
- for (const [key, value] of Object.entries(reqHeaders)) {
113
- if (!value) continue
114
- if (STRIP_FETCH_PROXY_HEADERS.has(key.toLowerCase())) continue
115
- headers[key] = Array.isArray(value) ? value.join(', ') : value
116
- }
117
- const rawNativeUserAgent = reqHeaders[FETCH_PROXY_NATIVE_USER_AGENT_HEADER]
118
- const nativeUserAgent = Array.isArray(rawNativeUserAgent)
119
- ? rawNativeUserAgent[0]
120
- : rawNativeUserAgent
121
- Object.assign(
122
- headers,
123
- targetUrl ? getFetchProxyTargetHeaders(targetUrl, nativeUserAgent) : {},
124
- )
125
- return headers
90
+ return buildFetchProxyUpstreamHeaders(nodeRequestHeaderEntries(reqHeaders), targetUrl)
126
91
  }
127
92
 
128
93
  export function buildAppApiProxyHeaders(
@@ -188,17 +153,6 @@ export async function handleFetchProxyRequest(
188
153
  return
189
154
  }
190
155
 
191
- let body: Buffer | undefined
192
- if (req.method !== 'GET' && req.method !== 'HEAD') {
193
- const chunks: Buffer[] = []
194
- for await (const chunk of req) {
195
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
196
- }
197
- if (chunks.length > 0) {
198
- body = Buffer.concat(chunks)
199
- }
200
- }
201
-
202
156
  const originalMethod = req.method || 'GET'
203
157
  const proxy = async (
204
158
  targetUrl: URL,
@@ -300,7 +254,17 @@ export async function handleFetchProxyRequest(
300
254
  await pipeline(proxyRes, res)
301
255
  }
302
256
 
257
+ let body: Buffer | undefined
303
258
  try {
259
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
260
+ const chunks: Buffer[] = []
261
+ for await (const chunk of req) {
262
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
263
+ }
264
+ if (chunks.length > 0) {
265
+ body = Buffer.concat(chunks)
266
+ }
267
+ }
304
268
  await proxy(upstreamUrl, originalMethod, body, 0)
305
269
  } catch (err) {
306
270
  const norm = normalizeHostname(upstreamUrl.hostname)
@@ -1,17 +1,17 @@
1
- // shared upstream header policy for SootSim's CORS-bypassing fetch proxy.
1
+ // shared upstream header policy for Peach's CORS-bypassing fetch proxy.
2
2
  // requests still forward tenant auth and app headers, but the proxy transport
3
3
  // defaults to native-app semantics: no browser Origin, Referer, Sec-Fetch-*.
4
- // the User-Agent an NSURLSession request on a real device sends is the
5
- // app's own (`<app>/<version> CFNetwork/<cf> Darwin/<darwin>`), never a
6
- // browser string; the engine computes that shape (bundle-exec/app-config
7
- // identity + the device profile's OS) and hands it to the proxy through this
8
- // header, since `fetch()` cannot set `User-Agent` itself (forbidden header
4
+ // the User-Agent an NSURLSession request on a real device sends is CFNetwork's
5
+ // default (`<CFBundleName>/<CFBundleVersion> CFNetwork/<cf> Darwin/<darwin>`),
6
+ // never a browser string; the engine computes it from the app identity
7
+ // (packages/peach-engine/src/ios/native-user-agent.ts) and hands it to the
8
+ // proxy through this header, since `fetch()` cannot set `User-Agent` itself (forbidden header
9
9
  // name). web-backed mobile APIs that require a specific web origin opt in
10
10
  // below.
11
11
 
12
12
  // the engine attaches the native-shaped User-Agent it computed under this
13
13
  // name; the proxy moves it onto the real `user-agent` header and never lets
14
- // the name itself reach upstream (see STRIP_FETCH_PROXY_HEADERS).
14
+ // the name itself reach upstream (see buildFetchProxyUpstreamHeaders).
15
15
  export const FETCH_PROXY_NATIVE_USER_AGENT_HEADER = 'x-sootsim-native-user-agent'
16
16
 
17
17
  const HOST_HEADER_OVERRIDES: Array<{
@@ -82,14 +82,71 @@ export function resolveFetchProxyTargetUrl(requested: URL): URL {
82
82
  return replacement ? new URL(replacement) : requested
83
83
  }
84
84
 
85
- export function getFetchProxyTargetHeaders(
86
- targetUrl: URL,
87
- nativeUserAgent?: string,
85
+ // browser-context and hop headers a native NSURLSession request never sends.
86
+ // the inbound reverse-proxy hop headers (x-forwarded-*, x-real-ip, forwarded)
87
+ // describe the browser→proxy hop: Clerk's FAPI attributes a request to an
88
+ // instance via x-forwarded-host and rejects a foreign one as "Invalid host",
89
+ // and the client-ip variants would leak the viewer's IP.
90
+ const STRIP_FETCH_PROXY_REQUEST_HEADERS = new Set([
91
+ 'host',
92
+ 'x-forwarded',
93
+ 'x-real-ip',
94
+ 'forwarded',
95
+ 'origin',
96
+ 'referer',
97
+ 'user-agent',
98
+ 'accept-encoding',
99
+ 'cookie',
100
+ 'connection',
101
+ 'keep-alive',
102
+ 'transfer-encoding',
103
+ 'upgrade',
104
+ 'content-length',
105
+ 'sec-fetch-site',
106
+ 'sec-fetch-mode',
107
+ 'sec-fetch-dest',
108
+ 'sec-ch-ua',
109
+ 'sec-ch-ua-mobile',
110
+ 'sec-ch-ua-platform',
111
+ FETCH_PROXY_NATIVE_USER_AGENT_HEADER,
112
+ ])
113
+
114
+ // the one upstream request header policy every fetch-proxy receiver applies
115
+ // (the local dev/daemon handler, the hosted Contrast /__proxy, the demo
116
+ // gateway), so they cannot diverge: forward app headers, drop browser and hop
117
+ // headers and the carrier, and move the carrier's native User-Agent onto
118
+ // `user-agent`. header names arrive lowercased from both node and fetch.
119
+ export function buildFetchProxyUpstreamHeaders(
120
+ requestHeaders: Iterable<readonly [string, string]>,
121
+ targetUrl?: URL,
88
122
  ): Record<string, string> {
89
- const hostOverrides = headerOverridesFor(targetUrl.hostname)
123
+ const headers: Record<string, string> = {}
124
+ let nativeUserAgent: string | undefined
125
+ for (const [rawKey, value] of requestHeaders) {
126
+ const key = rawKey.toLowerCase()
127
+ if (key === FETCH_PROXY_NATIVE_USER_AGENT_HEADER) nativeUserAgent = value
128
+ if (STRIP_FETCH_PROXY_REQUEST_HEADERS.has(key) || key.startsWith('x-forwarded-')) {
129
+ continue
130
+ }
131
+ headers[key] = value
132
+ }
133
+ if (!targetUrl) return headers
90
134
  return {
135
+ ...headers,
91
136
  'accept-encoding': 'identity',
92
137
  ...(nativeUserAgent ? { 'user-agent': nativeUserAgent } : {}),
93
- ...hostOverrides?.headers,
138
+ ...headerOverridesFor(targetUrl.hostname)?.headers,
139
+ }
140
+ }
141
+
142
+ // node's IncomingMessage headers as the entries the policy reads.
143
+ export function nodeRequestHeaderEntries(
144
+ headers: Record<string, string | string[] | undefined>,
145
+ ): Array<[string, string]> {
146
+ const entries: Array<[string, string]> = []
147
+ for (const [key, value] of Object.entries(headers)) {
148
+ if (!value) continue
149
+ entries.push([key, Array.isArray(value) ? value.join(', ') : value])
94
150
  }
151
+ return entries
95
152
  }