Skip to content

Commit c052bed

Browse files
committed
docs(agent-audit): enforce user edits precedence
- Forbid discard operations unless explicitly requested - Remove guidance that implies user edits can be discarded by default - Add warnings to git references and self-review command
1 parent df64db9 commit c052bed

5 files changed

Lines changed: 38 additions & 10 deletions

File tree

commands/self-review.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ description: Comprehensive local code review comparing current branch to main -
44

55
# SELF CODE REVIEW MODE ACTIVATED
66

7-
You are now in **SELF REVIEW** phase - performing a comprehensive local code review comparing the current branch to `main`, following the structured review approach from `100-core.mdc` and `050-workflow.mdc`.
7+
You are now in **SELF REVIEW** phase - performing a comprehensive local code review comparing the current branch to `main`, following the structured review approach from `100-core.mdc` and `010-workflow.mdc`.
88

99
> [!IMPORTANT]
10-
> This is a **read-only analysis**. No commits or pushes will be made without explicit user authorization (see `060-agent-audit.mdc`).
10+
> This is a **read-only analysis**. No commits or pushes will be made without explicit user authorization (see `020-agent-audit.mdc`).
1111
1212
## Phase 1: Context Gathering & Audit Setup
1313

14-
**Audit Requirements (from `060-agent-audit.mdc`):**
14+
**Audit Requirements (from `020-agent-audit.mdc`):**
1515

1616
- Record baseline: `HEAD` SHA, branch name, timestamp
1717
- Document all commands with exit codes in audit report
1818

1919
> [!NOTE]
20-
> **Checkpoints:** Only create checkpoints (`git stash`, rollback branch) if Phase 5 (Automated Fixes) will be applied. For read-only analysis, baseline recording is sufficient since formatting changes are easily reversible with `git restore` or `git checkout`.
20+
> **Checkpoints:** Only create checkpoints (`git stash`, rollback branch) if Phase 5 (Automated Fixes) will be applied.
21+
> For read-only analysis, baseline recording is sufficient.
22+
>
23+
> Do not discard user working-tree edits with `git restore` / `git checkout --` unless the user explicitly asks (see `020-agent-audit.mdc`).
2124
2225
1. **Branch Information:**
2326
- Current branch name (`git branch --show-current`)
@@ -130,7 +133,7 @@ Generate a structured review report:
130133
## Phase 5: Automated Fixes (Optional)
131134

132135
> [!IMPORTANT]
133-
> **Before applying fixes:** Create checkpoints per `060-agent-audit.mdc`:
136+
> **Before applying fixes:** Create checkpoints per `020-agent-audit.mdc`:
134137
>
135138
> - `git stash push -u -m "checkpoint/<YYYYMMDD_HHMMSS>"`
136139
> - `git branch "checkpoint/<YYYYMMDD_HHMMSS>" <baseline-sha>`
@@ -149,7 +152,7 @@ Generate a structured review report:
149152
3. **Re-run linters:** Verify fixes resolved issues
150153

151154
> [!TIP]
152-
> Formatting changes are easily reversible with `git restore <file>` or `git checkout -- <file>`, but checkpoints provide additional safety for complex changes.
155+
> If the user wants to revert formatting changes, propose the exact revert commands (for example `git restore <file>`), but do not run them unless the user explicitly asks. Checkpoints provide additional safety for complex changes.
153156
154157
## Phase 6: Verification & Audit Report
155158

@@ -158,7 +161,7 @@ Generate a structured review report:
158161
3. **Diff summary:** Show final `git diff main...HEAD --stat`
159162
4. **Ready for PR:** Confirm all Critical issues resolved
160163

161-
**Generate Audit Report (per `060-agent-audit.mdc`):**
164+
**Generate Audit Report (per `020-agent-audit.mdc`):**
162165

163166
- Ensure `GIT_REPO_ROOT` is set, then write/append the report to `<GIT_REPO_ROOT>/extras/agent_reports/$(date +%F)-agent-report-<repo>-<branch>.md` (if `<GIT_REPO_ROOT>/extras/` exists and is gitignored) or `/tmp/$(date +%F)-agent-report-<repo>-<branch>.md`
164167
- Include:
@@ -179,7 +182,7 @@ Generate a structured review report:
179182
- Refactor code not part of current changes
180183
- Add features not in the current scope
181184
- Change APIs or break existing functionality
182-
- **Commit or push** without explicit user authorization (see `060-agent-audit.mdc`)
185+
- **Commit or push** without explicit user authorization (see `020-agent-audit.mdc`)
183186
- Perform any remote writes (git push, PR creation, etc.)
184187

185188
**DO:**
@@ -230,7 +233,7 @@ If CodeRabbit is available and configured for the repository:
230233

231234
**Integration:** This workflow aligns with:
232235

233-
- `050-workflow.mdc` Review Phase
236+
- `010-workflow.mdc` Review Phase
234237
- `100-core.mdc` Code Review Mode standards
235-
- `060-agent-audit.mdc` Audit requirements
238+
- `020-agent-audit.mdc` Audit requirements
236239
- `110-git.mdc` Commit standards

rules/020-agent-audit.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ Minimum checkpoints:
5454
- **Rollback anchor**: create a local checkpoint reference:
5555
- `git branch "checkout-point/<id>" <baseline-sha>`
5656

57+
> [!IMPORTANT]
58+
> **User edits always take precedence.**
59+
>
60+
> AI agents MUST NOT discard or overwrite a user's manual working-tree changes unless the user explicitly asks.
61+
> Treat these as destructive operations that require explicit user direction:
62+
>
63+
> - `git restore ...` (worktree discard)
64+
> - `git checkout -- ...` (worktree discard)
65+
> - `git reset --hard ...` (index + worktree discard)
66+
> - `git clean -fd ...` (untracked deletion)
67+
>
68+
> If the agent needs to revert *its own* changes, it must propose the exact commands and file list first and wait for approval.
69+
5770
Checkpoint rules:
5871
- Each checkpoint MUST have a unique `<id>` (recommend `YYYYMMDD_HHMMSS`).
5972
- Every checkpoint MUST be recorded with a timestamp and identifier in the audit report.

rules/130-git.mdc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ Git 2.23+ split the multi-purpose `checkout` into focused commands for clarity a
592592
| `git checkout -- file` | `git restore file` | Restore file from index |
593593
| `git checkout HEAD -- file` | `git restore -s HEAD file` | Restore file from commit |
594594

595+
> [!IMPORTANT]
596+
> `git restore`, `git checkout -- <path>`, `git reset --hard`, and `git clean -fd` can discard local changes.
597+
> AI agents MUST NOT run discard operations unless the user explicitly requests it.
598+
595599
**Why prefer `switch`?**
596600

597601
`checkout` is a multi-purpose tool that does many different things: switch branches, create branches, restore files, detach HEAD. When you see `git checkout somename`, you cannot immediately tell if it is switching to a branch, restoring a file, or going to a specific commit.

skills/core-engineering/references/git-modern-commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Git 2.23+ split the multi-purpose `checkout` into focused commands for clarity and safety.
44

5+
> [!IMPORTANT]
6+
> Commands like `git restore`, `git checkout -- <path>`, `git reset --hard`, and `git clean -fd` can discard local changes.
7+
> If you are operating as an AI agent, do not run discard operations unless the user explicitly requests it.
8+
59
## `git switch` vs `git checkout`
610

711
| Old Command | New Command | Purpose |

skills/core-engineering/references/git-reflog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# The Reflog: Git's Safety Net
22

3+
> [!IMPORTANT]
4+
> `git reset --hard` and similar commands can discard local changes.
5+
> If you are operating as an AI agent, do not run discard operations unless the user explicitly requests it.
6+
37
## What is the Reflog?
48

59
The **reflog** (reference log) is Git's time machine. While `git log` shows only commits reachable from branches/tags, the reflog records **every movement of HEAD** — every checkout, reset, commit, rebase, branch switch, and even "lost" commits.

0 commit comments

Comments
 (0)