cartog
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesecartog — Code Graph Navigation Skill
cartog — 代码图谱导航工具
When to Use
适用场景
Use cartog before reaching for grep, cat, or file reads when you need to:
- Understand the structure of a file →
cartog outline <file> - Find who calls a function →
cartog callers <name> - See what a function calls →
cartog callees <name> - Assess refactoring impact →
cartog impact <name> --depth 3 - Find all references →
cartog refs <name> - Understand class hierarchies →
cartog hierarchy <class> - See file dependencies →
cartog deps <file>
当你需要完成以下操作时,请在使用grep、cat或读取文件之前先使用cartog:
- 理解文件结构 →
cartog outline <file> - 查找调用某个函数的对象 →
cartog callers <name> - 查看某个函数调用了哪些内容 →
cartog callees <name> - 评估重构影响 →
cartog impact <name> --depth 3 - 查找所有引用 →
cartog refs <name> - 理解类继承层级 →
cartog hierarchy <class> - 查看文件依赖 →
cartog deps <file>
Workflow Rules
工作流规则
- Before you grep or read a file to understand structure, query cartog first.
- Use instead of
cartog outline <file>when you need structure, not content.cat <file> - Before refactoring, run to see the blast radius.
cartog impact <symbol> - Only fall back to grep/read when cartog doesn't have what you need (e.g., reading actual implementation logic, string literals, config values).
- After making code changes, run to update the graph.
cartog index .
- 在使用grep或读取文件来理解结构之前,先查询cartog。
- 使用替代
cartog outline <file>,当你需要了解结构而非内容时。cat <file> - 在重构之前,运行查看影响范围。
cartog impact <symbol> - 仅当cartog无法满足需求时(例如查看实际实现逻辑、字符串字面量、配置值),再使用grep或读取文件。
- 完成代码修改后,运行来更新图谱。
cartog index .
Setup
安装配置
Ensure cartog is indexed before first use:
bash
bash scripts/ensure_indexed.sh首次使用前请确保已完成cartog的索引构建:
bash
bash scripts/ensure_indexed.shCommands Reference
命令参考
Index (build/rebuild)
索引(构建/重建)
bash
cartog index . # Index current directory
cartog index src/ # Index specific directorybash
cartog index . # 索引当前目录
cartog index src/ # 索引指定目录Outline (file structure)
大纲(文件结构)
bash
cartog outline src/auth/tokens.pyOutput shows symbols with types, signatures, and line ranges — no need to read the file.
bash
cartog outline src/auth/tokens.py输出内容包含符号的类型、签名和行号范围——无需读取文件内容。
Callers (who calls this?)
调用方(谁调用了这个函数?)
bash
cartog callers validate_tokenbash
cartog callers validate_tokenCallees (what does this call?)
被调用方(这个函数调用了哪些内容?)
bash
cartog callees UserService.authenticatebash
cartog callees UserService.authenticateImpact (transitive blast radius)
影响范围(传递性影响半径)
bash
cartog impact SessionManager --depth 3Shows everything that transitively depends on a symbol up to N hops.
bash
cartog impact SessionManager --depth 3展示所有与该符号存在N层以内传递依赖的内容。
Refs (all references)
所有引用
bash
cartog refs parse_configReturns calls, imports, inherits — every edge pointing to this name.
bash
cartog refs parse_config返回调用、导入、继承关系——所有指向该名称的关联。
Hierarchy (inheritance tree)
继承层级(继承树)
bash
cartog hierarchy BaseServicebash
cartog hierarchy BaseServiceDeps (file imports)
文件依赖(导入关系)
bash
cartog deps src/routes/auth.pybash
cartog deps src/routes/auth.pyStats (index summary)
统计信息(索引摘要)
bash
cartog statsbash
cartog statsJSON Output
JSON输出
All commands support for structured output:
--jsonbash
cartog --json callers validate_token
cartog --json outline src/auth/tokens.py所有命令均支持参数以生成结构化输出:
--jsonbash
cartog --json callers validate_token
cartog --json outline src/auth/tokens.pyDecision Heuristics
决策指引
| I need to... | Use |
|---|---|
| Know what's in a file | |
| Find usages of a function | |
| Understand what a function does at a high level | |
| Check if a change is safe | |
| Find all references (imports, calls, inherits) | |
| Understand class hierarchy | |
| See file dependencies | |
| Read actual implementation logic | |
| Search for string literals / config | |
| 我需要... | 使用命令 |
|---|---|
| 了解文件内容结构 | |
| 查找函数的调用方 | |
| 从宏观层面理解函数功能 | |
| 检查代码变更是否安全 | |
| 查找所有引用(导入、调用、继承) | |
| 理解类继承层级 | |
| 查看文件依赖关系 | |
| 查看实际实现逻辑 | |
| 搜索字符串字面量/配置项 | |
Limitations
局限性
- Structural/heuristic resolution, not full semantic. ~90% accuracy for cross-file references.
- Currently supports: Python, TypeScript/JavaScript, Rust, Go. Java planned.
- Does not index string literals, comments (except docstrings), or config values.
- Method resolution is name-based — resolves
foo.bar(), notbarspecifically.Foo.bar
- 采用结构化/启发式解析,而非完整语义分析。跨文件引用的准确率约为90%。
- 当前支持:Python、TypeScript/JavaScript、Rust、Go。计划支持Java。
- 不索引字符串字面量、注释(文档字符串除外)或配置值。
- 方法解析基于名称——会解析
foo.bar(),而非特指bar。Foo.bar