Skip to content

Commit f645147

Browse files
author
invalid
committed
refactor(plugin): restructure skills into unified entry skill + commands + hooks
- Replace 5 individual skills with 1 unified codemap skill for smart routing - Add 5 slash commands (scan, load, query, update, impact) for direct invocation - Add SessionStart hook to auto-detect .codemap/ and prompt user - Bump version to 0.2.0 - Update README with new structure, commands, and workflow
1 parent ca27e9a commit f645147

15 files changed

Lines changed: 301 additions & 231 deletions

File tree

.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.1.0"
10+
"version": "0.2.0"
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.1.0",
16+
"version": "0.2.0",
1717
"source": "./ccplugin",
1818
"category": "productivity",
1919
"author": { "name": "killvxk" },

README.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ Run the following commands inside a Claude Code session (these are slash command
7171

7272
After installation, **restart Claude Code** for the plugin to take effect.
7373

74-
> **原理 / How it works:** Claude Code 读取根目录的 `.claude-plugin/marketplace.json`,其中 `"source": "./ccplugin"` 指向插件目录。然后从 `ccplugin/.claude-plugin/plugin.json` 加载插件清单,自动发现 `ccplugin/skills/` 下的所有 skill。
74+
> **原理 / How it works:** Claude Code 读取根目录的 `.claude-plugin/marketplace.json`,其中 `"source": "./ccplugin"` 指向插件目录。然后从 `ccplugin/.claude-plugin/plugin.json` 加载插件清单,自动发现 `ccplugin/commands/` 下的斜杠命令、`ccplugin/skills/` 下的 skill、以及 `ccplugin/hooks/` 下的事件钩子
7575
>
76-
> 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 all skills under `ccplugin/skills/`.
76+
> 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/`.
7777
7878
#### 5. 验证插件已安装 / Verify plugin installed
7979

8080
重启 Claude Code 后,输入 / After restarting Claude Code, type:
8181

8282
```
83-
/scan
83+
/codemap:codemap-scan
8484
```
8585

86-
如果插件正确安装,该 skill 会被识别并触发代码扫描流程
86+
如果插件正确安装,该命令会触发代码扫描流程
8787

88-
If the plugin is installed correctly, this skill will be recognized and trigger the code scan workflow.
88+
If the plugin is installed correctly, this command will trigger the code scan workflow.
8989

9090
#### 卸载 / Uninstall
9191

@@ -175,12 +175,18 @@ CodeMap/
175175
├── ccplugin/ # 插件根目录 (CLAUDE_PLUGIN_ROOT)
176176
│ ├── .claude-plugin/
177177
│ │ └── plugin.json # 插件清单 / Plugin manifest
178-
│ ├── skills/ # Claude Code Skills (自动触发)
179-
│ │ ├── codemap-scan/SKILL.md # 全量扫描
180-
│ │ ├── codemap-load/SKILL.md # 智能加载
181-
│ │ ├── codemap-update/SKILL.md # 增量更新
182-
│ │ ├── codemap-query/SKILL.md # 符号查询
183-
│ │ └── codemap-impact/SKILL.md # 影响分析
178+
│ ├── commands/ # 斜杠命令 / Slash commands
179+
│ │ ├── scan.md # /codemap:codemap-scan
180+
│ │ ├── load.md # /codemap:codemap-load
181+
│ │ ├── update.md # /codemap:codemap-update
182+
│ │ ├── query.md # /codemap:codemap-query
183+
│ │ └── impact.md # /codemap:codemap-impact
184+
│ ├── skills/ # 自动触发 Skill / Auto-triggering skill
185+
│ │ └── codemap/SKILL.md # 统一入口,智能路由 / Unified entry, smart routing
186+
│ ├── hooks/ # 事件钩子 / Event hooks
187+
│ │ ├── hooks.json # SessionStart 自动检测
188+
│ │ └── scripts/
189+
│ │ └── detect-codemap.sh
184190
│ └── cli/ # CLI 工具
185191
│ ├── bin/codegraph.js # 入口 / Entry point
186192
│ ├── src/ # 源码 / Source
@@ -242,28 +248,39 @@ codegraph impact auth --depth 3 --dir /path/to/project
242248

243249
---
244250

245-
## Skills
251+
## Skills & Commands
246252

247-
作为 Claude Code 插件安装后,以下 skill 会根据对话上下文自动触发
253+
作为 Claude Code 插件安装后,提供以下能力
248254

249-
When installed as a Claude Code plugin, these skills auto-trigger based on conversation context:
255+
When installed as a Claude Code plugin, the following capabilities are available:
250256

251-
| Skill | 触发词 / Triggers On |
257+
### 自动触发 / Auto-Triggering
258+
259+
`codemap` skill 会根据对话上下文自动激活,智能判断该执行哪个操作。同时 `SessionStart` hook 会在每次会话开始时自动检测 `.codemap/` 是否存在并提示。
260+
261+
The `codemap` skill auto-activates based on conversation context and intelligently routes to the right operation. A `SessionStart` hook also detects `.codemap/` at session start.
262+
263+
### 斜杠命令 / Slash Commands
264+
265+
也可以手动调用:/ You can also invoke manually:
266+
267+
| 命令 / Command | 描述 / Description |
252268
|-------|------------|
253-
| `codemap-scan` | "扫描", "索引", "scan", "index", "map codebase" |
254-
| `codemap-load` | "加载图谱", "项目结构", "load", "code structure" |
255-
| `codemap-update` | "更新图谱", "refresh", "代码改了" |
256-
| `codemap-query` | "查找", "谁调用了", "where is", "find function" |
257-
| `codemap-impact` | "影响范围", "refactor impact", "change impact" |
269+
| `/codemap:codemap-scan` | 全量扫描项目,生成 .codemap/ 图谱 / Full scan, generate .codemap/ graph |
270+
| `/codemap:codemap-load [target]` | 加载图谱到上下文(概览/模块/文件)/ Load graph into context |
271+
| `/codemap:codemap-update` | 增量更新图谱 / Incremental update |
272+
| `/codemap:codemap-query <symbol>` | 查询符号定义和调用关系 / Query symbol definitions and call relations |
273+
| `/codemap:codemap-impact <target>` | 分析变更影响范围 / Analyze change impact |
258274

259275
### 典型工作流 / Typical Workflow
260276

261277
```
262-
1. 首次使用 / First time: /scan → 生成 .codemap/ 图谱
263-
2. 新会话开始 / New session: /load → 加载概览 (~500 tokens)
264-
3. 深入模块 / Dive into module: /load auth → 加载 auth 模块 (~2-5k tokens)
265-
4. 代码修改后 / After changes: /update → 增量更新图谱
266-
5. 重构前 / Before refactor: /impact auth → 查看影响范围
278+
1. 首次使用 / First time: /codemap:codemap-scan → 生成 .codemap/ 图谱
279+
2. 新会话开始 / New session: (自动检测 / auto-detected) → SessionStart hook 提示加载
280+
3. 加载概览 / Load overview: /codemap:codemap-load → 加载概览 (~500 tokens)
281+
4. 深入模块 / Dive into module: /codemap:codemap-load auth → 加载 auth 模块 (~2-5k tokens)
282+
5. 代码修改后 / After changes: /codemap:codemap-update → 增量更新图谱
283+
6. 重构前 / Before refactor: /codemap:codemap-impact auth → 查看影响范围
267284
```
268285

269286
---

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.1.0",
3+
"version": "0.2.0",
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/commands/impact.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: codemap-impact
3+
description: 分析修改某个模块或文件的影响范围,用于重构前的风险评估
4+
arguments:
5+
- name: target
6+
description: 要分析的模块名或文件路径
7+
required: true
8+
- name: depth
9+
description: 依赖追踪深度,默认 3
10+
required: false
11+
---
12+
13+
# CodeMap Impact — 变更影响分析
14+
15+
分析修改某个模块或文件会影响到哪些其他部分,用于重构前的风险评估。
16+
17+
## 执行步骤
18+
19+
### 1. 执行影响分析
20+
21+
```bash
22+
node "${CLAUDE_PLUGIN_ROOT}/cli/bin/codegraph.js" impact "{{target}}" --depth {{depth:-3}}
23+
```
24+
25+
`<target>` 可以是模块名(如 `auth`)或文件路径(如 `src/auth/login.ts`)。
26+
27+
### 2. 展示影响范围
28+
29+
向用户报告:
30+
- 目标:被分析的模块/文件
31+
- 直接依赖方:直接导入此模块/文件的模块
32+
- 传递依赖方:间接受影响的模块(通过依赖链传播)
33+
- 受影响文件总数
34+
- 建议关注点:依赖链最深的文件优先关注
35+
36+
### 3. 给出建议
37+
38+
- 影响范围较小(< 5 个文件)→ 可以直接修改
39+
- 影响范围中等(5-20 个文件)→ 建议分步重构
40+
- 影响范围较大(> 20 个文件)→ 建议先写迁移计划

ccplugin/commands/load.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: codemap-load
3+
description: 从 .codemap/ 加载代码图谱到当前会话上下文,支持加载概览、指定模块或文件
4+
arguments:
5+
- name: target
6+
description: 模块名或文件路径。不指定则加载项目概览
7+
required: false
8+
---
9+
10+
# CodeMap Load — 智能加载代码图谱
11+
12+
`.codemap/` 读取已缓存的代码图谱,按需注入上下文。相比全量读取源码,可节省约 95% token。
13+
14+
## 执行步骤
15+
16+
### 1. 检测图谱是否存在
17+
18+
```bash
19+
ls .codemap/graph.json 2>/dev/null && echo "CODEMAP_EXISTS" || echo "NO_CODEMAP"
20+
```
21+
22+
如果不存在,建议用户先执行 `/codemap:codemap-scan` 生成图谱。
23+
24+
### 2. 检查图谱新鲜度
25+
26+
```bash
27+
node "${CLAUDE_PLUGIN_ROOT}/cli/bin/codegraph.js" status
28+
```
29+
30+
如果图谱可能过期(commit hash 不匹配或距离上次更新很久),建议先执行 `/codemap:codemap-update`
31+
32+
### 3. 加载策略
33+
34+
#### 无参数
35+
36+
加载项目概览(约 500 token)。使用 Read 工具读取 `.codemap/slices/_overview.json`
37+
38+
#### 带模块名: `<target>` 是模块名
39+
40+
```bash
41+
node "${CLAUDE_PLUGIN_ROOT}/cli/bin/codegraph.js" slice {{target}} --with-deps
42+
```
43+
44+
加载目标模块的完整切片 + 依赖模块概览。
45+
46+
#### 带文件路径: `<target>` 是文件路径
47+
48+
查找该文件所属模块,加载该模块切片。

ccplugin/commands/query.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: codemap-query
3+
description: 在代码图谱中查询函数、类、类型的定义位置和调用关系
4+
arguments:
5+
- name: symbol
6+
description: 要查询的符号名称(函数名、类名、类型名)
7+
required: true
8+
- name: type
9+
description: "过滤符号类型: function, class, type"
10+
required: false
11+
---
12+
13+
# CodeMap Query — 符号查询
14+
15+
在代码图谱中搜索函数、类、类型或模块的定义和关联信息。
16+
17+
## 执行步骤
18+
19+
### 1. 执行查询
20+
21+
```bash
22+
node "${CLAUDE_PLUGIN_ROOT}/cli/bin/codegraph.js" query "{{symbol}}" {{#type}}--type {{type}}{{/type}}
23+
```
24+
25+
### 2. 展示结果
26+
27+
向用户展示:
28+
- 符号类型(函数/类/接口/类型别名)
29+
- 定义位置(文件:行号)
30+
- 函数签名(如果是函数)
31+
- 调用者和被调用者
32+
- 所属模块
33+
34+
### 3. 深入查看
35+
36+
如果用户需要看源码细节,根据查询结果的文件路径和行号范围,使用 Read 工具读取对应的源码段落。只读取精确需要的代码,而不是整个文件。

ccplugin/commands/scan.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: codemap-scan
3+
description: 全量扫描项目代码,生成 AST 结构化图谱到 .codemap/ 目录
4+
arguments:
5+
- name: dir
6+
description: 要扫描的目录路径,默认为当前目录
7+
required: false
8+
---
9+
10+
# CodeMap Scan — 全量代码图谱扫描
11+
12+
通过 AST 解析生成项目的结构化代码图谱,存储到 `.codemap/` 目录。
13+
14+
## 执行步骤
15+
16+
### 1. 检测图谱是否已存在
17+
18+
```bash
19+
ls .codemap/graph.json 2>/dev/null && echo "CODEMAP_EXISTS" || echo "NO_CODEMAP"
20+
```
21+
22+
- 如果已存在,提醒用户图谱已存在,建议使用 `/codemap:codemap-update` 增量更新。如果用户确认要重新全量扫描,继续执行。
23+
- 如果不存在,继续执行。
24+
25+
### 2. 执行全量扫描
26+
27+
```bash
28+
node "${CLAUDE_PLUGIN_ROOT}/cli/bin/codegraph.js" scan {{dir:-.}}
29+
```
30+
31+
### 3. 展示扫描摘要
32+
33+
使用 Read 工具读取 `.codemap/slices/_overview.json`,向用户展示:
34+
- 项目名称、源文件总数与语言分布
35+
- 检测到的模块列表(各模块文件数、函数数)
36+
- 入口文件、模块间依赖关系概览
37+
38+
### 4. 提示后续操作
39+
40+
- `/codemap:codemap-load` — 加载项目概览到上下文
41+
- `/codemap:codemap-load <模块名>` — 加载特定模块详细图谱
42+
- `/codemap:codemap-query <符号名>` — 查询函数/类的定义和调用关系
43+
- 图谱已持久化,下次会话只需 `/codemap:codemap-load` 即可恢复上下文
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
---
22
name: codemap-update
3-
description: >
4-
Use after code has been modified, after git commits, when the code graph
5-
might be outdated, or when the user says "更新图谱", "同步", "refresh",
6-
"update map", "代码改了", "图谱过期", "刷新", "重新索引变更".
7-
Also use when /load detects the graph commit hash doesn't match current HEAD.
3+
description: 增量更新代码图谱,只重新解析变更的文件
84
---
95

10-
# CodeMap Update -- 增量更新图谱
6+
# CodeMap Update 增量更新图谱
117

128
基于文件哈希比较,只重新解析变更的文件,将更新合并到现有图谱。
139

@@ -28,12 +24,12 @@ CLI 会自动:
2824

2925
### 2. 展示变更摘要
3026

31-
向用户报告 CLI 输出中的信息
27+
向用户报告:
3228
- 新增文件数 (+N)
3329
- 修改文件数 (~N)
3430
- 删除文件数 (-N)
3531
- 更新耗时
3632

3733
### 3. 刷新已加载的上下文
3834

39-
如果当前会话已经通过 `/load` 加载了某些模块的图谱,且这些模块受到更新影响,重新执行 `/load` 刷新上下文
35+
如果当前会话已经通过 `/codemap:codemap-load` 加载了某些模块的图谱,且这些模块受到更新影响,重新执行加载刷新上下文

ccplugin/hooks/hooks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"hooks": [
3+
{
4+
"event": "SessionStart",
5+
"hooks": [
6+
{
7+
"type": "command",
8+
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-codemap.sh"
9+
}
10+
]
11+
}
12+
]
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
# detect-codemap.sh — SessionStart hook
3+
# 检测当前工作目录是否有 .codemap/ 图谱,输出提示信息
4+
5+
if [ -f ".codemap/graph.json" ]; then
6+
echo "[CodeMap] 检测到 .codemap/ 图谱已存在。建议使用 /codemap:codemap-load 加载项目上下文,或 /codemap:codemap-update 更新图谱。"
7+
else
8+
echo "[CodeMap] 未检测到 .codemap/ 图谱。如需生成代码图谱,请使用 /codemap:codemap-scan。"
9+
fi

0 commit comments

Comments
 (0)