|
1 | 1 | # CodeMap |
2 | 2 |
|
| 3 | +基于 AST 的代码图谱映射插件,适用于 [Claude Code](https://docs.anthropic.com/en/docs/claude-code)。扫描代码库一次,持久化结构图谱,后续会话加载紧凑切片即可恢复上下文——相比重新读取全部源码,节省约 95% token。 |
| 4 | + |
3 | 5 | AST-based code graph mapping plugin for [Claude Code](https://docs.anthropic.com/en/docs/claude-code). Scan your codebase once, persist a structural graph, and load compact slices in future sessions — saving ~95% tokens compared to re-reading all source files. |
4 | 6 |
|
5 | | -## Features |
| 7 | +## 特性 / Features |
6 | 8 |
|
7 | | -- **AST Parsing** — Uses tree-sitter (WASM) for accurate structural analysis, no regex guessing |
8 | | -- **Multi-Language** — TypeScript, JavaScript, Python, Go, Rust, Java, C, C++ |
9 | | -- **Smart Slicing** — Project overview (~500 tokens) + per-module slices (~2-5k tokens) instead of full source (~200k+) |
10 | | -- **Incremental Updates** — File hash comparison detects changes; only re-parses modified files |
11 | | -- **Impact Analysis** — See what's affected before you refactor |
12 | | -- **Auto-Triggering** — Skills activate automatically based on your conversation context |
| 9 | +- **AST 解析 / AST Parsing** — 使用 tree-sitter (WASM) 进行精确的结构分析,非正则猜测 / Uses tree-sitter (WASM) for accurate structural analysis, no regex guessing |
| 10 | +- **多语言支持 / Multi-Language** — TypeScript, JavaScript, Python, Go, Rust, Java, C, C++ |
| 11 | +- **智能切片 / Smart Slicing** — 项目概览 (~500 tokens) + 按模块切片 (~2-5k tokens),替代全量源码 (~200k+) / Project overview (~500 tokens) + per-module slices (~2-5k tokens) instead of full source (~200k+) |
| 12 | +- **增量更新 / Incremental Updates** — 基于文件哈希比较检测变更,仅重新解析修改的文件 / File hash comparison detects changes; only re-parses modified files |
| 13 | +- **影响分析 / Impact Analysis** — 重构前查看哪些模块会受影响 / See what's affected before you refactor |
| 14 | +- **自动触发 / Auto-Triggering** — Skill 根据对话上下文自动激活 / Skills activate automatically based on your conversation context |
13 | 15 |
|
14 | | -## Installation |
| 16 | +## 安装 / Installation |
15 | 17 |
|
16 | 18 | ```bash |
17 | 19 | cd cli |
18 | 20 | npm install |
19 | 21 | ``` |
20 | 22 |
|
| 23 | +然后在 Claude Code 中注册插件,指向 `.claude-plugin/` 目录。 |
| 24 | + |
21 | 25 | Then register the plugin in Claude Code by pointing to the `.claude-plugin/` directory. |
22 | 26 |
|
23 | | -## CLI Commands |
| 27 | +## CLI 命令 / CLI Commands |
| 28 | + |
| 29 | +所有命令通过 `node cli/bin/codegraph.js <command>` 运行。 |
24 | 30 |
|
25 | 31 | All commands are run via `node cli/bin/codegraph.js <command>`. |
26 | 32 |
|
27 | | -| Command | Description | |
| 33 | +| 命令 / Command | 描述 / Description | |
28 | 34 | |---------|-------------| |
29 | | -| `scan <dir>` | Full AST scan, generates `.codemap/` with graph + slices | |
30 | | -| `status` | Show graph metadata (files, modules, last scan time) | |
31 | | -| `query <symbol>` | Search for functions, classes, types by name | |
32 | | -| `slice [module]` | Output project overview or a specific module slice as JSON | |
33 | | -| `update` | Incremental update — re-parse only changed files | |
34 | | -| `impact <target>` | Analyze which modules are affected by changing a target | |
| 35 | +| `scan <dir>` | 全量 AST 扫描,生成 `.codemap/` 图谱和切片 / Full AST scan, generates `.codemap/` with graph + slices | |
| 36 | +| `status` | 显示图谱元信息(文件数、模块、上次扫描时间)/ Show graph metadata (files, modules, last scan time) | |
| 37 | +| `query <symbol>` | 按名称搜索函数、类、类型 / Search for functions, classes, types by name | |
| 38 | +| `slice [module]` | 输出项目概览或指定模块切片(JSON)/ Output project overview or a specific module slice as JSON | |
| 39 | +| `update` | 增量更新——仅重新解析变更的文件 / Incremental update — re-parse only changed files | |
| 40 | +| `impact <target>` | 分析修改目标会影响哪些模块 / Analyze which modules are affected by changing a target | |
35 | 41 |
|
36 | | -### Examples |
| 42 | +### 示例 / Examples |
37 | 43 |
|
38 | 44 | ```bash |
39 | | -# Scan a project |
| 45 | +# 扫描项目 / Scan a project |
40 | 46 | node cli/bin/codegraph.js scan /path/to/project |
41 | 47 |
|
42 | | -# Check graph status |
| 48 | +# 检查图谱状态 / Check graph status |
43 | 49 | node cli/bin/codegraph.js status |
44 | 50 |
|
45 | | -# Query a symbol |
| 51 | +# 查询符号 / Query a symbol |
46 | 52 | node cli/bin/codegraph.js query "handleLogin" |
47 | 53 |
|
48 | | -# Get module slice with dependencies |
| 54 | +# 获取模块切片(含依赖)/ Get module slice with dependencies |
49 | 55 | node cli/bin/codegraph.js slice auth --with-deps |
50 | 56 |
|
51 | | -# Incremental update after code changes |
| 57 | +# 增量更新 / Incremental update after code changes |
52 | 58 | node cli/bin/codegraph.js update |
53 | 59 |
|
54 | | -# Impact analysis before refactoring |
| 60 | +# 影响分析 / Impact analysis before refactoring |
55 | 61 | node cli/bin/codegraph.js impact auth --depth 3 |
56 | 62 | ``` |
57 | 63 |
|
58 | 64 | ## Skills |
59 | 65 |
|
| 66 | +作为 Claude Code 插件安装后,以下 skill 会根据对话上下文自动触发: |
| 67 | + |
60 | 68 | When installed as a Claude Code plugin, these skills auto-trigger based on conversation context: |
61 | 69 |
|
62 | | -| Skill | Triggers On | |
| 70 | +| Skill | 触发词 / Triggers On | |
63 | 71 | |-------|------------| |
64 | 72 | | `/scan` | "扫描", "索引", "scan", "index", "map codebase" | |
65 | 73 | | `/load` | "加载图谱", "项目结构", "load", "code structure" | |
66 | 74 | | `/update` | "更新图谱", "refresh", "代码改了" | |
67 | 75 | | `/query` | "查找", "谁调用了", "where is", "find function" | |
68 | 76 | | `/impact` | "影响范围", "refactor impact", "change impact" | |
69 | 77 |
|
70 | | -## Supported Languages |
| 78 | +## 支持的语言 / Supported Languages |
71 | 79 |
|
72 | | -| Language | Extensions | Extracted Structures | |
| 80 | +| 语言 / Language | 扩展名 / Extensions | 提取结构 / Extracted Structures | |
73 | 81 | |----------|-----------|---------------------| |
74 | | -| TypeScript | `.ts`, `.tsx` | Functions, imports, exports, classes, interfaces, type aliases | |
75 | | -| JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | Functions, imports, exports, classes | |
76 | | -| Python | `.py` | Functions (decorated), imports, `__all__` exports, classes | |
77 | | -| Go | `.go` | Functions, methods (with receiver), imports, exported names, structs, type specs | |
78 | | -| Rust | `.rs` | Functions, impl methods, use declarations, pub exports, structs, enums, traits | |
79 | | -| Java | `.java` | Methods, constructors, imports, public exports, classes, interfaces, enums | |
80 | | -| C | `.c`, `.h` | Functions, `#include`, non-static exports, structs, enums, typedefs | |
81 | | -| C++ | `.cpp`, `.cc`, `.cxx`, `.hpp`, `.hh` | Qualified functions (`Class::method`), includes, classes, structs, namespaces | |
| 82 | +| TypeScript | `.ts`, `.tsx` | 函数、导入、导出、类、接口、类型别名 / Functions, imports, exports, classes, interfaces, type aliases | |
| 83 | +| JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | 函数、导入、导出、类 / Functions, imports, exports, classes | |
| 84 | +| Python | `.py` | 函数(含装饰器)、导入、`__all__` 导出、类 / Functions (decorated), imports, `__all__` exports, classes | |
| 85 | +| Go | `.go` | 函数、方法(含接收者)、导入、导出名、结构体、类型声明 / Functions, methods (with receiver), imports, exported names, structs, type specs | |
| 86 | +| Rust | `.rs` | 函数、impl 方法、use 声明、pub 导出、结构体、枚举、trait / Functions, impl methods, use declarations, pub exports, structs, enums, traits | |
| 87 | +| Java | `.java` | 方法、构造器、导入、public 导出、类、接口、枚举 / Methods, constructors, imports, public exports, classes, interfaces, enums | |
| 88 | +| C | `.c`, `.h` | 函数、`#include`、非 static 导出、结构体、枚举、typedef / Functions, `#include`, non-static exports, structs, enums, typedefs | |
| 89 | +| C++ | `.cpp`, `.cc`, `.cxx`, `.hpp`, `.hh` | 限定函数名(`Class::method`)、include、类、结构体、命名空间 / Qualified functions (`Class::method`), includes, classes, structs, namespaces | |
| 90 | + |
| 91 | +## 图谱结构 / Graph Structure |
82 | 92 |
|
83 | | -## Graph Structure |
| 93 | +扫描后生成 `.codemap/` 目录: |
84 | 94 |
|
85 | 95 | Scanning produces a `.codemap/` directory: |
86 | 96 |
|
87 | 97 | ``` |
88 | 98 | .codemap/ |
89 | | -├── graph.json # Full structural graph |
90 | | -├── meta.json # File hashes, timestamps, commit info |
| 99 | +├── graph.json # 完整结构图谱 / Full structural graph |
| 100 | +├── meta.json # 文件哈希、时间戳、提交信息 / File hashes, timestamps, commit info |
91 | 101 | └── slices/ |
92 | | - ├── _overview.json # Compact project overview (~500 tokens) |
93 | | - ├── auth.json # Per-module detailed slice |
| 102 | + ├── _overview.json # 紧凑项目概览 (~500 tokens) / Compact project overview (~500 tokens) |
| 103 | + ├── auth.json # 按模块的详细切片 / Per-module detailed slice |
94 | 104 | ├── api.json |
95 | 105 | └── ... |
96 | 106 | ``` |
97 | 107 |
|
98 | | -## Tests |
| 108 | +## 测试 / Tests |
99 | 109 |
|
100 | 110 | ```bash |
101 | 111 | cd cli |
102 | 112 | npm test |
103 | 113 | ``` |
104 | 114 |
|
105 | | -## License |
| 115 | +## 许可证 / License |
106 | 116 |
|
107 | 117 | [MIT](LICENSE) |
0 commit comments