claude-flow-novice 1.6.1 → 1.6.2

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 (244) hide show
  1. package/.claude/agents/cfn-loop/product-owner.md +54 -4
  2. package/.claude/commands/cfn-claude-sync.md +303 -0
  3. package/.claude/commands/cfn-loop-epic.md +290 -0
  4. package/.claude/commands/cfn-loop-single.md +168 -0
  5. package/.claude/commands/cfn-loop-sprints.md +384 -0
  6. package/.claude/commands/cfn-loop.md +180 -0
  7. package/.claude/commands/metrics-summary.md +58 -0
  8. package/.claude/commands/parse-epic.md +357 -0
  9. package/.claude/settings.json +4 -4
  10. package/.claude/settings.local.json +9 -2
  11. package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
  12. package/.claude-flow-novice/dist/mcp/server.js +21 -2
  13. package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
  14. package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
  16. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
  17. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
  18. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
  19. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  20. package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
  21. package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
  22. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
  23. package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
  24. package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
  25. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
  26. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
  27. package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
  28. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
  29. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
  30. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
  31. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
  32. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
  33. package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
  34. package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
  35. package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
  36. package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
  37. package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
  38. package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
  39. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
  40. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
  41. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
  42. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
  43. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
  44. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  45. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
  46. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  47. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
  48. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
  49. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
  50. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  51. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
  52. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
  53. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
  54. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
  55. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
  56. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  57. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
  58. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
  59. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
  60. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
  61. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
  62. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
  63. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
  64. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
  65. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
  66. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
  67. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
  68. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
  69. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
  70. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
  71. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
  72. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
  73. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
  74. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
  75. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
  76. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
  77. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
  78. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
  79. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
  80. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
  81. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
  82. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
  83. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
  84. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
  85. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
  86. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
  87. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
  88. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
  89. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
  90. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
  91. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
  92. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
  93. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
  94. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
  95. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
  96. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
  97. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
  98. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
  99. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
  100. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
  101. package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
  102. package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
  103. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
  104. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
  105. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
  106. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
  107. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
  108. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  109. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
  110. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
  111. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
  112. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
  113. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
  114. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
  115. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
  116. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
  117. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
  118. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
  119. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
  120. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
  121. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
  122. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
  123. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
  124. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
  125. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
  126. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
  127. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
  128. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
  129. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
  130. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
  131. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
  132. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
  133. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
  134. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
  135. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
  136. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
  137. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
  138. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
  139. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
  140. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
  141. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
  142. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
  143. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
  144. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
  145. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
  146. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
  147. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
  148. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
  149. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
  150. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
  151. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
  152. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
  153. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
  154. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
  155. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
  156. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
  157. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
  158. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
  159. package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
  160. package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
  161. package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
  162. package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
  163. package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
  164. package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
  165. package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
  166. package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
  167. package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
  168. package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
  169. package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
  170. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  171. package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
  172. package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
  173. package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
  174. package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
  175. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
  176. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
  177. package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
  178. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
  179. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
  180. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
  181. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
  182. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
  183. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
  184. package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
  185. package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
  186. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
  187. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
  188. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
  189. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
  190. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
  191. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
  192. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
  193. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
  195. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
  197. package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
  198. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
  199. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
  201. package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
  203. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
  205. package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
  207. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
  209. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
  211. package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
  213. package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
  214. package/.claude-flow-novice/metrics.db +0 -0
  215. package/.claude-flow-novice/metrics.db-shm +0 -0
  216. package/.claude-flow-novice/metrics.db-wal +0 -0
  217. package/CLAUDE.md +29 -0
  218. package/README.md +27 -0
  219. package/config/hooks/post-edit-pipeline.js +36 -2
  220. package/examples/metrics-counter-demo.ts +106 -0
  221. package/examples/persistent-metrics-demo.ts +83 -0
  222. package/examples/phase-5-multi-level-control.ts +282 -0
  223. package/examples/session-pool-optimizer-example.ts +311 -0
  224. package/package.json +15 -3
  225. package/scripts/check-routing-stats.cjs +122 -0
  226. package/scripts/pre-publish-validation.cjs +212 -0
  227. package/scripts/test-provider-routing.cjs +228 -0
  228. package/scripts/test-routing-telemetry.cjs +147 -0
  229. package/scripts/test-zai-10k.cjs +81 -0
  230. package/scripts/test-zai-api.cjs +191 -0
  231. package/scripts/test-zai-diagnostic.cjs +151 -0
  232. package/scripts/test-zai-final.cjs +128 -0
  233. package/scripts/test-zai-with-env.cjs +85 -0
  234. package/scripts/validate-coordination-cli.js +69 -0
  235. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  236. package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
  237. package/src/observability/metrics-counter.ts +347 -0
  238. package/src/observability/metrics-storage.ts +356 -0
  239. package/src/observability/telemetry.ts +658 -0
  240. package/src/slash-commands/cfn-claude-sync.js +533 -0
  241. package/src/slash-commands/index.js +5 -0
  242. package/src/slash-commands/metrics-summary-class.js +74 -0
  243. package/src/slash-commands/metrics-summary.js +335 -0
  244. package/src/slash-commands/register-all-commands.js +12 -0
@@ -0,0 +1,248 @@
1
+ /**
2
+ * ConfigTranslator - Unified configuration translation for V1/V2 coordination systems
3
+ *
4
+ * Provides bidirectional translation between unified configuration format
5
+ * and version-specific config structures for V1 (CoordinationTopologyConfig)
6
+ * and V2 (FactoryOptions).
7
+ *
8
+ * @module coordination/config-translator
9
+ */ /**
10
+ * ConfigTranslator - Static utility class for config translation
11
+ *
12
+ * Handles bidirectional conversion between unified config and version-specific formats.
13
+ * Provides intelligent defaults based on topology and agent count.
14
+ *
15
+ * Key Translation Rules:
16
+ * - topology: 'mesh' → V1 mesh config / V2 SDK mode
17
+ * - topology: 'hierarchical' → V1 hierarchical config / V2 SDK mode
18
+ * - maxAgents → V1 maxAgents / V2 maxConcurrentAgents
19
+ * - strategy → V1 strategy / V2 enableDynamicAllocation
20
+ * - enableConsensus → V1 consensus config / V2 N/A (built-in)
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const unified: UnifiedCoordinatorConfig = {
25
+ * topology: 'mesh',
26
+ * maxAgents: 5,
27
+ * strategy: 'balanced',
28
+ * enableConsensus: true
29
+ * };
30
+ *
31
+ * // Translate to V1
32
+ * const v1Config = ConfigTranslator.toV1Config(unified);
33
+ * const coordinator = await createTopologyCoordinator(v1Config, deps);
34
+ *
35
+ * // Translate to V2
36
+ * const v2Config = ConfigTranslator.toV2Config(unified);
37
+ * const coordinator = await CoordinatorFactory.create(v2Config);
38
+ * ```
39
+ */ export class ConfigTranslator {
40
+ /**
41
+ * Translate unified config to V1 CoordinationTopologyConfig
42
+ *
43
+ * Generates topology-specific config objects for hierarchical or mesh modes.
44
+ * Applies intelligent defaults based on agent count and topology type.
45
+ *
46
+ * @param unified - Unified coordinator configuration
47
+ * @returns V1 CoordinationTopologyConfig
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const v1Config = ConfigTranslator.toV1Config({
52
+ * topology: 'hierarchical',
53
+ * maxAgents: 15,
54
+ * strategy: 'adaptive'
55
+ * });
56
+ * // Returns: { topology: 'hierarchical', maxAgents: 15, hierarchical: {...}, consensus: {...} }
57
+ * ```
58
+ */ static toV1Config(unified) {
59
+ const topology = unified.topology || 'mesh';
60
+ const maxAgents = unified.maxAgents || 10;
61
+ const strategy = unified.strategy || 'balanced';
62
+ const config = {
63
+ topology,
64
+ maxAgents,
65
+ strategy
66
+ };
67
+ // Add hierarchical-specific config
68
+ if (topology === 'hierarchical') {
69
+ const hierarchicalConfig = {
70
+ minWorkers: Math.min(8, maxAgents),
71
+ maxWorkers: maxAgents,
72
+ autoScale: true,
73
+ scalingThreshold: 0.8,
74
+ healthCheckInterval: 30000,
75
+ taskTimeout: 120000,
76
+ workerRetryAttempts: 3
77
+ };
78
+ config.hierarchical = hierarchicalConfig;
79
+ }
80
+ // Add mesh-specific config
81
+ if (topology === 'mesh') {
82
+ const meshConfig = {
83
+ maxAgents,
84
+ maxConnections: Math.floor(maxAgents / 3),
85
+ taskDistributionStrategy: 'capability-based',
86
+ enableDependencyTracking: true,
87
+ completionTimeout: 60000,
88
+ rebalanceInterval: 15000,
89
+ memoryNamespace: 'mesh-coordination'
90
+ };
91
+ config.mesh = meshConfig;
92
+ }
93
+ // Add consensus config if enabled
94
+ if (unified.enableConsensus) {
95
+ const protocol = topology === 'hierarchical' ? 'raft' : 'quorum';
96
+ const consensusConfig = {
97
+ protocol,
98
+ timeout: 5000,
99
+ maxRetries: 3,
100
+ quorumSize: Math.ceil(maxAgents / 2) + 1
101
+ };
102
+ config.consensus = consensusConfig;
103
+ }
104
+ return config;
105
+ }
106
+ /**
107
+ * Translate unified config to V2 FactoryOptions
108
+ *
109
+ * Generates V2-compatible config with SDK mode defaults and modern features.
110
+ * Always defaults to SDK mode with dynamic allocation enabled.
111
+ *
112
+ * @param unified - Unified coordinator configuration
113
+ * @returns V2 FactoryOptions
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const v2Config = ConfigTranslator.toV2Config({
118
+ * topology: 'mesh',
119
+ * maxAgents: 5,
120
+ * tokenBudget: 50000
121
+ * });
122
+ * // Returns: { mode: 'sdk', maxConcurrentAgents: 5, defaultTokenBudget: 50000, ... }
123
+ * ```
124
+ */ static toV2Config(unified) {
125
+ const maxAgents = unified.maxAgents || 10;
126
+ const tokenBudget = unified.tokenBudget || 20000;
127
+ return {
128
+ // V2 defaults to SDK mode
129
+ mode: 'sdk',
130
+ // Agent limits
131
+ maxConcurrentAgents: maxAgents,
132
+ defaultTokenBudget: tokenBudget,
133
+ // API credentials (from environment or unified config)
134
+ apiKey: unified.apiKey || process.env.ANTHROPIC_API_KEY,
135
+ // Dynamic allocation (maps from strategy)
136
+ enableDynamicAllocation: unified.strategy !== 'performance',
137
+ // Logging
138
+ verbose: unified.verbose || false
139
+ };
140
+ }
141
+ /**
142
+ * Validate unified config for completeness
143
+ *
144
+ * Checks that required fields are present and values are within valid ranges.
145
+ *
146
+ * @param config - Unified config to validate
147
+ * @returns Validation errors (empty array if valid)
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const errors = ConfigTranslator.validate({ topology: 'mesh' });
152
+ * if (errors.length > 0) {
153
+ * console.error('Config validation failed:', errors);
154
+ * }
155
+ * ```
156
+ */ static validate(config) {
157
+ const errors = [];
158
+ // Validate topology
159
+ if (config.topology && ![
160
+ 'mesh',
161
+ 'hierarchical'
162
+ ].includes(config.topology)) {
163
+ errors.push(`Invalid topology: ${config.topology}. Must be 'mesh' or 'hierarchical'.`);
164
+ }
165
+ // Validate maxAgents
166
+ if (config.maxAgents !== undefined) {
167
+ if (config.maxAgents < 1) {
168
+ errors.push(`Invalid maxAgents: ${config.maxAgents}. Must be at least 1.`);
169
+ }
170
+ if (config.maxAgents > 100) {
171
+ errors.push(`Invalid maxAgents: ${config.maxAgents}. Maximum is 100.`);
172
+ }
173
+ }
174
+ // Validate strategy
175
+ if (config.strategy && ![
176
+ 'balanced',
177
+ 'adaptive',
178
+ 'performance'
179
+ ].includes(config.strategy)) {
180
+ errors.push(`Invalid strategy: ${config.strategy}. Must be 'balanced', 'adaptive', or 'performance'.`);
181
+ }
182
+ // Validate tokenBudget
183
+ if (config.tokenBudget !== undefined && config.tokenBudget < 1000) {
184
+ errors.push(`Invalid tokenBudget: ${config.tokenBudget}. Must be at least 1000.`);
185
+ }
186
+ return errors;
187
+ }
188
+ /**
189
+ * Merge multiple unified configs with priority
190
+ *
191
+ * Combines multiple config objects, with later configs taking precedence.
192
+ * Useful for layering defaults, environment, and user configs.
193
+ *
194
+ * @param configs - Config objects to merge (in priority order)
195
+ * @returns Merged unified config
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const defaults = { topology: 'mesh', maxAgents: 5 };
200
+ * const userConfig = { maxAgents: 10, strategy: 'adaptive' };
201
+ * const merged = ConfigTranslator.merge(defaults, userConfig);
202
+ * // Returns: { topology: 'mesh', maxAgents: 10, strategy: 'adaptive' }
203
+ * ```
204
+ */ static merge(...configs) {
205
+ return configs.reduce((acc, config)=>{
206
+ return {
207
+ ...acc,
208
+ ...config
209
+ };
210
+ }, {});
211
+ }
212
+ /**
213
+ * Get default config for topology type
214
+ *
215
+ * Provides opinionated defaults optimized for each topology.
216
+ *
217
+ * @param topology - Topology type
218
+ * @returns Default unified config
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const meshDefaults = ConfigTranslator.getDefaults('mesh');
223
+ * // Returns: { topology: 'mesh', maxAgents: 7, strategy: 'balanced', ... }
224
+ * ```
225
+ */ static getDefaults(topology) {
226
+ if (topology === 'mesh') {
227
+ return {
228
+ topology: 'mesh',
229
+ maxAgents: 7,
230
+ strategy: 'balanced',
231
+ enableConsensus: true,
232
+ tokenBudget: 20000,
233
+ verbose: false
234
+ };
235
+ } else {
236
+ return {
237
+ topology: 'hierarchical',
238
+ maxAgents: 15,
239
+ strategy: 'adaptive',
240
+ enableConsensus: true,
241
+ tokenBudget: 20000,
242
+ verbose: false
243
+ };
244
+ }
245
+ }
246
+ }
247
+
248
+ //# sourceMappingURL=config-translator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/coordination/config-translator.ts"],"names":["ConfigTranslator","toV1Config","unified","topology","maxAgents","strategy","config","hierarchicalConfig","minWorkers","Math","min","maxWorkers","autoScale","scalingThreshold","healthCheckInterval","taskTimeout","workerRetryAttempts","hierarchical","meshConfig","maxConnections","floor","taskDistributionStrategy","enableDependencyTracking","completionTimeout","rebalanceInterval","memoryNamespace","mesh","enableConsensus","protocol","consensusConfig","timeout","maxRetries","quorumSize","ceil","consensus","toV2Config","tokenBudget","mode","maxConcurrentAgents","defaultTokenBudget","apiKey","process","env","ANTHROPIC_API_KEY","enableDynamicAllocation","verbose","validate","errors","includes","push","undefined","merge","configs","reduce","acc","getDefaults"],"mappings":"AAAA;;;;;;;;CAQC,GAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,M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;;;;;;;;;;;;GAgBC,GACD,OAAOI,MAAM,GAAGC,OAA4C,EAA4B;QACtF,OAAOA,QAAQC,MAAM,CAAC,CAACC,KAAKhD;YAC1B,OAAO;gBACL,GAAGgD,GAAG;gBACN,GAAGhD,MAAM;YACX;QACF,GAAG,CAAC;IACN;IAEA;;;;;;;;;;;;;GAaC,GACD,OAAOiD,YAAYpD,QAAiC,EAA4B;QAC9E,IAAIA,aAAa,QAAQ;YACvB,OAAO;gBACLA,UAAU;gBACVC,WAAW;gBACXC,UAAU;gBACVsB,iBAAiB;gBACjBS,aAAa;gBACbS,SAAS;YACX;QACF,OAAO;YACL,OAAO;gBACL1C,UAAU;gBACVC,WAAW;gBACXC,UAAU;gBACVsB,iBAAiB;gBACjBS,aAAa;gBACbS,SAAS;YACX;QACF;IACF;AACF"}
@@ -0,0 +1,287 @@
1
+ /**
2
+ * CoordinationToggle - Version-aware coordinator factory
3
+ *
4
+ * Provides unified factory interface for V1/V2 coordination systems.
5
+ * Auto-detects version from environment and instantiates appropriate coordinator.
6
+ *
7
+ * @module coordination/coordination-toggle
8
+ */ import { CoordinatorFactory } from './v2/coordinator-factory.js';
9
+ import { createTopologyCoordinator } from './index.js';
10
+ import { Logger } from '../core/logger.js';
11
+ import { V1CoordinatorAdapter } from './adapters/v1-coordinator-adapter.js';
12
+ import { ConfigTranslator } from './config-translator.js';
13
+ import { TelemetrySystem } from '../observability/telemetry.js';
14
+ // Re-export ConfigTranslator for test compatibility
15
+ export { ConfigTranslator } from './config-translator.js';
16
+ /**
17
+ * CoordinationToggle - Factory selector for V1/V2 coordinators
18
+ *
19
+ * Features:
20
+ * - Auto-detects coordination version from COORDINATION_VERSION env var
21
+ * - Translates unified config to version-specific formats
22
+ * - Returns ICoordinator interface regardless of version
23
+ * - Enables gradual V2 migration without breaking V1 usage
24
+ *
25
+ * Version Selection Priority:
26
+ * 1. Explicit config.version ('v1' | 'v2')
27
+ * 2. COORDINATION_VERSION environment variable
28
+ * 3. Default: 'v2' (current recommended version)
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Auto-detect version (uses COORDINATION_VERSION env var or defaults to v2)
33
+ * const coordinator = await CoordinationToggle.create({
34
+ * topology: 'mesh',
35
+ * maxAgents: 5
36
+ * });
37
+ *
38
+ * // Explicit V1 coordinator
39
+ * const v1Coordinator = await CoordinationToggle.create({
40
+ * version: 'v1',
41
+ * topology: 'hierarchical',
42
+ * maxAgents: 12
43
+ * });
44
+ *
45
+ * // Explicit V2 coordinator
46
+ * const v2Coordinator = await CoordinationToggle.create({
47
+ * version: 'v2',
48
+ * topology: 'mesh',
49
+ * maxAgents: 5,
50
+ * tokenBudget: 20000
51
+ * });
52
+ * ```
53
+ */ export class CoordinationToggle {
54
+ static logger = new Logger({
55
+ level: 'info',
56
+ format: 'text',
57
+ destination: 'console'
58
+ });
59
+ static telemetry = new TelemetrySystem({
60
+ enableMetrics: true,
61
+ enablePersistence: true
62
+ });
63
+ /**
64
+ * Create coordinator instance based on version
65
+ *
66
+ * Auto-detects coordination version and instantiates appropriate coordinator:
67
+ * - V1: Legacy coordination system (QueenAgent/MeshCoordinator)
68
+ * - V2: Modern coordination system (SDK/CLI/Hybrid modes)
69
+ *
70
+ * @param config - Unified coordinator configuration
71
+ * @returns Promise resolving to ICoordinator instance
72
+ * @throws Error if version not supported or dependencies missing
73
+ */ static async create(config = {}) {
74
+ const startTime = Date.now();
75
+ // Determine effective version
76
+ const version = this.detectVersion(config);
77
+ this.logger.info('CoordinationToggle: Creating coordinator', {
78
+ requestedVersion: config.version ?? 'auto',
79
+ detectedVersion: version,
80
+ topology: config.topology ?? 'mesh',
81
+ maxAgents: config.maxAgents ?? 10
82
+ });
83
+ // Create version-specific coordinator
84
+ let coordinator;
85
+ if (version === 'v1') {
86
+ coordinator = await this.createV1Coordinator(config);
87
+ } else {
88
+ coordinator = await this.createV2Coordinator(config);
89
+ }
90
+ const initTime = Date.now() - startTime;
91
+ this.logger.info('CoordinationToggle: Coordinator created', {
92
+ version,
93
+ initTimeMs: initTime
94
+ });
95
+ // Track coordinator initialization time
96
+ this.telemetry.recordTimer('coordination.initialization', initTime, {
97
+ version,
98
+ topology: config.topology || 'mesh',
99
+ maxAgents: String(config.maxAgents || 5)
100
+ });
101
+ return coordinator;
102
+ }
103
+ /**
104
+ * Detect coordination version from config or environment
105
+ *
106
+ * Priority:
107
+ * 1. Explicit config.version
108
+ * 2. COORDINATION_VERSION environment variable
109
+ * 3. Default: 'v2'
110
+ *
111
+ * @private
112
+ * @param config - Unified configuration
113
+ * @returns Detected version ('v1' | 'v2')
114
+ */ static detectVersion(config) {
115
+ // Priority 1: Explicit version in config
116
+ if (config.version) {
117
+ return config.version;
118
+ }
119
+ // Priority 2: Environment variable (VUL-1 FIX: strict validation with case-insensitive support)
120
+ const envVersion = process.env.COORDINATION_VERSION;
121
+ if (envVersion) {
122
+ const normalized = envVersion.toLowerCase();
123
+ // Strict regex validation to prevent injection
124
+ if (!/^v[12]$/.test(normalized)) {
125
+ throw new Error(`Invalid COORDINATION_VERSION: "${envVersion}". Must be exactly 'v1' or 'v2' (case-insensitive).`);
126
+ }
127
+ return normalized;
128
+ }
129
+ // Priority 3: Default to v2
130
+ return 'v2';
131
+ }
132
+ /**
133
+ * Create V1 coordinator (legacy system)
134
+ *
135
+ * Translates unified config to V1 CoordinationTopologyConfig format
136
+ * and wraps result in V1CoordinatorAdapter for ICoordinator compatibility.
137
+ *
138
+ * @private
139
+ * @param config - Unified configuration
140
+ * @returns Promise resolving to V1 coordinator wrapped in adapter
141
+ * @throws Error if V1 dependencies not provided
142
+ */ static async createV1Coordinator(config) {
143
+ this.logger.debug('Creating V1 coordinator', {
144
+ topology: config.topology,
145
+ maxAgents: config.maxAgents
146
+ });
147
+ // Translate unified config to V1 format
148
+ const v1Config = ConfigTranslator.toV1Config(config);
149
+ // V1 requires dependencies (memory, broker, dependencyGraph, logger)
150
+ if (!config.dependencies) {
151
+ this.getDefaultV1Dependencies(); // Will throw error
152
+ }
153
+ // VUL-4 FIX: Validate dependency object structure
154
+ this.validateV1Dependencies(config.dependencies);
155
+ const dependencies = config.dependencies;
156
+ // VUL-5 FIX: Log selected version for transparency
157
+ this.logger.info('V1 coordinator selected', {
158
+ version: 'v1',
159
+ topology: config.topology,
160
+ source: config.version ? 'explicit' : 'environment/default'
161
+ });
162
+ // Track V1 coordinator usage metrics
163
+ this.telemetry.recordCounter('coordination.version.selected', 1, {
164
+ version: 'v1',
165
+ topology: config.topology || 'mesh',
166
+ source: config.version ? 'explicit' : 'environment'
167
+ });
168
+ // Create V1 topology coordinator
169
+ const v1Coordinator = await createTopologyCoordinator(v1Config, dependencies);
170
+ // Wrap V1 coordinator with adapter for ICoordinator compatibility
171
+ return new V1CoordinatorAdapter(v1Coordinator);
172
+ }
173
+ /**
174
+ * Create V2 coordinator (modern system)
175
+ *
176
+ * Translates unified config to V2 FactoryOptions format
177
+ * and uses CoordinatorFactory for instantiation.
178
+ *
179
+ * @private
180
+ * @param config - Unified configuration
181
+ * @returns Promise resolving to V2 coordinator
182
+ */ static async createV2Coordinator(config) {
183
+ this.logger.debug('Creating V2 coordinator', {
184
+ topology: config.topology,
185
+ maxAgents: config.maxAgents,
186
+ tokenBudget: config.tokenBudget
187
+ });
188
+ // Translate unified config to V2 format
189
+ const v2Config = ConfigTranslator.toV2Config(config);
190
+ // VUL-5 FIX: Log selected version for transparency
191
+ this.logger.info('V2 coordinator selected', {
192
+ version: 'v2',
193
+ topology: config.topology,
194
+ source: config.version ? 'explicit' : 'environment/default'
195
+ });
196
+ // Track V2 coordinator usage metrics
197
+ this.telemetry.recordCounter('coordination.version.selected', 1, {
198
+ version: 'v2',
199
+ topology: config.topology || 'mesh',
200
+ source: config.version ? 'explicit' : 'environment',
201
+ mode: v2Config.mode || 'sdk'
202
+ });
203
+ // Use CoordinatorFactory to create V2 coordinator
204
+ return await CoordinatorFactory.create(v2Config);
205
+ }
206
+ /**
207
+ * Get default V1 dependencies for standalone usage
208
+ *
209
+ * Creates minimal dependency set when not provided in config.
210
+ * Uses in-memory implementations for testing/development.
211
+ *
212
+ * @private
213
+ * @returns Default V1 dependencies
214
+ */ static getDefaultV1Dependencies() {
215
+ // TODO: Implement default in-memory dependencies
216
+ // For now, throw error requiring explicit dependencies
217
+ throw new Error('V1 coordination requires dependencies (memory, broker, dependencyGraph, logger).\n' + 'Provide via config.dependencies or use V2 mode: { version: "v2" }');
218
+ }
219
+ /**
220
+ * Validate V1 dependencies for security (VUL-4 FIX)
221
+ *
222
+ * Prevents prototype pollution and ensures required keys exist.
223
+ *
224
+ * @private
225
+ * @param dependencies - Dependencies object to validate
226
+ * @throws Error if validation fails
227
+ */ static validateV1Dependencies(dependencies) {
228
+ if (!dependencies || typeof dependencies !== 'object') {
229
+ throw new Error('V1 dependencies must be a valid object');
230
+ }
231
+ // VUL-4: Check for prototype pollution attack vectors
232
+ const dangerousKeys = [
233
+ '__proto__',
234
+ 'constructor',
235
+ 'prototype'
236
+ ];
237
+ for (const key of dangerousKeys){
238
+ if (key in dependencies) {
239
+ throw new Error(`Security violation: Dependencies object contains dangerous key "${key}"`);
240
+ }
241
+ }
242
+ // VUL-4: Validate required keys
243
+ const requiredKeys = [
244
+ 'memory',
245
+ 'broker',
246
+ 'dependencyGraph',
247
+ 'logger'
248
+ ];
249
+ for (const key of requiredKeys){
250
+ if (!(key in dependencies)) {
251
+ throw new Error(`V1 dependencies missing required key: "${key}". Required: ${requiredKeys.join(', ')}`);
252
+ }
253
+ if (!dependencies[key]) {
254
+ throw new Error(`V1 dependency "${key}" is null or undefined. All dependencies must be valid objects.`);
255
+ }
256
+ }
257
+ }
258
+ /**
259
+ * Get version detection summary for debugging
260
+ *
261
+ * @returns Human-readable version detection info
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * console.log(CoordinationToggle.getVersionSummary());
266
+ * // Output:
267
+ * // Coordination Version Detection:
268
+ * // - COORDINATION_VERSION: v2
269
+ * // - Default Version: v2
270
+ * // - V1 Available: true
271
+ * // - V2 Available: true
272
+ * ```
273
+ */ static getVersionSummary() {
274
+ const envVersion = process.env.COORDINATION_VERSION?.toLowerCase();
275
+ const defaultVersion = 'v2';
276
+ const lines = [
277
+ 'Coordination Version Detection:',
278
+ `- COORDINATION_VERSION: ${envVersion ?? 'not set'}`,
279
+ `- Default Version: ${defaultVersion}`,
280
+ '- V1 Available: true (legacy)',
281
+ '- V2 Available: true (recommended)'
282
+ ];
283
+ return lines.join('\n');
284
+ }
285
+ }
286
+
287
+ //# sourceMappingURL=coordination-toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/coordination/coordination-toggle.ts"],"names":["CoordinatorFactory","createTopologyCoordinator","Logger","V1CoordinatorAdapter","ConfigTranslator","TelemetrySystem","CoordinationToggle","logger","level","format","destination","telemetry","enableMetrics","enablePersistence","create","config","startTime","Date","now","version","detectVersion","info","requestedVersion","detectedVersion","topology","maxAgents","coordinator","createV1Coordinator","createV2Coordinator","initTime","initTimeMs","recordTimer","String","envVersion","process","env","COORDINATION_VERSION","normalized","toLowerCase","test","Error","debug","v1Config","toV1Config","dependencies","getDefaultV1Dependencies","validateV1Dependencies","source","recordCounter","v1Coordinator","tokenBudget","v2Config","toV2Config","mode","dangerousKeys","key","requiredKeys","join","getVersionSummary","defaultVersion","lines"],"mappings":"AAAA;;;;;;;CAOC,GAGD,SAASA,kBAAkB,QAA6B,8BAA8B;AACtF,SAASC,yBAAyB,QAAyC,aAAa;AACxF,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,oBAAoB,QAAQ,uCAAuC;AAC5E,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,eAAe,QAAQ,gCAAgC;AAEhE,oDAAoD;AACpD,SAASD,gBAAgB,QAAQ,yBAAyB;AAyC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCC,GACD,OAAO,MAAME;IACX,OAAwBC,SAAS,IAAIL,OAAO;QAC1CM,OAAO;QACPC,QAAQ;QACRC,aAAa;IACf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AAC;YAE1F;QACF;IACF;IAEA;;;;;;;;;;;;;;;GAeC,GACD,OAAOG,oBAA4B;QACjC,MAAMzB,aAAaC,QAAQC,GAAG,CAACC,oBAAoB,EAAEE;QACrD,MAAMqB,iBAAiB;QAEvB,MAAMC,QAAkB;YACtB;YACA,CAAC,wBAAwB,EAAE3B,cAAc,WAAW;YACpD,CAAC,mBAAmB,EAAE0B,gBAAgB;YACtC;YACA;SACD;QAED,OAAOC,MAAMH,IAAI,CAAC;IACpB;AACF"}
@@ -11,7 +11,7 @@
11
11
  * Based on PBFT (Practical Byzantine Fault Tolerance) adapted for mesh coordination.
12
12
  */ import { EventEmitter } from 'node:events';
13
13
  import { performance } from 'perf_hooks';
14
- import crypto from 'crypto';
14
+ import * as crypto from 'crypto';
15
15
  // ============================================================================
16
16
  // Distributed Consensus Manager
17
17
  // ============================================================================
@@ -21,6 +21,7 @@ export class DistributedConsensusManager extends EventEmitter {
21
21
  agentStakes;
22
22
  consensusHistory;
23
23
  activeProposals;
24
+ agentKeyPairs;
24
25
  constructor(config = {}){
25
26
  super();
26
27
  this.config = {
@@ -37,6 +38,7 @@ export class DistributedConsensusManager extends EventEmitter {
37
38
  this.agentStakes = new Map();
38
39
  this.consensusHistory = [];
39
40
  this.activeProposals = new Map();
41
+ this.agentKeyPairs = new Map();
40
42
  }
41
43
  /**
42
44
  * Register agent with proof-of-work verification
@@ -202,6 +204,8 @@ export class DistributedConsensusManager extends EventEmitter {
202
204
  /**
203
205
  * Request vote from a specific peer
204
206
  */ async requestVoteFromPeer(agentId, proposal) {
207
+ // Ensure agent has RSA keypair
208
+ this.ensureAgentKeypair(agentId);
205
209
  // Simulate network latency
206
210
  await new Promise((resolve)=>setTimeout(resolve, Math.random() * 100));
207
211
  // Simulate agent validation
@@ -218,13 +222,14 @@ export class DistributedConsensusManager extends EventEmitter {
218
222
  return vote;
219
223
  }
220
224
  /**
221
- * Validate votes for cryptographic integrity
225
+ * Validate votes for cryptographic integrity using RSA public key verification
222
226
  */ validateVotes(votes, agents) {
223
227
  const validVotes = [];
224
228
  for (const vote of votes){
225
- // Verify signature
226
- const expectedSignature = this.signVote(vote.voterId, vote.proposalId, vote.validations);
227
- if (vote.signature === expectedSignature) {
229
+ // Verify RSA signature using agent's public key
230
+ const voteData = `${vote.voterId}:${vote.proposalId}:${vote.validations.overallScore}:${vote.validations.nonce}`;
231
+ const isValid = this.verifySignature(vote.voterId, voteData, vote.signature);
232
+ if (isValid) {
228
233
  validVotes.push(vote);
229
234
  } else {
230
235
  this.emit('vote:invalid_signature', {
@@ -511,21 +516,75 @@ export class DistributedConsensusManager extends EventEmitter {
511
516
  return validation;
512
517
  }
513
518
  /**
514
- * Sign validation with agent's private key (simulated)
519
+ * Ensure agent has RSA keypair (2048-bit)
520
+ */ ensureAgentKeypair(agentId) {
521
+ if (!this.agentKeyPairs.has(agentId)) {
522
+ const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
523
+ modulusLength: 2048,
524
+ publicKeyEncoding: {
525
+ type: 'spki',
526
+ format: 'pem'
527
+ },
528
+ privateKeyEncoding: {
529
+ type: 'pkcs8',
530
+ format: 'pem'
531
+ }
532
+ });
533
+ this.agentKeyPairs.set(agentId, {
534
+ publicKey,
535
+ privateKey
536
+ });
537
+ }
538
+ }
539
+ /**
540
+ * Sign validation with agent's RSA private key
515
541
  */ signValidation(validation) {
542
+ this.ensureAgentKeypair(validation.agentId);
516
543
  const data = JSON.stringify({
517
544
  agentId: validation.agentId,
518
545
  timestamp: validation.timestamp,
519
546
  dimensions: validation.dimensions,
520
547
  nonce: validation.nonce
521
548
  });
522
- return this.hash(data + validation.agentId);
549
+ const keypair = this.agentKeyPairs.get(validation.agentId);
550
+ const signature = crypto.sign('sha256', Buffer.from(data), {
551
+ key: keypair.privateKey,
552
+ padding: crypto.constants.RSA_PKCS1_PSS_PADDING
553
+ });
554
+ return signature.toString('base64');
523
555
  }
524
556
  /**
525
- * Sign vote with agent's private key (simulated)
557
+ * Sign vote with agent's RSA private key
526
558
  */ signVote(agentId, proposalId, validation) {
559
+ this.ensureAgentKeypair(agentId);
527
560
  const data = `${agentId}:${proposalId}:${validation.overallScore}:${validation.nonce}`;
528
- return this.hash(data);
561
+ const keypair = this.agentKeyPairs.get(agentId);
562
+ const signature = crypto.sign('sha256', Buffer.from(data), {
563
+ key: keypair.privateKey,
564
+ padding: crypto.constants.RSA_PKCS1_PSS_PADDING
565
+ });
566
+ return signature.toString('base64');
567
+ }
568
+ /**
569
+ * Verify RSA signature using agent's public key
570
+ */ verifySignature(agentId, data, signature) {
571
+ const keypair = this.agentKeyPairs.get(agentId);
572
+ if (!keypair) {
573
+ return false;
574
+ }
575
+ try {
576
+ const isValid = crypto.verify('sha256', Buffer.from(data), {
577
+ key: keypair.publicKey,
578
+ padding: crypto.constants.RSA_PKCS1_PSS_PADDING
579
+ }, Buffer.from(signature, 'base64'));
580
+ return isValid;
581
+ } catch (error) {
582
+ this.emit('signature:verification_failed', {
583
+ agentId,
584
+ error: error instanceof Error ? error.message : String(error)
585
+ });
586
+ return false;
587
+ }
529
588
  }
530
589
  /**
531
590
  * Generate cryptographic hash