Repository navigation
feat(guardrails): add a log mode that records matching calls without blocking them - #80
Merged
Merged
Conversation
…blocking them A rule can carry mode "log". A call it matches goes through, and one row (time, bot, rule, tool, the rule that blocked the same call if any, and the masked text around the match) is appended to guardrail-log/<YYYY-MM>.ndjson in the data folder. Omitting mode keeps today's behavior: the rule blocks. The log is written by the Claude and Codex hook for native tools, by the MCP gate for MCP tools, and by Pi and the OpenAI-compatible runtime for both, so one call is one row. The deny is printed before any row is written, and a row that cannot be written is dropped, so a log rule never turns into a block. Switching an enforced rule to log is a loosening, so only the person can do it; log to enforce is a tightening and stays open to the bot. Rows follow the decision log's retention.
This was referenced Dec 2, 2026
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.
Stacked on #79 (
feat/guardrail-examples): the base of this PR is that branch, so the diff shows only the log mode. Merge #79 first, then retarget this PR tomain.Summary
A tool guardrail rule can now carry
mode:"enforce"(default) or"log". A log-mode rule never blocks. A call it matches goes through, and one row is appended toguardrail-log/<YYYY-MM>.ndjsonin the data folder:{"at":"2026-12-01T17:57:19.326Z","botId":"evidence-bot","ruleId":"no-direct-git-push","tool":"native:Bash","blockedBy":null,"excerpt":"git log --grep push -1 --oneline\nShow the most recent commit whose message conta"}excerptis the text the rule read, 80 characters either side of its first match, with secrets masked.blockedByis the enforced rule that blocked the same call, ornull: it tells a call that is already blocked apart from a call that would be newly blocked once the log rule is switched to enforce.modeis the same as"enforce", is not stored back, and changes nothing for existing rules.server/hooks/omb-tool-guard.ts) and by Pi'stool_call. MCP tools are written by the MCP gate (server/mcp-gate.ts) and by Pi'sexecute. The OpenAI-compatible runtime (chat-mcp-tools.ts) writes both, skipping a rule it already wrote for the same call on a host computer tool.decisions.retentionDays).Security boundary
toolGuardrailsWidensnow compares enforced rules only:app_settings
bots.guardrailsrefuses enforce → log with the existing owner-only message.PATCH /api/bots/:idrefuses it with 409 while another bot is working, and takes it with a browser Origin, as with every other loosening. Both are covered by tests.Decisions
main().then(exit 0, exit 0), and an exit 0 with no output is read as allow (inferred from the hook contract; not run). A write error ahead of the deny would have switched an enforced rule off. Test: an unwritable log folder still denies.OPENAI_API_KEY=from its value and leave a fragment unmasked. Measured on the same input: cut-then-mask keptd4a1b2c3d4a1b2c3d4of the key; mask-then-cut kept none. A mark follows the first match through the masking so the window stays centred.protectedPaths. Measured with the real matcher: with a rule active,tail -n 5 <log file>is blocked andcd <data> && rm -r guardrail-logis not, and a bot with no rules is not protected at all. So it would get in the way of reading and not stop tampering. The log is for watching a rule before enforcing it. It is not an audit record.bot id, folder) so the hook process, which has no access to the store, can write.Before / After
A real Claude turn (
claude -p, haiku) in a throwaway repo whose only commit message contains "push". The turn is told to rungit log --grep push -1 --onelineonce. The hook isomb-tool-guard.ts, wired as intoolGuardHookSettings. The rule isno-direct-git-push(the pattern from the live rule).Before (main
5ac219492hook, rule withoutmode):A read-only
git logis blocked and nothing records that it happened.After (this branch, same rule with
"mode": "log"):The command ran and exactly one row was written. The excerpt starts with the command and continues with the Bash tool's
description: a rule withoutmatch.fieldsreads every string in the input.Verification
vitest runover the guardrail files and everything that imports them (25 files:shared/tool-guardrails,server/tool-guardrail-log,server/hooks,mcp-gate,routes/bot-patch,app-settings,store,team-backup,saved-steps/dispatch,request-auth,tool-permission-audit.e2e, and the pi, pi-mcp-extension, chat-mcp-tools, openai-chat, claude and codex drivers): 1688 passed, 1 skipped. Run withFORCE_COLORandNO_COLORunset: with the shell'sFORCE_COLOR=3 NO_COLOR=1, Node prints a warning on stderr andserver/hooks/omb-hook.test.tsfails onexpect(stderr).toBe(""). That file is not touched here and passes without them.modeis stored only aslog, and an invalid value is refused.enforceproduce the same verdict.blockedBy; an unwritable folder still denies; MCP calls are left to the gate; no log target is quiet.blockedByset.scripts/bundle-server.mjsdoes it.pnpm typecheck: exit 0.oxlint --deny-warnings .: exit 0.Not covered
omb-tool-guard.ts, which the Claude turn above exercised, and the Codex driver tests pass.OMB_OWN_MCP_HTTP=1Claude MCP calls may not pass the gate, so they would not be recorded. Not checked.tools: ["*"]log rule on a busy bot grows it until retention prunes it.