Contract Validation Skill
Validates agent input and output contracts using the Contract-First design pattern. Every OMT agent has a contract in contracts/<agent-name>.json that defines required inputs, outputs, and validation rules.
Core Concepts
Agent Contract Structure
Every agent must define:
- •Input Contract: What the agent needs to start (sources, required fields, validation rules)
- •Output Contract: What the agent must produce (required fields, destinations)
- •Validation Rules: How to verify correctness (see
references/validation-rules.md)
Contract Validation Flow
1. Read agent contract: contracts/<agent-name>.json 2. Gather input data from contract's source locations 3. Validate input contract 4. Execute agent logic 5. Validate output contract 6. Update state.json with results
How to Validate
Step 1: Read the Contract
Use the Read tool to load the agent's contract definition:
Read contracts/dev.json
The contract specifies input_contract.source — a list of file paths to gather input from.
Step 2: Validate Input Before Execution
Before starting agent work:
- •
Gather input data — For each source in
input_contract.source, use the Read tool to check the file exists and has content:- •Read
outputs/pm.md(requirements from @pm) - •Read
outputs/arch.md(architecture from @arch) - •Use Glob to find existing files matching patterns (e.g.,
tests/**/*.test.ts)
- •Read
- •
Check required fields — For each field in
input_contract.required:- •Verify the data exists and is not empty
- •Apply validation rules (e.g.,
fileExists,minLength:N) - •If any required field fails: stop and report errors
- •
Record validation — Use
ContractValidator.validateInput()fromlib/contract-validator.tsand log the result.
Step 3: Validate Output After Execution
After completing agent work:
- •
Collect output data — Gather all outputs specified in
output_contract.required:- •Use Glob to list created files (e.g.,
tests/**/*.test.ts,src/**/*.ts) - •Capture execution results (e.g., test status: "15/15 passed")
- •Use Glob to list created files (e.g.,
- •
Check output requirements — For each field in
output_contract.required:- •Verify data exists and meets validation rules
- •Check arrays have minimum items (
minItems:N) - •Check strings match patterns (
pattern:REGEX)
- •
Update state — Use
StateManager.recordExecutionAgent()fromlib/state-manager.tsto record results in.agents/state.json.
Example: Dev Agent Contract
The contracts/dev.json contract defines:
Input (from @pm and @arch):
- •
requirements— Requirements document (outputs/pm.md, validation:fileExists) - •
architecture— Architecture design (outputs/arch.md, validation:fileExists) - •
existing_tests— Optional existing test files
Output (to tests/, src/, outputs/dev.md):
- •
test_files— Created test files (validation:minItems:1) - •
implementation_files— Modified source files (validation:minItems:1) - •
tests_status— Test execution status (validation:pattern:^\d+/\d+ passed$)
References
- •Validation rules and contract schema:
references/validation-rules.md - •Patterns, debugging, and complete examples:
references/patterns-and-examples.md - •Contract definitions:
contracts/pm.json,contracts/arch.json,contracts/dev.json - •Runtime libraries:
lib/contract-validator.ts,lib/state-manager.ts