tirth8205 / code-review-graph
tirth8205 / code-review-graph
code-review-graph: Stop burning tokens. Start reviewing smarter. code-review-graph:停止浪费 Token,开启更智能的代码审查。
AI coding tools can end up re-reading large parts of your codebase on review tasks. code-review-graph fixes that. It builds a structural map of your code with Tree-sitter, tracks changes incrementally, and gives your AI assistant precise context via MCP so it reads only what matters. AI 编程工具在执行审查任务时,往往会重复读取代码库的大部分内容。code-review-graph 解决了这个问题。它利用 Tree-sitter 构建代码的结构图,进行增量式变更追踪,并通过 MCP(Model Context Protocol)为 AI 助手提供精确的上下文,使其只读取真正重要的部分。
Quick Start
快速开始
pip install code-review-graph
# or:
pipx install code-review-graph
code-review-graph install # auto-detects and configures all supported platforms
code-review-graph build # parse your codebase
One command sets up everything. install detects which AI coding tools you have, writes the correct MCP configuration for each one, installs platform-native hooks/skills where supported, and injects graph-aware instructions into your platform rules. It auto-detects whether you installed via uvx or pip/pipx and generates the right config. Restart your editor/tool after installing.
只需一条命令即可完成所有设置。install 会自动检测你所使用的 AI 编程工具,为每个工具写入正确的 MCP 配置,在支持的平台上安装原生钩子(hooks)或技能,并将具备图感知能力的指令注入到你的平台规则中。它能自动检测你是通过 uvx 还是 pip/pipx 安装的,并生成相应的配置。安装后请重启你的编辑器或工具。
To target a specific platform: 若要针对特定平台进行配置:
code-review-graph install --platform codex # configure only Codex
code-review-graph install --platform cursor # configure only Cursor
# ... (additional platform commands)
Requires Python 3.10+. For the best experience, install uv (the MCP config will use uvx if available, otherwise falls back to the code-review-graph command directly).
需要 Python 3.10+。为了获得最佳体验,建议安装 uv(MCP 配置将优先使用 uvx,否则将直接回退到 code-review-graph 命令)。
To remove CRG from a Git or SVN project, use the symmetric uninstall command from anywhere inside its working tree. The target is normalized to the working tree root, and non-repository directories are refused. It removes only CRG-owned files and entries; unrelated MCP servers, hooks, skills, and JSONC comments remain untouched. Shared configuration changes use atomic replacement so a failed write leaves the original file intact.
若要从 Git 或 SVN 项目中移除 CRG,可在工作树内的任意位置使用对应的 uninstall 命令。目标路径会被标准化为工作树根目录,非仓库目录将被拒绝。该命令仅移除 CRG 创建的文件和条目;无关的 MCP 服务器、钩子、技能和 JSONC 注释将保持不变。共享配置的更改采用原子替换,因此如果写入失败,原始文件将保持完整。
How It Works
工作原理
Your repository is parsed into an AST with Tree-sitter, stored as a graph of nodes (functions, classes, imports) and edges (calls, inheritance, test coverage), then queried at review time to compute the minimal set of files your AI assistant needs to read. 你的仓库会被 Tree-sitter 解析为抽象语法树(AST),并存储为包含节点(函数、类、导入)和边(调用、继承、测试覆盖率)的图结构。在审查时,系统会查询该图,计算出 AI 助手需要读取的最少文件集。
Blast-radius analysis 影响范围分析 When a file changes, the graph traces every caller, dependent, and test that could be affected. This is the “blast radius” of the change. Your AI reads only these files instead of scanning the whole project. 当文件发生变更时,图结构会追踪所有可能受影响的调用者、依赖项和测试。这就是变更的“影响范围”(Blast-radius)。你的 AI 只需读取这些文件,而无需扫描整个项目。
Incremental updates in < 2 seconds 2 秒内的增量更新 When hooks or watch mode are enabled, file saves and supported commit hooks trigger incremental updates. The graph diffs changed files, finds their dependents via SHA-256 hash checks, and re-parses only what changed. A 2,900-file project re-indexes in under 2 seconds. 当启用钩子或监视模式时,文件保存和支持的提交钩子会触发增量更新。图结构会对变更文件进行差异分析,通过 SHA-256 哈希校验查找依赖项,并仅重新解析变更部分。一个包含 2,900 个文件的项目可在 2 秒内完成重新索引。
The monorepo problem, solved 解决 Monorepo 问题 Large monorepos are where token waste is most painful. The graph cuts through the noise — 27,700+ files excluded from review context, only ~15 files actually read. 大型 Monorepo 是 Token 浪费最严重的地方。该图结构能有效过滤噪音——在审查上下文中排除 27,700 多个无关文件,实际仅读取约 15 个文件。
Broad language coverage + Jupyter notebooks 广泛的语言支持 + Jupyter Notebooks Parser support covers functions, classes, imports, call sites, inheritance, and test detection across the current parser surface, using Tree-sitter where available and targeted fallbacks where needed. 解析器支持涵盖了当前解析范围内的函数、类、导入、调用点、继承和测试检测。在可用时使用 Tree-sitter,并在必要时提供针对性的回退方案。
Add your own language (no fork needed)
添加自定义语言(无需 Fork)
If your repo uses a language the parser does not cover yet, drop a languages.toml into .code-review-graph/ mapping file extensions to any grammar bundled in tree_sitter_language_pack, plus the tree-sitter node types for functions, classes, imports, and calls.
如果你的仓库使用了解析器尚未覆盖的语言,只需在 .code-review-graph/ 中放入一个 languages.toml 文件,将文件扩展名映射到 tree_sitter_language_pack 中捆绑的任何语法,并指定函数、类、导入和调用的 Tree-sitter 节点类型即可。