Repository navigation
Expand file tree
/
Copy pathcommand-output-schemas.ts
More file actions
867 lines (828 loc) · 33.2 KB
/
Copy pathcommand-output-schemas.ts
File metadata and controls
867 lines (828 loc) · 33.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
import type { JsonSchema } from '../commands/command-contract.ts';
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
import { commandSupportsSettleObservation } from '@agent-device/command-registry/registry';
import {
booleanSchema,
enumSchema,
looseObjectSchema,
numberSchema,
objectSchema,
stringArraySchema,
stringSchema,
} from '../commands/command-input.ts';
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../commands/replay/index.ts';
import { BACK_MODES } from '@agent-device/contracts/back-mode';
import { NATIVE_PATH_DISPOSITION_VALUES } from '@agent-device/contracts/recording-native-path';
import { RECORDER_OBSERVATION_VALUES } from '@agent-device/contracts/recording-stop-observation';
import { DEVICE_ROTATIONS, FOLD_POSES } from '@agent-device/contracts/device';
import { FOLD_SCREEN_COORDINATE_SPACE } from '@agent-device/contracts/fold-runtime';
import { SESSION_SURFACES } from '@agent-device/contracts/session';
import { TV_REMOTE_BUTTONS } from '@agent-device/contracts/tv-remote';
import { DEVICE_TARGETS, PUBLIC_PLATFORMS } from '@agent-device/kernel/device';
/**
* Registry of per-command MCP `outputSchema`s, keyed by the daemon command
* NAME. It is type-tied to the typed-result spine `CommandResultMap`
* (@agent-device/command-registry/command-result) via
* `satisfies Record<keyof CommandResultMap, JsonSchema>`, so the one-for-one
* invariant is compiler-enforced: a new `CommandResultMap` entry without a schema
* here is a missing-key error, and a typo'd/extra key is an excess-property error.
* The genuinely-dynamic commands (snapshot overlays, gestures, perf, logs, …) are
* absent from BOTH maps — their tools stay byte-identical to today (no
* `outputSchema` key), exactly as `CommandResultMap` omits them rather than
* inventing a shape.
*
* There is no type→JSON-Schema generator in this repo. Schemas are hand-authored from
* matching contract types, using the shared JSON-Schema primitives in
* `src/commands/command-input.ts`. Where a command family is owned by one module (the
* descriptors' `ownerFiles`), that module authors its entries and projects them into this
* map instead of being hand-listed here. Two invariants:
* - NEVER strict: no `additionalProperties: false` anywhere, so the additive
* `cost` object (opted in via `--cost` / `includeCost`) and any other additive
* fields ride into `structuredContent` and still validate.
* - Accurate, never invented: required-vs-optional, enums, `const` discriminants
* and discriminated-union branches mirror the source contract types.
*
* The opt-in `--settle` observation (#1101) is not hand-listed per entry: the
* base map carries none and `deriveSettleObservationSchemas` grafts it onto
* exactly the entries whose descriptor declares the post-action observation
* trait (#1652).
*/
export const DEVICE_KINDS = ['simulator', 'emulator', 'device'] as const;
function constSchema(value: string): JsonSchema {
return { type: 'string', const: value };
}
function nullableStringSchema(description?: string): JsonSchema {
return { type: ['string', 'null'], ...(description ? { description } : {}) };
}
const responseCostSchema: JsonSchema = objectSchema(
{
wallClockMs: numberSchema('Total wall-clock time for the request in milliseconds.'),
runnerRoundTrips: numberSchema(
'Number of real runner round-trips made while serving the request.',
),
nodeCount: numberSchema(
'Number of nodes in the original node tree when the response carries one.',
),
},
['wallClockMs', 'runnerRoundTrips'],
);
const artifactSchema = objectSchema(
{
field: stringSchema(),
artifactType: stringSchema(),
path: stringSchema(),
localPath: stringSchema(),
fileName: stringSchema(),
},
['field'],
);
type InteractionExtra = {
properties?: Record<string, JsonSchema>;
required?: readonly string[];
};
/**
* Canonical interaction response data built by buildInteractionResponseData:
* shared target/coordinate/evidence fields plus per-command extras. The runtime
* result still has richer internal node/backend data; this schema documents the
* JSON payload returned to clients.
*/
function interactionResponseDataSchema(extra: InteractionExtra = {}): JsonSchema {
const extraProperties = extra.properties ?? {};
const extraRequired = extra.required ?? [];
return objectSchema(
{
targetKind: enumSchema(['point', 'ref', 'selector'], 'Resolved interaction target kind.'),
x: numberSchema('Resolved interaction x coordinate when available.'),
y: numberSchema('Resolved interaction y coordinate when available.'),
referenceWidth: numberSchema('Reference frame width for visualizing the interaction point.'),
referenceHeight: numberSchema(
'Reference frame height for visualizing the interaction point.',
),
ref: stringSchema('Snapshot ref without the @ prefix when the target was an @ref.'),
selector: stringSchema('Selector expression when the target was a selector.'),
selectorChain: stringArraySchema(),
refLabel: stringSchema(),
targetHittable: booleanSchema(),
hint: stringSchema(),
warning: stringSchema(),
message: stringSchema(),
evidence: interactionEvidenceSchema,
resolution: resolutionDisclosureSchema,
cost: responseCostSchema,
maestroNonHittableCoordinateFallbackAllowed: booleanSchema(
'Whether the direct iOS Maestro coordinate fallback was allowed for this selector.',
),
maestroNonHittableCoordinateFallbackUsed: booleanSchema(
'Whether the direct iOS Maestro coordinate fallback was actually used.',
),
maestroFallbackReason: constSchema('non-hittable-coordinate'),
...extraProperties,
},
['targetKind', ...extraRequired],
);
}
// ResolutionDiagnosticEntry (packages/contracts/src/interaction.ts) — a disambiguation
// winner or losing alternative. Never a snapshot ref.
const resolutionDiagnosticEntrySchema: JsonSchema = objectSchema(
{
diagnosticRef: stringSchema(
'Opaque non-@ diagnostic token. Never a snapshot ref: not issued via refsGeneration and cannot be pinned or reused as an @ref target. UTF-8 truncated to 256 bytes.',
),
role: stringSchema('UTF-8 truncated to 256 bytes.'),
label: stringSchema('UTF-8 truncated to 256 bytes.'),
},
['diagnosticRef'],
);
// ResolutionDisclosure (packages/contracts/src/interaction.ts) — never ref-issuing;
// absent on paths where the guarantee is inapplicable (ADR 0012 decision 2).
// `alternatives` rides default/full levels only; the digest view omits it.
const resolutionDisclosureSchema: JsonSchema = {
type: 'object',
description:
'Pre-action disclosure of how the acting path resolved its target. Absent when resolutionDisclosure is inapplicable for the path.',
oneOf: [
objectSchema(
{
source: constSchema('runtime'),
phase: constSchema('pre-action'),
kind: constSchema('unique'),
},
['source', 'phase', 'kind'],
),
objectSchema(
{
source: constSchema('runtime'),
phase: constSchema('pre-action'),
kind: constSchema('disambiguated'),
matchCount: numberSchema('Total matches resolveSelectorChain found before disambiguation.'),
winnerDiagnostic: resolutionDiagnosticEntrySchema,
tiebreak: enumSchema(
['visible', 'deepest', 'smallest-area', 'structural-equivalence'],
'The comparison that decided the winner.',
),
alternatives: {
type: 'array',
description:
'At most 5 losing candidates, document order. Present at default/full response levels and omitted in digest. The winner is never included.',
items: resolutionDiagnosticEntrySchema,
},
},
['source', 'phase', 'kind', 'matchCount', 'winnerDiagnostic', 'tiebreak'],
),
objectSchema(
{ source: constSchema('ref'), phase: constSchema('pre-action'), kind: constSchema('exact') },
['source', 'phase', 'kind'],
),
objectSchema(
{
source: constSchema('ref'),
phase: constSchema('pre-action'),
kind: constSchema('label-fallback'),
},
['source', 'phase', 'kind'],
),
objectSchema({ source: constSchema('direct-ios'), kind: constSchema('not-observed') }, [
'source',
'kind',
]),
],
};
// PostActionSurfaceChange (packages/contracts/src/interaction.ts) — the post-action capture
// describes a different surface than the pre-action baseline (#2438), so no same-surface
// comparison is presented across it.
const postActionSurfaceChangeSchema: JsonSchema = objectSchema(
{
from: stringSchema('Surface the pre-action baseline described: a host bundle id, or app.'),
to: stringSchema('Surface the post-action capture describes: a host bundle id, or app.'),
disclosure: stringSchema('Agent-facing sentence explaining the surface transition.'),
},
['from', 'to', 'disclosure'],
'Present when an in-place system surface (web sign-in or Apple Pay sheet) was presented over the app, or left it.',
);
// InteractionEvidence (packages/contracts/src/interaction.ts) — opt-in `--verify` cheap
// post-condition evidence (#1047).
const interactionEvidenceSchema: JsonSchema = objectSchema(
{
foregroundApp: stringSchema('Foreground app bundle id or name, when the capture carries it.'),
nodeCount: numberSchema('Node count in the post-action interactive-only capture.'),
interactiveNodeCount: numberSchema('Subset of nodeCount the platform reports as hittable.'),
digest: stringSchema('Order-independent digest of the post-action node multiset.'),
changedFromBefore: booleanSchema(
'Whether the post-action digest differs from the pre-action capture digest. false is evidence, not failure. With surfaceChange present, no digest comparison is made: it reports that surface transition.',
),
surfaceChange: postActionSurfaceChangeSchema,
},
['nodeCount', 'interactiveNodeCount', 'digest', 'changedFromBefore'],
);
// SettleObservation (packages/contracts/src/interaction.ts) — opt-in `--settle` settled
// diff observation (#1101).
const settleObservationSchema: JsonSchema = objectSchema(
{
settled: booleanSchema(
'Whether the UI held the quiet window before the deadline. false is advisory, not failure.',
),
waitedMs: numberSchema(),
captures: numberSchema(),
quietMs: numberSchema(),
timeoutMs: numberSchema(),
refsGeneration: numberSchema(
'Snapshot generation of the stored settled tree; refs on added diff lines were minted from it.',
),
refs: {
type: 'array',
items: objectSchema(
{
ref: stringSchema('Plain ref body (e12) minted from the stored settled tree.'),
},
['ref'],
),
},
surfaceChange: postActionSurfaceChangeSchema,
diff: objectSchema(
{
summary: objectSchema(
{
additions: numberSchema(),
removals: numberSchema(),
unchanged: numberSchema(),
},
['additions', 'removals', 'unchanged'],
),
lines: {
type: 'array',
items: objectSchema(
{
kind: enumSchema(['added', 'removed']),
text: stringSchema(),
ref: stringSchema('Plain ref body (e12) for added lines.'),
},
['kind', 'text'],
),
},
truncated: booleanSchema('Lines were capped to the response bound.'),
},
['summary', 'lines'],
'Settled diff vs the pre-action tree (changed lines only).',
),
tail: {
type: 'array',
description:
'Unchanged interactive refs tail: still-present, actionable elements from the settled tree, attached only when diff carries zero added-line refs (a modal-dismiss/toast-only diff).',
items: objectSchema(
{
ref: stringSchema('Plain ref body (e12) minted from the stored settled tree.'),
role: stringSchema(),
label: stringSchema(),
},
['ref', 'role'],
),
},
tailTruncated: booleanSchema('Present (true) when tail candidates exceeded the response cap.'),
hint: stringSchema(),
},
['settled', 'waitedMs', 'captures', 'quietMs', 'timeoutMs'],
);
// boot / shutdown share the resolved-device header (packages/contracts/src/device.ts).
const deviceHeaderProperties: Record<string, JsonSchema> = {
// Public leaf vocabulary (ios | macos | android | linux | web): boot/shutdown
// emit publicPlatformString, never the internal `apple` platform.
platform: enumSchema(PUBLIC_PLATFORMS),
target: enumSchema(DEVICE_TARGETS),
device: stringSchema('Human-readable device name.'),
id: stringSchema('Stable device id.'),
kind: enumSchema(DEVICE_KINDS),
};
const deviceHeaderRequired = ['platform', 'target', 'device', 'id', 'kind'] as const;
// TargetShutdownResult (packages/contracts/src/target-shutdown-contract.ts).
const targetShutdownResultSchema: JsonSchema = objectSchema(
{
success: booleanSchema(),
exitCode: numberSchema(),
stdout: stringSchema(),
stderr: stringSchema(),
error: looseObjectSchema('Normalized error detail when shutdown failed.'),
},
['success', 'exitCode', 'stdout', 'stderr'],
);
/** Grafts the opt-in `--settle` observation onto a closed schema or union branch. */
function withSettleObservation(schema: JsonSchema): JsonSchema {
// Union-shaped results (fill) carry the observation in EACH branch, never
// next to the oneOf.
if (schema.oneOf) {
return { ...schema, oneOf: schema.oneOf.map(withSettleObservation) };
}
return {
...schema,
properties: { ...(schema.properties ?? {}), settle: settleObservationSchema },
};
}
/**
* #1652: whether a command's output schema advertises `settle` derives from
* its descriptor post-action observation trait instead of hand-listed
* properties per schema. The base map below carries no settle property
* anywhere; this pass grafts it onto exactly the trait-capable entries.
* Copies only — press and click share one base schema object, so an in-place
* graft would leak across them.
*/
function deriveSettleObservationSchemas(
schemas: Record<keyof CommandResultMap, JsonSchema>,
): Record<keyof CommandResultMap, JsonSchema> {
const derived: Record<keyof CommandResultMap, JsonSchema> = { ...schemas };
for (const command of Object.keys(derived) as Array<keyof CommandResultMap>) {
if (!commandSupportsSettleObservation(command)) continue;
derived[command] = withSettleObservation(derived[command]);
}
return derived;
}
const tapInteractionResponseDataSchema = interactionResponseDataSchema({
properties: {
evidence: interactionEvidenceSchema,
button: enumSchema(['secondary', 'middle']),
count: numberSchema('Number of press/click repetitions.'),
intervalMs: numberSchema('Delay between repeated press/click actions.'),
holdMs: numberSchema('Hold duration for each action.'),
jitterPx: numberSchema('Randomization radius in pixels.'),
doubleTap: booleanSchema('Whether the command requested a double-tap action.'),
},
});
const fillResponseProperties = {
text: stringSchema('Text submitted to the field.'),
delayMs: numberSchema('Delay between typed characters in milliseconds.'),
evidence: interactionEvidenceSchema,
};
const fillVerificationTargetSchema = objectSchema(
{
resourceId: nullableStringSchema('Android resource id of the exact field that changed.'),
className: nullableStringSchema('Android class name of the exact field that changed.'),
packageName: nullableStringSchema('Android package name that owns the exact field.'),
rect: objectSchema(
{
x: numberSchema(),
y: numberSchema(),
width: numberSchema(),
height: numberSchema(),
},
['x', 'y', 'width', 'height'],
'Screen-space rectangle of the exact field that changed.',
),
},
['resourceId', 'className', 'packageName', 'rect'],
'Target identity captured before fill and matched after fill.',
);
const confirmedFillResponseSchema: JsonSchema = {
...interactionResponseDataSchema({
properties: fillResponseProperties,
required: ['text'],
}),
// The public result contract omits verification evidence on an ordinary
// confirmed fill. Keep this branch disjoint from the unconfirmed branch
// without making the response strict to unrelated additive fields.
not: objectSchema({}, ['verification']),
};
const unconfirmedFillResponseSchema = interactionResponseDataSchema({
properties: {
...fillResponseProperties,
verification: constSchema('unconfirmed'),
requested: stringSchema('Literal text requested by the fill command.'),
before: nullableStringSchema('Raw target text captured before the fill.'),
after: nullableStringSchema('Raw target text captured after the fill.'),
target: fillVerificationTargetSchema,
},
required: ['text', 'verification', 'requested', 'before', 'after', 'target'],
});
const BASE_COMMAND_OUTPUT_SCHEMAS = {
// buildInteractionResponseData public payloads for interaction commands.
// #1652: the opt-in `settle` observation is NOT listed here — the trait
// derivation pass grafts it onto settle-capable entries below.
press: tapInteractionResponseDataSchema,
click: tapInteractionResponseDataSchema,
fill: {
type: 'object',
description:
'Fill response. Android may return target-bound unconfirmed evidence when the exact app-owned field changed but formatting prevented raw equality.',
oneOf: [confirmedFillResponseSchema, unconfirmedFillResponseSchema],
},
longpress: interactionResponseDataSchema({
properties: {
durationMs: numberSchema(),
gesture: constSchema('longpress'),
},
}),
hover: interactionResponseDataSchema({
properties: {
gesture: constSchema('hover'),
},
}),
find: objectSchema(
{
ref: stringSchema('Snapshot ref without the @ prefix when the find action returns one.'),
refsGeneration: numberSchema('ADR 0014 ref frame epoch for read-only find actions.'),
found: booleanSchema('Whether a wait/exists/read-only find satisfied its condition.'),
waitedMs: numberSchema('Milliseconds waited for a read-only find condition.'),
text: stringSchema('Text value returned by find get_text.'),
node: looseObjectSchema('Snapshot node for find get_attrs/get_text.'),
matches: {
type: 'array',
description: 'Every match for the read-only find list action (#1625): { ref, node } each.',
items: looseObjectSchema('One listed match with its snapshot ref and node.'),
},
locator: stringSchema('Locator kind used for the find action.'),
query: stringSchema('Query argument used for the find action.'),
x: numberSchema('Resolved x coordinate for mutating find actions.'),
y: numberSchema('Resolved y coordinate for mutating find actions.'),
message: stringSchema('Diagnostic message for mutating find actions.'),
cost: responseCostSchema,
},
[],
'Daemon response data for the find command.',
),
// packages/contracts/src/device.ts
boot: objectSchema({ ...deviceHeaderProperties, booted: { type: 'boolean', const: true } }, [
...deviceHeaderRequired,
'booted',
]),
shutdown: objectSchema({ ...deviceHeaderProperties, shutdown: targetShutdownResultSchema }, [
...deviceHeaderRequired,
'shutdown',
]),
// packages/contracts/src/viewport.ts
viewport: objectSchema(
{ width: numberSchema(), height: numberSchema(), message: stringSchema() },
['width', 'height', 'message'],
),
// packages/contracts/src/navigation.ts. `back`'s settle observation is grafted
// by the derivation pass below.
back: objectSchema(
{
action: constSchema('back'),
mode: enumSchema(BACK_MODES),
message: stringSchema(),
},
['action', 'mode', 'message'],
),
home: objectSchema({ action: constSchema('home'), message: stringSchema() }, [
'action',
'message',
]),
orientation: objectSchema(
{
action: constSchema('orientation'),
orientation: enumSchema(DEVICE_ROTATIONS),
message: stringSchema(),
confirmed: booleanSchema(),
warning: stringSchema(),
},
['action', 'orientation', 'message'],
),
'app-switcher': objectSchema({ action: constSchema('app-switcher'), message: stringSchema() }, [
'action',
'message',
]),
fold: objectSchema(
{
action: constSchema('fold'),
pose: enumSchema(FOLD_POSES),
hingeAngleDegrees: numberSchema('Hinge angle CoreDevice read back after the pose settled.'),
screen: objectSchema(
{
display: stringSchema('CoreDevice name of the panel the device now lights.'),
coordinateSpace: constSchema(FOLD_SCREEN_COORDINATE_SPACE),
widthPt: numberSchema(
'Panel width in native panel points (pixels divided by point scale), NOT snapshot coordinates; take a fresh snapshot to place a tap.',
),
heightPt: numberSchema(
'Panel height in native panel points (pixels divided by point scale), NOT snapshot coordinates; take a fresh snapshot to place a tap.',
),
},
['display', 'coordinateSpace', 'widthPt', 'heightPt'],
),
message: stringSchema(),
},
['action', 'pose', 'hingeAngleDegrees', 'message'],
),
'action-button': objectSchema({ action: constSchema('action-button'), message: stringSchema() }, [
'action',
'message',
]),
'tv-remote': objectSchema(
{
action: constSchema('tv-remote'),
button: enumSchema(TV_REMOTE_BUTTONS),
durationMs: numberSchema(),
message: stringSchema(),
},
['action', 'button', 'message'],
),
// packages/contracts/src/wait.ts — compact public daemon projection.
wait: objectSchema(
{
waitedMs: numberSchema(),
kind: constSchema('selector'),
text: stringSchema(),
selector: stringSchema(),
captures: numberSchema(),
nodeCount: numberSchema(),
hint: stringSchema(),
warning: stringSchema(),
},
['waitedMs'],
),
// packages/contracts/src/scroll-command.ts — ScrollCommandResult. The
// settle-capable generic-route pair must both be typed so the trait
// derivation grafts the observation onto each (#1652); platform leaves add
// gesture-plan coordinates on top, which the non-strict schema admits.
scroll: objectSchema(
{
direction: enumSchema(['up', 'down', 'left', 'right']),
edge: enumSchema(['top', 'bottom']),
until: stringSchema('Until scrolls only: the selector the passes stopped on.'),
passes: numberSchema('Edge and until scrolls only: how many scroll-and-check passes ran.'),
amount: numberSchema(),
pixels: numberSchema(),
durationMs: numberSchema(),
message: stringSchema(),
keyboardAvoided: booleanSchema(
'Present only when an on-screen keyboard forced the swipe into the band above it; the reported pixels were planned against the shorter referenceHeight.',
),
keyboardMinY: numberSchema(
'Where the keyboard began, in the same unit as the gesture coordinates. Clipped scrolls only.',
),
movement: enumSchema(
['moved', 'at-edge', 'unchanged', 'unobserved'],
'Directional scrolls only: what the owner observed after its gesture. `moved` means the content inside the scroller the swipe ran in differs from the tree the session stored immediately before the gesture; `at-edge` and `unchanged` mean it did not change, with no hidden content left to reveal and with no end-of-content signal to read, respectively; `unobserved` means the pair could not back a claim in either direction — nothing comparable was available (no stored tree, a capture from another lineage, a surface that never came to rest), or every difference sits outside the scroller that was swiped, which a changing status bar does on Android — so the reported distance rests on the gesture plan alone. The field is absent — which is never a claim that nothing moved — on the tiers that verify per pass (`scroll top`/`bottom`, `--until`), on a runtime bound without a capture, on a platform whose scroll dispatches no swipe (the Linux wheel), and where the caller already owns that observation (`--settle`, or a replay with `postGestureStabilization: false`).',
),
},
['direction'],
),
// packages/contracts/src/prepare.ts — prepare is not MCP-exposed, but the schema stays
// map-complete with CommandResultMap.
prepare: objectSchema(
{
action: constSchema('ios-runner'),
// PublicPlatform leaf, mirroring PrepareCommandResult (packages/contracts/src/prepare.ts).
platform: enumSchema(PUBLIC_PLATFORMS),
deviceId: stringSchema(),
deviceName: stringSchema(),
kind: enumSchema(DEVICE_KINDS),
durationMs: numberSchema(),
runner: objectSchema({}, []),
cache: enumSchema(['exact', 'restore-key', 'miss', 'external']),
artifact: enumSchema(['valid', 'rebuilt']),
buildMs: numberSchema(),
connectMs: numberSchema(),
healthCheckMs: numberSchema(),
xctestrunPath: stringSchema(),
recoveryReason: stringSchema(),
failureReason: stringSchema(),
timing: objectSchema(
{
totalMs: numberSchema(),
additiveParts: objectSchema(
{
buildMs: numberSchema(),
connectAfterBuildMs: numberSchema(),
healthCheckMs: numberSchema(),
},
['connectAfterBuildMs', 'healthCheckMs'],
),
containment: objectSchema(
{
connectMs: { type: 'array', items: constSchema('buildMs') },
healthCheckMs: { type: 'array', items: stringSchema() },
},
['healthCheckMs'],
),
note: stringSchema(),
},
['totalMs', 'additiveParts', 'containment', 'note'],
),
message: stringSchema(),
},
[
'action',
'platform',
'deviceId',
'deviceName',
'kind',
'durationMs',
'runner',
'connectMs',
'healthCheckMs',
'timing',
'message',
],
),
// packages/contracts/src/push.ts — discriminated union on public platform.
push: {
type: 'object',
oneOf: [
objectSchema(
{ platform: constSchema('ios'), bundleId: stringSchema(), message: stringSchema() },
['platform', 'bundleId', 'message'],
),
objectSchema(
{
platform: constSchema('android'),
package: stringSchema(),
action: stringSchema(),
extrasCount: numberSchema(),
message: stringSchema(),
},
['platform', 'package', 'action', 'extrasCount', 'message'],
),
],
},
// packages/contracts/src/app-events.ts
'trigger-app-event': objectSchema(
{
event: stringSchema(),
eventUrl: stringSchema(),
transport: constSchema('deep-link'),
message: stringSchema(),
},
['event', 'eventUrl', 'transport', 'message'],
),
// packages/contracts/src/clipboard.ts — discriminated union on `action`.
clipboard: {
type: 'object',
oneOf: [
objectSchema({ action: constSchema('read'), text: stringSchema() }, ['action', 'text']),
objectSchema(
{ action: constSchema('write'), textLength: numberSchema(), message: stringSchema() },
['action', 'textLength', 'message'],
),
],
},
// packages/contracts/src/app-state.ts — discriminated union on `platform`.
appstate: {
type: 'object',
oneOf: [
objectSchema(
{
platform: enumSchema(['ios', 'macos']),
appName: stringSchema(),
appBundleId: stringSchema(),
source: constSchema('session'),
surface: enumSchema(SESSION_SURFACES),
device_udid: stringSchema('iOS only — the session device UDID.'),
ios_simulator_device_set: {
type: ['string', 'null'],
description: 'iOS only — the simulator set path, or null when unknown.',
},
},
['platform', 'appName', 'source', 'surface'],
),
objectSchema(
{
platform: constSchema('android'),
package: stringSchema(),
activity: stringSchema(),
},
['platform', 'package', 'activity'],
),
],
},
// packages/contracts/src/keyboard.ts — flat closed shape; `platform`/`action` always present.
keyboard: objectSchema(
{
platform: enumSchema(['android', 'ios']),
action: enumSchema(['status', 'dismiss', 'enter']),
visible: booleanSchema(),
wasVisible: booleanSchema(),
dismissed: booleanSchema(),
attempts: numberSchema(),
inputType: stringSchema(),
type: enumSchema(['text', 'number', 'email', 'phone', 'password', 'datetime', 'unknown']),
inputMethodPackage: stringSchema(),
focusedPackage: stringSchema(),
focusedResourceId: stringSchema(),
inputOwner: enumSchema(['app', 'ime', 'unknown']),
message: stringSchema(),
},
['platform', 'action'],
),
// packages/contracts/src/doctor.ts
doctor: objectSchema(
{
status: enumSchema(['pass', 'warn', 'fail', 'info']),
summary: stringSchema(),
kind: enumSchema(['auto', 'react-native', 'expo', 'repack']),
platform: stringSchema(),
target: enumSchema(DEVICE_TARGETS),
targetApp: stringSchema(),
metro: objectSchema({ host: stringSchema(), port: numberSchema() }, ['host', 'port']),
checks: {
type: 'array',
items: objectSchema(
{
id: stringSchema(),
status: enumSchema(['pass', 'warn', 'fail', 'info']),
summary: stringSchema(),
hint: stringSchema(),
command: stringSchema(),
evidence: looseObjectSchema(),
},
['id', 'status', 'summary'],
),
},
},
['status', 'summary', 'kind', 'checks'],
),
// packages/contracts/src/diff.ts — the public Node command accepts snapshot diffs.
diff: objectSchema(
{
mode: constSchema('snapshot'),
baselineInitialized: booleanSchema(),
summary: objectSchema(
{
additions: numberSchema(),
removals: numberSchema(),
unchanged: numberSchema(),
},
['additions', 'removals', 'unchanged'],
),
lines: {
type: 'array',
items: objectSchema(
{
kind: enumSchema(['added', 'removed']),
text: stringSchema(),
ref: stringSchema(),
},
['kind', 'text'],
),
},
warnings: stringArraySchema(),
},
['mode', 'baselineInitialized', 'summary', 'lines'],
),
// packages/contracts/src/recording.ts
record: {
type: 'object',
oneOf: [
objectSchema(
{
recording: constSchema('started'),
outPath: stringSchema(),
sessionStateDir: stringSchema(),
recordingBackend: stringSchema(),
recordingScope: stringSchema(),
recordOnlySession: booleanSchema(),
activeSessionApp: looseObjectSchema(),
showTouches: booleanSchema(),
},
['recording', 'outPath', 'sessionStateDir', 'showTouches'],
),
objectSchema(
{
recording: constSchema('stopped'),
outPath: stringSchema(),
telemetryPath: stringSchema(),
artifacts: { type: 'array', items: artifactSchema },
recordingBackend: stringSchema(),
recordingScope: stringSchema(),
recordOnlySession: booleanSchema(),
activeSessionApp: looseObjectSchema(),
durationMs: numberSchema(),
capturedDurationMs: numberSchema(),
recorder: enumSchema(
RECORDER_OBSERVATION_VALUES,
'What the recorder was observed doing when the recording was stopped: confirmed, or lost when the session holding it died. ADR 0024 reserves unconfirmed for the step that gains the probe.',
),
nativePathDisposition: enumSchema(
NATIVE_PATH_DISPOSITION_VALUES,
'What became of the artifact path the recorder writes to: retirable while it still owes a removal, retired once that removal was verified. ADR 0024 reserves pending.',
),
showTouches: booleanSchema(),
warning: stringSchema(),
overlayWarning: stringSchema(),
chunks: { type: 'array', items: looseObjectSchema() },
},
['recording', 'outPath', 'artifacts', 'durationMs', 'showTouches'],
),
],
},
trace: {
type: 'object',
oneOf: [
objectSchema({ trace: constSchema('started'), outPath: stringSchema() }, [
'trace',
'outPath',
]),
objectSchema(
{
trace: constSchema('stopped'),
outPath: stringSchema(),
artifacts: { type: 'array', items: artifactSchema },
},
['trace', 'outPath', 'artifacts'],
),
],
},
// A family that owns its commands authors their advertised response shape beside the
// command surface and projects it here. This spread stays last: a hand-written entry for
// a projected command then fails as TS2783 instead of quietly overriding the family's,
// and this map's `satisfies` still refuses a missing `CommandResultMap` key.
...REPLAY_COMMAND_OUTPUT_SCHEMAS,
} satisfies Record<keyof CommandResultMap, JsonSchema>;
export const COMMAND_OUTPUT_SCHEMAS = deriveSettleObservationSchemas(BASE_COMMAND_OUTPUT_SCHEMAS);