feat(guardrails): block destructive git commands (bash_destructive_git) #116

Merged
alee merged 7 commits from feat/guardrails-destructive-git into main 2026-10-18 01:26:53 +00:00
Owner

What

New always-scope guardrail rule bash_destructive_git (block | warn | off; absent key means block) in the opencode plugin. It blocks history-destroying git commands even in a worktree and with no active boulder:

  • reset --hard|--keep|--merge
  • clean with -f/--force
  • checkout -f, checkout ., checkout <ref> -- .
  • restore with pathspec .
  • branch -D / branch -f, switch -f
  • update-ref -d, reflog expire|delete, gc --prune=now

Allowed (pinned by tests): git checkout <ref> -- <file>, git restore --source=<ref> -- <file>, git revert, git reset <path>, read-only commands, clean -n.

Why

2026-10-10: a worker asked to restore one file ran git reset --hard origin/main in the classifier-reliability worktree and moved the branch off 8 commits. They survived only via the reflog. No existing rule objected (bash_banned has no --hard; bash_main_checkout only fires in the main checkout).

Notes

  • Matcher skips git global options, including the space forms --git-dir /x and --work-tree /x.
  • Known gap, documented: bash -c '...' wrappers are not inspected (shared with the other bash rules).
  • A parent agent's own recovery with reset --hard is blocked too, on purpose: the log line is the signal for the operator to decide.
  • Replay harness ALWAYS_RULES updated; hook-level test proves the wiring (mutation evidence in commit 794f70d).
  • Plugin only: 8 files, no Python or config changes. .omo/guardrails.json untouched.

Verification

cd deploy/opencode-plugin && node --test: 436 tests, 0 fail (baseline was 328). Merges cleanly with current origin/main (checked with git merge-tree).

Install (operator)

command cp -f deploy/opencode-plugin/guardrails.js ~/.config/opencode/plugins/guardrails.js

then restart opencode (plugins load at process start). This branch's version is already installed locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XtPLeRkmHJk4VeiTEUfhVR

## What New always-scope guardrail rule `bash_destructive_git` (block | warn | off; absent key means block) in the opencode plugin. It blocks history-destroying git commands even in a worktree and with no active boulder: - `reset --hard|--keep|--merge` - `clean` with `-f`/`--force` - `checkout -f`, `checkout .`, `checkout <ref> -- .` - `restore` with pathspec `.` - `branch -D` / `branch -f`, `switch -f` - `update-ref -d`, `reflog expire|delete`, `gc --prune=now` Allowed (pinned by tests): `git checkout <ref> -- <file>`, `git restore --source=<ref> -- <file>`, `git revert`, `git reset <path>`, read-only commands, `clean -n`. ## Why 2026-10-10: a worker asked to restore one file ran `git reset --hard origin/main` in the classifier-reliability worktree and moved the branch off 8 commits. They survived only via the reflog. No existing rule objected (`bash_banned` has no `--hard`; `bash_main_checkout` only fires in the main checkout). ## Notes - Matcher skips git global options, including the space forms `--git-dir /x` and `--work-tree /x`. - Known gap, documented: `bash -c '...'` wrappers are not inspected (shared with the other bash rules). - A parent agent's own recovery with `reset --hard` is blocked too, on purpose: the log line is the signal for the operator to decide. - Replay harness `ALWAYS_RULES` updated; hook-level test proves the wiring (mutation evidence in commit 794f70d). - Plugin only: 8 files, no Python or config changes. `.omo/guardrails.json` untouched. ## Verification `cd deploy/opencode-plugin && node --test`: 436 tests, 0 fail (baseline was 328). Merges cleanly with current origin/main (checked with `git merge-tree`). ## Install (operator) ``` command cp -f deploy/opencode-plugin/guardrails.js ~/.config/opencode/plugins/guardrails.js ``` then restart opencode (plugins load at process start). This branch's version is already installed locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XtPLeRkmHJk4VeiTEUfhVR
alee added 7 commits 2026-10-18 01:26:41 +00:00
alee merged commit 25e8eaa411 into main 2026-10-18 01:26:53 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alee/6krrt#116