claude-flow-novice 2.0.3 → 2.0.4

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 (272) hide show
  1. package/dist/src/cli/commands/guidance.js +487 -668
  2. package/dist/src/cli/commands/index-validate.js +18 -29
  3. package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
  4. package/dist/src/cli/commands/neural-goal-init.js +92 -125
  5. package/dist/src/cli/commands/swarm-exec.js +317 -393
  6. package/dist/src/cli/commands/swarm.js +1 -1
  7. package/dist/src/cli/commands/validate-framework.js +983 -1100
  8. package/dist/src/cli/commands/validate.js +144 -223
  9. package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
  10. package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
  11. package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
  12. package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
  13. package/dist/src/cli/simple-commands/agent.js +157 -193
  14. package/dist/src/cli/simple-commands/analysis.js +336 -446
  15. package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
  16. package/dist/src/cli/simple-commands/automation.js +481 -469
  17. package/dist/src/cli/simple-commands/batch-manager.js +261 -313
  18. package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
  19. package/dist/src/cli/simple-commands/claude-track.js +68 -90
  20. package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
  21. package/dist/src/cli/simple-commands/config.js +245 -290
  22. package/dist/src/cli/simple-commands/coordination.js +182 -234
  23. package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
  24. package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
  25. package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
  26. package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
  27. package/dist/src/cli/simple-commands/github/github-api.js +535 -574
  28. package/dist/src/cli/simple-commands/github/init.js +276 -303
  29. package/dist/src/cli/simple-commands/github.js +222 -247
  30. package/dist/src/cli/simple-commands/goal.js +51 -63
  31. package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
  32. package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
  33. package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
  34. package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
  35. package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
  36. package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
  37. package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
  38. package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
  39. package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
  40. package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
  41. package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
  42. package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
  43. package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
  44. package/dist/src/cli/simple-commands/hive.js +90 -79
  45. package/dist/src/cli/simple-commands/hook-safety.js +431 -521
  46. package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
  47. package/dist/src/cli/simple-commands/hooks.js +1064 -1204
  48. package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
  49. package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
  50. package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
  51. package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
  52. package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
  53. package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
  54. package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
  55. package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
  56. package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
  57. package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
  58. package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
  59. package/dist/src/cli/simple-commands/init/help.js +104 -107
  60. package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
  61. package/dist/src/cli/simple-commands/init/index.js +1510 -1759
  62. package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
  63. package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
  64. package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
  65. package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
  66. package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
  67. package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
  68. package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
  69. package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
  70. package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
  71. package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
  72. package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
  73. package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
  74. package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
  75. package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
  76. package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
  77. package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
  78. package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
  79. package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
  80. package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
  81. package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
  82. package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
  83. package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
  84. package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
  85. package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
  86. package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
  87. package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
  88. package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
  89. package/dist/src/cli/simple-commands/init.js +1 -2
  90. package/dist/src/cli/simple-commands/mcp-health.js +131 -158
  91. package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
  92. package/dist/src/cli/simple-commands/mcp.js +345 -400
  93. package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
  94. package/dist/src/cli/simple-commands/memory.js +247 -311
  95. package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
  96. package/dist/src/cli/simple-commands/monitor.js +294 -363
  97. package/dist/src/cli/simple-commands/neural.js +51 -65
  98. package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
  99. package/dist/src/cli/simple-commands/pair-basic.js +528 -656
  100. package/dist/src/cli/simple-commands/pair-old.js +430 -543
  101. package/dist/src/cli/simple-commands/pair-working.js +615 -751
  102. package/dist/src/cli/simple-commands/pair.js +615 -751
  103. package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
  104. package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
  105. package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
  106. package/dist/src/cli/simple-commands/process-ui.js +230 -254
  107. package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
  108. package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
  109. package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
  110. package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
  111. package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
  112. package/dist/src/cli/simple-commands/sparc/index.js +241 -298
  113. package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
  114. package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
  115. package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
  116. package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
  117. package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
  118. package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
  119. package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
  120. package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
  121. package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
  122. package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
  123. package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
  124. package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
  125. package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
  126. package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
  127. package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
  128. package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
  129. package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
  130. package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
  131. package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
  132. package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
  133. package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
  134. package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
  135. package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
  136. package/dist/src/cli/simple-commands/sparc.js +465 -493
  137. package/dist/src/cli/simple-commands/start-ui.js +108 -132
  138. package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
  139. package/dist/src/cli/simple-commands/start.js +1 -1
  140. package/dist/src/cli/simple-commands/status.js +254 -275
  141. package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
  142. package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
  143. package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
  144. package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
  145. package/dist/src/cli/simple-commands/stream-chain.js +260 -318
  146. package/dist/src/cli/simple-commands/stream-processor.js +290 -315
  147. package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
  148. package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
  149. package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
  150. package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
  151. package/dist/src/cli/simple-commands/swarm.js +887 -1082
  152. package/dist/src/cli/simple-commands/task.js +161 -206
  153. package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
  154. package/dist/src/cli/simple-commands/token-tracker.js +258 -316
  155. package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
  156. package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
  157. package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
  158. package/dist/src/cli/simple-commands/training.js +170 -227
  159. package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
  160. package/dist/src/cli/simple-commands/verification-integration.js +389 -417
  161. package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
  162. package/dist/src/cli/simple-commands/verification.js +493 -513
  163. package/dist/src/cli/simple-commands/web-server.js +766 -836
  164. package/dist/src/cli/simple-commands/webui-validator.js +106 -124
  165. package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
  166. package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
  167. package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
  168. package/dist/src/coordination/iteration-tracker.js +363 -454
  169. package/dist/src/enterprise/analytics-manager.js +1135 -0
  170. package/dist/src/enterprise/audit-manager.js +1115 -0
  171. package/dist/src/enterprise/cloud-manager.js +891 -0
  172. package/dist/src/enterprise/deployment-manager.js +966 -0
  173. package/dist/src/enterprise/index.js +6 -0
  174. package/dist/src/enterprise/project-manager.js +584 -0
  175. package/dist/src/enterprise/security-manager.js +991 -0
  176. package/dist/src/index.js +1 -1
  177. package/dist/src/mcp/DEPRECATED.js +46 -60
  178. package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
  179. package/dist/src/mcp/implementations/agent-tracker.js +114 -128
  180. package/dist/src/mcp/implementations/daa-tools.js +292 -350
  181. package/dist/src/mcp/implementations/workflow-tools.js +329 -361
  182. package/dist/src/mcp/mcp-config-manager.js +1183 -1331
  183. package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
  184. package/dist/src/mcp/mcp-server-novice.js +11 -17
  185. package/dist/src/mcp/mcp-server-sdk.js +11 -17
  186. package/dist/src/mcp/mcp-server.js +1620 -1484
  187. package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
  188. package/dist/src/memory/advanced-serializer.js +609 -589
  189. package/dist/src/memory/enhanced-examples.js +220 -305
  190. package/dist/src/memory/enhanced-memory.js +295 -336
  191. package/dist/src/memory/enhanced-session-serializer.js +408 -492
  192. package/dist/src/memory/fallback-memory-system.js +900 -1021
  193. package/dist/src/memory/fallback-store.js +93 -131
  194. package/dist/src/memory/high-performance-serialization.js +592 -730
  195. package/dist/src/memory/in-memory-store.js +161 -213
  196. package/dist/src/memory/index.js +123 -157
  197. package/dist/src/memory/lock-free-structures.js +578 -764
  198. package/dist/src/memory/memory-mapped-persistence.js +585 -766
  199. package/dist/src/memory/memory-pressure-manager.js +569 -707
  200. package/dist/src/memory/migration.js +358 -445
  201. package/dist/src/memory/shared-memory.js +641 -768
  202. package/dist/src/memory/sqlite-store.js +245 -325
  203. package/dist/src/memory/sqlite-wrapper.js +122 -151
  204. package/dist/src/memory/swarm-memory.js +470 -603
  205. package/dist/src/memory/test-example.js +126 -134
  206. package/dist/src/memory/ultra-fast-memory-store.js +622 -821
  207. package/dist/src/memory/unified-memory-manager.js +356 -437
  208. package/dist/src/migration/index.js +92 -0
  209. package/dist/src/migration/logger.js +121 -0
  210. package/dist/src/migration/migration-analyzer.js +268 -0
  211. package/dist/src/migration/migration-runner.js +522 -0
  212. package/dist/src/migration/migration-validator.js +285 -0
  213. package/dist/src/migration/progress-reporter.js +150 -0
  214. package/dist/src/migration/rollback-manager.js +321 -0
  215. package/dist/src/migration/tests/migration-system.test.js +7 -0
  216. package/dist/src/migration/types.js +3 -0
  217. package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
  218. package/dist/src/swarm/__tests__/integration.test.js +227 -0
  219. package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
  220. package/dist/src/swarm/advanced-orchestrator.js +1095 -0
  221. package/dist/src/swarm/claude-code-interface.js +961 -0
  222. package/dist/src/swarm/claude-flow-executor.js +229 -0
  223. package/dist/src/swarm/consensus-coordinator.js +475 -0
  224. package/dist/src/swarm/coordinator.js +2993 -0
  225. package/dist/src/swarm/direct-executor.js +1180 -0
  226. package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
  227. package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
  228. package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
  229. package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
  230. package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
  231. package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
  232. package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
  233. package/dist/src/swarm/executor-v2.js +322 -0
  234. package/dist/src/swarm/executor.js +815 -0
  235. package/dist/src/swarm/hive-mind-integration.js +703 -0
  236. package/dist/src/swarm/index.js +41 -0
  237. package/dist/src/swarm/json-output-aggregator.js +267 -0
  238. package/dist/src/swarm/large-scale-coordinator.js +542 -0
  239. package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
  240. package/dist/src/swarm/memory.js +1117 -0
  241. package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
  242. package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
  243. package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
  244. package/dist/src/swarm/optimizations/connection-pool.js +244 -0
  245. package/dist/src/swarm/optimizations/index.js +28 -0
  246. package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
  247. package/dist/src/swarm/optimizations/ttl-map.js +234 -0
  248. package/dist/src/swarm/prompt-cli.js +200 -0
  249. package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
  250. package/dist/src/swarm/prompt-copier.js +381 -0
  251. package/dist/src/swarm/prompt-manager.js +295 -0
  252. package/dist/src/swarm/prompt-utils.js +310 -0
  253. package/dist/src/swarm/result-aggregator.js +718 -0
  254. package/dist/src/swarm/sparc-executor.js +1568 -0
  255. package/dist/src/swarm/strategies/auto.js +758 -0
  256. package/dist/src/swarm/strategies/base.js +128 -0
  257. package/dist/src/swarm/strategies/research.js +914 -0
  258. package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
  259. package/dist/src/swarm/types.js +52 -0
  260. package/dist/src/swarm/workers/copy-worker.js +56 -0
  261. package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
  262. package/dist/src/utils/github-cli-safe.js +56 -64
  263. package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
  264. package/dist/src/utils/npx-isolated-cache.js +104 -119
  265. package/dist/src/utils/preference-manager.js +622 -652
  266. package/dist/src/utils/timezone-utils.js +86 -105
  267. package/dist/src/validators/epic-config-schema.js +214 -0
  268. package/dist/src/validators/index.js +10 -0
  269. package/dist/src/validators/swarm-init-validator.js +259 -0
  270. package/dist/src/validators/todowrite-batching-validator.js +215 -0
  271. package/dist/src/validators/todowrite-integration.js +187 -0
  272. package/package.json +2 -2
@@ -4,621 +4,582 @@
4
4
  * Provides authentication, rate limiting, and API wrappers for GitHub workflow commands
5
5
  *
6
6
  * Enhanced with GitHub CLI Safety Wrapper for secure command execution
7
- */
8
-
9
- import { printSuccess, printError, printWarning, printInfo } from '../utils.js';
10
- import { githubCli, GitHubCliSafe } from '../../utils/github-cli-safety-wrapper.js';
11
-
7
+ */ import { printSuccess, printError, printWarning, printInfo } from "../utils.js";
8
+ import { GitHubCliSafe } from "../../utils/github-cli-safety-wrapper.js";
12
9
  // GitHub API Configuration
13
10
  const GITHUB_API_BASE = 'https://api.github.com';
14
11
  const GITHUB_RATE_LIMIT = 5000; // API calls per hour
15
12
  const GITHUB_WEBHOOK_SECRET = process.env.GITHUB_WEBHOOK_SECRET;
16
-
17
- class GitHubAPIClient {
18
- constructor(token = null) {
19
- this.token = token || process.env.GITHUB_TOKEN;
20
- this.rateLimitRemaining = GITHUB_RATE_LIMIT;
21
- this.rateLimitResetTime = null;
22
- this.lastRequestTime = 0;
23
- this.requestQueue = [];
24
- this.isProcessingQueue = false;
25
-
26
- // Initialize GitHub CLI safety wrapper
27
- this.cliSafe = new GitHubCliSafe({
28
- timeout: 60000, // 1 minute timeout for CLI operations
29
- maxRetries: 3,
30
- enableRateLimit: true,
31
- enableLogging: false, // Can be enabled for debugging
32
- });
33
- }
34
-
35
- /**
13
+ let GitHubAPIClient = class GitHubAPIClient {
14
+ /**
36
15
  * Authentication Methods
37
- */
38
- async authenticate(token = null) {
39
- if (token) {
40
- this.token = token;
41
- }
42
-
43
- if (!this.token) {
44
- printError('GitHub token not found. Set GITHUB_TOKEN environment variable or provide token.');
45
- return false;
46
- }
47
-
48
- try {
49
- const response = await this.request('/user');
50
- if (response.success) {
51
- printSuccess(`Authenticated as ${response.data.login}`);
52
- return true;
53
- }
54
- return false;
55
- } catch (error) {
56
- printError(`Authentication failed: ${error.message}`);
57
- return false;
58
- }
59
- }
60
-
61
- /**
16
+ */ async authenticate(token = null) {
17
+ if (token) {
18
+ this.token = token;
19
+ }
20
+ if (!this.token) {
21
+ printError('GitHub token not found. Set GITHUB_TOKEN environment variable or provide token.');
22
+ return false;
23
+ }
24
+ try {
25
+ const response = await this.request('/user');
26
+ if (response.success) {
27
+ printSuccess(`Authenticated as ${response.data.login}`);
28
+ return true;
29
+ }
30
+ return false;
31
+ } catch (error) {
32
+ printError(`Authentication failed: ${error.message}`);
33
+ return false;
34
+ }
35
+ }
36
+ /**
62
37
  * Rate Limiting Management
63
- */
64
- async checkRateLimit() {
65
- if (this.rateLimitRemaining <= 1) {
66
- const resetTime = new Date(this.rateLimitResetTime);
67
- const now = new Date();
68
- const waitTime = resetTime.getTime() - now.getTime();
69
-
70
- if (waitTime > 0) {
71
- printWarning(`Rate limit exceeded. Waiting ${Math.ceil(waitTime / 1000)}s...`);
72
- await this.sleep(waitTime);
73
- }
74
- }
75
- }
76
-
77
- updateRateLimitInfo(headers) {
78
- this.rateLimitRemaining = parseInt(headers['x-ratelimit-remaining'] || '0');
79
- this.rateLimitResetTime = new Date((parseInt(headers['x-ratelimit-reset']) || 0) * 1000);
80
- }
81
-
82
- /**
38
+ */ async checkRateLimit() {
39
+ if (this.rateLimitRemaining <= 1) {
40
+ const resetTime = new Date(this.rateLimitResetTime);
41
+ const now = new Date();
42
+ const waitTime = resetTime.getTime() - now.getTime();
43
+ if (waitTime > 0) {
44
+ printWarning(`Rate limit exceeded. Waiting ${Math.ceil(waitTime / 1000)}s...`);
45
+ await this.sleep(waitTime);
46
+ }
47
+ }
48
+ }
49
+ updateRateLimitInfo(headers) {
50
+ this.rateLimitRemaining = parseInt(headers['x-ratelimit-remaining'] || '0');
51
+ this.rateLimitResetTime = new Date((parseInt(headers['x-ratelimit-reset']) || 0) * 1000);
52
+ }
53
+ /**
83
54
  * Core API Request Method
84
- */
85
- async request(endpoint, options = {}) {
86
- await this.checkRateLimit();
87
-
88
- const url = endpoint.startsWith('http') ? endpoint : `${GITHUB_API_BASE}${endpoint}`;
89
- const headers = {
90
- Authorization: `token ${this.token}`,
91
- Accept: 'application/vnd.github.v3+json',
92
- 'User-Agent': 'Claude-Flow-GitHub-Integration',
93
- ...options.headers,
94
- };
95
-
96
- const requestOptions = {
97
- method: options.method || 'GET',
98
- headers,
99
- ...options,
100
- };
101
-
102
- if (options.body) {
103
- requestOptions.body = JSON.stringify(options.body);
104
- headers['Content-Type'] = 'application/json';
105
- }
106
-
107
- try {
108
- const response = await fetch(url, requestOptions);
109
- this.updateRateLimitInfo(response.headers);
110
-
111
- const data = await response.json();
112
-
113
- if (!response.ok) {
114
- throw new Error(`GitHub API error: ${data.message || response.statusText}`);
115
- }
116
-
117
- return {
118
- success: true,
119
- data,
120
- headers: response.headers,
121
- status: response.status,
122
- };
123
- } catch (error) {
124
- return {
125
- success: false,
126
- error: error.message,
127
- status: error.status || 500,
128
- };
129
- }
130
- }
131
-
132
- /**
55
+ */ async request(endpoint, options = {}) {
56
+ await this.checkRateLimit();
57
+ const url = endpoint.startsWith('http') ? endpoint : `${GITHUB_API_BASE}${endpoint}`;
58
+ const headers = {
59
+ Authorization: `token ${this.token}`,
60
+ Accept: 'application/vnd.github.v3+json',
61
+ 'User-Agent': 'Claude-Flow-GitHub-Integration',
62
+ ...options.headers
63
+ };
64
+ const requestOptions = {
65
+ method: options.method || 'GET',
66
+ headers,
67
+ ...options
68
+ };
69
+ if (options.body) {
70
+ requestOptions.body = JSON.stringify(options.body);
71
+ headers['Content-Type'] = 'application/json';
72
+ }
73
+ try {
74
+ const response = await fetch(url, requestOptions);
75
+ this.updateRateLimitInfo(response.headers);
76
+ const data = await response.json();
77
+ if (!response.ok) {
78
+ throw new Error(`GitHub API error: ${data.message || response.statusText}`);
79
+ }
80
+ return {
81
+ success: true,
82
+ data,
83
+ headers: response.headers,
84
+ status: response.status
85
+ };
86
+ } catch (error) {
87
+ return {
88
+ success: false,
89
+ error: error.message,
90
+ status: error.status || 500
91
+ };
92
+ }
93
+ }
94
+ /**
133
95
  * Repository Operations
134
- */
135
- async getRepository(owner, repo) {
136
- return await this.request(`/repos/${owner}/${repo}`);
137
- }
138
-
139
- async listRepositories(options = {}) {
140
- const params = new URLSearchParams({
141
- sort: options.sort || 'updated',
142
- direction: options.direction || 'desc',
143
- per_page: options.perPage || 30,
144
- page: options.page || 1,
145
- });
146
-
147
- return await this.request(`/user/repos?${params}`);
148
- }
149
-
150
- async createRepository(repoData) {
151
- return await this.request('/user/repos', {
152
- method: 'POST',
153
- body: repoData,
154
- });
155
- }
156
-
157
- /**
96
+ */ async getRepository(owner, repo) {
97
+ return await this.request(`/repos/${owner}/${repo}`);
98
+ }
99
+ async listRepositories(options = {}) {
100
+ const params = new URLSearchParams({
101
+ sort: options.sort || 'updated',
102
+ direction: options.direction || 'desc',
103
+ per_page: options.perPage || 30,
104
+ page: options.page || 1
105
+ });
106
+ return await this.request(`/user/repos?${params}`);
107
+ }
108
+ async createRepository(repoData) {
109
+ return await this.request('/user/repos', {
110
+ method: 'POST',
111
+ body: repoData
112
+ });
113
+ }
114
+ /**
158
115
  * Pull Request Operations
159
- */
160
- async listPullRequests(owner, repo, options = {}) {
161
- const params = new URLSearchParams({
162
- state: options.state || 'open',
163
- sort: options.sort || 'created',
164
- direction: options.direction || 'desc',
165
- per_page: options.perPage || 30,
166
- page: options.page || 1,
167
- });
168
-
169
- return await this.request(`/repos/${owner}/${repo}/pulls?${params}`);
170
- }
171
-
172
- async createPullRequest(owner, repo, prData) {
173
- return await this.request(`/repos/${owner}/${repo}/pulls`, {
174
- method: 'POST',
175
- body: prData,
176
- });
177
- }
178
-
179
- async updatePullRequest(owner, repo, prNumber, prData) {
180
- return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}`, {
181
- method: 'PATCH',
182
- body: prData,
183
- });
184
- }
185
-
186
- async mergePullRequest(owner, repo, prNumber, mergeData) {
187
- return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/merge`, {
188
- method: 'PUT',
189
- body: mergeData,
190
- });
191
- }
192
-
193
- async requestPullRequestReview(owner, repo, prNumber, reviewData) {
194
- return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/requested_reviewers`, {
195
- method: 'POST',
196
- body: reviewData,
197
- });
198
- }
199
-
200
- /**
116
+ */ async listPullRequests(owner, repo, options = {}) {
117
+ const params = new URLSearchParams({
118
+ state: options.state || 'open',
119
+ sort: options.sort || 'created',
120
+ direction: options.direction || 'desc',
121
+ per_page: options.perPage || 30,
122
+ page: options.page || 1
123
+ });
124
+ return await this.request(`/repos/${owner}/${repo}/pulls?${params}`);
125
+ }
126
+ async createPullRequest(owner, repo, prData) {
127
+ return await this.request(`/repos/${owner}/${repo}/pulls`, {
128
+ method: 'POST',
129
+ body: prData
130
+ });
131
+ }
132
+ async updatePullRequest(owner, repo, prNumber, prData) {
133
+ return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}`, {
134
+ method: 'PATCH',
135
+ body: prData
136
+ });
137
+ }
138
+ async mergePullRequest(owner, repo, prNumber, mergeData) {
139
+ return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/merge`, {
140
+ method: 'PUT',
141
+ body: mergeData
142
+ });
143
+ }
144
+ async requestPullRequestReview(owner, repo, prNumber, reviewData) {
145
+ return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/requested_reviewers`, {
146
+ method: 'POST',
147
+ body: reviewData
148
+ });
149
+ }
150
+ /**
201
151
  * Issue Operations
202
- */
203
- async listIssues(owner, repo, options = {}) {
204
- const params = new URLSearchParams({
205
- state: options.state || 'open',
206
- sort: options.sort || 'created',
207
- direction: options.direction || 'desc',
208
- per_page: options.perPage || 30,
209
- page: options.page || 1,
210
- });
211
-
212
- if (options.labels) {
213
- params.append('labels', options.labels);
214
- }
215
-
216
- return await this.request(`/repos/${owner}/${repo}/issues?${params}`);
217
- }
218
-
219
- async createIssue(owner, repo, issueData) {
220
- return await this.request(`/repos/${owner}/${repo}/issues`, {
221
- method: 'POST',
222
- body: issueData,
223
- });
224
- }
225
-
226
- async updateIssue(owner, repo, issueNumber, issueData) {
227
- return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}`, {
228
- method: 'PATCH',
229
- body: issueData,
230
- });
231
- }
232
-
233
- async addIssueLabels(owner, repo, issueNumber, labels) {
234
- return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/labels`, {
235
- method: 'POST',
236
- body: { labels },
237
- });
238
- }
239
-
240
- async assignIssue(owner, repo, issueNumber, assignees) {
241
- return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, {
242
- method: 'POST',
243
- body: { assignees },
244
- });
245
- }
246
-
247
- /**
152
+ */ async listIssues(owner, repo, options = {}) {
153
+ const params = new URLSearchParams({
154
+ state: options.state || 'open',
155
+ sort: options.sort || 'created',
156
+ direction: options.direction || 'desc',
157
+ per_page: options.perPage || 30,
158
+ page: options.page || 1
159
+ });
160
+ if (options.labels) {
161
+ params.append('labels', options.labels);
162
+ }
163
+ return await this.request(`/repos/${owner}/${repo}/issues?${params}`);
164
+ }
165
+ async createIssue(owner, repo, issueData) {
166
+ return await this.request(`/repos/${owner}/${repo}/issues`, {
167
+ method: 'POST',
168
+ body: issueData
169
+ });
170
+ }
171
+ async updateIssue(owner, repo, issueNumber, issueData) {
172
+ return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}`, {
173
+ method: 'PATCH',
174
+ body: issueData
175
+ });
176
+ }
177
+ async addIssueLabels(owner, repo, issueNumber, labels) {
178
+ return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/labels`, {
179
+ method: 'POST',
180
+ body: {
181
+ labels
182
+ }
183
+ });
184
+ }
185
+ async assignIssue(owner, repo, issueNumber, assignees) {
186
+ return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, {
187
+ method: 'POST',
188
+ body: {
189
+ assignees
190
+ }
191
+ });
192
+ }
193
+ /**
248
194
  * Release Operations
249
- */
250
- async listReleases(owner, repo, options = {}) {
251
- const params = new URLSearchParams({
252
- per_page: options.perPage || 30,
253
- page: options.page || 1,
254
- });
255
-
256
- return await this.request(`/repos/${owner}/${repo}/releases?${params}`);
257
- }
258
-
259
- async createRelease(owner, repo, releaseData) {
260
- return await this.request(`/repos/${owner}/${repo}/releases`, {
261
- method: 'POST',
262
- body: releaseData,
263
- });
264
- }
265
-
266
- async updateRelease(owner, repo, releaseId, releaseData) {
267
- return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
268
- method: 'PATCH',
269
- body: releaseData,
270
- });
271
- }
272
-
273
- async deleteRelease(owner, repo, releaseId) {
274
- return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
275
- method: 'DELETE',
276
- });
277
- }
278
-
279
- /**
195
+ */ async listReleases(owner, repo, options = {}) {
196
+ const params = new URLSearchParams({
197
+ per_page: options.perPage || 30,
198
+ page: options.page || 1
199
+ });
200
+ return await this.request(`/repos/${owner}/${repo}/releases?${params}`);
201
+ }
202
+ async createRelease(owner, repo, releaseData) {
203
+ return await this.request(`/repos/${owner}/${repo}/releases`, {
204
+ method: 'POST',
205
+ body: releaseData
206
+ });
207
+ }
208
+ async updateRelease(owner, repo, releaseId, releaseData) {
209
+ return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
210
+ method: 'PATCH',
211
+ body: releaseData
212
+ });
213
+ }
214
+ async deleteRelease(owner, repo, releaseId) {
215
+ return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
216
+ method: 'DELETE'
217
+ });
218
+ }
219
+ /**
280
220
  * Workflow Operations
281
- */
282
- async listWorkflows(owner, repo) {
283
- return await this.request(`/repos/${owner}/${repo}/actions/workflows`);
284
- }
285
-
286
- async triggerWorkflow(owner, repo, workflowId, ref = 'main', inputs = {}) {
287
- return await this.request(
288
- `/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`,
289
- {
290
- method: 'POST',
291
- body: { ref, inputs },
292
- },
293
- );
294
- }
295
-
296
- async listWorkflowRuns(owner, repo, options = {}) {
297
- const params = new URLSearchParams({
298
- per_page: options.perPage || 30,
299
- page: options.page || 1,
300
- });
301
-
302
- if (options.status) {
303
- params.append('status', options.status);
304
- }
305
-
306
- return await this.request(`/repos/${owner}/${repo}/actions/runs?${params}`);
307
- }
308
-
309
- /**
221
+ */ async listWorkflows(owner, repo) {
222
+ return await this.request(`/repos/${owner}/${repo}/actions/workflows`);
223
+ }
224
+ async triggerWorkflow(owner, repo, workflowId, ref = 'main', inputs = {}) {
225
+ return await this.request(`/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`, {
226
+ method: 'POST',
227
+ body: {
228
+ ref,
229
+ inputs
230
+ }
231
+ });
232
+ }
233
+ async listWorkflowRuns(owner, repo, options = {}) {
234
+ const params = new URLSearchParams({
235
+ per_page: options.perPage || 30,
236
+ page: options.page || 1
237
+ });
238
+ if (options.status) {
239
+ params.append('status', options.status);
240
+ }
241
+ return await this.request(`/repos/${owner}/${repo}/actions/runs?${params}`);
242
+ }
243
+ /**
310
244
  * Branch Operations
311
- */
312
- async listBranches(owner, repo) {
313
- return await this.request(`/repos/${owner}/${repo}/branches`);
314
- }
315
-
316
- async createBranch(owner, repo, branchName, sha) {
317
- return await this.request(`/repos/${owner}/${repo}/git/refs`, {
318
- method: 'POST',
319
- body: {
320
- ref: `refs/heads/${branchName}`,
321
- sha,
322
- },
323
- });
324
- }
325
-
326
- async getBranchProtection(owner, repo, branch) {
327
- return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`);
328
- }
329
-
330
- async updateBranchProtection(owner, repo, branch, protection) {
331
- return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`, {
332
- method: 'PUT',
333
- body: protection,
334
- });
335
- }
336
-
337
- /**
245
+ */ async listBranches(owner, repo) {
246
+ return await this.request(`/repos/${owner}/${repo}/branches`);
247
+ }
248
+ async createBranch(owner, repo, branchName, sha) {
249
+ return await this.request(`/repos/${owner}/${repo}/git/refs`, {
250
+ method: 'POST',
251
+ body: {
252
+ ref: `refs/heads/${branchName}`,
253
+ sha
254
+ }
255
+ });
256
+ }
257
+ async getBranchProtection(owner, repo, branch) {
258
+ return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`);
259
+ }
260
+ async updateBranchProtection(owner, repo, branch, protection) {
261
+ return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`, {
262
+ method: 'PUT',
263
+ body: protection
264
+ });
265
+ }
266
+ /**
338
267
  * Webhook Operations
339
- */
340
- async listWebhooks(owner, repo) {
341
- return await this.request(`/repos/${owner}/${repo}/hooks`);
342
- }
343
-
344
- async createWebhook(owner, repo, webhookData) {
345
- return await this.request(`/repos/${owner}/${repo}/hooks`, {
346
- method: 'POST',
347
- body: webhookData,
348
- });
349
- }
350
-
351
- async updateWebhook(owner, repo, hookId, webhookData) {
352
- return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
353
- method: 'PATCH',
354
- body: webhookData,
355
- });
356
- }
357
-
358
- async deleteWebhook(owner, repo, hookId) {
359
- return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
360
- method: 'DELETE',
361
- });
362
- }
363
-
364
- /**
268
+ */ async listWebhooks(owner, repo) {
269
+ return await this.request(`/repos/${owner}/${repo}/hooks`);
270
+ }
271
+ async createWebhook(owner, repo, webhookData) {
272
+ return await this.request(`/repos/${owner}/${repo}/hooks`, {
273
+ method: 'POST',
274
+ body: webhookData
275
+ });
276
+ }
277
+ async updateWebhook(owner, repo, hookId, webhookData) {
278
+ return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
279
+ method: 'PATCH',
280
+ body: webhookData
281
+ });
282
+ }
283
+ async deleteWebhook(owner, repo, hookId) {
284
+ return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
285
+ method: 'DELETE'
286
+ });
287
+ }
288
+ /**
365
289
  * Event Processing
366
- */
367
- async processWebhookEvent(event, signature, payload) {
368
- if (!this.verifyWebhookSignature(signature, payload)) {
369
- throw new Error('Invalid webhook signature');
370
- }
371
-
372
- const eventData = JSON.parse(payload);
373
-
374
- switch (event) {
375
- case 'push':
376
- return this.handlePushEvent(eventData);
377
- case 'pull_request':
378
- return this.handlePullRequestEvent(eventData);
379
- case 'issues':
380
- return this.handleIssuesEvent(eventData);
381
- case 'release':
382
- return this.handleReleaseEvent(eventData);
383
- case 'workflow_run':
384
- return this.handleWorkflowRunEvent(eventData);
385
- default:
386
- printInfo(`Unhandled event type: ${event}`);
387
- return { handled: false, event };
388
- }
389
- }
390
-
391
- verifyWebhookSignature(signature, payload) {
392
- if (!GITHUB_WEBHOOK_SECRET) {
393
- printWarning('GITHUB_WEBHOOK_SECRET not set. Skipping signature verification.');
394
- return true;
395
- }
396
-
397
- const crypto = require('crypto');
398
- const hmac = crypto.createHmac('sha256', GITHUB_WEBHOOK_SECRET);
399
- hmac.update(payload);
400
- const expectedSignature = `sha256=${hmac.digest('hex')}`;
401
-
402
- return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
403
- }
404
-
405
- /**
290
+ */ async processWebhookEvent(event, signature, payload) {
291
+ if (!this.verifyWebhookSignature(signature, payload)) {
292
+ throw new Error('Invalid webhook signature');
293
+ }
294
+ const eventData = JSON.parse(payload);
295
+ switch(event){
296
+ case 'push':
297
+ return this.handlePushEvent(eventData);
298
+ case 'pull_request':
299
+ return this.handlePullRequestEvent(eventData);
300
+ case 'issues':
301
+ return this.handleIssuesEvent(eventData);
302
+ case 'release':
303
+ return this.handleReleaseEvent(eventData);
304
+ case 'workflow_run':
305
+ return this.handleWorkflowRunEvent(eventData);
306
+ default:
307
+ printInfo(`Unhandled event type: ${event}`);
308
+ return {
309
+ handled: false,
310
+ event
311
+ };
312
+ }
313
+ }
314
+ verifyWebhookSignature(signature, payload) {
315
+ if (!GITHUB_WEBHOOK_SECRET) {
316
+ printWarning('GITHUB_WEBHOOK_SECRET not set. Skipping signature verification.');
317
+ return true;
318
+ }
319
+ const crypto = require('crypto');
320
+ const hmac = crypto.createHmac('sha256', GITHUB_WEBHOOK_SECRET);
321
+ hmac.update(payload);
322
+ const expectedSignature = `sha256=${hmac.digest('hex')}`;
323
+ return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
324
+ }
325
+ /**
406
326
  * Event Handlers
407
- */
408
- async handlePushEvent(eventData) {
409
- printInfo(`Push event: ${eventData.commits.length} commits to ${eventData.ref}`);
410
- return { handled: true, event: 'push', data: eventData };
411
- }
412
-
413
- async handlePullRequestEvent(eventData) {
414
- const action = eventData.action;
415
- const pr = eventData.pull_request;
416
- printInfo(`Pull request ${action}: #${pr.number} - ${pr.title}`);
417
- return { handled: true, event: 'pull_request', action, data: eventData };
418
- }
419
-
420
- async handleIssuesEvent(eventData) {
421
- const action = eventData.action;
422
- const issue = eventData.issue;
423
- printInfo(`Issue ${action}: #${issue.number} - ${issue.title}`);
424
- return { handled: true, event: 'issues', action, data: eventData };
425
- }
426
-
427
- async handleReleaseEvent(eventData) {
428
- const action = eventData.action;
429
- const release = eventData.release;
430
- printInfo(`Release ${action}: ${release.tag_name} - ${release.name}`);
431
- return { handled: true, event: 'release', action, data: eventData };
432
- }
433
-
434
- async handleWorkflowRunEvent(eventData) {
435
- const action = eventData.action;
436
- const workflowRun = eventData.workflow_run;
437
- printInfo(`Workflow run ${action}: ${workflowRun.name} - ${workflowRun.conclusion}`);
438
- return { handled: true, event: 'workflow_run', action, data: eventData };
439
- }
440
-
441
- /**
327
+ */ async handlePushEvent(eventData) {
328
+ printInfo(`Push event: ${eventData.commits.length} commits to ${eventData.ref}`);
329
+ return {
330
+ handled: true,
331
+ event: 'push',
332
+ data: eventData
333
+ };
334
+ }
335
+ async handlePullRequestEvent(eventData) {
336
+ const action = eventData.action;
337
+ const pr = eventData.pull_request;
338
+ printInfo(`Pull request ${action}: #${pr.number} - ${pr.title}`);
339
+ return {
340
+ handled: true,
341
+ event: 'pull_request',
342
+ action,
343
+ data: eventData
344
+ };
345
+ }
346
+ async handleIssuesEvent(eventData) {
347
+ const action = eventData.action;
348
+ const issue = eventData.issue;
349
+ printInfo(`Issue ${action}: #${issue.number} - ${issue.title}`);
350
+ return {
351
+ handled: true,
352
+ event: 'issues',
353
+ action,
354
+ data: eventData
355
+ };
356
+ }
357
+ async handleReleaseEvent(eventData) {
358
+ const action = eventData.action;
359
+ const release = eventData.release;
360
+ printInfo(`Release ${action}: ${release.tag_name} - ${release.name}`);
361
+ return {
362
+ handled: true,
363
+ event: 'release',
364
+ action,
365
+ data: eventData
366
+ };
367
+ }
368
+ async handleWorkflowRunEvent(eventData) {
369
+ const action = eventData.action;
370
+ const workflowRun = eventData.workflow_run;
371
+ printInfo(`Workflow run ${action}: ${workflowRun.name} - ${workflowRun.conclusion}`);
372
+ return {
373
+ handled: true,
374
+ event: 'workflow_run',
375
+ action,
376
+ data: eventData
377
+ };
378
+ }
379
+ /**
442
380
  * Utility Methods
443
- */
444
- async sleep(ms) {
445
- return new Promise((resolve) => setTimeout(resolve, ms));
446
- }
447
-
448
- parseRepository(repoString) {
449
- const match = repoString.match(/^([^/]+)\/([^/]+)$/);
450
- if (!match) {
451
- throw new Error('Invalid repository format. Use: owner/repo');
452
- }
453
- return { owner: match[1], repo: match[2] };
454
- }
455
-
456
- formatDate(dateString) {
457
- return new Date(dateString).toLocaleString();
458
- }
459
-
460
- formatFileSize(bytes) {
461
- const units = ['B', 'KB', 'MB', 'GB'];
462
- let size = bytes;
463
- let unitIndex = 0;
464
-
465
- while (size >= 1024 && unitIndex < units.length - 1) {
466
- size /= 1024;
467
- unitIndex++;
468
- }
469
-
470
- return `${size.toFixed(2)} ${units[unitIndex]}`;
471
- }
472
-
473
- /**
381
+ */ async sleep(ms) {
382
+ return new Promise((resolve)=>setTimeout(resolve, ms));
383
+ }
384
+ parseRepository(repoString) {
385
+ const match = repoString.match(/^([^/]+)\/([^/]+)$/);
386
+ if (!match) {
387
+ throw new Error('Invalid repository format. Use: owner/repo');
388
+ }
389
+ return {
390
+ owner: match[1],
391
+ repo: match[2]
392
+ };
393
+ }
394
+ formatDate(dateString) {
395
+ return new Date(dateString).toLocaleString();
396
+ }
397
+ formatFileSize(bytes) {
398
+ const units = [
399
+ 'B',
400
+ 'KB',
401
+ 'MB',
402
+ 'GB'
403
+ ];
404
+ let size = bytes;
405
+ let unitIndex = 0;
406
+ while(size >= 1024 && unitIndex < units.length - 1){
407
+ size /= 1024;
408
+ unitIndex++;
409
+ }
410
+ return `${size.toFixed(2)} ${units[unitIndex]}`;
411
+ }
412
+ /**
474
413
  * Safe GitHub CLI Methods
475
414
  * These methods use the GitHubCliSafe wrapper for secure command execution
476
- */
477
-
478
- /**
415
+ */ /**
479
416
  * Create issue using GitHub CLI (safe alternative to createIssue API method)
480
417
  * @param {Object} issueData - Issue data
481
418
  * @returns {Promise<Object>} - CLI execution result
482
- */
483
- async createIssueCLI(issueData) {
484
- try {
485
- const result = await this.cliSafe.createIssue({
486
- title: issueData.title,
487
- body: issueData.body,
488
- labels: issueData.labels || [],
489
- assignees: issueData.assignees || [],
490
- });
491
-
492
- printSuccess(`Issue created via CLI: ${issueData.title}`);
493
- return { success: true, data: result };
494
- } catch (error) {
495
- printError(`Failed to create issue via CLI: ${error.message}`);
496
- return { success: false, error: error.message };
497
- }
498
- }
499
-
500
- /**
419
+ */ async createIssueCLI(issueData) {
420
+ try {
421
+ const result = await this.cliSafe.createIssue({
422
+ title: issueData.title,
423
+ body: issueData.body,
424
+ labels: issueData.labels || [],
425
+ assignees: issueData.assignees || []
426
+ });
427
+ printSuccess(`Issue created via CLI: ${issueData.title}`);
428
+ return {
429
+ success: true,
430
+ data: result
431
+ };
432
+ } catch (error) {
433
+ printError(`Failed to create issue via CLI: ${error.message}`);
434
+ return {
435
+ success: false,
436
+ error: error.message
437
+ };
438
+ }
439
+ }
440
+ /**
501
441
  * Create PR using GitHub CLI (safe alternative to createPullRequest API method)
502
442
  * @param {Object} prData - PR data
503
443
  * @returns {Promise<Object>} - CLI execution result
504
- */
505
- async createPullRequestCLI(prData) {
506
- try {
507
- const result = await this.cliSafe.createPR({
508
- title: prData.title,
509
- body: prData.body,
510
- base: prData.base || 'main',
511
- head: prData.head,
512
- draft: prData.draft || false,
513
- });
514
-
515
- printSuccess(`PR created via CLI: ${prData.title}`);
516
- return { success: true, data: result };
517
- } catch (error) {
518
- printError(`Failed to create PR via CLI: ${error.message}`);
519
- return { success: false, error: error.message };
520
- }
521
- }
522
-
523
- /**
444
+ */ async createPullRequestCLI(prData) {
445
+ try {
446
+ const result = await this.cliSafe.createPR({
447
+ title: prData.title,
448
+ body: prData.body,
449
+ base: prData.base || 'main',
450
+ head: prData.head,
451
+ draft: prData.draft || false
452
+ });
453
+ printSuccess(`PR created via CLI: ${prData.title}`);
454
+ return {
455
+ success: true,
456
+ data: result
457
+ };
458
+ } catch (error) {
459
+ printError(`Failed to create PR via CLI: ${error.message}`);
460
+ return {
461
+ success: false,
462
+ error: error.message
463
+ };
464
+ }
465
+ }
466
+ /**
524
467
  * Add issue comment using GitHub CLI
525
468
  * @param {number} issueNumber - Issue number
526
469
  * @param {string} body - Comment body
527
470
  * @returns {Promise<Object>} - CLI execution result
528
- */
529
- async addIssueCommentCLI(issueNumber, body) {
530
- try {
531
- const result = await this.cliSafe.addIssueComment(issueNumber, body);
532
- printSuccess(`Comment added to issue #${issueNumber}`);
533
- return { success: true, data: result };
534
- } catch (error) {
535
- printError(`Failed to add comment to issue #${issueNumber}: ${error.message}`);
536
- return { success: false, error: error.message };
537
- }
538
- }
539
-
540
- /**
471
+ */ async addIssueCommentCLI(issueNumber, body) {
472
+ try {
473
+ const result = await this.cliSafe.addIssueComment(issueNumber, body);
474
+ printSuccess(`Comment added to issue #${issueNumber}`);
475
+ return {
476
+ success: true,
477
+ data: result
478
+ };
479
+ } catch (error) {
480
+ printError(`Failed to add comment to issue #${issueNumber}: ${error.message}`);
481
+ return {
482
+ success: false,
483
+ error: error.message
484
+ };
485
+ }
486
+ }
487
+ /**
541
488
  * Add PR comment using GitHub CLI
542
489
  * @param {number} prNumber - PR number
543
490
  * @param {string} body - Comment body
544
491
  * @returns {Promise<Object>} - CLI execution result
545
- */
546
- async addPRCommentCLI(prNumber, body) {
547
- try {
548
- const result = await this.cliSafe.addPRComment(prNumber, body);
549
- printSuccess(`Comment added to PR #${prNumber}`);
550
- return { success: true, data: result };
551
- } catch (error) {
552
- printError(`Failed to add comment to PR #${prNumber}: ${error.message}`);
553
- return { success: false, error: error.message };
554
- }
555
- }
556
-
557
- /**
492
+ */ async addPRCommentCLI(prNumber, body) {
493
+ try {
494
+ const result = await this.cliSafe.addPRComment(prNumber, body);
495
+ printSuccess(`Comment added to PR #${prNumber}`);
496
+ return {
497
+ success: true,
498
+ data: result
499
+ };
500
+ } catch (error) {
501
+ printError(`Failed to add comment to PR #${prNumber}: ${error.message}`);
502
+ return {
503
+ success: false,
504
+ error: error.message
505
+ };
506
+ }
507
+ }
508
+ /**
558
509
  * Create release using GitHub CLI
559
510
  * @param {Object} releaseData - Release data
560
511
  * @returns {Promise<Object>} - CLI execution result
561
- */
562
- async createReleaseCLI(releaseData) {
563
- try {
564
- const result = await this.cliSafe.createRelease({
565
- tag: releaseData.tag_name,
566
- title: releaseData.name,
567
- body: releaseData.body,
568
- prerelease: releaseData.prerelease || false,
569
- draft: releaseData.draft || false,
570
- });
571
-
572
- printSuccess(`Release created via CLI: ${releaseData.tag_name}`);
573
- return { success: true, data: result };
574
- } catch (error) {
575
- printError(`Failed to create release via CLI: ${error.message}`);
576
- return { success: false, error: error.message };
577
- }
578
- }
579
-
580
- /**
512
+ */ async createReleaseCLI(releaseData) {
513
+ try {
514
+ const result = await this.cliSafe.createRelease({
515
+ tag: releaseData.tag_name,
516
+ title: releaseData.name,
517
+ body: releaseData.body,
518
+ prerelease: releaseData.prerelease || false,
519
+ draft: releaseData.draft || false
520
+ });
521
+ printSuccess(`Release created via CLI: ${releaseData.tag_name}`);
522
+ return {
523
+ success: true,
524
+ data: result
525
+ };
526
+ } catch (error) {
527
+ printError(`Failed to create release via CLI: ${error.message}`);
528
+ return {
529
+ success: false,
530
+ error: error.message
531
+ };
532
+ }
533
+ }
534
+ /**
581
535
  * Check GitHub CLI authentication and availability
582
536
  * @returns {Promise<boolean>} - True if CLI is ready to use
583
- */
584
- async checkCLIStatus() {
585
- try {
586
- const isAvailable = await this.cliSafe.checkGitHubCli();
587
- if (!isAvailable) {
588
- printWarning('GitHub CLI is not installed or not in PATH');
589
- return false;
590
- }
591
-
592
- const isAuthenticated = await this.cliSafe.checkAuthentication();
593
- if (!isAuthenticated) {
594
- printWarning('GitHub CLI is not authenticated. Run: gh auth login');
595
- return false;
596
- }
597
-
598
- printSuccess('GitHub CLI is ready for use');
599
- return true;
600
- } catch (error) {
601
- printError(`GitHub CLI status check failed: ${error.message}`);
602
- return false;
603
- }
604
- }
605
-
606
- /**
537
+ */ async checkCLIStatus() {
538
+ try {
539
+ const isAvailable = await this.cliSafe.checkGitHubCli();
540
+ if (!isAvailable) {
541
+ printWarning('GitHub CLI is not installed or not in PATH');
542
+ return false;
543
+ }
544
+ const isAuthenticated = await this.cliSafe.checkAuthentication();
545
+ if (!isAuthenticated) {
546
+ printWarning('GitHub CLI is not authenticated. Run: gh auth login');
547
+ return false;
548
+ }
549
+ printSuccess('GitHub CLI is ready for use');
550
+ return true;
551
+ } catch (error) {
552
+ printError(`GitHub CLI status check failed: ${error.message}`);
553
+ return false;
554
+ }
555
+ }
556
+ /**
607
557
  * Get GitHub CLI wrapper statistics
608
558
  * @returns {Object} - Usage statistics
609
- */
610
- getCLIStats() {
611
- return this.cliSafe.getStats();
612
- }
613
-
614
- /**
559
+ */ getCLIStats() {
560
+ return this.cliSafe.getStats();
561
+ }
562
+ /**
615
563
  * Cleanup CLI resources (call before shutdown)
616
- */
617
- async cleanupCLI() {
618
- await this.cliSafe.cleanup();
619
- }
620
- }
621
-
564
+ */ async cleanupCLI() {
565
+ await this.cliSafe.cleanup();
566
+ }
567
+ constructor(token = null){
568
+ this.token = token || process.env.GITHUB_TOKEN;
569
+ this.rateLimitRemaining = GITHUB_RATE_LIMIT;
570
+ this.rateLimitResetTime = null;
571
+ this.lastRequestTime = 0;
572
+ this.requestQueue = [];
573
+ this.isProcessingQueue = false;
574
+ // Initialize GitHub CLI safety wrapper
575
+ this.cliSafe = new GitHubCliSafe({
576
+ timeout: 60000,
577
+ maxRetries: 3,
578
+ enableRateLimit: true,
579
+ enableLogging: false
580
+ });
581
+ }
582
+ };
622
583
  // Export singleton instance
623
584
  export const githubAPI = new GitHubAPIClient();
624
585
  export default GitHubAPIClient;