gaia-patternslisted
Install: claude install-skill metraton/gaia
# Gaia Code Patterns
Construction patterns for building Gaia components. Every component type follows a discoverable pattern -- read 2-3 existing examples before creating a new one. For the full component inventory, see `reference.md`.
## Prompt -> Result Flow
```
1. User sends prompt
|
2. Orchestrator routes to agent (DB-backed surface_routing table)
|
3. Pre-Tool Hook (pre_tool_use.py)
+-- Inject project context (from ~/.gaia/gaia.db via context_provider.py)
+-- Load skills from frontmatter
+-- Validate permissions
|
4. Agent executes -> returns agent_contract_handoff
|
5. Post-Tool Hook -> audit + metrics
|
6. Orchestrator processes agent_state (APPROVAL_REQUEST / NEEDS_INPUT / COMPLETE)
```
## Hook Patterns
Entry points (`hooks/*.py`) are stdin/stdout glue only. All logic lives in the adapter layer.
```
hooks/pre_tool_use.py -- reads stdin, calls adapter, writes stdout
-> adapters/claude_code.py -- parses event, dispatches to modules
-> modules/security/* -- blocked_commands, mutative_verbs
-> modules/context/* -- context_injector, contracts_loader
-> modules/agents/* -- contract_validator, skill_injection
```
**To add a new module:** Write module in `modules/<package>/`, import and call it from the relevant adapter method. Modules receive parsed context and return results; they never read stdin or write stdout.
**To add a new hook entry point:** Create `hooks/<event_name>.py`, register it in `buil