Repository navigation
Expand file tree
/
Copy pathregistry.ts
More file actions
2108 lines (2017 loc) · 83.4 KB
/
Copy pathregistry.ts
File metadata and controls
2108 lines (2017 loc) · 83.4 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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// The typed-flags request from contracts/, not the daemon's server-side refinement: these
// descriptors read `command`, `positionals` and `flags` and never touch `internal`.
import type { CommandFlags, DispatchedCommand } from '@agent-device/contracts/command';
import type {
RuntimeUseStep,
RuntimeUseStepSelector,
} from '@agent-device/contracts/command-platform-execution';
import type { RefFrameEffect } from '@agent-device/contracts/replay';
import {
checkFindArgs,
isReadOnlyFindAction,
parseFindArgs,
type FindAction,
} from '@agent-device/selectors';
import { resolveWaitBudgetMs } from './wait-positionals.ts';
import {
DEFAULT_TIMEOUT_POLICY,
FOLD_TIMEOUT_POLICY,
INSTALL_REQUEST_TIMEOUT_MS,
LEASE_ALLOCATE_REQUEST_TIMEOUT_MS,
PREPARE_REQUEST_TIMEOUT_MS,
} from './timeout-policy.ts';
import { resolvePostActionObservationSupport } from './post-action-observation.ts';
import type { PostActionObservationSupport } from './post-action-observation.ts';
import type { DaemonCommandDescriptor } from './daemon-command-descriptor.ts';
import {
deployAppUse,
readyMaterializeAndDeployAppUse,
readySendPushNotificationUse,
} from '@agent-device/contracts/app-deployment-runtime-plan';
import {
closeApplicationRuntimePlanUses,
openApplicationRuntimePlanUses,
prepareAppleRunnerRuntimeUse,
runtimeCommandRuntimePlanUses,
} from '@agent-device/contracts/application-lifecycle-runtime-plan';
import { appLogRuntimePlanUses } from '@agent-device/contracts/logs-runtime-plan';
import { audioRuntimePlanUses } from '@agent-device/contracts/audio-runtime-plan';
import { networkDumpUse } from '@agent-device/contracts/network-runtime-plan';
import { inventoryUse } from '@agent-device/contracts/platform-module';
import {
alertRuntimePlanUses,
actionButtonRuntimeUse,
foldRuntimeUse,
appEventRuntimeUse,
appStateRuntimeUses,
appSwitcherRuntimeUse,
appsRuntimeUse,
backRuntimeUse,
clickRuntimeUses,
clipboardRuntimePlanUses,
deviceBootRuntimeUses,
fillRuntimeUses,
findRuntimeIntent,
findRuntimePlanUses,
focusRuntimeUse,
gestureRuntimePlanUses,
gestureViewportRuntimeUse,
homeRuntimeUse,
hoverRuntimeUses,
keyboardRuntimePlanUses,
longPressRuntimeUses,
orientationRuntimeUse,
perfRuntimePlanUses,
pressRuntimeUses,
resolveSelectorCaptureRuntimePlan,
resolveSettingsRuntimePlan,
resolveSnapshotRuntimePlan,
screenshotRuntimePlanUses,
scrollRuntimePlanUses,
selectorCaptureRuntimePlanUses,
selectorTextCaptureRuntimePlanUses,
settingsRuntimePlanUses,
shutdownTargetUse,
snapshotRuntimePlanUses,
swipeRuntimePlanUses,
tapPointUse,
tvRemoteRuntimeUse,
typeTextRuntimeUse,
viewportRuntimeUse,
waitSelectorCaptureRuntimePlanUses,
} from '@agent-device/contracts/platform-runtime-operations';
import { assertRecordRuntimeExecution } from '@agent-device/contracts/record-runtime-execution';
import { screenRecordingRuntimePlanUses } from '@agent-device/contracts/screen-recording-runtime-plan';
import { readDeclaredPlatformExecution } from './platform-execution-entry.ts';
import type {
CommandCatalogGroup,
CommandDescriptor,
CommandFrameworkTier,
DeviceClaimPolicy,
RecordingEffect,
CommandResponseDataTransform,
CommandTimeoutPolicy,
TargetIdentityVerification,
} from './types.ts';
// `platformExecution` stays REQUIRED here (ADR 0019 §6): a raw descriptor that omits it
// is a compile error, and {@link readDeclaredPlatformExecution} is the matching runtime gate.
type RawCommandDescriptorShape<T> = T extends CommandDescriptor
? Omit<T, 'mcpExposed'> & {
mcpExposed?: boolean;
ownerFiles?: readonly [string, ...string[]];
}
: never;
type RawCommandDescriptor = RawCommandDescriptorShape<CommandDescriptor>;
type RawCommandCatalogGroup<T> = T extends { catalog: { group: infer Group } } ? Group : never;
type RawCommandCatalogKey<T> = T extends { catalog: { key: infer Key extends string } }
? Key
: T extends { name: infer Name extends string }
? Name
: never;
export type DescriptorCommandNameForCatalogGroup<Group extends CommandCatalogGroup> =
Extract<(typeof commandDescriptors)[number], { name: string }> extends infer Descriptor
? Descriptor extends { name: infer Name extends string }
? RawCommandCatalogGroup<Descriptor> extends Group
? Name
: never
: never
: never;
export type DescriptorCliCommandName =
| DescriptorCommandNameForCatalogGroup<'public'>
| DescriptorCommandNameForCatalogGroup<'local-cli'>;
export type DescriptorCatalogRecord<Group extends CommandCatalogGroup> = {
readonly [
Descriptor in Extract<
(typeof commandDescriptors)[number],
{ name: string }
> as RawCommandCatalogGroup<Descriptor> extends Group ? RawCommandCatalogKey<Descriptor> : never
]: Descriptor['name'];
};
/**
* The literal union of every command whose `daemon.route` is `'session'`.
* Drives `SESSION_COMMAND_HANDLER_IMPLS` in `src/daemon/handlers/session.ts`: adding a
* session-routed descriptor without a matching handler table entry is a compile error rather
* than a runtime routing gap caught only by `expectHandlerResponse`.
*/
export type DescriptorSessionRouteCommandName =
Extract<
(typeof commandDescriptors)[number],
{ daemon: { route: 'session' } }
> extends infer Descriptor
? Descriptor extends { name: infer Name extends string }
? Name
: never
: never;
/**
* The literal union of every command the daemon routes. A command that never reaches a
* daemon route cannot be the target of a request, so this is the type a caller building
* one must name — an unregistered or CLI-only target is a compile error rather than a
* string the receiver rejects at runtime.
*/
export type DescriptorDaemonRouteCommandName =
Extract<(typeof commandDescriptors)[number], { daemon: object }> extends infer Descriptor
? Descriptor extends { name: infer Name extends string }
? Name
: never
: never;
// ---------------------------------------------------------------------------
// Daemon request-policy trait bundles — copied VERBATIM from
// src/daemon/daemon-command-registry.ts (DAEMON_COMMAND_DESCRIPTORS).
// ---------------------------------------------------------------------------
const ADMISSION_AND_LOCK_EXEMPT = {
leaseAdmissionExempt: true,
sessionExecutionLockExempt: true,
} as const;
const REQUEST_EXECUTION_EXEMPT = {
leaseAdmissionExempt: true,
sessionExecutionLockExempt: true,
selectorValidationExempt: true,
} as const;
const allowAnyDeviceSessionless = (): boolean => true;
const isRecordingStartRequest = (req: DispatchedCommand): boolean =>
(req.positionals?.[0] ?? '').toLowerCase() === 'start';
const isShardedTestRequest = (req: DispatchedCommand): boolean =>
req.command === 'test' &&
(typeof req.flags?.shardAll === 'number' || typeof req.flags?.shardSplit === 'number');
// #2016: a plain `close` (no app-target positional) has nothing to close via
// flags, so it's the only close shape eligible for the sessionless
// no-lease-anywhere admission bypass in request-admission.ts. `close <app>`
// resolves its device straight from flags when there's no session and must
// stay behind full lease/tenant admission.
const resolvePlainCloseLeaseAdmissionExemption = (
req: DispatchedCommand,
): { kind: 'unconditional' } | undefined =>
(req.positionals?.length ?? 0) === 0 ? { kind: 'unconditional' } : undefined;
const resolveDeferredProviderAppCatalogLeaseAdmissionExemption: NonNullable<
DaemonCommandDescriptor['sessionlessLeaseAdmissionExemption']
> = (req) => {
const provider = req.flags?.leaseProvider;
return req.flags?.leaseId === undefined &&
typeof provider === 'string' &&
(req.flags?.platform === 'android' || req.flags?.platform === 'ios')
? { kind: 'provider-app-catalog', provider }
: undefined;
};
// ADR 0014 request-sensitive ref-frame resolvers. The action is the leading
// positional (see keyboard/alert daemon writers in src/commands/system/index.ts
// and src/commands/capture/alert.ts). Only the read-only status probes preserve
// the frame; every mutating subaction crosses a device side effect.
//
// keyboard actions are status/get/dismiss/enter/return (src/commands/system/
// runtime/system.ts): status/get inspect, while dismiss hides the keyboard and
// enter/return dispatch a real return key. Anything other than a read is
// classified may-invalidate (the honest superset for unknown subactions).
const KEYBOARD_READ_ONLY_ACTIONS = new Set(['status', 'get']);
const keyboardRefFrameEffect = (req: DispatchedCommand): RefFrameEffect =>
readOnlySubactionRefFrameEffect(req, KEYBOARD_READ_ONLY_ACTIONS, 'status');
// alert actions are get/wait/accept/dismiss: get/wait read, accept/dismiss act.
const ALERT_READ_ONLY_ACTIONS = new Set(['get', 'wait']);
const alertRefFrameEffect = (req: DispatchedCommand): RefFrameEffect =>
readOnlySubactionRefFrameEffect(req, ALERT_READ_ONLY_ACTIONS, 'get');
const keyboardRecordingEffect = (req: DispatchedCommand): RecordingEffect =>
readOnlySubactionRecordingEffect(req, KEYBOARD_READ_ONLY_ACTIONS, 'status');
const alertRecordingEffect = (req: DispatchedCommand): RecordingEffect =>
readOnlySubactionRecordingEffect(req, ALERT_READ_ONLY_ACTIONS, 'get');
const findRecordingEffect = (req: DispatchedCommand): RecordingEffect => {
try {
return isReadOnlyFindAction(parseFindArgs(req.positionals ?? []).action)
? 'observes-app'
: 'mutates-app';
} catch {
// Invalid requests never record, but classify the unknown shape conservatively.
return 'mutates-app';
}
};
const clipboardRecordingEffect = (req: DispatchedCommand): RecordingEffect =>
readOnlySubactionRecordingEffect(req, new Set(['read']), '');
// A settings request reads only when it names a readable setting with nothing after it; every other
// settings request changes device state — including `settings text-size <category>`, which names the
// same word and performs a mutation. The leg comes from the same resolver the daemon admits with, so
// the classification and the operation it selects are one declaration rather than two that a test
// holds together.
const settingsRequestReads = (req: DispatchedCommand): boolean =>
resolveSettingsRuntimePlan(req.positionals).kind === 'read';
const settingsRecordingEffect = (req: DispatchedCommand): RecordingEffect =>
settingsRequestReads(req) ? 'observes-app' : 'mutates-app';
const settingsRefFrameEffect = (req: DispatchedCommand): RefFrameEffect =>
settingsRequestReads(req) ? 'preserve' : 'may-invalidate';
function readOnlySubactionRefFrameEffect(
req: DispatchedCommand,
readOnlyActions: ReadonlySet<string>,
defaultAction: string,
): RefFrameEffect {
return readOnlyActions.has((req.positionals?.[0] ?? defaultAction).toLowerCase())
? 'preserve'
: 'may-invalidate';
}
function readOnlySubactionRecordingEffect(
req: DispatchedCommand,
readOnlyActions: ReadonlySet<string>,
defaultAction: string,
): RecordingEffect {
return readOnlyActions.has((req.positionals?.[0] ?? defaultAction).toLowerCase())
? 'observes-app'
: 'mutates-app';
}
const NO_PLATFORM_EXECUTION = { kind: 'none' } as const;
// Host-scoped platform work (ADR 0019): the descriptor consumes a neutral typed host service and
// binds no device runtime of its own.
const HOST_PLATFORM_EXECUTION = { kind: 'host' } as const;
/**
* The daemon/recording traits every generic-route mutating command shares. The legacy execution
* pair it was split from (`dispatch`/`capability`) is gone: `scroll` was its last consumer, and
* R53 migrated it, so every generic-route mutating command now spreads this alone.
*/
const GENERIC_MUTATING_COMMAND_TRAITS = {
recordsSessionAction: true,
recordingEffect: 'mutates-app',
deviceClaimPolicy: 'require-owner',
daemon: {
route: 'generic',
refFrameEffect: 'may-invalidate',
androidBlockingDialogGuard: true,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
} as const satisfies Pick<
Extract<CommandDescriptor, { recordsSessionAction: true }>,
| 'recordsSessionAction'
| 'recordingEffect'
| 'deviceClaimPolicy'
| 'daemon'
| 'timeoutPolicy'
| 'batchable'
>;
// click/fill/press/longpress differ only in their timeout budget and response
// shaping: same owner file, same pre-dispatch target identity, same interaction
// route and dialog guard, same device buckets, and the same session-bound claim
// policy. Sharing that here is what keeps them from drifting apart one field at
// a time.
const TARGETED_TOUCH_INTERACTION_TRAITS = {
targetIdentityVerification: 'pre-dispatch',
catalog: { group: 'public' },
recordsSessionAction: true,
recordingEffect: 'mutates-app',
deviceClaimPolicy: 'require-owner',
daemon: {
route: 'interaction',
refFrameEffect: 'may-invalidate',
androidBlockingDialogGuard: true,
},
} as const satisfies Pick<
Extract<CommandDescriptor, { recordsSessionAction: true }>,
| 'targetIdentityVerification'
| 'catalog'
| 'recordsSessionAction'
| 'recordingEffect'
| 'deviceClaimPolicy'
| 'daemon'
>;
// ---------------------------------------------------------------------------
// Timeout policies — descriptor-owned request-envelope budget source and
// on-timeout daemon policy (ADR 0008). This replaces the two deleted client
// hand lists (`isExplicitTimeoutCommand` in daemon-client.ts and
// `DAEMON_PRESERVING_TIMEOUT_COMMANDS` in daemon-client-timeout.ts) plus the
// per-command envelope branches of `resolveDaemonRequestTimeoutMs`.
// ---------------------------------------------------------------------------
// Read-only capture commands that can block in platform accessibility bridges
// while the app is crashed or never idle share snapshot's failure mode. Keep the
// daemon/session alive on their timeouts so callers can still collect
// screenshot/perf/log evidence and close the session after the runner abort
// path has been triggered — resetting the daemon here turned one timed-out wait
// into a lost session for every session the daemon owned.
const PRESERVE_DAEMON_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...DEFAULT_TIMEOUT_POLICY,
onTimeout: 'preserve-daemon',
};
// Installs run long device subprocesses; their envelope stays above the longest
// platform install subprocess timeout (see INSTALL_REQUEST_TIMEOUT_MS).
const INSTALL_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...DEFAULT_TIMEOUT_POLICY,
envelopeMs: INSTALL_REQUEST_TIMEOUT_MS,
};
// Lease-route commands act on billed cloud sessions the daemon owns; resetting
// the daemon on a client timeout would SIGKILL it mid-create/mid-release and
// orphan them all (#1774). Allocation also gets an envelope sized for remote
// device allocation (see LEASE_ALLOCATION_BUDGET_MS).
const LEASE_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...DEFAULT_TIMEOUT_POLICY,
onTimeout: 'preserve-daemon',
};
const LEASE_ALLOCATE_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...LEASE_TIMEOUT_POLICY,
envelopeMs: LEASE_ALLOCATE_REQUEST_TIMEOUT_MS,
};
const DEFAULT_SETTLE_TIMEOUT_MS = 10_000;
// Settle-capable interaction commands also resolve their target through the
// same platform accessibility capture as snapshot/find (#1105): a hung capture
// is their dominant timeout mode, so on top of the --settle flag-sourced
// widening envelope above, keep the daemon (and sessions) alive on timeout too.
const SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...DEFAULT_TIMEOUT_POLICY,
// --settle (#1101) makes --timeout bound the SETTLE wait, not the whole
// request. Widen the envelope by the settle budget so selector/action
// overhead still has room before the post-action wait.
budget: {
source: 'flag',
envelope: 'widen',
defaultBudgetMs: DEFAULT_SETTLE_TIMEOUT_MS,
},
onTimeout: 'preserve-daemon',
};
const TOUCH_INTERACTION_RESPONSE_DATA_TRANSFORM = {
fields: {
count: { defaultValue: 1, omitDefault: true },
intervalMs: { defaultValue: 0, omitDefault: true },
holdMs: { defaultValue: 0, omitDefault: true },
jitterPx: { defaultValue: 0, omitDefault: true },
doubleTap: { defaultValue: false, omitDefault: true },
},
} as const satisfies CommandResponseDataTransform;
const FILL_INTERACTION_RESPONSE_DATA_TRANSFORM = {
fields: {
delayMs: { defaultValue: 0 },
},
} as const satisfies CommandResponseDataTransform;
/**
* A settle-capable command spends its `--timeout` on the post-action wait, so
* the envelope has to widen by that budget wherever the trait is declared —
* interaction route or generic route (#1638). `withoutObservation` is the
* policy the command would carry if the trait were dropped, so removing a
* trait restores the command's own envelope instead of silently leaving it on
* the settle one.
*/
function postActionObservationTimeoutPolicy(
command: string,
withoutObservation: CommandTimeoutPolicy,
): CommandTimeoutPolicy {
return resolvePostActionObservationSupport(command) !== undefined
? SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY
: withoutObservation;
}
function postActionObservation(command: string): PostActionObservationSupport {
const support = resolvePostActionObservationSupport(command);
if (support === undefined) {
throw new Error(`Missing post-action observation descriptor support for ${command}`);
}
return support;
}
/**
* Whether this build carries the descriptors' `ownerFiles` claims. Production defines
* `__OWNER_FILES__` as `false`, so every `ownerFilesEnabled ? { ownerFiles: [...] } : {}` spread
* in the root below folds to nothing and the navigation paths never reach a bundle — which
* `pnpm check:bundle-owner-files` proves over `dist/`.
*/
const ownerFilesEnabled = typeof __OWNER_FILES__ === 'undefined' || __OWNER_FILES__;
// ---------------------------------------------------------------------------
// The command declaration root (ADR 0008). Each entry carries the command identity
// facets plus whichever daemon, batch, MCP, timeout, observation, and
// platform-dispatch traits that command owns. Public catalog identity and the
// non-public dispatch aliases live here too; every view derives from this
// array rather than recreating command-name sets.
// ---------------------------------------------------------------------------
const DEPLOY_APP_COMMAND_DESCRIPTOR = {
deviceClaimPolicy: 'transient-exclusive',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/install.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: true,
recordingEffect: 'mutates-app',
daemon: { route: 'session', refFrameEffect: 'may-invalidate' },
platformExecution: { kind: 'device-runtime', use: deployAppUse },
timeoutPolicy: INSTALL_TIMEOUT_POLICY,
batchable: true,
} as const;
/**
* Plan-time selectors for the commands whose declared alternatives differ in what they execute.
* Each reads the daemon step exactly as its handler will (`flags` and `positionals`; a structured
* `input` only when a caller kept one) and resolves the same plan the handler resolves, for both
* sides of the active-app split the plan cannot know yet.
*/
export const selectSnapshotStepUses: RuntimeUseStepSelector = (step) => {
const customActions =
step.flags?.['snapshotCustomActions'] === true || step.input?.['customActions'] === true;
return [true, false].map(
(hasActiveApp) => resolveSnapshotRuntimePlan({ customActions, hasActiveApp }).use,
);
};
/**
* `find` parses its action from positionals and defaults a missing one to click, so a step the
* handler would not parse as a read-only, focus, or type action keeps every declared alternative
* (fail closed), including a step whose positionals are not there to parse.
*/
export const selectFindStepUses: RuntimeUseStepSelector = (step) => {
const action = findStepAction(step);
if (action === undefined || !plansOwnLeg(action)) return findRuntimePlanUses;
const intent = findRuntimeIntent(action);
return [true, false].map(
(hasActiveApp) => resolveSelectorCaptureRuntimePlan({ hasActiveApp, intent }).use,
);
};
function plansOwnLeg(action: FindAction['kind']): boolean {
return isReadOnlyFindAction(action) || action === 'focus' || action === 'type';
}
function findStepAction(step: RuntimeUseStep): FindAction['kind'] | undefined {
if (step.positionals === undefined) return undefined;
const checked = checkFindArgs(step.positionals, step.flags);
return checked.ok ? checked.parsed.action : undefined;
}
export const RAW_COMMAND_DESCRIPTORS = [
{
name: 'human_control',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled ? { ownerFiles: ['src/daemon/handlers/human-control.ts'] as const } : {}),
catalog: { group: 'internal', key: 'humanControl' },
recordsSessionAction: false,
daemon: {
route: 'humanControl',
refFrameEffect: 'preserve',
selectorValidationExempt: true,
skipSessionlessProviderDevice: allowAnyDeviceSessionless,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
// -- lease (route: lease) --
{
name: 'lease_allocate',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled ? { ownerFiles: ['src/daemon/handlers/lease.ts'] as const } : {}),
catalog: { group: 'internal', key: 'leaseAllocate' },
recordsSessionAction: false,
daemon: {
route: 'lease',
refFrameEffect: 'preserve',
...ADMISSION_AND_LOCK_EXEMPT,
},
timeoutPolicy: LEASE_ALLOCATE_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'lease_heartbeat',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled ? { ownerFiles: ['src/daemon/handlers/lease.ts'] as const } : {}),
catalog: { group: 'internal', key: 'leaseHeartbeat' },
recordsSessionAction: false,
daemon: {
route: 'lease',
refFrameEffect: 'preserve',
...ADMISSION_AND_LOCK_EXEMPT,
},
timeoutPolicy: LEASE_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'lease_release',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled ? { ownerFiles: ['src/daemon/handlers/lease.ts'] as const } : {}),
catalog: { group: 'internal', key: 'leaseRelease' },
recordsSessionAction: false,
daemon: {
route: 'lease',
refFrameEffect: 'preserve',
...ADMISSION_AND_LOCK_EXEMPT,
},
timeoutPolicy: LEASE_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'artifacts',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/artifacts.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'lease',
refFrameEffect: 'preserve',
...ADMISSION_AND_LOCK_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
// -- session (route: session) --
{
name: 'session_list',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled
? { ownerFiles: ['src/daemon/session-lifecycle/internal/inventory.ts'] as const }
: {}),
catalog: { group: 'internal', key: 'sessionList' },
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'inventory',
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'session_save_script',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled
? { ownerFiles: ['src/daemon/handlers/session-script-publication.ts'] as const }
: {}),
catalog: { group: 'internal', key: 'sessionSaveScript' },
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'publication',
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'devices',
deviceClaimPolicy: 'observe',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/device.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'inventory',
lockPolicySelectorOverride: true,
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: { kind: 'inventory', use: inventoryUse },
},
{
name: 'capabilities',
deviceClaimPolicy: 'observe',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/device.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'inventory',
lockPolicySelectorOverride: true,
preferExplicitDeviceOverExistingSession: true,
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
// R63: `capabilities` executes nothing on a device. It reads one side-effect-free facts
// inspection and projects each command's own declared uses against it, so it has no platform
// execution path of its own to migrate — which is what `none` states. It is deliberately last
// among the command units: it projects the union of every migrated command's facts, so it is
// only truthful once that surface is complete.
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'doctor',
deviceClaimPolicy: 'observe',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/doctor.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'inventory',
lockPolicySelectorOverride: true,
allowSessionlessDefaultDevice: allowAnyDeviceSessionless,
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: HOST_PLATFORM_EXECUTION,
},
{
name: 'apps',
deviceClaimPolicy: 'observe',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/app.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'inventory',
lockPolicySelectorOverride: true,
preferExplicitDeviceOverExistingSession: true,
sessionlessLeaseAdmissionExemption: resolveDeferredProviderAppCatalogLeaseAdmissionExemption,
},
platformExecution: { kind: 'device-runtime', uses: [appsRuntimeUse] as const },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'boot',
deviceClaimPolicy: 'transient-exclusive',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/device.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'may-invalidate',
sessionKind: 'state',
},
platformExecution: { kind: 'device-runtime', uses: deviceBootRuntimeUses },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'shutdown',
deviceClaimPolicy: 'transient-exclusive',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/device.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'may-invalidate',
sessionKind: 'state',
},
platformExecution: { kind: 'device-runtime', use: shutdownTargetUse },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'appstate',
deviceClaimPolicy: 'observe',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/system/index.ts'] as const } : {}),
catalog: { group: 'public', key: 'appState' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'state',
},
platformExecution: { kind: 'device-runtime', uses: appStateRuntimeUses },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'perf',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/perf/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: true,
recordingEffect: 'observes-app',
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'observability',
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: { kind: 'device-runtime', uses: perfRuntimePlanUses },
},
{
name: 'logs',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/observability/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'observability',
},
platformExecution: { kind: 'device-runtime', uses: appLogRuntimePlanUses },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'events',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/observability/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'observability',
allowInvalidRecording: true,
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
// Wave 6 residue: `events` flushes and reads the session's own event log. It touches no
// device at all, so it has no platform execution path to migrate.
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'network',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/observability/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'observability',
},
platformExecution: { kind: 'device-runtime', use: networkDumpUse },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'audio',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/observability/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
sessionKind: 'observability',
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: { kind: 'device-runtime', uses: audioRuntimePlanUses },
},
{
name: 'replay',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/replay/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'delegated',
sessionKind: 'replay',
skipSessionlessProviderDevice: isShardedTestRequest,
saveScriptFlagOwner: true,
},
// Replay durations are script-dependent; --timeout bounds the envelope.
timeoutPolicy: { ...DEFAULT_TIMEOUT_POLICY, budget: { source: 'flag' } },
batchable: false,
// Every native and Maestro action re-enters the daemon request pipeline under the delegated
// command descriptor. Maestro viewport reads do the same through `runtime gesture-viewport`,
// so replay owns orchestration but no platform execution of its own.
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'test',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/replay/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'delegated',
sessionKind: 'replay',
skipSessionlessProviderDevice: isShardedTestRequest,
},
// Test runs stream per-scenario progress and are budgeted downstream; no
// client envelope at all.
timeoutPolicy: { ...DEFAULT_TIMEOUT_POLICY, envelopeMs: 'unbounded' },
batchable: true,
// Test is suite orchestration over replay attempts; each attempt delegates its admitted
// operations, including Maestro viewport acquisition, to their own descriptors.
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'runtime',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled
? {
ownerFiles: [
'src/daemon/handlers/session-runtime-command.ts',
'src/daemon/handlers/session-runtime-port-reverse.ts',
] as const,
}
: {}),
catalog: { group: 'internal' },
recordsSessionAction: false,
daemon: { route: 'session', refFrameEffect: 'preserve' },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: {
kind: 'device-runtime',
uses: [...runtimeCommandRuntimePlanUses, gestureViewportRuntimeUse],
},
},
{
name: 'clipboard',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/system/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
// R55 retires this command's capability bucket and its `dispatch` leaf together: admission is
// whichever action-selected fact (`readClipboard`/`writeClipboard`) the parsed subcommand
// names, and the only execution is that one bound operation (ADR 0019 §9).
recordsSessionAction: true,
recordingEffect: clipboardRecordingEffect,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: { kind: 'device-runtime', uses: clipboardRuntimePlanUses },
},
{
name: 'keyboard',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/system/index.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
// R46 retires this command's capability bucket and its `dispatch` leaf together: admission is
// whichever action-selected fact (`keyboardStatus`/`keyboardDismiss`/`keyboardEnter`) the
// parsed action names, and the only execution is that one bound operation (ADR 0019 §9).
recordsSessionAction: true,
recordingEffect: keyboardRecordingEffect,
daemon: {
route: 'session',
refFrameEffect: keyboardRefFrameEffect,
androidBlockingDialogGuard: true,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
platformExecution: { kind: 'device-runtime', uses: keyboardRuntimePlanUses },
},
{
name: 'install',
...DEPLOY_APP_COMMAND_DESCRIPTOR,
},
{
name: 'reinstall',
...DEPLOY_APP_COMMAND_DESCRIPTOR,
},
{
name: 'install_source',
deviceClaimPolicy: 'transient-exclusive',
...(ownerFilesEnabled
? { ownerFiles: ['src/daemon/handlers/session-app-source-deployment.ts'] as const }
: {}),
catalog: { group: 'internal', key: 'installSource' },
recordsSessionAction: true,
recordingEffect: 'mutates-app',
daemon: { route: 'session', refFrameEffect: 'may-invalidate' },
platformExecution: { kind: 'device-runtime', use: readyMaterializeAndDeployAppUse },
timeoutPolicy: INSTALL_TIMEOUT_POLICY,
batchable: false,
},
{
name: 'release_materialized_paths',
deviceClaimPolicy: 'none',
...(ownerFilesEnabled
? { ownerFiles: ['src/daemon/handlers/session-app-source-deployment.ts'] as const }
: {}),
catalog: { group: 'internal', key: 'releaseMaterializedPaths' },
recordsSessionAction: false,
daemon: {
route: 'session',
refFrameEffect: 'preserve',
...REQUEST_EXECUTION_EXEMPT,
},
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: false,
platformExecution: NO_PLATFORM_EXECUTION,
},
{
name: 'push',
deviceClaimPolicy: 'transient-exclusive',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/push.ts'] as const } : {}),
catalog: { group: 'public' },
frameworkTier: 'extended',
recordsSessionAction: true,
recordingEffect: 'mutates-app',
daemon: { route: 'session', refFrameEffect: 'may-invalidate' },
platformExecution: { kind: 'device-runtime', use: readySendPushNotificationUse },
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
batchable: true,
},
{
name: 'trigger-app-event',
deviceClaimPolicy: 'require-owner',
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/management/push.ts'] as const } : {}),
catalog: { group: 'public', key: 'triggerAppEvent' },
frameworkTier: 'extended',
// R57 retires this command's capability bucket and its `dispatch` leaf together: admission is
// the owner's `triggerAppEvent` fact, and the only execution is that one bound operation. The
// event name, payload, and URL template stay daemon policy (ADR 0019 §2 — a facet input names