Skip to content

Commit baba06c

Browse files
invalidclaude
andcommitted
feat(v0.2.1): multi-level binary discovery, auto-download, and Rust CLI hardening
Plugin infrastructure: - Rewrite codegraph/codegraph.cmd wrappers with 5-level binary lookup (PATH > ~/.codemap/bin/ > plugin dir > dev build > auto-download) - Update detect-codemap.sh hook with same discovery logic - Update README with new installation workflow Rust CLI improvements: - Convert walk_nodes from recursive to iterative (prevent stack overflow) - Add Default impl to all language adapters (clippy compliance) - Unify convert_types: exclude class/struct for all languages - Fix posix_normalize handling of leading ".." - Add loop protection in unix_to_datetime (year < 10000) - Sanitize module names in slicer to prevent path traversal - Use HashSet for dedup check in differ - Proper error handling for parser set_language - Remove unused parser module Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 49bcf9c commit baba06c

24 files changed

Lines changed: 371 additions & 126 deletions

.claude-plugin/marketplace.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
},
88
"metadata": {
99
"description": "AST-based code graph mapping plugin for Claude Code — scan once, persist structural graph, load compact slices to save ~95% tokens",
10-
"version": "0.2.0"
10+
"version": "0.2.1"
1111
},
1212
"plugins": [
1313
{
1414
"name": "codemap",
1515
"description": "AST-based code graph mapping plugin — scan codebase, persist structural graph, load compact slices in future sessions, saving ~95% tokens compared to re-reading all source files",
16-
"version": "0.2.0",
16+
"version": "0.2.1",
1717
"source": "./ccplugin",
1818
"category": "productivity",
1919
"author": { "name": "killvxk" },

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ docs/impl-notes/
88
*.log
99
*.tgz
1010
.DS_Store
11+
.claude/
12+
docs/plan/
13+
.codemap-rust-backup/
1114

1215
# Rust 构建产物
1316
rust-cli/target/

README.md

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,41 @@ git clone https://github.com/killvxk/CodeMap.git
3232
cd CodeMap
3333
```
3434

35-
#### 2. 验证 CLI 可用 / Verify CLI works
35+
#### 2. 二进制引擎 / Binary Engine
3636

37-
预编译二进制已包含在 `ccplugin/bin/` 目录中,无需额外安装依赖:
37+
插件首次执行命令时会**自动从 GitHub Releases 下载**对应平台的二进制到 `~/.codemap/bin/`,无需手动操作。
3838

39-
The pre-compiled binary is included in `ccplugin/bin/` — no additional dependencies required:
39+
The plugin **automatically downloads** the platform-specific binary from GitHub Releases to `~/.codemap/bin/` on first command execution. No manual steps required.
4040

41-
```bash
42-
# Linux / macOS
43-
ccplugin/bin/codegraph-linux --version # Linux x64
44-
ccplugin/bin/codegraph-macos --version # macOS (Intel/Apple Silicon)
41+
你也可以提前手动安装(二进制查找优先级从高到低):
42+
43+
You can also install manually. Binary lookup order (highest to lowest priority):
4544

46-
# Windows (Git Bash / PowerShell)
47-
ccplugin/bin/codegraph-windows.exe --version
45+
| 优先级 / Priority | 位置 / Location | 说明 / Description |
46+
|---|---|---|
47+
| 1 | `PATH` | 全局安装 / Globally installed |
48+
| 2 | `~/.codemap/bin/` | 用户级专用目录(推荐)/ User-level dedicated directory (recommended) |
49+
| 3 | `ccplugin/bin/` | 插件目录(向后兼容)/ Plugin directory (backward compatible) |
50+
| 4 | `rust-cli/target/release/` | 本地开发构建 / Local dev build |
51+
| 5 | 自动下载 / Auto-download | 从 GitHub Releases 下载到 `~/.codemap/bin/` |
52+
53+
```bash
54+
# 手动安装示例 / Manual install example
55+
mkdir -p ~/.codemap/bin
56+
# Linux x64
57+
curl -fSL -o ~/.codemap/bin/codegraph-x86_64-linux \
58+
https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-x86_64-linux
59+
chmod +x ~/.codemap/bin/codegraph-x86_64-linux
60+
61+
# macOS Apple Silicon
62+
curl -fSL -o ~/.codemap/bin/codegraph-aarch64-macos \
63+
https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-aarch64-macos
64+
chmod +x ~/.codemap/bin/codegraph-aarch64-macos
4865
```
4966

50-
> 如果 `ccplugin/bin/` 中没有适合你平台的二进制,可以从 [GitHub Releases](https://github.com/killvxk/CodeMap/releases) 下载,或参考下方"从源码构建"说明
67+
> 支持通过环境变量 `CODEMAP_HOME` 自定义目录(默认 `~/.codemap`
5168
>
52-
> 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.
69+
> Customize the directory via `CODEMAP_HOME` env var (default `~/.codemap`).
5370
5471
#### 3. 安装为 Claude Code 插件 / Install as Claude Code plugin
5572

@@ -99,23 +116,27 @@ If the plugin is installed correctly, this command will trigger the code scan wo
99116

100117
### 方式二:下载预编译二进制 / Download Pre-compiled Binary
101118

102-
[GitHub Releases](https://github.com/killvxk/CodeMap/releases) 下载适合你平台的二进制文件:
119+
[GitHub Releases](https://github.com/killvxk/CodeMap/releases) 下载适合你平台的二进制文件,放到 `~/.codemap/bin/` 或 PATH 中
103120

104-
Download the binary for your platform from [GitHub Releases](https://github.com/killvxk/CodeMap/releases):
121+
Download the binary for your platform from [GitHub Releases](https://github.com/killvxk/CodeMap/releases) and place it in `~/.codemap/bin/` or anywhere in your PATH:
105122

106123
```bash
107124
# Linux x64
108-
curl -L https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-linux -o codegraph
109-
chmod +x codegraph
110-
sudo mv codegraph /usr/local/bin/
125+
mkdir -p ~/.codemap/bin
126+
curl -fSL -o ~/.codemap/bin/codegraph-x86_64-linux \
127+
https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-x86_64-linux
128+
chmod +x ~/.codemap/bin/codegraph-x86_64-linux
111129

112-
# macOS (Intel / Apple Silicon — 通用二进制)
113-
curl -L https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-macos -o codegraph
114-
chmod +x codegraph
115-
sudo mv codegraph /usr/local/bin/
130+
# macOS (Apple Silicon)
131+
mkdir -p ~/.codemap/bin
132+
curl -fSL -o ~/.codemap/bin/codegraph-aarch64-macos \
133+
https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-aarch64-macos
134+
chmod +x ~/.codemap/bin/codegraph-aarch64-macos
116135

117136
# Windows (PowerShell)
118-
Invoke-WebRequest -Uri https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-windows.exe -OutFile codegraph.exe
137+
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.codemap\bin"
138+
Invoke-WebRequest -Uri https://github.com/killvxk/CodeMap/releases/latest/download/codegraph-x86_64-windows.exe `
139+
-OutFile "$env:USERPROFILE\.codemap\bin\codegraph-x86_64-windows.exe"
119140
```
120141

121142
安装后可以直接使用 `codegraph` 命令:
@@ -147,25 +168,14 @@ cargo build --release
147168
# 1. 确保测试通过 / Ensure tests pass
148169
cd rust-cli && cargo test
149170
150-
# 2. 交叉编译所有平台 / Cross-compile for all platforms
151-
cargo build --release --target x86_64-unknown-linux-gnu
152-
cargo build --release --target aarch64-apple-darwin
153-
cargo build --release --target x86_64-pc-windows-gnu
154-
155-
# 3. 提交并打 tag / Commit and tag
171+
# 2. 提交并打 tag,CI 自动构建并发布 / Commit, tag, and let CI build & release
156172
cd ..
157173
git add .
158-
git commit -m "release: v0.2.0"
159-
git tag v0.2.0
174+
git commit -m "release: v0.2.1"
175+
git tag v0.2.1
160176
git push origin main --tags
161-
162-
# 4. 在 GitHub 创建 Release,上传二进制 / Create GitHub Release and upload binaries
163-
gh release create v0.2.0 \
164-
ccplugin/bin/codegraph-linux \
165-
ccplugin/bin/codegraph-macos \
166-
ccplugin/bin/codegraph-windows.exe \
167-
--title "CodeMap v0.2.0" \
168-
--generate-notes
177+
# GitHub Actions 会自动为所有平台构建并创建 Release
178+
# GitHub Actions will automatically build for all platforms and create a Release
169179
```
170180

171181
---
@@ -191,10 +201,9 @@ CodeMap/
191201
│ │ ├── hooks.json # SessionStart 自动检测
192202
│ │ └── scripts/
193203
│ │ └── detect-codemap.sh
194-
│ └── bin/ # 预编译二进制 / Pre-compiled binaries
195-
│ ├── codegraph-linux # Linux x64
196-
│ ├── codegraph-macos # macOS (Intel + Apple Silicon)
197-
│ └── codegraph-windows.exe # Windows x64
204+
│ └── bin/ # 二进制 wrapper / Binary wrappers
205+
│ ├── codegraph # Unix wrapper (自动发现/下载二进制)
206+
│ └── codegraph.cmd # Windows wrapper
198207
├── rust-cli/ # Rust CLI 源码 / Rust CLI source
199208
│ ├── Cargo.toml
200209
│ ├── src/

ccplugin/.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codemap",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "AST-based code graph mapping plugin for Claude Code — scan once, persist structural graph, load compact slices to save ~95% tokens",
55
"author": {
66
"name": "killvxk",

ccplugin/bin/codegraph

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env bash
2-
# codegraph — platform-detecting wrapper
3-
# 根据当前 OS 和 CPU 架构选择正确的预编译二进制并执行
2+
# codegraph — platform-detecting wrapper with multi-level binary discovery
3+
# 查找优先级: PATH > ~/.codemap/bin/ > 插件目录 > 开发构建 > 自动下载
44

55
set -euo pipefail
66

7-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
# ── 平台检测 ──────────────────────────────────────────────────────────────────
88

9-
# 检测 OS
109
case "$(uname -s 2>/dev/null)" in
1110
Linux*) _OS="linux" ;;
1211
Darwin*) _OS="macos" ;;
@@ -17,7 +16,6 @@ case "$(uname -s 2>/dev/null)" in
1716
;;
1817
esac
1918

20-
# 检测 CPU 架构
2119
case "$(uname -m 2>/dev/null)" in
2220
x86_64|amd64) _ARCH="x86_64" ;;
2321
aarch64|arm64) _ARCH="aarch64" ;;
@@ -27,19 +25,84 @@ case "$(uname -m 2>/dev/null)" in
2725
;;
2826
esac
2927

30-
# 构造二进制路径
3128
_BIN_NAME="codegraph-${_ARCH}-${_OS}"
3229
if [ "$_OS" = "windows" ]; then
3330
_BIN_NAME="${_BIN_NAME}.exe"
3431
fi
3532

36-
_BIN_PATH="${SCRIPT_DIR}/${_BIN_NAME}"
33+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34+
CODEMAP_HOME="${CODEMAP_HOME:-$HOME/.codemap}"
35+
CODEMAP_BIN_DIR="${CODEMAP_HOME}/bin"
36+
GITHUB_REPO="killvxk/CodeMap"
37+
38+
# ── 多级查找 ──────────────────────────────────────────────────────────────────
39+
40+
_BIN=""
41+
42+
# 1. PATH 中的 arch-specific 二进制
43+
if command -v "$_BIN_NAME" >/dev/null 2>&1; then
44+
_BIN="$(command -v "$_BIN_NAME")"
45+
fi
46+
47+
# 2. ~/.codemap/bin/
48+
if [ -z "$_BIN" ] && [ -f "${CODEMAP_BIN_DIR}/${_BIN_NAME}" ]; then
49+
_BIN="${CODEMAP_BIN_DIR}/${_BIN_NAME}"
50+
fi
51+
52+
# 3. 插件目录 (向后兼容)
53+
if [ -z "$_BIN" ] && [ -f "${SCRIPT_DIR}/${_BIN_NAME}" ]; then
54+
_BIN="${SCRIPT_DIR}/${_BIN_NAME}"
55+
fi
56+
57+
# 4. 开发构建 (rust-cli/target/)
58+
if [ -z "$_BIN" ]; then
59+
_DEV_NAME="codegraph"
60+
[ "$_OS" = "windows" ] && _DEV_NAME="codegraph.exe"
61+
for _CANDIDATE in \
62+
"${SCRIPT_DIR}/../../rust-cli/target/release/${_DEV_NAME}" \
63+
"${SCRIPT_DIR}/../../rust-cli/target/debug/${_DEV_NAME}" \
64+
"./rust-cli/target/release/${_DEV_NAME}" \
65+
"./rust-cli/target/debug/${_DEV_NAME}"
66+
do
67+
if [ -f "$_CANDIDATE" ]; then
68+
_BIN="$_CANDIDATE"
69+
break
70+
fi
71+
done
72+
fi
73+
74+
# 5. 自动下载
75+
if [ -z "$_BIN" ]; then
76+
echo "[CodeMap] 未找到 codegraph 二进制 (${_BIN_NAME}),正在从 GitHub Releases 下载..." >&2
77+
78+
# 获取最新 release 的下载 URL
79+
_DOWNLOAD_URL="https://github.com/${GITHUB_REPO}/releases/latest/download/${_BIN_NAME}"
80+
81+
mkdir -p "$CODEMAP_BIN_DIR"
82+
_TARGET="${CODEMAP_BIN_DIR}/${_BIN_NAME}"
83+
84+
if command -v curl >/dev/null 2>&1; then
85+
curl -fSL --progress-bar -o "$_TARGET" "$_DOWNLOAD_URL"
86+
elif command -v wget >/dev/null 2>&1; then
87+
wget -q --show-progress -O "$_TARGET" "$_DOWNLOAD_URL"
88+
else
89+
echo "[CodeMap] 下载失败:未找到 curl 或 wget" >&2
90+
echo "[CodeMap] 请手动下载: ${_DOWNLOAD_URL}" >&2
91+
echo "[CodeMap] 放置到以下任一位置:" >&2
92+
echo "[CodeMap] 1. ~/.codemap/bin/${_BIN_NAME}" >&2
93+
echo "[CodeMap] 2. PATH 中的任意目录" >&2
94+
exit 1
95+
fi
96+
97+
if [ $? -ne 0 ] || [ ! -f "$_TARGET" ]; then
98+
echo "[CodeMap] 下载失败,请手动下载: ${_DOWNLOAD_URL}" >&2
99+
rm -f "$_TARGET"
100+
exit 1
101+
fi
37102

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
103+
chmod +x "$_TARGET"
104+
echo "[CodeMap] 已下载到 ${_TARGET}" >&2
105+
_BIN="$_TARGET"
43106
fi
44107

45-
exec "$_BIN_PATH" "$@"
108+
exec "$_BIN" "$@"

0 commit comments

Comments
 (0)