Overview
The Allternit Hooks System is the agent operating system’s event-triggered policy and habit layer. It turns operational conventions — “verify specs before editing files”, “ask before running destructive tools”, “escalate ambiguous security decisions” — into executable hooks that run automatically as agents work. Hooks observe events across four layers of the stack, match them against registered handlers, and either allow the action, block it with aSYSTEM_LAW violation, or escalate it to a human approver. Over time, proven habits can be promoted from informal documentation all the way to non-bypassable hard gates through the Habit Promotion Protocol.
The Hooks System is implemented as the allternit-hooks-system Rust crate and is consumed by the kernel, runtimes, and CLI surfaces.
Key concepts
Hook layers
Hooks are organized by scope. Each layer sees a different class of events and enforces a different kind of boundary.Hook events
Every hook is triggered by a typed event. The engine logs the event, finds matching registered hooks, and executes them in priority order.Safety tiers
Tools are classified by how much damage they can cause. The Hooks System uses this tier to decide whether preconditions must be verified before execution.
A
Dangerous or Critical tool invoked without satisfied preconditions is blocked and recorded as a hard SYSTEM_LAW violation.
Tool types
The Hooks System recognizes four tool categories that influence which policy bundle is applied:Read— file or resource inspectionWrite— file creation or mutationDestructive— deletes, renames, or irreversible changesNetwork— outbound calls or tunnel operations
Hook definition
A hook is a small, registered rule. It declares which events it handles, whether it is blocking, and its execution priority.HookResult with blocked: true, a human-readable message, and any SYSTEM_LAW violations that were raised.
Architecture
TheHooksSystemEngine sits between agent runtimes and the two governance engines: allternit-system-law for constitutional violations and allternit-harness-engineering for risk-tiered preflight checks.
- The runtime emits a
HookEvent. - The engine appends it to the event log.
- Enabled hooks whose
event_typesmatch are collected and sorted by priority. - Each hook’s handler runs and produces a
HookResult. - If any blocking hook returns
blocked: true, the underlying action is aborted. - Violations are forwarded to
SystemLawEnginefor persistence and escalation.
Code examples
Register a kernel tool gate
Check a tool invocation
Validate workspace spec presence
Gate task output
Habit Promotion Protocol
Not every convention should start as a hard gate. The Habit Promotion Protocol lets teams graduate a practice through six stages, each one more automated and more rigid than the last.
A habit cannot reach
Hook or HardGate until it passes a determinism test: repeated runs with the same inputs must produce the same decision. Teams must also document failure modes and a rollback plan before final promotion.
Human-layer gates
Some decisions should never be fully automated. The Hooks System provides escalation and approval events that hand control back to a person.Integration with governance engines
The Hooks System does not store constitutional law itself. It delegates hard decisions to two sibling crates:allternit-system-law— records violations, severity, and unresolved hard gates. When a dangerous tool is invoked without preconditions, the hook creates aViolationSeverity::Hardentry under a law such asLAW-TOOL-001.allternit-harness-engineering— evaluates risk tiers, runs preflight checks, and supplies remediation plans. The Hooks System can call into the harness before allowing aDangerousorCriticalaction.
Error codes
Event log
Every event processed by the engine is retained in an append-only log. This log is useful for debugging, auditing, and training new habits.tool_invoke or every human-layer escalation in a session.