@mycodemap/mycodemap 0.5.0 → 0.5.1
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/CHANGELOG.md +13 -0
- package/README.md +77 -9
- package/dist/cli/commands/analyze.d.ts +18 -0
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +239 -6
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/check.d.ts +22 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +168 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/ci.d.ts +25 -0
- package/dist/cli/commands/ci.d.ts.map +1 -1
- package/dist/cli/commands/ci.js +139 -36
- package/dist/cli/commands/ci.js.map +1 -1
- package/dist/cli/commands/complexity.d.ts.map +1 -1
- package/dist/cli/commands/complexity.js +6 -0
- package/dist/cli/commands/complexity.js.map +1 -1
- package/dist/cli/commands/design.d.ts +5 -0
- package/dist/cli/commands/design.d.ts.map +1 -1
- package/dist/cli/commands/design.js +6 -0
- package/dist/cli/commands/design.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +1 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +121 -8
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/history.d.ts +26 -0
- package/dist/cli/commands/history.d.ts.map +1 -0
- package/dist/cli/commands/history.js +92 -0
- package/dist/cli/commands/history.js.map +1 -0
- package/dist/cli/commands/mcp.d.ts +13 -0
- package/dist/cli/commands/mcp.d.ts.map +1 -0
- package/dist/cli/commands/mcp.js +108 -0
- package/dist/cli/commands/mcp.js.map +1 -0
- package/dist/cli/commands/workflow.d.ts.map +1 -1
- package/dist/cli/commands/workflow.js +22 -2
- package/dist/cli/commands/workflow.js.map +1 -1
- package/dist/cli/config-loader.d.ts.map +1 -1
- package/dist/cli/config-loader.js +3 -2
- package/dist/cli/config-loader.js.map +1 -1
- package/dist/cli/contract-checker.d.ts +33 -0
- package/dist/cli/contract-checker.d.ts.map +1 -0
- package/dist/cli/contract-checker.js +719 -0
- package/dist/cli/contract-checker.js.map +1 -0
- package/dist/cli/contract-diff-scope.d.ts +14 -0
- package/dist/cli/contract-diff-scope.d.ts.map +1 -0
- package/dist/cli/contract-diff-scope.js +127 -0
- package/dist/cli/contract-diff-scope.js.map +1 -0
- package/dist/cli/contract-gate-thresholds.d.ts +14 -0
- package/dist/cli/contract-gate-thresholds.d.ts.map +1 -0
- package/dist/cli/contract-gate-thresholds.js +19 -0
- package/dist/cli/contract-gate-thresholds.js.map +1 -0
- package/dist/cli/design-contract-loader.d.ts.map +1 -1
- package/dist/cli/design-contract-loader.js +355 -3
- package/dist/cli/design-contract-loader.js.map +1 -1
- package/dist/cli/design-scope-resolver.d.ts.map +1 -1
- package/dist/cli/design-scope-resolver.js +89 -41
- package/dist/cli/design-scope-resolver.js.map +1 -1
- package/dist/cli/index.js +18 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/paths.d.ts.map +1 -1
- package/dist/cli/paths.js +30 -7
- package/dist/cli/paths.js.map +1 -1
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +16 -0
- package/dist/core/analyzer.js.map +1 -1
- package/dist/domain/entities/CodeGraph.d.ts +5 -1
- package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
- package/dist/domain/entities/CodeGraph.js +29 -12
- package/dist/domain/entities/CodeGraph.js.map +1 -1
- package/dist/domain/entities/Dependency.d.ts +8 -1
- package/dist/domain/entities/Dependency.d.ts.map +1 -1
- package/dist/domain/entities/Dependency.js +19 -4
- package/dist/domain/entities/Dependency.js.map +1 -1
- package/dist/domain/entities/Symbol.d.ts +2 -1
- package/dist/domain/entities/Symbol.d.ts.map +1 -1
- package/dist/domain/entities/Symbol.js +6 -3
- package/dist/domain/entities/Symbol.js.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.d.ts +1 -0
- package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.js +7 -2
- package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts +3 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js +10 -2
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +3 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +9 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +3 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.js +9 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +53 -0
- package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -0
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js +879 -0
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -0
- package/dist/infrastructure/storage/graph-helpers.d.ts +3 -1
- package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
- package/dist/infrastructure/storage/graph-helpers.js +90 -0
- package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
- package/dist/infrastructure/storage/index.d.ts +1 -1
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +3 -1
- package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
- package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +27 -0
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -0
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +246 -0
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -0
- package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts +25 -0
- package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts.map +1 -0
- package/dist/infrastructure/storage/sqlite/perf-thresholds.js +25 -0
- package/dist/infrastructure/storage/sqlite/perf-thresholds.js.map +1 -0
- package/dist/infrastructure/storage/sqlite/schema.d.ts +4 -0
- package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -0
- package/dist/infrastructure/storage/sqlite/schema.js +111 -0
- package/dist/infrastructure/storage/sqlite/schema.js.map +1 -0
- package/dist/interface/types/design-check.d.ts +73 -0
- package/dist/interface/types/design-check.d.ts.map +1 -0
- package/dist/interface/types/design-check.js +4 -0
- package/dist/interface/types/design-check.js.map +1 -0
- package/dist/interface/types/design-contract.d.ts +56 -1
- package/dist/interface/types/design-contract.d.ts.map +1 -1
- package/dist/interface/types/history-risk.d.ts +90 -0
- package/dist/interface/types/history-risk.d.ts.map +1 -0
- package/dist/interface/types/history-risk.js +4 -0
- package/dist/interface/types/history-risk.js.map +1 -0
- package/dist/interface/types/index.d.ts +17 -2
- package/dist/interface/types/index.d.ts.map +1 -1
- package/dist/interface/types/storage.d.ts +28 -1
- package/dist/interface/types/storage.d.ts.map +1 -1
- package/dist/orchestrator/adapters/ast-grep-adapter.d.ts +10 -0
- package/dist/orchestrator/adapters/ast-grep-adapter.d.ts.map +1 -1
- package/dist/orchestrator/adapters/ast-grep-adapter.js +46 -17
- package/dist/orchestrator/adapters/ast-grep-adapter.js.map +1 -1
- package/dist/orchestrator/adapters/codemap-adapter.d.ts.map +1 -1
- package/dist/orchestrator/adapters/codemap-adapter.js +2 -22
- package/dist/orchestrator/adapters/codemap-adapter.js.map +1 -1
- package/dist/orchestrator/history-risk-service.d.ts +55 -0
- package/dist/orchestrator/history-risk-service.d.ts.map +1 -0
- package/dist/orchestrator/history-risk-service.js +680 -0
- package/dist/orchestrator/history-risk-service.js.map +1 -0
- package/dist/orchestrator/types.d.ts +19 -1
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js +19 -0
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/server/mcp/index.d.ts +4 -0
- package/dist/server/mcp/index.d.ts.map +1 -0
- package/dist/server/mcp/index.js +5 -0
- package/dist/server/mcp/index.js.map +1 -0
- package/dist/server/mcp/server.d.ts +17 -0
- package/dist/server/mcp/server.d.ts.map +1 -0
- package/dist/server/mcp/server.js +84 -0
- package/dist/server/mcp/server.js.map +1 -0
- package/dist/server/mcp/service.d.ts +22 -0
- package/dist/server/mcp/service.d.ts.map +1 -0
- package/dist/server/mcp/service.js +177 -0
- package/dist/server/mcp/service.js.map +1 -0
- package/dist/server/mcp/types.d.ts +56 -0
- package/dist/server/mcp/types.d.ts.map +1 -0
- package/dist/server/mcp/types.js +4 -0
- package/dist/server/mcp/types.js.map +1 -0
- package/docs/AI_ASSISTANT_SETUP.md +1 -1
- package/docs/SETUP_GUIDE.md +6 -6
- package/docs/ai-guide/COMMANDS.md +98 -4
- package/docs/ai-guide/INTEGRATION.md +137 -433
- package/docs/ai-guide/OUTPUT.md +476 -6
- package/docs/ai-guide/PATTERNS.md +41 -11
- package/docs/ai-guide/PROMPTS.md +11 -6
- package/docs/backlog.md +177 -0
- package/docs/eatdogfood-reports/2026-04-17-eatdogfood-agent-experience.md +231 -0
- package/docs/exec-plans/completed/2026-04-17-eatdogfood-codemap-cli.md +103 -0
- package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +102 -0
- package/docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md +47 -0
- package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +11 -10
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +10 -10
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +17 -12
- package/docs/rules/README.md +16 -11
- package/docs/rules/architecture-guardrails.md +24 -336
- package/docs/rules/code-quality-redlines.md +25 -311
- package/docs/rules/engineering-with-codex-openai.md +14 -1
- package/docs/rules/validation.md +90 -40
- package/mycodemap.config.schema.json +3 -3
- package/package.json +7 -2
- package/scripts/benchmark-governance-graph.mjs +132 -0
- package/scripts/calibrate-contract-gate.mjs +221 -0
- package/scripts/capability-report.py +255 -0
- package/scripts/qa-rule-control.sh +254 -0
- package/scripts/report-high-risk-files.mjs +395 -0
- package/scripts/rule-context.mjs +155 -0
- package/scripts/smoke-sqlite-impact.mjs +85 -0
- package/scripts/sync-analyze-docs.js +1 -0
- package/scripts/tests/test_capability_report.py +89 -0
- package/scripts/tests/test_rule_control_workflow.py +51 -0
- package/scripts/tests/test_validate_rules.py +81 -0
- package/scripts/validate-ai-docs.js +283 -1
- package/scripts/validate-docs.js +249 -42
- package/scripts/validate-rules.py +254 -0
|
@@ -1,515 +1,219 @@
|
|
|
1
|
-
# AI Guide -
|
|
1
|
+
# AI Guide - MCP / Agent 集成
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> 当前 canonical integration path:**真实本地 stdio MCP server**。旧 CLI wrapper 只作为 fallback。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 1. 当前事实边界
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"description": "生成代码地图,必须在其他命令之前执行",
|
|
19
|
-
"command": "mycodemap generate",
|
|
20
|
-
"timeout": 60000
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"name": "codemap_query_symbol",
|
|
24
|
-
"description": "查询符号定义位置",
|
|
25
|
-
"command": "mycodemap query -s {symbol} -j",
|
|
26
|
-
"parameters": {
|
|
27
|
-
"symbol": { "type": "string", "description": "符号名称" }
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"name": "codemap_read",
|
|
32
|
-
"description": "分析文件变更的影响范围",
|
|
33
|
-
"command": "mycodemap analyze -i read -t {target} --scope transitive --json",
|
|
34
|
-
"parameters": {
|
|
35
|
-
"target": { "type": "string", "description": "目标文件路径" }
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"name": "codemap_find",
|
|
40
|
-
"description": "搜索与关键词相关的代码",
|
|
41
|
-
"command": "mycodemap analyze -i find -k {keyword} --json",
|
|
42
|
-
"parameters": {
|
|
43
|
-
"keyword": { "type": "string", "description": "搜索关键词" }
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"name": "codemap_check_ci",
|
|
48
|
-
"description": "执行 CI 门禁检查",
|
|
49
|
-
"command": "mycodemap ci {check_type}",
|
|
50
|
-
"parameters": {
|
|
51
|
-
"check_type": {
|
|
52
|
-
"type": "string",
|
|
53
|
-
"enum": ["check-commits", "check-headers", "assess-risk"],
|
|
54
|
-
"description": "检查类型"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
```
|
|
9
|
+
| 维度 | 当前基线 |
|
|
10
|
+
|------|----------|
|
|
11
|
+
| transport | 本地 `stdio` |
|
|
12
|
+
| 读写权限 | **只读** |
|
|
13
|
+
| public surface | `mycodemap mcp install`、`mycodemap mcp start` |
|
|
14
|
+
| MCP tools | `codemap_query`、`codemap_impact` |
|
|
15
|
+
| 图前置条件 | 先执行 `mycodemap generate --symbol-level` |
|
|
16
|
+
| 稳定性 | **experimental** |
|
|
17
|
+
| 非目标 | HTTP MCP、远程 transport、写操作、全局 host lifecycle |
|
|
61
18
|
|
|
62
19
|
---
|
|
63
20
|
|
|
64
|
-
|
|
21
|
+
## 1.1 速查表
|
|
65
22
|
|
|
66
|
-
|
|
23
|
+
| 你遇到的问题 | 先看什么 |
|
|
24
|
+
|--------------|----------|
|
|
25
|
+
| 想让 host 真正通过 MCP 调 CodeMap | 本文第 2-4 节 |
|
|
26
|
+
| host 只会跑命令,不会连 MCP | 本文第 6 节 fallback |
|
|
27
|
+
| 想判断 storage / 运行时是否满足 | 本文第 7 节故障排查 |
|
|
67
28
|
|
|
68
|
-
```markdown
|
|
69
|
-
---
|
|
70
|
-
name: codemap
|
|
71
|
-
description: CodeMap 代码分析工具,用于项目结构分析、符号查询、依赖分析和影响评估
|
|
72
29
|
---
|
|
73
30
|
|
|
74
|
-
##
|
|
31
|
+
## 2. canonical 集成步骤
|
|
75
32
|
|
|
76
|
-
|
|
33
|
+
### Step 1: 生成 symbol-level 图
|
|
77
34
|
|
|
78
35
|
```bash
|
|
79
|
-
|
|
80
|
-
CODEMAP="mycodemap"
|
|
81
|
-
elif [ -f "./node_modules/.bin/mycodemap" ]; then
|
|
82
|
-
CODEMAP="./node_modules/.bin/mycodemap"
|
|
83
|
-
else
|
|
84
|
-
CODEMAP="npx @mycodemap/mycodemap"
|
|
85
|
-
fi
|
|
36
|
+
mycodemap generate --symbol-level
|
|
86
37
|
```
|
|
87
38
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
1. **首次使用必须先执行 generate**
|
|
91
|
-
```bash
|
|
92
|
-
$CODEMAP generate
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
2. **查询符号定义**
|
|
96
|
-
```bash
|
|
97
|
-
$CODEMAP query -s "SymbolName" -j
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
3. **分析变更影响**
|
|
101
|
-
```bash
|
|
102
|
-
$CODEMAP analyze -i read -t "file.ts" --scope transitive --json
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
4. **搜索代码**
|
|
106
|
-
```bash
|
|
107
|
-
$CODEMAP analyze -i find -k "keyword" --json
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## 完整文档
|
|
111
|
-
|
|
112
|
-
参考项目根目录的 `AI_GUIDE.md` 和 `docs/ai-guide/` 目录。
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
#### Claude Code Skill
|
|
116
|
-
|
|
117
|
-
```markdown
|
|
118
|
-
# CodeMap Code Analysis
|
|
119
|
-
|
|
120
|
-
## Overview
|
|
121
|
-
|
|
122
|
-
Use CodeMap CLI for TypeScript/JavaScript project analysis.
|
|
39
|
+
如果输出里的 `graphStatus = "partial"`,说明图是降级结果;MCP tools 仍可返回结果,但会显式带 `graph_status: "partial"`。
|
|
123
40
|
|
|
124
|
-
|
|
41
|
+
### Step 2: 安装到当前仓库 `.mcp.json`
|
|
125
42
|
|
|
126
|
-
### Generate Code Map (Required First Step)
|
|
127
43
|
```bash
|
|
128
|
-
mycodemap
|
|
44
|
+
mycodemap mcp install
|
|
129
45
|
```
|
|
130
46
|
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
mycodemap query -s "SymbolName" -j
|
|
134
|
-
```
|
|
47
|
+
该命令当前只做一件事:在**当前仓库根目录**的 `.mcp.json` 里写入一个 experimental server entry。
|
|
135
48
|
|
|
136
|
-
###
|
|
137
|
-
```bash
|
|
138
|
-
mycodemap analyze -i read -t "file.ts" --scope transitive --json
|
|
139
|
-
```
|
|
49
|
+
### Step 3: 让 MCP host 启动 stdio server
|
|
140
50
|
|
|
141
|
-
### Search Code
|
|
142
51
|
```bash
|
|
143
|
-
mycodemap
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Decision Tree
|
|
147
|
-
|
|
148
|
-
1. Understanding project structure → `generate` + read `AI_MAP.md`
|
|
149
|
-
2. Finding symbol location → `query -s`
|
|
150
|
-
3. Assessing change impact → `analyze -i read`
|
|
151
|
-
4. Searching related code → `analyze -i find`
|
|
152
|
-
|
|
153
|
-
## Reference
|
|
154
|
-
|
|
155
|
-
See `AI_GUIDE.md` in project root for complete documentation.
|
|
52
|
+
mycodemap mcp start
|
|
156
53
|
```
|
|
157
54
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
## Description
|
|
55
|
+
注意:
|
|
56
|
+
- 这是给 MCP host 启动的 `stdio` server,不是给人类终端交互的命令
|
|
57
|
+
- `stdout` 只承载 MCP 协议帧
|
|
58
|
+
- 欢迎信息、迁移提示、runtime log 不会混入 `stdout`
|
|
164
59
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
## Available Tools
|
|
168
|
-
|
|
169
|
-
- `codemap_generate`: Generate code map
|
|
170
|
-
- `codemap_query`: Query symbols
|
|
171
|
-
- `codemap_read`: Analyze change impact and surrounding context
|
|
172
|
-
- `codemap_find`: Search code
|
|
173
|
-
|
|
174
|
-
## Workflow
|
|
60
|
+
---
|
|
175
61
|
|
|
176
|
-
|
|
177
|
-
2. Use `codemap_query` to find definitions
|
|
178
|
-
3. Use `codemap_read` before making changes
|
|
179
|
-
4. Use `codemap_find` to find related code
|
|
62
|
+
## 3. `.mcp.json` 参考配置
|
|
180
63
|
|
|
181
|
-
|
|
64
|
+
`mcp install` 会写入与下列 shape 等价的配置:
|
|
182
65
|
|
|
183
|
-
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"mycodemap-experimental": {
|
|
70
|
+
"command": "node",
|
|
71
|
+
"args": ["dist/cli/index.js", "mcp", "start"],
|
|
72
|
+
"cwd": "/absolute/path/to/repo",
|
|
73
|
+
"env": {
|
|
74
|
+
"MYCODEMAP_RUNTIME_LOG_ENABLED": "false"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
184
79
|
```
|
|
185
80
|
|
|
186
|
-
|
|
81
|
+
### 当前宿主支持边界
|
|
187
82
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
| 错误 | 原因 | 解决方案 |
|
|
193
|
-
|------|------|----------|
|
|
194
|
-
| `代码地图不存在,请先运行 codemap generate` | 未生成代码地图 | 执行 `mycodemap generate` |
|
|
195
|
-
| `符号未找到` | 拼写错误或不存在 | 使用 `query -S` 模糊搜索 |
|
|
196
|
-
| `模块未找到` | 路径错误或已删除 | 检查路径或使用 `query -m` 部分匹配 |
|
|
197
|
-
| `tree-sitter 不可用` | 原生模块未编译 | 安装构建工具后重新安装 |
|
|
198
|
-
| `文件头缺少 [META]` | 新文件未加头 | 添加标准文件头注释 |
|
|
199
|
-
| `提交格式错误` | 不符合 [TAG] 格式 | 修改为 `[TAG] scope: message` |
|
|
200
|
-
| `风险评分过高` | 变更文件太多 | 拆分提交或添加解释 |
|
|
201
|
-
| `输出契约验证失败` | analyze 输出格式变更 | 检查 schemaVersion 和字段 |
|
|
202
|
-
| `pluginReport.diagnostics` 出现 `initialize` / `generate` 错误 | 插件加载或执行失败 | 检查 `mycodemap.config.json` 的 `plugins` 段、插件导出格式和生成路径 |
|
|
203
|
-
| `UNSUPPORTED_STORAGE_TYPE` / `ADAPTER_NOT_AVAILABLE` / `KUZU_INIT_FAILED` | 图存储后端配置不受支持或缺少依赖 | 检查 `mycodemap.config.json.storage`,确认未继续使用 `neo4j`,并安装 `kuzu` |
|
|
83
|
+
- 当前文档只保证**repo-local `.mcp.json`** 这一路径
|
|
84
|
+
- 不承诺全局安装、升级覆盖策略或卸载命令
|
|
85
|
+
- 若你的 host 不读取 `.mcp.json`,请手动拷贝上面的 server entry 到宿主自己的 MCP 配置文件
|
|
204
86
|
|
|
205
87
|
---
|
|
206
88
|
|
|
207
|
-
|
|
89
|
+
## 4. MCP tool contract
|
|
90
|
+
|
|
91
|
+
### `codemap_query`
|
|
208
92
|
|
|
209
|
-
|
|
93
|
+
输入:
|
|
210
94
|
|
|
211
95
|
```typescript
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (!existsSync(codemapPath)) {
|
|
217
|
-
console.log('代码地图不存在,正在生成...');
|
|
218
|
-
await exec('mycodemap generate');
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 检查是否过期(超过 1 小时)
|
|
223
|
-
const stat = statSync(codemapPath);
|
|
224
|
-
const age = Date.now() - stat.mtimeMs;
|
|
225
|
-
if (age > 3600000) {
|
|
226
|
-
console.log('代码地图已过期,正在更新...');
|
|
227
|
-
await exec('mycodemap generate');
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return true;
|
|
96
|
+
interface CodemapQueryInput {
|
|
97
|
+
symbol: string;
|
|
98
|
+
filePath?: string;
|
|
231
99
|
}
|
|
100
|
+
```
|
|
232
101
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return data.results;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// 尝试 2: 模糊搜索
|
|
244
|
-
console.log('精确查询无结果,尝试模糊搜索...');
|
|
245
|
-
result = await exec(`mycodemap query -S "${symbolName}" -l 20 -j`);
|
|
246
|
-
data = JSON.parse(result);
|
|
247
|
-
|
|
248
|
-
if (data.count > 0) {
|
|
249
|
-
return data.results;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// 尝试 3: 统一搜索
|
|
253
|
-
console.log('模糊搜索无结果,尝试统一搜索...');
|
|
254
|
-
result = await exec(`mycodemap analyze -i find -k "${symbolName}" --topK 20 --json`);
|
|
255
|
-
data = JSON.parse(result);
|
|
256
|
-
|
|
257
|
-
return data.results || [];
|
|
258
|
-
}
|
|
102
|
+
返回:
|
|
103
|
+
- symbol 定义
|
|
104
|
+
- callers
|
|
105
|
+
- callees
|
|
106
|
+
- `graph_status`
|
|
107
|
+
- `generated_at`
|
|
108
|
+
- `error.code`(若失败)
|
|
259
109
|
|
|
260
|
-
|
|
261
|
-
async function analyzeImpact(file: string, maxFiles: number = 50): Promise<any> {
|
|
262
|
-
// 先尝试不包含传递依赖
|
|
263
|
-
let result = await exec(`mycodemap impact -f "${file}" -j`);
|
|
264
|
-
let data = JSON.parse(result);
|
|
265
|
-
|
|
266
|
-
const totalFiles = (data.direct?.length || 0) + (data.transitive?.length || 0);
|
|
267
|
-
|
|
268
|
-
if (totalFiles > maxFiles) {
|
|
269
|
-
console.warn(`影响范围过大 (${totalFiles} 个文件),仅返回直接依赖`);
|
|
270
|
-
return {
|
|
271
|
-
...data,
|
|
272
|
-
transitive: [],
|
|
273
|
-
warning: '影响范围过大,仅显示直接依赖'
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return data;
|
|
278
|
-
}
|
|
110
|
+
### `codemap_impact`
|
|
279
111
|
|
|
280
|
-
|
|
281
|
-
async function searchWithFallback(keyword: string): Promise<any[]> {
|
|
282
|
-
let result = await exec(`mycodemap analyze -i find -k "${keyword}" --topK 8 --json`);
|
|
283
|
-
let data = JSON.parse(result);
|
|
284
|
-
|
|
285
|
-
if (data.confidence?.level === 'low') {
|
|
286
|
-
console.log('置信度较低,扩大搜索范围...');
|
|
287
|
-
result = await exec(`mycodemap analyze -i find -k "${keyword}" --topK 20 --json`);
|
|
288
|
-
data = JSON.parse(result);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return data.results || [];
|
|
292
|
-
}
|
|
112
|
+
输入:
|
|
293
113
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return defaultValue;
|
|
301
|
-
}
|
|
114
|
+
```typescript
|
|
115
|
+
interface CodemapImpactInput {
|
|
116
|
+
symbol: string;
|
|
117
|
+
filePath?: string;
|
|
118
|
+
depth?: number;
|
|
119
|
+
limit?: number;
|
|
302
120
|
}
|
|
303
121
|
```
|
|
304
122
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
"""确保代码地图存在"""
|
|
315
|
-
codemap_path = '.mycodemap/codemap.json'
|
|
316
|
-
|
|
317
|
-
if not os.path.exists(codemap_path):
|
|
318
|
-
print('代码地图不存在,正在生成...')
|
|
319
|
-
subprocess.run(['mycodemap', 'generate'], check=True)
|
|
320
|
-
return True
|
|
321
|
-
|
|
322
|
-
# 检查是否过期(超过 1 小时)
|
|
323
|
-
import time
|
|
324
|
-
mtime = os.path.getmtime(codemap_path)
|
|
325
|
-
if time.time() - mtime > 3600:
|
|
326
|
-
print('代码地图已过期,正在更新...')
|
|
327
|
-
subprocess.run(['mycodemap', 'generate'], check=True)
|
|
328
|
-
|
|
329
|
-
return True
|
|
330
|
-
|
|
331
|
-
def find_symbol(symbol_name: str) -> List[Dict[str, Any]]:
|
|
332
|
-
"""查找符号,逐级回退"""
|
|
333
|
-
# 尝试 1: 精确查询
|
|
334
|
-
result = subprocess.run(
|
|
335
|
-
['mycodemap', 'query', '-s', symbol_name, '-j'],
|
|
336
|
-
capture_output=True, text=True
|
|
337
|
-
)
|
|
338
|
-
data = json.loads(result.stdout)
|
|
339
|
-
|
|
340
|
-
if data.get('count', 0) > 0:
|
|
341
|
-
return data['results']
|
|
342
|
-
|
|
343
|
-
# 尝试 2: 模糊搜索
|
|
344
|
-
print('精确查询无结果,尝试模糊搜索...')
|
|
345
|
-
result = subprocess.run(
|
|
346
|
-
['mycodemap', 'query', '-S', symbol_name, '-l', '20', '-j'],
|
|
347
|
-
capture_output=True, text=True
|
|
348
|
-
)
|
|
349
|
-
data = json.loads(result.stdout)
|
|
350
|
-
|
|
351
|
-
if data.get('count', 0) > 0:
|
|
352
|
-
return data['results']
|
|
353
|
-
|
|
354
|
-
# 尝试 3: 统一搜索
|
|
355
|
-
print('模糊搜索无结果,尝试统一搜索...')
|
|
356
|
-
result = subprocess.run(
|
|
357
|
-
['mycodemap', 'analyze', '-i', 'find', '-k', symbol_name, '--topK', '20', '--json'],
|
|
358
|
-
capture_output=True, text=True
|
|
359
|
-
)
|
|
360
|
-
data = json.loads(result.stdout)
|
|
361
|
-
|
|
362
|
-
return data.get('results', [])
|
|
363
|
-
|
|
364
|
-
def safe_parse_json(json_str: str, default_value: Any) -> Any:
|
|
365
|
-
"""安全的 JSON 解析"""
|
|
366
|
-
try:
|
|
367
|
-
return json.loads(json_str)
|
|
368
|
-
except json.JSONDecodeError:
|
|
369
|
-
print('JSON 解析失败,使用默认值')
|
|
370
|
-
return default_value
|
|
371
|
-
```
|
|
123
|
+
返回:
|
|
124
|
+
- `root_symbol`
|
|
125
|
+
- symbol-level caller impact 链
|
|
126
|
+
- `depth` / `limit` / `truncated`
|
|
127
|
+
- `graph_status`
|
|
128
|
+
- `generated_at`
|
|
129
|
+
- `error.code`(若失败)
|
|
130
|
+
|
|
131
|
+
> 完整输出类型见 `docs/ai-guide/OUTPUT.md`。
|
|
372
132
|
|
|
373
133
|
---
|
|
374
134
|
|
|
375
|
-
|
|
135
|
+
## 5. 错误语义
|
|
376
136
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// 分块查询
|
|
384
|
-
const modules = ['src/cli', 'src/core', 'src/domain'];
|
|
385
|
-
for (const module of modules) {
|
|
386
|
-
await exec(`mycodemap analyze -i show -t "${module}" --json`);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
137
|
+
| `error.code` | 何时出现 | 应对方式 |
|
|
138
|
+
|--------------|----------|----------|
|
|
139
|
+
| `GRAPH_NOT_FOUND` | 还没生成 symbol-level 图 | 先跑 `mycodemap generate --symbol-level` |
|
|
140
|
+
| `SYMBOL_NOT_FOUND` | 请求的 symbol 不存在 | 检查拼写,或先用 `query -S` / `analyze -i find` 搜索 |
|
|
141
|
+
| `AMBIGUOUS_EDGE` | 同名 symbol 无法仅靠 `symbol` / `filePath` 消歧 | 补充更具体的 `filePath` |
|
|
389
142
|
|
|
390
|
-
|
|
391
|
-
async function batchQuery(symbols: string[], concurrency: number = 5) {
|
|
392
|
-
const results = [];
|
|
393
|
-
for (let i = 0; i < symbols.length; i += concurrency) {
|
|
394
|
-
const batch = symbols.slice(i, i + concurrency);
|
|
395
|
-
const batchResults = await Promise.all(
|
|
396
|
-
batch.map(s => exec(`mycodemap query -s "${s}" -j`).catch(() => null))
|
|
397
|
-
);
|
|
398
|
-
results.push(...batchResults.filter(Boolean));
|
|
399
|
-
}
|
|
400
|
-
return results;
|
|
401
|
-
}
|
|
143
|
+
### `graph_status` 解读
|
|
402
144
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
else resolve(stdout);
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
setTimeout(() => {
|
|
412
|
-
child.kill();
|
|
413
|
-
reject(new Error('Command timeout'));
|
|
414
|
-
}, timeoutMs);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
```
|
|
145
|
+
| 值 | 含义 |
|
|
146
|
+
|----|------|
|
|
147
|
+
| `complete` | 图完整,可正常消费 |
|
|
148
|
+
| `partial` | 图降级,结果可用但不应伪装成完整 truth |
|
|
149
|
+
| `missing` | 图不存在,工具会返回 `GRAPH_NOT_FOUND` |
|
|
418
150
|
|
|
419
151
|
---
|
|
420
152
|
|
|
421
|
-
##
|
|
153
|
+
## 6. fallback:旧 CLI wrapper
|
|
422
154
|
|
|
423
|
-
|
|
155
|
+
如果你的宿主暂时**不支持真正 MCP server**,可以临时回退到直接调用 CLI:
|
|
424
156
|
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// 如果需要清除缓存
|
|
430
|
-
function clearCodeMapCache() {
|
|
431
|
-
// 删除索引缓存文件
|
|
432
|
-
const cacheDir = '.mycodemap/cache';
|
|
433
|
-
if (existsSync(cacheDir)) {
|
|
434
|
-
rmSync(cacheDir, { recursive: true });
|
|
435
|
-
}
|
|
436
|
-
}
|
|
157
|
+
```bash
|
|
158
|
+
mycodemap query -s "SymbolName" -j
|
|
159
|
+
mycodemap impact -f "src/file.ts" -j
|
|
160
|
+
mycodemap analyze -i find -k "SymbolName" --json --structured
|
|
437
161
|
```
|
|
438
162
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
for (const file of files) {
|
|
444
|
-
await exec(`mycodemap impact -f "${file}"`);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// 好的做法:先生成,再批量查询
|
|
448
|
-
await exec('mycodemap generate');
|
|
449
|
-
const results = await Promise.all(
|
|
450
|
-
files.map(f => exec(`mycodemap impact -f "${f}" -j`))
|
|
451
|
-
);
|
|
452
|
-
```
|
|
163
|
+
但要注意:
|
|
164
|
+
- 这不是原生 MCP
|
|
165
|
+
- 你需要自己做命令拼装、stdout JSON 解析和错误分类
|
|
166
|
+
- canonical path 仍然是 `mcp install` + `mcp start`
|
|
453
167
|
|
|
454
168
|
---
|
|
455
169
|
|
|
456
|
-
##
|
|
170
|
+
## 7. 故障排查
|
|
457
171
|
|
|
458
|
-
|
|
459
|
-
```typescript
|
|
460
|
-
const safeSymbol = symbolName.replace(/["'`]/g, '');
|
|
461
|
-
await exec(`mycodemap query -s "${safeSymbol}"`);
|
|
462
|
-
```
|
|
172
|
+
### host 能启动 server,但工具返回 `GRAPH_NOT_FOUND`
|
|
463
173
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
throw new Error('Invalid path');
|
|
468
|
-
}
|
|
469
|
-
```
|
|
174
|
+
```bash
|
|
175
|
+
mycodemap generate --symbol-level
|
|
176
|
+
```
|
|
470
177
|
|
|
471
|
-
|
|
178
|
+
### `mcp install` 后看不到 server
|
|
472
179
|
|
|
473
|
-
|
|
180
|
+
- 确认 host 会读取当前仓库根目录的 `.mcp.json`
|
|
181
|
+
- 不会读取的话,手动复制 `mycodemap-experimental` entry 到宿主配置
|
|
474
182
|
|
|
475
|
-
|
|
183
|
+
### `mcp start` 无法启动
|
|
476
184
|
|
|
477
|
-
|
|
185
|
+
先确认:
|
|
478
186
|
|
|
479
187
|
```bash
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
# 解决方案 1: 全局安装
|
|
484
|
-
npm install -g @mycodemap/mycodemap
|
|
188
|
+
npm run build
|
|
189
|
+
node dist/cli/index.js mcp start
|
|
190
|
+
```
|
|
485
191
|
|
|
486
|
-
|
|
487
|
-
alias mycodemap='npx @mycodemap/mycodemap'
|
|
192
|
+
若宿主要求依赖 symbol-level / SQLite 路径,还需确认:
|
|
488
193
|
|
|
489
|
-
|
|
490
|
-
npm
|
|
491
|
-
./node_modules/.bin/mycodemap
|
|
194
|
+
```bash
|
|
195
|
+
npm ls better-sqlite3
|
|
492
196
|
```
|
|
493
197
|
|
|
494
|
-
###
|
|
198
|
+
### 结果为空但不是错误
|
|
495
199
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
sudo apt-get install build-essential
|
|
200
|
+
- 先检查 `graph_status` 是否为 `partial`
|
|
201
|
+
- 再检查 symbol 是否真的唯一;必要时补 `filePath`
|
|
499
202
|
|
|
500
|
-
|
|
501
|
-
xcode-select --install
|
|
203
|
+
### storage 运行时错误速查表
|
|
502
204
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
205
|
+
| 错误 / 信号 | 含义 | 处理方式 |
|
|
206
|
+
|-------------|------|----------|
|
|
207
|
+
| `UNSUPPORTED_STORAGE_TYPE` / `STORAGE_BACKEND_MIGRATED` / `SQLITE_NOT_AVAILABLE` | 当前 storage 配置不受支持,或显式 `sqlite` 但运行时条件不满足 | 检查 `mycodemap.config.json.storage`,确认是否仍在使用旧 backend,或当前机器是否满足 SQLite 运行时要求 |
|
|
208
|
+
| `better-sqlite3` 缺失 | 显式 `sqlite` 需要本地 SQLite binding | 安装 `better-sqlite3` |
|
|
209
|
+
| Node.js `>=20` 不满足 | SQLite 路径需要较新的 Node 运行时 | 升级 Node.js |
|
|
210
|
+
| SQLite 不可用时会 warning 后回退 `filesystem` | 仅 `storage.type = "auto"` 会这么做 | 若你要强制 SQLite,请改用显式 `storage.type = "sqlite"` 并补齐依赖 |
|
|
506
211
|
|
|
507
|
-
|
|
212
|
+
---
|
|
508
213
|
|
|
509
|
-
|
|
510
|
-
# 强制重新生成
|
|
511
|
-
mycodemap generate --force
|
|
214
|
+
## 8. 交叉引用
|
|
512
215
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
216
|
+
- 命令参考:`docs/ai-guide/COMMANDS.md`
|
|
217
|
+
- 输出契约:`docs/ai-guide/OUTPUT.md`
|
|
218
|
+
- 主索引:`AI_GUIDE.md`
|
|
219
|
+
- 执行手册:`CLAUDE.md`
|