Repository navigation
Expand file tree
/
Copy pathprepare.ts
More file actions
141 lines (132 loc) · 5.54 KB
/
Copy pathprepare.ts
File metadata and controls
141 lines (132 loc) · 5.54 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
import { PUBLIC_COMMANDS } from '@agent-device/command-registry/catalog';
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
import { PUBLIC_PLATFORMS } from '@agent-device/kernel/device';
import {
enumField,
enumSchema,
integerField,
numberSchema,
objectSchema,
requiredField,
stringSchema,
} from '../command-input.ts';
import {
commonInputFromFlags,
direct,
requiredDaemonString,
requiredString,
} from '../cli-grammar/common.ts';
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
import type { JsonSchema } from '../command-contract.ts';
import { defineCommandFacet } from '../family/types.ts';
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
import { managementCliOutputFormatters } from './output.ts';
const PREPARE_ACTION_VALUES = ['ios-runner'] as const;
// Duplicated from packages/kernel/src/device.ts, which exports only the `DeviceKind` type, not
// this value list; importing the published schema back through command-output-schemas.ts would
// cycle, matching the constSchema/DEVICE_KINDS duplication precedent from the other projected
// management families.
const DEVICE_KINDS = ['simulator', 'emulator', 'device'] as const;
function constSchema(value: string): JsonSchema {
return { type: 'string', const: value };
}
/**
* This family's advertised MCP `outputSchema`, keyed by daemon command name and projected into
* the command map by `src/mcp/command-output-schemas.ts`. Non-strict like every other entry: no
* `additionalProperties: false`, so additive response fields keep validating. prepare is not
* MCP-exposed, but the schema stays map-complete with `CommandResultMap`.
*/
export const PREPARE_COMMAND_OUTPUT_SCHEMAS = {
// packages/contracts/src/prepare.ts
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', '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',
],
),
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'prepare'>;
const prepareCommandMetadata = defineFieldCommandMetadata(
'prepare',
'Prepare platform helper infrastructure. ios-runner builds/reuses, starts, and health-checks the XCTest runner so later Apple snapshots and interactions do not pay first-use startup cost. In JSON output, top-level buildMs/connectMs/healthCheckMs are diagnostic fields and may overlap; use timing.additiveParts for additive wall-clock phase totals. In CI, run it after boot/install and before replay/test; if replay/test starts a separate daemon, stop the prepare daemon before replay/test so it does not keep the prepared runner lease. It is not a recovery step for "runner already owned by another agent-device daemon"; stop the owning daemon on the Mac with simulator access instead. Runner build/start output is written to the session runner.log; daemon.log is for daemon lifecycle/startup issues.',
{
action: requiredField(enumField(PREPARE_ACTION_VALUES)),
timeoutMs: integerField('Maximum wall-clock time for the prepare command.'),
},
);
const prepareCliSchema = {
usageOverride: 'prepare ios-runner --platform ios|macos',
listUsageOverride: 'prepare',
positionalArgs: ['ios-runner'],
allowedFlags: ['timeoutMs'],
} as const satisfies CommandSchemaOverride;
const prepareCliReader: CliReader = (positionals, flags) => ({
...commonInputFromFlags(flags),
action: requiredString(positionals[0], 'prepare requires subcommand'),
timeoutMs: flags.timeoutMs,
});
const prepareDaemonWriter: DaemonWriter = direct(PUBLIC_COMMANDS.prepare, (input) => [
requiredDaemonString(input.action, 'prepare requires subcommand'),
]);
export const prepareCommandFacet = defineCommandFacet({
name: 'prepare',
text: {
summary: 'Pre-warm platform helpers before automation',
},
metadata: prepareCommandMetadata,
run: (client, input) => client.command.prepare(input),
cliSchema: prepareCliSchema,
cliReader: prepareCliReader,
daemonWriter: prepareDaemonWriter,
cliOutputFormatter: managementCliOutputFormatters.prepare,
});