Metadata-Version: 2.4
Name: hwcc
Version: 0.3.0
Summary: Hardware Context Compiler — transforms hardware docs into AI-optimized context
Project-URL: Homepage, https://github.com/Ecro/hwcc
Project-URL: Repository, https://github.com/Ecro/hwcc
Author: Noel
License-Expression: MIT
License-File: LICENSE
Keywords: ai,context,datasheet,embedded,hardware,mcp,svd
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Embedded Systems
Requires-Python: >=3.11
Requires-Dist: chromadb>=0.5
Requires-Dist: cmsis-svd>=0.6
Requires-Dist: jinja2>=3.1
Requires-Dist: pdfplumber>=0.11
Requires-Dist: pymupdf>=1.24
Requires-Dist: rich>=13.0
Requires-Dist: tiktoken>=0.7
Requires-Dist: tomli-w>=1.0
Requires-Dist: tomli>=2.0; python_version < '3.12'
Requires-Dist: typer>=0.12
Provides-Extra: bench
Requires-Dist: anthropic>=0.40; extra == 'bench'
Requires-Dist: openai>=1.50; extra == 'bench'
Provides-Extra: dev
Requires-Dist: mypy>=1.13; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.8; extra == 'dev'
Provides-Extra: mcp
Requires-Dist: mcp>=1.0; extra == 'mcp'
Description-Content-Type: text/markdown

# hwcc — Hardware Context Compiler

AI coding tools already read everything in your repo — source code, Makefiles, configs. But they can't read the vendor PDF on your desk. They hallucinate register addresses, get init sequences wrong, and miss errata.

**hwcc** fixes this. It transforms hardware documentation (datasheets, SVD files, reference manuals, device trees) into AI-optimized context files that any coding tool can consume — Claude Code, Codex, Cursor, Gemini CLI, or Copilot.

## Install

```bash
pipx install hwcc
```

Or with pip (in a virtual environment):

```bash
pip install hwcc
```

Requires Python 3.11+. No API keys needed — runs 100% locally by default.

## Quick Start

```bash
# Initialize in your project
cd my-firmware-project
hwcc init --chip STM32F407

# Add hardware documentation
hwcc add docs/STM32F407.svd
hwcc add docs/reference-manual.pdf
hwcc add docs/errata.pdf

# Check what's indexed
hwcc status
```

That's it. `hwcc add` automatically compiles context into your `CLAUDE.md` (and other tool files) with hardware register maps, peripheral details, and coding conventions — all between safe `<!-- BEGIN/END HWCC CONTEXT -->` markers that never touch your existing content.

## What It Produces

After `hwcc add`, your project gets:

| File | Tool | Content |
|------|------|---------|
| `CLAUDE.md` | Claude Code | Hardware context section |
| `AGENTS.md` | Codex CLI | Same context, Codex format |
| `.cursor/rules/hardware.mdc` | Cursor | Cursor rules format |
| `.gemini/GEMINI.md` | Gemini CLI | Gemini format |
| `.github/copilot-instructions.md` | GitHub Copilot | Copilot format |

Plus internal context files in `.rag/context/`:
- **`hot.md`** — Concise hardware summary (~120 lines), always loaded
- **`peripherals/*.md`** — Per-peripheral deep context (registers, usage patterns, errata)

## Supported Documents

| Format | What It Extracts |
|--------|-----------------|
| `.svd` | Register maps with bit-fields, reset values, access types |
| `.pdf` | Text + tables from datasheets, reference manuals, errata |
| `.dts` / `.dtsi` | Device tree topology, peripheral nodes, pin configs |
| `.md` / `.txt` | Passthrough (application notes, custom docs) |

## Commands

```
hwcc init [--chip <mcu>]                Initialize project
hwcc add <file> [--type <type>]         Add document(s) to index
hwcc remove <doc_id>                    Remove a document
hwcc status                             Show project status
hwcc compile [--target <tool>]          Regenerate context files
hwcc version                            Show version
```

### Useful Options

```bash
# Add with explicit chip tag (useful for multi-chip projects)
hwcc add power-ic.pdf --chip TPS65217

# Compile for a specific tool only
hwcc compile --target claude

# Skip auto-compile after adding (compile manually later)
hwcc add docs/*.svd --no-compile
```

## Configuration

`hwcc init` creates `.rag/config.toml`:

```toml
[project]
name = "motor-controller"

[hardware]
mcu = "STM32F407VGT6"
mcu_family = "STM32F4"

[software]
rtos = "FreeRTOS 10.5.1"
hal = "STM32 HAL v1.27.1"

[conventions]
register_access = "HAL functions only, no direct register writes"

[embedding]
provider = "chromadb"  # Default: built-in, zero-config

[output]
targets = ["claude", "codex", "cursor", "gemini"]
```

Edit this file to tune what context gets generated.

## Example Output

See [`examples/stm32f407-motor/`](examples/stm32f407-motor/) for a complete sample project with pre-generated output. Key files:

- [`CLAUDE.md`](examples/stm32f407-motor/CLAUDE.md) — User content preserved, hardware context injected between markers
- [`peripherals/spi1.md`](examples/stm32f407-motor/.rag/context/peripherals/spi1.md) — Full SPI1 register map with bit-fields and reset values
- [`peripherals/tim1.md`](examples/stm32f407-motor/.rag/context/peripherals/tim1.md) — TIM1 advanced timer registers

## How It Works

```
Raw Docs → Parse → Chunk → Embed → Store → Compile → Output Files
             |        |       |       |         |
           SVD/PDF  512-tok  ONNX  ChromaDB  Jinja2 templates
           parser   splits   local  vectors   per-tool output
```

All processing is deterministic and local. No LLM calls in the core pipeline. Embedding uses ChromaDB's built-in ONNX model (`all-MiniLM-L6-v2`) — zero configuration needed.

## Why Not Just Give the AI the PDF?

- PDFs are huge (500+ pages). Context windows are expensive and lossy.
- SVD register data is structured — parsing it deterministically is more reliable than LLM extraction.
- Pre-compiled context survives context compaction (Claude Code's auto-compaction can drop raw PDFs).
- RAG is ~1,250x cheaper than stuffing full documents into every prompt.

## Development

```bash
git clone https://github.com/Ecro/hwcc.git
cd hwcc
pip install -e ".[dev]"

pytest tests/           # 675 tests
ruff check src/ tests/  # lint
mypy src/hwcc/          # type check
```

## License

MIT
