@agentic-qe/v3 3.0.0-alpha.6 → 3.0.0-alpha.8

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 (612) hide show
  1. package/assets/agents/v3/subagents/v3-qe-code-reviewer.md +339 -0
  2. package/assets/agents/v3/subagents/v3-qe-integration-reviewer.md +344 -0
  3. package/assets/agents/v3/subagents/v3-qe-performance-reviewer.md +351 -0
  4. package/assets/agents/v3/subagents/v3-qe-security-reviewer.md +374 -0
  5. package/assets/agents/v3/subagents/v3-qe-tdd-green.md +334 -0
  6. package/assets/agents/v3/subagents/v3-qe-tdd-red.md +329 -0
  7. package/assets/agents/v3/subagents/v3-qe-tdd-refactor.md +361 -0
  8. package/assets/agents/v3/v3-qe-accessibility-auditor.md +266 -0
  9. package/assets/agents/v3/v3-qe-bdd-generator.md +279 -0
  10. package/assets/agents/v3/v3-qe-chaos-engineer.md +265 -0
  11. package/assets/agents/v3/v3-qe-code-complexity.md +298 -0
  12. package/assets/agents/v3/v3-qe-code-intelligence.md +262 -0
  13. package/assets/agents/v3/v3-qe-contract-validator.md +267 -0
  14. package/assets/agents/v3/v3-qe-coverage-specialist.md +227 -0
  15. package/assets/agents/v3/v3-qe-defect-predictor.md +251 -0
  16. package/assets/agents/v3/v3-qe-dependency-mapper.md +277 -0
  17. package/assets/agents/v3/v3-qe-deployment-advisor.md +275 -0
  18. package/assets/agents/v3/v3-qe-flaky-hunter.md +248 -0
  19. package/assets/agents/v3/v3-qe-fleet-commander.md +293 -0
  20. package/assets/agents/v3/v3-qe-gap-detector.md +260 -0
  21. package/assets/agents/v3/v3-qe-graphql-tester.md +308 -0
  22. package/assets/agents/v3/v3-qe-impact-analyzer.md +299 -0
  23. package/assets/agents/v3/v3-qe-integration-tester.md +238 -0
  24. package/assets/agents/v3/v3-qe-kg-builder.md +273 -0
  25. package/assets/agents/v3/v3-qe-learning-coordinator.md +226 -0
  26. package/assets/agents/v3/v3-qe-load-tester.md +280 -0
  27. package/assets/agents/v3/v3-qe-metrics-optimizer.md +300 -0
  28. package/assets/agents/v3/v3-qe-mutation-tester.md +301 -0
  29. package/assets/agents/v3/v3-qe-parallel-executor.md +240 -0
  30. package/assets/agents/v3/v3-qe-pattern-learner.md +271 -0
  31. package/assets/agents/v3/v3-qe-performance-tester.md +262 -0
  32. package/assets/agents/v3/v3-qe-property-tester.md +247 -0
  33. package/assets/agents/v3/v3-qe-quality-gate.md +218 -0
  34. package/assets/agents/v3/v3-qe-queen-coordinator.md +214 -0
  35. package/assets/agents/v3/v3-qe-qx-partner.md +313 -0
  36. package/assets/agents/v3/v3-qe-regression-analyzer.md +322 -0
  37. package/assets/agents/v3/v3-qe-requirements-validator.md +360 -0
  38. package/assets/agents/v3/v3-qe-responsive-tester.md +311 -0
  39. package/assets/agents/v3/v3-qe-retry-handler.md +256 -0
  40. package/assets/agents/v3/v3-qe-risk-assessor.md +273 -0
  41. package/assets/agents/v3/v3-qe-root-cause-analyzer.md +286 -0
  42. package/assets/agents/v3/v3-qe-security-auditor.md +299 -0
  43. package/assets/agents/v3/v3-qe-security-scanner.md +235 -0
  44. package/assets/agents/v3/v3-qe-tdd-specialist.md +239 -0
  45. package/assets/agents/v3/v3-qe-test-architect.md +233 -0
  46. package/assets/agents/v3/v3-qe-transfer-specialist.md +295 -0
  47. package/assets/agents/v3/v3-qe-visual-tester.md +232 -0
  48. package/assets/skills/accessibility-testing/SKILL.md +216 -0
  49. package/assets/skills/agentdb-advanced/SKILL.md +550 -0
  50. package/assets/skills/agentdb-learning/SKILL.md +545 -0
  51. package/assets/skills/agentdb-memory-patterns/SKILL.md +339 -0
  52. package/assets/skills/agentdb-optimization/SKILL.md +509 -0
  53. package/assets/skills/agentdb-vector-search/SKILL.md +339 -0
  54. package/assets/skills/agentic-jujutsu/SKILL.md +645 -0
  55. package/assets/skills/agentic-quality-engineering/SKILL.md +335 -0
  56. package/assets/skills/api-testing-patterns/SKILL.md +294 -0
  57. package/assets/skills/aqe-v2-v3-migration/skill.md +322 -0
  58. package/assets/skills/brutal-honesty-review/README.md +218 -0
  59. package/assets/skills/brutal-honesty-review/SKILL.md +235 -0
  60. package/assets/skills/brutal-honesty-review/resources/assessment-rubrics.md +295 -0
  61. package/assets/skills/brutal-honesty-review/resources/review-template.md +102 -0
  62. package/assets/skills/brutal-honesty-review/scripts/assess-code.sh +179 -0
  63. package/assets/skills/brutal-honesty-review/scripts/assess-tests.sh +223 -0
  64. package/assets/skills/bug-reporting-excellence/SKILL.md +225 -0
  65. package/assets/skills/chaos-engineering-resilience/SKILL.md +158 -0
  66. package/assets/skills/cicd-pipeline-qe-orchestrator/README.md +304 -0
  67. package/assets/skills/cicd-pipeline-qe-orchestrator/SKILL.md +315 -0
  68. package/assets/skills/cicd-pipeline-qe-orchestrator/resources/workflows/microservice-pipeline.md +239 -0
  69. package/assets/skills/cicd-pipeline-qe-orchestrator/resources/workflows/mobile-pipeline.md +375 -0
  70. package/assets/skills/cicd-pipeline-qe-orchestrator/resources/workflows/monolith-pipeline.md +268 -0
  71. package/assets/skills/code-review-quality/SKILL.md +227 -0
  72. package/assets/skills/compatibility-testing/SKILL.md +205 -0
  73. package/assets/skills/compliance-testing/SKILL.md +225 -0
  74. package/assets/skills/consultancy-practices/SKILL.md +202 -0
  75. package/assets/skills/context-driven-testing/SKILL.md +196 -0
  76. package/assets/skills/contract-testing/SKILL.md +222 -0
  77. package/assets/skills/database-testing/SKILL.md +244 -0
  78. package/assets/skills/exploratory-testing-advanced/SKILL.md +201 -0
  79. package/assets/skills/flow-nexus-neural/SKILL.md +738 -0
  80. package/assets/skills/flow-nexus-platform/SKILL.md +1157 -0
  81. package/assets/skills/flow-nexus-swarm/SKILL.md +610 -0
  82. package/assets/skills/github-code-review/SKILL.md +1140 -0
  83. package/assets/skills/github-multi-repo/SKILL.md +874 -0
  84. package/assets/skills/github-project-management/SKILL.md +1277 -0
  85. package/assets/skills/github-release-management/SKILL.md +1081 -0
  86. package/assets/skills/github-workflow-automation/SKILL.md +1065 -0
  87. package/assets/skills/hive-mind-advanced/SKILL.md +712 -0
  88. package/assets/skills/holistic-testing-pact/SKILL.md +171 -0
  89. package/assets/skills/hooks-automation/SKILL.md +1201 -0
  90. package/assets/skills/localization-testing/SKILL.md +221 -0
  91. package/assets/skills/mobile-testing/SKILL.md +219 -0
  92. package/assets/skills/mutation-testing/SKILL.md +229 -0
  93. package/assets/skills/n8n-expression-testing/SKILL.md +434 -0
  94. package/assets/skills/n8n-integration-testing-patterns/SKILL.md +540 -0
  95. package/assets/skills/n8n-security-testing/SKILL.md +599 -0
  96. package/assets/skills/n8n-trigger-testing-strategies/SKILL.md +541 -0
  97. package/assets/skills/n8n-workflow-testing-fundamentals/SKILL.md +447 -0
  98. package/assets/skills/pair-programming/SKILL.md +1202 -0
  99. package/assets/skills/performance-analysis/SKILL.md +563 -0
  100. package/assets/skills/performance-testing/SKILL.md +310 -0
  101. package/assets/skills/quality-metrics/SKILL.md +225 -0
  102. package/assets/skills/reasoningbank-agentdb/SKILL.md +446 -0
  103. package/assets/skills/reasoningbank-intelligence/SKILL.md +201 -0
  104. package/assets/skills/refactoring-patterns/SKILL.md +205 -0
  105. package/assets/skills/regression-testing/SKILL.md +227 -0
  106. package/assets/skills/risk-based-testing/SKILL.md +206 -0
  107. package/assets/skills/security-testing/SKILL.md +306 -0
  108. package/assets/skills/sherlock-review/SKILL.md +250 -0
  109. package/assets/skills/shift-left-testing/SKILL.md +225 -0
  110. package/assets/skills/shift-right-testing/SKILL.md +227 -0
  111. package/assets/skills/six-thinking-hats/README.md +190 -0
  112. package/assets/skills/six-thinking-hats/SKILL.md +280 -0
  113. package/assets/skills/six-thinking-hats/resources/examples/api-testing-example.md +345 -0
  114. package/assets/skills/six-thinking-hats/resources/templates/solo-session-template.md +167 -0
  115. package/assets/skills/six-thinking-hats/resources/templates/team-session-template.md +336 -0
  116. package/assets/skills/skill-builder/SKILL.md +910 -0
  117. package/assets/skills/sparc-methodology/SKILL.md +1115 -0
  118. package/assets/skills/stream-chain/SKILL.md +563 -0
  119. package/assets/skills/swarm-advanced/SKILL.md +973 -0
  120. package/assets/skills/swarm-orchestration/SKILL.md +179 -0
  121. package/assets/skills/tdd-london-chicago/SKILL.md +244 -0
  122. package/assets/skills/technical-writing/SKILL.md +178 -0
  123. package/assets/skills/test-automation-strategy/SKILL.md +230 -0
  124. package/assets/skills/test-data-management/SKILL.md +270 -0
  125. package/assets/skills/test-design-techniques/SKILL.md +244 -0
  126. package/assets/skills/test-environment-management/SKILL.md +243 -0
  127. package/assets/skills/test-reporting-analytics/SKILL.md +214 -0
  128. package/assets/skills/testability-scoring/README.md +71 -0
  129. package/assets/skills/testability-scoring/SKILL.md +346 -0
  130. package/assets/skills/testability-scoring/resources/templates/config.template.js +84 -0
  131. package/assets/skills/testability-scoring/resources/templates/testability-scoring.spec.template.js +532 -0
  132. package/assets/skills/testability-scoring/scripts/generate-html-report.js +1007 -0
  133. package/assets/skills/testability-scoring/scripts/run-assessment.sh +70 -0
  134. package/assets/skills/v3-qe-chaos-resilience/SKILL.md +238 -0
  135. package/assets/skills/v3-qe-code-intelligence/SKILL.md +209 -0
  136. package/assets/skills/v3-qe-contract-testing/SKILL.md +218 -0
  137. package/assets/skills/v3-qe-coverage-analysis/SKILL.md +187 -0
  138. package/assets/skills/v3-qe-defect-intelligence/SKILL.md +205 -0
  139. package/assets/skills/v3-qe-learning-optimization/SKILL.md +238 -0
  140. package/assets/skills/v3-qe-quality-assessment/SKILL.md +213 -0
  141. package/assets/skills/v3-qe-requirements-validation/SKILL.md +248 -0
  142. package/assets/skills/v3-qe-test-execution/SKILL.md +182 -0
  143. package/assets/skills/v3-qe-test-generation/SKILL.md +141 -0
  144. package/assets/skills/v3-qe-visual-accessibility/SKILL.md +242 -0
  145. package/assets/skills/verification-quality/SKILL.md +649 -0
  146. package/assets/skills/visual-testing-advanced/SKILL.md +219 -0
  147. package/assets/skills/xp-practices/SKILL.md +229 -0
  148. package/dist/cli/bundle.js +23 -13
  149. package/dist/init/agents-installer.js +4 -4
  150. package/dist/init/agents-installer.js.map +1 -1
  151. package/dist/init/init-wizard.d.ts.map +1 -1
  152. package/dist/init/init-wizard.js +15 -5
  153. package/dist/init/init-wizard.js.map +1 -1
  154. package/dist/init/skills-installer.js +4 -4
  155. package/dist/init/skills-installer.js.map +1 -1
  156. package/package.json +7 -1
  157. package/docs/analysis/V3-INIT-REQUIREMENTS-ANALYSIS.md +0 -352
  158. package/implementation/README.md +0 -90
  159. package/implementation/adrs/ADR-030-coherence-gated-quality-gates.md +0 -312
  160. package/implementation/adrs/ADR-031-strange-loop-self-awareness.md +0 -484
  161. package/implementation/adrs/ADR-032-time-crystal-scheduling.md +0 -530
  162. package/implementation/adrs/ADR-033-early-exit-testing.md +0 -634
  163. package/implementation/adrs/ADR-034-neural-topology-optimizer.md +0 -589
  164. package/implementation/adrs/ADR-035-causal-discovery.md +0 -610
  165. package/implementation/adrs/ADR-036-result-persistence.md +0 -326
  166. package/implementation/adrs/ADR-037-v3-qe-agent-naming.md +0 -105
  167. package/implementation/adrs/ADR-038-v3-qe-memory-unification.md +0 -154
  168. package/implementation/adrs/ADR-039-v3-qe-mcp-optimization.md +0 -179
  169. package/implementation/adrs/ADR-040-v3-qe-agentic-flow-integration.md +0 -240
  170. package/implementation/adrs/ADR-041-v3-qe-cli-enhancement.md +0 -296
  171. package/implementation/adrs/ADR-042-v3-qe-token-tracking-integration.md +0 -517
  172. package/implementation/adrs/v3-adrs.md +0 -2783
  173. package/implementation/planning/AQE-V3-MASTER-PLAN.md +0 -815
  174. package/security-scan-report-2026-01-11.md +0 -410
  175. package/security-verification-report-2026-01-11.md +0 -278
  176. package/src/benchmarks/performance-benchmarks.ts +0 -646
  177. package/src/benchmarks/run-benchmarks.ts +0 -324
  178. package/src/causal-discovery/causal-graph.ts +0 -450
  179. package/src/causal-discovery/discovery-engine.ts +0 -438
  180. package/src/causal-discovery/index.ts +0 -117
  181. package/src/causal-discovery/types.ts +0 -456
  182. package/src/causal-discovery/weight-matrix.ts +0 -453
  183. package/src/cli/commands/qe-tools.ts +0 -634
  184. package/src/cli/index.ts +0 -1976
  185. package/src/compatibility/agent-mapper.ts +0 -291
  186. package/src/compatibility/cli-adapter.ts +0 -277
  187. package/src/compatibility/config-migrator.ts +0 -334
  188. package/src/compatibility/index.ts +0 -112
  189. package/src/compatibility/mcp-adapter.ts +0 -248
  190. package/src/compatibility/types.ts +0 -156
  191. package/src/coordination/claims/claim-repository.ts +0 -636
  192. package/src/coordination/claims/claim-service.ts +0 -675
  193. package/src/coordination/claims/handoff-manager.ts +0 -535
  194. package/src/coordination/claims/index.ts +0 -276
  195. package/src/coordination/claims/interfaces.ts +0 -687
  196. package/src/coordination/claims/work-stealing.ts +0 -436
  197. package/src/coordination/cross-domain-router.ts +0 -492
  198. package/src/coordination/index.ts +0 -127
  199. package/src/coordination/interfaces.ts +0 -691
  200. package/src/coordination/protocol-executor.ts +0 -760
  201. package/src/coordination/protocols/code-intelligence-index.ts +0 -855
  202. package/src/coordination/protocols/defect-investigation.ts +0 -1184
  203. package/src/coordination/protocols/index.ts +0 -11
  204. package/src/coordination/protocols/learning-consolidation.ts +0 -1181
  205. package/src/coordination/protocols/morning-sync.ts +0 -1055
  206. package/src/coordination/protocols/quality-gate.ts +0 -1566
  207. package/src/coordination/protocols/security-audit.ts +0 -1587
  208. package/src/coordination/queen-coordinator.ts +0 -1176
  209. package/src/coordination/result-saver.ts +0 -780
  210. package/src/coordination/task-executor.ts +0 -1146
  211. package/src/coordination/workflow-orchestrator.ts +0 -1917
  212. package/src/domains/chaos-resilience/coordinator.ts +0 -1032
  213. package/src/domains/chaos-resilience/index.ts +0 -143
  214. package/src/domains/chaos-resilience/interfaces.ts +0 -659
  215. package/src/domains/chaos-resilience/plugin.ts +0 -691
  216. package/src/domains/chaos-resilience/services/chaos-engineer.ts +0 -1097
  217. package/src/domains/chaos-resilience/services/index.ts +0 -19
  218. package/src/domains/chaos-resilience/services/load-tester.ts +0 -799
  219. package/src/domains/chaos-resilience/services/performance-profiler.ts +0 -792
  220. package/src/domains/code-intelligence/coordinator.ts +0 -631
  221. package/src/domains/code-intelligence/index.ts +0 -86
  222. package/src/domains/code-intelligence/interfaces.ts +0 -162
  223. package/src/domains/code-intelligence/plugin.ts +0 -451
  224. package/src/domains/code-intelligence/services/impact-analyzer.ts +0 -567
  225. package/src/domains/code-intelligence/services/index.ts +0 -26
  226. package/src/domains/code-intelligence/services/knowledge-graph.ts +0 -1067
  227. package/src/domains/code-intelligence/services/semantic-analyzer.ts +0 -901
  228. package/src/domains/contract-testing/coordinator.ts +0 -1038
  229. package/src/domains/contract-testing/index.ts +0 -122
  230. package/src/domains/contract-testing/interfaces.ts +0 -458
  231. package/src/domains/contract-testing/plugin.ts +0 -746
  232. package/src/domains/contract-testing/services/api-compatibility.ts +0 -748
  233. package/src/domains/contract-testing/services/contract-validator.ts +0 -1700
  234. package/src/domains/contract-testing/services/index.ts +0 -19
  235. package/src/domains/contract-testing/services/schema-validator.ts +0 -1102
  236. package/src/domains/coverage-analysis/coordinator.ts +0 -485
  237. package/src/domains/coverage-analysis/index.ts +0 -114
  238. package/src/domains/coverage-analysis/interfaces.ts +0 -142
  239. package/src/domains/coverage-analysis/plugin.ts +0 -172
  240. package/src/domains/coverage-analysis/services/coverage-analyzer.ts +0 -449
  241. package/src/domains/coverage-analysis/services/coverage-embedder.ts +0 -733
  242. package/src/domains/coverage-analysis/services/coverage-parser.ts +0 -753
  243. package/src/domains/coverage-analysis/services/gap-detector.ts +0 -592
  244. package/src/domains/coverage-analysis/services/hnsw-index.ts +0 -728
  245. package/src/domains/coverage-analysis/services/index.ts +0 -61
  246. package/src/domains/coverage-analysis/services/risk-scorer.ts +0 -540
  247. package/src/domains/coverage-analysis/services/sublinear-analyzer.ts +0 -747
  248. package/src/domains/defect-intelligence/coordinator.ts +0 -635
  249. package/src/domains/defect-intelligence/index.ts +0 -83
  250. package/src/domains/defect-intelligence/interfaces.ts +0 -152
  251. package/src/domains/defect-intelligence/plugin.ts +0 -483
  252. package/src/domains/defect-intelligence/services/causal-root-cause-analyzer.ts +0 -494
  253. package/src/domains/defect-intelligence/services/defect-predictor.ts +0 -852
  254. package/src/domains/defect-intelligence/services/index.ts +0 -37
  255. package/src/domains/defect-intelligence/services/pattern-learner.ts +0 -738
  256. package/src/domains/defect-intelligence/services/root-cause-analyzer.ts +0 -637
  257. package/src/domains/domain-interface.ts +0 -77
  258. package/src/domains/index.ts +0 -23
  259. package/src/domains/learning-optimization/coordinator.ts +0 -1215
  260. package/src/domains/learning-optimization/index.ts +0 -127
  261. package/src/domains/learning-optimization/interfaces.ts +0 -570
  262. package/src/domains/learning-optimization/plugin.ts +0 -851
  263. package/src/domains/learning-optimization/services/index.ts +0 -29
  264. package/src/domains/learning-optimization/services/learning-coordinator.ts +0 -972
  265. package/src/domains/learning-optimization/services/metrics-optimizer.ts +0 -915
  266. package/src/domains/learning-optimization/services/production-intel.ts +0 -971
  267. package/src/domains/learning-optimization/services/transfer-specialist.ts +0 -723
  268. package/src/domains/quality-assessment/coherence/gate-controller.ts +0 -549
  269. package/src/domains/quality-assessment/coherence/index.ts +0 -211
  270. package/src/domains/quality-assessment/coherence/lambda-calculator.ts +0 -384
  271. package/src/domains/quality-assessment/coherence/partition-detector.ts +0 -469
  272. package/src/domains/quality-assessment/coherence/types.ts +0 -384
  273. package/src/domains/quality-assessment/coordinator.ts +0 -605
  274. package/src/domains/quality-assessment/index.ts +0 -97
  275. package/src/domains/quality-assessment/interfaces.ts +0 -152
  276. package/src/domains/quality-assessment/plugin.ts +0 -496
  277. package/src/domains/quality-assessment/services/coherence-gate.ts +0 -358
  278. package/src/domains/quality-assessment/services/deployment-advisor.ts +0 -571
  279. package/src/domains/quality-assessment/services/index.ts +0 -34
  280. package/src/domains/quality-assessment/services/quality-analyzer.ts +0 -670
  281. package/src/domains/quality-assessment/services/quality-gate.ts +0 -384
  282. package/src/domains/requirements-validation/coordinator.ts +0 -812
  283. package/src/domains/requirements-validation/index.ts +0 -92
  284. package/src/domains/requirements-validation/interfaces.ts +0 -303
  285. package/src/domains/requirements-validation/plugin.ts +0 -576
  286. package/src/domains/requirements-validation/services/bdd-scenario-writer.ts +0 -676
  287. package/src/domains/requirements-validation/services/index.ts +0 -20
  288. package/src/domains/requirements-validation/services/requirements-validator.ts +0 -559
  289. package/src/domains/requirements-validation/services/testability-scorer.ts +0 -639
  290. package/src/domains/security-compliance/coordinator.ts +0 -757
  291. package/src/domains/security-compliance/index.ts +0 -120
  292. package/src/domains/security-compliance/interfaces.ts +0 -434
  293. package/src/domains/security-compliance/plugin.ts +0 -509
  294. package/src/domains/security-compliance/services/compliance-validator.ts +0 -1226
  295. package/src/domains/security-compliance/services/index.ts +0 -31
  296. package/src/domains/security-compliance/services/security-auditor.ts +0 -2227
  297. package/src/domains/security-compliance/services/security-scanner.ts +0 -2354
  298. package/src/domains/security-compliance/services/semgrep-integration.ts +0 -289
  299. package/src/domains/test-execution/coordinator.ts +0 -426
  300. package/src/domains/test-execution/index.ts +0 -76
  301. package/src/domains/test-execution/interfaces.ts +0 -119
  302. package/src/domains/test-execution/plugin.ts +0 -208
  303. package/src/domains/test-execution/services/flaky-detector.ts +0 -1240
  304. package/src/domains/test-execution/services/index.ts +0 -8
  305. package/src/domains/test-execution/services/retry-handler.ts +0 -820
  306. package/src/domains/test-execution/services/test-executor.ts +0 -885
  307. package/src/domains/test-generation/coordinator.ts +0 -656
  308. package/src/domains/test-generation/index.ts +0 -77
  309. package/src/domains/test-generation/interfaces.ts +0 -118
  310. package/src/domains/test-generation/plugin.ts +0 -397
  311. package/src/domains/test-generation/services/index.ts +0 -23
  312. package/src/domains/test-generation/services/pattern-matcher.ts +0 -1725
  313. package/src/domains/test-generation/services/test-generator.ts +0 -2750
  314. package/src/domains/visual-accessibility/coordinator.ts +0 -860
  315. package/src/domains/visual-accessibility/index.ts +0 -116
  316. package/src/domains/visual-accessibility/interfaces.ts +0 -435
  317. package/src/domains/visual-accessibility/plugin.ts +0 -568
  318. package/src/domains/visual-accessibility/services/accessibility-tester.ts +0 -982
  319. package/src/domains/visual-accessibility/services/axe-core-audit.ts +0 -630
  320. package/src/domains/visual-accessibility/services/index.ts +0 -28
  321. package/src/domains/visual-accessibility/services/responsive-tester.ts +0 -934
  322. package/src/domains/visual-accessibility/services/visual-tester.ts +0 -458
  323. package/src/early-exit/early-exit-controller.ts +0 -490
  324. package/src/early-exit/early-exit-decision.ts +0 -391
  325. package/src/early-exit/index.ts +0 -115
  326. package/src/early-exit/quality-signal.ts +0 -389
  327. package/src/early-exit/speculative-executor.ts +0 -505
  328. package/src/early-exit/types.ts +0 -407
  329. package/src/feedback/coverage-learner.ts +0 -456
  330. package/src/feedback/feedback-loop.ts +0 -426
  331. package/src/feedback/index.ts +0 -72
  332. package/src/feedback/pattern-promotion.ts +0 -373
  333. package/src/feedback/quality-score-calculator.ts +0 -334
  334. package/src/feedback/test-outcome-tracker.ts +0 -450
  335. package/src/feedback/types.ts +0 -497
  336. package/src/index.ts +0 -224
  337. package/src/init/agents-installer.ts +0 -536
  338. package/src/init/index.ts +0 -80
  339. package/src/init/init-wizard.ts +0 -1061
  340. package/src/init/project-analyzer.ts +0 -696
  341. package/src/init/self-configurator.ts +0 -488
  342. package/src/init/skills-installer.ts +0 -467
  343. package/src/init/types.ts +0 -432
  344. package/src/integrations/ruvector/ast-complexity.ts +0 -470
  345. package/src/integrations/ruvector/coverage-router.ts +0 -594
  346. package/src/integrations/ruvector/diff-risk-classifier.ts +0 -759
  347. package/src/integrations/ruvector/fallback.ts +0 -942
  348. package/src/integrations/ruvector/graph-boundaries.ts +0 -809
  349. package/src/integrations/ruvector/index.ts +0 -363
  350. package/src/integrations/ruvector/interfaces.ts +0 -609
  351. package/src/integrations/ruvector/q-learning-router.ts +0 -550
  352. package/src/kernel/agent-coordinator.ts +0 -165
  353. package/src/kernel/agentdb-backend.ts +0 -504
  354. package/src/kernel/event-bus.ts +0 -129
  355. package/src/kernel/hybrid-backend.ts +0 -538
  356. package/src/kernel/index.ts +0 -28
  357. package/src/kernel/interfaces.ts +0 -257
  358. package/src/kernel/kernel.ts +0 -285
  359. package/src/kernel/memory-backend.ts +0 -169
  360. package/src/kernel/memory-factory.ts +0 -293
  361. package/src/kernel/plugin-loader.ts +0 -179
  362. package/src/learning/index.ts +0 -219
  363. package/src/learning/pattern-store.ts +0 -990
  364. package/src/learning/qe-guidance.ts +0 -832
  365. package/src/learning/qe-hooks.ts +0 -644
  366. package/src/learning/qe-patterns.ts +0 -449
  367. package/src/learning/qe-reasoning-bank.ts +0 -951
  368. package/src/learning/real-embeddings.ts +0 -277
  369. package/src/learning/real-qe-reasoning-bank.ts +0 -833
  370. package/src/learning/sqlite-persistence.ts +0 -554
  371. package/src/mcp/entry.ts +0 -59
  372. package/src/mcp/handlers/agent-handlers.ts +0 -285
  373. package/src/mcp/handlers/core-handlers.ts +0 -317
  374. package/src/mcp/handlers/domain-handlers.ts +0 -1444
  375. package/src/mcp/handlers/index.ts +0 -57
  376. package/src/mcp/handlers/memory-handlers.ts +0 -338
  377. package/src/mcp/handlers/task-handlers.ts +0 -363
  378. package/src/mcp/index.ts +0 -30
  379. package/src/mcp/metrics/index.ts +0 -14
  380. package/src/mcp/metrics/metrics-collector.ts +0 -503
  381. package/src/mcp/protocol-server.ts +0 -752
  382. package/src/mcp/security/cve-prevention.ts +0 -742
  383. package/src/mcp/security/index.ts +0 -356
  384. package/src/mcp/security/oauth21-provider.ts +0 -821
  385. package/src/mcp/security/rate-limiter.ts +0 -615
  386. package/src/mcp/security/sampling-server.ts +0 -662
  387. package/src/mcp/security/schema-validator.ts +0 -855
  388. package/src/mcp/server.ts +0 -657
  389. package/src/mcp/tool-registry.ts +0 -391
  390. package/src/mcp/tools/base.ts +0 -399
  391. package/src/mcp/tools/chaos-resilience/inject.ts +0 -699
  392. package/src/mcp/tools/code-intelligence/analyze.ts +0 -745
  393. package/src/mcp/tools/contract-testing/validate.ts +0 -708
  394. package/src/mcp/tools/coverage-analysis/index.ts +0 -770
  395. package/src/mcp/tools/defect-intelligence/predict.ts +0 -466
  396. package/src/mcp/tools/index.ts +0 -214
  397. package/src/mcp/tools/learning-optimization/optimize.ts +0 -772
  398. package/src/mcp/tools/quality-assessment/evaluate.ts +0 -385
  399. package/src/mcp/tools/registry.ts +0 -248
  400. package/src/mcp/tools/requirements-validation/validate.ts +0 -394
  401. package/src/mcp/tools/security-compliance/scan.ts +0 -365
  402. package/src/mcp/tools/test-execution/execute.ts +0 -291
  403. package/src/mcp/tools/test-generation/generate.ts +0 -544
  404. package/src/mcp/tools/visual-accessibility/index.ts +0 -791
  405. package/src/mcp/transport/index.ts +0 -31
  406. package/src/mcp/transport/stdio.ts +0 -318
  407. package/src/mcp/types.ts +0 -543
  408. package/src/neural-optimizer/index.ts +0 -111
  409. package/src/neural-optimizer/replay-buffer.ts +0 -455
  410. package/src/neural-optimizer/swarm-topology.ts +0 -508
  411. package/src/neural-optimizer/topology-optimizer.ts +0 -828
  412. package/src/neural-optimizer/types.ts +0 -481
  413. package/src/neural-optimizer/value-network.ts +0 -351
  414. package/src/optimization/auto-tuner.ts +0 -817
  415. package/src/optimization/index.ts +0 -77
  416. package/src/optimization/metric-collectors.ts +0 -474
  417. package/src/optimization/qe-workers.ts +0 -704
  418. package/src/optimization/tuning-algorithm.ts +0 -401
  419. package/src/optimization/types.ts +0 -314
  420. package/src/routing/index.ts +0 -51
  421. package/src/routing/qe-agent-registry.ts +0 -963
  422. package/src/routing/qe-task-router.ts +0 -564
  423. package/src/routing/routing-feedback.ts +0 -365
  424. package/src/routing/types.ts +0 -406
  425. package/src/shared/embeddings/embedding-cache.ts +0 -157
  426. package/src/shared/embeddings/index.ts +0 -50
  427. package/src/shared/embeddings/nomic-embedder.ts +0 -404
  428. package/src/shared/embeddings/ollama-client.ts +0 -195
  429. package/src/shared/embeddings/types.ts +0 -147
  430. package/src/shared/entities/agent.ts +0 -141
  431. package/src/shared/entities/base-entity.ts +0 -79
  432. package/src/shared/entities/index.ts +0 -6
  433. package/src/shared/events/domain-events.ts +0 -259
  434. package/src/shared/events/index.ts +0 -5
  435. package/src/shared/git/git-analyzer.ts +0 -656
  436. package/src/shared/git/index.ts +0 -11
  437. package/src/shared/http/http-client.ts +0 -420
  438. package/src/shared/http/index.ts +0 -13
  439. package/src/shared/index.ts +0 -41
  440. package/src/shared/io/file-reader.ts +0 -525
  441. package/src/shared/io/index.ts +0 -25
  442. package/src/shared/llm/cache.ts +0 -473
  443. package/src/shared/llm/circuit-breaker.ts +0 -369
  444. package/src/shared/llm/cost-tracker.ts +0 -460
  445. package/src/shared/llm/index.ts +0 -140
  446. package/src/shared/llm/interfaces.ts +0 -629
  447. package/src/shared/llm/provider-manager.ts +0 -685
  448. package/src/shared/llm/providers/claude.ts +0 -524
  449. package/src/shared/llm/providers/index.ts +0 -8
  450. package/src/shared/llm/providers/ollama.ts +0 -575
  451. package/src/shared/llm/providers/openai.ts +0 -609
  452. package/src/shared/metrics/code-metrics.ts +0 -520
  453. package/src/shared/metrics/index.ts +0 -23
  454. package/src/shared/metrics/system-metrics.ts +0 -353
  455. package/src/shared/parsers/index.ts +0 -6
  456. package/src/shared/parsers/typescript-parser.ts +0 -841
  457. package/src/shared/security/compliance-patterns.ts +0 -666
  458. package/src/shared/security/index.ts +0 -30
  459. package/src/shared/security/osv-client.ts +0 -468
  460. package/src/shared/types/index.ts +0 -150
  461. package/src/shared/value-objects/index.ts +0 -273
  462. package/src/strange-loop/healing-controller.ts +0 -833
  463. package/src/strange-loop/index.ts +0 -104
  464. package/src/strange-loop/self-model.ts +0 -494
  465. package/src/strange-loop/strange-loop.ts +0 -446
  466. package/src/strange-loop/swarm-observer.ts +0 -448
  467. package/src/strange-loop/topology-analyzer.ts +0 -565
  468. package/src/strange-loop/types.ts +0 -640
  469. package/src/time-crystal/default-phases.ts +0 -520
  470. package/src/time-crystal/index.ts +0 -164
  471. package/src/time-crystal/oscillator.ts +0 -425
  472. package/src/time-crystal/phase-executor.ts +0 -521
  473. package/src/time-crystal/scheduler.ts +0 -1025
  474. package/src/time-crystal/test-runner.ts +0 -787
  475. package/src/time-crystal/types.ts +0 -421
  476. package/src/workers/base-worker.ts +0 -304
  477. package/src/workers/daemon.ts +0 -264
  478. package/src/workers/index.ts +0 -119
  479. package/src/workers/interfaces.ts +0 -393
  480. package/src/workers/worker-manager.ts +0 -424
  481. package/src/workers/workers/compliance-checker.ts +0 -445
  482. package/src/workers/workers/coverage-tracker.ts +0 -344
  483. package/src/workers/workers/defect-predictor.ts +0 -375
  484. package/src/workers/workers/flaky-detector.ts +0 -390
  485. package/src/workers/workers/index.ts +0 -17
  486. package/src/workers/workers/learning-consolidation.ts +0 -442
  487. package/src/workers/workers/performance-baseline.ts +0 -434
  488. package/src/workers/workers/quality-gate.ts +0 -419
  489. package/src/workers/workers/regression-monitor.ts +0 -357
  490. package/src/workers/workers/security-scan.ts +0 -349
  491. package/src/workers/workers/test-health.ts +0 -359
  492. package/tests/integration/code-intelligence/knowledge-graph-real.test.ts +0 -540
  493. package/tests/integration/coordination/cross-domain-router.test.ts +0 -403
  494. package/tests/integration/coordination/protocol-executor.test.ts +0 -454
  495. package/tests/integration/coordination/workflow-orchestrator.test.ts +0 -418
  496. package/tests/integration/feedback/feedback-loop-integration.test.ts +0 -560
  497. package/tests/integration/migration/v2-to-v3-migration.test.ts +0 -471
  498. package/tests/integration/parsers/typescript-parser.test.ts +0 -463
  499. package/tests/integration/security/vulnerability-detection.test.ts +0 -628
  500. package/tests/integration/test-execution/coordinator.test.ts +0 -410
  501. package/tests/integration/test-generation/coordinator.test.ts +0 -361
  502. package/tests/mocks/index.ts +0 -228
  503. package/tests/time-crystal/default-phases.test.ts +0 -476
  504. package/tests/time-crystal/oscillator.test.ts +0 -541
  505. package/tests/time-crystal/phase-executor.test.ts +0 -653
  506. package/tests/time-crystal/scheduler.test.ts +0 -626
  507. package/tests/time-crystal/test-runner.test.ts +0 -594
  508. package/tests/unit/causal-discovery/causal-graph.test.ts +0 -504
  509. package/tests/unit/causal-discovery/causal-root-cause-analyzer.test.ts +0 -347
  510. package/tests/unit/causal-discovery/discovery-engine.test.ts +0 -435
  511. package/tests/unit/causal-discovery/weight-matrix.test.ts +0 -328
  512. package/tests/unit/cli/cli.test.ts +0 -341
  513. package/tests/unit/cli/commands.test.ts +0 -414
  514. package/tests/unit/cli/init-command.test.ts +0 -274
  515. package/tests/unit/cli/migrate-command.test.ts +0 -396
  516. package/tests/unit/coordination/claims/claim-service.test.ts +0 -949
  517. package/tests/unit/coordination/claims/handoff-manager.test.ts +0 -773
  518. package/tests/unit/coordination/claims/work-stealing.test.ts +0 -492
  519. package/tests/unit/coordination/queen-coordinator.test.ts +0 -966
  520. package/tests/unit/coordination/result-saver.test.ts +0 -653
  521. package/tests/unit/coordination/task-executor.test.ts +0 -810
  522. package/tests/unit/domains/chaos-resilience/chaos-engineer.test.ts +0 -484
  523. package/tests/unit/domains/chaos-resilience/load-tester.test.ts +0 -559
  524. package/tests/unit/domains/chaos-resilience/performance-profiler.test.ts +0 -490
  525. package/tests/unit/domains/code-intelligence/impact-analyzer.test.ts +0 -560
  526. package/tests/unit/domains/code-intelligence/knowledge-graph.test.ts +0 -460
  527. package/tests/unit/domains/code-intelligence/semantic-analyzer.test.ts +0 -584
  528. package/tests/unit/domains/contract-testing/api-compatibility.test.ts +0 -483
  529. package/tests/unit/domains/contract-testing/contract-validator.test.ts +0 -370
  530. package/tests/unit/domains/contract-testing/schema-validator.test.ts +0 -610
  531. package/tests/unit/domains/coverage-analysis/coverage-embedder.test.ts +0 -298
  532. package/tests/unit/domains/coverage-analysis/hnsw-index.test.ts +0 -292
  533. package/tests/unit/domains/coverage-analysis/sublinear-analyzer.test.ts +0 -506
  534. package/tests/unit/domains/defect-intelligence/defect-predictor.test.ts +0 -370
  535. package/tests/unit/domains/defect-intelligence/pattern-learner.test.ts +0 -546
  536. package/tests/unit/domains/defect-intelligence/root-cause-analyzer.test.ts +0 -534
  537. package/tests/unit/domains/learning-optimization/learning-coordinator.test.ts +0 -541
  538. package/tests/unit/domains/learning-optimization/metrics-optimizer.test.ts +0 -552
  539. package/tests/unit/domains/learning-optimization/production-intel.test.ts +0 -589
  540. package/tests/unit/domains/learning-optimization/transfer-specialist.test.ts +0 -453
  541. package/tests/unit/domains/quality-assessment/coherence-gate.test.ts +0 -1006
  542. package/tests/unit/domains/quality-assessment/deployment-advisor.test.ts +0 -515
  543. package/tests/unit/domains/quality-assessment/quality-analyzer.test.ts +0 -401
  544. package/tests/unit/domains/quality-assessment/quality-gate.test.ts +0 -324
  545. package/tests/unit/domains/requirements-validation/bdd-scenario-writer.test.ts +0 -479
  546. package/tests/unit/domains/requirements-validation/requirements-validator.test.ts +0 -452
  547. package/tests/unit/domains/requirements-validation/testability-scorer.test.ts +0 -505
  548. package/tests/unit/domains/security-compliance/compliance-validator.test.ts +0 -500
  549. package/tests/unit/domains/security-compliance/security-auditor.test.ts +0 -498
  550. package/tests/unit/domains/security-compliance/security-scanner.test.ts +0 -412
  551. package/tests/unit/domains/visual-accessibility/accessibility-tester.test.ts +0 -432
  552. package/tests/unit/domains/visual-accessibility/responsive-tester.test.ts +0 -506
  553. package/tests/unit/domains/visual-accessibility/visual-tester.test.ts +0 -412
  554. package/tests/unit/early-exit/early-exit-controller.test.ts +0 -548
  555. package/tests/unit/early-exit/early-exit-decision.test.ts +0 -617
  556. package/tests/unit/early-exit/index.test.ts +0 -254
  557. package/tests/unit/early-exit/quality-signal.test.ts +0 -589
  558. package/tests/unit/early-exit/speculative-executor.test.ts +0 -453
  559. package/tests/unit/feedback/coverage-learner.test.ts +0 -288
  560. package/tests/unit/feedback/feedback-loop.test.ts +0 -458
  561. package/tests/unit/feedback/pattern-promotion.test.ts +0 -390
  562. package/tests/unit/feedback/quality-score-calculator.test.ts +0 -364
  563. package/tests/unit/feedback/test-outcome-tracker.test.ts +0 -243
  564. package/tests/unit/init/init-wizard.test.ts +0 -881
  565. package/tests/unit/init/project-analyzer.test.ts +0 -807
  566. package/tests/unit/init/self-configurator.test.ts +0 -493
  567. package/tests/unit/integrations/ruvector/ast-complexity.test.ts +0 -240
  568. package/tests/unit/integrations/ruvector/coverage-router.test.ts +0 -366
  569. package/tests/unit/integrations/ruvector/diff-risk-classifier.test.ts +0 -340
  570. package/tests/unit/integrations/ruvector/graph-boundaries.test.ts +0 -355
  571. package/tests/unit/integrations/ruvector/q-learning-router.test.ts +0 -314
  572. package/tests/unit/kernel/agent-coordinator.test.ts +0 -220
  573. package/tests/unit/kernel/event-bus.test.ts +0 -197
  574. package/tests/unit/learning/qe-reasoning-bank.test.ts +0 -666
  575. package/tests/unit/learning/real-qe-reasoning-bank.benchmark.test.ts +0 -415
  576. package/tests/unit/mcp/mcp-server.test.ts +0 -544
  577. package/tests/unit/mcp/metrics/metrics-collector.test.ts +0 -340
  578. package/tests/unit/mcp/security/cve-prevention.test.ts +0 -512
  579. package/tests/unit/mcp/security/oauth21-provider.test.ts +0 -624
  580. package/tests/unit/mcp/security/rate-limiter.test.ts +0 -410
  581. package/tests/unit/mcp/security/sampling-server.test.ts +0 -420
  582. package/tests/unit/mcp/security/schema-validator.test.ts +0 -494
  583. package/tests/unit/mcp/tools/base.test.ts +0 -336
  584. package/tests/unit/mcp/tools/domain-tools.test.ts +0 -759
  585. package/tests/unit/mcp/tools/registry.test.ts +0 -240
  586. package/tests/unit/neural-optimizer/replay-buffer.test.ts +0 -403
  587. package/tests/unit/neural-optimizer/swarm-topology.test.ts +0 -473
  588. package/tests/unit/neural-optimizer/topology-optimizer.test.ts +0 -595
  589. package/tests/unit/neural-optimizer/value-network.test.ts +0 -343
  590. package/tests/unit/optimization/auto-tuner.test.ts +0 -506
  591. package/tests/unit/optimization/metric-collectors.test.ts +0 -352
  592. package/tests/unit/optimization/qe-workers.test.ts +0 -407
  593. package/tests/unit/optimization/tuning-algorithm.test.ts +0 -467
  594. package/tests/unit/routing/qe-agent-registry.test.ts +0 -229
  595. package/tests/unit/routing/qe-task-router.test.ts +0 -390
  596. package/tests/unit/routing/routing-feedback.test.ts +0 -339
  597. package/tests/unit/shared/embeddings/nomic-embedder.test.ts +0 -419
  598. package/tests/unit/shared/http/http-client.test.ts +0 -719
  599. package/tests/unit/shared/io/file-reader.test.ts +0 -511
  600. package/tests/unit/shared/llm/cache.test.ts +0 -391
  601. package/tests/unit/shared/llm/circuit-breaker.test.ts +0 -293
  602. package/tests/unit/shared/llm/cost-tracker.test.ts +0 -431
  603. package/tests/unit/shared/llm/provider-manager.test.ts +0 -550
  604. package/tests/unit/shared/llm/providers.test.ts +0 -532
  605. package/tests/unit/shared/parsers/typescript-parser.test.ts +0 -693
  606. package/tests/unit/shared/value-objects.test.ts +0 -184
  607. package/tests/unit/strange-loop/strange-loop.test.ts +0 -1170
  608. package/tests/unit/workers/base-worker.test.ts +0 -341
  609. package/tests/unit/workers/daemon.test.ts +0 -291
  610. package/tests/unit/workers/worker-manager.test.ts +0 -284
  611. package/tsconfig.json +0 -32
  612. package/vitest.config.ts +0 -27
@@ -1,1176 +0,0 @@
1
- /**
2
- * Agentic QE v3 - Queen Coordinator
3
- * The sovereign orchestrator of the hierarchical hive operations.
4
- * Manages 12 domain coordinators, work stealing, and cross-domain workflows.
5
- *
6
- * Per Master Plan Section 4.1:
7
- * - Agent #1 in the hierarchy
8
- * - Coordinates 47 agents across 12 domains
9
- * - Implements work stealing for load balancing
10
- * - Orchestrates cross-domain protocols
11
- */
12
-
13
- import { v4 as uuidv4 } from 'uuid';
14
- import {
15
- DomainName,
16
- DomainEvent,
17
- ALL_DOMAINS,
18
- Result,
19
- ok,
20
- err,
21
- Priority,
22
- AgentStatus,
23
- Severity,
24
- } from '../shared/types';
25
- import {
26
- EventBus,
27
- AgentCoordinator,
28
- AgentInfo,
29
- DomainPlugin,
30
- DomainHealth,
31
- MemoryBackend,
32
- QEKernel,
33
- } from '../kernel/interfaces';
34
- import { CrossDomainRouter, ProtocolExecutor, WorkflowExecutor } from './interfaces';
35
-
36
- // ============================================================================
37
- // Types
38
- // ============================================================================
39
-
40
- /**
41
- * Task that can be assigned to domains
42
- */
43
- export interface QueenTask {
44
- readonly id: string;
45
- readonly type: TaskType;
46
- readonly priority: Priority;
47
- readonly targetDomains: DomainName[];
48
- readonly payload: Record<string, unknown>;
49
- readonly timeout: number;
50
- readonly createdAt: Date;
51
- readonly requester?: string;
52
- readonly correlationId?: string;
53
- }
54
-
55
- export type TaskType =
56
- | 'generate-tests'
57
- | 'execute-tests'
58
- | 'analyze-coverage'
59
- | 'assess-quality'
60
- | 'predict-defects'
61
- | 'validate-requirements'
62
- | 'index-code'
63
- | 'scan-security'
64
- | 'validate-contracts'
65
- | 'test-accessibility'
66
- | 'run-chaos'
67
- | 'optimize-learning'
68
- | 'cross-domain-workflow'
69
- | 'protocol-execution';
70
-
71
- /**
72
- * Task execution status
73
- */
74
- export interface TaskExecution {
75
- readonly taskId: string;
76
- readonly task: QueenTask;
77
- readonly status: 'queued' | 'assigned' | 'running' | 'completed' | 'failed' | 'cancelled';
78
- readonly assignedDomain?: DomainName;
79
- readonly assignedAgents: string[];
80
- readonly startedAt?: Date;
81
- readonly completedAt?: Date;
82
- readonly result?: unknown;
83
- readonly error?: string;
84
- readonly retryCount: number;
85
- }
86
-
87
- /**
88
- * Domain group for coordination
89
- */
90
- export interface DomainGroup {
91
- readonly name: string;
92
- readonly domains: DomainName[];
93
- readonly priority: Priority;
94
- readonly description: string;
95
- }
96
-
97
- /**
98
- * Work stealing configuration
99
- */
100
- export interface WorkStealingConfig {
101
- enabled: boolean;
102
- idleThreshold: number; // Time in ms before domain is considered idle
103
- loadThreshold: number; // Max pending tasks before stealing is triggered
104
- stealBatchSize: number; // Number of tasks to steal at once
105
- checkInterval: number; // How often to check for work stealing opportunities
106
- }
107
-
108
- /**
109
- * Queen Coordinator metrics
110
- */
111
- export interface QueenMetrics {
112
- readonly tasksReceived: number;
113
- readonly tasksCompleted: number;
114
- readonly tasksFailed: number;
115
- readonly tasksStolen: number;
116
- readonly averageTaskDuration: number;
117
- readonly domainUtilization: Map<DomainName, number>;
118
- readonly agentUtilization: number;
119
- readonly protocolsExecuted: number;
120
- readonly workflowsExecuted: number;
121
- readonly uptime: number;
122
- }
123
-
124
- /**
125
- * Queen Coordinator configuration
126
- */
127
- export interface QueenConfig {
128
- maxConcurrentTasks: number;
129
- defaultTaskTimeout: number;
130
- taskRetryLimit: number;
131
- workStealing: WorkStealingConfig;
132
- enableMetrics: boolean;
133
- metricsInterval: number;
134
- priorityWeights: Record<Priority, number>;
135
- }
136
-
137
- /**
138
- * Queen health status
139
- */
140
- export interface QueenHealth {
141
- status: 'healthy' | 'degraded' | 'unhealthy';
142
- domainHealth: Map<DomainName, DomainHealth>;
143
- totalAgents: number;
144
- activeAgents: number;
145
- pendingTasks: number;
146
- runningTasks: number;
147
- workStealingActive: boolean;
148
- lastHealthCheck: Date;
149
- issues: HealthIssue[];
150
- }
151
-
152
- export interface HealthIssue {
153
- domain?: DomainName;
154
- severity: Severity;
155
- message: string;
156
- timestamp: Date;
157
- }
158
-
159
- /**
160
- * Queen Coordinator interface
161
- */
162
- export interface IQueenCoordinator {
163
- // Lifecycle
164
- initialize(): Promise<void>;
165
- dispose(): Promise<void>;
166
-
167
- // Task Management
168
- submitTask(task: Omit<QueenTask, 'id' | 'createdAt'>): Promise<Result<string, Error>>;
169
- cancelTask(taskId: string): Promise<Result<void, Error>>;
170
- getTaskStatus(taskId: string): TaskExecution | undefined;
171
- listTasks(filter?: TaskFilter): TaskExecution[];
172
-
173
- // Domain Coordination
174
- getDomainHealth(domain: DomainName): DomainHealth | undefined;
175
- getDomainLoad(domain: DomainName): number;
176
- getIdleDomains(): DomainName[];
177
- getBusyDomains(): DomainName[];
178
-
179
- // Work Stealing
180
- enableWorkStealing(): void;
181
- disableWorkStealing(): void;
182
- triggerWorkStealing(): Promise<number>;
183
-
184
- // Agent Management
185
- listAllAgents(): AgentInfo[];
186
- getAgentsByDomain(domain: DomainName): AgentInfo[];
187
- requestAgentSpawn(domain: DomainName, type: string, capabilities: string[]): Promise<Result<string, Error>>;
188
-
189
- // Health & Metrics
190
- getHealth(): QueenHealth;
191
- getMetrics(): QueenMetrics;
192
-
193
- // Protocol & Workflow
194
- executeProtocol(protocolId: string, params?: Record<string, unknown>): Promise<Result<string, Error>>;
195
- executeWorkflow(workflowId: string, params?: Record<string, unknown>): Promise<Result<string, Error>>;
196
- }
197
-
198
- export interface TaskFilter {
199
- status?: TaskExecution['status'];
200
- domain?: DomainName;
201
- priority?: Priority;
202
- type?: TaskType;
203
- fromDate?: Date;
204
- toDate?: Date;
205
- }
206
-
207
- // ============================================================================
208
- // Domain Groups (per Master Plan Section 4.1)
209
- // ============================================================================
210
-
211
- export const DOMAIN_GROUPS: DomainGroup[] = [
212
- {
213
- name: 'Core Testing',
214
- domains: ['test-generation', 'test-execution', 'coverage-analysis', 'quality-assessment'],
215
- priority: 'p0',
216
- description: 'Core testing workflow domains',
217
- },
218
- {
219
- name: 'Intelligence',
220
- domains: ['defect-intelligence', 'code-intelligence', 'requirements-validation', 'security-compliance'],
221
- priority: 'p0',
222
- description: 'Intelligence and analysis domains',
223
- },
224
- {
225
- name: 'Specialized',
226
- domains: ['contract-testing', 'visual-accessibility', 'chaos-resilience', 'learning-optimization'],
227
- priority: 'p1',
228
- description: 'Specialized testing domains',
229
- },
230
- ];
231
-
232
- // Task type to domain mapping
233
- const TASK_DOMAIN_MAP: Record<TaskType, DomainName[]> = {
234
- 'generate-tests': ['test-generation'],
235
- 'execute-tests': ['test-execution'],
236
- 'analyze-coverage': ['coverage-analysis'],
237
- 'assess-quality': ['quality-assessment'],
238
- 'predict-defects': ['defect-intelligence'],
239
- 'validate-requirements': ['requirements-validation'],
240
- 'index-code': ['code-intelligence'],
241
- 'scan-security': ['security-compliance'],
242
- 'validate-contracts': ['contract-testing'],
243
- 'test-accessibility': ['visual-accessibility'],
244
- 'run-chaos': ['chaos-resilience'],
245
- 'optimize-learning': ['learning-optimization'],
246
- 'cross-domain-workflow': ALL_DOMAINS as unknown as DomainName[],
247
- 'protocol-execution': ALL_DOMAINS as unknown as DomainName[],
248
- };
249
-
250
- // ============================================================================
251
- // Default Configuration
252
- // ============================================================================
253
-
254
- const DEFAULT_CONFIG: QueenConfig = {
255
- maxConcurrentTasks: 50,
256
- defaultTaskTimeout: 300000, // 5 minutes
257
- taskRetryLimit: 3,
258
- workStealing: {
259
- enabled: true,
260
- idleThreshold: 5000, // 5 seconds
261
- loadThreshold: 10,
262
- stealBatchSize: 3,
263
- checkInterval: 10000, // 10 seconds
264
- },
265
- enableMetrics: true,
266
- metricsInterval: 60000, // 1 minute
267
- priorityWeights: {
268
- p0: 100,
269
- p1: 50,
270
- p2: 25,
271
- p3: 10,
272
- },
273
- };
274
-
275
- // ============================================================================
276
- // Queen Coordinator Implementation
277
- // ============================================================================
278
-
279
- export class QueenCoordinator implements IQueenCoordinator {
280
- private readonly config: QueenConfig;
281
- private readonly tasks: Map<string, TaskExecution> = new Map();
282
- private readonly taskQueue: Map<Priority, QueenTask[]> = new Map();
283
- private readonly domainQueues: Map<DomainName, QueenTask[]> = new Map();
284
- private readonly domainLastActivity: Map<DomainName, Date> = new Map();
285
-
286
- private initialized = false;
287
- private workStealingTimer: NodeJS.Timeout | null = null;
288
- private metricsTimer: NodeJS.Timeout | null = null;
289
- private startTime: Date = new Date();
290
-
291
- // Metrics counters
292
- private tasksReceived = 0;
293
- private tasksCompleted = 0;
294
- private tasksFailed = 0;
295
- private tasksStolen = 0;
296
- private taskDurations: number[] = [];
297
- private protocolsExecuted = 0;
298
- private workflowsExecuted = 0;
299
-
300
- constructor(
301
- private readonly eventBus: EventBus,
302
- private readonly agentCoordinator: AgentCoordinator,
303
- private readonly memory: MemoryBackend,
304
- private readonly router: CrossDomainRouter,
305
- private readonly protocolExecutor?: ProtocolExecutor,
306
- private readonly workflowExecutor?: WorkflowExecutor,
307
- private readonly domainPlugins?: Map<DomainName, DomainPlugin>,
308
- config: Partial<QueenConfig> = {}
309
- ) {
310
- this.config = { ...DEFAULT_CONFIG, ...config };
311
-
312
- // Initialize priority queues
313
- (['p0', 'p1', 'p2', 'p3'] as Priority[]).forEach(p => {
314
- this.taskQueue.set(p, []);
315
- });
316
-
317
- // Initialize domain queues
318
- ALL_DOMAINS.forEach(domain => {
319
- this.domainQueues.set(domain, []);
320
- this.domainLastActivity.set(domain, new Date());
321
- });
322
- }
323
-
324
- // ============================================================================
325
- // Lifecycle
326
- // ============================================================================
327
-
328
- async initialize(): Promise<void> {
329
- if (this.initialized) return;
330
-
331
- this.startTime = new Date();
332
-
333
- // Initialize cross-domain router
334
- await this.router.initialize();
335
-
336
- // Subscribe to domain events for coordination
337
- this.subscribeToEvents();
338
-
339
- // Start work stealing if enabled
340
- if (this.config.workStealing.enabled) {
341
- this.startWorkStealing();
342
- }
343
-
344
- // Start metrics collection if enabled
345
- if (this.config.enableMetrics) {
346
- this.startMetricsCollection();
347
- }
348
-
349
- // Load persisted state
350
- await this.loadState();
351
-
352
- // Publish initialization event
353
- await this.publishEvent('QueenInitialized', {
354
- timestamp: new Date(),
355
- config: this.config,
356
- domains: ALL_DOMAINS,
357
- });
358
-
359
- this.initialized = true;
360
- }
361
-
362
- async dispose(): Promise<void> {
363
- // Stop timers
364
- if (this.workStealingTimer) {
365
- clearInterval(this.workStealingTimer);
366
- this.workStealingTimer = null;
367
- }
368
- if (this.metricsTimer) {
369
- clearInterval(this.metricsTimer);
370
- this.metricsTimer = null;
371
- }
372
-
373
- // Save state
374
- await this.saveState();
375
-
376
- // Cancel all pending tasks
377
- for (const [taskId, execution] of this.tasks) {
378
- if (execution.status === 'queued' || execution.status === 'running') {
379
- await this.cancelTask(taskId);
380
- }
381
- }
382
-
383
- // Publish shutdown event
384
- await this.publishEvent('QueenShutdown', {
385
- timestamp: new Date(),
386
- metrics: this.getMetrics(),
387
- });
388
-
389
- // Dispose router
390
- await this.router.dispose();
391
-
392
- this.initialized = false;
393
- }
394
-
395
- // ============================================================================
396
- // Task Management
397
- // ============================================================================
398
-
399
- async submitTask(taskInput: Omit<QueenTask, 'id' | 'createdAt'>): Promise<Result<string, Error>> {
400
- if (!this.initialized) {
401
- return err(new Error('Queen Coordinator not initialized'));
402
- }
403
-
404
- const taskId = `task_${uuidv4()}`;
405
- const task: QueenTask = {
406
- ...taskInput,
407
- id: taskId,
408
- createdAt: new Date(),
409
- timeout: taskInput.timeout || this.config.defaultTaskTimeout,
410
- };
411
-
412
- // Check concurrent task limit
413
- const runningCount = this.getRunningTaskCount();
414
- if (runningCount >= this.config.maxConcurrentTasks) {
415
- // Queue the task instead of rejecting
416
- this.enqueueTask(task);
417
- const execution: TaskExecution = {
418
- taskId,
419
- task,
420
- status: 'queued',
421
- assignedAgents: [],
422
- retryCount: 0,
423
- };
424
- this.tasks.set(taskId, execution);
425
- this.tasksReceived++;
426
-
427
- await this.publishEvent('TaskQueued', { taskId, task, position: this.getQueuePosition(task) });
428
- return ok(taskId);
429
- }
430
-
431
- // Assign task to appropriate domain(s)
432
- const assignResult = await this.assignTask(task);
433
- if (!assignResult.success) {
434
- return assignResult;
435
- }
436
-
437
- this.tasksReceived++;
438
- await this.publishEvent('TaskSubmitted', { taskId, task });
439
-
440
- return ok(taskId);
441
- }
442
-
443
- async cancelTask(taskId: string): Promise<Result<void, Error>> {
444
- const execution = this.tasks.get(taskId);
445
- if (!execution) {
446
- return err(new Error(`Task not found: ${taskId}`));
447
- }
448
-
449
- if (execution.status === 'completed' || execution.status === 'failed') {
450
- return err(new Error(`Task already finished: ${taskId}`));
451
- }
452
-
453
- // Update status
454
- const updated: TaskExecution = {
455
- ...execution,
456
- status: 'cancelled',
457
- completedAt: new Date(),
458
- };
459
- this.tasks.set(taskId, updated);
460
-
461
- // Remove from queues
462
- this.removeFromQueues(execution.task);
463
-
464
- // Stop assigned agents if any
465
- for (const agentId of execution.assignedAgents) {
466
- await this.agentCoordinator.stop(agentId);
467
- }
468
-
469
- await this.publishEvent('TaskCancelled', { taskId });
470
-
471
- return ok(undefined);
472
- }
473
-
474
- getTaskStatus(taskId: string): TaskExecution | undefined {
475
- return this.tasks.get(taskId);
476
- }
477
-
478
- listTasks(filter?: TaskFilter): TaskExecution[] {
479
- let tasks = Array.from(this.tasks.values());
480
-
481
- if (filter) {
482
- if (filter.status) {
483
- tasks = tasks.filter(t => t.status === filter.status);
484
- }
485
- if (filter.domain) {
486
- tasks = tasks.filter(t => t.assignedDomain === filter.domain);
487
- }
488
- if (filter.priority) {
489
- tasks = tasks.filter(t => t.task.priority === filter.priority);
490
- }
491
- if (filter.type) {
492
- tasks = tasks.filter(t => t.task.type === filter.type);
493
- }
494
- if (filter.fromDate) {
495
- tasks = tasks.filter(t => t.task.createdAt >= filter.fromDate!);
496
- }
497
- if (filter.toDate) {
498
- tasks = tasks.filter(t => t.task.createdAt <= filter.toDate!);
499
- }
500
- }
501
-
502
- return tasks;
503
- }
504
-
505
- // ============================================================================
506
- // Domain Coordination
507
- // ============================================================================
508
-
509
- getDomainHealth(domain: DomainName): DomainHealth | undefined {
510
- if (this.domainPlugins) {
511
- const plugin = this.domainPlugins.get(domain);
512
- return plugin?.getHealth();
513
- }
514
-
515
- // Fallback: compute from agent coordinator
516
- const agents = this.agentCoordinator.listAgents({ domain });
517
- return {
518
- status: agents.length > 0 ? 'healthy' : 'degraded',
519
- agents: {
520
- total: agents.length,
521
- active: agents.filter(a => a.status === 'running').length,
522
- idle: agents.filter(a => a.status === 'idle').length,
523
- failed: agents.filter(a => a.status === 'failed').length,
524
- },
525
- lastActivity: this.domainLastActivity.get(domain),
526
- errors: [],
527
- };
528
- }
529
-
530
- getDomainLoad(domain: DomainName): number {
531
- const queue = this.domainQueues.get(domain) || [];
532
- const runningTasks = Array.from(this.tasks.values())
533
- .filter(t => t.assignedDomain === domain && t.status === 'running');
534
- return queue.length + runningTasks.length;
535
- }
536
-
537
- getIdleDomains(): DomainName[] {
538
- const now = Date.now();
539
- const idleThreshold = this.config.workStealing.idleThreshold;
540
-
541
- return ALL_DOMAINS.filter(domain => {
542
- const lastActivity = this.domainLastActivity.get(domain);
543
- const load = this.getDomainLoad(domain);
544
- return load === 0 && lastActivity && (now - lastActivity.getTime()) > idleThreshold;
545
- });
546
- }
547
-
548
- getBusyDomains(): DomainName[] {
549
- const loadThreshold = this.config.workStealing.loadThreshold;
550
- return ALL_DOMAINS.filter(domain => this.getDomainLoad(domain) > loadThreshold);
551
- }
552
-
553
- // ============================================================================
554
- // Work Stealing Algorithm
555
- // ============================================================================
556
-
557
- enableWorkStealing(): void {
558
- if (!this.workStealingTimer) {
559
- this.startWorkStealing();
560
- }
561
- }
562
-
563
- disableWorkStealing(): void {
564
- if (this.workStealingTimer) {
565
- clearInterval(this.workStealingTimer);
566
- this.workStealingTimer = null;
567
- }
568
- }
569
-
570
- async triggerWorkStealing(): Promise<number> {
571
- let stolenCount = 0;
572
- const idleDomains = this.getIdleDomains();
573
- const busyDomains = this.getBusyDomains();
574
-
575
- if (idleDomains.length === 0 || busyDomains.length === 0) {
576
- return 0;
577
- }
578
-
579
- // Sort busy domains by load (highest first)
580
- busyDomains.sort((a, b) => this.getDomainLoad(b) - this.getDomainLoad(a));
581
-
582
- for (const busyDomain of busyDomains) {
583
- if (idleDomains.length === 0) break;
584
-
585
- const queue = this.domainQueues.get(busyDomain) || [];
586
- const stealCount = Math.min(queue.length, this.config.workStealing.stealBatchSize);
587
-
588
- for (let i = 0; i < stealCount && idleDomains.length > 0; i++) {
589
- // Find a task that can be handled by an idle domain
590
- const task = queue.find(t => this.canDomainHandleTask(idleDomains[0], t));
591
-
592
- if (task) {
593
- // Steal the task
594
- const stealerDomain = idleDomains.shift()!;
595
- this.removeFromQueues(task);
596
-
597
- // Reassign to idle domain
598
- await this.assignTaskToDomain(task, stealerDomain);
599
-
600
- stolenCount++;
601
- this.tasksStolen++;
602
-
603
- await this.publishEvent('TaskStolen', {
604
- taskId: task.id,
605
- fromDomain: busyDomain,
606
- toDomain: stealerDomain,
607
- });
608
- }
609
- }
610
- }
611
-
612
- return stolenCount;
613
- }
614
-
615
- // ============================================================================
616
- // Agent Management
617
- // ============================================================================
618
-
619
- listAllAgents(): AgentInfo[] {
620
- return this.agentCoordinator.listAgents();
621
- }
622
-
623
- getAgentsByDomain(domain: DomainName): AgentInfo[] {
624
- return this.agentCoordinator.listAgents({ domain });
625
- }
626
-
627
- async requestAgentSpawn(
628
- domain: DomainName,
629
- type: string,
630
- capabilities: string[]
631
- ): Promise<Result<string, Error>> {
632
- if (!this.agentCoordinator.canSpawn()) {
633
- return err(new Error('Maximum concurrent agents reached (15)'));
634
- }
635
-
636
- const result = await this.agentCoordinator.spawn({
637
- name: `${domain}-${type}-${Date.now()}`,
638
- domain,
639
- type,
640
- capabilities,
641
- });
642
-
643
- if (result.success) {
644
- this.domainLastActivity.set(domain, new Date());
645
- await this.publishEvent('AgentSpawned', {
646
- agentId: result.value,
647
- domain,
648
- type,
649
- capabilities,
650
- });
651
- }
652
-
653
- return result;
654
- }
655
-
656
- // ============================================================================
657
- // Health & Metrics
658
- // ============================================================================
659
-
660
- getHealth(): QueenHealth {
661
- const domainHealth = new Map<DomainName, DomainHealth>();
662
- const issues: HealthIssue[] = [];
663
- let unhealthyCount = 0;
664
- let degradedCount = 0;
665
-
666
- for (const domain of ALL_DOMAINS) {
667
- const health = this.getDomainHealth(domain);
668
- if (health) {
669
- domainHealth.set(domain, health);
670
- if (health.status === 'unhealthy') {
671
- unhealthyCount++;
672
- issues.push({
673
- domain,
674
- severity: 'high',
675
- message: `Domain ${domain} is unhealthy`,
676
- timestamp: new Date(),
677
- });
678
- } else if (health.status === 'degraded') {
679
- degradedCount++;
680
- issues.push({
681
- domain,
682
- severity: 'medium',
683
- message: `Domain ${domain} is degraded`,
684
- timestamp: new Date(),
685
- });
686
- }
687
- }
688
- }
689
-
690
- const agents = this.agentCoordinator.listAgents();
691
- const activeAgents = agents.filter(a => a.status === 'running').length;
692
- const pendingTasks = this.getQueuedTaskCount();
693
- const runningTasks = this.getRunningTaskCount();
694
-
695
- // Determine overall health
696
- let status: QueenHealth['status'] = 'healthy';
697
- if (unhealthyCount > 0) {
698
- status = 'unhealthy';
699
- } else if (degradedCount > ALL_DOMAINS.length / 2) {
700
- status = 'degraded';
701
- }
702
-
703
- return {
704
- status,
705
- domainHealth,
706
- totalAgents: agents.length,
707
- activeAgents,
708
- pendingTasks,
709
- runningTasks,
710
- workStealingActive: this.workStealingTimer !== null,
711
- lastHealthCheck: new Date(),
712
- issues,
713
- };
714
- }
715
-
716
- getMetrics(): QueenMetrics {
717
- const domainUtilization = new Map<DomainName, number>();
718
- let totalLoad = 0;
719
-
720
- for (const domain of ALL_DOMAINS) {
721
- const load = this.getDomainLoad(domain);
722
- domainUtilization.set(domain, load);
723
- totalLoad += load;
724
- }
725
-
726
- const agents = this.agentCoordinator.listAgents();
727
- const activeAgents = agents.filter(a => a.status === 'running').length;
728
- const agentUtilization = agents.length > 0 ? activeAgents / agents.length : 0;
729
-
730
- const avgDuration = this.taskDurations.length > 0
731
- ? this.taskDurations.reduce((a, b) => a + b, 0) / this.taskDurations.length
732
- : 0;
733
-
734
- return {
735
- tasksReceived: this.tasksReceived,
736
- tasksCompleted: this.tasksCompleted,
737
- tasksFailed: this.tasksFailed,
738
- tasksStolen: this.tasksStolen,
739
- averageTaskDuration: avgDuration,
740
- domainUtilization,
741
- agentUtilization,
742
- protocolsExecuted: this.protocolsExecuted,
743
- workflowsExecuted: this.workflowsExecuted,
744
- uptime: Date.now() - this.startTime.getTime(),
745
- };
746
- }
747
-
748
- // ============================================================================
749
- // Protocol & Workflow
750
- // ============================================================================
751
-
752
- async executeProtocol(
753
- protocolId: string,
754
- params?: Record<string, unknown>
755
- ): Promise<Result<string, Error>> {
756
- if (!this.protocolExecutor) {
757
- return err(new Error('Protocol executor not configured'));
758
- }
759
-
760
- const result = await this.protocolExecutor.execute(protocolId, params);
761
- if (result.success) {
762
- this.protocolsExecuted++;
763
- await this.publishEvent('ProtocolExecuted', {
764
- protocolId,
765
- executionId: result.value.executionId,
766
- });
767
- return ok(result.value.executionId);
768
- }
769
-
770
- return result as Result<string, Error>;
771
- }
772
-
773
- async executeWorkflow(
774
- workflowId: string,
775
- params?: Record<string, unknown>
776
- ): Promise<Result<string, Error>> {
777
- if (!this.workflowExecutor) {
778
- return err(new Error('Workflow executor not configured'));
779
- }
780
-
781
- const result = await this.workflowExecutor.execute(workflowId, params);
782
- if (result.success) {
783
- this.workflowsExecuted++;
784
- await this.publishEvent('WorkflowExecuted', {
785
- workflowId,
786
- executionId: result.value.executionId,
787
- });
788
- return ok(result.value.executionId);
789
- }
790
-
791
- return result as Result<string, Error>;
792
- }
793
-
794
- // ============================================================================
795
- // Private Methods
796
- // ============================================================================
797
-
798
- private subscribeToEvents(): void {
799
- // Listen for task completion events from domains
800
- for (const domain of ALL_DOMAINS) {
801
- this.router.subscribeToDoamin(domain, async (event) => {
802
- await this.handleDomainEvent(event);
803
- });
804
- }
805
-
806
- // Listen for specific coordination events
807
- this.router.subscribeToEventType('TaskCompleted', async (event) => {
808
- await this.handleTaskCompleted(event);
809
- });
810
-
811
- this.router.subscribeToEventType('TaskFailed', async (event) => {
812
- await this.handleTaskFailed(event);
813
- });
814
-
815
- this.router.subscribeToEventType('AgentStatusChanged', async (event) => {
816
- await this.handleAgentStatusChanged(event);
817
- });
818
- }
819
-
820
- private async handleDomainEvent(event: DomainEvent): Promise<void> {
821
- // Update domain activity
822
- this.domainLastActivity.set(event.source, new Date());
823
-
824
- // Check if this frees up capacity for queued tasks
825
- await this.processQueue();
826
- }
827
-
828
- private async handleTaskCompleted(event: DomainEvent): Promise<void> {
829
- const { taskId, result } = event.payload as { taskId: string; result: unknown };
830
- const execution = this.tasks.get(taskId);
831
-
832
- if (execution) {
833
- const duration = execution.startedAt
834
- ? Date.now() - execution.startedAt.getTime()
835
- : 0;
836
-
837
- this.tasks.set(taskId, {
838
- ...execution,
839
- status: 'completed',
840
- completedAt: new Date(),
841
- result,
842
- });
843
-
844
- this.tasksCompleted++;
845
- this.taskDurations.push(duration);
846
-
847
- // Keep only last 1000 durations for averaging
848
- if (this.taskDurations.length > 1000) {
849
- this.taskDurations.shift();
850
- }
851
- }
852
-
853
- // Process queue for next task
854
- await this.processQueue();
855
- }
856
-
857
- private async handleTaskFailed(event: DomainEvent): Promise<void> {
858
- const { taskId, error } = event.payload as { taskId: string; error: string };
859
- const execution = this.tasks.get(taskId);
860
-
861
- if (execution) {
862
- // Check if we should retry
863
- if (execution.retryCount < this.config.taskRetryLimit) {
864
- // Retry the task
865
- const retried: TaskExecution = {
866
- ...execution,
867
- status: 'queued',
868
- retryCount: execution.retryCount + 1,
869
- error,
870
- };
871
- this.tasks.set(taskId, retried);
872
- this.enqueueTask(execution.task);
873
-
874
- await this.publishEvent('TaskRetrying', {
875
- taskId,
876
- retryCount: retried.retryCount,
877
- error,
878
- });
879
- } else {
880
- // Mark as failed
881
- this.tasks.set(taskId, {
882
- ...execution,
883
- status: 'failed',
884
- completedAt: new Date(),
885
- error,
886
- });
887
- this.tasksFailed++;
888
- }
889
- }
890
-
891
- await this.processQueue();
892
- }
893
-
894
- private async handleAgentStatusChanged(event: DomainEvent): Promise<void> {
895
- const { agentId: _agentId, status, domain } = event.payload as {
896
- agentId: string;
897
- status: AgentStatus;
898
- domain: DomainName;
899
- };
900
-
901
- this.domainLastActivity.set(domain, new Date());
902
-
903
- // If agent completed or failed, check for queued tasks
904
- if (status === 'completed' || status === 'failed') {
905
- await this.processQueue();
906
- }
907
- }
908
-
909
- private async assignTask(task: QueenTask): Promise<Result<string, Error>> {
910
- const targetDomains = task.targetDomains.length > 0
911
- ? task.targetDomains
912
- : TASK_DOMAIN_MAP[task.type] || [];
913
-
914
- if (targetDomains.length === 0) {
915
- return err(new Error(`No domains configured for task type: ${task.type}`));
916
- }
917
-
918
- // Find the least loaded domain that can handle this task
919
- let bestDomain: DomainName | undefined;
920
- let lowestLoad = Infinity;
921
-
922
- for (const domain of targetDomains) {
923
- const load = this.getDomainLoad(domain);
924
- const health = this.getDomainHealth(domain);
925
-
926
- if (health?.status !== 'unhealthy' && load < lowestLoad) {
927
- lowestLoad = load;
928
- bestDomain = domain;
929
- }
930
- }
931
-
932
- if (!bestDomain) {
933
- return err(new Error('No healthy domain available for task'));
934
- }
935
-
936
- return this.assignTaskToDomain(task, bestDomain);
937
- }
938
-
939
- private async assignTaskToDomain(task: QueenTask, domain: DomainName): Promise<Result<string, Error>> {
940
- // Spawn an agent for this task if needed
941
- const spawnResult = await this.requestAgentSpawn(
942
- domain,
943
- 'task-worker',
944
- ['task-execution', task.type]
945
- );
946
-
947
- const agentIds: string[] = [];
948
- if (spawnResult.success) {
949
- agentIds.push(spawnResult.value);
950
- }
951
-
952
- const execution: TaskExecution = {
953
- taskId: task.id,
954
- task,
955
- status: 'running',
956
- assignedDomain: domain,
957
- assignedAgents: agentIds,
958
- startedAt: new Date(),
959
- retryCount: 0,
960
- };
961
-
962
- this.tasks.set(task.id, execution);
963
- this.domainLastActivity.set(domain, new Date());
964
-
965
- await this.publishEvent('TaskAssigned', {
966
- taskId: task.id,
967
- domain,
968
- agentIds,
969
- });
970
-
971
- // Invoke domain API if available
972
- if (this.domainPlugins) {
973
- const plugin = this.domainPlugins.get(domain);
974
- if (plugin) {
975
- try {
976
- await plugin.handleEvent({
977
- id: uuidv4(),
978
- type: 'TaskAssigned',
979
- timestamp: new Date(),
980
- source: 'queen-coordinator' as DomainName,
981
- correlationId: task.correlationId,
982
- payload: { task },
983
- });
984
- } catch (error) {
985
- // Log but don't fail - domain will handle via event bus
986
- }
987
- }
988
- }
989
-
990
- return ok(task.id);
991
- }
992
-
993
- private enqueueTask(task: QueenTask): void {
994
- const priorityQueue = this.taskQueue.get(task.priority);
995
- if (priorityQueue) {
996
- priorityQueue.push(task);
997
- // Sort by creation time within priority
998
- priorityQueue.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
999
- }
1000
-
1001
- // Also add to domain-specific queues
1002
- for (const domain of task.targetDomains) {
1003
- const domainQueue = this.domainQueues.get(domain);
1004
- if (domainQueue) {
1005
- domainQueue.push(task);
1006
- }
1007
- }
1008
- }
1009
-
1010
- private removeFromQueues(task: QueenTask): void {
1011
- // Remove from priority queue
1012
- const priorityQueue = this.taskQueue.get(task.priority);
1013
- if (priorityQueue) {
1014
- const idx = priorityQueue.findIndex(t => t.id === task.id);
1015
- if (idx !== -1) {
1016
- priorityQueue.splice(idx, 1);
1017
- }
1018
- }
1019
-
1020
- // Remove from domain queues
1021
- for (const domain of ALL_DOMAINS) {
1022
- const domainQueue = this.domainQueues.get(domain);
1023
- if (domainQueue) {
1024
- const idx = domainQueue.findIndex(t => t.id === task.id);
1025
- if (idx !== -1) {
1026
- domainQueue.splice(idx, 1);
1027
- }
1028
- }
1029
- }
1030
- }
1031
-
1032
- private async processQueue(): Promise<void> {
1033
- const runningCount = this.getRunningTaskCount();
1034
- if (runningCount >= this.config.maxConcurrentTasks) {
1035
- return;
1036
- }
1037
-
1038
- // Process by priority (p0 first)
1039
- for (const priority of ['p0', 'p1', 'p2', 'p3'] as Priority[]) {
1040
- const queue = this.taskQueue.get(priority);
1041
- if (!queue || queue.length === 0) continue;
1042
-
1043
- const task = queue.shift();
1044
- if (task) {
1045
- this.removeFromQueues(task);
1046
- await this.assignTask(task);
1047
-
1048
- // Check if we can process more
1049
- if (this.getRunningTaskCount() >= this.config.maxConcurrentTasks) {
1050
- return;
1051
- }
1052
- }
1053
- }
1054
- }
1055
-
1056
- private getQueuePosition(task: QueenTask): number {
1057
- let position = 0;
1058
-
1059
- // Count tasks ahead in higher priority queues
1060
- for (const p of ['p0', 'p1', 'p2', 'p3'] as Priority[]) {
1061
- const queue = this.taskQueue.get(p);
1062
- if (queue) {
1063
- if (p === task.priority) {
1064
- position += queue.findIndex(t => t.id === task.id);
1065
- break;
1066
- }
1067
- position += queue.length;
1068
- }
1069
- }
1070
-
1071
- return position;
1072
- }
1073
-
1074
- private getRunningTaskCount(): number {
1075
- return Array.from(this.tasks.values())
1076
- .filter(t => t.status === 'running' || t.status === 'assigned')
1077
- .length;
1078
- }
1079
-
1080
- private getQueuedTaskCount(): number {
1081
- return Array.from(this.tasks.values())
1082
- .filter(t => t.status === 'queued')
1083
- .length;
1084
- }
1085
-
1086
- private canDomainHandleTask(domain: DomainName, task: QueenTask): boolean {
1087
- const compatibleDomains = TASK_DOMAIN_MAP[task.type] || [];
1088
- return compatibleDomains.includes(domain);
1089
- }
1090
-
1091
- private startWorkStealing(): void {
1092
- this.workStealingTimer = setInterval(async () => {
1093
- await this.triggerWorkStealing();
1094
- }, this.config.workStealing.checkInterval);
1095
- }
1096
-
1097
- private startMetricsCollection(): void {
1098
- this.metricsTimer = setInterval(async () => {
1099
- const metrics = this.getMetrics();
1100
- await this.publishEvent('MetricsCollected', { metrics });
1101
-
1102
- // Store metrics in memory for historical analysis
1103
- await this.memory.set(`queen:metrics:${Date.now()}`, metrics, {
1104
- ttl: 86400000, // 24 hours
1105
- namespace: 'queen-coordinator',
1106
- });
1107
- }, this.config.metricsInterval);
1108
- }
1109
-
1110
- private async loadState(): Promise<void> {
1111
- try {
1112
- const state = await this.memory.get<{
1113
- tasks: [string, TaskExecution][];
1114
- }>('queen:state');
1115
-
1116
- if (state) {
1117
- for (const [id, execution] of state.tasks) {
1118
- // Only restore queued tasks
1119
- if (execution.status === 'queued') {
1120
- this.tasks.set(id, execution);
1121
- this.enqueueTask(execution.task);
1122
- }
1123
- }
1124
- }
1125
- } catch {
1126
- // Ignore errors loading state
1127
- }
1128
- }
1129
-
1130
- private async saveState(): Promise<void> {
1131
- const queuedTasks = Array.from(this.tasks.entries())
1132
- .filter(([, t]) => t.status === 'queued');
1133
-
1134
- await this.memory.set(
1135
- 'queen:state',
1136
- { tasks: queuedTasks },
1137
- { namespace: 'queen-coordinator', persist: true }
1138
- );
1139
- }
1140
-
1141
- private async publishEvent(type: string, payload: Record<string, unknown>): Promise<void> {
1142
- await this.eventBus.publish({
1143
- id: uuidv4(),
1144
- type: `Queen${type}`,
1145
- timestamp: new Date(),
1146
- source: 'queen-coordinator' as DomainName,
1147
- payload,
1148
- });
1149
- }
1150
- }
1151
-
1152
- // ============================================================================
1153
- // Factory Function
1154
- // ============================================================================
1155
-
1156
- /**
1157
- * Create a Queen Coordinator from a QE Kernel
1158
- */
1159
- export function createQueenCoordinator(
1160
- kernel: QEKernel,
1161
- router: CrossDomainRouter,
1162
- protocolExecutor?: ProtocolExecutor,
1163
- workflowExecutor?: WorkflowExecutor,
1164
- config?: Partial<QueenConfig>
1165
- ): QueenCoordinator {
1166
- return new QueenCoordinator(
1167
- kernel.eventBus,
1168
- kernel.coordinator,
1169
- kernel.memory,
1170
- router,
1171
- protocolExecutor,
1172
- workflowExecutor,
1173
- undefined,
1174
- config
1175
- );
1176
- }