Skip to content

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.

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:

bash
# 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 configure

Inside an active kompile chat session:

text
/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 wizard

Running /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:

  1. 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).
  2. 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.
  3. Advanced options gate (Configure advanced options? [y/N]):
    • Default N jumps straight to Banned tools & commands/keywords, saves .kompile/enforcer-config.json, and prints a summary.
    • Choosing y additionally 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), or 4) 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

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 ​

TypeDescription
STOP_CMDBlock specific shell commands
BAN_CMDPrevent command execution
BAN_TOOLBlock a specific tool ID
BAN_DIFF_REGEXCatch banned code patterns in file diffs
LLM judgeUse an LLM to evaluate responses against custom criteria
Deflection monitorDeterministic 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, default true): Logs what would fire without correcting — review /judge judgements for DEFLECTION records, then ask the agent to switch enforcement on (deflectionReportOnly=false).
  • Pattern vs. semantic mode (deflectionMode): Defaults to deterministic pattern matching; semantic additionally 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:

bash
# 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=3

Behavior ​

  • 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-corrections times
  • --diff-patterns catches banned code patterns in file diffs

Released under the Apache-2.0 License.