claude-flow-novice 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/.claude/agents/cfn-loop/product-owner.md +54 -4
  2. package/.claude/commands/cfn-claude-sync.md +303 -0
  3. package/.claude/commands/cfn-loop-epic.md +290 -0
  4. package/.claude/commands/cfn-loop-single.md +168 -0
  5. package/.claude/commands/cfn-loop-sprints.md +384 -0
  6. package/.claude/commands/cfn-loop.md +180 -0
  7. package/.claude/commands/metrics-summary.md +58 -0
  8. package/.claude/commands/parse-epic.md +357 -0
  9. package/.claude/settings.json +4 -4
  10. package/.claude/settings.local.json +9 -2
  11. package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
  12. package/.claude-flow-novice/dist/mcp/server.js +21 -2
  13. package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
  14. package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
  16. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
  17. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
  18. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
  19. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  20. package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
  21. package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
  22. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
  23. package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
  24. package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
  25. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
  26. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
  27. package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
  28. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
  29. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
  30. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
  31. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
  32. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
  33. package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
  34. package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
  35. package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
  36. package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
  37. package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
  38. package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
  39. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
  40. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
  41. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
  42. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
  43. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
  44. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  45. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
  46. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  47. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
  48. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
  49. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
  50. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  51. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
  52. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
  53. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
  54. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
  55. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
  56. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  57. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
  58. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
  59. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
  60. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
  61. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
  62. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
  63. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
  64. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
  65. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
  66. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
  67. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
  68. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
  69. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
  70. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
  71. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
  72. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
  73. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
  74. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
  75. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
  76. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
  77. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
  78. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
  79. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
  80. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
  81. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
  82. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
  83. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
  84. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
  85. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
  86. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
  87. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
  88. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
  89. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
  90. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
  91. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
  92. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
  93. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
  94. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
  95. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
  96. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
  97. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
  98. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
  99. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
  100. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
  101. package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
  102. package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
  103. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
  104. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
  105. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
  106. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
  107. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
  108. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  109. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
  110. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
  111. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
  112. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
  113. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
  114. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
  115. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
  116. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
  117. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
  118. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
  119. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
  120. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
  121. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
  122. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
  123. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
  124. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
  125. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
  126. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
  127. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
  128. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
  129. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
  130. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
  131. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
  132. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
  133. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
  134. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
  135. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
  136. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
  137. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
  138. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
  139. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
  140. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
  141. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
  142. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
  143. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
  144. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
  145. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
  146. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
  147. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
  148. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
  149. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
  150. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
  151. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
  152. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
  153. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
  154. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
  155. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
  156. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
  157. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
  158. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
  159. package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
  160. package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
  161. package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
  162. package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
  163. package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
  164. package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
  165. package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
  166. package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
  167. package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
  168. package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
  169. package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
  170. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  171. package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
  172. package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
  173. package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
  174. package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
  175. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
  176. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
  177. package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
  178. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
  179. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
  180. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
  181. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
  182. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
  183. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
  184. package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
  185. package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
  186. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
  187. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
  188. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
  189. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
  190. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
  191. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
  192. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
  193. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
  195. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
  197. package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
  198. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
  199. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
  201. package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
  203. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
  205. package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
  207. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
  209. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
  211. package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
  213. package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
  214. package/.claude-flow-novice/metrics.db +0 -0
  215. package/.claude-flow-novice/metrics.db-shm +0 -0
  216. package/.claude-flow-novice/metrics.db-wal +0 -0
  217. package/CLAUDE.md +29 -0
  218. package/README.md +27 -0
  219. package/config/hooks/post-edit-pipeline.js +36 -2
  220. package/examples/metrics-counter-demo.ts +106 -0
  221. package/examples/persistent-metrics-demo.ts +83 -0
  222. package/examples/phase-5-multi-level-control.ts +282 -0
  223. package/examples/session-pool-optimizer-example.ts +311 -0
  224. package/package.json +15 -3
  225. package/scripts/check-routing-stats.cjs +122 -0
  226. package/scripts/pre-publish-validation.cjs +212 -0
  227. package/scripts/test-provider-routing.cjs +228 -0
  228. package/scripts/test-routing-telemetry.cjs +147 -0
  229. package/scripts/test-zai-10k.cjs +81 -0
  230. package/scripts/test-zai-api.cjs +191 -0
  231. package/scripts/test-zai-diagnostic.cjs +151 -0
  232. package/scripts/test-zai-final.cjs +128 -0
  233. package/scripts/test-zai-with-env.cjs +85 -0
  234. package/scripts/validate-coordination-cli.js +69 -0
  235. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  236. package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
  237. package/src/observability/metrics-counter.ts +347 -0
  238. package/src/observability/metrics-storage.ts +356 -0
  239. package/src/observability/telemetry.ts +658 -0
  240. package/src/slash-commands/cfn-claude-sync.js +533 -0
  241. package/src/slash-commands/index.js +5 -0
  242. package/src/slash-commands/metrics-summary-class.js +74 -0
  243. package/src/slash-commands/metrics-summary.js +335 -0
  244. package/src/slash-commands/register-all-commands.js +12 -0
@@ -0,0 +1,462 @@
1
+ /**
2
+ * V1 Coordinator Adapter - Wraps V1 TopologyCoordinator with V2 ICoordinator Interface
3
+ *
4
+ * Purpose: Enable V1 coordination system (QueenAgent/MeshCoordinator) to work
5
+ * transparently through the V2 ICoordinator interface for toggle support.
6
+ *
7
+ * Key Features:
8
+ * - Wraps V1 TopologyCoordinator (hierarchical or mesh)
9
+ * - Maps V2 spawnAgent() → V1 delegateTask() or assignTask()
10
+ * - NOOP fallback for SDK-only features (pause/resume)
11
+ * - Translates V1 metrics to V2 CoordinatorMetrics format
12
+ * - Handles topology-specific method dispatch
13
+ *
14
+ * Limitations:
15
+ * - V1 does not support pause/resume (SDK feature) → returns error or NOOP
16
+ * - V1 does not support checkpointing → methods return empty/error
17
+ * - Metrics translation is best-effort (V1 and V2 track different data)
18
+ *
19
+ * @module coordination/adapters/v1-coordinator-adapter
20
+ */ import { AgentState } from '../v2/core/agent-state.js';
21
+ import { Logger } from '../../core/logger.js';
22
+ /**
23
+ * V1CoordinatorAdapter - Wraps V1 coordination with V2 interface
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Wrap V1 hierarchical coordinator
28
+ * const v1Coord = await createCoordinator({ topology: 'hierarchical' });
29
+ * const adapter = new V1CoordinatorAdapter(v1Coord, 'noop');
30
+ * await adapter.initialize();
31
+ *
32
+ * // Use V2 interface with V1 backend
33
+ * const agent = await adapter.spawnAgent({
34
+ * agentId: 'worker-1',
35
+ * type: 'coder',
36
+ * priority: 5
37
+ * });
38
+ * ```
39
+ */ export class V1CoordinatorAdapter {
40
+ v1Coordinator;
41
+ fallbackBehavior;
42
+ logger;
43
+ isInitialized = false;
44
+ startTime = Date.now();
45
+ // Agent tracking for V2 compatibility
46
+ spawnedAgents = new Map();
47
+ agentSessions = new Map();
48
+ // Metrics tracking
49
+ metrics = {
50
+ totalAgentsSpawned: 0,
51
+ totalTerminations: 0,
52
+ totalCheckpoints: 0,
53
+ totalRestores: 0,
54
+ checkpointLatencies: [],
55
+ restoreLatencies: [],
56
+ tokensSaved: 0,
57
+ totalTokensUsed: 0
58
+ };
59
+ constructor(v1Coordinator, fallbackBehavior = 'noop'){
60
+ this.v1Coordinator = v1Coordinator;
61
+ this.fallbackBehavior = fallbackBehavior;
62
+ // VUL-4 FIX: Validate v1Coordinator object structure
63
+ this.validateCoordinatorObject(v1Coordinator);
64
+ this.logger = new Logger({
65
+ level: 'info',
66
+ format: 'json',
67
+ destination: 'console'
68
+ }, {
69
+ component: 'V1CoordinatorAdapter'
70
+ });
71
+ }
72
+ /**
73
+ * Validate V1 coordinator object for security (VUL-4 FIX)
74
+ *
75
+ * Prevents prototype pollution and ensures required structure exists.
76
+ *
77
+ * @private
78
+ * @param coordinator - V1 coordinator object to validate
79
+ * @throws Error if validation fails
80
+ */ validateCoordinatorObject(coordinator) {
81
+ if (!coordinator || typeof coordinator !== 'object') {
82
+ throw new Error('V1 coordinator must be a valid object');
83
+ }
84
+ // VUL-4: Check for prototype pollution attack vectors (use hasOwnProperty to avoid false positives)
85
+ const dangerousKeys = [
86
+ '__proto__',
87
+ 'constructor',
88
+ 'prototype'
89
+ ];
90
+ for (const key of dangerousKeys){
91
+ if (Object.prototype.hasOwnProperty.call(coordinator, key)) {
92
+ throw new Error(`Security violation: Coordinator object contains dangerous key "${key}"`);
93
+ }
94
+ }
95
+ // VUL-4: Validate required properties
96
+ const requiredProps = [
97
+ 'topology',
98
+ 'coordinator',
99
+ 'initialize',
100
+ 'shutdown'
101
+ ];
102
+ for (const prop of requiredProps){
103
+ if (!(prop in coordinator)) {
104
+ throw new Error(`V1 coordinator missing required property: "${prop}". Required: ${requiredProps.join(', ')}`);
105
+ }
106
+ }
107
+ // Validate topology value
108
+ const validTopologies = [
109
+ 'hierarchical',
110
+ 'mesh',
111
+ 'hybrid'
112
+ ];
113
+ if (!validTopologies.includes(coordinator.topology)) {
114
+ throw new Error(`Invalid topology: "${coordinator.topology}". Must be one of: ${validTopologies.join(', ')}`);
115
+ }
116
+ }
117
+ // ===========================
118
+ // Coordinator Lifecycle
119
+ // ===========================
120
+ async initialize() {
121
+ if (this.isInitialized) {
122
+ this.logger.warn('V1CoordinatorAdapter already initialized');
123
+ return;
124
+ }
125
+ this.logger.info('Initializing V1CoordinatorAdapter...');
126
+ // Initialize wrapped V1 coordinator
127
+ await this.v1Coordinator.initialize();
128
+ this.isInitialized = true;
129
+ this.startTime = Date.now();
130
+ this.logger.info(`V1CoordinatorAdapter initialized with ${this.v1Coordinator.topology} topology`);
131
+ }
132
+ async cleanup() {
133
+ if (!this.isInitialized) {
134
+ return;
135
+ }
136
+ this.logger.info('Cleaning up V1CoordinatorAdapter...');
137
+ // Shutdown wrapped V1 coordinator
138
+ await this.v1Coordinator.shutdown();
139
+ // Clear tracking data
140
+ this.spawnedAgents.clear();
141
+ this.agentSessions.clear();
142
+ this.isInitialized = false;
143
+ this.logger.info('V1CoordinatorAdapter cleanup complete');
144
+ }
145
+ isReady() {
146
+ return this.isInitialized;
147
+ }
148
+ // ===========================
149
+ // Agent Lifecycle Management
150
+ // ===========================
151
+ async spawnAgent(config) {
152
+ if (!this.isInitialized) {
153
+ throw new Error('V1CoordinatorAdapter not initialized');
154
+ }
155
+ this.logger.debug(`Spawning agent ${config.agentId} (type: ${config.type})`);
156
+ let v1Result;
157
+ let agent;
158
+ // Route to appropriate V1 method based on topology
159
+ if (this.v1Coordinator.topology === 'hierarchical') {
160
+ // Hierarchical: Use QueenAgent.delegateTask()
161
+ const queenAgent = this.v1Coordinator.coordinator;
162
+ // V1 QueenAgent requires spawning worker first, then delegating task
163
+ const workerId = await queenAgent.spawnWorker(config.type, {
164
+ skills: config.metadata?.skills || [],
165
+ maxConcurrentTasks: 3,
166
+ priority: config.priority || 1,
167
+ specializations: config.metadata?.specializations
168
+ }, config.metadata?.caller);
169
+ // Create task to delegate (V1 Task format)
170
+ const task = {
171
+ id: config.agentId,
172
+ type: config.type,
173
+ description: config.metadata?.description || `Task for ${config.agentId}`,
174
+ priority: config.priority || 1,
175
+ dependencies: [],
176
+ status: 'pending',
177
+ input: config.metadata?.input || {},
178
+ createdAt: new Date()
179
+ };
180
+ v1Result = await queenAgent.delegateTask(task, config.metadata?.caller, workerId);
181
+ agent = this.mapV1DelegationResultToAgent(v1Result, config, workerId);
182
+ } else {
183
+ // Mesh: Use MeshCoordinator.registerAgent() and coordinateTask()
184
+ const meshCoordinator = this.v1Coordinator.coordinator;
185
+ // Register agent in mesh
186
+ await meshCoordinator.registerAgent(config.agentId, {
187
+ name: config.agentId,
188
+ type: config.type,
189
+ status: 'ready',
190
+ capabilities: config.metadata?.capabilities || []
191
+ });
192
+ // Coordinate task for the agent
193
+ const taskId = await meshCoordinator.coordinateTask(config.metadata?.description || `Task for ${config.agentId}`, {
194
+ requiredCapabilities: config.metadata?.capabilities,
195
+ priority: config.priority || 1
196
+ });
197
+ agent = this.mapV1MeshResultToAgent(taskId, config);
198
+ }
199
+ // Track agent in adapter
200
+ this.spawnedAgents.set(config.agentId, agent);
201
+ // Create agent session
202
+ const session = {
203
+ sessionId: config.sessionId || `session-${config.agentId}`,
204
+ agentId: config.agentId,
205
+ state: agent.state,
206
+ isPaused: false,
207
+ checkpoints: [],
208
+ priority: config.priority || 1,
209
+ metadata: config.metadata || {}
210
+ };
211
+ this.agentSessions.set(config.agentId, session);
212
+ // Update metrics
213
+ this.metrics.totalAgentsSpawned++;
214
+ this.logger.info(`Agent ${config.agentId} spawned successfully via V1 ${this.v1Coordinator.topology} topology`);
215
+ return agent;
216
+ }
217
+ async pauseAgent(agentId, reason) {
218
+ // V1 does not support pause/resume - SDK-only feature
219
+ this.logger.warn(`[V1 Adapter] Pause not supported for agent ${agentId} - V1 coordination does not support SDK features`);
220
+ if (this.fallbackBehavior === 'error') {
221
+ throw new Error(`V1 coordination does not support pause/resume. Use V2 with SDK mode. Agent: ${agentId}, Reason: ${reason || 'none'}`);
222
+ }
223
+ // NOOP fallback - do nothing but log warning
224
+ this.logger.warn(`[V1 Adapter] Pause operation ignored for agent ${agentId}. Reason: ${reason || 'none'}`);
225
+ }
226
+ async resumeAgent(agentId, checkpointId, messageUUID) {
227
+ // V1 does not support pause/resume - SDK-only feature
228
+ this.logger.warn(`[V1 Adapter] Resume not supported for agent ${agentId} - V1 coordination does not support SDK features`);
229
+ if (this.fallbackBehavior === 'error') {
230
+ throw new Error(`V1 coordination does not support pause/resume. Use V2 with SDK mode. Agent: ${agentId}, CheckpointId: ${checkpointId || 'none'}, MessageUUID: ${messageUUID || 'none'}`);
231
+ }
232
+ // NOOP fallback - do nothing but log warning
233
+ this.logger.warn(`[V1 Adapter] Resume operation ignored for agent ${agentId}. CheckpointId: ${checkpointId || 'none'}, MessageUUID: ${messageUUID || 'none'}`);
234
+ }
235
+ async terminateAgent(agentId, reason) {
236
+ if (!this.isInitialized) {
237
+ throw new Error('V1CoordinatorAdapter not initialized');
238
+ }
239
+ const agent = this.spawnedAgents.get(agentId);
240
+ if (!agent) {
241
+ throw new Error(`Agent not found: ${agentId}`);
242
+ }
243
+ this.logger.debug(`Terminating agent ${agentId}. Reason: ${reason || 'none'}`);
244
+ // V1 doesn't have explicit termination - just remove from tracking
245
+ this.spawnedAgents.delete(agentId);
246
+ this.agentSessions.delete(agentId);
247
+ // Update metrics
248
+ this.metrics.totalTerminations++;
249
+ this.logger.info(`Agent ${agentId} terminated. Reason: ${reason || 'none'}`);
250
+ }
251
+ // ===========================
252
+ // State Management
253
+ // ===========================
254
+ async getAgentState(agentId) {
255
+ const agent = this.spawnedAgents.get(agentId);
256
+ if (!agent) {
257
+ throw new Error(`Agent not found: ${agentId}`);
258
+ }
259
+ return agent.state;
260
+ }
261
+ async getAgentSession(agentId) {
262
+ const session = this.agentSessions.get(agentId);
263
+ if (!session) {
264
+ throw new Error(`Agent session not found: ${agentId}`);
265
+ }
266
+ return session;
267
+ }
268
+ async createCheckpoint(agentId, reason, metadata) {
269
+ // V1 does not support checkpointing - SDK-only feature
270
+ this.logger.warn(`[V1 Adapter] Checkpointing not supported for agent ${agentId} - V1 coordination does not support SDK features`);
271
+ if (this.fallbackBehavior === 'error') {
272
+ throw new Error(`V1 coordination does not support checkpointing. Use V2 with SDK mode. Agent: ${agentId}, Reason: ${reason || 'none'}`);
273
+ }
274
+ // Return stub checkpoint for compatibility
275
+ const stubCheckpoint = {
276
+ id: `stub-checkpoint-${agentId}-${Date.now()}`,
277
+ sessionId: this.agentSessions.get(agentId)?.sessionId || 'unknown',
278
+ agentId,
279
+ messageUUID: 'not-supported',
280
+ state: AgentState.IDLE,
281
+ timestamp: new Date(),
282
+ metadata: {
283
+ reason: reason || 'V1 stub checkpoint',
284
+ autoCheckpoint: false,
285
+ context: {
286
+ v1Adapter: true,
287
+ ...metadata
288
+ }
289
+ }
290
+ };
291
+ this.logger.warn(`[V1 Adapter] Created stub checkpoint for agent ${agentId}. Checkpoints are not functional in V1 mode.`);
292
+ return stubCheckpoint;
293
+ }
294
+ async restoreCheckpoint(checkpointId) {
295
+ // V1 does not support checkpointing - SDK-only feature
296
+ this.logger.warn(`[V1 Adapter] Checkpoint restoration not supported - V1 coordination does not support SDK features. CheckpointId: ${checkpointId}`);
297
+ if (this.fallbackBehavior === 'error') {
298
+ throw new Error(`V1 coordination does not support checkpoint restoration. Use V2 with SDK mode. CheckpointId: ${checkpointId}`);
299
+ }
300
+ // Return first available agent as stub
301
+ const firstAgent = Array.from(this.spawnedAgents.values())[0];
302
+ if (!firstAgent) {
303
+ throw new Error('No agents available to restore from stub checkpoint');
304
+ }
305
+ this.logger.warn(`[V1 Adapter] Restore checkpoint operation ignored. Returning first available agent as stub.`);
306
+ return firstAgent;
307
+ }
308
+ async listCheckpoints(agentId, limit) {
309
+ // V1 does not support checkpointing - return empty array
310
+ this.logger.warn(`[V1 Adapter] Checkpoint listing not supported for agent ${agentId} - V1 coordination does not support SDK features`);
311
+ if (this.fallbackBehavior === 'error') {
312
+ throw new Error(`V1 coordination does not support checkpointing. Use V2 with SDK mode. Agent: ${agentId}`);
313
+ }
314
+ return [];
315
+ }
316
+ // ===========================
317
+ // Metrics & Monitoring
318
+ // ===========================
319
+ getMetrics() {
320
+ const activeAgents = Array.from(this.spawnedAgents.values()).filter((agent)=>agent.state !== AgentState.TERMINATED && agent.state !== AgentState.COMPLETED).length;
321
+ const pausedAgents = Array.from(this.spawnedAgents.values()).filter((agent)=>agent.state === AgentState.PAUSED).length;
322
+ const avgCheckpointTime = this.metrics.checkpointLatencies.length > 0 ? this.metrics.checkpointLatencies.reduce((sum, val)=>sum + val, 0) / this.metrics.checkpointLatencies.length : 0;
323
+ const avgRestoreTime = this.metrics.restoreLatencies.length > 0 ? this.metrics.restoreLatencies.reduce((sum, val)=>sum + val, 0) / this.metrics.restoreLatencies.length : 0;
324
+ // P99 calculation (simplified - returns max for small datasets)
325
+ const p99RestoreTime = this.metrics.restoreLatencies.length > 0 ? Math.max(...this.metrics.restoreLatencies) : 0;
326
+ return {
327
+ totalAgentsSpawned: this.metrics.totalAgentsSpawned,
328
+ activeAgents,
329
+ pausedAgents,
330
+ totalTerminations: this.metrics.totalTerminations,
331
+ totalCheckpoints: this.metrics.totalCheckpoints,
332
+ totalRestores: this.metrics.totalRestores,
333
+ averageCheckpointTimeMs: avgCheckpointTime,
334
+ averageRestoreTimeMs: avgRestoreTime,
335
+ p99RestoreTimeMs: p99RestoreTime,
336
+ tokensSaved: this.metrics.tokensSaved,
337
+ totalTokensUsed: this.metrics.totalTokensUsed,
338
+ uptimeMs: Date.now() - this.startTime
339
+ };
340
+ }
341
+ getActiveAgents() {
342
+ return Array.from(this.spawnedAgents.values()).filter((agent)=>agent.state !== AgentState.PAUSED && agent.state !== AgentState.TERMINATED && agent.state !== AgentState.COMPLETED);
343
+ }
344
+ getPausedAgents() {
345
+ return Array.from(this.spawnedAgents.values()).filter((agent)=>agent.state === AgentState.PAUSED);
346
+ }
347
+ async updateTokenUsage(agentId, tokensUsed) {
348
+ const agent = this.spawnedAgents.get(agentId);
349
+ if (!agent) {
350
+ throw new Error(`Agent not found: ${agentId}`);
351
+ }
352
+ // Update total token usage
353
+ this.metrics.totalTokensUsed += tokensUsed;
354
+ // Update agent metadata
355
+ if (!agent.metadata) {
356
+ agent.metadata = {};
357
+ }
358
+ agent.metadata.tokensUsed = (agent.metadata.tokensUsed || 0) + tokensUsed;
359
+ this.logger.debug(`Updated token usage for agent ${agentId}: +${tokensUsed} (total: ${agent.metadata.tokensUsed})`);
360
+ }
361
+ // ===========================
362
+ // Private Helper Methods
363
+ // ===========================
364
+ /**
365
+ * Map V1 QueenAgent DelegationResult to V2 Agent
366
+ */ mapV1DelegationResultToAgent(v1Result, config, workerId) {
367
+ const state = this.mapV1StatusToAgentState(v1Result.status);
368
+ return {
369
+ agentId: config.agentId,
370
+ sessionId: config.sessionId || `session-${config.agentId}`,
371
+ type: config.type,
372
+ state,
373
+ isPaused: false,
374
+ priority: config.priority || 1,
375
+ session: {
376
+ sessionId: config.sessionId || `session-${config.agentId}`,
377
+ agentId: config.agentId,
378
+ state,
379
+ isPaused: false,
380
+ checkpoints: [],
381
+ priority: config.priority || 1,
382
+ metadata: {
383
+ ...config.metadata,
384
+ v1WorkerId: workerId,
385
+ v1TaskId: v1Result.taskId,
386
+ v1DelegatedAt: v1Result.delegatedAt
387
+ }
388
+ },
389
+ metadata: {
390
+ ...config.metadata,
391
+ v1WorkerId: workerId,
392
+ v1TaskId: v1Result.taskId,
393
+ v1DelegatedAt: v1Result.delegatedAt
394
+ }
395
+ };
396
+ }
397
+ /**
398
+ * Map V1 MeshCoordinator task to V2 Agent
399
+ */ mapV1MeshResultToAgent(taskId, config) {
400
+ return {
401
+ agentId: config.agentId,
402
+ sessionId: config.sessionId || `session-${config.agentId}`,
403
+ type: config.type,
404
+ state: AgentState.WORKING,
405
+ isPaused: false,
406
+ priority: config.priority || 1,
407
+ session: {
408
+ sessionId: config.sessionId || `session-${config.agentId}`,
409
+ agentId: config.agentId,
410
+ state: AgentState.WORKING,
411
+ isPaused: false,
412
+ checkpoints: [],
413
+ priority: config.priority || 1,
414
+ metadata: {
415
+ ...config.metadata,
416
+ v1TaskId: taskId
417
+ }
418
+ },
419
+ metadata: {
420
+ ...config.metadata,
421
+ v1TaskId: taskId
422
+ }
423
+ };
424
+ }
425
+ /**
426
+ * Map V1 worker/task status to V2 AgentState enum
427
+ */ mapV1StatusToAgentState(v1Status) {
428
+ switch(v1Status){
429
+ case 'accepted':
430
+ return AgentState.WORKING;
431
+ case 'queued':
432
+ return AgentState.WAITING;
433
+ case 'rejected':
434
+ return AgentState.ERROR;
435
+ default:
436
+ return AgentState.IDLE;
437
+ }
438
+ }
439
+ /**
440
+ * Get topology type from wrapped V1 coordinator
441
+ * Note: V1 TopologyType includes 'hybrid', but V2 only uses 'hierarchical' | 'mesh'
442
+ */ getTopology() {
443
+ const topology = this.v1Coordinator.topology;
444
+ // Map 'hybrid' to 'mesh' for V2 compatibility
445
+ return topology === 'hybrid' ? 'mesh' : topology;
446
+ }
447
+ /**
448
+ * Get agent count from wrapped V1 coordinator
449
+ */ getAgentCount() {
450
+ if (this.v1Coordinator.topology === 'hierarchical') {
451
+ const queenAgent = this.v1Coordinator.coordinator;
452
+ const stats = queenAgent.getWorkerStats();
453
+ return stats.total;
454
+ } else {
455
+ const meshCoordinator = this.v1Coordinator.coordinator;
456
+ const status = meshCoordinator.getCoordinatorStatus();
457
+ return status.agentCount;
458
+ }
459
+ }
460
+ }
461
+
462
+ //# sourceMappingURL=v1-coordinator-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordination/adapters/v1-coordinator-adapter.ts"],"names":["AgentState","Logger","V1CoordinatorAdapter","logger","isInitialized","startTime","Date","now","spawnedAgents","Map","agentSessions","metrics","totalAgentsSpawned","totalTerminations","totalCheckpoints","totalRestores","checkpointLatencies","restoreLatencies","tokensSaved","totalTokensUsed","v1Coordinator","fallbackBehavior","validateCoordinatorObject","level","format","destination","component","coordinator","Error","dangerousKeys","key","Object","prototype","hasOwnProperty","call","requiredProps","prop","join","validTopologies","includes","topology","initialize","warn","info","cleanup","shutdown","clear","isReady","spawnAgent","config","debug","agentId","type","v1Result","agent","queenAgent","workerId","spawnWorker","skills","metadata","maxConcurrentTasks","priority","specializations","caller","task","id","description","dependencies","status","input","createdAt","delegateTask","mapV1DelegationResultToAgent","meshCoordinator","registerAgent","name","capabilities","taskId","coordinateTask","requiredCapabilities","mapV1MeshResultToAgent","set","session","sessionId","state","isPaused","checkpoints","pauseAgent","reason","resumeAgent","checkpointId","messageUUID","terminateAgent","get","delete","getAgentState","getAgentSession","createCheckpoint","stubCheckpoint","IDLE","timestamp","autoCheckpoint","context","v1Adapter","restoreCheckpoint","firstAgent","Array","from","values","listCheckpoints","limit","getMetrics","activeAgents","filter","TERMINATED","COMPLETED","length","pausedAgents","PAUSED","avgCheckpointTime","reduce","sum","val","avgRestoreTime","p99RestoreTime","Math","max","averageCheckpointTimeMs","averageRestoreTimeMs","p99RestoreTimeMs","uptimeMs","getActiveAgents","getPausedAgents","updateTokenUsage","tokensUsed","mapV1StatusToAgentState","v1WorkerId","v1TaskId","v1DelegatedAt","delegatedAt","WORKING","v1Status","WAITING","ERROR","getTopology","getAgentCount","stats","getWorkerStats","total","getCoordinatorStatus","agentCount"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;CAmBC,GAaD,SAASA,UAAU,QAAQ,4BAA4B;AACvD,SAASC,MAAM,QAAQ,uBAAuB;AAS9C;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,MAAMC;;;IACHC,OAAe;IACfC,gBAAyB,MAAM;IAC/BC,YAAoBC,KAAKC,GAAG,GAAG;IAEvC,sCAAsC;IAC9BC,gBAAoC,IAAIC,MAAM;IAC9CC,gBAA2C,IAAID,MAAM;IAE7D,mBAAmB;IACXE,UAAU;QAChBC,oBAAoB;QACpBC,mBAAmB;QACnBC,kBAAkB;QAClBC,eAAe;QACfC,qBAAqB,EAAE;QACvBC,kBAAkB,EAAE;QACpBC,aAAa;QACbC,iBAAiB;IACnB,EAAE;IAEF,YACE,AAAQC,aAAkC,EAC1C,AAAQC,mBAAqC,MAAM,CACnD;aAFQD,gBAAAA;aACAC,mBAAAA;QAER,qDAAqD;QACrD,IAAI,CAACC,yBAAyB,CAACF;QAE/B,IAAI,CAACjB,MAAM,GAAG,IAAIF,OAChB;YACEsB,OAAO;YACPC,QAAQ;YACRC,aAAa;QACf,GACA;YAAEC,WAAW;QAAuB;IAExC;IAEA;;;;;;;;GAQC,GACD,AAAQJ,0BAA0BK,WAAgB,EAAQ;QACxD,IAAI,CAACA,eAAe,OAAOA,gBAAgB,UAAU;YACnD,MAAM,IAAIC,MAAM;QAClB;QAEA,oGAAoG;QACpG,MAAMC,gBAAgB;YAAC;YAAa;YAAe;SAAY;QAC/D,KAAK,MAAMC,OAAOD,cAAe;YAC/B,IAAIE,OAAOC,SAAS,CAACC,cAAc,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