## Mechanical Enforcement & Lifecycle Guardrails (3-Tier Hook Architecture)
In agentic frameworks (Claude Code, Gemini Antigravity, AGY CLI), an agent cannot exit a turn without passing through configured lifecycle guardrails. `rule 00-instinct` is mechanically enforced via three complementary hook mechanisms before every turn-ending response:
### 1. Turn-End Audit Hook (`Stop` / `PostInvocation` Event)
- **Execution Lifecycle**: When the agent finishes tool execution and attempts to conclude its turn (`Stop` or `PostInvocation`), the runtime intercepts the event before delivering the response to the user.
- **Verification Logic**:
1. The hook script reads the active conversation transcript (`transcript.jsonl`) to extract the user's exact instruction and the agent's actions/claims.
2. It performs a ground-truth sanity check against the filesystem (e.g., comparing claims of "deleted artifacts" against actual `git status` or file existence).
3. In `judge` mode, it invokes an independent fast model (e.g., Haiku or Gemini Flash) to audit whether the agent made unverified assertions, deviated from constraints, or engaged in unprompted scope creep.
- **Blocking Mechanism**: If a discrepancy or unconfirmed claim is detected, the hook outputs `{"decision": "continue", "reason": "
### 2. Pre-Generation Ground-Truth State Injection (`PreInvocation` Event)
- **Execution Lifecycle**: Fires immediately before the model generates its response or tool calls.
- **Verification Logic**:
- Automatically queries lightweight ground-truth states (e.g., `git status --short`, active background processes, modified file list).
- Injects this data as an `ephemeralMessage` into the prompt context:
```json
{
"injectSteps": [
{
"ephemeralMessage": "MANDATORY RULE 00-INSTINCT PREFLIGHT: Verify all claims against primary ground truth. Uncommitted files: [list], Active processes on port 30975: [none]."
}
]
}
```
- Eliminates hallucinations regarding file existence before the model begins formulating affirmative statements.
### 3. Pre-Action Risk Blocker (`PreToolUse` Event)
- **Execution Lifecycle**: Inspects every pending mutating tool call (`run_command`, `write_to_file`, `replace_file_content`) before execution.
- **Verification Logic**:
- Deterministically catches unconfirmed destructive actions, unauthorized git commits, or out-of-scope code generation during plan-only phases, prompting for explicit user confirmation (`"permissionDecision": "ask"`).
### Reference Implementation & Runtime Activation
- **Canonical Script**: [`hooks/intent-guard/intent-guard.mjs`](../hooks/intent-guard/intent-guard.mjs) (or `~/agentic//hooks/intent-guard/intent-guard.mjs`).
- **Registered Events**: `PreToolUse` (risk gate) and `Stop` (turn-end audit).
- **Runtime Activation**:
- **Claude Code**: Merged into `~/.claude/settings.json` under the `hooks` key or via `~/agentic//hooks/_plugin`.
- **Antigravity / Gemini**: Configured in `.agents/hooks.json` or `~/.gemini/config/hooks.json` under `Stop` and `PreInvocation`.
## Relationship to Other Rules & Precedence
This rule outranks all other global rules (`rule 01-language-english`, `rule 02-korean-verb-usage`, `rule 04-meta-labels`, `rule 11-evidence-required`, `rule 12-tech-versions`). It serves as the upstream guard for `rule 11-evidence-required` §3 by prohibiting silent completion of unverified states. This is the highest-priority rule in the system; only the user's explicit direction lifts a stop.