Skip to content

Commit aff1c88

Browse files
committed
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.
1 parent 0aeb0ad commit aff1c88

4 files changed

Lines changed: 79 additions & 30 deletions

File tree

‎src/commands/management/doctor.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
11
import { PUBLIC_COMMANDS } from '@agent-device/command-registry/catalog';
22
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
3+
import type { CommandResultMap } from '@agent-device/command-registry/command-result';
4+
import { DEVICE_TARGETS } from '@agent-device/kernel/device';
35
import * as commandInput from '../command-input.ts';
6+
import {
7+
enumSchema,
8+
looseObjectSchema,
9+
numberSchema,
10+
objectSchema,
11+
stringSchema,
12+
} from '../command-input.ts';
413
import { commonInputFromFlags, direct } from '../cli-grammar/common.ts';
514
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
15+
import type { JsonSchema } from '../command-contract.ts';
616
import { defineCommandFacet } from '../family/types.ts';
717
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
818
import { managementCliOutputFormatters } from './output.ts';
919

20+
/**
21+
* This family's advertised MCP `outputSchema`, keyed by daemon command name and projected into
22+
* the command map by `src/mcp/command-output-schemas.ts`.
23+
*/
24+
export const DOCTOR_COMMAND_OUTPUT_SCHEMAS = {
25+
// packages/contracts/src/doctor.ts
26+
doctor: objectSchema(
27+
{
28+
status: enumSchema(['pass', 'warn', 'fail', 'info']),
29+
summary: stringSchema(),
30+
kind: enumSchema(['auto', 'react-native', 'expo', 'repack']),
31+
platform: stringSchema(),
32+
target: enumSchema(DEVICE_TARGETS),
33+
targetApp: stringSchema(),
34+
metro: objectSchema({ host: stringSchema(), port: numberSchema() }, ['host', 'port']),
35+
checks: {
36+
type: 'array',
37+
items: objectSchema(
38+
{
39+
id: stringSchema(),
40+
status: enumSchema(['pass', 'warn', 'fail', 'info']),
41+
summary: stringSchema(),
42+
hint: stringSchema(),
43+
command: stringSchema(),
44+
evidence: looseObjectSchema(),
45+
},
46+
['id', 'status', 'summary'],
47+
),
48+
},
49+
},
50+
['status', 'summary', 'kind', 'checks'],
51+
),
52+
} satisfies Pick<Record<keyof CommandResultMap, JsonSchema>, 'doctor'>;
53+
1054
const doctorCommandMetadata = defineFieldCommandMetadata(
1155
'doctor',
1256
'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.',
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)