Repository navigation
Expand file tree
/
Copy pathcommand-types.ts
More file actions
201 lines (182 loc) · 7.74 KB
/
Copy pathcommand-types.ts
File metadata and controls
201 lines (182 loc) · 7.74 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
import type { DaemonWireRequest } from '@agent-device/contracts/command';
import type { ReplayDivergenceResume, ReplayRepairHint } from '@agent-device/contracts/divergence';
import type { GestureExecutionProfile } from '@agent-device/contracts/gesture-plan-types';
import type {
ReplayObservationAuthorityBinder,
ReplayTargetGuardDenotation,
TargetAnnotationV1,
} from '@agent-device/contracts/replay';
import type { SessionAction, SessionScope } from '@agent-device/contracts/session';
import type { SnapshotDiagnosticsState } from '@agent-device/contracts/capture';
import type { ReplayTestAttemptStepSink } from '@agent-device/replay-test';
import type { DaemonResponse, SessionRuntimeHints } from '@agent-device/kernel/contracts';
import type { DeviceInfo } from '@agent-device/kernel/device';
import type { Rect, SnapshotState } from '@agent-device/kernel/snapshot';
/**
* The slice of the daemon's live session record replay reads. The daemon passes its full
* `SessionState`; replay never names the record itself, so the port depends on these fields and
* nothing else the daemon keeps on a session.
*/
export type ReplaySessionState = Readonly<{
name: string;
device: DeviceInfo;
appBundleId?: string;
actions: SessionAction[];
trace?: Readonly<{ outPath: string }>;
/** Read for presence only: an active recording means replay video must not start another. */
screenRecording?: object;
snapshotDiagnostics?: Pick<SnapshotDiagnosticsState, 'samples'>;
}>;
export type ReplaySessionStore = Readonly<{
get: () => ReplaySessionState | undefined;
lookup: () => Readonly<{ address: string; session: ReplaySessionState }> | undefined;
getRuntimeHints: () => SessionRuntimeHints | undefined;
ensureSessionDir: () => string;
/** Rejects the request when its device/platform selectors contradict the session's binding. */
assertSelectorMatches: (flags: DaemonWireRequest['flags']) => void;
/**
* The runtime hints an `open` dispatched from this session would run with: the request's own,
* the session's persisted ones, and the platform defaults the daemon owns.
*/
resolveOpenRuntimeHints: (params: {
request: DaemonWireRequest;
device?: DeviceInfo;
platform?: 'ios' | 'android';
}) => SessionRuntimeHints | undefined;
}>;
/**
* The replay side of the ref-publication owner: the operational capture it reads, a binder for
* the daemon-side authority that records a capture and publishes exactly its own projection, and
* the daemon's snapshot capture over this session. The session-store pair the authority is drawn
* from stays in the daemon.
*/
export type ReplaySessionObservation = Readonly<{
get: () => ReplaySessionState | undefined;
bindAuthority: ReplayObservationAuthorityBinder;
capture: (params: {
flags: DaemonWireRequest['flags'];
logPath: string;
}) => Promise<{ snapshot: SnapshotState }>;
}>;
/** Immutable read projection of the repair-transaction fields the coordinator's writers touch. */
export type ReplaySessionView = Readonly<{
repairBoundary: number | undefined;
pendingRecordAndHeal:
| Readonly<{ expectedFrom: number; actionsCountAtDivergence: number }>
| undefined;
/** The session's script-publication state, as arming reads it: kind, target, persisted force. */
scriptPublication: Readonly<{
kind: 'none' | 'authoring' | 'repair';
status: string | undefined;
targetPath: string | undefined;
targetForce: boolean;
}>;
}>;
export type ReplayResumeStamper = Readonly<{
sessionExists(): boolean;
stampCorrectiveWatermark(params: {
resume: ReplayDivergenceResume;
repairHint: ReplayRepairHint;
failedIndex: number;
actions: SessionAction[];
}): void;
}>;
/**
* The daemon-owned gateway one replay request reaches the repair transaction and the corrective
* resume watermark through. The daemon constructs it over its locked session; replay only calls.
*/
export type ReplayCoordinator = {
view(): ReplaySessionView | undefined;
armStep(params: {
saveScript: boolean | string;
force: boolean | undefined;
sourcePath: string;
firstArm: boolean;
}): void;
demoteForRerunIfArmed(): void;
markCompleteIfArmed(): void;
markSessionHeldIfArmed(response: DaemonResponse): DaemonResponse;
clearTombstone(): void;
clearCorrectiveWatermarkIfExpected(expectedFrom: number | undefined): void;
readonly resumeStamper: ReplayResumeStamper;
};
export type ReplayTestSessionFactory = (sessionName: string, logPath: string) => ReplaySession;
export type ReplaySession = Readonly<{
/** The effective SessionStore key selected by request binding. */
name: string;
logPath: string;
store: ReplaySessionStore;
/** Bound observation reads and writes used by the ref-publication owner and divergence capture. */
observationStore: ReplaySessionObservation;
/** The repair-transaction gateway the daemon bound over this session. */
coordinator: ReplayCoordinator;
}>;
/**
* What a nested dispatch asks the daemon to honor beyond the wire request. Each field names the
* daemon's own request-private key; the daemon folds the bag into the request's private half
* before dispatch, so replay never composes that half itself.
*/
export type ReplayDispatchOptions = Readonly<{
/** Every step a replay plan dispatches; the recorder reads it to classify authored provenance. */
replayPlanStep?: true;
resolvedSessionScope?: SessionScope;
replayTargetGuard?: ReplayTargetGuardDenotation;
replayTargetGuards?: Readonly<{
source: ReplayTargetGuardDenotation;
destination: ReplayTargetGuardDenotation;
}>;
replayLandmarkGuard?: TargetAnnotationV1;
/** Runs before an `open` dispatches; a failure response aborts the dispatch with it. */
openLifecycle?: Readonly<{ beforeDispatch: () => Promise<DaemonResponse | undefined> }>;
closeAppOnly?: boolean;
observationOnly?: true;
gestureViewport?: Rect;
gestureExecutionProfile?: GestureExecutionProfile;
}>;
export type ReplayDispatchRequest = DaemonWireRequest &
Readonly<{ dispatch?: ReplayDispatchOptions }>;
export type ReplayInvoke = (request: ReplayDispatchRequest) => Promise<DaemonResponse>;
/** Daemon policy replay consults but does not own. */
export type ReplayDaemonDependencies = Readonly<{
/** The isolation scope a request opens sessions under. Throws when the request is inadmissible. */
resolveSessionScope: (request: DaemonWireRequest) => SessionScope;
}>;
export type ReplayCommand = Readonly<{
request: DaemonWireRequest;
/**
* True when the request arrived over the daemon's public network surface: flow scripts are then
* untrusted, and `runScript` HTTP calls may not reach private addresses.
*/
publicNetworkOnly?: true;
/** The isolation scope the daemon already resolved for this request, when it did. */
resolvedSessionScope?: SessionScope;
/** Dispatch options every request this command issues carries, before its own. */
dispatch?: ReplayDispatchOptions;
session: ReplaySession;
invoke: ReplayInvoke;
dependencies: ReplayDaemonDependencies;
tracePath?: string;
onStep?: ReplayTestAttemptStepSink;
}>;
type ReplayRequestContext = Readonly<{
token: DaemonWireRequest['token'];
meta: DaemonWireRequest['meta'];
}>;
export type ReplayRecordVideoRequest = Readonly<
{ request: ReplayRequestContext; sessionName: string } & (
| { phase: 'start'; outputPath: string }
| { phase: 'stop' }
)
>;
export type ReplayRecordVideo = (params: ReplayRecordVideoRequest) => Promise<DaemonResponse>;
export type ReplayTestVideoOwner = Readonly<{
record: ReplayRecordVideo;
throwIfCanceled: () => void;
}>;
type ReplayTestSessionCleanup = (sessionName: string) => Promise<void>;
export type ReplayTestCommand = ReplayCommand &
Readonly<{
createSession: ReplayTestSessionFactory;
cleanupSession: ReplayTestSessionCleanup;
video?: ReplayTestVideoOwner;
}>;