@sdsrs/code-graph 0.163.0 → 0.165.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -6
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/agents/code-explorer.md +15 -12
- package/claude-plugin/hooks/hooks.json +91 -1
- package/claude-plugin/scripts/adopt.js +62 -37
- package/claude-plugin/scripts/cg-answer.js +7 -0
- package/claude-plugin/scripts/covering-tests.js +1 -2
- package/claude-plugin/scripts/doctor.js +40 -1
- package/claude-plugin/scripts/incremental-index.js +4 -1
- package/claude-plugin/scripts/lifecycle.js +49 -13
- package/claude-plugin/scripts/post-grep-inject.js +58 -3
- package/claude-plugin/scripts/pre-edit-guide.js +122 -83
- package/claude-plugin/scripts/pre-grep-guide.js +243 -11
- package/claude-plugin/scripts/pre-read-guide.js +42 -28
- package/claude-plugin/scripts/project-root.js +23 -1
- package/claude-plugin/scripts/recommendation-log.js +11 -9
- package/claude-plugin/scripts/session-edits.js +58 -3
- package/claude-plugin/scripts/session-init.js +142 -349
- package/claude-plugin/scripts/stop-impact.js +171 -10
- package/claude-plugin/scripts/user-prompt-context.js +48 -16
- package/claude-plugin/skills/explore/SKILL.md +10 -7
- package/claude-plugin/templates/code-graph-snapshot.yml +1 -1
- package/claude-plugin/templates/plugin_code_graph_mcp.md +58 -169
- package/package.json +6 -6
|
@@ -1,172 +1,61 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: code-graph-mcp
|
|
3
|
-
description: code-graph
|
|
2
|
+
name: code-graph-mcp plugin contract
|
|
3
|
+
description: When to use the code-graph CLI / MCP tools instead of rounds of Grep + Read, and what the graph cannot see
|
|
4
4
|
type: reference
|
|
5
5
|
---
|
|
6
|
-
# code-graph-mcp
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
> `node <插件目录>/claude-plugin/scripts/adopt.js unadopt`(SessionStart 的提示行
|
|
63
|
-
> 会印出这台机器上的完整路径)、`node <插件目录>/claude-plugin/scripts/doctor.js`。
|
|
64
|
-
>
|
|
65
|
-
> `grep` 是 drop-in 替代:`-F` 字面 / `-i` / `-w` / `-l` / `-c` 计数 / `-t <lang>` 按语言筛 /
|
|
66
|
-
> `-g <glob>` 路径过滤 / `-A/-B/-C N` 上下文 / `-M N` 行宽上限(默认 512,防长行刷屏)/
|
|
67
|
-
> 多路径 / `-m 0` 取消每文件上限,退出码兼容 grep(0/1/2),召回达 git-grep 级
|
|
68
|
-
> (tracked-but-gitignored 也能搜到),每条命中标注所属 fn/class。
|
|
69
|
-
>
|
|
70
|
-
> v0.10.0 起:tools/list 默认只暴露 7 个核心工具;下表"进阶 5"中的工具
|
|
71
|
-
> 已从 tools/list 隐藏以节省 session 启动 tokens。**Claude Code 里请走 CLI
|
|
72
|
-
> 子命令**(MCP schema 不在 list,Claude Code 的 ToolSearch 不会加载,直接
|
|
73
|
-
> 调用会得到 `No such tool available`——实测验证见下方"进阶 5")。写
|
|
74
|
-
> MCP SDK / 原生 `tools/call` JSON-RPC 的脚本场景仍可按名调用。
|
|
75
|
-
|
|
76
|
-
### 核心 7(tools/list 默认暴露)
|
|
77
|
-
|
|
78
|
-
| 意图 | 工具 | 关键参数 / 例子 |
|
|
79
|
-
|------|------|----------------|
|
|
80
|
-
| "谁调用 X?" / "X 调了啥?" | `get_call_graph` / `callgraph X` | 替代 `grep "X("` |
|
|
81
|
-
| "Y 模块长啥样?" | `module_overview` / `overview Y/` | 替代逐文件 Read |
|
|
82
|
-
| "找做 Z 的代码"(概念) | MCP `semantic_code_search`(RRF 混合);CLI `search`(纯 FTS5) | 不知道精确名;要向量召回走 MCP |
|
|
83
|
-
| "返回 T 类型的函数" | `ast_search --returns T` | 结构化筛选 |
|
|
84
|
-
| "X 在哪被引用?" | `find_references` / `refs X` | 含 callers/importers;`refs X --min-confidence extracted` 滤掉跨文件裸名低置信边(inferred/ambiguous) |
|
|
85
|
-
| "看 X 的源码 / 签名" | `get_ast_node` / `show X` | `include_impact=true` 影响面 / `include_similar=true` 嵌入近邻 |
|
|
86
|
-
| "项目结构总览" | `project_map` / `map` | 起手势用 `--compact` |
|
|
87
|
-
| "X 文件依赖谁?" / "Y 模块下的死代码" | `module_overview path=Y include_deps=true` / `include_dead=true` | 文件路径走 deps;目录/文件走 dead |
|
|
88
|
-
| HTTP 路由 → handler 链 | `get_call_graph route_path="GET /api/x"` | 取代 trace_http_chain |
|
|
89
|
-
|
|
90
|
-
### 旧名兼容 + CLI 速查(v0.18.4 fold 后)
|
|
91
|
-
|
|
92
|
-
v0.18.4 把原"进阶 5"折叠进核心 7 的 flag。**Claude Code 内**首选上表的新 flag 形式。
|
|
93
|
-
|
|
94
|
-
可按名调用的只有这 7 个:`project_map` / `semantic_code_search` / `get_call_graph` /
|
|
95
|
-
`get_ast_node` / `module_overview` / `ast_search` / `find_references`。
|
|
96
|
-
`impact_analysis` **不在其列,已从 dispatcher 删除**——按名调用返回 `Unknown tool`。
|
|
97
|
-
隐藏旧名 `read_snippet` / `dependency_graph` / `find_similar_code` / `find_dead_code` /
|
|
98
|
-
`trace_http_chain`(+ alias `find_http_route`)仍有 dispatcher arm,raw JSON-RPC / MCP
|
|
99
|
-
SDK / 既有脚本不破;但它们不在 `tools/list`,Claude Code 的 ToolSearch 不为其加载
|
|
100
|
-
schema —— 实操中一律走新 flag。CLI 子命令保持原样:
|
|
101
|
-
|
|
102
|
-
| 意图 | CLI(Bash 工作流) | 等价 MCP 新形式 |
|
|
103
|
-
|------|--------------------|------------------|
|
|
104
|
-
| "改 X 会炸啥?" | `code-graph-mcp impact X` | `get_ast_node symbol_name=X include_impact=true` |
|
|
105
|
-
| HTTP 路由 → handler 链路 | `code-graph-mcp trace /api/x` | `get_call_graph route_path="GET /api/x"` |
|
|
106
|
-
| "X 文件依赖谁?" | `code-graph-mcp deps src/x.rs` | `module_overview path="src/x.rs" include_deps=true` |
|
|
107
|
-
| "相似/重复函数"(需 embedding) | `code-graph-mcp similar X` | `get_ast_node symbol_name=X include_similar=true` |
|
|
108
|
-
| "未使用的代码" | `code-graph-mcp dead-code [path]` | `module_overview path=<path> include_dead=true` |
|
|
109
|
-
| "架构咽喉/桥节点是谁?" | `code-graph-mcp centrality` | —(CLI-only;betweenness 中心性,补 `map` 的 caller_count 度中心性) |
|
|
110
|
-
| "循环导入依赖(哪些文件互相 import)?" | `code-graph-mcp cycles` | —(CLI-only;文件级 import 环 = SCC;JS/TS/Py/Go 是坏味,Rust 内部环常良性) |
|
|
111
|
-
| "可疑/意外的跨模块耦合?" | `code-graph-mcp surprising` | —(CLI-only;跨文件 calls/refs 按 低置信(ambiguous>inferred)+跨模块+sole-bridge 打分) |
|
|
112
|
-
| "代码健康总览(想要一份报告)?" | `code-graph-mcp report` | —(CLI-only;汇总 summary+置信度 / hot / chokepoints / cycles / surprising / dead-code) |
|
|
113
|
-
|
|
114
|
-
**dead-code 的 `ignore_paths`**:CLI 默认豁免 `["claude-plugin/", "benches/"]`
|
|
115
|
-
(macro/shell 入口点);`--no-ignore` 关闭。MCP 端也接同名参数。
|
|
116
|
-
|
|
117
|
-
## 不要替代
|
|
118
|
-
|
|
119
|
-
- 非代码文件(README/JSON/log) → 用内置 `Grep`
|
|
120
|
-
- 代码里查常量/函数名/字符串首选 `code-graph-mcp grep "pattern" [path]`(每个命中带 containing function/module 上下文,结构化);只做纯文本匹配且不关心上下文时用内置 `Grep`
|
|
121
|
-
- 即将编辑的具体文件 → 用 `Read`(`overview <file>` 看概览,`show SYMBOL` 看某符号)
|
|
122
|
-
|
|
123
|
-
## 工作流惯例
|
|
124
|
-
|
|
125
|
-
1. 起手 `project_map`(或 Bash 调 `code-graph-mcp map --compact`)看架构
|
|
126
|
-
2. `semantic_code_search` 默认带 `compact=true`,省 token
|
|
127
|
-
3. 展开节点:`get_ast_node node_id=N compact=true` 看签名 / 不带 compact 看全文
|
|
128
|
-
4. 改前评估影响:`get_ast_node symbol_name=X include_impact=true`(核心 7 内,首选)
|
|
129
|
-
或 Bash 调 `code-graph-mcp impact X`(独立进程;输出更细:风险等级 + 路由 + 文件计数)
|
|
130
|
-
5. 搜不到结果 → `code-graph-mcp health-check` 检查索引与 embedding 覆盖率
|
|
131
|
-
|
|
132
|
-
可用 prompts:`impact-analysis`、`understand-module`、`trace-request`
|
|
133
|
-
|
|
134
|
-
## CLI 速查(替 Bash)
|
|
135
|
-
|
|
136
|
-
```
|
|
137
|
-
code-graph-mcp grep "pattern" [path] # ripgrep + AST 上下文(-t lang / -g glob / -c 计数 / -M 行宽)
|
|
138
|
-
code-graph-mcp search "concept" # 纯 FTS5(要混合检索走 MCP semantic_code_search)
|
|
139
|
-
code-graph-mcp ast-search "q" --type fn # 结构化筛选
|
|
140
|
-
code-graph-mcp map # 项目架构
|
|
141
|
-
code-graph-mcp overview src/mcp/ # 模块总览
|
|
142
|
-
code-graph-mcp callgraph SYMBOL # 调用图
|
|
143
|
-
code-graph-mcp impact SYMBOL # 影响面(--change-type ∈ signature|behavior|remove,默认 behavior)
|
|
144
|
-
code-graph-mcp show SYMBOL # 节点详情
|
|
145
|
-
code-graph-mcp refs SYMBOL --relation calls # --relation ∈ calls|imports|inherits|implements|references|exports|routes_to|all
|
|
146
|
-
code-graph-mcp refs SYMBOL --min-confidence extracted # ∈ extracted|inferred|ambiguous;extracted=只看精确边(callgraph/impact/trace 同款)
|
|
147
|
-
code-graph-mcp centrality # 架构咽喉(betweenness 桥节点;补 map 的 caller_count)
|
|
148
|
-
code-graph-mcp cycles # 循环导入依赖(文件级 import 环 / SCC)
|
|
149
|
-
code-graph-mcp surprising # 可疑跨模块耦合(低置信 + 跨模块 + sole-bridge 打分)
|
|
150
|
-
code-graph-mcp report # 代码健康总览(汇总 hot/chokepoints/cycles/surprising/dead-code)
|
|
151
|
-
code-graph-mcp dead-code [path] # 未使用代码(默认豁免 claude-plugin/)
|
|
152
|
-
code-graph-mcp dead-code --ignore tmp/ --ignore scripts/bin/ # 自定义豁免前缀
|
|
153
|
-
code-graph-mcp dead-code --no-ignore # 关掉默认豁免,看完整列表
|
|
154
|
-
code-graph-mcp health-check # 索引健康
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
完整列表:`code-graph-mcp --help`。
|
|
158
|
-
|
|
159
|
-
## 质量门槛
|
|
160
|
-
|
|
161
|
-
- `compact=true` 一般够用;要看完整代码再去掉
|
|
162
|
-
- `impact` 在 `--change-type signature` 时返回最严格的破坏面
|
|
163
|
-
- 索引陈旧 → SessionStart 自带 `ensureIndexFresh`;手动跑 `incremental-index`
|
|
164
|
-
|
|
165
|
-
## 卸载 / 回退
|
|
166
|
-
|
|
167
|
-
- `code-graph-mcp unadopt` — 精确移除 CLAUDE.md 里的 managed 块 + `.claude/plugin_code_graph_mcp.md`(块移光后若 CLAUDE.md 只剩我们的内容则连文件一起删,否则保留你的正文);并清理任何遗留 memory-dir 制品。
|
|
168
|
-
- `CODE_GRAPH_NO_AUTO_ADOPT=1`(`~/.claude/settings.json` env) — 阻止未来自动安装,不影响已安装状态。
|
|
169
|
-
- `CODE_GRAPH_NO_TEMPLATE_REFRESH=1` — 锁定 CLAUDE.md 块 + 本文件不随插件升级刷新;允许手动编辑长久保留。
|
|
170
|
-
- `CODE_GRAPH_VERBOSE_HOOKS=1`(v0.17.0+) — opt in 到 SessionStart `project_map` 注入(默认 OFF)。
|
|
171
|
-
- `CODE_GRAPH_QUIET_HOOKS=1` — UserPromptSubmit context push 的 escape hatch(默认 ON);同时强制 SessionStart `project_map` quiet。
|
|
172
|
-
- `CODE_GRAPH_QUIET_HOOKS=0` — 强制恢复 SessionStart `project_map` 注入(向后兼容路径)。
|
|
6
|
+
# code-graph-mcp: when to reach for it
|
|
7
|
+
|
|
8
|
+
Written by `code-graph-mcp adopt` to `.claude/plugin_code_graph_mcp.md`, next to the
|
|
9
|
+
CLAUDE.md block; `code-graph-mcp unadopt` removes both. The CLI runs from Bash with no
|
|
10
|
+
tool loading; the MCP tools return the same data but are deferred behind ToolSearch in
|
|
11
|
+
Claude Code.
|
|
12
|
+
|
|
13
|
+
## Pick the command by the question
|
|
14
|
+
|
|
15
|
+
| Question | CLI | MCP tool |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| Who calls X / what does X call? | `code-graph-mcp callgraph X` | `get_call_graph` |
|
|
18
|
+
| What breaks if X's signature changes? | `code-graph-mcp impact X --change-type signature` | `get_ast_node include_impact=true` |
|
|
19
|
+
| Every use of X (rename / remove) | `code-graph-mcp refs X`, then `grep -w X` | `find_references` |
|
|
20
|
+
| Source and signature of X | `code-graph-mcp show X` | `get_ast_node` |
|
|
21
|
+
| What is in this dir or file? | `code-graph-mcp overview <path>` | `module_overview` |
|
|
22
|
+
| Find code by what it does | `code-graph-mcp search "words"` (full-text) | `semantic_code_search` (adds vector ranking once embeddings exist) |
|
|
23
|
+
| Text search, each hit with its enclosing fn | `code-graph-mcp grep "pat" [path]` | — |
|
|
24
|
+
| Tests that load these files | `code-graph-mcp affected <files>` | — |
|
|
25
|
+
| HTTP route to its handler chain | `code-graph-mcp trace "GET /api/x"` | `get_call_graph route_path="GET /api/x"` |
|
|
26
|
+
| Project layout | `code-graph-mcp map --compact` | `project_map` |
|
|
27
|
+
| Symbols by kind, return type or params | `code-graph-mcp ast-search "q" --type fn --returns T` | `ast_search` |
|
|
28
|
+
|
|
29
|
+
`grep` takes `-F -i -w -l -c`, `-t <lang>`, `-g <glob>`, `-A/-B/-C N` and exits like grep
|
|
30
|
+
(0 hits, 1 none, 2 error). Large answers: `callgraph` and `overview` accept `--budget N`.
|
|
31
|
+
|
|
32
|
+
## What the graph cannot see
|
|
33
|
+
|
|
34
|
+
- A call it could not resolve leaves no edge: dynamic dispatch, reflection, callbacks
|
|
35
|
+
passed as values, unresolved imports. An empty caller list is not proof that nothing
|
|
36
|
+
calls X — check with grep before deleting or renaming. `impact` reports such a
|
|
37
|
+
function as `Risk: UNKNOWN`.
|
|
38
|
+
- `callgraph` and `impact` hide by-name `ambiguous` edges by default
|
|
39
|
+
(`--min-confidence ambiguous` shows them); `refs` shows every tier. Never narrow a
|
|
40
|
+
rename audit with `--min-confidence extracted`: that tier is same-file only and drops
|
|
41
|
+
every cross-file caller.
|
|
42
|
+
- A JS function held only by a variable (`const f = function () {}`) or a computed
|
|
43
|
+
member (`obj[k] = …`) is not a node. A call on a receiver with no written type
|
|
44
|
+
(hono's `c.json()`) binds by name and is often `ambiguous`, hidden by default.
|
|
45
|
+
- `affected` follows resolved imports; with unresolved ones (a tsconfig path alias, a
|
|
46
|
+
computed `require(name)`) its test list is a lower bound.
|
|
47
|
+
- `dead-code` is dependable for Rust. Elsewhere read it as candidates: interface
|
|
48
|
+
methods, re-exports and framework entry points show up in it.
|
|
49
|
+
|
|
50
|
+
## Still use the plain tools
|
|
51
|
+
|
|
52
|
+
- Grep for literal strings, config and non-code files; Read the file you are about to edit.
|
|
53
|
+
- Answers look empty or stale: `code-graph-mcp health-check`, then
|
|
54
|
+
`code-graph-mcp incremental-index`.
|
|
55
|
+
|
|
56
|
+
## Switches (`env` in `~/.claude/settings.json`)
|
|
57
|
+
|
|
58
|
+
- `CODE_GRAPH_QUIET_HOOKS=1` — hooks stop injecting context.
|
|
59
|
+
- `CODE_GRAPH_NO_TEMPLATE_REFRESH=1` — no notice when this file drifts from the shipped one.
|
|
60
|
+
|
|
61
|
+
All commands: `code-graph-mcp --help`. All switches: README, "Environment variables".
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdsrs/code-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.165.0",
|
|
4
4
|
"description": "MCP server that indexes codebases into an AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"node": ">=16"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@sdsrs/code-graph-linux-x64": "0.
|
|
39
|
-
"@sdsrs/code-graph-linux-arm64": "0.
|
|
40
|
-
"@sdsrs/code-graph-darwin-x64": "0.
|
|
41
|
-
"@sdsrs/code-graph-darwin-arm64": "0.
|
|
42
|
-
"@sdsrs/code-graph-win32-x64": "0.
|
|
38
|
+
"@sdsrs/code-graph-linux-x64": "0.165.0",
|
|
39
|
+
"@sdsrs/code-graph-linux-arm64": "0.165.0",
|
|
40
|
+
"@sdsrs/code-graph-darwin-x64": "0.165.0",
|
|
41
|
+
"@sdsrs/code-graph-darwin-arm64": "0.165.0",
|
|
42
|
+
"@sdsrs/code-graph-win32-x64": "0.165.0"
|
|
43
43
|
}
|
|
44
44
|
}
|