Repository navigation
Description
The agent-guard vetted-ops-spelling guard added in #1674 leaves two spellings unchecked.
Neither one escapes the sandbox (the exclusions name only the literal ~/.claude/magpie/<tool> form), but both slip past the guard that should catch them.
1. Prefix wrappers: env uv run …
env uv run --project tools/vetted-ops vetted-op-read pr-view 1
command uv run --project /home/alice/.claude/magpie/vetted-ops vetted-op-read pr-view 1
The engine looks only at a segment's first word (argv[0]), and env / command are not guarded heads.
This is not specific to the new guard: Segment.__init__ in tools/agent-guard/src/agent_guard/__init__.py already notes that env git / command git stay unguarded for every guard (commit-trailer, empty-rebase, mention, …).
Proposed fix, in the engine rather than in one guard: strip env (with its NAME=value assignments and options such as -i, -u NAME) and command (with -p) before matching, so every guard sees the wrapped command.
Prefix assignments must still feed Segment.env, so overrides such as MAGPIE_ALLOW_VETTED_PATH=1 keep working.
2. A quoted ~
uv run --project "~/.claude/magpie/vetted-ops" vetted-op-read pr-view 1
The guard compares the base after shlex removes the quotes, so this matches the allowed spelling.
The shell does not expand a quoted ~, though: uv gets a directory literally named ~, the sandbox exclusion does not match, and the call fails inside the sandbox instead of being refused with the corrected command.
Proposed fix: have the guard look at the raw segment and refuse a quoted ~ with the same corrected-command message.
Acceptance
env …andcommand …around a guarded command are checked as that command, by every guard, with tests per guard family.- A quoted
~base is refused byvetted-ops-spelling, with a test. - The "prefix wrappers … remain a separate, pre-existing gap" comment in
Segment.__init__is removed.
Activity
fix(agent-guard): see through env/command; refuse a quoted ~ and the …
fix(agent-guard): see through env/command; refuse a quoted ~ and the …