---
name: router
description: Project navigation hub. Read at the start of every session. Contains current state, routing table, and task protocol.
edges:
  - target: context/architecture.md
    condition: when working on system design, integrations, or understanding how components connect
  - target: context/stack.md
    condition: when working with specific technologies, libraries, or making tech decisions
  - target: context/conventions.md
    condition: when writing new code, reviewing code, or unsure about project patterns
  - target: context/decisions.md
    condition: when making architectural choices or understanding why something is built a certain way
  - target: context/setup.md
    condition: when setting up the dev environment or running the project for the first time
  - target: patterns/INDEX.md
    condition: when starting a task — check the pattern index for a matching pattern file
last_updated: 2026-04-07
---

# Project Context

If you haven't already read `AGENTS.md`, read it now — it contains the project identity, non-negotiables, and commands.

Then read this file fully before doing anything else in this session.

## Current Project State

CAI v2.0 — production-ready, published to npm as `@temroi/cai`.

**Working:**
- Drift detection: 10 checkers (`cai check`), deterministic, <100ms
- Auto-fix: `cai fix` — tool-config sync, pattern index rebuild, path normalization
- MCP server: 6 tools (`cai_list_context`, `cai_get_context`, `cai_search`, `cai_check_drift`, `cai_context_for_task`, `cai_pattern_suggest`)
- Token-aware context routing: `cai_context_for_task` — returns most relevant sections within a token budget
- Back-pressure: `cai verify` — typecheck + build + drift, installs as Claude Code Stop hook
- Hot-path weighted scoring + drift trend history (`cai check --history`)
- Correction learning: `cai learn` — records prompts, clusters corrections, writes CLAUDE.md rules (enabled by default since v1.5)
- Pattern library: global `~/.cai/`, content-hashed, `cai pattern share/suggest/install`
- Auto-pattern from commits: `cai pattern recurring [--write]`
- Code map: `cai codex` (tree-sitter for TS/JS/Python/Go/Rust)
- Session context hook: `cai session --auto` (UserPromptSubmit)
- All major AI tool configs: Claude Code, Cursor, Windsurf, Copilot, OpenCode

**Known issues:**
- Staleness checker slow on repos with deep git history — use `--fast` or `--skip staleness` in CI

## Routing Table

Load the relevant file based on the current task. Always load `context/architecture.md` first if not already in context this session.

| Task type | Load |
|-----------|------|
| Understanding how the system works | `context/architecture.md` |
| Working with a specific technology | `context/stack.md` |
| Writing or reviewing code | `context/conventions.md` |
| Making a design decision | `context/decisions.md` |
| Setting up or running the project | `context/setup.md` |
| Any specific task | Check `patterns/INDEX.md` for a matching pattern |

## Task Protocol

For every task, follow this loop:

1. **ORIENT** — Use `cai_search` first to find relevant facts before loading full files. If you need more detail, load with `mode: summary`, then `mode: full` only if necessary. Check `patterns/INDEX.md` for a matching pattern. If one exists, follow it. Note which files you loaded.
2. **EXECUTE** — Do the work. If a pattern exists, follow its Steps. If you are about to deviate from an established pattern, say so before writing any code — state the deviation and why.
3. **CHECK** — Load `context/conventions.md` and run the Verify Checklist item by item. State each item and whether the output passes. Do not summarise — enumerate explicitly.
4. **DIAGNOSE** — If verification fails or something breaks, check `patterns/INDEX.md` for a debug pattern. Follow it. Fix the issue and re-run CHECK.
5. **UPDATE** — After completing the task:
   - If no pattern exists for this task type, create one in `patterns/` using the format in `patterns/README.md`. Add it to `patterns/INDEX.md`.
   - If a pattern exists but you deviated from it or discovered a new gotcha, update it with what you learned.
   - If any `context/` file is now out of date because of this work, update it surgically — do not rewrite entire files.
   - Update the "Current Project State" section above if the work was significant.
