claude-flow-novice 1.6.1 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/.claude/agents/cfn-loop/product-owner.md +54 -4
  2. package/.claude/commands/cfn-claude-sync.md +303 -0
  3. package/.claude/commands/cfn-loop-epic.md +290 -0
  4. package/.claude/commands/cfn-loop-single.md +168 -0
  5. package/.claude/commands/cfn-loop-sprints.md +384 -0
  6. package/.claude/commands/cfn-loop.md +180 -0
  7. package/.claude/commands/metrics-summary.md +58 -0
  8. package/.claude/commands/parse-epic.md +357 -0
  9. package/.claude/settings.json +5 -4
  10. package/.claude/settings.local.json +9 -2
  11. package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
  12. package/.claude-flow-novice/dist/mcp/server.js +21 -2
  13. package/.claude-flow-novice/dist/src/api/auth-service.js +84 -38
  14. package/.claude-flow-novice/dist/src/api/auth-service.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
  16. package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
  17. package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
  18. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
  19. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
  20. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
  21. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  22. package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
  23. package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
  24. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
  25. package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
  26. package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
  27. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
  28. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
  29. package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
  30. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
  31. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
  32. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
  33. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
  34. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
  35. package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
  36. package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
  37. package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
  38. package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
  39. package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
  40. package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
  41. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
  42. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
  43. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
  44. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
  45. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
  46. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  47. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
  48. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  49. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
  50. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
  51. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
  52. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  53. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
  54. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
  55. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
  56. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
  57. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
  58. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  59. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
  60. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
  61. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
  62. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
  63. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
  64. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
  65. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
  66. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
  67. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
  68. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
  69. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
  70. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
  71. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
  72. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
  73. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
  74. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
  75. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
  76. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
  77. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
  78. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
  79. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
  80. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
  81. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
  82. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
  83. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
  84. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
  85. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
  86. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
  87. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
  88. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
  89. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
  90. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
  91. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
  92. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
  93. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
  94. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
  95. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
  96. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
  97. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
  98. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
  99. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
  100. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
  101. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
  102. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
  103. package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
  104. package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
  105. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
  106. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
  107. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
  108. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
  109. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
  110. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  111. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
  112. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
  113. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
  114. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
  115. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
  116. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
  117. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
  118. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
  119. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
  120. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
  121. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
  122. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
  123. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
  124. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
  125. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
  126. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
  127. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
  128. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
  129. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
  130. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
  131. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
  132. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
  133. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
  134. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
  135. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
  136. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
  137. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
  138. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
  139. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
  140. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
  141. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
  142. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
  143. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
  144. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
  145. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
  146. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
  147. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
  148. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
  149. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
  150. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
  151. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
  152. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
  153. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
  154. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
  155. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
  156. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
  157. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
  158. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
  159. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
  160. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
  161. package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
  162. package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
  163. package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
  164. package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
  165. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +719 -0
  166. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -0
  167. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js +363 -0
  168. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js.map +1 -0
  169. package/.claude-flow-novice/dist/src/monitoring/apm/index.js +97 -0
  170. package/.claude-flow-novice/dist/src/monitoring/apm/index.js.map +1 -0
  171. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js +384 -0
  172. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js.map +1 -0
  173. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js +612 -0
  174. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js.map +1 -0
  175. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js +282 -0
  176. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js.map +1 -0
  177. package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
  178. package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
  179. package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
  180. package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
  181. package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
  182. package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
  183. package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
  184. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  185. package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
  186. package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
  187. package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
  188. package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
  189. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
  190. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
  191. package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
  192. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
  193. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
  195. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
  197. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
  198. package/.claude-flow-novice/dist/src/web/api/apm-routes.js +355 -0
  199. package/.claude-flow-novice/dist/src/web/api/apm-routes.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
  201. package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
  203. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
  205. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
  207. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
  209. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
  211. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
  213. package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
  214. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
  215. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
  216. package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
  217. package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
  218. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
  219. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
  220. package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
  221. package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
  222. package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
  223. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
  224. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
  225. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
  226. package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
  227. package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
  228. package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
  229. package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
  230. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js +425 -0
  231. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js.map +1 -0
  232. package/.claude-flow-novice/dist/src/web/security/security-middleware.js +379 -0
  233. package/.claude-flow-novice/dist/src/web/security/security-middleware.js.map +1 -0
  234. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js +441 -0
  235. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js.map +1 -0
  236. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js +255 -1
  237. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js.map +1 -1
  238. package/.claude-flow-novice/metrics.db +0 -0
  239. package/.claude-flow-novice/metrics.db-shm +0 -0
  240. package/.claude-flow-novice/metrics.db-wal +0 -0
  241. package/AGENT_PERFORMANCE_GUIDELINES.md +88 -0
  242. package/CLAUDE.md +60 -3
  243. package/MEMORY_LEAK_ROOT_CAUSE.md +149 -0
  244. package/README.md +27 -0
  245. package/config/hooks/post-edit-pipeline.js +36 -2
  246. package/examples/metrics-counter-demo.ts +106 -0
  247. package/examples/persistent-metrics-demo.ts +83 -0
  248. package/examples/phase-5-multi-level-control.ts +282 -0
  249. package/examples/session-pool-optimizer-example.ts +311 -0
  250. package/package.json +18 -4
  251. package/scripts/check-routing-stats.cjs +122 -0
  252. package/scripts/monitor-loop.sh +65 -0
  253. package/scripts/monitor-memory.sh +47 -0
  254. package/scripts/monitor.py +43 -0
  255. package/scripts/pre-publish-validation.cjs +212 -0
  256. package/scripts/test-provider-routing.cjs +228 -0
  257. package/scripts/test-routing-telemetry.cjs +147 -0
  258. package/scripts/test-zai-10k.cjs +81 -0
  259. package/scripts/test-zai-api.cjs +191 -0
  260. package/scripts/test-zai-diagnostic.cjs +151 -0
  261. package/scripts/test-zai-final.cjs +128 -0
  262. package/scripts/test-zai-with-env.cjs +85 -0
  263. package/scripts/validate-coordination-cli.js +69 -0
  264. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  265. package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
  266. package/src/observability/metrics-counter.ts +347 -0
  267. package/src/observability/metrics-storage.ts +356 -0
  268. package/src/observability/telemetry.ts +658 -0
  269. package/src/slash-commands/cfn-claude-sync.js +533 -0
  270. package/src/slash-commands/index.js +5 -0
  271. package/src/slash-commands/metrics-summary-class.js +74 -0
  272. package/src/slash-commands/metrics-summary.js +335 -0
  273. package/src/slash-commands/register-all-commands.js +12 -0
@@ -0,0 +1,282 @@
1
+ // Metrics collection system for Claude Flow Novice
2
+ // Integrates with Prometheus, DataDog, and New Relic
3
+ import { createPrometheusMetrics } from './prometheus-collector';
4
+ import { createDataDogMetrics } from './datadog-collector';
5
+ import { createNewRelicMetrics } from './newrelic-collector';
6
+ import { Logger } from '../utils/logger';
7
+ export class MetricsCollector {
8
+ config;
9
+ logger;
10
+ prometheusCollector;
11
+ dataDogCollector;
12
+ newRelicCollector;
13
+ customMetrics = new Map();
14
+ constructor(config){
15
+ this.config = config;
16
+ this.logger = new Logger('MetricsCollector');
17
+ this.initializeCollectors();
18
+ this.registerCustomMetrics();
19
+ }
20
+ initializeCollectors() {
21
+ if (this.config.providers.prometheus?.enabled) {
22
+ this.prometheusCollector = createPrometheusMetrics(this.config.providers.prometheus);
23
+ this.logger.info('Prometheus metrics collector initialized');
24
+ }
25
+ if (this.config.providers.datadog?.enabled) {
26
+ this.dataDogCollector = createDataDogMetrics(this.config.providers.datadog);
27
+ this.logger.info('DataDog metrics collector initialized');
28
+ }
29
+ if (this.config.providers.newrelic?.enabled) {
30
+ this.newRelicCollector = createNewRelicMetrics(this.config.providers.newrelic);
31
+ this.logger.info('New Relic metrics collector initialized');
32
+ }
33
+ }
34
+ registerCustomMetrics() {
35
+ if (!this.config.customMetrics) return;
36
+ for (const [name, definition] of Object.entries(this.config.customMetrics)){
37
+ this.registerMetric(definition);
38
+ }
39
+ }
40
+ registerMetric(definition) {
41
+ this.customMetrics.set(definition.name, definition);
42
+ // Register with each provider
43
+ if (this.prometheusCollector) {
44
+ this.prometheusCollector.registerMetric(definition);
45
+ }
46
+ if (this.dataDogCollector) {
47
+ this.dataDogCollector.registerMetric(definition);
48
+ }
49
+ if (this.newRelicCollector) {
50
+ this.newRelicCollector.registerMetric(definition);
51
+ }
52
+ }
53
+ increment(name, value = 1, labels) {
54
+ this.sendToAllProviders('increment', name, value, labels);
55
+ }
56
+ gauge(name, value, labels) {
57
+ this.sendToAllProviders('gauge', name, value, labels);
58
+ }
59
+ histogram(name, value, labels) {
60
+ this.sendToAllProviders('histogram', name, value, labels);
61
+ }
62
+ timing(name, value, labels) {
63
+ this.sendToAllProviders('timing', name, value, labels);
64
+ }
65
+ sendToAllProviders(type, name, value, labels) {
66
+ try {
67
+ if (this.prometheusCollector) {
68
+ this.prometheusCollector[type](name, value, labels);
69
+ }
70
+ if (this.dataDogCollector) {
71
+ this.dataDogCollector[type](name, value, labels);
72
+ }
73
+ if (this.newRelicCollector) {
74
+ this.newRelicCollector[type](name, value, labels);
75
+ }
76
+ } catch (error) {
77
+ this.logger.error('Failed to send metric to providers', {
78
+ error,
79
+ name,
80
+ type
81
+ });
82
+ }
83
+ }
84
+ // HTTP request metrics
85
+ recordHttpRequest(method, route, statusCode, duration, userAgent) {
86
+ const labels = {
87
+ method,
88
+ route,
89
+ status_code: statusCode.toString(),
90
+ status_class: this.getStatusClass(statusCode),
91
+ user_agent: userAgent ? this.getUserAgentCategory(userAgent) : 'unknown'
92
+ };
93
+ this.increment('http_requests_total', 1, labels);
94
+ this.histogram('http_request_duration_seconds', duration, labels);
95
+ if (statusCode >= 400) {
96
+ this.increment('http_errors_total', 1, labels);
97
+ }
98
+ }
99
+ // Business metrics
100
+ recordAgentOperation(agentType, operation, duration, success, errorType) {
101
+ const labels = {
102
+ agent_type: agentType,
103
+ operation,
104
+ success: success.toString()
105
+ };
106
+ this.increment('agent_operations_total', 1, labels);
107
+ this.histogram('agent_operation_duration_seconds', duration, labels);
108
+ if (!success && errorType) {
109
+ this.increment('agent_errors_total', 1, {
110
+ ...labels,
111
+ error_type: errorType
112
+ });
113
+ }
114
+ }
115
+ recordSwarmActivity(swarmSize, topology, duration, success) {
116
+ const labels = {
117
+ topology,
118
+ success: success.toString()
119
+ };
120
+ this.gauge('active_swarm_size', swarmSize);
121
+ this.increment('swarm_executions_total', 1, labels);
122
+ this.histogram('swarm_execution_duration_seconds', duration, labels);
123
+ }
124
+ // System metrics
125
+ recordMemoryUsage(used, total, component) {
126
+ const labels = {
127
+ component
128
+ };
129
+ const usagePercent = used / total * 100;
130
+ this.gauge('memory_usage_bytes', used, labels);
131
+ this.gauge('memory_usage_percent', usagePercent, labels);
132
+ }
133
+ recordCPUUsage(percent, component) {
134
+ this.gauge('cpu_usage_percent', percent, {
135
+ component
136
+ });
137
+ }
138
+ // Database metrics
139
+ recordDatabaseQuery(operation, table, duration, success, errorType) {
140
+ const labels = {
141
+ operation,
142
+ table,
143
+ success: success.toString()
144
+ };
145
+ this.increment('database_queries_total', 1, labels);
146
+ this.histogram('database_query_duration_seconds', duration, labels);
147
+ if (!success && errorType) {
148
+ this.increment('database_errors_total', 1, {
149
+ ...labels,
150
+ error_type: errorType
151
+ });
152
+ }
153
+ }
154
+ // Cache metrics
155
+ recordCacheOperation(operation, key, duration) {
156
+ const labels = {
157
+ operation,
158
+ key_prefix: key.split(':')[0] || 'unknown'
159
+ };
160
+ this.increment('cache_operations_total', 1, labels);
161
+ if (duration) {
162
+ this.histogram('cache_operation_duration_seconds', duration, labels);
163
+ }
164
+ }
165
+ // Utility methods
166
+ getStatusClass(statusCode) {
167
+ if (statusCode >= 200 && statusCode < 300) return '2xx';
168
+ if (statusCode >= 300 && statusCode < 400) return '3xx';
169
+ if (statusCode >= 400 && statusCode < 500) return '4xx';
170
+ if (statusCode >= 500) return '5xx';
171
+ return 'unknown';
172
+ }
173
+ getUserAgentCategory(userAgent) {
174
+ if (userAgent.includes('curl') || userAgent.includes('wget')) return 'cli';
175
+ if (userAgent.includes('Mozilla')) return 'browser';
176
+ if (userAgent.includes('bot') || userAgent.includes('crawler')) return 'bot';
177
+ return 'other';
178
+ }
179
+ // Health check
180
+ async healthCheck() {
181
+ const providers = {};
182
+ if (this.prometheusCollector) {
183
+ try {
184
+ await this.prometheusCollector.healthCheck();
185
+ providers.prometheus = true;
186
+ } catch {
187
+ providers.prometheus = false;
188
+ }
189
+ }
190
+ if (this.dataDogCollector) {
191
+ try {
192
+ await this.dataDogCollector.healthCheck();
193
+ providers.datadog = true;
194
+ } catch {
195
+ providers.datadog = false;
196
+ }
197
+ }
198
+ if (this.newRelicCollector) {
199
+ try {
200
+ await this.newRelicCollector.healthCheck();
201
+ providers.newrelic = true;
202
+ } catch {
203
+ providers.newrelic = false;
204
+ }
205
+ }
206
+ const allHealthy = Object.values(providers).every((status)=>status);
207
+ return {
208
+ status: allHealthy ? 'healthy' : 'degraded',
209
+ providers
210
+ };
211
+ }
212
+ // Shutdown
213
+ async shutdown() {
214
+ this.logger.info('Shutting down metrics collector');
215
+ if (this.prometheusCollector) {
216
+ await this.prometheusCollector.shutdown();
217
+ }
218
+ if (this.dataDogCollector) {
219
+ await this.dataDogCollector.shutdown();
220
+ }
221
+ if (this.newRelicCollector) {
222
+ await this.newRelicCollector.shutdown();
223
+ }
224
+ this.logger.info('Metrics collector shutdown complete');
225
+ }
226
+ }
227
+ // Factory function
228
+ export function createMetricsCollector(config) {
229
+ return new MetricsCollector(config);
230
+ }
231
+ // Default configuration
232
+ export const defaultMetricsConfig = {
233
+ enabled: true,
234
+ providers: {
235
+ prometheus: {
236
+ enabled: true,
237
+ port: 9090,
238
+ endpoint: '/metrics'
239
+ }
240
+ },
241
+ customMetrics: {
242
+ claude_flow_operations_total: {
243
+ type: 'counter',
244
+ name: 'claude_flow_operations_total',
245
+ description: 'Total number of Claude Flow operations',
246
+ labels: [
247
+ 'operation_type',
248
+ 'agent_type',
249
+ 'status'
250
+ ]
251
+ },
252
+ claude_flow_operation_duration: {
253
+ type: 'histogram',
254
+ name: 'claude_flow_operation_duration_seconds',
255
+ description: 'Duration of Claude Flow operations',
256
+ labels: [
257
+ 'operation_type',
258
+ 'agent_type'
259
+ ],
260
+ buckets: [
261
+ 0.1,
262
+ 0.5,
263
+ 1,
264
+ 2,
265
+ 5,
266
+ 10,
267
+ 30,
268
+ 60
269
+ ]
270
+ },
271
+ active_agents_count: {
272
+ type: 'gauge',
273
+ name: 'active_agents_count',
274
+ description: 'Number of currently active agents',
275
+ labels: [
276
+ 'agent_type'
277
+ ]
278
+ }
279
+ }
280
+ };
281
+
282
+ //# sourceMappingURL=metrics-collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/monitoring/metrics-collector.ts"],"names":["createPrometheusMetrics","createDataDogMetrics","createNewRelicMetrics","Logger","MetricsCollector","config","logger","prometheusCollector","dataDogCollector","newRelicCollector","customMetrics","Map","initializeCollectors","registerCustomMetrics","providers","prometheus","enabled","info","datadog","newrelic","name","definition","Object","entries","registerMetric","set","increment","value","labels","sendToAllProviders","gauge","histogram","timing","type","error","recordHttpRequest","method","route","statusCode","duration","userAgent","status_code","toString","status_class","getStatusClass","user_agent","getUserAgentCategory","recordAgentOperation","agentType","operation","success","errorType","agent_type","error_type","recordSwarmActivity","swarmSize","topology","recordMemoryUsage","used","total","component","usagePercent","recordCPUUsage","percent","recordDatabaseQuery","table","recordCacheOperation","key","key_prefix","split","includes","healthCheck","allHealthy","values","every","status","shutdown","createMetricsCollector","defaultMetricsConfig","port","endpoint","claude_flow_operations_total","description","claude_flow_operation_duration","buckets","active_agents_count"],"mappings":"AAAA,mDAAmD;AACnD,qDAAqD;AAErD,SAASA,uBAAuB,QAAQ,yBAAyB;AACjE,SAASC,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,MAAM,QAAQ,kBAAkB;AAyCzC,OAAO,MAAMC;IACHC,OAAsB;IACtBC,OAAe;IACfC,oBAA0B;IAC1BC,iBAAuB;IACvBC,kBAAwB;IACxBC,gBAA+C,IAAIC,MAAM;IAEjE,YAAYN,MAAqB,CAAE;QACjC,IAAI,CAACA,MAAM,GAAGA;QACd,IAAI,CAACC,MAAM,GAAG,IAAIH,OAAO;QAEzB,IAAI,CAACS,oBAAoB;QACzB,IAAI,CAACC,qBAAqB;IAC5B;IAEQD,uBAA6B;QACnC,IAAI,IAAI,CAACP,MAAM,CAACS,SAAS,CAACC,UAAU,EAAEC,SAAS;YAC7C,IAAI,CAACT,mBAAmB,GAAGP,wBAAwB,IAAI,CAACK,MAAM,CAACS,SAAS,CAACC,UAAU;YACnF,IAAI,CAACT,MAAM,CAACW,IAAI,CAAC;QACnB;QAEA,IAAI,IAAI,CAACZ,MAAM,CAACS,SAAS,CAACI,OAAO,EAAEF,SAAS;YAC1C,IAAI,CAACR,gBAAgB,GAAGP,qBAAqB,IAAI,CAACI,MAAM,CAACS,SAAS,CAACI,OAAO;YAC1E,IAAI,CAACZ,MAAM,CAACW,IAAI,CAAC;QACnB;QAEA,IAAI,IAAI,CAACZ,MAAM,CAACS,SAAS,CAACK,QAAQ,EAAEH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}
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Simple Metrics Counter API
3
+ *
4
+ * Provides easy-to-use functions to increment metrics counters
5
+ * with optional tags for dimensional analysis.
6
+ */ import { getGlobalTelemetry } from './telemetry.js';
7
+ // ============================================================================
8
+ // Public API - Simple Counter Functions
9
+ // ============================================================================
10
+ /**
11
+ * Increment a metric counter by 1 (or custom value)
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Simple counter
16
+ * incrementMetric('api.requests');
17
+ *
18
+ * // Counter with tags
19
+ * incrementMetric('api.requests', 1, {
20
+ * endpoint: '/users',
21
+ * method: 'GET',
22
+ * status: '200'
23
+ * });
24
+ *
25
+ * // Custom increment value
26
+ * incrementMetric('bytes.uploaded', 1024, { fileType: 'image' });
27
+ * ```
28
+ */ export function incrementMetric(metricName, value = 1, tags = {}) {
29
+ const telemetry = getGlobalTelemetry();
30
+ telemetry.recordCounter(metricName, value, tags);
31
+ }
32
+ /**
33
+ * Record a gauge value (point-in-time measurement)
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Record current queue size
38
+ * recordGauge('queue.size', 42);
39
+ *
40
+ * // Record with context
41
+ * recordGauge('memory.usage', process.memoryUsage().heapUsed, {
42
+ * unit: 'bytes',
43
+ * process: 'worker-1'
44
+ * });
45
+ * ```
46
+ */ export function recordGauge(metricName, value, tags = {}) {
47
+ const telemetry = getGlobalTelemetry();
48
+ telemetry.recordGauge(metricName, value, tags);
49
+ }
50
+ /**
51
+ * Record a timing/duration metric
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const start = Date.now();
56
+ * await doWork();
57
+ * recordTiming('task.duration', Date.now() - start, { taskType: 'export' });
58
+ * ```
59
+ */ export function recordTiming(metricName, durationMs, tags = {}) {
60
+ const telemetry = getGlobalTelemetry();
61
+ telemetry.recordTimer(metricName, durationMs, tags);
62
+ }
63
+ /**
64
+ * Wrapper to measure function execution time
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const result = await measureExecution('api.fetch', async () => {
69
+ * return await fetch('https://api.example.com/data');
70
+ * }, { endpoint: '/data' });
71
+ * ```
72
+ */ export async function measureExecution(metricName, fn, tags = {}) {
73
+ const start = Date.now();
74
+ try {
75
+ const result = await fn();
76
+ recordTiming(metricName, Date.now() - start, {
77
+ ...tags,
78
+ status: 'success'
79
+ });
80
+ return result;
81
+ } catch (error) {
82
+ recordTiming(metricName, Date.now() - start, {
83
+ ...tags,
84
+ status: 'error'
85
+ });
86
+ throw error;
87
+ }
88
+ }
89
+ /**
90
+ * Synchronous execution measurement
91
+ */ export function measureExecutionSync(metricName, fn, tags = {}) {
92
+ const start = Date.now();
93
+ try {
94
+ const result = fn();
95
+ recordTiming(metricName, Date.now() - start, {
96
+ ...tags,
97
+ status: 'success'
98
+ });
99
+ return result;
100
+ } catch (error) {
101
+ recordTiming(metricName, Date.now() - start, {
102
+ ...tags,
103
+ status: 'error'
104
+ });
105
+ throw error;
106
+ }
107
+ }
108
+ // ============================================================================
109
+ // Pre-defined Domain Metrics (Convenience Functions)
110
+ // ============================================================================
111
+ /**
112
+ * Track provider routing decisions
113
+ */ export function trackProviderRouting(provider, tier, agentType, source) {
114
+ incrementMetric('provider.request', 1, {
115
+ provider,
116
+ tier,
117
+ agentType,
118
+ source
119
+ });
120
+ }
121
+ /**
122
+ * Track agent spawns
123
+ */ export function trackAgentSpawn(agentType, swarmId, topology) {
124
+ incrementMetric('agent.spawned', 1, {
125
+ agentType,
126
+ swarmId,
127
+ topology
128
+ });
129
+ }
130
+ /**
131
+ * Track agent completion
132
+ */ export function trackAgentCompletion(agentType, success, durationMs) {
133
+ incrementMetric('agent.completed', 1, {
134
+ agentType,
135
+ status: success ? 'success' : 'failure'
136
+ });
137
+ recordTiming('agent.duration', durationMs, {
138
+ agentType,
139
+ status: success ? 'success' : 'failure'
140
+ });
141
+ }
142
+ /**
143
+ * Track task orchestration
144
+ */ export function trackTaskOrchestration(taskType, strategy, agentCount) {
145
+ incrementMetric('task.orchestrated', 1, {
146
+ taskType,
147
+ strategy
148
+ });
149
+ recordGauge('task.agents', agentCount, {
150
+ taskType,
151
+ strategy
152
+ });
153
+ }
154
+ /**
155
+ * Track swarm operations
156
+ */ export function trackSwarmOperation(operation, topology, agentCount) {
157
+ incrementMetric('swarm.operation', 1, {
158
+ operation,
159
+ topology
160
+ });
161
+ if (agentCount !== undefined) {
162
+ recordGauge('swarm.size', agentCount, {
163
+ topology
164
+ });
165
+ }
166
+ }
167
+ /**
168
+ * Track API calls (generic)
169
+ */ export function trackAPICall(endpoint, method, statusCode, durationMs) {
170
+ incrementMetric('api.requests', 1, {
171
+ endpoint,
172
+ method,
173
+ status: statusCode.toString()
174
+ });
175
+ recordTiming('api.duration', durationMs, {
176
+ endpoint,
177
+ method
178
+ });
179
+ }
180
+ /**
181
+ * Track errors
182
+ */ export function trackError(errorType, component, severity = 'medium') {
183
+ incrementMetric('errors.count', 1, {
184
+ errorType,
185
+ component,
186
+ severity
187
+ });
188
+ }
189
+ /**
190
+ * Track memory usage
191
+ */ export function trackMemoryUsage(component) {
192
+ const usage = process.memoryUsage();
193
+ recordGauge('memory.heap.used', usage.heapUsed, {
194
+ component,
195
+ unit: 'bytes'
196
+ });
197
+ recordGauge('memory.heap.total', usage.heapTotal, {
198
+ component,
199
+ unit: 'bytes'
200
+ });
201
+ recordGauge('memory.rss', usage.rss, {
202
+ component,
203
+ unit: 'bytes'
204
+ });
205
+ }
206
+ /**
207
+ * Track subscription usage
208
+ */ export function trackSubscriptionUsage(used, limit, remaining) {
209
+ recordGauge('subscription.usage', used, {
210
+ limit: limit.toString(),
211
+ remaining: remaining.toString(),
212
+ utilizationPct: (used / limit * 100).toFixed(1)
213
+ });
214
+ }
215
+ // ============================================================================
216
+ // Query Helpers
217
+ // ============================================================================
218
+ /**
219
+ * Get current metric value (latest gauge or counter sum)
220
+ */ export function getMetricValue(metricName) {
221
+ const telemetry = getGlobalTelemetry();
222
+ const metrics = telemetry.getMetrics(metricName);
223
+ if (metrics.length === 0) return 0;
224
+ // For counters, sum all values
225
+ if (metrics[0].type === 'counter') {
226
+ return metrics.reduce((sum, m)=>sum + m.value, 0);
227
+ }
228
+ // For gauges, return latest value
229
+ return metrics[metrics.length - 1].value;
230
+ }
231
+ /**
232
+ * Get metric breakdown by tag
233
+ */ export function getMetricBreakdown(metricName, tagKey) {
234
+ const telemetry = getGlobalTelemetry();
235
+ const metrics = telemetry.getMetrics(metricName);
236
+ const breakdown = {};
237
+ metrics.forEach((metric)=>{
238
+ const tagValue = metric.tags[tagKey] || 'unknown';
239
+ breakdown[tagValue] = (breakdown[tagValue] || 0) + metric.value;
240
+ });
241
+ return breakdown;
242
+ }
243
+ // ============================================================================
244
+ // Exports
245
+ // ============================================================================
246
+ export default {
247
+ // Core functions
248
+ incrementMetric,
249
+ recordGauge,
250
+ recordTiming,
251
+ measureExecution,
252
+ measureExecutionSync,
253
+ // Domain-specific trackers
254
+ trackProviderRouting,
255
+ trackAgentSpawn,
256
+ trackAgentCompletion,
257
+ trackTaskOrchestration,
258
+ trackSwarmOperation,
259
+ trackAPICall,
260
+ trackError,
261
+ trackMemoryUsage,
262
+ trackSubscriptionUsage,
263
+ // Query helpers
264
+ getMetricValue,
265
+ getMetricBreakdown
266
+ };
267
+
268
+ //# sourceMappingURL=metrics-counter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/observability/metrics-counter.ts"],"names":["getGlobalTelemetry","incrementMetric","metricName","value","tags","telemetry","recordCounter","recordGauge","recordTiming","durationMs","recordTimer","measureExecution","fn","start","Date","now","result","status","error","measureExecutionSync","trackProviderRouting","provider","tier","agentType","source","trackAgentSpawn","swarmId","topology","trackAgentCompletion","success","trackTaskOrchestration","taskType","strategy","agentCount","trackSwarmOperation","operation","undefined","trackAPICall","endpoint","method","statusCode","toString","trackError","errorType","component","severity","trackMemoryUsage","usage","process","memoryUsage","heapUsed","unit","heapTotal","rss","trackSubscriptionUsage","used","limit","remaining","utilizationPct","toFixed","getMetricValue","metrics","getMetrics","length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