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 a SYSTEM_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.
Events carry enough context for the handler to make a decision without re-querying the runtime: the tool ID and safety tier for tool invocations, the spec type and validity for workspace checks, the escalation reason for human-layer gates, and so on.

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 inspection
  • Write — file creation or mutation
  • Destructive — deletes, renames, or irreversible changes
  • Network — 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.
When a hook blocks an action, it returns a HookResult with blocked: true, a human-readable message, and any SYSTEM_LAW violations that were raised.

Architecture

The HooksSystemEngine 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 flow for a single event:
  1. The runtime emits a HookEvent.
  2. The engine appends it to the event log.
  3. Enabled hooks whose event_types match are collected and sorted by priority.
  4. Each hook’s handler runs and produces a HookResult.
  5. If any blocking hook returns blocked: true, the underlying action is aborted.
  6. Violations are forwarded to SystemLawEngine for 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.
Approval events record who authorized an action and why, producing an audit trail that can be reviewed later:

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 a ViolationSeverity::Hard entry under a law such as LAW-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 a Dangerous or Critical action.
This separation keeps the Hooks System focused on when to evaluate policy and leaves the what of the policy to the dedicated governance layers.

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.
Because the log is scoped by layer and event type, security review tools can quickly surface every blocked tool_invoke or every human-layer escalation in a session.