Skip to content

Commit e8d89e9

Browse files
invalidclaude
andcommitted
feat: add Rust CLI v0.2.0 with full AST code graph engine
Complete Rust rewrite of the Node.js CLI, providing native tree-sitter bindings for 8 languages (TS, JS, Python, Go, Rust, Java, C, C++). - 6 commands: scan, update, query, impact, status, slice - Incremental update via file hash diffing - Module dependency resolution (JS/TS relative imports) - Impact analysis with BFS transitive dependant traversal - Shared path utilities extracted to path_utils.rs - 286 tests passing across unit and integration suites - Plugin wrapper scripts and CI release workflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f645147 commit e8d89e9

51 files changed

Lines changed: 8003 additions & 109 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
name: Build ${{ matrix.target }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- target: x86_64-unknown-linux-gnu
20+
os: ubuntu-22.04
21+
artifact: codegraph-x86_64-linux
22+
- target: aarch64-unknown-linux-gnu
23+
os: ubuntu-22.04
24+
artifact: codegraph-aarch64-linux
25+
use_cross: true
26+
- target: x86_64-apple-darwin
27+
os: macos-13
28+
artifact: codegraph-x86_64-macos
29+
- target: aarch64-apple-darwin
30+
os: macos-14
31+
artifact: codegraph-aarch64-macos
32+
- target: x86_64-pc-windows-msvc
33+
os: windows-2022
34+
artifact: codegraph-x86_64-windows.exe
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Install Rust toolchain
40+
uses: dtolnay/rust-toolchain@stable
41+
with:
42+
targets: ${{ matrix.target }}
43+
44+
- name: Install cross
45+
if: matrix.use_cross
46+
run: cargo install cross --git https://github.com/cross-rs/cross
47+
48+
- name: Build (cross)
49+
if: matrix.use_cross
50+
working-directory: rust-cli
51+
run: cross build --release --target ${{ matrix.target }}
52+
53+
- name: Build (cargo)
54+
if: "!matrix.use_cross"
55+
working-directory: rust-cli
56+
run: cargo build --release --target ${{ matrix.target }}
57+
58+
- name: Rename binary (Unix)
59+
if: runner.os != 'Windows'
60+
run: |
61+
cp rust-cli/target/${{ matrix.target }}/release/codegraph ${{ matrix.artifact }}
62+
63+
- name: Rename binary (Windows)
64+
if: runner.os == 'Windows'
65+
run: |
66+
cp rust-cli/target/${{ matrix.target }}/release/codegraph.exe ${{ matrix.artifact }}
67+
68+
- name: Upload artifact
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: ${{ matrix.artifact }}
72+
path: ${{ matrix.artifact }}
73+
retention-days: 1
74+
75+
release:
76+
name: Create GitHub Release
77+
needs: build
78+
runs-on: ubuntu-22.04
79+
steps:
80+
- uses: actions/checkout@v4
81+
82+
- name: Download all artifacts
83+
uses: actions/download-artifact@v4
84+
with:
85+
path: dist/
86+
87+
- name: Flatten artifacts
88+
run: |
89+
mkdir -p release-bins
90+
find dist/ -type f | while read f; do
91+
cp "$f" "release-bins/$(basename "$f")"
92+
done
93+
ls -lh release-bins/
94+
95+
- name: Create Release
96+
uses: softprops/action-gh-release@v2
97+
with:
98+
files: release-bins/*
99+
generate_release_notes: true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ docs/impl-notes/
88
*.log
99
*.tgz
1010
.DS_Store
11+
12+
# Rust 构建产物
13+
rust-cli/target/
14+
15+
# 预编译二进制(通过 Release 分发,不入库)
16+
ccplugin/bin/codegraph-*

README.md

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AST-based code graph mapping plugin for [Claude Code](https://docs.anthropic.com
66

77
## 特性 / Features
88

9-
- **AST 解析 / AST Parsing** — 使用 tree-sitter (WASM) 进行精确的结构分析,非正则猜测 / Uses tree-sitter (WASM) for accurate structural analysis, no regex guessing
9+
- **AST 解析 / AST Parsing** — 使用 tree-sitter 原生绑定进行精确的结构分析,非正则猜测 / Uses tree-sitter native bindings for accurate structural analysis, no regex guessing
1010
- **多语言支持 / Multi-Language** — TypeScript, JavaScript, Python, Go, Rust, Java, C, C++
1111
- **智能切片 / Smart Slicing** — 项目概览 (~500 tokens) + 按模块切片 (~2-5k tokens),替代全量源码 (~200k+) / Project overview (~500 tokens) + per-module slices (~2-5k tokens) instead of full source (~200k+)
1212
- **增量更新 / Incremental Updates** — 基于文件哈希比较检测变更,仅重新解析修改的文件 / File hash comparison detects changes; only re-parses modified files
@@ -19,8 +19,6 @@ AST-based code graph mapping plugin for [Claude Code](https://docs.anthropic.com
1919

2020
### 前置条件 / Prerequisites
2121

22-
- **Node.js** >= 18
23-
- **npm** >= 9
2422
- **Claude Code** CLI ([安装指南 / Install Guide](https://docs.anthropic.com/en/docs/claude-code))
2523

2624
### 方式一:作为 Claude Code 插件安装(推荐)/ Install as Claude Code Plugin (Recommended)
@@ -32,22 +30,26 @@ git clone https://github.com/killvxk/CodeMap.git
3230
cd CodeMap
3331
```
3432

35-
#### 2. 安装 CLI 依赖 / Install CLI dependencies
33+
#### 2. 验证 CLI 可用 / Verify CLI works
3634

37-
```bash
38-
cd ccplugin/cli
39-
npm install
40-
cd ../..
41-
```
35+
预编译二进制已包含在 `ccplugin/bin/` 目录中,无需额外安装依赖:
4236

43-
#### 3. 验证 CLI 可用 / Verify CLI works
37+
The pre-compiled binary is included in `ccplugin/bin/` — no additional dependencies required:
4438

4539
```bash
46-
node ccplugin/cli/bin/codegraph.js --version
47-
# 输出 / Output: 0.1.0
40+
# Linux / macOS
41+
ccplugin/bin/codegraph-linux --version # Linux x64
42+
ccplugin/bin/codegraph-macos --version # macOS (Intel/Apple Silicon)
43+
44+
# Windows (Git Bash / PowerShell)
45+
ccplugin/bin/codegraph-windows.exe --version
4846
```
4947

50-
#### 4. 安装为 Claude Code 插件 / Install as Claude Code plugin
48+
> 如果 `ccplugin/bin/` 中没有适合你平台的二进制,可以从 [GitHub Releases](https://github.com/killvxk/CodeMap/releases) 下载,或参考下方"从源码构建"说明。
49+
>
50+
> If no binary matches your platform in `ccplugin/bin/`, download from [GitHub Releases](https://github.com/killvxk/CodeMap/releases) or see "Build from Source" below.
51+
52+
#### 3. 安装为 Claude Code 插件 / Install as Claude Code plugin
5153

5254
在 Claude Code 对话中执行以下命令(注意:这是 Claude Code 内部的斜杠命令,不是终端命令):
5355

@@ -75,7 +77,7 @@ After installation, **restart Claude Code** for the plugin to take effect.
7577
>
7678
> Claude Code reads `.claude-plugin/marketplace.json` at the repo root, where `"source": "./ccplugin"` points to the plugin directory. It then loads `ccplugin/.claude-plugin/plugin.json` and auto-discovers commands in `ccplugin/commands/`, skills in `ccplugin/skills/`, and hooks in `ccplugin/hooks/`.
7779
78-
#### 5. 验证插件已安装 / Verify plugin installed
80+
#### 4. 验证插件已安装 / Verify plugin installed
7981

8082
重启 Claude Code 后,输入 / After restarting Claude Code, type:
8183

@@ -93,17 +95,25 @@ If the plugin is installed correctly, this command will trigger the code scan wo
9395
/plugin uninstall codemap@codemap-plugins
9496
```
9597

96-
### 方式二:全局安装 CLI / Global CLI Installation
98+
### 方式二:下载预编译二进制 / Download Pre-compiled Binary
9799

98-
如果你只需要 CLI 工具(不需要 Claude Code 插件集成)
100+
[GitHub Releases](https://github.com/killvxk/CodeMap/releases) 下载适合你平台的二进制文件
99101

100-
If you only need the CLI tool (without Claude Code plugin integration):
102+
Download the binary for your platform from [GitHub Releases](https://github.com/killvxk/CodeMap/releases):
101103

102104
```bash
103-
git clone https://github.com/killvxk/CodeMap.git
104-
cd CodeMap/ccplugin/cli
105-
npm install
106-
npm link
105+
# Linux x64
106+
curl -L https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-linux -o codegraph
107+
chmod +x codegraph
108+
sudo mv codegraph /usr/local/bin/
109+
110+
# macOS (Intel / Apple Silicon — 通用二进制)
111+
curl -L https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-macos -o codegraph
112+
chmod +x codegraph
113+
sudo mv codegraph /usr/local/bin/
114+
115+
# Windows (PowerShell)
116+
Invoke-WebRequest -Uri https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-windows.exe -OutFile codegraph.exe
107117
```
108118

109119
安装后可以直接使用 `codegraph` 命令:
@@ -116,51 +126,43 @@ codegraph status /path/to/project
116126
codegraph query handleLogin --dir /path/to/project
117127
```
118128

119-
### 方式三:构建发布包 / Build Release Distribution
120-
121-
用于将 CLI 打包分发给他人或部署到 CI。
129+
### 方式三:从源码构建 / Build from Source
122130

123-
For packaging the CLI to distribute or deploy in CI.
131+
需要 Rust 工具链([rustup.rs](https://rustup.rs)):
124132

125-
#### 生成 npm tarball / Generate npm tarball
133+
Requires Rust toolchain ([rustup.rs](https://rustup.rs)):
126134

127135
```bash
128-
cd ccplugin/cli
129-
npm pack
130-
# 生成 / Produces: codegraph-0.1.0.tgz
131-
```
132-
133-
#### 从 tarball 安装 / Install from tarball
134-
135-
```bash
136-
npm install -g codegraph-0.1.0.tgz
137-
codegraph --version
136+
git clone https://github.com/killvxk/CodeMap.git
137+
cd CodeMap/rust-cli
138+
cargo build --release
139+
# 二进制输出到 / Binary at: target/release/codegraph
138140
```
139141

140142
#### GitHub Release 发布流程 / GitHub Release Workflow
141143

142144
```bash
143145
# 1. 确保测试通过 / Ensure tests pass
144-
cd ccplugin/cli && npm test
145-
146-
# 2. 更新版本号 / Bump version
147-
npm version patch # 或 minor / major
146+
cd rust-cli && cargo test
148147

149-
# 3. 生成发布包 / Generate release package
150-
npm pack
148+
# 2. 交叉编译所有平台 / Cross-compile for all platforms
149+
cargo build --release --target x86_64-unknown-linux-gnu
150+
cargo build --release --target aarch64-apple-darwin
151+
cargo build --release --target x86_64-pc-windows-gnu
151152

152-
# 4. 提交并打 tag / Commit and tag
153-
cd ../..
153+
# 3. 提交并打 tag / Commit and tag
154+
cd ..
154155
git add .
155-
git commit -m "release: v$(node -p "require('./ccplugin/cli/package.json').version")"
156-
git tag "v$(node -p "require('./ccplugin/cli/package.json').version")"
156+
git commit -m "release: v0.2.0"
157+
git tag v0.2.0
157158
git push origin main --tags
158159

159-
# 5. 在 GitHub 创建 Release,上传 .tgz 文件
160-
# Create a GitHub Release and upload the .tgz file
161-
gh release create "v$(node -p "require('./ccplugin/cli/package.json').version")" \
162-
ccplugin/cli/codegraph-*.tgz \
163-
--title "CodeMap v$(node -p "require('./ccplugin/cli/package.json').version")" \
160+
# 4. 在 GitHub 创建 Release,上传二进制 / Create GitHub Release and upload binaries
161+
gh release create v0.2.0 \
162+
ccplugin/bin/codegraph-linux \
163+
ccplugin/bin/codegraph-macos \
164+
ccplugin/bin/codegraph-windows.exe \
165+
--title "CodeMap v0.2.0" \
164166
--generate-notes
165167
```
166168

@@ -187,22 +189,24 @@ CodeMap/
187189
│ │ ├── hooks.json # SessionStart 自动检测
188190
│ │ └── scripts/
189191
│ │ └── detect-codemap.sh
190-
│ └── cli/ # CLI 工具
191-
│ ├── bin/codegraph.js # 入口 / Entry point
192-
│ ├── src/ # 源码 / Source
193-
│ │ ├── index.js # Commander 注册
194-
│ │ ├── scanner.js # 全量扫描引擎
195-
│ │ ├── parser.js # tree-sitter WASM 解析
196-
│ │ ├── graph.js # 图谱数据结构
197-
│ │ ├── differ.js # 增量更新引擎
198-
│ │ ├── query.js # 查询引擎
199-
│ │ ├── slicer.js # 切片生成
200-
│ │ ├── impact.js # 影响分析
201-
│ │ ├── traverser.js # 文件遍历与语言检测
202-
│ │ ├── commands/ # CLI 命令实现
203-
│ │ └── languages/ # 语言适配器 (8 种)
204-
│ ├── test/ # 测试 (84 tests)
205-
│ └── package.json
192+
│ └── bin/ # 预编译二进制 / Pre-compiled binaries
193+
│ ├── codegraph-linux # Linux x64
194+
│ ├── codegraph-macos # macOS (Intel + Apple Silicon)
195+
│ └── codegraph-windows.exe # Windows x64
196+
├── rust-cli/ # Rust CLI 源码 / Rust CLI source
197+
│ ├── Cargo.toml
198+
│ ├── src/
199+
│ │ ├── main.rs # CLI 入口(clap)
200+
│ │ ├── scanner.rs # 全量扫描引擎
201+
│ │ ├── graph.rs # 图谱数据结构
202+
│ │ ├── differ.rs # 增量更新引擎
203+
│ │ ├── query.rs # 查询引擎
204+
│ │ ├── slicer.rs # 切片生成
205+
│ │ ├── impact.rs # 影响分析
206+
│ │ ├── path_utils.rs # 共享路径工具函数
207+
│ │ ├── traverser.rs # 文件遍历与语言检测
208+
│ │ └── languages/ # 语言适配器 (8 种)
209+
│ └── tests/ # 集成测试 (286 tests)
206210
├── README.md
207211
└── LICENSE # MIT
208212
```
@@ -211,9 +215,9 @@ CodeMap/
211215

212216
## CLI 命令 / CLI Commands
213217

214-
所有命令通过 `codegraph <command>` `node ccplugin/cli/bin/codegraph.js <command>` 运行
218+
所有命令通过 `codegraph <command>` 运行(预编译二进制,无需 Node.js
215219

216-
All commands run via `codegraph <command>` or `node ccplugin/cli/bin/codegraph.js <command>`.
220+
All commands run via `codegraph <command>` (pre-compiled binary, no Node.js required).
217221

218222
| 命令 / Command | 描述 / Description |
219223
|---------|-------------|
@@ -322,9 +326,9 @@ Scanning produces a `.codemap/` directory inside the target project:
322326
## 测试 / Tests
323327

324328
```bash
325-
cd ccplugin/cli
326-
npm test
327-
# 84 tests, 14 test suites
329+
cd rust-cli
330+
cargo test
331+
# 286 tests, all passing
328332
```
329333

330334
## 许可证 / License

ccplugin/bin/codegraph

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# codegraph — platform-detecting wrapper
3+
# 根据当前 OS 和 CPU 架构选择正确的预编译二进制并执行
4+
5+
set -euo pipefail
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
# 检测 OS
10+
case "$(uname -s 2>/dev/null)" in
11+
Linux*) _OS="linux" ;;
12+
Darwin*) _OS="macos" ;;
13+
MINGW*|MSYS*|CYGWIN*) _OS="windows" ;;
14+
*)
15+
echo "[CodeMap] Unsupported OS: $(uname -s)" >&2
16+
exit 1
17+
;;
18+
esac
19+
20+
# 检测 CPU 架构
21+
case "$(uname -m 2>/dev/null)" in
22+
x86_64|amd64) _ARCH="x86_64" ;;
23+
aarch64|arm64) _ARCH="aarch64" ;;
24+
*)
25+
echo "[CodeMap] Unsupported architecture: $(uname -m)" >&2
26+
exit 1
27+
;;
28+
esac
29+
30+
# 构造二进制路径
31+
_BIN_NAME="codegraph-${_ARCH}-${_OS}"
32+
if [ "$_OS" = "windows" ]; then
33+
_BIN_NAME="${_BIN_NAME}.exe"
34+
fi
35+
36+
_BIN_PATH="${SCRIPT_DIR}/${_BIN_NAME}"
37+
38+
if [ ! -f "$_BIN_PATH" ]; then
39+
echo "[CodeMap] Binary not found: ${_BIN_PATH}" >&2
40+
echo "[CodeMap] Please download the release binary for ${_ARCH}-${_OS} from:" >&2
41+
echo "[CodeMap] https://github.com/killvxk/CodeMap/releases" >&2
42+
exit 1
43+
fi
44+
45+
exec "$_BIN_PATH" "$@"

0 commit comments

Comments
 (0)