Skip to content

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 bare kompile 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_config tool).

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 patternWhy it is blockedCompliant Kompile tool
sed -i, perl -i/-pi, awk -i inplaceIn-place rewrites bypass read-before-edit and diff indexingedit, edit_batch, edit_patch
Output redirects (>), tee, touch, truncate, patchShell writes bypass managed file/memory trackingwrite, edit, patch, memory
Shell access to Kompile or provider memory pathsPrevents corrupting managed memory outside index/lock rulesmemory
grep, egrep, fgrep, rg, ag, ack (even in pipelines/stdin)Bypasses bounded search and cached handlesgrep, 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 viewsread, read_batch, fetch_result, process action=output
sed (on files, pipelines, or stdin)Bypasses structured search and exact editsgrep / read / edit
lsUnstructured directory scrapinglist
find, fd, locateUnbounded recursive traversalglob
Shell loops (for, while, until, select) & sleep pollingBurns CPU/turns polling instead of reactive wakeupsprocess 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/null and equivalent forms that create no file artifact.
  • Input redirection: <, heredocs, and - stdin placeholders (except when feeding banned sed/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:

EnforcerWhat it blocks in shell/process callsCompliant pathConfig / 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. executionRegister 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 locksHarness 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 copiesdraft / 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.json means ON).
  • Before delivering a final response to the user, the agent must complete at least one successful memory tool call with action=recall in that same turn (a recall returning zero matches still counts; action=save does not satisfy recall).
  • Enforced across all three runtime surfaces:
    1. Standard agentic chat loop (native models + streaming vendor routes).
    2. Emulated passthrough (from the vendor's parsed tool-use stream).
    3. Claude Code's native Stop hook (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 MANDATE correction (bounded to DEFAULT_MAX_CORRECTIONS = 2, hard max 4).

Opting out:

text
/judge memory off

Or 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:line references, incident IDs, or a recorded handoff).
  • Safe rollout: defaults to deflectionReportOnly: true so you can inspect DEFLECTION verdicts in /judge judgements before 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 + custom deflectionExtraPatterns / deflectionWhitelistPhrases) or semantic (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.

Released under the Apache-2.0 License.