claude-flow-novice 1.6.1 → 1.6.3

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 (273) 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 +5 -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/auth-service.js +84 -38
  14. package/.claude-flow-novice/dist/src/api/auth-service.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
  16. package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
  17. package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
  18. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
  19. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
  20. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
  21. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  22. package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
  23. package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
  24. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
  25. package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
  26. package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
  27. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
  28. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
  29. package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
  30. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
  31. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
  32. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
  33. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
  34. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
  35. package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
  36. package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
  37. package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
  38. package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
  39. package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
  40. package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
  41. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
  42. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
  43. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
  44. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
  45. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
  46. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  47. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
  48. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  49. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
  50. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
  51. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
  52. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  53. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
  54. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
  55. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
  56. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
  57. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
  58. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  59. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
  60. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
  61. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
  62. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
  63. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
  64. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
  65. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
  66. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
  67. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
  68. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
  69. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
  70. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
  71. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
  72. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
  73. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
  74. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
  75. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
  76. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
  77. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
  78. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
  79. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
  80. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
  81. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
  82. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
  83. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
  84. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
  85. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
  86. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
  87. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
  88. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
  89. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
  90. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
  91. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
  92. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
  93. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
  94. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
  95. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
  96. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
  97. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
  98. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
  99. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
  100. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
  101. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
  102. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
  103. package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
  104. package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
  105. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
  106. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
  107. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
  108. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
  109. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
  110. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  111. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
  112. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
  113. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
  114. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
  115. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
  116. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
  117. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
  118. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
  119. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
  120. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
  121. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
  122. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
  123. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
  124. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
  125. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
  126. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
  127. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
  128. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
  129. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
  130. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
  131. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
  132. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
  133. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
  134. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
  135. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
  136. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
  137. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
  138. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
  139. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
  140. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
  141. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
  142. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
  143. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
  144. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
  145. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
  146. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
  147. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
  148. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
  149. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
  150. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
  151. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
  152. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
  153. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
  154. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
  155. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
  156. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
  157. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
  158. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
  159. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
  160. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
  161. package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
  162. package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
  163. package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
  164. package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
  165. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +719 -0
  166. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -0
  167. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js +363 -0
  168. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js.map +1 -0
  169. package/.claude-flow-novice/dist/src/monitoring/apm/index.js +97 -0
  170. package/.claude-flow-novice/dist/src/monitoring/apm/index.js.map +1 -0
  171. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js +384 -0
  172. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js.map +1 -0
  173. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js +612 -0
  174. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js.map +1 -0
  175. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js +282 -0
  176. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js.map +1 -0
  177. package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
  178. package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
  179. package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
  180. package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
  181. package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
  182. package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
  183. package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
  184. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  185. package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
  186. package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
  187. package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
  188. package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
  189. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
  190. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
  191. package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
  192. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
  193. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
  195. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
  197. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
  198. package/.claude-flow-novice/dist/src/web/api/apm-routes.js +355 -0
  199. package/.claude-flow-novice/dist/src/web/api/apm-routes.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
  201. package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
  203. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
  205. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
  207. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
  209. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
  211. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
  213. package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
  214. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
  215. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
  216. package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
  217. package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
  218. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
  219. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
  220. package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
  221. package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
  222. package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
  223. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
  224. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
  225. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
  226. package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
  227. package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
  228. package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
  229. package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
  230. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js +425 -0
  231. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js.map +1 -0
  232. package/.claude-flow-novice/dist/src/web/security/security-middleware.js +379 -0
  233. package/.claude-flow-novice/dist/src/web/security/security-middleware.js.map +1 -0
  234. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js +441 -0
  235. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js.map +1 -0
  236. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js +255 -1
  237. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js.map +1 -1
  238. package/.claude-flow-novice/metrics.db +0 -0
  239. package/.claude-flow-novice/metrics.db-shm +0 -0
  240. package/.claude-flow-novice/metrics.db-wal +0 -0
  241. package/AGENT_PERFORMANCE_GUIDELINES.md +88 -0
  242. package/CLAUDE.md +60 -3
  243. package/MEMORY_LEAK_ROOT_CAUSE.md +149 -0
  244. package/README.md +27 -0
  245. package/config/hooks/post-edit-pipeline.js +36 -2
  246. package/examples/metrics-counter-demo.ts +106 -0
  247. package/examples/persistent-metrics-demo.ts +83 -0
  248. package/examples/phase-5-multi-level-control.ts +282 -0
  249. package/examples/session-pool-optimizer-example.ts +311 -0
  250. package/package.json +18 -4
  251. package/scripts/check-routing-stats.cjs +122 -0
  252. package/scripts/monitor-loop.sh +65 -0
  253. package/scripts/monitor-memory.sh +47 -0
  254. package/scripts/monitor.py +43 -0
  255. package/scripts/pre-publish-validation.cjs +212 -0
  256. package/scripts/test-provider-routing.cjs +228 -0
  257. package/scripts/test-routing-telemetry.cjs +147 -0
  258. package/scripts/test-zai-10k.cjs +81 -0
  259. package/scripts/test-zai-api.cjs +191 -0
  260. package/scripts/test-zai-diagnostic.cjs +151 -0
  261. package/scripts/test-zai-final.cjs +128 -0
  262. package/scripts/test-zai-with-env.cjs +85 -0
  263. package/scripts/validate-coordination-cli.js +69 -0
  264. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  265. package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
  266. package/src/observability/metrics-counter.ts +347 -0
  267. package/src/observability/metrics-storage.ts +356 -0
  268. package/src/observability/telemetry.ts +658 -0
  269. package/src/slash-commands/cfn-claude-sync.js +533 -0
  270. package/src/slash-commands/index.js +5 -0
  271. package/src/slash-commands/metrics-summary-class.js +74 -0
  272. package/src/slash-commands/metrics-summary.js +335 -0
  273. package/src/slash-commands/register-all-commands.js +12 -0
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Agent Coordination V2 - Topological Sort Implementation
3
+ *
4
+ * Kahn's algorithm for topological sorting of dependency graphs.
5
+ * Provides O(V+E) complexity for computing execution ordering.
6
+ *
7
+ * @module coordination/v2/dependency/topological-sort
8
+ */ /**
9
+ * Topological Sort using Kahn's Algorithm.
10
+ *
11
+ * Kahn's algorithm works by:
12
+ * 1. Computing in-degree for all nodes
13
+ * 2. Starting with nodes having in-degree 0 (no dependencies)
14
+ * 3. Removing nodes from queue and decrementing in-degrees
15
+ * 4. Adding nodes with in-degree 0 to queue
16
+ * 5. Repeating until all nodes processed or cycle detected
17
+ *
18
+ * Time Complexity: O(V + E)
19
+ * Space Complexity: O(V)
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const sorter = new TopologicalSort(graph);
24
+ * const result = sorter.sort();
25
+ *
26
+ * if (result.success) {
27
+ * console.log('Execution order:', result.order);
28
+ * } else {
29
+ * console.error('Cycle detected:', result.cycles);
30
+ * }
31
+ * ```
32
+ */ export class TopologicalSort {
33
+ graph;
34
+ /**
35
+ * Creates a new topological sorter.
36
+ *
37
+ * @param graph - Dependency graph to sort
38
+ */ constructor(graph){
39
+ this.graph = graph;
40
+ }
41
+ /**
42
+ * Performs topological sort using Kahn's algorithm.
43
+ *
44
+ * Returns nodes in dependency order (dependencies before dependents).
45
+ * If graph contains cycles, sort fails and cycles are reported.
46
+ *
47
+ * Algorithm:
48
+ * 1. Calculate in-degree for each node (count of incoming edges)
49
+ * 2. Queue all nodes with in-degree 0 (no dependencies)
50
+ * 3. While queue not empty:
51
+ * a. Dequeue node and add to result
52
+ * b. For each dependent of node:
53
+ * - Decrement its in-degree
54
+ * - If in-degree becomes 0, enqueue it
55
+ * 4. If result contains all nodes → success
56
+ * Else → cycle exists
57
+ *
58
+ * @returns Topological sort result
59
+ */ sort() {
60
+ const inDegree = new Map();
61
+ const queue = [];
62
+ const result = [];
63
+ // Step 1: Initialize in-degrees
64
+ for (const nodeId of this.graph.getAllNodes().map((n)=>n.id)){
65
+ const dependencies = this.graph.getDependencies(nodeId);
66
+ inDegree.set(nodeId, dependencies.size);
67
+ // Step 2: Enqueue nodes with no dependencies
68
+ if (dependencies.size === 0) {
69
+ queue.push(nodeId);
70
+ }
71
+ }
72
+ // Step 3: Process nodes with zero in-degree (BFS)
73
+ while(queue.length > 0){
74
+ const nodeId = queue.shift();
75
+ result.push(nodeId);
76
+ // Step 4: Update in-degrees for dependents
77
+ const dependents = this.graph.getDependents(nodeId);
78
+ for (const dependentId of dependents){
79
+ const currentInDegree = inDegree.get(dependentId);
80
+ const newInDegree = currentInDegree - 1;
81
+ inDegree.set(dependentId, newInDegree);
82
+ // Enqueue if all dependencies satisfied
83
+ if (newInDegree === 0) {
84
+ queue.push(dependentId);
85
+ }
86
+ }
87
+ }
88
+ // Step 5: Validate result (all nodes processed?)
89
+ const totalNodes = this.graph.size();
90
+ const success = result.length === totalNodes;
91
+ if (!success) {
92
+ // Cycle detected - identify cycles
93
+ const cycleDetection = this.graph.detectCycles();
94
+ return {
95
+ order: result,
96
+ success: false,
97
+ error: `Cannot compute topological order: graph contains cycles. Processed ${result.length}/${totalNodes} nodes.`,
98
+ cycles: cycleDetection.cycles
99
+ };
100
+ }
101
+ return {
102
+ order: result,
103
+ success: true
104
+ };
105
+ }
106
+ /**
107
+ * Validates if graph is acyclic (DAG).
108
+ *
109
+ * @returns True if graph is a DAG (can be topologically sorted)
110
+ */ isDAG() {
111
+ return this.sort().success;
112
+ }
113
+ /**
114
+ * Gets ready nodes (nodes with all dependencies satisfied).
115
+ *
116
+ * This is useful for incremental execution - get next batch of
117
+ * executable tasks without sorting the entire graph.
118
+ *
119
+ * @param completed - Set of already completed node IDs
120
+ * @returns Array of node IDs ready for execution
121
+ */ getReadyNodes(completed) {
122
+ const ready = [];
123
+ for (const node of this.graph.getAllNodes()){
124
+ // Skip completed nodes
125
+ if (completed.has(node.id)) {
126
+ continue;
127
+ }
128
+ // Check if all dependencies are completed
129
+ const dependencies = this.graph.getDependencies(node.id);
130
+ let allDepsCompleted = true;
131
+ for (const depId of dependencies){
132
+ if (!completed.has(depId)) {
133
+ allDepsCompleted = false;
134
+ break;
135
+ }
136
+ }
137
+ if (allDepsCompleted) {
138
+ ready.push(node.id);
139
+ }
140
+ }
141
+ return ready;
142
+ }
143
+ /**
144
+ * Computes partial topological order for a subset of nodes.
145
+ *
146
+ * This is useful when you only care about ordering a subset of nodes
147
+ * (e.g., tasks for a specific agent).
148
+ *
149
+ * @param nodeIds - Subset of node IDs to order
150
+ * @returns Topological order for subset (or null if cycles exist)
151
+ */ sortSubset(nodeIds) {
152
+ const subsetInDegree = new Map();
153
+ const queue = [];
154
+ const result = [];
155
+ // Initialize in-degrees for subset only
156
+ for (const nodeId of nodeIds){
157
+ const dependencies = this.graph.getDependencies(nodeId);
158
+ // Count dependencies within subset
159
+ let inDegreeCount = 0;
160
+ for (const depId of dependencies){
161
+ if (nodeIds.has(depId)) {
162
+ inDegreeCount++;
163
+ }
164
+ }
165
+ subsetInDegree.set(nodeId, inDegreeCount);
166
+ if (inDegreeCount === 0) {
167
+ queue.push(nodeId);
168
+ }
169
+ }
170
+ // BFS processing
171
+ while(queue.length > 0){
172
+ const nodeId = queue.shift();
173
+ result.push(nodeId);
174
+ const dependents = this.graph.getDependents(nodeId);
175
+ for (const dependentId of dependents){
176
+ if (!nodeIds.has(dependentId)) continue;
177
+ const currentInDegree = subsetInDegree.get(dependentId);
178
+ const newInDegree = currentInDegree - 1;
179
+ subsetInDegree.set(dependentId, newInDegree);
180
+ if (newInDegree === 0) {
181
+ queue.push(dependentId);
182
+ }
183
+ }
184
+ }
185
+ // Validate complete
186
+ if (result.length !== nodeIds.size) {
187
+ return null; // Cycle in subset
188
+ }
189
+ return result;
190
+ }
191
+ /**
192
+ * Computes execution levels (nodes at same depth can run in parallel).
193
+ *
194
+ * Returns nodes grouped by execution level:
195
+ * - Level 0: Nodes with no dependencies
196
+ * - Level 1: Nodes depending only on Level 0
197
+ * - Level N: Nodes depending on Level N-1 or earlier
198
+ *
199
+ * @returns Array of levels, each containing node IDs at that level
200
+ */ computeLevels() {
201
+ const levels = [];
202
+ const nodeLevel = new Map();
203
+ const completed = new Set();
204
+ // Process nodes level by level
205
+ let currentLevel = 0;
206
+ while(completed.size < this.graph.size()){
207
+ const levelNodes = this.getReadyNodes(completed);
208
+ if (levelNodes.length === 0) {
209
+ break;
210
+ }
211
+ levels.push(levelNodes);
212
+ // Mark nodes as completed and assign level
213
+ for (const nodeId of levelNodes){
214
+ completed.add(nodeId);
215
+ nodeLevel.set(nodeId, currentLevel);
216
+ }
217
+ currentLevel++;
218
+ }
219
+ return levels;
220
+ }
221
+ }
222
+
223
+ //# sourceMappingURL=topological-sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/coordination/v2/dependency/topological-sort.ts"],"names":["TopologicalSort","graph","sort","inDegree","Map","queue","result","nodeId","getAllNodes","map","n","id","dependencies","getDependencies","set","size","push","length","shift","dependents","getDependents","dependentId","currentInDegree","get","newInDegree","totalNodes","success","cycleDetection","detectCycles","order","error","cycles","isDAG","getReadyNodes","completed","ready","node","has","allDepsCompleted","depId","sortSubset","nodeIds","subsetInDegree","inDegreeCount","computeLevels","levels","nodeLevel","Set","currentLevel","levelNodes","add"],"mappings":"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"}
@@ -0,0 +1,436 @@
1
+ /**
2
+ * Agent Coordination V2 - Help Coordinator
3
+ *
4
+ * Help routing and lifecycle management with MessageBroker integration.
5
+ * Target: <200ms p95 latency for routing help requests to best-match agents.
6
+ *
7
+ * @module coordination/v2/help-system/help-coordinator
8
+ */ import { HelpRequest, HelpRequestPriority } from './help-request.js';
9
+ import { HelpMatcher } from './help-matcher.js';
10
+ import { MessagePriority } from '../core/message.js';
11
+ /**
12
+ * Help coordinator implementation with routing and lifecycle management
13
+ */ export class HelpCoordinator {
14
+ /** Help request matcher */ matcher;
15
+ /** Active help requests */ activeRequests;
16
+ /** Request queue (overflow when max concurrent reached) */ requestQueue;
17
+ /** Routing results history */ routingHistory;
18
+ /** Coordinator configuration */ config;
19
+ /** Performance metrics */ metrics;
20
+ /** Recent routing latencies for percentile calculation */ recentLatencies;
21
+ /** Request ID counter */ requestCounter;
22
+ constructor(config){
23
+ this.matcher = new HelpMatcher(config?.matcherConfig);
24
+ this.activeRequests = new Map();
25
+ this.requestQueue = [];
26
+ this.routingHistory = [];
27
+ this.recentLatencies = [];
28
+ this.requestCounter = 0;
29
+ this.config = {
30
+ matcherConfig: config?.matcherConfig ?? {},
31
+ maxConcurrentRequests: config?.maxConcurrentRequests ?? 100,
32
+ autoRetry: config?.autoRetry ?? true,
33
+ maxRoutingAttempts: config?.maxRoutingAttempts ?? 3,
34
+ enableQueue: config?.enableQueue ?? true,
35
+ maxQueueSize: config?.maxQueueSize ?? 500,
36
+ messageBroker: config?.messageBroker,
37
+ enableEventPublishing: config?.enableEventPublishing ?? config?.messageBroker !== undefined
38
+ };
39
+ this.metrics = {
40
+ totalRequests: 0,
41
+ successfulRoutes: 0,
42
+ failedRoutes: 0,
43
+ averageRoutingLatencyMs: 0,
44
+ p95RoutingLatencyMs: 0,
45
+ p99RoutingLatencyMs: 0,
46
+ activeRequests: 0,
47
+ queuedRequests: 0,
48
+ resolvedRequests: 0,
49
+ expiredRequests: 0
50
+ };
51
+ }
52
+ /**
53
+ * Create and route help request
54
+ * Target: <200ms p95 latency
55
+ */ async createHelpRequest(requesterId, description, capabilities, priority = HelpRequestPriority.NORMAL, metadata) {
56
+ const startTime = performance.now();
57
+ // Generate unique request ID
58
+ const requestId = this.generateRequestId();
59
+ // Create help request
60
+ const request = new HelpRequest({
61
+ requestId,
62
+ requesterId,
63
+ priority,
64
+ capabilities,
65
+ description,
66
+ metadata
67
+ });
68
+ this.metrics.totalRequests++;
69
+ // Check concurrent request limit
70
+ if (this.activeRequests.size >= this.config.maxConcurrentRequests) {
71
+ if (this.config.enableQueue && this.requestQueue.length < this.config.maxQueueSize) {
72
+ this.requestQueue.push(request);
73
+ this.metrics.queuedRequests++;
74
+ return {
75
+ routingId: this.generateRoutingId(),
76
+ request,
77
+ match: null,
78
+ status: 'no_match',
79
+ latencyMs: performance.now() - startTime,
80
+ timestamp: new Date(),
81
+ error: 'Request queued - max concurrent requests reached'
82
+ };
83
+ }
84
+ return {
85
+ routingId: this.generateRoutingId(),
86
+ request,
87
+ match: null,
88
+ status: 'failed',
89
+ latencyMs: performance.now() - startTime,
90
+ timestamp: new Date(),
91
+ error: 'Max concurrent requests reached and queue is full'
92
+ };
93
+ }
94
+ // Route request to best match
95
+ const result = await this.routeRequest(request);
96
+ const latency = performance.now() - startTime;
97
+ result.latencyMs = latency;
98
+ this.recordRoutingMetrics(latency, result.status === 'success');
99
+ return result;
100
+ }
101
+ /**
102
+ * Route help request to best matching agent
103
+ */ async routeRequest(request) {
104
+ const routingId = this.generateRoutingId();
105
+ const startTime = performance.now();
106
+ try {
107
+ // Find best match
108
+ const match = await this.matcher.findMatch(request);
109
+ if (!match) {
110
+ this.metrics.failedRoutes++;
111
+ return {
112
+ routingId,
113
+ request,
114
+ match: null,
115
+ status: 'no_match',
116
+ latencyMs: performance.now() - startTime,
117
+ timestamp: new Date(),
118
+ error: 'No matching agent found'
119
+ };
120
+ }
121
+ // Mark request as matched
122
+ request.markMatched(match.agentId);
123
+ // Track active request
124
+ this.activeRequests.set(request.requestId, request);
125
+ this.metrics.activeRequests = this.activeRequests.size;
126
+ this.metrics.successfulRoutes++;
127
+ const result = {
128
+ routingId,
129
+ request,
130
+ match,
131
+ status: 'success',
132
+ latencyMs: performance.now() - startTime,
133
+ timestamp: new Date()
134
+ };
135
+ this.routingHistory.push(result);
136
+ // Publish routing success event via MessageBroker
137
+ await this.publishRoutingEvent(result);
138
+ return result;
139
+ } catch (error) {
140
+ this.metrics.failedRoutes++;
141
+ return {
142
+ routingId,
143
+ request,
144
+ match: null,
145
+ status: 'failed',
146
+ latencyMs: performance.now() - startTime,
147
+ timestamp: new Date(),
148
+ error: error instanceof Error ? error.message : 'Unknown routing error'
149
+ };
150
+ }
151
+ }
152
+ /**
153
+ * Mark help request as in progress
154
+ */ async startHelp(requestId) {
155
+ const request = this.activeRequests.get(requestId);
156
+ if (!request) {
157
+ throw new Error(`Help request ${requestId} not found`);
158
+ }
159
+ request.markInProgress();
160
+ // Publish help started event
161
+ await this.publishHelpStartedEvent(request);
162
+ }
163
+ /**
164
+ * Mark help request as resolved
165
+ */ async resolveHelp(requestId, metadata) {
166
+ const request = this.activeRequests.get(requestId);
167
+ if (!request) {
168
+ throw new Error(`Help request ${requestId} not found`);
169
+ }
170
+ request.markResolved(metadata);
171
+ this.activeRequests.delete(requestId);
172
+ this.metrics.activeRequests = this.activeRequests.size;
173
+ this.metrics.resolvedRequests++;
174
+ // Publish help resolved event
175
+ await this.publishHelpResolvedEvent(request, metadata);
176
+ // Process next queued request
177
+ this.processQueue();
178
+ }
179
+ /**
180
+ * Mark help request as failed
181
+ */ async failHelp(requestId, reason, metadata) {
182
+ const request = this.activeRequests.get(requestId);
183
+ if (!request) {
184
+ throw new Error(`Help request ${requestId} not found`);
185
+ }
186
+ request.markFailed(reason, metadata);
187
+ this.activeRequests.delete(requestId);
188
+ this.metrics.activeRequests = this.activeRequests.size;
189
+ // Publish help failed event
190
+ await this.publishHelpFailedEvent(request, reason, metadata);
191
+ // Retry if enabled and possible
192
+ if (this.config.autoRetry && request.canRetry()) {
193
+ const retried = await request.retry();
194
+ if (retried) {
195
+ // Re-route retried request
196
+ await this.routeRequest(request);
197
+ }
198
+ }
199
+ // Process next queued request
200
+ this.processQueue();
201
+ }
202
+ /**
203
+ * Cancel help request
204
+ */ async cancelHelp(requestId, reason) {
205
+ const request = this.activeRequests.get(requestId);
206
+ if (!request) {
207
+ throw new Error(`Help request ${requestId} not found`);
208
+ }
209
+ request.cancel(reason);
210
+ this.activeRequests.delete(requestId);
211
+ this.metrics.activeRequests = this.activeRequests.size;
212
+ // Process next queued request
213
+ this.processQueue();
214
+ }
215
+ /**
216
+ * Get help request status
217
+ */ getRequestStatus(requestId) {
218
+ const request = this.activeRequests.get(requestId);
219
+ return request ? request.status : null;
220
+ }
221
+ /**
222
+ * Get help request details
223
+ */ getRequest(requestId) {
224
+ return this.activeRequests.get(requestId) || null;
225
+ }
226
+ /**
227
+ * Register agent profile for matching
228
+ */ registerAgent(profile) {
229
+ this.matcher.registerAgent(profile);
230
+ }
231
+ /**
232
+ * Unregister agent profile
233
+ */ unregisterAgent(agentId) {
234
+ this.matcher.unregisterAgent(agentId);
235
+ }
236
+ /**
237
+ * Update agent state
238
+ */ updateAgentState(agentId, state) {
239
+ this.matcher.updateAgentState(agentId, state);
240
+ }
241
+ /**
242
+ * Update agent workload
243
+ */ updateAgentWorkload(agentId, workload) {
244
+ this.matcher.updateAgentWorkload(agentId, workload);
245
+ }
246
+ /**
247
+ * Process queued requests
248
+ */ async processQueue() {
249
+ if (this.requestQueue.length === 0) {
250
+ return;
251
+ }
252
+ if (this.activeRequests.size >= this.config.maxConcurrentRequests) {
253
+ return;
254
+ }
255
+ // Process highest priority queued request
256
+ this.requestQueue.sort((a, b)=>b.priority - a.priority);
257
+ const nextRequest = this.requestQueue.shift();
258
+ if (nextRequest) {
259
+ this.metrics.queuedRequests = this.requestQueue.length;
260
+ await this.routeRequest(nextRequest);
261
+ }
262
+ }
263
+ /**
264
+ * Record routing metrics
265
+ */ recordRoutingMetrics(latencyMs, success) {
266
+ this.recentLatencies.push(latencyMs);
267
+ // Keep only last 1000 latencies
268
+ if (this.recentLatencies.length > 1000) {
269
+ this.recentLatencies.shift();
270
+ }
271
+ // Update average latency
272
+ const totalRoutes = this.metrics.successfulRoutes + this.metrics.failedRoutes;
273
+ this.metrics.averageRoutingLatencyMs = (this.metrics.averageRoutingLatencyMs * (totalRoutes - 1) + latencyMs) / totalRoutes;
274
+ // Update percentiles
275
+ const sorted = [
276
+ ...this.recentLatencies
277
+ ].sort((a, b)=>a - b);
278
+ this.metrics.p95RoutingLatencyMs = sorted[Math.floor(sorted.length * 0.95)] || 0;
279
+ this.metrics.p99RoutingLatencyMs = sorted[Math.floor(sorted.length * 0.99)] || 0;
280
+ }
281
+ /**
282
+ * Generate unique request ID
283
+ */ generateRequestId() {
284
+ return `help_req_${Date.now()}_${++this.requestCounter}`;
285
+ }
286
+ /**
287
+ * Generate unique routing ID
288
+ */ generateRoutingId() {
289
+ return `route_${Date.now()}_${this.requestCounter}`;
290
+ }
291
+ /**
292
+ * Get coordinator metrics
293
+ */ getMetrics() {
294
+ return {
295
+ ...this.metrics,
296
+ matcherMetrics: this.matcher.getMetrics()
297
+ };
298
+ }
299
+ /**
300
+ * Get all active requests
301
+ */ getActiveRequests() {
302
+ return Array.from(this.activeRequests.values());
303
+ }
304
+ /**
305
+ * Get queued requests
306
+ */ getQueuedRequests() {
307
+ return [
308
+ ...this.requestQueue
309
+ ];
310
+ }
311
+ /**
312
+ * Get routing history
313
+ */ getRoutingHistory(limit) {
314
+ return limit ? this.routingHistory.slice(-limit) : [
315
+ ...this.routingHistory
316
+ ];
317
+ }
318
+ /**
319
+ * Clear coordinator state
320
+ */ clear() {
321
+ this.activeRequests.clear();
322
+ this.requestQueue = [];
323
+ this.routingHistory = [];
324
+ this.matcher.clear();
325
+ this.recentLatencies = [];
326
+ this.requestCounter = 0;
327
+ this.metrics = {
328
+ totalRequests: 0,
329
+ successfulRoutes: 0,
330
+ failedRoutes: 0,
331
+ averageRoutingLatencyMs: 0,
332
+ p95RoutingLatencyMs: 0,
333
+ p99RoutingLatencyMs: 0,
334
+ activeRequests: 0,
335
+ queuedRequests: 0,
336
+ resolvedRequests: 0,
337
+ expiredRequests: 0
338
+ };
339
+ }
340
+ // ============================================
341
+ // MessageBroker Event Publishing
342
+ // ============================================
343
+ /**
344
+ * Publish routing event to MessageBroker
345
+ */ async publishRoutingEvent(result) {
346
+ if (!this.config.enableEventPublishing || !this.config.messageBroker) {
347
+ return;
348
+ }
349
+ try {
350
+ await this.config.messageBroker.publish({
351
+ topic: 'help.event.routed',
352
+ payload: {
353
+ routingId: result.routingId,
354
+ requestId: result.request.requestId,
355
+ requesterId: result.request.requesterId,
356
+ status: result.status,
357
+ latencyMs: result.latencyMs,
358
+ match: result.match ? {
359
+ agentId: result.match.agentId,
360
+ score: result.match.score
361
+ } : null,
362
+ timestamp: result.timestamp
363
+ },
364
+ priority: MessagePriority.LOW
365
+ });
366
+ } catch (error) {
367
+ console.error('[HelpCoordinator] Error publishing routing event:', error);
368
+ }
369
+ }
370
+ /**
371
+ * Publish help started event to MessageBroker
372
+ */ async publishHelpStartedEvent(request) {
373
+ if (!this.config.enableEventPublishing || !this.config.messageBroker) {
374
+ return;
375
+ }
376
+ try {
377
+ await this.config.messageBroker.publish({
378
+ topic: `help.accepted.${request.requestId}`,
379
+ payload: {
380
+ requestId: request.requestId,
381
+ helperId: request.matchedHelperId,
382
+ timestamp: new Date()
383
+ },
384
+ priority: MessagePriority.HIGH
385
+ });
386
+ } catch (error) {
387
+ console.error('[HelpCoordinator] Error publishing help started event:', error);
388
+ }
389
+ }
390
+ /**
391
+ * Publish help resolved event to MessageBroker
392
+ */ async publishHelpResolvedEvent(request, metadata) {
393
+ if (!this.config.enableEventPublishing || !this.config.messageBroker) {
394
+ return;
395
+ }
396
+ try {
397
+ await this.config.messageBroker.publish({
398
+ topic: `help.completed.${request.requestId}`,
399
+ payload: {
400
+ requestId: request.requestId,
401
+ helperId: request.matchedHelperId,
402
+ success: true,
403
+ result: metadata,
404
+ timestamp: new Date()
405
+ },
406
+ priority: MessagePriority.HIGH
407
+ });
408
+ } catch (error) {
409
+ console.error('[HelpCoordinator] Error publishing help resolved event:', error);
410
+ }
411
+ }
412
+ /**
413
+ * Publish help failed event to MessageBroker
414
+ */ async publishHelpFailedEvent(request, reason, metadata) {
415
+ if (!this.config.enableEventPublishing || !this.config.messageBroker) {
416
+ return;
417
+ }
418
+ try {
419
+ await this.config.messageBroker.publish({
420
+ topic: `help.completed.${request.requestId}`,
421
+ payload: {
422
+ requestId: request.requestId,
423
+ helperId: request.matchedHelperId,
424
+ success: false,
425
+ error: reason,
426
+ timestamp: new Date()
427
+ },
428
+ priority: MessagePriority.HIGH
429
+ });
430
+ } catch (error) {
431
+ console.error('[HelpCoordinator] Error publishing help failed event:', error);
432
+ }
433
+ }
434
+ }
435
+
436
+ //# sourceMappingURL=help-coordinator.js.map