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
@@ -39,6 +39,7 @@ import {
39
39
  type RnxCloudSimInstance,
40
40
  type RnxCloudSimView,
41
41
  } from '../src/cloud-contract.ts'
42
+ import { isRecord } from '../src/is-record'
42
43
  import {
43
44
  RNX_METRO_MODULE_IDENTITY_VERSION,
44
45
  type RNXMetroModuleIdentityMetadata,
@@ -62,7 +63,6 @@ import type {
62
63
  ParsedBridgeCliArgs,
63
64
  WsBridge,
64
65
  } from './ws-bridge.ts'
65
- import { isRecord } from '../src/is-record'
66
66
 
67
67
  export const DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin
68
68
  export const MAX_RNX_CLOUD_BUNDLE_BYTES = RNX_CLOUD_MAX_ARTIFACT_BYTES
@@ -1633,7 +1633,7 @@ function readBoxDisplayGrant(value: unknown): BoxDisplayGrant {
1633
1633
  }
1634
1634
 
1635
1635
  // mints a watch-only display grant from the box and builds the bare shell
1636
- // watch url for it: the same /sootsim/#remoteEngine fragment the nano service
1636
+ // watch url for it: the same /simulator#remoteEngine fragment the nano service
1637
1637
  // mints, pointed at the box's display socket instead. the box token stays in
1638
1638
  // this process; only the grant travels in the fragment.
1639
1639
  export async function requestBoxWatchUrl(options: {
@@ -1683,7 +1683,7 @@ export async function requestBoxWatchUrl(options: {
1683
1683
  throw new Error('box display-grant returned unreadable JSON')
1684
1684
  }
1685
1685
  const grant = readBoxDisplayGrant(parsed)
1686
- const watch = new URL('/sootsim/', rnxPublicBrand.origin)
1686
+ const watch = new URL('/simulator', rnxPublicBrand.origin)
1687
1687
  // the shell boots its stage at its own default device, while the box page
1688
1688
  // hosts its simulator at the grant's device profile. without ?device= the
1689
1689
  // tenant refuses the host hello on dimensions and paints nothing — the
@@ -30,6 +30,7 @@ const NODE_COMMAND_NAMES = [
30
30
  'state',
31
31
  'reset',
32
32
  'camera',
33
+ 'location',
33
34
  'mode',
34
35
  'debug',
35
36
  'timeline',
@@ -286,6 +287,7 @@ export function createRnxCommandInvocation(
286
287
  case 'reset':
287
288
  case 'permissions':
288
289
  case 'camera':
290
+ case 'location':
289
291
  return { ...common, family: 'action' }
290
292
  case 'screenshot':
291
293
  return { ...common, family: 'screenshot', command: 'screenshot' }
@@ -357,6 +357,7 @@ function looksLikeSootsimUrl(target: string): boolean {
357
357
  url.searchParams.has('bundle') ||
358
358
  url.searchParams.has('demo') ||
359
359
  url.pathname.includes('/sootsim/index.html') ||
360
+ /^\/simulator(?:\/(?:rn(?:\/[^/]+)?|app\/[^/]+|dock\/[^/]+))?$/.test(pathname) ||
360
361
  pathname === '/sootsim' ||
361
362
  url.pathname === '/__soot' ||
362
363
  url.pathname === '/__soot/' ||
@@ -36,6 +36,10 @@ import {
36
36
  setDebugChannels,
37
37
  } from './inspect/core'
38
38
  import { callTestBridge } from './inspect/shared'
39
+ import type {
40
+ ImageAuditReport,
41
+ ImageAuditRow,
42
+ } from '../../../peach-engine/src/render-worker/compositor-protocol'
39
43
 
40
44
  interface DebugOptions {
41
45
  port?: number
@@ -289,33 +293,6 @@ async function call<T = unknown>(bridge: WsBridge, code: string): Promise<T> {
289
293
  return evalInBridge<T>(bridge, code)
290
294
  }
291
295
 
292
- interface ImageAuditRowView {
293
- nodeId: number
294
- type: string
295
- testID: string | null
296
- sourceUri: string | null
297
- resizeMode: string | null
298
- sampling: string | null
299
- vector: boolean
300
- intrinsic: { width: number; height: number } | null
301
- decoded: { width: number; height: number }
302
- sampled: { width: number; height: number }
303
- destination: { x: number; y: number; width: number; height: number }
304
- decision: { gpuBacked: boolean; hasMipmaps: boolean }
305
- deviceScale: number
306
- dpr: number
307
- needed: { width: number; height: number }
308
- effective: { width: number; height: number }
309
- ceiling: { width: number; height: number } | null
310
- shortfall: number | null
311
- }
312
-
313
- interface ImageAuditReportView {
314
- draws: number
315
- samplingCounts: { mipmapped: number; cubic: number; repeat: number; none: number }
316
- rows: ImageAuditRowView[]
317
- }
318
-
319
296
  function readNumberFlag(args: string[], flag: string): number | null {
320
297
  const index = args.indexOf(flag)
321
298
  if (index < 0) return null
@@ -327,13 +304,13 @@ function readNumberFlag(args: string[], flag: string): number | null {
327
304
  // request is what forces the frame: it runs the same publish-and-paint pass
328
305
  // `peach screenshot` does, so the rows describe pixels that were actually
329
306
  // produced rather than a tree walk's guess about them.
330
- async function runImageAudit(bridge: WsBridge): Promise<ImageAuditReportView> {
307
+ async function runImageAudit(bridge: WsBridge): Promise<ImageAuditReport> {
331
308
  await call(
332
309
  bridge,
333
310
  "window.__sootsimCompositor.getStats(false, false, undefined, 'enable').then(() => 'enabled')",
334
311
  )
335
312
  await bridge.send({ type: 'screenshot' })
336
- const stats = await call<{ imageAudit?: ImageAuditReportView | null }>(
313
+ const stats = await call<{ imageAudit?: ImageAuditReport | null }>(
337
314
  bridge,
338
315
  "window.__sootsimCompositor.getStats(false, false, undefined, 'disable').then((s) => ({ imageAudit: s.imageAudit }))",
339
316
  )
@@ -346,15 +323,15 @@ function ratioText(value: number | null): string {
346
323
  return value === null ? ' - ' : value.toFixed(3).padStart(6)
347
324
  }
348
325
 
349
- function sourceText(row: ImageAuditRowView): string {
326
+ function sourceText(row: ImageAuditRow): string {
350
327
  const uri = row.sourceUri ?? row.testID ?? `node ${row.nodeId}`
351
328
  if (uri.length <= 58) return uri
352
329
  return `...${uri.slice(-55)}`
353
330
  }
354
331
 
355
332
  function printImageAudit(
356
- report: ImageAuditReportView,
357
- rows: ImageAuditRowView[],
333
+ report: ImageAuditReport,
334
+ rows: ImageAuditRow[],
358
335
  minimum: number,
359
336
  ): void {
360
337
  const withCeiling = report.rows.filter((row) => row.shortfall !== null)
@@ -365,7 +342,7 @@ function printImageAudit(
365
342
  )
366
343
  console.log(
367
344
  ` sampling: mipmapped ${report.samplingCounts.mipmapped} · cubic ${report.samplingCounts.cubic} · ` +
368
- `repeat ${report.samplingCounts.repeat} · none ${report.samplingCounts.none}`,
345
+ `repeat ${report.samplingCounts.repeat} · exact ${report.samplingCounts.exact} · none ${report.samplingCounts.none}`,
369
346
  )
370
347
  if (rows.length === 0) {
371
348
  console.log(' every image delivered its source resolution')
@@ -1,4 +1,5 @@
1
1
  import { BridgeInputError } from '../../src/bridge-contract-input'
2
+ import type { PerformResult } from '../../src/bridge-contract'
2
3
  import type { SimPerformStep } from '../../src/sim-client'
3
4
 
4
5
  interface TargetedDoubleTapAction {
@@ -13,10 +14,17 @@ interface TargetedLongPressAction {
13
14
  durationMs: number
14
15
  }
15
16
 
17
+ interface TargetedTypeAction {
18
+ type: 'targetedType'
19
+ id: string
20
+ text: string
21
+ }
22
+
16
23
  export type DoChainAction =
17
24
  | SimPerformStep
18
25
  | TargetedDoubleTapAction
19
26
  | TargetedLongPressAction
27
+ | TargetedTypeAction
20
28
 
21
29
  const DO_CHAIN_ACTIONS = new Set([
22
30
  'tap',
@@ -170,10 +178,7 @@ export function parseDoChainActions(args: string[]): DoChainAction[] {
170
178
  case 'type-into': {
171
179
  const text = values.slice(1).join(' ')
172
180
  if (!values[0] || !text) invalidAction(index, 'type-into <id> <text>')
173
- return [
174
- { type: 'tapId', id: values[0] },
175
- { type: 'type', text },
176
- ]
181
+ return [{ type: 'targetedType', id: values[0], text }]
177
182
  }
178
183
 
179
184
  case 'key':
@@ -344,8 +349,37 @@ export async function runDoChain(
344
349
  await checkSimHealth(sim)
345
350
 
346
351
  const steps: SimPerformStep[] = []
352
+ const result: PerformResult = { ok: true, completed: 0, steps: [], durationMs: 0 }
353
+ const deadline = Date.now() + parsed.commandTimeoutMs
354
+ const flushSteps = async () => {
355
+ if (steps.length === 0) return
356
+ const timeoutMs = deadline - Date.now()
357
+ if (timeoutMs <= 0) throw new BridgeInputError('do chain exceeded its timeout')
358
+ if (!sim) throw new BridgeInputError('do chain has no connected simulator')
359
+ let batch: PerformResult
360
+ try {
361
+ batch = await sim.perform(steps, { timeoutMs })
362
+ } catch (error) {
363
+ if (!(error instanceof SimPerformError)) throw error
364
+ batch = error.result
365
+ }
366
+ result.steps.push(
367
+ ...batch.steps.map((step) => ({ ...step, index: step.index + result.completed })),
368
+ )
369
+ result.completed += batch.completed
370
+ result.durationMs += batch.durationMs
371
+ steps.length = 0
372
+ if (!batch.ok)
373
+ throw new SimPerformError({ ...result, ok: false, error: batch.error })
374
+ }
347
375
  for (const action of actions) {
348
- if (action.type !== 'targetedDoubleTap' && action.type !== 'targetedLongPress') {
376
+ // the named field can mount as a result of the preceding chain steps.
377
+ if (action.type === 'targetedType') await flushSteps()
378
+ if (
379
+ action.type !== 'targetedDoubleTap' &&
380
+ action.type !== 'targetedLongPress' &&
381
+ action.type !== 'targetedType'
382
+ ) {
349
383
  steps.push(action)
350
384
  continue
351
385
  }
@@ -359,6 +393,22 @@ export async function runDoChain(
359
393
  if (refusal) {
360
394
  throw new BridgeInputError(`do chain #${action.id}: ${refusal}`)
361
395
  }
396
+ if (action.type === 'targetedType') {
397
+ if (
398
+ typeof target.nodeId !== 'number' ||
399
+ !Number.isSafeInteger(target.nodeId) ||
400
+ target.nodeId === 0
401
+ ) {
402
+ throw new BridgeInputError(
403
+ 'type-into requires a resolved text input node identity',
404
+ )
405
+ }
406
+ steps.push(
407
+ { type: 'tap', x: target.x, y: target.y, target: { nodeId: target.nodeId } },
408
+ { type: 'typeInto', text: action.text, nodeId: target.nodeId },
409
+ )
410
+ continue
411
+ }
362
412
  steps.push(
363
413
  action.type === 'targetedDoubleTap'
364
414
  ? {
@@ -376,7 +426,7 @@ export async function runDoChain(
376
426
  )
377
427
  }
378
428
 
379
- const result = await sim.perform(steps, { timeoutMs: parsed.commandTimeoutMs })
429
+ await flushSteps()
380
430
  if (!skipSettle) {
381
431
  try {
382
432
  const budgetMs = isAgentEnv() ? 400 : 200
@@ -1163,6 +1163,7 @@ export interface WaitReadyStatus {
1163
1163
  nodes: number
1164
1164
  targets: number
1165
1165
  liveFrameActive: boolean
1166
+ browserSurfaceCount: number
1166
1167
  liveFrameChannels: number
1167
1168
  liveFramePublishes: number
1168
1169
  flag: unknown
@@ -1316,6 +1317,7 @@ function waitReadyStatus(result: SemanticWaitResult, ready: boolean): WaitReadyS
1316
1317
  nodes: probe?.nodes ?? 0,
1317
1318
  targets: probe?.targets ?? 0,
1318
1319
  liveFrameActive: probe?.liveFrameActive ?? false,
1320
+ browserSurfaceCount: probe?.browserSurfaceCount ?? 0,
1319
1321
  liveFrameChannels: probe?.liveFrameChannels ?? 0,
1320
1322
  liveFramePublishes: probe?.liveFramePublishes ?? 0,
1321
1323
  flag: probe?.flag,
@@ -90,7 +90,8 @@ function summarizeSimUrl(url: string | undefined): string | null {
90
90
  if (
91
91
  parsed.pathname.includes('/sootsim/index.html') ||
92
92
  parsed.pathname === '/sootsim/' ||
93
- parsed.pathname === '/sootsim'
93
+ parsed.pathname === '/sootsim' ||
94
+ /^\/simulator(?:\/|$)/.test(parsed.pathname)
94
95
  ) {
95
96
  return 'embedded peach'
96
97
  }
@@ -80,6 +80,16 @@ export async function waitForSootsimIdle({
80
80
  let requestInFlight = 0
81
81
  let renderStatsAvailable = false
82
82
  let frameCount = -1
83
+ let shellAnimating = false
84
+ // strict also waits out shell motion: a system alert, sheet or menu
85
+ // animates in the shell worker while the app's own stats read still,
86
+ // so its presentation is complete only once the shell's list empties.
87
+ if (strict) {
88
+ try {
89
+ const motion = await window.__sootsimTest?.listAnimations?.()
90
+ shellAnimating = Array.isArray(motion) && motion.some((anim) => anim.realm === 'shell')
91
+ } catch {}
92
+ }
83
93
  try {
84
94
  const stats = await window.__sootsimRenderHost?.queryStats?.()
85
95
  if (stats) {
@@ -117,7 +127,7 @@ export async function waitForSootsimIdle({
117
127
  }
118
128
  walk(root)
119
129
  }
120
- return { layout: nodes.join(';'), frameCount, animating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
130
+ return { layout: nodes.join(';'), frameCount, animating, shellAnimating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
121
131
  }
122
132
 
123
133
  // how long generic background network is allowed to keep us waiting AFTER
@@ -148,13 +158,16 @@ export async function waitForSootsimIdle({
148
158
  const snapshot = await readSnapshot()
149
159
  polls++
150
160
  if (snapshot.layoutDirty) dirtyPolls++
151
- if (snapshot.animating) animatingPolls++
161
+ if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
152
162
  if (polls > 1 && snapshot.layout !== lastLayout) layoutChangedPolls++
153
163
  const painted = paintStill && snapshot.frameCount !== lastFrameCount
154
164
  if (polls > 1 && painted) paintedPolls++
155
165
  const strictOk =
156
166
  !strict ||
157
- (snapshot.renderStatsAvailable && !snapshot.animating && !snapshot.layoutDirty)
167
+ (snapshot.renderStatsAvailable &&
168
+ !snapshot.animating &&
169
+ !snapshot.shellAnimating &&
170
+ !snapshot.layoutDirty)
158
171
  // visually settled: no animations, no image content loading, layout
159
172
  // unchanged since the last poll.
160
173
  const visuallyStill =
@@ -190,6 +203,7 @@ export async function waitForSootsimIdle({
190
203
  const blockers = []
191
204
  if (strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
192
205
  if (last.animating) blockers.push('animations still running')
206
+ if (last.shellAnimating) blockers.push('shell animations still running')
193
207
  if (last.layoutDirty) blockers.push('layout still dirty')
194
208
  if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
195
209
  if (last.layout !== lastLayout) blockers.push('layout still changing')
@@ -211,6 +211,7 @@ export interface ReloadReadyResult {
211
211
  nodes: number
212
212
  targets: number
213
213
  liveFrameActive: boolean
214
+ browserSurfaceCount: number
214
215
  liveFrameChannels: number
215
216
  liveFramePublishes: number
216
217
  flag: unknown
@@ -244,6 +245,7 @@ export async function pollForReloadReady(
244
245
  nodes: status.nodes,
245
246
  targets: status.targets,
246
247
  liveFrameActive: status.liveFrameActive,
248
+ browserSurfaceCount: status.browserSurfaceCount,
247
249
  liveFrameChannels: status.liveFrameChannels,
248
250
  liveFramePublishes: status.liveFramePublishes,
249
251
  flag: status.flag,
@@ -4,8 +4,8 @@ import { waitForSootsimIdle } from './settling'
4
4
  import type { WsBridge } from '../../ws-bridge'
5
5
 
6
6
  // alias for `do settle` under the discoverable `wait` verb grouping.
7
- // layout hash stability across 3 polls; --strict also requires worker
8
- // animation flags to be clear.
7
+ // layout hash stability across 3 polls; --strict also requires the app's
8
+ // animation flags clear and no shell motion (alerts, sheets, menus).
9
9
  export async function runWaitIdleSubcommand(opts: {
10
10
  bridge: WsBridge
11
11
  args: string[]
@@ -32,7 +32,7 @@ export async function runWaitReadySubcommand(opts: {
32
32
  const { status, idle, elapsedMs } = await waitReadyAndSettle(bridge, timeoutMs, {
33
33
  onProgress(progress) {
34
34
  console.error(
35
- ` still waiting after ${progress.elapsedMs}ms — ${waitReadyReason(progress)} (nodes: ${progress.nodes}, targets: ${progress.targets}, live surfaces: ${progress.liveFrameActive ? progress.liveFrameChannels : 0}, errors: ${progress.errors})`,
35
+ ` still waiting after ${progress.elapsedMs}ms — ${waitReadyReason(progress)} (nodes: ${progress.nodes}, targets: ${progress.targets}, live surfaces: ${progress.liveFrameActive ? progress.liveFrameChannels : 0}, browser surfaces: ${progress.browserSurfaceCount}, errors: ${progress.errors})`,
36
36
  )
37
37
  },
38
38
  })
@@ -54,13 +54,13 @@ export async function runWaitReadySubcommand(opts: {
54
54
 
55
55
  function printReady(status: WaitReadyStatus, elapsedMs: number): void {
56
56
  console.log(
57
- ` ready in ${elapsedMs}ms: ${status.nodes} nodes, ${status.targets} targets${status.liveFrameActive ? `, ${status.liveFrameChannels} live surfaces` : ''}`,
57
+ ` ready in ${elapsedMs}ms: ${status.nodes} nodes, ${status.targets} targets${status.liveFrameActive ? `, ${status.liveFrameChannels} live surfaces` : ''}${status.browserSurfaceCount ? `, ${status.browserSurfaceCount} browser surfaces` : ''}`,
58
58
  )
59
59
  }
60
60
 
61
61
  function timedOut(status: WaitReadyStatus, elapsedMs: number): never {
62
62
  console.error(
63
- ` ⚠ wait ready timed out after ${elapsedMs}ms — ${waitReadyReason(status)} (nodes: ${status.nodes}, targets: ${status.targets}, live surfaces: ${status.liveFrameActive ? status.liveFrameChannels : 0}, errors: ${status.errors})`,
63
+ ` ⚠ wait ready timed out after ${elapsedMs}ms — ${waitReadyReason(status)} (nodes: ${status.nodes}, targets: ${status.targets}, live surfaces: ${status.liveFrameActive ? status.liveFrameChannels : 0}, browser surfaces: ${status.browserSurfaceCount}, errors: ${status.errors})`,
64
64
  )
65
65
  rnxExit(1)
66
66
  }
@@ -859,11 +859,11 @@ async function waitForKeyboardVisible(
859
859
  */
860
860
  async function performCloudKeys(
861
861
  bridge: WsBridge,
862
- steps: Array<{ type: 'type'; text: string } | { type: 'key'; key: string }>,
862
+ steps: Array<Extract<PerformStep, { type: 'type' | 'typeInto' | 'key' }>>,
863
863
  actionLabel: string,
864
- ): Promise<void> {
864
+ ): Promise<PerformResult> {
865
865
  const result: PerformResult = await bridge.send({ type: 'perform', steps })
866
- if (result.ok) return
866
+ if (result.ok) return result
867
867
  const failed = result.steps.find((step) => !step.ok)
868
868
  console.error(
869
869
  ` ${actionLabel} failed: ${failed?.error ?? result.error ?? 'no text input had focus'}. focus an input first with peach do tap-id or peach do type-into.`,
@@ -2483,13 +2483,39 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2483
2483
  printTapFailure(`id "${targetId}"`, outcome)
2484
2484
  rnxExit(1)
2485
2485
  }
2486
- await performCloudKeys(bridge, [{ type: 'type', text }], 'type-into')
2486
+ const nodeId: unknown = outcome.payload.target?.nodeId
2487
+ if (
2488
+ typeof nodeId !== 'number' ||
2489
+ !Number.isSafeInteger(nodeId) ||
2490
+ nodeId === 0
2491
+ ) {
2492
+ console.error(' type-into requires a resolved text input node identity')
2493
+ rnxExit(1)
2494
+ }
2495
+ const typed = await performCloudKeys(
2496
+ bridge,
2497
+ [{ type: 'typeInto', text, nodeId }],
2498
+ 'type-into',
2499
+ )
2500
+ const receipt: unknown = typed.steps[0]?.value
2501
+ if (
2502
+ !receipt ||
2503
+ typeof receipt !== 'object' ||
2504
+ typeof Reflect.get(receipt, 'secureTextEntry') !== 'boolean'
2505
+ ) {
2506
+ console.error(' type-into did not return its matched input secure state')
2507
+ rnxExit(1)
2508
+ }
2509
+ const recordedText =
2510
+ Reflect.get(receipt, 'secureTextEntry') === true
2511
+ ? SECURE_TEXT_REDACTION
2512
+ : text
2487
2513
  await recordInspectAction(
2488
2514
  'inspect type-into',
2489
- { tapOn: { id: targetId }, inputText: text },
2490
- `type-into #${targetId} ${JSON.stringify(text)}`,
2515
+ { tapOn: { id: targetId }, inputText: recordedText },
2516
+ `type-into #${targetId} ${JSON.stringify(recordedText)}`,
2491
2517
  )
2492
- console.log(` typed into ${targetId}: ${JSON.stringify(text)}`)
2518
+ console.log(` typed into ${targetId}: ${JSON.stringify(recordedText)}`)
2493
2519
  break
2494
2520
  }
2495
2521
  // step 1: find the element
@@ -0,0 +1,164 @@
1
+ // peach location drives the simulated device location — the `simctl location`
2
+ // equivalent. the sim's one device location feeds every app through the host
3
+ // service geolocation seam (engine/geolocation-source.ts); it never reads the
4
+ // host Mac's real position.
5
+
6
+ import { printBridgeFailureDiagnostics } from '../bridge-diagnostics'
7
+ import { createBridgeFromParsed, parseBridgeCliArgs, type WsBridge } from '../ws-bridge'
8
+ import type { LocationCommand, LocationResult } from '../../src/bridge-contract'
9
+
10
+ function printHelp() {
11
+ console.log(`
12
+ peach location — control the simulator's simulated device location
13
+
14
+ usage:
15
+ peach location get [--json]
16
+ peach location set <lat>,<lon> [--altitude <m>] [--accuracy <m>] [--heading <deg>] [--speed <m/s>]
17
+ peach location clear
18
+
19
+ subcommands:
20
+ get report the current simulated location (custom or iOS's default)
21
+ set set the device location, read by getCurrentPosition and every active watcher
22
+ clear return the device to iOS's own default location
23
+
24
+ options:
25
+ --altitude <m> meters above sea level
26
+ --accuracy <m> horizontal accuracy in meters
27
+ --heading <deg> course in degrees, 0-359.9, relative to true north
28
+ --speed <m/s> ground speed in meters per second
29
+ --json print result as JSON
30
+ --sim <id> target a specific sim
31
+ --port <p> WS bridge port (default: 7668)
32
+
33
+ examples:
34
+ peach location set 37.785834,-122.406417
35
+ peach location set 40.748817,-73.985428 --accuracy 10
36
+ peach location get
37
+ peach location clear
38
+ `)
39
+ }
40
+
41
+ function isLocationResult(value: unknown): value is LocationResult {
42
+ if (!value || typeof value !== 'object') return false
43
+ const ok = Reflect.get(value, 'ok')
44
+ const source = Reflect.get(value, 'source')
45
+ return typeof ok === 'boolean' && (source === 'custom' || source === 'default')
46
+ }
47
+
48
+ async function sendLocationCommand(
49
+ bridge: WsBridge,
50
+ location: LocationCommand,
51
+ ): Promise<LocationResult> {
52
+ const result: unknown = await bridge.send({ type: 'location', location })
53
+ if (!isLocationResult(result)) {
54
+ throw new Error('location bridge returned an invalid result')
55
+ }
56
+ return result
57
+ }
58
+
59
+ function printLocationResult(result: LocationResult, json: boolean): void {
60
+ if (json) {
61
+ console.log(JSON.stringify(result))
62
+ return
63
+ }
64
+ if (result.fix) {
65
+ const { latitude, longitude, altitude, accuracy, heading, speed } = result.fix
66
+ const parts = [`${latitude},${longitude}`]
67
+ if (altitude !== undefined) parts.push(`altitude=${altitude}`)
68
+ if (accuracy !== undefined) parts.push(`accuracy=${accuracy}`)
69
+ if (heading !== undefined) parts.push(`heading=${heading}`)
70
+ if (speed !== undefined) parts.push(`speed=${speed}`)
71
+ console.log(` location (${result.source}): ${parts.join(' ')}`)
72
+ } else {
73
+ console.log(` location (${result.source}): unavailable`)
74
+ }
75
+ if (!result.ok && result.error) console.error(` location failed: ${result.error}`)
76
+ }
77
+
78
+ function parseCoordinatePair(
79
+ input: string,
80
+ ): { latitude: number; longitude: number } | null {
81
+ const [latRaw, lonRaw] = input.split(',')
82
+ if (!latRaw || !lonRaw) return null
83
+ const latitude = Number(latRaw)
84
+ const longitude = Number(lonRaw)
85
+ if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return null
86
+ return { latitude, longitude }
87
+ }
88
+
89
+ export async function runLocation(
90
+ args: string[],
91
+ opts: { port?: number } = {},
92
+ ): Promise<number> {
93
+ const parsed = parseBridgeCliArgs(args, {
94
+ port: opts.port,
95
+ stripBooleanFlags: ['--help', '-h', '--json'],
96
+ stripValueFlags: ['--altitude', '--accuracy', '--heading', '--speed'],
97
+ })
98
+ const positional = parsed.positional
99
+ const subcommand = positional[0]
100
+ if (
101
+ !subcommand ||
102
+ subcommand === 'help' ||
103
+ args.includes('--help') ||
104
+ args.includes('-h')
105
+ ) {
106
+ printHelp()
107
+ return subcommand ? 0 : 1
108
+ }
109
+
110
+ const bridge = createBridgeFromParsed(parsed)
111
+ const json = args.includes('--json')
112
+ try {
113
+ if (subcommand === 'get') {
114
+ const result = await sendLocationCommand(bridge, { action: 'get' })
115
+ printLocationResult(result, json)
116
+ return result.ok ? 0 : 1
117
+ }
118
+
119
+ if (subcommand === 'clear') {
120
+ const result = await sendLocationCommand(bridge, { action: 'clear' })
121
+ printLocationResult(result, json)
122
+ return result.ok ? 0 : 1
123
+ }
124
+
125
+ if (subcommand === 'set') {
126
+ const coordinates = positional[1]
127
+ if (!coordinates) {
128
+ console.error(' usage: peach location set <lat>,<lon>')
129
+ return 1
130
+ }
131
+ const pair = parseCoordinatePair(coordinates)
132
+ if (!pair) {
133
+ console.error(` invalid coordinates: ${coordinates} (expected <lat>,<lon>)`)
134
+ return 1
135
+ }
136
+ const numberFlag = (flag: string): number | undefined => {
137
+ const index = args.indexOf(flag)
138
+ if (index < 0) return undefined
139
+ const value = Number(args[index + 1])
140
+ return Number.isFinite(value) ? value : undefined
141
+ }
142
+ const result = await sendLocationCommand(bridge, {
143
+ action: 'set',
144
+ ...pair,
145
+ altitude: numberFlag('--altitude'),
146
+ accuracy: numberFlag('--accuracy'),
147
+ heading: numberFlag('--heading'),
148
+ speed: numberFlag('--speed'),
149
+ })
150
+ printLocationResult(result, json)
151
+ return result.ok ? 0 : 1
152
+ }
153
+
154
+ console.error(` unknown location subcommand: ${subcommand}`)
155
+ printHelp()
156
+ return 1
157
+ } catch (error) {
158
+ console.error(` location failed: ${error instanceof Error ? error.message : error}`)
159
+ await printBridgeFailureDiagnostics(bridge)
160
+ return 1
161
+ } finally {
162
+ bridge.close()
163
+ }
164
+ }
@@ -365,7 +365,7 @@ async function runRemoteCreate(
365
365
  *
366
366
  * a box created from the already-built app boots it in its own page, and this
367
367
  * opens the bare shell watch url minted from the box's display grant — the same
368
- * /sootsim/#remoteEngine fragment the nano service mints, pointed at the box.
368
+ * /simulator#remoteEngine fragment the nano service mints, pointed at the box.
369
369
  */
370
370
  async function runRemoteBox(
371
371
  platform: RuntimePlatform,