feat: v0.15.0 — per-operation enforcement in watch mode - #31
Merged
Merged
Conversation
Adds OperationRule dataclass and per-operation check in check_event(). Rules match tool name + glob pattern and can alert or block specific operations (e.g. block bash 'rm *', alert write '*.env'). Rules are configured via operation_rules in .agent-watch.json. Also integrates TokenBudgetWatcher into watch mode: fires when context window usage crosses max_context_pct threshold (default 90%). CLI: --max-context-pct flag on agent-strace watch Closes #21 Co-authored-by: Ona <no-reply@ona.com>
TokenBudgetWatcher is introduced in v0.21.0. The watch.py integration uses a try/except ImportError so the per-operation enforcement branch passes CI independently. Token budget tests that require the module are deferred to the v0.21.0 branch. Co-authored-by: Ona <no-reply@ona.com>
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.
Closes #21
What
Extends
watch.pywith per-operation enforcement rules that can alert or block specific tool calls without killing the entire session.How it works
OperationRulematches on tool name + glob pattern:{ "operation_rules": [ {"tool": "bash", "pattern": "rm *", "action": "block", "reason": "no deletions"}, {"tool": "write", "pattern": "*.env", "action": "alert"}, {"tool": "*", "pattern": "*/prod/*","action": "alert", "reason": "prod access"} ] }Rules fire at most once per unique (tool, pattern, target) combination to avoid alert fatigue.
Also integrates
TokenBudgetWatcherinto the watch loop — fires when cumulative input tokens crossmax_context_pct(default 90%) of the model's context window.Tests
tests/test_watch_operations.py— 12 tests.