# Agent Prime

Cross-IDE context injection via a three-layer architecture.

## Layers

1. **AGENTS.md** (static) — `.beadloom/AGENTS.md` with MCP tool list, architecture rules, conventions. Regenerated by `generate_agents_md()`, preserves content below `## Custom` marker.

2. **IDE adapters** (pointers) — `.cursorrules`, `.windsurfrules`, `.clinerules` files that instruct agents to read AGENTS.md. Created by `setup_rules_auto()` on bootstrap.

3. **`beadloom prime`** (dynamic) — CLI command and MCP tool that queries the DB for current project state: architecture summary, stale docs, lint violations, domain list.

## API

### `prime_context(project_root, *, fmt="markdown")`

Returns compact project context. Static layer (config, rules, AGENTS.md) always available. Dynamic layer (DB queries) degrades gracefully without DB.

- `fmt="markdown"` — human-readable output (~1000-1500 tokens)
- `fmt="json"` — structured dict for programmatic use

### `setup_rules_auto(project_root)`

Auto-detects IDEs by marker files and creates adapter files. Returns list of created file paths.

### `generate_agents_md(project_root)`

Generates `.beadloom/AGENTS.md` with v2 template. Injects rules from `rules.yml`. Preserves user content below `## Custom`.

## CLI

- `beadloom prime [--json] [--update] [--project PATH]`
- `beadloom setup-rules [--tool cursor|windsurf|cline] [--project PATH]`

## MCP

- `prime` tool (no parameters) — returns JSON context for agent sessions

## Source

- `src/beadloom/onboarding/scanner.py` — `prime_context()`, `setup_rules_auto()`, `generate_agents_md()`
- `src/beadloom/services/cli.py` — `prime` and `setup-rules` commands
- `src/beadloom/services/mcp_server.py` — `prime` MCP tool
