feat: pai-governance-guard — structural authority separation pack#866
Closed
devongenerally-png wants to merge 1 commit into
Closed
feat: pai-governance-guard — structural authority separation pack#866devongenerally-png wants to merge 1 commit into
devongenerally-png wants to merge 1 commit into
Conversation
Deterministic authorization layer as a Claude Code PreToolUse hook. Complements SecurityValidator by addressing unauthorized-but-not-dangerous actions. PROPOSE/DECIDE/PROMOTE pipeline: - Serialize tool calls into structured ActionIntent with SHA-256 hash - Evaluate against user-defined YAML policy (no LLM) - Gate on verdict + append hash-chained witness log 146 tests, zero runtime dependencies, fail-closed semantics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
Hey @devongenerally-png — Kai here, Daniel's AI assistant, doing the next pass of triage on the PAI repo. Closing this out because the If you'd like to re-propose this as a v5-native skill or design pattern, please open a fresh issue or PR against the new release. Thanks for taking the time to put this together — really appreciated. — Kai 🤖 |
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
pai-governance-guard adds a deterministic governance layer that complements SecurityValidator by addressing a different class of risk: actions that aren't pattern-matchable as dangerous but exceed authorized scope.
SecurityValidator catches known-dangerous commands (
rm -rf, credential access, destructive git ops). Governance-guard addresses the structural question: should this action happen at all, given the user's policy?Repo: https://github.com/MetaCortex-Dynamics/governance-guard
The Gap This Fills
PAI's current security model is defense-in-depth with two layers:
validate-protected.ts) — scans for credential patterns before commitsSecurityValidator.hook.ts) — pattern-matches commands againstpatterns.yamltiersBoth layers are valuable and this pack doesn't replace either of them. But both operate on the same principle: known-bad pattern detection. They block things that look dangerous.
The gap is actions that don't look dangerous but aren't authorized:
These actions don't match any regex tier. They pass SecurityValidator cleanly. But they exceed the user's intended authorization. The agent proposed the action, evaluated whether it was appropriate, and executed it — all in the same computational pathway.
PAI Principle #5 says: "AI is probabilistic; your infrastructure shouldn't be." Governance-guard makes the authorization decision deterministic.
How It Works
Three-phase pipeline as a PreToolUse hook:
PROPOSE — Serializes the tool call into a structured
ActionIntent(tool name, action type, target, parameters). Binds with SHA-256 hash.DECIDE — Evaluates the intent against a user-defined YAML policy. Pure function. No LLM. No interpretation. Policy + intent → verdict (approve / deny / escalate). Default: deny.
PROMOTE — Approved actions proceed. Denied actions are blocked (exit code 2). Escalated actions prompt the user. Every decision is recorded in a hash-chained witness log.
How It Integrates With PAI
This pack is designed as a companion to SecurityValidator, not a replacement:
validate-protected.tsSecurityValidator.hook.tsgovernance-guardHook registration: PreToolUse with
*matcher (evaluates all tool calls, not just Bash). Runs alongside SecurityValidator — both hooks fire, both must pass.Policy presets: Three YAML presets that match PAI's security philosophy:
minimal.yaml— Blocks destructive + credential access (similar scope to SecurityValidator, structured format)standard.yaml— Deny-default with explicit allows (recommended)strict.yaml— Allow reads only, deny everything elseWitness chain: JSONL log at
$PAI_DIR/MEMORY/GOVERNANCE/— integrates with PAI's existing MEMORY system. Every governance decision is captured as a learning signal, consistent with PAI's continuous learning architecture.Zero dependencies. Custom YAML parser, Node built-in crypto. Matches PAI's principle of deterministic infrastructure.
What's In the Pack
Tests
146 tests passing across 7 test suites:
canonical.test.ts— Hash computation, deterministic serializationyaml-parse.test.ts— YAML parser, all policy presetsintent.test.ts— Action classification for all tool typespolicy-engine.test.ts— Rule matching, modal gates, policy loadingwitness.test.ts— Hash chain integrity, tamper detectionintegration.test.ts— End-to-end pipeline with all policy presetsadversarial.test.ts— Spoofed hashes, path traversal, replay attacks, malformed YAMLAlignment With PAI Principles
What This Does NOT Do
About
Built by MetaCortex Dynamics — governance infrastructure for autonomous systems.
The core implementation is also available as a standalone package.
AI disclosure: Architecture review and spec drafting assisted by Claude. All code reviewed, understood, and tested by the author. The PROPOSE/DECIDE/PROMOTE governance architecture is original work. 146/146 tests fully passing.
License: MIT