## Why

The audit-harness repo provides a production-tested 3-layer audit enforcement system for LLM agents — hooks (PostToolUse, Stop, UserPromptSubmit), skills (/start, /end, /recover, /report-daily), and a Python core library (AuditContext). This system solves the #1 pain point for agent-based code analysis tools: context window loss and lack of traceability. Integrating these patterns into boocontext (code scanner) and codecontext (code graph engine) will provide persistent audit trails, context recovery across sessions, and structured operation logs.

The total effort to port the high-value subset is approximately **25-30 person-days**, with the highest ROI being the buffer/flush pipeline and unified index schema for codecontext.

## What Changes

### New Capabilities
- **context-recovery**: Port audit-harness's graded context loading system (L0-L4) into boocontext for LLM context window persistence across code analysis sessions. Each analysis step is recorded to a JSONL buffer, flushed to session trails on completion, and recoverable on session resume.

- **hook-audit-pipeline**: Port the 3 audit hooks (PostToolUse → buffer, Stop → flush to trail, UserPromptSubmit → context injection) into codecontext as MCP server middleware. Every tool call in codecontext's MCP server is automatically logged to an audit trail with timestamps, summaries, and session IDs.

- **session-lifecycle**: Port the /start → /end → /recover → /report-daily skill flow into boocode's command system. /start creates named analysis sessions with context recovery, /end performs integrity checks and generates summaries, /recovers restores lost context through graded loading, /report-daily generates structured work reports from audit data.

### Modified Capabilities
- boocontext's `MCP server` → Add audit middleware layer for automatic tool-call capture
- codecontext's `graph index` → Adopt audit-harness's unified index.json schema for cross-session state tracking

## Capabilities

### New Capabilities
- `context-recovery`: Graded context loading (L0-L4) from persistent audit trails. On session start or `/recover`, loads index summary (~200t), task state (~500t), user corrections (~1000t), or full context (~3000t) depending on need. Prevents rework of already-corrected mistakes.

- `hook-audit-pipeline`: Three MCP middleware hooks: PostToolUse captures tool calls (tool_name, session_id, summary) to audit_buffer.jsonl; Stop flushes buffer + pending to session trail + updates unified index; UserPromptSubmit injects current session context and CRITICAL alerts into every user turn.

- `session-lifecycle`: Named analysis sessions with lifecycle: /start creates session.json + .current_session; /end integrity-checks all records, generates session_summary.md; /recover loads context in increasing detail; /report-daily generates 7-section work reports with operation stats, anomalies, user feedback, backlog.

### Modified Capabilities
- `mcp-server` (boocontext): Add optional audit middleware that intercepts tool calls for logging
- `graph-index` (codecontext): Extend index schema to include audit-compatible session tracking

## Impact

- **boocontext**: Adds ~500 lines of Go/TS for buffer management and hook middleware. No breaking changes — audit is opt-in via configuration.
- **codecontext**: Adds ~300 lines of TypeScript for the unified index schema extension. Backward compatible.
- **boocode**: Adds 4 new commands (/start, /end, /recover, /report-daily), ~400 lines of skill definitions. No existing command breakage.
- **Dependencies**: Python 3.10+ for the audit_context.py core (boocontext already uses Python for tree-sitter); bash for hooks (existing shell tooling). No new external services.
