claude-flow-novice 1.6.4 → 1.6.5

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 (269) hide show
  1. package/.claude/commands/parse-epic.js +180 -0
  2. package/.claude/settings.local.json +2 -1
  3. package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +37 -2
  4. package/.claude-flow-novice/dist/mcp/transports/base.js +5 -0
  5. package/.claude-flow-novice/dist/mcp/transports/base.js.map +1 -0
  6. package/.claude-flow-novice/dist/mcp/transports/http.js +414 -0
  7. package/.claude-flow-novice/dist/mcp/transports/http.js.map +1 -0
  8. package/.claude-flow-novice/dist/mcp/transports/stdio.js +217 -0
  9. package/.claude-flow-novice/dist/mcp/transports/stdio.js.map +1 -0
  10. package/.claude-flow-novice/dist/src/cli/commands/parse-epic.js +129 -0
  11. package/.claude-flow-novice/dist/src/cli/commands/parse-epic.js.map +1 -0
  12. package/.claude-flow-novice/dist/src/cli/index.js +3 -0
  13. package/.claude-flow-novice/dist/src/cli/index.js.map +1 -1
  14. package/.claude-flow-novice/dist/src/cli/utils/epic-parser.js +266 -0
  15. package/.claude-flow-novice/dist/src/cli/utils/epic-parser.js.map +1 -0
  16. package/.claude-flow-novice/dist/src/communication/message-bus.js +105 -2
  17. package/.claude-flow-novice/dist/src/communication/message-bus.js.map +1 -1
  18. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +1 -1
  19. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -1
  20. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/artifact-cache-optimizer.js +632 -0
  21. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/artifact-cache-optimizer.js.map +1 -0
  22. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/index.js +11 -0
  23. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/index.js.map +1 -0
  24. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/checkpoints/checkpoint-compressor.js +318 -0
  25. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  26. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/completion-detector.js +234 -0
  27. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/completion-detector.js.map +1 -0
  28. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/hierarchical-detector.js +347 -0
  29. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/hierarchical-detector.js.map +1 -0
  30. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/index.js +13 -0
  31. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/index.js.map +1 -0
  32. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/lamport-clock.js +173 -0
  33. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/lamport-clock.js.map +1 -0
  34. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/mesh-detector.js +526 -0
  35. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/mesh-detector.js.map +1 -0
  36. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/sdk-completion-detector.js +443 -0
  37. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/sdk-completion-detector.js.map +1 -0
  38. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/swarm-shutdown.js +366 -0
  39. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/swarm-shutdown.js.map +1 -0
  40. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinator-factory.js +287 -0
  41. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinator-factory.js.map +1 -0
  42. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.example.js +364 -0
  43. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  44. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.js +492 -0
  45. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.js.map +1 -0
  46. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/hierarchical-coordinator.js +786 -0
  47. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  48. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/index.js +16 -0
  49. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/index.js.map +1 -0
  50. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/parent-child-manager.js +342 -0
  51. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/parent-child-manager.js.map +1 -0
  52. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/swarm-coordinator-v2.js +601 -0
  53. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  54. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/agent-state.js +9 -0
  55. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/agent-state.js.map +1 -0
  56. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dead-letter-queue.js +413 -0
  57. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dead-letter-queue.js.map +1 -0
  58. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-graph.js +471 -0
  59. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-graph.js.map +1 -0
  60. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-node.js +379 -0
  61. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-node.js.map +1 -0
  62. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-resolver.js +335 -0
  63. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-resolver.js.map +1 -0
  64. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/help-request-metrics.js +211 -0
  65. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/help-request-metrics.js.map +1 -0
  66. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/index.js +33 -0
  67. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/index.js.map +1 -0
  68. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-broker.js +920 -0
  69. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-broker.js.map +1 -0
  70. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-router.js +385 -0
  71. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-router.js.map +1 -0
  72. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message.js +138 -0
  73. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message.js.map +1 -0
  74. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/resource-manager-safe.js +478 -0
  75. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/resource-manager-safe.js.map +1 -0
  76. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine-config.js +358 -0
  77. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine-config.js.map +1 -0
  78. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine.js +588 -0
  79. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine.js.map +1 -0
  80. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-transition.js +153 -0
  81. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-transition.js.map +1 -0
  82. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/task-scheduler.js +360 -0
  83. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/task-scheduler.js.map +1 -0
  84. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/topic-manager.js +337 -0
  85. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/topic-manager.js.map +1 -0
  86. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/deadlock-detector.js +424 -0
  87. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/deadlock-detector.js.map +1 -0
  88. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/index.js +9 -0
  89. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/index.js.map +1 -0
  90. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/resource-manager.js +669 -0
  91. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/resource-manager.js.map +1 -0
  92. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/artifact-storage.js +451 -0
  93. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/artifact-storage.js.map +1 -0
  94. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/cycle-detector.js +271 -0
  95. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/cycle-detector.js.map +1 -0
  96. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-graph.js +335 -0
  97. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-graph.js.map +1 -0
  98. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-manager.js +439 -0
  99. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-manager.js.map +1 -0
  100. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-request.js +92 -0
  101. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-request.js.map +1 -0
  102. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/index.js +21 -0
  103. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/index.js.map +1 -0
  104. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/topological-sort.js +223 -0
  105. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/topological-sort.js.map +1 -0
  106. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-coordinator.js +436 -0
  107. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-coordinator.js.map +1 -0
  108. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-matcher.js +278 -0
  109. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-matcher.js.map +1 -0
  110. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request-handler.js +317 -0
  111. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request-handler.js.map +1 -0
  112. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request.js +273 -0
  113. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request.js.map +1 -0
  114. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/index.js +15 -0
  115. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/index.js.map +1 -0
  116. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/waiting-agent-pool.js +512 -0
  117. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/waiting-agent-pool.js.map +1 -0
  118. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/index.js +67 -0
  119. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/index.js.map +1 -0
  120. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/help-deadlock-integration.js +557 -0
  121. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/help-deadlock-integration.js.map +1 -0
  122. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/index.js +14 -0
  123. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/index.js.map +1 -0
  124. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.example.js +212 -0
  125. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  126. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.js +552 -0
  127. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.js.map +1 -0
  128. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/state-machine-integration.js +635 -0
  129. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/state-machine-integration.js.map +1 -0
  130. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/IArtifactStorage.js +28 -0
  131. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/IArtifactStorage.js.map +1 -0
  132. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ICoordinator.js +9 -0
  133. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ICoordinator.js.map +1 -0
  134. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ISessionStore.js +25 -0
  135. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ISessionStore.js.map +1 -0
  136. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/index.js +14 -0
  137. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/index.js.map +1 -0
  138. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/artifact-adapter.js +308 -0
  139. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/artifact-adapter.js.map +1 -0
  140. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/completion-storage.js +439 -0
  141. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/completion-storage.js.map +1 -0
  142. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-graph-storage.js +540 -0
  143. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-graph-storage.js.map +1 -0
  144. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-storage.js +367 -0
  145. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-storage.js.map +1 -0
  146. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/index.js +14 -0
  147. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/index.js.map +1 -0
  148. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/message-storage.js +518 -0
  149. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/message-storage.js.map +1 -0
  150. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/state-storage.js +377 -0
  151. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/state-storage.js.map +1 -0
  152. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channel.js +371 -0
  153. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channel.js.map +1 -0
  154. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/dependency-channel.js +355 -0
  155. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/dependency-channel.js.map +1 -0
  156. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/help-channel.js +424 -0
  157. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/help-channel.js.map +1 -0
  158. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/index.js +16 -0
  159. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/index.js.map +1 -0
  160. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/state-channel.js +295 -0
  161. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/state-channel.js.map +1 -0
  162. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/task-channel.js +411 -0
  163. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/task-channel.js.map +1 -0
  164. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/index.js +14 -0
  165. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/index.js.map +1 -0
  166. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-bus.js +387 -0
  167. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-bus.js.map +1 -0
  168. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-persistence.js +589 -0
  169. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-persistence.js.map +1 -0
  170. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-router.js +444 -0
  171. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-router.js.map +1 -0
  172. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/artifact-storage.js +560 -0
  173. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/artifact-storage.js.map +1 -0
  174. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/background-orchestrator.js +335 -0
  175. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/background-orchestrator.js.map +1 -0
  176. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/bash-output-monitor.js +104 -0
  177. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/bash-output-monitor.js.map +1 -0
  178. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/checkpoint-manager.js +847 -0
  179. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/checkpoint-manager.js.map +1 -0
  180. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/help-coordinator.js +470 -0
  181. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/help-coordinator.js.map +1 -0
  182. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/hierarchical-background-integration.js +450 -0
  183. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/hierarchical-background-integration.js.map +1 -0
  184. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/index.js +13 -0
  185. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/index.js.map +1 -0
  186. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/message-bus-integration.js +625 -0
  187. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/message-bus-integration.js.map +1 -0
  188. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/multi-level-control.js +545 -0
  189. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/multi-level-control.js.map +1 -0
  190. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-controller.js +740 -0
  191. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-controller.js.map +1 -0
  192. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-message-integration.js +415 -0
  193. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-message-integration.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/session-pool-optimizer.js +615 -0
  195. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/session-pool-optimizer.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-machine-integration.js +547 -0
  197. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-machine-integration.js.map +1 -0
  198. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-sdk-integration.js +342 -0
  199. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-sdk-integration.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/security/payload-validator.js +259 -0
  201. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/security/payload-validator.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/framework-registry.js +273 -0
  203. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/framework-registry.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/index.js +8 -0
  205. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/index.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-config-manager.js +310 -0
  207. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-config-manager.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-validator.js +218 -0
  209. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-validator.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/types/sdk.js +9 -0
  211. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/types/sdk.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/index.js +6 -0
  213. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/index.js.map +1 -0
  214. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/priority-queue.js +145 -0
  215. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/priority-queue.js.map +1 -0
  216. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/sdk-helpers.js +122 -0
  217. package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/sdk-helpers.js.map +1 -0
  218. package/.claude-flow-novice/dist/src/coordination/config-translator.js +17 -43
  219. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -1
  220. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +34 -76
  221. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -1
  222. package/.claude-flow-novice/dist/src/coordination/shared/core/agent-state.js +172 -0
  223. package/.claude-flow-novice/dist/src/coordination/shared/core/agent-state.js.map +1 -0
  224. package/.claude-flow-novice/dist/src/coordination/shared/core/index.js +7 -0
  225. package/.claude-flow-novice/dist/src/coordination/shared/core/index.js.map +1 -0
  226. package/.claude-flow-novice/dist/src/coordination/shared/index.js +19 -0
  227. package/.claude-flow-novice/dist/src/coordination/shared/index.js.map +1 -0
  228. package/.claude-flow-novice/dist/src/coordination/shared/interfaces/ICoordinator.js +24 -0
  229. package/.claude-flow-novice/dist/src/coordination/shared/interfaces/ICoordinator.js.map +1 -0
  230. package/.claude-flow-novice/dist/src/coordination/shared/interfaces/index.js +7 -0
  231. package/.claude-flow-novice/dist/src/coordination/shared/interfaces/index.js.map +1 -0
  232. package/.claude-flow-novice/dist/src/coordination/shared/message-broker.js +920 -0
  233. package/.claude-flow-novice/dist/src/coordination/shared/message-broker.js.map +1 -0
  234. package/.claude-flow-novice/dist/src/coordination/shared/message.js +138 -0
  235. package/.claude-flow-novice/dist/src/coordination/shared/message.js.map +1 -0
  236. package/.claude-flow-novice/dist/src/coordination/shared/security/payload-validator.js +259 -0
  237. package/.claude-flow-novice/dist/src/coordination/shared/security/payload-validator.js.map +1 -0
  238. package/.claude-flow-novice/dist/src/coordination/shared/transparency/index.js +17 -0
  239. package/.claude-flow-novice/dist/src/coordination/shared/transparency/index.js.map +1 -0
  240. package/.claude-flow-novice/dist/src/coordination/shared/transparency/interfaces/transparency-system.js +19 -0
  241. package/.claude-flow-novice/dist/src/coordination/shared/transparency/interfaces/transparency-system.js.map +1 -0
  242. package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-integration.js +357 -0
  243. package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-integration.js.map +1 -0
  244. package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-system.js +679 -0
  245. package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-system.js.map +1 -0
  246. package/.claude-flow-novice/dist/src/coordination/shared/types/index.js +7 -0
  247. package/.claude-flow-novice/dist/src/coordination/shared/types/index.js.map +1 -0
  248. package/.claude-flow-novice/dist/src/coordination/shared/types/sdk.js +10 -0
  249. package/.claude-flow-novice/dist/src/coordination/shared/types/sdk.js.map +1 -0
  250. package/.claude-flow-novice/dist/src/feature-flags/core/FeatureFlagManager.js +52 -2
  251. package/.claude-flow-novice/dist/src/feature-flags/core/FeatureFlagManager.js.map +1 -1
  252. package/.claude-flow-novice/dist/src/mcp/mcp-server-novice.js +37 -2
  253. package/.claude-flow-novice/dist/src/mcp/session-manager.js +3 -1
  254. package/.claude-flow-novice/dist/src/mcp/session-manager.js.map +1 -1
  255. package/.claude-flow-novice/dist/src/providers/provider-manager.js +36 -3
  256. package/.claude-flow-novice/dist/src/providers/provider-manager.js.map +1 -1
  257. package/.claude-flow-novice/dist/src/utils/markdown-sanitizer.js +65 -41
  258. package/.claude-flow-novice/dist/src/utils/markdown-sanitizer.js.map +1 -1
  259. package/.claude-flow-novice/dist/src/web/api/server.js +1 -1
  260. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -1
  261. package/.claude-flow-novice/dist/src/workflows/progressive-rollout-manager.js +30 -0
  262. package/.claude-flow-novice/dist/src/workflows/progressive-rollout-manager.js.map +1 -1
  263. package/.claude-flow-novice/metrics.db-shm +0 -0
  264. package/.claude-flow-novice/metrics.db-wal +0 -0
  265. package/package.json +2 -2
  266. package/scripts/monitoring/alert-monitor.sh +220 -0
  267. package/scripts/monitoring/view-alerts.sh +307 -0
  268. package/scripts/test-zai-api.cjs +2 -2
  269. package/src/slash-commands/parse-epic.js +1 -1
@@ -0,0 +1,342 @@
1
+ /**
2
+ * Agent Coordination V2 - State Machine SDK Integration
3
+ *
4
+ * Integrates SessionManager with state machine lifecycle events.
5
+ * Provides auto-checkpoint on state transitions, event broadcasting,
6
+ * and message UUID tracking for recovery.
7
+ *
8
+ * @module coordination/v2/sdk/state-sdk-integration
9
+ */ import { EventEmitter } from 'node:events';
10
+ import { STATE_TRANSITIONS } from '../core/state-machine-config.js';
11
+ /**
12
+ * StateSDKIntegration - Connects state machine with SDK session management
13
+ *
14
+ * Features:
15
+ * - Auto-checkpoint creation on state transitions (<500ms budget)
16
+ * - Event broadcasting to all sessions (<50ms latency)
17
+ * - Message UUID tracking for checkpoint recovery
18
+ * - Zero failures in event listener system
19
+ */ export class StateSDKIntegration extends EventEmitter {
20
+ checkpointManager;
21
+ queryController;
22
+ config;
23
+ metrics;
24
+ sessions = new Map();
25
+ messageUUIDIndex = new Map();
26
+ lastCheckpointTime = new Map();
27
+ initialized = false;
28
+ constructor(checkpointManager, queryController, config = {}){
29
+ super();
30
+ this.checkpointManager = checkpointManager;
31
+ this.queryController = queryController;
32
+ this.config = {
33
+ checkpointTimeoutMs: config.checkpointTimeoutMs ?? 500,
34
+ eventBroadcastTimeoutMs: config.eventBroadcastTimeoutMs ?? 50,
35
+ enableAutoCheckpoint: config.enableAutoCheckpoint ?? true,
36
+ checkpointThrottleMs: config.checkpointThrottleMs ?? 100
37
+ };
38
+ this.metrics = this.initializeMetrics();
39
+ }
40
+ /**
41
+ * Initialize the integration system
42
+ */ async initialize() {
43
+ if (this.initialized) {
44
+ return;
45
+ }
46
+ // Initialize checkpoint manager
47
+ await this.checkpointManager.initialize();
48
+ // Initialize query controller
49
+ await this.queryController.initialize();
50
+ // Set up event listeners
51
+ this.setupEventListeners();
52
+ this.initialized = true;
53
+ console.log('✅ StateSDKIntegration initialized');
54
+ }
55
+ /**
56
+ * Handle state transition event from state machine
57
+ * Creates checkpoint, broadcasts event, tracks UUID
58
+ */ async onStateTransition(event) {
59
+ if (!this.initialized) {
60
+ throw new Error('StateSDKIntegration not initialized');
61
+ }
62
+ const startTime = performance.now();
63
+ try {
64
+ // Validate transition is allowed by canonical matrix
65
+ const validTransitions = STATE_TRANSITIONS[event.fromState];
66
+ if (!validTransitions?.includes(event.toState)) {
67
+ const error = new Error(`Invalid state transition: ${event.fromState} → ${event.toState}. ` + `Valid transitions from ${event.fromState}: ${validTransitions?.join(', ') || 'none'}`);
68
+ this.metrics.broadcastFailures++;
69
+ console.error('❌ State transition validation failed:', error.message);
70
+ this.emit('state:transition:error', {
71
+ event,
72
+ error
73
+ });
74
+ throw error;
75
+ }
76
+ // Get session for agent
77
+ const session = await this.getOrCreateSession(event.agentId);
78
+ // Create checkpoint before state change (if enabled and not throttled)
79
+ let checkpoint = null;
80
+ if (this.config.enableAutoCheckpoint && this.shouldCreateCheckpoint(event.agentId)) {
81
+ checkpoint = await this.createCheckpointForTransition(event, session);
82
+ }
83
+ // Broadcast state change to all sessions
84
+ const eventData = {
85
+ agentId: event.agentId,
86
+ sessionId: session.sessionId,
87
+ from: event.fromState,
88
+ to: event.toState,
89
+ checkpointUUID: checkpoint?.messageUUID,
90
+ checkpointId: checkpoint?.id,
91
+ timestamp: new Date(),
92
+ metadata: event.metadata
93
+ };
94
+ await this.broadcastStateChange(eventData);
95
+ // Track message UUID for recovery
96
+ if (checkpoint) {
97
+ await this.trackMessageUUID(event.agentId, checkpoint.messageUUID);
98
+ }
99
+ // Update metrics
100
+ this.metrics.totalStateTransitions++;
101
+ const totalTime = performance.now() - startTime;
102
+ // Verify performance budget
103
+ if (totalTime > this.config.checkpointTimeoutMs) {
104
+ console.warn(`⚠️ State transition processing exceeded budget: ${totalTime.toFixed(2)}ms (target: ${this.config.checkpointTimeoutMs}ms)`);
105
+ }
106
+ this.emit('state:transition:complete', eventData);
107
+ } catch (error) {
108
+ this.metrics.checkpointFailures++;
109
+ console.error('❌ State transition processing failed:', error);
110
+ this.emit('state:transition:error', {
111
+ event,
112
+ error
113
+ });
114
+ throw error;
115
+ }
116
+ }
117
+ /**
118
+ * Create checkpoint for state transition
119
+ */ async createCheckpointForTransition(event, session) {
120
+ const startTime = performance.now();
121
+ try {
122
+ // Generate message UUID for checkpoint
123
+ const messageUUID = this.generateMessageUUID(event.agentId, event.toState);
124
+ // Create state snapshot
125
+ const stateSnapshot = {
126
+ agentId: event.agentId,
127
+ sessionId: session.sessionId,
128
+ state: event.toState,
129
+ previousState: event.fromState,
130
+ transitionType: event.type,
131
+ timestamp: Date.now(),
132
+ metadata: event.metadata
133
+ };
134
+ // Create checkpoint via CheckpointManager
135
+ const checkpointId = await this.checkpointManager.createCheckpoint(session.sessionId, event.agentId, messageUUID, event.toState, stateSnapshot, {
136
+ reason: `State transition: ${event.fromState} -> ${event.toState}`,
137
+ autoCheckpoint: true,
138
+ context: event.metadata
139
+ });
140
+ const checkpoint = {
141
+ id: checkpointId,
142
+ sessionId: session.sessionId,
143
+ agentId: event.agentId,
144
+ messageUUID,
145
+ state: event.toState,
146
+ timestamp: new Date(),
147
+ metadata: {
148
+ reason: `State transition: ${event.fromState} -> ${event.toState}`,
149
+ autoCheckpoint: true,
150
+ context: event.metadata
151
+ }
152
+ };
153
+ // Update metrics
154
+ const checkpointTime = performance.now() - startTime;
155
+ this.metrics.totalCheckpointsCreated++;
156
+ this.metrics.averageCheckpointTimeMs = (this.metrics.averageCheckpointTimeMs * (this.metrics.totalCheckpointsCreated - 1) + checkpointTime) / this.metrics.totalCheckpointsCreated;
157
+ // Update throttle tracking
158
+ this.lastCheckpointTime.set(event.agentId, Date.now());
159
+ // Verify performance target
160
+ if (checkpointTime > this.config.checkpointTimeoutMs) {
161
+ console.warn(`⚠️ Checkpoint creation exceeded budget: ${checkpointTime.toFixed(2)}ms (target: ${this.config.checkpointTimeoutMs}ms)`);
162
+ }
163
+ return checkpoint;
164
+ } catch (error) {
165
+ this.metrics.checkpointFailures++;
166
+ console.error('❌ Checkpoint creation failed:', error);
167
+ throw error;
168
+ }
169
+ }
170
+ /**
171
+ * Broadcast state change event to all registered sessions
172
+ */ async broadcastStateChange(eventData) {
173
+ const startTime = performance.now();
174
+ try {
175
+ // Emit event to all listeners
176
+ this.emit('state_change', eventData);
177
+ // Broadcast via QueryController (if sessions are registered)
178
+ const activeSessions = this.queryController.getActiveSessions();
179
+ for (const session of activeSessions){
180
+ // Skip the session that triggered the event
181
+ if (session.agentId === eventData.agentId) {
182
+ continue;
183
+ }
184
+ // Update session metadata with latest state change
185
+ session.metadata.lastStateChange = eventData;
186
+ }
187
+ // Update metrics
188
+ const broadcastTime = performance.now() - startTime;
189
+ this.metrics.totalEventsBroadcast++;
190
+ this.metrics.averageEventBroadcastTimeMs = (this.metrics.averageEventBroadcastTimeMs * (this.metrics.totalEventsBroadcast - 1) + broadcastTime) / this.metrics.totalEventsBroadcast;
191
+ // Verify performance target
192
+ if (broadcastTime > this.config.eventBroadcastTimeoutMs) {
193
+ console.warn(`⚠️ Event broadcast exceeded latency target: ${broadcastTime.toFixed(2)}ms (target: ${this.config.eventBroadcastTimeoutMs}ms)`);
194
+ }
195
+ } catch (error) {
196
+ this.metrics.broadcastFailures++;
197
+ console.error('❌ Event broadcast failed:', error);
198
+ throw error;
199
+ }
200
+ }
201
+ /**
202
+ * Track message UUID for checkpoint recovery
203
+ */ async trackMessageUUID(agentId, messageUUID) {
204
+ this.messageUUIDIndex.set(messageUUID, agentId);
205
+ this.metrics.messageUUIDsTracked++;
206
+ // Store in session metadata
207
+ const session = this.sessions.get(agentId);
208
+ if (session) {
209
+ session.currentMessageUUID = messageUUID;
210
+ }
211
+ }
212
+ /**
213
+ * Resume session from message UUID checkpoint
214
+ */ async resumeSessionAt(messageUUID) {
215
+ const agentId = this.messageUUIDIndex.get(messageUUID);
216
+ if (!agentId) {
217
+ throw new Error(`No agent found for message UUID: ${messageUUID}`);
218
+ }
219
+ const session = this.sessions.get(agentId);
220
+ if (!session) {
221
+ throw new Error(`No session found for agent: ${agentId}`);
222
+ }
223
+ // Resume via QueryController
224
+ await this.queryController.resumeSessionAt(session.sessionId, messageUUID);
225
+ }
226
+ /**
227
+ * Get or create session for agent
228
+ */ async getOrCreateSession(agentId) {
229
+ let session = this.sessions.get(agentId);
230
+ if (!session) {
231
+ // Check if session exists in QueryController
232
+ const sessionId = `session_${agentId}_${Date.now()}`;
233
+ session = this.queryController.registerSession(agentId, sessionId);
234
+ this.sessions.set(agentId, session);
235
+ }
236
+ return session;
237
+ }
238
+ /**
239
+ * Check if checkpoint should be created (throttling)
240
+ */ shouldCreateCheckpoint(agentId) {
241
+ const lastTime = this.lastCheckpointTime.get(agentId);
242
+ if (!lastTime) {
243
+ return true;
244
+ }
245
+ const elapsed = Date.now() - lastTime;
246
+ return elapsed >= this.config.checkpointThrottleMs;
247
+ }
248
+ /**
249
+ * Generate message UUID for checkpoint
250
+ */ generateMessageUUID(agentId, state) {
251
+ const timestamp = Date.now();
252
+ const random = Math.random().toString(36).substring(2, 10);
253
+ return `msg_${agentId}_${state}_${timestamp}_${random}`;
254
+ }
255
+ /**
256
+ * Set up event listeners for error handling
257
+ */ setupEventListeners() {
258
+ // Query controller is an EventEmitter and can emit errors
259
+ this.queryController.on('error', (error)=>{
260
+ this.metrics.broadcastFailures++;
261
+ console.error('❌ QueryController error:', error);
262
+ this.emit('error', {
263
+ source: 'query-controller',
264
+ error
265
+ });
266
+ });
267
+ // Note: CheckpointManager is not an EventEmitter
268
+ // Error handling is done via try-catch in onStateTransition
269
+ }
270
+ /**
271
+ * Register session for state change notifications
272
+ */ registerSession(session) {
273
+ this.sessions.set(session.agentId, session);
274
+ }
275
+ /**
276
+ * Unregister session
277
+ */ unregisterSession(agentId) {
278
+ this.sessions.delete(agentId);
279
+ this.lastCheckpointTime.delete(agentId);
280
+ }
281
+ /**
282
+ * Get integration metrics
283
+ */ getMetrics() {
284
+ return {
285
+ ...this.metrics
286
+ };
287
+ }
288
+ /**
289
+ * Get checkpoint by message UUID
290
+ */ async getCheckpointByMessageUUID(messageUUID) {
291
+ const checkpoint = await this.checkpointManager.getCheckpointByMessageUUID(messageUUID);
292
+ if (!checkpoint) {
293
+ return null;
294
+ }
295
+ return {
296
+ id: checkpoint.id,
297
+ sessionId: checkpoint.sessionId,
298
+ agentId: checkpoint.agentId,
299
+ messageUUID: checkpoint.messageUUID,
300
+ state: checkpoint.state,
301
+ timestamp: checkpoint.timestamp,
302
+ metadata: checkpoint.metadata
303
+ };
304
+ }
305
+ /**
306
+ * Enable/disable auto-checkpoint
307
+ */ setAutoCheckpointEnabled(enabled) {
308
+ this.config.enableAutoCheckpoint = enabled;
309
+ console.log(`Auto-checkpoint ${enabled ? 'enabled' : 'disabled'}`);
310
+ }
311
+ /**
312
+ * Check if integration is ready
313
+ */ isReady() {
314
+ return this.initialized;
315
+ }
316
+ /**
317
+ * Cleanup resources
318
+ */ async cleanup() {
319
+ this.sessions.clear();
320
+ this.messageUUIDIndex.clear();
321
+ this.lastCheckpointTime.clear();
322
+ this.removeAllListeners();
323
+ this.initialized = false;
324
+ console.log('✅ StateSDKIntegration cleaned up');
325
+ }
326
+ /**
327
+ * Initialize metrics
328
+ */ initializeMetrics() {
329
+ return {
330
+ totalStateTransitions: 0,
331
+ totalCheckpointsCreated: 0,
332
+ totalEventsBroadcast: 0,
333
+ averageCheckpointTimeMs: 0,
334
+ averageEventBroadcastTimeMs: 0,
335
+ checkpointFailures: 0,
336
+ broadcastFailures: 0,
337
+ messageUUIDsTracked: 0
338
+ };
339
+ }
340
+ }
341
+
342
+ //# sourceMappingURL=state-sdk-integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../src/coordination/archives/v2-sdk-typescript/v2/sdk/state-sdk-integration.ts"],"names":["EventEmitter","STATE_TRANSITIONS","StateSDKIntegration","checkpointManager","queryController","config","metrics","sessions","Map","messageUUIDIndex","lastCheckpointTime","initialized","checkpointTimeoutMs","eventBroadcastTimeoutMs","enableAutoCheckpoint","checkpointThrottleMs","initializeMetrics","initialize","setupEventListeners","console","log","onStateTransition","event","Error","startTime","performance","now","validTransitions","fromState","includes","toState","error","join","broadcastFailures","message","emit","session","getOrCreateSession","agentId","checkpoint","shouldCreateCheckpoint","createCheckpointForTransition","eventData","sessionId","from","to","checkpointUUID","messageUUID","checkpointId","id","timestamp","Date","metadata","broadcastStateChange","trackMessageUUID","totalStateTransitions","totalTime","warn","toFixed","checkpointFailures","generateMessageUUID","stateSnapshot","state","previousState","transitionType","type","createCheckpoint","reason","autoCheckpoint","context","checkpointTime","totalCheckpointsCreated","averageCheckpointTimeMs","set","activeSessions","getActiveSessions","lastStateChange","broadcastTime","totalEventsBroadcast","averageEventBroadcastTimeMs","messageUUIDsTracked","get","currentMessageUUID","resumeSessionAt","registerSession","lastTime","elapsed","random","Math","toString","substring","on","source","unregisterSession","delete","getMetrics","getCheckpointByMessageUUID","setAutoCheckpointEnabled","enabled","isReady","cleanup","clear","removeAllListeners"],"mappings":"AAAA;;;;;;;;CAQC,GAED,SAASA,YAAY,QAAQ,cAAc;AAI3C,SAASC,iBAAiB,QAA2B,kCAAkC;AAiDvF;;;;;;;;CAQC,GACD,OAAO,MAAMC,4BAA4BF;IACtBG,kBAAqC;IACrCC,gBAAiC;IACjCC,OAA4C;IAErDC,QAAyB;IACzBC,WAAsC,IAAIC,MAAM;IAChDC,mBAAwC,IAAID,MAAM;IAClDE,qBAA0C,IAAIF,MAAM;IACpDG,cAAuB,MAAM;IAErC,YACER,iBAAoC,EACpCC,eAAgC,EAChCC,SAAoC,CAAC,CAAC,CACtC;QACA,KAAK;QAEL,IAAI,CAACF,iBAAiB,GAAGA;QACzB,IAAI,CAACC,eAAe,GAAGA;QAEvB,IAAI,CAACC,MAAM,GAAG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;QAEnBQ,QAAQC,GAAG,CAAC;IACd;IAEA;;GAEC,GACD,AAAQJ,oBAAqC;QAC3C,OAAO;YACLuC,uBAAuB;YACvBgB,yBAAyB;YACzBO,sBAAsB;YACtBN,yBAAyB;YACzBO,6BAA6B;YAC7BpB,oBAAoB;YACpB1B,mBAAmB;YACnB+C,qBAAqB;QACvB;IACF;AACF"}
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Payload Validator - SEC-INJ-001 Mitigation
3
+ *
4
+ * Validates and sanitizes message payloads to prevent:
5
+ * - Prototype pollution attacks
6
+ * - Code injection via eval/Function
7
+ * - Memory bombs (deeply nested objects)
8
+ * - Oversized payloads
9
+ *
10
+ * @module coordination/v2/security/payload-validator
11
+ */ /**
12
+ * Payload validation rule configuration.
13
+ */ /**
14
+ * Payload validation error.
15
+ */ export class PayloadValidationError extends Error {
16
+ constructor(message){
17
+ super(message);
18
+ this.name = 'PayloadValidationError';
19
+ }
20
+ }
21
+ /**
22
+ * Payload Validator Implementation.
23
+ *
24
+ * Provides comprehensive validation and sanitization of message payloads
25
+ * to prevent injection attacks and resource exhaustion.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const validator = new PayloadValidator({
30
+ * maxDepth: 5,
31
+ * maxSize: 1024 * 1024,
32
+ * forbiddenKeys: ['__proto__', 'constructor', 'prototype'],
33
+ * allowedTypes: ['string', 'number', 'boolean', 'object', 'array']
34
+ * });
35
+ *
36
+ * const result = validator.validate(userPayload);
37
+ * if (!result.valid) {
38
+ * throw new Error(`Validation failed: ${result.errors.join(', ')}`);
39
+ * }
40
+ *
41
+ * const sanitized = validator.sanitize(userPayload);
42
+ * ```
43
+ */ export class PayloadValidator {
44
+ rules;
45
+ /**
46
+ * Default validation rules (secure defaults).
47
+ */ static DEFAULT_RULES = {
48
+ maxDepth: 5,
49
+ maxSize: 1024 * 1024,
50
+ allowedTypes: [
51
+ 'string',
52
+ 'number',
53
+ 'boolean',
54
+ 'object',
55
+ 'array',
56
+ 'null'
57
+ ],
58
+ forbiddenKeys: [
59
+ '__proto__',
60
+ 'constructor',
61
+ 'prototype',
62
+ 'eval',
63
+ 'Function'
64
+ ]
65
+ };
66
+ /**
67
+ * Creates a new payload validator.
68
+ *
69
+ * @param rules - Validation rules (uses secure defaults if not provided)
70
+ */ constructor(rules){
71
+ this.rules = {
72
+ ...PayloadValidator.DEFAULT_RULES,
73
+ ...rules
74
+ };
75
+ }
76
+ /**
77
+ * Validates a payload against configured rules.
78
+ *
79
+ * @param payload - Payload to validate
80
+ * @returns Validation result with errors if any
81
+ */ validate(payload) {
82
+ const errors = [];
83
+ try {
84
+ // SEC-INJ-001-BYPASS: Check for prototype chain pollution BEFORE serialization
85
+ // Object literals with __proto__ can pollute the prototype chain before validation runs
86
+ if (typeof payload === 'object' && payload !== null) {
87
+ const proto = Object.getPrototypeOf(payload);
88
+ if (proto !== Object.prototype && proto !== null) {
89
+ errors.push(`Prototype pollution detected: object has modified prototype chain`);
90
+ }
91
+ }
92
+ // SEC-INJ-001: Check payload size
93
+ const serialized = JSON.stringify(payload);
94
+ const size = Buffer.byteLength(serialized, 'utf8');
95
+ if (size > this.rules.maxSize) {
96
+ errors.push(`Payload size ${size} bytes exceeds maximum ${this.rules.maxSize} bytes`);
97
+ }
98
+ // SEC-INJ-001: Check object depth
99
+ const depth = this.getObjectDepth(payload);
100
+ if (depth > this.rules.maxDepth) {
101
+ errors.push(`Payload depth ${depth} exceeds maximum depth ${this.rules.maxDepth}`);
102
+ }
103
+ // SEC-INJ-001: Check for forbidden keys (prototype pollution vectors)
104
+ const allKeys = this.getAllKeys(payload);
105
+ const foundForbidden = allKeys.filter((key)=>this.rules.forbiddenKeys.includes(key));
106
+ if (foundForbidden.length > 0) {
107
+ errors.push(`Forbidden keys detected: ${foundForbidden.join(', ')}`);
108
+ }
109
+ // SEC-INJ-001: Check for dangerous type patterns
110
+ const typeErrors = this.validateTypes(payload);
111
+ errors.push(...typeErrors);
112
+ return {
113
+ valid: errors.length === 0,
114
+ errors,
115
+ depth,
116
+ size
117
+ };
118
+ } catch (error) {
119
+ // Catch circular reference or serialization errors
120
+ return {
121
+ valid: false,
122
+ errors: [
123
+ `Validation error: ${error instanceof Error ? error.message : String(error)}`
124
+ ]
125
+ };
126
+ }
127
+ }
128
+ /**
129
+ * Sanitizes a payload by removing dangerous keys and normalizing structure.
130
+ *
131
+ * Creates a deep clone with prototype chain stripped to prevent pollution attacks.
132
+ *
133
+ * @param payload - Payload to sanitize
134
+ * @returns Sanitized payload (deep frozen)
135
+ */ sanitize(payload) {
136
+ if (payload === null || payload === undefined) {
137
+ return payload;
138
+ }
139
+ // SEC-INJ-001: JSON round-trip removes prototype chain and functions
140
+ const serialized = JSON.stringify(payload);
141
+ const parsed = JSON.parse(serialized);
142
+ // SEC-INJ-001: Remove forbidden keys recursively
143
+ const cleaned = this.removeForbiddenKeys(parsed);
144
+ // SEC-INJ-001: Deep freeze to prevent modification
145
+ return this.deepFreeze(cleaned);
146
+ }
147
+ /**
148
+ * Gets the maximum depth of an object.
149
+ *
150
+ * @param obj - Object to measure
151
+ * @param currentDepth - Current recursion depth (internal)
152
+ * @returns Maximum nesting depth
153
+ */ getObjectDepth(obj, currentDepth = 0) {
154
+ if (obj === null || typeof obj !== 'object') {
155
+ return currentDepth;
156
+ }
157
+ if (Array.isArray(obj)) {
158
+ if (obj.length === 0) return currentDepth + 1;
159
+ return Math.max(...obj.map((item)=>this.getObjectDepth(item, currentDepth + 1)));
160
+ }
161
+ const keys = Object.keys(obj);
162
+ if (keys.length === 0) return currentDepth + 1;
163
+ return Math.max(...keys.map((key)=>this.getObjectDepth(obj[key], currentDepth + 1)));
164
+ }
165
+ /**
166
+ * Extracts all keys from an object recursively.
167
+ *
168
+ * @param obj - Object to extract keys from
169
+ * @returns Array of all keys (including nested)
170
+ */ getAllKeys(obj) {
171
+ if (obj === null || typeof obj !== 'object') {
172
+ return [];
173
+ }
174
+ const keys = [];
175
+ if (Array.isArray(obj)) {
176
+ obj.forEach((item)=>{
177
+ keys.push(...this.getAllKeys(item));
178
+ });
179
+ } else {
180
+ // FIX SEC-INJ-001: Use getOwnPropertyNames + getOwnPropertySymbols
181
+ // to detect non-enumerable properties like __proto__, constructor
182
+ const propertyNames = Object.getOwnPropertyNames(obj);
183
+ const propertySymbols = Object.getOwnPropertySymbols(obj);
184
+ propertyNames.forEach((key)=>{
185
+ keys.push(key);
186
+ keys.push(...this.getAllKeys(obj[key]));
187
+ });
188
+ // Include symbol properties for comprehensive coverage
189
+ propertySymbols.forEach((sym)=>{
190
+ keys.push(sym.toString());
191
+ keys.push(...this.getAllKeys(obj[sym]));
192
+ });
193
+ }
194
+ return keys;
195
+ }
196
+ /**
197
+ * Validates payload types recursively.
198
+ *
199
+ * @param obj - Object to validate
200
+ * @returns Array of type validation errors
201
+ */ validateTypes(obj) {
202
+ const errors = [];
203
+ if (obj === null) {
204
+ return errors; // null is allowed
205
+ }
206
+ const type = Array.isArray(obj) ? 'array' : typeof obj;
207
+ if (!this.rules.allowedTypes.includes(type)) {
208
+ errors.push(`Type '${type}' not allowed in payload`);
209
+ return errors; // Don't recurse into invalid types
210
+ }
211
+ if (type === 'object' || type === 'array') {
212
+ const values = Array.isArray(obj) ? obj : Object.values(obj);
213
+ values.forEach((value)=>{
214
+ errors.push(...this.validateTypes(value));
215
+ });
216
+ }
217
+ return errors;
218
+ }
219
+ /**
220
+ * Removes forbidden keys from object recursively.
221
+ *
222
+ * @param obj - Object to clean
223
+ * @returns Cleaned object
224
+ */ removeForbiddenKeys(obj) {
225
+ if (obj === null || typeof obj !== 'object') {
226
+ return obj;
227
+ }
228
+ if (Array.isArray(obj)) {
229
+ return obj.map((item)=>this.removeForbiddenKeys(item));
230
+ }
231
+ const cleaned = {};
232
+ Object.keys(obj).forEach((key)=>{
233
+ if (!this.rules.forbiddenKeys.includes(key)) {
234
+ cleaned[key] = this.removeForbiddenKeys(obj[key]);
235
+ }
236
+ });
237
+ return cleaned;
238
+ }
239
+ /**
240
+ * Deep freezes an object to prevent modification.
241
+ *
242
+ * @param obj - Object to freeze
243
+ * @returns Frozen object
244
+ */ deepFreeze(obj) {
245
+ if (obj === null || typeof obj !== 'object') {
246
+ return obj;
247
+ }
248
+ if (Array.isArray(obj)) {
249
+ obj.forEach((item)=>this.deepFreeze(item));
250
+ } else {
251
+ Object.keys(obj).forEach((key)=>{
252
+ this.deepFreeze(obj[key]);
253
+ });
254
+ }
255
+ return Object.freeze(obj);
256
+ }
257
+ }
258
+
259
+ //# sourceMappingURL=payload-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../src/coordination/archives/v2-sdk-typescript/v2/security/payload-validator.ts"],"names":["PayloadValidationError","Error","message","name","PayloadValidator","rules","DEFAULT_RULES","maxDepth","maxSize","allowedTypes","forbiddenKeys","validate","payload","errors","proto","Object","getPrototypeOf","prototype","push","serialized","JSON","stringify","size","Buffer","byteLength","depth","getObjectDepth","allKeys","getAllKeys","foundForbidden","filter","key","includes","length","join","typeErrors","validateTypes","valid","error","String","sanitize","undefined","parsed","parse","cleaned","removeForbiddenKeys","deepFreeze","obj","currentDepth","Array","isArray","Math","max","map","item","keys","forEach","propertyNames","getOwnPropertyNames","propertySymbols","getOwnPropertySymbols","sym","toString","type","values","value","freeze"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GAgCD;;CAEC,GACD,OAAO,MAAMA,+BAA+BC;IAC1C,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA;QACN,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,MAAMC;IACHC,MAA6B;IAErC;;GAEC,GACD,OAAOC,gBAAuC;QAC5CC,UAAU;QACVC,SAAS,OAAO;QAChBC,cAAc;YAAC;YAAU;YAAU;YAAW;YAAU;YAAS;SAAO;QACxEC,eAAe;YAAC;YAAa;YAAe;YAAa;YAAQ;SAAW;IAC9E,EAAE;IAEF;;;;GAIC,GACD,YAAYL,K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