Skip to content

Commit 37b9ead

Browse files
committed
fix: derive wire projection from command descriptors
1 parent 555ee94 commit 37b9ead

7 files changed

Lines changed: 95 additions & 75 deletions

File tree

‎src/commands/command-input.ts‎

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import {
1010
type DeviceTarget,
1111
type PlatformSelector,
1212
} from '../kernel/device.ts';
13-
import {
14-
INTERACTION_REPEAT_WIRE_ECHO_FIELDS,
15-
type WireEchoOptions,
16-
} from '../core/interaction-wire-projection.ts';
1713
import type { JsonSchema } from './command-contract.ts';
1814
import { AppError } from '../kernel/errors.ts';
1915

@@ -131,7 +127,6 @@ export type CommandField<T> = {
131127
schema: JsonSchema;
132128
required: boolean;
133129
read: FieldReader<T>;
134-
wireEcho?: WireEchoOptions;
135130
};
136131

137132
export type CommandFieldMap = Record<string, CommandField<unknown>>;
@@ -159,19 +154,6 @@ export function requiredField<T>(
159154
};
160155
}
161156

162-
export function wireEchoField<T>(
163-
field: CommandField<T>,
164-
options: WireEchoOptions = {},
165-
): CommandField<T> {
166-
return {
167-
...field,
168-
wireEcho: {
169-
mode: options.mode ?? 'always',
170-
...(Object.hasOwn(options, 'defaultValue') ? { defaultValue: options.defaultValue } : {}),
171-
},
172-
};
173-
}
174-
175157
export function stringField(description?: string): CommandField<string> {
176158
return optionalField(stringSchema(description), optionalString);
177159
}
@@ -249,24 +231,11 @@ export function selectorSnapshotFields() {
249231

250232
export function repeatedFields() {
251233
return {
252-
count: wireEchoField(integerField('Number of press/click repetitions.', { min: 1 }), {
253-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS.count,
254-
}),
255-
intervalMs: wireEchoField(
256-
integerField('Delay between repeated press/click actions.', { min: 0 }),
257-
{
258-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS.intervalMs,
259-
},
260-
),
261-
holdMs: wireEchoField(integerField('Hold duration for each action.', { min: 0 }), {
262-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS.holdMs,
263-
}),
264-
jitterPx: wireEchoField(integerField('Randomization radius in pixels.', { min: 0 }), {
265-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS.jitterPx,
266-
}),
267-
doubleTap: wireEchoField(booleanField('Request a double-tap action.'), {
268-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS.doubleTap,
269-
}),
234+
count: integerField('Number of press/click repetitions.', { min: 1 }),
235+
intervalMs: integerField('Delay between repeated press/click actions.', { min: 0 }),
236+
holdMs: integerField('Hold duration for each action.', { min: 0 }),
237+
jitterPx: integerField('Randomization radius in pixels.', { min: 0 }),
238+
doubleTap: booleanField('Request a double-tap action.'),
270239
};
271240
}
272241

‎src/commands/interaction/metadata.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
requiredNumber,
2121
selectorSnapshotFields,
2222
stringField,
23-
wireEchoField,
2423
type CommandFieldMap,
2524
type CommonCommandInput,
2625
type InferCommandInput,
@@ -43,7 +42,6 @@ import {
4342
commandSupportsVerifyEvidence,
4443
} from '../../core/command-descriptor/registry.ts';
4544
import type { PostActionObservationSupportFor } from '../../core/command-descriptor/post-action-observation.ts';
46-
import { FILL_DELAY_WIRE_ECHO } from '../../core/interaction-wire-projection.ts';
4745

4846
const FIND_ACTION_VALUES = [
4947
'click',
@@ -122,9 +120,7 @@ const pressFields = {
122120
const fillFields = {
123121
target: requiredField(interactionTargetField()),
124122
text: requiredField(stringField('Text to enter into the target.')),
125-
delayMs: wireEchoField(integerField('Delay between typed characters.', { min: 0 }), {
126-
...FILL_DELAY_WIRE_ECHO,
127-
}),
123+
delayMs: integerField('Delay between typed characters.', { min: 0 }),
128124
...selectorSnapshotFields(),
129125
...postActionObservationFields('fill'),
130126
};

‎src/core/__tests__/interaction-wire-projection.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@ import {
33
interactionWireEchoFromInput,
44
projectInteractionWireData,
55
} from '../interaction-wire-projection.ts';
6+
import { resolveCommandWireProjection } from '../command-descriptor/registry.ts';
67

78
describe('interaction wire projection', () => {
9+
test('reads command-owned wire echo specs from descriptors', () => {
10+
expect(resolveCommandWireProjection('press')?.wireEcho).toEqual({
11+
count: { defaultValue: 1, mode: 'omit-default' },
12+
intervalMs: { defaultValue: 0, mode: 'omit-default' },
13+
holdMs: { defaultValue: 0, mode: 'omit-default' },
14+
jitterPx: { defaultValue: 0, mode: 'omit-default' },
15+
doubleTap: { defaultValue: false, mode: 'omit-default' },
16+
});
17+
expect(resolveCommandWireProjection('fill')?.wireEcho.delayMs).toEqual({ defaultValue: 0 });
18+
expect(resolveCommandWireProjection('longpress')).toBeUndefined();
19+
});
20+
821
test('omits default press repeat values', () => {
922
expect(
1023
interactionWireEchoFromInput('press', {

‎src/core/command-descriptor/registry.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
import type { CommandCapability } from '../capabilities.ts';
88
import type { DaemonRequest } from '../../daemon/types.ts';
99
import { resolveWaitBudgetMs } from '../wait-positionals.ts';
10+
import {
11+
FILL_DELAY_WIRE_ECHO,
12+
INTERACTION_REPEAT_WIRE_ECHO_FIELDS,
13+
type CommandWireProjection,
14+
} from '../interaction-wire-echo.ts';
1015
import {
1116
DEFAULT_TIMEOUT_POLICY,
1217
INSTALL_REQUEST_TIMEOUT_MS,
@@ -125,6 +130,19 @@ const SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY: CommandTimeoutPolicy = {
125130
onTimeout: 'preserve-daemon',
126131
};
127132

133+
const TOUCH_INTERACTION_WIRE_PROJECTION = {
134+
wireEcho: {
135+
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS,
136+
},
137+
} as const satisfies CommandWireProjection;
138+
139+
const FILL_INTERACTION_WIRE_PROJECTION = {
140+
wireEcho: {
141+
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS,
142+
delayMs: FILL_DELAY_WIRE_ECHO,
143+
},
144+
} as const satisfies CommandWireProjection;
145+
128146
function interactionTimeoutPolicy(command: string): CommandTimeoutPolicy {
129147
return resolvePostActionObservationSupport(command) !== undefined
130148
? SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY
@@ -516,6 +534,7 @@ const RAW_COMMAND_DESCRIPTORS = [
516534
capability: { apple: APPLE_SIM_AND_DEVICE, android: ANDROID_ALL, linux: LINUX_DEVICE },
517535
timeoutPolicy: interactionTimeoutPolicy(PUBLIC_COMMANDS.click),
518536
postActionObservation: postActionObservation(PUBLIC_COMMANDS.click),
537+
wireProjection: TOUCH_INTERACTION_WIRE_PROJECTION,
519538
batchable: true,
520539
},
521540
{
@@ -524,6 +543,7 @@ const RAW_COMMAND_DESCRIPTORS = [
524543
capability: { apple: APPLE_SIM_AND_DEVICE, android: ANDROID_ALL, linux: LINUX_DEVICE },
525544
timeoutPolicy: interactionTimeoutPolicy(PUBLIC_COMMANDS.fill),
526545
postActionObservation: postActionObservation(PUBLIC_COMMANDS.fill),
546+
wireProjection: FILL_INTERACTION_WIRE_PROJECTION,
527547
batchable: true,
528548
},
529549
{
@@ -540,6 +560,7 @@ const RAW_COMMAND_DESCRIPTORS = [
540560
capability: { apple: APPLE_SIM_AND_DEVICE, android: ANDROID_ALL, linux: LINUX_DEVICE },
541561
timeoutPolicy: interactionTimeoutPolicy(PUBLIC_COMMANDS.press),
542562
postActionObservation: postActionObservation(PUBLIC_COMMANDS.press),
563+
wireProjection: TOUCH_INTERACTION_WIRE_PROJECTION,
543564
batchable: true,
544565
},
545566
{
@@ -775,6 +796,12 @@ const TIMEOUT_POLICY_BY_COMMAND: ReadonlyMap<string, CommandTimeoutPolicy> = new
775796
commandDescriptors.map((descriptor) => [descriptor.name, descriptor.timeoutPolicy]),
776797
);
777798

799+
const WIRE_PROJECTION_BY_COMMAND: ReadonlyMap<string, CommandWireProjection> = new Map(
800+
Array.from(COMMAND_DESCRIPTOR_BY_NAME.values()).flatMap((descriptor) =>
801+
descriptor.wireProjection ? [[descriptor.name, descriptor.wireProjection] as const] : [],
802+
),
803+
);
804+
778805
export function resolveCommandPostActionObservationSupport(
779806
command: string | undefined,
780807
): PostActionObservationSupport | undefined {
@@ -800,3 +827,10 @@ export function resolveCommandTimeoutPolicy(command: string | undefined): Comman
800827
if (command === undefined) return DEFAULT_TIMEOUT_POLICY;
801828
return TIMEOUT_POLICY_BY_COMMAND.get(command) ?? DEFAULT_TIMEOUT_POLICY;
802829
}
830+
831+
export function resolveCommandWireProjection(
832+
command: string | undefined,
833+
): CommandWireProjection | undefined {
834+
if (command === undefined) return undefined;
835+
return WIRE_PROJECTION_BY_COMMAND.get(command);
836+
}

‎src/core/command-descriptor/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CommandCapability } from '../capabilities.ts';
2+
import type { CommandWireProjection } from '../interaction-wire-echo.ts';
23
import type { DaemonCommandDescriptor } from '../../daemon/daemon-command-registry.ts';
34
import type { PostActionObservationSupport } from './post-action-observation.ts';
45

@@ -81,6 +82,9 @@ export type CommandTimeoutPolicy = {
8182
* commands that support `--settle`/`--verify`; consumed by
8283
* command surfaces and timeout policy instead of repeated
8384
* command-name lists.
85+
* - `wireProjection` — optional response projection metadata for command-owned
86+
* echoes in daemon responses. This keeps response shaping on
87+
* the same descriptor surface as other command traits.
8488
*
8589
* The registry started dormant (proven byte-equal to the hand tables by the
8690
* parity tests) and is now the live source: the daemon registry, capability
@@ -95,4 +99,5 @@ export type CommandDescriptor = {
9599
mcpExposed: boolean;
96100
timeoutPolicy: CommandTimeoutPolicy;
97101
postActionObservation?: PostActionObservationSupport;
102+
wireProjection?: CommandWireProjection;
98103
};

‎src/core/interaction-wire-echo.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type WireEchoMode = 'always' | 'omit-default';
2+
3+
export type WireEchoOptions = {
4+
defaultValue?: unknown;
5+
mode?: WireEchoMode;
6+
};
7+
8+
export type CommandWireProjection = {
9+
wireEcho: Record<string, WireEchoOptions>;
10+
};
11+
12+
export const INTERACTION_REPEAT_WIRE_ECHO_FIELDS = {
13+
count: { defaultValue: 1, mode: 'omit-default' },
14+
intervalMs: { defaultValue: 0, mode: 'omit-default' },
15+
holdMs: { defaultValue: 0, mode: 'omit-default' },
16+
jitterPx: { defaultValue: 0, mode: 'omit-default' },
17+
doubleTap: { defaultValue: false, mode: 'omit-default' },
18+
} as const satisfies Record<string, WireEchoOptions>;
19+
20+
export const FILL_DELAY_WIRE_ECHO = {
21+
defaultValue: 0,
22+
} as const satisfies WireEchoOptions;

‎src/core/interaction-wire-projection.ts‎

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,31 @@
1-
export type WireEchoMode = 'always' | 'omit-default';
1+
import { resolveCommandWireProjection } from './command-descriptor/registry.ts';
2+
import type { WireEchoOptions } from './interaction-wire-echo.ts';
23

3-
export type WireEchoOptions = {
4-
defaultValue?: unknown;
5-
mode?: WireEchoMode;
6-
};
7-
8-
export const INTERACTION_REPEAT_WIRE_ECHO_FIELDS = {
9-
count: { defaultValue: 1, mode: 'omit-default' },
10-
intervalMs: { defaultValue: 0, mode: 'omit-default' },
11-
holdMs: { defaultValue: 0, mode: 'omit-default' },
12-
jitterPx: { defaultValue: 0, mode: 'omit-default' },
13-
doubleTap: { defaultValue: false, mode: 'omit-default' },
14-
} as const satisfies Record<string, WireEchoOptions>;
15-
16-
export const FILL_DELAY_WIRE_ECHO = {
17-
defaultValue: 0,
18-
} as const satisfies WireEchoOptions;
19-
20-
const TOUCH_WIRE_ECHO_FIELDS = {
21-
...INTERACTION_REPEAT_WIRE_ECHO_FIELDS,
22-
} as const satisfies Record<string, WireEchoOptions>;
23-
24-
const INTERACTION_WIRE_ECHO_FIELDS = {
25-
click: TOUCH_WIRE_ECHO_FIELDS,
26-
press: TOUCH_WIRE_ECHO_FIELDS,
27-
fill: {
28-
...TOUCH_WIRE_ECHO_FIELDS,
29-
delayMs: FILL_DELAY_WIRE_ECHO,
30-
},
31-
} as const satisfies Record<string, Record<string, WireEchoOptions>>;
32-
33-
export type InteractionWireEchoCommand = keyof typeof INTERACTION_WIRE_ECHO_FIELDS;
4+
export type InteractionWireEchoCommand = 'click' | 'press' | 'fill';
345

356
export function interactionWireEchoFromInput(
367
command: InteractionWireEchoCommand,
378
input: Record<string, unknown> | undefined,
389
): Record<string, unknown> {
39-
return projectWireEchoSpecsFromInput(INTERACTION_WIRE_ECHO_FIELDS[command], input ?? {});
10+
return projectWireEchoSpecsFromInput(readCommandWireEchoSpecs(command), input ?? {});
4011
}
4112

4213
export function projectInteractionWireData(
4314
command: InteractionWireEchoCommand,
4415
input: Record<string, unknown> | undefined,
4516
base: Record<string, unknown> | undefined,
4617
): Record<string, unknown> {
47-
return projectWireEchoSpecsFromInput(INTERACTION_WIRE_ECHO_FIELDS[command], input ?? {}, base);
18+
return projectWireEchoSpecsFromInput(readCommandWireEchoSpecs(command), input ?? {}, base);
19+
}
20+
21+
function readCommandWireEchoSpecs(
22+
command: InteractionWireEchoCommand,
23+
): Record<string, WireEchoOptions> {
24+
const projection = resolveCommandWireProjection(command);
25+
if (!projection) {
26+
throw new Error(`Missing wire projection descriptor for ${command}`);
27+
}
28+
return projection.wireEcho;
4829
}
4930

5031
function projectWireEchoSpecsFromInput(

0 commit comments

Comments
 (0)