peachsim 0.1.1814 → 0.1.1815

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 (105) hide show
  1. package/cli/commands/control.ts +5 -2
  2. package/cli/commands/inspect.ts +43 -385
  3. package/cli/commands/package.ts +6 -1
  4. package/cli/commands/runtime.ts +2 -2
  5. package/cli/outbound-endpoints.ts +1 -1
  6. package/dist-lib/agent-daemon-client.cjs +1 -1
  7. package/dist-lib/agent-events.cjs +1 -1
  8. package/dist-lib/attached-projects.cjs +1 -1
  9. package/dist-lib/auth/shared-session.cjs +1 -1
  10. package/dist-lib/backend-origin.cjs +1 -1
  11. package/dist-lib/beta.cjs +1 -1
  12. package/dist-lib/beta.mjs +1 -1
  13. package/dist-lib/bridge-constants.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.mjs +1 -1
  16. package/dist-lib/bridge-contract.cjs +1 -1
  17. package/dist-lib/bridge-contract.mjs +1 -1
  18. package/dist-lib/bundle-channel.cjs +453 -331
  19. package/dist-lib/capture-contract.cjs +1 -1
  20. package/dist-lib/capture-contract.mjs +1 -1
  21. package/dist-lib/cloud-contract.cjs +1 -1
  22. package/dist-lib/cloud-contract.mjs +1 -1
  23. package/dist-lib/cloud-test-args.cjs +1 -1
  24. package/dist-lib/cloud-test-args.mjs +1 -1
  25. package/dist-lib/cloud.cjs +1 -1
  26. package/dist-lib/cloud.mjs +1 -1
  27. package/dist-lib/config.cjs +1 -1
  28. package/dist-lib/config.mjs +1 -1
  29. package/dist-lib/detox/index.cjs +89 -14
  30. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  31. package/dist-lib/expo-swift-bundle.cjs +26 -18
  32. package/dist-lib/expo-swift-metadata.cjs +1 -1
  33. package/dist-lib/expo-swift-metadata.mjs +1 -1
  34. package/dist-lib/home-paths.cjs +1 -1
  35. package/dist-lib/host/bridge-host.cjs +464 -336
  36. package/dist-lib/host/fetch-proxy-handler.cjs +14 -12
  37. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  38. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  39. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  40. package/dist-lib/host/websocket-proxy.cjs +1 -1
  41. package/dist-lib/index.cjs +15 -14
  42. package/dist-lib/jump-to-source-babel.cjs +1 -1
  43. package/dist-lib/jump-to-source-native.cjs +1 -1
  44. package/dist-lib/kotlin-host.cjs +1 -1
  45. package/dist-lib/menu.cjs +1 -1
  46. package/dist-lib/menu.mjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  48. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  49. package/dist-lib/metro-production-bundle.cjs +1 -1
  50. package/dist-lib/metro-production-bundle.mjs +1 -1
  51. package/dist-lib/metro.cjs +15 -14
  52. package/dist-lib/native-app-identity-project.cjs +4 -3
  53. package/dist-lib/native-app-identity-project.mjs +4 -3
  54. package/dist-lib/native-app-identity.cjs +1 -1
  55. package/dist-lib/native-app-identity.mjs +1 -1
  56. package/dist-lib/native-firebase-metadata.cjs +1 -1
  57. package/dist-lib/native-firebase-metadata.mjs +1 -1
  58. package/dist-lib/pdfium-raster.cjs +1 -1
  59. package/dist-lib/pdfium-raster.mjs +1 -1
  60. package/dist-lib/plist.cjs +1 -1
  61. package/dist-lib/plist.mjs +1 -1
  62. package/dist-lib/profiles.cjs +1 -1
  63. package/dist-lib/public-brand.cjs +1 -1
  64. package/dist-lib/public-origins-lib-esm.json +24 -24
  65. package/dist-lib/public-origins-lib.json +66 -63
  66. package/dist-lib/react-native-host-modules.cjs +1 -1
  67. package/dist-lib/react-native-host-modules.mjs +1 -1
  68. package/dist-lib/reap-browser.cjs +1 -1
  69. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  70. package/dist-lib/sdk.cjs +1 -1
  71. package/dist-lib/sdk.mjs +1 -1
  72. package/dist-lib/skills.cjs +503 -342
  73. package/dist-lib/swift-compile.cjs +4 -3
  74. package/dist-lib/swift-compile.mjs +4 -3
  75. package/dist-lib/swift-package.cjs +1 -1
  76. package/dist-lib/swift-package.mjs +1 -1
  77. package/dist-lib/swift-submit.cjs +1 -1
  78. package/dist-lib/swift-submit.mjs +1 -1
  79. package/dist-lib/swift-toolchain.cjs +1 -1
  80. package/dist-lib/swift.cjs +1 -1
  81. package/dist-lib/vite-swift.cjs +26 -18
  82. package/dist-lib/vite.cjs +14 -12
  83. package/dist-lib/worklet-executable.cjs +1 -1
  84. package/dist-lib/worklet-executable.mjs +1 -1
  85. package/dist-types/packages/peach-engine/src/engine/nativeReplayContract.d.ts +2 -0
  86. package/package.json +1 -1
  87. package/runtime-companion.json +1 -1
  88. package/src/cli-runtime.ts +32 -4
  89. package/src/expo-swift-ready.ts +16 -2
  90. package/src/installed-native-libraries.ts +79 -18
  91. package/src/nitro-adapter.lock.json +240 -240
  92. package/src/nitro-compile.ts +6 -3
  93. package/src/nitro-dependencies.ts +8 -2
  94. package/src/nitro-source.ts +34 -3
  95. package/src/nitro-superset.lock.json +14 -14
  96. package/src/nitroContract.ts +26 -3
  97. package/src/runtime-delivery.ts +2 -2
  98. package/src/swift-compile.ts +2 -1
  99. package/src/swift-distribution.lock.json +9 -8
  100. package/src/swift-installed-targets.ts +13 -0
  101. package/src/swift-standins.ts +8 -2
  102. package/src/turbo-bundle.ts +20 -1
  103. package/src/turbo-compile.ts +6 -12
  104. package/src/turbo-runtime.lock.json +19 -19
  105. package/src/turbo-source.ts +16 -0
@@ -1,6 +1,3 @@
1
- // peach inspect — dump node tree, accessibility info, query nodes
2
- // connects to the peach WS bridge (no Playwright)
3
-
4
1
  import { Script } from 'node:vm'
5
2
  import { getCliInspectVerbMeta } from '@peach/skills/cli'
6
3
  import { renderCliCommandHelp, renderCliGroupHelp } from '@peach/skills/cli/renderers'
@@ -130,9 +127,7 @@ interface InspectOptions extends BridgeTransportOption {
130
127
  internalPerfCommand?: 'shell' | 'scroll'
131
128
  }
132
129
 
133
- // shape of entries in the shared observability store — mirrors
134
- // packages/peach-engine/src/observability/types.ts NetworkEntry. duplicated
135
- // here so this command doesn't cross-import from engine internals.
130
+ // a copy of NetworkEntry from packages/peach-engine/src/observability/types.ts; change both together.
136
131
  interface NetworkEntryPayload {
137
132
  sourcePath?: string
138
133
  sourceHash?: string
@@ -166,9 +161,6 @@ function formatNetworkDuration(ms: number | null): string {
166
161
  return `${(ms / 1000).toFixed(2)}s`.padStart(5)
167
162
  }
168
163
 
169
- // when a tap-id / tap-text query misses, walk the live tree's testIDs and
170
- // emit the canonical "recover a wedged sim" hint. shared by the genuine-dead
171
- // paths in the failure handler.
172
164
  function printRecoverHint(): void {
173
165
  process.stderr.write(
174
166
  ` the sim is not responding. recover it with:\n` +
@@ -177,14 +169,6 @@ function printRecoverHint(): void {
177
169
  )
178
170
  }
179
171
 
180
- // cheap liveness probe: a command timing out does NOT prove the sim is dead.
181
- // `describe` on a big screen (rainbow's loaded home is hundreds of nodes)
182
- // blows the 15s default while `get errors` answers instantly — same sim. send
183
- // a trivial eval on a short budget; if it answers, the sim is alive and the
184
- // previous command just needs a narrower scope or a bigger timeout.
185
- // send a one-step `perform` batch and flatten the result back to the
186
- // `{ ok, value, error? }` shape these subcommands have always printed. the
187
- // engine executes the step in-page and emits the agent-cursor action itself.
188
172
  async function performSingleStep(
189
173
  bridge: WsBridge,
190
174
  step: PerformStep,
@@ -199,8 +183,7 @@ async function performSingleStep(
199
183
  }
200
184
  }
201
185
 
202
- // runs after a command already spent its whole budget, so an explicit --timeout
203
- // must not make the liveness check wait that long a second time
186
+ // runs after a command spent its whole budget; a long --timeout must not make this wait again.
204
187
  async function probeSimResponsive(bridge: WsBridge): Promise<boolean> {
205
188
  try {
206
189
  await bridge.send({ type: 'evaluate', code: '1' }, { timeoutMs: 3000 })
@@ -210,17 +193,12 @@ async function probeSimResponsive(bridge: WsBridge): Promise<boolean> {
210
193
  }
211
194
  }
212
195
 
213
- // a bare `do tap <x>` resolves a testID; users coming from maestro's
214
- // `tapOn: <text>` pass visible text there, so point them at `--text`.
215
196
  async function reportMissingTarget(
216
197
  bridge: WsBridge,
217
198
  verb: 'tap' | 'double-tap' | 'long-press',
218
199
  target: { mode: 'testid' | 'text'; value: string },
219
200
  ): Promise<void> {
220
201
  if (target.mode === 'testid') {
221
- // the tree can hold the id while the engine has no point to press: the node
222
- // is not painted yet, or was replaced since the query. say so, so the
223
- // suggestion list never names the id that was just reported missing.
224
202
  const exact = await inspectFind(bridge, { testId: target.value }).catch(() => null)
225
203
  if (exact?.result) {
226
204
  console.error(
@@ -240,9 +218,6 @@ async function reportMissingTarget(
240
218
  maybeHint('wait-selector-for-missing-testid', target.value)
241
219
  }
242
220
 
243
- // surface the 5 closest candidates so callers can fix the typo without
244
- // dumping the full tree. uses a cheap prefix + Levenshtein score so a
245
- // trailing digit or near-miss casing still bubbles to the top.
246
221
  async function printSimilarTestIds(bridge: WsBridge, query: string): Promise<void> {
247
222
  try {
248
223
  const found = await inspectFind(bridge, { visible: true })
@@ -262,7 +237,7 @@ async function printSimilarTestIds(bridge: WsBridge, query: string): Promise<voi
262
237
  id,
263
238
  score: scoreIdSimilarity(q, id.toLowerCase()),
264
239
  }))
265
- .filter((entry) => entry.score < q.length + 4) // drop obvious non-matches
240
+ .filter((entry) => entry.score < q.length + 4)
266
241
  .sort((a, b) => a.score - b.score)
267
242
  .slice(0, 5)
268
243
  if (ranked.length === 0) return
@@ -270,17 +245,13 @@ async function printSimilarTestIds(bridge: WsBridge, query: string): Promise<voi
270
245
  for (const entry of ranked) {
271
246
  console.error(` ${entry.id}`)
272
247
  }
273
- } catch {
274
- // if the suggestion path fails the user still got the "not found" msg
275
- }
248
+ } catch {}
276
249
  }
277
250
 
278
251
  function scoreIdSimilarity(needle: string, candidate: string): number {
279
252
  if (candidate === needle) return 0
280
253
  if (candidate.includes(needle)) return 1
281
254
  if (needle.includes(candidate)) return 2
282
- // tiny prefix/suffix bonus so `nav-back` ranks above unrelated long names
283
- // when querying `back`.
284
255
  let prefix = 0
285
256
  while (
286
257
  prefix < needle.length &&
@@ -298,11 +269,7 @@ function formatNetworkStatus(e: NetworkEntryPayload): string {
298
269
  return String(e.status)
299
270
  }
300
271
 
301
- // how long a reload waits for the guest to boot, emit ready and settle. one
302
- // budget for an in-place app reload and a full page reload alike: a real app
303
- // that signs in and fetches over the network remounts past 10 s on a large
304
- // screen, while a full engine boot runs 5-8 s unloaded and well past 10 s on
305
- // a busy box.
272
+ // one budget for in-place and full reloads: a real app remounts past 10 s on a large screen, and a full boot runs 5-8 s unloaded.
306
273
  const RELOAD_READY_TIMEOUT_MS = 30000
307
274
 
308
275
  function describeReloadReadyBlocker(result: ReloadReadyResult): string {
@@ -345,14 +312,12 @@ function printNetworkDetail(e: NetworkEntryPayload) {
345
312
  for (const [k, v] of rows) console.log(` ${k.padEnd(13)} ${v}`)
346
313
  }
347
314
 
348
- // ANSI colors for the `logs` verb. the LogEntry / LogLevel types + filtering
349
- // live in inspect/core.ts so the CLI and the agent share one definition.
350
315
  const LOG_LEVEL_COLOR: Record<LogLevel, string> = {
351
- error: '\x1b[31m', // red
352
- warn: '\x1b[33m', // yellow
353
- info: '\x1b[36m', // cyan
354
- debug: '\x1b[35m', // magenta
355
- log: '\x1b[37m', // white
316
+ error: '\x1b[31m',
317
+ warn: '\x1b[33m',
318
+ info: '\x1b[36m',
319
+ debug: '\x1b[35m',
320
+ log: '\x1b[37m',
356
321
  }
357
322
  const ANSI_RESET = '\x1b[0m'
358
323
  const ANSI_DIM = '\x1b[2m'
@@ -377,17 +342,6 @@ function printLogRow(e: LogEntry, useColor: boolean) {
377
342
 
378
343
  const SWITCHER_SETTLE_GRACE_MS = 120
379
344
 
380
- // parse sample-color / screenshot rect args. supports several shapes so the
381
- // command is friendly for both humans and scripted agents:
382
- // <x> <y> single pixel (w=h=1)
383
- // <x> <y> <w> <h> positional area
384
- // --area x,y,w,h comma-separated area
385
- // --x n --y n --w n --h n
386
- // --id <testID> snap to node's bounding box
387
- // --text <text> snap to node matching text
388
- // returns null when no rect flags are present — callers then either fall
389
- // back to a full-canvas capture (screenshot) or report an argument error
390
- // (sample-color).
391
345
  async function resolveSampleRect(
392
346
  args: string[],
393
347
  bridge: WsBridge,
@@ -432,7 +386,6 @@ async function resolveSampleRect(
432
386
  return { x: fx ?? 0, y: fy ?? 0, w: fw ?? 1, h: fh ?? 1 }
433
387
  }
434
388
 
435
- // positional: "<verb> <x> <y> [w] [h]"
436
389
  const positional = args.filter(
437
390
  (a, i) =>
438
391
  i > 0 &&
@@ -473,7 +426,6 @@ function printRenderProfile(worker: string, rp: Record<string, any> | undefined)
473
426
  .filter(Boolean)
474
427
  .join(' · ')
475
428
  if (recordCauses) console.log(` why recorded: ${recordCauses}`)
476
- // idle work, so it is a total for the capture, not a per-frame average.
477
429
  if (rp.prewarmRecords) {
478
430
  console.log(
479
431
  ` pre-recorded: ${rp.prewarmRecords} boundaries at idle (${Number(rp.prewarmRecordMs).toFixed(1)}ms total)`,
@@ -520,10 +472,6 @@ function printRenderProfile(worker: string, rp: Record<string, any> | undefined)
520
472
  )
521
473
  }
522
474
 
523
- // pretty-print the shell frame profile payload (__sootsimShellPerf.stop()):
524
- // per-painted-frame timing from the shell worker merged with the render
525
- // profile counters. numbers arrive pre-rounded from the worker. also used by
526
- // `peach test --profile`, which records the same payload.
527
475
  export function printShellPerfReport(result: Record<string, any>) {
528
476
  const fps = result.avgMs > 0 ? (1000 / result.avgMs).toFixed(1) : '?'
529
477
  const jank = result.jank && typeof result.jank === 'object' ? result.jank : null
@@ -715,10 +663,6 @@ export function printShellPerfReport(result: Record<string, any>) {
715
663
  )
716
664
  }
717
665
  }
718
- // two profiles, two workers: the shell paints chrome/overlays, the
719
- // compositor paints home + app:one + app:two. guest-app scroll work is all
720
- // in the compositor one — reading the shell's raster counters for an app
721
- // workload is how a live raster tier reads as dead.
722
666
  printRenderProfile('shell worker', result.renderProfile)
723
667
  printRenderProfile('compositor worker', result.compositorRenderProfile)
724
668
  const worst = Array.isArray(result.worstFrames) ? result.worstFrames : []
@@ -745,9 +689,6 @@ export function printShellPerfReport(result: Record<string, any>) {
745
689
  }
746
690
  }
747
691
 
748
- // core bridge-facing helpers moved to ./inspect/shared — this file now just
749
- // imports them (see top-of-file imports).
750
-
751
692
  async function waitForShellState(
752
693
  bridge: WsBridge,
753
694
  timeoutMs: number,
@@ -764,16 +705,6 @@ async function waitForShellState(
764
705
  }
765
706
 
766
707
  async function getKeyboardState(bridge: WsBridge) {
767
- // focusedInput is sourced from __sootsimTest.getFocusedNode(), which reads
768
- // through the focus-keyboard-runtime (P2). previously this scanned
769
- // test.queryAll({}) for `n.style._focused` — a flag nothing in the engine
770
- // actually sets — so the cli always reported focusedInput: null, even
771
- // when an input was focused. that silently misled the 2026-04-17 bluesky
772
- // tap-routing investigation by ~30 minutes.
773
- //
774
- // phase + frame now also come from the runtime snapshot (same single
775
- // source) so cli consumers see the same state as KeyboardAvoidingView
776
- // and the keyboard-controller compat stub.
777
708
  return bridge
778
709
  .send({
779
710
  type: 'evaluate',
@@ -831,8 +762,7 @@ async function getKeyboardState(bridge: WsBridge) {
831
762
  }>
832
763
  }
833
764
 
834
- // a tap focuses its input whether or not a software keyboard presents: with
835
- // a hardware keyboard connected iOS shows none, so focus is the proof.
765
+ // focus is the proof of a tap: with a hardware keyboard connected, iOS shows no software keyboard.
836
766
  async function waitForInputFocus(bridge: WsBridge, nodeId: number, timeoutMs: number) {
837
767
  const deadline = Date.now() + timeoutMs
838
768
  while (true) {
@@ -842,10 +772,6 @@ async function waitForInputFocus(bridge: WsBridge, nodeId: number, timeoutMs: nu
842
772
  }
843
773
  }
844
774
 
845
- /**
846
- * dispatch through the shared input executor, which checks the requested
847
- * node identity before targeted typing and carries refusals out of the CLI.
848
- */
849
775
  async function performKeys(
850
776
  bridge: WsBridge,
851
777
  steps: Array<Extract<PerformStep, { type: 'type' | 'typeInto' | 'key' }>>,
@@ -962,9 +888,6 @@ async function recordInspectAction(
962
888
  summary: string,
963
889
  ) {
964
890
  const result = rememberFlowCandidate({ source, step, summary })
965
- // when a flow draft is active, make the pending-candidate model visible —
966
- // otherwise a sequence of `do` actions silently overwrites each other and
967
- // `maestro end` exports far fewer steps than the user expects (F13-4).
968
891
  if (!result.active) return
969
892
  if (result.replaced) {
970
893
  console.error(
@@ -1032,12 +955,6 @@ function buildTapCandidateFromNode(
1032
955
  }
1033
956
 
1034
957
  export async function runInspect(args: string[], opts: InspectOptions) {
1035
- // strip a leading grouping verb — `get`, `do`, and (when forwarded from
1036
- // runDebug) `debug`. these are organizational prefixes and shouldn't leak
1037
- // into subcommand dispatch. e.g.:
1038
- // peach get tree → effectiveArgs = ['tree']
1039
- // peach do tap 100 200 → effectiveArgs = ['tap', '100', '200']
1040
- // peach debug state shell → effectiveArgs = ['state', 'shell']
1041
958
  const verbPrefix =
1042
959
  args[0] === 'get' || args[0] === 'do' || args[0] === 'debug' || args[0] === 'wait'
1043
960
  ? args[0]
@@ -1064,21 +981,14 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1064
981
  '-w',
1065
982
  '--strict',
1066
983
  '--no-wait',
1067
- // `find --verbose` / `find --dump` emits full node JSON per result.
1068
984
  '--dump',
1069
- // `network` command flags — boolean toggles
1070
985
  '--failed',
1071
986
  '--slow',
1072
987
  '--tail',
1073
988
  '-f',
1074
- // `find --interactive-targets` (alias `find --actions`) — ranked tappable list
1075
989
  '--interactive-targets',
1076
990
  '--actions',
1077
- // `logs` command: include engine-internal [sootsim] debug messages
1078
991
  '--internal',
1079
- // `describe` boolean flags — without these they leak into `positional`
1080
- // and get mistaken for a text filter (`describe --compact` then matches
1081
- // nothing). value-taking describe flags live in stripValueFlags below.
1082
992
  '--compact',
1083
993
  '--no-xy',
1084
994
  ],
@@ -1090,16 +1000,12 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1090
1000
  '--test-id',
1091
1001
  '--text',
1092
1002
  '--max-ms',
1093
- // `network` / `logs` command flags that take a value
1094
1003
  '--filter',
1095
1004
  '--limit',
1096
1005
  '--level',
1097
- // `network --slow` slow-threshold (ms). default 1000.
1098
1006
  '--threshold',
1099
- // `wait event` filters
1100
1007
  '--equals',
1101
1008
  '--since',
1102
- // `describe` value flags — narrowing selectors
1103
1009
  '--testid-like',
1104
1010
  '--only',
1105
1011
  '--subtree',
@@ -1108,17 +1014,11 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1108
1014
  const positional = parsed.positional
1109
1015
  const subcommand =
1110
1016
  verbPrefix === 'debug' && positional[0] === 'eval' ? 'js' : positional[0]
1111
- // used by inspectCommand() below to format usage/error strings with the
1112
- // same prefix the user actually typed. null when they typed a top-level
1113
- // command, and inspectCommand asks the registry for the group instead.
1114
1017
  const invocationPrefix: 'get' | 'do' | 'debug' | 'wait' | null = verbPrefix
1115
1018
  const isTopLevel =
1116
1019
  typeof effectiveArgs[0] === 'string' &&
1117
1020
  TOP_LEVEL_RUNTIME_COMMANDS.has(effectiveArgs[0])
1118
1021
  const topLevelCommand = isTopLevel ? effectiveArgs[0] : null
1119
- // a usage string has to name something the user can actually type. the
1120
- // registry knows which group each verb belongs to, so an unprefixed
1121
- // invocation still renders `peach get tree` rather than a bare verb.
1122
1022
  const inspectCommand = (name: string) => {
1123
1023
  if (opts.internalPerfCommand && name === 'perf') {
1124
1024
  return `peach perf ${opts.internalPerfCommand}`
@@ -1142,16 +1042,12 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1142
1042
  }
1143
1043
 
1144
1044
  if (!subcommand || args.includes('--help') || args.includes('-h')) {
1145
- // all help output comes from the registry in packages/peach-skills
1146
- // so `peach do --help`, `peach get --help`, the website docs, and
1147
- // the Contrast skill markdown stay in lock-step.
1045
+ // help output comes from the registry in packages/peach-skills, so every help surface reads one source.
1148
1046
  const docContext = {
1149
1047
  bridgePort: DEFAULT_SOOTSIM_BRIDGE_PORT,
1150
1048
  defaultShellUrl: DEFAULT_SOOTSIM_SHELL_URL,
1151
1049
  }
1152
1050
 
1153
- // grouping-verb entry — clusters by subgroup (targeting, text input,
1154
- // gestures, lifecycle, ...) so related verbs read as a visual family.
1155
1051
  if (
1156
1052
  invocationPrefix === 'do' ||
1157
1053
  invocationPrefix === 'get' ||
@@ -1173,7 +1069,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1173
1069
  }
1174
1070
  }
1175
1071
 
1176
- // catch-all help — every group's listing stitched together.
1177
1072
  const groupSections = ['do', 'get', 'debug', 'wait']
1178
1073
  .map((g) => renderCliGroupHelp(g, docContext))
1179
1074
  .filter((s): s is string => s != null)
@@ -1204,8 +1099,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1204
1099
 
1205
1100
  if (invocationPrefix === 'do' && subcommand === 'scan') {
1206
1101
  const { runCamera } = await import('./camera')
1207
- // runCamera returns a code instead of exiting, so `do scan` has to carry
1208
- // it out. dropping it made a failed scan exit 0.
1102
+ // runCamera returns a code instead of exiting; dropping it made a failed scan exit 0.
1209
1103
  const code = await runCamera(effectiveArgs, { port: opts.port })
1210
1104
  if (code !== 0) peachExit(code)
1211
1105
  return
@@ -1218,9 +1112,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1218
1112
  return
1219
1113
  }
1220
1114
 
1221
- // driver discovery works offline; a live bridge also reports each running renderer.
1222
- // short-circuit here so users can discover drivers even when no peach
1223
- // session is running.
1115
+ // driver discovery must work with no bridge running, so it short-circuits before the bridge check.
1224
1116
  if (
1225
1117
  subcommand === 'list' &&
1226
1118
  effectiveArgs.some((a) => a === '--drivers' || a === '-D')
@@ -1232,7 +1124,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1232
1124
  try {
1233
1125
  sims = await bridge.listSims()
1234
1126
  } catch {
1235
- // local availability remains useful when no bridge is running.
1236
1127
  } finally {
1237
1128
  bridge.close()
1238
1129
  }
@@ -1277,19 +1168,13 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1277
1168
  'globals',
1278
1169
  'perf',
1279
1170
  'storage-clear',
1280
- // bridge-level commands — they don't touch a specific sim, so skip the
1281
- // per-sim console/request probe (which would otherwise claim a lease
1282
- // and show "call · evaluated page" in the sim overlay).
1171
+ // bridge-level commands touch no sim, so they skip the per-sim console and request probe.
1283
1172
  'list',
1284
1173
  'wait',
1285
1174
  'sleep',
1286
1175
  ])
1287
1176
 
1288
- // failed-request dumps used to print the entire response body verbatim.
1289
- // a backend 500 ships a ~1.5KB `<!DOCTYPE html>…` error page, repeated
1290
- // per failed request, which buries the actual step result and makes
1291
- // flow/maestro output unparseable (QA F20-3). collapse an HTML body to a
1292
- // one-line summary and hard-cap everything else.
1177
+ // a backend 500 ships a ~1.5KB html error page, so failed-request bodies are capped.
1293
1178
  const RESPONSE_BODY_MAX = 200
1294
1179
  function formatResponseBodyForLog(body: string): string {
1295
1180
  const flat = body.replace(/\s+/g, ' ').trim()
@@ -1321,44 +1206,25 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1321
1206
  return `${entry.method} ${target}`
1322
1207
  }
1323
1208
 
1324
- // batched post-command probe: one bridge roundtrip for both console + request
1325
- // counts. used by the default post-command notice loop so non-skip commands
1326
- // don't pay 2 separate roundtrips. also usable by subcommands (e.g. describe)
1327
- // that want to fold the probe into their own eval.
1328
1209
  type SummaryCounts = {
1329
1210
  console: { errors: number; warnings: number; total: number } | null
1330
1211
  requests: { failed: number; total: number } | null
1331
1212
  }
1332
- // after a write command briefly poll in the sim until layout is stable,
1333
- // capped by autoWaitBudgetMs. logs on timeout so it's obvious when the
1334
- // next CLI call may see mid-animation state.
1335
1213
  async function autoSettleAfterWrite(b: WsBridge): Promise<void> {
1336
- // a cloud sim runs no browser page, so the idle probe's evaluate never
1337
- // lands there. without this it settled nothing and the next read handed
1338
- // out coordinates a sheet was still animating away from, which is how a
1339
- // dialog button tap missed and the scrim under it answered the press.
1214
+ // a cloud sim runs no browser page for the idle probe; without this branch nothing settles.
1340
1215
  if (b.plane === 'cloud') {
1341
1216
  try {
1342
- // a cloud settle drains the whole transition in the sim rather than
1343
- // polling from here, so it gets a transport deadline, not the browser
1344
- // path's poll cap: a full screen transition is seconds of cpu render.
1217
+ // a cloud settle drains the transition inside the sim, so it needs a transport deadline, not a poll.
1345
1218
  await b.send({ type: 'settle' }, { timeoutMs: 15_000 })
1346
1219
  } catch (error) {
1347
- // the write itself already landed, so this never fails the command.
1348
- // it does have to be said out loud: a swallowed settle looks exactly
1349
- // like a settled sim to the next read, and that read then hands out
1350
- // coordinates the screen is still animating away from.
1220
+ // the write already landed, so a settle failure is reported on stderr and never fails the command.
1351
1221
  process.stderr.write(
1352
1222
  ` ⚠ auto-settle failed (${error instanceof Error ? error.message : String(error)}) — next command may see mid-animation state. use \`peach do settle\` to retry.\n`,
1353
1223
  )
1354
1224
  }
1355
1225
  return
1356
1226
  }
1357
- // budget is a CAP, not a fixed wait: waitForSootsimIdle drains a screen
1358
- // transition that starts, even past the budget, then gives the new screen
1359
- // the budget and returns the instant layout is stable. image
1360
- // loads and requests move nothing, so they do not hold it. longer
1361
- // transitions and loads should use an explicit `do settle` or `wait idle`.
1227
+ // the budget is a cap: a transition that starts is still drained past it.
1362
1228
  const budgetMs = autoWaitBudgetMs()
1363
1229
  try {
1364
1230
  const { settled, elapsed, blockedBy } = await waitForSootsimIdle({
@@ -1374,8 +1240,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1374
1240
  )
1375
1241
  }
1376
1242
  } catch (error) {
1377
- // the write already landed. an unread idle probe must not fail it or
1378
- // claim the screen was watched until the budget.
1379
1243
  if (error instanceof IdleObservationError) {
1380
1244
  process.stderr.write(
1381
1245
  ` ⚠ ${error.message}. next command may see mid-animation state. use \`peach do settle\` to retry.\n`,
@@ -1425,9 +1289,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1425
1289
  try {
1426
1290
  const raw = await bridge.send({
1427
1291
  type: 'evaluate',
1428
- // console count merges the ws-bridge buffer + observability store (see
1429
- // MERGED_CONSOLE_COUNT_EVAL) so the proactive notice agrees with what
1430
- // `get errors` returns for forwarded render-worker failures.
1292
+ // merged console count (see MERGED_CONSOLE_COUNT_EVAL) so the notice agrees with `get errors`.
1431
1293
  code: `(async () => ({
1432
1294
  console: ${MERGED_CONSOLE_COUNT_EVAL},
1433
1295
  requests: (await window.__sootsimTest?.getRequestCounts?.()) || null,
@@ -1484,12 +1346,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1484
1346
  }
1485
1347
  }
1486
1348
 
1487
- // proactive note when a blocking native-UI surface (Alert / ActionSheet) was
1488
- // open at the moment a write command ran. these live in the shell worker, so
1489
- // `describe` (tenant tree) can't see them — but they swallow every tap/drag/
1490
- // type meant for the app underneath, so a `do` that "did nothing" is usually a
1491
- // modal eating the input. fed from a pre-action capture so the note still
1492
- // fires when the action itself dismissed the modal (e.g. a tap on a button).
1349
+ // alerts and action sheets live in the shell worker, outside the tenant tree; capture them before the action so a dismissing tap still reports them.
1493
1350
  function printNativeUISummary(open: OpenNativeUISurface[]) {
1494
1351
  for (const ui of open) {
1495
1352
  const title = ui.title ? ` (“${ui.title}”)` : ''
@@ -1534,8 +1391,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1534
1391
 
1535
1392
  if (!opts.includeTail || errors === 0) return
1536
1393
 
1537
- // merged tail (ws-bridge buffer + observability) so a render-worker-only
1538
- // error is shown, not just dropped to "N errors" with an empty tail.
1539
1394
  const recentErrors = await inspectErrors(bridge, 5)
1540
1395
  if (!Array.isArray(recentErrors) || recentErrors.length === 0) return
1541
1396
 
@@ -1553,11 +1408,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1553
1408
  }
1554
1409
  }
1555
1410
 
1556
- // cursor footer — replaces the old "console: N errors" line with a delta
1557
- // summary of every timeline kind since this CLI identity's previous call.
1558
- // empty → no output (clean), so commands stay quiet when nothing has
1559
- // happened. priority-ordered kinds keep the most important signals
1560
- // (errors, toasts, screens) leftmost in the one-liner.
1561
1411
  const CURSOR_FOOTER_ORDER: readonly string[] = [
1562
1412
  'console',
1563
1413
  'fetch',
@@ -1578,10 +1428,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1578
1428
  ]
1579
1429
  async function printCursorFooter(b: WsBridge): Promise<void> {
1580
1430
  const cliKey = getCliIdentityKey()
1581
- // single eval roundtrip: summary buckets by kind plus a console
1582
- // level breakdown (errors vs warnings). agents care about that
1583
- // distinction enough that the footer should show it directly. one
1584
- // call to keep the post-command overhead at ~1 bridge hop.
1585
1431
  type FooterPayload = {
1586
1432
  summary: { total: number; byKind: Record<string, number>; lastAt: number | null }
1587
1433
  consoleSplit: { error: number; warn: number } | null
@@ -1632,7 +1478,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1632
1478
  }
1633
1479
  if (parts.length === 0) return
1634
1480
  console.error(`\n since last: ${parts.join(' · ')} — peach what-happened`)
1635
- // advance cursor so the next CLI call only sees *new* events.
1636
1481
  if (payload.summary.lastAt) {
1637
1482
  try {
1638
1483
  await callInBridge(
@@ -1641,16 +1486,11 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1641
1486
  cliKey,
1642
1487
  payload.summary.lastAt,
1643
1488
  )
1644
- } catch {
1645
- // best-effort — never fail the command because the cursor
1646
- // couldn't be advanced.
1647
- }
1489
+ } catch {}
1648
1490
  }
1649
1491
  }
1650
1492
 
1651
- // warn if target sim is hidden — animations and rAF are throttled,
1652
- // coordinates are wrong, launch transitions never complete.
1653
- // only check for commands that interact with the canvas.
1493
+ // a hidden sim throttles animations and rAF, so coordinates are wrong and launch transitions never finish.
1654
1494
  const writeCommands = new Set([
1655
1495
  'tap',
1656
1496
  'double-tap',
@@ -1710,16 +1550,11 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1710
1550
  }
1711
1551
 
1712
1552
  try {
1713
- // capture any blocking native-UI modal BEFORE running a write command, so
1714
- // the trailing note reflects the state when the action was attempted even
1715
- // if the action itself dismissed the modal (e.g. a tap that hit a button).
1716
1553
  const nativeUIBeforeWrite = writeCommands.has(subcommand)
1717
1554
  ? await detectOpenNativeUI(bridge)
1718
1555
  : []
1719
1556
  switch (subcommand) {
1720
1557
  case 'list': {
1721
- // name the bridge world so dev-bridge vs daemon is never ambiguous
1722
- // (the two can coexist; `list` used to silently flap between them).
1723
1558
  printBridgeWorldNotice(parsed.wsPort)
1724
1559
  await runListSubcommand({ bridge, simId, args: effectiveArgs })
1725
1560
  break
@@ -1834,21 +1669,12 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1834
1669
  }
1835
1670
 
1836
1671
  case 'event': {
1837
- // peach wait event <kind> — timeline-backed wait. delegates
1838
- // matcher + polling to runWaitEventSubcommand so the same
1839
- // logic is reachable from `peach wait event` regardless of
1840
- // verb-group prefix (and the same shape is testable on its
1841
- // own).
1842
1672
  await runWaitEventSubcommand({ bridge, args, positional, inspectUsage })
1843
1673
  break
1844
1674
  }
1845
1675
 
1846
1676
  case 'layout': {
1847
1677
  const id = positional[1]
1848
- // bare `peach get layout` (no id) measures visible elements on the
1849
- // screen by bounding box. --styling opts into box-model/style detail via
1850
- // the shared get-layout kernel the agent's app_get_layout also uses.
1851
- // passing an id keeps the single-node {x, y, width, height} lookup.
1852
1678
  if (!id) {
1853
1679
  await runGetLayoutSubcommand({ bridge, args: effectiveArgs })
1854
1680
  break
@@ -1957,9 +1783,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1957
1783
  )
1958
1784
  break
1959
1785
  }
1960
- // resolve in order: testID → id → text. first hit wins, includes the
1961
- // resolved transform and a parent chain so agents can skip the usual
1962
- // __sootsimRoot walk.
1963
1786
  const result = await bridge.send({
1964
1787
  type: 'evaluate',
1965
1788
  code: buildGetNodeEval(matcher),
@@ -1968,7 +1791,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
1968
1791
  break
1969
1792
  }
1970
1793
 
1971
- // `tap-id` is `tap` with an exact testID, so a numeric id stays an id.
1972
1794
  case 'tap-id':
1973
1795
  case 'tap': {
1974
1796
  let x = Number(positional[1])
@@ -2309,8 +2131,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2309
2131
  ...(payload.strategy && payload.strategy !== 'matched-node'
2310
2132
  ? { strategy: payload.strategy }
2311
2133
  : {}),
2312
- // expose the disambiguation outcome so agents can confirm which
2313
- // of the N matches was tapped, or notice that only one exists.
2314
2134
  ...((payload.total ?? 0) > 1 || nthIndex !== null
2315
2135
  ? { nth: { index: payload.idx, total: payload.total } }
2316
2136
  : {}),
@@ -2321,18 +2141,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2321
2141
  }
2322
2142
 
2323
2143
  case 'tap-best': {
2324
- // peach do tap-best <query> — try tap-id, then tap-text. the
2325
- // common agent ergonomic problem: the agent has a label like
2326
- // "Create expense" and doesn't know whether that's a testID
2327
- // or visible text. with tap-text it fails when the only
2328
- // match is a testID; with tap-id it fails when the only
2329
- // match is visible text. tap-best collapses both into one
2330
- // command and prints which strategy hit.
2331
- //
2332
- // tap-best does NOT subsume tap-text's disambiguation flags
2333
- // (--nth, --within, --near, --min-y) — those are still on
2334
- // tap-text directly. tap-best is the "I don't care which
2335
- // strategy works as long as one does" flavour.
2336
2144
  const query = positional[1]
2337
2145
  if (!query) {
2338
2146
  console.error(inspectUsage('tap-best', '<query>'))
@@ -2448,7 +2256,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2448
2256
  console.log(` typed into ${targetId}: ${JSON.stringify(recordedText)}`)
2449
2257
  break
2450
2258
  }
2451
- // step 1: find the element
2452
2259
  const tiArg = JSON.stringify(targetId)
2453
2260
  const tiPayload = await bridge.send({
2454
2261
  type: 'evaluate',
@@ -2483,7 +2290,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2483
2290
  console.error(' type-into requires a resolved text input node identity')
2484
2291
  peachExit(1)
2485
2292
  }
2486
- // step 2: tap to focus
2487
2293
  const tapResult = await bridge.send({
2488
2294
  type: 'tap',
2489
2295
  x: tiPayload.cx,
@@ -2512,8 +2318,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2512
2318
  )
2513
2319
  peachExit(1)
2514
2320
  }
2515
- // type at the live selection through the same guarded operation as
2516
- // chained and cloud typing; clearing first changes controlled values.
2517
2321
  const typed = await performKeys(
2518
2322
  bridge,
2519
2323
  [{ type: 'typeInto', text, nodeId }],
@@ -2803,8 +2607,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2803
2607
  }
2804
2608
 
2805
2609
  case 'touch': {
2806
- // perform batches are self-contained (a pointer never outlives its
2807
- // batch), so a lone phase could never hold a press between commands.
2610
+ // a perform batch is self-contained: a pointer never outlives it, so no press spans commands.
2808
2611
  console.error(
2809
2612
  ' error: a touch lives within one batch; chain its phases, e.g. peach do touch down 200 720 --then touch move 200 400 --then touch up 200 400',
2810
2613
  )
@@ -2895,11 +2698,9 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2895
2698
  break
2896
2699
  case 'swipe-from-bottom-edge':
2897
2700
  fromX = centerX
2898
- // start inside the shell's home-indicator region at the screen edge.
2899
2701
  fromY = height - edgeInset
2900
2702
  toY = Math.max(topInset, fromY - travelY)
2901
2703
  break
2902
- // no default — `preset` is validated against GESTURE_PRESETS above.
2903
2704
  }
2904
2705
  const steps = Math.max(8, Math.round(durationMs / 16))
2905
2706
  const stepMs = Math.max(1, Math.round(durationMs / steps))
@@ -2974,8 +2775,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
2974
2775
 
2975
2776
  case 'state': {
2976
2777
  const stateCmd = positional[1]
2977
- // `peach get state` (no sub-arg) → compact runtime dashboard.
2978
- // `peach debug state <kind>` continues to dispatch the raw dumps.
2979
2778
  if (verbPrefix === 'get' && !stateCmd) {
2980
2779
  const base = await callTestBridge<Record<string, any>>(
2981
2780
  bridge,
@@ -3042,11 +2841,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3042
2841
  result = await callInBridge(bridge, '__sootsimRenderHost.queryStats')
3043
2842
  break
3044
2843
  case 'ownership':
3045
- // plan P1: one authoritative read model for surface ownership
3046
- // + pointerOnSurface delivery observability. bridges through
3047
- // __sootsimRenderHost.getOwnershipSnapshot which reads the
3048
- // shell scene, registered aux surfaces, and
3049
- // pointer-delivery.ts stats.
3050
2844
  result = await bridge.send({
3051
2845
  type: 'evaluate',
3052
2846
  code: `(() => {
@@ -3059,9 +2853,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3059
2853
  })
3060
2854
  break
3061
2855
  case 'keyboard':
3062
- // focused input sourced from __sootsimTest.getFocusedNode() —
3063
- // single authoritative source. getLayout() ships the full
3064
- // keyboard state bundle (spec, mode, shifted, capsLock, accessory).
3065
2856
  result = await bridge.send({
3066
2857
  type: 'evaluate',
3067
2858
  code: `(async () => {
@@ -3154,11 +2945,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3154
2945
  )
3155
2946
  break
3156
2947
  case 'worklets': {
3157
- // both worklet runtimes, side by side. the shell runtime is where
3158
- // shell-sourced events (keyboard, scroll) are dispatched from, so a
3159
- // handler the tenant holds locally instead of forwarding will never
3160
- // fire. compare `eventHandlerNames` across the two to see which
3161
- // side a given event is waiting on.
3162
2948
  const [tenant, shell] = await Promise.all([
3163
2949
  callTestBridge(bridge, 'getWorkletSlotStats'),
3164
2950
  callInBridge(
@@ -3362,9 +3148,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3362
3148
  const result = await runShellVisualCommand(bridge, 'appearance', mode)
3363
3149
  ok = !!result?.ok
3364
3150
  state = { appearance: result }
3365
- // human-readable confirmation line. without this the only output
3366
- // is the multi-line JSON blob below, whose last line is a bare
3367
- // `}` — useless when scanned or piped through `tail -1` (F13-8).
3368
3151
  if (ok) {
3369
3152
  const applied = (result as { applied?: string } | null)?.applied ?? mode
3370
3153
  console.log(` appearance: ${applied}`)
@@ -3387,12 +3170,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3387
3170
  }
3388
3171
 
3389
3172
  case 'reload': {
3390
- // a cloud simulator is a headless runtime with no page to reload, and
3391
- // peach itself runs inside the box's workerd isolate rather than a node
3392
- // process, so the full-page branch below cannot work: it reconnects
3393
- // through `waitForBridgeConnected`, whose `createBridge` constructs the
3394
- // `ws` package's WebSocket, and that import has no constructor in
3395
- // workerd.
3173
+ // a cloud sim has no page to reload, and peach runs inside the box's workerd isolate, not node.
3396
3174
  if (bridge.plane === 'cloud') {
3397
3175
  const message =
3398
3176
  'peach do reload is not available on a cloud simulator; it runs headless with no page to reload. restart the simulator instead.'
@@ -3403,16 +3181,10 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3403
3181
  }
3404
3182
  peachExit(1)
3405
3183
  }
3406
- // reload waits for the guest app's `sootsim:externalAppReady` signal
3407
- // (not just a live ws connection) within RELOAD_READY_TIMEOUT_MS. fatal
3408
- // bundle failures surface as console errors that pile up fast — bail
3409
- // early in that case instead of waiting the full budget.
3184
+ // a reload is ready on the guest's `sootsim:externalAppReady` signal, not a live ws connection.
3410
3185
  let issuedReload = false
3411
3186
  let inPlaceReload = false
3412
- // a reload rewrites the sim's running app, so it takes the cli lease
3413
- // like any other write. a live foreign lease refuses here, before the
3414
- // sim is touched, and the refusal must not be swallowed by the
3415
- // reconnect handling below.
3187
+ // a reload rewrites the running app, so it takes the cli lease like any other write; a foreign lease refusal must not be swallowed by the reconnect handling below.
3416
3188
  await evalInBridge(bridge, 'window.__sootsimConsole?.clear()', {
3417
3189
  acquireLock: true,
3418
3190
  })
@@ -3458,8 +3230,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3458
3230
  console.log(' engine build changed since page load — full page reload')
3459
3231
  }
3460
3232
  } catch (error) {
3461
- // no sim at all is not a reload in flight: report it rather than
3462
- // waiting out the reconnect budget.
3233
+ // no sim at all is not a reload in flight: report it instead of waiting out the reconnect budget.
3463
3234
  const message = error instanceof Error ? error.message : String(error)
3464
3235
  if (
3465
3236
  message === 'no sim connected' ||
@@ -3467,12 +3238,10 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3467
3238
  ) {
3468
3239
  throw error
3469
3240
  }
3470
- // an in-place restart that outlives the budget is still replacing the
3471
- // app, so a ready poll now would read the app it replaces.
3241
+ // an in-place restart past the budget is still replacing the app; a ready poll now would read the old one.
3472
3242
  if (message.startsWith('command timed out')) {
3473
3243
  throw new Error(`reload did not finish within ${RELOAD_READY_TIMEOUT_MS}ms`)
3474
3244
  }
3475
- // the sim may already be in the middle of reloading; fall through to reconnect wait
3476
3245
  }
3477
3246
  console.log(' reloading...')
3478
3247
  let finalBridge: WsBridge | null = bridge
@@ -3482,9 +3251,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3482
3251
  timeoutMs: RELOAD_READY_TIMEOUT_MS,
3483
3252
  })
3484
3253
  } else {
3485
- // full page reload — wait for a fresh bridge before polling for ready.
3486
- // engine-drift escalation made page reloads the COMMON case during
3487
- // engine iteration.
3254
+ // wait for a fresh bridge before polling ready; engine-drift escalation makes page reloads the common case.
3488
3255
  if (issuedReload) await sleep(300)
3489
3256
  const reconnected = await waitForBridgeConnected(
3490
3257
  wsPort,
@@ -3524,9 +3291,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3524
3291
  )
3525
3292
  }
3526
3293
  }
3527
- // dump captured console errors for context, regardless of outcome.
3528
- // merged read so a render-worker / root-error-boundary mount crash
3529
- // (forwarded only through the observability store) is shown here.
3530
3294
  if (finalBridge) {
3531
3295
  try {
3532
3296
  const errors = await inspectErrors(finalBridge, 10)
@@ -3548,9 +3312,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3548
3312
  }
3549
3313
  }
3550
3314
  }
3551
- } catch {
3552
- // ignore errors checking for errors
3553
- }
3315
+ } catch {}
3554
3316
  }
3555
3317
  if (!readyResult?.ready) {
3556
3318
  peachExit(1)
@@ -3626,9 +3388,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3626
3388
  }
3627
3389
  }
3628
3390
  }
3629
- } catch {
3630
- // ignore errors checking for errors
3631
- }
3391
+ } catch {}
3632
3392
  if (!readyResult.ready) {
3633
3393
  peachExit(1)
3634
3394
  }
@@ -3656,11 +3416,8 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3656
3416
  console.error(` ${inspectCommand('js')} SootSim.state.root.children.length`)
3657
3417
  peachExit(1)
3658
3418
  }
3659
- // --tenant: evaluate inside the TENANT worker's global scope (guest
3660
- // bundle, metro module table, compat stubs) via the test bridge's
3661
- // evalInTenant escape hatch, instead of the host/engine realm.
3419
+ // --tenant evaluates in the tenant worker's global scope: guest bundle, metro module table, compat stubs.
3662
3420
  if (args.includes('--tenant')) {
3663
- // the flag itself lands in the joined positional tail — drop it
3664
3421
  const tenantCode = positional
3665
3422
  .slice(1)
3666
3423
  .filter((t) => t !== '--tenant')
@@ -3672,11 +3429,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3672
3429
  printJson(result)
3673
3430
  break
3674
3431
  }
3675
- // wrap in async to support await in worker mode. no identifier
3676
- // rewriting — the snippet runs verbatim so tokens like `root`,
3677
- // `debug`, `test` refer to whatever the user actually typed.
3678
- // compile without executing to distinguish expressions from statements;
3679
- // punctuation inside callbacks, literals and comments is not a separator.
3680
3432
  let expandedCode = code
3681
3433
  if (!expandedCode.startsWith('(async')) {
3682
3434
  expandedCode = `(async () => (\n${code}\n))()`
@@ -3690,7 +3442,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3690
3442
  const result = await bridge.send({ type: 'evaluate', code: expandedCode })
3691
3443
  printJson(result)
3692
3444
 
3693
- // suggest CLI commands for common verbose eval patterns
3694
3445
  const lc = code.toLowerCase()
3695
3446
  const suggestions: string[] = []
3696
3447
  if (lc.includes('sootsim:gohome') || lc.includes('gohome'))
@@ -3720,7 +3471,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3720
3471
  }
3721
3472
 
3722
3473
  case 'globals': {
3723
- // show all available peach globals and their methods
3724
3474
  const info = await bridge.send({
3725
3475
  type: 'evaluate',
3726
3476
  code: `(async () => {
@@ -3990,9 +3740,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
3990
3740
  }
3991
3741
 
3992
3742
  const eventName = `sootsim:${event}`
3993
- // transition profiling needs a longer timeout due to the 600ms
3994
- // wait. these are progress/framing lines, so keep them on stderr —
3995
- // stdout must stay a clean JSON document under --json.
3996
3743
  printWarn(` profiling ${event} transition...`)
3997
3744
  printWarn(` (use --timeout 10000 if this times out)`)
3998
3745
 
@@ -4028,9 +3775,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4028
3775
  default:
4029
3776
  console.error(` unknown perf subcommand: ${perfCmd}`)
4030
3777
  console.error(` valid: start, stop, transition`)
4031
- // people reach for `perf --reset` (or `reset`) out of habit, but
4032
- // `perf start` already clears the frame buffer — there is no
4033
- // separate reset step. say so instead of just erroring.
4034
3778
  if (/^--?reset$/.test(perfCmd)) {
4035
3779
  console.error(
4036
3780
  ` note: 'perf start' already clears prior frames — no reset needed`,
@@ -4124,8 +3868,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4124
3868
  for (const a of anims) {
4125
3869
  const realm = String(a.realm ?? 'tenant').padEnd(6)
4126
3870
  const kind = String(a.kind).padEnd(10)
4127
- // a native-driver registration without an advertised graph has no
4128
- // knowable endpoints or progress; print what is real, not NaN.
4129
3871
  const range =
4130
3872
  typeof a.from === 'number' && typeof a.to === 'number'
4131
3873
  ? `${a.from.toFixed(2)}→${a.to.toFixed(2)}`
@@ -4218,25 +3960,8 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4218
3960
  }
4219
3961
 
4220
3962
  case 'network': {
4221
- // peach network — live request inspector backed by the shared
4222
- // observability store (installed at engine boot, fed by worker-side
4223
- // fetch + XHR capture over BroadcastChannel).
4224
- //
4225
- // shapes:
4226
- // peach network [limit] last N entries (default 20)
4227
- // peach network --failed only non-2xx / errored
4228
- // peach network --slow only requests slower than --threshold (default 1000ms)
4229
- // peach network --threshold <ms> customize slow threshold for --slow
4230
- // peach network --filter <substring> url substring filter
4231
- // peach network --json raw json output
4232
- // peach network tail | -f follow mode (polls)
4233
- // peach network get <id> detail for one entry
4234
- // peach network clear drop the buffer
4235
3963
  const sub = positional[1]
4236
3964
 
4237
- // manual flag scan — parseBridgeCliArgs already stripped these
4238
- // from positional but didn't give us the values, so re-walk the
4239
- // raw input to pull --filter / --limit / --failed / --slow / --threshold / --tail / -f / --json.
4240
3965
  let filter: string | null = null
4241
3966
  let limitFlag: number | null = null
4242
3967
  let failedOnly = false
@@ -4298,9 +4023,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4298
4023
  break
4299
4024
  }
4300
4025
 
4301
- // list / tail mode share the same fetch + format path. default
4302
- // limit is 20; tail mode uses a larger buffer window (200) so
4303
- // spikes don't blow past the ring.
4304
4026
  const limit = limitFlag ?? (tail ? 200 : sub ? Number(sub) : 20)
4305
4027
  if (!Number.isFinite(limit)) {
4306
4028
  console.error(
@@ -4331,18 +4053,12 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4331
4053
  out = out.filter((e) => !!e.error || (e.status != null && e.status >= 400))
4332
4054
  }
4333
4055
  if (slowOnly) {
4334
- // only completed requests can be classified as slow — durationMs
4335
- // is null until a response (or error) arrives. don't include
4336
- // in-flight requests in the slow list (they may finish fast).
4337
4056
  out = out.filter(
4338
4057
  (e) => e.durationMs != null && e.durationMs >= slowThresholdMs,
4339
4058
  )
4340
4059
  }
4341
4060
  if (filter) {
4342
4061
  const lf = filter.toLowerCase()
4343
- // the response content type and the file type the loader asked
4344
- // for are matched too: a url without the extension (a 404 or an
4345
- // extensionless asset) still names its type
4346
4062
  out = out.filter(
4347
4063
  (e) =>
4348
4064
  (e.displayUrl || e.url).toLowerCase().includes(lf) ||
@@ -4350,8 +4066,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4350
4066
  (e.requestedType ?? '').toLowerCase().includes(lf),
4351
4067
  )
4352
4068
  }
4353
- // when --slow is on without --tail, sort by durationMs descending
4354
- // so the slowest requests print first regardless of finish order.
4355
4069
  if (slowOnly && !tail) {
4356
4070
  out = [...out].sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0))
4357
4071
  }
@@ -4388,10 +4102,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4388
4102
  break
4389
4103
  }
4390
4104
 
4391
- // tail mode — poll every 250ms, track the set of completed ids
4392
- // we've already printed, and emit new entries as they land. only
4393
- // prints *completed* entries (durationMs != null) so each request
4394
- // renders once with its final status, not twice.
4395
4105
  console.log(' tailing network (ctrl-c to stop)...\n')
4396
4106
  const seen = new Set<string>()
4397
4107
  let running = true
@@ -4419,17 +4129,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4419
4129
  }
4420
4130
 
4421
4131
  case 'logs': {
4422
- // peach logs — live console inspector backed by the shared
4423
- // observability log store (fed by worker-side console capture over
4424
- // BroadcastChannel). mirrors `peach network`:
4425
- //
4426
- // peach logs [limit] last N entries (default 50)
4427
- // peach logs --level error,warn filter by level (csv)
4428
- // peach logs --filter <str> message substring filter
4429
- // peach logs --internal include engine-internal [sootsim] logs (hidden by default)
4430
- // peach logs --json raw json output
4431
- // peach logs tail | -f follow mode (polls)
4432
- // peach logs clear drop the buffer
4433
4132
  const sub = positional[1]
4434
4133
 
4435
4134
  let filter: string | null = null
@@ -4489,9 +4188,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4489
4188
 
4490
4189
  const fetchEntries = () => inspectLogs(bridge)
4491
4190
 
4492
- // engine-internal logs (bundle-loader setup, HMR trap messages, etc.)
4493
- // are noise when debugging guest-app behavior — filterLogEntries hides
4494
- // them by default; pass --internal to include them.
4495
4191
  const applyFilter = (all: LogEntry[]) =>
4496
4192
  filterLogEntries(all, {
4497
4193
  level: levelFilter,
@@ -4545,10 +4241,6 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4545
4241
  peachExit(1)
4546
4242
  }
4547
4243
 
4548
- // auto-settle after any write command so the next CLI call doesn't see
4549
- // mid-transition state. short deadline — if the app has a perpetual
4550
- // background animation, we bail to layout-only stability via the same
4551
- // logic `do settle` uses. opt-out: --no-wait or PEACH_NO_AUTO_WAIT=1.
4552
4244
  if (
4553
4245
  writeCommands.has(subcommand) &&
4554
4246
  !args.includes('--no-wait') &&
@@ -4558,31 +4250,15 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4558
4250
  await autoSettleAfterWrite(bridge)
4559
4251
  }
4560
4252
 
4561
- // framing prose (this note, the cursor footer, hints, console summaries)
4562
- // goes to stderr, never stdout. a `--json` flag is not a usable signal for
4563
- // that: `do tap-id`, `do tap-text`, and the rest of the write verbs print a
4564
- // JSON document by default with no flag at all, so gating on the flag left
4565
- // exactly those commands emitting `{...}` followed by `since last: …` and
4566
- // breaking every parser. keeping payload on stdout and prose on stderr is
4567
- // the only rule that holds for both.
4568
- // the native-UI note flags a blocking Alert/ActionSheet that was up when an
4569
- // interaction verb ran — it silently eats taps/drags meant for the app, the
4570
- // single most confusing "my `do` did nothing" failure.
4253
+ // framing prose goes to stderr, never stdout; a --json flag is not a usable signal for that.
4571
4254
  if (nativeUIBeforeWrite.length > 0) {
4572
4255
  printNativeUISummary(nativeUIBeforeWrite)
4573
4256
  }
4574
4257
 
4575
- // cursor footer reads `bridges.timeline.summary` keyed on the agent's
4576
- // stable cliSessionKey so every CLI call shows only what's *new* since the
4577
- // previous call from the same agent (not a global count). after printing,
4578
- // advance the cursor past the rendered window so the next call starts
4579
- // fresh.
4580
4258
  if (!consoleSummarySkip.has(subcommand)) {
4581
4259
  try {
4582
4260
  await printCursorFooter(bridge)
4583
- } catch {
4584
- // ignore footer errors; the main command already succeeded
4585
- }
4261
+ } catch {}
4586
4262
  }
4587
4263
  } catch (err: any) {
4588
4264
  rethrowIfExit(err)
@@ -4592,22 +4268,14 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4592
4268
  const unknownSim = /^no sim connected with id ([^;]+)(?:; connected sims: .+)?$/.exec(
4593
4269
  message,
4594
4270
  )
4595
- // a failure whose own message proves the sim/bridge is unresponsive must
4596
- // NOT trigger the secondary diagnostic round-trips below — each of them
4597
- // issues its own bridge command, which against the same dead sim just
4598
- // re-incurs the full per-command timeout. three sequential probes turn a
4599
- // single 15s timeout into ~60s of apparent hang (QA F19-1). there is
4600
- // nothing useful to fetch from a sim that just timed out, so skip them.
4271
+ // a failure that proves the sim is unresponsive must skip the secondary round-trips; each would re-incur the timeout.
4601
4272
  const timedOut = /^command timed out after (\d+(?:\.\d+)?)s$/.exec(message)
4602
- // a disconnected bridge is genuinely gone; recover is right and probing
4603
- // it would just re-incur a full timeout. no bridge at all means there is
4604
- // no sim to recover, only one to open.
4273
+ // a disconnected bridge is gone: recover, and probing would just re-incur a full timeout.
4605
4274
  const disconnected =
4606
4275
  message.startsWith('sim disconnected:') ||
4607
4276
  message.startsWith('bridge never reconnected')
4608
4277
  if (refusedBeforeTouchingSim(bridge)) {
4609
- // the bridge refused before reaching the sim, so every secondary probe
4610
- // below would be a read of a sim this cli does not hold.
4278
+ // the bridge refused before reaching the sim, so secondary probes would read a sim this cli does not hold.
4611
4279
  } else if (unknownSim) {
4612
4280
  await printUnknownSimHint(bridge, wsPort, unknownSim[1])
4613
4281
  } else if (
@@ -4616,11 +4284,7 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4616
4284
  ) {
4617
4285
  printMissingSimHint(wsPort)
4618
4286
  } else if (timedOut) {
4619
- // a command timeout alone does not mean a wedged sim — a large screen
4620
- // can blow the budget on `describe`'s tree serialization while the sim
4621
- // answers everything else fine. probe once (short budget); if it's
4622
- // alive, point at narrowing/raising the budget instead of force-closing
4623
- // a healthy sim.
4287
+ // a command timeout alone does not mean a wedged sim: `describe` serialization can blow the budget on a large screen.
4624
4288
  const alive = await probeSimResponsive(bridge)
4625
4289
  if (alive) {
4626
4290
  const cmd = subcommand ?? 'describe'
@@ -4639,19 +4303,13 @@ export async function runInspect(args: string[], opts: InspectOptions) {
4639
4303
  } else {
4640
4304
  try {
4641
4305
  await printBridgeStateSummary(bridge)
4642
- } catch {
4643
- // ignore secondary bridge errors while already failing the command
4644
- }
4306
+ } catch {}
4645
4307
  try {
4646
4308
  await printConsoleSummary({ includeTail: true })
4647
- } catch {
4648
- // ignore secondary bridge errors while already failing the command
4649
- }
4309
+ } catch {}
4650
4310
  try {
4651
4311
  await printRequestSummary({ includeTail: true })
4652
- } catch {
4653
- // ignore secondary request summary errors while already failing the command
4654
- }
4312
+ } catch {}
4655
4313
  }
4656
4314
  peachExit(1)
4657
4315
  } finally {