/policy-enforce — periodic policy audits for long chats
Long chats are compacted again and again, and an agent can drift from (or forget) requirements you set early on. /policy-enforce keeps a checklist of policy items and, on a trigger you choose, has a task subagent audit the conversation against every item. When the auditor finds a violation, the chat shows a report and interrupts the agent with what it must fix.
Wizard
Bare /policy-enforce (or /policy-enforce-global, which starts in the project scope) opens an editor in the terminal for items, the trigger and the auditor. Both scopes can be edited, and nothing is written until Save; Cancel or Esc discards the changes. Save and audit now also starts an audit.
The auditor model is chosen the way resolve_model finds routes: a registered provider, its auth route (oauth, native or api-key where the provider offers more than one), a filter on model ids, then a thinking level from the chosen model's variants. Only models the route's discovery returns are offered. A discovery failure (for example a missing login) is shown, and no other route or account is tried.
Without a terminal, bare /policy-enforce shows the status; /policy-enforce status always does.
Items
Items are stored exactly like reminders, in two scopes:
/policy-enforce Plan before editing # session item (alias: add <item>)
/policy-enforce-global Never run git reset # project item, shared by every session
/policy-enforce list | remove <n> | clear
/policy-enforce-global list | remove <n> | clearProject items are numbered first, then session items: #1 [project] …, #2 [session] …. Storage: ~/.kompile/conversations/<session>.policies.json and <project>/.kompile/chat-policies.json.
Trigger
/policy-enforce every 10 # every 10 completed turns ("10 turns" also works)
/policy-enforce every 30m # the /loop duration grammar: 90s, 30m, 1h, 2h30m (minimum 1m)
/policy-enforce off # no automatic audits in this session
/policy-enforce reset # drop the session trigger; the project trigger applies
/policy-enforce run # audit nowA session trigger overrides the project trigger (/policy-enforce-global every …). Turns that finish while an audit is running are not counted, and only one audit runs at a time. The turn count restarts after every audit.
With no policy items in either scope nothing is audited, whatever the trigger says: no subagent is launched, turns are not counted (adding the first item starts the count from zero), the interval timer is not armed, and status shows the trigger as inactive. Adding the first item, here or from another chat in the project, activates the trigger; clearing the last one deactivates it. /policy-enforce run with no items says so instead of starting an audit.
Standard chat only: the managed passthrough REPL does not offer /policy-enforce.
Auditor
The auditor is a task subagent launched through the chat's own task tool, so it gets a subagent panel row, follows your permissions, and is subject to /subagent-config model bans and failover.
The auditor setting holds every task argument that picks the child and its route: agent_type or role, model, thinking, provider, authentication_method, and purpose (the workflow purpose, used only while a workflow team is active). Fields left unset inherit the chat's own delegation defaults. The agent type defaults to code-reviewer.
/policy-enforce agent code-reviewer # default
/policy-enforce agent explore-deep model sonnet
/policy-enforce agent role:my-policy-reviewer # run as a role instead of an agent type
/policy-enforce agent model claude-sonnet-4-5 provider anthropic auth oauth thinking high
/policy-enforce agent resetEach agent command replaces the scope's auditor as a whole. A session auditor overrides the project's as a unit. Auth methods and providers are checked when the auditor is set; agent types, roles and model bans are checked when the audit's task runs, and a rejection is reported as a failed audit.
The auditor receives the numbered items, the path of the session transcript (append-only, so it still holds what compaction removed from the live context), and the newest ~60 KB of that transcript inline. It is instructed to stay read-only and to report a violation only with concrete evidence, answering in the enforcer verdict shape (compliant, violations, correction_prompt, severity, reasoning).
Outcomes
Pass — one line:
✓ [policy] audit #3 · 7/7 items OK · code-reviewer · 38s.Violation — a report block, then the agent is interrupted through the same path judge feedback uses (a running turn is cancelled and the fix becomes its hand-off; an idle chat starts a turn). The agent receives a
<kompile_policy_enforcement>block listing each violation with its evidence, the required fixes, and every policy item restated.━━ Policy enforcement · audit #4 · 2 violations ━━ code-reviewer · 41s · every 10 turns ✗ [#2] Plan before editing — edited 3 files with no plan in the last 6 turns ✗ [#5] Never run git reset — ran `git checkout -- Foo.java` ✓ 5 other items OK Fix: Stop editing; present a plan, and restore Foo.java by editing it back. → Interrupting the agent with the required fixesInconclusive — the auditor returned no usable verdict; reported, nothing enforced.
Failed — the subagent could not run (unknown agent type, banned model, …); reported, nothing enforced.
Every audit is also recorded in the session's judgements.jsonl as a POLICY_AUDIT record. /policy-enforce status shows items, trigger, auditor, the last result, and when the next audit is due.
Setting it up through an agent: the policy_enforce tool
The policy_enforce tool (chat, mcp-stdio and the daemon; in the workflow tool group) lets an agent configure all of this, so you can ask it to "set up policy enforcement for this project". It edits the same files as the slash command:
| action | arguments |
|---|---|
status, list | none: items per scope, the effective trigger, and the effective auditor as taskArguments |
add / remove / clear | item / number (from the list order) / none |
set_trigger / reset_trigger | every: 10, 30m, 2h30m, or off |
set_auditor / reset_auditor | agent_type or role, model, thinking, provider, authentication_method, purpose; copy taskArguments from resolve_model |
run | none; audits now, but only in a live chat process |
scope is project (the default: every chat in the project) or session. A session-scope edit applies to session_id, which defaults to the calling session. Over mcp-stdio the calling session is the MCP session, not your chat, so pass your chat's session id or use the project scope. Subagents may inspect the settings (status, list) but not change them.
Web input
/policy-enforce and /policy-enforce-global edit the same item, trigger, and auditor files over web input; bare input shows the status. Audits fire only inside a live chat process, so run over web input reports that and starts nothing.