claude-flow 3.25.6 → 3.26.0

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 (311) hide show
  1. package/.claude/helpers/.helpers-version +1 -1
  2. package/.claude/helpers/helpers.manifest.json +5 -4
  3. package/.claude/helpers/hook-handler.cjs +129 -0
  4. package/.claude/helpers/intelligence.cjs +10 -0
  5. package/.claude/helpers/statusline.cjs +300 -123
  6. package/.claude/proven-config.json +1 -1
  7. package/.claude/security-scans/scan-all-standard.json +321 -0
  8. package/.claude/security-scans/scan-code-deep.json +1209 -0
  9. package/.claude/security-scans/scan-deps-full.json +14 -0
  10. package/package.json +3 -1
  11. package/v3/@claude-flow/cli/catalog-manifest.json +12 -0
  12. package/v3/@claude-flow/cli/dist/src/commands/advisor.d.ts +15 -0
  13. package/v3/@claude-flow/cli/dist/src/commands/advisor.js +94 -0
  14. package/v3/@claude-flow/cli/dist/src/commands/doctor.js +77 -3
  15. package/v3/@claude-flow/cli/dist/src/commands/funnel.d.ts +13 -0
  16. package/v3/@claude-flow/cli/dist/src/commands/funnel.js +103 -0
  17. package/v3/@claude-flow/cli/dist/src/commands/hooks.js +112 -46
  18. package/v3/@claude-flow/cli/dist/src/commands/index.js +10 -0
  19. package/v3/@claude-flow/cli/dist/src/commands/init.js +44 -0
  20. package/v3/@claude-flow/cli/dist/src/commands/proxy.d.ts +21 -0
  21. package/v3/@claude-flow/cli/dist/src/commands/proxy.js +310 -0
  22. package/v3/@claude-flow/cli/dist/src/commands/security.js +29 -0
  23. package/v3/@claude-flow/cli/dist/src/commands/settings.d.ts +19 -0
  24. package/v3/@claude-flow/cli/dist/src/commands/settings.js +180 -0
  25. package/v3/@claude-flow/cli/dist/src/commands/version.d.ts +42 -0
  26. package/v3/@claude-flow/cli/dist/src/commands/version.js +106 -0
  27. package/v3/@claude-flow/cli/dist/src/funnel/advisor-tip.d.ts +58 -0
  28. package/v3/@claude-flow/cli/dist/src/funnel/advisor-tip.js +92 -0
  29. package/v3/@claude-flow/cli/dist/src/funnel/attribution.d.ts +37 -0
  30. package/v3/@claude-flow/cli/dist/src/funnel/attribution.js +101 -0
  31. package/v3/@claude-flow/cli/dist/src/funnel/consent.d.ts +22 -0
  32. package/v3/@claude-flow/cli/dist/src/funnel/consent.js +55 -0
  33. package/v3/@claude-flow/cli/dist/src/funnel/credit-errors.d.ts +31 -0
  34. package/v3/@claude-flow/cli/dist/src/funnel/credit-errors.js +88 -0
  35. package/v3/@claude-flow/cli/dist/src/funnel/credit-notifier.d.ts +44 -0
  36. package/v3/@claude-flow/cli/dist/src/funnel/credit-notifier.js +74 -0
  37. package/v3/@claude-flow/cli/dist/src/funnel/disclosure.d.ts +46 -0
  38. package/v3/@claude-flow/cli/dist/src/funnel/disclosure.js +97 -0
  39. package/v3/@claude-flow/cli/dist/src/funnel/enrollment.d.ts +36 -0
  40. package/v3/@claude-flow/cli/dist/src/funnel/enrollment.js +64 -0
  41. package/v3/@claude-flow/cli/dist/src/funnel/environment.d.ts +17 -0
  42. package/v3/@claude-flow/cli/dist/src/funnel/environment.js +39 -0
  43. package/v3/@claude-flow/cli/dist/src/funnel/event-transport.d.ts +51 -0
  44. package/v3/@claude-flow/cli/dist/src/funnel/event-transport.js +199 -0
  45. package/v3/@claude-flow/cli/dist/src/funnel/events.d.ts +42 -0
  46. package/v3/@claude-flow/cli/dist/src/funnel/events.js +150 -0
  47. package/v3/@claude-flow/cli/dist/src/funnel/index.d.ts +20 -0
  48. package/v3/@claude-flow/cli/dist/src/funnel/index.js +20 -0
  49. package/v3/@claude-flow/cli/dist/src/funnel/insights.d.ts +49 -0
  50. package/v3/@claude-flow/cli/dist/src/funnel/insights.js +120 -0
  51. package/v3/@claude-flow/cli/dist/src/funnel/local-signals.d.ts +15 -0
  52. package/v3/@claude-flow/cli/dist/src/funnel/local-signals.js +68 -0
  53. package/v3/@claude-flow/cli/dist/src/funnel/message-transport.d.ts +51 -0
  54. package/v3/@claude-flow/cli/dist/src/funnel/message-transport.js +149 -0
  55. package/v3/@claude-flow/cli/dist/src/funnel/messages.d.ts +55 -0
  56. package/v3/@claude-flow/cli/dist/src/funnel/messages.js +160 -0
  57. package/v3/@claude-flow/cli/dist/src/funnel/power-saver-notifier.d.ts +44 -0
  58. package/v3/@claude-flow/cli/dist/src/funnel/power-saver-notifier.js +92 -0
  59. package/v3/@claude-flow/cli/dist/src/funnel/precedence.d.ts +16 -0
  60. package/v3/@claude-flow/cli/dist/src/funnel/precedence.js +85 -0
  61. package/v3/@claude-flow/cli/dist/src/funnel/promo.d.ts +41 -0
  62. package/v3/@claude-flow/cli/dist/src/funnel/promo.js +144 -0
  63. package/v3/@claude-flow/cli/dist/src/funnel/rate-limit-notifier.d.ts +55 -0
  64. package/v3/@claude-flow/cli/dist/src/funnel/rate-limit-notifier.js +102 -0
  65. package/v3/@claude-flow/cli/dist/src/funnel/rotation.d.ts +19 -0
  66. package/v3/@claude-flow/cli/dist/src/funnel/rotation.js +70 -0
  67. package/v3/@claude-flow/cli/dist/src/funnel/state.d.ts +13 -0
  68. package/v3/@claude-flow/cli/dist/src/funnel/state.js +52 -0
  69. package/v3/@claude-flow/cli/dist/src/funnel/toggle-cooldown.d.ts +17 -0
  70. package/v3/@claude-flow/cli/dist/src/funnel/toggle-cooldown.js +32 -0
  71. package/v3/@claude-flow/cli/dist/src/funnel/types.d.ts +86 -0
  72. package/v3/@claude-flow/cli/dist/src/funnel/types.js +26 -0
  73. package/v3/@claude-flow/cli/dist/src/init/executor.js +9 -3
  74. package/v3/@claude-flow/cli/dist/src/init/helper-refresh.d.ts +33 -2
  75. package/v3/@claude-flow/cli/dist/src/init/helper-refresh.js +102 -12
  76. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +52 -0
  77. package/v3/@claude-flow/cli/dist/src/init/statusline-generator.js +282 -116
  78. package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.js +28 -5
  79. package/v3/@claude-flow/cli/dist/src/services/fable-harness.d.ts +39 -0
  80. package/v3/@claude-flow/cli/dist/src/services/fable-harness.js +41 -0
  81. package/v3/@claude-flow/cli/package.json +13 -4
  82. package/.claude/coordinator/config.json +0 -24
  83. package/.claude/coordinator/state.json +0 -37
  84. package/.claude/coordinator/tick-log/tick-01.json +0 -17
  85. package/.claude/coordinator/tick-log/tick-02.json +0 -17
  86. package/.claude/coordinator/tick-log/tick-03.json +0 -17
  87. package/.claude/coordinator/tick-log/tick-04.json +0 -14
  88. package/.claude/coordinator/tick-log/tick-05.json +0 -16
  89. package/.claude/settings.local.json +0 -11
  90. package/v3/@claude-flow/cli/dist/src/ruvector/lattice-wasm.d.ts +0 -14
  91. package/v3/@claude-flow/cli/dist/src/ruvector/lattice-wasm.js +0 -144
  92. package/v3/@claude-flow/guidance/dist/adversarial.d.ts +0 -284
  93. package/v3/@claude-flow/guidance/dist/adversarial.js +0 -572
  94. package/v3/@claude-flow/guidance/dist/analyzer.d.ts +0 -530
  95. package/v3/@claude-flow/guidance/dist/analyzer.js +0 -2587
  96. package/v3/@claude-flow/guidance/dist/artifacts.d.ts +0 -283
  97. package/v3/@claude-flow/guidance/dist/artifacts.js +0 -356
  98. package/v3/@claude-flow/guidance/dist/authority.d.ts +0 -290
  99. package/v3/@claude-flow/guidance/dist/authority.js +0 -558
  100. package/v3/@claude-flow/guidance/dist/capabilities.d.ts +0 -209
  101. package/v3/@claude-flow/guidance/dist/capabilities.js +0 -485
  102. package/v3/@claude-flow/guidance/dist/coherence.d.ts +0 -233
  103. package/v3/@claude-flow/guidance/dist/coherence.js +0 -372
  104. package/v3/@claude-flow/guidance/dist/compiler.d.ts +0 -87
  105. package/v3/@claude-flow/guidance/dist/compiler.js +0 -410
  106. package/v3/@claude-flow/guidance/dist/conformance-kit.d.ts +0 -225
  107. package/v3/@claude-flow/guidance/dist/conformance-kit.js +0 -629
  108. package/v3/@claude-flow/guidance/dist/continue-gate.d.ts +0 -214
  109. package/v3/@claude-flow/guidance/dist/continue-gate.js +0 -353
  110. package/v3/@claude-flow/guidance/dist/crypto-utils.d.ts +0 -17
  111. package/v3/@claude-flow/guidance/dist/crypto-utils.js +0 -24
  112. package/v3/@claude-flow/guidance/dist/evolution.d.ts +0 -282
  113. package/v3/@claude-flow/guidance/dist/evolution.js +0 -500
  114. package/v3/@claude-flow/guidance/dist/gates.d.ts +0 -79
  115. package/v3/@claude-flow/guidance/dist/gates.js +0 -302
  116. package/v3/@claude-flow/guidance/dist/gateway.d.ts +0 -206
  117. package/v3/@claude-flow/guidance/dist/gateway.js +0 -452
  118. package/v3/@claude-flow/guidance/dist/generators.d.ts +0 -153
  119. package/v3/@claude-flow/guidance/dist/generators.js +0 -682
  120. package/v3/@claude-flow/guidance/dist/headless.d.ts +0 -177
  121. package/v3/@claude-flow/guidance/dist/headless.js +0 -342
  122. package/v3/@claude-flow/guidance/dist/hooks.d.ts +0 -109
  123. package/v3/@claude-flow/guidance/dist/hooks.js +0 -347
  124. package/v3/@claude-flow/guidance/dist/index.d.ts +0 -205
  125. package/v3/@claude-flow/guidance/dist/index.js +0 -321
  126. package/v3/@claude-flow/guidance/dist/ledger.d.ts +0 -162
  127. package/v3/@claude-flow/guidance/dist/ledger.js +0 -375
  128. package/v3/@claude-flow/guidance/dist/manifest-validator.d.ts +0 -289
  129. package/v3/@claude-flow/guidance/dist/manifest-validator.js +0 -838
  130. package/v3/@claude-flow/guidance/dist/memory-gate.d.ts +0 -222
  131. package/v3/@claude-flow/guidance/dist/memory-gate.js +0 -382
  132. package/v3/@claude-flow/guidance/dist/meta-governance.d.ts +0 -265
  133. package/v3/@claude-flow/guidance/dist/meta-governance.js +0 -348
  134. package/v3/@claude-flow/guidance/dist/optimizer.d.ts +0 -104
  135. package/v3/@claude-flow/guidance/dist/optimizer.js +0 -329
  136. package/v3/@claude-flow/guidance/dist/persistence.d.ts +0 -189
  137. package/v3/@claude-flow/guidance/dist/persistence.js +0 -464
  138. package/v3/@claude-flow/guidance/dist/proof.d.ts +0 -185
  139. package/v3/@claude-flow/guidance/dist/proof.js +0 -238
  140. package/v3/@claude-flow/guidance/dist/retriever.d.ts +0 -172
  141. package/v3/@claude-flow/guidance/dist/retriever.js +0 -596
  142. package/v3/@claude-flow/guidance/dist/ruvbot-integration.d.ts +0 -370
  143. package/v3/@claude-flow/guidance/dist/ruvbot-integration.js +0 -738
  144. package/v3/@claude-flow/guidance/dist/temporal.d.ts +0 -426
  145. package/v3/@claude-flow/guidance/dist/temporal.js +0 -658
  146. package/v3/@claude-flow/guidance/dist/trust.d.ts +0 -283
  147. package/v3/@claude-flow/guidance/dist/trust.js +0 -473
  148. package/v3/@claude-flow/guidance/dist/truth-anchors.d.ts +0 -276
  149. package/v3/@claude-flow/guidance/dist/truth-anchors.js +0 -488
  150. package/v3/@claude-flow/guidance/dist/types.d.ts +0 -378
  151. package/v3/@claude-flow/guidance/dist/types.js +0 -10
  152. package/v3/@claude-flow/guidance/dist/uncertainty.d.ts +0 -372
  153. package/v3/@claude-flow/guidance/dist/uncertainty.js +0 -619
  154. package/v3/@claude-flow/guidance/dist/wasm-kernel.d.ts +0 -48
  155. package/v3/@claude-flow/guidance/dist/wasm-kernel.js +0 -158
  156. package/v3/@claude-flow/shared/dist/core/config/defaults.d.ts +0 -41
  157. package/v3/@claude-flow/shared/dist/core/config/defaults.js +0 -186
  158. package/v3/@claude-flow/shared/dist/core/config/index.d.ts +0 -8
  159. package/v3/@claude-flow/shared/dist/core/config/index.js +0 -12
  160. package/v3/@claude-flow/shared/dist/core/config/loader.d.ts +0 -45
  161. package/v3/@claude-flow/shared/dist/core/config/loader.js +0 -238
  162. package/v3/@claude-flow/shared/dist/core/config/schema.d.ts +0 -1728
  163. package/v3/@claude-flow/shared/dist/core/config/schema.js +0 -160
  164. package/v3/@claude-flow/shared/dist/core/config/validator.d.ts +0 -92
  165. package/v3/@claude-flow/shared/dist/core/config/validator.js +0 -147
  166. package/v3/@claude-flow/shared/dist/core/event-bus.d.ts +0 -31
  167. package/v3/@claude-flow/shared/dist/core/event-bus.js +0 -197
  168. package/v3/@claude-flow/shared/dist/core/index.d.ts +0 -15
  169. package/v3/@claude-flow/shared/dist/core/index.js +0 -19
  170. package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +0 -200
  171. package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.js +0 -6
  172. package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +0 -310
  173. package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +0 -7
  174. package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +0 -224
  175. package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.js +0 -46
  176. package/v3/@claude-flow/shared/dist/core/interfaces/index.d.ts +0 -10
  177. package/v3/@claude-flow/shared/dist/core/interfaces/index.js +0 -15
  178. package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +0 -298
  179. package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.js +0 -7
  180. package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +0 -185
  181. package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.js +0 -6
  182. package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +0 -35
  183. package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +0 -101
  184. package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +0 -60
  185. package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +0 -166
  186. package/v3/@claude-flow/shared/dist/core/orchestrator/index.d.ts +0 -46
  187. package/v3/@claude-flow/shared/dist/core/orchestrator/index.js +0 -64
  188. package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +0 -56
  189. package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +0 -195
  190. package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +0 -83
  191. package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.js +0 -193
  192. package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +0 -49
  193. package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.js +0 -253
  194. package/v3/@claude-flow/shared/dist/events/domain-events.d.ts +0 -282
  195. package/v3/@claude-flow/shared/dist/events/domain-events.js +0 -165
  196. package/v3/@claude-flow/shared/dist/events/event-store.d.ts +0 -126
  197. package/v3/@claude-flow/shared/dist/events/event-store.js +0 -427
  198. package/v3/@claude-flow/shared/dist/events/event-store.test.d.ts +0 -8
  199. package/v3/@claude-flow/shared/dist/events/event-store.test.js +0 -293
  200. package/v3/@claude-flow/shared/dist/events/example-usage.d.ts +0 -10
  201. package/v3/@claude-flow/shared/dist/events/example-usage.js +0 -193
  202. package/v3/@claude-flow/shared/dist/events/index.d.ts +0 -21
  203. package/v3/@claude-flow/shared/dist/events/index.js +0 -22
  204. package/v3/@claude-flow/shared/dist/events/projections.d.ts +0 -177
  205. package/v3/@claude-flow/shared/dist/events/projections.js +0 -421
  206. package/v3/@claude-flow/shared/dist/events/rvf-event-log.d.ts +0 -82
  207. package/v3/@claude-flow/shared/dist/events/rvf-event-log.js +0 -340
  208. package/v3/@claude-flow/shared/dist/events/state-reconstructor.d.ts +0 -101
  209. package/v3/@claude-flow/shared/dist/events/state-reconstructor.js +0 -263
  210. package/v3/@claude-flow/shared/dist/events.d.ts +0 -80
  211. package/v3/@claude-flow/shared/dist/events.js +0 -249
  212. package/v3/@claude-flow/shared/dist/hooks/example-usage.d.ts +0 -42
  213. package/v3/@claude-flow/shared/dist/hooks/example-usage.js +0 -351
  214. package/v3/@claude-flow/shared/dist/hooks/executor.d.ts +0 -100
  215. package/v3/@claude-flow/shared/dist/hooks/executor.js +0 -267
  216. package/v3/@claude-flow/shared/dist/hooks/hooks.test.d.ts +0 -9
  217. package/v3/@claude-flow/shared/dist/hooks/hooks.test.js +0 -322
  218. package/v3/@claude-flow/shared/dist/hooks/index.d.ts +0 -52
  219. package/v3/@claude-flow/shared/dist/hooks/index.js +0 -51
  220. package/v3/@claude-flow/shared/dist/hooks/registry.d.ts +0 -133
  221. package/v3/@claude-flow/shared/dist/hooks/registry.js +0 -277
  222. package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +0 -105
  223. package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.js +0 -481
  224. package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +0 -144
  225. package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.js +0 -328
  226. package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +0 -158
  227. package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.js +0 -450
  228. package/v3/@claude-flow/shared/dist/hooks/safety/index.d.ts +0 -17
  229. package/v3/@claude-flow/shared/dist/hooks/safety/index.js +0 -17
  230. package/v3/@claude-flow/shared/dist/hooks/session-hooks.d.ts +0 -234
  231. package/v3/@claude-flow/shared/dist/hooks/session-hooks.js +0 -334
  232. package/v3/@claude-flow/shared/dist/hooks/task-hooks.d.ts +0 -163
  233. package/v3/@claude-flow/shared/dist/hooks/task-hooks.js +0 -326
  234. package/v3/@claude-flow/shared/dist/hooks/types.d.ts +0 -267
  235. package/v3/@claude-flow/shared/dist/hooks/types.js +0 -62
  236. package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +0 -9
  237. package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.js +0 -93
  238. package/v3/@claude-flow/shared/dist/index.d.ts +0 -20
  239. package/v3/@claude-flow/shared/dist/index.js +0 -50
  240. package/v3/@claude-flow/shared/dist/mcp/connection-pool.d.ts +0 -98
  241. package/v3/@claude-flow/shared/dist/mcp/connection-pool.js +0 -364
  242. package/v3/@claude-flow/shared/dist/mcp/index.d.ts +0 -69
  243. package/v3/@claude-flow/shared/dist/mcp/index.js +0 -84
  244. package/v3/@claude-flow/shared/dist/mcp/server.d.ts +0 -166
  245. package/v3/@claude-flow/shared/dist/mcp/server.js +0 -590
  246. package/v3/@claude-flow/shared/dist/mcp/session-manager.d.ts +0 -136
  247. package/v3/@claude-flow/shared/dist/mcp/session-manager.js +0 -335
  248. package/v3/@claude-flow/shared/dist/mcp/tool-registry.d.ts +0 -178
  249. package/v3/@claude-flow/shared/dist/mcp/tool-registry.js +0 -439
  250. package/v3/@claude-flow/shared/dist/mcp/transport/http.d.ts +0 -104
  251. package/v3/@claude-flow/shared/dist/mcp/transport/http.js +0 -476
  252. package/v3/@claude-flow/shared/dist/mcp/transport/index.d.ts +0 -102
  253. package/v3/@claude-flow/shared/dist/mcp/transport/index.js +0 -238
  254. package/v3/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +0 -104
  255. package/v3/@claude-flow/shared/dist/mcp/transport/stdio.js +0 -263
  256. package/v3/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +0 -133
  257. package/v3/@claude-flow/shared/dist/mcp/transport/websocket.js +0 -396
  258. package/v3/@claude-flow/shared/dist/mcp/types.d.ts +0 -436
  259. package/v3/@claude-flow/shared/dist/mcp/types.js +0 -54
  260. package/v3/@claude-flow/shared/dist/plugin-interface.d.ts +0 -544
  261. package/v3/@claude-flow/shared/dist/plugin-interface.js +0 -23
  262. package/v3/@claude-flow/shared/dist/plugin-loader.d.ts +0 -139
  263. package/v3/@claude-flow/shared/dist/plugin-loader.js +0 -434
  264. package/v3/@claude-flow/shared/dist/plugin-registry.d.ts +0 -183
  265. package/v3/@claude-flow/shared/dist/plugin-registry.js +0 -457
  266. package/v3/@claude-flow/shared/dist/plugins/index.d.ts +0 -10
  267. package/v3/@claude-flow/shared/dist/plugins/index.js +0 -10
  268. package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +0 -106
  269. package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +0 -241
  270. package/v3/@claude-flow/shared/dist/plugins/official/index.d.ts +0 -10
  271. package/v3/@claude-flow/shared/dist/plugins/official/index.js +0 -10
  272. package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +0 -121
  273. package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +0 -355
  274. package/v3/@claude-flow/shared/dist/plugins/types.d.ts +0 -93
  275. package/v3/@claude-flow/shared/dist/plugins/types.js +0 -9
  276. package/v3/@claude-flow/shared/dist/resilience/bulkhead.d.ts +0 -105
  277. package/v3/@claude-flow/shared/dist/resilience/bulkhead.js +0 -206
  278. package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +0 -132
  279. package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.js +0 -233
  280. package/v3/@claude-flow/shared/dist/resilience/index.d.ts +0 -19
  281. package/v3/@claude-flow/shared/dist/resilience/index.js +0 -19
  282. package/v3/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +0 -168
  283. package/v3/@claude-flow/shared/dist/resilience/rate-limiter.js +0 -314
  284. package/v3/@claude-flow/shared/dist/resilience/retry.d.ts +0 -91
  285. package/v3/@claude-flow/shared/dist/resilience/retry.js +0 -159
  286. package/v3/@claude-flow/shared/dist/security/index.d.ts +0 -10
  287. package/v3/@claude-flow/shared/dist/security/index.js +0 -12
  288. package/v3/@claude-flow/shared/dist/security/input-validation.d.ts +0 -73
  289. package/v3/@claude-flow/shared/dist/security/input-validation.js +0 -201
  290. package/v3/@claude-flow/shared/dist/security/secure-random.d.ts +0 -92
  291. package/v3/@claude-flow/shared/dist/security/secure-random.js +0 -142
  292. package/v3/@claude-flow/shared/dist/services/index.d.ts +0 -7
  293. package/v3/@claude-flow/shared/dist/services/index.js +0 -7
  294. package/v3/@claude-flow/shared/dist/services/v3-progress.service.d.ts +0 -124
  295. package/v3/@claude-flow/shared/dist/services/v3-progress.service.js +0 -402
  296. package/v3/@claude-flow/shared/dist/types/agent.types.d.ts +0 -137
  297. package/v3/@claude-flow/shared/dist/types/agent.types.js +0 -6
  298. package/v3/@claude-flow/shared/dist/types/index.d.ts +0 -11
  299. package/v3/@claude-flow/shared/dist/types/index.js +0 -17
  300. package/v3/@claude-flow/shared/dist/types/mcp.types.d.ts +0 -266
  301. package/v3/@claude-flow/shared/dist/types/mcp.types.js +0 -7
  302. package/v3/@claude-flow/shared/dist/types/memory.types.d.ts +0 -236
  303. package/v3/@claude-flow/shared/dist/types/memory.types.js +0 -7
  304. package/v3/@claude-flow/shared/dist/types/swarm.types.d.ts +0 -186
  305. package/v3/@claude-flow/shared/dist/types/swarm.types.js +0 -65
  306. package/v3/@claude-flow/shared/dist/types/task.types.d.ts +0 -178
  307. package/v3/@claude-flow/shared/dist/types/task.types.js +0 -32
  308. package/v3/@claude-flow/shared/dist/types.d.ts +0 -197
  309. package/v3/@claude-flow/shared/dist/types.js +0 -21
  310. package/v3/@claude-flow/shared/dist/utils/secure-logger.d.ts +0 -69
  311. package/v3/@claude-flow/shared/dist/utils/secure-logger.js +0 -208
@@ -1,596 +0,0 @@
1
- /**
2
- * Task Intent Classifier + Shard Retriever
3
- *
4
- * Stores rule shards in vector storage with embeddings and metadata.
5
- * At task start, retrieves the top N shards by semantic similarity
6
- * with hard filters by risk class and repo scope.
7
- *
8
- * Retrieval contract:
9
- * 1. Always include the constitution
10
- * 2. Retrieve up to 5 shards by semantic similarity
11
- * 3. Add hard filters by risk class and repo scope
12
- * 4. Contradiction check: prefer higher-priority rule ID
13
- *
14
- * @module @claude-flow/guidance/retriever
15
- */
16
- // ============================================================================
17
- // Intent Classification
18
- // ============================================================================
19
- /** Intent detection patterns with confidence weights */
20
- const INTENT_PATTERNS = {
21
- 'bug-fix': [
22
- { pattern: /\b(fix|bug|broken|error|crash|issue|wrong|incorrect|fail)\b/i, weight: 0.8 },
23
- { pattern: /\b(not working|doesn't work|unexpected|regression)\b/i, weight: 0.9 },
24
- ],
25
- 'feature': [
26
- { pattern: /\b(add|create|implement|build|new|introduce|develop)\b/i, weight: 0.5 },
27
- { pattern: /\b(feature|capability|functionality|support for)\b/i, weight: 0.9 },
28
- { pattern: /\b(user|page|profile|dashboard|form|widget|component|module)\b/i, weight: 0.3 },
29
- ],
30
- 'refactor': [
31
- { pattern: /\b(refactor|restructure|reorganize|simplify|clean|extract|inline)\b/i, weight: 0.9 },
32
- { pattern: /\b(improve readability|reduce complexity|code quality)\b/i, weight: 0.8 },
33
- ],
34
- 'security': [
35
- { pattern: /\b(security|auth|permission|access control|encrypt|secret|token)\b/i, weight: 0.9 },
36
- { pattern: /\b(cve|vulnerability|injection|xss|csrf|sanitize)\b/i, weight: 1.0 },
37
- ],
38
- 'performance': [
39
- { pattern: /\b(performance|optimize|speed|slow|fast|cache|memory usage|latency)\b/i, weight: 0.9 },
40
- { pattern: /\b(bottleneck|profile|benchmark|throughput|efficient)\b/i, weight: 0.8 },
41
- ],
42
- 'testing': [
43
- { pattern: /\b(tests?|specs?|coverage|mocks?|asserts?|tdd|unit tests?|integration tests?)\b/i, weight: 1.0 },
44
- { pattern: /\b(test suite|test case|test plan|quality assurance)\b/i, weight: 0.9 },
45
- ],
46
- 'docs': [
47
- { pattern: /\b(document|readme|jsdoc|comment|explain|describe|tutorial)\b/i, weight: 0.8 },
48
- { pattern: /\b(api docs|documentation|usage guide|changelog)\b/i, weight: 0.9 },
49
- ],
50
- 'deployment': [
51
- { pattern: /\b(deploy|release|publish|ci|cd|pipeline|docker|kubernetes)\b/i, weight: 0.9 },
52
- { pattern: /\b(staging|production|rollback|migration|version)\b/i, weight: 0.7 },
53
- ],
54
- 'architecture': [
55
- { pattern: /\b(architect|design pattern|system design|structure|boundary)\b/i, weight: 0.8 },
56
- { pattern: /\b(module boundary|component architecture|layer|service mesh|domain model|aggregate root)\b/i, weight: 0.7 },
57
- { pattern: /\b(interface|api design|separation of concerns)\b/i, weight: 0.6 },
58
- ],
59
- 'debug': [
60
- { pattern: /\b(debug|trace|log|diagnose|investigate|root cause)\b/i, weight: 0.9 },
61
- { pattern: /\b(stack trace|breakpoint|inspect|reproduction)\b/i, weight: 0.8 },
62
- ],
63
- 'general': [
64
- { pattern: /./, weight: 0.1 },
65
- ],
66
- };
67
- /**
68
- * Deterministic hash-based embedding provider — **test-only**.
69
- *
70
- * Produces fixed-dimension vectors from a simple character-hash → sin()
71
- * transform. The resulting embeddings have no real semantic meaning;
72
- * they are stable and fast, which makes them useful for unit/integration
73
- * tests that need a concrete {@link IEmbeddingProvider} without loading
74
- * an ONNX model.
75
- *
76
- * **Do NOT use in production** — replace with a real model-backed
77
- * provider (e.g. the agentic-flow ONNX integration).
78
- */
79
- export class HashEmbeddingProvider {
80
- dimensions;
81
- cache = new Map();
82
- constructor(dimensions = 384) {
83
- this.dimensions = dimensions;
84
- }
85
- async embed(text) {
86
- const key = text.slice(0, 200);
87
- if (this.cache.has(key))
88
- return this.cache.get(key);
89
- const embedding = this.hashEmbed(text);
90
- this.cache.set(key, embedding);
91
- return embedding;
92
- }
93
- async batchEmbed(texts) {
94
- return Promise.all(texts.map(t => this.embed(t)));
95
- }
96
- hashEmbed(text) {
97
- const embedding = new Float32Array(this.dimensions);
98
- const normalized = text.toLowerCase().trim();
99
- for (let i = 0; i < this.dimensions; i++) {
100
- let hash = 0;
101
- for (let j = 0; j < normalized.length; j++) {
102
- hash = ((hash << 5) - hash + normalized.charCodeAt(j) * (i + 1)) | 0;
103
- }
104
- embedding[i] = (Math.sin(hash) + 1) / 2;
105
- }
106
- // L2 normalize
107
- let norm = 0;
108
- for (let i = 0; i < this.dimensions; i++) {
109
- norm += embedding[i] * embedding[i];
110
- }
111
- norm = Math.sqrt(norm);
112
- if (norm > 0) {
113
- for (let i = 0; i < this.dimensions; i++) {
114
- embedding[i] /= norm;
115
- }
116
- }
117
- return embedding;
118
- }
119
- }
120
- // ============================================================================
121
- // Shard Retriever
122
- // ============================================================================
123
- export class ShardRetriever {
124
- shards = [];
125
- constitution = null;
126
- embeddingProvider;
127
- indexed = false;
128
- globCache = new Map();
129
- // M3 perf substrate — packed embedding matrix for batched cosine.
130
- // The per-shard `embedding: Float32Array` fields are scattered allocations
131
- // that produce poor cache locality during scoreShards's O(n) scan. We
132
- // additionally cache a single contiguous Float32Array of shape
133
- // (shardCount × dim) and run the cosine as a tight matrix-vector dot.
134
- // V8 emits much tighter inner-loop code for this access pattern and
135
- // memory bandwidth becomes the floor.
136
- //
137
- // `packedDim === 0` when not yet packed (no shards, or shards lack
138
- // embeddings). Stale on shard mutation — `indexShards()` repacks.
139
- packedEmbeddings = null;
140
- packedDim = 0;
141
- packedShardCount = 0;
142
- // M4 perf substrate — RaBitQ-style 1-bit-per-dim signatures.
143
- // For unit vectors, the sign pattern of each dim is a Locality-Sensitive
144
- // Hash. P[sign(q[i]) === sign(s[i])] ≈ 1 - θ/π where θ is the angle
145
- // between q and s. So Hamming distance between signatures approximates
146
- // angular distance, and cosine ≈ 1 - 2·hamming/dim. For dim=384 this
147
- // costs 12 Uint32 (48 bytes) per shard — a 32x memory reduction vs
148
- // Float32Array — and the comparison is XOR + popcount per 32-bit word,
149
- // which V8 lowers to a tight machine-code loop.
150
- //
151
- // At dim=384: 6 multiplies per word × 12 words = 72 ops to compare two
152
- // signatures vs 384 multiplies for the full Float32 cosine. Even with
153
- // popcount in JS via the Hamming-Weight bit trick, this is ~6-8x
154
- // faster than the dot product. We use it as a coarse pre-filter:
155
- // compute Hamming distances, take the top-K candidates by Hamming, then
156
- // do exact cosine on just those. Top-K is much smaller than N so the
157
- // exact-cosine work is bounded.
158
- //
159
- // `bitsPerSig === dim` rounded up to a multiple of 32 (we waste at most
160
- // 31 bits per shard at non-aligned dims).
161
- packedSignatures = null;
162
- wordsPerSig = 0; // = ceil(dim/32)
163
- constructor(embeddingProvider) {
164
- this.embeddingProvider = embeddingProvider ?? new HashEmbeddingProvider();
165
- }
166
- /**
167
- * Load a compiled policy bundle
168
- */
169
- async loadBundle(bundle) {
170
- this.constitution = bundle.constitution;
171
- this.shards = bundle.shards;
172
- this.indexed = false;
173
- await this.indexShards();
174
- }
175
- /**
176
- * Index all shards by generating embeddings.
177
- *
178
- * M3 substrate — also packs every shard embedding into a single
179
- * contiguous Float32Array (`packedEmbeddings`) so scoreShards can run
180
- * the cosine as a vectorized matrix-vector dot in cache-friendly
181
- * sequential memory rather than chasing per-shard heap pointers.
182
- * Costs O(n × dim) at index time (one-shot) for an O(n) scan win
183
- * on every query.
184
- */
185
- async indexShards() {
186
- if (this.indexed)
187
- return;
188
- const texts = this.shards.map(s => s.compactText);
189
- const embeddings = await this.embeddingProvider.batchEmbed(texts);
190
- let dim = 0;
191
- for (let i = 0; i < this.shards.length; i++) {
192
- this.shards[i].embedding = embeddings[i];
193
- if (embeddings[i] && embeddings[i].length > dim)
194
- dim = embeddings[i].length;
195
- }
196
- // Pack into a single contiguous Float32Array. Shards without an
197
- // embedding (or with a wrong dim) get a row of zeros — they fall
198
- // through to similarity=0 in the existing scoring path.
199
- if (dim > 0 && this.shards.length > 0) {
200
- const packed = new Float32Array(this.shards.length * dim);
201
- for (let i = 0; i < this.shards.length; i++) {
202
- const e = this.shards[i].embedding;
203
- if (e && e.length === dim) {
204
- packed.set(e, i * dim);
205
- }
206
- }
207
- this.packedEmbeddings = packed;
208
- this.packedDim = dim;
209
- this.packedShardCount = this.shards.length;
210
- // M4 — also compute the 1-bit sign signature per shard. Each row
211
- // is `ceil(dim/32)` Uint32 words; bit i is `embedding[i] > 0`.
212
- const words = (dim + 31) >>> 5;
213
- const sigs = new Uint32Array(this.shards.length * words);
214
- for (let i = 0; i < this.shards.length; i++) {
215
- const e = this.shards[i].embedding;
216
- if (!e || e.length !== dim)
217
- continue;
218
- const base = i * words;
219
- for (let w = 0; w < words; w++) {
220
- let bits = 0;
221
- const dimStart = w * 32;
222
- const dimEnd = Math.min(dim, dimStart + 32);
223
- for (let b = dimStart; b < dimEnd; b++) {
224
- if (e[b] > 0)
225
- bits |= 1 << (b - dimStart);
226
- }
227
- sigs[base + w] = bits >>> 0;
228
- }
229
- }
230
- this.packedSignatures = sigs;
231
- this.wordsPerSig = words;
232
- }
233
- else {
234
- this.packedEmbeddings = null;
235
- this.packedDim = 0;
236
- this.packedShardCount = 0;
237
- this.packedSignatures = null;
238
- this.wordsPerSig = 0;
239
- }
240
- this.indexed = true;
241
- }
242
- /**
243
- * Build a 1-bit sign signature for the query vector. Matches the
244
- * packed-shard format produced in indexShards above.
245
- */
246
- buildQuerySignature(q) {
247
- const dim = q.length;
248
- const words = (dim + 31) >>> 5;
249
- const sig = new Uint32Array(words);
250
- for (let w = 0; w < words; w++) {
251
- let bits = 0;
252
- const start = w * 32;
253
- const end = Math.min(dim, start + 32);
254
- for (let b = start; b < end; b++) {
255
- if (q[b] > 0)
256
- bits |= 1 << (b - start);
257
- }
258
- sig[w] = bits >>> 0;
259
- }
260
- return sig;
261
- }
262
- /**
263
- * Hamming-Weight popcount on a single 32-bit word (Wegner / Wilkes).
264
- * Tested at ~1 ns on V8 — no native popcnt instruction exposed.
265
- */
266
- static popcount32(x) {
267
- x = x - ((x >>> 1) & 0x55555555);
268
- x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
269
- x = (x + (x >>> 4)) & 0x0f0f0f0f;
270
- return (x * 0x01010101) >>> 24;
271
- }
272
- /**
273
- * Classify task intent
274
- */
275
- classifyIntent(taskDescription) {
276
- let bestIntent = 'general';
277
- let bestScore = 0;
278
- for (const [intent, patterns] of Object.entries(INTENT_PATTERNS)) {
279
- if (intent === 'general')
280
- continue; // Skip general fallback during scoring
281
- let score = 0;
282
- for (const { pattern, weight } of patterns) {
283
- if (pattern.test(taskDescription)) {
284
- score += weight;
285
- }
286
- }
287
- if (score > bestScore) {
288
- bestScore = score;
289
- bestIntent = intent;
290
- }
291
- }
292
- // Normalize confidence to 0-1
293
- const confidence = Math.min(bestScore / 3, 1);
294
- return { intent: bestIntent, confidence };
295
- }
296
- /**
297
- * Retrieve relevant shards for a task
298
- *
299
- * Contract:
300
- * 1. Always include the constitution
301
- * 2. Up to maxShards by semantic similarity
302
- * 3. Hard filters by risk class and repo scope
303
- * 4. Contradiction check: prefer higher priority
304
- */
305
- async retrieve(request) {
306
- const startTime = performance.now();
307
- if (!this.constitution) {
308
- throw new Error('No policy bundle loaded. Call loadBundle() first.');
309
- }
310
- // Step 1: Classify intent
311
- const { intent: detectedIntent } = this.classifyIntent(request.taskDescription);
312
- const intent = request.intent ?? detectedIntent;
313
- // Step 2: Generate query embedding
314
- const queryEmbedding = await this.embeddingProvider.embed(request.taskDescription);
315
- // Step 3: Score all shards
316
- const maxShards = request.maxShards ?? 5;
317
- const scored = this.scoreShards(queryEmbedding, intent, request.riskFilter, request.repoScope);
318
- // Step 4: Select top N with contradiction resolution
319
- const selected = this.selectWithContradictionCheck(scored, maxShards);
320
- // Step 5: Build combined policy text
321
- const policyText = this.buildPolicyText(this.constitution, selected);
322
- const latencyMs = performance.now() - startTime;
323
- return {
324
- constitution: this.constitution,
325
- shards: selected,
326
- detectedIntent: intent,
327
- contradictionsResolved: this.countContradictions(selected),
328
- policyText,
329
- latencyMs,
330
- };
331
- }
332
- /**
333
- * Score all shards against the query.
334
- *
335
- * M3 perf substrate — three changes from the baseline:
336
- *
337
- * 1. Filter FIRST, cosine SECOND. The old code computed cosine for
338
- * every shard regardless of whether riskFilter/repoScope would
339
- * throw it away. We now decide eligibility first and only do
340
- * the 384-dim multiply for survivors.
341
- *
342
- * 2. Packed-matrix cosine — when `packedEmbeddings` is current and
343
- * dim matches, compute the dot directly from contiguous memory
344
- * (one allocation, sequential reads) instead of dereferencing
345
- * `shard.embedding` per call. Embeddings are always unit-
346
- * normalised so cosine === dot + clamp.
347
- *
348
- * 3. Top-K partial selection — when the caller only wants `maxShards`
349
- * results (typical), don't `.sort()` the entire candidate list.
350
- * Maintain a fixed-size heap of size K and only compare/swap
351
- * against its current minimum. Drops the final step from
352
- * O(n log n) to O(n log K).
353
- */
354
- scoreShards(queryEmbedding, intent, riskFilter, repoScope) {
355
- const results = [];
356
- const usePacked = this.packedEmbeddings !== null &&
357
- this.packedShardCount === this.shards.length &&
358
- this.packedDim === queryEmbedding.length;
359
- const packed = this.packedEmbeddings;
360
- const dim = this.packedDim;
361
- // M4 quantization fast path — for large shard sets, the bit-signature
362
- // popcount is ~11x faster than full Float32 cosine (proven in
363
- // bench-quantization.mjs). The sign-random-projection theorem
364
- // guarantees the Hamming distance approximates the angular distance,
365
- // so we can compute coarse similarities for all N shards at the
366
- // quantized cost and the result is good enough for the
367
- // sort/intent-boost/risk-boost path that follows.
368
- //
369
- // Only fires when (a) the packed signatures are current, (b) shard
370
- // count is >= 100 so the constant-factor cost of building the query
371
- // signature is amortised, and (c) dimensions match.
372
- const useQuantized = usePacked &&
373
- this.packedSignatures !== null &&
374
- this.packedShardCount >= 100 &&
375
- this.wordsPerSig === ((dim + 31) >>> 5);
376
- let querySig = null;
377
- if (useQuantized) {
378
- querySig = this.buildQuerySignature(queryEmbedding);
379
- }
380
- const sigs = this.packedSignatures;
381
- const wps = this.wordsPerSig;
382
- for (let si = 0; si < this.shards.length; si++) {
383
- const shard = this.shards[si];
384
- // Hard filter: risk class — skip cosine on filtered shards
385
- if (riskFilter && riskFilter.length > 0) {
386
- if (!riskFilter.includes(shard.rule.riskClass))
387
- continue;
388
- }
389
- // Hard filter: repo scope
390
- if (repoScope) {
391
- const matchesScope = shard.rule.repoScopes.some(scope => scope === '**/*' || this.matchGlob(repoScope, scope));
392
- if (!matchesScope)
393
- continue;
394
- }
395
- // Semantic similarity — only compute for survivors of the filter.
396
- // Prefer the quantized Hamming approximation when available (11x
397
- // faster than full Float32 dot — proven in bench-quantization.mjs).
398
- let similarity = 0;
399
- if (useQuantized && querySig !== null && sigs !== null) {
400
- const base = si * wps;
401
- let hamming = 0;
402
- for (let w = 0; w < wps; w++) {
403
- // Inline popcount32 — V8 emits much tighter machine code than
404
- // a function call inside the inner loop. Two cycles per word.
405
- let x = (sigs[base + w] ^ querySig[w]) >>> 0;
406
- x = x - ((x >>> 1) & 0x55555555);
407
- x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
408
- x = (x + (x >>> 4)) & 0x0f0f0f0f;
409
- hamming += (x * 0x01010101) >>> 24;
410
- }
411
- // Sign-random-projection: cos(θ) ≈ cos(π · hamming/dim).
412
- const sim = Math.cos((Math.PI * hamming) / dim);
413
- similarity = sim < 0 ? 0 : sim > 1 ? 1 : sim;
414
- }
415
- else if (usePacked && packed !== null) {
416
- const off = si * dim;
417
- let dot = 0;
418
- for (let k = 0; k < dim; k++)
419
- dot += packed[off + k] * queryEmbedding[k];
420
- similarity = dot < 0 ? 0 : dot > 1 ? 1 : dot;
421
- }
422
- else if (shard.embedding) {
423
- similarity = this.cosineSimilarity(queryEmbedding, shard.embedding);
424
- }
425
- // Intent boost: if shard matches detected intent, boost score
426
- const intentBoost = shard.rule.intents.includes(intent) ? 0.15 : 0;
427
- // Risk boost: critical/high rules get a boost
428
- const riskBoost = shard.rule.riskClass === 'critical' ? 0.1
429
- : shard.rule.riskClass === 'high' ? 0.05
430
- : 0;
431
- const finalScore = similarity + intentBoost + riskBoost;
432
- const reasons = [];
433
- if (similarity > 0.3)
434
- reasons.push(`semantic match (${(similarity * 100).toFixed(0)}%)`);
435
- if (intentBoost > 0)
436
- reasons.push(`intent match (${intent})`);
437
- if (riskBoost > 0)
438
- reasons.push(`risk priority (${shard.rule.riskClass})`);
439
- results.push({
440
- shard,
441
- similarity: finalScore,
442
- reason: reasons.join(', ') || 'general relevance',
443
- });
444
- }
445
- // Sort by combined score descending
446
- return results.sort((a, b) => b.similarity - a.similarity);
447
- }
448
- /**
449
- * Select top N shards with contradiction checking
450
- * When two rules contradict, keep the one with higher priority
451
- */
452
- selectWithContradictionCheck(scored, maxShards) {
453
- const selected = [];
454
- const selectedDomains = new Map(); // domain -> highest priority
455
- for (const item of scored) {
456
- if (selected.length >= maxShards)
457
- break;
458
- // Check for potential contradictions with already selected shards
459
- let dominated = false;
460
- for (const domain of item.shard.rule.domains) {
461
- const existingPriority = selectedDomains.get(domain);
462
- if (existingPriority !== undefined && existingPriority > item.shard.rule.priority) {
463
- // Higher priority rule already selected for this domain
464
- // Check if they're likely contradictory (similar domain, different intent)
465
- const existing = selected.find(s => s.shard.rule.domains.includes(domain) &&
466
- s.shard.rule.priority > item.shard.rule.priority);
467
- if (existing && this.areContradictory(existing.shard.rule, item.shard.rule)) {
468
- dominated = true;
469
- break;
470
- }
471
- }
472
- }
473
- if (!dominated) {
474
- selected.push(item);
475
- for (const domain of item.shard.rule.domains) {
476
- const current = selectedDomains.get(domain) ?? 0;
477
- selectedDomains.set(domain, Math.max(current, item.shard.rule.priority));
478
- }
479
- }
480
- }
481
- return selected;
482
- }
483
- /**
484
- * Check if two rules are contradictory
485
- */
486
- areContradictory(a, b) {
487
- const negationPatterns = [
488
- { positive: /\bmust\b/i, negative: /\bnever\b|\bdo not\b|\bavoid\b/i },
489
- { positive: /\balways\b/i, negative: /\bnever\b|\bdon't\b/i },
490
- { positive: /\brequire\b/i, negative: /\bforbid\b|\bprohibit\b/i },
491
- ];
492
- for (const { positive, negative } of negationPatterns) {
493
- if ((positive.test(a.text) && negative.test(b.text)) ||
494
- (negative.test(a.text) && positive.test(b.text))) {
495
- return true;
496
- }
497
- }
498
- return false;
499
- }
500
- /**
501
- * Count contradictions in selected set
502
- */
503
- countContradictions(selected) {
504
- let count = 0;
505
- for (let i = 0; i < selected.length; i++) {
506
- for (let j = i + 1; j < selected.length; j++) {
507
- if (this.areContradictory(selected[i].shard.rule, selected[j].shard.rule)) {
508
- count++;
509
- }
510
- }
511
- }
512
- return count;
513
- }
514
- /**
515
- * Build combined policy text for injection
516
- */
517
- buildPolicyText(constitution, shards) {
518
- const parts = [];
519
- // Always include constitution
520
- parts.push(constitution.text);
521
- // Add retrieved shards
522
- if (shards.length > 0) {
523
- parts.push('');
524
- parts.push('## Task-Specific Rules');
525
- parts.push('');
526
- for (const { shard, reason } of shards) {
527
- parts.push(`- ${shard.compactText}`);
528
- }
529
- }
530
- return parts.join('\n');
531
- }
532
- /**
533
- * Simple glob matching (supports * and **).
534
- * Compiled regexes are cached per glob to avoid re-compiling on every call.
535
- */
536
- matchGlob(path, glob) {
537
- let re = this.globCache.get(glob);
538
- if (!re) {
539
- const pattern = glob
540
- .replace(/\*\*/g, '{{GLOBSTAR}}')
541
- .replace(/\*/g, '[^/]*')
542
- .replace(/{{GLOBSTAR}}/g, '.*')
543
- .replace(/\//g, '\\/');
544
- re = new RegExp(`^${pattern}$`);
545
- this.globCache.set(glob, re);
546
- }
547
- return re.test(path);
548
- }
549
- /**
550
- * Cosine similarity between two vectors.
551
- *
552
- * Phase 1 perf — the embeddings this retriever consumes are always
553
- * unit-normalised at production time:
554
- * - HashEmbeddingProvider divides by L2 norm before returning
555
- * (this file, line 134)
556
- * - ONNX providers (all-MiniLM-L6-v2 and friends) emit unit vectors
557
- * by design
558
- * That means `sqrt(normA) * sqrt(normB) === 1` and the only useful
559
- * computation per pair is the dot product. The old 3-accumulator
560
- * version computed dot + both norms + two sqrts + a div + a clamp —
561
- * for a result the math already guarantees lies in [-1, 1]. We drop
562
- * to pure dot + a defensive clamp.
563
- *
564
- * This compounds: every `scoreShards()` call ran `O(shards)` of these,
565
- * and `retrieveForTask()` runs it per query.
566
- */
567
- cosineSimilarity(a, b) {
568
- if (a.length !== b.length)
569
- return 0;
570
- let dot = 0;
571
- for (let i = 0; i < a.length; i++)
572
- dot += a[i] * b[i];
573
- // Defensive clamp — unit vectors should land in [-1, 1] but tiny
574
- // FP drift can produce 1.0000000002. Snap to [0, 1].
575
- return dot < 0 ? 0 : dot > 1 ? 1 : dot;
576
- }
577
- /**
578
- * Get current shard count
579
- */
580
- get shardCount() {
581
- return this.shards.length;
582
- }
583
- /**
584
- * Get constitution
585
- */
586
- getConstitution() {
587
- return this.constitution;
588
- }
589
- }
590
- /**
591
- * Create a retriever instance
592
- */
593
- export function createRetriever(embeddingProvider) {
594
- return new ShardRetriever(embeddingProvider);
595
- }
596
- //# sourceMappingURL=retriever.js.map