Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .claude/agent-guard.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <repo> exec -- git push --force (target one repo)
- meta git snapshot create <name> before force pushing
- git fetch, then git branch backup/<name> origin/<branch> to keep the remote tip
"""

[[patterns]]
Expand All @@ -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 <name> (save state first)
- meta git snapshot restore <name> (reversible reset)
- Commit, or git stash push -u -m <msg>, to keep the work first
- git reflog to find and go back to an earlier commit (commits only)
- Target a specific repo: cd <repo> && git reset --hard
"""

Expand All @@ -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 <repo> exec -- git clean -fd (target specific repos)
- meta git snapshot create <name> before cleaning
- git stash push -u -m <msg> to keep untracked files instead
"""

[[patterns]]
Expand All @@ -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 -- <specific-file> (target specific files)
- meta --include <repo> exec -- git checkout . (target one repo)
- meta git snapshot create <name> before reverting
- git stash push -m <msg> to keep the changes instead
"""

[[patterns]]
Expand All @@ -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 <branch> (safe delete — only works if merged)
- git branch -v to check merge status first
- meta git snapshot create <name> before deleting
- git branch backup/<name> <branch> first to keep its commits
- meta --include <repo> exec -- git branch -D <branch> (target specific repos)
"""

Expand All @@ -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 <stash> to inspect contents first
- git stash apply <stash> instead of pop (preserves the stash)
- meta git snapshot create <name> captures all stashes
"""

[[patterns]]
Expand All @@ -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 <stash> to remove specific entries one at a time
- meta git snapshot create <name> before clearing (captures all stashes)
- meta --include <repo> exec -- git stash clear (target specific repos)
"""

Expand All @@ -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 -- <cmd> to preview operations
- meta git snapshot create <name> before destructive operations
- Commit and push work you want to keep first
"""

# Examples: Project-specific overrides
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
6 changes: 3 additions & 3 deletions src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion tests/guard.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading