Skip to content
This repository was archived by the owner on Dec 3, 2026. It is now read-only.

fix(init, skills): a crashing guard blocks; skills say what the guard can't see and how to remove a repo - #225

Merged
mateodelnorte merged 2 commits into
mainfrom
fix/guard-hook-blocks-on-crash
Dec 2, 2026
Merged

mateodelnorte merged 2 commits into
mainfrom
fix/guard-hook-blocks-on-crash

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What was broken

The PreToolUse hook that meta init skills writes to .claude/settings.json was

agent --help 2>/dev/null | grep -q 'Claude Code agent toolkit' && agent guard; exit 0

The trailing ; exit 0 means that when gitkb's agent guard crashes, is killed (OOM, timeout) or fails before printing a decision, the hook exits 0 and Claude Code runs the command anyway.

Docs gap too: the meta-workspace skill and meta git --help never said how to remove a repo from a workspace, so an agent asked to do it reached for rm -rf <repo>.

The fix

  • The hook is now

    if agent --help 2>/dev/null | grep 'Claude Code agent toolkit' >/dev/null; then agent guard || exit 2; fi
    
    • no agent on PATH, or an agent that isn't gitkb's → exit 0, no output (allowed, as before);
    • gitkb's guard prints its decision and exits 0 → unchanged (Claude Code reads the decision);
    • gitkb's guard fails without a decision → exit 2, which Claude Code treats as "block".

    grep reads all of agent --help (no -q). With -q, a shell running with set -o pipefail could see agent killed by SIGPIPE after grep's early exit, take the if as false and skip the guard. The identity check is the same text as before.

  • Upgrade of users' settings (contract): meta init skills (and the --update notice) rewrites only these exact strings, the ones older metas wrote:

    1. meta agent guard: written by init in the archived gitkb/meta_cli repo from ecbba5b (2026-01-31) to 4d782e9 (2026-05-19). Today's meta exits 2 on it (unrecognized command 'agent'), which blocks every Bash call.
    2. agent guard
    3. agent --help 2>/dev/null | grep -q 'Claude Code agent toolkit' && agent guard; exit 0

    Any other hook command is left as it is, including a hand-written one that looks similar (e.g. ./target/debug/agent guard). This repo's own .claude/settings.json uses the new command; a test checks that it matches. The upgrade message now reads "Made the PreToolUse hook run only gitkb's agent and block when its guard fails, in …".

  • .claude/agent-guard.toml is deleted. It was a schema 1.0 copy of the old default rules: its 8 ids are exactly the guard's built-ins, and it has no custom rule. Nothing in meta reads it. The rewritten guard in fix(guard)!: judge commands by their arguments; policy overrides built-ins by id; fail closed agent#10 refuses v1 policy files by denying every command, so with that guard installed, every Bash call in this repo would be denied. Checked with the agent#10 binary: with the file present, git status gets a deny ("cannot load its policy"). Without it, git status is allowed and git -C x reset --hard is denied.

  • rewrite_hooks takes a list of old commands (the context-hook upgrade passes its one). docs_lint skips the retired meta agent guard, which init has to name in order to replace it.

  • Docs and skills:

    • meta-safety skill: the guard judges the operation whatever its spelling, refuses what it can't parse, and blocks when it crashes. It is a safety net, not a lock, and can't see scripts, variables, interpreters, git aliases or other tools. Before anything destructive, back up a ref (git branch backup/<name>) or push. A refusal means stop and ask, not find another way to run it. The default list now also has what agent#10 refuses: force next to --force-with-lease, git push --mirror/--delete/:<ref>, git checkout -f, git switch -f, git restore ., and rm -r of .git or a folder that holds one.
    • docs/agent_skills.md: the settings paragraph is split into the hooks, the guard hook, and the older hooks that get rewritten (the three guard strings and the older context hook). A hook command you wrote yourself is left as it is.
    • Removing a repo from a workspace (drop it from .meta.yaml, then meta git update --prune, which keeps a repo holding anything no remote has): meta-workspace skill, README, meta git update --help, and the one-line update summary in meta git --help.
    • No meta-side text recommended meta exec / meta --include … exec as a way around a denial (searched rg -n "include.*exec|exec -- git push" claude-plugin docs README.md meta_cli), so nothing to remove there.
    • shipped.txt gets the new blob ids of the two changed skills, as the init test asks.

Merge order: the skill text and the deletion of the v1 policy file assume the guard of gitkb/agent#10 ("fix(guard)!: judge commands by their arguments; …"). Merge this with or after that PR.

Decision followed

The panel's decision on the guard: use this hook form. A missing or foreign agent must still allow the command, and a crashing guard must block it. Upgrade only the exact strings meta shipped before.

Callers

The hook string ends up in users' settings files, and they're upgraded as listed above. Searched harmony with rg --no-ignore --hidden -g '!.git' -g '!**/.worktrees/**' -g '!**/target/**' "Claude Code agent toolkit' && agent guard|\"agent guard\"|isn't cloned; never pull". Nothing parses the hook string or the update summary. The only matches outside meta are gitkb/agent's README, which shows a hand-written bare agent guard hook; meta already upgrades that. Not breaking for callers.

Tests and proof

  • init::tests::the_guard_command_runs_only_gitkb_s_agent_and_blocks_when_it_fails runs the installed command with a fake agent on PATH. Under sh -c:

    • foreign agent → (0, "")
    • no agent → (0, "")
    • gitkb's agent printing a deny → (0, deny)
    • gitkb's agent exiting 1 silently → (2, "")

    Under bash -o pipefail -c, gitkb's agent with a long --help → (0, deny).

  • an_older_meta_s_guard_hook_is_made_safe covers the three old strings (meta agent guard named literally) and checks the upgrade message. It also has a custom ./target/debug/agent guard; exit 0 that has to stay as it is.

  • init.bats: the --update notice test covers both agent guard and the …; exit 0 form.

  • Mutations, each caught:

    • drop || exit 2 → crash case (Some(1), "")
    • back to grep -q → pipefail case left: (Some(0), "") right: (Some(0), "{\"deny\":1}\n")
    • drop "meta agent guard" from the list → upgrade test fails
    • message back to "never block on its failure" → upgrade test fails
    • match with command.contains("agent guard") or ends_with("exit 0") → the custom case is rewritten
    • drop the …; exit 0 string → the bats --update notice test fails (line 209)
  • cargo test -p meta, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all --check and make bats FILE=init pass, except init.bats test 33, which is flaky on base too (it failed in 1 of 3 full runs on c9ef397). Its cause is a race in the test: in find . | sort > tree.before the redirect belongs to sort, so find sometimes runs before tree.before exists and leaves it out. It doesn't involve the hook.

… can't see and how to remove a repo

The hook `meta init skills` installs ended with `; exit 0`, so when gitkb's
`agent guard` crashed or was killed before printing a decision, the Bash
command ran. It is now
`if agent --help 2>/dev/null | grep -q 'Claude Code agent toolkit'; then agent guard || exit 2; fi`:
a missing or foreign `agent` still lets the command run, a failing guard
blocks it (exit 2). `meta init skills` upgrades only the two commands older
metas wrote (`agent guard` and the `...; exit 0` form); a hook command the
user wrote is left alone.

The meta-safety skill says the guard judges the operation whatever its
spelling, refuses what it can't parse, is a net not a lock, can't see
scripts, variables, interpreters, aliases or other tools, and that a ref
should be backed up or pushed first. The meta-workspace skill, README and
`meta git update --help` say how to remove a repo from a workspace.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 11 billable files and costs up to $2.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 76 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: adcf88a5-261a-4ac0-b392-c6f7875da936
Commits

Reviewing files that changed from the base of the PR and between c9ef397 and d74ee7b.

Files selected for processing: 11

  • .claude/agent-guard.toml
  • .claude/settings.json
  • README.md
  • claude-plugin/skills/meta-safety/SKILL.md
  • claude-plugin/skills/meta-workspace/SKILL.md
  • docs/agent_skills.md
  • meta_cli/src/docs_lint.rs
  • meta_cli/src/init.rs
  • meta_cli/src/shipped.txt
  • meta_git_cli/src/update.rs
  • tests/init.bats
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…skipping the guard, drop the v1 guard policy
@gold-silver-copper
gold-silver-copper marked this pull request as ready for review December 2, 2026 02:44
@mateodelnorte
mateodelnorte merged commit b7a65a3 into main Dec 2, 2026
13 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants