Top-Level Structure
A valid patchset document has exactly this shape:
- The file path on the PATCH line is the authoritative target — relative to the workspace root.
- A PATCHSET may contain one or more PATCH blocks.
- PATCH blocks are never nested.
- Comments (
# …) are only allowed as standalone lines outside PATCH blocks. - Inside any PATCH block, comment lines are forbidden — no exceptions.
Content Prefixes & Separator
Every content line inside an operation carries one of two prefixes. The prefix is determined solely by which block the line belongs to — not by whether the line is blank or non-blank.
- (dash space)
- def process_data(items):
- return items
- (blank old line → exactly "- ")
. (dot space)
. def process_data(items, validate=True):
. return items
. (blank new line → exactly ". ")
The separator between an old block and a new block must be exactly:
- A blank line in an old/anchor block → write as
-(dash-space, nothing after). Never use.. - A blank line in a new/insert block → write as
.(dot-space, nothing after). Never use-. - This rule applies in every operation — INSERT BEFORE, INSERT AFTER, DELETE, REPLACE, CREATEFILE — without exception.
Anchor Model & Uniqueness
v1.3 is anchor-first. An anchor block is a contiguous block of one or more - lines. The executor finds exactly one acceptable match for each anchor in the target file.
- If an anchor block has zero matches, the operation fails — nothing is written.
- If an anchor block matches more than once, the executor refuses to guess and the operation fails.
- Authors should include enough surrounding old lines in anchors to make matches unique.
- Line numbers are not part of Patch Language v1.3. The content itself is the locator.
Operations
Adds new lines immediately before a matched anchor block.
- The executor locates a unique match for the anchor block.
- New lines are inserted immediately before the first line of the matched anchor.
- One or more
.lines are required.
Adds new lines immediately after a matched anchor block.
- New lines are inserted immediately after the last line of the matched anchor.
- One or more
.lines are required.
Removes an explicit old-content block from the file.
- The
-block is both the anchor and the deletion target. - On success, the matched lines are removed from the file.
- No separator (
---) or new block is used — DELETE has no new content.
Swaps an explicit old block for a new block at the same logical location.
In the example above, the second - line and the second . line each represent a blank line in the file.
- The
-block is the old-state anchor; the.block replaces it. - At least one line is required in each block.
- One-line edits must use a sufficiently unique old block; if a single-line old block is not unique, include surrounding lines until it is.
Creates a brand-new file. The target file must not already exist in the workspace.
- The authoritative file path is the one on the PATCH line.
- One or more
.lines are required — they form the full file content. - No separator or old block is used — CREATEFILE has no anchor.
Removes an entire file from the workspace. The target file must exist.
- DELETEFILE has no content block — no
-or.lines. - The entire file is removed on Apply.
Executor Behaviour
For each operation the executor must:
- Verify that every anchor or old block resolves to exactly one acceptable location.
- If an anchor resolves to zero locations — fail.
- If an anchor resolves to multiple plausible locations — refuse to guess.
- In non-interactive execution, ambiguity is a hard failure.
- In interactive execution, the executor may present candidate matches and require explicit user choice before proceeding.
Hard Limits
These rules are never violated, regardless of how a request is framed:
- Output git diff, unified diff, or context diff.
- Output comments inside any PATCH block.
- Include code fences or markdown formatting inside the PATCHSET body.
- Omit required anchor or old blocks for INSERT, DELETE, or REPLACE.
- Use line numbers as patch semantics.
- Guess when an old block is ambiguous.
- Renumber or rewrite the target file outside the requested operations.
- Use
.as the prefix for any line in an old or anchor block. - Use
-as the prefix for any line in a new or insert block.