@mycodemap/mycodemap 0.1.0 → 0.2.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.
Files changed (283) hide show
  1. package/CHANGELOG.md +164 -6
  2. package/README.md +407 -141
  3. package/dist/cli/commands/ci.d.ts +7 -1
  4. package/dist/cli/commands/ci.d.ts.map +1 -1
  5. package/dist/cli/commands/ci.js +38 -0
  6. package/dist/cli/commands/ci.js.map +1 -1
  7. package/dist/cli/commands/cycles.d.ts.map +1 -1
  8. package/dist/cli/commands/cycles.js +2 -0
  9. package/dist/cli/commands/cycles.js.map +1 -1
  10. package/dist/cli/commands/export.d.ts +6 -0
  11. package/dist/cli/commands/export.d.ts.map +1 -0
  12. package/dist/cli/commands/export.js +108 -0
  13. package/dist/cli/commands/export.js.map +1 -0
  14. package/dist/cli/commands/generate.d.ts.map +1 -1
  15. package/dist/cli/commands/generate.js +96 -0
  16. package/dist/cli/commands/generate.js.map +1 -1
  17. package/dist/cli/commands/init.d.ts.map +1 -1
  18. package/dist/cli/commands/init.js +3 -1
  19. package/dist/cli/commands/init.js.map +1 -1
  20. package/dist/cli/commands/logs.d.ts +5 -0
  21. package/dist/cli/commands/logs.d.ts.map +1 -0
  22. package/dist/cli/commands/logs.js +189 -0
  23. package/dist/cli/commands/logs.js.map +1 -0
  24. package/dist/cli/commands/report.d.ts +12 -0
  25. package/dist/cli/commands/report.d.ts.map +1 -0
  26. package/dist/cli/commands/report.js +158 -0
  27. package/dist/cli/commands/report.js.map +1 -0
  28. package/dist/cli/commands/server.d.ts +9 -0
  29. package/dist/cli/commands/server.d.ts.map +1 -0
  30. package/dist/cli/commands/server.js +68 -0
  31. package/dist/cli/commands/server.js.map +1 -0
  32. package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
  33. package/dist/cli/commands/watch-foreground.js +2 -0
  34. package/dist/cli/commands/watch-foreground.js.map +1 -1
  35. package/dist/cli/commands/watch.d.ts.map +1 -1
  36. package/dist/cli/commands/watch.js +2 -0
  37. package/dist/cli/commands/watch.js.map +1 -1
  38. package/dist/cli/first-run-guide.d.ts +23 -0
  39. package/dist/cli/first-run-guide.d.ts.map +1 -0
  40. package/dist/cli/first-run-guide.js +83 -0
  41. package/dist/cli/first-run-guide.js.map +1 -0
  42. package/dist/cli/index.js +85 -1
  43. package/dist/cli/index.js.map +1 -1
  44. package/dist/cli/platform-check.d.ts +21 -0
  45. package/dist/cli/platform-check.d.ts.map +1 -0
  46. package/dist/cli/platform-check.js +94 -0
  47. package/dist/cli/platform-check.js.map +1 -0
  48. package/dist/cli/tree-sitter-check.d.ts +35 -0
  49. package/dist/cli/tree-sitter-check.d.ts.map +1 -0
  50. package/dist/cli/tree-sitter-check.js +133 -0
  51. package/dist/cli/tree-sitter-check.js.map +1 -0
  52. package/dist/cli/utils/sanitize.d.ts +54 -0
  53. package/dist/cli/utils/sanitize.d.ts.map +1 -0
  54. package/dist/cli/utils/sanitize.js +131 -0
  55. package/dist/cli/utils/sanitize.js.map +1 -0
  56. package/dist/cli-new/commands/export.d.ts +15 -0
  57. package/dist/cli-new/commands/export.d.ts.map +1 -0
  58. package/dist/cli-new/commands/export.js +107 -0
  59. package/dist/cli-new/commands/export.js.map +1 -0
  60. package/dist/cli-new/commands/query.d.ts +14 -0
  61. package/dist/cli-new/commands/query.d.ts.map +1 -0
  62. package/dist/cli-new/commands/query.js +120 -0
  63. package/dist/cli-new/commands/query.js.map +1 -0
  64. package/dist/cli-new/commands/server.d.ts +13 -0
  65. package/dist/cli-new/commands/server.d.ts.map +1 -0
  66. package/dist/cli-new/commands/server.js +94 -0
  67. package/dist/cli-new/commands/server.js.map +1 -0
  68. package/dist/cli-new/index.d.ts +11 -0
  69. package/dist/cli-new/index.d.ts.map +1 -0
  70. package/dist/cli-new/index.js +63 -0
  71. package/dist/cli-new/index.js.map +1 -0
  72. package/dist/cli-new/types/index.d.ts +88 -0
  73. package/dist/cli-new/types/index.d.ts.map +1 -0
  74. package/dist/cli-new/types/index.js +7 -0
  75. package/dist/cli-new/types/index.js.map +1 -0
  76. package/dist/domain/entities/CodeGraph.d.ts +134 -0
  77. package/dist/domain/entities/CodeGraph.d.ts.map +1 -0
  78. package/dist/domain/entities/CodeGraph.js +316 -0
  79. package/dist/domain/entities/CodeGraph.js.map +1 -0
  80. package/dist/domain/entities/Dependency.d.ts +78 -0
  81. package/dist/domain/entities/Dependency.d.ts.map +1 -0
  82. package/dist/domain/entities/Dependency.js +132 -0
  83. package/dist/domain/entities/Dependency.js.map +1 -0
  84. package/dist/domain/entities/Module.d.ts +75 -0
  85. package/dist/domain/entities/Module.d.ts.map +1 -0
  86. package/dist/domain/entities/Module.js +151 -0
  87. package/dist/domain/entities/Module.js.map +1 -0
  88. package/dist/domain/entities/Project.d.ts +50 -0
  89. package/dist/domain/entities/Project.d.ts.map +1 -0
  90. package/dist/domain/entities/Project.js +99 -0
  91. package/dist/domain/entities/Project.js.map +1 -0
  92. package/dist/domain/entities/Symbol.d.ts +75 -0
  93. package/dist/domain/entities/Symbol.d.ts.map +1 -0
  94. package/dist/domain/entities/Symbol.js +130 -0
  95. package/dist/domain/entities/Symbol.js.map +1 -0
  96. package/dist/domain/events/DomainEvent.d.ts +76 -0
  97. package/dist/domain/events/DomainEvent.d.ts.map +1 -0
  98. package/dist/domain/events/DomainEvent.js +153 -0
  99. package/dist/domain/events/DomainEvent.js.map +1 -0
  100. package/dist/domain/index.d.ts +10 -0
  101. package/dist/domain/index.d.ts.map +1 -0
  102. package/dist/domain/index.js +18 -0
  103. package/dist/domain/index.js.map +1 -0
  104. package/dist/domain/repositories/CodeGraphRepository.d.ts +58 -0
  105. package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -0
  106. package/dist/domain/repositories/CodeGraphRepository.js +37 -0
  107. package/dist/domain/repositories/CodeGraphRepository.js.map +1 -0
  108. package/dist/domain/services/CodeGraphBuilder.d.ts +50 -0
  109. package/dist/domain/services/CodeGraphBuilder.d.ts.map +1 -0
  110. package/dist/domain/services/CodeGraphBuilder.js +121 -0
  111. package/dist/domain/services/CodeGraphBuilder.js.map +1 -0
  112. package/dist/infrastructure/parser/implementations/GoParser.d.ts +25 -0
  113. package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -0
  114. package/dist/infrastructure/parser/implementations/GoParser.js +158 -0
  115. package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -0
  116. package/dist/infrastructure/parser/implementations/PythonParser.d.ts +30 -0
  117. package/dist/infrastructure/parser/implementations/PythonParser.d.ts.map +1 -0
  118. package/dist/infrastructure/parser/implementations/PythonParser.js +201 -0
  119. package/dist/infrastructure/parser/implementations/PythonParser.js.map +1 -0
  120. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +63 -0
  121. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -0
  122. package/dist/infrastructure/parser/implementations/TypeScriptParser.js +420 -0
  123. package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -0
  124. package/dist/infrastructure/parser/index.d.ts +13 -0
  125. package/dist/infrastructure/parser/index.d.ts.map +1 -0
  126. package/dist/infrastructure/parser/index.js +32 -0
  127. package/dist/infrastructure/parser/index.js.map +1 -0
  128. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts +124 -0
  129. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -0
  130. package/dist/infrastructure/parser/interfaces/ParserBase.js +200 -0
  131. package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -0
  132. package/dist/infrastructure/parser/registry/ParserRegistry.d.ts +68 -0
  133. package/dist/infrastructure/parser/registry/ParserRegistry.d.ts.map +1 -0
  134. package/dist/infrastructure/parser/registry/ParserRegistry.js +116 -0
  135. package/dist/infrastructure/parser/registry/ParserRegistry.js.map +1 -0
  136. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +44 -0
  137. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -0
  138. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +129 -0
  139. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -0
  140. package/dist/infrastructure/repositories/index.d.ts +3 -0
  141. package/dist/infrastructure/repositories/index.d.ts.map +1 -0
  142. package/dist/infrastructure/repositories/index.js +7 -0
  143. package/dist/infrastructure/repositories/index.js.map +1 -0
  144. package/dist/infrastructure/storage/StorageFactory.d.ts +53 -0
  145. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -0
  146. package/dist/infrastructure/storage/StorageFactory.js +150 -0
  147. package/dist/infrastructure/storage/StorageFactory.js.map +1 -0
  148. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts +52 -0
  149. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -0
  150. package/dist/infrastructure/storage/adapters/FileSystemStorage.js +315 -0
  151. package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -0
  152. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +52 -0
  153. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -0
  154. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +235 -0
  155. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -0
  156. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +37 -0
  157. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -0
  158. package/dist/infrastructure/storage/adapters/MemoryStorage.js +229 -0
  159. package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -0
  160. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +49 -0
  161. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +1 -0
  162. package/dist/infrastructure/storage/adapters/Neo4jStorage.js +222 -0
  163. package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +1 -0
  164. package/dist/infrastructure/storage/index.d.ts +6 -0
  165. package/dist/infrastructure/storage/index.d.ts.map +1 -0
  166. package/dist/infrastructure/storage/index.js +13 -0
  167. package/dist/infrastructure/storage/index.js.map +1 -0
  168. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +76 -0
  169. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -0
  170. package/dist/infrastructure/storage/interfaces/StorageBase.js +116 -0
  171. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -0
  172. package/dist/interface/config/index.d.ts +102 -0
  173. package/dist/interface/config/index.d.ts.map +1 -0
  174. package/dist/interface/config/index.js +7 -0
  175. package/dist/interface/config/index.js.map +1 -0
  176. package/dist/interface/types/index.d.ts +425 -0
  177. package/dist/interface/types/index.d.ts.map +1 -0
  178. package/dist/interface/types/index.js +8 -0
  179. package/dist/interface/types/index.js.map +1 -0
  180. package/dist/interface/types/parser.d.ts +103 -0
  181. package/dist/interface/types/parser.d.ts.map +1 -0
  182. package/dist/interface/types/parser.js +7 -0
  183. package/dist/interface/types/parser.js.map +1 -0
  184. package/dist/interface/types/storage.d.ts +98 -0
  185. package/dist/interface/types/storage.d.ts.map +1 -0
  186. package/dist/interface/types/storage.js +7 -0
  187. package/dist/interface/types/storage.js.map +1 -0
  188. package/dist/orchestrator/test-linker.js +1 -1
  189. package/dist/orchestrator/test-linker.js.map +1 -1
  190. package/dist/server/CodeMapServer.d.ts +51 -0
  191. package/dist/server/CodeMapServer.d.ts.map +1 -0
  192. package/dist/server/CodeMapServer.js +146 -0
  193. package/dist/server/CodeMapServer.js.map +1 -0
  194. package/dist/server/handlers/AnalysisHandler.d.ts +82 -0
  195. package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -0
  196. package/dist/server/handlers/AnalysisHandler.js +196 -0
  197. package/dist/server/handlers/AnalysisHandler.js.map +1 -0
  198. package/dist/server/handlers/QueryHandler.d.ts +57 -0
  199. package/dist/server/handlers/QueryHandler.d.ts.map +1 -0
  200. package/dist/server/handlers/QueryHandler.js +260 -0
  201. package/dist/server/handlers/QueryHandler.js.map +1 -0
  202. package/dist/server/index.d.ts +7 -0
  203. package/dist/server/index.d.ts.map +1 -0
  204. package/dist/server/index.js +13 -0
  205. package/dist/server/index.js.map +1 -0
  206. package/dist/server/routes/api.d.ts +8 -0
  207. package/dist/server/routes/api.d.ts.map +1 -0
  208. package/dist/server/routes/api.js +372 -0
  209. package/dist/server/routes/api.js.map +1 -0
  210. package/dist/server/types/index.d.ts +171 -0
  211. package/dist/server/types/index.d.ts.map +1 -0
  212. package/dist/server/types/index.js +7 -0
  213. package/dist/server/types/index.js.map +1 -0
  214. package/dist/types/index.d.ts +6 -372
  215. package/dist/types/index.d.ts.map +1 -1
  216. package/dist/types/index.js +9 -3
  217. package/dist/types/index.js.map +1 -1
  218. package/docs/AI_ASSISTANT_SETUP.md +811 -0
  219. package/docs/PUBLISHING.md +162 -0
  220. package/docs/README.md +37 -0
  221. package/docs/SETUP_GUIDE.md +493 -0
  222. package/docs/ai-guide/COMMANDS.md +369 -0
  223. package/docs/ai-guide/INTEGRATION.md +513 -0
  224. package/docs/ai-guide/OUTPUT.md +465 -0
  225. package/docs/ai-guide/PATTERNS.md +409 -0
  226. package/docs/ai-guide/PROMPTS.md +414 -0
  227. package/docs/ai-guide/QUICKSTART.md +114 -0
  228. package/docs/ai-guide/README.md +66 -0
  229. package/docs/archive/AI_INTEGRATION_GUIDE_ARCHIVED.md +391 -0
  230. package/docs/archive/ARCHIVE.md +39 -0
  231. package/docs/archive/MYCLAUDE_GUIDE.md +305 -0
  232. package/docs/archive/PUBLISH_NPM_DESIGN_V1.md +1699 -0
  233. package/docs/archive/PUBLISH_NPM_DESIGN_V2.md +396 -0
  234. package/docs/archive/README.md +29 -0
  235. package/docs/archive/TASK_DESIGN_COVERAGE_REPORT.md +320 -0
  236. package/docs/archive/TEST_SUMMARY.md +140 -0
  237. package/docs/archive/comprehensive_test_report.md +337 -0
  238. package/docs/archive/design-docs/CI_GATEWAY_DESIGN.md +790 -0
  239. package/docs/archive/design-docs/PUBLISH_NPM_DESIGN_FINAL.md +491 -0
  240. package/docs/archive/design-docs/REFACTOR_ARCHITECTURE_OVERVIEW.md +558 -0
  241. package/docs/archive/design-docs/REFACTOR_CONFIDENCE_DESIGN.md +250 -0
  242. package/docs/archive/design-docs/REFACTOR_GIT_ANALYZER_DESIGN.md +791 -0
  243. package/docs/archive/design-docs/REFACTOR_ORCHESTRATOR_DESIGN.md +1071 -0
  244. package/docs/archive/design-docs/REFACTOR_RESULT_FUSION_DESIGN.md +321 -0
  245. package/docs/archive/design-docs/REFACTOR_TEST_LINKER_DESIGN.md +317 -0
  246. package/docs/archive/myclaude.md +1084 -0
  247. package/docs/archive/plans/2026-03-14-go-language-support-design.md +92 -0
  248. package/docs/archive/product-specs/REFACTOR_REQUIREMENTS.md +976 -0
  249. package/docs/archive/scenario-2-deps-analysis.md +353 -0
  250. package/docs/archive/test-report-symbol-search.md +384 -0
  251. package/docs/archive/test-scenario-4-complexity-analysis.md +460 -0
  252. package/docs/archive/test_report_scenario5.md +615 -0
  253. package/docs/archive/test_scenario_3_impact_analysis_report.md +520 -0
  254. package/docs/design-docs/README.md +26 -0
  255. package/docs/exec-plans/MVP3-IMPLEMENTATION-ROADMAP.md +524 -0
  256. package/docs/exec-plans/README.md +29 -0
  257. package/docs/exec-plans/active/.gitkeep +0 -0
  258. package/docs/exec-plans/completed/.gitkeep +0 -0
  259. package/docs/exec-plans/completed/2026-03-03-deps-path-extension-fix.md +186 -0
  260. package/docs/exec-plans/completed/2026-03-03-post-task-plan.md +135 -0
  261. package/docs/exec-plans/completed/harness-engineering-rollout.md +184 -0
  262. package/docs/exec-plans/tech-debt/.gitkeep +0 -0
  263. package/docs/exec-plans/tech-debt/2026-03-15-lint-guardrail-gap.md +30 -0
  264. package/docs/generated/README.md +19 -0
  265. package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +504 -0
  266. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +322 -0
  267. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +1374 -0
  268. package/docs/product-specs/README.md +22 -0
  269. package/docs/references/README.md +15 -0
  270. package/docs/references/tmp.md +527 -0
  271. package/docs/rules/README.md +16 -0
  272. package/docs/rules/architecture-guardrails.md +349 -0
  273. package/docs/rules/code-quality-redlines.md +321 -0
  274. package/docs/rules/deployment.md +23 -0
  275. package/docs/rules/engineering-with-codex-openai.md +202 -0
  276. package/docs/rules/testing.md +73 -0
  277. package/docs/rules/validation.md +39 -0
  278. package/examples/README.md +61 -0
  279. package/examples/claude/codemap-skill.md +94 -0
  280. package/examples/codex/codemap-agent.md +66 -0
  281. package/examples/copilot/copilot-instructions.md +24 -0
  282. package/examples/kimi/codemap-skill.md +92 -0
  283. package/package.json +22 -7
@@ -0,0 +1,558 @@
1
+ # CodeMap 编排层重构设计方案 - 概要设计
2
+
3
+ > 归档时间:2026-03-15
4
+ > 归档原因:历史重构概要设计,文内对 workflow 同时存在“已实现”和“规划中”的冲突描述。
5
+ > 当前依据:`ARCHITECTURE.md`、`docs/rules/*`、`src/cli/commands/workflow.ts`
6
+ > 状态:仅供历史对照,不作为当前执行依据。
7
+
8
+
9
+ > 版本: 2.5
10
+ > 日期: 2026-02-28
11
+ > 状态: 已完成 (v2.5 工作流编排器已实现)
12
+
13
+ ---
14
+
15
+ ## 文档导航
16
+
17
+ 本文档是架构设计的**概要文档**,概述整体架构设计。如需了解特定模块的详细设计,请参考对应的详细设计文档:
18
+
19
+ | 模块 | 详细设计文档 |
20
+ |------|-------------|
21
+ | 置信度机制 | [REFACTOR_CONFIDENCE_DESIGN.md](./REFACTOR_CONFIDENCE_DESIGN.md) |
22
+ | 多工具结果融合 | [REFACTOR_RESULT_FUSION_DESIGN.md](./REFACTOR_RESULT_FUSION_DESIGN.md) |
23
+ | CLI 命令与编排层 | [REFACTOR_ORCHESTRATOR_DESIGN.md](./REFACTOR_ORCHESTRATOR_DESIGN.md) |
24
+ | 测试关联器 | [REFACTOR_TEST_LINKER_DESIGN.md](./REFACTOR_TEST_LINKER_DESIGN.md) |
25
+ | Git 分析器 | [REFACTOR_GIT_ANALYZER_DESIGN.md](./REFACTOR_GIT_ANALYZER_DESIGN.md) |
26
+ | **CI 门禁护栏** | **[CI_GATEWAY_DESIGN.md](./CI_GATEWAY_DESIGN.md)** (v2.4 新增) |
27
+ | **工作流编排器** | **[REFACTOR_ORCHESTRATOR_DESIGN.md](./REFACTOR_ORCHESTRATOR_DESIGN.md)** (v2.5 已实现 ✅) |
28
+
29
+ ---
30
+
31
+ ## 1. 设计前提:职责分离
32
+
33
+ **核心原则**:Codemap 只负责执行,意图理解交给上游 AI (Claude Code / Codex)
34
+
35
+ ```
36
+ 用户自然语言
37
+
38
+
39
+ Claude Code / Codex CLI
40
+ │ 意图理解 + 转换为 Codemap 指令
41
+
42
+ Codemap (结构化输入 → 执行分析)
43
+
44
+
45
+ 结果返回
46
+ ```
47
+
48
+ **约束**:
49
+ - **禁止 grep 体系**:所有用户可见输出必须走 CodeMap 语义链路
50
+ - rg 仅作为**内部调试工具**(默认关闭),不暴露给上游 AI Agent
51
+
52
+ #### 本地兜底校验层
53
+
54
+ 即使上游 AI 理解正确,本地仍需三重校验防止故障放大:
55
+
56
+ | 校验层 | 检查内容 | 失败处理 |
57
+ |--------|----------|----------|
58
+ | **Intent 白名单** | 请求的 intent 是否在允许列表 | 返回 E0001,提示有效 intent |
59
+ | **参数完整性** | 必填参数是否存在、类型正确 | 返回 E0002,提示缺少参数 |
60
+ | **低置信度降级** | 输出置信度低于阈值时 | 返回 E0006 + 建议,而非错误 |
61
+
62
+ ---
63
+
64
+ ## 2. 目标与约束
65
+
66
+ ### 2.1 核心目标
67
+
68
+ 增强 AI 大模型对项目代码的理解和查询能力,减少 token 消耗和搜索错误。
69
+
70
+ ### 2.2 关键指标
71
+
72
+ | 指标 | 目标值 | 测量方法 |
73
+ |------|--------|----------|
74
+ | Token 消耗降低 | >= 40% | 统计 analyze 输出 token 数 vs rg/grep 基准 |
75
+ | Hit@8 | >= 90% | Top-8 结果中包含用户期望结果的比率 |
76
+ | 默认输出规则 | Top-K=8、每条<=160 token | 代码约束 |
77
+ | 基准集 | 30 条查询 | 预先定义的典型查询 |
78
+ | 搜索范围 | TS/JS + Markdown | 配置约束 |
79
+ | Commit 格式 | `[TAG] scope: message` | 强制标签化 (v2.4 新增) |
80
+ | 文件头注释 | `[META]`/`[WHY]` 必填 | CI 门禁 (v2.4 新增) |
81
+ | AI 饲料 | `.mycodemap/ai-feed.txt` | 自动生成 (v2.4 新增) |
82
+
83
+ ### 2.3 Benchmark 协议
84
+
85
+ #### 数据集位置
86
+ - 基准查询集: `refer/benchmark-quality.ts` (30 条预定义查询)
87
+ - 测试项目: `/data/codemap` 自身作为测试目标
88
+
89
+ #### 执行命令
90
+ ```bash
91
+ # 基准测试(直接运行)
92
+ npx ts-node refer/benchmark-quality.ts
93
+
94
+ # 基准测试(Vitest 集成)
95
+ npx vitest run refer/benchmark-quality.test.ts
96
+
97
+ # Token 消耗测量
98
+ node dist/cli/index.js analyze --intent search --keywords <keyword> --json | \
99
+ jq '[.results[].content] | map(. | split(" ") | length) | add'
100
+
101
+ # 对比基准 (rg)
102
+ rg <keyword> --json | jq '[.[] | .lines | split(" ") | length] | add'
103
+ ```
104
+
105
+ #### Token 统计方法
106
+ - 使用 cl100k_base 估算
107
+ - 统计公式: `输出 token = sum(result.content.split(/\s/) | length)`
108
+
109
+ #### 固定版本
110
+ - Node.js: v20.x LTS
111
+ - TypeScript: 5.x
112
+ - codemap: 当前版本 (通过 `codemap --version` 获取)
113
+
114
+ ### 2.3 技术约束
115
+
116
+ - 入口:单 CLI 编排(优先快速落地)
117
+ - 集成方式:fork 子进程调用外部工具
118
+
119
+ ### 2.4 版本范围
120
+
121
+ #### v1.0 范围(本期实施)
122
+
123
+ | 维度 | 支持范围 | 非目标 |
124
+ |------|----------|--------|
125
+ | **语言** | TypeScript、JavaScript、Markdown | Python、Go、Rust 等 |
126
+ | **文件类型** | `.ts`、`.tsx`、`.js`、`.jsx`、`.md` | 二进制、配置(yaml/json) |
127
+ | **Intent** | impact, dependency, search, documentation, complexity, overview, refactor, reference | - |
128
+ | **工具链** | CodeMap 核心 + ast-grep | qmd 其他外部工具 |
129
+
130
+ #### v2.0 扩展开关(规划中)
131
+
132
+ ```typescript
133
+ // 配置开关 - v2.0 启用
134
+ interface ExpansionConfig {
135
+ enableMultiLanguage: boolean; // 多语言支持
136
+ enableBinaryAnalysis: boolean; // 二进制分析
137
+ enableMoreTools: string[]; // 扩展工具列表
138
+ }
139
+ ```
140
+
141
+ > ⚠️ **注意**:ast-grep 本身支持多语言,但 v1.0 聚焦 TS/JS 场景,其他语言作为可选扩展。
142
+
143
+ ---
144
+
145
+ ## 3. 整体架构
146
+
147
+ ```
148
+ ┌─────────────────────────────────────────────────────────────┐
149
+ │ Claude Code / Codex CLI │
150
+ │ 意图理解 → 转换为 Codemap 指令 │
151
+ └──────────────────────────┬──────────────────────────────────┘
152
+
153
+
154
+ ┌─────────────────────────────────────────────────────────────┐
155
+ │ 用户 CLI 入口 │
156
+ │ codemap analyze --intent impact ... │
157
+ └──────────────────────────┬──────────────────────────────────┘
158
+
159
+
160
+ ┌─────────────────────────────────────────────────────────────┐
161
+ │ 意图路由 (Intent Router) │
162
+ │ 根据 intent 类型路由到执行计划 │
163
+ └──────────────────────────┬──────────────────────────────────┘
164
+
165
+
166
+ ┌─────────────────────────────────────────────────────────────┐
167
+ │ 工具编排器 (Tool Orchestrator) │
168
+ │ 执行工具 → 计算置信度 → 回退级联 → 结果融合 │
169
+ └──────────────────────────┬──────────────────────────────────┘
170
+
171
+ ┌─────────────────┼─────────────────┐
172
+ │ │ │
173
+ ▼ ▼ ▼
174
+ ┌─────────────────┐ ┌─────────────┐ ┌─────────────────┐
175
+ │ CodeMap 核心 │ │ ast-grep │ │ 内部工具 │
176
+ │ (依赖/复杂度/ │ │ (代码搜索/ │ │ (rg 仅调试用) │
177
+ │ 影响评估/概览) │ │ AST分析) │ │ 默认关闭 │
178
+ └─────────────────┘ └─────────────┘ └─────────────────┘
179
+ │ │ │
180
+ └─────────────────┼─────────────────┘
181
+
182
+
183
+ ┌─────────────────────────────────────────────────────────────┐
184
+ │ 结果归一化 + 输出裁剪 │
185
+ │ 统一格式 + Top-K + Token 限制 │
186
+ └─────────────────────────────────────────────────────────────┘
187
+
188
+
189
+ ┌─────────────────────────────────────────────────────────────┐
190
+ │ AI 饲料生成器 (v2.4 新增) │
191
+ │ 扫描文件头 → 分析 Git 历史 → 生成 ai-feed.txt │
192
+ └─────────────────────────────────────────────────────────────┘
193
+
194
+
195
+ ┌─────────────────────────────────────────────────────────────┐
196
+ │ CI 门禁护栏 (v2.4 新增) │
197
+ │ 本地 Hook (pre-commit) + 服务端 CI (GitHub Actions) │
198
+ │ Commit 格式验证 → 文件头检查 → 风险评估 │
199
+ └─────────────────────────────────────────────────────────────┘
200
+ ```
201
+
202
+ ### 工具职责划分
203
+
204
+ | 工具 | 职责 | 调用方式 | 权重 | 可见性 |
205
+ |------|------|----------|------|--------|
206
+ | **CodeMap 核心** | 代码结构提取、依赖图生成、复杂度分析、影响评估、项目概览 | 本地调用 | 0.9 | 用户可见 |
207
+ | **ast-grep** | 代码模式匹配、语义搜索、AST 分析(v1 聚焦 TS/JS) | fork 子进程 | 1.0 | 用户可见 |
208
+ | **rg-internal** | 内部兜底文本搜索(默认关闭) | fork 子进程 | 0.7 | **仅内部** |
209
+ | **AI 饲料** | 结构化代码元数据、风险评估数据 | 本地调用 | 0.85 | 用户可见 (v2.4 新增) |
210
+
211
+ ### 输出协议版本化
212
+
213
+ #### 统一输出格式
214
+
215
+ ```typescript
216
+ interface CodemapOutput {
217
+ schemaVersion: string; // 格式: "v1.0.0"
218
+ intent: string; // 执行的 intent 类型
219
+ tool: string; // 主要工具
220
+ confidence: {
221
+ score: number; // 0-1
222
+ level: 'high' | 'medium' | 'low';
223
+ };
224
+ results: UnifiedResult[]; // 结果列表
225
+ metadata?: {
226
+ executionTime: number; // 毫秒
227
+ resultCount: number;
228
+ };
229
+ }
230
+ ```
231
+
232
+ #### 稳定字段列表(向后兼容)
233
+
234
+ | 字段 | 兼容性 | 说明 |
235
+ |------|--------|------|
236
+ | `schemaVersion` | **必须** | 版本标识 |
237
+ | `intent` | **必须** | intent 类型 |
238
+ | `confidence.score` | **必须** | 置信度分数 |
239
+ | `confidence.level` | **必须** | 置信度级别 |
240
+ | `results[].id` | **必须** | 唯一标识 |
241
+ | `results[].file` | **必须** | 文件路径 |
242
+ | `results[].content` | **必须** | 内容(可能被截断) |
243
+
244
+ #### 向后兼容策略
245
+
246
+ 1. **新增字段**:可选字段,旧版本忽略
247
+ 2. **废弃字段**:先标记弃用 (deprecated),下个主版本移除
248
+ 3. **破坏性变更**:仅在主版本号升级时(如 v1 → v2)
249
+
250
+ #### Golden Files 测试
251
+
252
+ ```bash
253
+ # 测试用例位置
254
+ tests/golden/
255
+ ├── v1.0.0-impact.json # 影响分析输出
256
+ ├── v1.0.0-search.json # 搜索输出
257
+ ├── v1.0.0-dependency.json # 依赖输出
258
+ └── ...
259
+ ```
260
+
261
+ ---
262
+
263
+ ## 4. 核心模块概览
264
+
265
+ ### 4.1 置信度机制
266
+
267
+ 基于搜索结果质量(结果数量、质量、场景匹配度)计算置信度,决定是否触发回退。
268
+
269
+ **详见**: [REFACTOR_CONFIDENCE_DESIGN.md](./REFACTOR_CONFIDENCE_DESIGN.md)
270
+
271
+ ### 4.2 多工具结果融合
272
+
273
+ 统一结果格式,加权合并、去重、排序。
274
+
275
+ **详见**: [REFACTOR_RESULT_FUSION_DESIGN.md](./REFACTOR_RESULT_FUSION_DESIGN.md)
276
+
277
+ ### 4.3 工具编排器
278
+
279
+ 执行工具、超时控制、错误隔离、回退级联。
280
+
281
+ **详见**: [REFACTOR_ORCHESTRATOR_DESIGN.md](./REFACTOR_ORCHESTRATOR_DESIGN.md)
282
+
283
+ ### 4.4 测试关联器
284
+
285
+ 在影响分析中自动关联测试文件。
286
+
287
+ **详见**: [REFACTOR_TEST_LINKER_DESIGN.md](./REFACTOR_TEST_LINKER_DESIGN.md)
288
+
289
+ ### 4.5 Git 分析器
290
+
291
+ 分析文件修改历史,评估修改风险。
292
+
293
+ **详见**: [REFACTOR_GIT_ANALYZER_DESIGN.md](./REFACTOR_GIT_ANALYZER_DESIGN.md)
294
+
295
+ ### 4.6 AI 饲料生成器 (v2.4 新增)
296
+
297
+ 生成结构化 AI 消费数据,包含文件元数据、依赖复杂度、修改热度等维度。
298
+
299
+ **功能**:
300
+ - 扫描文件头注释 `[META]`/`[WHY]`/`[DEPS]`
301
+ - 分析 Git 历史(30天修改频率、标签分布)
302
+ - 计算 GRAVITY/HEAT/IMPACT 三维评分
303
+ - 输出 `.mycodemap/ai-feed.txt`
304
+
305
+ > 风险评分公式统一以 `../product-specs/REFACTOR_REQUIREMENTS.md` 第 8.6 节为单一真源。
306
+
307
+ **详见**: [REFACTOR_GIT_ANALYZER_DESIGN.md](./REFACTOR_GIT_ANALYZER_DESIGN.md) 第4节
308
+
309
+ ### 4.7 CI 门禁护栏 (v2.4 新增)
310
+
311
+ 双层次 CI 门禁:本地 pre-commit hook + 服务端 GitHub Actions。
312
+
313
+ **功能**:
314
+ - Commit 格式验证 `[TAG]`
315
+ - 文件头注释强制检查
316
+ - 危险置信度评估
317
+ - AI 饲料同步验证
318
+
319
+ **详见**: [CI_GATEWAY_DESIGN.md](./CI_GATEWAY_DESIGN.md)
320
+
321
+ ### 4.8 工作流编排器 (v2.5 规划)
322
+
323
+ 串联所有模块的"粘合剂",提供开发流程的阶段管理、上下文传递和检查点机制。
324
+
325
+ **功能**:
326
+ - 阶段状态机管理(pending → running → completed → verified)
327
+ - 阶段间上下文持久化(WorkflowContext)
328
+ - 阶段交付物检查点(PhaseCheckpoint)
329
+ - 交互式工作流引导(WorkflowCLI)
330
+
331
+ **详见**: [工作流编排器设计](./REFACTOR_ORCHESTRATOR_DESIGN.md#8-工作流编排器设计-v25-规划)
332
+
333
+ ---
334
+
335
+ ## 5. CLI 命令结构
336
+
337
+ ```bash
338
+ # 核心命令
339
+ codemap generate # 生成代码地图(含 AI 饲料)
340
+ codemap analyze # 全面分析(主要入口)
341
+
342
+ # 细分命令(直接调用底层能力)
343
+ codemap impact # 影响分析
344
+ codemap deps # 依赖查看
345
+ codemap cycles # 循环依赖检测
346
+ codemap complexity # 复杂度分析
347
+ codemap query # 查询
348
+
349
+ # CI 门禁命令 (v2.4 新增)
350
+ codemap ci check-commits # 验证 Commit 格式
351
+ codemap ci check-headers # 验证文件头注释
352
+ codemap ci assess-risk # 评估危险置信度
353
+ codemap ci check-output-contract # 验证输出契约(schemaVersion、Top-K、token限制)
354
+
355
+ # 工作流命令 (v2.5 规划)
356
+ codemap workflow start # 启动交互式工作流
357
+ codemap workflow status # 查看当前工作流状态
358
+ codemap workflow visualize # 可视化当前工作流
359
+ codemap workflow proceed # 推进到下一阶段
360
+ codemap workflow resume # 恢复中断的工作流
361
+ codemap workflow checkpoint # 手动创建检查点
362
+ codemap workflow template ... # 模板管理与应用
363
+ ```
364
+
365
+ ### analyze 命令参数
366
+
367
+ #### 参数契约(JSON Schema)
368
+
369
+ ```typescript
370
+ // CLI 参数契约
371
+ const AnalyzeArgsSchema = {
372
+ type: 'object',
373
+ properties: {
374
+ intent: {
375
+ type: 'string',
376
+ enum: ['impact', 'dependency', 'search', 'documentation', 'complexity', 'overview', 'refactor', 'reference'],
377
+ default: 'search',
378
+ description: '意图类型'
379
+ },
380
+ keywords: {
381
+ type: 'array',
382
+ items: { type: 'string', maxLength: 100 },
383
+ maxItems: 10,
384
+ description: '搜索关键词'
385
+ },
386
+ targets: {
387
+ type: 'array',
388
+ items: { type: 'string' },
389
+ description: '目标文件/模块路径'
390
+ },
391
+ scope: {
392
+ type: 'string',
393
+ enum: ['direct', 'transitive'],
394
+ default: 'direct',
395
+ description: '搜索范围'
396
+ },
397
+ topK: {
398
+ type: 'number',
399
+ minimum: 1,
400
+ maximum: 100,
401
+ default: 8,
402
+ description: '返回结果数量'
403
+ },
404
+ includeTests: {
405
+ type: 'boolean',
406
+ default: false,
407
+ description: '是否包含测试文件'
408
+ },
409
+ includeGitHistory: {
410
+ type: 'boolean',
411
+ default: false,
412
+ description: '是否包含 Git 历史'
413
+ },
414
+ json: {
415
+ type: 'boolean',
416
+ default: false,
417
+ description: 'JSON 格式输出'
418
+ },
419
+ outputMode: {
420
+ type: 'string',
421
+ enum: ['machine', 'human'],
422
+ default: 'human',
423
+ description: '输出模式。machine 模式禁止额外日志,保证纯 JSON'
424
+ }
425
+ },
426
+ required: []
427
+ } as const;
428
+ ```
429
+
430
+ > 当 `json=true` 时,必须自动切换或强制要求 `outputMode='machine'`,以确保输出可被 `JSON.parse` 直接消费。
431
+
432
+ #### 错误码表
433
+
434
+ | 错误码 | 含义 | 用户提示 | 可观测字段 |
435
+ |--------|------|----------|------------|
436
+ | E0001 | 无效 intent 值 | `无效的 intent: ${value},允许值: ${enum}` | `intent`, `validIntents` |
437
+ | E0002 | 缺少必要参数 | `缺少必要参数: ${param}` | `missingParams` |
438
+ | E0003 | 目标路径不存在 | `目标路径不存在: ${path}` | `path` |
439
+ | E0004 | 工具执行超时 | `${tool} 执行超时 (${timeout}ms)` | `tool`, `timeout` |
440
+ | E0005 | 工具执行失败 | `${tool} 执行失败: ${error}` | `tool`, `error` |
441
+ | E0006 | 置信度过低 | `结果置信度过低 (${score}),建议调整关键词` | `confidence`, `suggestion` |
442
+ | **E0007** | **Commit 格式错误** | **提交信息必须以 [TAG] 开头** | **message** (v2.4 新增) |
443
+ | **E0008** | **文件头缺失** | **文件缺少 [META] 或 [WHY] 注释** | **file** (v2.4 新增) |
444
+ | **E0009** | **高风险文件** | **修改高风险文件需说明缓解措施** | **file, riskLevel** (v2.4 新增) |
445
+
446
+ #### CLI 示例
447
+
448
+ ```bash
449
+ # 影响分析
450
+ codemap analyze --intent impact --targets src/cache/ --scope transitive --include-tests
451
+
452
+ # 代码搜索
453
+ codemap analyze --intent search --keywords parser --top-k 8 --json
454
+
455
+ # 依赖分析
456
+ codemap analyze --intent dependency --targets src/core/
457
+
458
+ # 文档搜索
459
+ codemap analyze --intent documentation --keywords "系统架构"
460
+ ```
461
+
462
+ ---
463
+
464
+ ## 6. 文件结构
465
+
466
+ ```
467
+ src/
468
+ ├── cli/
469
+ │ ├── commands/
470
+ │ │ ├── analyze.ts # 统一入口
471
+ │ │ ├── ci.ts # CI 门禁 (v2.4 新增)
472
+ │ │ ├── impact.ts # 现有命令
473
+ │ │ ├── deps.ts # 现有命令
474
+ │ │ └── complexity.ts # 现有命令
475
+ │ └── index.ts
476
+ ├── orchestrator/ # 编排层
477
+ │ ├── index.ts
478
+ │ ├── types.ts # 统一结果格式
479
+ │ ├── intent-router.ts # 意图路由
480
+ │ ├── tool-orchestrator.ts # 工具编排 + 回退
481
+ │ ├── confidence.ts # 置信度计算
482
+ │ ├── result-fusion.ts # 结果融合
483
+ │ ├── adapters/ # 工具适配器
484
+ │ ├── test-linker.ts # 测试关联
485
+ │ ├── git-analyzer.ts # Git 分析
486
+ │ ├── ai-feed-generator.ts # AI 饲料生成 (v2.4 新增)
487
+ │ ├── file-header-scanner.ts # 文件头扫描 (v2.4 新增)
488
+ │ └── commit-validator.ts # Commit 验证 (v2.4 新增)
489
+ └── ...
490
+
491
+ # CI 配置文件 (v2.4 新增)
492
+ .github/
493
+ └── workflows/
494
+ └── ci-gateway.yml # GitHub Actions 门禁
495
+ .git/hooks/ # 本地 Hook (v2.4 新增)
496
+ ├── commit-msg # Commit 格式验证
497
+ └── pre-commit # 测试 + 文件头检查
498
+
499
+ ---
500
+
501
+ ## 7. 实施计划
502
+
503
+ | 阶段 | 周期 | 内容 | 交付物 | DoD (Definition of Done) | 阻塞条件 | 回滚点 |
504
+ |------|------|------|--------|--------------------------|----------|--------|
505
+ | **Phase 1** | 1 天 | 定义 `UnifiedResult` 接口 + 适配器基类 | 统一格式规范 | TypeScript 接口定义完成,单元测试覆盖 | - | 本阶段回滚:删除新增文件 |
506
+ | **Phase 2** | 1 天 | 实现置信度计算 `calculateConfidence` | 置信度机制 | 置信度计算函数实现,三级阈值可配置 | Phase 1 完成 | 本阶段回滚:保留接口定义 |
507
+ | **Phase 3** | 1 天 | 实现 `ResultFusion` 融合逻辑 | 多工具融合 | 加权合并、去重、排序逻辑测试通过 | Phase 2 完成 | 本阶段回滚:保留置信度模块 |
508
+ | **Phase 4** | 1 天 | 实现 `ToolOrchestrator` + 回退链 | 编排器 | 超时控制、错误隔离、回退触发测试通过 | Phase 3 完成 | 本阶段回滚:保留融合逻辑 |
509
+ | **Phase 5** | 1 天 | 改造现有命令为可调用模式 | 复用能力 | 现有命令模块化,可被编排器调用 | Phase 4 完成 | 本阶段回滚:保留编排器 |
510
+ | **Phase 6** | 1 天 | 实现 `AnalyzeCommand` + 测试关联 | 统一入口 | CLI 入口测试通过,测试关联功能正常 | Phase 5 完成 | 本阶段回滚:保留模块化命令 |
511
+ | **Phase 7** | 1 天 | 实现 Git 分析器 | Git 风险评分 | Git 历史分析、风险评分功能正常 | Phase 6 完成 | 本阶段回滚:保留入口命令 |
512
+ | **Phase 8** | 1 天 | 实现 AI 饲料生成器 | `.mycodemap/ai-feed.txt` | 生成结构化 AI 消费数据 | Phase 7 完成 | 本阶段回滚:保留 Git 分析 |
513
+ | **Phase 9** | 1 天 | 实现 CI 门禁护栏 | CI Gateway | Commit 格式、文件头检查、风险评级 | Phase 8 完成 | 本阶段回滚:保留 AI 饲料 |
514
+ | **Phase 10** | 1 天 | 测试 + 基准验证 | 30 条查询评测 | Hit@8 >= 90%, Token 降低 >= 40% | Phase 9 完成 | 本阶段回滚:保留完整功能 |
515
+
516
+ **预计周期**:10 天 (v2.4 新增 CI 门禁阶段)
517
+
518
+ ### 门禁规则
519
+
520
+ - **进入条件**:上一阶段 DoD 验收通过
521
+ - **退出条件**:本阶段交付物 + 最小验收测试通过
522
+ - **阻塞处理**:若阶段阻塞超过 2 天,启动回滚
523
+
524
+ ---
525
+
526
+ ## 8. 验收标准
527
+
528
+ - [ ] `codemap analyze` 命令可正常执行
529
+ - [ ] 意图路由正确映射到工具
530
+ - [ ] 置信度正确计算(高/中/低三级)
531
+ - [ ] 回退级联正常工作
532
+ - [ ] 多工具结果正确融合(去重+排序)
533
+ - [ ] 测试关联基于 Jest/Vitest 配置
534
+ - [ ] Git 提交历史风险评分正常
535
+ - [ ] **AI 饲料生成正常 (v2.4 新增)**
536
+ - [ ] **CI 门禁本地 Hook 正常工作 (v2.4 新增)**
537
+ - [ ] **CI 门禁服务端检查通过 (v2.4 新增)**
538
+ - [ ] **Commit 格式 `[TAG]` 验证通过 (v2.4 新增)**
539
+ - [ ] **文件头注释 `[META]`/`[WHY]` 完整 (v2.4 新增)**
540
+ - [ ] 现有命令保持兼容
541
+ - [ ] 输出符合 Top-K=8、每条<=160 token
542
+ - [ ] Hit@8 >= 90%
543
+ - [ ] Token 消耗降低 >= 40%
544
+
545
+ ---
546
+
547
+ ## 附录
548
+
549
+ ### 相关文档
550
+
551
+ - 评估报告: `CODEMAP_ASSESSMENT_REPORT.md`
552
+ - 方案对比: `MULTI_TOOL_REFACTOR_OPTIONS.md`
553
+ - 需求与用户场景: `../product-specs/REFACTOR_REQUIREMENTS.md`
554
+ - **CI 门禁设计: `CI_GATEWAY_DESIGN.md` (v2.4 新增)**
555
+
556
+ ### 参考资源
557
+
558
+ - ast-grep 官方文档: https://ast-grep.github.io/