@mycodemap/mycodemap 0.4.2 → 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.
Files changed (288) hide show
  1. package/CHANGELOG.md +105 -3
  2. package/README.md +192 -53
  3. package/dist/ai/claude.d.ts +38 -0
  4. package/dist/ai/claude.d.ts.map +1 -0
  5. package/dist/ai/claude.js +169 -0
  6. package/dist/ai/claude.js.map +1 -0
  7. package/dist/ai/codex.d.ts +38 -0
  8. package/dist/ai/codex.d.ts.map +1 -0
  9. package/dist/ai/codex.js +169 -0
  10. package/dist/ai/codex.js.map +1 -0
  11. package/dist/ai/factory.d.ts +48 -0
  12. package/dist/ai/factory.d.ts.map +1 -0
  13. package/dist/ai/factory.js +95 -0
  14. package/dist/ai/factory.js.map +1 -0
  15. package/dist/ai/index.d.ts +12 -0
  16. package/dist/ai/index.d.ts.map +1 -0
  17. package/dist/ai/index.js +29 -0
  18. package/dist/ai/index.js.map +1 -0
  19. package/dist/ai/provider.d.ts +70 -0
  20. package/dist/ai/provider.d.ts.map +1 -0
  21. package/dist/ai/provider.js +31 -0
  22. package/dist/ai/provider.js.map +1 -0
  23. package/dist/ai/subagent-caller.d.ts +90 -0
  24. package/dist/ai/subagent-caller.d.ts.map +1 -0
  25. package/dist/ai/subagent-caller.js +280 -0
  26. package/dist/ai/subagent-caller.js.map +1 -0
  27. package/dist/ai/types.d.ts +70 -0
  28. package/dist/ai/types.d.ts.map +1 -0
  29. package/dist/ai/types.js +5 -0
  30. package/dist/ai/types.js.map +1 -0
  31. package/dist/cli/commands/analyze.d.ts +18 -0
  32. package/dist/cli/commands/analyze.d.ts.map +1 -1
  33. package/dist/cli/commands/analyze.js +239 -6
  34. package/dist/cli/commands/analyze.js.map +1 -1
  35. package/dist/cli/commands/check.d.ts +22 -0
  36. package/dist/cli/commands/check.d.ts.map +1 -0
  37. package/dist/cli/commands/check.js +168 -0
  38. package/dist/cli/commands/check.js.map +1 -0
  39. package/dist/cli/commands/ci.d.ts +25 -0
  40. package/dist/cli/commands/ci.d.ts.map +1 -1
  41. package/dist/cli/commands/ci.js +139 -36
  42. package/dist/cli/commands/ci.js.map +1 -1
  43. package/dist/cli/commands/complexity.d.ts.map +1 -1
  44. package/dist/cli/commands/complexity.js +6 -0
  45. package/dist/cli/commands/complexity.js.map +1 -1
  46. package/dist/cli/commands/design.d.ts +52 -0
  47. package/dist/cli/commands/design.d.ts.map +1 -0
  48. package/dist/cli/commands/design.js +274 -0
  49. package/dist/cli/commands/design.js.map +1 -0
  50. package/dist/cli/commands/generate.d.ts +1 -0
  51. package/dist/cli/commands/generate.d.ts.map +1 -1
  52. package/dist/cli/commands/generate.js +121 -8
  53. package/dist/cli/commands/generate.js.map +1 -1
  54. package/dist/cli/commands/history.d.ts +26 -0
  55. package/dist/cli/commands/history.d.ts.map +1 -0
  56. package/dist/cli/commands/history.js +92 -0
  57. package/dist/cli/commands/history.js.map +1 -0
  58. package/dist/cli/commands/mcp.d.ts +13 -0
  59. package/dist/cli/commands/mcp.d.ts.map +1 -0
  60. package/dist/cli/commands/mcp.js +108 -0
  61. package/dist/cli/commands/mcp.js.map +1 -0
  62. package/dist/cli/commands/server.d.ts +9 -0
  63. package/dist/cli/commands/server.d.ts.map +1 -0
  64. package/dist/cli/commands/server.js +65 -0
  65. package/dist/cli/commands/server.js.map +1 -0
  66. package/dist/cli/commands/ship/pipeline.d.ts.map +1 -1
  67. package/dist/cli/commands/ship/pipeline.js +8 -1
  68. package/dist/cli/commands/ship/pipeline.js.map +1 -1
  69. package/dist/cli/commands/ship/publisher.d.ts +9 -1
  70. package/dist/cli/commands/ship/publisher.d.ts.map +1 -1
  71. package/dist/cli/commands/ship/publisher.js +149 -6
  72. package/dist/cli/commands/ship/publisher.js.map +1 -1
  73. package/dist/cli/commands/workflow.d.ts.map +1 -1
  74. package/dist/cli/commands/workflow.js +22 -2
  75. package/dist/cli/commands/workflow.js.map +1 -1
  76. package/dist/cli/config-loader.d.ts.map +1 -1
  77. package/dist/cli/config-loader.js +3 -2
  78. package/dist/cli/config-loader.js.map +1 -1
  79. package/dist/cli/contract-checker.d.ts +33 -0
  80. package/dist/cli/contract-checker.d.ts.map +1 -0
  81. package/dist/cli/contract-checker.js +719 -0
  82. package/dist/cli/contract-checker.js.map +1 -0
  83. package/dist/cli/contract-diff-scope.d.ts +14 -0
  84. package/dist/cli/contract-diff-scope.d.ts.map +1 -0
  85. package/dist/cli/contract-diff-scope.js +127 -0
  86. package/dist/cli/contract-diff-scope.js.map +1 -0
  87. package/dist/cli/contract-gate-thresholds.d.ts +14 -0
  88. package/dist/cli/contract-gate-thresholds.d.ts.map +1 -0
  89. package/dist/cli/contract-gate-thresholds.js +19 -0
  90. package/dist/cli/contract-gate-thresholds.js.map +1 -0
  91. package/dist/cli/design-contract-loader.d.ts +15 -0
  92. package/dist/cli/design-contract-loader.d.ts.map +1 -0
  93. package/dist/cli/design-contract-loader.js +527 -0
  94. package/dist/cli/design-contract-loader.js.map +1 -0
  95. package/dist/cli/design-contract-schema.d.ts +11 -0
  96. package/dist/cli/design-contract-schema.d.ts.map +1 -0
  97. package/dist/cli/design-contract-schema.js +75 -0
  98. package/dist/cli/design-contract-schema.js.map +1 -0
  99. package/dist/cli/design-handoff-builder.d.ts +15 -0
  100. package/dist/cli/design-handoff-builder.d.ts.map +1 -0
  101. package/dist/cli/design-handoff-builder.js +345 -0
  102. package/dist/cli/design-handoff-builder.js.map +1 -0
  103. package/dist/cli/design-scope-resolver.d.ts +8 -0
  104. package/dist/cli/design-scope-resolver.d.ts.map +1 -0
  105. package/dist/cli/design-scope-resolver.js +760 -0
  106. package/dist/cli/design-scope-resolver.js.map +1 -0
  107. package/dist/cli/design-verification-builder.d.ts +8 -0
  108. package/dist/cli/design-verification-builder.d.ts.map +1 -0
  109. package/dist/cli/design-verification-builder.js +369 -0
  110. package/dist/cli/design-verification-builder.js.map +1 -0
  111. package/dist/cli/index.js +20 -6
  112. package/dist/cli/index.js.map +1 -1
  113. package/dist/cli/paths.d.ts.map +1 -1
  114. package/dist/cli/paths.js +30 -7
  115. package/dist/cli/paths.js.map +1 -1
  116. package/dist/cli-new/commands/server.d.ts +13 -0
  117. package/dist/cli-new/commands/server.d.ts.map +1 -0
  118. package/dist/cli-new/commands/server.js +90 -0
  119. package/dist/cli-new/commands/server.js.map +1 -0
  120. package/dist/core/analyzer.d.ts.map +1 -1
  121. package/dist/core/analyzer.js +16 -0
  122. package/dist/core/analyzer.js.map +1 -1
  123. package/dist/domain/entities/CodeGraph.d.ts +5 -1
  124. package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
  125. package/dist/domain/entities/CodeGraph.js +29 -12
  126. package/dist/domain/entities/CodeGraph.js.map +1 -1
  127. package/dist/domain/entities/Dependency.d.ts +8 -1
  128. package/dist/domain/entities/Dependency.d.ts.map +1 -1
  129. package/dist/domain/entities/Dependency.js +19 -4
  130. package/dist/domain/entities/Dependency.js.map +1 -1
  131. package/dist/domain/entities/Symbol.d.ts +2 -1
  132. package/dist/domain/entities/Symbol.d.ts.map +1 -1
  133. package/dist/domain/entities/Symbol.js +6 -3
  134. package/dist/domain/entities/Symbol.js.map +1 -1
  135. package/dist/generator/ai-overview.d.ts +51 -0
  136. package/dist/generator/ai-overview.d.ts.map +1 -0
  137. package/dist/generator/ai-overview.js +160 -0
  138. package/dist/generator/ai-overview.js.map +1 -0
  139. package/dist/infrastructure/storage/StorageFactory.d.ts +13 -5
  140. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
  141. package/dist/infrastructure/storage/StorageFactory.js +62 -16
  142. package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
  143. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts +3 -1
  144. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -1
  145. package/dist/infrastructure/storage/adapters/FileSystemStorage.js +10 -2
  146. package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -1
  147. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +3 -1
  148. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -1
  149. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +9 -1
  150. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -1
  151. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +3 -1
  152. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -1
  153. package/dist/infrastructure/storage/adapters/MemoryStorage.js +9 -1
  154. package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -1
  155. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +41 -0
  156. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +1 -0
  157. package/dist/infrastructure/storage/adapters/Neo4jStorage.js +162 -0
  158. package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +1 -0
  159. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +53 -0
  160. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -0
  161. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +879 -0
  162. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -0
  163. package/dist/infrastructure/storage/graph-helpers.d.ts +3 -1
  164. package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
  165. package/dist/infrastructure/storage/graph-helpers.js +90 -0
  166. package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
  167. package/dist/infrastructure/storage/index.d.ts +1 -1
  168. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  169. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +3 -1
  170. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
  171. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
  172. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +27 -0
  173. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -0
  174. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +246 -0
  175. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -0
  176. package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts +25 -0
  177. package/dist/infrastructure/storage/sqlite/perf-thresholds.d.ts.map +1 -0
  178. package/dist/infrastructure/storage/sqlite/perf-thresholds.js +25 -0
  179. package/dist/infrastructure/storage/sqlite/perf-thresholds.js.map +1 -0
  180. package/dist/infrastructure/storage/sqlite/schema.d.ts +4 -0
  181. package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -0
  182. package/dist/infrastructure/storage/sqlite/schema.js +111 -0
  183. package/dist/infrastructure/storage/sqlite/schema.js.map +1 -0
  184. package/dist/interface/types/design-check.d.ts +73 -0
  185. package/dist/interface/types/design-check.d.ts.map +1 -0
  186. package/dist/interface/types/design-check.js +4 -0
  187. package/dist/interface/types/design-check.js.map +1 -0
  188. package/dist/interface/types/design-contract.d.ts +123 -0
  189. package/dist/interface/types/design-contract.d.ts.map +1 -0
  190. package/dist/interface/types/design-contract.js +7 -0
  191. package/dist/interface/types/design-contract.js.map +1 -0
  192. package/dist/interface/types/design-handoff.d.ts +68 -0
  193. package/dist/interface/types/design-handoff.d.ts.map +1 -0
  194. package/dist/interface/types/design-handoff.js +4 -0
  195. package/dist/interface/types/design-handoff.js.map +1 -0
  196. package/dist/interface/types/design-mapping.d.ts +51 -0
  197. package/dist/interface/types/design-mapping.d.ts.map +1 -0
  198. package/dist/interface/types/design-mapping.js +4 -0
  199. package/dist/interface/types/design-mapping.js.map +1 -0
  200. package/dist/interface/types/design-verification.d.ts +49 -0
  201. package/dist/interface/types/design-verification.d.ts.map +1 -0
  202. package/dist/interface/types/design-verification.js +4 -0
  203. package/dist/interface/types/design-verification.js.map +1 -0
  204. package/dist/interface/types/history-risk.d.ts +90 -0
  205. package/dist/interface/types/history-risk.d.ts.map +1 -0
  206. package/dist/interface/types/history-risk.js +4 -0
  207. package/dist/interface/types/history-risk.js.map +1 -0
  208. package/dist/interface/types/index.d.ts +20 -1
  209. package/dist/interface/types/index.d.ts.map +1 -1
  210. package/dist/interface/types/storage.d.ts +28 -1
  211. package/dist/interface/types/storage.d.ts.map +1 -1
  212. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts +10 -0
  213. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts.map +1 -1
  214. package/dist/orchestrator/adapters/ast-grep-adapter.js +46 -17
  215. package/dist/orchestrator/adapters/ast-grep-adapter.js.map +1 -1
  216. package/dist/orchestrator/adapters/codemap-adapter.d.ts.map +1 -1
  217. package/dist/orchestrator/adapters/codemap-adapter.js +2 -22
  218. package/dist/orchestrator/adapters/codemap-adapter.js.map +1 -1
  219. package/dist/orchestrator/ai-feed-generator.d.ts +210 -0
  220. package/dist/orchestrator/ai-feed-generator.d.ts.map +1 -0
  221. package/dist/orchestrator/ai-feed-generator.js +377 -0
  222. package/dist/orchestrator/ai-feed-generator.js.map +1 -0
  223. package/dist/orchestrator/history-risk-service.d.ts +55 -0
  224. package/dist/orchestrator/history-risk-service.d.ts.map +1 -0
  225. package/dist/orchestrator/history-risk-service.js +680 -0
  226. package/dist/orchestrator/history-risk-service.js.map +1 -0
  227. package/dist/orchestrator/types.d.ts +19 -1
  228. package/dist/orchestrator/types.d.ts.map +1 -1
  229. package/dist/orchestrator/types.js +19 -0
  230. package/dist/orchestrator/types.js.map +1 -1
  231. package/dist/server/mcp/index.d.ts +4 -0
  232. package/dist/server/mcp/index.d.ts.map +1 -0
  233. package/dist/server/mcp/index.js +5 -0
  234. package/dist/server/mcp/index.js.map +1 -0
  235. package/dist/server/mcp/server.d.ts +17 -0
  236. package/dist/server/mcp/server.d.ts.map +1 -0
  237. package/dist/server/mcp/server.js +84 -0
  238. package/dist/server/mcp/server.js.map +1 -0
  239. package/dist/server/mcp/service.d.ts +22 -0
  240. package/dist/server/mcp/service.d.ts.map +1 -0
  241. package/dist/server/mcp/service.js +177 -0
  242. package/dist/server/mcp/service.js.map +1 -0
  243. package/dist/server/mcp/types.d.ts +56 -0
  244. package/dist/server/mcp/types.d.ts.map +1 -0
  245. package/dist/server/mcp/types.js +4 -0
  246. package/dist/server/mcp/types.js.map +1 -0
  247. package/docs/AI_ASSISTANT_SETUP.md +1 -1
  248. package/docs/SETUP_GUIDE.md +6 -6
  249. package/docs/ai-guide/COMMANDS.md +171 -4
  250. package/docs/ai-guide/INTEGRATION.md +137 -433
  251. package/docs/ai-guide/OUTPUT.md +890 -5
  252. package/docs/ai-guide/PATTERNS.md +54 -14
  253. package/docs/ai-guide/PROMPTS.md +17 -6
  254. package/docs/archive/test-report-symbol-search.md +384 -0
  255. package/docs/archive/test-scenario-4-complexity-analysis.md +460 -0
  256. package/docs/archive/test_report_scenario5.md +615 -0
  257. package/docs/archive/test_scenario_3_impact_analysis_report.md +520 -0
  258. package/docs/backlog.md +177 -0
  259. package/docs/eatdogfood-reports/2026-04-17-eatdogfood-agent-experience.md +231 -0
  260. package/docs/exec-plans/completed/2026-04-17-eatdogfood-codemap-cli.md +103 -0
  261. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +102 -0
  262. package/docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md +126 -0
  263. package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +11 -10
  264. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +10 -10
  265. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +17 -12
  266. package/docs/product-specs/README.md +2 -1
  267. package/docs/rules/README.md +16 -11
  268. package/docs/rules/architecture-guardrails.md +24 -336
  269. package/docs/rules/code-quality-redlines.md +25 -311
  270. package/docs/rules/engineering-with-codex-openai.md +20 -3
  271. package/docs/rules/validation.md +90 -37
  272. package/mycodemap.config.schema.json +3 -3
  273. package/package.json +7 -2
  274. package/scripts/benchmark-governance-graph.mjs +132 -0
  275. package/scripts/calibrate-contract-gate.mjs +221 -0
  276. package/scripts/capability-report.py +255 -0
  277. package/scripts/experiments/arcadedb-http-smoke.mjs +90 -0
  278. package/scripts/qa-rule-control.sh +254 -0
  279. package/scripts/report-high-risk-files.mjs +395 -0
  280. package/scripts/rule-context.mjs +155 -0
  281. package/scripts/smoke-sqlite-impact.mjs +85 -0
  282. package/scripts/sync-analyze-docs.js +1 -0
  283. package/scripts/tests/test_capability_report.py +89 -0
  284. package/scripts/tests/test_rule_control_workflow.py +51 -0
  285. package/scripts/tests/test_validate_rules.py +81 -0
  286. package/scripts/validate-ai-docs.js +283 -1
  287. package/scripts/validate-docs.js +479 -25
  288. package/scripts/validate-rules.py +254 -0
@@ -1,515 +1,219 @@
1
- # AI Guide - 集成与错误处理
1
+ # AI Guide - MCP / Agent 集成
2
2
 
3
- > AI 工作流的集成方式和常见错误处理
3
+ > 当前 canonical integration path:**真实本地 stdio MCP server**。旧 CLI wrapper 只作为 fallback。
4
4
 
5
5
  ---
6
6
 
7
- ## AI 工作流的集成
7
+ ## 1. 当前事实边界
8
8
 
9
- ### MCP (Model Context Protocol) 集成
10
-
11
- CodeMap 注册为 MCP 工具:
12
-
13
- ```json
14
- {
15
- "tools": [
16
- {
17
- "name": "codemap_generate",
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
- ### Skill/Knowledge 集成
21
+ ## 1.1 速查表
65
22
 
66
- #### Kimi CLI Skill
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
- 首先检测 CLI 是否可用:
33
+ ### Step 1: 生成 symbol-level 图
77
34
 
78
35
  ```bash
79
- if command -v mycodemap &> /dev/null; then
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
- ## Commands
41
+ ### Step 2: 安装到当前仓库 `.mcp.json`
125
42
 
126
- ### Generate Code Map (Required First Step)
127
43
  ```bash
128
- mycodemap generate
44
+ mycodemap mcp install
129
45
  ```
130
46
 
131
- ### Query Symbol
132
- ```bash
133
- mycodemap query -s "SymbolName" -j
134
- ```
47
+ 该命令当前只做一件事:在**当前仓库根目录**的 `.mcp.json` 里写入一个 experimental server entry。
135
48
 
136
- ### Analyze Impact
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 analyze -i find -k "keyword" --json
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
- #### Codex CLI Agent
159
-
160
- ```markdown
161
- # CodeMap Agent
162
-
163
- ## Description
55
+ 注意:
56
+ - 这是给 MCP host 启动的 `stdio` server,不是给人类终端交互的命令
57
+ - `stdout` 只承载 MCP 协议帧
58
+ - 欢迎信息、迁移提示、runtime log 不会混入 `stdout`
164
59
 
165
- Code analysis tool for TypeScript projects.
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
- 1. Always start with `codemap_generate`
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
- ## Documentation
64
+ `mcp install` 会写入与下列 shape 等价的配置:
182
65
 
183
- Full guide: `AI_GUIDE.md`
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
- #### TypeScript
93
+ 输入:
210
94
 
211
95
  ```typescript
212
- // 模式 1: 代码地图过期/不存在
213
- async function ensureCodeMap(): Promise<boolean> {
214
- const codemapPath = '.mycodemap/codemap.json';
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
- // 模式 2: 查询无结果,逐级回退
234
- async function findSymbol(symbolName: string): Promise<any[]> {
235
- // 尝试 1: 精确查询
236
- let result = await exec(`mycodemap query -s "${symbolName}" -j`);
237
- let data = JSON.parse(result);
238
-
239
- if (data.count > 0) {
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
- // 模式 3: 影响范围太大,缩小范围
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
- // 模式 4: 置信度太低,扩大搜索
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
- // 模式 5: 安全的 JSON 解析
295
- function safeParseJSON<T>(json: string, defaultValue: T): T {
296
- try {
297
- return JSON.parse(json) as T;
298
- } catch {
299
- console.error('JSON 解析失败,使用默认值');
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
- #### Python
306
-
307
- ```python
308
- import json
309
- import subprocess
310
- import os
311
- from typing import List, Dict, Any, Optional
312
-
313
- def ensure_code_map() -> bool:
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
- ```typescript
378
- // 情况 1: 大项目处理
379
- async function handleLargeProject() {
380
- // 使用 fast 模式
381
- await exec('mycodemap generate -m fast');
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
- // 情况 2: 并发查询控制
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
- // 情况 3: 超时处理
404
- async function execWithTimeout(command: string, timeoutMs: number = 30000) {
405
- return new Promise((resolve, reject) => {
406
- const child = exec(command, (err, stdout) => {
407
- if (err) reject(err);
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
- ```typescript
426
- // 利用 CodeMap 内置缓存(60秒 TTL)
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
- ```typescript
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
- 1. **命令注入防护**: 始终对用户输入进行转义
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
- 2. **路径遍历防护**: 验证文件路径
465
- ```typescript
466
- if (!filePath.startsWith('src/')) {
467
- throw new Error('Invalid path');
468
- }
469
- ```
174
+ ```bash
175
+ mycodemap generate --symbol-level
176
+ ```
470
177
 
471
- 3. **敏感信息**: 输出中可能包含文件路径,注意隐私
178
+ ### `mcp install` 后看不到 server
472
179
 
473
- ---
180
+ - 确认 host 会读取当前仓库根目录的 `.mcp.json`
181
+ - 不会读取的话,手动复制 `mycodemap-experimental` entry 到宿主配置
474
182
 
475
- ## 故障排除
183
+ ### `mcp start` 无法启动
476
184
 
477
- ### CLI 未找到
185
+ 先确认:
478
186
 
479
187
  ```bash
480
- # 检查安装
481
- which mycodemap || echo "未安装"
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
- # 解决方案 2: 使用 npx
487
- alias mycodemap='npx @mycodemap/mycodemap'
192
+ 若宿主要求依赖 symbol-level / SQLite 路径,还需确认:
488
193
 
489
- # 解决方案 3: 本地安装
490
- npm install --save-dev @mycodemap/mycodemap
491
- ./node_modules/.bin/mycodemap
194
+ ```bash
195
+ npm ls better-sqlite3
492
196
  ```
493
197
 
494
- ### tree-sitter 构建失败
198
+ ### 结果为空但不是错误
495
199
 
496
- ```bash
497
- # Ubuntu/Debian
498
- sudo apt-get install build-essential
200
+ - 先检查 `graph_status` 是否为 `partial`
201
+ - 再检查 symbol 是否真的唯一;必要时补 `filePath`
499
202
 
500
- # macOS
501
- xcode-select --install
203
+ ### storage 运行时错误速查表
502
204
 
503
- # 然后重新安装
504
- npm rebuild
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
- ```bash
510
- # 强制重新生成
511
- mycodemap generate --force
214
+ ## 8. 交叉引用
512
215
 
513
- # 或重新运行一次 generate 刷新输出
514
- mycodemap generate
515
- ```
216
+ - 命令参考:`docs/ai-guide/COMMANDS.md`
217
+ - 输出契约:`docs/ai-guide/OUTPUT.md`
218
+ - 主索引:`AI_GUIDE.md`
219
+ - 执行手册:`CLAUDE.md`