From 698349d1adc25440e2dab2dba5a63214e005861e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 12 Nov 2026 09:31:57 +0100 Subject: [PATCH 1/4] fix(mcp): accept digest settle results in the interaction output schema The settle digest drops diff.lines and keeps diff.summary plus settle.refs. The advertised output schema still required lines, so MCP clients rejected every press, click, fill, longpress, and hover result requested with settle and responseLevel digest. Guard the class: real daemon output for snapshot, get, settled click, screenshot, and network at default and digest levels must validate against the advertised MCP outputSchema. Co-Authored-By: Claude Opus 5.5 --- .../src/command-output-schemas.ts | 4 +- test/output-economy/mcp-output-schema.test.ts | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/output-economy/mcp-output-schema.test.ts diff --git a/packages/command-surface/src/command-output-schemas.ts b/packages/command-surface/src/command-output-schemas.ts index 080bea4def..f8c092c4f7 100644 --- a/packages/command-surface/src/command-output-schemas.ts +++ b/packages/command-surface/src/command-output-schemas.ts @@ -88,6 +88,8 @@ const settleObservationSchema: JsonSchema = objectSchema( ), lines: { type: 'array', + description: + 'Changed lines. Absent at the digest response level, which keeps summary and settle.refs.', items: objectSchema( { kind: enumSchema(['added', 'removed']), @@ -99,7 +101,7 @@ const settleObservationSchema: JsonSchema = objectSchema( }, truncated: booleanSchema('Lines were capped to the response bound.'), }, - ['summary', 'lines'], + ['summary'], 'Settled diff vs the pre-action tree (changed lines only).', ), tail: { diff --git a/test/output-economy/mcp-output-schema.test.ts b/test/output-economy/mcp-output-schema.test.ts new file mode 100644 index 0000000000..de99f1f91a --- /dev/null +++ b/test/output-economy/mcp-output-schema.test.ts @@ -0,0 +1,43 @@ +import { expect, test } from 'vitest'; +import type { CommandName } from '@agent-device/command-surface'; +import { listCommandTools } from '../../src/mcp/command-tools.ts'; +import { validateAgainstSchema } from '../../src/mcp/__tests__/output-schema-validator.ts'; +import { captureOutputEconomyDaemonResponses } from './daemon-route-fixtures.ts'; + +const daemon = await captureOutputEconomyDaemonResponses(); + +// Real daemon output at each response level, keyed by the command that produced it. +const samples: Array<[string, CommandName, Record]> = [ + ['snapshot default', 'snapshot', daemon.snapshotDefault], + ['snapshot digest', 'snapshot', daemon.snapshotDigest], + ['get default', 'get', daemon.selectorDefault], + ['get digest', 'get', daemon.selectorDigest], + ['settled click default', 'click', daemon.settleDefault], + ['settled click digest', 'click', daemon.settleDigest], + ['settled click tail default', 'click', daemon.settleTailDefault], + ['settled click tail digest', 'click', daemon.settleTailDigest], + ['screenshot default', 'screenshot', daemon.screenshotDefault], + ['screenshot digest', 'screenshot', daemon.screenshotDigest], + ['network default', 'network', daemon.networkDefault], + ['network digest', 'network', daemon.networkDigest], +]; + +const outputSchemas = new Map(listCommandTools().map((tool) => [tool.name, tool.outputSchema])); +// A sample is checked once its tool advertises an outputSchema; untyped tools have nothing to violate. +const typedSamples = samples.flatMap(([label, name, data]) => { + const schema = outputSchemas.get(name); + return schema ? [[label, schema, data] as const] : []; +}); + +test.each(typedSamples)( + '%s validates against the advertised MCP outputSchema', + (_label, schema, data) => { + expect(validateAgainstSchema(data, schema)).toEqual([]); + }, +); + +test('settled interaction output is checked at both response levels', () => { + expect(typedSamples.map(([label]) => label)).toEqual( + expect.arrayContaining(['settled click default', 'settled click digest']), + ); +}); From aacc4c3324fac675418412a5d71e9e6f88ce48de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 12 Nov 2026 10:17:28 +0100 Subject: [PATCH 2/4] docs(mcp): note that output schemas cover every response level Co-Authored-By: Claude Opus 5.5 --- packages/command-surface/src/command-output-schemas.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/command-surface/src/command-output-schemas.ts b/packages/command-surface/src/command-output-schemas.ts index f8c092c4f7..c78c596f15 100644 --- a/packages/command-surface/src/command-output-schemas.ts +++ b/packages/command-surface/src/command-output-schemas.ts @@ -44,7 +44,9 @@ import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from './system/index.ts'; * `cost` object (opted in via `--cost` / `includeCost`) and any other additive * fields ride into `structuredContent` and still validate. * - Accurate, never invented: required-vs-optional, enums, `const` discriminants - * and discriminated-union branches mirror the source contract types. + * and discriminated-union branches mirror the source contract types. One schema + * serves every response level, so a field a digest view drops is optional here + * even when the contract type requires it at the default level. * * The opt-in `--settle` observation (#1101) is not hand-listed per entry: the * base map carries none and `deriveSettleObservationSchemas` grafts it onto From 63d686aba3330ded94abb7d8d413a051400c8add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 12 Nov 2026 10:17:28 +0100 Subject: [PATCH 3/4] fix(test): use collision-free sentinels in the project-config leak check The fixture value run-123 matched the CI temp directory agent-device-test-run-12303, so the test failed whenever the runner's pid started with 123. Unique sentinel values keep the substring match strict. Co-Authored-By: Claude Opus 5.5 --- src/__tests__/cli-config-trust.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/__tests__/cli-config-trust.test.ts b/src/__tests__/cli-config-trust.test.ts index 4fee8a118d..da3007755b 100644 --- a/src/__tests__/cli-config-trust.test.ts +++ b/src/__tests__/cli-config-trust.test.ts @@ -17,11 +17,11 @@ test('project config rejects remote connection fields before daemon dispatch wit path.join(project, 'agent-device.json'), JSON.stringify({ daemonBaseUrl: 'https://daemon.example.test', - daemonAuthToken: 'token-123', + daemonAuthToken: 'leak-sentinel-token', daemonTransport: 'http', - tenant: 'tenant-123', - runId: 'run-123', - leaseId: 'lease-123', + tenant: 'leak-sentinel-tenant', + runId: 'leak-sentinel-run', + leaseId: 'leak-sentinel-lease', platform: 'ios', }), 'utf8', @@ -37,7 +37,7 @@ test('project config rejects remote connection fields before daemon dispatch wit const output = `${result.stdout}\n${result.stderr}`; assert.match(output, /daemonBaseUrl/); assert.match(output, /not allowed in project config file/i); - assert.doesNotMatch(output, /daemon\.example\.test|token-123|tenant-123|run-123|lease-123/); + assert.doesNotMatch(output, /daemon\.example\.test|leak-sentinel/); fs.rmSync(root, { recursive: true, force: true }); }); From 19e5374a04f162fb03aa4cec7472bd59e0117842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 12 Nov 2026 10:39:37 +0100 Subject: [PATCH 4/4] fix(test): tolerate a pid that exits between the liveness check and the kill Killing the probe ends its node --test runner, so the runner could exit between isAlive() and process.kill(), and the test failed with kill ESRCH. Co-Authored-By: Claude Opus 5.5 --- scripts/node-test-tmpdir.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/node-test-tmpdir.test.ts b/scripts/node-test-tmpdir.test.ts index 8a01d83489..9b38fbee6e 100644 --- a/scripts/node-test-tmpdir.test.ts +++ b/scripts/node-test-tmpdir.test.ts @@ -145,7 +145,7 @@ function killLeftovers(evidenceRoot: string): void { const pids = JSON.parse(fs.readFileSync(evidencePath, 'utf8')) as LeftoverPids; for (const pid of [pids.fixture, pids.fixtureChild, pids.tool]) { // pid 0 or a negative pid would address a whole process group. - if (Number.isInteger(pid) && pid > 0 && isAlive(pid)) process.kill(pid, 'SIGKILL'); + if (Number.isInteger(pid) && pid > 0) killIfAlive(pid); } } @@ -553,7 +553,7 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits // Once every consumer is gone — the detached child AND the orphaned node --test chain, // which holds the same TMPDIR — it is an ordinary abandoned directory. - for (const pid of consumersOf(evidence!)) if (isAlive(pid)) process.kill(pid, 'SIGKILL'); + for (const pid of consumersOf(evidence!)) killIfAlive(pid); await waitFor( () => !liveRunDirectoryConsumers().has(path.basename(runDir)), 20_000, @@ -565,9 +565,7 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits ); assert.equal(fs.existsSync(runDir), false, 'with no owner and no consumer it is pruned'); } finally { - for (const pid of evidence ? consumersOf(evidence) : []) { - if (isAlive(pid)) process.kill(pid, 'SIGKILL'); - } + for (const pid of evidence ? consumersOf(evidence) : []) killIfAlive(pid); if (wrapper.child.exitCode === null && wrapper.child.signalCode === null) { wrapper.child.kill('SIGKILL'); } @@ -577,6 +575,16 @@ test('probe starts a long-lived detached child that inherits TMPDIR, then waits } }); +// A pid can exit between a liveness check and the signal (killing a probe ends its runner), so +// "already gone" is the outcome the caller wanted, not an error. +function killIfAlive(pid: number): void { + try { + process.kill(pid, 'SIGKILL'); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw error; + } +} + function isAlive(pid: number): boolean { try { process.kill(pid, 0);