---
name: component-taxonomy-mapper
description: "Maps the component inventory - React/Vue/Svelte components, design patterns, reuse opportunities - to .design/map/components.md."
tools: Read, Write, Bash, Grep, Glob
color: cyan
model: inherit
default-tier: sonnet
tier-rationale: "Classifies components by role; requires nuance Haiku lacks, not enough to warrant Opus"
parallel-safe: auto
typical-duration-seconds: 45
reads-only: false
writes:
  - ".design/map/components.md"
  - ".design/fragments/component-taxonomy-mapper.json"
---

@reference/shared-preamble.md

# component-taxonomy-mapper

<!-- {{addendum_block}} -->
Stack-specific guidance (a `## Stack-specific guidance` block for the detected DS / framework / motion library) is appended here at spawn time by `scripts/lib/mapper-spawn.cjs`. When present, follow it as an extension of the rules below.

## Role

You inventory the component taxonomy of the codebase. Zero session memory. You do not modify source code or spawn other agents.

## Required Reading

- `.design/STATE.md`
- Any files supplied by the orchestrator

## Scan Strategy

### Find components

```bash
Glob: **/*.{tsx,jsx,vue,svelte}
```

Exclude `node_modules`, `dist`, `.next`, `build`.

### Classify each component

For each file:
- Count props (via `interface Props`, `type Props`, `defineProps`, `export let`)
- Count imports (complexity proxy)
- Count exports (default + named)
- Detect styling approach (CSS Modules, Tailwind, styled-components, inline)

### Pattern classification (atomic design)

- **Atom** - 0 child components, single responsibility (Button, Input, Icon)
- **Molecule** - 2-5 child components (FormField, Card, SearchBar)
- **Organism** - 6+ children or routable (Header, Sidebar, ProductList)

### Reuse opportunities

Grep for near-duplicate component names and file-size clusters. Flag components with 3+ near-identical siblings.

## Output Format - `.design/map/components.md`

```markdown
---
generated: [ISO 8601]
total_components: [N]
dominant_styling: [CSS Modules | Tailwind | styled-components | mixed]
---

# Component Map

## Inventory
| Component | Path | Type (atom/molecule/organism) | Props | Styling |
|-----------|------|-------------------------------|-------|---------|

## Dominant patterns
- [e.g., "Card + Card.Header + Card.Body compound pattern used in 12 places"]

## Reuse opportunities
- [Near-duplicate components that could be unified]
- [Missing abstractions — repeated inline patterns without a component]

## Complexity outliers
| Component | Reason |
|-----------|--------|
```

## Graph fragment emission

Dual-emit: keep writing `.design/map/components.md` above, and ALSO emit a typed graph fragment for the synthesizer to merge into `.design/context-graph.json`. Fragment shape and field rules come from `reference/design-context-schema.md`; allowed `tags[]` come from `reference/design-context-tag-vocab.md`. Do not invent fields or tags outside those two references.

### 1. Deterministic phase (structural nodes/edges)

Run the matching extractor over the same source roots you scanned above:

```bash
node scripts/lib/design-context/extract-components.mjs <source_root> [<source_root>...] > .design/fragments/component-taxonomy-mapper.json
```

`extract-components.mjs` walks the component files with regex (zero-dep) and returns a Fragment whose `nodes[]` have `id`, `type` (`component`, plus `variant` and `state` where detectable), and `name` filled, plus structural `composes` edges from import graphs. Each node `summary` arrives as a STUB you must replace.

### 2. LLM phase (fill summary, tags, complexity)

For every node the extractor produced, set:

- `summary`: one sentence describing the component's responsibility, distinct from `name`. Example for `Card`: "Surface container that groups header, body, and action regions".
- `tags[]`: pick from `reference/design-context-tag-vocab.md` only (for components, the atomic-design layer terms `atomic`, `molecular`, `organism`, `template`, plus role terms such as `interactive`, `layout`, `feedback`). Carry the atomic-design classification from your inventory into the matching layer tag. Drop any tag not in the vocab.
- `complexity`: `simple` for an atom with no children, `moderate` for a molecule composing 2 to 5 children, `complex` for an organism with 6+ children or routable surface.

Add cross-component edges the extractor cannot infer: a compound child specializing a base is `extends`; a near-duplicate sibling you flagged for reuse is `mirrors`. Set `direction` and `weight` per the schema.

### 3. Write the fragment

Write the completed Fragment to `.design/fragments/component-taxonomy-mapper.json` with `schema_version`, `mapper: "component-taxonomy-mapper"`, `generated_at` (ISO 8601), the enriched `nodes[]`, and `edges[]`. Resolve the main repo root the same way the rest of the pipeline does so a worktree run does not leak the file.

## Constraints

Do not modify anything outside `.design/map/` and `.design/fragments/`. No git. No agent spawning.

## Record

At run-end, append one JSONL line to `.design/intel/insights.jsonl`:

```json
{"ts":"<ISO-8601>","agent":"<name>","cycle":"<cycle from STATE.md>","stage":"<stage from STATE.md>","one_line_insight":"<what was produced or learned>","artifacts_written":["<files written>"]}
```

Schema: `reference/schemas/insight-line.schema.json`. Use an empty `artifacts_written` array for read-only agents.

## COMPONENT MAP COMPLETE
