The Enforcer (Deterministic Policies)
Kompile's Enforcer plane is the hard, deterministic layer that runs before tool calls execute and before a turn finishes. Unlike the LLM Judge, deterministic enforcers use no LLM, add sub-millisecond overhead, and fail closed — closing the gap where prompt instructions and probabilistic judges let shell workarounds slip through.
The same deterministic policy (ShellMandatePolicy) is wired into every tool-validation path: MCP stdio & daemon sessions (EnforcerToolCallGuard), inline judge evaluation (EnforcerJudge), inline keyword evaluation (KeywordEnforcerEvaluator), and native provider PreToolUse hooks (ShellMandateHook).
Configure With the Guided Wizard (No Hand-Editing Required)
To set up project enforcer rules interactively without typing flags or editing JSON:
- In the terminal: run
kompile configure enforcer,kompile enforcer init, or barekompile configure(option 6 — Enforcer). - Inside
kompile chat: run/enforcer init(or/judge init) to launch the numbered setup wizard and reload immediately. - Via an agent: describe the rule in plain English (
enforcer_configtool).
See Policy Enforcer CLI & Wizard for the full step-by-step wizard walkthrough.
1. Shell Mandate (ShellMandatePolicy)
Dedicated Kompile tools give you structured diffs, read-before-edit safety, multi-agent edit locks, cached large-result handles (ref:ID), and searchable audit logs. When an agent invokes a shell tool (bash, process, or a vendor shell equivalent) to bypass those tools, ShellMandatePolicy blocks the call and tells the agent which compliant tool to use.
What Is Blocked
| Blocked shell pattern | Why it is blocked | Compliant Kompile tool |
|---|---|---|
sed -i, perl -i/-pi, awk -i inplace | In-place rewrites bypass read-before-edit and diff indexing | edit, edit_batch, edit_patch |
Output redirects (>), tee, touch, truncate, patch | Shell writes bypass managed file/memory tracking | write, edit, patch, memory |
| Shell access to Kompile or provider memory paths | Prevents corrupting managed memory outside index/lock rules | memory |
grep, egrep, fgrep, rg, ag, ack (even in pipelines/stdin) | Bypasses bounded search and cached handles | grep, grep_batch, fetch_result(pattern=...) |
cat, head, tail, less, more, tac on files (and head/tail output slicing) | Bypasses line-numbered reads and paged log views | read, read_batch, fetch_result, process action=output |
sed (on files, pipelines, or stdin) | Bypasses structured search and exact edits | grep / read / edit |
ls | Unstructured directory scraping | list |
find, fd, locate | Unbounded recursive traversal | glob |
Shell loops (for, while, until, select) & sleep polling | Burns CPU/turns polling instead of reactive wakeups | process action=launch + monitor / host wakeups |
What Stays Deliberately Allowed
Kompile does not ban bash outright. The following pass ShellMandatePolicy and proceed to normal permission and judge checks:
- Filesystem administration with no dedicated tool:
rm,rmdir,mv,cp,ln,mkdir,chmod,chown. - System & version-control commands:
git, service management, diagnostics. - Non-search piped filters: e.g.
ps aux | awk '{print $2}'. - Null-device suppression:
2>/dev/nulland equivalent forms that create no file artifact. - Input redirection:
<, heredocs, and-stdin placeholders (except when feeding bannedsed/grep).
2. The Four Toggleable Specialized Enforcers
Wired directly inside ShellMandatePolicy.analyzeSegment, four specialized policies enforce project hygiene and resource safety. All four are on by default and can be toggled in ~/.kompile/harness-config.json or via environment variables:
| Enforcer | What it blocks in shell/process calls | Compliant path | Config / toggle |
|---|---|---|---|
Build Enforcer (BuildEnforcerPolicy) | Direct mvn, gradle, make, cmake, npm, cargo, etc. | build tool (validates command and records .kompile/build-provenance/) | ~/.kompile/harness-config.json or env toggle |
Script Enforcer (ScriptEnforcerPolicy) | Ad-hoc inline python, node, java, perl, etc. execution | Register with script_manager, run with script | ~/.kompile/harness-config.json or env toggle |
Lane Enforcer (LaneEnforcerPolicy) | flock, lockfile, dotlockfile, lckdo, setlock, with-lock-ex, and out-of-project scripts taking private locks | Harness resource admission (.kompile/resource-policy.json, /resources) | ~/.kompile/harness-config.json or env toggle |
Draft Enforcer (DraftEnforcerPolicy) | Out-of-tree backup copies, staging overlays, and manual diff3 merge scratch copies | draft / draft_batch (create, revise, rebase, apply, revert) | draftEnforcerEnabled: false in ~/.kompile/harness-config.json |
3. OS /tmp Write Redirect (OsTmpWritePolicy)
Native file mutations and non-read-only shell commands targeting /tmp are blocked by OsTmpWritePolicy. Kompile exports a per-session scratch directory as $TMPDIR (~/.kompile/conversations/<id>/tmp), which is automatically swept by SessionTmpGcTarget so abandoned scratch files never accumulate in system /tmp.
4. Memory-Before-Response Mandate (MemoryResponseMandate)
Agents frequently ignore persistent memory unless forced to query it. Kompile's MemoryResponseMandate is a deterministic turn-end gate (no LLM):
- On by default (a missing
.kompile/enforcer-config.jsonmeans ON). - Before delivering a final response to the user, the agent must complete at least one successful
memorytool call withaction=recallin that same turn (a recall returning zero matches still counts;action=savedoes not satisfy recall). - Enforced across all three runtime surfaces:
- Standard agentic chat loop (native models + streaming vendor routes).
- Emulated passthrough (from the vendor's parsed tool-use stream).
- Claude Code's native
Stophook (MemoryResponseHook), holding the turn open inside Claude Code itself during raw passthrough.
- If the agent tries to finish without recalling, the turn stays open with a
[kompile] MEMORY MANDATEcorrection (bounded toDEFAULT_MAX_CORRECTIONS = 2, hard max4).
Opting out:
/judge memory offOr via MCP / config: enforcer_config set field=memory_before_response value=false (persisted in .kompile/enforcer-config.json for a project or ~/.kompile/config/enforcer-config.json globally).
5. Deflection Monitor (DeflectionMonitor, Opt-In)
The deflection monitor is a separate deterministic (non-LLM) behavioral gate that catches receipt-less excuses — claims like "not my error", "pre-existing issue", "out of scope", or "works on my machine" made without concrete evidence.
- Evidence passes: the exact same phrasing is allowed when backed by receipts (an executed
git log, a test run,file:linereferences, incident IDs, or a recorded handoff). - Safe rollout: defaults to
deflectionReportOnly: trueso you can inspectDEFLECTIONverdicts in/judge judgementsbefore switching to active enforcement (deflectionReportOnly: false). - Escalation ladder: first violation injects an ownership mandate (run a diagnostic or cite the artifact + owner); repeated deflection escalates to an evidence-first mandate, then blocks the turn.
- Modes:
pattern(deterministic phrase library + customdeflectionExtraPatterns/deflectionWhitelistPhrases) orsemantic(adds WordNet/embedding paraphrase matching).
Enable in .kompile/enforcer-config.json and manage in chat with /deflection status | reload | help. See Policy Enforcer CLI for the full JSON schema.