Ripple
# Ripple
**See what a change ripples into before you make it.**
Coding agents read files; they don't see connections. Ripple turns a Python repository into a local [Relate](https://relatedb.ai) graph — functions, calls, tests, runtime coverage and git history in one embedded store — so an agent (or you) can ask, before touching a function:
- **What breaks if I change it?** — every transitive caller, not just the ones `grep` finds
- **Which tests prove it still works?** — tests that reach it through the call graph *and* tests that actually executed it
- **Who should review the change?** — the authors of its current lines
- **What is dead, untested, or tangled?** — dead code, untested code, import cycles
Everything runs locally: Relate is an embedded graph database (a library, no server, no account), and the agent is Claude Code talking to Ripple over MCP. No API keys required.
Built for the [Relate by Neo4j Hackathon](https://relate.devpost.com/) — theme *Context, Connected*.
**Demo video (1.5 min):** https://www.youtube.com/watch?v=DZOcLVNHOnk
---
## Quick start (3 commands)
Requires Python ≥ 3.10 and git.
```bash
git clone https://github.com/andreivasilache/ripple.git && cd ripple
uv venv && uv pip install -e . # or: python3 -m venv .venv && .venv/bin/pip install -e .
.venv/bin/ripple demo
```
`ripple demo` builds a small demo repository (`shop`, see below) into `tmp/shop`, indexes it into the Relate store `store/ripple.rl`, and answers the four questions. It works offline and takes about a second.
The store is also **committed** — [`store/ripple.rl`](store/ripple.rl) is a single Relate file you can inspect without running anything (see [Inspect the graph](#inspect-the-graph)).
### What you'll see
```
Q1. What breaks if I change round_money?
Impact of shop.money.round_money: 26 caller(s) up to depth 6
in 12 module(s), 14 test(s) among them, deepest chain 4 hop(s)
DEPTH FUNCTION MODULE
1 (8) shop.discounts.Discount.apply shop.discounts
shop.payments.PaymentProcessor._pay_card shop.payments
shop.pricing.calculate_total shop.pricing
...
Q2. Which tests should I run after changing X?
Tests for shop.payments.PaymentProcessor._pay_card: 1 test(s)
TEST STATIC DYNAMIC
tests.test_orders.test_place_order_paid_by_card - yes <- dynamic only: invisible to static analysis
Q3. Who should review a change to calculate_total?
AUTHOR EMAIL LINES SHARE LAST CHANGE
Alice alice@example.com 7 58% 2025-06-10
Bob bob@example.com 5 42% 2026-01-14
Q4. What code is dead or untested?
Dead code: 2 function(s) nothing calls and no test runs
shop.legacy.legacy_discount shop.legacy Dave 2025-04-17
shop.legacy.legacy_price shop.legacy Dave 2025-03-04
Import cycles: 1
shop.orders -> shop.payments -> shop.orders
```
---
## Use it from Claude Code (the agent)
The repo ships a [`.mcp.json`](.mcp.json) that registers Ripple's MCP server (`.venv/bin/ripple mcp`).
1. Run the quick start above (so `.venv` and `store/ripple.rl` exist).
2. Open this folder in Claude Code and approve the `ripple` MCP server when asked (or check `/mcp`).
3. Ask, for example:
- *"What breaks if I change round_money?"*
- *"Which tests should I run after changing PaymentProcessor._pay_card?"*
- *"Who should review a change to calculate_total?"*
- *"Is there dead code in this repo, and who wrote it?"*
The server's tools, all read-only:
| Tool | Answers |
|---|---|
| `find_symbol(name)` | Resolve a short name (`calculate_total`) to full qualnames |
| `impact(symbol, max_depth)` | Transitive callers with their shortest distance |
| `tests_for(symbol)` | Tests to run, each marked static and/or dynamic |
| `reviewers(symbol)` | Authors of the function's current lines, with share and last change |
| `dead_code()` / `untested()` | Functions nothing calls and no test runs / no test reaches |
| `import_cycles()` | Module import cycles |
| `graph_stats()` / `graph_schema()` | Counts and the schema, so the agent can write its own Cypher |
| `cypher(query, params)` | Any read-only Cypher query over the graph |
To use Ripple from another project, add the same server to that project's MCP config with an absolute path to this repo's `.venv/bin/ripple` and `--store /path/to/store.rl` (e.g. `"args": ["--store", "/abs/path/store.rl", "mcp"]`).
---
## How it uses Relate
**Mode: a single file.** Ripple keeps its graph in one persistent Relate store, [`store/ripple.rl`](store/ripple.rl), opened with `relate.connect("store/ripple.rl")` (see [`store.py`](src/ripple/store.py)). The file is committed, so you can inspect the saved graph without running anything.
**Why a single file:** the graph is a build artifact of one repository, so one file is easy to commit, copy and hand to someone, and Relate runs inside the process: no server, no account. Writers (`ripple index`, `ripple demo`) open it read-write; every query command and the MCP server open it with `read_only=True`, so asking questions can never change the graph. Tests use Relate's in-memory mode for speed.
Relate does the real work: every question is a Cypher query over the graph (variable-length `CALLS` traversals with `ANY SHORTEST`, aggregation over `BLAMED_TO`, existence checks across `EXERCISES`), and agents can run their own read-only Cypher through the MCP `cypher` tool.
## Why a graph
A call graph, a coverage report and `git blame` each answer part of the question. The interesting answers live in the **connections between them**:
- **Impact is transitive.** Changing `round_money` affects `calculate_total`, which affects `Cart.total`, which affects `place_order`… That is a variable-length traversal, `(caller)-[:CALLS]->{1,6}(target)`, not a lookup.
- **Static and dynamic analysis see different things.** `PaymentProcessor.charge` dispatches with `getattr(self, f"_pay_{method}")`, so no static analyser sees the call to `_pay_card`. Coverage does. Ripple stores both as edges (`CALLS` and `EXERCISES`) and combines them: `_pay_card` gets its test, and isn't falsely reported as dead code.
- **Ownership is a path.** Function → `BLAMED_TO` → Commit → `AUTHORED_BY` → Author, aggregated over the function's current lines.
### Schema
```mermaid
graph LR
Repo -->|CONTAINS| Module
Module -->|DEFINES| Class
Module -->|DEFINES| Function
Module -->|IMPORTS| Module
Class -->|HAS_METHOD| Function
Class -->|INHERITS| Class
Function -->|CALLS| Function
Function -->|"EXERCISES (test → code)"| Function
Function -->|BLAMED_TO| Commit
Commit -->|AUTHORED_BY| Author
Commit -->|CHANGED| Module
```
| Label | Properties |
|---|---|
| `Repo` | `name`, `head_sha`, `indexed_at` |
| `Module` | `name` (`shop.pricing`), `path`, `is_test`, `loc` |
| `Class` | `qualname`, `name`, `module`, `lineno`, `end_lineno` |
| `Function` | `qualname` (`shop.pricing.calculate_total`), `name`, `module`, `lineno`, `end_lineno`, `is_test`, `is_method` |
| `Commit` | `sha`, `date`, `message` |
| `Author` | `email`, `name` |
Relationship properties: `CALLS {lineno}`, `EXERCISES {lines}` (lines of the function the test executed), `BLAMED_TO {lines}` (lines of the function last changed in that commit).
### How it's built
```
Python repo ──► parse (ast) ── modules, classes, functions, imports, resolved calls ──┐
──► git log + blame ── commits, authors, blame lines per function ──────────┼──► Relate store (.rl)
──► coverage.py ── per-test dynamic contexts → test → function edges ───┘ │
queries.py (Cypher) ◄──────┘
│ │
ripple CLI MCP server
```
| Module | Role |
|---|---|
| [`parse.py`](src/ripple/parse.py) | Static call graph with the stdlib `ast`: resolves local names, (relative/aliased) imports, `self.`/`super()`/`Class.method`, constructors → `__init__`, and simple local-variable types |
| [`history.py`](src/ripple/history.py) | `git log` and `git blame --line-porcelain`, aggregated per function |
| [`coverage_map.py`](src/ripple/coverage_map.py) | Runs the repo's pytest suite under coverage with `dynamic_context = test_function` |
| [`ingest.py`](src/ripple/ingest.py) | Batched `UNWIND … MERGE` into Relate in one transaction, with uniqueness constraints |
| [`queries.py`](src/ripple/queries.py) | The questions as Cypher (`ANY SHORTEST` quantified paths keep traversals fast) |
| [`cli.py`](src/ripple/cli.py), [`mcp_server.py`](src/ripple/mcp_server.py) | Two front ends over the same queries |
---
## The demo repository: `shop`
[`examples/shop_history/`](examples/shop_history/) holds a tiny e-commerce package and its git history as plain files (a nested `.git` can't be committed). `ripple.sample.build_sample_repo()` replays it into a real git repo with fixed authors and dates, so the HEAD SHA — and every answer — is identical on every machine.
It was built on purpose so each question has an interesting answer: a central `round_money` helper, a `getattr` dispatch only coverage can see, a function half-rewritten by a second author, legacy code by an author who left, a function called only from the CLI that no test reaches, and an `orders ↔ payments` import cycle.
The exact expected answers are in [`EXPECTED.md`](examples/shop_history/EXPECTED.md) (blame and coverage numbers machine-verified), and [`tests/test_demo_questions.py`](tests/test_demo_questions.py) checks the whole pipeline against them — including all 74 static call edges and 148 coverage edges.
---
## Index your own repository
```bash
.venv/bin/ripple --store tmp/myrepo.rl index /path/to/your/repo
.venv/bin/ripple --store tmp/myrepo.rl impact some_function
```
- Coverage runs your test suite with `python -m coverage run -m pytest`. By default it uses Ripple's interpreter; point it at your project's environment with `--python /path/to/your/.venv/bin/python` (that environment needs `pytest` and `coverage`), or skip it with `--no-coverage` (static analysis and history still work).
- Module names are relative to the path you index. For a `src/` layout, index the `src` directory so imports like `mypackage.x` resolve.
- `--no-history` skips git.
- `index` replaces the store's content. A Relate `.rl` file allows one writer and no reader while it's being written, so MCP tool calls during indexing fail until it finishes.
## Inspect the graph
**See it:** `ripple viz --open` writes one self-contained HTML page (no server, works offline) and opens it. Click a function to light up everything that depends on it, with its tests and reviewers in the side panel; filter node and relationship types, search, drag and zoom.
Every command takes `--store PATH` (default `store/ripple.rl`, or `$RIPPLE_STORE`) and `--json`.
```bash
.venv/bin/ripple stats
.venv/bin/ripple query "MATCH (f:Function)<-[:CALLS]-(c) RETURN f.qualname AS fn, count(c) AS callers ORDER BY callers DESC LIMIT 5"
.venv/bin/ripple query "MATCH (t:Function)-[:EXERCISES]->(f:Function) WHERE NOT EXISTS { MATCH (t)-[:CALLS]->{1,6}(f) } RETURN t.qualname AS test, f.qualname AS reached_only_at_runtime"
```
Or straight from Python with Relate's own API:
```python
import relate
with relate.connect("store/ripple.rl", read_only=True) as conn:
for row in conn.execute(
"MATCH (f:Function {qualname: $q})-[b:BLAMED_TO]->(:Commit)-[:AUTHORED_BY]->(a:Author) "
"RETURN a.name AS author, sum(b.lines) AS lines ORDER BY lines DESC",
{"q": "shop.pricing.calculate_total"},
):
print(row["author"], row["lines"])
```
If you have the [Relate CLI](https://relatedb.ai/docs/get-started/install) installed, `relate query -d store/ripple.rl` opens an interactive shell on the same file.
## Development
```bash
.venv/bin/pytest # ~130 tests, ~15 s
```
## Limitations
- Python only. Static call resolution is deliberately conservative: calls through parameters, attributes of unknown objects, and `getattr` produce no static edge (coverage fills some of that gap when tests exercise the code).
- Coverage requires the target's test suite to run with pytest.
- Blame uses `HEAD`; uncommitted edits can shift line ranges until you commit and re-index.
## License
MIT
TDQS
Scored across 10 tools
Each tool answers a clearly different question (find a symbol, find callers, find tests, find reviewers, find dead code), so misselection is unlikely for the core analysis tools. The main soft spot is dead_code vs untested, which both surface 'nothing touches this' functions and differ only by the call-vs-coverage nuance, and graph_stats vs graph_schema are adjacent enough to require reading the descriptions.
All names are lowercase snake_case and readable, but the grammatical patterns are mixed: verb_noun (find_symbol, import_cycles, graph_stats), noun (reviewers, cypher), verb (impact), and noun_prep (tests_for). A user cannot predict from a name whether a tool is an action or a resource, though nothing is truly ambiguous.
Ten tools is well within the sweet spot, and each one corresponds to a distinct code-analysis question an agent would actually ask. The two generic escape hatches (cypher, graph_schema) are justified rather than filler.
The surface covers the practical pre-edit workflow: locate a symbol, see what breaks, pick tests, pick reviewers, plus repo hygiene via dead code, untested code, and import cycles. Gaps are minor: impact only reports callers, so there is no direct 'what does this call' (downstream) query, and there is no way to index/refresh or inspect a symbol's source; the cypher tool can work around most of these.