Skip to content

Commit dd27903

Browse files
committed
refactor(mcp): declare shared schema primitives once
1 parent d821710 commit dd27903

4 files changed

Lines changed: 13 additions & 28 deletions

File tree

‎src/commands/command-input.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export function stringSchema(description?: string): JsonSchema {
115115
return { type: 'string', ...(description ? { description } : {}) };
116116
}
117117

118+
export function nullableStringSchema(description?: string): JsonSchema {
119+
return { type: ['string', 'null'], ...(description ? { description } : {}) };
120+
}
121+
118122
export function numberSchema(
119123
description?: string,
120124
options: { min?: number; max?: number } = {},

‎src/commands/interaction/index.ts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import { postActionObservationCliFlags } from '../post-action-observation-gramma
2929
import type { JsonSchema } from '../command-contract.ts';
3030
import {
3131
booleanSchema,
32+
constSchema,
3233
enumSchema,
3334
looseObjectSchema,
35+
nullableStringSchema,
3436
numberSchema,
3537
objectSchema,
3638
stringArraySchema,
@@ -63,19 +65,10 @@ import {
6365
import { interactionCliOutputFormatters } from './output.ts';
6466
import { selectorCliReaders, selectorDaemonWriters } from './selectors.ts';
6567

66-
function constSchema(value: string): JsonSchema {
67-
return { type: 'string', const: value };
68-
}
69-
70-
function nullableStringSchema(description?: string): JsonSchema {
71-
return { type: ['string', 'null'], ...(description ? { description } : {}) };
72-
}
73-
7468
// PostActionSurfaceChange (packages/contracts/src/interaction.ts) — the post-action capture
7569
// describes a different surface than the pre-action baseline (#2438), so no same-surface
76-
// comparison is presented across it. Mirrored in src/mcp/command-output-schemas.ts for the
77-
// generic `--settle` observation, which every family (not only this one) can carry.
78-
const postActionSurfaceChangeSchema: JsonSchema = objectSchema(
70+
// comparison is presented across it.
71+
export const postActionSurfaceChangeSchema: JsonSchema = objectSchema(
7972
{
8073
from: stringSchema('Surface the pre-action baseline described: a host bundle id, or app.'),
8174
to: stringSchema('Surface the post-action capture describes: a host bundle id, or app.'),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const INTERACTION_COMMANDS = Object.keys(INTERACTION_COMMAND_OUTPUT_SCHEMAS) as
1010

1111
// press, click, fill, longpress, and hover carry the post-action observation trait (#1652): the
1212
// composed map grafts a `settle` property onto a COPY, so they are not reference-equal to the
13-
// module's own object. find is read-only and carries no such trait.
13+
// module's own object. find carries no such trait.
1414
const SETTLE_DERIVED_COMMANDS = new Set(['press', 'click', 'fill', 'longpress', 'hover']);
1515

1616
test('MCP interaction family output schemas are the family module entries, not copies', () => {

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
stringArraySchema,
1212
stringSchema,
1313
} from '../commands/command-input.ts';
14-
import { INTERACTION_COMMAND_OUTPUT_SCHEMAS } from '../commands/interaction/index.ts';
14+
import {
15+
INTERACTION_COMMAND_OUTPUT_SCHEMAS,
16+
postActionSurfaceChangeSchema,
17+
} from '../commands/interaction/index.ts';
1518
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../commands/replay/index.ts';
1619
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../commands/system/index.ts';
1720
import { NATIVE_PATH_DISPOSITION_VALUES } from '@agent-device/contracts/recording-native-path';
@@ -60,21 +63,6 @@ const artifactSchema = objectSchema(
6063
['field'],
6164
);
6265

63-
// PostActionSurfaceChange (packages/contracts/src/interaction.ts) — the post-action capture
64-
// describes a different surface than the pre-action baseline (#2438), so no same-surface
65-
// comparison is presented across it. Also mirrored in the interaction family module
66-
// (src/commands/interaction/index.ts), which needs it for its own InteractionEvidence
67-
// projection without importing back into this file.
68-
const postActionSurfaceChangeSchema: JsonSchema = objectSchema(
69-
{
70-
from: stringSchema('Surface the pre-action baseline described: a host bundle id, or app.'),
71-
to: stringSchema('Surface the post-action capture describes: a host bundle id, or app.'),
72-
disclosure: stringSchema('Agent-facing sentence explaining the surface transition.'),
73-
},
74-
['from', 'to', 'disclosure'],
75-
'Present when an in-place system surface (web sign-in or Apple Pay sheet) was presented over the app, or left it.',
76-
);
77-
7866
// SettleObservation (packages/contracts/src/interaction.ts) — opt-in `--settle` settled
7967
// diff observation (#1101).
8068
const settleObservationSchema: JsonSchema = objectSchema(

0 commit comments

Comments
 (0)