@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,98 @@
1
+ // [META] since:2026-03-02 | owner:orchestrator-team | stable:true
2
+ // [WHY] Route analyze intents to primary/secondary tools with whitelist validation
3
+ /**
4
+ * 有效的意图类型白名单
5
+ */
6
+ const VALID_INTENTS = [
7
+ 'impact',
8
+ 'dependency',
9
+ 'search',
10
+ 'documentation',
11
+ 'complexity',
12
+ 'overview',
13
+ 'refactor',
14
+ 'reference'
15
+ ];
16
+ /**
17
+ * 意图到默认工具的映射
18
+ */
19
+ const INTENT_DEFAULT_TOOL = {
20
+ impact: 'codemap',
21
+ dependency: 'codemap',
22
+ search: 'ast-grep',
23
+ documentation: 'codemap',
24
+ complexity: 'codemap',
25
+ overview: 'codemap',
26
+ refactor: 'ast-grep',
27
+ reference: 'ast-grep'
28
+ };
29
+ /**
30
+ * IntentRouter 类 - 意图路由器
31
+ */
32
+ export class IntentRouter {
33
+ /** 有效意图白名单 */
34
+ validIntents = VALID_INTENTS;
35
+ /**
36
+ * 将分析参数路由为 CodemapIntent
37
+ *
38
+ * @param args 分析命令参数
39
+ * @returns CodemapIntent 对象
40
+ */
41
+ route(args) {
42
+ // 解析 intent
43
+ const intent = this.parseIntent(args.intent);
44
+ // 验证 intent 是否有效
45
+ this.validateIntent(intent);
46
+ // 确定目标
47
+ const targets = args.targets ?? [];
48
+ // 确定关键词
49
+ const keywords = args.keywords ?? [];
50
+ // 确定范围
51
+ const scope = args.scope ?? 'direct';
52
+ // 确定工具
53
+ const tool = args.intent ? INTENT_DEFAULT_TOOL[intent] : 'codemap';
54
+ const secondary = intent === 'impact' ? 'ast-grep' : undefined;
55
+ return {
56
+ intent,
57
+ targets,
58
+ keywords,
59
+ scope,
60
+ tool,
61
+ secondary
62
+ };
63
+ }
64
+ /**
65
+ * 解析 intent 字符串为 IntentType
66
+ */
67
+ parseIntent(intent) {
68
+ if (!intent) {
69
+ // 默认意图
70
+ return 'search';
71
+ }
72
+ return intent;
73
+ }
74
+ /**
75
+ * 验证 intent 是否在白名单中
76
+ *
77
+ * @param intent 意图类型
78
+ * @throws 如果 intent 无效,抛出错误
79
+ */
80
+ validateIntent(intent) {
81
+ if (!this.validIntents.includes(intent)) {
82
+ throw new Error(`无效的 intent: ${intent}. 有效的意图类型: ${this.validIntents.join(', ')}`);
83
+ }
84
+ }
85
+ /**
86
+ * 检查 intent 是否有效
87
+ */
88
+ isValidIntent(intent) {
89
+ return this.validIntents.includes(intent);
90
+ }
91
+ /**
92
+ * 获取所有有效的意图类型
93
+ */
94
+ getValidIntents() {
95
+ return [...this.validIntents];
96
+ }
97
+ }
98
+ //# sourceMappingURL=intent-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-router.js","sourceRoot":"","sources":["../../src/orchestrator/intent-router.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,mFAAmF;AAWnF;;GAEG;AACH,MAAM,aAAa,GAAiB;IAClC,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,eAAe;IACf,YAAY;IACZ,UAAU;IACV,UAAU;IACV,WAAW;CACZ,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAA+B;IACtD,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,SAAS;IACrB,MAAM,EAAE,UAAU;IAClB,aAAa,EAAE,SAAS;IACxB,UAAU,EAAE,SAAS;IACrB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,UAAU;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,cAAc;IACN,YAAY,GAAiB,aAAa,CAAC;IAEnD;;;;;OAKG;IACH,KAAK,CAAC,IAAiB;QACrB,YAAY;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE7C,iBAAiB;QACjB,IAAI,CAAC,cAAc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[META] ResultFusion - 多工具结果融合模块
3
+ * [WHY] 将多个工具的输出统一格式转换、加权合并、去重、排序
4
+ *
5
+ * 负责将多个工具(CodeMap 核心、ast-grep、AI 饲料等)的输出进行统一格式转换、
6
+ * 加权合并、去重、排序和截断。
7
+ *
8
+ * 融合策略(按顺序执行):
9
+ * 1. 加权合并 - 按工具权重调整 relevance
10
+ * 2. AI 饲料融合 - 合并 AI 饲料结果(预留接口)
11
+ * 3. 风险加权 - 基于 riskLevel 调整 relevance
12
+ * 4. 去重 - 基于 file:line 作为 key
13
+ * 5. 排序 - 按 relevance 降序(影响分析场景按风险排序)
14
+ * 6. 关键词加权 - 提升匹配关键词的结果
15
+ * 7. 截断 - Top-K + Token 限制
16
+ */
17
+ import type { UnifiedResult } from './types';
18
+ import type { AIFeed } from './git-analyzer';
19
+ /**
20
+ * 融合选项配置
21
+ */
22
+ export interface FusionOptions {
23
+ /** 返回结果数量上限,默认 8 */
24
+ topK?: number;
25
+ /** 关键词权重映射 */
26
+ keywordWeights?: Record<string, number>;
27
+ /** 意图类型,影响排序策略 */
28
+ intent?: string;
29
+ /** 每个结果的最大 token 数,默认 160 */
30
+ maxTokens?: number;
31
+ }
32
+ /**
33
+ * ResultFusion 类 - 多工具结果融合器
34
+ */
35
+ export declare class ResultFusion {
36
+ /**
37
+ * 多工具结果融合
38
+ *
39
+ * @param resultsByTool - 按工具分组的的结果映射
40
+ * @param options - 融合选项
41
+ * @returns 融合后的统一结果数组
42
+ */
43
+ fuse(resultsByTool: Map<string, UnifiedResult[]>, options: FusionOptions): UnifiedResult[];
44
+ /**
45
+ * 获取工具权重
46
+ */
47
+ private getToolWeight;
48
+ /**
49
+ * 应用工具权重
50
+ */
51
+ private applyToolWeights;
52
+ /**
53
+ * 应用风险加权
54
+ * 根据 riskLevel 调整 relevance
55
+ */
56
+ private applyRiskBoost;
57
+ /**
58
+ * 去重
59
+ * 基于 file:line 作为 key,保留 relevance 更高的结果
60
+ */
61
+ private deduplicate;
62
+ /**
63
+ * 排序结果
64
+ * - impact 场景:按风险等级排序(high > medium > low),同等级按 relevance
65
+ * - 其他场景:按 relevance 降序
66
+ */
67
+ private sortResults;
68
+ /**
69
+ * 按风险影响排序
70
+ * 高风险优先,同风险等级按 relevance 排序
71
+ */
72
+ private sortByRiskImpact;
73
+ /**
74
+ * 应用关键词加权
75
+ */
76
+ private applyKeywordBoost;
77
+ /**
78
+ * 对结果内容进行 token 截断
79
+ */
80
+ private truncateResults;
81
+ }
82
+ /**
83
+ * 按 token 数量截断内容
84
+ *
85
+ * 使用简单估算:
86
+ * - 英文约 4 字符 = 1 token
87
+ * - 中文约 1 字符 = 1 token
88
+ *
89
+ * @param content - 原始内容
90
+ * @param maxTokens - 最大 token 数
91
+ * @returns 截断后的内容
92
+ */
93
+ export declare function truncateByToken(content: string, maxTokens: number): string;
94
+ /**
95
+ * 将 AI 饲料转换为 UnifiedResult
96
+ * @param feed - AI 饲料数组
97
+ * @returns UnifiedResult 数组
98
+ */
99
+ export declare function convertAIFeedToResults(feed: AIFeed[]): UnifiedResult[];
100
+ /**
101
+ * 格式化 AI 饲料内容
102
+ * 使用纯文本标记代替 emoji,确保机器可读性
103
+ * @param f - AI 饲料项
104
+ * @returns 格式化后的内容字符串
105
+ */
106
+ export declare function formatAIFeedContent(f: AIFeed): string;
107
+ /**
108
+ * 计算风险等级
109
+ * 风险评分公式以 REFACTOR_REQUIREMENTS.md 为单一真源
110
+ * @param f - AI 饲料项
111
+ * @returns 风险等级: 'high' | 'medium' | 'low'
112
+ */
113
+ export declare function calculateRiskLevel(f: AIFeed): 'high' | 'medium' | 'low';
114
+ //# sourceMappingURL=result-fusion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-fusion.d.ts","sourceRoot":"","sources":["../../src/orchestrator/result-fusion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,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Fusion - 多工具结果融合模块
3
+ * [WHY] 将多个工具的输出统一格式转换、加权合并、去重、排序
4
+ *
5
+ * 负责将多个工具(CodeMap 核心、ast-grep、AI 饲料等)的输出进行统一格式转换、
6
+ * 加权合并、去重、排序和截断。
7
+ *
8
+ * 融合策略(按顺序执行):
9
+ * 1. 加权合并 - 按工具权重调整 relevance
10
+ * 2. AI 饲料融合 - 合并 AI 饲料结果(预留接口)
11
+ * 3. 风险加权 - 基于 riskLevel 调整 relevance
12
+ * 4. 去重 - 基于 file:line 作为 key
13
+ * 5. 排序 - 按 relevance 降序(影响分析场景按风险排序)
14
+ * 6. 关键词加权 - 提升匹配关键词的结果
15
+ * 7. 截断 - Top-K + Token 限制
16
+ */
17
+ /**
18
+ * 工具权重配置
19
+ */
20
+ const TOOL_WEIGHTS = {
21
+ 'ast-grep': 1.0, // AST 分析最准确
22
+ 'codemap': 0.9, // 结构分析次之
23
+ 'ai-feed': 0.85, // AI 饲料数据
24
+ 'rg-internal': 0.7 // 文本搜索兜底(仅内部调试用)
25
+ };
26
+ /**
27
+ * 默认工具权重
28
+ */
29
+ const DEFAULT_TOOL_WEIGHT = 0.5;
30
+ /**
31
+ * 风险等级调整值
32
+ */
33
+ const RISK_BOOST = {
34
+ 'high': -0.1, // 高风险文件降权,提示谨慎
35
+ 'medium': 0, // 中风险文件不做调整
36
+ 'low': 0.05 // 低风险文件加权,推荐优先修改
37
+ };
38
+ /**
39
+ * 风险排序优先级
40
+ */
41
+ const RISK_ORDER = {
42
+ 'high': 0,
43
+ 'medium': 1,
44
+ 'low': 2
45
+ };
46
+ /**
47
+ * ResultFusion 类 - 多工具结果融合器
48
+ */
49
+ export class ResultFusion {
50
+ /**
51
+ * 多工具结果融合
52
+ *
53
+ * @param resultsByTool - 按工具分组的的结果映射
54
+ * @param options - 融合选项
55
+ * @returns 融合后的统一结果数组
56
+ */
57
+ fuse(resultsByTool, options) {
58
+ const topK = options.topK ?? 8;
59
+ const keywordWeights = options.keywordWeights ?? {};
60
+ const maxTokens = options.maxTokens ?? 160;
61
+ // 1. 加权合并
62
+ let allResults = this.applyToolWeights(resultsByTool);
63
+ // 2. 风险加权(v2.4)
64
+ allResults = this.applyRiskBoost(allResults);
65
+ // 3. 去重(基于文件+行号)
66
+ allResults = this.deduplicate(allResults);
67
+ // 4. 排序
68
+ allResults = this.sortResults(allResults, options.intent);
69
+ // 5. 关键词加权
70
+ allResults = this.applyKeywordBoost(allResults, keywordWeights);
71
+ // 6. Token 截断
72
+ allResults = this.truncateResults(allResults, maxTokens);
73
+ // 7. Top-K 裁剪
74
+ return allResults.slice(0, topK);
75
+ }
76
+ /**
77
+ * 获取工具权重
78
+ */
79
+ getToolWeight(tool) {
80
+ return TOOL_WEIGHTS[tool] ?? DEFAULT_TOOL_WEIGHT;
81
+ }
82
+ /**
83
+ * 应用工具权重
84
+ */
85
+ applyToolWeights(resultsByTool) {
86
+ const allResults = [];
87
+ for (const [tool, results] of resultsByTool) {
88
+ const toolWeight = this.getToolWeight(tool);
89
+ const weighted = results.map(r => ({
90
+ ...r,
91
+ relevance: r.relevance * toolWeight
92
+ }));
93
+ allResults.push(...weighted);
94
+ }
95
+ return allResults;
96
+ }
97
+ /**
98
+ * 应用风险加权
99
+ * 根据 riskLevel 调整 relevance
100
+ */
101
+ applyRiskBoost(results) {
102
+ return results.map(r => {
103
+ const riskLevel = r.metadata?.riskLevel;
104
+ if (!riskLevel)
105
+ return r;
106
+ const boost = RISK_BOOST[riskLevel] ?? 0;
107
+ const newRelevance = Math.max(0, Math.min(1, r.relevance + boost));
108
+ return {
109
+ ...r,
110
+ relevance: newRelevance
111
+ };
112
+ });
113
+ }
114
+ /**
115
+ * 去重
116
+ * 基于 file:line 作为 key,保留 relevance 更高的结果
117
+ */
118
+ deduplicate(results) {
119
+ const seen = new Map();
120
+ for (const result of results) {
121
+ const key = `${result.file}:${result.line ?? ''}`;
122
+ const existing = seen.get(key);
123
+ if (!existing) {
124
+ seen.set(key, result);
125
+ }
126
+ else if (result.relevance > existing.relevance) {
127
+ // 保留分数更高的结果
128
+ seen.set(key, result);
129
+ }
130
+ }
131
+ return Array.from(seen.values());
132
+ }
133
+ /**
134
+ * 排序结果
135
+ * - impact 场景:按风险等级排序(high > medium > low),同等级按 relevance
136
+ * - 其他场景:按 relevance 降序
137
+ */
138
+ sortResults(results, intent) {
139
+ if (intent === 'impact') {
140
+ return this.sortByRiskImpact(results);
141
+ }
142
+ // 默认按 relevance 降序
143
+ return [...results].sort((a, b) => b.relevance - a.relevance);
144
+ }
145
+ /**
146
+ * 按风险影响排序
147
+ * 高风险优先,同风险等级按 relevance 排序
148
+ */
149
+ sortByRiskImpact(results) {
150
+ return [...results].sort((a, b) => {
151
+ const riskA = a.metadata?.riskLevel ?? 'low';
152
+ const riskB = b.metadata?.riskLevel ?? 'low';
153
+ const riskDiff = RISK_ORDER[riskA] - RISK_ORDER[riskB];
154
+ if (riskDiff !== 0)
155
+ return riskDiff;
156
+ // 同风险等级按 relevance 降序
157
+ return b.relevance - a.relevance;
158
+ });
159
+ }
160
+ /**
161
+ * 应用关键词加权
162
+ */
163
+ applyKeywordBoost(results, keywordWeights) {
164
+ if (Object.keys(keywordWeights).length === 0) {
165
+ return results;
166
+ }
167
+ return results.map(r => {
168
+ let boost = 0;
169
+ for (const keyword of r.keywords) {
170
+ boost += keywordWeights[keyword] ?? 0;
171
+ }
172
+ const newRelevance = Math.max(0, Math.min(1, r.relevance + boost));
173
+ return {
174
+ ...r,
175
+ relevance: newRelevance
176
+ };
177
+ }).sort((a, b) => b.relevance - a.relevance);
178
+ }
179
+ /**
180
+ * 对结果内容进行 token 截断
181
+ */
182
+ truncateResults(results, maxTokens) {
183
+ return results.map(r => ({
184
+ ...r,
185
+ content: truncateByToken(r.content, maxTokens)
186
+ }));
187
+ }
188
+ }
189
+ /**
190
+ * 按 token 数量截断内容
191
+ *
192
+ * 使用简单估算:
193
+ * - 英文约 4 字符 = 1 token
194
+ * - 中文约 1 字符 = 1 token
195
+ *
196
+ * @param content - 原始内容
197
+ * @param maxTokens - 最大 token 数
198
+ * @returns 截断后的内容
199
+ */
200
+ export function truncateByToken(content, maxTokens) {
201
+ // 处理空字符串或 undefined
202
+ if (!content) {
203
+ return '';
204
+ }
205
+ // 简单估算:按空格分割的词 + 中文字符数
206
+ const words = content.split(/\s+/);
207
+ let tokenCount = 0;
208
+ const result = [];
209
+ for (const word of words) {
210
+ // 统计中文字符数量
211
+ const chineseChars = (word.match(/[\u4e00-\u9fa5]/g) || []).length;
212
+ const englishChars = word.length - chineseChars;
213
+ // 英文按 4 字符 = 1 token 估算
214
+ const wordTokens = chineseChars + Math.ceil(englishChars / 4);
215
+ if (tokenCount + wordTokens > maxTokens) {
216
+ // 超过限制,添加省略号并退出
217
+ if (result.length > 0) {
218
+ return result.join(' ') + '...';
219
+ }
220
+ // 如果第一个词就超长了,截断该词
221
+ if (chineseChars > 0) {
222
+ const availableTokens = maxTokens - tokenCount;
223
+ if (availableTokens > 0) {
224
+ // 取前 availableTokens 个中文字符
225
+ let taken = 0;
226
+ let truncated = '';
227
+ for (const char of word) {
228
+ if (taken >= availableTokens)
229
+ break;
230
+ if (/[\u4e00-\u9fa5]/.test(char)) {
231
+ taken++;
232
+ }
233
+ truncated += char;
234
+ }
235
+ return truncated + '...';
236
+ }
237
+ }
238
+ return '...';
239
+ }
240
+ result.push(word);
241
+ tokenCount += wordTokens;
242
+ }
243
+ return content;
244
+ }
245
+ // ==================== AI 饲料结果融合函数 (v2.4 新增) ====================
246
+ /**
247
+ * 标签风险权重映射
248
+ * 基于 REFACTOR_REQUIREMENTS.md 第 8.6 节
249
+ */
250
+ const TAG_WEIGHTS = {
251
+ 'BUGFIX': 0.9, // 修复过的代码 = 曾经有问题
252
+ 'REFACTOR': 0.8, // 重构过的代码 = 复杂度较高
253
+ 'FEATURE': 0.7, // 新功能 = 可能不稳定
254
+ 'CONFIG': 0.5, // 配置变更 = 中等风险
255
+ 'DOCS': 0.2, // 文档 = 低风险
256
+ 'DELETE': 0.1, // 删除代码 = 极低风险
257
+ 'UNKNOWN': 0.5, // 未知 = 默认中等风险
258
+ 'NEW': 0.5 // 新文件 = 默认中等风险
259
+ };
260
+ /**
261
+ * 将 AI 饲料转换为 UnifiedResult
262
+ * @param feed - AI 饲料数组
263
+ * @returns UnifiedResult 数组
264
+ */
265
+ export function convertAIFeedToResults(feed) {
266
+ return feed.map(f => ({
267
+ id: `ai-feed-${f.file}`,
268
+ source: 'ai-feed',
269
+ toolScore: f.gravity / 20, // 归一化
270
+ type: 'risk-assessment',
271
+ file: f.file,
272
+ content: formatAIFeedContent(f),
273
+ relevance: calculateAIFeedRelevance(f),
274
+ keywords: [f.heat.lastType, f.meta.why || ''].filter(Boolean),
275
+ metadata: {
276
+ gravity: f.gravity,
277
+ heatScore: f.heat,
278
+ impactCount: f.dependents.length,
279
+ stability: f.meta.stable,
280
+ riskLevel: calculateRiskLevel(f)
281
+ }
282
+ }));
283
+ }
284
+ /**
285
+ * 格式化 AI 饲料内容
286
+ * 使用纯文本标记代替 emoji,确保机器可读性
287
+ * @param f - AI 饲料项
288
+ * @returns 格式化后的内容字符串
289
+ */
290
+ export function formatAIFeedContent(f) {
291
+ const riskFlag = f.meta.stable ? '[STABLE]' : f.heat.freq30d > 5 ? '[HIGH RISK]' : '[MEDIUM RISK]';
292
+ return `${riskFlag} ${f.file}\n` +
293
+ ` GRAVITY: ${f.gravity} | HEAT: ${f.heat.freq30d}/${f.heat.lastType}\n` +
294
+ ` WHY: ${f.meta.why || 'N/A'}\n` +
295
+ ` IMPACT: ${f.dependents.length} files depend on this`;
296
+ }
297
+ /**
298
+ * 计算 AI 饲料的相关度
299
+ * @param f - AI 饲料项
300
+ * @returns 相关度分数 (0-1)
301
+ */
302
+ function calculateAIFeedRelevance(f) {
303
+ // 基于 gravity 和 heat 计算基础分数
304
+ const gravityScore = Math.min(f.gravity / 20, 1) * 0.4;
305
+ const heatScore = Math.min(f.heat.freq30d / 10, 1) * 0.3;
306
+ const impactScore = Math.min(f.dependents.length / 50, 1) * 0.3;
307
+ return Math.min(1, gravityScore + heatScore + impactScore);
308
+ }
309
+ /**
310
+ * 计算风险等级
311
+ * 风险评分公式以 REFACTOR_REQUIREMENTS.md 为单一真源
312
+ * @param f - AI 饲料项
313
+ * @returns 风险等级: 'high' | 'medium' | 'low'
314
+ */
315
+ export function calculateRiskLevel(f) {
316
+ const gravityNorm = Math.min(f.gravity / 20, 1);
317
+ const freqNorm = Math.min(f.heat.freq30d / 10, 1);
318
+ const tagWeight = TAG_WEIGHTS[f.heat.lastType] ?? TAG_WEIGHTS['UNKNOWN'];
319
+ const stableBoost = f.meta.stable ? 0 : 0.15;
320
+ const impactNorm = Math.min(f.dependents.length / 50, 1);
321
+ const score = Math.min(Math.max(gravityNorm * 0.30 +
322
+ freqNorm * 0.15 +
323
+ tagWeight * 0.10 +
324
+ stableBoost +
325
+ impactNorm * 0.10, 0), 1);
326
+ if (score > 0.7)
327
+ return 'high';
328
+ if (score > 0.4)
329
+ return 'medium';
330
+ return 'low';
331
+ }
332
+ //# sourceMappingURL=result-fusion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-fusion.js","sourceRoot":"","sources":["../../src/orchestrator/result-fusion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoBH;;GAEG;AACH,MAAM,YAAY,GAA2B;IAC3C,UAAU,EAAE,GAAG,EAAO,YAAY;IAClC,SAAS,EAAE,GAAG,EAAQ,SAAS;IAC/B,SAAS,EAAE,IAAI,EAAO,UAAU;IAChC,aAAa,EAAE,GAAG,CAAI,iBAAiB;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,GAA2B;IACzC,MAAM,EAAE,CAAC,GAAG,EAAK,eAAe;IAChC,QAAQ,EAAE,CAAC,EAAM,YAAY;IAC7B,KAAK,EAAE,IAAI,CAAM,iBAAiB;CACnC,CAAC;AAEF;;GAEG;AACH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