agent-enforcement — a pi extension that enforces rules on agents via hooks

A pi extension (Layer 1 of the agent-enforcement system) that enforces declarative rules on the agent it is loaded into, at hook points in the agent's own turn. It is not a skill that asks politely — it checks behavior and acts (warn, steer, mutate, block, rewrite result, auto-continue).

Domain boundary: this extension knows about tools, turns, and sessions. It does not know about Overseers, sentinels, or any higher pattern. Individual rules (authored separately, in YAML) may be about anything. See DESIGN.md for the full design, the hook surface, the enforcement-strength spectrum, and provenance.

Posture: guardrails for honest mistakes, not a jail for adversaries. The extension is co-resident with the agent (loaded by its own pi) and can be unloaded/reloaded like any pi extension. The strongest in-process action is block, which the LLM is told about.

Hooks used

Event Acts
tool_call warn / steer / mutate args / block
tool_result warn / steer / rewrite result
turn_end warn / steer (+ trigger_turn auto-continue, capped by max_repeat)
session_start load the rule store

Rule store

Rules are YAML files loaded at session_start from (priority order):

  1. <cwd>/.agents/enforcement/rules/*.yaml (and parent dirs up)
  2. ~/.agents/enforcement/rules/*.yaml

Project rules take precedence (first definition by id wins). Invalid rules are logged and skipped (fail-safe). A /enforcement command lists loaded rules for debugging.

See rules/ for synthetic format examples and DESIGN.md for the schema. Key when matchers: tool, tool_regex, arg_match, result_match, message_match, no_tool_calls, plus a predicate module escape hatch for conditions too rich to express declaratively. Regexes support a leading (?i) for case-insensitivity (JS RegExp has no inline flags).

The rules corpus is private

The rules/ directory in this repo holds synthetic examples only — fake tool names, fake patterns — that demonstrate the rule schema. They are NOT a live ruleset.

The live rules corpus is private to the deployment. It is not fetched from this repo. It is vendored inside the consuming nixos-configs (private) and reaches every Paseo daemon via the agent-enforcement-rules package + a home.file install to ~/.agents/enforcement/rules/. Rules evolve through PRs to nixos-configs.

Why the engine is public but the rules are not: a public ruleset would let adversaries read the predicates and route around them. The engine (the matcher) is safe to publish; the corpus (what it matches) is not.

Install

As a pi package (the intended distribution path — clones the repo and reads the pi.extensions manifest from the root package.json):

pi install git:https://git.johnogle.info/ash-bot/agent-enforcement.git

The manifest points at ./extension/index.ts; its only runtime dependency is js-yaml (installed from package.json by pi / nix). See PLAN.md for the nix flake-input distribution shape. (You can also drop a hand copy of extension/ into ~/.pi/agent/extensions/agent-enforcement/ for a quick local install.)

Test

Deterministic match-logic test (no LLM, no network) — self-contained: it builds the rule set from the synthetic demo fixtures in test/fixtures/ (fake tool names + fake patterns), so it reveals no posture and does not depend on the host's ~/.agents or a project .agents dir. Run from the repo root:

npm install               # populates node_modules/js-yaml (+ dev types)
node --import /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/node_modules/jiti/lib/jiti-register.mjs test/match.test.mjs
npx tsc --noEmit -p extension/tsconfig.json   # typecheck (needs @types/node)

See TEST.md for the recorded end-to-end proof runs that show the tool_call block fires and reaches the model, the turn_end auto-continue fires and re-triggers (capped at max_repeat), and an MCP tool call can be blocked by name — all against the synthetic demo rules.

S
Description
pi extension that enforces declarative rules on agents via hooks (tool_call/tool_result/turn_end). Engine of the agent-enforcement system.
Readme
108 KiB
0 Stars 1 Watchers 0 Forks
Languages
TypeScript 83.4%
JavaScript 16.6%