fix(policy): Restructure policy evaluation for per-violation callbacks#27
Merged
anormang1992 merged 1 commit intomainfrom Mar 19, 2026
Merged
Conversation
…allbacks and correct orchestration PolicyGate.evaluate() now returns list[PolicyViolation] instead of PolicyResult, moving decision orchestration into VRE.check_policy(). Hard blocks (requires_confirmation=False) are immediate and non-overridable; only confirmation-required violations are routed to on_policy. Key changes: - PolicyCallbackResult model for structured callback returns (passed=True means action passes) - on_policy signature: Callable[[list[PolicyViolation]], bool] — receives only pending violations - PENDING enum value removed — only PASS and BLOCK remain - PolicyViolation.requires_confirmation delegates to policy, carries callback_result - Claude Code hook combines confirmation violations into single bulleted TUI prompt - Demo ProtectedFileDeletePolicy callback with filesystem inspection - parse_bash_primitives returns base command for unrecognized commands (visibility into blocks) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Summary
list[PolicyViolation]instead ofPolicyResult— the gate collects violations, orchestration lives inVRE.check_policy()requires_confirmation=False) are immediate and non-overridable —on_policyis never consultedon_policy, which now receiveslist[PolicyViolation]instead of a single message stringPolicyCallbackResultmodel for structured callback returns —passed=Truemeans the action passes the policy (no violation),passed=Falsemeans it fails (violation fires)PENDINGenum value removed —PolicyActionis nowPASSorBLOCKonlyProtectedFileDeletePolicycallback that inspectsrmcommands for protected files via literal match, glob expansion against the filesystem, and recursive directory inspectionparse_bash_primitivesreturns the base command name for unrecognized commands instead of an empty list, giving visibility into why unknown commands are blockedTest plan
PolicyCallbackResultsemantics, mixed violation orchestration, andon_policypassthrough🤖 Generated with Claude Code