@mycodemap/mycodemap 0.1.1 → 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 (243) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +241 -67
  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/export.d.ts +6 -0
  8. package/dist/cli/commands/export.d.ts.map +1 -0
  9. package/dist/cli/commands/export.js +108 -0
  10. package/dist/cli/commands/export.js.map +1 -0
  11. package/dist/cli/commands/generate.d.ts.map +1 -1
  12. package/dist/cli/commands/generate.js +96 -0
  13. package/dist/cli/commands/generate.js.map +1 -1
  14. package/dist/cli/commands/server.d.ts +9 -0
  15. package/dist/cli/commands/server.d.ts.map +1 -0
  16. package/dist/cli/commands/server.js +68 -0
  17. package/dist/cli/commands/server.js.map +1 -0
  18. package/dist/cli/index.js +22 -1
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli-new/commands/export.d.ts +15 -0
  21. package/dist/cli-new/commands/export.d.ts.map +1 -0
  22. package/dist/cli-new/commands/export.js +107 -0
  23. package/dist/cli-new/commands/export.js.map +1 -0
  24. package/dist/cli-new/commands/query.d.ts +14 -0
  25. package/dist/cli-new/commands/query.d.ts.map +1 -0
  26. package/dist/cli-new/commands/query.js +120 -0
  27. package/dist/cli-new/commands/query.js.map +1 -0
  28. package/dist/cli-new/commands/server.d.ts +13 -0
  29. package/dist/cli-new/commands/server.d.ts.map +1 -0
  30. package/dist/cli-new/commands/server.js +94 -0
  31. package/dist/cli-new/commands/server.js.map +1 -0
  32. package/dist/cli-new/index.d.ts +11 -0
  33. package/dist/cli-new/index.d.ts.map +1 -0
  34. package/dist/cli-new/index.js +63 -0
  35. package/dist/cli-new/index.js.map +1 -0
  36. package/dist/cli-new/types/index.d.ts +88 -0
  37. package/dist/cli-new/types/index.d.ts.map +1 -0
  38. package/dist/cli-new/types/index.js +7 -0
  39. package/dist/cli-new/types/index.js.map +1 -0
  40. package/dist/domain/entities/CodeGraph.d.ts +134 -0
  41. package/dist/domain/entities/CodeGraph.d.ts.map +1 -0
  42. package/dist/domain/entities/CodeGraph.js +316 -0
  43. package/dist/domain/entities/CodeGraph.js.map +1 -0
  44. package/dist/domain/entities/Dependency.d.ts +78 -0
  45. package/dist/domain/entities/Dependency.d.ts.map +1 -0
  46. package/dist/domain/entities/Dependency.js +132 -0
  47. package/dist/domain/entities/Dependency.js.map +1 -0
  48. package/dist/domain/entities/Module.d.ts +75 -0
  49. package/dist/domain/entities/Module.d.ts.map +1 -0
  50. package/dist/domain/entities/Module.js +151 -0
  51. package/dist/domain/entities/Module.js.map +1 -0
  52. package/dist/domain/entities/Project.d.ts +50 -0
  53. package/dist/domain/entities/Project.d.ts.map +1 -0
  54. package/dist/domain/entities/Project.js +99 -0
  55. package/dist/domain/entities/Project.js.map +1 -0
  56. package/dist/domain/entities/Symbol.d.ts +75 -0
  57. package/dist/domain/entities/Symbol.d.ts.map +1 -0
  58. package/dist/domain/entities/Symbol.js +130 -0
  59. package/dist/domain/entities/Symbol.js.map +1 -0
  60. package/dist/domain/events/DomainEvent.d.ts +76 -0
  61. package/dist/domain/events/DomainEvent.d.ts.map +1 -0
  62. package/dist/domain/events/DomainEvent.js +153 -0
  63. package/dist/domain/events/DomainEvent.js.map +1 -0
  64. package/dist/domain/index.d.ts +10 -0
  65. package/dist/domain/index.d.ts.map +1 -0
  66. package/dist/domain/index.js +18 -0
  67. package/dist/domain/index.js.map +1 -0
  68. package/dist/domain/repositories/CodeGraphRepository.d.ts +58 -0
  69. package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -0
  70. package/dist/domain/repositories/CodeGraphRepository.js +37 -0
  71. package/dist/domain/repositories/CodeGraphRepository.js.map +1 -0
  72. package/dist/domain/services/CodeGraphBuilder.d.ts +50 -0
  73. package/dist/domain/services/CodeGraphBuilder.d.ts.map +1 -0
  74. package/dist/domain/services/CodeGraphBuilder.js +121 -0
  75. package/dist/domain/services/CodeGraphBuilder.js.map +1 -0
  76. package/dist/infrastructure/parser/implementations/GoParser.d.ts +25 -0
  77. package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -0
  78. package/dist/infrastructure/parser/implementations/GoParser.js +158 -0
  79. package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -0
  80. package/dist/infrastructure/parser/implementations/PythonParser.d.ts +30 -0
  81. package/dist/infrastructure/parser/implementations/PythonParser.d.ts.map +1 -0
  82. package/dist/infrastructure/parser/implementations/PythonParser.js +201 -0
  83. package/dist/infrastructure/parser/implementations/PythonParser.js.map +1 -0
  84. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +63 -0
  85. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -0
  86. package/dist/infrastructure/parser/implementations/TypeScriptParser.js +420 -0
  87. package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -0
  88. package/dist/infrastructure/parser/index.d.ts +13 -0
  89. package/dist/infrastructure/parser/index.d.ts.map +1 -0
  90. package/dist/infrastructure/parser/index.js +32 -0
  91. package/dist/infrastructure/parser/index.js.map +1 -0
  92. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts +124 -0
  93. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -0
  94. package/dist/infrastructure/parser/interfaces/ParserBase.js +200 -0
  95. package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -0
  96. package/dist/infrastructure/parser/registry/ParserRegistry.d.ts +68 -0
  97. package/dist/infrastructure/parser/registry/ParserRegistry.d.ts.map +1 -0
  98. package/dist/infrastructure/parser/registry/ParserRegistry.js +116 -0
  99. package/dist/infrastructure/parser/registry/ParserRegistry.js.map +1 -0
  100. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +44 -0
  101. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -0
  102. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +129 -0
  103. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -0
  104. package/dist/infrastructure/repositories/index.d.ts +3 -0
  105. package/dist/infrastructure/repositories/index.d.ts.map +1 -0
  106. package/dist/infrastructure/repositories/index.js +7 -0
  107. package/dist/infrastructure/repositories/index.js.map +1 -0
  108. package/dist/infrastructure/storage/StorageFactory.d.ts +53 -0
  109. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -0
  110. package/dist/infrastructure/storage/StorageFactory.js +150 -0
  111. package/dist/infrastructure/storage/StorageFactory.js.map +1 -0
  112. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts +52 -0
  113. package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -0
  114. package/dist/infrastructure/storage/adapters/FileSystemStorage.js +315 -0
  115. package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -0
  116. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +52 -0
  117. package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -0
  118. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +235 -0
  119. package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -0
  120. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +37 -0
  121. package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -0
  122. package/dist/infrastructure/storage/adapters/MemoryStorage.js +229 -0
  123. package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -0
  124. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +49 -0
  125. package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +1 -0
  126. package/dist/infrastructure/storage/adapters/Neo4jStorage.js +222 -0
  127. package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +1 -0
  128. package/dist/infrastructure/storage/index.d.ts +6 -0
  129. package/dist/infrastructure/storage/index.d.ts.map +1 -0
  130. package/dist/infrastructure/storage/index.js +13 -0
  131. package/dist/infrastructure/storage/index.js.map +1 -0
  132. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +76 -0
  133. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -0
  134. package/dist/infrastructure/storage/interfaces/StorageBase.js +116 -0
  135. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -0
  136. package/dist/interface/config/index.d.ts +102 -0
  137. package/dist/interface/config/index.d.ts.map +1 -0
  138. package/dist/interface/config/index.js +7 -0
  139. package/dist/interface/config/index.js.map +1 -0
  140. package/dist/interface/types/index.d.ts +425 -0
  141. package/dist/interface/types/index.d.ts.map +1 -0
  142. package/dist/interface/types/index.js +8 -0
  143. package/dist/interface/types/index.js.map +1 -0
  144. package/dist/interface/types/parser.d.ts +103 -0
  145. package/dist/interface/types/parser.d.ts.map +1 -0
  146. package/dist/interface/types/parser.js +7 -0
  147. package/dist/interface/types/parser.js.map +1 -0
  148. package/dist/interface/types/storage.d.ts +98 -0
  149. package/dist/interface/types/storage.d.ts.map +1 -0
  150. package/dist/interface/types/storage.js +7 -0
  151. package/dist/interface/types/storage.js.map +1 -0
  152. package/dist/orchestrator/test-linker.js +1 -1
  153. package/dist/orchestrator/test-linker.js.map +1 -1
  154. package/dist/server/CodeMapServer.d.ts +51 -0
  155. package/dist/server/CodeMapServer.d.ts.map +1 -0
  156. package/dist/server/CodeMapServer.js +146 -0
  157. package/dist/server/CodeMapServer.js.map +1 -0
  158. package/dist/server/handlers/AnalysisHandler.d.ts +82 -0
  159. package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -0
  160. package/dist/server/handlers/AnalysisHandler.js +196 -0
  161. package/dist/server/handlers/AnalysisHandler.js.map +1 -0
  162. package/dist/server/handlers/QueryHandler.d.ts +57 -0
  163. package/dist/server/handlers/QueryHandler.d.ts.map +1 -0
  164. package/dist/server/handlers/QueryHandler.js +260 -0
  165. package/dist/server/handlers/QueryHandler.js.map +1 -0
  166. package/dist/server/index.d.ts +7 -0
  167. package/dist/server/index.d.ts.map +1 -0
  168. package/dist/server/index.js +13 -0
  169. package/dist/server/index.js.map +1 -0
  170. package/dist/server/routes/api.d.ts +8 -0
  171. package/dist/server/routes/api.d.ts.map +1 -0
  172. package/dist/server/routes/api.js +372 -0
  173. package/dist/server/routes/api.js.map +1 -0
  174. package/dist/server/types/index.d.ts +171 -0
  175. package/dist/server/types/index.d.ts.map +1 -0
  176. package/dist/server/types/index.js +7 -0
  177. package/dist/server/types/index.js.map +1 -0
  178. package/dist/types/index.d.ts +6 -372
  179. package/dist/types/index.d.ts.map +1 -1
  180. package/dist/types/index.js +9 -3
  181. package/dist/types/index.js.map +1 -1
  182. package/docs/AI_ASSISTANT_SETUP.md +68 -0
  183. package/docs/PUBLISHING.md +162 -0
  184. package/docs/README.md +37 -0
  185. package/docs/SETUP_GUIDE.md +91 -5
  186. package/docs/ai-guide/COMMANDS.md +369 -0
  187. package/docs/ai-guide/INTEGRATION.md +513 -0
  188. package/docs/ai-guide/OUTPUT.md +465 -0
  189. package/docs/ai-guide/PATTERNS.md +409 -0
  190. package/docs/ai-guide/PROMPTS.md +414 -0
  191. package/docs/ai-guide/QUICKSTART.md +114 -0
  192. package/docs/ai-guide/README.md +66 -0
  193. package/docs/archive/AI_INTEGRATION_GUIDE_ARCHIVED.md +7 -1
  194. package/docs/archive/ARCHIVE.md +39 -0
  195. package/docs/archive/MYCLAUDE_GUIDE.md +305 -0
  196. package/docs/archive/PUBLISH_NPM_DESIGN_V1.md +6 -0
  197. package/docs/archive/PUBLISH_NPM_DESIGN_V2.md +6 -0
  198. package/docs/archive/README.md +29 -0
  199. package/docs/archive/TASK_DESIGN_COVERAGE_REPORT.md +6 -0
  200. package/docs/archive/TEST_SUMMARY.md +140 -0
  201. package/docs/archive/comprehensive_test_report.md +337 -0
  202. package/docs/{CI_GATEWAY_DESIGN.md → archive/design-docs/CI_GATEWAY_DESIGN.md} +6 -0
  203. package/docs/{PUBLISH_NPM_DESIGN_FINAL.md → archive/design-docs/PUBLISH_NPM_DESIGN_FINAL.md} +7 -1
  204. package/docs/{REFACTOR_ARCHITECTURE_OVERVIEW.md → archive/design-docs/REFACTOR_ARCHITECTURE_OVERVIEW.md} +8 -2
  205. package/docs/{REFACTOR_CONFIDENCE_DESIGN.md → archive/design-docs/REFACTOR_CONFIDENCE_DESIGN.md} +6 -0
  206. package/docs/{REFACTOR_GIT_ANALYZER_DESIGN.md → archive/design-docs/REFACTOR_GIT_ANALYZER_DESIGN.md} +8 -2
  207. package/docs/{REFACTOR_ORCHESTRATOR_DESIGN.md → archive/design-docs/REFACTOR_ORCHESTRATOR_DESIGN.md} +6 -0
  208. package/docs/{REFACTOR_RESULT_FUSION_DESIGN.md → archive/design-docs/REFACTOR_RESULT_FUSION_DESIGN.md} +6 -0
  209. package/docs/{REFACTOR_TEST_LINKER_DESIGN.md → archive/design-docs/REFACTOR_TEST_LINKER_DESIGN.md} +6 -0
  210. package/docs/archive/myclaude.md +1084 -0
  211. package/docs/archive/plans/2026-03-14-go-language-support-design.md +92 -0
  212. package/docs/{REFACTOR_REQUIREMENTS.md → archive/product-specs/REFACTOR_REQUIREMENTS.md} +11 -5
  213. package/docs/archive/scenario-2-deps-analysis.md +353 -0
  214. package/docs/archive/test-report-symbol-search.md +384 -0
  215. package/docs/archive/test-scenario-4-complexity-analysis.md +460 -0
  216. package/docs/archive/test_report_scenario5.md +615 -0
  217. package/docs/archive/test_scenario_3_impact_analysis_report.md +520 -0
  218. package/docs/design-docs/README.md +26 -0
  219. package/docs/exec-plans/MVP3-IMPLEMENTATION-ROADMAP.md +524 -0
  220. package/docs/exec-plans/README.md +29 -0
  221. package/docs/exec-plans/active/.gitkeep +0 -0
  222. package/docs/exec-plans/completed/.gitkeep +0 -0
  223. package/docs/{plans/POST_TASK_PLAN.md → exec-plans/completed/2026-03-03-post-task-plan.md} +9 -3
  224. package/docs/exec-plans/completed/harness-engineering-rollout.md +184 -0
  225. package/docs/exec-plans/tech-debt/.gitkeep +0 -0
  226. package/docs/exec-plans/tech-debt/2026-03-15-lint-guardrail-gap.md +30 -0
  227. package/docs/generated/README.md +19 -0
  228. package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +504 -0
  229. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +322 -0
  230. package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +1374 -0
  231. package/docs/product-specs/README.md +22 -0
  232. package/docs/references/README.md +15 -0
  233. package/docs/references/tmp.md +527 -0
  234. package/docs/rules/README.md +16 -0
  235. package/docs/rules/architecture-guardrails.md +349 -0
  236. package/docs/rules/code-quality-redlines.md +321 -0
  237. package/docs/rules/deployment.md +23 -0
  238. package/docs/rules/engineering-with-codex-openai.md +202 -0
  239. package/docs/rules/testing.md +73 -0
  240. package/docs/rules/validation.md +39 -0
  241. package/package.json +19 -6
  242. package/docs/OMC_TEAM_DEBUG_REPORT.md +0 -285
  243. /package/docs/{plans/archive → exec-plans/completed}/2026-03-03-deps-path-extension-fix.md +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,84 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.2.0] - 2026-03-17 - MVP3 Architecture Release
6
+
7
+ ### 🏗️ MVP3 分层架构重构
8
+
9
+ CodeMap 完成重大架构升级,采用清晰的分层架构设计:Interface → Infrastructure → Domain → Server → CLI
10
+
11
+ #### Interface Layer
12
+ - 核心类型定义中心 (`src/interface/types/`)
13
+ - 存储接口契约 (`IStorage`, `IStorageFactory`)
14
+ - 解析器接口契约 (`ILanguageParser`, `IParserRegistry`)
15
+
16
+ #### Infrastructure Layer
17
+ - **存储抽象**: 支持多种存储后端
18
+ - `FileSystemStorage` - 文件系统存储(默认)
19
+ - `MemoryStorage` - 内存存储(测试用)
20
+ - `KuzuDBStorage` - KùzuDB 图数据库(可选)
21
+ - `Neo4jStorage` - Neo4j 图数据库(可选)
22
+ - `StorageFactory` - 自动选择存储后端
23
+ - **解析器抽象**: 多语言支持架构
24
+ - `ParserBase` - 解析器抽象基类
25
+ - `ParserRegistry` - 解析器注册表
26
+ - `TypeScriptParser` - TypeScript/JavaScript 解析
27
+ - `GoParser` - Go 语言解析
28
+ - `PythonParser` - Python 解析
29
+ - **仓库实现**: `CodeGraphRepositoryImpl` 连接 Domain 和 Infrastructure
30
+
31
+ #### Domain Layer
32
+ - 领域实体: `Project`, `Module`, `Symbol`, `Dependency`
33
+ - 聚合根: `CodeGraph`
34
+ - 领域服务: `CodeGraphBuilder`
35
+ - 领域事件: `DomainEvent` 及其子类
36
+ - 仓库接口: `CodeGraphRepository`
37
+
38
+ #### Server Layer
39
+ - HTTP API 服务器 (`CodeMapServer`)
40
+ - RESTful 端点设计
41
+ - `QueryHandler` - 查询处理
42
+ - `AnalysisHandler` - 分析处理
43
+ - 支持 CORS、健康检查、错误处理
44
+
45
+ #### CLI Layer (MVP3 集成)
46
+ - 新增 `server` 命令 - 启动 HTTP API 服务器
47
+ - 新增 `export` 命令 - 导出代码图到多种格式
48
+
49
+ ### Added
50
+
51
+ #### New CLI Commands
52
+ - `mycodemap server` - 启动 HTTP API 服务器 (`-p`, `--host`, `--cors`, `--open`)
53
+ - `mycodemap export` - 导出代码图 (`json`, `graphml`, `dot`, `mermaid`)
54
+
55
+ #### HTTP API Endpoints
56
+ - `GET /api/v1/health` - 健康检查
57
+ - `GET /api/v1/stats` - 项目统计
58
+ - `GET /api/v1/search/symbols?q=` - 符号搜索
59
+ - `GET /api/v1/modules/:id` - 模块详情
60
+ - `GET /api/v1/symbols/:id` - 符号详情
61
+ - `POST /api/v1/analysis/impact` - 影响分析
62
+ - `GET /api/v1/analysis/cycles` - 循环依赖检测
63
+ - `GET /api/v1/graph` - 依赖图数据
64
+ - `GET /api/v1/export/:format` - 数据导出
65
+
66
+ #### Dependencies
67
+ - `hono` - 轻量级 HTTP 框架
68
+ - `@hono/node-server` - Node.js 服务器适配器
69
+
70
+ ### Test Coverage
71
+ - 新增 37 个单元测试,总计 **742 个测试全部通过**
72
+ - Domain 实体测试 (Project, Module)
73
+ - Parser 测试 (ParserRegistry, TypeScriptParser)
74
+ - Repository 测试 (CodeGraphRepositoryImpl)
75
+
76
+ ---
77
+
78
+ ## [0.1.2] - 2026-03-20
79
+
80
+ ### Changed
81
+ - 文档同步更新:CLI 命令列表、MVP3 架构描述、代码示例全面刷新
82
+
5
83
  ## [0.1.1] - 2026-03-07
6
84
 
7
85
  ### Added
package/README.md CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  > TypeScript 代码地图工具 - 为 AI 辅助开发提供结构化上下文
4
4
 
5
- CodeMap 是一个专为 TypeScript/JavaScript 项目设计的代码分析工具。它通过静态分析自动生成项目的结构化代码地图,帮助 AI 编程助手(如 Claude、Copilot)快速理解项目架构、模块关系和代码上下文。
5
+ CodeMap 是一个专为 TypeScript/JavaScript/Go 项目设计的代码分析工具。它通过静态分析自动生成项目的结构化代码地图,帮助 AI 编程助手(如 Claude、Copilot)快速理解项目架构、模块关系和代码上下文。
6
6
 
7
7
  ## 特性
8
8
 
9
+ - **分层架构 (MVP3)** - 清晰的分层设计:Interface → Infrastructure → Domain → Server → CLI
9
10
  - **双层解析模式** - 提供 `fast`(快速正则)和 `smart`(TypeScript AST)两种解析模式,按需平衡速度与精度
11
+ - **多语言支持** - 支持 TypeScript/JavaScript、Go、Python(可扩展架构)
12
+ - **HTTP API 服务器** - 内置 REST API 服务器,支持查询、分析、导出
10
13
  - **多格式输出** - 自动生成 `AI_MAP.md`(全局概览)、`CONTEXT.md` + `context/`(模块上下文)、`codemap.json`(结构化数据)
11
14
  - **依赖图可视化** - 生成 Mermaid 格式的模块依赖关系图
12
15
  - **增量缓存** - 基于文件哈希的 LRU 缓存机制,仅重新分析变更文件
@@ -17,6 +20,7 @@ CodeMap 是一个专为 TypeScript/JavaScript 项目设计的代码分析工具
17
20
  - **工作流编排** - v2.5 新增:6 阶段智能工作流 (reference → impact → risk → implementation → commit → ci)
18
21
  - **CI 门禁** - v2.5 新增:提交格式检查、风险评估、输出契约验证
19
22
  - **插件系统** - 可扩展的插件架构,支持自定义分析和输出
23
+ - **存储抽象** - 支持文件系统、内存、KùzuDB、Neo4j 多种存储后端
20
24
 
21
25
  ## 安装
22
26
 
@@ -36,6 +40,10 @@ npm install -g @mycodemap/mycodemap
36
40
 
37
41
  **环境要求**: Node.js >= 18.0.0
38
42
 
43
+ **MVP3 新依赖**:
44
+ - `hono` - HTTP 服务器框架
45
+ - `@hono/node-server` - Node.js 适配器
46
+
39
47
  ## 快速开始
40
48
 
41
49
  ```bash
@@ -58,12 +66,36 @@ ls .mycodemap/
58
66
 
59
67
  ## 文档导航
60
68
 
69
+ ### 人类用户
70
+
61
71
  | 文档 | 目标读者 | 内容 |
62
72
  |------|----------|------|
73
+ | [🧭 文档索引](docs/README.md) | 所有读者 | 文档分层、阅读顺序与迁移状态 |
74
+ | [🏗️ 架构总图](ARCHITECTURE.md) | 开发者 | 系统地图、模块边界、主执行流 |
75
+ | [📋 MVP3 实施路线图](docs/exec-plans/MVP3-IMPLEMENTATION-ROADMAP.md) | 开发者 | 分层架构重构完整计划与状态 |
63
76
  | [📖 安装配置指南](docs/SETUP_GUIDE.md) | 人类开发者 | 完整的安装、配置和使用指南 |
64
- | [🤖 AI 助手集成指南](docs/AI_ASSISTANT_SETUP.md) | AI 用户 | Kimi/Claude/Codex/Copilot 配置指引 |
65
77
  | [📁 配置示例](examples/) | 所有用户 | 各平台的现成配置文件 |
66
78
 
79
+ ### 🤖 AI / Agent 专属文档
80
+
81
+ > 如果你是 AI 助手或 Agent,**请优先阅读以下文档**:
82
+
83
+ | 文档 | 说明 |
84
+ |------|------|
85
+ | **[📘 AI_GUIDE.md](AI_GUIDE.md)** | **AI 主指南** - 快速参考、命令选择决策树、提示词模板速用 |
86
+ | **[🚀 docs/ai-guide/QUICKSTART.md](docs/ai-guide/QUICKSTART.md)** | 快速开始、场景-命令映射表 |
87
+ | **[📚 docs/ai-guide/COMMANDS.md](docs/ai-guide/COMMANDS.md)** | 完整 CLI 命令参考 |
88
+ | **[📊 docs/ai-guide/OUTPUT.md](docs/ai-guide/OUTPUT.md)** | JSON 输出结构解析 |
89
+ | **[🔄 docs/ai-guide/PATTERNS.md](docs/ai-guide/PATTERNS.md)** | 标准工作流模式 |
90
+ | **[💬 docs/ai-guide/PROMPTS.md](docs/ai-guide/PROMPTS.md)** | 即用型提示词模板 |
91
+ | **[🔧 docs/ai-guide/INTEGRATION.md](docs/ai-guide/INTEGRATION.md)** | 集成指南、错误处理 |
92
+ | **[🛡️ AGENTS.md](AGENTS.md)** | 仓库级强约束、任务分级、代码红线 |
93
+ | **[⚡ CLAUDE.md](CLAUDE.md)** | AI 执行手册、验收清单 |
94
+ | **[🤖 docs/AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md)** | AI 助手配置指引 |
95
+ | **[🛠️ docs/rules/engineering-with-codex-openai.md](docs/rules/engineering-with-codex-openai.md) | 面向 agent 的工程约束 |
96
+
97
+ **AI 快速入口**: `.cursorrules` | `.github/copilot-instructions.md`
98
+
67
99
  ## CLI 命令
68
100
 
69
101
  ### `mycodemap init`
@@ -150,7 +182,7 @@ mycodemap query -S "plugin" -l 5 # 限制结果数量
150
182
  | `-m, --module <path>` | 查询模块信息 | - |
151
183
  | `-d, --deps <name>` | 查询依赖关系 | - |
152
184
  | `-S, --search <word>` | 模糊搜索 | - |
153
- | `-l, --limit <number>` | 限制结果数量 | `20` |
185
+ | `-l, --limit <number>` | 限制结果数量 | `50` |
154
186
  | `-j, --json` | 以 JSON 格式输出 | - |
155
187
 
156
188
  ### `mycodemap deps`
@@ -256,6 +288,48 @@ mycodemap logs clear -d 30 --confirm # 清理 30 天前的日志
256
288
  | `--format <format>` | 导出格式 (`json`/`txt`) | `json` |
257
289
  | `-c, --confirm` | 确认清理操作 | - |
258
290
 
291
+ ### `mycodemap server` (MVP3)
292
+
293
+ 启动 CodeMap HTTP API 服务器。
294
+
295
+ ```bash
296
+ mycodemap server # 启动服务器 (默认端口 3000)
297
+ mycodemap server -p 8080 # 指定端口
298
+ mycodemap server -p 3000 --open # 自动打开浏览器
299
+ mycodemap server --cors # 启用 CORS
300
+ ```
301
+
302
+ | 选项 | 说明 | 默认值 |
303
+ |------|------|--------|
304
+ | `-p, --port <number>` | 服务器端口 | `3000` |
305
+ | `-h, --host <string>` | 服务器主机 | `0.0.0.0` |
306
+ | `--cors` | 启用 CORS | `false` |
307
+ | `--open` | 自动打开浏览器 | `false` |
308
+
309
+ **API 端点:**
310
+ - `GET /api/v1/health` - 健康检查
311
+ - `GET /api/v1/stats` - 项目统计
312
+ - `GET /api/v1/search/symbols?q=` - 符号搜索
313
+ - `GET /api/v1/modules/:id` - 模块详情
314
+ - `POST /api/v1/analysis/impact` - 影响分析
315
+ - `GET /api/v1/export/:format` - 导出数据
316
+
317
+ ### `mycodemap export` (MVP3)
318
+
319
+ 导出代码图到各种格式。
320
+
321
+ ```bash
322
+ mycodemap export json # 导出为 JSON
323
+ mycodemap export graphml # 导出为 GraphML (Gephi 兼容)
324
+ mycodemap export dot # 导出为 DOT (Graphviz)
325
+ mycodemap export mermaid # 导出为 Mermaid 语法
326
+ mycodemap export json -o ./out # 指定输出路径
327
+ ```
328
+
329
+ | 选项 | 说明 | 默认值 |
330
+ |------|------|--------|
331
+ | `-o, --output <path>` | 输出文件路径 | 自动根据格式生成 |
332
+
259
333
  ## 工作流编排 (v2.5)
260
334
 
261
335
  CodeMap v2.5 引入智能工作流编排系统,将复杂任务分解为 6 个有序阶段,每个阶段自动分析并传递上下文。
@@ -375,6 +449,12 @@ Current phase: reference
375
449
  CodeMap 提供 CI 阶段自动检查,确保代码质量。
376
450
 
377
451
  ```bash
452
+ # 检查 README / docs / CLI 示例是否与仓库事实同步
453
+ npm run docs:check
454
+
455
+ # 通过统一 CLI 护栏入口复用同一检查
456
+ mycodemap ci check-docs-sync
457
+
378
458
  # 检查提交格式 ([TAG] scope: message)
379
459
  mycodemap ci check-commits
380
460
 
@@ -460,67 +540,87 @@ mycodemap ci check-output-contract
460
540
 
461
541
  独立的 Mermaid 依赖关系图文件,可在支持 Mermaid 的 Markdown 渲染器中直接预览。
462
542
 
463
- ## 项目架构
543
+ ## MVP3 分层架构
544
+
545
+ CodeMap 采用清晰的分层架构设计(MVP3),各层职责明确:
546
+
547
+ ```
548
+ ┌─────────────────────────────────────────────────────────────┐
549
+ │ CLI Layer │
550
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
551
+ │ │ server │ │ export │ │ 原有命令(generate..)│ │
552
+ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │
553
+ ├─────────────────────────────────────────────────────────────┤
554
+ │ Server Layer │
555
+ │ HTTP API / QueryHandler / AnalysisHandler │
556
+ ├─────────────────────────────────────────────────────────────┤
557
+ │ Domain Layer │
558
+ │ Project / Module / Symbol / Dependency / CodeGraph │
559
+ ├─────────────────────────────────────────────────────────────┤
560
+ │ Infrastructure Layer │
561
+ │ ┌──────────────────┐ ┌──────────────────┐ │
562
+ │ │ Storage │ │ Parser │ │
563
+ │ │ - FileSystem │ │ - TypeScript │ │
564
+ │ │ - Memory │ │ - Go │ │
565
+ │ │ - KùzuDB │ │ - Python │ │
566
+ │ │ - Neo4j │ │ - Registry │ │
567
+ │ └──────────────────┘ └──────────────────┘ │
568
+ │ ┌──────────────────┐ │
569
+ │ │ Repository │ CodeGraphRepositoryImpl │
570
+ │ └──────────────────┘ │
571
+ ├─────────────────────────────────────────────────────────────┤
572
+ │ Interface Layer │
573
+ │ 类型定义与契约 (Types, ILanguageParser, IStorage) │
574
+ └─────────────────────────────────────────────────────────────┘
575
+ ```
576
+
577
+ ### 架构层说明
578
+
579
+ | 层级 | 路径 | 职责 | 关键组件 |
580
+ |------|------|------|----------|
581
+ | **CLI** | `src/cli/` | 命令行接口 | `server`, `export`, `generate` 命令 |
582
+ | **Server** | `src/server/` | HTTP API | `CodeMapServer`, `QueryHandler` |
583
+ | **Domain** | `src/domain/` | 核心业务逻辑 | `Project`, `Module`, `CodeGraph` |
584
+ | **Infrastructure** | `src/infrastructure/` | 技术实现 | `Storage`, `Parser`, `Repository` |
585
+ | **Interface** | `src/interface/` | 类型契约 | `types/`, `config/` |
586
+
587
+ ### 项目目录结构
464
588
 
465
589
  ```
466
590
  src/
467
- ├── cli/ # CLI 命令入口
468
- │ ├── index.ts # Commander 命令注册
469
- └── commands/ # 各子命令实现
470
- ├── analyze.ts # 统一分析入口(支持多意图路由)
471
- ├── impact.ts # 影响范围分析
472
- ├── deps.ts # 依赖分析
473
- ├── complexity.ts # 复杂度分析
474
- ├── workflow.ts # 工作流编排命令
475
- │ └── ci.ts # CI 门禁命令
476
- ├── core/ # 核心分析引擎
477
- └── analyzer.ts # 主分析器
478
- ├── parser/ # 解析器层
479
- ├── interfaces/ # 解析器接口定义 (IParser)
480
- └── implementations/
481
- ├── fast-parser.ts # 快速正则解析器
482
- └── smart-parser.ts # TypeScript AST 解析器
483
- ├── orchestrator/ # 编排层(v2.5 新增)
484
- ├── index.ts # 统一导出
485
- │ ├── types.ts # UnifiedResult 类型定义
486
- │ ├── confidence.ts # 置信度计算
487
- ├── result-fusion.ts # 结果融合
488
- │ ├── tool-orchestrator.ts # 工具编排器
489
- │ ├── intent-router.ts # 意图路由
490
- │ ├── test-linker.ts # 测试关联器
491
- ├── git-analyzer.ts # Git 分析器
492
- ├── ai-feed-generator.ts # AI 饲料生成器
493
- ├── file-header-scanner.ts # 文件头扫描器
494
- │ ├── commit-validator.ts # 提交验证器
495
- ├── adapters/ # 工具适配器
496
- │ │ ├── base-adapter.ts # 适配器基类
497
- │ │ ├── codemap-adapter.ts # CodeMap 适配器
498
- │ │ └── ast-grep-adapter.ts # AstGrep 适配器
499
- └── workflow/ # 工作流模块
500
- │ ├── workflow-orchestrator.ts # 工作流编排器
501
- │ ├── workflow-persistence.ts # 工作流持久化
502
- │ ├── phase-checkpoint.ts # 阶段检查点
503
- │ └── config.ts # 工作流配置
504
- ├── generator/ # 输出生成器
505
- │ ├── index.ts # AI_MAP / JSON / Mermaid 生成
506
- │ └── context.ts # CONTEXT.md 生成
507
- ├── cache/ # 缓存系统
508
- │ ├── lru-cache.ts # LRU 缓存实现
509
- │ ├── parse-cache.ts # 解析结果缓存
510
- │ └── file-hash-cache.ts # 文件哈希缓存
511
- ├── watcher/ # 文件监听
512
- │ ├── file-watcher.ts # 文件变更监听
513
- │ ├── daemon.ts # 守护进程管理
514
- │ └── watch-worker.ts # 监听工作线程
515
- ├── plugins/ # 插件系统
516
- │ ├── types.ts # 插件接口定义
517
- │ ├── plugin-registry.ts # 插件注册中心
518
- │ ├── plugin-loader.ts # 插件加载器
519
- │ └── built-in/ # 内置插件
520
- │ ├── complexity-analyzer.ts # 复杂度分析
521
- │ └── call-graph.ts # 调用图分析
522
- └── types/ # 类型定义
523
- └── index.ts # 核心类型
591
+ ├── cli/ # CLI 命令入口 (原有 + MVP3 新增)
592
+ │ ├── commands/
593
+ │ ├── server.ts # MVP3: HTTP API 服务器
594
+ ├── export.ts # MVP3: 导出命令
595
+ ├── generate.ts # 生成代码地图
596
+ ├── query.ts # 查询命令
597
+ │ └── ... # 其他命令
598
+ └── index.ts
599
+ ├── server/ # MVP3: HTTP API 服务器层
600
+ ├── CodeMapServer.ts # 主服务器类
601
+ ├── handlers/ # QueryHandler, AnalysisHandler
602
+ │ └── routes/ # API 路由
603
+ ├── domain/ # MVP3: 领域层
604
+ ├── entities/ # Project, Module, Symbol, Dependency
605
+ ├── services/ # CodeGraphBuilder
606
+ ├── events/ # DomainEvent
607
+ │ └── repositories/ # 仓库接口
608
+ ├── infrastructure/ # MVP3: 基础设施层
609
+ │ ├── storage/ # 存储适配器
610
+ ├── adapters/ # FileSystem, Memory, KùzuDB, Neo4j
611
+ │ └── StorageFactory.ts
612
+ │ ├── parser/ # 解析器
613
+ ├── interfaces/ # ParserBase
614
+ ├── implementations/# TypeScript, Go, Python
615
+ │ └── registry/ # ParserRegistry
616
+ └── repositories/ # 仓库实现
617
+ ├── interface/ # MVP3: 接口层
618
+ │ ├── types/ # 核心类型定义
619
+ └── config/ # 配置类型
620
+ ├── core/ # 核心分析引擎 (原有)
621
+ ├── parser/ # 原有解析器 (逐步迁移到 infrastructure/parser)
622
+ ├── orchestrator/ # 编排层 (v2.5)
623
+ └── ...
524
624
  ```
525
625
 
526
626
  ## AI 助手集成
@@ -550,21 +650,91 @@ mkdir -p .agents/skills/codemap
550
650
  cp examples/codex/codemap-agent.md .agents/skills/codemap/SKILL.md
551
651
  ```
552
652
 
553
- 详细配置请参考 [AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md)。
653
+ 详细配置请参考 [AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md),设计与规则入口请先看 [docs/README.md](docs/README.md)
554
654
 
555
655
  ## 新增 CLI 命令
556
656
 
557
657
  ### `mycodemap analyze`
558
658
 
559
- 统一分析入口,支持多意图路由:
659
+ 统一分析入口,支持多意图路由和结构化输出:
660
+
661
+ ```bash
662
+ # 影响分析(查看文件变更影响范围)
663
+ mycodemap analyze -i impact -t src/cli/index.ts
664
+ mycodemap analyze -i impact -t src/cli/index.ts --scope transitive
665
+ mycodemap analyze -i impact -t src/cli/index.ts --include-tests
666
+
667
+ # 依赖分析
668
+ mycodemap analyze -i dependency -t src/cli/index.ts
669
+
670
+ # 项目概览
671
+ mycodemap analyze -i overview -t src/orchestrator
672
+
673
+ # 复杂度分析
674
+ mycodemap analyze -i complexity -t src/domain
675
+
676
+ # 搜索分析
677
+ mycodemap analyze -i search -k UnifiedResult
678
+
679
+ # 重构建议
680
+ mycodemap analyze -i refactor -t src/cache
681
+
682
+ # 引用查找
683
+ mycodemap analyze -i reference -t src/interface/types
684
+
685
+ # 文档生成
686
+ mycodemap analyze -i documentation -t src/domain/services
687
+
688
+ # 机器可读输出(JSON)
689
+ mycodemap analyze -i impact -t src/index.ts --json
690
+ mycodemap analyze -i impact -t src/index.ts --structured --json
691
+ ```
692
+
693
+ | 选项 | 说明 | 默认值 |
694
+ |------|------|--------|
695
+ | `-i, --intent <type>` | 分析类型:`impact`/`dependency`/`search`/`documentation`/`complexity`/`overview`/`refactor`/`reference` | `impact` |
696
+ | `-t, --targets <paths...>` | 目标文件/模块路径(必填) | - |
697
+ | `-k, --keywords <words...>` | 搜索关键词(用于 search/documentation 意图) | - |
698
+ | `-s, --scope <scope>` | 范围:`direct`(直接)/`transitive`(传递) | `direct` |
699
+ | `-n, --topK <number>` | 返回结果数量 | `8` |
700
+ | `--include-tests` | 包含测试文件关联 | - |
701
+ | `--include-git-history` | 包含 Git 历史分析 | - |
702
+ | `--json` | JSON 格式输出 | - |
703
+ | `--structured` | 纯结构化输出(移除自然语言字段,配合 `--json` 使用) | - |
704
+ | `--output-mode <mode>` | 输出模式:`machine`/`human` | `human` |
705
+
706
+ ### `mycodemap ci`
707
+
708
+ CI Gateway - 代码质量门禁工具:
560
709
 
561
710
  ```bash
562
- mycodemap analyze "分析 tool-orchestrator 的影响范围"
563
- mycodemap analyze --intent impact --file src/cli/index.ts
564
- mycodemap analyze --intent dependency --file src/cli/index.ts
565
- mycodemap analyze --intent search "UnifiedResult"
711
+ # 验证提交格式([TAG] scope: message)
712
+ mycodemap ci check-commits
713
+ mycodemap ci check-commits -c 5
714
+ mycodemap ci check-commits -r origin/main..HEAD
715
+
716
+ # 验证文件头注释([META], [WHY])
717
+ mycodemap ci check-headers
718
+ mycodemap ci check-headers -d src/domain
719
+ mycodemap ci check-headers -f "src/index.ts,src/cli/index.ts"
720
+
721
+ # 评估变更风险
722
+ mycodemap ci assess-risk
723
+ mycodemap ci assess-risk -t 0.5
724
+
725
+ # 验证文档同步
726
+ mycodemap ci check-docs-sync
727
+
728
+ # 验证输出契约
729
+ mycodemap ci check-output-contract
730
+
731
+ # 检查提交文件数量(限制 10 个文件)
732
+ mycodemap ci check-commit-size
733
+ mycodemap ci check-commit-size -m 15
566
734
  ```
567
735
 
736
+ 支持的提交 TAG 类型:`[REFACTOR]`, `[TEST]`, `[DOCS]`, `[FEAT]`, `[FIX]`, `[CHORE]`, `[PERF]`, `[SECURITY]`, `[BREAKING]`, `[HOTFIX]`, `[MIGRATION]`, `[WIP]`
737
+
568
738
  ## 贡献指南
569
739
 
570
740
  欢迎提交 Issue 和 Pull Request!
@@ -590,6 +760,10 @@ npm test # 功能测试(src/**/*.test.ts)
590
760
  npm run benchmark # 性能基准测试(refer/benchmark-quality.test.ts)
591
761
  npm run test:all # 功能 + 基准(串联执行)
592
762
 
763
+ # 文档 / CLI 示例护栏
764
+ npm run docs:check
765
+ node dist/cli/index.js ci check-docs-sync
766
+
593
767
  # 类型检查
594
768
  npm run typecheck
595
769
 
@@ -11,12 +11,18 @@ export declare enum CIErrorCode {
11
11
  E0008_MISSING_HEADER = "E0008",
12
12
  E0009_MISSING_WHY = "E0009",
13
13
  E0010_OUTPUT_CONTRACT_VIOLATION = "E0010",
14
- E0011_COMMIT_TOO_LARGE = "E0011"
14
+ E0011_COMMIT_TOO_LARGE = "E0011",
15
+ E0012_DOCS_GUARDRAIL_FAILED = "E0012"
15
16
  }
16
17
  /**
17
18
  * CI 命令错误信息
18
19
  */
19
20
  export declare const CI_ERROR_MESSAGES: Record<CIErrorCode, string>;
21
+ export declare function resolveDocsGuardrailScriptPath(projectRoot?: string): string;
22
+ export declare function runDocsGuardrailCheck(options?: {
23
+ root?: string;
24
+ projectRoot?: string;
25
+ }): void;
20
26
  /**
21
27
  * 创建 CI Gateway 命令
22
28
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/ci.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC;;GAEG;AACH,oBAAY,WAAW;IACrB,2BAA2B,UAAU;IACrC,oBAAoB,UAAU;IAC9B,iBAAiB,UAAU;IAC3B,+BAA+B,UAAU;IACzC,sBAAsB,UAAU;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMzD,CAAC;AA2dF;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CA0CzC;AAED,eAAO,MAAM,SAAS,SAAoB,CAAC"}
1
+ {"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/ci.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC;;GAEG;AACH,oBAAY,WAAW;IACrB,2BAA2B,UAAU;IACrC,oBAAoB,UAAU;IAC9B,iBAAiB,UAAU;IAC3B,+BAA+B,UAAU;IACzC,sBAAsB,UAAU;IAChC,2BAA2B,UAAU;CACtC;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAOzD,CAAC;AAcF,wBAAgB,8BAA8B,CAAC,WAAW,GAAE,MAAsB,GAAG,MAAM,CAE1F;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,IAAI,CAiBjG;AAydD;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAgDzC;AAED,eAAO,MAAM,SAAS,SAAoB,CAAC"}
@@ -2,6 +2,9 @@
2
2
  * [META] CI Gateway CLI 命令
3
3
  * [WHY] 提供 CI 门禁相关的子命令
4
4
  */
5
+ import { execFileSync } from 'node:child_process';
6
+ import { existsSync } from 'node:fs';
7
+ import path from 'node:path';
5
8
  import { Command } from 'commander';
6
9
  import { validateCommitMessage, validateRecentCommits, VALID_TAGS } from '../../orchestrator/commit-validator.js';
7
10
  import { scanDirectory, scanFileHeader } from '../../orchestrator/file-header-scanner.js';
@@ -17,6 +20,7 @@ export var CIErrorCode;
17
20
  CIErrorCode["E0009_MISSING_WHY"] = "E0009";
18
21
  CIErrorCode["E0010_OUTPUT_CONTRACT_VIOLATION"] = "E0010";
19
22
  CIErrorCode["E0011_COMMIT_TOO_LARGE"] = "E0011";
23
+ CIErrorCode["E0012_DOCS_GUARDRAIL_FAILED"] = "E0012";
20
24
  })(CIErrorCode || (CIErrorCode = {}));
21
25
  /**
22
26
  * CI 命令错误信息
@@ -27,6 +31,7 @@ export const CI_ERROR_MESSAGES = {
27
31
  [CIErrorCode.E0009_MISSING_WHY]: '文件头缺少 [WHY] 注释',
28
32
  [CIErrorCode.E0010_OUTPUT_CONTRACT_VIOLATION]: '输出契约校验失败',
29
33
  [CIErrorCode.E0011_COMMIT_TOO_LARGE]: 'Commit 包含文件数量超过限制',
34
+ [CIErrorCode.E0012_DOCS_GUARDRAIL_FAILED]: '文档护栏校验失败',
30
35
  };
31
36
  /**
32
37
  * 单 commit 文件数量限制
@@ -38,6 +43,24 @@ function parseGitDiffFiles(command) {
38
43
  .map((line) => line.trim())
39
44
  .filter(Boolean);
40
45
  }
46
+ export function resolveDocsGuardrailScriptPath(projectRoot = process.cwd()) {
47
+ return path.join(projectRoot, 'scripts', 'validate-docs.js');
48
+ }
49
+ export function runDocsGuardrailCheck(options = {}) {
50
+ const projectRoot = options.projectRoot ?? process.cwd();
51
+ const scriptPath = resolveDocsGuardrailScriptPath(projectRoot);
52
+ if (!existsSync(scriptPath)) {
53
+ throw new Error(`Documentation guardrail script not found: ${scriptPath}`);
54
+ }
55
+ const args = [scriptPath];
56
+ if (options.root) {
57
+ args.push('--root', options.root);
58
+ }
59
+ execFileSync(process.execPath, args, {
60
+ cwd: projectRoot,
61
+ stdio: 'inherit',
62
+ });
63
+ }
41
64
  async function getChangedFiles(options) {
42
65
  if (options.files) {
43
66
  return options.files
@@ -81,6 +104,16 @@ async function getChangedFiles(options) {
81
104
  process.exit(1);
82
105
  }
83
106
  }
107
+ async function checkDocsSyncAction(options) {
108
+ try {
109
+ runDocsGuardrailCheck({ root: options.root });
110
+ }
111
+ catch (error) {
112
+ const message = error instanceof Error ? error.message : String(error);
113
+ console.error(`ERROR: [${CIErrorCode.E0012_DOCS_GUARDRAIL_FAILED}] ${message}`);
114
+ process.exit(1);
115
+ }
116
+ }
84
117
  /**
85
118
  * check-commits 子命令 - 验证 Commit 格式
86
119
  */
@@ -462,6 +495,11 @@ export function createCICommand() {
462
495
  .option('-f, --files <files>', '逗号分隔的变更文件列表')
463
496
  .option('-t, --threshold <number>', '风险阈值 (0-1)', '0.7')
464
497
  .action(assessRiskAction);
498
+ ci
499
+ .command('check-docs-sync')
500
+ .description('验证当前仓库高信号文档、CLI 示例与护栏配置是否保持同步')
501
+ .option('--root <path>', '指定要校验的仓库根目录')
502
+ .action(checkDocsSyncAction);
465
503
  ci
466
504
  .command('check-output-contract')
467
505
  .description('验证 analyze 命令的输出契约')