-
Notifications
You must be signed in to change notification settings - Fork 0
Feature Phase2 Governance Spec
Feature ID: phase2-governance Status: Specified Created: 2026-01-24 Version: 1.1 Source: docs/prds/phase2_prd.md
Phase 2 Governance introduces a policy governance layer to CCH, enhancing explainability, auditability, gradual rollout capabilities, and enterprise readiness. This upgrade evolves CCH from "a powerful local hook system" into "a deterministic, auditable AI policy engine."
LLMs do not enforce policy. LLMs are subject to policy.
- CCH is the policy authority
- Skills are policy authors
- Claude is policy-constrained execution
Comparable to:
- OPA (but human-readable)
- Terraform Sentinel (but local)
- Kubernetes admission controllers (but for agents)
All new features are optional. Existing configurations continue to work unchanged.
As a policy administrator I want to attach metadata to rules documenting their origin and purpose So that I can audit and explain why rules exist
Acceptance Criteria:
- Rules support optional
metadatablock - Metadata fields:
author,created_by,reason,confidence,last_reviewed,ticket,tags - Metadata is ignored by matcher engine (no runtime impact)
- Metadata is included in log entries
- Metadata is displayed by
cch explain rule <name>
Example Configuration:
rules:
- name: block-force-push
metadata:
author: "security-team"
created_by: "aws-cdk-skill@1.2.0"
reason: "Enforce infrastructure coding standards"
confidence: high
last_reviewed: 2025-01-21
ticket: "PLAT-3421"
tags: [security, infra, compliance]
matchers:
tools: ["Bash"]
command_match: "git push.*--force"
actions:
block: trueAs a policy administrator I want to set rules to enforce, warn, or audit mode So that I can gradually roll out policies and test them safely
Acceptance Criteria:
- Rules support optional
modefield:enforce | warn | audit - Default mode is
enforce(current behavior) -
enforce: Normal blocking behavior -
warn: Never blocks, injects warning context instead -
audit: No injection, no blocking, logs only - Mode is included in log entries
- Mode is displayed by
cch explain rule <name>
Mode Behavior Matrix:
| Mode | Blocks? | Injects? | Logs? |
|---|---|---|---|
| enforce | Yes | Yes | Yes |
| warn | No | Warning only | Yes |
| audit | No | No | Yes |
Use Cases:
| Scenario | Mode |
|---|---|
| Rollout new guardrails | audit |
| Soft cultural rules | warn |
| Security policy | enforce |
| Observability only | audit |
As a policy administrator I want to define explicit rule priorities So that I have deterministic control over policy ordering
Acceptance Criteria:
- Rules support optional
priorityfield (integer) - Higher numbers run first
- Default priority is 0
- Rules sorted by: 1) priority (desc), 2) file order (stable)
- Priority is included in log entries
- Priority is displayed by
cch explain rule <name>
Example:
rules:
- name: security-block
priority: 100 # Runs first
actions:
block: true
- name: inject-context
priority: 50 # Runs second
actions:
inject: ".claude/context.md"
- name: log-everything
priority: 0 # Runs last (default)
mode: auditAs a policy administrator I want deterministic conflict resolution between rules So that I can predict policy outcomes
Acceptance Criteria:
- Conflict resolution follows explicit rules (not emergent)
-
enforcemode wins overwarnandaudit - Among same modes, higher priority wins
- Multiple blocks: highest priority block message used
- Conflict resolution logged for debugging
Conflict Resolution Table:
| Situation | Outcome |
|---|---|
| enforce + warn | enforce wins |
| audit + enforce | enforce wins |
| warn only | inject warning |
| audit only | log only |
| multiple enforce | highest priority wins |
As a developer I want to see complete rule details including metadata and activity So that I can understand and debug policy behavior
Acceptance Criteria:
- Command:
cch explain rule <rule-name> - Displays: name, event, mode, priority
- Displays: matchers configuration
- Displays: action configuration
- Displays: full metadata block
- Displays: recent activity (trigger count, block count, last trigger)
- Supports
--jsonoutput format
Example Output:
Rule: no-console-log
Event: PreToolUse
Mode: enforce
Priority: 100
Matchers:
tools: [Edit, Write]
extensions: [.ts, .js]
Action:
run: .claude/validators/no-console-log.py
Metadata:
author: cch-skill
created_by: react-skill@2.1.0
reason: Enforce CLAUDE.md rule
confidence: high
last_reviewed: 2025-01-21
Recent Activity:
Triggered 14 times
Blocked 3 times
Last trigger: 2025-01-20 14:32
As a security auditor I want comprehensive log entries with governance metadata So that I can build dashboards and generate compliance evidence
Acceptance Criteria:
- Log entries include
modefield - Log entries include
priorityfield - Log entries include
metadatablock (if present) - Log entries include
decisionfield (allowed, blocked, warned, audited) - JSON Lines format maintained
- Backward compatible (new fields are additive)
Enhanced Log Entry Example:
{
"timestamp": "2025-01-21T14:32:11Z",
"session_id": "abc123",
"event": "PreToolUse",
"rule_name": "no-console-log",
"mode": "enforce",
"priority": 100,
"decision": "blocked",
"metadata": {
"author": "cch-skill",
"created_by": "react-skill@2.1.0",
"reason": "CLAUDE.md enforcement"
}
}As a security-conscious user I want to mark validators with trust levels So that I can track the provenance of external scripts
Acceptance Criteria:
-
runaction supports optionaltrustfield - Trust levels:
local | verified | untrusted - v1.1: Informational only (no enforcement)
- Trust level logged in entries
- Prepares for future sandboxing/signing
Example:
actions:
run:
script: .claude/validators/check.py
trust: localTrust Level Semantics:
| Trust | Meaning |
|---|---|
| local | User-authored script |
| verified | Signed skill package |
| untrusted | External source |
Rule struct additions:
pub struct Rule {
// Existing fields...
pub name: String,
pub matchers: Matchers,
pub actions: Actions,
// New Phase 2 fields
pub mode: Option<PolicyMode>, // enforce | warn | audit
pub priority: Option<i32>, // Default: 0
pub metadata: Option<RuleMetadata>,
}
#[derive(Default)]
pub enum PolicyMode {
#[default]
Enforce,
Warn,
Audit,
}
pub struct RuleMetadata {
pub author: Option<String>,
pub created_by: Option<String>,
pub reason: Option<String>,
pub confidence: Option<Confidence>,
pub last_reviewed: Option<String>,
pub ticket: Option<String>,
pub tags: Option<Vec<String>>,
}
pub enum Confidence {
High,
Medium,
Low,
}LogEntry struct additions:
pub struct LogEntry {
// Existing fields...
// New Phase 2 fields
pub mode: Option<PolicyMode>,
pub priority: Option<i32>,
pub decision: Option<Decision>,
pub metadata: Option<RuleMetadata>,
}
pub enum Decision {
Allowed,
Blocked,
Warned,
Audited,
}- Rule Sorting: Before matching, sort rules by priority (desc), then file order
- Mode Handling: After match, apply mode-specific behavior
- Conflict Resolution: When multiple rules match, apply resolution logic
- Enhanced Logging: Include all new fields in log entries
Updated cch explain rule command:
- Add
--jsonflag for structured output - Include metadata in output
- Include activity statistics from log analysis
| Metric | Target | Notes |
|---|---|---|
| Processing overhead | < 0.5ms | For mode/priority/metadata handling |
| Memory overhead | < 1KB per rule | For metadata storage |
| Log entry size | < 2KB average | With full metadata |
cd cch_cli
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test- Unit tests for PolicyMode parsing
- Unit tests for priority sorting
- Unit tests for conflict resolution
- Integration tests for each mode behavior
- Integration tests for enhanced logging
- Integration tests for
cch explain rule
| Feature | Required? | Default |
|---|---|---|
| metadata | Optional | None |
| mode | Optional | enforce |
| priority | Optional | 0 |
| trust | Optional | None |
Existing configs work unchanged. All new features use Option with sensible defaults.
- Add PolicyMode enum and parsing
- Add priority field and sorting
- Add RuleMetadata struct and parsing
- Update rule matching to respect priority order
- Update action execution to respect mode
- Extend LogEntry with new fields
- Update log writer to include metadata
- Add Decision enum
- Maintain backward compatibility
- Update
cch explain rulecommand - Add activity statistics
- Add
--jsonoutput format - Update help text
- Add trust field to run action
- Parse and log trust levels
- No enforcement (informational only)
Total Estimated: 5.5-9 days
imports:
- source: "github.com/org/cch-baselines"
version: ">=1.2.0"- Enforce trust levels
- Sandbox untrusted validators
- Signature verification
- Versioned policy repositories
- Central policy management
- Team sharing
| Metric | Target |
|---|---|
| Backward compatibility | 100% existing configs work |
| Performance overhead | < 0.5ms per event |
| Test coverage | > 90% for new code |
| Documentation | Complete for all new features |
| Question | Status | Decision |
|---|---|---|
| Should warn mode inject or just log? | Resolved | Inject warning context |
| Default priority value? | Resolved | 0 |
| Trust level enforcement in v1.1? | Resolved | Informational only |
| Activity stats from log analysis? | Open | Yes, parse recent logs |