Skip to content

ci: Repo-level hook that enforces soldr over bare cargo/rustup (#691) - #715

Merged
zackees merged 2 commits into
masterfrom
tooling/691-soldr-tool-guard
Oct 14, 2026
Merged

zackees merged 2 commits into
masterfrom
tooling/691-soldr-tool-guard

Conversation

@zackees

@zackees zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

Fixes #691
Refs #699

  • ci/hooks/tool_guard.py (uv script, ported from soldr's .claude/hooks/tool_guard.py) is a PreToolUse hook that denies bare cargo/rustup/rustc/... with a soldr <tool> hint, and bare python/pip with a uv hint.
    • It parses the command with shlex instead of matching substrings.
    • Denied: FOO=1 cargo build, env [-u X] cargo build, exec/time/sudo/command prefixes, bash -c "cargo build" (checked recursively), and every newline, ;, &&, || and | segment.
    • Allowed: gh issue create --body "... bare rustup", echo cargo:warning, git commit -m 'cargo ...', heredoc bodies, and docker/ssh arguments.
  • .claude/settings.json wires it on Bash|Shell|PowerShell, anchored on $CLAUDE_PROJECT_DIR and guarded by [ -f ci/hooks/tool_guard.py ] (fbuild's pattern). .gitignore now tracks only the two shared settings files, so other local agent state stays ignored.
  • No double denial under clud: the hook exits silently when CLUD_SESSION_ID is set. .clud/settings.json sets rust.use_soldr, so clud users also get the shims.
  • CI side: ci/test_tool_guard.py runs in ./lint (ci/test_*.py). It also scans tracked shell scripts under ci/ and rust/tools/ for bare Rust tools. Two container-internal scripts, which run in images without soldr, are allowlisted with reasons.
  • AGENTS.md documents the hook and notes that Codex has no repo hook.

RED → GREEN

  • RED: the test commit alone fails at import (FileNotFoundError: ci/hooks/tool_guard.py).
  • GREEN: 17 tests pass and ./lint is ok. End to end, I ran the settings command with CLUD_SESSION_ID unset: cargo test and bash -c "cargo build" are denied, while soldr cargo test and gh issue create --body "bare rustup" produce no output (allowed).

ci/hooks/tool_guard.py, ported from soldr's tool_guard.py, denies bare Rust
tools and bare python/pip in agent shell commands. It parses the command:
FOO=bar, env/exec/sudo prefixes, bash -c strings and every line and pipe
segment are checked, while quoted bodies, echo arguments and heredoc bodies
are allowed. It is silent in clud sessions, which enforce the same rule.
.claude/settings.json wires it (anchored on CLAUDE_PROJECT_DIR, guarded by
[ -f ]); .clud/settings.json turns on clud's soldr shims. ci/test_tool_guard.py
also fails on bare Rust tools in ci/ and rust/tools/ shell scripts.

Fixes #691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

tooling: Ship a repo-level agent hook that enforces soldr over bare cargo/rustup

1 participant