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,385 @@
1
+ /**
2
+ * WebSocket Hook for Real-time Updates
3
+ * Provides WebSocket connection management for real-time dashboard updates
4
+ */ import { useState, useEffect, useRef, useCallback } from 'react';
5
+ import { io } from 'socket.io-client';
6
+ export const useWebSocket = (options = {})=>{
7
+ const { url = `ws://${window.location.host}`, autoConnect = true, reconnectAttempts = 5, reconnectDelay = 1000, heartbeatInterval = 30000, onConnect, onDisconnect, onError, onMessage } = options;
8
+ const [socket, setSocket] = useState(null);
9
+ const [status, setStatus] = useState({
10
+ connected: false,
11
+ reconnectAttempts: 0,
12
+ lastConnected: undefined,
13
+ lastMessage: undefined,
14
+ error: undefined
15
+ });
16
+ const [error, setError] = useState(null);
17
+ const [lastMessage, setLastMessage] = useState(null);
18
+ const socketRef = useRef(null);
19
+ const reconnectTimeoutRef = useRef();
20
+ const heartbeatIntervalRef = useRef();
21
+ const subscriptionsRef = useRef(new Map());
22
+ const connect = useCallback(()=>{
23
+ if (socketRef.current?.connected) {
24
+ return;
25
+ }
26
+ try {
27
+ const newSocket = io(url, {
28
+ transports: [
29
+ 'websocket',
30
+ 'polling'
31
+ ],
32
+ upgrade: true,
33
+ rememberUpgrade: true,
34
+ timeout: 10000,
35
+ forceNew: true
36
+ });
37
+ socketRef.current = newSocket;
38
+ setSocket(newSocket);
39
+ // Connection established
40
+ newSocket.on('connect', ()=>{
41
+ console.log('WebSocket connected');
42
+ setStatus((prev)=>({
43
+ ...prev,
44
+ connected: true,
45
+ reconnectAttempts: 0,
46
+ lastConnected: new Date(),
47
+ error: undefined
48
+ }));
49
+ setError(null);
50
+ onConnect?.();
51
+ // Start heartbeat
52
+ if (heartbeatIntervalRef.current) {
53
+ clearInterval(heartbeatIntervalRef.current);
54
+ }
55
+ heartbeatIntervalRef.current = setInterval(()=>{
56
+ if (newSocket.connected) {
57
+ newSocket.emit('ping');
58
+ }
59
+ }, heartbeatInterval);
60
+ // Request initial data
61
+ newSocket.emit('request-mcp-status');
62
+ newSocket.emit('request-swarm-metrics');
63
+ });
64
+ // Connection lost
65
+ newSocket.on('disconnect', (reason)=>{
66
+ console.log('WebSocket disconnected:', reason);
67
+ setStatus((prev)=>({
68
+ ...prev,
69
+ connected: false
70
+ }));
71
+ onDisconnect?.();
72
+ // Clear heartbeat
73
+ if (heartbeatIntervalRef.current) {
74
+ clearInterval(heartbeatIntervalRef.current);
75
+ }
76
+ // Auto-reconnect
77
+ if (reason !== 'io client disconnect' && status.reconnectAttempts < reconnectAttempts) {
78
+ const delay = reconnectDelay * Math.pow(2, status.reconnectAttempts);
79
+ console.log(`Reconnecting in ${delay}ms...`);
80
+ reconnectTimeoutRef.current = setTimeout(()=>{
81
+ setStatus((prev)=>({
82
+ ...prev,
83
+ reconnectAttempts: prev.reconnectAttempts + 1
84
+ }));
85
+ connect();
86
+ }, delay);
87
+ }
88
+ });
89
+ // Connection error
90
+ newSocket.on('connect_error', (error)=>{
91
+ console.error('WebSocket connection error:', error);
92
+ const errorMessage = error.message || 'Connection failed';
93
+ setError(errorMessage);
94
+ setStatus((prev)=>({
95
+ ...prev,
96
+ connected: false,
97
+ error: errorMessage
98
+ }));
99
+ onError?.(error);
100
+ });
101
+ // Handle messages
102
+ newSocket.on('message', (data)=>{
103
+ try {
104
+ const message = typeof data === 'string' ? JSON.parse(data) : data;
105
+ setLastMessage(message);
106
+ setStatus((prev)=>({
107
+ ...prev,
108
+ lastMessage: new Date()
109
+ }));
110
+ // Notify subscribers
111
+ const subscribers = subscriptionsRef.current.get(message.type);
112
+ if (subscribers) {
113
+ subscribers.forEach((callback)=>callback(message.payload));
114
+ }
115
+ onMessage?.(message);
116
+ } catch (error) {
117
+ console.error('Error parsing WebSocket message:', error);
118
+ }
119
+ });
120
+ // Handle specific dashboard events
121
+ newSocket.on('mcp-status', (data)=>{
122
+ const message = {
123
+ type: 'agent_update',
124
+ timestamp: new Date(),
125
+ payload: data
126
+ };
127
+ setLastMessage(message);
128
+ onMessage?.(message);
129
+ });
130
+ newSocket.on('swarm-metrics', (data)=>{
131
+ const message = {
132
+ type: 'metrics_update',
133
+ timestamp: new Date(),
134
+ payload: data
135
+ };
136
+ setLastMessage(message);
137
+ onMessage?.(message);
138
+ });
139
+ newSocket.on('hierarchy-change', (data)=>{
140
+ const message = {
141
+ type: 'hierarchy_change',
142
+ timestamp: new Date(),
143
+ payload: data
144
+ };
145
+ setLastMessage(message);
146
+ onMessage?.(message);
147
+ });
148
+ newSocket.on('event-stream', (data)=>{
149
+ const message = {
150
+ type: 'event_stream',
151
+ timestamp: new Date(),
152
+ payload: data
153
+ };
154
+ setLastMessage(message);
155
+ onMessage?.(message);
156
+ });
157
+ newSocket.on('error', (data)=>{
158
+ const message = {
159
+ type: 'error',
160
+ timestamp: new Date(),
161
+ payload: data
162
+ };
163
+ setLastMessage(message);
164
+ setError(data.message || 'WebSocket error');
165
+ onMessage?.(message);
166
+ });
167
+ // Heartbeat response
168
+ newSocket.on('pong', ()=>{
169
+ // Heartbeat received
170
+ });
171
+ } catch (error) {
172
+ console.error('Failed to create WebSocket connection:', error);
173
+ setError(error instanceof Error ? error.message : 'Unknown error');
174
+ onError?.(error instanceof Error ? error : new Error('Unknown error'));
175
+ }
176
+ }, [
177
+ url,
178
+ reconnectAttempts,
179
+ reconnectDelay,
180
+ heartbeatInterval,
181
+ status.reconnectAttempts,
182
+ onConnect,
183
+ onDisconnect,
184
+ onError,
185
+ onMessage
186
+ ]);
187
+ const disconnect = useCallback(()=>{
188
+ if (reconnectTimeoutRef.current) {
189
+ clearTimeout(reconnectTimeoutRef.current);
190
+ }
191
+ if (heartbeatIntervalRef.current) {
192
+ clearInterval(heartbeatIntervalRef.current);
193
+ }
194
+ if (socketRef.current) {
195
+ socketRef.current.disconnect();
196
+ socketRef.current = null;
197
+ }
198
+ setSocket(null);
199
+ setStatus((prev)=>({
200
+ ...prev,
201
+ connected: false
202
+ }));
203
+ }, []);
204
+ const reconnect = useCallback(()=>{
205
+ disconnect();
206
+ setTimeout(connect, 100);
207
+ }, [
208
+ disconnect,
209
+ connect
210
+ ]);
211
+ const sendMessage = useCallback((type, payload)=>{
212
+ if (socketRef.current?.connected) {
213
+ socketRef.current.emit('message', {
214
+ type,
215
+ payload
216
+ });
217
+ } else {
218
+ console.warn('WebSocket not connected, cannot send message:', type);
219
+ }
220
+ }, []);
221
+ const subscribe = useCallback((event, callback)=>{
222
+ if (!subscriptionsRef.current.has(event)) {
223
+ subscriptionsRef.current.set(event, new Set());
224
+ }
225
+ subscriptionsRef.current.get(event).add(callback);
226
+ // Return unsubscribe function
227
+ return ()=>{
228
+ const subscribers = subscriptionsRef.current.get(event);
229
+ if (subscribers) {
230
+ subscribers.delete(callback);
231
+ if (subscribers.size === 0) {
232
+ subscriptionsRef.current.delete(event);
233
+ }
234
+ }
235
+ };
236
+ }, []);
237
+ // Auto-connect on mount
238
+ useEffect(()=>{
239
+ if (autoConnect) {
240
+ connect();
241
+ }
242
+ return ()=>{
243
+ disconnect();
244
+ };
245
+ }, [
246
+ autoConnect,
247
+ connect,
248
+ disconnect
249
+ ]);
250
+ return {
251
+ socket,
252
+ status,
253
+ isConnected: status.connected,
254
+ error,
255
+ sendMessage,
256
+ subscribe,
257
+ disconnect,
258
+ reconnect,
259
+ lastMessage
260
+ };
261
+ };
262
+ // Higher-order hook for dashboard state management
263
+ export const useDashboardWebSocket = (initialData, options)=>{
264
+ const [dashboardState, setDashboardState] = useState({
265
+ agents: initialData.agents || [],
266
+ statuses: initialData.statuses || {},
267
+ events: initialData.events || [],
268
+ metrics: initialData.metrics || null,
269
+ alerts: initialData.alerts || [],
270
+ resourceUsage: initialData.resourceUsage || {
271
+ memoryUsage: 0,
272
+ cpuUsage: 0,
273
+ networkLatency: 0,
274
+ diskUsage: 0
275
+ },
276
+ filters: initialData.filters || {},
277
+ loading: initialData.loading || false,
278
+ error: initialData.error || null,
279
+ lastUpdated: initialData.lastUpdated || null,
280
+ connected: initialData.connected || false
281
+ });
282
+ const webSocket = useWebSocket({
283
+ ...options,
284
+ onMessage: (message)=>{
285
+ switch(message.type){
286
+ case 'agent_update':
287
+ setDashboardState((prev)=>({
288
+ ...prev,
289
+ statuses: {
290
+ ...prev.statuses,
291
+ ...message.payload.statuses
292
+ },
293
+ lastUpdated: new Date()
294
+ }));
295
+ break;
296
+ case 'hierarchy_change':
297
+ setDashboardState((prev)=>({
298
+ ...prev,
299
+ agents: message.payload.agents || prev.agents,
300
+ lastUpdated: new Date()
301
+ }));
302
+ break;
303
+ case 'metrics_update':
304
+ setDashboardState((prev)=>({
305
+ ...prev,
306
+ metrics: message.payload.metrics || prev.metrics,
307
+ resourceUsage: message.payload.resourceUsage || prev.resourceUsage,
308
+ alerts: message.payload.alerts || prev.alerts,
309
+ lastUpdated: new Date()
310
+ }));
311
+ break;
312
+ case 'event_stream':
313
+ setDashboardState((prev)=>({
314
+ ...prev,
315
+ events: [
316
+ message.payload.event,
317
+ ...prev.events.slice(0, 999)
318
+ ],
319
+ lastUpdated: new Date()
320
+ }));
321
+ break;
322
+ case 'error':
323
+ setDashboardState((prev)=>({
324
+ ...prev,
325
+ error: message.payload.message,
326
+ lastUpdated: new Date()
327
+ }));
328
+ break;
329
+ }
330
+ options?.onMessage?.(message);
331
+ },
332
+ onConnect: ()=>{
333
+ setDashboardState((prev)=>({
334
+ ...prev,
335
+ connected: true,
336
+ error: null,
337
+ lastUpdated: new Date()
338
+ }));
339
+ options?.onConnect?.();
340
+ },
341
+ onDisconnect: ()=>{
342
+ setDashboardState((prev)=>({
343
+ ...prev,
344
+ connected: false,
345
+ lastUpdated: new Date()
346
+ }));
347
+ options?.onDisconnect?.();
348
+ },
349
+ onError: (error)=>{
350
+ setDashboardState((prev)=>({
351
+ ...prev,
352
+ connected: false,
353
+ error: error.message,
354
+ lastUpdated: new Date()
355
+ }));
356
+ options?.onError?.(error);
357
+ }
358
+ });
359
+ const refreshData = useCallback(()=>{
360
+ if (webSocket.isConnected) {
361
+ webSocket.sendMessage('refresh', {});
362
+ }
363
+ }, [
364
+ webSocket
365
+ ]);
366
+ const updateFilters = useCallback((filters)=>{
367
+ setDashboardState((prev)=>({
368
+ ...prev,
369
+ filters: {
370
+ ...prev.filters,
371
+ ...filters
372
+ }
373
+ }));
374
+ }, []);
375
+ return {
376
+ ...webSocket,
377
+ dashboardState,
378
+ setDashboardState,
379
+ refreshData,
380
+ updateFilters
381
+ };
382
+ };
383
+ export default useWebSocket;
384
+
385
+ //# sourceMappingURL=useWebSocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/web/dashboard/hooks/useWebSocket.ts"],"names":["useState","useEffect","useRef","useCallback","io","useWebSocket","options","url","window","location","host","autoConnect","reconnectAttempts","reconnectDelay","heartbeatInterval","onConnect","onDisconnect","onError","onMessage","socket","setSocket","status","setStatus","connected","lastConnected","undefined","lastMessage","error","setError","setLastMessage","socketRef","reconnectTimeoutRef","heartbeatIntervalRef","subscriptionsRef","Map","connect","current","newSocket","transports","upgrade","rememberUpgrade","timeout","forceNew","on","console","log","prev","Date","clearInterval","setInterval","emit","reason","delay","Math","pow","setTimeout","errorMessage","message","data","JSON","parse","subscribers","get","type","forEach","callback","payload","timestamp","Error","disconnect","clearTimeout","reconnect","sendMessage","warn","subscribe","event","has","set","Set","add","delete","size","isConnected","useDashboardWebSocket","initialData","dashboardState","setDashboardState","agents","statuses","events","metrics","alerts","resourceUsage","memoryUsage","cpuUsage","networkLatency","diskUsage","filters","loading","lastUpdated","webSocket","slice","refreshData","updateFilters"],"mappings":"AAAA;;;CAGC,GAED,SAASA,QAAQ,EAAEC,SAAS,EAAEC,MAAM,EAAEC,WAAW,QAAQ,QAAQ;AACjE,SAASC,EAAE,QAAgB,mBAAmB;AA2B9C,OAAO,MAAMC,eAAe,CAACC,UAA+B,CAAC,CAAC;IAC5D,MAAM,EACJC,MAAM,CAAC,KAAK,EAAEC,OAAOC,QAAQ,CAACC,IAAI,EAAE,EACpCC,cAAc,IAAI,EAClBC,oBAAoB,CAAC,EACrBC,iBAAiB,IAAI,EACrBC,oBAAoB,KAAK,EACzBC,SAAS,EACTC,YAAY,EACZC,OAAO,EACPC,SAAS,EACV,GAAGZ;IAEJ,MAAM,CAACa,QAAQC,UAAU,GAAGpB,SAAwB;IACpD,MAAM,CAACqB,QAAQC,UAAU,GAAGtB,SAA0B;QACpDuB,WAAW;QACXX,mBAAmB;QACnBY,eAAeC;QACfC,aAAaD;QACbE,OAAOF;IACT;IACA,MAAM,CAACE,OAAOC,SAAS,GAAG5B,SAAwB;IAClD,MAAM,CAAC0B,aAAaG,eAAe,GAAG7B,SAAkC;IAExE,MAAM8B,YAAY5B,OAAsB;IACxC,MAAM6B,sBAAsB7B;IAC5B,MAAM8B,uBAAuB9B;IAC7B,MAAM+B,mBAAmB/B,OAA8C,IAAIgC;IAE3E,MAAMC,UAAUhC,YAAY;QAC1B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S;oBAAE,GAAGnD,KAAKmD,OAAO;oBAAE,GAAGA,OAAO;gBAAC;YACzC,CAAA;IACF,GAAG,EAAE;IAEL,OAAO;QACL,GAAGG,SAAS;QACZf;QACAC;QACAgB;QACAC;IACF;AACF,EAAE;AAEF,eAAelG,aAAa"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Dashboard Module Exports
3
+ * Central export point for all dashboard components and utilities
4
+ */ // Main Components
5
+ export { default as Dashboard } from './Dashboard';
6
+ export { default as AgentHierarchyTree } from './components/AgentHierarchyTree';
7
+ export { default as AgentStatusMonitor } from './components/AgentStatusMonitor';
8
+ export { default as PerformanceMetricsChart } from './components/PerformanceMetricsChart';
9
+ export { default as EventTimeline } from './components/EventTimeline';
10
+ export { default as ResourceGauges } from './components/ResourceGauges';
11
+ // Hooks
12
+ export { useWebSocket, useDashboardWebSocket } from './hooks/useWebSocket';
13
+ // Utilities
14
+ export const createDashboardConfig = (overrides = {})=>({
15
+ refreshInterval: 5000,
16
+ maxEvents: 1000,
17
+ enableAnimations: true,
18
+ theme: 'light',
19
+ autoRefresh: true,
20
+ ...overrides
21
+ });
22
+ export const formatBytes = (bytes)=>{
23
+ const sizes = [
24
+ 'B',
25
+ 'KB',
26
+ 'MB',
27
+ 'GB',
28
+ 'TB'
29
+ ];
30
+ if (bytes === 0) return '0 B';
31
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
32
+ return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${sizes[i]}`;
33
+ };
34
+ export const formatDuration = (ms)=>{
35
+ const seconds = Math.floor(ms / 1000);
36
+ const minutes = Math.floor(seconds / 60);
37
+ const hours = Math.floor(minutes / 60);
38
+ if (hours > 0) return `${hours}h ${minutes % 60}m`;
39
+ if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
40
+ return `${seconds}s`;
41
+ };
42
+ export const getAgentStateColor = (state)=>{
43
+ switch(state){
44
+ case 'active':
45
+ return 'text-green-600 bg-green-50 border-green-200';
46
+ case 'paused':
47
+ return 'text-yellow-600 bg-yellow-50 border-yellow-200';
48
+ case 'error':
49
+ return 'text-red-600 bg-red-50 border-red-200';
50
+ case 'terminated':
51
+ return 'text-gray-600 bg-gray-50 border-gray-200';
52
+ default:
53
+ return 'text-blue-600 bg-blue-50 border-blue-200';
54
+ }
55
+ };
56
+ export const getAlertSeverityColor = (severity)=>{
57
+ switch(severity){
58
+ case 'critical':
59
+ return 'text-red-600 bg-red-50 border-red-200';
60
+ case 'high':
61
+ return 'text-orange-600 bg-orange-50 border-orange-200';
62
+ case 'medium':
63
+ return 'text-yellow-600 bg-yellow-50 border-yellow-200';
64
+ case 'low':
65
+ return 'text-blue-600 bg-blue-50 border-blue-200';
66
+ default:
67
+ return 'text-gray-600 bg-gray-50 border-gray-200';
68
+ }
69
+ };
70
+ // Default export
71
+ export default {
72
+ Dashboard,
73
+ AgentHierarchyTree,
74
+ AgentStatusMonitor,
75
+ PerformanceMetricsChart,
76
+ EventTimeline,
77
+ ResourceGauges,
78
+ useWebSocket,
79
+ useDashboardWebSocket,
80
+ createDashboardConfig,
81
+ formatBytes,
82
+ formatDuration,
83
+ getAgentStateColor,
84
+ getAlertSeverityColor
85
+ };
86
+
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/web/dashboard/index.ts"],"names":["default","Dashboard","AgentHierarchyTree","AgentStatusMonitor","PerformanceMetricsChart","EventTimeline","ResourceGauges","useWebSocket","useDashboardWebSocket","createDashboardConfig","overrides","refreshInterval","maxEvents","enableAnimations","theme","autoRefresh","formatBytes","bytes","sizes","i","Math","floor","log","pow","toFixed","formatDuration","ms","seconds","minutes","hours","getAgentStateColor","state","getAlertSeverityColor","severity"],"mappings":"AAAA;;;CAGC,GAED,kBAAkB;AAClB,SAASA,WAAWC,SAAS,QAAQ,cAAc;AACnD,SAASD,WAAWE,kBAAkB,QAAQ,kCAAkC;AAChF,SAASF,WAAWG,kBAAkB,QAAQ,kCAAkC;AAChF,SA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Ac,OAAO;QAC1B;YAAS,OAAO;IAClB;AACF,EAAE;AAEF,OAAO,MAAMC,wBAAwB,CAACC;IACpC,OAAQA;QACN,KAAK;YAAY,OAAO;QACxB,KAAK;YAAQ,OAAO;QACpB,KAAK;YAAU,OAAO;QACtB,KAAK;YAAO,OAAO;QACnB;YAAS,OAAO;IAClB;AACF,EAAE;AAEF,iBAAiB;AACjB,eAAe;IACbhC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAO;IACAS;IACAK;IACAE;AACF,EAAE"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Dashboard Types for Agent Lifecycle Transparency System
3
+ * TypeScript interfaces and type definitions for the React dashboard
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/web/dashboard/types.ts"],"names":[],"mappings":"AAAA;;;CAGC,GAmRD,WAGC"}
Binary file
package/CLAUDE.md CHANGED
@@ -390,6 +390,35 @@ claude mcp add claude-flow-novice npx claude-flow-novice mcp start
390
390
  }
391
391
  ```
392
392
 
393
+ **🚨 MANDATORY: Post-Edit Hook Execution**
394
+
395
+ **CRITICAL**: Every primary swarm agent MUST run the post-edit-pipeline hook after EVERY file edit:
396
+
397
+ ```bash
398
+ # REQUIRED after each file modification
399
+ node config/hooks/post-edit-pipeline.js "[FILE_PATH]" --memory-key "swarm/[agent]/[step]"
400
+ ```
401
+
402
+ **Agent Instructions Template:**
403
+ ```
404
+ Task("Agent Name", `
405
+ Your implementation task here...
406
+
407
+ MANDATORY: After EVERY file edit, run:
408
+ node config/hooks/post-edit-pipeline.js "[FILE_PATH]" --memory-key "swarm/[agent-name]/step-[N]"
409
+
410
+ Report confidence score when complete.
411
+ `, "agent-type")
412
+ ```
413
+
414
+ **Post-Edit Hook Benefits:**
415
+ - Real-time validation (formatting, linting, type checking)
416
+ - Security scanning (hardcoded credentials, XSS, eval())
417
+ - Single-file testing (1-5s vs 10-60s full suite)
418
+ - TDD compliance detection (Red-Green-Refactor phases)
419
+ - Rust quality checks (unwrap/expect/panic with line numbers)
420
+ - Coverage tracking (Jest, pytest, cargo-tarpaulin)
421
+
393
422
  **Confidence Score Interpretation:**
394
423
  - **0.90-1.00**: Excellent - production ready
395
424
  - **0.75-0.89**: Good - minor improvements possible
package/README.md CHANGED
@@ -121,6 +121,33 @@ const result = await orchestrator.executePhase({
121
121
  - 🚀 [Sprint Orchestration](docs/SPRINT_ORCHESTRATION.md) - Two-tier phase/sprint system guide
122
122
  - 🎯 [Scope Control](docs/CFN_LOOP_SCOPE_CONTROL.md) - Product Owner GOAP-based scope enforcement (NEW)
123
123
  - 🎯 [MCP Endpoints](planning/COMPREHENSIVE_MCP_ENDPOINTS_REFERENCE.md) - Complete reference including CFN Loop commands
124
+ - 🔄 [CFN Claude Sync](docs/slash-commands/cfn-claude-sync-usage.md) - DRY principle: sync CLAUDE.md to slash commands (NEW)
125
+
126
+ ### CFN Claude Sync - Configuration Management (NEW in v1.6.1)
127
+
128
+ **Single Source of Truth**: Maintain CFN Loop configuration in one place (CLAUDE.md) and automatically sync to all slash command files.
129
+
130
+ ```bash
131
+ # After editing CLAUDE.md CFN Loop rules:
132
+ /cfn-claude-sync --dry-run # Preview changes
133
+ /cfn-claude-sync # Apply to 8 files (4 markdown + 4 JS)
134
+ npm test # Validate
135
+ git commit -m "chore: sync CFN Loop from CLAUDE.md"
136
+ ```
137
+
138
+ **What Gets Synchronized**:
139
+ - ✅ Consensus threshold (≥90%)
140
+ - ✅ Confidence gate (≥75%)
141
+ - ✅ Loop 2/3 max iterations (10/10)
142
+ - ✅ Complexity tiers (Simple: 2-3, Medium: 4-6, Complex: 8-12, Enterprise: 15-20)
143
+ - ✅ GOAP decision types (PROCEED/DEFER/ESCALATE)
144
+ - ✅ Autonomous execution rules
145
+
146
+ **Files Updated**:
147
+ - `.claude/commands/cfn-loop*.md` (4 markdown templates)
148
+ - `src/slash-commands/cfn-loop*.js` (4 JavaScript generators)
149
+
150
+ **Why This Matters**: Edit once in CLAUDE.md instead of manually updating 9 files. Eliminates duplication and ensures consistency.
124
151
 
125
152
  ## 🚀 Quick Start
126
153
 
@@ -635,8 +635,14 @@ class SingleFileTestEngine {
635
635
 
636
636
  async runCargoTestSingleFile(file) {
637
637
  try {
638
- const result = await execAsync(`cargo test --message-format=json`, {
639
- cwd: path.dirname(file)
638
+ // Extract module name from file path for targeted testing
639
+ const moduleName = this.extractRustModuleName(file);
640
+ const testFilter = moduleName ? `--test ${moduleName}` : '';
641
+
642
+ // Run only tests for this specific file/module, not full compilation
643
+ const result = await execAsync(`cargo test ${testFilter} --message-format=json --no-fail-fast -- --nocapture`, {
644
+ cwd: this.findCargoRoot(file),
645
+ timeout: 30000 // 30 second timeout for single file
640
646
  });
641
647
 
642
648
  const lines = result.stdout.trim().split('\n');
@@ -697,6 +703,34 @@ class SingleFileTestEngine {
697
703
  };
698
704
  }
699
705
 
706
+ // Rust-specific helpers
707
+ extractRustModuleName(file) {
708
+ // Extract module name from file path
709
+ // e.g., src/services/email.rs → services::email
710
+ const cargoRoot = this.findCargoRoot(file);
711
+ const relative = path.relative(cargoRoot, file);
712
+ const modulePath = relative
713
+ .replace(/^src\//, '')
714
+ .replace(/\.rs$/, '')
715
+ .replace(/\//g, '::')
716
+ .replace(/\\/, '::'); // Windows paths
717
+ return modulePath;
718
+ }
719
+
720
+ findCargoRoot(file) {
721
+ // Walk up directory tree to find Cargo.toml
722
+ let dir = path.dirname(file);
723
+ for (let i = 0; i < 10; i++) { // Limit depth to prevent infinite loop
724
+ if (fsSync.existsSync(path.join(dir, 'Cargo.toml'))) {
725
+ return dir;
726
+ }
727
+ const parent = path.dirname(dir);
728
+ if (parent === dir) break; // Reached root
729
+ dir = parent;
730
+ }
731
+ return path.dirname(file); // Fallback to file directory
732
+ }
733
+
700
734
  // Coverage analysis
701
735
  async getJestCoverage(file) {
702
736
  try {