Repository navigation
feat(guardrails): check a rule's deny and allow examples when it is saved - #79
Merged
Merged
Conversation
…aved
A rule can list calls it must block (examples.deny) and calls it must let through (examples.allow): a command string, or a {tool, input} call when the rule reads named fields or the whole input matters. PATCH /api/bots/:id and app_settings bots.guardrails run each example through the rule's own matcher and refuse the save with 400, naming every example that disagrees. Examples do not change what a rule blocks, so they stay out of the widening check, and enforcement never re-checks them.
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A tool guardrail rule can now carry
examples: calls it must block (deny) and calls it must let through (allow). When the rule list is saved, every example runs through that rule's own matcher, and a save whose examples disagree is refused with 400 that names each failing example.{ "id": "no-direct-git-push", "tools": ["native:shell"], "match": { "kind": "regex", "patterns": ["(^|[;&|])\\s*[^;&|'\"]*\\bgit\\b[^;&|'\"]*\\spush\\b"] }, "examples": { "deny": ["git push origin feat/x"], "allow": ["git stash list", { "tool": "Bash", "input": { "command": "git log --oneline", "description": "Check commits before a push" } }] }, "message": "Push only through omb-push." }{ "tool", "input" }call. A string goes through the rule's argument matcher. A call goes through the rule's tool selectors and its matcher with the exact input, the way a real call is judged.match.fieldstakes only{ tool, input }examples. A string would have to be copied into every field, and that cannot catch a field name the engine does not send, such asfields: ["command"]against Codexexec_command, which sends{ "cmd": ... }.PATCH /api/bots/:id(server/routes/bot-patch.ts) and thebots.guardrailsvalue check in app_settings (server/app-settings/registry-bots.ts). app_settings writes through the same PATCH route, so both paths refuse the same way. The app_settings help text andalloweddescribe the new field.Why
While trying out
no-direct-git-pushon a bot,git stash push -m wipandgit log --grep pushwere blocked. Nothing caught them before the rule was saved. They only showed up when the bot ran them. Examples put the intended allow and deny cases next to the rule, and saving proves them.Decisions
parseToolGuardrails. parse also runs on every tool call: the hook process and the MCP gate parse the policy file per call, and a parse failure becomesinvalid-policy, which blocks every call of that bot. If a later matcher change made a saved example disagree, checking examples in parse would lock the bot out. parse checks only the shape ofexamples. The agreement check lives intoolGuardrailExampleFailuresand runs where rules are saved.canonicalRuleSignatureleaves them out. A bot may add, change, or remove examples on its own, and a person is not needed.store.patchBotand does not run the example check. That path does not change what a rule blocks either.Before / After
Same script, run against a real verification server (
launchVerificationServer, temporary data dir), with the rule pattern copied from the liveno-direct-git-pushrule.Before (main
5ac219492):The rule saves silently, there is no way to state the intended allow cases, and the false positives appear only at call time.
After (this branch):
The save that claims
git stash push -m wipis allowed is refused and names the example. Examples that agree with the rule save. What the rule blocks at call time does not change.Verification
npx vitest run shared/tool-guardrails.test.ts server/routes/bot-patch.test.ts server/app-settings/host.test.ts server/store.test.ts server/team-backup.test.ts server/drivers/claude.test.ts server/drivers/codex.test.ts server/saved-steps/dispatch.test.ts server/tool-permission-audit.e2e.test.ts server/request-auth.test.ts: 10 files, 1081 passed, 1 skipped.toolGuardrailExampleFailures, including a description that makes a field-less rule blockgit log --onelineand a Codexcmdinput missed byfields: ["command"], examples-only changes not counting as widening, a 400 from the PATCH route while another bot is busy, and a 400 from app_settingsset.pnpm typecheck: exit 0.oxlint --deny-warnings .: exit 0.Not covered