@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,409 @@
1
+ # AI Guide - 使用模式与最佳实践
2
+
3
+ > 标准工作流模式和输出处理最佳实践
4
+
5
+ ---
6
+
7
+ ## 标准工作流模式
8
+
9
+ ### 模式 A: 首次接触项目
10
+
11
+ **适用场景**: 初次了解一个 CodeMap 项目
12
+
13
+ **执行步骤**:
14
+
15
+ ```bash
16
+ # Step 1: 生成代码地图
17
+ node dist/cli/index.js generate
18
+
19
+ # Step 2: 读取项目概览
20
+ read_file(".mycodemap/AI_MAP.md")
21
+
22
+ # Step 3: 分析项目结构
23
+ # - 查看入口点列表
24
+ # - 了解模块组织
25
+ # - 识别核心功能
26
+
27
+ # Step 4: 如果需要深入特定模块
28
+ node dist/cli/index.js query -m "src/core" -j
29
+
30
+ # Step 5: 获取依赖关系
31
+ node dist/cli/index.js deps -m "src" -j
32
+ ```
33
+
34
+ **输出内容**:
35
+ - 项目基本信息(文件数、代码行数、模块数)
36
+ - 入口点列表
37
+ - 模块组织表
38
+ - Mermaid 依赖图
39
+ - 关键类型和导出
40
+
41
+ ---
42
+
43
+ ### 模式 B: 实现新功能
44
+
45
+ **适用场景**: 在项目中添加新功能
46
+
47
+ **执行步骤**:
48
+
49
+ ```bash
50
+ # Step 1: 搜索相关代码
51
+ node dist/cli/index.js analyze -i search -k "相关关键词" --json
52
+
53
+ # Step 2: 分析影响范围(如果有修改现有代码)
54
+ node dist/cli/index.js analyze -i impact -t "目标文件" --include-tests --json
55
+
56
+ # Step 3: 检查复杂度(选择最佳实现位置)
57
+ node dist/cli/index.js analyze -i complexity -t "候选目录" --json
58
+
59
+ # Step 4: 实现代码
60
+ # - 遵循文件头规范
61
+ # - 添加 [META] 和 [WHY] 注释
62
+
63
+ # Step 5: 验证文件头
64
+ node dist/cli/index.js ci check-headers -f "新文件.ts"
65
+
66
+ # Step 6: 运行测试
67
+ npm test
68
+ ```
69
+
70
+ **决策要点**:
71
+ - 选择复杂度低的模块作为实现点
72
+ - 避免影响范围过大的文件
73
+ - 确保有对应的测试文件
74
+
75
+ ---
76
+
77
+ ### 模式 C: 重构代码
78
+
79
+ **适用场景**: 改善代码结构而不改变外部行为
80
+
81
+ **执行步骤**:
82
+
83
+ ```bash
84
+ # Step 1: 检测现有循环依赖
85
+ node dist/cli/index.js cycles -j
86
+
87
+ # Step 2: 分析目标模块复杂度
88
+ node dist/cli/index.js analyze -i complexity -t "目标模块" --json
89
+
90
+ # Step 3: 评估影响范围
91
+ node dist/cli/index.js analyze -i impact -t "目标文件" --scope transitive --json
92
+
93
+ # Step 4: 获取重构建议
94
+ node dist/cli/index.js analyze -i refactor -t "目标模块" --json
95
+
96
+ # Step 5: 执行重构
97
+
98
+ # Step 6: 验证无新增循环依赖
99
+ node dist/cli/index.js cycles -j
100
+
101
+ # Step 7: 验证复杂度降低
102
+ node dist/cli/index.js analyze -i complexity -t "目标模块" --json
103
+
104
+ # Step 8: 运行测试
105
+ npm test
106
+ ```
107
+
108
+ **注意事项**:
109
+ - 确保有充分的测试覆盖
110
+ - 小步提交,每个重构步骤一个 commit
111
+ - 使用 `[REFACTOR]` 标签提交
112
+
113
+ ---
114
+
115
+ ### 模式 D: 修复 Bug
116
+
117
+ **适用场景**: 定位和修复代码缺陷
118
+
119
+ **执行步骤**:
120
+
121
+ ```bash
122
+ # Step 1: 定位问题代码
123
+ node dist/cli/index.js query -s "Bug相关类名" -j
124
+
125
+ # Step 2: 分析影响范围
126
+ node dist/cli/index.js impact -f "问题文件" --transitive -j
127
+
128
+ # Step 3: 查找相关测试
129
+ node dist/cli/index.js query -s "相关测试" --include-references -j
130
+
131
+ # Step 4: 搜索相似代码(防止同类问题)
132
+ node dist/cli/index.js analyze -i search -k "问题模式" --json
133
+
134
+ # Step 5: 修复 Bug
135
+
136
+ # Step 6: 运行测试
137
+ npm test
138
+
139
+ # Step 7: 使用 [FIX] 标签提交
140
+ # [FIX] module: 修复 XXX 问题
141
+ ```
142
+
143
+ ---
144
+
145
+ ### 模式 E: 代码审查
146
+
147
+ **适用场景**: 审查代码变更
148
+
149
+ **执行步骤**:
150
+
151
+ ```bash
152
+ # Step 1: 检查提交格式
153
+ node dist/cli/index.js ci check-commits
154
+
155
+ # Step 2: 检查文件头
156
+ node dist/cli/index.js ci check-headers
157
+
158
+ # Step 3: 评估变更风险
159
+ node dist/cli/index.js ci assess-risk
160
+
161
+ # Step 4: 检查输出契约(如果修改了 analyze)
162
+ node dist/cli/index.js ci check-output-contract
163
+
164
+ # Step 5: 检查文档同步
165
+ node dist/cli/index.js ci check-docs-sync
166
+
167
+ # Step 6: 运行测试
168
+ npm test
169
+ ```
170
+
171
+ ---
172
+
173
+ ### 模式 F: 复杂任务管理
174
+
175
+ **适用场景**: 需要多步骤完成的复杂开发任务
176
+
177
+ **执行步骤**:
178
+
179
+ ```bash
180
+ # Step 1: 启动工作流
181
+ node dist/cli/index.js workflow start "实现用户认证模块"
182
+
183
+ # Step 2: 查看当前阶段建议
184
+ node dist/cli/index.js workflow status
185
+
186
+ # Step 3: 执行当前阶段的分析和实现
187
+
188
+ # Step 4: 完成阶段后推进
189
+ node dist/cli/index.js workflow proceed
190
+
191
+ # Step 5: 可视化进度
192
+ node dist/cli/index.js workflow visualize
193
+
194
+ # Step 6: 创建检查点(重要里程碑)
195
+ node dist/cli/index.js workflow checkpoint
196
+
197
+ # Step 7: 重复直到完成
198
+ ```
199
+
200
+ **工作流阶段**:
201
+ 1. `reference` - 参考搜索
202
+ 2. `impact` - 影响分析
203
+ 3. `risk` - 风险评估
204
+ 4. `implementation` - 代码实现
205
+ 5. `commit` - 提交验证
206
+ 6. `ci` - CI 验证
207
+
208
+ ---
209
+
210
+ ## 输出处理模式
211
+
212
+ ### 模式 1: 提取文件列表
213
+
214
+ ```typescript
215
+ function extractFilesFromAnalyze(output: string): string[] {
216
+ const data = JSON.parse(output);
217
+ const files = data.results
218
+ .map((r: any) => r.location?.file || r.file)
219
+ .filter(Boolean);
220
+ return [...new Set(files)]; // 去重
221
+ }
222
+
223
+ // 使用示例
224
+ const files = extractFilesFromAnalyze(analyzeOutput);
225
+ console.log(`将影响 ${files.length} 个文件`);
226
+ ```
227
+
228
+ ---
229
+
230
+ ### 模式 2: 提取测试文件
231
+
232
+ ```typescript
233
+ function extractTestFiles(output: string): string[] {
234
+ const data = JSON.parse(output);
235
+ const testFiles = data.results
236
+ .filter((r: any) => r.metadata?.testFile)
237
+ .map((r: any) => r.metadata.testFile)
238
+ .filter(Boolean);
239
+ return [...new Set(testFiles)];
240
+ }
241
+
242
+ // 使用示例
243
+ const tests = extractTestFiles(impactOutput);
244
+ console.log(`需要检查 ${tests.length} 个测试文件`);
245
+ ```
246
+
247
+ ---
248
+
249
+ ### 模式 3: 检查置信度
250
+
251
+ ```typescript
252
+ function checkConfidence(output: string): { ok: boolean; reason?: string } {
253
+ const data = JSON.parse(output);
254
+ const { level, score } = data.confidence || {};
255
+
256
+ if (level === 'high' && score >= 0.7) {
257
+ return { ok: true };
258
+ }
259
+
260
+ if (level === 'medium') {
261
+ return {
262
+ ok: false,
263
+ reason: `中等置信度 (${score}),建议人工复核`
264
+ };
265
+ }
266
+
267
+ return {
268
+ ok: false,
269
+ reason: `置信度过低 (${score}),建议扩大搜索范围`
270
+ };
271
+ }
272
+
273
+ // 使用示例
274
+ const check = checkConfidence(analyzeOutput);
275
+ if (!check.ok) {
276
+ console.warn(check.reason);
277
+ }
278
+ ```
279
+
280
+ ---
281
+
282
+ ### 模式 4: 按相关度过滤
283
+
284
+ ```typescript
285
+ function filterByRelevance(
286
+ output: string,
287
+ threshold: number = 0.5
288
+ ): any[] {
289
+ const data = JSON.parse(output);
290
+ return data.results.filter((r: any) => r.relevance >= threshold);
291
+ }
292
+
293
+ // 使用示例
294
+ const highRelevance = filterByRelevance(analyzeOutput, 0.7);
295
+ console.log(`高度相关结果: ${highRelevance.length} 个`);
296
+ ```
297
+
298
+ ---
299
+
300
+ ### 模式 5: 按目录分组
301
+
302
+ ```typescript
303
+ function groupByDirectory(output: string): Record<string, number> {
304
+ const data = JSON.parse(output);
305
+ const groups: Record<string, number> = {};
306
+
307
+ for (const result of data.results) {
308
+ const parts = result.file.split('/');
309
+ const dir = parts.slice(0, -1).join('/') || 'root';
310
+ groups[dir] = (groups[dir] || 0) + 1;
311
+ }
312
+
313
+ return groups;
314
+ }
315
+
316
+ // 使用示例
317
+ const groups = groupByDirectory(analyzeOutput);
318
+ // { 'src/cli': 5, 'src/core': 3, ... }
319
+ ```
320
+
321
+ ---
322
+
323
+ ### 模式 6: 排序和分页
324
+
325
+ ```typescript
326
+ function sortAndPaginate(
327
+ output: string,
328
+ sortBy: 'relevance' | 'file' = 'relevance',
329
+ page: number = 1,
330
+ pageSize: number = 10
331
+ ): any[] {
332
+ const data = JSON.parse(output);
333
+ let results = [...data.results];
334
+
335
+ // 排序
336
+ if (sortBy === 'relevance') {
337
+ results.sort((a, b) => b.relevance - a.relevance);
338
+ } else {
339
+ results.sort((a, b) => a.file.localeCompare(b.file));
340
+ }
341
+
342
+ // 分页
343
+ const start = (page - 1) * pageSize;
344
+ return results.slice(start, start + pageSize);
345
+ }
346
+ ```
347
+
348
+ ---
349
+
350
+ ## 性能优化模式
351
+
352
+ ### 缓存利用
353
+
354
+ ```typescript
355
+ // 默认开启缓存,60秒 TTL
356
+ // 如果需要强制刷新
357
+ deleteCacheForProject(projectRoot);
358
+ ```
359
+
360
+ ### 批量查询
361
+
362
+ ```typescript
363
+ // 不好的做法:多次查询
364
+ for (const file of files) {
365
+ await exec(`mycodemap impact -f ${file}`); // 每次都要加载索引
366
+ }
367
+
368
+ // 好的做法:一次生成,多次查询
369
+ await exec('mycodemap generate');
370
+ // 后续 query 命令会利用缓存
371
+ ```
372
+
373
+ ---
374
+
375
+ ## 安全模式
376
+
377
+ ### 边界检查
378
+
379
+ ```typescript
380
+ function safeParseOutput(output: string): any | null {
381
+ try {
382
+ return JSON.parse(output);
383
+ } catch {
384
+ return null;
385
+ }
386
+ }
387
+
388
+ function safeExtractFiles(output: string): string[] {
389
+ const data = safeParseOutput(output);
390
+ if (!data || !Array.isArray(data.results)) {
391
+ return [];
392
+ }
393
+ return data.results.map((r: any) => r.file).filter(Boolean);
394
+ }
395
+ ```
396
+
397
+ ---
398
+
399
+ ## 最佳实践总结
400
+
401
+ | 实践 | 说明 |
402
+ |------|------|
403
+ | 先生成后查询 | 首次使用必须先运行 `generate` |
404
+ | 优先使用 JSON | 需要解析结果时使用 `--json` |
405
+ | 检查置信度 | 低置信度结果需要人工复核 |
406
+ | 过滤后再处理 | 使用 `--topK` 或 relevance 过滤减少数据量 |
407
+ | 利用缓存 | 多次查询时缓存会自动生效 |
408
+ | 渐进式分析 | 先 overview → 再 specific |
409
+ | 验证后提交 | 使用 `ci` 命令验证后再提交 |