Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/design/tool-input-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Tool input validation at the execution boundary

Tool arguments are checked against the declared JSON Schema before execution,
including after global hooks, per-tool hooks, approval rewrites and derived task
observation inputs. Nested properties, array elements, string and numeric bounds,
composition keywords and document-local references are enforced. Draft-07 is the
default dialect; an explicit `$schema` can select draft-2019-09 or draft-2020-12.
Invalid, unsupported, asynchronous or unresolved schemas block the call. Schema
validation never downloads referenced documents.

Existing parameter-name compatibility runs first: for example `timeout_ms` can
satisfy a declared `timeoutMs`, and `file_path` can satisfy a declared `path`.
Validation does not apply JSON Schema defaults, coerce types or remove extra
properties. Extra fields remain accepted unless the tool schema rejects them.
This keeps approval inputs and third-party MCP payloads intact.

SDK `Tool` accepts an optional `inputZodSchema` with a structural synchronous
`safeParse(input)` interface; Moss does not depend on Zod. A successful result
must be `{ success: true, data }`; a rejected result has `success: false`.
Explicit parser normalization such as trimming or coercion is allowed, but the
normalized object must still satisfy the full JSON Schema. A parser must be pure
and idempotent because each execution boundary rechecks input. Moss verifies
idempotence on an isolated copy and blocks a transform that changes a second
time. A thrown or asynchronous parser blocks the call. Parser output that is not
an object also blocks the call.

Errors identify schema rules without copying rejected values, dynamic object
keys, arbitrary parser messages or compiler exception text. Tool implementations
still own device availability, permission checks, state-dependent constraints and
post-condition verification; JSON Schema success does not prove a device action
succeeded.

Run `node scripts/verify/cli.mjs --stage tool-input-schema` for the offline
execution-boundary probe. It is also included in `npm run verify`. The probe uses
no-op implementations and performs no provider requests or device operations.

SDK change: `Tool.inputZodSchema` is an additive optional field. Inputs that
violate previously declared but unenforced JSON Schema constraints now fail
before execution; this is an intentional validation tightening.
91 changes: 78 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"examples": "node scripts/verify/cli.mjs --stage examples"
},
"dependencies": {
"ajv": "8.20.0",
"ajv-formats": "3.0.1",
"ink": "^7.1.1",
"micromatch": "^4.0.8",
"picocolors": "^1.1.1",
Expand Down
3 changes: 3 additions & 0 deletions scripts/verify/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import { stage as loopPruneStage } from './stages/loop-prune.mjs';
import { stage as loopFollowStage } from './stages/loop-follow.mjs';
import { stage as loopCheckTimeoutStage } from './stages/loop-check-timeout.mjs';
import { stage as taskObservationStage } from './stages/task-observation.mjs';
import { stage as toolInputSchemaStage } from './stages/tool-input-schema.mjs';
import { stage as editRecoveryStage } from './stages/edit-recovery.mjs';
import { stage as loopHealthStage } from './stages/loop-health.mjs';
import { stage as runTestsVerdictStage } from './stages/run-tests-verdict.mjs';
Expand Down Expand Up @@ -208,6 +209,7 @@ const STAGES = new Map(
loopFollowStage,
loopCheckTimeoutStage,
taskObservationStage,
toolInputSchemaStage,
editRecoveryStage,
loopHealthStage,
runTestsVerdictStage,
Expand Down Expand Up @@ -251,6 +253,7 @@ const STAGES = new Map(

const ORDER = [...STAGES.keys()];
const FAST_GATE = [
'tool-input-schema',
'edit-recovery',
'static',
'smoke',
Expand Down
22 changes: 22 additions & 0 deletions scripts/verify/stages/tool-input-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import path from 'node:path';
import { captureProcess } from '../lib/proc.mjs';

export const stage = {
name: 'tool-input-schema',
requires: ['build'],
description: 'Recursive tool schemas and optional parsers guard the actual execution boundary',
async run(context) {
const result = await captureProcess(
process.execPath,
[path.join(context.root, 'scripts/verify/tool-input-schema.mjs')],
{ cwd: context.root, env: { ...process.env, MOSS_NO_RDK_DOCS: '1' }, timeoutMs: 30000 }
);
if (result.timedOut || result.status !== 0)
return {
ok: false,
detail: `probe exited ${String(result.status ?? result.signal)}\n${result.stdout}${result.stderr}`,
};
console.log(result.stdout.trim());
return { ok: true };
},
};
Loading
Loading