กลับไปหน้า Tools

GetNotes Tools

tirth8205/code-review-graph

Tool นี้คืออะไร

`code-review-graph` เป็นเครื่องมือที่ช่วยให้ AI ตรวจสอบโค้ดได้อย่างมีประสิทธิภาพมากขึ้น โดยสร้างแผนผังโครงสร้างของโค้ดและติดตามการเปลี่ยนแปลง เพื่อให้ AI ได้รับบริบทที่แม่นยำและลดการใช้โทเค็นที่ไม่จำเป็น เหมาะสำหรับนักพัฒนาที่ใช้ AI ในการรีวิวโค้ดในโปรเจกต์ขนาดใหญ่หรือ monorepo

ข้อมูลโปรเจกต์

ดาว

19.8K

Forks

2.1K

License

MIT

อัปเดต GitHub ล่าสุด

18 ก.ค. 2569

เพิ่มใน GetNotes

18 ก.ค. 2569

Repository

tirth8205/code-review-graph

รูปแบบ

CLI / Terminal

เหมาะกับงาน

AI และ AgentsCoding Agents

เหมาะกับอาชีพ

Ecosystem

Python

แปลและเรียบเรียงโดย AI

เนื้อหาฉบับภาษาไทย

ใช้อ่านเพื่อทำความเข้าใจเบื้องต้น โปรดตรวจสอบรายละเอียดสำคัญกับเอกสารต้นฉบับด้านล่าง

code-review-graph

หยุดเผาผลาญโทเค็น เริ่มรีวิวอย่างชาญฉลาดขึ้น

English | 简体中文 | 日本語 | 한국어 | हिन्दी

PyPI Downloads Stars MIT Licence CI Python 3.10+ MCP Website Discord

การใช้งาน · คำสั่ง · คำถามที่พบบ่อย · การแก้ไขปัญหา · GitHub Action · การทำซ้ำเกณฑ์มาตรฐาน · แผนงาน

เครื่องมือ AI สำหรับการเขียนโค้ดอาจต้องอ่านโค้ดส่วนใหญ่ใน codebase ของคุณซ้ำไปซ้ำมาในงานรีวิว code-review-graph แก้ปัญหานั้นได้ โดยจะสร้างแผนผังโครงสร้างของโค้ดของคุณด้วย Tree-sitter ติดตามการเปลี่ยนแปลงทีละน้อย และให้บริบทที่แม่นยำแก่ผู้ช่วย AI ของคุณผ่าน MCP เพื่อให้อ่านเฉพาะส่วนที่สำคัญเท่านั้น


เริ่มต้นอย่างรวดเร็ว

bash
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

คำสั่งเดียวก็ตั้งค่าทุกอย่างได้ install จะตรวจจับเครื่องมือ AI สำหรับการเขียนโค้ดที่คุณมี เขียนการกำหนดค่า MCP ที่ถูกต้องสำหรับแต่ละเครื่องมือ ติดตั้ง hooks/skills ที่เป็น native ของแพลตฟอร์มที่รองรับ และแทรกคำแนะนำที่เข้าใจกราฟลงในกฎของแพลตฟอร์มของคุณ โดยจะตรวจจับโดยอัตโนมัติว่าคุณติดตั้งผ่าน uvx หรือ pip/pipx และสร้างการกำหนดค่าที่ถูกต้อง รีสตาร์ท editor/tool ของคุณหลังจากติดตั้ง

หากต้องการกำหนดเป้าหมายแพลตฟอร์มเฉพาะ:

bash
code-review-graph install --platform codex       # configure only Codex
code-review-graph install --platform cursor      # configure only Cursor
code-review-graph install --platform claude-code  # configure only Claude Code
code-review-graph install --platform gemini-cli   # configure only Gemini CLI
code-review-graph install --platform kiro         # configure only Kiro
code-review-graph install --platform copilot      # configure only GitHub Copilot (VS Code)
code-review-graph install --platform copilot-cli  # configure only GitHub Copilot CLI
code-review-graph install --platform codebuddy    # configure only CodeBuddy Code

ต้องใช้ Python 3.10+ เพื่อประสบการณ์ที่ดีที่สุด ให้ติดตั้ง uv (การกำหนดค่า MCP จะใช้ uvx หากมี มิฉะนั้นจะกลับไปใช้คำสั่ง code-review-graph โดยตรง)

หากต้องการลบ CRG ออกจากโปรเจกต์ Git หรือ SVN ให้ใช้คำสั่ง uninstall ที่สมมาตรจากที่ใดก็ได้ภายใน working tree ของโปรเจกต์ เป้าหมายจะถูกปรับให้เป็น working tree root และไดเรกทอรีที่ไม่ใช่ repository จะถูกปฏิเสธ โดยจะลบเฉพาะไฟล์และรายการที่ CRG เป็นเจ้าของเท่านั้น เซิร์ฟเวอร์ MCP, hooks, skills และคอมเมนต์ JSONC ที่ไม่เกี่ยวข้องจะยังคงอยู่ การเปลี่ยนแปลงการกำหนดค่าที่ใช้ร่วมกันจะใช้การแทนที่แบบ atomic ดังนั้นหากการเขียนล้มเหลว ไฟล์ต้นฉบับจะยังคงอยู่

bash
code-review-graph uninstall --dry-run    # preview every action; write nothing
code-review-graph uninstall              # preview, ask for confirmation, then apply
code-review-graph uninstall --yes        # apply without prompting
code-review-graph uninstall --all-repos  # also clean every registered repository
code-review-graph uninstall --keep-data  # remove integrations but keep graph databases
code-review-graph uninstall --keep-user-configs --repo .  # clean this project only

จากนั้นเปิดโปรเจกต์ของคุณและถามผู้ช่วย AI ของคุณ:

code
Build the code review graph for this project

การสร้างครั้งแรกใช้เวลาประมาณ 10 วินาทีสำหรับโปรเจกต์ที่มี 500 ไฟล์ หลังจากนั้น โหมด watch และ hooks ที่รองรับสามารถอัปเดตกราฟได้โดยอัตโนมัติ

วิธีการทำงาน

repository ของคุณจะถูกแยกวิเคราะห์เป็น AST ด้วย Tree-sitter จัดเก็บเป็นกราฟของโหนด (ฟังก์ชัน, คลาส, การนำเข้า) และเอดจ์ (การเรียก, การสืบทอด, การครอบคลุมการทดสอบ) จากนั้นจะถูกสอบถามในเวลาที่รีวิวเพื่อคำนวณชุดไฟล์ขั้นต่ำที่ผู้ช่วย AI ของคุณจำเป็นต้องอ่าน

การวิเคราะห์ Blast-radius

เมื่อไฟล์มีการเปลี่ยนแปลง กราฟจะติดตามผู้เรียก, ผู้พึ่งพา และการทดสอบทั้งหมดที่อาจได้รับผลกระทบ นี่คือ "blast radius" ของการเปลี่ยนแปลง AI ของคุณจะอ่านเฉพาะไฟล์เหล่านี้แทนที่จะสแกนทั้งโปรเจกต์

การอัปเดตแบบเพิ่มขึ้นในเวลา < 2 วินาที

เมื่อเปิดใช้งาน hooks หรือโหมด watch การบันทึกไฟล์และ commit hooks ที่รองรับจะกระตุ้นการอัปเดตแบบเพิ่มขึ้น กราฟจะเปรียบเทียบไฟล์ที่เปลี่ยนแปลง ค้นหาผู้พึ่งพาผ่านการตรวจสอบแฮช SHA-256 และแยกวิเคราะห์เฉพาะส่วนที่เปลี่ยนแปลงเท่านั้น โปรเจกต์ที่มี 2,900 ไฟล์จะถูกจัดทำดัชนีใหม่ในเวลาไม่ถึง 2 วินาที

ปัญหา monorepo ได้รับการแก้ไขแล้ว

monorepo ขนาดใหญ่คือจุดที่การสิ้นเปลืองโทเค็นเจ็บปวดที่สุด กราฟจะตัดผ่านความยุ่งเหยิง — ไฟล์กว่า 27,700 ไฟล์ถูกยกเว้นจากบริบทการรีวิว มีเพียงประมาณ 15 ไฟล์เท่านั้นที่ถูกอ่านจริง

การรองรับภาษาที่หลากหลาย + Jupyter notebooks

การรองรับ Parser ครอบคลุมฟังก์ชัน, คลาส, การนำเข้า, call sites, การสืบทอด และการตรวจจับการทดสอบทั่วทั้งพื้นผิว parser ปัจจุบัน โดยใช้ Tree-sitter เมื่อมี และ fallbacks ที่กำหนดเป้าหมายเมื่อจำเป็น การรองรับปัจจุบันรวมถึง Python, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, โครงสร้าง Terraform/OpenTofu (.tf; ไฟล์ .hcl ทั่วไปจะถูกรู้จักเป็นโหนดไฟล์), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, ไฟล์ Astro ที่แยกวิเคราะห์ผ่าน TypeScript parser, Jupyter/Databricks notebooks (.ipynb) และไฟล์ Perl XS (.xs) Generic YAML ไม่ถือว่าเป็นซอร์สโค้ด

โปรเจกต์ PHP ยังได้รับการแก้ไข Composer PSR-4 ที่จำกัด repository, การอ้างอิง Blade template และเอดจ์เชิงความหมายของ Laravel Route/Eloquent เมื่อซอร์สโค้ดมีการนำเข้าเฟรมเวิร์กที่ชัดเจน, การสืบทอดโมเดล และหลักฐาน receiver

เพิ่มภาษาของคุณเอง (ไม่ต้อง Fork)

หาก repo ของคุณใช้ภาษาที่ตัวแยกวิเคราะห์ยังไม่รองรับ คุณสามารถวางไฟล์ languages.toml ลงใน .code-review-graph/ เพื่อแมปนามสกุลไฟล์เข้ากับไวยากรณ์ใดๆ ที่รวมอยู่ใน tree_sitter_language_pack รวมถึงประเภทโหนด tree-sitter สำหรับฟังก์ชัน, คลาส, การนำเข้า และการเรียก:

toml
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]

ตัวเดิน tree-sitter ทั่วไปจะจัดการการดึงข้อมูลจากตรงนั้น — ไม่มีการเปลี่ยนแปลงโค้ด และภาษาในตัวไม่สามารถถูกเขียนทับได้ ดู docs/CUSTOM_LANGUAGES.md สำหรับการอ้างอิง Schema, กฎการตรวจสอบ และตัวอย่างการทำงานแบบครบวงจร

การรีวิว PR ที่มีการให้คะแนนความเสี่ยงใน CI (GitHub Action)

การวิเคราะห์เดียวกันนี้ทำงานเป็น GitHub Action แบบคอมโพสิต — และยังคงเป็นแบบ local-first: กราฟความรู้ถูกสร้างและสอบถามทั้งหมดบน CI runner ของคุณ โดยไม่มีการส่งซอร์สโค้ดไปยังบริการภายนอกใดๆ ในแต่ละ pull request แอคชันจะโพสต์คอมเมนต์แบบ sticky เพียงหนึ่งเดียวพร้อมฟังก์ชันที่ให้คะแนนความเสี่ยง, โฟลว์การทำงานที่ได้รับผลกระทบ และช่องว่างในการทดสอบ ซึ่งจะอัปเดตในตำแหน่งเดิมทุกครั้งที่ push อินพุต fail-on-risk ที่เป็นทางเลือกจะเปลี่ยนการรีวิวให้เป็นเกตการรวม (merge gate)

yaml
# .github/workflows/code-review-graph.yml
on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: tirth8205/code-review-graph@v2.3.6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

ดู docs/GITHUB_ACTION.md สำหรับอินพุต, ระดับความเสี่ยง และรายละเอียดการแคช หรือเวิร์กโฟลว์ dogfood ที่ repo นี้รันบนตัวเองใน .github/workflows/pr-review.yml


เกณฑ์มาตรฐาน

ตัวเลขสำคัญ: การลดโทเค็นต่อคำถามโดยเฉลี่ยใน 6 repos อยู่ที่ประมาณ 82 เท่า (เทียบกับฐานข้อมูลทั้งหมดกับการสอบถามกราฟ) 528 เท่าที่ถูกอ้างถึงบ่อยครั้งคือค่าสูงสุด — repo ที่ดีที่สุดเพียงหนึ่งเดียว (fastapi) — ไม่ใช่ผลลัพธ์ทั่วไป

ตัวเลขทั้งหมดมาจากการรันการประเมินอัตโนมัติกับ 6 repositories โอเพนซอร์สจริง (รวม 13 คอมมิต) ทุกการกำหนดค่าจะตรึง SHA อัปสตรีม, ตัวตรวจจับชุมชน Leiden ทำงานด้วย seed ที่กำหนด และการฝังข้อมูลเป็นแบบกำหนดได้บน CPU — ดังนั้นการรันสองครั้งบนเครื่องที่ต่างกันจะให้ตัวเลขที่เหมือนกัน สูตรการทำซ้ำทั้งหมดพร้อมเอาต์พุตที่คาดหวังอยู่ใน docs/REPRODUCING.md การรันแบบรายงานเท่านั้นรายสัปดาห์บนการกำหนดค่าที่เล็กที่สุดสองรายการอยู่ใน .github/workflows/eval.yml

สำหรับคำถามทั่วไปของเอเจนต์ ("การยืนยันตัวตนทำงานอย่างไร", "จุดเริ่มต้นหลักคืออะไร", เป็นต้น) กราฟจะส่งคืนผลการค้นหาที่ตรงเป้าหมายประมาณ 2,000–3,500 โทเค็น + ขอบของเพื่อนบ้าน แทนที่จะบังคับให้เอเจนต์อ่านไฟล์ต้นฉบับทุกไฟล์ ตารางด้านล่างเป็นค่าเฉลี่ยจาก 5 คำถามตัวอย่างที่กำหนดไว้ใน code_review_graph/token_benchmark.py

RepoSnapshot SHAnaive_corpus_tokensavg graph_tokensReduction
fastapi0227991a951,0712,169528.4x
code-review-graph84bde354208,8212,49593.0x
gin5c00df8a166,8681,99091.8x
flaska29f88ce125,0221,98671.4x
expressb4ab7d65135,9553,46540.6x
httpxb55d463589,4922,43838.0x

การลดโทเค็นต่อคำถามโดยเฉลี่ยใน 6 repos: ~82 เท่า ช่วงคือ 38x – 528x โดยที่ 528x คือกรณีที่ดีที่สุด (fastapi ซึ่งเป็น corpus ที่ใหญ่ที่สุด) ไม่ใช่ตัวเลขหลัก

ฐานข้อมูลทั้งหมดข้างต้นเป็นขอบเขตบนที่ไม่มีเอเจนต์จริงจ่าย: เอเจนต์ที่มีความสามารถจะค้นหาตัวระบุและอ่านเฉพาะไฟล์ที่ตรงกันที่สุด เกณฑ์มาตรฐานการประเมิน agent_baseline วัดฐานข้อมูลที่สมจริงนั้น — การค้นหา grep แบบ pure-python ทั่วทั้ง corpus, ไฟล์ 3 อันดับแรกตามจำนวนการจับคู่, นับโทเค็นและเปรียบเทียบกับต้นทุนการสอบถามกราฟ (evaluate/results/<repo>_agent_baseline_*.csv)

เกณฑ์มาตรฐาน eval/benchmarks/token_efficiency.py อย่างเป็นทางการวัดสถานการณ์ที่แตกต่างกัน — JSON get_review_context() แบบเต็มเทียบกับเนื้อหาไฟล์ที่เปลี่ยนแปลงของคอมมิต — และรายงานอัตราส่วนที่ต่ำกว่า 1 สำหรับคอมมิตขนาดเล็ก เนื่องจากผลตอบรับของบริบทการรีวิวมีขอบรัศมีผลกระทบพร้อมกับส่วนย่อยของซอร์สโค้ดที่เกินกว่า diff ไฟล์เดียวเล็กๆ นั่นไม่ใช่ข้อผิดพลาด; เกณฑ์มาตรฐานทั้งสองตอบคำถามที่แตกต่างกัน ดู docs/REPRODUCING.md สำหรับระเบียบวิธีวิจัยฉบับเต็ม

ตั้งแต่ v2.3.4 เครื่องมือรีวิวและผลกระทบจะแนบการประมาณค่า context_savings ที่กระชับ เพื่อให้ไคลเอนต์ MCP สามารถเห็นบริบทโดยประมาณที่บันทึกไว้ต่อการเรียก ใน v2.3.5 CLI จะแสดงสิ่งนี้เป็นแผง Token Savings ที่มีกรอบสี่เหลี่ยมที่แสดงด้านบน (ดู "แผง Token Savings" ในส่วนการใช้งาน) และเพิ่ม --verify เพื่อตรวจสอบกับ tokenizer cl100k_base ของ OpenAI ข้อมูลการปรับเทียบใน docs/REPRODUCING.md แสดงให้เห็นว่าการประมาณค่าอยู่ภายใน ~1% ของโทเค็น GPT-4 จริงโดยรวมในไฟล์ตัวอย่าง 222 ไฟล์

การวิเคราะห์รัศมีผลกระทบกู้คืนทุกไฟล์ใน ground truth ในคอมมิตการประเมินทั้ง 13 รายการ — แต่ให้อ่านว่าเป็นขอบเขตบน ไม่ใช่ "recall 100%": ในโหมดนี้ ground truth (ไฟล์ที่เปลี่ยนแปลง + ไฟล์ที่มีขอบการเรียก/การนำเข้าเข้าสู่ไฟล์เหล่านั้น) ได้มาจากกราฟเดียวกันกับที่ตัวทำนายใช้ ดังนั้นจึงเป็นแบบวงกลมโดยโครงสร้าง การทำนายเกินที่เห็นได้ในคอลัมน์ precision เป็นการแลกเปลี่ยนที่จงใจ: การแจ้งเตือนไฟล์มากเกินไปดีกว่าการพลาดการพึ่งพาที่เสียหาย

RepoCommitsAvg F1Avg PrecisionRecall (graph-derived upper bound)
httpx20.8640.7861.0
fastapi20.8340.7501.0
code-review-graph20.7340.5841.0
express20.6670.5001.0
flask20.6280.4811.0
gin30.6090.4391.0
Average130.7140.5781.000

เกณฑ์มาตรฐานยังรัน โหมด co-change ที่ซื่อสัตย์: ตัวทำนายจะถูกตั้งค่าเริ่มต้นด้วยไฟล์ที่เปลี่ยนแปลงเพียงไฟล์เดียวและให้คะแนนเทียบกับไฟล์ อื่นๆ ที่ผู้เขียนได้แก้ไขจริงในคอมมิตเดียวกัน — หลักฐานที่เป็นอิสระจากประวัติ Git ไม่ใช่จากกราฟ ทั้งสองโหมดจะปรากฏเคียงข้างกันในไฟล์ CSV ผลลัพธ์ (คอลัมน์ ground_truth_mode) ตัวเลข co-change จะถูกเพิ่มไปยังสถิติที่เป็นทางการเมื่อถูกบันทึกโดย eval runner; เราจะไม่อ้างอิงตัวเลขเหล่านั้นก่อนที่จะทำการวัด

RepoFilesNodesEdgesFlow DetectionSearch Latency
express1411,91017,553106ms0.7ms
fastapi1,1226,28527,117128ms1.5ms
flask831,4467,97495ms0.7ms
gin991,28616,762111ms0.5ms
httpx601,2537,89696ms0.4ms

ข้อจำกัดและจุดอ่อนที่ทราบ

  • "Recall 1.0" ของผลกระทบได้มาจากกราฟและเป็นแบบวงกลม: ground truth ทางประวัติศาสตร์มาจากขอบกราฟเดียวกันกับที่ตัวทำนายใช้ ดังนั้นจึงเป็นขอบเขตบนโดยโครงสร้าง โหมด co-change ที่ซื่อสัตย์ (ให้คะแนนเทียบกับไฟล์ที่ถูกเปลี่ยนแปลงร่วมกันจริงในคอมมิตเดียวกัน) ถูกวัดควบคู่กันไป; คาดว่าตัวเลขเหล่านั้นจะต่ำกว่าอย่างมาก
  • การเปลี่ยนแปลงไฟล์เดียวขนาดเล็ก: บริบทของกราฟสามารถเกินกว่าการอ่านไฟล์แบบธรรมดาสำหรับการแก้ไขเล็กน้อย (ดูผลลัพธ์ของ express ด้านบน) ค่าใช้จ่ายเพิ่มเติมคือข้อมูลเมตาเชิงโครงสร้างที่ช่วยให้สามารถวิเคราะห์หลายไฟล์ได้
  • คุณภาพการค้นหา (MRR 0.35): การค้นหาด้วยคีย์เวิร์ดพบผลลัพธ์ที่ถูกต้องใน 4 อันดับแรกสำหรับคำค้นส่วนใหญ่ แต่การจัดอันดับยังต้องปรับปรุง คำค้นของ express คืนค่า 0 ผลลัพธ์เนื่องจากการตั้งชื่อรูปแบบโมดูล
  • การตรวจจับโฟลว์ (recall 33%): รูปแบบการเข้าใช้งานของเฟรมเวิร์กและแบบทั่วไปแข็งแกร่งที่สุดสำหรับ Python และ PHP/Laravel การตรวจจับโฟลว์ของ JavaScript และ Go ยังต้องปรับปรุง
  • การแลกเปลี่ยนระหว่าง Precision กับ Recall: การวิเคราะห์ผลกระทบถูกออกแบบมาให้ระมัดระวังโดยเจตนา มันจะแจ้งเตือนไฟล์ที่ อาจ ได้รับผลกระทบ ซึ่งหมายถึงการมี false positives บางส่วนในกราฟการพึ่งพาขนาดใหญ่

คุณสมบัติ

คุณสมบัติรายละเอียด
การอัปเดตแบบเพิ่มหน่วยแยกวิเคราะห์เฉพาะไฟล์ที่เปลี่ยนแปลง การอัปเดตครั้งต่อไปจะเสร็จสิ้นภายใน 2 วินาที
รองรับภาษาและโน้ตบุ๊กหลากหลายPython, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, โครงสร้าง Terraform/OpenTofu (.tf; ไฟล์ .hcl ทั่วไปเป็นแบบไฟล์เท่านั้น), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, ไฟล์ Astro ที่แยกวิเคราะห์ผ่าน TypeScript parser, Jupyter/Databricks (.ipynb), และ Perl XS (.xs)
การแยกวิเคราะห์ PHP ที่รับรู้เฟรมเวิร์กการนำเข้า Composer PSR-4 ที่จำกัดตาม Repository, การอ้างอิงเทมเพลต Blade, และขอบ Laravel Route-to-controller และ Eloquent relationship ที่มีหลักฐานยืนยัน
การวิเคราะห์รัศมีผลกระทบแสดงฟังก์ชัน, คลาส และไฟล์ที่น่าจะได้รับผลกระทบจากการเปลี่ยนแปลง
Auto-update hooksHooks และ watch mode สามารถอัปเดตกราฟเมื่อบันทึกไฟล์และ commit hooks ที่รองรับ
การค้นหาเชิงความหมายการฝังเวกเตอร์เสริมผ่าน sentence-transformers, Google Gemini, MiniMax, หรือปลายทางที่เข้ากันได้กับ OpenAI (OpenAI จริง, Azure, new-api, LiteLLM, vLLM, LocalAI)
การแสดงผลแบบโต้ตอบกราฟ D3.js แบบ force-directed พร้อมการค้นหา, สลับตำนานชุมชน และโหนดที่ปรับขนาดตามดีกรี
การตรวจจับ Hub & Bridgeค้นหาโหนดที่มีการเชื่อมต่อมากที่สุดและจุดคอขวดทางสถาปัตยกรรมผ่าน betweenness centrality
การให้คะแนนความประหลาดใจตรวจจับการเชื่อมโยงที่ไม่คาดคิด: ข้ามชุมชน, ข้ามภาษา, ขอบจากส่วนปลายไปยังศูนย์กลาง
การวิเคราะห์ช่องว่างความรู้ระบุโหนดที่แยกตัว, จุดร้อนที่ไม่ได้ทดสอบ, ชุมชนที่บาง และจุดอ่อนเชิงโครงสร้าง
คำถามแนะนำคำถามรีวิวที่สร้างขึ้นอัตโนมัติจากการวิเคราะห์กราฟ (bridges, hubs, surprises)
ความเชื่อมั่นของขอบการให้คะแนนความเชื่อมั่นสามระดับ (EXTRACTED/INFERRED/AMBIGUOUS) พร้อมคะแนนทศนิยมบนขอบ
การสำรวจกราฟการสำรวจ BFS/DFS แบบอิสระจากโหนดใดๆ ด้วยความลึกและงบประมาณโทเค็นที่กำหนดค่าได้
รูปแบบการส่งออกGraphML (Gephi/yEd), Neo4j Cypher, Obsidian vault พร้อม wikilinks, กราฟ SVG แบบคงที่
Graph diffเปรียบเทียบสแนปช็อตกราฟเมื่อเวลาผ่านไป: โหนด/ขอบใหม่/ที่ถูกลบ, การเปลี่ยนแปลงชุมชน
การวัดประสิทธิภาพโทเค็นวัดโทเค็น corpus เต็มรูปแบบแบบ naive เทียบกับโทเค็นการสอบถามกราฟด้วยอัตราส่วนต่อคำถาม
การประมาณการประหยัดบริบทเมตาเดตา context_savings ที่กระชับบนเอาต์พุตการรีวิว MCP/CLI ที่เกี่ยวข้อง โดยระบุว่าเป็นค่าประมาณและเก็บไว้ในสามฟิลด์เล็กๆ
Memory loopเก็บผลลัพธ์ Q&A เป็น markdown เพื่อนำกลับมาใช้ใหม่ เพื่อให้กราฟเติบโตจากการสอบถาม
การแยกชุมชนอัตโนมัติชุมชนที่มีขนาดใหญ่เกินไป (>25% ของกราฟ) จะถูกแยกซ้ำๆ ผ่าน Leiden
โฟลว์การทำงานติดตามสายการเรียกจากจุดเริ่มต้น จัดเรียงตามความสำคัญถ่วงน้ำหนัก
การตรวจจับชุมชนจัดกลุ่มโค้ดที่เกี่ยวข้องผ่านอัลกอริทึม Leiden พร้อมการปรับขนาดความละเอียดสำหรับกราฟขนาดใหญ่
ภาพรวมสถาปัตยกรรมแผนที่สถาปัตยกรรมที่สร้างขึ้นอัตโนมัติพร้อมคำเตือนการเชื่อมโยง
การรีวิวที่ให้คะแนนความเสี่ยงdetect_changes แมป diffs ไปยังฟังก์ชัน, โฟลว์ และช่องว่างการทดสอบที่ได้รับผลกระทบ
ภาษาที่กำหนดเองเพิ่มภาษาใหม่ผ่าน .code-review-graph/languages.toml — ไม่ต้อง fork หรือเปลี่ยนแปลงโค้ด
GitHub Actionคอมเมนต์รีวิว PR ที่ให้คะแนนความเสี่ยงแบบ sticky ใน CI พร้อมเกตการรวม fail-on-risk ที่เป็นทางเลือก
เครื่องมือ Refactoringดูตัวอย่างการเปลี่ยนชื่อ, การตรวจจับโค้ดที่ไม่ได้ใช้งานที่รับรู้เฟรมเวิร์ก, คำแนะนำที่ขับเคลื่อนโดยชุมชน
การสร้าง Wikiสร้าง markdown wiki อัตโนมัติจากโครงสร้างชุมชน
Multi-repo registryลงทะเบียนหลาย repo, ค้นหาข้ามทั้งหมด
Multi-repo daemoncrg-daemon ตรวจสอบหลาย repo เป็น child processes พร้อมการตรวจสอบสุขภาพและการรีสตาร์ทอัตโนมัติ
MCP prompts5 เทมเพลตเวิร์กโฟลว์: review, architecture, debug, onboard, pre-merge
การค้นหาข้อความเต็มการค้นหาแบบไฮบริดที่ขับเคลื่อนโดย FTS5 ซึ่งรวมการค้นหาด้วยคีย์เวิร์ดและความคล้ายคลึงของเวกเตอร์
ที่เก็บข้อมูลในเครื่องไฟล์ SQLite ใน .code-review-graph/ การจัดเก็บกราฟหลักไม่จำเป็นต้องมีฐานข้อมูลภายนอกหรือบริการคลาวด์
Watch modeการอัปเดตกราฟอย่างต่อเนื่องในขณะที่คุณทำงาน

การใช้งาน

คำสั่งคำอธิบาย
/code-review-graph:build-graphสร้างหรือสร้างกราฟโค้ดใหม่
/code-review-graph:review-deltaตรวจสอบการเปลี่ยนแปลงตั้งแต่คอมมิตล่าสุด
/code-review-graph:review-prตรวจสอบ PR แบบเต็มพร้อมการวิเคราะห์ขอบเขตผลกระทบ
bash
code-review-graph install          # ตรวจจับและกำหนดค่าแพลตฟอร์มทั้งหมดโดยอัตโนมัติ
code-review-graph install --platform <name>  # กำหนดเป้าหมายแพลตฟอร์มที่เฉพาะเจาะจง
code-review-graph uninstall --dry-run  # ดูตัวอย่างการลบอาร์ติแฟกต์ที่ติดตั้งอย่างปลอดภัย
code-review-graph build            # แยกวิเคราะห์โค้ดเบสทั้งหมด
code-review-graph update           # อัปเดตแบบเพิ่มหน่วย (เฉพาะไฟล์ที่เปลี่ยนแปลง)
code-review-graph status           # สถิติกราฟ
code-review-graph watch            # อัปเดตอัตโนมัติเมื่อไฟล์เปลี่ยนแปลง
code-review-graph visualize        # สร้างกราฟ HTML แบบโต้ตอบ
code-review-graph visualize --format json      # ส่งออกข้อมูลกราฟภายในเป็น JSON
code-review-graph visualize --format graphml   # ส่งออกเป็น GraphML
code-review-graph visualize --format svg       # ส่งออกเป็น SVG
code-review-graph visualize --format obsidian  # ส่งออกเป็น Obsidian vault
code-review-graph visualize --format cypher    # ส่งออกเป็น Neo4j Cypher
code-review-graph wiki             # สร้าง markdown wiki จากคอมมูนิตี้
code-review-graph detect-changes --brief         # แผงความเสี่ยง + การประหยัดโทเค็น (อ่านอย่างเดียว)
code-review-graph update --brief                 # รีเฟรชกราฟ + แผงเดียวกัน
code-review-graph detect-changes --brief --verify  # ตรวจสอบข้ามกับ tiktoken
code-review-graph register <path>  # ลงทะเบียน repo ใน multi-repo registry
code-review-graph unregister <id>  # ลบ repo ออกจาก registry
code-review-graph repos            # แสดงรายการ repositories ที่ลงทะเบียน
code-review-graph daemon start     # เริ่ม daemon สำหรับ multi-repo watch
code-review-graph daemon stop      # หยุด daemon
code-review-graph daemon status    # แสดงสถานะ daemon และ repos
code-review-graph eval             # รันการประเมินประสิทธิภาพ
code-review-graph serve            # เริ่มต้น MCP server

การส่งออก JSON จะยังคงอยู่ในไดเรกทอรีข้อมูลกราฟภายใน ซึ่ง Git จะละเว้นโดยค่าเริ่มต้น ไฟล์เหล่านี้อาจมีพาธแบบสัมบูรณ์และเมตาดาต้าโครงสร้างโค้ด ดังนั้นโปรดตรวจสอบและทำความสะอาดไฟล์ที่ส่งออกก่อนที่จะเผยแพร่ภายนอกเครื่องของคุณ

ทั้งสองคำสั่งจะแสดงแผงขนาดกะทัดรัดเดียวกันที่แสดงจำนวนโทเค็นที่กราฟช่วยคุณประหยัดได้เมื่อเทียบกับการส่งไฟล์ที่เปลี่ยนแปลงไปยังเอเจนต์โดยตรง ทั้งสองคำสั่งแตกต่างกันใน สิ่งเดียว: กราฟจะถูกรีเฟรชก่อนหรือไม่

text
┌─────────────────────── Token Savings ────────────────────────┐
│ Full context would be:     12,921 tokens                     │
│ Graph context used:           762 tokens                     │
│ Saved:                     12,159 tokens (~94%)              │
│ Breakdown: Functions 244 · Tests 191 · Risk 244 · Other 83   │
└──────────────────────────────────────────────────────────────┘
คำสั่งสิ่งที่ทำเมื่อไหร่ที่ควรใช้
detect-changes --briefอ่านอย่างเดียว ดูการเปลี่ยนแปลงปัจจุบันของคุณ, สอบถามกราฟ ที่มีอยู่, แสดงแผง ~1 วินาทีส่วนใหญ่แล้ว — hooks (หรือ crg-daemon) จะรักษากราฟให้สดใหม่อยู่เบื้องหลัง ดังนั้นแค่นี้ก็เพียงพอแล้ว
update --briefแยกวิเคราะห์ไฟล์ที่เปลี่ยนแปลงของคุณลงในกราฟก่อน จากนั้นแสดงแผงเดียวกัน ~5 วินาทีหลังจากการ rebase, ชุดการเปลี่ยนแปลงขนาดใหญ่ หรือเมื่อใดก็ตามที่คุณสงสัยว่ากราฟไม่เป็นปัจจุบัน

ทั้งสองคำสั่งจะจบลงด้วย แผงเดียวกัน เนื่องจากทั้งสองเรียกใช้ขั้นตอน analyze_changes() เดียวกันในตอนท้าย ความแตกต่างคือตัวกราฟเองได้รับการรีเฟรชก่อนที่จะทำการวิเคราะห์นั้นหรือไม่

เพิ่ม --verify ในคำสั่งใดก็ได้เพื่อตรวจสอบตัวเลขที่แสดงกับ tokenizer cl100k_base ของ OpenAI (ตระกูล GPT-4) ต้องใช้ pip install tiktoken ค่าประมาณจะอยู่ภายใน ~1% ของโทเค็นจริงในการเปลี่ยนแปลงทั่วไป — ดู docs/REPRODUCING.md สำหรับข้อมูลการปรับเทียบ

เมตาดาต้า context_savings เดียวกันนี้ยังแนบโดยอัตโนมัติกับการตอบกลับ JSON ของเครื่องมือ MCP get_impact_radius, get_review_context, detect_changes และ get_architecture_overview ดังนั้นเอเจนต์ AI จึงสามารถแสดงการประหยัดให้มนุษย์เห็นในการแชทได้โดยไม่ต้องมีการแจ้งเตือนเพิ่มเติม

หากเอดิเตอร์ของคุณไม่รองรับ hooks (เช่น Cursor, OpenCode) หรือคุณเพียงต้องการให้กราฟของคุณอัปเดตอยู่เบื้องหลังโดยไม่ต้องมีการรวมเข้ากับเอดิเตอร์ใดๆ daemon นี้เหมาะสำหรับคุณ มันจะเฝ้าดู repo ของคุณเพื่อตรวจจับการเปลี่ยนแปลงไฟล์และสร้างกราฟใหม่โดยอัตโนมัติ — ไม่จำเป็นต้องใช้คำสั่ง build หรือ update ด้วยตนเอง

daemon รวมอยู่ใน code-review-graph แล้ว — ไม่ต้องติดตั้งแยกต่างหาก

การตั้งค่าอย่างรวดเร็ว:

bash
# 1. ลงทะเบียน repo ที่คุณต้องการเฝ้าดู
crg-daemon add ~/project-a --alias proj-a
crg-daemon add ~/project-b

# 2. เริ่ม daemon (ทำงานอยู่เบื้องหลัง)
crg-daemon start

# 3. แค่นั้นเอง — กราฟจะอัปเดตโดยอัตโนมัติ
crg-daemon status                 # ตรวจสอบสถานะ daemon และ watcher ของแต่ละ repo
crg-daemon logs --repo proj-a -f  # ดู log สำหรับ repo ที่เฉพาะเจาะจง
crg-daemon stop                   # หยุด daemon และกระบวนการ watcher ทั้งหมด

นอกจากนี้ยังมีให้ใช้งานในรูปแบบ code-review-graph daemon start|stop|status|...

ภายใต้เบื้องหลัง crg-daemon add จะเขียนลงในไฟล์คอนฟิก TOML ที่ ~/.code-review-graph/watch.toml คุณยังสามารถแก้ไขไฟล์นี้ได้โดยตรง:

toml
[[repos]]
path = "/home/user/project-a"
alias = "proj-a"

[[repos]]
path = "/home/user/project-b"
alias = "project-b"

daemon จะตรวจสอบไฟล์คอนฟิกนี้เพื่อหาการเปลี่ยนแปลงและเริ่ม/หยุดกระบวนการ watcher โดยอัตโนมัติเมื่อมีการเพิ่มหรือลบ repo การตรวจสอบสุขภาพทุก 30 วินาทีจะรีสตาร์ท watcher ที่หยุดทำงาน ไม่จำเป็นต้องมี dependency ภายนอก

ดู docs/COMMANDS.md สำหรับการอ้างอิงคอนฟิกแบบเต็มและตัวเลือกทั้งหมดที่มี

ผู้ช่วย AI ของคุณจะใช้สิ่งเหล่านี้โดยอัตโนมัติเมื่อสร้างกราฟแล้ว

เครื่องมือคำอธิบาย
build_or_update_graph_toolสร้างหรืออัปเดตกราฟแบบเพิ่มหน่วย
run_postprocess_toolรันการตรวจจับ flow, การตรวจจับ community และการทำดัชนี FTS ซ้ำ
get_minimal_context_toolบริบทที่กะทัดรัดเป็นพิเศษ (~100 โทเค็น) — เรียกใช้สิ่งนี้ก่อน
get_impact_radius_toolขอบเขตผลกระทบของไฟล์ที่เปลี่ยนแปลง
get_review_context_toolบริบทการรีวิวที่ปรับให้เหมาะสมกับโทเค็นพร้อมสรุปโครงสร้าง
query_graph_toolการสอบถามผู้เรียก, ผู้ถูกเรียก, การทดสอบ, การนำเข้า, การสืบทอด
traverse_graph_toolการสำรวจ BFS/DFS จากโหนดใดๆ ด้วยงบประมาณโทเค็น
semantic_search_nodes_toolค้นหาเอนทิตีโค้ดตามชื่อหรือความหมาย
embed_graph_toolคำนวณ vector embeddings สำหรับการค้นหาเชิงความหมาย
list_graph_stats_toolขนาดและสถานะของกราฟ
get_docs_section_toolดึงส่วนเอกสาร
find_large_functions_toolค้นหาฟังก์ชัน/คลาสที่เกินเกณฑ์จำนวนบรรทัด
list_flows_toolแสดงรายการ execution flows ที่เรียงตามความสำคัญ
get_flow_toolรับรายละเอียดของ execution flow เดียว
get_affected_flows_toolค้นหา flows ที่ได้รับผลกระทบจากไฟล์ที่เปลี่ยนแปลง
list_communities_toolแสดงรายการ code communities ที่ตรวจพบ
get_community_toolรับรายละเอียดของ community เดียว
get_architecture_overview_toolภาพรวมสถาปัตยกรรมจากโครงสร้าง community
detect_changes_toolการวิเคราะห์ผลกระทบการเปลี่ยนแปลงที่ให้คะแนนความเสี่ยงสำหรับการรีวิวโค้ด
get_hub_nodes_toolค้นหาโหนดที่มีการเชื่อมต่อมากที่สุด (จุดร้อนทางสถาปัตยกรรม)
get_bridge_nodes_toolค้นหาจุดคอขวดผ่าน betweenness centrality
get_knowledge_gaps_toolระบุจุดอ่อนเชิงโครงสร้างและจุดร้อนที่ยังไม่ได้ทดสอบ
get_surprising_connections_toolตรวจจับการเชื่อมโยงข้าม community ที่ไม่คาดคิด
get_suggested_questions_toolคำถามรีวิวที่สร้างขึ้นโดยอัตโนมัติจากการวิเคราะห์
refactor_toolดูตัวอย่างการเปลี่ยนชื่อ, การตรวจจับโค้ดที่ไม่ได้ใช้, คำแนะนำ
apply_refactor_toolใช้การ refactoring ที่เคยดูตัวอย่างไว้ก่อนหน้านี้
generate_wiki_toolสร้าง markdown wiki จาก communities
get_wiki_page_toolดึงหน้า wiki ที่เฉพาะเจาะจง
list_repos_toolแสดงรายการ repositories ที่ลงทะเบียน
cross_repo_search_toolค้นหาข้าม repositories ที่ลงทะเบียนทั้งหมด

MCP Prompts (5 เทมเพลตเวิร์กโฟลว์): review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check

หากต้องการยกเว้นพาธจากการทำดัชนี ให้สร้างไฟล์ .code-review-graphignore ใน root ของ repository ของคุณ:

code
generated/**
*.generated.ts
vendor/**
node_modules/**

หมายเหตุ: ใน git repos เฉพาะไฟล์ที่ถูกติดตามเท่านั้นที่จะถูกทำดัชนี (git ls-files) ดังนั้นไฟล์ที่ถูก gitignore จะถูกข้ามโดยอัตโนมัติ ใช้ .code-review-graphignore เพื่อยกเว้นไฟล์ที่ถูกติดตามหรือเมื่อ git ไม่พร้อมใช้งาน

กลุ่มการพึ่งพาเสริม:

bash
pip install "code-review-graph[embeddings]"          # การฝังเวกเตอร์ในเครื่อง (sentence-transformers)
pip install "code-review-graph[google-embeddings]"   # การฝัง Google Gemini
pip install "code-review-graph[communities]"         # การตรวจจับชุมชน (igraph)
pip install "code-review-graph[enrichment]"          # การเสริมการแก้ไขการเรียกใช้ Python (Jedi)
pip install "code-review-graph[eval]"                # เกณฑ์การประเมิน (matplotlib)
pip install "code-review-graph[wiki]"                # การสร้าง Wiki ด้วยสรุป LLM (ollama)
pip install "code-review-graph[all]"                 # การพึ่งพาเสริมทั้งหมด

ตัวแปรสภาพแวดล้อม

ตัวแปรคำอธิบายค่าเริ่มต้น
CRG_GIT_TIMEOUTระยะเวลาหมดเวลาเป็นวินาทีสำหรับการดำเนินการ Git30
CRG_DATA_DIRไดเรกทอรีสำหรับแทนที่ฐานข้อมูลกราฟและสิ่งประดิษฐ์กราฟที่สร้างขึ้น-
CRG_EMBEDDING_MODELโมเดลเริ่มต้นสำหรับการฝังเวกเตอร์all-MiniLM-L6-v2
CRG_ACCEPT_CLOUD_EMBEDDINGSระงับคำเตือนการส่งออกข้อมูลการฝังบนคลาวด์

เอกสารโปรเจกต์

อ่านเอกสารต้นฉบับ

README วิธีติดตั้ง วิธีใช้งาน และข้อกำหนดจาก repository ต้นฉบับ

ดูไฟล์บน GitHub
tirth8205%2Fcode-review-graph | Trendshift
PyPIDownloadsStarsMIT LicenceCIPython 3.10+MCPWebsiteDiscord

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.

The Token Problem: 38x to 528x token reduction across 6 real repositories

Quick Start

bash
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.

One Install, Every Platform: auto-detects Codex, Claude Code, CodeBuddy Code, Cursor, Windsurf, Zed, Continue, OpenCode, Antigravity, Gemini CLI, Qwen, Qoder, Kiro, and GitHub Copilot

To target a specific platform:

bash
code-review-graph install --platform codex       # configure only Codex
code-review-graph install --platform cursor      # configure only Cursor
code-review-graph install --platform claude-code  # configure only Claude Code
code-review-graph install --platform gemini-cli   # configure only Gemini CLI
code-review-graph install --platform kiro         # configure only Kiro
code-review-graph install --platform copilot      # configure only GitHub Copilot (VS Code)
code-review-graph install --platform copilot-cli  # configure only GitHub Copilot CLI
code-review-graph install --platform codebuddy    # configure only CodeBuddy Code

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).

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.

bash
code-review-graph uninstall --dry-run    # preview every action; write nothing
code-review-graph uninstall              # preview, ask for confirmation, then apply
code-review-graph uninstall --yes        # apply without prompting
code-review-graph uninstall --all-repos  # also clean every registered repository
code-review-graph uninstall --keep-data  # remove integrations but keep graph databases
code-review-graph uninstall --keep-user-configs --repo .  # clean this project only

Then open your project and ask your AI assistant:

code
Build the code review graph for this project

The initial build takes ~10 seconds for a 500-file project. After that, watch mode and supported hooks can keep the graph updated automatically.

How It Works

How your AI assistant uses the graph: User asks for review, AI checks MCP tools, graph returns blast radius and risk scores, AI reads only what matters

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.

Architecture pipeline: Repository to Tree-sitter Parser to SQLite Graph to Blast Radius to Minimal Review Set

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 visualization showing how a change to login() propagates to callers, dependents, and tests

Incremental updates in < 2 seconds

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.

Incremental update flow: supported hook or watch update triggers diff, finds dependents, re-parses only 5 files while 2,910 are skipped

The monorepo problem, solved

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.

code-review-graph repo: 208,821 source tokens funnel down to ~2,495 token graph responses — 93x fewer tokens per question

Broad language coverage + Jupyter notebooks

Language coverage organized by category: Web, Backend, Systems, Mobile, Scripting, Config, plus Jupyter and Databricks notebook support

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. Current support includes Python, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, Terraform/OpenTofu structure (.tf; generic .hcl files are recognized as file nodes), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, Astro files parsed through the TypeScript parser, Jupyter/Databricks notebooks (.ipynb), and Perl XS files (.xs). Generic YAML is not treated as source code.

PHP projects additionally get repository-bounded Composer PSR-4 resolution, Blade template references, and Laravel Route/Eloquent semantic edges when the source includes explicit framework imports, model inheritance, and receiver evidence.

Add your own language (no fork needed)

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:

toml
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]

The generic tree-sitter walker handles extraction from there — no code changes, and built-in languages can never be overridden. See docs/CUSTOM_LANGUAGES.md for the schema reference, validation rules, and a worked end-to-end example.

Risk-scored PR reviews in CI (GitHub Action)

The same analysis runs as a composite GitHub Action — and it stays local-first: the knowledge graph is built and queried entirely on your CI runner, with no source code sent to any external service. On each pull request the action posts a single sticky comment with risk-scored functions, affected execution flows, and test gaps, updated in place on every push. An optional fail-on-risk input turns the review into a merge gate.

yaml
# .github/workflows/code-review-graph.yml
on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: tirth8205/code-review-graph@v2.3.6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

See docs/GITHUB_ACTION.md for inputs, risk levels, and caching details, or the dogfood workflow this repo runs on itself in .github/workflows/pr-review.yml.


Benchmarks

Benchmarks across 6 real repositories: ~82x median per-question token reduction (528x max), 0.71 average impact F1 against graph-derived ground truth

Headline number: the median per-question token reduction across the 6 repos is ~82x (whole-corpus baseline vs graph query). The frequently quoted 528x is the maximum — a single best-case repo (fastapi) — not the typical result.

All numbers come from the automated evaluation runner against 6 real open-source repositories (13 commits total). Every config pins an upstream SHA, the Leiden community detector runs with a fixed seed, and embeddings are deterministic on CPU — so two runs on different machines produce identical numbers. The full reproduction recipe with expected outputs is in docs/REPRODUCING.md. A weekly report-only run on the two smallest configs lives in .github/workflows/eval.yml.

For a typical agent question ("how does authentication work", "what is the main entry point", etc.), the graph returns ~2,000–3,500 tokens of targeted search hits + neighbor edges instead of forcing the agent to read every source file. The table below averages over the 5 sample questions defined in code_review_graph/token_benchmark.py.

RepoSnapshot SHAnaive_corpus_tokensavg graph_tokensReduction
fastapi0227991a951,0712,169528.4x
code-review-graph84bde354208,8212,49593.0x
gin5c00df8a166,8681,99091.8x
flaska29f88ce125,0221,98671.4x
expressb4ab7d65135,9553,46540.6x
httpxb55d463589,4922,43838.0x

Median per-question reduction across the 6 repos: ~82x. The range is 38x – 528x, where 528x is the best case (fastapi, the largest corpus), not the headline.

The whole-corpus baseline above is an upper bound no real agent pays: a competent agent greps for identifiers and reads only the best-matching files. The agent_baseline eval benchmark measures that realistic baseline — a pure-python grep over the corpus, top-3 files by match count, token-counted and compared to the graph query cost (evaluate/results/<repo>_agent_baseline_*.csv).

The formal eval/benchmarks/token_efficiency.py benchmark measures a different scenario — full get_review_context() JSON versus just the changed-file content of a commit — and reports ratios below 1 for small commits, because the review-context response carries impact-radius edges plus source snippets that exceed a tiny single-file diff. That is not a bug; the two benchmarks answer different questions. See docs/REPRODUCING.md for the full methodology.

Since v2.3.4, review and impact tools attach a compact context_savings estimate so MCP clients can see the approximate context saved per call. In v2.3.5 the CLI surfaces this as the boxed Token Savings panel shown above (see "Token Savings panel" in the Usage section) and adds --verify to cross-check against OpenAI's cl100k_base tokenizer. Calibration data in docs/REPRODUCING.md shows the estimate is within ~1% of real GPT-4 tokens in aggregate across 222 sample files.

Blast-radius analysis recovers every file in the ground truth on all 13 evaluation commits — but read that as an upper bound, not as "100% recall": in this mode the ground truth (changed files + files with call/import edges into them) is derived from the same graph the predictor traverses, so it is circular by construction. The over-prediction visible in the precision column is a deliberate trade-off: better to flag too many files than miss a broken dependency.

RepoCommitsAvg F1Avg PrecisionRecall (graph-derived upper bound)
httpx20.8640.7861.0
fastapi20.8340.7501.0
code-review-graph20.7340.5841.0
express20.6670.5001.0
flask20.6280.4811.0
gin30.6090.4391.0
Average130.7140.5781.000

The benchmark also runs an honest co-change mode: the predictor is seeded with a single changed file and graded against the other files the author actually touched in the same commit — independent-ish evidence from git history, not from the graph. Both modes appear side by side in the result CSVs (ground_truth_mode column). Co-change numbers will be added to the canonical stats once captured by the eval runner; we do not quote them before measuring.

RepoFilesNodesEdgesFlow DetectionSearch Latency
express1411,91017,553106ms0.7ms
fastapi1,1226,28527,117128ms1.5ms
flask831,4467,97495ms0.7ms
gin991,28616,762111ms0.5ms
httpx601,2537,89696ms0.4ms

Limitations and known weaknesses

  • Impact "recall 1.0" is graph-derived and circular: the historical ground truth comes from the same graph edges the predictor walks, so it is an upper bound by construction. The honest co-change mode (grade against files actually co-changed in the same commit) is measured alongside it; expect those numbers to be substantially lower.
  • Small single-file changes: Graph context can exceed naive file reads for trivial edits (see express results above). The overhead is the structural metadata that enables multi-file analysis.
  • Search quality (MRR 0.35): Keyword search finds the right result in the top-4 for most queries, but ranking needs improvement. Express queries return 0 hits due to module-pattern naming.
  • Flow detection (33% recall): Framework and conventional entry patterns are strongest for Python and PHP/Laravel. JavaScript and Go flow detection needs work.
  • Precision vs recall trade-off: Impact analysis is deliberately conservative. It flags files that might be affected, which means some false positives in large dependency graphs.

Features

FeatureDetails
Incremental updatesRe-parses only changed files. Subsequent updates complete in under 2 seconds.
Broad language + notebook supportPython, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, Terraform/OpenTofu structure (.tf; generic .hcl files are file-only), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, Astro files parsed through the TypeScript parser, Jupyter/Databricks (.ipynb), and Perl XS (.xs)
Framework-aware PHP parsingRepository-bounded Composer PSR-4 imports, Blade template references, and evidence-gated Laravel Route-to-controller and Eloquent relationship edges
Blast-radius analysisShows which functions, classes, and files are likely affected by a change
Auto-update hooksHooks and watch mode can update the graph on file saves and supported commit hooks
Semantic searchOptional vector embeddings via sentence-transformers, Google Gemini, MiniMax, or any OpenAI-compatible endpoint (real OpenAI, Azure, new-api, LiteLLM, vLLM, LocalAI)
Interactive visualisationD3.js force-directed graph with search, community legend toggles, and degree-scaled nodes
Hub & bridge detectionFind most-connected nodes and architectural chokepoints via betweenness centrality
Surprise scoringDetect unexpected coupling: cross-community, cross-language, peripheral-to-hub edges
Knowledge gap analysisIdentify isolated nodes, untested hotspots, thin communities, and structural weaknesses
Suggested questionsAuto-generated review questions from graph analysis (bridges, hubs, surprises)
Edge confidenceThree-tier confidence scoring (EXTRACTED/INFERRED/AMBIGUOUS) with float scores on edges
Graph traversalFree-form BFS/DFS exploration from any node with configurable depth and token budget
Export formatsGraphML (Gephi/yEd), Neo4j Cypher, Obsidian vault with wikilinks, SVG static graph
Graph diffCompare graph snapshots over time: new/removed nodes, edges, community changes
Token benchmarkingMeasure naive full-corpus tokens vs graph query tokens with per-question ratios
Estimated context savingsCompact context_savings metadata on relevant MCP/CLI review outputs, labelled as estimated and kept to three small fields
Memory loopPersist Q&A results as markdown for re-ingestion, so the graph grows from queries
Community auto-splitOversized communities (>25% of graph) are recursively split via Leiden
Execution flowsTrace call chains from entry points, sorted by weighted criticality
Community detectionCluster related code via Leiden algorithm with resolution scaling for large graphs
Architecture overviewAuto-generated architecture map with coupling warnings
Risk-scored reviewsdetect_changes maps diffs to affected functions, flows, and test gaps
Custom languagesAdd new languages via .code-review-graph/languages.toml — no fork or code changes needed
GitHub ActionSticky risk-scored PR review comments in CI, with an optional fail-on-risk merge gate
Refactoring toolsRename preview, framework-aware dead code detection, community-driven suggestions
Wiki generationAuto-generate markdown wiki from community structure
Multi-repo registryRegister multiple repos, search across all of them
Multi-repo daemoncrg-daemon watches multiple repos as child processes, with health checks and auto-restart
MCP prompts5 workflow templates: review, architecture, debug, onboard, pre-merge
Full-text searchFTS5-powered hybrid search combining keyword and vector similarity
Local storageSQLite file in .code-review-graph/. Core graph storage needs no external database or cloud service.
Watch modeContinuous graph updates as you work

Usage

CommandDescription
/code-review-graph:build-graphBuild or rebuild the code graph
/code-review-graph:review-deltaReview changes since last commit
/code-review-graph:review-prFull PR review with blast-radius analysis
bash
code-review-graph install          # Auto-detect and configure all platforms
code-review-graph install --platform <name>  # Target a specific platform
code-review-graph uninstall --dry-run  # Preview safe removal of installed artifacts
code-review-graph build            # Parse entire codebase
code-review-graph update           # Incremental update (changed files only)
code-review-graph status           # Graph statistics
code-review-graph watch            # Auto-update on file changes
code-review-graph visualize        # Generate interactive HTML graph
code-review-graph visualize --format json      # Export local graph data as JSON
code-review-graph visualize --format graphml   # Export as GraphML
code-review-graph visualize --format svg       # Export as SVG
code-review-graph visualize --format obsidian  # Export as Obsidian vault
code-review-graph visualize --format cypher    # Export as Neo4j Cypher
code-review-graph wiki             # Generate markdown wiki from communities
code-review-graph detect-changes --brief         # Risk panel + token savings (read-only)
code-review-graph update --brief                 # Refresh graph + same panel
code-review-graph detect-changes --brief --verify  # Cross-check vs tiktoken
code-review-graph register <path>  # Register repo in multi-repo registry
code-review-graph unregister <id>  # Remove repo from registry
code-review-graph repos            # List registered repositories
code-review-graph daemon start     # Start multi-repo watch daemon
code-review-graph daemon stop      # Stop the daemon
code-review-graph daemon status    # Show daemon status and repos
code-review-graph eval             # Run evaluation benchmarks
code-review-graph serve            # Start MCP server

JSON exports stay inside the local graph data directory, which Git ignores by default. They can contain absolute paths and code-structure metadata, so inspect and sanitize an export before publishing it outside your machine.

Both commands print the same compact panel showing how many tokens the graph saved you compared to handing the changed files to an agent raw. They differ in one thing: whether the graph gets refreshed first.

text
┌─────────────────────── Token Savings ────────────────────────┐
│ Full context would be:     12,921 tokens                     │
│ Graph context used:           762 tokens                     │
│ Saved:                     12,159 tokens (~94%)              │
│ Breakdown: Functions 244 · Tests 191 · Risk 244 · Other 83   │
└──────────────────────────────────────────────────────────────┘
CommandWhat it doesWhen to use
detect-changes --briefRead-only. Looks at your current changes, queries the existing graph, prints the panel. ~1 sec.Most of the time — the hooks (or crg-daemon) keep the graph fresh in the background, so this is enough.
update --briefRe-parses your changed files into the graph first, then prints the same panel. ~5 sec.After a rebase, a large change set, or any time you suspect the graph is stale.

Both end with the same panel because both call the same analyze_changes() step at the end. The difference is whether the graph itself got refreshed before that analysis ran.

Add --verify to either command to cross-check the displayed numbers against OpenAI's cl100k_base tokenizer (the GPT-4 family). Requires pip install tiktoken. The estimate stays within ~1% of real tokens on a typical change set — see docs/REPRODUCING.md for the calibration data.

The same context_savings metadata is also attached automatically to the JSON responses of get_impact_radius, get_review_context, detect_changes, and get_architecture_overview MCP tools, so AI agents can surface the savings to humans in chat without any extra prompting.

If your editor doesn't support hooks (e.g. Cursor, OpenCode), or you just want your graph to stay fresh in the background without any editor integration, the daemon is for you. It watches your repos for file changes and automatically rebuilds the graph — no manual build or update commands needed.

The daemon is included with code-review-graph — no separate install required.

Quick setup:

bash
# 1. Register the repos you want to watch
crg-daemon add ~/project-a --alias proj-a
crg-daemon add ~/project-b

# 2. Start the daemon (runs in the background)
crg-daemon start

# 3. That's it — graphs stay up to date automatically
crg-daemon status                 # check daemon and per-repo watcher status
crg-daemon logs --repo proj-a -f  # tail logs for a specific repo
crg-daemon stop                   # stop daemon and all watcher processes

Also available as code-review-graph daemon start|stop|status|....

Under the hood, crg-daemon add writes to a TOML config file at ~/.code-review-graph/watch.toml. You can also edit this file directly:

toml
[[repos]]
path = "/home/user/project-a"
alias = "proj-a"

[[repos]]
path = "/home/user/project-b"
alias = "project-b"

The daemon monitors this config file for changes and automatically starts/stops watcher processes as repos are added or removed. Health checks every 30 seconds restart dead watchers. No external dependencies required.

See docs/COMMANDS.md for the full config reference and all available options.

Your AI assistant uses these automatically once the graph is built.

ToolDescription
build_or_update_graph_toolBuild or incrementally update the graph
run_postprocess_toolRe-run flow detection, community detection, and FTS indexing
get_minimal_context_toolUltra-compact context (~100 tokens) — call this first
get_impact_radius_toolBlast radius of changed files
get_review_context_toolToken-optimised review context with structural summary
query_graph_toolCallers, callees, tests, imports, inheritance queries
traverse_graph_toolBFS/DFS traversal from any node with token budget
semantic_search_nodes_toolSearch code entities by name or meaning
embed_graph_toolCompute vector embeddings for semantic search
list_graph_stats_toolGraph size and health
get_docs_section_toolRetrieve documentation sections
find_large_functions_toolFind functions/classes exceeding a line-count threshold
list_flows_toolList execution flows sorted by criticality
get_flow_toolGet details of a single execution flow
get_affected_flows_toolFind flows affected by changed files
list_communities_toolList detected code communities
get_community_toolGet details of a single community
get_architecture_overview_toolArchitecture overview from community structure
detect_changes_toolRisk-scored change impact analysis for code review
get_hub_nodes_toolFind most-connected nodes (architectural hotspots)
get_bridge_nodes_toolFind chokepoints via betweenness centrality
get_knowledge_gaps_toolIdentify structural weaknesses and untested hotspots
get_surprising_connections_toolDetect unexpected cross-community coupling
get_suggested_questions_toolAuto-generated review questions from analysis
refactor_toolRename preview, dead code detection, suggestions
apply_refactor_toolApply a previously previewed refactoring
generate_wiki_toolGenerate markdown wiki from communities
get_wiki_page_toolRetrieve a specific wiki page
list_repos_toolList registered repositories
cross_repo_search_toolSearch across all registered repositories

MCP Prompts (5 workflow templates): review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check

To exclude paths from indexing, create a .code-review-graphignore file in your repository root:

code
generated/**
*.generated.ts
vendor/**
node_modules/**

Note: in git repos, only tracked files are indexed (git ls-files), so gitignored files are skipped automatically. Use .code-review-graphignore to exclude tracked files or when git isn't available.

Optional dependency groups:

bash
pip install "code-review-graph[embeddings]"          # Local vector embeddings (sentence-transformers)
pip install "code-review-graph[google-embeddings]"   # Google Gemini embeddings
pip install "code-review-graph[communities]"         # Community detection (igraph)
pip install "code-review-graph[enrichment]"          # Python call-resolution enrichment (Jedi)
pip install "code-review-graph[eval]"                # Evaluation benchmarks (matplotlib)
pip install "code-review-graph[wiki]"                # Wiki generation with LLM summaries (ollama)
pip install "code-review-graph[all]"                 # All optional dependencies

Environment Variables

VariableDescriptionDefault
CRG_GIT_TIMEOUTTimeout in seconds for Git operations30
CRG_DATA_DIROverride directory for graph databases and generated graph artefacts-
CRG_EMBEDDING_MODELDefault model for vector embeddingsall-MiniLM-L6-v2
CRG_ACCEPT_CLOUD_EMBEDDINGSSuppress the cloud embedding egress warning after explicit acknowledgement-
CRG_ALLOW_REMOTE_CODEAllow HuggingFace models that require trust_remote_code=True0
CRG_MAX_IMPACT_NODESMaximum nodes to include in impact analysis500
CRG_MAX_IMPACT_DEPTHSearch depth for blast-radius analysis2
CRG_MAX_BFS_DEPTHMaximum depth for graph traversal15
CRG_MAX_CHANGED_FUNCSMaximum changed functions analysed in one change report500
CRG_MAX_TRANSITIVE_FRONTIERMaximum frontier size for transitive caller/callee expansion50
CRG_TOOL_TIMEOUTOptional timeout in seconds for bounded MCP tools (0 disables timeout)0
CRG_RECURSE_SUBMODULESInclude git submodules in file collection when set to 1, true, or yes-
CRG_TOOLSComma-separated allowlist of MCP tools to expose when serving-
GOOGLE_API_KEYAPI key for Google Gemini embeddings-
MINIMAX_API_KEYAPI key for MiniMax embeddings-
CRG_OPENAI_BASE_URLOpenAI-compatible embeddings endpoint-
CRG_OPENAI_API_KEYAPI key for OpenAI-compatible embeddings-
CRG_OPENAI_MODELModel name for OpenAI-compatible embeddings-
CRG_OPENAI_DIMENSIONPin embedding dimension (v3 models support reduction)-
NO_COLORIf set, disables ANSI colors in terminal-
CRG_SERIAL_PARSEIf 1, disables parallel parsing (use for debugging)-

OpenAI-compatible embeddings (real OpenAI, Azure, or any self-hosted gateway like new-api / LiteLLM / vLLM / LocalAI / Ollama in openai mode) need no extra install — just set the environment variables and pass provider="openai" to embed_graph:

bash
export CRG_OPENAI_BASE_URL=http://127.0.0.1:3000/v1     # or https://api.openai.com/v1
export CRG_OPENAI_API_KEY=sk-...
export CRG_OPENAI_MODEL=text-embedding-3-small          # whatever your gateway serves
# optional:
export CRG_OPENAI_DIMENSION=1536                        # pin dim (v3 models support reduction)
export CRG_OPENAI_BATCH_SIZE=100                        # lower for gateways with tight limits
                                                        # (e.g. Qwen text-embedding-v4 caps at 10)

The cloud-egress warning is auto-skipped when the base URL points to localhost (127.0.0.1, localhost, 0.0.0.0, ::1).

Model selection tip. Avoid -preview / -beta / -exp model IDs (e.g. google/gemini-embedding-2-preview) for anything you plan to keep long-term — preview models can change weights (different dimension → full re-embed required) or be deprecated without notice. Prefer stable GA releases such as text-embedding-3-small / text-embedding-3-large (OpenAI), Qwen/Qwen3-Embedding-8B (via self-hosted vLLM / LocalAI), or gemini-embedding-001 (via the native Gemini provider, which requires GOOGLE_API_KEY instead of the OpenAI-compatible path).

code-review-graph embeds identifiers, signatures, structural context, and a bounded first-paragraph docstring/doc-comment summary. It does not transmit function bodies. Graphs created before documentation extraction was added need one full code-review-graph build before re-embedding so every file is reparsed. Routine builds never refresh embeddings by default. To refresh an existing index after a build, explicitly pass both --embedding-provider and --embedding-model; cloud choices may transmit this source-derived text and incur API cost.

Tool Filtering

CRG exposes 30 MCP tools by default. In token-constrained environments, you can limit the server to a subset of tools using --tools or the CRG_TOOLS environment variable:

bash
# Via CLI flag
code-review-graph serve --tools query_graph_tool,semantic_search_nodes_tool,detect_changes_tool

# Via environment variable
CRG_TOOLS=query_graph_tool,semantic_search_nodes_tool code-review-graph serve

The CLI flag takes precedence over the environment variable. When neither is set, all tools are available. This is especially useful for MCP client configurations:

json
{
  "mcpServers": {
    "code-review-graph": {
      "command": "code-review-graph",
      "args": ["serve", "--tools", "query_graph_tool,semantic_search_nodes_tool,detect_changes_tool,get_review_context_tool"]
    }
  }
}

FAQ & how it compares

Short, honest answers in docs/FAQ.md:

Troubleshooting

pip / pipx cannot download hatchling (or Errno 9 / Bad file descriptor to PyPI)

Installing from a source tree (for example pipx install .) needs build dependencies from PyPI (for example hatchling). If you see Could not find a version that satisfies the requirement hatchling after connection warnings, the Python/pip in that terminal may not be able to open an HTTPS client to pypi.org (sometimes seen in an integrated editor terminal; less often system-wide with VPN, firewall, or proxy).

Options:

  1. 1Run the same command from **macOS Terminal.app** (or iTerm) instead of the IDE’s terminal, then retry `pipx install .` or `pipx install "git+https://..."` .
  2. 2Use **[uv](https://docs.astral.sh/uv/)** to install the CLI from a checkout (uses different download machinery than `pip` in many cases): cd /path/to/code-review-graph uv tool install . --force
  3. 3For **development in a clone** without a global install, use `uv sync` and `uv run code-review-graph …` (or activate `.venv` after `uv sync`).

Diagnose (optional): python3 scripts/diagnose_pypi_connectivity.py — if it prints FAILED, the issue is environment/network, not a wrong package name in this repo.

Windows Configuration Issues (Invalid JSON / Connection Closed)

If you are using Windows and encounter Invalid JSON: EOF while parsing or MCP error -32000: Connection closed when connecting via Claude Code, do not use the cmd /c wrapper in your config.

Ensure fastmcp is updated to at least 3.2.4+. Then, configure your ~/.claude.json to execute the .exe directly and pass the UTF-8 environment variable via the config:

json
"code-review-graph": {
  "command": "C:\\path\\to\\your\\venv\\Scripts\\code-review-graph.exe",
  "args": ["serve", "--repo", "C:\\path\\to\\your\\project"],
  "env": { "PYTHONUTF8": "1" }
}

Contributing

bash
git clone https://github.com/tirth8205/code-review-graph.git
cd code-review-graph
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

Edit code_review_graph/parser.py and add your extension to EXTENSION_TO_LANGUAGE along with node type mappings in _CLASS_TYPES, _FUNCTION_TYPES, _IMPORT_TYPES, and _CALL_TYPES. Include a test fixture and open a PR.

Licence

MIT. See LICENSE.

#ai-coding#claude#claude-code#code-review#graphrag#incremental#knowledge-graph#llm#mcp#python#static-analysis#tree-sitter