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,669 @@
1
+ /**
2
+ * Agent Coordination V2 - Resource Manager
3
+ *
4
+ * Manages resource allocation and deadlock prevention through:
5
+ * - Resource allocation tracking with <5% overhead
6
+ * - Circular wait detection (Wait-For-Graph)
7
+ * - Resource ordering enforcement
8
+ * - Timeout-based automatic resource release
9
+ * - Thread-safe concurrent access control
10
+ *
11
+ * Performance targets:
12
+ * - Allocation tracking overhead: <5%
13
+ * - Lock acquisition: <10ms (p95)
14
+ * - Deadlock detection: <500ms (p95)
15
+ *
16
+ * @module coordination/v2/deadlock/resource-manager
17
+ */ import { EventEmitter } from 'node:events';
18
+ import { Logger } from '../../../core/logger.js';
19
+ /**
20
+ * Resource types that can be allocated to agents
21
+ */ export var ResourceType = /*#__PURE__*/ function(ResourceType) {
22
+ /** Memory/token budget allocation */ ResourceType["MEMORY"] = "memory";
23
+ /** File access lock */ ResourceType["FILE"] = "file";
24
+ /** API rate limit quota */ ResourceType["API_QUOTA"] = "api_quota";
25
+ /** Database connection */ ResourceType["DATABASE"] = "database";
26
+ /** Network socket */ ResourceType["NETWORK"] = "network";
27
+ /** Compute/CPU allocation */ ResourceType["COMPUTE"] = "compute";
28
+ /** Generic custom resource */ ResourceType["CUSTOM"] = "custom";
29
+ return ResourceType;
30
+ }({});
31
+ /**
32
+ * Resource Manager
33
+ *
34
+ * Thread-safe resource allocation manager with deadlock prevention.
35
+ * Tracks resource ownership, detects circular waits, and enforces
36
+ * resource ordering to prevent deadlocks.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const manager = new ResourceManager(config);
41
+ * await manager.initialize();
42
+ *
43
+ * // Acquire resource
44
+ * await manager.acquire('agent-1', 'file:/path/to/file', 10);
45
+ *
46
+ * // Release resource
47
+ * await manager.release('agent-1', 'file:/path/to/file');
48
+ *
49
+ * // Check for deadlocks
50
+ * const cycles = manager.detectCircularWaits();
51
+ * if (cycles.length > 0) {
52
+ * console.log('Deadlock detected:', cycles);
53
+ * }
54
+ * ```
55
+ */ export class ResourceManager extends EventEmitter {
56
+ logger;
57
+ config;
58
+ /** Active resource allocations: resourceId -> allocation */ allocations = new Map();
59
+ /** Resource wait queues: resourceId -> queue of requests */ waitQueues = new Map();
60
+ /** Agent resource holdings: agentId -> Set of resourceIds */ agentResources = new Map();
61
+ /** Wait-for graph edges for deadlock detection */ waitForGraph = new Map();
62
+ /** Resource ordering for deadlock prevention (resourceId -> order number) */ resourceOrder = new Map();
63
+ nextOrderNumber = 0;
64
+ /** Performance tracking */ overheadSamples = [];
65
+ MAX_SAMPLES = 1000;
66
+ /** Metrics */ metrics = {
67
+ totalAllocations: 0,
68
+ activeAllocations: 0,
69
+ totalRequests: 0,
70
+ pendingRequests: 0,
71
+ deadlocksDetected: 0,
72
+ timeoutReleases: 0,
73
+ averageOverheadMs: 0,
74
+ p95OverheadMs: 0,
75
+ allocationsByType: new Map()
76
+ };
77
+ /** Cleanup timers */ cleanupTimer;
78
+ deadlockCheckTimer;
79
+ /** Thread safety lock (using mutex pattern) */ operationLock = Promise.resolve();
80
+ constructor(config = {}){
81
+ super();
82
+ this.logger = new Logger({
83
+ level: 'info',
84
+ format: 'text',
85
+ destination: 'console'
86
+ }, {
87
+ namespace: 'ResourceManager'
88
+ });
89
+ this.config = {
90
+ defaultTimeoutMs: config.defaultTimeoutMs ?? 30000,
91
+ maxResourcesPerAgent: config.maxResourcesPerAgent ?? 100,
92
+ enableDeadlockDetection: config.enableDeadlockDetection ?? true,
93
+ deadlockCheckIntervalMs: config.deadlockCheckIntervalMs ?? 5000,
94
+ enableResourceOrdering: config.enableResourceOrdering ?? true,
95
+ cleanupIntervalMs: config.cleanupIntervalMs ?? 10000
96
+ };
97
+ }
98
+ /**
99
+ * Initialize the resource manager
100
+ */ async initialize() {
101
+ this.logger.info('Initializing ResourceManager', {
102
+ config: this.config
103
+ });
104
+ // Start cleanup timer
105
+ this.cleanupTimer = setInterval(()=>{
106
+ this.cleanup().catch((err)=>{
107
+ this.logger.error('Cleanup failed', err);
108
+ });
109
+ }, this.config.cleanupIntervalMs);
110
+ // Start deadlock detection timer
111
+ if (this.config.enableDeadlockDetection) {
112
+ this.deadlockCheckTimer = setInterval(()=>{
113
+ this.checkForDeadlocks().catch((err)=>{
114
+ this.logger.error('Deadlock check failed', err);
115
+ });
116
+ }, this.config.deadlockCheckIntervalMs);
117
+ }
118
+ this.emit('initialized');
119
+ }
120
+ /**
121
+ * Shutdown the resource manager
122
+ */ async shutdown() {
123
+ this.logger.info('Shutting down ResourceManager');
124
+ // Clear timers
125
+ if (this.cleanupTimer) {
126
+ clearInterval(this.cleanupTimer);
127
+ this.cleanupTimer = undefined;
128
+ }
129
+ if (this.deadlockCheckTimer) {
130
+ clearInterval(this.deadlockCheckTimer);
131
+ this.deadlockCheckTimer = undefined;
132
+ }
133
+ // Release all resources
134
+ await this.withLock(async ()=>{
135
+ const allAllocations = Array.from(this.allocations.entries());
136
+ for (const [resourceId, allocation] of allAllocations){
137
+ await this.releaseInternal(allocation.holderId, resourceId);
138
+ }
139
+ this.allocations.clear();
140
+ this.waitQueues.clear();
141
+ this.agentResources.clear();
142
+ this.waitForGraph.clear();
143
+ });
144
+ this.emit('shutdown');
145
+ }
146
+ /**
147
+ * Acquire a resource for an agent
148
+ *
149
+ * @param agentId - Agent requesting the resource
150
+ * @param resourceId - Resource to acquire
151
+ * @param priority - Request priority (higher = more urgent)
152
+ * @param timeoutMs - Acquisition timeout (optional, uses default if not specified)
153
+ * @returns Promise that resolves when resource is acquired
154
+ * @throws Error if acquisition times out or fails
155
+ */ async acquire(agentId, resourceId, priority = 0, timeoutMs) {
156
+ const startTime = performance.now();
157
+ const timeout = timeoutMs ?? this.config.defaultTimeoutMs;
158
+ const request = {
159
+ agentId,
160
+ resourceId,
161
+ priority,
162
+ timestamp: new Date(),
163
+ enqueuedAt: Date.now(),
164
+ timeoutMs: timeout
165
+ };
166
+ this.metrics.totalRequests++;
167
+ try {
168
+ await this.withLock(async ()=>{
169
+ // Check if agent already holds this resource
170
+ if (this.allocations.get(resourceId)?.holderId === agentId) {
171
+ this.logger.debug('Agent already holds resource', {
172
+ agentId,
173
+ resourceId
174
+ });
175
+ return;
176
+ }
177
+ // Check resource limits
178
+ const agentResourceCount = this.agentResources.get(agentId)?.size ?? 0;
179
+ if (agentResourceCount >= this.config.maxResourcesPerAgent) {
180
+ throw new Error(`Agent ${agentId} has reached maximum resource limit (${this.config.maxResourcesPerAgent})`);
181
+ }
182
+ // Check resource ordering if enabled
183
+ if (this.config.enableResourceOrdering) {
184
+ this.enforceResourceOrdering(agentId, resourceId);
185
+ }
186
+ // Try to allocate immediately
187
+ if (!this.allocations.has(resourceId)) {
188
+ await this.allocateResource(agentId, resourceId, priority);
189
+ return;
190
+ }
191
+ // Resource is held, add to wait queue
192
+ await this.addToWaitQueue(request);
193
+ });
194
+ // Wait for resource to become available
195
+ await this.waitForResource(agentId, resourceId, timeout);
196
+ // Track overhead
197
+ const overhead = performance.now() - startTime;
198
+ this.trackOverhead(overhead);
199
+ this.logger.debug('Resource acquired', {
200
+ agentId,
201
+ resourceId,
202
+ overheadMs: overhead.toFixed(2)
203
+ });
204
+ } catch (error) {
205
+ this.logger.error('Resource acquisition failed', {
206
+ agentId,
207
+ resourceId,
208
+ error: error instanceof Error ? error.message : String(error)
209
+ });
210
+ throw error;
211
+ }
212
+ }
213
+ /**
214
+ * Release a resource held by an agent
215
+ *
216
+ * @param agentId - Agent releasing the resource
217
+ * @param resourceId - Resource to release
218
+ */ async release(agentId, resourceId) {
219
+ await this.withLock(async ()=>{
220
+ await this.releaseInternal(agentId, resourceId);
221
+ });
222
+ }
223
+ /**
224
+ * Release all resources held by an agent
225
+ *
226
+ * @param agentId - Agent ID
227
+ */ async releaseAll(agentId) {
228
+ await this.withLock(async ()=>{
229
+ const resources = this.agentResources.get(agentId);
230
+ if (!resources) {
231
+ return;
232
+ }
233
+ this.logger.info('Releasing all resources for agent', {
234
+ agentId,
235
+ resourceCount: resources.size
236
+ });
237
+ // Release all resources
238
+ const releases = Array.from(resources).map((resourceId)=>this.releaseInternal(agentId, resourceId));
239
+ await Promise.all(releases);
240
+ });
241
+ }
242
+ /**
243
+ * Get current resource allocations
244
+ *
245
+ * @returns Map of resourceId -> allocation
246
+ */ getAllocations() {
247
+ return new Map(this.allocations);
248
+ }
249
+ /**
250
+ * Get resources held by a specific agent
251
+ *
252
+ * @param agentId - Agent ID
253
+ * @returns Set of resource IDs held by the agent
254
+ */ getAgentResources(agentId) {
255
+ return new Set(this.agentResources.get(agentId) ?? []);
256
+ }
257
+ /**
258
+ * Detect circular waits in the wait-for graph
259
+ *
260
+ * @returns Array of detected circular wait cycles
261
+ */ detectCircularWaits() {
262
+ const cycles = [];
263
+ const visited = new Set();
264
+ const recursionStack = new Set();
265
+ const path = [];
266
+ // DFS-based cycle detection
267
+ const detectCycle = (agentId)=>{
268
+ visited.add(agentId);
269
+ recursionStack.add(agentId);
270
+ path.push(agentId);
271
+ const edges = this.waitForGraph.get(agentId) ?? [];
272
+ for (const edge of edges){
273
+ if (!visited.has(edge.holder)) {
274
+ if (detectCycle(edge.holder)) {
275
+ return true;
276
+ }
277
+ } else if (recursionStack.has(edge.holder)) {
278
+ // Cycle detected
279
+ const cycleStartIndex = path.indexOf(edge.holder);
280
+ const cycleAgents = path.slice(cycleStartIndex);
281
+ const cycleResources = edges.filter((e)=>cycleAgents.includes(e.holder)).map((e)=>e.resourceId);
282
+ cycles.push({
283
+ agents: cycleAgents,
284
+ resources: Array.from(new Set(cycleResources)),
285
+ detectedAt: new Date(),
286
+ path: [
287
+ ...path,
288
+ edge.holder
289
+ ]
290
+ });
291
+ return true;
292
+ }
293
+ }
294
+ path.pop();
295
+ recursionStack.delete(agentId);
296
+ return false;
297
+ };
298
+ // Check all agents
299
+ const allAgents = Array.from(this.waitForGraph.keys());
300
+ for (const agentId of allAgents){
301
+ if (!visited.has(agentId)) {
302
+ detectCycle(agentId);
303
+ }
304
+ }
305
+ if (cycles.length > 0) {
306
+ this.metrics.deadlocksDetected += cycles.length;
307
+ this.logger.warn('Circular wait cycles detected', {
308
+ count: cycles.length,
309
+ cycles: cycles.map((c)=>({
310
+ agents: c.agents,
311
+ resources: c.resources
312
+ }))
313
+ });
314
+ this.emit('deadlock-detected', {
315
+ cycles
316
+ });
317
+ }
318
+ return cycles;
319
+ }
320
+ /**
321
+ * Get current metrics
322
+ *
323
+ * @returns Current resource manager metrics
324
+ */ getMetrics() {
325
+ // Update current state
326
+ this.metrics.activeAllocations = this.allocations.size;
327
+ this.metrics.pendingRequests = Array.from(this.waitQueues.values()).reduce((sum, queue)=>sum + queue.length, 0);
328
+ // Calculate overhead percentiles
329
+ if (this.overheadSamples.length > 0) {
330
+ const sorted = [
331
+ ...this.overheadSamples
332
+ ].sort((a, b)=>a - b);
333
+ this.metrics.averageOverheadMs = sorted.reduce((sum, val)=>sum + val, 0) / sorted.length;
334
+ const p95Index = Math.floor(sorted.length * 0.95);
335
+ this.metrics.p95OverheadMs = sorted[p95Index] ?? 0;
336
+ }
337
+ return {
338
+ ...this.metrics
339
+ };
340
+ }
341
+ /**
342
+ * Get health status
343
+ */ async getHealthStatus() {
344
+ const metrics = this.getMetrics();
345
+ const cycles = this.detectCircularWaits();
346
+ return {
347
+ healthy: cycles.length === 0,
348
+ error: cycles.length > 0 ? `${cycles.length} deadlocks detected` : undefined,
349
+ metrics: {
350
+ activeAllocations: metrics.activeAllocations,
351
+ pendingRequests: metrics.pendingRequests,
352
+ deadlocksDetected: metrics.deadlocksDetected,
353
+ overheadPercentage: (metrics.averageOverheadMs / 100 * 100).toFixed(2)
354
+ }
355
+ };
356
+ }
357
+ // ==================== PRIVATE METHODS ====================
358
+ /**
359
+ * Thread-safe operation wrapper
360
+ */ async withLock(operation) {
361
+ // Chain operations to ensure serial execution
362
+ const currentLock = this.operationLock;
363
+ let resolveLock;
364
+ this.operationLock = new Promise((resolve)=>{
365
+ resolveLock = resolve;
366
+ });
367
+ try {
368
+ await currentLock;
369
+ return await operation();
370
+ } finally{
371
+ resolveLock();
372
+ }
373
+ }
374
+ /**
375
+ * Internal resource allocation (assumes lock is held)
376
+ */ async allocateResource(agentId, resourceId, priority) {
377
+ // Get or assign resource order
378
+ if (!this.resourceOrder.has(resourceId)) {
379
+ this.resourceOrder.set(resourceId, this.nextOrderNumber++);
380
+ }
381
+ // Determine resource type from ID
382
+ const type = this.getResourceType(resourceId);
383
+ // Create allocation
384
+ const allocation = {
385
+ resourceId,
386
+ type,
387
+ holderId: agentId,
388
+ allocatedAt: new Date(),
389
+ priority
390
+ };
391
+ this.allocations.set(resourceId, allocation);
392
+ // Track agent resources
393
+ if (!this.agentResources.has(agentId)) {
394
+ this.agentResources.set(agentId, new Set());
395
+ }
396
+ this.agentResources.get(agentId).add(resourceId);
397
+ // Update metrics
398
+ this.metrics.totalAllocations++;
399
+ const currentCount = this.metrics.allocationsByType.get(type) ?? 0;
400
+ this.metrics.allocationsByType.set(type, currentCount + 1);
401
+ // Remove from wait graph
402
+ this.removeFromWaitGraph(agentId, resourceId);
403
+ this.logger.debug('Resource allocated', {
404
+ agentId,
405
+ resourceId,
406
+ type,
407
+ priority
408
+ });
409
+ this.emit('resource-acquired', {
410
+ agentId,
411
+ resourceId,
412
+ allocation
413
+ });
414
+ }
415
+ /**
416
+ * Internal resource release (assumes lock is held)
417
+ */ async releaseInternal(agentId, resourceId) {
418
+ const allocation = this.allocations.get(resourceId);
419
+ if (!allocation) {
420
+ this.logger.debug('Resource not allocated', {
421
+ agentId,
422
+ resourceId
423
+ });
424
+ return;
425
+ }
426
+ if (allocation.holderId !== agentId) {
427
+ this.logger.warn('Agent does not hold resource', {
428
+ agentId,
429
+ resourceId,
430
+ actualHolder: allocation.holderId
431
+ });
432
+ return;
433
+ }
434
+ // Remove allocation
435
+ this.allocations.delete(resourceId);
436
+ this.agentResources.get(agentId)?.delete(resourceId);
437
+ // Update metrics
438
+ const type = allocation.type;
439
+ const currentCount = this.metrics.allocationsByType.get(type) ?? 0;
440
+ this.metrics.allocationsByType.set(type, Math.max(0, currentCount - 1));
441
+ this.logger.debug('Resource released', {
442
+ agentId,
443
+ resourceId
444
+ });
445
+ this.emit('resource-released', {
446
+ agentId,
447
+ resourceId
448
+ });
449
+ // Process wait queue
450
+ await this.processWaitQueue(resourceId);
451
+ }
452
+ /**
453
+ * Add request to wait queue
454
+ */ async addToWaitQueue(request) {
455
+ if (!this.waitQueues.has(request.resourceId)) {
456
+ this.waitQueues.set(request.resourceId, []);
457
+ }
458
+ const queue = this.waitQueues.get(request.resourceId);
459
+ queue.push(request);
460
+ // Sort by effective priority (base priority + age-based boost)
461
+ // This prevents starvation: low-priority agents eventually get highest priority
462
+ this.sortWaitQueue(queue);
463
+ // Update wait-for graph
464
+ const allocation = this.allocations.get(request.resourceId);
465
+ if (allocation) {
466
+ this.addToWaitGraph(request.agentId, allocation.holderId, request.resourceId);
467
+ }
468
+ this.logger.debug('Added to wait queue', {
469
+ agentId: request.agentId,
470
+ resourceId: request.resourceId,
471
+ queueLength: queue.length
472
+ });
473
+ }
474
+ /**
475
+ * Sort wait queue by effective priority with age-based boost
476
+ * Prevents starvation by increasing priority as requests age
477
+ */ sortWaitQueue(queue) {
478
+ const now = Date.now();
479
+ queue.sort((a, b)=>{
480
+ // Calculate age in seconds
481
+ const ageA = (now - a.enqueuedAt) / 1000;
482
+ const ageB = (now - b.enqueuedAt) / 1000;
483
+ // Effective priority = base priority + age boost
484
+ // Age boost: 1 priority point per second of waiting
485
+ // This ensures even low-priority agents eventually get served
486
+ const effectivePriorityA = a.priority + ageA;
487
+ const effectivePriorityB = b.priority + ageB;
488
+ return effectivePriorityB - effectivePriorityA;
489
+ });
490
+ }
491
+ /**
492
+ * Wait for resource to become available
493
+ */ async waitForResource(agentId, resourceId, timeoutMs) {
494
+ const startTime = Date.now();
495
+ return new Promise((resolve, reject)=>{
496
+ const checkInterval = setInterval(()=>{
497
+ const allocation = this.allocations.get(resourceId);
498
+ // Check if we now hold the resource
499
+ if (allocation?.holderId === agentId) {
500
+ clearInterval(checkInterval);
501
+ resolve();
502
+ return;
503
+ }
504
+ // Check if we're still in the queue
505
+ const queue = this.waitQueues.get(resourceId);
506
+ const stillWaiting = queue?.some((req)=>req.agentId === agentId);
507
+ if (!stillWaiting) {
508
+ clearInterval(checkInterval);
509
+ reject(new Error('Request removed from wait queue'));
510
+ return;
511
+ }
512
+ // Check timeout
513
+ if (Date.now() - startTime > timeoutMs) {
514
+ clearInterval(checkInterval);
515
+ // Remove from queue
516
+ const index = queue?.findIndex((req)=>req.agentId === agentId) ?? -1;
517
+ if (index !== -1) {
518
+ queue?.splice(index, 1);
519
+ }
520
+ this.removeFromWaitGraph(agentId, resourceId);
521
+ reject(new Error(`Resource acquisition timeout: ${resourceId}`));
522
+ }
523
+ }, 100);
524
+ });
525
+ }
526
+ /**
527
+ * Process wait queue for a resource
528
+ */ async processWaitQueue(resourceId) {
529
+ const queue = this.waitQueues.get(resourceId);
530
+ if (!queue || queue.length === 0) {
531
+ return;
532
+ }
533
+ // Re-sort queue to account for aging changes since last sort
534
+ // This ensures the most deserving agent (considering age) gets the resource
535
+ this.sortWaitQueue(queue);
536
+ // Allocate to next in queue (highest effective priority)
537
+ const nextRequest = queue.shift();
538
+ await this.allocateResource(nextRequest.agentId, resourceId, nextRequest.priority);
539
+ // Clean up empty queue
540
+ if (queue.length === 0) {
541
+ this.waitQueues.delete(resourceId);
542
+ }
543
+ }
544
+ /**
545
+ * Enforce resource ordering to prevent circular waits
546
+ */ enforceResourceOrdering(agentId, resourceId) {
547
+ const agentResources = this.agentResources.get(agentId);
548
+ if (!agentResources || agentResources.size === 0) {
549
+ return;
550
+ }
551
+ const requestedOrder = this.resourceOrder.get(resourceId) ?? this.nextOrderNumber;
552
+ // Check if agent holds any resource with higher order
553
+ const heldResources = Array.from(agentResources);
554
+ for (const heldResourceId of heldResources){
555
+ const heldOrder = this.resourceOrder.get(heldResourceId) ?? 0;
556
+ if (heldOrder > requestedOrder) {
557
+ throw new Error(`Resource ordering violation: agent ${agentId} holds ${heldResourceId} (order ${heldOrder}) but requests ${resourceId} (order ${requestedOrder})`);
558
+ }
559
+ }
560
+ }
561
+ /**
562
+ * Add edge to wait-for graph
563
+ */ addToWaitGraph(waiter, holder, resourceId) {
564
+ if (!this.waitForGraph.has(waiter)) {
565
+ this.waitForGraph.set(waiter, []);
566
+ }
567
+ const edges = this.waitForGraph.get(waiter);
568
+ const existing = edges.find((e)=>e.holder === holder && e.resourceId === resourceId);
569
+ if (!existing) {
570
+ edges.push({
571
+ waiter,
572
+ holder,
573
+ resourceId,
574
+ waitingSince: new Date()
575
+ });
576
+ }
577
+ }
578
+ /**
579
+ * Remove edge from wait-for graph
580
+ */ removeFromWaitGraph(waiter, resourceId) {
581
+ const edges = this.waitForGraph.get(waiter);
582
+ if (!edges) {
583
+ return;
584
+ }
585
+ const filtered = edges.filter((e)=>e.resourceId !== resourceId);
586
+ if (filtered.length === 0) {
587
+ this.waitForGraph.delete(waiter);
588
+ } else {
589
+ this.waitForGraph.set(waiter, filtered);
590
+ }
591
+ }
592
+ /**
593
+ * Cleanup expired requests and stale locks
594
+ */ async cleanup() {
595
+ await this.withLock(async ()=>{
596
+ const now = Date.now();
597
+ // Clean up expired wait queue requests
598
+ const allQueues = Array.from(this.waitQueues.entries());
599
+ for (const [resourceId, queue] of allQueues){
600
+ const filtered = queue.filter((req)=>{
601
+ const age = now - req.timestamp.getTime();
602
+ if (age > req.timeoutMs) {
603
+ this.logger.warn('Removing expired wait request', {
604
+ agentId: req.agentId,
605
+ resourceId,
606
+ ageMs: age
607
+ });
608
+ this.removeFromWaitGraph(req.agentId, resourceId);
609
+ return false;
610
+ }
611
+ return true;
612
+ });
613
+ if (filtered.length === 0) {
614
+ this.waitQueues.delete(resourceId);
615
+ } else {
616
+ this.waitQueues.set(resourceId, filtered);
617
+ }
618
+ }
619
+ // Clean up stale locks (held longer than 2x default timeout)
620
+ const staleThreshold = this.config.defaultTimeoutMs * 2;
621
+ const allAllocations = Array.from(this.allocations.entries());
622
+ for (const [resourceId, allocation] of allAllocations){
623
+ const age = now - allocation.allocatedAt.getTime();
624
+ if (age > staleThreshold) {
625
+ this.logger.warn('Force releasing stale lock', {
626
+ resourceId,
627
+ agentId: allocation.holderId,
628
+ ageMs: age
629
+ });
630
+ this.metrics.timeoutReleases++;
631
+ await this.releaseInternal(allocation.holderId, resourceId);
632
+ }
633
+ }
634
+ });
635
+ }
636
+ /**
637
+ * Periodic deadlock detection
638
+ */ async checkForDeadlocks() {
639
+ const cycles = this.detectCircularWaits();
640
+ if (cycles.length > 0) {
641
+ this.logger.error('Deadlocks detected during periodic check', {
642
+ count: cycles.length,
643
+ cycles
644
+ });
645
+ }
646
+ }
647
+ /**
648
+ * Determine resource type from resource ID
649
+ */ getResourceType(resourceId) {
650
+ if (resourceId.startsWith('file:')) return "file";
651
+ if (resourceId.startsWith('memory:')) return "memory";
652
+ if (resourceId.startsWith('api:')) return "api_quota";
653
+ if (resourceId.startsWith('db:')) return "database";
654
+ if (resourceId.startsWith('net:')) return "network";
655
+ if (resourceId.startsWith('cpu:')) return "compute";
656
+ return "custom";
657
+ }
658
+ /**
659
+ * Track overhead sample for metrics
660
+ */ trackOverhead(overheadMs) {
661
+ this.overheadSamples.push(overheadMs);
662
+ // Keep only last N samples
663
+ if (this.overheadSamples.length > this.MAX_SAMPLES) {
664
+ this.overheadSamples.shift();
665
+ }
666
+ }
667
+ }
668
+
669
+ //# sourceMappingURL=resource-manager.js.map