Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Terminal agents: keep the patch within owned files

Last updated: 5 Oct 202611 min read
tutorial
AdvancedBy AITrove Editorial

A patch plan should name the files and behavior it intends to change. Before editing, capture the current diff and identify pre-existing changes. After editing, inspect the new diff and explain every changed file against the request. Avoid broad formatting passes that rewrite unrelated code merely to make the patch look consistent. If another agent or person changes the same file during work, re-read it and merge intent deliberately; never restore a stale copy over their work. The prompt may propose a minimal patch, but the filesystem and version-control checks establish what actually changed.

Operational case

The Manifest Gate task touches importer validation and its focused tests. An existing stylesheet edit belongs to another task. The agent changes only the importer and test fixture, then compares the final diff with the starting state. A background process updates the import schema while the agent is working; the agent rereads that schema before finalizing its validation call. It does not revert the concurrent update. If the schema change makes the original approach invalid, the agent adjusts the patch and reruns affected checks.

Output
Owned: importer validation and importer tests.
Pre-existing: stylesheet edit; preserve it.
Concurrent: schema update; reread before final patch.
Review: every new changed file maps to duplicate-slug request.
Conflict: adapt and retest; never overwrite stale state.

Performance and operating cost

A diff review is O(D) in changed lines, far cheaper than scanning an entire repository after every small edit. Re-reading a contested file costs O(F) for its content size and prevents accidental loss of another change. A minimal patch usually shortens code review and rollback, but do not omit a necessary migration or fixture update solely to minimize line count. Ownership is a correctness constraint, not a cosmetic preference.

Common Mistakes

  • Do not erase unrelated work to obtain a clean diff.
  • Do not run a repository-wide formatter for a two-file fix without need.
  • Do not apply a stale patch after another writer changed the same file.

Connected lessons

prompt engineering
terminal agents
Storage details