@mesrai/mesrai-graph
v0.1.0
Published
Code graph builder for Mesrai code review — parses source code into structural graphs with nodes, edges, and analysis
Maintainers
Readme
@mesrai/mesrai-graph
Internal code-graph builder for the Mesrai AI code review platform.
Turns a source tree into a structural graph (functions, classes, calls, imports, inheritance, tests) so the Mesrai review agent can reason about pull requests with real cross-file context — what a change touches, what depends on it, and where the tests live.
Distributed as a Bun-based CLI + Node-importable library. Runs inside Mesrai CI pipelines and ephemeral E2B sandboxes during each PR review.
Internal tool — proprietary. Not accepting external contributions or issues. See LICENSE.
Install
bun install -g @mesrai/mesrai-graphRequires Bun ≥ 1.3.0.
mesrai-graph --versionUsage
# Step 1 — build a baseline graph for the repo
mesrai-graph parse --all --repo-dir . --out graph.json
# Step 2 — get review context for the files in a PR
mesrai-graph context \
--files src/billing/charge.ts src/billing/refund.ts \
--graph graph.json \
--format prompt \
--out -The prompt format is plain text appended to the LLM system prompt. The json format is structured for programmatic consumption inside the Mesrai agent loop.
Capabilities
| Capability | Notes |
|---|---|
| 15-language extraction | TS/JS, Python, Go, Java, Kotlin, Rust, C/C++, C#, PHP, Ruby, Scala, Swift, Dart, Elixir |
| 5-tier call resolver | receiver → di → class → cascade — every CALLS edge carries tier + numeric confidence |
| Receiver-type inference | Resolves foo.bar() from constructor results, typed params, factory returns, singletons |
| DI awareness | Spring (@Autowired/implicit ctor), Jakarta CDI, EJB, JAX-RS, NestJS, Kotlin/Java field injection |
| Inheritance walk | Walks class hierarchy with cycle protection when Foo.method is inherited |
| Contract diffs | Detects param/return/modifier/async/decorator changes — not just body edits |
| Incremental updates | update re-parses only changed files (content-hash based) |
| Streaming JSON output | Handles million-node monorepos without exhausting memory |
| Pipe-friendly | --out - writes JSON to stdout; logs to stderr |
Per-language capability tiers: docs/language-support-matrix.md.
Commands
| Command | Purpose |
|---|---|
| parse | Build a graph from source files |
| update | Re-parse only changed files, merge into existing graph |
| analyze | Compute blast-radius / risk per function for changed files |
| context | Produce per-file review context (JSON or prompt format) |
| diff | Compare graphs across two refs to surface contract changes |
| communities | Cluster modules by coupling — find boundary lines |
| flows | Trace execution paths across function calls |
| search | Query the graph by name, kind, caller, or callee |
Run any command with --help for the full flag list.
Library usage
import { parseGraph, getContext } from "@mesrai/mesrai-graph";
const graph = await parseGraph({ repoDir: "./my-repo", maxMemoryMb: 1024 });
const context = await getContext({
graph,
files: ["src/auth/login.ts"],
format: "json",
});Type definitions ship with the package.
Graph shape (short)
Nodes carry name, kind (function/method/class/interface/enum/test), file, line range, plus is_exported, is_async, decorators, throws, complexity.
Edge types:
CALLS— function-to-function (withtier+confidence)IMPORTS— file-to-fileINHERITS/IMPLEMENTS— class hierarchyTESTED_BY— code → testCONTAINS— class → method / file → class
Full schema: docs/SCHEMA.md.
License
Proprietary — Mesrai Technologies. See LICENSE.
