Apply Contract Proposal Patch
apply_contract_patchVerifies a completed contract's proposed patch against its SHA-256 baseline and atomically applies it via git apply—or dry-runs it—aborting on drift to prevent overwrites.
Instructions
Verify the cryptographic dispatch baseline SHA-256 lock and atomically apply a COMPLETED contract's proposed_patch to workspace_root via git apply (ADR-0007).
Purpose
Completes the zero-write proposal loop (write_mode="proposal") by allowing the requester host to dry-run or atomically land a worker's unified diff only when the local baseline has not drifted.
Strict Preconditions & Safety Gates
Contract must be in COMPLETED status with write_mode="proposal", non-empty proposed_patch, and proposal_applied_at === null (refuses duplicate application with ALREADY_APPLIED).
Baseline Drift Lock: Every existing pointer file touched by proposed_patch must currently match its exact dispatched SHA-256 in pointers_json, and newly created files must not already exist on disk. Any drift immediately aborts with status="PROPOSAL_CONFLICT" (zero fuzzy merging, zero overwrites).
Runs "git apply --check" in workspace_root; when dry_run is false, executes "git apply", computes post-apply SHA-256 hashes into verified_sha256, and records proposal_applied_at.
Return Value
Returns { ok, contract_id, status: 'APPLIED' | 'DRY_RUN_OK' | 'ALREADY_APPLIED' | 'PROPOSAL_CONFLICT' | 'PRECONDITION_FAILED', dry_run, proposed_patch_sha256?, proposal_applied_at?, touched_files?, verified_sha256?, drifted_files?, git_check_error?, remediation?, message }.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"contract_id": "<contract_id>"
},
"name": "apply_contract_patch"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | When true, verifies the cryptographic baseline SHA-256 lock and runs `git apply --check` without modifying any workspace files or database state (default: false). | |
| agent_id | No | Optional caller agent identifier for audit attribution (defaults to AGENT_NAME env var). | |
| contract_id | Yes | The COMPLETED contract ID carrying a worker-submitted proposed_patch (write_mode="proposal", ADR-0007). |