| name | harness-synthesizer |
| description | Synthesize code harnesses for agent action validation โ AutoHarness-inspired verifier/filter/policy generation |
| scope | core |
| version | 1.0.0 |
| user-invocable | true |
| argument-hint | [--mode verifier|filter|policy] [--agent <name>] [--dry-run] |
| effort | high |
Harness Synthesizer Skill
Purpose
Synthesize executable validation harnesses for agent tool calls, inspired by AutoHarness (Google DeepMind, arxiv 2603.03329). Generates code-level verifiers that check action validity before or after execution, reducing agent errors through structured constraint enforcement.
Default mode is advisory (verifier). Hard enforcement requires explicit --hard-enforce opt-in per R021.
Three Modes
| Mode | Flag | Behavior | Enforcement |
|---|
verifier | default | Post-hoc check: validates tool call results after execution | Advisory only |
filter | --mode filter | Pre-execution check: blocks invalid tool calls | Opt-in, requires --hard-enforce |
policy | --mode policy | Suggests the best valid action from available options | Advisory only |
Verifier Mode (Default)
Generates a YAML harness that describes post-execution checks for each tool the agent uses. Checks are emitted as advisory warnings โ they do not block execution.
harness:
agent: lang-golang-expert
mode: verifier
rules:
- tool: Write
checks:
- field: file_path
pattern: ".*\\.go$"
on_fail: warn
- field: content
must_not_contain: "TODO:"
on_fail: warn
- tool: Bash
checks:
- command_pattern: "^(go build|go test|go fmt|go vet)"
on_fail: warn
Filter Mode (Opt-in)
Generates pre-execution filter rules. Requires --hard-enforce flag. Used when advisory warnings are insufficient and the risk of invalid actions is high.
harness:
agent: mgr-gitnerd
mode: filter
enforcement: hard
rules:
- tool: Bash
blocks:
- pattern: "git push --force"
reason: "Force push to protected branch"
- pattern: "git reset --hard"
reason: "Destructive reset without confirmation"
Policy Mode
Generates a policy function that ranks valid actions and suggests the best one. Useful for agents with multiple valid paths to the same goal.
harness:
agent: qa-engineer
mode: policy
policies:
- scenario: "test file modification"
preferred_sequence:
- tool: Read
reason: "Read before modifying"
- tool: Edit
reason: "Edit is safer than Write for existing files"
avoid:
- tool: Write
on_existing_file: true
reason: "Overwrites without diff"
Workflow
- Read target agent frontmatter โ extract
tools, domain, limitations fields
- Analyze recent tool call patterns โ check
.claude/outputs/ for prior session logs (if available)
Tool: Writing artifacts under .claude/outputs/
Under mode: "bypassPermissions", direct Write/Edit/Bash on .claude/** paths (including .claude/outputs/sessions/) is permitted (CC v2.1.121+, #1101) โ no /tmp wrapping is needed.
Write harness-synthesizer results directly to .claude/outputs/sessions/$(date +%Y-%m-%d)/harness-synthesizer-$(date +%H%M%S).md. Read-only Bash on .claude/outputs/ (e.g., cat, head, wc) is allowed for verification. Catastrophic shell operations (e.g., rm -rf /) remain blocked by independent safety guards. For CC < v2.1.121, see git history for the legacy /tmp/*.sh bypass pattern.
Reference: R006 Sensitive Path Handling, R010 Universal bypassPermissions, #1101.
- Synthesize validation harness โ generate YAML harness matching agent's declared capabilities
- Refine via evaluator-optimizer loop โ iterate harness against edge cases (3 rounds max)
- Save output โ write to
.claude/outputs/harnesses/{agent-name}-{mode}.yaml
- Report โ print harness summary and integration instructions
Integration
| System | How |
|---|
action-validator | Harness output feeds into action-validator's code-verified mode |
adaptive-harness --learn | Auto-triggers harness-synthesizer for project-specific patterns |
evaluator-optimizer | Provides iterative refinement loop (gradient-free optimization) |
pipeline-guards | Harness checks usable as pipeline quality gates |
Usage Examples
/harness-synthesizer --agent lang-golang-expert --mode verifier
/harness-synthesizer --agent mgr-gitnerd --mode filter --dry-run
/harness-synthesizer --agent mgr-gitnerd --mode filter --hard-enforce
/harness-synthesizer --agent qa-engineer --mode policy
R021 Compliance
- Default
verifier mode: advisory only โ never blocks tool execution
filter mode without --hard-enforce: advisory only โ emits warnings
filter --hard-enforce: opt-in hard enforcement โ requires explicit user flag
- All harness output is saved to
.claude/outputs/harnesses/ (git-untracked)
Output Format
Harnesses are saved as YAML at .claude/outputs/harnesses/{agent-name}-{mode}.yaml. Each harness includes:
harness:
agent: {agent-name}
mode: verifier | filter | policy
version: 1.0.0
generated: {ISO-8601 timestamp}
enforcement: advisory | hard
rules: [...]
2-Stage Isolation Example (v0.108.0 via #986)
Source: #986 (Deep Insight Part 3 ํ์, guides/harness-engineering/ Section 3 ํ์ฅ)
harness ์์ฑ ์ ๊ฒฉ๋ฆฌ ์์ค์ ๋จ๊ณ์ ์ผ๋ก ์ ์ฉํ๋ 2-Stage Isolation ํจํด ๊ตฌ์ฒด ์์.
Stage 1 โ Base64 Encoding (input isolation)
์์ด์ ํธ ์์
์
๋ ฅ (ํนํ ์ธ๋ถ ์์ค์์ ์จ ๋ฐ์ดํฐ)์ ์ง์ shell/Python ์ปจํ
์คํธ์ ์ฃผ์
ํ์ง ์๊ณ Base64 ์ธ์ฝ๋ฉํ ํ runtime์์ ๋์ฝ๋:
import base64
encoded = base64.b64encode(user_input.encode()).decode()
subprocess_run([
"python", "-c",
f"import base64; process(base64.b64decode('{encoded}').decode())"
])
๋ฐฉ์ด ๋์: shell metacharacter ์ฃผ์
, quote escape ์ฐํ, ๋ค์ค๋ผ์ธ ํ์ด๋ก๋.
Stage 2 โ Subprocess Isolation (execution isolation)
Stage 1 ์ธ์ฝ๋ฉ ํ์๋, ์ค์ ์คํ์ ๊ฒฉ๋ฆฌ๋ subprocess์์ ์ํ. ๋ฉ์ธ ์์ด์ ํธ context์์ ์ง์ eval/exec ๊ธ์ง:
result = subprocess_run(
["python", "-c", safe_runner_script, encoded],
timeout=30,
capture_output=True,
env={"PATH": "/usr/bin"},
)
๋ฐฉ์ด ๋์: ๋ฌดํ ๋ฃจํ(timeout), ํ์ผ ์์คํ
์ ๊ทผ(env ์ ํ), ๋ถ๋ชจ ์์ด์ ํธ ์ํ ์ค์ผ.
Verifier/Filter/Policy Generation Before/After
harness-synthesizer๊ฐ ์์ฑํ๋ verifier/filter/policy์ 2-Stage Isolation์ ๊ธฐ๋ณธ ํ์ฑํ:
Before (v0.107.0 ์ด์ ):
- verifier๋ ๋ฌธ์์ด ๋งค์นญ๋ง ์ํ
- filter๋ ์ ๊ท์ ๊ธฐ๋ฐ ๋จ์ ์ฐจ๋จ
- policy๋ ํ์ฉ/๊ฑฐ๋ถ ๋ฆฌ์คํธ
After (v0.108.0, 2-Stage ๊ธฐ๋ณธ ์ ์ฉ):
- verifier: Base64 ์ธ์ฝ๋ฉ ํ subprocess AST ํ์ฑ โ ๊ตฌ์กฐ ๊ฒ์ฆ
- filter: Stage 1 ๋์ฝ๋ ํ AST ๋ ๋ฒจ ํํฐ (semantic, not lexical)
- policy: subprocess env ์ ํ + capability token (capability-based security)
Action Items
- harness-synthesizer ํธ์ถ์๋ ๊ธฐ๋ณธ์ผ๋ก 2-Stage ํ์ฑํ ๊ฐ์
- verifier/filter/policy ์ปค์คํ
์ Stage 1/2 ๋ชจ๋ ์ ์ง (ํ ๋จ๊ณ ๊ฑด๋๋ฐ์ง ๋ง ๊ฒ)
Cross-references
- #986 (source)
guides/harness-engineering/README.md Section 3
- #976 (Deep Insight Part 3 ๋ด์ฌํ โ ์ด ์น์
์ ๊ธฐ๋ฐ)
Related Guide
guides/harness-engineering/ โ ํ๋ค์ค ์์ง๋์ด๋ง ํตํฉ ๊ฐ์ด๋ (3-Layer Hierarchy + Context Engineering + Behavior/Isolation ์์น)