WaveQ
# WaveQ
[](https://github.com/IshaanDugar/waveq/actions/workflows/ci.yml)
[](LICENSE)
[](https://www.python.org/downloads/)
**Your AI assistant can read code — WaveQ lets it read waveforms too.**
WaveQ is a local [MCP](https://modelcontextprotocol.io/) server and CLI that indexes `.vcd` / `.vcd.gz` files into SQLite, then answers precise questions about signal values, transitions, edges, and clock cycles. Instead of dumping megabytes of raw VCD text into context, your agent gets compact, structured answers — and honest failures when data is missing or ambiguous.
Zero runtime dependencies. Pure Python. Runs entirely on your machine.
See how it works, with diagrams drawn from a real dump: **[ishaandugar.github.io/waveq](https://ishaandugar.github.io/waveq/)**
[](https://ishaandugar.github.io/waveq/)
Built for students, hobbyists and open-source hardware projects (cocotb, Verilator, Icarus, GHDL users): free, local, no accounts.
<!-- mcp-name: io.github.IshaanDugar/waveq -->
## Quick start
**Requirements:** Python 3.10+
**Claude Code** (plugin with the MCP server and a debugging skill):
```text
/plugin install waveq --marketplace IshaanDugar/waveq
```
**Any MCP client**, with [uv](https://docs.astral.sh/uv/) (nothing to install by hand):
```json
{ "mcpServers": { "waveq": { "command": "uvx", "args": ["--from", "git+https://github.com/IshaanDugar/waveq", "waveq", "mcp"] } } }
```
**CLI:** `pip install git+https://github.com/IshaanDugar/waveq`, then `waveq --help`.
**From source:**
```bash
git clone https://github.com/IshaanDugar/waveq.git
cd waveq
python -m venv .venv
# Linux / macOS
source .venv/bin/activate
pip install -e .
# Windows
.\.venv\Scripts\activate
pip install -e .
```
Try the included fixture:
```bash
waveq info examples/sample.vcd
waveq value examples/sample.vcd tb.valid 16ns
waveq digest examples/sample.vcd 30ns 10ns --scope u_apb
```
Start the MCP server (stdio JSON-RPC):
```bash
waveq-mcp
# or: python -m waveq.mcp_server
```
## Connect to your AI tool
WaveQ speaks MCP over stdio. Point any MCP-capable client at `python -m waveq.mcp_server` (or the `waveq-mcp` script after install).
| Client | Setup guide |
|--------|-------------|
| **Cursor** | [docs/install/mcp-clients.md](docs/install/mcp-clients.md#cursor) |
| **Claude Desktop** | [docs/install/mcp-clients.md](docs/install/mcp-clients.md#claude-desktop) |
| **OpenAI Codex** | [docs/install/codex-windows.md](docs/install/codex-windows.md) |
| **Other MCP hosts** | [docs/install/mcp-clients.md](docs/install/mcp-clients.md) |
Example agent prompt once connected:
```text
Use WaveQ on examples/sample.vcd. Check index_status; if query_ready is false,
build_index(level="full"). Resolve clk and reset, define clk as rising-edge clock,
and summarize activity around 10ns.
```
See [AGENTS.md](AGENTS.md) for the recommended tool workflow.
## What it does
- Parse VCD/VCD.GZ into a reusable local SQLite cache
- Resolve fuzzy signal names to exact hierarchical paths
- Query values at a time, changes in a window, edges, and stability
- Summarize a debug window with `window_digest` instead of raw dumps
- Find when conditions held with `find_times` — e.g. every cycle where `valid==1 && ready==1` at a rising clock edge — and sample the payload (address, data) of each match in the same call
- Conditions compare a signal with a constant **or with another signal** (`rs1 != q_rm`), with `== != < <= > >=`, masks, signed compares and bit-selects (`data[7:4]`)
- Ask for a number instead of a dump: `mode="count"`, `"summary"` (count, first/last, payload stats, 3 examples), `"table"` (columns + rows with short names) or `"rows"`
- `check_property`: an offline assertion over clock cycles (`antecedent |-> ##[m:n] consequent`, or "these signals stay stable") that returns counts and the first violations only
- `histogram`: value coverage per clock cycle, optionally filtered and binned
- Debug helpers: `x_report` (where did this X come from?), `activity` (where did a hung design go quiet?), `state_transitions` (FSM summary), `pair_events` (request→response latency and requests that never completed), `explain_time` (what changed around an assertion hit), `diff_summary` / `first_divergence` (where a mutant or failing run differs), `list_scopes` (browse the hierarchy)
- Short names: `set_scope` makes leaf names resolve inside one block, `define_alias` gives signals names that answers then use
- Build a clock cycle index and query by cycle
- Return `ok: false` on missing signals, bad times, or partial batch failures — no silent success
## What it does not do
WaveQ is **not** a simulator, waveform viewer, formal tool, or protocol checker. It reports observed VCD facts; `check_property` checks a rule over the cycles in one dump, which is evidence, not proof. Do not use it alone to prove APB/AHB/AXI correctness, CDC safety, or formal properties. Commercial formats (FSDB, VPD, WLF, SHM) are out of scope: dump VCD from the simulator instead.
## Formats
| Format | Support |
|---|---|
| VCD, `.vcd.gz` | native |
| Extended VCD (`.evcd`, IEEE 1364 port dumps) | native |
| FST (Verilator, Icarus, GTKWave), LXT, LXT2, VZT | converted with GTKWave's open tools (`fst2vcd`, `lxt2vcd`, `vzt2vcd`) when they are on PATH; the result is cached and reused |
| GHW (GHDL) | run GHDL with `--vcd=wave.vcd` or `--fst=wave.fst` |
## How it works
WaveQ is size-aware. Small VCDs may auto-index on configure; larger files stay metadata-only until you explicitly call `build_index`, or pass `index="full"` to `configure_waveform` to index in one call.
| VCD size | Class | Default on `configure_waveform` |
|---------:|-------|----------------------------------|
| < 10 MB | small | May build full indexes |
| 10–50 MB | medium | Metadata only |
| 50–250 MB | large | Metadata only |
| > 250 MB | huge | Metadata only |
On very long runs, index only what you need: `signals=[...]` stores just those signals, and `start` / `end` index just a time window (parsing stops at `end`). Both work on `configure_waveform` and `build_index`, and together they make a 100M-cycle dump practical.
The cache goes in `.waveq_cache` next to the VCD, except when that folder is synced (OneDrive, Dropbox, Google Drive, iCloud) or read-only: then it goes in the per-user cache directory (`%LOCALAPPDATA%\waveq\cache`, `~/Library/Caches/waveq`, or `~/.cache/waveq`). Set `WAVEQ_CACHE_DIR` or pass `cache_dir` to choose explicitly.
Recommended agent workflow:
1. `configure_waveform` (with `index="full"` if you will query it) → 2. `list_scopes` / `resolve_signals(compact=true)` → 3. `set_scope` / `define_alias` → 4. `define_clock` (for cycles) → 5. `explain_time` or `window_digest` near the failure → 6. `find_times`, `pair_events`, `check_property`, `histogram` for questions whose answer is a number
### MCP tools (31)
| Tool | Purpose |
|------|---------|
| `configure_waveform` | Load VCD metadata and cache |
| `index_status` | Check which index levels are ready |
| `build_index` | Build `changes`, `runs`, `edges`, or `full`, for every signal or only the `signals` you name |
| `waveform_info` | Timescale, signal count, time range, aliases, default scope |
| `set_scope` / `define_alias` | Short names: bare leaves resolve inside a scope; aliases name signals in answers |
| `resolve_signals` | Match approximate names to exact paths (`compact=true`: one line each) |
| `value_at` / `values_at` | Signal value(s) at one time |
| `changes` / `changes_many` | Transition lists in a window |
| `edges` / `first_edge_after` | Precomputed edge facts |
| `stable_between` | Held-value check over a range |
| `window_digest` | Compact "what changed here?" summary |
| `find_times` | When/whether conditions held: time intervals, or clock cycles (sampled before the edge), optionally with each match's payload values |
| `check_property` | Offline assertion: whenever the antecedent holds, the consequent follows within `##[m:n]` or signals stay stable; counts and first violations |
| `histogram` | Value coverage per clock cycle, with optional conditions and bins |
| `explain_time` | What changed in a scope within ± N cycles of a time, nearest first, plus x/z there |
| `first_divergence` | Compare two VCD runs and report when and on which signals they first differ |
| `diff_summary` | One row per diverging signal: first divergence and how many cycles (or ticks) differ |
| `define_clock` | Build cycle index from clock edges |
| `time_to_cycle` / `cycle_to_time` | Time ↔ cycle conversion |
| `values_at_cycle` / `changes_by_cycle` | Cycle-based queries (`sample="before"` matches `find_times`) |
| `list_scopes` | Browse the hierarchy with signal counts (metadata only, no index needed) |
| `x_report` | Signals holding x/z at a time, earliest-to-go-unknown first |
| `activity` | Last change per signal and idle signals — where a hung design went quiet |
| `state_transitions` | From→to transition counts and time spent in each value |
| `pair_events` | Pair request/response cycles (in order, or per ID): latency stats, unmatched requests, orphan responses |
### Conditions
```json
{"signal": "qst", "value": 4}
{"signal": "rs1", "op": "!=", "other": "q_rm"}
{"signal": "data[7:4]", "value": "0xa"}
{"signal": "status", "mask": "0x0f00", "op": ">=", "value": "0x0300"}
{"signal": "offset", "signed": true, "op": "<", "value": -4}
```
Conditions in one call are ANDed. A value containing x or z is never equal, less or greater than anything, so only `!=` matches it; ask for it directly with `"value": "x"`. Bit-selects use the declared range (`data[15:8]` on a `[15:8]` vector), and only the selected bits need to be known.
### Output modes
`find_times`, `pair_events`, `changes`, `changes_many` and `edges` take `mode`:
| Mode | Returns |
|---|---|
| `count` | the count, plus the first and last match |
| `summary` | count, first/last, per-payload distinct/min/max/top values, and a few examples as a table (scans every match) |
| `table` | `{"columns": [...], "rows": [[...]]}` with short column names |
| `rows` | one full object per match |
Over MCP, `find_times` and `pair_events` default to `summary` and the change and edge lists to `table`; the engine and CLI default to `rows`.
### Result shape
Success:
```json
{"ok": true, "status": "ok", "summary": "tb.valid=1 at 16ns", "data": {}, "confidence": 1.0}
```
Failure (batch tools do not hide partial errors):
```json
{"ok": false, "status": "partial_failure", "summary": "One or more signal lookups failed", "confidence": 0.0}
```
### Time syntax
Raw ticks (`42`) or unit times (`42ns`, `1.5us`). Unit times convert exactly via rational arithmetic — non-integral ticks fail instead of rounding silently.
## Performance
Synthetic benchmarks on a typical dev laptop (Windows, Python 3.x). Regenerate anytime:
```bash
python benchmarks/benchmark_waveq.py --output reports
```
### Query speed (median, after full index)
| Case | VCD size | Signals | Changes | `value_at` | `values_at` ×8 | `window_digest` | Cache reuse |
|------|---------:|--------:|--------:|-----------:|---------------:|----------------:|------------:|
| small | 45 KB | 32 | 6,871 | 0.06 ms | 0.49 ms | 5.6 ms | 1.6 ms |
| medium | 12.6 MB | 128 | 92,815 | 0.06 ms | 0.47 ms | 6.1 ms | 1.5 ms |
| large | 55.0 MB | 32 | 6,871 | 0.06 ms | 0.47 ms | 5.9 ms | 1.4 ms |
### Index build cost (one-time per VCD)
| Case | `configure_waveform` | Query-ready after configure? | Full `build_index` |
|------|---------------------:|------------------------------|-------------------:|
| small | 72 ms | yes (auto-indexed) | 57 ms |
| medium | 27 ms | no (metadata only) | 672 ms |
| large | 32 ms | no (metadata only) | 148 ms |
Large files stay metadata-only at configure time — you pay for indexing only when you need it.
### Why this matters for AI-assisted debug
| Without WaveQ | With WaveQ |
|---------------|------------|
| A **12 MB VCD** is millions of tokens — it cannot fit in any agent context window | `window_digest` returns a **compact JSON summary** in ~6 ms |
| Agent reads raw text, guesses signal hierarchy, may silently miss data | `resolve_signals` + `values_at` return **exact paths and values** with `ok: false` on failure |
| Re-parsing the same VCD on every question | SQLite cache **reattaches in ~1.5 ms** — index once, query many times |
| 8 separate signal lookups = 8 file scans | `values_at` / `changes_many` batch **8 signals in under 1 ms** |
| "What happened near the failure?" → dump entire time range | `window_digest(center, radius)` returns only what changed in that window |
**Rule of thumb:** after the one-time index build, point queries are sub-millisecond and debug-window summaries land in single-digit milliseconds — even on 50+ MB files. The real win is not raw speed alone; it is making waveform evidence **queryable and context-sized** for an AI agent instead of dumping unusable VCD text.
## CLI reference
```bash
waveq info <vcd>
waveq configure <vcd>
waveq index-status <vcd>
waveq build-index <vcd> --level full [--signals tb.clk tb.valid tb.data] [--start 1ms --end 2ms]
waveq resolve <vcd> <query> [--compact]
waveq value <vcd> <signal> <time>
waveq values <vcd> <time> <signal> [...]
waveq changes <vcd> <signal> <start> <end>
waveq edges <vcd> <signal> --kind rise --start 0ns --end 50ns
waveq digest <vcd> <center> <radius> [--scope <hier>]
waveq find <vcd> "tb.valid==1" "tb.ready==1" [--clock tb.clk] [--sample before|at] [--limit N] [--payload tb.data] [--mode count|summary|table|rows]
waveq find <vcd> "tb.rs1!=@tb.q_rm" "tb.data&0xf0>=0x30" --clock tb.clk --mode count # @ = another signal, &MASK
waveq check <vcd> --clock tb.clk --if "tb.req==1" --then "tb.ack==1" --delay "##[1:4]"
waveq check <vcd> --clock tb.clk --if "tb.busy==1" --stable tb.addr tb.len
waveq hist <vcd> tb.state --clock tb.clk [--when "tb.valid==1"] [--bins 0:7 8:max]
waveq explain <vcd> 1397245ns --clock tb.clk --scope u_core [--cycles 2]
waveq diffsum <vcd_a> <vcd_b> [--clock tb.clk] [--signals ...]
waveq scopes <vcd> [prefix] [--max-depth N]
waveq xreport <vcd> [--time 500ns] [--scope u_core]
waveq activity <vcd> [--start 0ns] [--end 1us] [--scope u_core] [--ignore tb.clk]
waveq transitions <vcd> tb.u_fsm.state
waveq pair <vcd> --clock tb.clk --request "tb.arvalid==1" "tb.arready==1" --response "tb.rvalid==1" "tb.rready==1" "tb.rlast==1" [--request-id tb.arid --response-id tb.rid]
waveq diff <vcd_a> <vcd_b> [--signals ...] [--scope S] [--start T] [--end T] [--limit N] [--other-cache-dir DIR]
```
## Development
```bash
python -m py_compile waveq/*.py # PowerShell: py_compile (Get-ChildItem waveq\*.py)
python -m unittest discover -s tests -v
python benchmarks/benchmark_waveq.py --output reports # optional; writes to reports/
```
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
## Repository layout
```text
waveq/ VCD parser, SQLite indexer, query engine, MCP server, CLI
tests/ Unit and MCP behavior tests
benchmarks/ Synthetic VCD performance + correctness checks
examples/ Sample VCD and smoke commands
docs/install/ MCP client setup guides
```
## License
GNU Affero General Public License v3.0 or later — see [LICENSE](LICENSE).
WaveQ is free for everyone to use, study, change and share. If you distribute a modified version, or run one as a service for others, you must publish your source under the same license.
Originally developed by Ishaan Dugar during an internship at Ambiq Micro. Ambiq Micro is not the author or maintainer of this project.
## Contributing
Issues and pull requests welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
TDQS
Scored across 18 tools
Each tool has a clearly distinct purpose, from indexing to querying values, edges, cycles, and batch operations. Even the similar tools like changes, changes_by_cycle, and changes_many are differentiated by their parameters and use cases.
Most names follow a verb_noun pattern (build_index, configure_waveform, resolve_signals), but there are exceptions like 'changes' and 'edges' which are nouns alone. The mix is minor and still readable.
18 tools cover the waveform analysis domain comprehensively without being excessive. Each tool serves a specific need, from indexing to batch queries and metadata retrieval.
The tool set covers all essential operations for VCD waveform analysis: configuration, indexing, value retrieval, edge detection, cycle mapping, batch operations, and metadata. No obvious gaps for the intended purpose.