README.md
1.8 KB
codegraph
本项目代码的轻量索引,探索代码结构时优先用它,而不是大范围 grep 或整篇读文件。
- 覆盖范围:
app/、scripts/、tests/(Python,用标准库ast精确解析:函数/类/方法、 行号、调用关系、import)和web/src/(TS/TSX,用正则近似解析:import/export、行号)。 - 索引文件
graph.json不随代码自动更新,改动较大后手动重建一次即可:
python tools/codegraph/build_codegraph.py
查询
python tools/codegraph/query_codegraph.py stats # 总览
python tools/codegraph/query_codegraph.py file app/api/documents.py # 这个文件有什么、依赖谁、被谁依赖
python tools/codegraph/query_codegraph.py symbol run_extract # 这个符号定义在哪、被谁调用
python tools/codegraph/query_codegraph.py search extract # 模糊搜符号名
python tools/codegraph/query_codegraph.py callers parse_file # 谁调用了它(Python,粒度到函数)
python tools/codegraph/query_codegraph.py importers web/src/lib/api.ts # 谁 import 了它(TS)
已知局限
- TS/TSX 是正则近似解析,不是真 AST:拿到的是 import/export 级别的信息,抓不到函数内部的调用链。
- Python 的
callers/symbol调用关系是按函数名字符串匹配的(不做跨文件的精确符号解析), 同名函数会被合并到一起——结果是「大概率相关的线索」,不是绝对精确的引用列表,findings 仍需用 Read/Grep 在具体文件里确认一遍。 - 不追踪运行时动态调用(
getattr、装饰器注入、DI 容器等)。
对于以上局限触发的场景(需要精确调用点、跨语言追踪、动态调用),退回到 Grep/Explore agent。