@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,70 @@
1
+ /**
2
+ * 文件变更事件
3
+ */
4
+ export interface FileChangeEvent {
5
+ type: 'add' | 'change' | 'unlink';
6
+ filePath: string;
7
+ timestamp: number;
8
+ }
9
+ /**
10
+ * File Watcher 配置
11
+ */
12
+ export interface FileWatcherConfig {
13
+ /** 监听目录 */
14
+ rootDir: string;
15
+ /** 监听模式 */
16
+ glob?: string[];
17
+ /** 忽略模式 */
18
+ ignored?: RegExp[];
19
+ /** 防抖延迟(毫秒) */
20
+ debounceDelay?: number;
21
+ /** 稳定性阈值(毫秒) */
22
+ stabilityThreshold?: number;
23
+ }
24
+ /**
25
+ * 文件变更处理器
26
+ */
27
+ export type FileChangeHandler = (event: FileChangeEvent) => void | Promise<void>;
28
+ /**
29
+ * File Watcher - 文件监控系统
30
+ */
31
+ export declare class FileWatcher {
32
+ private watcher;
33
+ private config;
34
+ private handlers;
35
+ private debounceTimer;
36
+ private pendingEvents;
37
+ constructor(config: FileWatcherConfig);
38
+ /**
39
+ * 添加变更处理器
40
+ */
41
+ onChange(handler: FileChangeHandler): void;
42
+ /**
43
+ * 启动文件监控
44
+ */
45
+ start(): Promise<void>;
46
+ /**
47
+ * 停止文件监控
48
+ */
49
+ stop(): Promise<void>;
50
+ /**
51
+ * 处理文件变更事件
52
+ */
53
+ private handleEvent;
54
+ /**
55
+ * 刷新待处理事件
56
+ */
57
+ private flushEvents;
58
+ /**
59
+ * 获取监控状态
60
+ */
61
+ getStatus(): {
62
+ watching: boolean;
63
+ watchedPaths: number;
64
+ };
65
+ }
66
+ /**
67
+ * 创建 FileWatcher 实例
68
+ */
69
+ export declare function createFileWatcher(config: FileWatcherConfig): FileWatcher;
70
+ //# sourceMappingURL=file-watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-watcher.d.ts","sourceRoot":"","sources":["../../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iBAAiB,GAAG,WAAW,CAExE"}
@@ -0,0 +1,127 @@
1
+ // ============================================
2
+ // File Watcher - 文件监控
3
+ // ============================================
4
+ import chokidar from 'chokidar';
5
+ import * as path from 'path';
6
+ /**
7
+ * File Watcher - 文件监控系统
8
+ */
9
+ export class FileWatcher {
10
+ watcher = null;
11
+ config;
12
+ handlers = [];
13
+ debounceTimer = null;
14
+ pendingEvents = new Map();
15
+ constructor(config) {
16
+ this.config = {
17
+ glob: ['src/**/*.ts'],
18
+ ignored: [/(^|[\/\\])\../, /node_modules/],
19
+ debounceDelay: 1000,
20
+ stabilityThreshold: 500,
21
+ ...config
22
+ };
23
+ }
24
+ /**
25
+ * 添加变更处理器
26
+ */
27
+ onChange(handler) {
28
+ this.handlers.push(handler);
29
+ }
30
+ /**
31
+ * 启动文件监控
32
+ */
33
+ async start() {
34
+ if (this.watcher) {
35
+ throw new Error('FileWatcher 已在运行');
36
+ }
37
+ const glob = this.config.glob || ['**/*.ts'];
38
+ this.watcher = chokidar.watch(glob, {
39
+ cwd: this.config.rootDir,
40
+ ignored: this.config.ignored,
41
+ persistent: true,
42
+ ignoreInitial: true,
43
+ awaitWriteFinish: {
44
+ stabilityThreshold: this.config.stabilityThreshold || 500,
45
+ pollInterval: 100
46
+ }
47
+ });
48
+ this.watcher
49
+ .on('add', (relativePath) => this.handleEvent('add', relativePath))
50
+ .on('change', (relativePath) => this.handleEvent('change', relativePath))
51
+ .on('unlink', (relativePath) => this.handleEvent('unlink', relativePath));
52
+ // 等待监控就绪
53
+ await new Promise((resolve) => {
54
+ this.watcher.on('ready', () => resolve());
55
+ });
56
+ }
57
+ /**
58
+ * 停止文件监控
59
+ */
60
+ async stop() {
61
+ if (this.watcher) {
62
+ await this.watcher.close();
63
+ this.watcher = null;
64
+ }
65
+ if (this.debounceTimer) {
66
+ clearTimeout(this.debounceTimer);
67
+ this.debounceTimer = null;
68
+ }
69
+ this.pendingEvents.clear();
70
+ }
71
+ /**
72
+ * 处理文件变更事件
73
+ */
74
+ handleEvent(type, relativePath) {
75
+ const absolutePath = path.resolve(this.config.rootDir, relativePath);
76
+ const event = {
77
+ type,
78
+ filePath: absolutePath,
79
+ timestamp: Date.now()
80
+ };
81
+ // 更新待处理事件
82
+ this.pendingEvents.set(relativePath, event);
83
+ // 防抖处理
84
+ if (this.debounceTimer) {
85
+ clearTimeout(this.debounceTimer);
86
+ }
87
+ this.debounceTimer = setTimeout(() => {
88
+ this.flushEvents();
89
+ }, this.config.debounceDelay);
90
+ }
91
+ /**
92
+ * 刷新待处理事件
93
+ */
94
+ flushEvents() {
95
+ for (const event of this.pendingEvents.values()) {
96
+ // 执行所有处理器
97
+ for (const handler of this.handlers) {
98
+ try {
99
+ const result = handler(event);
100
+ if (result instanceof Promise) {
101
+ result.catch(console.error);
102
+ }
103
+ }
104
+ catch (error) {
105
+ console.error('FileChangeHandler error:', error);
106
+ }
107
+ }
108
+ }
109
+ this.pendingEvents.clear();
110
+ }
111
+ /**
112
+ * 获取监控状态
113
+ */
114
+ getStatus() {
115
+ return {
116
+ watching: this.watcher !== null,
117
+ watchedPaths: this.watcher ? this.watcher._watched?.size || 0 : 0
118
+ };
119
+ }
120
+ }
121
+ /**
122
+ * 创建 FileWatcher 实例
123
+ */
124
+ export function createFileWatcher(config) {
125
+ return new FileWatcher(config);
126
+ }
127
+ //# sourceMappingURL=file-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-watcher.js","sourceRoot":"","sources":["../../src/watcher/file-watcher.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,sBAAsB;AACtB,+CAA+C;AAE/C,OAAO,QAAuB,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAgC7B;;GAEG;AACH,MAAM,OAAO,WAAW;IACd,OAAO,GAAqB,IAAI,CAAC;IACjC,MAAM,CAAoB;IAC1B,QAAQ,GAAwB,EAAE,CAAC;IACnC,aAAa,GAA0B,IAAI,CAAC;IAC5C,aA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C;QACrB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACK,WAAW;QACjB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;YAChD,UAAU;YACV,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACpC,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC9B,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;wBAC9B,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,OAAO,KAAK,IAAI;YAC/B,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,IAAI,CAAC,OAAe,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3E,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IACzD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { WatchDaemon, createWatchDaemon } from './daemon.js';
2
+ export type { WatchDaemonConfig, WatchDaemonStatus } from './daemon.js';
3
+ export { FileWatcher, createFileWatcher } from './file-watcher.js';
4
+ export type { FileWatcherConfig, FileChangeEvent, FileChangeHandler } from './file-watcher.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,6 @@
1
+ // ============================================
2
+ // Watcher Module - 文件监控和守护进程
3
+ // ============================================
4
+ export { WatchDaemon, createWatchDaemon } from './daemon.js';
5
+ export { FileWatcher, createFileWatcher } from './file-watcher.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,6BAA6B;AAC7B,+CAA+C;AAE/C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=watch-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-worker.d.ts","sourceRoot":"","sources":["../../src/watcher/watch-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,57 @@
1
+ // ============================================
2
+ // Watcher Worker - 后台工作进程
3
+ // ============================================
4
+ import { analyze } from '../core/analyzer.js';
5
+ import { generateAIMap, generateJSON, generateContext } from '../generator/index.js';
6
+ let config = null;
7
+ /**
8
+ * 运行分析
9
+ */
10
+ async function runAnalysis() {
11
+ if (!config) {
12
+ console.error('[Worker] 配置未初始化');
13
+ return;
14
+ }
15
+ console.log('[Worker] 开始分析...');
16
+ try {
17
+ const analysisOptions = {
18
+ mode: config.mode,
19
+ rootDir: config.rootDir,
20
+ output: config.outputDir
21
+ };
22
+ const codeMap = await analyze(analysisOptions);
23
+ await generateAIMap(codeMap, config.outputDir);
24
+ await generateJSON(codeMap, config.outputDir);
25
+ await generateContext(codeMap, config.outputDir);
26
+ console.log(`[Worker] 分析完成: ${codeMap.summary.totalFiles} 个文件`);
27
+ }
28
+ catch (error) {
29
+ console.error('[Worker] 分析失败:', error);
30
+ }
31
+ }
32
+ // 监听进程消息
33
+ process.on('message', async (message) => {
34
+ switch (message.type) {
35
+ case 'config':
36
+ config = message.payload;
37
+ console.log('[Worker] 配置已接收:', config);
38
+ // 初始分析
39
+ await runAnalysis();
40
+ break;
41
+ case 'trigger':
42
+ console.log('[Worker] 收到触发消息');
43
+ await runAnalysis();
44
+ break;
45
+ }
46
+ });
47
+ // 优雅退出
48
+ process.on('SIGTERM', () => {
49
+ console.log('[Worker] 收到 SIGTERM,正在退出...');
50
+ process.exit(0);
51
+ });
52
+ process.on('SIGINT', () => {
53
+ console.log('[Worker] 收到 SIGINT,正在退出...');
54
+ process.exit(0);
55
+ });
56
+ console.log('[Worker] 工作进程已启动,PID:', process.pid);
57
+ //# sourceMappingURL=watch-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-worker.js","sourceRoot":"","sources":["../../src/watcher/watch-worker.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,0BAA0B;AAC1B,+CAA+C;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAoBrF,IAAI,MAAM,GAAwB,IAAI,CAAC;AAEvC;;GAEG;AACH,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACjC,OAAO;IACT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CAAC,6BAA6B,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,76 @@
1
+ interface ParseTask {
2
+ filePath: string;
3
+ rootDir: string;
4
+ parserType: 'fast' | 'smart' | 'tree-sitter';
5
+ }
6
+ interface WorkerResult {
7
+ path: string;
8
+ exports: any[];
9
+ imports: any[];
10
+ symbols: any[];
11
+ dependencies: string[];
12
+ type: 'source' | 'test' | 'config' | 'type';
13
+ stats: {
14
+ lines: number;
15
+ codeLines: number;
16
+ commentLines: number;
17
+ blankLines: number;
18
+ };
19
+ error?: string;
20
+ }
21
+ export interface WorkerPoolConfig {
22
+ /** 线程数,默认 CPU 核心数 */
23
+ size?: number;
24
+ /** 单个任务超时时间(毫秒),默认 30000 */
25
+ timeout?: number;
26
+ }
27
+ export declare class WorkerPool {
28
+ private workers;
29
+ private taskQueue;
30
+ private activeWorkers;
31
+ private config;
32
+ private workerPath;
33
+ constructor(config?: WorkerPoolConfig);
34
+ /**
35
+ * 初始化线程池
36
+ */
37
+ initialize(): Promise<void>;
38
+ /**
39
+ * 创建 worker
40
+ */
41
+ private createWorker;
42
+ /**
43
+ * 执行解析任务
44
+ */
45
+ parse(task: ParseTask): Promise<WorkerResult>;
46
+ /**
47
+ * 批量解析(并行)
48
+ */
49
+ parseBatch(tasks: ParseTask[]): Promise<WorkerResult[]>;
50
+ /**
51
+ * 批量解析(带并发控制)
52
+ */
53
+ parseBatchWithConcurrency(tasks: ParseTask[], concurrency?: number): Promise<WorkerResult[]>;
54
+ /**
55
+ * 关闭线程池
56
+ */
57
+ terminate(): Promise<void>;
58
+ /**
59
+ * 获取池状态
60
+ */
61
+ getStatus(): {
62
+ size: number;
63
+ active: number;
64
+ queued: number;
65
+ };
66
+ }
67
+ /**
68
+ * 获取 Worker 线程池单例
69
+ */
70
+ export declare function getWorkerPool(config?: WorkerPoolConfig): WorkerPool;
71
+ /**
72
+ * 关闭 Worker 线程池
73
+ */
74
+ export declare function terminateWorkerPool(): Promise<void>;
75
+ export {};
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAUA,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;CAC9C;AAGD,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC5C,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,SAAS,CAIT;IACR,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,GAAE,gBAAqB;IAYzC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC;;OAEG;YACW,YAAY;IA6B1B;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IA0BnD;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAQ7D;;OAEG;IACG,yBAAyB,CAC7B,KAAK,EAAE,SAAS,EAAE,EAClB,WAAW,GAAE,MAAyB,GACrC,OAAO,CAAC,YAAY,EAAE,CAAC;IAyB1B;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAQhC;;OAEG;IACH,SAAS,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAO9D;AAKD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAKnE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKzD"}
@@ -0,0 +1,155 @@
1
+ // ============================================
2
+ // Worker Thread Pool - 线程池管理器
3
+ // ============================================
4
+ import { Worker } from 'worker_threads';
5
+ import * as path from 'path';
6
+ import * as os from 'os';
7
+ // 线程池类
8
+ export class WorkerPool {
9
+ workers = [];
10
+ taskQueue = [];
11
+ activeWorkers = new Set();
12
+ config;
13
+ workerPath;
14
+ constructor(config = {}) {
15
+ // 默认使用 CPU 核心数,但最多 8 个
16
+ const cpuCount = os.cpus().length;
17
+ this.config = {
18
+ size: Math.min(config.size || cpuCount, 8),
19
+ timeout: config.timeout || 30000
20
+ };
21
+ // 设置 worker 脚本路径
22
+ this.workerPath = path.join(__dirname, 'parse-worker.js');
23
+ }
24
+ /**
25
+ * 初始化线程池
26
+ */
27
+ async initialize() {
28
+ // 预创建 worker
29
+ const promises = [];
30
+ for (let i = 0; i < this.config.size; i++) {
31
+ promises.push(this.createWorker());
32
+ }
33
+ await Promise.all(promises);
34
+ }
35
+ /**
36
+ * 创建 worker
37
+ */
38
+ async createWorker() {
39
+ return new Promise((resolve, reject) => {
40
+ try {
41
+ const worker = new Worker(this.workerPath);
42
+ worker.on('online', () => {
43
+ this.workers.push(worker);
44
+ resolve();
45
+ });
46
+ worker.on('error', (error) => {
47
+ console.error('Worker error:', error);
48
+ this.workers = this.workers.filter(w => w !== worker);
49
+ this.activeWorkers.delete(worker);
50
+ });
51
+ worker.on('exit', (code) => {
52
+ if (code !== 0) {
53
+ console.error(`Worker exited with code ${code}`);
54
+ }
55
+ this.workers = this.workers.filter(w => w !== worker);
56
+ this.activeWorkers.delete(worker);
57
+ });
58
+ }
59
+ catch (error) {
60
+ reject(error);
61
+ }
62
+ });
63
+ }
64
+ /**
65
+ * 执行解析任务
66
+ */
67
+ async parse(task) {
68
+ // 如果没有可用的 worker,等待
69
+ if (this.workers.length === 0) {
70
+ // 创建一个临时 worker
71
+ await this.createWorker();
72
+ }
73
+ // 获取一个可用的 worker
74
+ const worker = this.workers[0];
75
+ return new Promise((resolve, reject) => {
76
+ const timeout = setTimeout(() => {
77
+ reject(new Error(`Task timeout: ${task.filePath}`));
78
+ }, this.config.timeout);
79
+ const messageHandler = (result) => {
80
+ clearTimeout(timeout);
81
+ worker.removeListener('message', messageHandler);
82
+ resolve(result);
83
+ };
84
+ worker.once('message', messageHandler);
85
+ worker.postMessage(task);
86
+ });
87
+ }
88
+ /**
89
+ * 批量解析(并行)
90
+ */
91
+ async parseBatch(tasks) {
92
+ // 使用所有可用的 worker 并行处理
93
+ const results = await Promise.all(tasks.map(task => this.parse(task)));
94
+ return results;
95
+ }
96
+ /**
97
+ * 批量解析(带并发控制)
98
+ */
99
+ async parseBatchWithConcurrency(tasks, concurrency = this.config.size) {
100
+ const results = [];
101
+ const executing = [];
102
+ for (const task of tasks) {
103
+ const promise = this.parse(task).then(result => {
104
+ results.push(result);
105
+ });
106
+ executing.push(promise);
107
+ if (executing.length >= concurrency) {
108
+ await Promise.race(executing);
109
+ // 移除已完成的
110
+ executing.splice(executing.findIndex(p => p.status === 'fulfilled'), 1);
111
+ }
112
+ }
113
+ await Promise.allSettled(executing);
114
+ return results;
115
+ }
116
+ /**
117
+ * 关闭线程池
118
+ */
119
+ async terminate() {
120
+ await Promise.all(this.workers.map(worker => worker.terminate()));
121
+ this.workers = [];
122
+ this.activeWorkers.clear();
123
+ }
124
+ /**
125
+ * 获取池状态
126
+ */
127
+ getStatus() {
128
+ return {
129
+ size: this.workers.length,
130
+ active: this.activeWorkers.size,
131
+ queued: this.taskQueue.length
132
+ };
133
+ }
134
+ }
135
+ // 单例实例
136
+ let workerPoolInstance = null;
137
+ /**
138
+ * 获取 Worker 线程池单例
139
+ */
140
+ export function getWorkerPool(config) {
141
+ if (!workerPoolInstance) {
142
+ workerPoolInstance = new WorkerPool(config);
143
+ }
144
+ return workerPoolInstance;
145
+ }
146
+ /**
147
+ * 关闭 Worker 线程池
148
+ */
149
+ export async function terminateWorkerPool() {
150
+ if (workerPoolInstance) {
151
+ await workerPoolInstance.terminate();
152
+ workerPoolInstance = null;
153
+ }
154
+ }
155
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,8BAA8B;AAC9B,+CAA+C;AAE/C,OAAO,EAAE,MAAM,EAAwC,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAmCzB,OAAO;AACP,MAAM,OAAO,UAAU;IACb,OAAO,GAAa,EAA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CAAC;IAC5B,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parse-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-worker.d.ts","sourceRoot":"","sources":["../../src/worker/parse-worker.ts"],"names":[],"mappings":""}