Skip to content

Commit 7c235bf

Browse files
authored
refactor(mcp): project doctor family output schema from its owning module (#3040)
* refactor(mcp): project doctor family output schema from its owning module Moves the single hand-authored MCP outputSchema entry for doctor out of command-output-schemas.ts into a frozen DOCTOR_COMMAND_OUTPUT_SCHEMAS map exported from src/commands/management/doctor.ts, following the #2810 projection seam already used by the other projected families on this stack. Registers the family in the PROJECTED_FAMILIES disjointness check and adds command-tools-management-doctor-schemas.test.ts with a reference-equality proof against the module object and an owner-file check, matching the pattern from the other projected families. The moved code is byte-identical to what command-output-schemas.ts held: same objectSchema/enumSchema/stringSchema/numberSchema/looseObjectSchema calls and field order. Verified the published outputSchema for doctor is byte-identical to origin/main by dumping COMMAND_OUTPUT_SCHEMAS.doctor as JSON in a temporary detached worktree of origin/main and diffing against this branch's head; both dumps matched byte-for-byte. Part of #2819. * refactor(mcp): merge the doctor family command-input imports
1 parent 7d198b7 commit 7c235bf

4 files changed

Lines changed: 83 additions & 35 deletions

File tree

‎src/commands/management/doctor.ts‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,65 @@
11
import { PUBLIC_COMMANDS } from '@agent-device/command-registry/catalog';
22
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
3-
import * as commandInput from '../command-input.ts';
3+
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
4+
import { DEVICE_TARGETS } from '@agent-device/kernel/device';
5+
import {
6+
booleanField,
7+
enumSchema,
8+
looseObjectSchema,
9+
numberSchema,
10+
objectSchema,
11+
stringField,
12+
stringSchema,
13+
} from '../command-input.ts';
414
import { commonInputFromFlags, direct } from '../cli-grammar/common.ts';
515
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
16+
import type { JsonSchema } from '../command-contract.ts';
617
import { defineCommandFacet } from '../family/types.ts';
718
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
819
import { managementCliOutputFormatters } from './output.ts';
920

21+
/**
22+
* This family's advertised MCP `outputSchema`, keyed by daemon command name and projected into
23+
* the command map by `src/mcp/command-output-schemas.ts`.
24+
*/
25+
export const DOCTOR_COMMAND_OUTPUT_SCHEMAS = {
26+
// packages/contracts/src/doctor.ts
27+
doctor: objectSchema(
28+
{
29+
status: enumSchema(['pass', 'warn', 'fail', 'info']),
30+
summary: stringSchema(),
31+
kind: enumSchema(['auto', 'react-native', 'expo', 'repack']),
32+
platform: stringSchema(),
33+
target: enumSchema(DEVICE_TARGETS),
34+
targetApp: stringSchema(),
35+
metro: objectSchema({ host: stringSchema(), port: numberSchema() }, ['host', 'port']),
36+
checks: {
37+
type: 'array',
38+
items: objectSchema(
39+
{
40+
id: stringSchema(),
41+
status: enumSchema(['pass', 'warn', 'fail', 'info']),
42+
summary: stringSchema(),
43+
hint: stringSchema(),
44+
command: stringSchema(),
45+
evidence: looseObjectSchema(),
46+
},
47+
['id', 'status', 'summary'],
48+
),
49+
},
50+
},
51+
['status', 'summary', 'kind', 'checks'],
52+
),
53+
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'doctor'>;
54+
1055
const doctorCommandMetadata = defineFieldCommandMetadata(
1156
'doctor',
1257
'Diagnose device, app, development-server, and React Native or Expo readiness issues. Returns compact evidence for local inventory, sessions, optional app discovery, toolchains, and server reachability.',
1358
{
14-
targetApp: commandInput.stringField(
59+
targetApp: stringField(
1560
'Installed app package/bundle id or app name to verify without opening a session.',
1661
),
17-
remote: commandInput.booleanField(
18-
'Check remote connection setup instead of local device inventory.',
19-
),
62+
remote: booleanField('Check remote connection setup instead of local device inventory.'),
2063
},
2164
);
2265

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'vitest';
3+
import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files';
4+
import { DOCTOR_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/doctor.ts';
5+
import { COMMAND_OUTPUT_SCHEMAS } from '../command-output-schemas.ts';
6+
7+
const DOCTOR_COMMANDS = Object.keys(DOCTOR_COMMAND_OUTPUT_SCHEMAS) as Array<
8+
keyof typeof DOCTOR_COMMAND_OUTPUT_SCHEMAS
9+
>;
10+
11+
// doctor does not carry the post-action observation trait (#1652): it is a device-runtime
12+
// command, not an interaction command, so the composed map never copies the entry and
13+
// reference equality must hold.
14+
test('MCP doctor family output schemas are the family module entries, not copies', () => {
15+
for (const command of DOCTOR_COMMANDS) {
16+
assert.equal(
17+
COMMAND_OUTPUT_SCHEMAS[command],
18+
DOCTOR_COMMAND_OUTPUT_SCHEMAS[command],
19+
`${command} is not reference-equal to the doctor module's own schema object`,
20+
);
21+
}
22+
});
23+
24+
test('the projected family map declares exactly the commands its module owns', () => {
25+
for (const command of DOCTOR_COMMANDS) {
26+
assert.ok(
27+
ownerFilesForCommand(command).includes('src/commands/management/doctor.ts'),
28+
`${command} projects its output schema from this module but does not name it as its owner`,
29+
);
30+
}
31+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files
55
import { commandSupportsSettleObservation } from '@agent-device/command-registry/registry';
66
import { WAIT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/capture/wait.ts';
77
import { PREPARE_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/prepare.ts';
8+
import { DOCTOR_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/doctor.ts';
89
import { DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/device.ts';
910
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/push.ts';
1011
import { VIEWPORT_COMMAND_OUTPUT_SCHEMAS } from '../../commands/management/viewport.ts';
@@ -81,6 +82,7 @@ const PROJECTED_FAMILIES = [
8182
{ name: 'interaction', schemas: INTERACTION_COMMAND_OUTPUT_SCHEMAS },
8283
{ name: 'capture-wait', schemas: WAIT_COMMAND_OUTPUT_SCHEMAS },
8384
{ name: 'management-prepare', schemas: PREPARE_COMMAND_OUTPUT_SCHEMAS },
85+
{ name: 'management-doctor', schemas: DOCTOR_COMMAND_OUTPUT_SCHEMAS },
8486
{ name: 'management-device', schemas: DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS },
8587
{ name: 'management-push', schemas: PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS },
8688
{ name: 'management-viewport', schemas: VIEWPORT_COMMAND_OUTPUT_SCHEMAS },

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
booleanSchema,
66
constSchema,
77
enumSchema,
8-
looseObjectSchema,
98
numberSchema,
109
objectSchema,
1110
stringArraySchema,
1211
stringSchema,
1312
} from '../commands/command-input.ts';
1413
import { WAIT_COMMAND_OUTPUT_SCHEMAS } from '../commands/capture/wait.ts';
1514
import { PREPARE_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/prepare.ts';
15+
import { DOCTOR_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/doctor.ts';
1616
import { DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/device.ts';
1717
import { PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/push.ts';
1818
import { VIEWPORT_COMMAND_OUTPUT_SCHEMAS } from '../commands/management/viewport.ts';
@@ -23,7 +23,6 @@ import {
2323
import { RECORDING_COMMAND_OUTPUT_SCHEMAS } from '../commands/recording/output-schemas.ts';
2424
import { REPLAY_COMMAND_OUTPUT_SCHEMAS } from '../commands/replay/index.ts';
2525
import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from '../commands/system/index.ts';
26-
import { DEVICE_TARGETS } from '@agent-device/kernel/device';
2726

2827
/**
2928
* Registry of per-command MCP `outputSchema`s, keyed by the daemon command
@@ -184,34 +183,6 @@ const BASE_COMMAND_OUTPUT_SCHEMAS = {
184183
['direction'],
185184
),
186185

187-
// packages/contracts/src/doctor.ts
188-
doctor: objectSchema(
189-
{
190-
status: enumSchema(['pass', 'warn', 'fail', 'info']),
191-
summary: stringSchema(),
192-
kind: enumSchema(['auto', 'react-native', 'expo', 'repack']),
193-
platform: stringSchema(),
194-
target: enumSchema(DEVICE_TARGETS),
195-
targetApp: stringSchema(),
196-
metro: objectSchema({ host: stringSchema(), port: numberSchema() }, ['host', 'port']),
197-
checks: {
198-
type: 'array',
199-
items: objectSchema(
200-
{
201-
id: stringSchema(),
202-
status: enumSchema(['pass', 'warn', 'fail', 'info']),
203-
summary: stringSchema(),
204-
hint: stringSchema(),
205-
command: stringSchema(),
206-
evidence: looseObjectSchema(),
207-
},
208-
['id', 'status', 'summary'],
209-
),
210-
},
211-
},
212-
['status', 'summary', 'kind', 'checks'],
213-
),
214-
215186
// packages/contracts/src/diff.ts — the public Node command accepts snapshot diffs.
216187
diff: objectSchema(
217188
{
@@ -247,6 +218,7 @@ const BASE_COMMAND_OUTPUT_SCHEMAS = {
247218
// and this map's `satisfies` still refuses a missing `CommandResultMap` key.
248219
...WAIT_COMMAND_OUTPUT_SCHEMAS,
249220
...PREPARE_COMMAND_OUTPUT_SCHEMAS,
221+
...DOCTOR_COMMAND_OUTPUT_SCHEMAS,
250222
...DEVICE_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS,
251223
...PUSH_MANAGEMENT_COMMAND_OUTPUT_SCHEMAS,
252224
...VIEWPORT_COMMAND_OUTPUT_SCHEMAS,

0 commit comments

Comments
 (0)