Dependency-Order Editing
Change files in dependency order: types and interfaces first, then implementations, then consumers, then tests. This ensures each file is valid at the time it’s edited, because its dependencies have already been updated. Editing in random order creates temporary broken states that confuse the agent.
Atomic Commits
After each logical group of changes, commit. “Renamed User.name to User.displayName in types” — commit. “Updated all components to use displayName” — commit. “Updated tests” — commit. Small, atomic commits create rollback points. If step 3 breaks, you revert to step 2 without losing step 1.
The Verify-After-Each Pattern
// After each group of changes:
1. Agent makes edits to a file group
2. Run type checker: tsc --noEmit
3. Run linter: eslint .
4. Run affected tests: npm test -- --changed
5. If all pass → commit & continue
6. If any fail → fix before proceeding
// Never let errors accumulate.
// Fix each failure before moving on.
// Accumulated errors are exponentially
// harder to debug than isolated ones.
Why this works: Each commit is a known-good state. The agent can always revert to the last passing commit. This transforms a scary 50-file refactor into a series of small, safe, verifiable steps. The total time is longer, but the risk of catastrophic failure drops to near zero.