@mycodemap/mycodemap 0.1.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 (329) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +559 -0
  4. package/dist/ai/claude.d.ts +38 -0
  5. package/dist/ai/claude.d.ts.map +1 -0
  6. package/dist/ai/claude.js +169 -0
  7. package/dist/ai/claude.js.map +1 -0
  8. package/dist/ai/codex.d.ts +38 -0
  9. package/dist/ai/codex.d.ts.map +1 -0
  10. package/dist/ai/codex.js +169 -0
  11. package/dist/ai/codex.js.map +1 -0
  12. package/dist/ai/factory.d.ts +48 -0
  13. package/dist/ai/factory.d.ts.map +1 -0
  14. package/dist/ai/factory.js +95 -0
  15. package/dist/ai/factory.js.map +1 -0
  16. package/dist/ai/index.d.ts +12 -0
  17. package/dist/ai/index.d.ts.map +1 -0
  18. package/dist/ai/index.js +29 -0
  19. package/dist/ai/index.js.map +1 -0
  20. package/dist/ai/provider.d.ts +70 -0
  21. package/dist/ai/provider.d.ts.map +1 -0
  22. package/dist/ai/provider.js +31 -0
  23. package/dist/ai/provider.js.map +1 -0
  24. package/dist/ai/subagent-caller.d.ts +90 -0
  25. package/dist/ai/subagent-caller.d.ts.map +1 -0
  26. package/dist/ai/subagent-caller.js +280 -0
  27. package/dist/ai/subagent-caller.js.map +1 -0
  28. package/dist/ai/types.d.ts +70 -0
  29. package/dist/ai/types.d.ts.map +1 -0
  30. package/dist/ai/types.js +5 -0
  31. package/dist/ai/types.js.map +1 -0
  32. package/dist/cache/file-hash-cache.d.ts +76 -0
  33. package/dist/cache/file-hash-cache.d.ts.map +1 -0
  34. package/dist/cache/file-hash-cache.js +159 -0
  35. package/dist/cache/file-hash-cache.js.map +1 -0
  36. package/dist/cache/index.d.ts +151 -0
  37. package/dist/cache/index.d.ts.map +1 -0
  38. package/dist/cache/index.js +303 -0
  39. package/dist/cache/index.js.map +1 -0
  40. package/dist/cache/lru-cache.d.ts +93 -0
  41. package/dist/cache/lru-cache.d.ts.map +1 -0
  42. package/dist/cache/lru-cache.js +194 -0
  43. package/dist/cache/lru-cache.js.map +1 -0
  44. package/dist/cache/parse-cache.d.ts +68 -0
  45. package/dist/cache/parse-cache.d.ts.map +1 -0
  46. package/dist/cache/parse-cache.js +173 -0
  47. package/dist/cache/parse-cache.js.map +1 -0
  48. package/dist/cli/commands/analyze.d.ts +96 -0
  49. package/dist/cli/commands/analyze.d.ts.map +1 -0
  50. package/dist/cli/commands/analyze.js +567 -0
  51. package/dist/cli/commands/analyze.js.map +1 -0
  52. package/dist/cli/commands/ci.d.ts +25 -0
  53. package/dist/cli/commands/ci.d.ts.map +1 -0
  54. package/dist/cli/commands/ci.js +481 -0
  55. package/dist/cli/commands/ci.js.map +1 -0
  56. package/dist/cli/commands/complexity.d.ts +70 -0
  57. package/dist/cli/commands/complexity.d.ts.map +1 -0
  58. package/dist/cli/commands/complexity.js +479 -0
  59. package/dist/cli/commands/complexity.js.map +1 -0
  60. package/dist/cli/commands/cycles.d.ts +10 -0
  61. package/dist/cli/commands/cycles.d.ts.map +1 -0
  62. package/dist/cli/commands/cycles.js +202 -0
  63. package/dist/cli/commands/cycles.js.map +1 -0
  64. package/dist/cli/commands/deps.d.ts +61 -0
  65. package/dist/cli/commands/deps.d.ts.map +1 -0
  66. package/dist/cli/commands/deps.js +340 -0
  67. package/dist/cli/commands/deps.js.map +1 -0
  68. package/dist/cli/commands/generate.d.ts +8 -0
  69. package/dist/cli/commands/generate.d.ts.map +1 -0
  70. package/dist/cli/commands/generate.js +61 -0
  71. package/dist/cli/commands/generate.js.map +1 -0
  72. package/dist/cli/commands/impact.d.ts +55 -0
  73. package/dist/cli/commands/impact.d.ts.map +1 -0
  74. package/dist/cli/commands/impact.js +455 -0
  75. package/dist/cli/commands/impact.js.map +1 -0
  76. package/dist/cli/commands/init.d.ts +4 -0
  77. package/dist/cli/commands/init.d.ts.map +1 -0
  78. package/dist/cli/commands/init.js +50 -0
  79. package/dist/cli/commands/init.js.map +1 -0
  80. package/dist/cli/commands/query.d.ts +22 -0
  81. package/dist/cli/commands/query.d.ts.map +1 -0
  82. package/dist/cli/commands/query.js +718 -0
  83. package/dist/cli/commands/query.js.map +1 -0
  84. package/dist/cli/commands/watch-foreground.d.ts +9 -0
  85. package/dist/cli/commands/watch-foreground.d.ts.map +1 -0
  86. package/dist/cli/commands/watch-foreground.js +67 -0
  87. package/dist/cli/commands/watch-foreground.js.map +1 -0
  88. package/dist/cli/commands/watch.d.ts +12 -0
  89. package/dist/cli/commands/watch.d.ts.map +1 -0
  90. package/dist/cli/commands/watch.js +114 -0
  91. package/dist/cli/commands/watch.js.map +1 -0
  92. package/dist/cli/commands/workflow.d.ts +25 -0
  93. package/dist/cli/commands/workflow.d.ts.map +1 -0
  94. package/dist/cli/commands/workflow.js +488 -0
  95. package/dist/cli/commands/workflow.js.map +1 -0
  96. package/dist/cli/index.d.ts +3 -0
  97. package/dist/cli/index.d.ts.map +1 -0
  98. package/dist/cli/index.js +115 -0
  99. package/dist/cli/index.js.map +1 -0
  100. package/dist/cli/paths.d.ts +90 -0
  101. package/dist/cli/paths.d.ts.map +1 -0
  102. package/dist/cli/paths.js +136 -0
  103. package/dist/cli/paths.js.map +1 -0
  104. package/dist/cli/runtime-logger.d.ts +13 -0
  105. package/dist/cli/runtime-logger.d.ts.map +1 -0
  106. package/dist/cli/runtime-logger.js +213 -0
  107. package/dist/cli/runtime-logger.js.map +1 -0
  108. package/dist/core/analyzer.d.ts +3 -0
  109. package/dist/core/analyzer.d.ts.map +1 -0
  110. package/dist/core/analyzer.js +359 -0
  111. package/dist/core/analyzer.js.map +1 -0
  112. package/dist/core/ast-complexity-analyzer.d.ts +40 -0
  113. package/dist/core/ast-complexity-analyzer.d.ts.map +1 -0
  114. package/dist/core/ast-complexity-analyzer.js +279 -0
  115. package/dist/core/ast-complexity-analyzer.js.map +1 -0
  116. package/dist/core/global-index.d.ts +69 -0
  117. package/dist/core/global-index.d.ts.map +1 -0
  118. package/dist/core/global-index.js +388 -0
  119. package/dist/core/global-index.js.map +1 -0
  120. package/dist/generator/ai-overview.d.ts +51 -0
  121. package/dist/generator/ai-overview.d.ts.map +1 -0
  122. package/dist/generator/ai-overview.js +160 -0
  123. package/dist/generator/ai-overview.js.map +1 -0
  124. package/dist/generator/context.d.ts +5 -0
  125. package/dist/generator/context.d.ts.map +1 -0
  126. package/dist/generator/context.js +514 -0
  127. package/dist/generator/context.js.map +1 -0
  128. package/dist/generator/file-describer.d.ts +93 -0
  129. package/dist/generator/file-describer.d.ts.map +1 -0
  130. package/dist/generator/file-describer.js +375 -0
  131. package/dist/generator/file-describer.js.map +1 -0
  132. package/dist/generator/index.d.ts +8 -0
  133. package/dist/generator/index.d.ts.map +1 -0
  134. package/dist/generator/index.js +259 -0
  135. package/dist/generator/index.js.map +1 -0
  136. package/dist/index.d.ts +5 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +6 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts +75 -0
  141. package/dist/orchestrator/adapters/ast-grep-adapter.d.ts.map +1 -0
  142. package/dist/orchestrator/adapters/ast-grep-adapter.js +242 -0
  143. package/dist/orchestrator/adapters/ast-grep-adapter.js.map +1 -0
  144. package/dist/orchestrator/adapters/base-adapter.d.ts +24 -0
  145. package/dist/orchestrator/adapters/base-adapter.d.ts.map +1 -0
  146. package/dist/orchestrator/adapters/base-adapter.js +2 -0
  147. package/dist/orchestrator/adapters/base-adapter.js.map +1 -0
  148. package/dist/orchestrator/adapters/codemap-adapter.d.ts +56 -0
  149. package/dist/orchestrator/adapters/codemap-adapter.d.ts.map +1 -0
  150. package/dist/orchestrator/adapters/codemap-adapter.js +163 -0
  151. package/dist/orchestrator/adapters/codemap-adapter.js.map +1 -0
  152. package/dist/orchestrator/adapters/index.d.ts +10 -0
  153. package/dist/orchestrator/adapters/index.d.ts.map +1 -0
  154. package/dist/orchestrator/adapters/index.js +3 -0
  155. package/dist/orchestrator/adapters/index.js.map +1 -0
  156. package/dist/orchestrator/ai-feed-generator.d.ts +210 -0
  157. package/dist/orchestrator/ai-feed-generator.d.ts.map +1 -0
  158. package/dist/orchestrator/ai-feed-generator.js +377 -0
  159. package/dist/orchestrator/ai-feed-generator.js.map +1 -0
  160. package/dist/orchestrator/commit-validator.d.ts +30 -0
  161. package/dist/orchestrator/commit-validator.d.ts.map +1 -0
  162. package/dist/orchestrator/commit-validator.js +87 -0
  163. package/dist/orchestrator/commit-validator.js.map +1 -0
  164. package/dist/orchestrator/confidence.d.ts +25 -0
  165. package/dist/orchestrator/confidence.d.ts.map +1 -0
  166. package/dist/orchestrator/confidence.js +138 -0
  167. package/dist/orchestrator/confidence.js.map +1 -0
  168. package/dist/orchestrator/file-header-scanner.d.ts +48 -0
  169. package/dist/orchestrator/file-header-scanner.d.ts.map +1 -0
  170. package/dist/orchestrator/file-header-scanner.js +158 -0
  171. package/dist/orchestrator/file-header-scanner.js.map +1 -0
  172. package/dist/orchestrator/git-analyzer.d.ts +192 -0
  173. package/dist/orchestrator/git-analyzer.d.ts.map +1 -0
  174. package/dist/orchestrator/git-analyzer.js +539 -0
  175. package/dist/orchestrator/git-analyzer.js.map +1 -0
  176. package/dist/orchestrator/index.d.ts +20 -0
  177. package/dist/orchestrator/index.d.ts.map +1 -0
  178. package/dist/orchestrator/index.js +16 -0
  179. package/dist/orchestrator/index.js.map +1 -0
  180. package/dist/orchestrator/intent-router.d.ts +41 -0
  181. package/dist/orchestrator/intent-router.d.ts.map +1 -0
  182. package/dist/orchestrator/intent-router.js +98 -0
  183. package/dist/orchestrator/intent-router.js.map +1 -0
  184. package/dist/orchestrator/result-fusion.d.ts +114 -0
  185. package/dist/orchestrator/result-fusion.d.ts.map +1 -0
  186. package/dist/orchestrator/result-fusion.js +332 -0
  187. package/dist/orchestrator/result-fusion.js.map +1 -0
  188. package/dist/orchestrator/test-linker.d.ts +166 -0
  189. package/dist/orchestrator/test-linker.d.ts.map +1 -0
  190. package/dist/orchestrator/test-linker.js +570 -0
  191. package/dist/orchestrator/test-linker.js.map +1 -0
  192. package/dist/orchestrator/tool-orchestrator.d.ts +108 -0
  193. package/dist/orchestrator/tool-orchestrator.d.ts.map +1 -0
  194. package/dist/orchestrator/tool-orchestrator.js +247 -0
  195. package/dist/orchestrator/tool-orchestrator.js.map +1 -0
  196. package/dist/orchestrator/types.d.ts +162 -0
  197. package/dist/orchestrator/types.d.ts.map +1 -0
  198. package/dist/orchestrator/types.js +39 -0
  199. package/dist/orchestrator/types.js.map +1 -0
  200. package/dist/orchestrator/workflow/ci-executor.d.ts +157 -0
  201. package/dist/orchestrator/workflow/ci-executor.d.ts.map +1 -0
  202. package/dist/orchestrator/workflow/ci-executor.js +423 -0
  203. package/dist/orchestrator/workflow/ci-executor.js.map +1 -0
  204. package/dist/orchestrator/workflow/config.d.ts +97 -0
  205. package/dist/orchestrator/workflow/config.d.ts.map +1 -0
  206. package/dist/orchestrator/workflow/config.js +115 -0
  207. package/dist/orchestrator/workflow/config.js.map +1 -0
  208. package/dist/orchestrator/workflow/git-analyzer.d.ts +173 -0
  209. package/dist/orchestrator/workflow/git-analyzer.d.ts.map +1 -0
  210. package/dist/orchestrator/workflow/git-analyzer.js +473 -0
  211. package/dist/orchestrator/workflow/git-analyzer.js.map +1 -0
  212. package/dist/orchestrator/workflow/index.d.ts +21 -0
  213. package/dist/orchestrator/workflow/index.d.ts.map +1 -0
  214. package/dist/orchestrator/workflow/index.js +21 -0
  215. package/dist/orchestrator/workflow/index.js.map +1 -0
  216. package/dist/orchestrator/workflow/phase-checkpoint.d.ts +38 -0
  217. package/dist/orchestrator/workflow/phase-checkpoint.d.ts.map +1 -0
  218. package/dist/orchestrator/workflow/phase-checkpoint.js +75 -0
  219. package/dist/orchestrator/workflow/phase-checkpoint.js.map +1 -0
  220. package/dist/orchestrator/workflow/phase-inheritance.d.ts +128 -0
  221. package/dist/orchestrator/workflow/phase-inheritance.d.ts.map +1 -0
  222. package/dist/orchestrator/workflow/phase-inheritance.js +266 -0
  223. package/dist/orchestrator/workflow/phase-inheritance.js.map +1 -0
  224. package/dist/orchestrator/workflow/result-fusion.d.ts +117 -0
  225. package/dist/orchestrator/workflow/result-fusion.d.ts.map +1 -0
  226. package/dist/orchestrator/workflow/result-fusion.js +246 -0
  227. package/dist/orchestrator/workflow/result-fusion.js.map +1 -0
  228. package/dist/orchestrator/workflow/templates.d.ts +116 -0
  229. package/dist/orchestrator/workflow/templates.d.ts.map +1 -0
  230. package/dist/orchestrator/workflow/templates.js +546 -0
  231. package/dist/orchestrator/workflow/templates.js.map +1 -0
  232. package/dist/orchestrator/workflow/test-linker.d.ts +152 -0
  233. package/dist/orchestrator/workflow/test-linker.d.ts.map +1 -0
  234. package/dist/orchestrator/workflow/test-linker.js +342 -0
  235. package/dist/orchestrator/workflow/test-linker.js.map +1 -0
  236. package/dist/orchestrator/workflow/types.d.ts +202 -0
  237. package/dist/orchestrator/workflow/types.d.ts.map +1 -0
  238. package/dist/orchestrator/workflow/types.js +4 -0
  239. package/dist/orchestrator/workflow/types.js.map +1 -0
  240. package/dist/orchestrator/workflow/visualizer.d.ts +56 -0
  241. package/dist/orchestrator/workflow/visualizer.d.ts.map +1 -0
  242. package/dist/orchestrator/workflow/visualizer.js +300 -0
  243. package/dist/orchestrator/workflow/visualizer.js.map +1 -0
  244. package/dist/orchestrator/workflow/workflow-context.d.ts +50 -0
  245. package/dist/orchestrator/workflow/workflow-context.d.ts.map +1 -0
  246. package/dist/orchestrator/workflow/workflow-context.js +105 -0
  247. package/dist/orchestrator/workflow/workflow-context.js.map +1 -0
  248. package/dist/orchestrator/workflow/workflow-orchestrator.d.ts +126 -0
  249. package/dist/orchestrator/workflow/workflow-orchestrator.d.ts.map +1 -0
  250. package/dist/orchestrator/workflow/workflow-orchestrator.js +489 -0
  251. package/dist/orchestrator/workflow/workflow-orchestrator.js.map +1 -0
  252. package/dist/orchestrator/workflow/workflow-persistence.d.ts +38 -0
  253. package/dist/orchestrator/workflow/workflow-persistence.d.ts.map +1 -0
  254. package/dist/orchestrator/workflow/workflow-persistence.js +166 -0
  255. package/dist/orchestrator/workflow/workflow-persistence.js.map +1 -0
  256. package/dist/parser/implementations/fast-parser.d.ts +65 -0
  257. package/dist/parser/implementations/fast-parser.d.ts.map +1 -0
  258. package/dist/parser/implementations/fast-parser.js +299 -0
  259. package/dist/parser/implementations/fast-parser.js.map +1 -0
  260. package/dist/parser/implementations/smart-parser.d.ts +220 -0
  261. package/dist/parser/implementations/smart-parser.d.ts.map +1 -0
  262. package/dist/parser/implementations/smart-parser.js +1536 -0
  263. package/dist/parser/implementations/smart-parser.js.map +1 -0
  264. package/dist/parser/implementations/tree-sitter-parser.d.ts +57 -0
  265. package/dist/parser/implementations/tree-sitter-parser.d.ts.map +1 -0
  266. package/dist/parser/implementations/tree-sitter-parser.js +375 -0
  267. package/dist/parser/implementations/tree-sitter-parser.js.map +1 -0
  268. package/dist/parser/index.d.ts +19 -0
  269. package/dist/parser/index.d.ts.map +1 -0
  270. package/dist/parser/index.js +449 -0
  271. package/dist/parser/index.js.map +1 -0
  272. package/dist/parser/interfaces/IParser.d.ts +218 -0
  273. package/dist/parser/interfaces/IParser.d.ts.map +1 -0
  274. package/dist/parser/interfaces/IParser.js +22 -0
  275. package/dist/parser/interfaces/IParser.js.map +1 -0
  276. package/dist/plugins/built-in/call-graph.d.ts +38 -0
  277. package/dist/plugins/built-in/call-graph.d.ts.map +1 -0
  278. package/dist/plugins/built-in/call-graph.js +135 -0
  279. package/dist/plugins/built-in/call-graph.js.map +1 -0
  280. package/dist/plugins/built-in/complexity-analyzer.d.ts +45 -0
  281. package/dist/plugins/built-in/complexity-analyzer.d.ts.map +1 -0
  282. package/dist/plugins/built-in/complexity-analyzer.js +155 -0
  283. package/dist/plugins/built-in/complexity-analyzer.js.map +1 -0
  284. package/dist/plugins/index.d.ts +34 -0
  285. package/dist/plugins/index.d.ts.map +1 -0
  286. package/dist/plugins/index.js +103 -0
  287. package/dist/plugins/index.js.map +1 -0
  288. package/dist/plugins/plugin-loader.d.ts +22 -0
  289. package/dist/plugins/plugin-loader.d.ts.map +1 -0
  290. package/dist/plugins/plugin-loader.js +200 -0
  291. package/dist/plugins/plugin-loader.js.map +1 -0
  292. package/dist/plugins/plugin-registry.d.ts +20 -0
  293. package/dist/plugins/plugin-registry.d.ts.map +1 -0
  294. package/dist/plugins/plugin-registry.js +143 -0
  295. package/dist/plugins/plugin-registry.js.map +1 -0
  296. package/dist/plugins/types.d.ts +72 -0
  297. package/dist/plugins/types.d.ts.map +1 -0
  298. package/dist/plugins/types.js +5 -0
  299. package/dist/plugins/types.js.map +1 -0
  300. package/dist/types/index.d.ts +373 -0
  301. package/dist/types/index.d.ts.map +1 -0
  302. package/dist/types/index.js +7 -0
  303. package/dist/types/index.js.map +1 -0
  304. package/dist/watcher/daemon.d.ts +64 -0
  305. package/dist/watcher/daemon.d.ts.map +1 -0
  306. package/dist/watcher/daemon.js +189 -0
  307. package/dist/watcher/daemon.js.map +1 -0
  308. package/dist/watcher/file-watcher.d.ts +70 -0
  309. package/dist/watcher/file-watcher.d.ts.map +1 -0
  310. package/dist/watcher/file-watcher.js +127 -0
  311. package/dist/watcher/file-watcher.js.map +1 -0
  312. package/dist/watcher/index.d.ts +5 -0
  313. package/dist/watcher/index.d.ts.map +1 -0
  314. package/dist/watcher/index.js +6 -0
  315. package/dist/watcher/index.js.map +1 -0
  316. package/dist/watcher/watch-worker.d.ts +2 -0
  317. package/dist/watcher/watch-worker.d.ts.map +1 -0
  318. package/dist/watcher/watch-worker.js +57 -0
  319. package/dist/watcher/watch-worker.js.map +1 -0
  320. package/dist/worker/index.d.ts +76 -0
  321. package/dist/worker/index.d.ts.map +1 -0
  322. package/dist/worker/index.js +155 -0
  323. package/dist/worker/index.js.map +1 -0
  324. package/dist/worker/parse-worker.d.ts +2 -0
  325. package/dist/worker/parse-worker.d.ts.map +1 -0
  326. package/dist/worker/parse-worker.js +202 -0
  327. package/dist/worker/parse-worker.js.map +1 -0
  328. package/mycodemap.config.schema.json +42 -0
  329. package/package.json +69 -0
@@ -0,0 +1,375 @@
1
+ // ============================================
2
+ // File Describer - 使用 Claude Code CLI 为每个文件生成内容描述
3
+ // ============================================
4
+ import * as fs from 'fs/promises';
5
+ import * as path from 'path';
6
+ import { spawn } from 'child_process';
7
+ /**
8
+ * 文件描述生成器 - 使用 Claude Code CLI
9
+ */
10
+ export class FileDescriber {
11
+ config;
12
+ cache = new Map();
13
+ cacheLoaded = false;
14
+ constructor(config = {}) {
15
+ this.config = {
16
+ cliPath: config.cliPath || 'claude',
17
+ concurrency: config.concurrency || 3,
18
+ enableCache: config.enableCache ?? true,
19
+ cacheDir: config.cacheDir || '.codemap/.cache',
20
+ timeout: config.timeout || 30000,
21
+ maxDescriptionLength: config.maxDescriptionLength || 500
22
+ };
23
+ }
24
+ /**
25
+ * 检查是否应该跳过 AI 生成
26
+ */
27
+ async shouldSkipAIGeneration() {
28
+ // 检查 Claude CLI 是否可用
29
+ const isAvailable = await this.isClaudeAvailable();
30
+ if (!isAvailable) {
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+ /**
36
+ * 检查 Claude CLI 是否可用
37
+ */
38
+ async isClaudeAvailable() {
39
+ return new Promise((resolve) => {
40
+ const proc = spawn(this.config.cliPath, ['--version'], {
41
+ stdio: 'ignore'
42
+ });
43
+ proc.on('close', (code) => {
44
+ resolve(code === 0);
45
+ });
46
+ proc.on('error', () => {
47
+ resolve(false);
48
+ });
49
+ // 2 秒超时
50
+ setTimeout(() => {
51
+ proc.kill();
52
+ resolve(false);
53
+ }, 2000);
54
+ });
55
+ }
56
+ /**
57
+ * 初始化缓存
58
+ */
59
+ async initCache() {
60
+ if (!this.config.enableCache || this.cacheLoaded)
61
+ return;
62
+ try {
63
+ const cacheFile = path.join(this.config.cacheDir, 'file-descriptions.json');
64
+ const data = await fs.readFile(cacheFile, 'utf-8');
65
+ const entries = JSON.parse(data);
66
+ for (const [key, value] of Object.entries(entries)) {
67
+ this.cache.set(key, value);
68
+ }
69
+ }
70
+ catch {
71
+ // 缓存文件不存在或读取失败,忽略
72
+ }
73
+ this.cacheLoaded = true;
74
+ }
75
+ /**
76
+ * 保存缓存
77
+ */
78
+ async saveCache() {
79
+ if (!this.config.enableCache)
80
+ return;
81
+ try {
82
+ await fs.mkdir(this.config.cacheDir, { recursive: true });
83
+ const cacheFile = path.join(this.config.cacheDir, 'file-descriptions.json');
84
+ const entries = Object.fromEntries(this.cache.entries());
85
+ await fs.writeFile(cacheFile, JSON.stringify(entries, null, 2));
86
+ }
87
+ catch {
88
+ // 保存失败,忽略
89
+ }
90
+ }
91
+ /**
92
+ * 计算文件内容哈希(用于缓存)
93
+ */
94
+ async computeHash(filePath) {
95
+ try {
96
+ const content = await fs.readFile(filePath, 'utf-8');
97
+ // 简单的哈希:取内容的前 1000 字符 + 文件大小 + 修改时间
98
+ const sample = content.slice(0, 1000);
99
+ const stats = await fs.stat(filePath);
100
+ return `${content.length}-${stats.mtimeMs}-${this.simpleHash(sample)}`;
101
+ }
102
+ catch {
103
+ return Date.now().toString();
104
+ }
105
+ }
106
+ /**
107
+ * 简单字符串哈希
108
+ */
109
+ simpleHash(str) {
110
+ let hash = 0;
111
+ for (let i = 0; i < str.length; i++) {
112
+ const char = str.charCodeAt(i);
113
+ hash = ((hash << 5) - hash) + char;
114
+ hash = hash & hash;
115
+ }
116
+ return Math.abs(hash).toString(16);
117
+ }
118
+ /**
119
+ * 构建用于 Claude 的提示词
120
+ */
121
+ buildPrompt(module, allModules, rootDir) {
122
+ const relativePath = path.relative(rootDir, module.path);
123
+ // 收集依赖信息
124
+ const importedBy = allModules.filter(m => m.dependencies.some(d => relativePath.includes(d) || d.includes(relativePath))).slice(0, 5);
125
+ // 构建符号信息摘要
126
+ const symbols = module.symbols.slice(0, 15).map(s => ({
127
+ name: s.name,
128
+ kind: s.kind,
129
+ visibility: s.visibility
130
+ }));
131
+ const context = {
132
+ filePath: relativePath,
133
+ type: module.type,
134
+ exports: module.exports.slice(0, 10).map(e => e.name),
135
+ imports: module.imports.slice(0, 10).map(i => i.source),
136
+ importedBy: importedBy.map(m => path.relative(rootDir, m.path)),
137
+ symbols,
138
+ stats: module.stats
139
+ };
140
+ return `分析以下代码文件,生成简洁的描述:
141
+
142
+ 文件路径: ${relativePath}
143
+ 类型: ${module.type}
144
+ 代码行数: ${module.stats.codeLines}
145
+ 导出符号数: ${module.exports.length}
146
+ 导入模块数: ${module.imports.length}
147
+
148
+ 导出符号:
149
+ ${module.exports.slice(0, 10).map(e => `- ${e.name} (${e.kind})`).join('\n')}
150
+
151
+ 主要符号:
152
+ ${symbols.map(s => `- ${s.name} (${s.kind})`).join('\n')}
153
+
154
+ 请用 JSON 格式返回以下信息:
155
+ {
156
+ "description": "用 2-3 句话描述这个文件的主要功能和用途(中文)",
157
+ "purpose": "一句话总结文件的核心职责",
158
+ "keyFeatures": ["关键功能1", "关键功能2", "关键功能3"],
159
+ "dependenciesSummary": "简述依赖关系(被谁依赖、依赖谁)"
160
+ }
161
+
162
+ 要求:
163
+ 1. 描述要简洁、准确、专业
164
+ 2. keyFeatures 最多列出 3-5 个
165
+ 3. 返回必须是有效的 JSON 格式
166
+ 4. 描述使用中文`;
167
+ }
168
+ /**
169
+ * 调用 Claude CLI
170
+ */
171
+ async callClaude(prompt) {
172
+ return new Promise((resolve, reject) => {
173
+ const args = [
174
+ '-p',
175
+ '--output-format', 'json',
176
+ '--dangerously-skip-permissions'
177
+ ];
178
+ let stdout = '';
179
+ let stderr = '';
180
+ let killed = false;
181
+ const proc = spawn(this.config.cliPath, args, {
182
+ stdio: ['pipe', 'pipe', 'pipe']
183
+ });
184
+ // 超时处理
185
+ const timeoutId = setTimeout(() => {
186
+ killed = true;
187
+ proc.kill('SIGTERM');
188
+ reject(new Error(`Claude 执行超时(${this.config.timeout / 1000}秒)`));
189
+ }, this.config.timeout);
190
+ proc.stdout.on('data', (data) => {
191
+ stdout += data.toString();
192
+ });
193
+ proc.stderr.on('data', (data) => {
194
+ stderr += data.toString();
195
+ });
196
+ proc.on('close', (code) => {
197
+ clearTimeout(timeoutId);
198
+ if (killed)
199
+ return;
200
+ if (code !== 0 && code !== null) {
201
+ reject(new Error(`Claude CLI 错误: ${stderr || `exit code ${code}`}`));
202
+ return;
203
+ }
204
+ resolve(stdout);
205
+ });
206
+ proc.on('error', (error) => {
207
+ clearTimeout(timeoutId);
208
+ if (!killed) {
209
+ reject(new Error(`Claude CLI 执行失败: ${error.message}`));
210
+ }
211
+ });
212
+ // 发送提示词
213
+ proc.stdin.write(prompt);
214
+ proc.stdin.end();
215
+ });
216
+ }
217
+ /**
218
+ * 解析 AI 响应
219
+ */
220
+ parseAIResponse(content, filePath) {
221
+ try {
222
+ // 尝试从 Claude 的 JSON 输出中提取结果
223
+ const lines = content.trim().split('\n');
224
+ let jsonStr = '';
225
+ // 从后往前找有效的 JSON 对象
226
+ for (let i = lines.length - 1; i >= 0; i--) {
227
+ const line = lines[i].trim();
228
+ if (line.startsWith('{') && line.endsWith('}')) {
229
+ jsonStr = line;
230
+ break;
231
+ }
232
+ }
233
+ // 如果没有找到 JSON 对象,尝试匹配 JSON
234
+ if (!jsonStr) {
235
+ const jsonMatch = content.match(/\{[\s\S]*\}/);
236
+ if (jsonMatch) {
237
+ jsonStr = jsonMatch[0];
238
+ }
239
+ }
240
+ if (jsonStr) {
241
+ const parsed = JSON.parse(jsonStr);
242
+ return {
243
+ filePath,
244
+ description: parsed.description || '暂无描述',
245
+ purpose: parsed.purpose || '',
246
+ keyFeatures: parsed.keyFeatures || [],
247
+ dependenciesSummary: parsed.dependenciesSummary || '',
248
+ generatedAt: new Date().toISOString()
249
+ };
250
+ }
251
+ }
252
+ catch {
253
+ // JSON 解析失败,使用原始内容
254
+ }
255
+ // 回退:使用原始内容
256
+ return {
257
+ filePath,
258
+ description: content.slice(0, this.config.maxDescriptionLength),
259
+ purpose: '',
260
+ keyFeatures: [],
261
+ dependenciesSummary: '',
262
+ generatedAt: new Date().toISOString()
263
+ };
264
+ }
265
+ /**
266
+ * 为单个文件生成描述
267
+ */
268
+ async describeFile(module, allModules, rootDir) {
269
+ // 检查是否应该跳过
270
+ if (await this.shouldSkipAIGeneration()) {
271
+ return null;
272
+ }
273
+ await this.initCache();
274
+ const relativePath = path.relative(rootDir, module.path);
275
+ const cacheKey = relativePath;
276
+ const currentHash = await this.computeHash(module.path);
277
+ // 检查缓存
278
+ const cached = this.cache.get(cacheKey);
279
+ if (cached && cached.hash === currentHash) {
280
+ return cached.description;
281
+ }
282
+ // 生成新描述
283
+ try {
284
+ const prompt = this.buildPrompt(module, allModules, rootDir);
285
+ const stdout = await this.callClaude(prompt);
286
+ // 解析响应
287
+ const parsed = this.parseAIResponse(stdout, relativePath);
288
+ // 更新缓存
289
+ this.cache.set(cacheKey, {
290
+ hash: currentHash,
291
+ description: parsed,
292
+ createdAt: new Date().toISOString()
293
+ });
294
+ // 异步保存缓存
295
+ this.saveCache().catch(() => { });
296
+ return parsed;
297
+ }
298
+ catch (error) {
299
+ console.error(`生成文件描述失败: ${relativePath}`, error);
300
+ return null;
301
+ }
302
+ }
303
+ /**
304
+ * 批量生成文件描述(带并发控制)
305
+ */
306
+ async describeFiles(modules, allModules, rootDir, onProgress) {
307
+ // 检查 Claude CLI 是否可用
308
+ const isAvailable = await this.isClaudeAvailable();
309
+ if (!isAvailable) {
310
+ console.log('⚠️ Claude CLI 不可用,跳过 AI 文件描述生成');
311
+ return new Map();
312
+ }
313
+ const results = new Map();
314
+ // 过滤掉不需要生成描述的文件(如测试文件、配置文件)
315
+ const targetModules = modules.filter(m => m.type === 'source' &&
316
+ !m.path.includes('.test.') &&
317
+ !m.path.includes('.spec.'));
318
+ const total = targetModules.length;
319
+ let completed = 0;
320
+ // 并发控制
321
+ const semaphore = new Semaphore(this.config.concurrency);
322
+ const tasks = targetModules.map(async (module) => {
323
+ await semaphore.acquire();
324
+ try {
325
+ const description = await this.describeFile(module, allModules, rootDir);
326
+ if (description) {
327
+ const relativePath = path.relative(rootDir, module.path);
328
+ results.set(relativePath, description);
329
+ }
330
+ }
331
+ finally {
332
+ semaphore.release();
333
+ completed++;
334
+ onProgress?.(completed, total);
335
+ }
336
+ });
337
+ await Promise.all(tasks);
338
+ return results;
339
+ }
340
+ }
341
+ /**
342
+ * 并发控制信号量
343
+ */
344
+ class Semaphore {
345
+ permits;
346
+ queue = [];
347
+ constructor(permits) {
348
+ this.permits = permits;
349
+ }
350
+ async acquire() {
351
+ if (this.permits > 0) {
352
+ this.permits--;
353
+ return;
354
+ }
355
+ return new Promise(resolve => {
356
+ this.queue.push(resolve);
357
+ });
358
+ }
359
+ release() {
360
+ if (this.queue.length > 0) {
361
+ const resolve = this.queue.shift();
362
+ resolve?.();
363
+ }
364
+ else {
365
+ this.permits++;
366
+ }
367
+ }
368
+ }
369
+ /**
370
+ * 创建文件描述生成器实例
371
+ */
372
+ export function createFileDescriber(config) {
373
+ return new FileDescriber(config);
374
+ }
375
+ //# sourceMappingURL=file-describer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-describer.js","sourceRoot":"","sources":["../../src/generator/file-describer.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,kDAAkD;AAClD,+CAA+C;AAE/C,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAgDtC;;GAEG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAAgC;IACtC,KAAK,GAA4B,IAAI,GAAG,EAAE,CAAC;IAC3C,WAAW,GAAG,KAAK,CAAC;IAE5B,YAAY,SAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,QAAQ;YACnC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC;YACpC,WAAW,EAAE,MAAM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CAAC,MAA4B;IAC9D,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { CodeMap, VisualizationConfig, MermaidConfig } from '../types/index.js';
2
+ export type { FileDescription, FileDescriberConfig } from './file-describer.js';
3
+ export { createFileDescriber, FileDescriber } from './file-describer.js';
4
+ export declare function generateAIMap(codeMap: CodeMap, outputDir: string, visualizationConfig?: Partial<VisualizationConfig>): Promise<void>;
5
+ export declare function generateMermaidGraph(codeMap: CodeMap, outputDir: string, config?: Partial<MermaidConfig>): Promise<void>;
6
+ export declare function generateJSON(codeMap: CodeMap, outputDir: string): Promise<void>;
7
+ export declare function generateContext(codeMap: CodeMap, outputDir: string): Promise<void>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKrF,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAsJzE,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,mBAAmB,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GACjD,OAAO,CAAC,IAAI,CAAC,CAqGf;AAGD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC,CAef;AAGD,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAGD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExF"}
@@ -0,0 +1,259 @@
1
+ // [META] since:2024-03 | owner:core-team | stable:true
2
+ // [WHY] 代码地图生成器模块,负责将分析结果转换为各种输出格式
3
+ import fs from 'fs/promises';
4
+ import path from 'path';
5
+ import { generateAllContexts } from './context.js';
6
+ export { createFileDescriber, FileDescriber } from './file-describer.js';
7
+ // 默认可视化配置
8
+ const defaultVisualizationConfig = {
9
+ mermaid: {
10
+ graphType: 'flowchart',
11
+ direction: 'LR',
12
+ nodeShape: 'box',
13
+ showLabels: true,
14
+ maxNodes: 50,
15
+ maxEdges: 100
16
+ },
17
+ includeTestFiles: false,
18
+ includeExternalDeps: false,
19
+ showComplexity: false,
20
+ outputFormat: 'markdown'
21
+ };
22
+ // 生成 Mermaid 依赖图
23
+ function generateMermaidDependencyGraph(codeMap, config) {
24
+ const lines = [];
25
+ const graphType = config.graphType === 'mindmap' ? 'mindmap' : 'flowchart';
26
+ lines.push(`\`\`\`mermaid`);
27
+ lines.push(`${graphType} ${config.direction}`);
28
+ // 定义节点样式
29
+ lines.push(' classDef core fill:#f9f,stroke:#333,stroke-width:2px');
30
+ lines.push(' classDef feature fill:#bbf,stroke:#333,stroke-width:2px');
31
+ lines.push(' classDef utility fill:#bfb,stroke:#333,stroke-width:2px');
32
+ lines.push(' classDef external fill:#fbb,stroke:#333,stroke-width:2px');
33
+ lines.push(' classDef entry fill:#ff9,stroke:#333,stroke-width:4px');
34
+ lines.push('');
35
+ // 分类节点
36
+ const categories = {
37
+ core: [],
38
+ feature: [],
39
+ utility: [],
40
+ external: [],
41
+ entry: []
42
+ };
43
+ for (const node of codeMap.dependencies.nodes) {
44
+ if (categories[node.category]) {
45
+ const label = path.basename(node.path, '.ts');
46
+ categories[node.category].push(`${node.id}["${label}"]`);
47
+ }
48
+ }
49
+ // 添加入口点
50
+ const entryPoints = codeMap.modules.filter(m => {
51
+ const basename = path.basename(m.path);
52
+ return basename === 'index.ts' || basename === 'main.ts' || basename === 'app.ts';
53
+ });
54
+ for (const ep of entryPoints) {
55
+ categories.entry.push(`${ep.id}["${path.basename(ep.path, '.ts')}"]`);
56
+ }
57
+ // 输出节点(限制数量)
58
+ let nodeCount = 0;
59
+ for (const [category, nodes] of Object.entries(categories)) {
60
+ if (nodes.length === 0)
61
+ continue;
62
+ lines.push(` %% ${category} modules`);
63
+ for (const node of nodes.slice(0, Math.floor(config.maxNodes / 5))) {
64
+ if (nodeCount >= config.maxNodes)
65
+ break;
66
+ lines.push(` ${node}:::${category === 'entry' ? 'entry' : category}`);
67
+ nodeCount++;
68
+ }
69
+ }
70
+ lines.push('');
71
+ // 输出边(限制数量)
72
+ let edgeCount = 0;
73
+ const edgeSet = new Set();
74
+ for (const edge of codeMap.dependencies.edges) {
75
+ if (edgeCount >= config.maxEdges)
76
+ break;
77
+ const key = `${edge.from}-->${edge.to}`;
78
+ if (edgeSet.has(key))
79
+ continue;
80
+ edgeSet.add(key);
81
+ let label = '';
82
+ if (config.showLabels) {
83
+ switch (edge.type) {
84
+ case 'import':
85
+ label = 'import';
86
+ break;
87
+ case 'inherit':
88
+ label = 'extends';
89
+ break;
90
+ case 'implement':
91
+ label = 'implements';
92
+ break;
93
+ case 'call':
94
+ label = 'calls';
95
+ break;
96
+ case 'type-ref':
97
+ label = 'type';
98
+ break;
99
+ }
100
+ }
101
+ const edgeStyle = edge.type === 'inherit' || edge.type === 'implement' ? '-.->' : '-->';
102
+ if (label) {
103
+ lines.push(` ${edge.from} ${edgeStyle} ${edge.to} |${label}|`);
104
+ }
105
+ else {
106
+ lines.push(` ${edge.from} ${edgeStyle} ${edge.to}`);
107
+ }
108
+ edgeCount++;
109
+ }
110
+ lines.push('```');
111
+ return lines.join('\n');
112
+ }
113
+ // 生成类型信息摘要
114
+ function generateTypeInfoSummary(codeMap) {
115
+ const lines = [];
116
+ // 收集类型信息
117
+ const typeDefs = new Map();
118
+ const interfaces = [];
119
+ const classes = [];
120
+ const types = [];
121
+ for (const mod of codeMap.modules) {
122
+ if (mod.symbols) {
123
+ for (const sym of mod.symbols) {
124
+ const count = typeDefs.get(sym.kind) || 0;
125
+ typeDefs.set(sym.kind, count + 1);
126
+ if (sym.kind === 'interface')
127
+ interfaces.push(sym.name);
128
+ else if (sym.kind === 'class')
129
+ classes.push(sym.name);
130
+ else if (sym.kind === 'type')
131
+ types.push(sym.name);
132
+ }
133
+ }
134
+ }
135
+ if (typeDefs.size > 0) {
136
+ lines.push('### Type Summary');
137
+ lines.push('');
138
+ lines.push('| Type Kind | Count |');
139
+ lines.push('|-----------|-------|');
140
+ for (const [kind, count] of typeDefs) {
141
+ lines.push(`| ${kind} | ${count} |`);
142
+ }
143
+ lines.push('');
144
+ }
145
+ return lines.join('\n');
146
+ }
147
+ // 生成 AI_MAP.md
148
+ export async function generateAIMap(codeMap, outputDir, visualizationConfig) {
149
+ const config = { ...defaultVisualizationConfig, ...visualizationConfig };
150
+ const lines = [];
151
+ // 头部
152
+ lines.push('# AI Code Map');
153
+ lines.push('');
154
+ lines.push(`> Generated at: ${codeMap.generatedAt}`);
155
+ lines.push('');
156
+ const mode = codeMap.actualMode || 'fast';
157
+ lines.push(`> Mode: ${mode === 'smart' ? 'Smart' : 'Fast'}`);
158
+ lines.push('');
159
+ // 项目概览
160
+ lines.push('## Project Overview');
161
+ lines.push('');
162
+ lines.push(`- **Project Name**: ${codeMap.project.name}`);
163
+ lines.push(`- **Total Files**: ${codeMap.summary.totalFiles}`);
164
+ lines.push(`- **Total Lines**: ${codeMap.summary.totalLines}`);
165
+ lines.push(`- **Total Modules**: ${codeMap.summary.totalModules}`);
166
+ lines.push(`- **Total Exports**: ${codeMap.summary.totalExports}`);
167
+ lines.push(`- **Total Types**: ${codeMap.summary.totalTypes}`);
168
+ lines.push('');
169
+ // 入口点
170
+ const entryPoints = codeMap.modules.filter(m => {
171
+ const basename = path.basename(m.path);
172
+ return basename === 'index.ts' || basename === 'main.ts' || basename === 'app.ts';
173
+ });
174
+ if (entryPoints.length > 0) {
175
+ lines.push('## Entry Points');
176
+ lines.push('');
177
+ for (const ep of entryPoints) {
178
+ lines.push(`- \`${path.relative(codeMap.project.rootDir, ep.path)}\``);
179
+ }
180
+ lines.push('');
181
+ }
182
+ // 模块组织
183
+ lines.push('## Module Organization');
184
+ lines.push('');
185
+ lines.push('| Module | Exports | Dependencies | Type |');
186
+ lines.push('|--------|---------|--------------|------|');
187
+ const displayModules = config.includeTestFiles
188
+ ? codeMap.modules
189
+ : codeMap.modules.filter(m => m.type !== 'test');
190
+ for (const mod of displayModules.slice(0, 50)) {
191
+ const relPath = path.relative(codeMap.project.rootDir, mod.path);
192
+ lines.push(`| ${relPath} | ${mod.exports.length} | ${mod.dependencies.length} | ${mod.type} |`);
193
+ }
194
+ if (displayModules.length > 50) {
195
+ lines.push(`| ... | ... | ... | ... |`);
196
+ }
197
+ lines.push('');
198
+ // 依赖关系 - 使用增强的 Mermaid 图
199
+ lines.push('## Dependencies');
200
+ lines.push('');
201
+ lines.push(generateMermaidDependencyGraph(codeMap, config.mermaid));
202
+ lines.push('');
203
+ // 类型信息摘要
204
+ lines.push(generateTypeInfoSummary(codeMap));
205
+ // 导出符号统计
206
+ lines.push('## Exports Summary');
207
+ lines.push('');
208
+ const exportCounts = new Map();
209
+ for (const mod of codeMap.modules) {
210
+ for (const exp of mod.exports) {
211
+ exportCounts.set(exp.name, (exportCounts.get(exp.name) || 0) + 1);
212
+ }
213
+ }
214
+ // 列出被多个模块导出的符号
215
+ const multiExport = Array.from(exportCounts.entries())
216
+ .filter(([_, count]) => count > 1)
217
+ .sort((a, b) => b[1] - a[1])
218
+ .slice(0, 10);
219
+ if (multiExport.length > 0) {
220
+ lines.push('### Shared Exports');
221
+ lines.push('');
222
+ for (const [name, count] of multiExport) {
223
+ lines.push(`- \`${name}\` (${count} modules)`);
224
+ }
225
+ }
226
+ lines.push('');
227
+ lines.push('---');
228
+ lines.push('*Generated by CodeMap*');
229
+ // 写入文件
230
+ const outputPath = path.join(outputDir, 'AI_MAP.md');
231
+ await fs.mkdir(outputDir, { recursive: true });
232
+ await fs.writeFile(outputPath, lines.join('\n'));
233
+ }
234
+ // 生成独立的 Mermaid 依赖图文件
235
+ export async function generateMermaidGraph(codeMap, outputDir, config) {
236
+ const mermaidConfig = {
237
+ graphType: config?.graphType || 'flowchart',
238
+ direction: config?.direction || 'LR',
239
+ nodeShape: config?.nodeShape || 'box',
240
+ showLabels: config?.showLabels ?? true,
241
+ maxNodes: config?.maxNodes || 50,
242
+ maxEdges: config?.maxEdges || 100
243
+ };
244
+ const graphContent = generateMermaidDependencyGraph(codeMap, mermaidConfig);
245
+ const outputPath = path.join(outputDir, 'dependency-graph.md');
246
+ await fs.mkdir(outputDir, { recursive: true });
247
+ await fs.writeFile(outputPath, graphContent);
248
+ }
249
+ // 生成 codemap.json
250
+ export async function generateJSON(codeMap, outputDir) {
251
+ const outputPath = path.join(outputDir, 'codemap.json');
252
+ await fs.mkdir(outputDir, { recursive: true });
253
+ await fs.writeFile(outputPath, JSON.stringify(codeMap, null, 2));
254
+ }
255
+ // 生成所有文件的 CONTEXT.md
256
+ export async function generateContext(codeMap, outputDir) {
257
+ await generateAllContexts(codeMap.modules, codeMap.project.rootDir, outputDir);
258
+ }
259
+ //# sourceMappingURL=index.js.map