Apply patch
apply_patchStage, validate, and atomically apply V4A patches, with context-based hunks and match quality feedback for safe file edits.
Instructions
Stage, validate, and atomically apply a V4A patch envelope. Each hunk locates itself by its context, so the context must be unique in the file; when it is not, add a scope header (@@ def my_function) naming the enclosing block, or add '*** End of File' to anchor the hunk at the end. A blank context line may be written as "" or as a single space. Matching is graded exact, then ignoring trailing whitespace, then ignoring indentation width, and the grade actually used comes back as match_quality. Success returns each file's revision, total_lines, and changed_ranges. Several updates to one path in one envelope chain in order. Full format reference: docs/tools-and-schemas.md. Example: *** Begin Patch *** Update File: app.py @@ -old +new *** End Patch
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| patch | Yes | ||
| dry_run | No | ||
| idempotency_key | No | Names this exact request so a retry after a lost response replays the recorded result (flagged idempotent_replay) instead of doing the work twice. Use a new key for new work: the key is bound to the arguments that first used it, and reusing it with any other argument — including a different dry_run — is refused with IDEMPOTENCY_KEY_REUSED. Only a successful non-dry-run result is recorded, and only the 64 most recently used keys are kept across all tools. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| clean | No | ||
| error | No | ||
| dry_run | No | ||
| summary | No | ||
| removals | No | ||
| warnings | No | ||
| additions | No | ||
| affected_files | No | ||
| already_applied | No | ||
| idempotent_replay | No | ||
| revision_algorithm | No |