Skip to content

Commit ed6ce2e

Browse files
committed
refactor(mcp): keep recording output schemas out of the CLI eager closure
1 parent 1c5ae11 commit ed6ce2e

6 files changed

Lines changed: 117 additions & 101 deletions

File tree

‎packages/command-registry/src/registry.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,14 @@ export const RAW_COMMAND_DESCRIPTORS = [
12091209
{
12101210
name: 'record',
12111211
deviceClaimPolicy: 'require-owner',
1212-
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/recording/index.ts'] as const } : {}),
1212+
...(ownerFilesEnabled
1213+
? {
1214+
ownerFiles: [
1215+
'src/commands/recording/index.ts',
1216+
'src/commands/recording/output-schemas.ts',
1217+
] as const,
1218+
}
1219+
: {}),
12131220
catalog: { group: 'public' },
12141221
frameworkTier: 'extended',
12151222
recordsSessionAction: true,
@@ -1227,7 +1234,14 @@ export const RAW_COMMAND_DESCRIPTORS = [
12271234
{
12281235
name: 'trace',
12291236
deviceClaimPolicy: 'require-owner',
1230-
...(ownerFilesEnabled ? { ownerFiles: ['src/commands/recording/index.ts'] as const } : {}),
1237+
...(ownerFilesEnabled
1238+
? {
1239+
ownerFiles: [
1240+
'src/commands/recording/index.ts',
1241+
'src/commands/recording/output-schemas.ts',
1242+
] as const,
1243+
}
1244+
: {}),
12311245
catalog: { group: 'public' },
12321246
frameworkTier: 'extended',
12331247
recordsSessionAction: true,

‎src/commands/recording/index.ts‎

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -7,118 +7,23 @@ import {
77
RECORDING_EXPORT_QUALITIES,
88
RECORDING_SCOPE_VALUES,
99
} from '@agent-device/contracts/recording';
10-
import { NATIVE_PATH_DISPOSITION_VALUES } from '@agent-device/contracts/recording-native-path';
11-
import { RECORDER_OBSERVATION_VALUES } from '@agent-device/contracts/recording-stop-observation';
1210
import { AppError } from '@agent-device/kernel/errors';
1311
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
14-
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
1512
import type { FlagKey } from '@agent-device/command-registry/flag-types';
1613
import { commonInputFromFlags, direct, optionalString } from '../cli-grammar/common.ts';
1714
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
18-
import type { JsonSchema } from '../command-contract.ts';
1915
import {
2016
booleanField,
21-
booleanSchema,
22-
constSchema,
2317
enumField,
24-
enumSchema,
2518
integerField,
26-
numberSchema,
27-
objectSchema,
28-
looseObjectSchema,
2919
requiredField,
3020
retiredField,
3121
stringField,
32-
stringSchema,
3322
} from '../command-input.ts';
3423
import { defineCommandFacet, defineCommandFamilyFromFacets } from '../family/types.ts';
3524
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
3625
import { recordingCliOutputFormatters } from './output.ts';
3726

38-
const artifactSchema = objectSchema(
39-
{
40-
field: stringSchema(),
41-
artifactType: stringSchema(),
42-
path: stringSchema(),
43-
localPath: stringSchema(),
44-
fileName: stringSchema(),
45-
},
46-
['field'],
47-
);
48-
49-
/**
50-
* This family's advertised MCP `outputSchema`s, keyed by daemon command name and projected into
51-
* the command map by `src/mcp/command-output-schemas.ts`. Non-strict like every other entry: no
52-
* `additionalProperties: false`, so additive response fields keep validating. Neither command
53-
* carries the post-action observation trait (#1652): both fire-and-report a recording or trace
54-
* lifecycle change, not an interaction, so no settle-graft copy applies here.
55-
*/
56-
export const RECORDING_COMMAND_OUTPUT_SCHEMAS = {
57-
// packages/contracts/src/recording.ts
58-
record: {
59-
type: 'object',
60-
oneOf: [
61-
objectSchema(
62-
{
63-
recording: constSchema('started'),
64-
outPath: stringSchema(),
65-
sessionStateDir: stringSchema(),
66-
recordingBackend: stringSchema(),
67-
recordingScope: stringSchema(),
68-
recordOnlySession: booleanSchema(),
69-
activeSessionApp: looseObjectSchema(),
70-
showTouches: booleanSchema(),
71-
},
72-
['recording', 'outPath', 'sessionStateDir', 'showTouches'],
73-
),
74-
objectSchema(
75-
{
76-
recording: constSchema('stopped'),
77-
outPath: stringSchema(),
78-
telemetryPath: stringSchema(),
79-
artifacts: { type: 'array', items: artifactSchema },
80-
recordingBackend: stringSchema(),
81-
recordingScope: stringSchema(),
82-
recordOnlySession: booleanSchema(),
83-
activeSessionApp: looseObjectSchema(),
84-
durationMs: numberSchema(),
85-
capturedDurationMs: numberSchema(),
86-
recorder: enumSchema(
87-
RECORDER_OBSERVATION_VALUES,
88-
'What the recorder was observed doing when the recording was stopped: confirmed, or lost when the session holding it died. ADR 0024 reserves unconfirmed for the step that gains the probe.',
89-
),
90-
nativePathDisposition: enumSchema(
91-
NATIVE_PATH_DISPOSITION_VALUES,
92-
'What became of the artifact path the recorder writes to: retirable while it still owes a removal, retired once that removal was verified. ADR 0024 reserves pending.',
93-
),
94-
showTouches: booleanSchema(),
95-
warning: stringSchema(),
96-
overlayWarning: stringSchema(),
97-
chunks: { type: 'array', items: looseObjectSchema() },
98-
},
99-
['recording', 'outPath', 'artifacts', 'durationMs', 'showTouches'],
100-
),
101-
],
102-
},
103-
trace: {
104-
type: 'object',
105-
oneOf: [
106-
objectSchema({ trace: constSchema('started'), outPath: stringSchema() }, [
107-
'trace',
108-
'outPath',
109-
]),
110-
objectSchema(
111-
{
112-
trace: constSchema('stopped'),
113-
outPath: stringSchema(),
114-
artifacts: { type: 'array', items: artifactSchema },
115-
},
116-
['trace', 'outPath', 'artifacts'],
117-
),
118-
],
119-
},
120-
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'record' | 'trace'>;
121-
12227
const RECORD_COMMAND_NAME = 'record';
12328
const TRACE_COMMAND_NAME = 'trace';
12429
const RECORDING_ACTION_VALUES = ['start', 'stop'] as const;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { NATIVE_PATH_DISPOSITION_VALUES } from '@agent-device/contracts/recording-native-path';
2+
import { RECORDER_OBSERVATION_VALUES } from '@agent-device/contracts/recording-stop-observation';
3+
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
4+
import type { JsonSchema } from '../command-contract.ts';
5+
import {
6+
booleanSchema,
7+
constSchema,
8+
enumSchema,
9+
looseObjectSchema,
10+
numberSchema,
11+
objectSchema,
12+
stringSchema,
13+
} from '../command-input.ts';
14+
15+
const artifactSchema = objectSchema(
16+
{
17+
field: stringSchema(),
18+
artifactType: stringSchema(),
19+
path: stringSchema(),
20+
localPath: stringSchema(),
21+
fileName: stringSchema(),
22+
},
23+
['field'],
24+
);
25+
26+
/**
27+
* This family's advertised MCP `outputSchema`s, keyed by daemon command name and projected into
28+
* the command map by `src/mcp/command-output-schemas.ts`. Non-strict like every other entry: no
29+
* `additionalProperties: false`, so additive response fields keep validating. Neither command
30+
* carries the post-action observation trait (#1652): both fire-and-report a recording or trace
31+
* lifecycle change, not an interaction, so no settle-graft copy applies here.
32+
*/
33+
export const RECORDING_COMMAND_OUTPUT_SCHEMAS = {
34+
// packages/contracts/src/recording.ts
35+
record: {
36+
type: 'object',
37+
oneOf: [
38+
objectSchema(
39+
{
40+
recording: constSchema('started'),
41+
outPath: stringSchema(),
42+
sessionStateDir: stringSchema(),
43+
recordingBackend: stringSchema(),
44+
recordingScope: stringSchema(),
45+
recordOnlySession: booleanSchema(),
46+
activeSessionApp: looseObjectSchema(),
47+
showTouches: booleanSchema(),
48+
},
49+
['recording', 'outPath', 'sessionStateDir', 'showTouches'],
50+
),
51+
objectSchema(
52+
{
53+
recording: constSchema('stopped'),
54+
outPath: stringSchema(),
55+
telemetryPath: stringSchema(),
56+
artifacts: { type: 'array', items: artifactSchema },
57+
recordingBackend: stringSchema(),
58+
recordingScope: stringSchema(),
59+
recordOnlySession: booleanSchema(),
60+
activeSessionApp: looseObjectSchema(),
61+
durationMs: numberSchema(),
62+
capturedDurationMs: numberSchema(),
63+
recorder: enumSchema(
64+
RECORDER_OBSERVATION_VALUES,
65+
'What the recorder was observed doing when the recording was stopped: confirmed, or lost when the session holding it died. ADR 0024 reserves unconfirmed for the step that gains the probe.',
66+
),
67+
nativePathDisposition: enumSchema(
68+
NATIVE_PATH_DISPOSITION_VALUES,
69+
'What became of the artifact path the recorder writes to: retirable while it still owes a removal, retired once that removal was verified. ADR 0024 reserves pending.',
70+
),
71+
showTouches: booleanSchema(),
72+
warning: stringSchema(),
73+
overlayWarning: stringSchema(),
74+
chunks: { type: 'array', items: looseObjectSchema() },
75+
},
76+
['recording', 'outPath', 'artifacts', 'durationMs', 'showTouches'],
77+
),
78+
],
79+
},
80+
trace: {
81+
type: 'object',
82+
oneOf: [
83+
objectSchema({ trace: constSchema('started'), outPath: stringSchema() }, [
84+
'trace',
85+
'outPath',
86+
]),
87+
objectSchema(
88+
{
89+
trace: constSchema('stopped'),
90+
outPath: stringSchema(),
91+
artifacts: { type: 'array', items: artifactSchema },
92+
},
93+
['trace', 'outPath', 'artifacts'],
94+
),
95+
],
96+
},
97+
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'record' | 'trace'>;

‎src/mcp/__tests__/command-tools-recording-schemas.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert/strict';
22
import { test } from 'vitest';
33
import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files';
4-
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../../commands/recording/index.ts';
4+
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../../commands/recording/output-schemas.ts';
55
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';
66
import { validateAgainstSchema } from './output-schema-validator.ts';
77

@@ -25,7 +25,7 @@ test('MCP recording family output schemas are the family module entries, not cop
2525
test('the projected family map declares exactly the commands its module owns', () => {
2626
for (const command of RECORDING_COMMANDS) {
2727
assert.ok(
28-
ownerFilesForCommand(command).includes('src/commands/recording/index.ts'),
28+
ownerFilesForCommand(command).includes('src/commands/recording/output-schemas.ts'),
2929
`${command} projects its output schema from this module but does not name it as its owner`,
3030
);
3131
}

‎src/mcp/__tests__/command-tools-replay-schemas.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { commandSupportsSettleObservation } from '@agent-device/command-registry
66
import { DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/device.ts';
77
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/push.ts';
88
import { INTERACTION_COMMAND_OUTPUT_SCHEMAS } from '../../commands/interaction/index.ts';
9-
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../../commands/recording/index.ts';
9+
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../../commands/recording/output-schemas.ts';
1010
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../../commands/replay/index.ts';
1111
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../../commands/system/index.ts';
1212
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';

‎src/mcp/command-output-schemas.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
INTERACTION_COMMAND_OUTPUT_SCHEMAS,
1818
postActionSurfaceChangeSchema,
1919
} from '../commands/interaction/index.ts';
20-
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../commands/recording/index.ts';
20+
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../commands/recording/output-schemas.ts';
2121
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../commands/replay/index.ts';
2222
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../commands/system/index.ts';
2323
import { DEVICE_KINDS, DEVICE_TARGETS, PUBLIC_PLATFORMS } from '@agent-device/kernel/device';

0 commit comments

Comments
 (0)