agentic-qe 3.9.29 → 3.9.31

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 (341) hide show
  1. package/.claude/skills/skills-manifest.json +1 -1
  2. package/CHANGELOG.md +176 -0
  3. package/assets/skills/skills-manifest.json +1 -1
  4. package/dist/bridge/captured-experience-bridge.js +31 -2
  5. package/dist/cli/bundle.js +5 -5
  6. package/dist/cli/chunks/adapter-CI2GZYME.js +2 -0
  7. package/dist/cli/chunks/{agent-booster-wasm-EPRGXS5D.js → agent-booster-wasm-AQXZYWZY.js} +2 -2
  8. package/dist/cli/chunks/{agent-handler-LF6D64UE.js → agent-handler-7N4ZPXCY.js} +2 -2
  9. package/dist/cli/chunks/{agent-memory-branch-XD3UQD6Y.js → agent-memory-branch-FLKF2JVX.js} +2 -2
  10. package/dist/cli/chunks/aqe-learning-engine-KNQKALLI.js +2 -0
  11. package/dist/cli/chunks/{audit-MNJONFOL.js → audit-B4V4IKTA.js} +2 -2
  12. package/dist/cli/chunks/base-P7PRMQWY.js +2 -0
  13. package/dist/cli/chunks/{hnswlib-node-PSQJ3C65.js → better-sqlite3-NYOVLWBG.js} +2 -2
  14. package/dist/cli/chunks/{brain-handler-SA2G3FDO.js → brain-handler-OOXJ2KYY.js} +4 -4
  15. package/dist/cli/chunks/{branch-enumerator-T7SZZTMH.js → branch-enumerator-LFKFW3A4.js} +2 -2
  16. package/dist/cli/chunks/{browser-OH5HUVOG.js → browser-F72IES2I.js} +3 -3
  17. package/dist/cli/chunks/browser-workflow-QUP4A763.js +2 -0
  18. package/dist/cli/chunks/{chunk-K7CFDRVW.js → chunk-2NLZXG6V.js} +1 -1
  19. package/dist/cli/chunks/{chunk-5Q26UGSU.js → chunk-35SFAIXE.js} +2 -2
  20. package/dist/cli/chunks/{chunk-UI6KM5PK.js → chunk-3VKB4HVT.js} +2 -2
  21. package/dist/cli/chunks/{chunk-UKYPDNQR.js → chunk-462MZLJB.js} +1 -1
  22. package/dist/cli/chunks/{chunk-WUKSEOUO.js → chunk-47QIAHUJ.js} +2 -2
  23. package/dist/cli/chunks/{chunk-R55RXPHB.js → chunk-4N736EES.js} +2 -2
  24. package/dist/cli/chunks/{chunk-5XRNUFEG.js → chunk-52D3CYE5.js} +2 -2
  25. package/dist/cli/chunks/{chunk-5MUYYPPW.js → chunk-5AMAJCZS.js} +3 -3
  26. package/dist/cli/chunks/{chunk-2JK43GR4.js → chunk-5G2L4XRU.js} +2 -2
  27. package/dist/cli/chunks/{chunk-C7MWQ4BI.js → chunk-5M4F3PAL.js} +1 -1
  28. package/dist/cli/chunks/{chunk-PYAITX6B.js → chunk-5WWQLPB4.js} +2 -2
  29. package/dist/cli/chunks/chunk-5Z6PYYWK.js +2 -0
  30. package/dist/cli/chunks/{chunk-VHJRWMZ5.js → chunk-62KYX5NH.js} +2 -2
  31. package/dist/cli/chunks/{chunk-667A24A4.js → chunk-7MXQV7RB.js} +12 -6
  32. package/dist/cli/chunks/{chunk-N5SS5YIS.js → chunk-7OVVBBOZ.js} +2 -2
  33. package/dist/cli/chunks/{chunk-TESFXE2W.js → chunk-7RPEBKQZ.js} +2 -2
  34. package/dist/cli/chunks/{chunk-3T4Q5V4B.js → chunk-7UHRT5AX.js} +2 -2
  35. package/dist/cli/chunks/{chunk-7PYHCYLJ.js → chunk-7V7TP242.js} +1 -1
  36. package/dist/cli/chunks/{chunk-IBSTVSKT.js → chunk-A424Z7LA.js} +1 -1
  37. package/dist/cli/chunks/{chunk-IX5LUHCN.js → chunk-AKFRM4IO.js} +2 -2
  38. package/dist/cli/chunks/{chunk-UGXYKPM4.js → chunk-AKJWBJDK.js} +2 -2
  39. package/dist/cli/chunks/{chunk-MBNFD2C3.js → chunk-AQN6PDHI.js} +1 -1
  40. package/dist/cli/chunks/{chunk-YCK464TF.js → chunk-BMS7WFDB.js} +1 -1
  41. package/dist/cli/chunks/{chunk-C7G7TA2H.js → chunk-BYHUGO73.js} +3 -3
  42. package/dist/cli/chunks/{chunk-ZZAZQKOA.js → chunk-CFLA2GBS.js} +2 -2
  43. package/dist/cli/chunks/{chunk-7AIVTUMM.js → chunk-CNKOIHF6.js} +2 -2
  44. package/dist/cli/chunks/{chunk-23B7TDPN.js → chunk-CQWZNVIM.js} +2 -2
  45. package/dist/cli/chunks/{chunk-REFFJUYT.js → chunk-CUSLB7MB.js} +2 -2
  46. package/dist/cli/chunks/chunk-CYUGE5ZQ.js +2 -0
  47. package/dist/cli/chunks/{chunk-BZ4OMPVJ.js → chunk-DMF4Z2M6.js} +2 -2
  48. package/dist/cli/chunks/{chunk-HEUAPPKE.js → chunk-DUF733Z7.js} +1 -1
  49. package/dist/cli/chunks/{chunk-VKJLHKLY.js → chunk-EAIPJSKH.js} +2 -2
  50. package/dist/cli/chunks/{chunk-GHBQVPJT.js → chunk-EJXRBAQF.js} +2 -2
  51. package/dist/cli/chunks/{chunk-N6A4XFUM.js → chunk-EKYPQ5DX.js} +1 -1
  52. package/dist/cli/chunks/{chunk-ZPFBEZV5.js → chunk-ENCFLC44.js} +2 -2
  53. package/dist/cli/chunks/{chunk-WQX2Q42U.js → chunk-FOAWHNOP.js} +2 -2
  54. package/dist/cli/chunks/{chunk-GBLW4QDV.js → chunk-FUHPLXJX.js} +1 -1
  55. package/dist/cli/chunks/{chunk-3E4VPGNW.js → chunk-G2U7Q6V6.js} +2 -2
  56. package/dist/cli/chunks/{chunk-7WRIYQG7.js → chunk-G3YKCZWQ.js} +3 -3
  57. package/dist/cli/chunks/{chunk-OLJLSLCY.js → chunk-GJSH4UZ3.js} +3 -3
  58. package/dist/cli/chunks/{chunk-XP5OUB2X.js → chunk-GN7FUCJH.js} +1 -1
  59. package/dist/cli/chunks/{chunk-UO3QSXYD.js → chunk-GQFAVT2I.js} +1 -1
  60. package/dist/cli/chunks/{chunk-AUE4QOT7.js → chunk-HHEIQHLQ.js} +2 -2
  61. package/dist/cli/chunks/{chunk-LRWREDZU.js → chunk-I3TFGMOQ.js} +1 -1
  62. package/dist/cli/chunks/{chunk-BUMNLVMC.js → chunk-IRRGUXAU.js} +1 -1
  63. package/dist/cli/chunks/{chunk-ZMZS6NKQ.js → chunk-IY4P35N3.js} +2 -2
  64. package/dist/cli/chunks/{chunk-SKIG6EOQ.js → chunk-JF3U456G.js} +2 -2
  65. package/dist/cli/chunks/{chunk-YEXQMYOM.js → chunk-JJRZOLDY.js} +2 -2
  66. package/dist/cli/chunks/{chunk-G426VZ5K.js → chunk-JKKV5KKS.js} +2 -2
  67. package/dist/cli/chunks/{chunk-I6PVI7R5.js → chunk-JMLOEW7Y.js} +2 -2
  68. package/dist/cli/chunks/chunk-JRIDPOEZ.js +95 -0
  69. package/dist/cli/chunks/{chunk-MCJRIW7M.js → chunk-K37CNLQZ.js} +1 -1
  70. package/dist/cli/chunks/{chunk-LIEKDXTS.js → chunk-K6MFAVXK.js} +2 -2
  71. package/dist/cli/chunks/{chunk-OPPASGEB.js → chunk-KJAIE7SL.js} +4 -4
  72. package/dist/cli/chunks/{chunk-ZWI5Z2SI.js → chunk-KXRDQQGN.js} +2 -2
  73. package/dist/cli/chunks/{chunk-Y7VPSAWH.js → chunk-L4JTTPU7.js} +2 -2
  74. package/dist/cli/chunks/{chunk-RXAJBMM7.js → chunk-L63KB63A.js} +2 -2
  75. package/dist/cli/chunks/{chunk-KX3XTWNR.js → chunk-L7DNPOAQ.js} +2 -2
  76. package/dist/cli/chunks/{chunk-LJDPZC6Q.js → chunk-LF5RO6WO.js} +1 -1
  77. package/dist/cli/chunks/{chunk-GWBI5IMK.js → chunk-LRWRFKQH.js} +1 -1
  78. package/dist/cli/chunks/{chunk-JXWZZTPN.js → chunk-M6RVKGIP.js} +2 -2
  79. package/dist/cli/chunks/{chunk-IQXDL7BX.js → chunk-MAJ5QFVY.js} +1 -1
  80. package/dist/cli/chunks/chunk-MYCVU3D3.js +14 -0
  81. package/dist/cli/chunks/{chunk-C7SJS5E4.js → chunk-N6P7ENG7.js} +2 -2
  82. package/dist/cli/chunks/{chunk-KQYKPEY6.js → chunk-N6SIKSCO.js} +2 -2
  83. package/dist/cli/chunks/{chunk-BP3KVVEM.js → chunk-NBKM7NKX.js} +2 -2
  84. package/dist/cli/chunks/{chunk-TZG7TJD5.js → chunk-NLUBN642.js} +2 -2
  85. package/dist/cli/chunks/{chunk-HCVIUAF2.js → chunk-NNF3GCGF.js} +2 -2
  86. package/dist/cli/chunks/{chunk-AYESXBSX.js → chunk-NTVJKQ5S.js} +2 -2
  87. package/dist/cli/chunks/{chunk-LPSIKIE2.js → chunk-NZQYNUGM.js} +2 -2
  88. package/dist/cli/chunks/{chunk-JX2AS6QZ.js → chunk-ONMJJ2C3.js} +1 -1
  89. package/dist/cli/chunks/{chunk-AOZ3JGJQ.js → chunk-OXOXNAEZ.js} +2 -2
  90. package/dist/cli/chunks/chunk-PSF6YQQM.js +180 -0
  91. package/dist/cli/chunks/{chunk-OW47RQEW.js → chunk-PTOTOBOU.js} +1 -1
  92. package/dist/cli/chunks/{chunk-FIMBLHR5.js → chunk-PUSZ4NBY.js} +2 -2
  93. package/dist/cli/chunks/chunk-PYYNY7RJ.js +2 -0
  94. package/dist/cli/chunks/{chunk-JXWJ6BLR.js → chunk-QEJBJST4.js} +1 -1
  95. package/dist/cli/chunks/{chunk-AQ4ZSM4D.js → chunk-QGLWFZVQ.js} +2 -2
  96. package/dist/cli/chunks/{chunk-ONFODTGV.js → chunk-QITO7E7Y.js} +1 -1
  97. package/dist/cli/chunks/{chunk-YWW6YPT5.js → chunk-QMSDKKYG.js} +1 -1
  98. package/dist/cli/chunks/{chunk-DCZV4QTP.js → chunk-RBDAHW2M.js} +2 -2
  99. package/dist/cli/chunks/{chunk-TLPIUYN3.js → chunk-RDJWUKIR.js} +2 -2
  100. package/dist/cli/chunks/{chunk-FDETLFX4.js → chunk-REJEFTWX.js} +1 -1
  101. package/dist/cli/chunks/{chunk-BVHLZ3TP.js → chunk-ROEIR3OD.js} +1 -1
  102. package/dist/cli/chunks/{chunk-GTJNB5B4.js → chunk-RTGNWRQI.js} +2 -2
  103. package/dist/cli/chunks/{chunk-XJJQZULZ.js → chunk-SL4TAJOE.js} +2 -2
  104. package/dist/cli/chunks/{chunk-ENJBAK7Y.js → chunk-T4DDCMKG.js} +113 -113
  105. package/dist/cli/chunks/{chunk-ZIX5MU4Q.js → chunk-TJGIIGKL.js} +2 -2
  106. package/dist/cli/chunks/{chunk-ZOORGOLY.js → chunk-TLCCM2AF.js} +1 -1
  107. package/dist/cli/chunks/{chunk-RBHWBTKA.js → chunk-TVHWI77X.js} +1 -1
  108. package/dist/cli/chunks/{chunk-P7HWW3VH.js → chunk-TYUIQSSF.js} +2 -2
  109. package/dist/cli/chunks/{chunk-YXMKMUQX.js → chunk-UIIEZMSM.js} +1 -1
  110. package/dist/cli/chunks/{chunk-VWDVQFEV.js → chunk-UIRTXM7C.js} +71 -71
  111. package/dist/cli/chunks/{chunk-2HUYG6Q6.js → chunk-UNXUSYRL.js} +3 -3
  112. package/dist/cli/chunks/chunk-VA45HLBF.js +2 -0
  113. package/dist/cli/chunks/{chunk-BMMXCDTH.js → chunk-VAIOZDG5.js} +1 -1
  114. package/dist/cli/chunks/{chunk-3YS4ZLL2.js → chunk-VLAGWLHF.js} +2 -2
  115. package/dist/cli/chunks/{chunk-SCXRYZ3U.js → chunk-VOOJDHLI.js} +14 -8
  116. package/dist/cli/chunks/{chunk-RRQH5BMQ.js → chunk-VSKABN3B.js} +29 -17
  117. package/dist/cli/chunks/{chunk-HHDPHHTX.js → chunk-VUL5HIKR.js} +2 -2
  118. package/dist/cli/chunks/{chunk-ZXWHKLZN.js → chunk-W7XVEWKQ.js} +1 -1
  119. package/dist/cli/chunks/{chunk-CZEQFAKE.js → chunk-WB6TI6Q3.js} +2 -2
  120. package/dist/cli/chunks/{chunk-YDBBXRH7.js → chunk-X2FLWV5C.js} +2 -2
  121. package/dist/cli/chunks/{chunk-G7LVJXZR.js → chunk-XE4YKDIM.js} +2 -2
  122. package/dist/cli/chunks/{chunk-A7ZCJ2XN.js → chunk-XGBIXRKD.js} +2 -2
  123. package/dist/cli/chunks/{chunk-B23E53WF.js → chunk-XMMWYQJK.js} +2 -2
  124. package/dist/cli/chunks/{chunk-3MFAU2JA.js → chunk-XNJ6DIEW.js} +2 -2
  125. package/dist/cli/chunks/{chunk-VJR2JIYP.js → chunk-XTWYCMAM.js} +2 -2
  126. package/dist/cli/chunks/{chunk-POV6V35B.js → chunk-XY3WUGD3.js} +2 -2
  127. package/dist/cli/chunks/{chunk-OU2FFOML.js → chunk-YEZJE2ZW.js} +4 -4
  128. package/dist/cli/chunks/{chunk-HDKXJMRS.js → chunk-YLEMSN46.js} +1 -1
  129. package/dist/cli/chunks/{chunk-SH7N3Y63.js → chunk-YMN4C32S.js} +3 -3
  130. package/dist/cli/chunks/{chunk-KIUJ4EI5.js → chunk-YN7HCVUP.js} +2 -2
  131. package/dist/cli/chunks/{chunk-WYSM5565.js → chunk-YQJBE6NX.js} +2 -2
  132. package/dist/cli/chunks/{chunk-QNIOQ4AR.js → chunk-ZBJRNCWX.js} +2 -2
  133. package/dist/cli/chunks/{chunk-NZIU2SEI.js → chunk-ZG4EKPGV.js} +1 -1
  134. package/dist/cli/chunks/{chunk-4ZAX5A6E.js → chunk-ZWSRIJ2T.js} +2 -2
  135. package/dist/cli/chunks/{ci-5BS5ALBZ.js → ci-LRTJSZHT.js} +2 -2
  136. package/dist/cli/chunks/{ci-output-I7CGW62R.js → ci-output-LISCHUKD.js} +2 -2
  137. package/dist/cli/chunks/{circuit-breaker-7P2V65XX.js → circuit-breaker-7PMP25KZ.js} +2 -2
  138. package/dist/cli/chunks/{claude-flow-setup-EKRLBRCE.js → claude-flow-setup-DOW4QVMC.js} +2 -2
  139. package/dist/cli/chunks/client-XF6SJO2C.js +2 -0
  140. package/dist/cli/chunks/{cline-installer-U6KRJJHQ.js → cline-installer-2NXQGW73.js} +2 -2
  141. package/dist/cli/chunks/{code-I6PB6YM7.js → code-3X6RWAS7.js} +2 -2
  142. package/dist/cli/chunks/{code-index-extractor-NP7JW32L.js → code-index-extractor-4ABP5WCP.js} +2 -2
  143. package/dist/cli/chunks/{codex-installer-52W4TK27.js → codex-installer-V7PII6GL.js} +2 -2
  144. package/dist/cli/chunks/{completions-LTOAC3Y5.js → completions-Y7LNQ63I.js} +2 -2
  145. package/dist/cli/chunks/{complexity-analyzer-RXAF5SX3.js → complexity-analyzer-XLYMAM6I.js} +2 -2
  146. package/dist/cli/chunks/{continuedev-installer-BNUOLW2M.js → continuedev-installer-GOT4TKNT.js} +2 -2
  147. package/dist/cli/chunks/{copilot-installer-YXANWEVX.js → copilot-installer-D6BAQVIO.js} +2 -2
  148. package/dist/cli/chunks/{cost-tracker-EBAHKAGL.js → cost-tracker-VT7C5Q52.js} +2 -2
  149. package/dist/cli/chunks/{coverage-SWVKYJ6V.js → coverage-C62MRP4M.js} +3 -3
  150. package/dist/cli/chunks/cross-domain-router-J2OFPM6R.js +2 -0
  151. package/dist/cli/chunks/{cursor-installer-QIZPJ5YQ.js → cursor-installer-WAWSS2K2.js} +2 -2
  152. package/dist/cli/chunks/{daemon-YPL4BMZX.js → daemon-CP2ETHRF.js} +3 -3
  153. package/dist/cli/chunks/{dag-attention-scheduler-6XXECMF2.js → dag-attention-scheduler-SZIZWPV7.js} +2 -2
  154. package/dist/cli/chunks/{detect-GGTJLBM6.js → detect-AJX6NJEP.js} +2 -2
  155. package/dist/cli/chunks/{dist-node-B6P2AD27.js → dist-node-E5X47QTY.js} +2 -2
  156. package/dist/cli/chunks/{domain-handler-TSZJEND7.js → domain-handler-FN3PIP45.js} +2 -2
  157. package/dist/cli/chunks/{domain-transfer-EBKK2ZKV.js → domain-transfer-N3TOJEMT.js} +2 -2
  158. package/dist/cli/chunks/dream-D5LD5SOZ.js +2 -0
  159. package/dist/cli/chunks/{embed-and-insert-pattern-OMRWRS6V.js → embed-and-insert-pattern-PJI5TZKR.js} +2 -2
  160. package/dist/cli/chunks/{eval-Q5PAQA5O.js → eval-OS54TDQU.js} +2 -2
  161. package/dist/cli/chunks/{experience-capture-middleware-5MOUWAON.js → experience-capture-middleware-FBM4ANZW.js} +3 -3
  162. package/dist/cli/chunks/{fast-paths-32E3N4KU.js → fast-paths-2CVAAPQO.js} +2 -2
  163. package/dist/cli/chunks/{feature-flags-WRIWP5VL.js → feature-flags-A5KFWVFC.js} +2 -2
  164. package/dist/cli/chunks/{feature-flags-VERJA5SQ.js → feature-flags-GEXTW6OT.js} +2 -2
  165. package/dist/cli/chunks/{file-discovery-2X6CZSTB.js → file-discovery-KWLVC7KN.js} +2 -2
  166. package/dist/cli/chunks/{fleet-VB2JTP7P.js → fleet-MNKH356S.js} +3 -3
  167. package/dist/cli/chunks/{gnn-wrapper-HNKBFKUD.js → gnn-wrapper-ALTWYFVZ.js} +2 -2
  168. package/dist/cli/chunks/{heartbeat-handler-Y5GIRQNS.js → heartbeat-handler-MBMEPEGW.js} +4 -4
  169. package/dist/cli/chunks/{heartbeat-scheduler-UGB57DTJ.js → heartbeat-scheduler-OH3SS7MH.js} +2 -2
  170. package/dist/cli/chunks/hnsw-adapter-M2MMM3N6.js +2 -0
  171. package/dist/cli/chunks/hnsw-index-JO7KNF7M.js +2 -0
  172. package/dist/cli/chunks/{hnsw-legacy-bridge-A6G6GPMS.js → hnsw-legacy-bridge-WTD5PR5V.js} +2 -2
  173. package/dist/cli/chunks/{better-sqlite3-XT27JRMH.js → hnswlib-node-WENGW3YX.js} +2 -2
  174. package/dist/cli/chunks/hooks-ELHGEBFK.js +248 -0
  175. package/dist/cli/chunks/{hybrid-router-LTAQGTNR.js → hybrid-router-D6ZMIZCE.js} +2 -2
  176. package/dist/cli/chunks/{hypergraph-engine-IRTPRX6K.js → hypergraph-engine-JOQ6TERZ.js} +2 -2
  177. package/dist/cli/chunks/{hypergraph-handler-6IVDHP2K.js → hypergraph-handler-HX45YWWN.js} +3 -3
  178. package/dist/cli/chunks/impact-analyzer-ROQL4J7P.js +2 -0
  179. package/dist/cli/chunks/{init-handler-NNLOQN2F.js → init-handler-TNVU6NQ6.js} +6 -6
  180. package/dist/cli/chunks/init-wizard-4BDFZX4M.js +2 -0
  181. package/dist/cli/chunks/kernel-37Y63WKR.js +2 -0
  182. package/dist/cli/chunks/{kilocode-installer-Q5A6WBX2.js → kilocode-installer-YC5RJIY4.js} +2 -2
  183. package/dist/cli/chunks/{kiro-installer-ZVOLX6AX.js → kiro-installer-EAB26M55.js} +2 -2
  184. package/dist/cli/chunks/knowledge-graph-V3DX6ZCX.js +2 -0
  185. package/dist/cli/chunks/learning-A2OB7D2B.js +117 -0
  186. package/dist/cli/chunks/{llm-router-EFIOXD3E.js → llm-router-KEG6PA7C.js} +4 -4
  187. package/dist/cli/chunks/{load-7HYD5K5T.js → load-D6ZDLVA3.js} +2 -2
  188. package/dist/cli/chunks/load-test-HPBA2CMT.js +2 -0
  189. package/dist/cli/chunks/{mcp-TQEPJY5L.js → mcp-ERJHZ6FN.js} +2 -2
  190. package/dist/cli/chunks/{memory-2P5KRDUP.js → memory-GSRIJIVR.js} +5 -5
  191. package/dist/cli/chunks/memory-backend-DODDBB46.js +2 -0
  192. package/dist/cli/chunks/memory-handlers-MFLCRS7V.js +2 -0
  193. package/dist/cli/chunks/{multi-model-executor-Z74ALKIH.js → multi-model-executor-GK3V7ERC.js} +2 -2
  194. package/dist/cli/chunks/{opencode-installer-2NICPXQZ.js → opencode-installer-6TTN26RG.js} +2 -2
  195. package/dist/cli/chunks/{orchestrator-ZPVU3M4M.js → orchestrator-YVTSM6QW.js} +37 -18
  196. package/dist/cli/chunks/{pipeline-B55E7S5P.js → pipeline-EWLJCY5G.js} +2 -2
  197. package/dist/cli/chunks/{platform-6FY6335Y.js → platform-2ULHQQME.js} +2 -2
  198. package/dist/cli/chunks/{plugin-F23VOSIL.js → plugin-PYN2KOXA.js} +2 -2
  199. package/dist/cli/chunks/{prime-radiant-advanced-wasm-LL7WPCNW.js → prime-radiant-advanced-wasm-IULCTOGZ.js} +2 -2
  200. package/dist/cli/chunks/protocol-executor-D56OYMCJ.js +2 -0
  201. package/dist/cli/chunks/{protocol-handler-JWPPGEUR.js → protocol-handler-FZYI2SBP.js} +2 -2
  202. package/dist/cli/chunks/{prove-S4PD63BK.js → prove-DN7S74SP.js} +2 -2
  203. package/dist/cli/chunks/{provider-manager-R7YYUTO3.js → provider-manager-FT3MCROB.js} +2 -2
  204. package/dist/cli/chunks/qe-reasoning-bank-KXROIEK7.js +2 -0
  205. package/dist/cli/chunks/{quality-UIG6G2BR.js → quality-ITBU6LGC.js} +2 -2
  206. package/dist/cli/chunks/queen-coordinator-XOGATERL.js +2 -0
  207. package/dist/cli/chunks/{real-embeddings-7GJEWY4C.js → real-embeddings-PZUZ5RXJ.js} +2 -2
  208. package/dist/cli/chunks/{roocode-installer-Y5YVCVVS.js → roocode-installer-2LMVZOUZ.js} +2 -2
  209. package/dist/cli/chunks/router-3EHNUCOM.js +2 -0
  210. package/dist/cli/chunks/routing-feedback-ZHKGET22.js +2 -0
  211. package/dist/cli/chunks/{routing-handler-YFBT7LZH.js → routing-handler-5RB73UCF.js} +2 -2
  212. package/dist/cli/chunks/{ruvector-commands-7WCRMBWZ.js → ruvector-commands-VBN4APMG.js} +2 -2
  213. package/dist/cli/chunks/{rvf-dual-writer-PPZ5AVFW.js → rvf-dual-writer-BNY4AUWT.js} +2 -2
  214. package/dist/cli/chunks/{rvf-migration-adapter-SVW4AKVC.js → rvf-migration-adapter-73MKPBGV.js} +2 -2
  215. package/dist/cli/chunks/{rvf-migration-coordinator-TNCPU743.js → rvf-migration-coordinator-SGVB7ZAZ.js} +2 -2
  216. package/dist/cli/chunks/rvf-native-adapter-4YC5IQUW.js +2 -0
  217. package/dist/cli/chunks/safe-db-PLJRHQIC.js +2 -0
  218. package/dist/cli/chunks/schedule-7DGELVJE.js +2 -0
  219. package/dist/cli/chunks/scheduler-VWASEC2J.js +2 -0
  220. package/dist/cli/chunks/{security-22YXZGU3.js → security-XUH4H7R3.js} +3 -3
  221. package/dist/cli/chunks/shared-rvf-adapter-DCVDY2XW.js +2 -0
  222. package/dist/cli/chunks/{shared-rvf-dual-writer-Q5OSQNW5.js → shared-rvf-dual-writer-GML4EDYF.js} +2 -2
  223. package/dist/cli/chunks/sqlite-persistence-CTEBGVOW.js +2 -0
  224. package/dist/cli/chunks/{status-handler-CTEEZTVQ.js → status-handler-XI7GJF6Z.js} +2 -2
  225. package/dist/cli/chunks/{structural-health-S72DLFPZ.js → structural-health-WPCYKOXV.js} +2 -2
  226. package/dist/cli/chunks/{sync-2AJ5S27F.js → sync-SFKTCRZC.js} +10 -10
  227. package/dist/cli/chunks/{task-handler-XQCQAUM3.js → task-handler-FZB55IEG.js} +2 -2
  228. package/dist/cli/chunks/{task-handlers-U6DXLSYJ.js → task-handlers-EXZGFH7F.js} +3 -3
  229. package/dist/cli/chunks/{test-K7C4CWFH.js → test-XYRN4OVU.js} +4 -4
  230. package/dist/cli/chunks/{test-scheduling-WQBR6C3V.js → test-scheduling-FLVOPGOT.js} +5 -5
  231. package/dist/cli/chunks/{token-bootstrap-IRZHAD7N.js → token-bootstrap-FDCFVRHM.js} +2 -2
  232. package/dist/cli/chunks/{token-usage-DIK6QRD5.js → token-usage-MHNZF3DM.js} +2 -2
  233. package/dist/cli/chunks/{transformers-RPUPJLSR.js → transformers-4CRVTMWY.js} +2 -2
  234. package/dist/cli/chunks/{tree-sitter-wasm-parser-A45KH4YZ.js → tree-sitter-wasm-parser-CI3V4AND.js} +2 -2
  235. package/dist/cli/chunks/{types-LO5DGIJC.js → types-RKCD4BNL.js} +2 -2
  236. package/dist/cli/chunks/unified-memory-YDKXKW3D.js +2 -0
  237. package/dist/cli/chunks/unified-memory-hnsw-6N7YZCLR.js +2 -0
  238. package/dist/cli/chunks/unified-persistence-UTWLPUQI.js +2 -0
  239. package/dist/cli/chunks/{upgrade-QZNMQOBY.js → upgrade-463W7VKH.js} +2 -2
  240. package/dist/cli/chunks/{validate-675K5FDZ.js → validate-LENSMEAY.js} +2 -2
  241. package/dist/cli/chunks/{validate-swarm-TJXJFTT4.js → validate-swarm-4FEBNAWA.js} +2 -2
  242. package/dist/cli/chunks/{vibium-2FFU5KPE.js → vibium-TXNVIVWJ.js} +2 -2
  243. package/dist/cli/chunks/visual-security-DGXSOFKD.js +2 -0
  244. package/dist/cli/chunks/{web-tree-sitter-VX55VO25.js → web-tree-sitter-BZEGWID4.js} +2 -2
  245. package/dist/cli/chunks/{windsurf-installer-A7FNN7RB.js → windsurf-installer-7AFXJTPU.js} +2 -2
  246. package/dist/cli/chunks/{witness-chain-QLIBCLCH.js → witness-chain-G6SUZOZG.js} +2 -2
  247. package/dist/cli/chunks/witness-chain-VP4MF6EU.js +2 -0
  248. package/dist/cli/chunks/{workflow-LQDA5VYM.js → workflow-EVQPO6FH.js} +4 -4
  249. package/dist/cli/chunks/workflow-orchestrator-VXSYAKQY.js +2 -0
  250. package/dist/cli/chunks/{wrappers-KE6AZMO6.js → wrappers-HR6RUDI2.js} +2 -2
  251. package/dist/cli/commands/hooks-handlers/editing-hooks.js +9 -3
  252. package/dist/cli/commands/hooks-handlers/hooks-dream-learning.js +16 -24
  253. package/dist/cli/commands/hooks-handlers/hooks-shared.d.ts +1 -1
  254. package/dist/cli/commands/hooks-handlers/hooks-shared.js +8 -1
  255. package/dist/cli/commands/hooks-handlers/routing-hooks.js +15 -3
  256. package/dist/cli/commands/hooks-handlers/task-hooks.js +37 -46
  257. package/dist/cli/commands/learning.js +194 -0
  258. package/dist/cli/commands/sync.js +3 -0
  259. package/dist/domains/requirements-validation/services/quality-criteria/quality-criteria-service.js +4 -1
  260. package/dist/init/phases/07-hooks.js +4 -1
  261. package/dist/init/phases/10-workers.js +24 -2
  262. package/dist/integrations/agentic-flow/onnx-embeddings/embedding-generator.js +15 -12
  263. package/dist/integrations/n8n/agent-factory.js +4 -1
  264. package/dist/integrations/n8n/n8n-adapter.js +4 -1
  265. package/dist/kernel/interfaces.d.ts +12 -0
  266. package/dist/kernel/kernel.d.ts +1 -0
  267. package/dist/kernel/kernel.js +57 -0
  268. package/dist/kernel/unified-memory-schemas.d.ts +1 -1
  269. package/dist/kernel/unified-memory-schemas.js +7 -1
  270. package/dist/learning/agent-routing.d.ts +134 -1
  271. package/dist/learning/agent-routing.js +185 -2
  272. package/dist/learning/dream/dream-insights-pruner.d.ts +49 -0
  273. package/dist/learning/dream/dream-insights-pruner.js +53 -0
  274. package/dist/learning/dream/dream-scheduler.js +17 -0
  275. package/dist/learning/loop-health.d.ts +84 -0
  276. package/dist/learning/loop-health.js +91 -0
  277. package/dist/learning/pattern-usage-recorder.d.ts +58 -0
  278. package/dist/learning/pattern-usage-recorder.js +72 -0
  279. package/dist/learning/qe-reasoning-bank-types.d.ts +11 -0
  280. package/dist/learning/qe-reasoning-bank.d.ts +11 -0
  281. package/dist/learning/qe-reasoning-bank.js +86 -3
  282. package/dist/learning/routing-topology-gate.d.ts +40 -0
  283. package/dist/learning/routing-topology-gate.js +55 -0
  284. package/dist/learning/sqlite-persistence.d.ts +6 -1
  285. package/dist/learning/sqlite-persistence.js +14 -20
  286. package/dist/mcp/bundle.js +3833 -3807
  287. package/dist/mcp/handlers/domain-handler-configs.js +72 -13
  288. package/dist/mcp/protocol-server.d.ts +6 -0
  289. package/dist/mcp/protocol-server.js +91 -2
  290. package/dist/mcp/tools/coherence/collapse.d.ts +4 -0
  291. package/dist/mcp/tools/coherence/collapse.js +48 -21
  292. package/dist/mcp/tools/embeddings/embedding.js +5 -2
  293. package/dist/routing/routing-feedback.js +7 -3
  294. package/dist/routing/routing-outcomes-migration.d.ts +31 -0
  295. package/dist/routing/routing-outcomes-migration.js +60 -0
  296. package/dist/test-scheduling/pipeline.d.ts +1 -1
  297. package/dist/test-scheduling/pipeline.js +8 -2
  298. package/dist/workers/workers/learning-consolidation.d.ts +28 -0
  299. package/dist/workers/workers/learning-consolidation.js +204 -0
  300. package/dist/workflows/browser/workflow-loader.js +4 -1
  301. package/package.json +1 -1
  302. package/dist/cli/chunks/adapter-4NVP2SYD.js +0 -2
  303. package/dist/cli/chunks/aqe-learning-engine-ZTR5KIGB.js +0 -2
  304. package/dist/cli/chunks/base-2M65XYDE.js +0 -2
  305. package/dist/cli/chunks/browser-workflow-7EXB6DUF.js +0 -2
  306. package/dist/cli/chunks/chunk-6ZJROHI3.js +0 -2
  307. package/dist/cli/chunks/chunk-J3CLEYJP.js +0 -14
  308. package/dist/cli/chunks/chunk-SRSL5OFF.js +0 -180
  309. package/dist/cli/chunks/chunk-WLPP7V3W.js +0 -95
  310. package/dist/cli/chunks/chunk-YXS6SHB2.js +0 -2
  311. package/dist/cli/chunks/client-KTEVHNVO.js +0 -2
  312. package/dist/cli/chunks/cross-domain-router-23RTLMQL.js +0 -2
  313. package/dist/cli/chunks/dream-KNO2ZF24.js +0 -2
  314. package/dist/cli/chunks/hnsw-adapter-JQHOAYXA.js +0 -2
  315. package/dist/cli/chunks/hnsw-index-AIUQDZLY.js +0 -2
  316. package/dist/cli/chunks/hooks-Z4U7DCTP.js +0 -259
  317. package/dist/cli/chunks/impact-analyzer-ULJRGNBM.js +0 -2
  318. package/dist/cli/chunks/init-wizard-R2WC5V2W.js +0 -2
  319. package/dist/cli/chunks/kernel-ZDQG4UWQ.js +0 -2
  320. package/dist/cli/chunks/knowledge-graph-RLCAQW6I.js +0 -2
  321. package/dist/cli/chunks/learning-NZLHSX4F.js +0 -107
  322. package/dist/cli/chunks/load-test-KH35UZSW.js +0 -2
  323. package/dist/cli/chunks/memory-backend-NOYRJTBH.js +0 -2
  324. package/dist/cli/chunks/memory-handlers-YEQ4LSIX.js +0 -2
  325. package/dist/cli/chunks/protocol-executor-OL36TRHK.js +0 -2
  326. package/dist/cli/chunks/qe-reasoning-bank-C4QW56VE.js +0 -2
  327. package/dist/cli/chunks/queen-coordinator-FDDIA6BW.js +0 -2
  328. package/dist/cli/chunks/router-RRKX62UE.js +0 -2
  329. package/dist/cli/chunks/routing-feedback-NRJJVC35.js +0 -2
  330. package/dist/cli/chunks/rvf-native-adapter-TQLQYN7Y.js +0 -2
  331. package/dist/cli/chunks/safe-db-COFZGOYL.js +0 -2
  332. package/dist/cli/chunks/schedule-QAMKOCVJ.js +0 -2
  333. package/dist/cli/chunks/scheduler-RFETEEGY.js +0 -2
  334. package/dist/cli/chunks/shared-rvf-adapter-QNA66NKB.js +0 -2
  335. package/dist/cli/chunks/sqlite-persistence-43TV2RI3.js +0 -2
  336. package/dist/cli/chunks/unified-memory-VSSMXGHP.js +0 -2
  337. package/dist/cli/chunks/unified-memory-hnsw-ZV324XYA.js +0 -2
  338. package/dist/cli/chunks/unified-persistence-EE2UVIXW.js +0 -2
  339. package/dist/cli/chunks/visual-security-LWH7LME7.js +0 -2
  340. package/dist/cli/chunks/witness-chain-3YAV5SLZ.js +0 -2
  341. package/dist/cli/chunks/workflow-orchestrator-4UG2CNYN.js +0 -2
@@ -7,7 +7,6 @@
7
7
  * @module onnx-embeddings/embedding-generator
8
8
  */
9
9
  import { EmbeddingModel, EmbeddingError, EmbeddingErrorType } from './types.js';
10
- import { secureRandom } from '../../../shared/utils/crypto-random.js';
11
10
  /**
12
11
  * LRU Cache for embeddings
13
12
  */
@@ -84,23 +83,27 @@ export class EmbeddingGenerator {
84
83
  return;
85
84
  }
86
85
  try {
87
- // In production, this would call the MCP embeddings_init tool
88
- // For now, we create a mock that bridges to the real implementation
86
+ // Issue #469: the previous mock implementation generated random vectors
87
+ // per call, which made cosine similarity meaningless. We now route
88
+ // through the shared @xenova/transformers pipeline (all-MiniLM-L6-v2)
89
+ // via real-embeddings.computeRealEmbedding, so identical text yields
90
+ // identical vectors and semantically-related text yields high cosine
91
+ // similarity.
92
+ const { computeRealEmbedding } = await import('../../../learning/real-embeddings.js');
89
93
  this.onnxRuntime = {
90
- generateEmbedding: async (text, model) => {
91
- // Bridge to agentic-flow MCP tool: embeddings_generate
92
- // This would call: mcp__claude-flow__embeddings_generate({ text, normalize: true })
93
- // Mock implementation - in production, this calls ONNX
94
- const dimensions = model === EmbeddingModel.MINI_LM_L6 ? 384 : 768;
95
- const vector = new Array(dimensions).fill(0).map(() => secureRandom() * 2 - 1);
96
- // Normalize if configured
94
+ generateEmbedding: async (text, _model) => {
95
+ // computeRealEmbedding already normalizes (pooling: mean, normalize: true)
96
+ // and returns a 384-dimensional vector for MiniLM-L6-v2. We honor the
97
+ // generator's `config.normalize` flag for parity with the previous mock.
98
+ const vector = await computeRealEmbedding(text);
97
99
  if (this.config.normalize) {
98
100
  const norm = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
99
- return vector.map(val => val / norm);
101
+ if (norm > 0)
102
+ return vector.map(val => val / norm);
100
103
  }
101
104
  return vector;
102
105
  },
103
- isAvailable: () => true
106
+ isAvailable: () => true,
104
107
  };
105
108
  this.isInitialized = true;
106
109
  }
@@ -7,10 +7,13 @@
7
7
  * IMPORTANT: This requires v2 to be built first (`npm run build` in root)
8
8
  */
9
9
  import { randomUUID } from 'crypto';
10
- import { resolve } from 'path';
10
+ import { resolve, dirname } from 'path';
11
+ import { fileURLToPath } from 'url';
11
12
  import { existsSync } from 'fs';
12
13
  import { N8N_TO_V3_DOMAIN_MAP } from './workflow-mapper.js';
13
14
  import { toErrorMessage } from '../../shared/error-utils.js';
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
14
17
  // ============================================================================
15
18
  // Minimal MemoryStore Implementation (for V2 agent compatibility)
16
19
  // ============================================================================
@@ -5,7 +5,10 @@
5
5
  * Provides workflow analysis, domain routing, and agent coordination.
6
6
  */
7
7
  import { existsSync } from 'fs';
8
- import { resolve } from 'path';
8
+ import { resolve, dirname } from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
9
12
  import { N8N_TO_V3_DOMAIN_MAP, analyzeWorkflowForDomains, getAllDomains, getPrimaryDomain, } from './workflow-mapper.js';
10
13
  // ============================================================================
11
14
  // Default Configuration
@@ -297,6 +297,18 @@ export interface KernelConfig {
297
297
  * can set false to skip the plugin-load cost.
298
298
  */
299
299
  enableExperienceBridge?: boolean;
300
+ /**
301
+ * Whether to start the DreamScheduler during initialize() (ADR-094).
302
+ * When true (default), dream cycles run inside the long-lived kernel
303
+ * process instead of hook subprocesses. Hook subprocesses keep only
304
+ * `incrementDreamExperience` — the kernel-side scheduler is the
305
+ * authoritative trigger.
306
+ *
307
+ * Long-lived processes (MCP server, daemon) want this true.
308
+ * Short-lived CLI commands that complete in <1s can set false to skip
309
+ * DreamEngine init cost.
310
+ */
311
+ enableDreamScheduler?: boolean;
300
312
  }
301
313
  /**
302
314
  * Event middleware interface for anti-drift and other event processing (ADR-060)
@@ -21,6 +21,7 @@ export declare class QEKernelImpl implements QEKernel {
21
21
  private _initialized;
22
22
  private _loopTracker;
23
23
  private _experienceBridge?;
24
+ private _dreamScheduler?;
24
25
  constructor(config?: Partial<KernelConfig>);
25
26
  get eventBus(): EventBus;
26
27
  get coordinator(): AgentCoordinator;
@@ -19,6 +19,8 @@ import * as fs from 'fs';
19
19
  import { PluginLifecycleManager } from '../plugins/lifecycle';
20
20
  import { PluginCache } from '../plugins/cache';
21
21
  import { CapturedExperienceBridge } from '../bridge/captured-experience-bridge.js';
22
+ import { DreamScheduler } from '../learning/dream/dream-scheduler.js';
23
+ import { createDreamEngine } from '../learning/dream/dream-engine.js';
22
24
  // Import domain plugin factories
23
25
  import { createTestGenerationPlugin } from '../domains/test-generation/plugin';
24
26
  import { createTestExecutionPlugin } from '../domains/test-execution/plugin';
@@ -69,6 +71,10 @@ const DEFAULT_CONFIG = {
69
71
  // working out of the box. CLI commands that don't need event-driven
70
72
  // domain reactions opt out by passing `enableExperienceBridge: false`.
71
73
  enableExperienceBridge: true,
74
+ // ADR-094: kernel-side dream cycles. Defaults match the bridge — long-lived
75
+ // processes start the scheduler so dream cycles run in the kernel rather
76
+ // than inside hook subprocesses. Short-lived CLIs opt out.
77
+ enableDreamScheduler: true,
72
78
  };
73
79
  export class QEKernelImpl {
74
80
  _eventBus;
@@ -83,6 +89,10 @@ export class QEKernelImpl {
83
89
  // Issue #479: drains captured_experiences into the eventBus so hook-driven
84
90
  // activity reaches the 13 domain plugins' subscribeToEvents() handlers.
85
91
  _experienceBridge;
92
+ // ADR-094: kernel-side dream cycles. Replaces the in-hook
93
+ // checkAndTriggerDream path so 10-second SQLite write transactions move
94
+ // out of short-lived hook subprocesses into the long-lived kernel.
95
+ _dreamScheduler;
86
96
  constructor(config = {}) {
87
97
  this._config = { ...DEFAULT_CONFIG, ...config };
88
98
  this._startTime = new Date();
@@ -262,9 +272,56 @@ export class QEKernelImpl {
262
272
  this._experienceBridge = undefined;
263
273
  }
264
274
  }
275
+ // ADR-094: Start the kernel-side DreamScheduler so dream cycles run in
276
+ // the long-lived process. Hook subprocesses no longer trigger dreams —
277
+ // they only bump the experience counter (incrementDreamExperience).
278
+ // The scheduler subscribes to its own event triggers (quality-gate
279
+ // failure, domain milestones) and runs time-based dreams on its own
280
+ // cadence (default 1h). DreamEngine.ensureConceptsLoaded() auto-loads
281
+ // patterns from qe_patterns, so no separate ReasoningBank is needed here.
282
+ if (this._config.enableDreamScheduler !== false) {
283
+ try {
284
+ const dreamEngine = createDreamEngine({
285
+ maxDurationMs: 10_000,
286
+ minConceptsRequired: 3,
287
+ });
288
+ await dreamEngine.initialize();
289
+ this._dreamScheduler = new DreamScheduler({
290
+ dreamEngine,
291
+ eventBus: this._eventBus,
292
+ memoryBackend: this._memory,
293
+ });
294
+ await this._dreamScheduler.initialize();
295
+ this._dreamScheduler.start();
296
+ }
297
+ catch (err) {
298
+ console.warn('[QEKernel] DreamScheduler failed to start:', err instanceof Error ? err.message : err);
299
+ // Tear down anything we partially constructed so we don't leak a
300
+ // half-initialized scheduler (e.g., engine init succeeded but
301
+ // scheduler.start threw).
302
+ if (this._dreamScheduler) {
303
+ try {
304
+ await this._dreamScheduler.dispose();
305
+ }
306
+ catch { /* swallow during cleanup */ }
307
+ }
308
+ this._dreamScheduler = undefined;
309
+ }
310
+ }
265
311
  this._initialized = true;
266
312
  }
267
313
  async dispose() {
314
+ // ADR-094: Stop the dream scheduler first so a dream-in-progress doesn't
315
+ // try to write to a disposed memory backend.
316
+ if (this._dreamScheduler) {
317
+ try {
318
+ await this._dreamScheduler.dispose();
319
+ }
320
+ catch (err) {
321
+ console.warn('[QEKernel] DreamScheduler dispose failed:', err instanceof Error ? err.message : err);
322
+ }
323
+ this._dreamScheduler = undefined;
324
+ }
268
325
  // Stop the bridge first so it doesn't try to publish to a disposed bus.
269
326
  if (this._experienceBridge) {
270
327
  await this._experienceBridge.stop();
@@ -17,6 +17,6 @@ export declare const QE_PATTERNS_SCHEMA = "\n -- QE Patterns table (unified fro
17
17
  export declare const MINCUT_SCHEMA = "\n -- MinCut Graph Snapshots (ADR-047)\n CREATE TABLE IF NOT EXISTS mincut_snapshots (\n id TEXT PRIMARY KEY,\n timestamp TEXT NOT NULL DEFAULT (datetime('now')),\n vertex_count INTEGER NOT NULL,\n edge_count INTEGER NOT NULL,\n total_weight REAL NOT NULL DEFAULT 0.0,\n is_connected INTEGER NOT NULL DEFAULT 1,\n component_count INTEGER NOT NULL DEFAULT 1,\n vertices_json TEXT NOT NULL,\n edges_json TEXT NOT NULL,\n created_at TEXT DEFAULT (datetime('now'))\n );\n\n -- MinCut History (time-series MinCut values)\n CREATE TABLE IF NOT EXISTS mincut_history (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp TEXT NOT NULL DEFAULT (datetime('now')),\n mincut_value REAL NOT NULL,\n vertex_count INTEGER NOT NULL,\n edge_count INTEGER NOT NULL,\n algorithm TEXT NOT NULL DEFAULT 'weighted-degree',\n duration_ms INTEGER,\n snapshot_id TEXT,\n created_at TEXT DEFAULT (datetime('now')),\n FOREIGN KEY (snapshot_id) REFERENCES mincut_snapshots(id) ON DELETE SET NULL\n );\n\n -- MinCut Weak Vertices (detected bottlenecks)\n CREATE TABLE IF NOT EXISTS mincut_weak_vertices (\n id TEXT PRIMARY KEY,\n vertex_id TEXT NOT NULL,\n weighted_degree REAL NOT NULL,\n risk_score REAL NOT NULL,\n reason TEXT NOT NULL,\n domain TEXT,\n vertex_type TEXT NOT NULL,\n suggestions_json TEXT,\n detected_at TEXT NOT NULL DEFAULT (datetime('now')),\n resolved_at TEXT,\n snapshot_id TEXT,\n created_at TEXT DEFAULT (datetime('now')),\n FOREIGN KEY (snapshot_id) REFERENCES mincut_snapshots(id) ON DELETE SET NULL\n );\n\n -- MinCut Alerts\n CREATE TABLE IF NOT EXISTS mincut_alerts (\n id TEXT PRIMARY KEY,\n severity TEXT NOT NULL,\n message TEXT NOT NULL,\n mincut_value REAL NOT NULL,\n threshold REAL NOT NULL,\n affected_vertices_json TEXT,\n remediations_json TEXT,\n acknowledged INTEGER DEFAULT 0,\n acknowledged_at TEXT,\n acknowledged_by TEXT,\n timestamp TEXT NOT NULL DEFAULT (datetime('now')),\n created_at TEXT DEFAULT (datetime('now'))\n );\n\n -- MinCut Healing Actions (self-healing history)\n CREATE TABLE IF NOT EXISTS mincut_healing_actions (\n id TEXT PRIMARY KEY,\n action_type TEXT NOT NULL,\n action_params_json TEXT NOT NULL,\n success INTEGER NOT NULL,\n mincut_before REAL NOT NULL,\n mincut_after REAL NOT NULL,\n improvement REAL NOT NULL DEFAULT 0.0,\n error_message TEXT,\n duration_ms INTEGER NOT NULL,\n triggered_by TEXT,\n snapshot_before_id TEXT,\n snapshot_after_id TEXT,\n created_at TEXT DEFAULT (datetime('now')),\n FOREIGN KEY (snapshot_before_id) REFERENCES mincut_snapshots(id) ON DELETE SET NULL,\n FOREIGN KEY (snapshot_after_id) REFERENCES mincut_snapshots(id) ON DELETE SET NULL\n );\n\n -- MinCut Strange Loop Observations (P1: self-organizing)\n CREATE TABLE IF NOT EXISTS mincut_observations (\n id TEXT PRIMARY KEY,\n iteration INTEGER NOT NULL,\n mincut_value REAL NOT NULL,\n weak_vertex_count INTEGER NOT NULL DEFAULT 0,\n weak_vertices_json TEXT,\n snapshot_id TEXT,\n prediction_json TEXT,\n actual_vs_predicted_diff REAL,\n timestamp TEXT NOT NULL DEFAULT (datetime('now')),\n FOREIGN KEY (snapshot_id) REFERENCES mincut_snapshots(id) ON DELETE SET NULL\n );\n\n -- MinCut Indexes\n CREATE INDEX IF NOT EXISTS idx_mincut_history_timestamp ON mincut_history(timestamp DESC);\n CREATE INDEX IF NOT EXISTS idx_mincut_history_value ON mincut_history(mincut_value);\n CREATE INDEX IF NOT EXISTS idx_mincut_weak_vertex ON mincut_weak_vertices(vertex_id);\n CREATE INDEX IF NOT EXISTS idx_mincut_weak_risk ON mincut_weak_vertices(risk_score DESC);\n CREATE INDEX IF NOT EXISTS idx_mincut_weak_resolved ON mincut_weak_vertices(resolved_at);\n CREATE INDEX IF NOT EXISTS idx_mincut_alerts_severity ON mincut_alerts(severity);\n CREATE INDEX IF NOT EXISTS idx_mincut_alerts_ack ON mincut_alerts(acknowledged);\n CREATE INDEX IF NOT EXISTS idx_mincut_healing_type ON mincut_healing_actions(action_type);\n CREATE INDEX IF NOT EXISTS idx_mincut_healing_success ON mincut_healing_actions(success);\n CREATE INDEX IF NOT EXISTS idx_mincut_observations_iter ON mincut_observations(iteration);\n";
18
18
  export declare const SONA_PATTERNS_SCHEMA = "\n -- SONA Patterns table (ADR-046: Pattern Persistence for Neural Backbone)\n CREATE TABLE IF NOT EXISTS sona_patterns (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n domain TEXT NOT NULL,\n state_embedding BLOB,\n action_embedding BLOB,\n action_type TEXT NOT NULL,\n action_value TEXT,\n outcome_reward REAL NOT NULL DEFAULT 0.0,\n outcome_success INTEGER NOT NULL DEFAULT 0,\n outcome_quality REAL NOT NULL DEFAULT 0.0,\n confidence REAL DEFAULT 0.5,\n usage_count INTEGER DEFAULT 0,\n success_count INTEGER DEFAULT 0,\n failure_count INTEGER DEFAULT 0,\n metadata TEXT,\n created_at TEXT DEFAULT (datetime('now')),\n updated_at TEXT DEFAULT (datetime('now')),\n last_used_at TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_sona_patterns_type ON sona_patterns(type);\n CREATE INDEX IF NOT EXISTS idx_sona_patterns_domain ON sona_patterns(domain);\n CREATE INDEX IF NOT EXISTS idx_sona_patterns_confidence ON sona_patterns(confidence DESC);\n CREATE INDEX IF NOT EXISTS idx_sona_patterns_updated ON sona_patterns(updated_at DESC);\n";
19
19
  export declare const WITNESS_CHAIN_SCHEMA = "\n -- Witness Chain (ADR-070: Cryptographic audit trail for QE decisions)\n CREATE TABLE IF NOT EXISTS witness_chain (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n prev_hash TEXT NOT NULL,\n action_hash TEXT NOT NULL,\n action_type TEXT NOT NULL,\n action_data TEXT,\n timestamp TEXT NOT NULL,\n actor TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_witness_action_type ON witness_chain(action_type);\n CREATE INDEX IF NOT EXISTS idx_witness_timestamp ON witness_chain(timestamp);\n";
20
- export declare const FEEDBACK_SCHEMA = "\n -- Test outcomes (ADR-023: Quality Feedback Loop)\n CREATE TABLE IF NOT EXISTS test_outcomes (\n id TEXT PRIMARY KEY,\n test_id TEXT NOT NULL,\n test_name TEXT NOT NULL,\n generated_by TEXT NOT NULL,\n pattern_id TEXT,\n framework TEXT NOT NULL,\n language TEXT NOT NULL,\n domain TEXT NOT NULL,\n passed INTEGER NOT NULL,\n error_message TEXT,\n coverage_lines REAL DEFAULT 0,\n coverage_branches REAL DEFAULT 0,\n coverage_functions REAL DEFAULT 0,\n mutation_score REAL,\n execution_time_ms REAL NOT NULL,\n flaky INTEGER DEFAULT 0,\n flakiness_score REAL,\n maintainability_score REAL NOT NULL,\n complexity REAL,\n lines_of_code INTEGER,\n assertion_count INTEGER,\n file_path TEXT,\n source_file_path TEXT,\n metadata_json TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_pattern ON test_outcomes(pattern_id);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_agent ON test_outcomes(generated_by);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_domain ON test_outcomes(domain);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_created ON test_outcomes(created_at);\n\n -- Routing outcomes (ADR-022: Adaptive QE Agent Routing, ADR-092: advisor_consultation_json)\n CREATE TABLE IF NOT EXISTS routing_outcomes (\n id TEXT PRIMARY KEY,\n task_json TEXT NOT NULL,\n decision_json TEXT NOT NULL,\n used_agent TEXT NOT NULL,\n followed_recommendation INTEGER NOT NULL,\n success INTEGER NOT NULL,\n quality_score REAL NOT NULL,\n duration_ms REAL NOT NULL,\n error TEXT,\n model_tier TEXT,\n advisor_consultation_json TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_agent ON routing_outcomes(used_agent);\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_created ON routing_outcomes(created_at);\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_tier ON routing_outcomes(model_tier);\n\n -- Coverage sessions (ADR-023: Coverage Learning)\n CREATE TABLE IF NOT EXISTS coverage_sessions (\n id TEXT PRIMARY KEY,\n target_path TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n technique TEXT NOT NULL,\n before_lines REAL DEFAULT 0,\n before_branches REAL DEFAULT 0,\n before_functions REAL DEFAULT 0,\n after_lines REAL DEFAULT 0,\n after_branches REAL DEFAULT 0,\n after_functions REAL DEFAULT 0,\n tests_generated INTEGER DEFAULT 0,\n tests_passed INTEGER DEFAULT 0,\n gaps_json TEXT,\n duration_ms REAL NOT NULL,\n started_at TEXT NOT NULL,\n completed_at TEXT NOT NULL,\n context_json TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_technique ON coverage_sessions(technique);\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_agent ON coverage_sessions(agent_id);\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_created ON coverage_sessions(created_at);\n";
20
+ export declare const FEEDBACK_SCHEMA = "\n -- Test outcomes (ADR-023: Quality Feedback Loop)\n CREATE TABLE IF NOT EXISTS test_outcomes (\n id TEXT PRIMARY KEY,\n test_id TEXT NOT NULL,\n test_name TEXT NOT NULL,\n generated_by TEXT NOT NULL,\n pattern_id TEXT,\n framework TEXT NOT NULL,\n language TEXT NOT NULL,\n domain TEXT NOT NULL,\n passed INTEGER NOT NULL,\n error_message TEXT,\n coverage_lines REAL DEFAULT 0,\n coverage_branches REAL DEFAULT 0,\n coverage_functions REAL DEFAULT 0,\n mutation_score REAL,\n execution_time_ms REAL NOT NULL,\n flaky INTEGER DEFAULT 0,\n flakiness_score REAL,\n maintainability_score REAL NOT NULL,\n complexity REAL,\n lines_of_code INTEGER,\n assertion_count INTEGER,\n file_path TEXT,\n source_file_path TEXT,\n metadata_json TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_pattern ON test_outcomes(pattern_id);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_agent ON test_outcomes(generated_by);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_domain ON test_outcomes(domain);\n CREATE INDEX IF NOT EXISTS idx_test_outcomes_created ON test_outcomes(created_at);\n\n -- Routing outcomes (ADR-022: Adaptive QE Agent Routing, ADR-092: advisor_consultation_json,\n -- ADR-095: exploration / criticality / q_weight for \u03B5-greedy routing telemetry)\n CREATE TABLE IF NOT EXISTS routing_outcomes (\n id TEXT PRIMARY KEY,\n task_json TEXT NOT NULL,\n decision_json TEXT NOT NULL,\n used_agent TEXT NOT NULL,\n followed_recommendation INTEGER NOT NULL,\n success INTEGER NOT NULL,\n quality_score REAL NOT NULL,\n duration_ms REAL NOT NULL,\n error TEXT,\n model_tier TEXT,\n advisor_consultation_json TEXT,\n -- ADR-095: routing exploration telemetry\n exploration INTEGER NOT NULL DEFAULT 0,\n criticality REAL,\n q_weight REAL,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_agent ON routing_outcomes(used_agent);\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_created ON routing_outcomes(created_at);\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_tier ON routing_outcomes(model_tier);\n CREATE INDEX IF NOT EXISTS idx_routing_outcomes_exploration ON routing_outcomes(exploration);\n\n -- Coverage sessions (ADR-023: Coverage Learning)\n CREATE TABLE IF NOT EXISTS coverage_sessions (\n id TEXT PRIMARY KEY,\n target_path TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n technique TEXT NOT NULL,\n before_lines REAL DEFAULT 0,\n before_branches REAL DEFAULT 0,\n before_functions REAL DEFAULT 0,\n after_lines REAL DEFAULT 0,\n after_branches REAL DEFAULT 0,\n after_functions REAL DEFAULT 0,\n tests_generated INTEGER DEFAULT 0,\n tests_passed INTEGER DEFAULT 0,\n gaps_json TEXT,\n duration_ms REAL NOT NULL,\n started_at TEXT NOT NULL,\n completed_at TEXT NOT NULL,\n context_json TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n );\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_technique ON coverage_sessions(technique);\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_agent ON coverage_sessions(agent_id);\n CREATE INDEX IF NOT EXISTS idx_coverage_sessions_created ON coverage_sessions(created_at);\n";
21
21
  export declare const STATS_TABLES: string[];
22
22
  //# sourceMappingURL=unified-memory-schemas.d.ts.map
@@ -540,7 +540,8 @@ export const FEEDBACK_SCHEMA = `
540
540
  CREATE INDEX IF NOT EXISTS idx_test_outcomes_domain ON test_outcomes(domain);
541
541
  CREATE INDEX IF NOT EXISTS idx_test_outcomes_created ON test_outcomes(created_at);
542
542
 
543
- -- Routing outcomes (ADR-022: Adaptive QE Agent Routing, ADR-092: advisor_consultation_json)
543
+ -- Routing outcomes (ADR-022: Adaptive QE Agent Routing, ADR-092: advisor_consultation_json,
544
+ -- ADR-095: exploration / criticality / q_weight for ε-greedy routing telemetry)
544
545
  CREATE TABLE IF NOT EXISTS routing_outcomes (
545
546
  id TEXT PRIMARY KEY,
546
547
  task_json TEXT NOT NULL,
@@ -553,11 +554,16 @@ export const FEEDBACK_SCHEMA = `
553
554
  error TEXT,
554
555
  model_tier TEXT,
555
556
  advisor_consultation_json TEXT,
557
+ -- ADR-095: routing exploration telemetry
558
+ exploration INTEGER NOT NULL DEFAULT 0,
559
+ criticality REAL,
560
+ q_weight REAL,
556
561
  created_at TEXT DEFAULT (datetime('now'))
557
562
  );
558
563
  CREATE INDEX IF NOT EXISTS idx_routing_outcomes_agent ON routing_outcomes(used_agent);
559
564
  CREATE INDEX IF NOT EXISTS idx_routing_outcomes_created ON routing_outcomes(created_at);
560
565
  CREATE INDEX IF NOT EXISTS idx_routing_outcomes_tier ON routing_outcomes(model_tier);
566
+ CREATE INDEX IF NOT EXISTS idx_routing_outcomes_exploration ON routing_outcomes(exploration);
561
567
 
562
568
  -- Coverage sessions (ADR-023: Coverage Learning)
563
569
  CREATE TABLE IF NOT EXISTS coverage_sessions (
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Agentic QE v3 - Agent Routing
3
3
  * ADR-021: QE ReasoningBank for Pattern Learning
4
+ * ADR-095: ε-greedy exploration with Q-value blending and mincut safety gate
4
5
  *
5
6
  * Static agent capability mapping and routing score calculation
6
7
  * used by QEReasoningBank.routeTask().
@@ -22,11 +23,28 @@ export interface AgentCapabilityProfile {
22
23
  export declare const AGENT_CAPABILITIES: Record<string, AgentCapabilityProfile>;
23
24
  /**
24
25
  * Scored agent with reasoning trace.
26
+ *
27
+ * ADR-095 telemetry fields (all optional, populated only when the
28
+ * corresponding signal source is wired):
29
+ * - `staticScore`: the pre-blend score (domain + capability + perf + …)
30
+ * - `qWeight`, `qValue`: when Q-table data was available
31
+ * - `exploration`: true if this agent was promoted to position 0 by the
32
+ * ε-greedy policy rather than scored to the top deterministically
25
33
  */
26
34
  export interface ScoredAgent {
27
35
  agent: string;
28
36
  score: number;
29
37
  reasoning: string[];
38
+ /** ADR-095: pre-blend static score for retrospective explainability */
39
+ staticScore?: number;
40
+ /** ADR-095: Q-value influence (0..MAX_Q_WEIGHT) on the final score */
41
+ qWeight?: number;
42
+ /** ADR-095: raw q_value from rl_q_values, for telemetry */
43
+ qValue?: number;
44
+ /** ADR-095: number of (state_key, action_key) visits behind the Q value */
45
+ qVisits?: number;
46
+ /** ADR-095: true when ε-greedy promoted this agent over the greedy winner */
47
+ exploration?: boolean;
30
48
  }
31
49
  /**
32
50
  * Routing weight configuration.
@@ -38,6 +56,114 @@ export interface RoutingWeights {
38
56
  /** Weight for language match boost (default: 1.0) */
39
57
  language?: number;
40
58
  }
59
+ /**
60
+ * Maximum Q-value influence on the final score.
61
+ *
62
+ * 0.4 means a fully-mature Q-value can move the score by up to ±0.2 (since
63
+ * normalizedQ ranges over (0, 1) and the static contribution clamps the
64
+ * upper bound). This is intentionally bounded so Q-values inform rather
65
+ * than override the static features.
66
+ *
67
+ * Tuning: post-deploy telemetry will tell us whether agents are actually
68
+ * being separated by Q-values. If the avg `q_weight` in routing_outcomes
69
+ * climbs but quality_score doesn't improve, this constant is too high.
70
+ */
71
+ export declare const MAX_Q_WEIGHT = 0.4;
72
+ /**
73
+ * Number of (state_key, action_key) visits at which qWeight saturates at
74
+ * MAX_Q_WEIGHT. Below this, qWeight ramps linearly from 0.
75
+ *
76
+ * 20 visits at the default 30-min worker tick + typical session cadence
77
+ * implies ~1 week of activity before a (state, agent) pair drives the
78
+ * decision. Adjust downward if cold-start latency proves problematic.
79
+ */
80
+ export declare const QWEIGHT_RAMP_VISITS = 20;
81
+ /**
82
+ * Q-value lookup callback supplied by the caller (QEReasoningBank.routeTask).
83
+ * Returns undefined when the (stateKey, agentType) pair has no recorded
84
+ * Q-value yet — caller does not need to handle missing-row vs zero-visits.
85
+ */
86
+ export type QValueLookup = (agentType: string) => {
87
+ qValue: number;
88
+ visits: number;
89
+ } | undefined;
90
+ /**
91
+ * Blend a static score with a Q-value contribution.
92
+ *
93
+ * effectiveScore = staticScore * (1 - qWeight) + normalizedQ * qWeight
94
+ *
95
+ * Returns { score, qWeight, qValue, qVisits } so callers can attach the
96
+ * telemetry fields to the ScoredAgent record.
97
+ */
98
+ export declare function blendStaticAndQValue(staticScore: number, qLookup: {
99
+ qValue: number;
100
+ visits: number;
101
+ } | undefined): {
102
+ score: number;
103
+ qWeight: number;
104
+ qValue: number;
105
+ qVisits: number;
106
+ };
107
+ /**
108
+ * Resolve the per-decision ε for the exploration policy.
109
+ *
110
+ * Priority order:
111
+ * 1. AQE_ROUTER_EXPLORATION_RATE env var (operator override, fixed)
112
+ * 2. Default base rate (0.05)
113
+ * The result is then multiplied by the mincut safety gate (caller passes
114
+ * `topologyCritical` derived from getSharedMinCutMonitor().isCritical()):
115
+ * critical topology → 0.2x dampening, healthy/unknown → 1.0x.
116
+ *
117
+ * Returns a number in [0, 1].
118
+ */
119
+ export declare function resolveExplorationRate(opts: {
120
+ envOverride?: string;
121
+ topologyCritical?: boolean;
122
+ }): {
123
+ epsilon: number;
124
+ baseEpsilon: number;
125
+ safetyMultiplier: number;
126
+ };
127
+ /**
128
+ * Apply the ε-greedy exploration policy to a sorted score list.
129
+ *
130
+ * With probability ε (computed from resolveExplorationRate), swaps the
131
+ * top-scored agent with a uniformly-random pick from positions 1..3 (or
132
+ * fewer if the list is shorter). Mutates `agentScores` in place. The
133
+ * promoted agent gets `exploration = true`.
134
+ *
135
+ * Uses `crypto.randomInt` for cryptographically-strong uniform sampling —
136
+ * matches the codebase convention (randomUUID is imported from 'crypto'
137
+ * in the same modules). Math.random() would work but breaks consistency.
138
+ */
139
+ export declare function applyExplorationPolicy(agentScores: ScoredAgent[], epsilon: number): void;
140
+ /**
141
+ * Derive a structural taskType from a free-form task description. Used to
142
+ * build the q-learning state_key shared with the post-task Bellman update
143
+ * (hooks-dream-learning.ts).
144
+ *
145
+ * Exported (rather than kept private in task-hooks) so QEReasoningBank can
146
+ * compute the same state_key at routing time as post-task does at outcome
147
+ * time — without that, the Q-table writer and reader would address
148
+ * different keys.
149
+ */
150
+ export declare function deriveTaskType(description: string): string;
151
+ /**
152
+ * Build the canonical Q-learning state_key. Must match the format used by
153
+ * `updateHookRouterQValue` in hooks-dream-learning.ts — the writer and
154
+ * reader must agree on the key shape.
155
+ */
156
+ export declare function buildRoutingStateKey(opts: {
157
+ taskType: string;
158
+ priority?: string;
159
+ domain?: string;
160
+ complexityBucket: number;
161
+ }): string;
162
+ /**
163
+ * Compute the complexity bucket [0, 10] from a task description length.
164
+ * Mirrors the formula in task-hooks.ts pre-task bridge.
165
+ */
166
+ export declare function deriveComplexityBucket(description: string): number;
41
167
  /**
42
168
  * Calculate agent scores for a routing request.
43
169
  *
@@ -49,7 +175,14 @@ export interface RoutingWeights {
49
175
  * @param requestLanguage - Optional language to boost agents with matching language expertise
50
176
  * @returns Sorted array of scored agents (highest score first)
51
177
  */
52
- export declare function calculateAgentScores(detectedDomains: QEDomain[], requestCapabilities: string[] | undefined, agentDomainPatternCounts: Map<string, number>, routingWeights: RoutingWeights, agentCapabilities?: Record<string, AgentCapabilityProfile>, requestLanguage?: string): ScoredAgent[];
178
+ export declare function calculateAgentScores(detectedDomains: QEDomain[], requestCapabilities: string[] | undefined, agentDomainPatternCounts: Map<string, number>, routingWeights: RoutingWeights, agentCapabilities?: Record<string, AgentCapabilityProfile>, requestLanguage?: string,
179
+ /**
180
+ * ADR-095: optional per-agent Q-value lookup. When provided, the static
181
+ * score is blended with the Q-value contribution via blendStaticAndQValue.
182
+ * When omitted (or returning undefined for every agent), behavior is
183
+ * identical to the pre-ADR-095 deterministic scoring.
184
+ */
185
+ qValueLookup?: QValueLookup): ScoredAgent[];
53
186
  /**
54
187
  * Domain compatibility matrix for cross-domain pattern transfer.
55
188
  * Maps each domain to its related domains (same as TransferSpecialistService).
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Agentic QE v3 - Agent Routing
3
3
  * ADR-021: QE ReasoningBank for Pattern Learning
4
+ * ADR-095: ε-greedy exploration with Q-value blending and mincut safety gate
4
5
  *
5
6
  * Static agent capability mapping and routing score calculation
6
7
  * used by QEReasoningBank.routeTask().
7
8
  */
9
+ import { randomInt } from 'crypto';
8
10
  // ============================================================================
9
11
  // Agent Capabilities Map
10
12
  // ============================================================================
@@ -72,6 +74,159 @@ export const AGENT_CAPABILITIES = {
72
74
  performanceScore: 0.75,
73
75
  },
74
76
  };
77
+ // ============================================================================
78
+ // ADR-095: Q-Value Blending + ε-Greedy Exploration
79
+ // ============================================================================
80
+ /**
81
+ * Maximum Q-value influence on the final score.
82
+ *
83
+ * 0.4 means a fully-mature Q-value can move the score by up to ±0.2 (since
84
+ * normalizedQ ranges over (0, 1) and the static contribution clamps the
85
+ * upper bound). This is intentionally bounded so Q-values inform rather
86
+ * than override the static features.
87
+ *
88
+ * Tuning: post-deploy telemetry will tell us whether agents are actually
89
+ * being separated by Q-values. If the avg `q_weight` in routing_outcomes
90
+ * climbs but quality_score doesn't improve, this constant is too high.
91
+ */
92
+ export const MAX_Q_WEIGHT = 0.4;
93
+ /**
94
+ * Number of (state_key, action_key) visits at which qWeight saturates at
95
+ * MAX_Q_WEIGHT. Below this, qWeight ramps linearly from 0.
96
+ *
97
+ * 20 visits at the default 30-min worker tick + typical session cadence
98
+ * implies ~1 week of activity before a (state, agent) pair drives the
99
+ * decision. Adjust downward if cold-start latency proves problematic.
100
+ */
101
+ export const QWEIGHT_RAMP_VISITS = 20;
102
+ /**
103
+ * Sigmoid mapping R → (0, 1) for Q-value normalization before blending.
104
+ * A fresh row with q_value = 0 contributes 0.5 (neutral); negative q_values
105
+ * (after a failure, given the asymmetric -1.0 penalty from ADR-061) push
106
+ * the contribution toward 0, positive q_values toward 1.
107
+ */
108
+ function sigmoid(x) {
109
+ return 1 / (1 + Math.exp(-x));
110
+ }
111
+ /**
112
+ * Blend a static score with a Q-value contribution.
113
+ *
114
+ * effectiveScore = staticScore * (1 - qWeight) + normalizedQ * qWeight
115
+ *
116
+ * Returns { score, qWeight, qValue, qVisits } so callers can attach the
117
+ * telemetry fields to the ScoredAgent record.
118
+ */
119
+ export function blendStaticAndQValue(staticScore, qLookup) {
120
+ if (!qLookup || qLookup.visits === 0) {
121
+ return { score: staticScore, qWeight: 0, qValue: 0, qVisits: 0 };
122
+ }
123
+ const qWeight = Math.min(qLookup.visits / QWEIGHT_RAMP_VISITS, 1) * MAX_Q_WEIGHT;
124
+ const normalizedQ = sigmoid(qLookup.qValue);
125
+ return {
126
+ score: staticScore * (1 - qWeight) + normalizedQ * qWeight,
127
+ qWeight,
128
+ qValue: qLookup.qValue,
129
+ qVisits: qLookup.visits,
130
+ };
131
+ }
132
+ /**
133
+ * Resolve the per-decision ε for the exploration policy.
134
+ *
135
+ * Priority order:
136
+ * 1. AQE_ROUTER_EXPLORATION_RATE env var (operator override, fixed)
137
+ * 2. Default base rate (0.05)
138
+ * The result is then multiplied by the mincut safety gate (caller passes
139
+ * `topologyCritical` derived from getSharedMinCutMonitor().isCritical()):
140
+ * critical topology → 0.2x dampening, healthy/unknown → 1.0x.
141
+ *
142
+ * Returns a number in [0, 1].
143
+ */
144
+ export function resolveExplorationRate(opts) {
145
+ const envValue = opts.envOverride;
146
+ const parsed = envValue !== undefined ? Number.parseFloat(envValue) : NaN;
147
+ const baseEpsilon = Number.isFinite(parsed) && parsed >= 0 && parsed <= 1
148
+ ? parsed
149
+ : 0.05;
150
+ const safetyMultiplier = opts.topologyCritical ? 0.2 : 1.0;
151
+ const epsilon = Math.min(Math.max(baseEpsilon * safetyMultiplier, 0), 1);
152
+ return { epsilon, baseEpsilon, safetyMultiplier };
153
+ }
154
+ /**
155
+ * Apply the ε-greedy exploration policy to a sorted score list.
156
+ *
157
+ * With probability ε (computed from resolveExplorationRate), swaps the
158
+ * top-scored agent with a uniformly-random pick from positions 1..3 (or
159
+ * fewer if the list is shorter). Mutates `agentScores` in place. The
160
+ * promoted agent gets `exploration = true`.
161
+ *
162
+ * Uses `crypto.randomInt` for cryptographically-strong uniform sampling —
163
+ * matches the codebase convention (randomUUID is imported from 'crypto'
164
+ * in the same modules). Math.random() would work but breaks consistency.
165
+ */
166
+ export function applyExplorationPolicy(agentScores, epsilon) {
167
+ if (epsilon <= 0 || agentScores.length < 2)
168
+ return;
169
+ // Compare in micro-units so randomInt can do uniform sampling without
170
+ // float arithmetic. ε = 0.05 → 50_000 micro-units in 1_000_000.
171
+ const epsilonMicro = Math.round(epsilon * 1_000_000);
172
+ if (epsilonMicro <= 0)
173
+ return;
174
+ if (randomInt(0, 1_000_000) >= epsilonMicro)
175
+ return;
176
+ // Pick from top alternatives (positions 1..min(3, length-1)).
177
+ const ceiling = Math.min(4, agentScores.length);
178
+ const exploreIdx = randomInt(1, ceiling);
179
+ const explored = agentScores[exploreIdx];
180
+ agentScores[exploreIdx] = agentScores[0];
181
+ agentScores[0] = explored;
182
+ agentScores[0].exploration = true;
183
+ agentScores[0].reasoning = [...agentScores[0].reasoning, '(exploration)'];
184
+ }
185
+ /**
186
+ * Derive a structural taskType from a free-form task description. Used to
187
+ * build the q-learning state_key shared with the post-task Bellman update
188
+ * (hooks-dream-learning.ts).
189
+ *
190
+ * Exported (rather than kept private in task-hooks) so QEReasoningBank can
191
+ * compute the same state_key at routing time as post-task does at outcome
192
+ * time — without that, the Q-table writer and reader would address
193
+ * different keys.
194
+ */
195
+ export function deriveTaskType(description) {
196
+ const d = description.toLowerCase();
197
+ if (/\bgenerate[- ]?test|\btest[- ]?gen|\bgenerate.+spec/.test(d))
198
+ return 'test-generation';
199
+ if (/\bcoverage|\banalyze.+cover/.test(d))
200
+ return 'coverage-analysis';
201
+ if (/\bquality|\bassess|\baudit/.test(d))
202
+ return 'quality-assessment';
203
+ if (/\bsecurity|\bvulnerab|\bcompliance/.test(d))
204
+ return 'security-compliance';
205
+ if (/\bdefect|\bbug|\bdiagnos/.test(d))
206
+ return 'defect-intelligence';
207
+ if (/\brequirement|\bspec\b/.test(d))
208
+ return 'requirements-validation';
209
+ if (/\brefactor|\brewrite|\boptim/.test(d))
210
+ return 'refactoring';
211
+ if (/\btest|\brun.+test/.test(d))
212
+ return 'test-execution';
213
+ return 'unknown';
214
+ }
215
+ /**
216
+ * Build the canonical Q-learning state_key. Must match the format used by
217
+ * `updateHookRouterQValue` in hooks-dream-learning.ts — the writer and
218
+ * reader must agree on the key shape.
219
+ */
220
+ export function buildRoutingStateKey(opts) {
221
+ return `${opts.taskType}|${opts.priority ?? 'normal'}|${opts.domain ?? 'any'}|${opts.complexityBucket}`;
222
+ }
223
+ /**
224
+ * Compute the complexity bucket [0, 10] from a task description length.
225
+ * Mirrors the formula in task-hooks.ts pre-task bridge.
226
+ */
227
+ export function deriveComplexityBucket(description) {
228
+ return Math.max(0, Math.min(10, Math.round(Math.min(description.length / 200, 1) * 10)));
229
+ }
75
230
  /**
76
231
  * Calculate agent scores for a routing request.
77
232
  *
@@ -83,7 +238,14 @@ export const AGENT_CAPABILITIES = {
83
238
  * @param requestLanguage - Optional language to boost agents with matching language expertise
84
239
  * @returns Sorted array of scored agents (highest score first)
85
240
  */
86
- export function calculateAgentScores(detectedDomains, requestCapabilities, agentDomainPatternCounts, routingWeights, agentCapabilities = AGENT_CAPABILITIES, requestLanguage) {
241
+ export function calculateAgentScores(detectedDomains, requestCapabilities, agentDomainPatternCounts, routingWeights, agentCapabilities = AGENT_CAPABILITIES, requestLanguage,
242
+ /**
243
+ * ADR-095: optional per-agent Q-value lookup. When provided, the static
244
+ * score is blended with the Q-value contribution via blendStaticAndQValue.
245
+ * When omitted (or returning undefined for every agent), behavior is
246
+ * identical to the pre-ADR-095 deterministic scoring.
247
+ */
248
+ qValueLookup) {
87
249
  const agentScores = [];
88
250
  for (const [agentType, profile] of Object.entries(agentCapabilities)) {
89
251
  let score = 0;
@@ -128,7 +290,28 @@ export function calculateAgentScores(detectedDomains, requestCapabilities, agent
128
290
  score += patternBoost;
129
291
  reasoning.push(`Pattern matches: ${patternCount}`);
130
292
  }
131
- agentScores.push({ agent: agentType, score, reasoning });
293
+ // ADR-095: blend Q-value if a lookup is provided
294
+ const staticScore = score;
295
+ if (qValueLookup) {
296
+ const q = qValueLookup(agentType);
297
+ const blended = blendStaticAndQValue(staticScore, q);
298
+ score = blended.score;
299
+ if (blended.qWeight > 0) {
300
+ reasoning.push(`Q-bonus (w=${blended.qWeight.toFixed(2)}, v=${blended.qVisits})`);
301
+ }
302
+ agentScores.push({
303
+ agent: agentType,
304
+ score,
305
+ reasoning,
306
+ staticScore,
307
+ qWeight: blended.qWeight,
308
+ qValue: blended.qValue,
309
+ qVisits: blended.qVisits,
310
+ });
311
+ }
312
+ else {
313
+ agentScores.push({ agent: agentType, score, reasoning, staticScore });
314
+ }
132
315
  }
133
316
  // Sort by score descending
134
317
  agentScores.sort((a, b) => b.score - a.score);