Repository navigation
Expand file tree
/
Copy pathgeneric-runtime-execution.ts
More file actions
116 lines (115 loc) · 4.89 KB
/
Copy pathgeneric-runtime-execution.ts
File metadata and controls
116 lines (115 loc) · 4.89 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
import type { ResolvedGenericExecution } from './generic-leaf-execution.ts';
import { resolveBoundFocusRuntime } from './focus-runtime.ts';
import { resolveBoundScrollRuntime } from './scroll-runtime.ts';
import type { ScreenshotRuntimeBindings } from './screenshot-runtime-binding.ts';
import type { DaemonCommandContext } from './context.ts';
import type { DaemonRequest } from './daemon-request.ts';
import type { SessionState } from './session-state.ts';
import { resolveBoundViewportRuntime } from './viewport-runtime.ts';
import { resolveBoundBackRuntime } from './back-runtime.ts';
import { isSystemButtonCommand, resolveBoundSystemButtonRuntime } from './system-button-runtime.ts';
import { resolveBoundOrientationRuntime } from './orientation-runtime.ts';
import { resolveBoundFoldRuntime } from './fold-runtime.ts';
import { resolveBoundTvRemoteRuntime } from './tv-remote-runtime.ts';
import { errorResponse } from '@agent-device/kernel/contracts';
/**
* The generic route's runtime-owned leaves (ADR 0019). Each one admits its own exact owner facts
* and binds once here, before the dispatcher runs, so the dispatcher itself never learns a command
* name.
*
* Every generic-route descriptor is now runtime-owned (R58 retired the last legacy dispatcher), so
* this is total over that route rather than a partial table with a legacy fallback behind it —
* `generic-route-runtime-completeness.test.ts` derives the denominator from the registry and fails
* if a descriptor joins the route without an arm here. The `default` therefore reports a routing
* gap; it is not a second execution path.
*/
export async function resolveGenericRuntimeExecution(
params: Readonly<{
req: DaemonRequest;
session: SessionState;
context: DaemonCommandContext;
}> &
ScreenshotRuntimeBindings,
): Promise<ResolvedGenericExecution> {
if (isSystemButtonCommand(params.req.command)) {
return await resolveBoundSystemButtonRuntime(params.req.command, {
device: params.session.device,
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
}
switch (params.req.command) {
case 'screenshot': {
// This branch alone owns an in-process command surface and the interaction implementations
// beneath it; the other leaves here are bound runtimes the dispatcher reaches directly, so
// only this one's module is deferred out of the daemon's startup closure.
const { resolveScreenshotGenericExecution } = await import('./screenshot-runtime.ts');
return await resolveScreenshotGenericExecution(params);
}
case 'focus':
return await resolveBoundFocusRuntime({
device: params.session.device,
positionals: params.req.positionals ?? [],
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'scroll':
return await resolveBoundScrollRuntime({
device: params.session.device,
positionals: params.req.positionals ?? [],
context: params.context,
// The scroll's own observation is decided here rather than in its execution closure: this is
// the last moment the session's stored tree is still the newest observation, before the
// dispatcher's ADR 0014 side-effect seam.
session: params.session,
flags: params.req.flags,
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'viewport':
return await resolveBoundViewportRuntime({
device: params.session.device,
positionals: params.req.positionals ?? [],
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'back':
return await resolveBoundBackRuntime({
device: params.session.device,
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'orientation':
return await resolveBoundOrientationRuntime({
device: params.session.device,
positionals: params.req.positionals ?? [],
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'fold':
return await resolveBoundFoldRuntime({
keyframes: params.req.flags?.keyframes,
device: params.session.device,
positionals: params.req.positionals ?? [],
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
case 'tv-remote':
return await resolveBoundTvRemoteRuntime({
device: params.session.device,
positionals: params.req.positionals ?? [],
durationMs: params.req.flags?.durationMs,
inspectFacts: params.inspectFacts,
bindDevice: params.bindDevice,
});
default:
return {
ok: false,
response: errorResponse(
'COMMAND_FAILED',
`${params.req.command} has no runtime execution on the generic route`,
{ reason: 'generic-route-runtime-missing' },
),
};
}
}