Patches & Diffs

Stable

The structured edit format, conflict resolution, and why agents do not write files directly.

Pimsy agents never write to a working tree directly. Every modification is expressed as a patch — a structured, reviewable, reversible description of an edit that is validated before it is applied.

Why not direct writes#

Direct file writes make three failure modes unavoidable. A partially-completed sequence of writes leaves the repository in a state that neither the agent nor a human intended. An edit based on a stale read silently clobbers concurrent work. And a write carries no record of intent, so a reviewer sees what changed but not why.

Patches address all three. They are atomic as a set, they carry the content hash of what the agent believed it was editing, and every hunk is annotated with the plan step that produced it.

Patch structure#

basestringrequired
Content hash of the tree state the patch was authored against. A mismatch at apply time raises a conflict rather than overwriting.
hunksHunk[]required
Ordered edits. Each targets a symbol identifier where possible and a line range only as a fallback, so a patch survives unrelated edits elsewhere in the same file.
rationaleRecord<string, string>required
Per-hunk explanation linking the edit to a change-plan step. Patches without rationale are rejected at validation.
invariantsstring[]
Properties the patch asserts it preserves. Checked against the verification result before the patch is offered for review.
reversalPatch
Automatically derived inverse. Present whenever the edit is mechanically reversible.

Symbol-anchored hunks#

A conventional diff addresses lines. If anything above a hunk changes, the hunk no longer applies. Pimsy hunks address symbols: "the body of this function", "this parameter in this signature". Unrelated edits elsewhere in the file are irrelevant, and a patch authored an hour ago still applies cleanly after a reformat.

Symbol-anchored hunk
hunk 2 of 4
  anchor     auth/session.resolveSessionToken  (body)
  base       sha256:9f2c…  verified
  rationale  step 3 — token comparison must be constant-time;
             the previous equality check leaked length through
             early return

- if (provided !== expected) return null
+ if (!constantTimeEquals(provided, expected)) return null

  invariant  returns null for every non-matching token
  invariant  no change to the success path

Conflict resolution#

ConditionResolution
Anchor symbol unchangedApply cleanly, regardless of surrounding edits
Anchor moved to a new fileFollow the symbol; apply at the new location
Anchor body changedRaise conflict; re-plan against the current body
Anchor deletedRaise conflict; the plan step is invalidated and returned to the planner
Base hash mismatch, anchors intactApply with a concurrency warning attached to review

Last updated 2026-08-20