diff --git a/.claude/agent-guard.toml b/.claude/agent-guard.toml index b5e7d4d..d951121 100644 --- a/.claude/agent-guard.toml +++ b/.claude/agent-guard.toml @@ -33,7 +33,7 @@ git push --force in a multi-repo workspace can overwrite history across \ multiple repos. Safer alternatives: - git push --force-with-lease (checks for upstream changes) - meta --include exec -- git push --force (target one repo) -- meta git snapshot create before force pushing +- git fetch, then git branch backup/ origin/ to keep the remote tip """ [[patterns]] @@ -44,8 +44,8 @@ matcher = { type = "regex", pattern = 'git\s+reset.*--hard\b' } message = """ git reset --hard destroys uncommitted work. In a multi-repo workspace, \ this can silently discard changes across repos. Safer alternatives: -- meta git snapshot create (save state first) -- meta git snapshot restore (reversible reset) +- Commit, or git stash push -u -m , to keep the work first +- git reflog to find and go back to an earlier commit (commits only) - Target a specific repo: cd && git reset --hard """ @@ -60,7 +60,7 @@ git clean -fd removes untracked files and directories permanently. \ In a multi-repo workspace, this affects all repos. Safer alternatives: - git clean -nd (dry run — preview what would be removed) - meta --include exec -- git clean -fd (target specific repos) -- meta git snapshot create before cleaning +- git stash push -u -m to keep untracked files instead """ [[patterns]] @@ -74,7 +74,7 @@ git checkout . reverts all modified files. In a multi-repo workspace, \ ensure you are in the correct repo directory. Safer alternatives: - git checkout -- (target specific files) - meta --include exec -- git checkout . (target one repo) -- meta git snapshot create before reverting +- git stash push -m to keep the changes instead """ [[patterns]] @@ -87,7 +87,7 @@ git branch -D force-deletes branches, potentially losing unmerged work. \ In a multi-repo workspace, this can affect coordination between repos. Safer alternatives: - git branch -d (safe delete — only works if merged) - git branch -v to check merge status first -- meta git snapshot create before deleting +- git branch backup/ first to keep its commits - meta --include exec -- git branch -D (target specific repos) """ @@ -102,7 +102,6 @@ For AI agents working across repos, this could discard important work. Safer alt - git stash list to review what will be dropped - git stash show to inspect contents first - git stash apply instead of pop (preserves the stash) -- meta git snapshot create captures all stashes """ [[patterns]] @@ -115,7 +114,6 @@ git stash clear removes ALL stash entries permanently. \ In a multi-repo workspace, this could discard important work across repos. Safer alternatives: - git stash list to review what will be cleared - git stash drop to remove specific entries one at a time -- meta git snapshot create before clearing (captures all stashes) - meta --include exec -- git stash clear (target specific repos) """ @@ -130,7 +128,7 @@ rm -rf on dangerous paths could destroy repo roots or workspace data. \ In a multi-repo workspace, this is especially dangerous. Safer alternatives: - Remove specific files instead of entire directories - meta --dry-run exec -- to preview operations -- meta git snapshot create before destructive operations +- Commit and push work you want to keep first """ # Examples: Project-specific overrides diff --git a/README.md b/README.md index 225c394..1e1e777 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ echo '{"tool_input":{"command":"git status"}}' | agent guard | Pattern | What it blocks | Safe alternative | |---------|----------------|------------------| | `git push --force` | Force push | `--force-with-lease` | -| `git reset --hard` | Hard reset | `git stash` or snapshot | +| `git reset --hard` | Hard reset | `git stash` or commit first; `git reflog` | | `git clean -fd` | Clean force | `git clean -nd` (dry run) | | `git checkout .` | Checkout all | Specific files | | `git branch -D` | Force delete branch | `git branch -d` | diff --git a/src/guard.rs b/src/guard.rs index 44d79cc..b9e7c72 100644 --- a/src/guard.rs +++ b/src/guard.rs @@ -282,7 +282,7 @@ impl GuardConfig { } // Sort by priority (highest first) - compiled.sort_by(|a, b| b.priority.cmp(&a.priority)); + compiled.sort_by_key(|a| std::cmp::Reverse(a.priority)); compiled } @@ -958,9 +958,9 @@ mod tests { } #[test] - fn reset_hard_reason_suggests_snapshot() { + fn reset_hard_reason_suggests_reflog() { let denial = evaluate_command("git reset --hard").unwrap(); - assert!(denial.reason.contains("snapshot")); + assert!(denial.reason.contains("git reflog")); } #[test] diff --git a/src/score.rs b/src/score.rs index 8861563..6d7a63b 100644 --- a/src/score.rs +++ b/src/score.rs @@ -116,7 +116,7 @@ impl SessionFinder { }) .collect(); - files.sort_by(|a, b| b.1.cmp(&a.1)); // Newest first + files.sort_by_key(|a| std::cmp::Reverse(a.1)); // Newest first Ok(files.into_iter().take(n).map(|(p, _)| p).collect()) } diff --git a/tests/guard.bats b/tests/guard.bats index ca322db..ca87031 100644 --- a/tests/guard.bats +++ b/tests/guard.bats @@ -80,7 +80,7 @@ setup() { run bash -c 'echo '"'"'{"tool_input":{"command":"git reset --hard"}}'"'"' | '"$AGENT_BIN"' guard' [ "$status" -eq 0 ] [[ "$output" == *"deny"* ]] - [[ "$output" == *"snapshot"* ]] + [[ "$output" == *"git reflog"* ]] } @test "guard denies git clean -fd" {