@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,108 @@
1
+ /**
2
+ * [META] ToolOrchestrator - 工具编排器
3
+ * [WHY] 负责执行工具、超时控制、错误隔离、回退级联,是连接 IntentRouter、适配器和结果融合的"胶水"组件。
4
+ */
5
+ import type { UnifiedResult, CodemapIntent } from './types.js';
6
+ import { type ConfidenceResult } from './confidence.js';
7
+ import type { ToolAdapter } from './adapters/base-adapter.js';
8
+ /**
9
+ * 执行结果
10
+ */
11
+ export interface ExecutionResult {
12
+ results: UnifiedResult[];
13
+ tool: string;
14
+ confidence: ConfidenceResult;
15
+ }
16
+ /**
17
+ * 安全执行结果
18
+ */
19
+ export interface SafeExecutionResult {
20
+ results: UnifiedResult[];
21
+ error?: Error;
22
+ }
23
+ /**
24
+ * ToolOrchestrator 类 - 工具编排器核心控制器
25
+ */
26
+ export declare class ToolOrchestrator {
27
+ /** 超时配置(毫秒) */
28
+ private readonly DEFAULT_TIMEOUT;
29
+ /** 工具适配器映射 */
30
+ private adapters;
31
+ /** 回退链配置 */
32
+ private fallbackChains;
33
+ /** 已执行过的工具(用于防止回退链循环) */
34
+ private executedTools;
35
+ /**
36
+ * 构造函数
37
+ * @param fallbackChains 自定义回退链配置
38
+ */
39
+ constructor(fallbackChains?: Record<string, string[]>);
40
+ /**
41
+ * 注册工具适配器
42
+ * @param adapter 工具适配器实例
43
+ */
44
+ registerAdapter(adapter: ToolAdapter): void;
45
+ /**
46
+ * 将 CodemapIntent 转换为适配器调用参数
47
+ * @param intent 意图对象
48
+ * @returns [keywords, options] 元组
49
+ */
50
+ private convertIntentToAdapterArgs;
51
+ /**
52
+ * 带超时控制的工具执行
53
+ *
54
+ * 使用 AbortController + Promise.race 实现真正的超时控制
55
+ *
56
+ * @param tool 工具名称
57
+ * @param intent 意图对象
58
+ * @param timeout 超时时间(毫秒),默认 30 秒
59
+ * @returns 工具执行结果数组
60
+ */
61
+ runToolWithTimeout(tool: string, intent: CodemapIntent, timeout?: number): Promise<UnifiedResult[]>;
62
+ /**
63
+ * 错误隔离的工具执行
64
+ *
65
+ * 包装工具执行,捕获所有异常
66
+ * 错误时返回空结果而非抛出异常(除致命错误外)
67
+ *
68
+ * @param tool 工具名称
69
+ * @param intent 意图对象
70
+ * @returns 安全执行结果
71
+ */
72
+ runToolSafely(tool: string, intent: CodemapIntent): Promise<SafeExecutionResult>;
73
+ /**
74
+ * 回退执行
75
+ *
76
+ * 执行主工具并计算置信度
77
+ * 当置信度 < medium 阈值时,依次执行回退链
78
+ * 合并主工具和回退工具的结果(去重 + 排序)
79
+ * 达到阈值或回退链耗尽后停止
80
+ *
81
+ * @param intent 意图对象
82
+ * @param primaryTool 主工具名称
83
+ * @returns 执行结果
84
+ */
85
+ executeWithFallback(intent: CodemapIntent, primaryTool: string): Promise<ExecutionResult>;
86
+ /**
87
+ * 并行执行
88
+ *
89
+ * 并行执行多个工具
90
+ * 每个工具独立超时控制
91
+ * 返回按工具分组的结果
92
+ *
93
+ * @param intent 意图对象
94
+ * @param tools 工具名称数组
95
+ * @returns 按工具分组的结果映射
96
+ */
97
+ executeParallel(intent: CodemapIntent, tools: string[]): Promise<Map<string, UnifiedResult[]>>;
98
+ /**
99
+ * 合并结果(去重 + 排序)
100
+ */
101
+ private mergeResults;
102
+ /**
103
+ * 获取中等阈值
104
+ */
105
+ private getMediumThreshold;
106
+ }
107
+ export type { ToolAdapter } from './adapters/base-adapter.js';
108
+ //# sourceMappingURL=tool-orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/tool-orchestrator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAA2B,MAAM,YAAY,CAAC;AACxF,OAAO,EAAqC,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC3F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a,EAAE,CAAC,CAAC;IAmBxC;;OAEG;IACH,OAAO,CAAC,YAAY;IA0BpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAG3B;AAGD,YAAY,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * [META] ToolOrchestrator - 工具编排器
3
+ * [WHY] 负责执行工具、超时控制、错误隔离、回退级联,是连接 IntentRouter、适配器和结果融合的"胶水"组件。
4
+ */
5
+ import { calculateConfidence, getThreshold } from './confidence.js';
6
+ /**
7
+ * 默认超时时间(毫秒)
8
+ */
9
+ const DEFAULT_TIMEOUT = 30000;
10
+ /**
11
+ * 预定义回退链(仅内部调试用,默认关闭)
12
+ * 用户可见输出必须走 CodeMap 语义链路
13
+ */
14
+ const FALLBACK_CHAINS = {
15
+ 'ast-grep': ['rg-internal'], // AST搜索 → 文本搜索(内部)
16
+ 'codemap': ['rg-internal'], // 结构分析 → 文本搜索(内部)
17
+ };
18
+ /**
19
+ * ToolOrchestrator 类 - 工具编排器核心控制器
20
+ */
21
+ export class ToolOrchestrator {
22
+ /** 超时配置(毫秒) */
23
+ DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
24
+ /** 工具适配器映射 */
25
+ adapters = new Map();
26
+ /** 回退链配置 */
27
+ fallbackChains;
28
+ /** 已执行过的工具(用于防止回退链循环) */
29
+ executedTools = new Set();
30
+ /**
31
+ * 构造函数
32
+ * @param fallbackChains 自定义回退链配置
33
+ */
34
+ constructor(fallbackChains) {
35
+ this.fallbackChains = fallbackChains ?? FALLBACK_CHAINS;
36
+ }
37
+ /**
38
+ * 注册工具适配器
39
+ * @param adapter 工具适配器实例
40
+ */
41
+ registerAdapter(adapter) {
42
+ this.adapters.set(adapter.name, adapter);
43
+ }
44
+ /**
45
+ * 将 CodemapIntent 转换为适配器调用参数
46
+ * @param intent 意图对象
47
+ * @returns [keywords, options] 元组
48
+ */
49
+ convertIntentToAdapterArgs(intent) {
50
+ const keywords = intent.keywords || [];
51
+ const options = {
52
+ intent: intent.intent,
53
+ targets: intent.targets,
54
+ scope: intent.scope,
55
+ timeout: DEFAULT_TIMEOUT,
56
+ };
57
+ return [keywords, options];
58
+ }
59
+ /**
60
+ * 带超时控制的工具执行
61
+ *
62
+ * 使用 AbortController + Promise.race 实现真正的超时控制
63
+ *
64
+ * @param tool 工具名称
65
+ * @param intent 意图对象
66
+ * @param timeout 超时时间(毫秒),默认 30 秒
67
+ * @returns 工具执行结果数组
68
+ */
69
+ async runToolWithTimeout(tool, intent, timeout = this.DEFAULT_TIMEOUT) {
70
+ // console.debug(`执行工具: ${tool}, 超时: ${timeout}ms`);
71
+ const adapter = this.adapters.get(tool);
72
+ if (!adapter) {
73
+ // console.warn(`工具 ${tool} 未注册,返回空结果`);
74
+ return [];
75
+ }
76
+ // 检查工具是否可用
77
+ if (!(await adapter.isAvailable())) {
78
+ // console.warn(`工具 ${tool} 不可用,返回空结果`);
79
+ return [];
80
+ }
81
+ // 将 intent 转换为适配器调用参数
82
+ const [keywords, options] = this.convertIntentToAdapterArgs(intent);
83
+ // 创建 AbortController 用于超时控制
84
+ const controller = new AbortController();
85
+ const timeoutId = setTimeout(() => {
86
+ controller.abort();
87
+ }, timeout);
88
+ // 将 signal 添加到 options
89
+ const optionsWithSignal = {
90
+ ...options,
91
+ signal: controller.signal,
92
+ timeout,
93
+ };
94
+ // 使用 Promise.race 实现硬超时
95
+ const executionPromise = adapter.execute(keywords, optionsWithSignal);
96
+ try {
97
+ const results = await Promise.race([
98
+ executionPromise,
99
+ new Promise((_, reject) => {
100
+ controller.signal.addEventListener('abort', () => {
101
+ reject(new DOMException('工具执行超时', 'AbortError'));
102
+ });
103
+ })
104
+ ]);
105
+ // console.debug(`工具 ${tool} 执行成功,返回 ${results.length} 条结果`);
106
+ return results;
107
+ }
108
+ catch (error) {
109
+ if (error instanceof Error && error.name === 'AbortError') {
110
+ // console.warn(`工具 ${tool} 执行超时 (${timeout}ms)`);
111
+ }
112
+ else {
113
+ // console.error(`工具 ${tool} 执行失败: ${error}`);
114
+ }
115
+ // 超时或错误时返回空结果,触发回退
116
+ return [];
117
+ }
118
+ finally {
119
+ clearTimeout(timeoutId);
120
+ }
121
+ }
122
+ /**
123
+ * 错误隔离的工具执行
124
+ *
125
+ * 包装工具执行,捕获所有异常
126
+ * 错误时返回空结果而非抛出异常(除致命错误外)
127
+ *
128
+ * @param tool 工具名称
129
+ * @param intent 意图对象
130
+ * @returns 安全执行结果
131
+ */
132
+ async runToolSafely(tool, intent) {
133
+ try {
134
+ const results = await this.runToolWithTimeout(tool, intent);
135
+ return { results };
136
+ }
137
+ catch (error) {
138
+ // console.error(`工具 ${tool} 执行异常:`, error);
139
+ return { results: [], error: error };
140
+ }
141
+ }
142
+ /**
143
+ * 回退执行
144
+ *
145
+ * 执行主工具并计算置信度
146
+ * 当置信度 < medium 阈值时,依次执行回退链
147
+ * 合并主工具和回退工具的结果(去重 + 排序)
148
+ * 达到阈值或回退链耗尽后停止
149
+ *
150
+ * @param intent 意图对象
151
+ * @param primaryTool 主工具名称
152
+ * @returns 执行结果
153
+ */
154
+ async executeWithFallback(intent, primaryTool) {
155
+ // 重置已执行工具集合
156
+ this.executedTools.clear();
157
+ // 1. 执行主工具
158
+ let results = await this.runToolWithTimeout(primaryTool, intent);
159
+ let confidence = calculateConfidence(results, intent.intent);
160
+ // console.debug(`主工具 ${primaryTool} 置信度: ${confidence.score.toFixed(2)} (${confidence.level})`);
161
+ // 2. 检查是否需要回退(低于当前 intent 的中等阈值)
162
+ const threshold = this.getMediumThreshold(intent.intent);
163
+ if (confidence.score < threshold) {
164
+ const fallbackTools = this.fallbackChains[primaryTool] || [];
165
+ for (const fallbackTool of fallbackTools) {
166
+ // 防止循环执行同一工具
167
+ if (this.executedTools.has(fallbackTool)) {
168
+ // console.warn(`跳过已执行的工具: ${fallbackTool}`);
169
+ continue;
170
+ }
171
+ this.executedTools.add(fallbackTool);
172
+ // console.warn(`[LOW CONFIDENCE] ${primaryTool} confidence: ${confidence.score.toFixed(2)}, trying ${fallbackTool}...`);
173
+ const fallbackResults = await this.runToolWithTimeout(fallbackTool, intent);
174
+ const fallbackConfidence = calculateConfidence(fallbackResults, intent.intent);
175
+ // 3. 合并结果(去重 + 排序)
176
+ results = this.mergeResults(results, fallbackResults);
177
+ // 更新置信度(取最大值)
178
+ confidence = {
179
+ score: Math.max(confidence.score, fallbackConfidence.score),
180
+ level: confidence.score > fallbackConfidence.score ? confidence.level : fallbackConfidence.level,
181
+ reasons: [...confidence.reasons, ...fallbackConfidence.reasons]
182
+ };
183
+ // console.debug(`回退工具 ${fallbackTool} 置信度: ${fallbackConfidence.score.toFixed(2)}, 合并后: ${confidence.score.toFixed(2)}`);
184
+ // 4. 达到阈值则停止回退
185
+ if (confidence.score >= threshold) {
186
+ confidence.reasons.push(`回退到 ${fallbackTool} 后达到阈值`);
187
+ break;
188
+ }
189
+ }
190
+ }
191
+ return { results, tool: primaryTool, confidence };
192
+ }
193
+ /**
194
+ * 并行执行
195
+ *
196
+ * 并行执行多个工具
197
+ * 每个工具独立超时控制
198
+ * 返回按工具分组的结果
199
+ *
200
+ * @param intent 意图对象
201
+ * @param tools 工具名称数组
202
+ * @returns 按工具分组的结果映射
203
+ */
204
+ async executeParallel(intent, tools) {
205
+ const resultsMap = new Map();
206
+ // 并行执行所有工具
207
+ const promises = tools.map(async (tool) => {
208
+ const results = await this.runToolWithTimeout(tool, intent);
209
+ return { tool, results };
210
+ });
211
+ const allResults = await Promise.all(promises);
212
+ // 收集结果
213
+ for (const { tool, results } of allResults) {
214
+ resultsMap.set(tool, results);
215
+ }
216
+ return resultsMap;
217
+ }
218
+ /**
219
+ * 合并结果(去重 + 排序)
220
+ */
221
+ mergeResults(primary, fallback) {
222
+ // 合并所有结果
223
+ const allResults = [...primary, ...fallback];
224
+ // 去重(基于 file:line)
225
+ const seen = new Map();
226
+ for (const result of allResults) {
227
+ const key = `${result.file}:${result.line ?? ''}`;
228
+ const existing = seen.get(key);
229
+ if (!existing) {
230
+ seen.set(key, result);
231
+ }
232
+ else if (result.relevance > existing.relevance) {
233
+ // 保留分数更高的结果
234
+ seen.set(key, result);
235
+ }
236
+ }
237
+ // 按 relevance 降序排序
238
+ return Array.from(seen.values()).sort((a, b) => b.relevance - a.relevance);
239
+ }
240
+ /**
241
+ * 获取中等阈值
242
+ */
243
+ getMediumThreshold(intent) {
244
+ return getThreshold(intent, 'medium');
245
+ }
246
+ }
247
+ //# sourceMappingURL=tool-orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/tool-orchestrator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAyB,MAAM,iBAAiB,CAAC;AAG3F;;GAEG;AACH,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;GAGG;AACH,MAAM,eAAe,GAA6B;IAChD,UAAU,EAAE,CAAC,aAAa,CAAC,EAAI,mBAAmB;IAClD,SAAS,EAAE,CAAC,aAAa,CAAC,EAAK,kBAAkB;CAClD,CAAC;AAmBF;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B,eAAe;IACE,eAAe,GAAG,eAAe,CAAC;IAEnD,cAAc;IACN,QAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC;IAEvD,YAAY;IACJ,cAAc,CAA2B;IAEjD,yBAAyB;IACjB,aAAa,GAAgB,IAAI,GAAG,EAAE,CAAC;IAE/C;;;OAGG;IACH,YAAY,cAAyC;QACnD,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,eAAe,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,OAAoB;QAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACK,0BAA0B,CAAC,MAAqB;QACtD,MAAM,QAAQ,GAAG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AAI,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;YAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAE/B,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACxB,CAAC;iBAAM,IAAI,MAAM,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACjD,YAAY;gBACZ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAED,mBAAmB;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,MAAkB;QAC3C,OAAO,YAAY,CAAC,MAA8C,EAAE,QAAQ,CAAC,CAAC;IAChF,CAAC;CACF"}
@@ -0,0 +1,162 @@
1
+ import type { SourceLocation } from '../types/index.js';
2
+ /**
3
+ * UnifiedResult 统一结果接口
4
+ * 用于规范化不同工具的输出格式
5
+ */
6
+ export interface UnifiedResult {
7
+ /** 唯一标识 */
8
+ id: string;
9
+ /** 来源工具 */
10
+ source: 'codemap' | 'ast-grep' | 'rg-internal' | 'ai-feed';
11
+ /** 工具返回的原始分数(0-1) */
12
+ toolScore: number;
13
+ /** 结果类型 */
14
+ type: 'file' | 'symbol' | 'code' | 'documentation' | 'risk-assessment';
15
+ /** 文件路径 */
16
+ file: string;
17
+ /** 行号(可选)- 保留向后兼容,建议使用 location */
18
+ line?: number;
19
+ /** 结构化位置信息(新增) */
20
+ location?: SourceLocation;
21
+ /** 截断后的内容 */
22
+ content: string;
23
+ /** 归一化相关度(0-1) */
24
+ relevance: number;
25
+ /** 匹配的关键词 */
26
+ keywords: string[];
27
+ /** 元数据(可选) */
28
+ metadata?: {
29
+ /** 符号类型 */
30
+ symbolType?: 'class' | 'function' | 'interface' | 'variable';
31
+ /** 依赖文件列表 */
32
+ dependencies?: string[];
33
+ /** 关联的测试文件 */
34
+ testFile?: string;
35
+ /** 提交次数 */
36
+ commitCount?: number;
37
+ /** 依赖复杂度评分 */
38
+ gravity?: number;
39
+ /** 热度评分对象 */
40
+ heatScore?: HeatScore;
41
+ /** 影响文件数 */
42
+ impactCount?: number;
43
+ /** 是否稳定 */
44
+ stability?: boolean;
45
+ /** 风险等级 */
46
+ riskLevel?: 'high' | 'medium' | 'low';
47
+ };
48
+ }
49
+ /**
50
+ * HeatScore 热度评分接口
51
+ */
52
+ export interface HeatScore {
53
+ /** 30天修改次数 */
54
+ freq30d: number;
55
+ /** 最后提交标签 */
56
+ lastType: string;
57
+ /** 最后修改日期(ISO 字符串格式) */
58
+ lastDate: string | null;
59
+ /** 是否稳定 (沉积岩 vs 火山灰) */
60
+ stability: boolean;
61
+ }
62
+ /**
63
+ * ToolOptions 工具选项类型
64
+ * 用于 execute 方法的 options 参数
65
+ */
66
+ export interface ToolOptions {
67
+ /** 超时时间(毫秒) */
68
+ timeout?: number;
69
+ /** 返回结果数量上限 */
70
+ topK?: number;
71
+ /** 是否包含测试文件 */
72
+ includeTests?: boolean;
73
+ /** 其他扩展选项 */
74
+ [key: string]: unknown;
75
+ }
76
+ /**
77
+ * IntentType 意图类型
78
+ */
79
+ export type IntentType = 'impact' | 'dependency' | 'search' | 'documentation' | 'complexity' | 'overview' | 'refactor' | 'reference';
80
+ /**
81
+ * CodemapIntent Codemap 意图对象
82
+ */
83
+ export interface CodemapIntent {
84
+ intent: IntentType;
85
+ targets: string[];
86
+ keywords: string[];
87
+ scope: 'direct' | 'transitive';
88
+ tool: string;
89
+ secondary?: string;
90
+ }
91
+ /**
92
+ * AnalyzeArgs 分析命令参数
93
+ */
94
+ export interface AnalyzeArgs {
95
+ intent?: string;
96
+ targets?: string[];
97
+ keywords?: string[];
98
+ scope?: 'direct' | 'transitive';
99
+ topK?: number;
100
+ includeTests?: boolean;
101
+ includeGitHistory?: boolean;
102
+ json?: boolean;
103
+ /** 输出完全结构化的 JSON(不包含自然语言字符串) */
104
+ structured?: boolean;
105
+ outputMode?: 'machine' | 'human';
106
+ }
107
+ /**
108
+ * Confidence 置信度对象
109
+ */
110
+ export interface Confidence {
111
+ /** 置信度分数 (0-1) */
112
+ score: number;
113
+ /** 置信度级别 */
114
+ level: 'high' | 'medium' | 'low';
115
+ }
116
+ /**
117
+ * ConfidenceResult 置信度结果
118
+ */
119
+ export interface ConfidenceResult {
120
+ /** 置信度分数 (0-1) */
121
+ score: number;
122
+ /** 置信度级别 */
123
+ level: 'high' | 'medium' | 'low';
124
+ /** 置信度来源说明 */
125
+ reasons: string[];
126
+ }
127
+ /**
128
+ * CodemapOutput Codemap 统一输出格式
129
+ * 用于规范 analyze 命令的 machine/json 输出
130
+ */
131
+ export interface CodemapOutput {
132
+ /** Schema 版本,格式: "v1.0.0" */
133
+ schemaVersion: string;
134
+ /** 执行的 intent 类型 */
135
+ intent: string;
136
+ /** 主要工具 */
137
+ tool: string;
138
+ /** 置信度信息 */
139
+ confidence: Confidence;
140
+ /** 结果列表 */
141
+ results: UnifiedResult[];
142
+ /** 可选的元数据 */
143
+ metadata?: {
144
+ /** 执行时间(毫秒) */
145
+ executionTime?: number;
146
+ /** 结果总数 */
147
+ resultCount?: number;
148
+ /** 总数(兼容旧字段) */
149
+ total?: number;
150
+ /** 范围 */
151
+ scope?: string;
152
+ };
153
+ }
154
+ /**
155
+ * 类型守卫:检查对象是否为 CodemapOutput
156
+ */
157
+ export declare function isCodemapOutput(obj: unknown): obj is CodemapOutput;
158
+ /**
159
+ * 计算置信度级别
160
+ */
161
+ export declare function calculateConfidenceLevel(score: number): 'high' | 'medium' | 'low';
162
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+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;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjC,cAAc;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW;IACX,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,aAAa;IACb,QAAQ,CAAC,EAAE;QACT,eAAe;QACf,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,gBAAgB;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa,CAoBlE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAIjF"}
@@ -0,0 +1,39 @@
1
+ // [META] since:2026-03-02 | owner:orchestrator-team | stable:true
2
+ // [WHY] Core type definitions with optional fields for flexible unified results
3
+ /**
4
+ * 类型守卫:检查对象是否为 CodemapOutput
5
+ */
6
+ export function isCodemapOutput(obj) {
7
+ if (typeof obj !== 'object' || obj === null) {
8
+ return false;
9
+ }
10
+ const output = obj;
11
+ // 检查必需字段
12
+ if (typeof output.schemaVersion !== 'string')
13
+ return false;
14
+ if (typeof output.intent !== 'string')
15
+ return false;
16
+ if (typeof output.tool !== 'string')
17
+ return false;
18
+ if (typeof output.confidence !== 'object' || output.confidence === null)
19
+ return false;
20
+ const confidence = output.confidence;
21
+ if (typeof confidence.score !== 'number')
22
+ return false;
23
+ if (!['high', 'medium', 'low'].includes(confidence.level))
24
+ return false;
25
+ if (!Array.isArray(output.results))
26
+ return false;
27
+ return true;
28
+ }
29
+ /**
30
+ * 计算置信度级别
31
+ */
32
+ export function calculateConfidenceLevel(score) {
33
+ if (score >= 0.7)
34
+ return 'high';
35
+ if (score >= 0.4)
36
+ return 'medium';
37
+ return 'low';
38
+ }
39
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/orchestrator/types.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,gFAAgF;AA6KhF;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,GAA8B,CAAC;IAE9C,SAAS;IACT,IAAI,OAAO,MAAM,CAAC,aAAa,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3D,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACpD,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,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