Policy Enforcer
The enforcer evaluates every agent response against project rules and can interrupt mid-stream, auto-rollback file changes on violations, and retry with correction prompts.
Interactive Setup Wizard (Recommended)
You do not need to hand-edit .kompile/enforcer-config.json or memorize CLI flags. Launch the guided numbered setup wizard (EnforcerSetupWizard) from the terminal or directly inside kompile chat:
# From the terminal (either command launches the same wizard)
kompile configure enforcer
kompile enforcer init
# Or via the master numbered configuration menu (choose option 6: Enforcer)
kompile configureInside an active kompile chat session:
/enforcer # (or /judge) opens the numbered Enforcer & Judge control menu (option 1 runs the setup wizard)
/enforcer init # (or /judge init) jumps directly into the setup wizardRunning /enforcer or /enforcer init inside chat reuses your active terminal, saves .kompile/enforcer-config.json, and reloads the active session's judge immediately (when there is no interactive terminal, bare /enforcer prints status).
What the Wizard Walks You Through
The default flow is intentionally short (2–3 quick prompts), with optional settings tucked behind a single advanced options prompt:
- Subordinate agent (terminal only; skipped automatically inside chat where the session agent is already known) — numbered picker of CLI agents detected on
PATH(claude,codex,gemini,qwen,opencode,aider). - Evaluation mode (numbered):
1) Keyword mode— instant pattern matching, no LLM needed (recommended for most cases).2) LLM judge— full LLM evaluation of agent output.
- Advanced options gate (
Configure advanced options? [y/N]):- Default
Njumps straight to Banned tools & commands/keywords, saves.kompile/enforcer-config.json, and prints a summary. - Choosing
yadditionally guides you through:- Rules (numbered):
1) Enter rules interactively,2) Point to an existing rule file,3) Create a new rule file (.kompile/enforcer-rules.txt template), or4) Skip - Diff patterns (regexes checked against file diffs)
- Diff archiving & auto-rollback
- Judge backend settings (when LLM judge mode is selected)
- Semantic matching (synonym/embedding paraphrase expansion)
- Max correction retries
- Rules (numbered):
- Default
Once configured, start a standalone enforcer session with bare kompile enforcer (no flags needed — it reads .kompile/enforcer-config.json), or re-run kompile enforcer init / /enforcer init anytime to reconfigure.
Rule Types
| Type | Description |
|---|---|
STOP_CMD | Block specific shell commands |
BAN_CMD | Prevent command execution |
BAN_TOOL | Block a specific tool ID |
BAN_DIFF_REGEX | Catch banned code patterns in file diffs |
| LLM judge | Use an LLM to evaluate responses against custom criteria |
| Deflection monitor | Deterministic ownership-mandate lane: flags "not my error" style claims made without receipts |
Deflection Monitoring (Opt-In)
The deflection monitor is a separate, deterministic lane (no LLM) that catches behavioral deflection: an agent asserting non-ownership — "not my error", "out of scope", "pre-existing issue", "works on my machine" — without receipts. The same phrasing is allowed when the agent shows evidence (executed git log, a test run, file:line references, incident IDs, or a recorded handoff), so legitimate "pre-existing, here's the proof" answers pass.
Enable it conversationally in chat ("Turn on deflection monitoring in report-only mode with receipts required") — the agent updates .kompile/enforcer-config.json via enforcer_config — or manage it with /deflection status | reload | help:
- Report-only first (
deflectionReportOnly, defaulttrue): Logs what would fire without correcting — review/judge judgementsforDEFLECTIONrecords, then ask the agent to switch enforcement on (deflectionReportOnly=false). - Pattern vs. semantic mode (
deflectionMode): Defaults to deterministicpatternmatching;semanticadditionally enables synonym/embedding paraphrase matching (configurable confidence threshold, max corrections, cross-turn limit, extra patterns, and whitelist phrases). - Ownership mandate on violation: The agent must run one diagnostic now, classify with evidence, and if genuinely out of scope, cite the artifact + owner and record the handoff. Repeated deflection escalates to an evidence-first mandate, then blocks the turn.
Design and test contract: docs/architecture/enforcer-deflection-design.md.
Non-Interactive & Scripting Flags (CI / Automation)
All wizard options also accept explicit flags for scripts and CI pipelines:
# Non-interactive project config initialization
kompile enforcer init --keyword-mode \
--ban-keyword "pre-existing" \
--ban-keyword "preexisting" \
--max-corrections 3
# Inspect or delete saved project config
kompile enforcer init --show
kompile enforcer init --delete
# Ad-hoc standalone enforcer run with inline overrides
kompile enforcer --agent=claude \
--rules="STOP_CMD: git push --force" \
--rules="BAN_DIFF_REGEX: password\s*=\"[^\"]+\"" \
--max-corrections=3Behavior
- Evaluates every agent response against all active rules
- Can interrupt mid-stream on violations
- Auto-rollback file changes when a violation is detected (archived under
.kompile/enforcer-archive/) - Retries with correction prompts up to
--max-correctionstimes --diff-patternscatches banned code patterns in file diffs