Edit Code
Overview
Edit code safely with per-file backups, inline change notes, and explicit user review before finalizing.
Workflow
- •
Locate project instructions.
- •Look for
AGENTS.mdoragents.mdat the project root and follow it. - •If neither exists, invoke
$project-agentsto generateAGENTS.mdat the project root before proceeding. - •If additional context is needed, skim
README.mdand nearby docs for conventions.
- •Look for
- •
Confirm file format supports comments.
- •If the file format does not allow comments (e.g., strict JSON), pause and ask the user how to record change notes before editing.
- •
Create a backup before any edits.
- •For
path/to/file.ext, createpath/to/file_bak.ext. - •If there is no extension, create
path/to/file_bak. - •If a backup already exists, ask whether to overwrite it.
- •For
- •
Apply minimal edits only.
- •Keep changes concise.
- •Do not refactor or alter the existing structure.
- •Touch only lines required to achieve the requested change.
- •
Annotate every change inline.
- •Add a short, language-appropriate comment at each modification site.
- •Use a consistent tag like
NOTE(change): .... - •Examples:
- •Python:
# NOTE(change): adjust bounds check - •JS/TS/Java/C/C++:
// NOTE(change): ... - •HTML:
<!-- NOTE(change): ... -->
- •Python:
- •
Present changes for review.
- •Show the modified snippets (or a focused diff) with the inline notes.
- •Ask for explicit approval.
- •
Handle approval outcome.
- •If approved: delete the
_bakbackup file(s) and remove inlineNOTE(change)comments from the modified file(s). - •If not approved: ask whether to redo from scratch or make small fixes.
- •Redo: delete the modified file, restore from the
_bakbackup, then start over. - •Small fixes: keep the backup and continue editing with new notes.
- •Redo: delete the modified file, restore from the
- •If approved: delete the
Multi-file edits
Repeat the backup/annotate/review steps per file. Do not delete any backups until all files are approved.
New files
If a request requires creating a new file with no prior version to back up, confirm with the user before proceeding.