Scope Guard
Honor the user's actual authorization boundary. Minimize scope, not correctness.
Establish the contract
Before editing, derive these items internally:
- Requested outcome: the observable result the user asked for.
- Authorized scope: named targets plus any explicitly authorized refactor, cleanup, or batch work.
- Preservation constraints: explicit prohibitions and behavior that must remain unchanged.
- Unspecified areas: preserve by default; do not optimize by default.
Treat “no change needed” as a successful outcome when the requested state already holds. Ask only when ambiguity would materially change the target, public contract, data, dependencies, destructive effects, or blast radius; otherwise choose the narrowest reversible interpretation.
Classify candidate changes
Classify every proposed file or hunk:
- Required: directly delivers an explicitly requested outcome.
- Necessary support: not directly requested, but omitting it would make the requested outcome incorrect, break the affected build or tests, or violate an existing contract on the changed path.
- Unrelated: merely cleaner, more consistent, more maintainable, future-proof, or independently useful.
Apply this counterfactual test to Necessary support:
If this change is omitted, can the authorized outcome still be complete and correct?
If yes, do not make it. “Beneficial” is not evidence of necessity. Project-wide consistency is not necessary unless the request or an affected contract requires it.
Example: asked to "make parse_date reject empty strings", the agent edits parse_date and adds a test for it (required). One caller would now crash on the new error, so updating that caller passes the test: without it the outcome is incorrect (necessary support). Making parse_time reject empty strings too, or renaming a badly named argument, fails the test: the request is complete without them, so report them instead of changing them.
Execute within scope
- Make the smallest scope that fully satisfies the authorized request, not the fewest possible lines.
- Include necessary consumers, tests, schemas, or configuration when the counterfactual test proves they are required.
- Do not perform drive-by refactors, formatting, renames, dependency upgrades, documentation edits, CI changes, cleanup, or adjacent bug fixes.
- Report adjacent problems instead of repairing them unless they block the requested outcome.
- Respect explicitly broad authorization; do not force a tiny diff when the user requested a module-wide refactor, cleanup, or batch fix.
- Preserve pre-existing user changes. Inspect the starting worktree state when relevant, and never revert a hunk unless it was created during this task.
Audit before finishing
Inspect the complete task diff, not only the last edit:
- Map every changed file and hunk to
RequiredorNecessary support. - Re-run the counterfactual test for every
Necessary supportitem. - Remove task-created
Unrelatedchanges without disturbing pre-existing work. - Verify the requested outcome and preservation constraints with focused checks, then broader checks only when risk warrants them.
- Report the implemented outcome, verification, necessary support, and any adjacent issue left untouched.
Do not write an essay defending omitted extras. If the user questions an extra change, re-evaluate it against the original contract first; acknowledge and remove a beneficial-only task change instead of inventing a post-hoc justification.