@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,87 @@
1
+ /**
2
+ * [META] Commit 格式验证器
3
+ * [WHY] 统一执行 CI 门禁的提交信息规则,避免本地与服务端口径漂移
4
+ */
5
+ export const VALID_TAGS = [
6
+ 'BUGFIX',
7
+ 'FEATURE',
8
+ 'REFACTOR',
9
+ 'CONFIG',
10
+ 'DOCS',
11
+ 'DELETE',
12
+ ];
13
+ /**
14
+ * 验证 Commit 消息是否符合 [TAG] 格式
15
+ * @param commitMessage - Commit 消息内容
16
+ * @returns 验证结果
17
+ */
18
+ export function validateCommitMessage(commitMessage) {
19
+ const firstLine = commitMessage.split('\n')[0]?.trim() ?? '';
20
+ if (!firstLine) {
21
+ return {
22
+ valid: false,
23
+ errorCode: 'E0007',
24
+ errorMessage: 'Commit message cannot be empty',
25
+ };
26
+ }
27
+ // 严格格式: [TAG] scope: message
28
+ const tagPattern = new RegExp(`^\\[(${VALID_TAGS.join('|')})\\]\\s+([^:]+):\\s+(.+)$`);
29
+ const match = firstLine.match(tagPattern);
30
+ if (!match) {
31
+ return {
32
+ valid: false,
33
+ errorCode: 'E0007',
34
+ errorMessage: `Expected format: [TAG] scope: message. Valid tags: ${VALID_TAGS.join(', ')}`,
35
+ };
36
+ }
37
+ const tag = match[1];
38
+ const scope = match[2]?.trim() ?? '';
39
+ const message = match[3]?.trim() ?? '';
40
+ if (!scope || !message) {
41
+ return {
42
+ valid: false,
43
+ errorCode: 'E0007',
44
+ errorMessage: 'Scope and message are required. Expected: [TAG] scope: message',
45
+ };
46
+ }
47
+ return {
48
+ valid: true,
49
+ tag,
50
+ commitMessage: `${scope}: ${message}`,
51
+ };
52
+ }
53
+ /**
54
+ * 从 git log 获取最近的 Commit 消息并验证
55
+ * @param count - 获取的 Commit 数量
56
+ * @returns 验证结果数组
57
+ */
58
+ export async function validateRecentCommits(count = 10, range) {
59
+ const { execSync } = await import('child_process');
60
+ try {
61
+ const command = range
62
+ ? `git log --format=%s ${range}`
63
+ : `git log -${count} --pretty=format:"%s"`;
64
+ const output = execSync(command, {
65
+ encoding: 'utf-8',
66
+ });
67
+ const messages = output.split('\n').filter(Boolean);
68
+ return messages.map(validateCommitMessage);
69
+ }
70
+ catch {
71
+ return [];
72
+ }
73
+ }
74
+ /**
75
+ * 验证并输出结果到控制台
76
+ */
77
+ export function validateAndPrint(message) {
78
+ const result = validateCommitMessage(message);
79
+ if (result.valid) {
80
+ console.log(`Valid commit: [${result.tag}] ${result.commitMessage}`);
81
+ }
82
+ else {
83
+ console.error(`ERROR: ${result.errorCode}: ${result.errorMessage}`);
84
+ process.exit(1);
85
+ }
86
+ }
87
+ //# sourceMappingURL=commit-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-validator.js","sourceRoot":"","sources":["../../src/orchestrator/commit-validator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,QAAQ;IACR,SAAS;IACT,UAAU;IACV,QAAQ;IACR,MAAM;IACN,QAAQ;CACA,CAAC;AAYX;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAAqB;IACzD,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAE7D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,OAAO;YAClB,YAAY,EAAE,gCAAgC;SAC/C,CAAC;IACJ,CAAC;IAED,6BAA6B;IAC7B,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,QAAQ,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACvF,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,CA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MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE9C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,kBAAkB,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IACvE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,UAAU,MAAM,CAAC,SAAS,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 置信度计算机制
3
+ * 用于评估搜索结果的质量,决定是否触发回退策略
4
+ */
5
+ import { UnifiedResult } from './types';
6
+ type IntentType = 'impact' | 'dependency' | 'search' | 'documentation' | 'complexity' | 'overview' | 'refactor' | 'reference';
7
+ interface SearchResult extends UnifiedResult {
8
+ }
9
+ interface ConfidenceResult {
10
+ score: number;
11
+ level: 'high' | 'medium' | 'low';
12
+ reasons: string[];
13
+ }
14
+ declare const CONFIDENCE_THRESHOLDS: Record<IntentType, {
15
+ high: number;
16
+ medium: number;
17
+ }>;
18
+ declare function clamp(value: number, min: number, max: number): number;
19
+ declare function getRelevance(result: SearchResult): number;
20
+ declare function getMatchCount(result: SearchResult): number;
21
+ declare function getThreshold(intent: IntentType, level: 'high' | 'medium'): number;
22
+ export declare function calculateConfidence(results: SearchResult[], intent: IntentType): ConfidenceResult;
23
+ export type { IntentType, SearchResult, ConfidenceResult };
24
+ export { CONFIDENCE_THRESHOLDS, getThreshold, getRelevance, getMatchCount, clamp };
25
+ //# sourceMappingURL=confidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidence.d.ts","sourceRoot":"","sources":["../../src/orchestrator/confidence.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,KAAK,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,QAAQ,GAAG,eAAe,GACpD,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;AAGvE,UAAU,YAAa,SAAQ,aAAa;CAAG;AAG/C,UAAU,gBAAgB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAGD,QAAA,MAAM,qBAAqB,EAAE,MAAM,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAS/E,CAAC;AAGF,iBAAS,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD,iBAAS,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAclD;AAGD,iBAAS,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAMnD;AAGD,iBAAS,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAE1E;AAGD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,EAAE,UAAU,GACjB,gBAAgB,CA8FlB;AAGD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,138 @@
1
+ // [META] since:2026-03 | owner:orchestrator-team | stable:true
2
+ // [WHY] Confidence calculation mechanism for evaluating search result quality
3
+ // and determining fallback strategies based on result count, quality, and scenario matching
4
+ // 每种 intent 的阈值配置
5
+ const CONFIDENCE_THRESHOLDS = {
6
+ impact: { high: 0.7, medium: 0.4 },
7
+ dependency: { high: 0.7, medium: 0.4 },
8
+ search: { high: 0.5, medium: 0.25 },
9
+ documentation: { high: 0.5, medium: 0.25 },
10
+ complexity: { high: 0.6, medium: 0.3 },
11
+ overview: { high: 0.6, medium: 0.3 },
12
+ refactor: { high: 0.6, medium: 0.3 },
13
+ reference: { high: 0.5, medium: 0.25 },
14
+ };
15
+ // 辅助函数:限制数值范围
16
+ function clamp(value, min, max) {
17
+ return Math.max(min, Math.min(max, value));
18
+ }
19
+ // 辅助函数:获取结果相关度(兼容多种字段格式)
20
+ function getRelevance(result) {
21
+ // 优先使用 relevance,其次 toolScore,最后 score
22
+ if ('relevance' in result && typeof result.relevance === 'number') {
23
+ return result.relevance;
24
+ }
25
+ if ('toolScore' in result && typeof result.toolScore === 'number') {
26
+ return result.toolScore;
27
+ }
28
+ // 兼容可能存在的 score 字段
29
+ const r = result;
30
+ if ('score' in r && typeof r.score === 'number') {
31
+ return r.score;
32
+ }
33
+ return 0;
34
+ }
35
+ // 辅助函数:获取结果匹配次数
36
+ function getMatchCount(result) {
37
+ // 基于 keywords 数量或返回 1(至少匹配一次)
38
+ if (result.keywords && Array.isArray(result.keywords)) {
39
+ return result.keywords.length;
40
+ }
41
+ return 1;
42
+ }
43
+ // 辅助函数:获取指定 intent 和 level 的阈值
44
+ function getThreshold(intent, level) {
45
+ return CONFIDENCE_THRESHOLDS[intent][level];
46
+ }
47
+ // 核心函数:计算置信度
48
+ export function calculateConfidence(results, intent) {
49
+ const reasons = [];
50
+ // 1. 结果数量评分 (40%权重)
51
+ // 最高5个结果得满分,按比例递减
52
+ const countScore = Math.min(results.length / 5, 1);
53
+ const countWeight = 0.4;
54
+ if (results.length === 0) {
55
+ reasons.push('未找到任何结果');
56
+ }
57
+ else if (results.length <= 5) {
58
+ reasons.push(`找到 ${results.length} 个相关结果`);
59
+ }
60
+ else {
61
+ reasons.push(`找到 ${results.length} 个相关结果(超出最优数量)`);
62
+ }
63
+ // 2. 结果质量评分 (40%权重)
64
+ // 基于结果平均相关度
65
+ let qualityScore = 0;
66
+ if (results.length > 0) {
67
+ const totalRelevance = results.reduce((sum, r) => sum + getRelevance(r), 0);
68
+ qualityScore = totalRelevance / results.length;
69
+ }
70
+ const qualityWeight = 0.4;
71
+ if (results.length > 0) {
72
+ const avgRelevance = Math.round(qualityScore * 100);
73
+ reasons.push(`平均相关度 ${avgRelevance}%`);
74
+ }
75
+ // 3. 场景匹配评分 (20%权重)
76
+ // 基于 intent 类型的特定规则
77
+ let scenarioScore = 0.5; // 默认中等
78
+ switch (intent) {
79
+ case 'search':
80
+ // search 对数量敏感
81
+ scenarioScore = results.length >= 3 ? 0.8 : results.length > 0 ? 0.5 : 0.2;
82
+ break;
83
+ case 'impact':
84
+ case 'dependency':
85
+ // impact/dependency 对质量敏感
86
+ scenarioScore = qualityScore >= 0.7 ? 0.9 : qualityScore >= 0.4 ? 0.6 : 0.3;
87
+ break;
88
+ case 'documentation':
89
+ // documentation 宽松一些
90
+ scenarioScore = results.length > 0 ? 0.7 : 0.3;
91
+ break;
92
+ case 'overview':
93
+ // overview 需要更多结果
94
+ scenarioScore = results.length >= 5 ? 0.9 : results.length >= 3 ? 0.6 : 0.3;
95
+ break;
96
+ case 'complexity':
97
+ // complexity 依赖质量
98
+ scenarioScore = qualityScore >= 0.6 ? 0.85 : 0.4;
99
+ break;
100
+ case 'refactor':
101
+ // refactor 需要高质量结果
102
+ scenarioScore = qualityScore >= 0.7 && results.length >= 2 ? 0.8 : 0.4;
103
+ break;
104
+ case 'reference':
105
+ // reference 适中
106
+ scenarioScore = results.length >= 2 && qualityScore >= 0.5 ? 0.75 : 0.4;
107
+ break;
108
+ default:
109
+ scenarioScore = 0.5;
110
+ }
111
+ const scenarioWeight = 0.2;
112
+ reasons.push(`场景 '${intent}' 匹配度评估完成`);
113
+ // 计算综合分数
114
+ const rawScore = countScore * countWeight +
115
+ qualityScore * qualityWeight +
116
+ scenarioScore * scenarioWeight;
117
+ // 限制在 [0, 1] 范围
118
+ const score = clamp(rawScore, 0, 1);
119
+ // 确定置信度级别
120
+ const highThreshold = getThreshold(intent, 'high');
121
+ const mediumThreshold = getThreshold(intent, 'medium');
122
+ let level;
123
+ if (score >= highThreshold) {
124
+ level = 'high';
125
+ reasons.push(`置信度 ${Math.round(score * 100)}% 达到高级阈值 (${Math.round(highThreshold * 100)}%)`);
126
+ }
127
+ else if (score >= mediumThreshold) {
128
+ level = 'medium';
129
+ reasons.push(`置信度 ${Math.round(score * 100)}% 达到中级阈值 (${Math.round(mediumThreshold * 100)}%)`);
130
+ }
131
+ else {
132
+ level = 'low';
133
+ reasons.push(`置信度 ${Math.round(score * 100)}% 低于中级阈值 (${Math.round(mediumThreshold * 100)}%),建议调整关键词`);
134
+ }
135
+ return { score, level, reasons };
136
+ }
137
+ export { CONFIDENCE_THRESHOLDS, getThreshold, getRelevance, getMatchCount, clamp };
138
+ //# sourceMappingURL=confidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidence.js","sourceRoot":"","sources":["../../src/orchestrator/confidence.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8EAA8E;AAC9E,4FAA4F;AAwB5F,kBAAkB;AAClB,MAAM,qBAAqB,GAAyD;IAClF,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAClC,UAAU,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACtC,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IACnC,aAAa,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAC1C,UAAU,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACt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C;QACN,KAAK,GAAG,KAAK,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC;IACzG,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC;AAID,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * [META] 文件头注释扫描器
3
+ * [WHY] 为 pre-commit 与 CI 提供统一的 [META]/[WHY] 校验逻辑
4
+ */
5
+ export declare const SUPPORTED_EXTENSIONS: string[];
6
+ export interface FileHeaderResult {
7
+ filePath: string;
8
+ valid: boolean;
9
+ errorCode?: 'E0008' | 'E0009';
10
+ errorMessage?: string;
11
+ hasMeta: boolean;
12
+ hasWhy: boolean;
13
+ }
14
+ export interface ScanOptions {
15
+ directory: string;
16
+ }
17
+ /**
18
+ * 扫描文件头注释
19
+ * @param filePath - 文件路径
20
+ * @returns 扫描结果
21
+ */
22
+ export declare function scanFileHeader(filePath: string): FileHeaderResult;
23
+ /**
24
+ * 扫描目录下的所有支持的文件
25
+ * @param options - 扫描选项
26
+ * @returns 扫描结果数组
27
+ */
28
+ export declare function scanDirectory(options: ScanOptions): FileHeaderResult[];
29
+ /**
30
+ * 验证并输出结果到控制台
31
+ */
32
+ export declare function scanAndPrint(directory: string): void;
33
+ /**
34
+ * 评估危险置信度
35
+ * 基于代码变更的风险级别进行评估
36
+ */
37
+ export interface RiskAssessment {
38
+ level: 'low' | 'medium' | 'high' | 'critical';
39
+ confidence: number;
40
+ factors: string[];
41
+ }
42
+ /**
43
+ * 评估代码变更的风险
44
+ * @param changedFiles - 变更的文件列表
45
+ * @returns 风险评估结果
46
+ */
47
+ export declare function assessRisk(changedFiles: string[]): RiskAssessment;
48
+ //# sourceMappingURL=file-header-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-header-scanner.d.ts","sourceRoot":"","sources":["../../src/orchestrator/file-header-scanner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,eAAO,MAAM,oBAAoB,UAAiD,CAAC;AAEnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AASD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,GACf,gBAAgB,CAqClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,gBAAgB,EAAE,CA+BtE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAqBpD;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,cAAc,CA0CjE"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * [META] 文件头注释扫描器
3
+ * [WHY] 为 pre-commit 与 CI 提供统一的 [META]/[WHY] 校验逻辑
4
+ */
5
+ import { readFileSync, readdirSync, statSync } from 'fs';
6
+ import { join, extname } from 'path';
7
+ export const SUPPORTED_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
8
+ const DEFAULT_HIGH_RISK_PATTERNS = [
9
+ /\/orchestrator\//,
10
+ /\/core\//,
11
+ /\/types\//,
12
+ /\.test\.|\.spec\./,
13
+ ];
14
+ /**
15
+ * 扫描文件头注释
16
+ * @param filePath - 文件路径
17
+ * @returns 扫描结果
18
+ */
19
+ export function scanFileHeader(filePath) {
20
+ const content = readFileSync(filePath, 'utf-8');
21
+ const lines = content.split('\n').slice(0, 20); // 只检查前 20 行
22
+ const hasMeta = /\[META\]/i.test(lines.join('\n'));
23
+ const hasWhy = /\[WHY\]/i.test(lines.join('\n'));
24
+ // 通用检查:必须有 [META]
25
+ if (!hasMeta) {
26
+ return {
27
+ filePath,
28
+ valid: false,
29
+ errorCode: 'E0008',
30
+ errorMessage: 'File header missing [META] comment. Add [META] metadata in the first 20 lines.',
31
+ hasMeta: false,
32
+ hasWhy,
33
+ };
34
+ }
35
+ // 通用检查:必须有 [WHY]
36
+ if (!hasWhy) {
37
+ return {
38
+ filePath,
39
+ valid: false,
40
+ errorCode: 'E0009',
41
+ errorMessage: 'File header missing [WHY] comment. Explain why this file exists in the first 20 lines.',
42
+ hasMeta,
43
+ hasWhy: false,
44
+ };
45
+ }
46
+ return {
47
+ filePath,
48
+ valid: true,
49
+ hasMeta,
50
+ hasWhy,
51
+ };
52
+ }
53
+ /**
54
+ * 扫描目录下的所有支持的文件
55
+ * @param options - 扫描选项
56
+ * @returns 扫描结果数组
57
+ */
58
+ export function scanDirectory(options) {
59
+ const { directory } = options;
60
+ const results = [];
61
+ function walkDir(dir) {
62
+ const entries = readdirSync(dir);
63
+ for (const entry of entries) {
64
+ const fullPath = join(dir, entry);
65
+ const stat = statSync(fullPath);
66
+ // 跳过 node_modules, .git 等目录
67
+ if (stat.isDirectory()) {
68
+ if (entry.startsWith('.') && entry !== '.')
69
+ continue;
70
+ if (entry === 'node_modules')
71
+ continue;
72
+ if (entry === 'dist' || entry === 'build')
73
+ continue;
74
+ if (entry === '__tests__' || entry === 'test')
75
+ continue;
76
+ walkDir(fullPath);
77
+ }
78
+ else if (stat.isFile()) {
79
+ const ext = extname(fullPath);
80
+ if (SUPPORTED_EXTENSIONS.includes(ext)) {
81
+ const result = scanFileHeader(fullPath);
82
+ results.push(result);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ walkDir(directory);
88
+ return results;
89
+ }
90
+ /**
91
+ * 验证并输出结果到控制台
92
+ */
93
+ export function scanAndPrint(directory) {
94
+ const results = scanDirectory({ directory });
95
+ let hasErrors = false;
96
+ for (const result of results) {
97
+ if (result.valid) {
98
+ console.log(`PASS ${result.filePath}: OK [META: ${result.hasMeta}, WHY: ${result.hasWhy}]`);
99
+ }
100
+ else {
101
+ console.error(`ERROR ${result.errorCode}: ${result.filePath}`);
102
+ console.error(` ${result.errorMessage}`);
103
+ hasErrors = true;
104
+ }
105
+ }
106
+ const total = results.length;
107
+ const valid = results.filter((r) => r.valid).length;
108
+ console.log(`\nTotal: ${total}, Valid: ${valid}, Invalid: ${total - valid}`);
109
+ if (hasErrors) {
110
+ process.exit(1);
111
+ }
112
+ }
113
+ /**
114
+ * 评估代码变更的风险
115
+ * @param changedFiles - 变更的文件列表
116
+ * @returns 风险评估结果
117
+ */
118
+ export function assessRisk(changedFiles) {
119
+ const factors = [];
120
+ let riskScore = 0;
121
+ for (const file of changedFiles) {
122
+ // 检查是否是高风险文件
123
+ if (DEFAULT_HIGH_RISK_PATTERNS.some((p) => p.test(file))) {
124
+ riskScore += 2;
125
+ factors.push(`High-risk file modified: ${file}`);
126
+ }
127
+ // 检查是否是测试文件
128
+ if (/\.test\.|\.spec\./.test(file)) {
129
+ riskScore += 1;
130
+ factors.push(`Test file modified: ${file}`);
131
+ }
132
+ // 检查是否是配置文件
133
+ if (/config|\.json$|\.yaml$|\.yml$/.test(file)) {
134
+ riskScore += 1;
135
+ factors.push(`Config file modified: ${file}`);
136
+ }
137
+ }
138
+ let level;
139
+ let confidence;
140
+ if (riskScore >= 10) {
141
+ level = 'critical';
142
+ confidence = 0.95;
143
+ }
144
+ else if (riskScore >= 5) {
145
+ level = 'high';
146
+ confidence = 0.8;
147
+ }
148
+ else if (riskScore >= 2) {
149
+ level = 'medium';
150
+ confidence = 0.6;
151
+ }
152
+ else {
153
+ level = 'low';
154
+ confidence = 0.3;
155
+ }
156
+ return { level, confidence, factors };
157
+ }
158
+ //# sourceMappingURL=file-header-scanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-header-scanner.js","sourceRoot":"","sources":["../../src/orchestrator/file-header-scanner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAY,MAAM,MAAM,CAAC;AAE/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAenF,MAAM,0BAA0B,GAAG;IACjC,kBAAkB;IAClB,UAAU;IACV,WAAW;IACX,mBAAmB;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAgB;IAEhB,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY;IAE5D,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,kBAAkB;IAClB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;YACL,QAAQ;Y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