@poetic-ai/poetic 1.42.1-bootstrap.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 (781) hide show
  1. package/.github/SECURITY.md +47 -0
  2. package/.nvmrc +1 -0
  3. package/.poetic/README.md +37 -0
  4. package/.poetic/providers/catalog.json +12051 -0
  5. package/.poetic/providers/pricing.json +1272 -0
  6. package/.poetic/providers/registry.json +3369 -0
  7. package/CHANGELOG.md +552 -0
  8. package/CODE_OF_CONDUCT.md +40 -0
  9. package/CONTRIBUTING.md +23 -0
  10. package/INSTALL.md +454 -0
  11. package/LICENSE +21 -0
  12. package/README.md +474 -0
  13. package/dist/BasicOptimizationCompetitionRunner-5H5TBYO4.js +153 -0
  14. package/dist/ExecutionTracker-UVONC4C6.js +16 -0
  15. package/dist/OptimizationConfig-7DFY2TST.js +17 -0
  16. package/dist/OptimizationEngine-MXTSOSST.js +1597 -0
  17. package/dist/PromptStore-U6ZD3ZMQ.js +18 -0
  18. package/dist/actions-M3AESHFF.js +322 -0
  19. package/dist/agent-ingest-HO77TH26.js +53 -0
  20. package/dist/aggregator-DNCBINFO.js +12 -0
  21. package/dist/ai-judge-LDWHURKK.js +156 -0
  22. package/dist/allowlist-grounding-RO6HKUFI.js +16 -0
  23. package/dist/allowlist-utils-23V7TJ3G.js +28 -0
  24. package/dist/anchored-turn-service-GFYU6GCQ.js +489 -0
  25. package/dist/api-transport-FS3CQRMN.js +1087 -0
  26. package/dist/apply-completion-mode-JBT2CTQO.js +89 -0
  27. package/dist/artifact-migrator-23L45ISD.js +267 -0
  28. package/dist/ask-UYVZY7JH.js +135 -0
  29. package/dist/auth-CSQP5RHJ.js +67 -0
  30. package/dist/auth-E6XUNZ5M.js +68 -0
  31. package/dist/auth-KQLJPZ2E.js +134 -0
  32. package/dist/auth-OC4E6633.js +71 -0
  33. package/dist/auth-R3NQ2ZF5.js +78 -0
  34. package/dist/auth-S4CTX4GQ.js +44 -0
  35. package/dist/auth-YLH3S7EY.js +69 -0
  36. package/dist/auth-liveness-TDDEZY3T.js +46 -0
  37. package/dist/auto-optimizer-HA3T23SF.js +80 -0
  38. package/dist/autoloop-cleanup-JOGKTLWA.js +109 -0
  39. package/dist/autoloop-evidence-gates-ACB5YW5G.js +36 -0
  40. package/dist/autoloop-gate-policy-XZA5EQFN.js +175 -0
  41. package/dist/autoloop-helpers-EFJLBQUP.js +22 -0
  42. package/dist/autoloop-ledger-W7QO62PX.js +96 -0
  43. package/dist/autoloop-ledger-subscriber-Z5RW5EIE.js +162 -0
  44. package/dist/autoloop-run-defaults-FERGRZGP.js +19 -0
  45. package/dist/autoloop-run-lock-CT2NWSV3.js +197 -0
  46. package/dist/autoloop-success-OPR74YEX.js +85 -0
  47. package/dist/autoloop-termination-summary-RN75F422.js +58 -0
  48. package/dist/autoloop-trajectory-K5I45UBR.js +282 -0
  49. package/dist/autoloop-wall-clock-T7ZVIQOC.js +12 -0
  50. package/dist/autonomous-loop-controller-4QJMOIIN.js +4120 -0
  51. package/dist/backend-P3DAYRP7.js +29 -0
  52. package/dist/background-executor-CBN552V4.js +257 -0
  53. package/dist/backlog-execution-intent-U4XYPTV6.js +15 -0
  54. package/dist/backup-active-store-5WXG6SXT.js +17 -0
  55. package/dist/backup-telemetry-db-XGLXAA3N.js +254 -0
  56. package/dist/basic-competition-master-WXZHUT42.js +344 -0
  57. package/dist/branch-archive-manager-RP6FP3ZC.js +254 -0
  58. package/dist/branch-cleanup-manager-RSHAI7YR.js +20 -0
  59. package/dist/build-gate-YFASRB5Z.js +71 -0
  60. package/dist/change-summary-WY7J5TOX.js +33 -0
  61. package/dist/chunk-25QL3M3L.js +899 -0
  62. package/dist/chunk-2ABC6SEC.js +2626 -0
  63. package/dist/chunk-2AICM4P3.js +1763 -0
  64. package/dist/chunk-2AQUWJPW.js +225 -0
  65. package/dist/chunk-2DY5KNVM.js +276 -0
  66. package/dist/chunk-2QJ3H3L7.js +42 -0
  67. package/dist/chunk-2UH6VQRZ.js +328 -0
  68. package/dist/chunk-2VSQMRCB.js +18 -0
  69. package/dist/chunk-2XQXYBM2.js +130 -0
  70. package/dist/chunk-2YFUIER7.js +426 -0
  71. package/dist/chunk-2YXZCZTX.js +1160 -0
  72. package/dist/chunk-32VLDFRT.js +797 -0
  73. package/dist/chunk-34CNP2HB.js +148 -0
  74. package/dist/chunk-35P3W3JX.js +456 -0
  75. package/dist/chunk-36PEBZAF.js +18 -0
  76. package/dist/chunk-3733QTI7.js +6818 -0
  77. package/dist/chunk-3A5PDH5L.js +12513 -0
  78. package/dist/chunk-3AOKYKA7.js +22 -0
  79. package/dist/chunk-3BCUNHKF.js +475 -0
  80. package/dist/chunk-3C26DPFK.js +566 -0
  81. package/dist/chunk-3FLXLLB7.js +26 -0
  82. package/dist/chunk-3FOZ2VHV.js +100 -0
  83. package/dist/chunk-3G6FZCRF.js +106 -0
  84. package/dist/chunk-3JWNRJSB.js +736 -0
  85. package/dist/chunk-3LUMR3D3.js +156 -0
  86. package/dist/chunk-3M57DADF.js +44 -0
  87. package/dist/chunk-3S62LLWJ.js +543 -0
  88. package/dist/chunk-3VABAKT2.js +1784 -0
  89. package/dist/chunk-44N5WZZH.js +45 -0
  90. package/dist/chunk-45FPSA3B.js +125 -0
  91. package/dist/chunk-4BIPZBT7.js +791 -0
  92. package/dist/chunk-4BJ3O4RQ.js +929 -0
  93. package/dist/chunk-4BTDUT2S.js +42 -0
  94. package/dist/chunk-4CSS7WVI.js +143 -0
  95. package/dist/chunk-4CUY7AFY.js +247 -0
  96. package/dist/chunk-4HN6DF7V.js +1027 -0
  97. package/dist/chunk-4HXKHDNH.js +1064 -0
  98. package/dist/chunk-4KKI477Q.js +44 -0
  99. package/dist/chunk-4NA7FSTV.js +595 -0
  100. package/dist/chunk-4NXPXE62.js +84 -0
  101. package/dist/chunk-4SALLK63.js +9831 -0
  102. package/dist/chunk-4SHKPCGK.js +110 -0
  103. package/dist/chunk-4VJITV4P.js +445 -0
  104. package/dist/chunk-4W2NRXQL.js +1205 -0
  105. package/dist/chunk-4XICK3HN.js +784 -0
  106. package/dist/chunk-55EJVV3C.js +385 -0
  107. package/dist/chunk-5DLKYTQX.js +4003 -0
  108. package/dist/chunk-5EERLVZB.js +139 -0
  109. package/dist/chunk-5HDP7XZG.js +91 -0
  110. package/dist/chunk-5LAMRH4X.js +969 -0
  111. package/dist/chunk-5REDMNLZ.js +310 -0
  112. package/dist/chunk-5UCJARII.js +1984 -0
  113. package/dist/chunk-5WCQRDRB.js +588 -0
  114. package/dist/chunk-5WRLK5KW.js +700 -0
  115. package/dist/chunk-66AGFTBQ.js +131 -0
  116. package/dist/chunk-66CIO2SV.js +48 -0
  117. package/dist/chunk-6BM72ZMG.js +31 -0
  118. package/dist/chunk-6BTFXYRO.js +276 -0
  119. package/dist/chunk-6EDAJH2I.js +68 -0
  120. package/dist/chunk-6EQKFDBH.js +457 -0
  121. package/dist/chunk-6KMJKHIQ.js +2193 -0
  122. package/dist/chunk-6MFRHTRI.js +115 -0
  123. package/dist/chunk-6QMUKUHH.js +632 -0
  124. package/dist/chunk-6TZJRKNW.js +321 -0
  125. package/dist/chunk-6V7HGQFZ.js +20 -0
  126. package/dist/chunk-6Y5TWI7H.js +146 -0
  127. package/dist/chunk-6Y5U7UFY.js +91 -0
  128. package/dist/chunk-6ZLAK3XG.js +14 -0
  129. package/dist/chunk-72XCRQED.js +34 -0
  130. package/dist/chunk-72YTZMAM.js +589 -0
  131. package/dist/chunk-73NCTWKL.js +188 -0
  132. package/dist/chunk-77I6G4CO.js +1 -0
  133. package/dist/chunk-7D7QT3BE.js +688 -0
  134. package/dist/chunk-7DNSNKJV.js +78 -0
  135. package/dist/chunk-7FMJVYBS.js +307 -0
  136. package/dist/chunk-7GDRQBQC.js +419 -0
  137. package/dist/chunk-7IL4A2PP.js +948 -0
  138. package/dist/chunk-7NPSXSHO.js +975 -0
  139. package/dist/chunk-7PS6INZP.js +302 -0
  140. package/dist/chunk-7QCZSLBH.js +1 -0
  141. package/dist/chunk-7R2WLDOS.js +62 -0
  142. package/dist/chunk-7XV3QXLT.js +878 -0
  143. package/dist/chunk-A2WKSVX7.js +43 -0
  144. package/dist/chunk-A3YGID55.js +133 -0
  145. package/dist/chunk-A5MRWHMI.js +1604 -0
  146. package/dist/chunk-A722DEVA.js +14 -0
  147. package/dist/chunk-AG2Z2SUZ.js +554 -0
  148. package/dist/chunk-AHWAZ2MU.js +137 -0
  149. package/dist/chunk-AIAQ3HS3.js +119 -0
  150. package/dist/chunk-ALAB3PBR.js +2206 -0
  151. package/dist/chunk-APPNGGN7.js +365 -0
  152. package/dist/chunk-APV6MK5E.js +137 -0
  153. package/dist/chunk-AQNPGRWS.js +395 -0
  154. package/dist/chunk-ASEP3M2W.js +968 -0
  155. package/dist/chunk-AT4TNPWW.js +2931 -0
  156. package/dist/chunk-ATVKCSGT.js +250 -0
  157. package/dist/chunk-AX6GWE7V.js +47 -0
  158. package/dist/chunk-AZQILSNQ.js +1376 -0
  159. package/dist/chunk-B76KHLX6.js +13 -0
  160. package/dist/chunk-BAV2HJXS.js +194 -0
  161. package/dist/chunk-BBHRN366.js +89 -0
  162. package/dist/chunk-BCZAENOH.js +448 -0
  163. package/dist/chunk-BIGSACCY.js +19527 -0
  164. package/dist/chunk-BPYMCIVD.js +9243 -0
  165. package/dist/chunk-BSE4R6XD.js +322 -0
  166. package/dist/chunk-BVPWRDCO.js +2321 -0
  167. package/dist/chunk-BXI4NXL3.js +507 -0
  168. package/dist/chunk-C3L6YQ7P.js +147 -0
  169. package/dist/chunk-C57KJOUQ.js +121 -0
  170. package/dist/chunk-CCV7BPSY.js +118 -0
  171. package/dist/chunk-CD7ISXA4.js +826 -0
  172. package/dist/chunk-CE5OZBYY.js +21 -0
  173. package/dist/chunk-CFBIG37O.js +154 -0
  174. package/dist/chunk-CHQV73H5.js +408 -0
  175. package/dist/chunk-CJC6GZ46.js +457 -0
  176. package/dist/chunk-CJHRFSNY.js +924 -0
  177. package/dist/chunk-CKP2Q3TP.js +1905 -0
  178. package/dist/chunk-CLKSETWE.js +10 -0
  179. package/dist/chunk-CQM3A35X.js +844 -0
  180. package/dist/chunk-CSLAS5GW.js +4007 -0
  181. package/dist/chunk-CTLUBNCW.js +622 -0
  182. package/dist/chunk-CVMVZWG4.js +3544 -0
  183. package/dist/chunk-CYB6QDCT.js +263 -0
  184. package/dist/chunk-D5EP5D2W.js +26 -0
  185. package/dist/chunk-DC4ZYMXJ.js +115 -0
  186. package/dist/chunk-DCAVAABI.js +348 -0
  187. package/dist/chunk-DCYF7EKG.js +26 -0
  188. package/dist/chunk-DF5SLDE4.js +966 -0
  189. package/dist/chunk-DN7UMLF7.js +5678 -0
  190. package/dist/chunk-DSFM56OA.js +1203 -0
  191. package/dist/chunk-DTY4APYV.js +218 -0
  192. package/dist/chunk-E3NTPHEO.js +194 -0
  193. package/dist/chunk-E74LUIID.js +302 -0
  194. package/dist/chunk-EJ42BNGY.js +2904 -0
  195. package/dist/chunk-EJ4ZAWLV.js +305 -0
  196. package/dist/chunk-EJGCZGUF.js +1483 -0
  197. package/dist/chunk-EK2U3YEG.js +486 -0
  198. package/dist/chunk-ELMFYNV7.js +109 -0
  199. package/dist/chunk-ENRGKNR5.js +25 -0
  200. package/dist/chunk-EQGIDAUF.js +62 -0
  201. package/dist/chunk-EX3OM35G.js +20414 -0
  202. package/dist/chunk-F5JO7HAS.js +94 -0
  203. package/dist/chunk-F7ER6ANO.js +174 -0
  204. package/dist/chunk-FATUVIIN.js +374 -0
  205. package/dist/chunk-FC23CTXV.js +322 -0
  206. package/dist/chunk-FCNAS3W2.js +1033 -0
  207. package/dist/chunk-FD4ERYEG.js +22 -0
  208. package/dist/chunk-FDVZLG6Z.js +3104 -0
  209. package/dist/chunk-FEPIFY7D.js +511 -0
  210. package/dist/chunk-FEQ4HXL7.js +412 -0
  211. package/dist/chunk-FFH5HHJU.js +5351 -0
  212. package/dist/chunk-FH7WOJAE.js +79 -0
  213. package/dist/chunk-FKAUPHMR.js +96 -0
  214. package/dist/chunk-FRG57FPM.js +240 -0
  215. package/dist/chunk-FUVP64ER.js +31 -0
  216. package/dist/chunk-G2PTLLEL.js +284 -0
  217. package/dist/chunk-G35UYQ6Z.js +69 -0
  218. package/dist/chunk-G36W2T2S.js +1143 -0
  219. package/dist/chunk-G4THLFV3.js +148 -0
  220. package/dist/chunk-GAFJEYLK.js +29 -0
  221. package/dist/chunk-GCCAPO3S.js +118 -0
  222. package/dist/chunk-GG6KJYW6.js +85 -0
  223. package/dist/chunk-GHHFDU2U.js +55 -0
  224. package/dist/chunk-GHTZSQB7.js +57 -0
  225. package/dist/chunk-GJTWJNLV.js +1374 -0
  226. package/dist/chunk-GKN3HMN4.js +2809 -0
  227. package/dist/chunk-GNH3QGTL.js +1342 -0
  228. package/dist/chunk-GOAQ2I7Y.js +7000 -0
  229. package/dist/chunk-GSGD5E4C.js +30 -0
  230. package/dist/chunk-GXWAJQOJ.js +5011 -0
  231. package/dist/chunk-H2AYQIHW.js +224 -0
  232. package/dist/chunk-H6G7QRMQ.js +35 -0
  233. package/dist/chunk-H7JAGHZT.js +59 -0
  234. package/dist/chunk-HAC6EHZZ.js +79 -0
  235. package/dist/chunk-HE2KH6EQ.js +161 -0
  236. package/dist/chunk-HIHENQDX.js +66 -0
  237. package/dist/chunk-HIO33P3G.js +19 -0
  238. package/dist/chunk-HK4AQZSR.js +438 -0
  239. package/dist/chunk-HMVQIPH3.js +547 -0
  240. package/dist/chunk-HOYBYAOA.js +257 -0
  241. package/dist/chunk-HQLGXODD.js +123 -0
  242. package/dist/chunk-HQXYYUNY.js +1231 -0
  243. package/dist/chunk-HY3ESWCA.js +708 -0
  244. package/dist/chunk-I46EG2XQ.js +65 -0
  245. package/dist/chunk-I4NPDSCB.js +279 -0
  246. package/dist/chunk-I5WRT7ZR.js +514 -0
  247. package/dist/chunk-I6BL3PDH.js +1024 -0
  248. package/dist/chunk-IATQ7NBI.js +679 -0
  249. package/dist/chunk-IC7I6YIJ.js +301 -0
  250. package/dist/chunk-IDCSOZVN.js +78 -0
  251. package/dist/chunk-IEXU4RR6.js +5742 -0
  252. package/dist/chunk-IFCBYECK.js +112 -0
  253. package/dist/chunk-IFZCPEY2.js +66 -0
  254. package/dist/chunk-IKFP2KUR.js +48 -0
  255. package/dist/chunk-IP7BYVUV.js +338 -0
  256. package/dist/chunk-IRJ2I6KH.js +166 -0
  257. package/dist/chunk-IUXNGKA6.js +152 -0
  258. package/dist/chunk-IZYIQQ7X.js +53 -0
  259. package/dist/chunk-IZZK3H6I.js +2175 -0
  260. package/dist/chunk-J3J4P7RW.js +353 -0
  261. package/dist/chunk-J62KPGII.js +464 -0
  262. package/dist/chunk-J6P3FWWW.js +130 -0
  263. package/dist/chunk-JD6SIZED.js +712 -0
  264. package/dist/chunk-JEV6UI7H.js +537 -0
  265. package/dist/chunk-JKBHJQMT.js +434 -0
  266. package/dist/chunk-JLS65NUQ.js +14 -0
  267. package/dist/chunk-JOSYEJKY.js +141 -0
  268. package/dist/chunk-JPKSXKNB.js +94 -0
  269. package/dist/chunk-JQD5VYKR.js +483 -0
  270. package/dist/chunk-JSOWEFEQ.js +351 -0
  271. package/dist/chunk-JSWMRQYG.js +28 -0
  272. package/dist/chunk-K4XK7SGB.js +6783 -0
  273. package/dist/chunk-K54Y7MLK.js +160 -0
  274. package/dist/chunk-KAT4RXUT.js +521 -0
  275. package/dist/chunk-KDMKKIRK.js +103 -0
  276. package/dist/chunk-KM3F7SYE.js +702 -0
  277. package/dist/chunk-KNDYMVWN.js +102 -0
  278. package/dist/chunk-KNT72VR6.js +132 -0
  279. package/dist/chunk-KQEBSK3T.js +274 -0
  280. package/dist/chunk-KT6VHSPF.js +84 -0
  281. package/dist/chunk-KTMW65UX.js +14 -0
  282. package/dist/chunk-L4427KOE.js +26 -0
  283. package/dist/chunk-L6OM4A22.js +189 -0
  284. package/dist/chunk-L7E6XCRA.js +1042 -0
  285. package/dist/chunk-L7JZLXQL.js +173 -0
  286. package/dist/chunk-LAMKBTXX.js +40 -0
  287. package/dist/chunk-LDCF2MKN.js +132 -0
  288. package/dist/chunk-LEIIWPWQ.js +78 -0
  289. package/dist/chunk-LFTQVYBB.js +31 -0
  290. package/dist/chunk-LGHII5ET.js +23 -0
  291. package/dist/chunk-LH34OGSB.js +265 -0
  292. package/dist/chunk-LO3X5NLS.js +326 -0
  293. package/dist/chunk-LPITVM7M.js +339 -0
  294. package/dist/chunk-LR5IJIGV.js +810 -0
  295. package/dist/chunk-LUVKFFWR.js +315 -0
  296. package/dist/chunk-LWCBNGH6.js +35 -0
  297. package/dist/chunk-LWTN3WRV.js +260 -0
  298. package/dist/chunk-LZBBXYWF.js +1004 -0
  299. package/dist/chunk-M34PS4NE.js +2213 -0
  300. package/dist/chunk-M3HQYKQX.js +308 -0
  301. package/dist/chunk-MCPQNJMK.js +482 -0
  302. package/dist/chunk-MF5HP6XV.js +221 -0
  303. package/dist/chunk-MFADRRTR.js +112 -0
  304. package/dist/chunk-MN6PL4AN.js +120 -0
  305. package/dist/chunk-MQ4WA34C.js +206 -0
  306. package/dist/chunk-MTVZITQ2.js +185 -0
  307. package/dist/chunk-MWHF5V7U.js +223 -0
  308. package/dist/chunk-MWHLBPNU.js +211 -0
  309. package/dist/chunk-MWK5UZQ3.js +1068 -0
  310. package/dist/chunk-MYLH2S4G.js +64 -0
  311. package/dist/chunk-MZ5WYKNA.js +28 -0
  312. package/dist/chunk-N5DX4JAK.js +12 -0
  313. package/dist/chunk-NEDCMN7E.js +415 -0
  314. package/dist/chunk-NEQUQHOX.js +223 -0
  315. package/dist/chunk-NGK6PEOG.js +25 -0
  316. package/dist/chunk-NM6PMYY4.js +768 -0
  317. package/dist/chunk-NOZGR2QO.js +2373 -0
  318. package/dist/chunk-NP2V3L7K.js +226 -0
  319. package/dist/chunk-NPZJMUZ4.js +194 -0
  320. package/dist/chunk-NRLY536M.js +260 -0
  321. package/dist/chunk-NS33V3IM.js +51 -0
  322. package/dist/chunk-NWOYOA6H.js +378 -0
  323. package/dist/chunk-NWRUSEXG.js +322 -0
  324. package/dist/chunk-O6V4PNLO.js +63 -0
  325. package/dist/chunk-OGMSYL6J.js +227 -0
  326. package/dist/chunk-OIS7J26S.js +319 -0
  327. package/dist/chunk-OKBTRSZI.js +205 -0
  328. package/dist/chunk-OMX5VL43.js +79 -0
  329. package/dist/chunk-ON3G73BU.js +264 -0
  330. package/dist/chunk-OPYFYTWQ.js +220 -0
  331. package/dist/chunk-OQ6K46CK.js +1734 -0
  332. package/dist/chunk-OSDYVKHW.js +2440 -0
  333. package/dist/chunk-OUM5S64R.js +3429 -0
  334. package/dist/chunk-OWB7JXUS.js +751 -0
  335. package/dist/chunk-OYZYO7TV.js +47 -0
  336. package/dist/chunk-P47VN5F4.js +282 -0
  337. package/dist/chunk-P6VQROCO.js +594 -0
  338. package/dist/chunk-P7CQGPLS.js +30 -0
  339. package/dist/chunk-PA6BCSOX.js +2872 -0
  340. package/dist/chunk-PGSPX4SU.js +15 -0
  341. package/dist/chunk-PIKLF7BM.js +432 -0
  342. package/dist/chunk-PJWJ3SAV.js +22 -0
  343. package/dist/chunk-PKIFMV72.js +100 -0
  344. package/dist/chunk-PTH5E5XO.js +195 -0
  345. package/dist/chunk-PYITM4N2.js +79 -0
  346. package/dist/chunk-PZ5AY32C.js +10 -0
  347. package/dist/chunk-Q3RO7N35.js +45 -0
  348. package/dist/chunk-Q3WIC6GQ.js +2670 -0
  349. package/dist/chunk-QGJDMEOV.js +34 -0
  350. package/dist/chunk-QJYIHVXT.js +100 -0
  351. package/dist/chunk-QNOB37UH.js +58 -0
  352. package/dist/chunk-QOCOVLUH.js +462 -0
  353. package/dist/chunk-QTCJ5CC5.js +172 -0
  354. package/dist/chunk-QU6JQJMH.js +3063 -0
  355. package/dist/chunk-QVFV5IP2.js +232 -0
  356. package/dist/chunk-QVZMFDYG.js +29 -0
  357. package/dist/chunk-R2ZYWNW3.js +1581 -0
  358. package/dist/chunk-R4UWBC35.js +200 -0
  359. package/dist/chunk-R6W23LKN.js +254 -0
  360. package/dist/chunk-RAK5HOIJ.js +459 -0
  361. package/dist/chunk-RDFRCT64.js +168 -0
  362. package/dist/chunk-RE5VZDFQ.js +58 -0
  363. package/dist/chunk-RGROYC2G.js +638 -0
  364. package/dist/chunk-RGWHUI5E.js +68 -0
  365. package/dist/chunk-RHVG6UNL.js +205 -0
  366. package/dist/chunk-RI4EX2QE.js +18 -0
  367. package/dist/chunk-RIKFAWZF.js +71 -0
  368. package/dist/chunk-RJAAKDRX.js +17 -0
  369. package/dist/chunk-RSXSD4MH.js +1016 -0
  370. package/dist/chunk-RW7RVSDV.js +79 -0
  371. package/dist/chunk-RWREC3KJ.js +517 -0
  372. package/dist/chunk-RZY7RKM5.js +500 -0
  373. package/dist/chunk-S2MNWFAG.js +52 -0
  374. package/dist/chunk-S2VQCZO4.js +22 -0
  375. package/dist/chunk-S54MKU6V.js +117 -0
  376. package/dist/chunk-S77XPALC.js +239 -0
  377. package/dist/chunk-SCW4ZF6R.js +150 -0
  378. package/dist/chunk-SKHGYQ7W.js +405 -0
  379. package/dist/chunk-SNLBO4BF.js +247 -0
  380. package/dist/chunk-SP3LFU6B.js +60 -0
  381. package/dist/chunk-SQZRPY23.js +5181 -0
  382. package/dist/chunk-SSB5UQHA.js +4128 -0
  383. package/dist/chunk-STJOHHSF.js +605 -0
  384. package/dist/chunk-STV6LYYE.js +45 -0
  385. package/dist/chunk-SUN4OFTW.js +740 -0
  386. package/dist/chunk-SURZ2WFE.js +326 -0
  387. package/dist/chunk-SUZ7UYZH.js +1972 -0
  388. package/dist/chunk-SZ7DL357.js +1047 -0
  389. package/dist/chunk-T2SZELJL.js +624 -0
  390. package/dist/chunk-T6VPI2XP.js +10338 -0
  391. package/dist/chunk-TAJPCXSB.js +13 -0
  392. package/dist/chunk-TAOOYK3P.js +358 -0
  393. package/dist/chunk-TDSEX5CF.js +24 -0
  394. package/dist/chunk-TFTGP7Z7.js +174 -0
  395. package/dist/chunk-TGON4N4O.js +197 -0
  396. package/dist/chunk-TIBZPAD2.js +9924 -0
  397. package/dist/chunk-TK644IOG.js +1813 -0
  398. package/dist/chunk-TRSVUPCX.js +25 -0
  399. package/dist/chunk-TSPQONRT.js +4533 -0
  400. package/dist/chunk-TSXGRLPR.js +107 -0
  401. package/dist/chunk-TWYLVAS2.js +152 -0
  402. package/dist/chunk-U2S3YEX3.js +224 -0
  403. package/dist/chunk-U32HWI76.js +437 -0
  404. package/dist/chunk-U45RTRGY.js +818 -0
  405. package/dist/chunk-U62VCQGR.js +49 -0
  406. package/dist/chunk-UDMS5AD3.js +307 -0
  407. package/dist/chunk-UGX7GI37.js +94 -0
  408. package/dist/chunk-UH3JJSHK.js +1 -0
  409. package/dist/chunk-UHRBTZYY.js +208 -0
  410. package/dist/chunk-UHT2KRG5.js +193 -0
  411. package/dist/chunk-UI2F6DJ5.js +118 -0
  412. package/dist/chunk-UKMAFG7A.js +189 -0
  413. package/dist/chunk-UUH2RVKS.js +585 -0
  414. package/dist/chunk-UVBBFDFQ.js +270 -0
  415. package/dist/chunk-UXZF3B7T.js +75 -0
  416. package/dist/chunk-V6YLL5WA.js +3746 -0
  417. package/dist/chunk-V72RMBM4.js +48 -0
  418. package/dist/chunk-VBNCKCCI.js +16 -0
  419. package/dist/chunk-VCAUV5XQ.js +3679 -0
  420. package/dist/chunk-VDSH7O4Y.js +152 -0
  421. package/dist/chunk-VNSYKC25.js +24 -0
  422. package/dist/chunk-VTLNJQ44.js +133 -0
  423. package/dist/chunk-VV6HOXRC.js +302 -0
  424. package/dist/chunk-VVGEPBPS.js +218 -0
  425. package/dist/chunk-VXF4Q3FW.js +20 -0
  426. package/dist/chunk-W3ZGW3C5.js +331 -0
  427. package/dist/chunk-W4OMESPG.js +271 -0
  428. package/dist/chunk-WDUORIHF.js +877 -0
  429. package/dist/chunk-WDVTY4U6.js +148 -0
  430. package/dist/chunk-WGXYDLMX.js +4386 -0
  431. package/dist/chunk-WMPU2UOV.js +82 -0
  432. package/dist/chunk-WOEVVPDP.js +1125 -0
  433. package/dist/chunk-WTLMSPBQ.js +256 -0
  434. package/dist/chunk-X43NMU4Z.js +1124 -0
  435. package/dist/chunk-X5NTI5U5.js +368 -0
  436. package/dist/chunk-X6UIEADS.js +949 -0
  437. package/dist/chunk-XAONGNST.js +57 -0
  438. package/dist/chunk-XB5YLCLB.js +13 -0
  439. package/dist/chunk-XGYF2QMZ.js +351 -0
  440. package/dist/chunk-XHEKQENB.js +255 -0
  441. package/dist/chunk-XPHKYHO4.js +878 -0
  442. package/dist/chunk-XQD2B6BB.js +507 -0
  443. package/dist/chunk-XT2ZQVTC.js +558 -0
  444. package/dist/chunk-XUSRFFA7.js +1859 -0
  445. package/dist/chunk-XUXVDPSZ.js +50 -0
  446. package/dist/chunk-XV7NZL4B.js +57 -0
  447. package/dist/chunk-XXCGJGSQ.js +121 -0
  448. package/dist/chunk-XYGDZCB5.js +659 -0
  449. package/dist/chunk-XZAMZUX5.js +992 -0
  450. package/dist/chunk-XZE4XARH.js +563 -0
  451. package/dist/chunk-Y34DUC4A.js +1356 -0
  452. package/dist/chunk-Y3J4JMTU.js +61 -0
  453. package/dist/chunk-Y4RC2YFX.js +1270 -0
  454. package/dist/chunk-Y55LZN5U.js +52 -0
  455. package/dist/chunk-Y5677NDO.js +183 -0
  456. package/dist/chunk-YESZJFK6.js +220 -0
  457. package/dist/chunk-YGXKOBQQ.js +292 -0
  458. package/dist/chunk-YMX76IOS.js +31 -0
  459. package/dist/chunk-YOTXESEH.js +257 -0
  460. package/dist/chunk-YQAAKTVH.js +712 -0
  461. package/dist/chunk-YVORHQ2S.js +579 -0
  462. package/dist/chunk-YWNAHW24.js +1552 -0
  463. package/dist/chunk-Z476RATD.js +1689 -0
  464. package/dist/chunk-ZDTGECTN.js +235 -0
  465. package/dist/chunk-ZDTMICNY.js +316 -0
  466. package/dist/chunk-ZIPWI2LY.js +151 -0
  467. package/dist/chunk-ZIVYXF7A.js +2344 -0
  468. package/dist/chunk-ZX65UI5W.js +78 -0
  469. package/dist/chunk-ZYG7GGKO.js +218 -0
  470. package/dist/chunk-ZZZUL4OF.js +38 -0
  471. package/dist/cli-utils-HUOTBRM3.js +40 -0
  472. package/dist/cli-validation-WLXWLUJL.js +111 -0
  473. package/dist/commit-utils-3QV2P6RA.js +202 -0
  474. package/dist/compete-config-resolver-SNH3TT2Q.js +76 -0
  475. package/dist/compete-request-XWNPOARL.js +364 -0
  476. package/dist/compete-results-PAP67LDR.js +208 -0
  477. package/dist/competition-outcome-tracker-GOZXNAQU.js +38 -0
  478. package/dist/config-HWHUNA72.js +166 -0
  479. package/dist/config-audit-EL3GHXS7.js +360 -0
  480. package/dist/config-explain-TNILDEVJ.js +12 -0
  481. package/dist/config-loader-VPFPFO4B.js +38 -0
  482. package/dist/config-manager-L3VRNTSG.js +67 -0
  483. package/dist/config-validator-SIIQEOFQ.js +72 -0
  484. package/dist/cost-7CX37DU3.js +53 -0
  485. package/dist/coverage-orchestrator-MNKHD6YC.js +772 -0
  486. package/dist/coverage-scanner-YVD62MLH.js +12 -0
  487. package/dist/createCompetitionRunner-LJG6ZQSO.js +46 -0
  488. package/dist/data-migration-state-VJK64DLT.js +31 -0
  489. package/dist/db-migrator-XSEIOGWY.js +34 -0
  490. package/dist/discovery-JGYGDD25.js +25 -0
  491. package/dist/doctor-CGBCD7IQ.js +186 -0
  492. package/dist/domain-analyzer-DL6BDR2N.js +29 -0
  493. package/dist/ensure-initialized-4BY73HLE.js +52 -0
  494. package/dist/entry.js +940 -0
  495. package/dist/environment-IGVH5X53.js +81 -0
  496. package/dist/error-parser-core-PPZ36A4S.js +50 -0
  497. package/dist/escalation-ladder-NWY5BJ57.js +130 -0
  498. package/dist/evaluation-context-KMWDSDYD.js +35 -0
  499. package/dist/evidence-plan-resolver-YIVH76PU.js +85 -0
  500. package/dist/execution-data-writer-OHAQ7G5H.js +53 -0
  501. package/dist/execution-policy-applier-ZHD3DCF3.js +31 -0
  502. package/dist/execution-preflight-Z4Y64V3I.js +209 -0
  503. package/dist/execution-roles-KBH2MC3M.js +66 -0
  504. package/dist/exit-code-error-Z4SW2DVK.js +14 -0
  505. package/dist/external-temp-cleanup-N2RZH4QP.js +311 -0
  506. package/dist/factory-IYBMCZG7.js +149 -0
  507. package/dist/file-utils-XIVR2ZMA.js +47 -0
  508. package/dist/flywheel-autoloop-executor-R3KD2G4D.js +249 -0
  509. package/dist/flywheel-competition-executor-XCFGVJSK.js +259 -0
  510. package/dist/flywheel-executor-LTSIZN2L.js +369 -0
  511. package/dist/flywheel-git-isolation-CZ5YVVZY.js +48 -0
  512. package/dist/flywheel-manifest-5UC4VBMA.js +108 -0
  513. package/dist/flywheel-model-defaults-7CVKP53V.js +27 -0
  514. package/dist/flywheel-preflight-6E33DJDK.js +104 -0
  515. package/dist/flywheel-resume-7HELH7QS.js +23 -0
  516. package/dist/flywheel-safety-7U7DPOAP.js +28 -0
  517. package/dist/flywheel-scope-decision-ZHKF6ZIN.js +11 -0
  518. package/dist/get-telemetry-logger-AZ46EPRP.js +73 -0
  519. package/dist/git-worktree-IY6V6DUO.js +18 -0
  520. package/dist/github-pr-manager-4XUO2YTM.js +211 -0
  521. package/dist/guidance-profile-config-E7XJL2VP.js +117 -0
  522. package/dist/guidance-profile-renderer-QK2YMAAP.js +21 -0
  523. package/dist/index-query-4JEUKA44.js +31 -0
  524. package/dist/index.js +108644 -0
  525. package/dist/instructions-CM6THDV7.js +64 -0
  526. package/dist/invoke-provider-auth-V5TC5UDS.js +223 -0
  527. package/dist/judge-scoring.json +80 -0
  528. package/dist/judge-test.js +555 -0
  529. package/dist/lab-mode-OTWVHN63.js +39 -0
  530. package/dist/lab-utils-VA6VXNOV.js +23 -0
  531. package/dist/linux-host-class-UY4KVLFD.js +29 -0
  532. package/dist/llm-judge-executor-34YPIRJ7.js +133 -0
  533. package/dist/local-executor-LJJSCWZX.js +223 -0
  534. package/dist/logger-6PRYM56M.js +72 -0
  535. package/dist/loop-spec-XTLQAVZ7.js +191 -0
  536. package/dist/manager-2HJG5CLT.js +25 -0
  537. package/dist/matrix-prompt-builder-LHDTJ4TY.js +497 -0
  538. package/dist/matrix-result-parser-7W35EUOV.js +15 -0
  539. package/dist/metadata-HQ43NDEK.js +22 -0
  540. package/dist/model-invocations-db-QBO4Y7WZ.js +38 -0
  541. package/dist/monitor-MCI3F4PX.js +72 -0
  542. package/dist/next-HQKDXIIR.js +90 -0
  543. package/dist/next-JC3V2UCS.js +69 -0
  544. package/dist/optimization-config-resolver-QPSFLCJU.js +75 -0
  545. package/dist/package-3YCWIQQ5.js +10 -0
  546. package/dist/parallel-orchestrator-NL7YJJU2.js +297 -0
  547. package/dist/parallel-worker.js +279 -0
  548. package/dist/parse-git-status-PIAF3OTP.js +10 -0
  549. package/dist/path-security-ETTH6TZL.js +39 -0
  550. package/dist/pattern-bank-UNJR5ADV.js +15 -0
  551. package/dist/plan-backlog-list-fast-DZK24LSZ.js +270 -0
  552. package/dist/plan-backlog-show-fast-63GBBH6Q.js +406 -0
  553. package/dist/plan-sprint-list-fast-TJ6ZUF5E.js +162 -0
  554. package/dist/plan-sprint-status-fast-YWE5X3NG.js +208 -0
  555. package/dist/plan-task-status-fast-K22BTTBW.js +349 -0
  556. package/dist/plan-to-flywheel-VFGCPINA.js +456 -0
  557. package/dist/planning-backlog-Y6TIJYWU.js +319 -0
  558. package/dist/poetic-root-V5DNXEAE.js +17 -0
  559. package/dist/preflight-OPANWMME.js +12 -0
  560. package/dist/process-registry-PDZJPTAS.js +27 -0
  561. package/dist/process-scanner-C22SYXYD.js +22 -0
  562. package/dist/processes-KMQUD7HY.js +29 -0
  563. package/dist/processes-json-fast-IBDXZ6WW.js +135 -0
  564. package/dist/profile-2XP3FWH2.js +149 -0
  565. package/dist/prompts-EPAAAMMF.js +168 -0
  566. package/dist/protected-branches-RNTEX7ET.js +57 -0
  567. package/dist/provider-aware-resource-manager-QBTZJMNP.js +18 -0
  568. package/dist/provider-matrix-KWTYA5QV.js +154 -0
  569. package/dist/provider-matrix-renderer-MZDWKKID.js +139 -0
  570. package/dist/provider-output-forwarding-DERID3TP.js +30 -0
  571. package/dist/provider-registry-J5NRBJKI.js +128 -0
  572. package/dist/provider-temp-cleanup-KYGLF6YU.js +14 -0
  573. package/dist/prune-engine-Q6E2DXBN.js +451 -0
  574. package/dist/quality-gate-33SHK43X.js +70 -0
  575. package/dist/quickstart-E32SODTA.js +62 -0
  576. package/dist/readiness-REWW7OSV.js +96 -0
  577. package/dist/registry-N6L36RE2.js +153 -0
  578. package/dist/repair-helpers-TTV5FEF4.js +117 -0
  579. package/dist/repo-root-2IGD4H7X.js +22 -0
  580. package/dist/resolution-engine-LXQYDSKS.js +127 -0
  581. package/dist/resolve-provider-cli-O2P6XZBZ.js +35 -0
  582. package/dist/restore-telemetry-db-BQL6DTQF.js +360 -0
  583. package/dist/result-streamer-WEHW476R.js +19 -0
  584. package/dist/routing-events-DHPUZDDF.js +27 -0
  585. package/dist/routing-history-store-UWCEXAP3.js +46 -0
  586. package/dist/routing-planner-VGQU35QM.js +160 -0
  587. package/dist/run-poetic-tui-ZZXFDOQ4.js +13517 -0
  588. package/dist/run-simulation.js +376 -0
  589. package/dist/runner-2YPKOJ6A.js +1092 -0
  590. package/dist/runner-HEJJ65AJ.js +1571 -0
  591. package/dist/safety-OCC4KJJR.js +64 -0
  592. package/dist/safety-stanza-BSVE6OJU.js +60 -0
  593. package/dist/sandbox-3AG2WJLM.js +94 -0
  594. package/dist/sandbox-5JOFBS75.js +81 -0
  595. package/dist/schema-extensions.sql +234 -0
  596. package/dist/security-2KI5XNDG.js +17 -0
  597. package/dist/setup-bb-plugin-QAQWZCV5.js +738 -0
  598. package/dist/setup-claude-code-P7BTTSPO.js +317 -0
  599. package/dist/setup-temp-cleanup-GASCWZ2I.js +20 -0
  600. package/dist/shared-utils-D6U6UREP.js +37 -0
  601. package/dist/simple-artifact-goal-OTXNGZY6.js +25 -0
  602. package/dist/sprint-QGXLN3SO.js +338 -0
  603. package/dist/sprint-bridge-FNKQCJGL.js +68 -0
  604. package/dist/sprint-execution-service-4ELKNJDS.js +311 -0
  605. package/dist/sprint-manager-7TNCXCIX.js +91 -0
  606. package/dist/sqlite-wrapper-UDWCTNLJ.js +17 -0
  607. package/dist/stale-cleanup-orchestrator-H5XKGZP2.js +62 -0
  608. package/dist/storage-access-F6ALDN4S.js +22 -0
  609. package/dist/synthesis-TGQUVAW3.js +185 -0
  610. package/dist/task-classifier-DZIRBSS2.js +494 -0
  611. package/dist/task-list-fast-PJ2EXVZE.js +147 -0
  612. package/dist/task-manager-5742GMJK.js +93 -0
  613. package/dist/task-splitter-6MBXSWF6.js +79 -0
  614. package/dist/task-type-detector-OLVOMXZO.js +21 -0
  615. package/dist/task-type-resolver-4HG6TXFV.js +42 -0
  616. package/dist/telemetry-JX7EMNOZ.js +131 -0
  617. package/dist/telemetry-health-tracker-DMSSGBZ2.js +11 -0
  618. package/dist/telemetry-path-resolver-7ICSG276.js +28 -0
  619. package/dist/telemetry-reliability-2MLJ4J6B.js +125 -0
  620. package/dist/token-estimator-PDU345YE.js +37 -0
  621. package/dist/transports-3UEO6C5Y.js +255 -0
  622. package/dist/unified-cost-tracker-F3W5NMPG.js +35 -0
  623. package/dist/unified-state-cleanup-LJPF2BOW.js +276 -0
  624. package/dist/universal-cost-calculator-BAJV35GA.js +42 -0
  625. package/dist/user-agents-GHUGCSKN.js +22 -0
  626. package/dist/variant-delivery-state-XCOYVCM4.js +33 -0
  627. package/dist/variant-state-cleanup-QIEKRULB.js +280 -0
  628. package/dist/variant-success-PJXWE3ZV.js +12 -0
  629. package/dist/variant-worker-HPTUA37Z.js +4196 -0
  630. package/dist/variant-worker.js +24 -0
  631. package/dist/variants-2HDYZOCG.js +233 -0
  632. package/dist/verification-toolchains-VVKT3GBF.js +28 -0
  633. package/dist/verify-commands-5F6CJV4B.js +37 -0
  634. package/dist/warning-EGQGUUIO.js +12 -0
  635. package/dist/work-edge-RWEDWJZF.js +49 -0
  636. package/dist/work-item-writer-WHAVZXAY.js +19 -0
  637. package/dist/worker-AGWHD4D2.js +1435 -0
  638. package/dist/worker.js +19 -0
  639. package/dist/worktree-metrics-3DFUYVYE.js +26 -0
  640. package/dist/writeback-VZKHYHSN.js +44 -0
  641. package/docs/CLI_REFERENCE.md +7040 -0
  642. package/docs/PROVIDER_SETUP.md +1570 -0
  643. package/docs/README.md +96 -0
  644. package/docs/TROUBLESHOOTING.md +2232 -0
  645. package/docs/getting-started/QUICK_START.md +294 -0
  646. package/docs/getting-started/README.md +188 -0
  647. package/docs/getting-started/SETUP.md +52 -0
  648. package/docs/reference/AGENT_CONTEXT.md +38 -0
  649. package/docs/reference/PROVIDER_RELEASE_TIERS.md +34 -0
  650. package/docs/reference/README.md +381 -0
  651. package/docs/reference/SECURITY.md +262 -0
  652. package/integrations/bb-plugin-poetic/README.md +362 -0
  653. package/integrations/bb-plugin-poetic/app.css +341 -0
  654. package/integrations/bb-plugin-poetic/app.tsx +5059 -0
  655. package/integrations/bb-plugin-poetic/package.json +45 -0
  656. package/integrations/bb-plugin-poetic/server.ts +444 -0
  657. package/integrations/bb-plugin-poetic/src/adapter.ts +3312 -0
  658. package/integrations/bb-plugin-poetic/src/backlog-authoring-model.ts +150 -0
  659. package/integrations/bb-plugin-poetic/src/backlog-authoring-schema.ts +355 -0
  660. package/integrations/bb-plugin-poetic/src/backlog-authoring-service.ts +419 -0
  661. package/integrations/bb-plugin-poetic/src/backlog-authoring-view.ts +1026 -0
  662. package/integrations/bb-plugin-poetic/src/competition-defaults-schema.ts +122 -0
  663. package/integrations/bb-plugin-poetic/src/competition-defaults-service.ts +105 -0
  664. package/integrations/bb-plugin-poetic/src/competition-defaults-view.ts +138 -0
  665. package/integrations/bb-plugin-poetic/src/contract.ts +615 -0
  666. package/integrations/bb-plugin-poetic/src/finalize-model.ts +205 -0
  667. package/integrations/bb-plugin-poetic/src/finalize-schema.ts +158 -0
  668. package/integrations/bb-plugin-poetic/src/finalize-service.ts +382 -0
  669. package/integrations/bb-plugin-poetic/src/finalize-view.ts +159 -0
  670. package/integrations/bb-plugin-poetic/src/judge-operations-readback.ts +303 -0
  671. package/integrations/bb-plugin-poetic/src/judge-operations-schema.ts +33 -0
  672. package/integrations/bb-plugin-poetic/src/judge-operations-view.ts +459 -0
  673. package/integrations/bb-plugin-poetic/src/model.ts +1302 -0
  674. package/integrations/bb-plugin-poetic/src/monitor-service.ts +233 -0
  675. package/integrations/bb-plugin-poetic/src/panel-read-ux.ts +97 -0
  676. package/integrations/bb-plugin-poetic/src/patch-preview-schema.ts +166 -0
  677. package/integrations/bb-plugin-poetic/src/patch-preview-service.ts +480 -0
  678. package/integrations/bb-plugin-poetic/src/patch-preview-view.ts +109 -0
  679. package/integrations/bb-plugin-poetic/src/planning-readback.ts +204 -0
  680. package/integrations/bb-plugin-poetic/src/planning-service.ts +594 -0
  681. package/integrations/bb-plugin-poetic/src/planning-workspace-schema.ts +95 -0
  682. package/integrations/bb-plugin-poetic/src/planning-workspace.ts +323 -0
  683. package/integrations/bb-plugin-poetic/src/poll-handoff.ts +136 -0
  684. package/integrations/bb-plugin-poetic/src/project-target-server.ts +21 -0
  685. package/integrations/bb-plugin-poetic/src/project-target.ts +45 -0
  686. package/integrations/bb-plugin-poetic/src/reference-index.ts +192 -0
  687. package/integrations/bb-plugin-poetic/src/repository-schema.ts +30 -0
  688. package/integrations/bb-plugin-poetic/src/result-explorer-view.ts +597 -0
  689. package/integrations/bb-plugin-poetic/src/result-readback-model.ts +163 -0
  690. package/integrations/bb-plugin-poetic/src/result-readback-schema.ts +319 -0
  691. package/integrations/bb-plugin-poetic/src/result-readback-service.ts +333 -0
  692. package/integrations/bb-plugin-poetic/src/run-page-view.ts +177 -0
  693. package/integrations/bb-plugin-poetic/src/setup-config-schema.ts +291 -0
  694. package/integrations/bb-plugin-poetic/src/setup-config-service.ts +590 -0
  695. package/integrations/bb-plugin-poetic/src/setup-config-view.ts +413 -0
  696. package/integrations/bb-plugin-poetic/src/sprint-close-model.ts +150 -0
  697. package/integrations/bb-plugin-poetic/src/sprint-close-schema.ts +136 -0
  698. package/integrations/bb-plugin-poetic/src/sprint-close-service.ts +341 -0
  699. package/integrations/bb-plugin-poetic/src/sprint-close-view.ts +116 -0
  700. package/integrations/bb-plugin-poetic/src/sprint-composition-model.ts +714 -0
  701. package/integrations/bb-plugin-poetic/src/sprint-composition-readback.ts +231 -0
  702. package/integrations/bb-plugin-poetic/src/sprint-composition-schema.ts +601 -0
  703. package/integrations/bb-plugin-poetic/src/sprint-composition-service.ts +775 -0
  704. package/integrations/bb-plugin-poetic/src/sprint-composition-view.ts +1221 -0
  705. package/integrations/bb-plugin-poetic/src/task-authoring-model.ts +567 -0
  706. package/integrations/bb-plugin-poetic/src/task-authoring-schema.ts +635 -0
  707. package/integrations/bb-plugin-poetic/src/task-authoring-service.ts +842 -0
  708. package/integrations/bb-plugin-poetic/src/task-authoring-view.ts +1227 -0
  709. package/integrations/bb-plugin-poetic/src/task-detail-readback.ts +56 -0
  710. package/integrations/bb-plugin-poetic/src/task-detail-schema.ts +144 -0
  711. package/integrations/bb-plugin-poetic/src/task-navigation.ts +446 -0
  712. package/integrations/bb-plugin-poetic/src/workbench-route.ts +74 -0
  713. package/integrations/bb-plugin-poetic/tests/host-contract.test.ts +773 -0
  714. package/integrations/bb-plugin-poetic/tsconfig.json +18 -0
  715. package/integrations/bb-plugin-poetic/types/PROVENANCE.json +52 -0
  716. package/integrations/bb-plugin-poetic/types/bb-plugin-sdk-app.d.ts +1444 -0
  717. package/integrations/bb-plugin-poetic/types/bb-plugin-sdk.d.ts +13030 -0
  718. package/integrations/bb-plugin-poetic/vitest.host.config.ts +71 -0
  719. package/package.json +331 -0
  720. package/schemas/README.md +80 -0
  721. package/schemas/config-v1.schema.json +136 -0
  722. package/schemas/execution-config.schema.json +47 -0
  723. package/schemas/judge-scoring.schema.json +370 -0
  724. package/schemas/poetic.config.schema.json +2214 -0
  725. package/schemas/provider-config.schema.json +203 -0
  726. package/schemas/telemetry-config.schema.json +79 -0
  727. package/schemas/user-preferences.schema.json +141 -0
  728. package/scripts/assert-node-runtime.mjs +140 -0
  729. package/scripts/preflight-native.mjs +49 -0
  730. package/scripts/preinstall-node-check.mjs +78 -0
  731. package/scripts/setup-git-hooks.mjs +24 -0
  732. package/scripts/sync.sh +2722 -0
  733. package/scripts/write-node-launcher.sh +108 -0
  734. package/src/resources/gemini/slash-packs/default/plan.toml +15 -0
  735. package/src/resources/gemini/slash-packs/default/summary.toml +16 -0
  736. package/src/resources/gemini/slash-packs/default/tests.toml +16 -0
  737. package/templates/.poetic/README.md +37 -0
  738. package/templates/.poetic/agents/README.md +296 -0
  739. package/templates/.poetic/agents/api-documenter.md +147 -0
  740. package/templates/.poetic/agents/backend-architect.md +31 -0
  741. package/templates/.poetic/agents/code-reviewer.md +157 -0
  742. package/templates/.poetic/agents/data-scientist.md +179 -0
  743. package/templates/.poetic/agents/database-optimizer.md +145 -0
  744. package/templates/.poetic/agents/debugger.md +31 -0
  745. package/templates/.poetic/agents/deployment-engineer.md +164 -0
  746. package/templates/.poetic/agents/devops-troubleshooter.md +139 -0
  747. package/templates/.poetic/agents/frontend-developer.md +150 -0
  748. package/templates/.poetic/agents/javascript-pro.md +36 -0
  749. package/templates/.poetic/agents/performance-engineer.md +151 -0
  750. package/templates/.poetic/agents/python-pro.md +137 -0
  751. package/templates/.poetic/agents/test-automator.md +147 -0
  752. package/templates/.poetic/agents/typescript-pro.md +34 -0
  753. package/templates/.poetic/config/poetic.config.jsonc +69 -0
  754. package/templates/.poetic/config/project-context.template.json +6 -0
  755. package/templates/.poetic/config/task-type-aliases.presets/kanban.yaml +14 -0
  756. package/templates/.poetic/config/task-type-aliases.presets/scrum.yaml +17 -0
  757. package/templates/.poetic/config/task-type-aliases.presets/xp.yaml +12 -0
  758. package/templates/.poetic/config/task-type-aliases.yaml +28 -0
  759. package/templates/.poetic/gitignore.template +55 -0
  760. package/templates/.poetic/task-types/analysis.yaml +40 -0
  761. package/templates/.poetic/task-types/architecture.yaml +38 -0
  762. package/templates/.poetic/task-types/doc.yaml +35 -0
  763. package/templates/.poetic/task-types/feature.yaml +23 -0
  764. package/templates/.poetic/task-types/general.yaml +6 -0
  765. package/templates/.poetic/task-types/security.yaml +39 -0
  766. package/templates/AGENTS.template.md +99 -0
  767. package/templates/CLAUDE.template.md +1 -0
  768. package/templates/GEMINI.template.md +1 -0
  769. package/templates/builtin-workflows/code-review.yaml +73 -0
  770. package/templates/builtin-workflows/compete-streak.yaml +78 -0
  771. package/templates/builtin-workflows/hello-verify.yaml +10 -0
  772. package/templates/builtin-workflows/judge-regression.yaml +114 -0
  773. package/templates/builtin-workflows/skills/code-review/SKILL.md +60 -0
  774. package/templates/builtin-workflows/skills/hello-verify/SKILL.md +6 -0
  775. package/templates/guard-kit/GUARD_SETUP.md.template +255 -0
  776. package/templates/guard-kit/check.mjs.template +777 -0
  777. package/templates/guard-kit/config.json.template +6 -0
  778. package/templates/guard-kit/poetic-guard.yml.template +189 -0
  779. package/templates/profiles/README.md +56 -0
  780. package/templates/profiles/frontier-claude.json +27 -0
  781. package/templates/profiles/frontier-codex.json +26 -0
@@ -0,0 +1,2670 @@
1
+ import {
2
+ PromptStore
3
+ } from "./chunk-OQ6K46CK.js";
4
+ import {
5
+ SEVEN_DAYS_MS
6
+ } from "./chunk-3AOKYKA7.js";
7
+ import {
8
+ parseJsonWithContext
9
+ } from "./chunk-QVZMFDYG.js";
10
+ import {
11
+ emitWarning
12
+ } from "./chunk-EJGCZGUF.js";
13
+
14
+ // src/prompts/analytics.ts
15
+ var AnalyticsEngine = class {
16
+ TREND_WINDOW = 10;
17
+ // Number of recent values to analyze
18
+ MIN_SAMPLES_FOR_TREND = 4;
19
+ REGRESSION_THRESHOLD = 2;
20
+ // Standard deviations from mean
21
+ /**
22
+ * Detect trend in metric values
23
+ *
24
+ * @param metrics Array of metric values
25
+ * @param metric Type of metric being analyzed
26
+ * @returns Trend analysis with type and strength
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const successRates = [0.70, 0.72, 0.75, 0.78, 0.80, 0.82, 0.83];
31
+ * const trend = analytics.detectTrend(successRates, 'success_rate');
32
+ * console.log(`Trend: ${trend.type}, Strength: ${trend.strength}`);
33
+ * ```
34
+ */
35
+ detectTrend(metrics, _metric) {
36
+ if (metrics.length < this.MIN_SAMPLES_FOR_TREND) {
37
+ return {
38
+ type: "insufficient_data",
39
+ strength: 0,
40
+ slope: 0,
41
+ direction: "flat",
42
+ lastNValues: metrics
43
+ };
44
+ }
45
+ const window = metrics.slice(-this.TREND_WINDOW);
46
+ const { slope, rSquared } = this.linearRegression(
47
+ Array.from({ length: window.length }, (_, i) => i),
48
+ window
49
+ );
50
+ const absSlope = Math.abs(slope);
51
+ let type = "stable";
52
+ let strength = rSquared;
53
+ const firstValue = window[0] ?? 0;
54
+ const lastValue = window[window.length - 1] ?? 0;
55
+ const totalChange = Math.abs(lastValue - firstValue);
56
+ const relativeChange = totalChange / Math.max(Math.abs(firstValue), 0.01);
57
+ if (absSlope < 5e-3 || relativeChange < 0.02 && absSlope < 0.3) {
58
+ type = "stable";
59
+ strength = 1 - Math.min(1, absSlope);
60
+ } else if (slope > 0) {
61
+ type = "improving";
62
+ strength = Math.min(1, rSquared * (1 + absSlope / 10));
63
+ } else {
64
+ type = "declining";
65
+ strength = Math.min(1, rSquared * (1 + absSlope / 10));
66
+ }
67
+ const direction = slope > 0.05 ? "up" : slope < -0.05 ? "down" : "flat";
68
+ return {
69
+ type,
70
+ strength: Math.max(0, Math.min(1, strength)),
71
+ slope,
72
+ direction,
73
+ lastNValues: window
74
+ };
75
+ }
76
+ /**
77
+ * Forecast future performance
78
+ *
79
+ * @param metrics Historical metric values
80
+ * @param daysAhead Days to forecast ahead (default 7)
81
+ * @param versionId Version being analyzed
82
+ * @param metricType Type of metric
83
+ * @returns Forecast with confidence
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const historicalCompleteness = [75, 76, 77, 78, 79, 80];
88
+ * const forecast = analytics.forecastPerformance(
89
+ * historicalCompleteness,
90
+ * 7,
91
+ * 'v2.0.0',
92
+ * 'completeness'
93
+ * );
94
+ * console.log(`Forecasted: ${forecast.forecastedValue}/100`);
95
+ * ```
96
+ */
97
+ forecastPerformance(metrics, daysAhead, versionId, metricType) {
98
+ if (metrics.length < this.MIN_SAMPLES_FOR_TREND) {
99
+ return {
100
+ versionId,
101
+ metric: metricType,
102
+ currentValue: metrics[metrics.length - 1] ?? 0,
103
+ forecastedValue: metrics[metrics.length - 1] ?? 0,
104
+ daysAhead,
105
+ confidence: 0,
106
+ trendType: "insufficient_data",
107
+ reasoning: "Insufficient data for forecasting (need at least 5 samples)"
108
+ };
109
+ }
110
+ const trend = this.detectTrend(metrics);
111
+ const x = Array.from({ length: metrics.length }, (_, i) => i);
112
+ const { slope, intercept } = this.linearRegression(x, metrics);
113
+ const forecastedValue = intercept + slope * (metrics.length + daysAhead);
114
+ const currentValue = metrics[metrics.length - 1] ?? 0;
115
+ let adjustedForecasted = forecastedValue;
116
+ if (metricType === "success_rate") {
117
+ const maxValue = Math.max(...metrics);
118
+ if (maxValue > 1) {
119
+ adjustedForecasted = Math.max(0, Math.min(100, forecastedValue));
120
+ } else {
121
+ adjustedForecasted = Math.max(0, Math.min(1, forecastedValue));
122
+ }
123
+ } else if (metricType === "completeness") {
124
+ adjustedForecasted = Math.max(0, Math.min(100, forecastedValue));
125
+ } else if (metricType === "duration") {
126
+ adjustedForecasted = Math.max(0, forecastedValue);
127
+ }
128
+ const distanceConfidence = Math.max(0.2, 1 - daysAhead / 30);
129
+ const trendConfidence = trend.strength;
130
+ const confidence = (distanceConfidence + trendConfidence) / 2;
131
+ let reasoning = `Based on ${metrics.length} historical samples. `;
132
+ if (trend.type === "improving") {
133
+ reasoning += `Trending upward (slope: ${slope.toFixed(3)}). `;
134
+ } else if (trend.type === "declining") {
135
+ reasoning += `Trending downward (slope: ${slope.toFixed(3)}). `;
136
+ } else {
137
+ reasoning += "Performance is stable. ";
138
+ }
139
+ reasoning += `Confidence: ${(confidence * 100).toFixed(0)}%`;
140
+ return {
141
+ versionId,
142
+ metric: metricType,
143
+ currentValue,
144
+ forecastedValue: adjustedForecasted,
145
+ daysAhead,
146
+ confidence,
147
+ trendType: trend.type,
148
+ reasoning
149
+ };
150
+ }
151
+ /**
152
+ * Detect regressions in prompt performance
153
+ *
154
+ * @param metrics Array of performance metrics
155
+ * @param versionId Version being analyzed
156
+ * @returns Array of detected regressions
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const regressions = analytics.detectRegressions(
161
+ * metricsHistory,
162
+ * 'v1.5.0'
163
+ * );
164
+ * regressions.forEach(r => {
165
+ * console.log(`[${r.severity}] ${r.metric}: ${r.actualValue} vs ${r.expectedValue}`);
166
+ * });
167
+ * ```
168
+ */
169
+ detectRegressions(metrics, versionId) {
170
+ const regressions = [];
171
+ if (metrics.length < 5) {
172
+ return regressions;
173
+ }
174
+ const successRates = metrics.map((m) => m.successRate);
175
+ const successRegression = this.detectMetricRegression(successRates, "success_rate");
176
+ if (successRegression) {
177
+ regressions.push({
178
+ versionId,
179
+ metric: "success_rate",
180
+ expectedValue: successRegression.expected,
181
+ actualValue: successRegression.actual,
182
+ deviation: successRegression.deviation,
183
+ severity: this.calculateSeverity(successRegression.deviation, "success_rate"),
184
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
185
+ reason: `Success rate dropped from ${(successRegression.expected * 100).toFixed(1)}% to ${(successRegression.actual * 100).toFixed(1)}%`
186
+ });
187
+ }
188
+ const completeness = metrics.map((m) => m.avgCompleteness);
189
+ const completenessRegression = this.detectMetricRegression(completeness, "completeness");
190
+ if (completenessRegression) {
191
+ regressions.push({
192
+ versionId,
193
+ metric: "completeness",
194
+ expectedValue: completenessRegression.expected,
195
+ actualValue: completenessRegression.actual,
196
+ deviation: completenessRegression.deviation,
197
+ severity: this.calculateSeverity(completenessRegression.deviation, "completeness"),
198
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
199
+ reason: `Completeness dropped from ${completenessRegression.expected.toFixed(1)} to ${completenessRegression.actual.toFixed(1)}`
200
+ });
201
+ }
202
+ const durations = metrics.map((m) => m.avgDuration);
203
+ const durationRegression = this.detectMetricRegression(durations, "duration");
204
+ if (durationRegression && durationRegression.deviation > 0) {
205
+ regressions.push({
206
+ versionId,
207
+ metric: "duration",
208
+ expectedValue: durationRegression.expected,
209
+ actualValue: durationRegression.actual,
210
+ deviation: durationRegression.deviation,
211
+ severity: this.calculateSeverity(durationRegression.deviation, "duration"),
212
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
213
+ reason: `Execution time increased from ${durationRegression.expected.toFixed(1)}s to ${durationRegression.actual.toFixed(1)}s`
214
+ });
215
+ }
216
+ return regressions;
217
+ }
218
+ /**
219
+ * Suggest optimizations based on performance analysis
220
+ *
221
+ * @param metrics Current performance metrics
222
+ * @param versionId Version being analyzed
223
+ * @param historicalMetrics Historical metrics for comparison
224
+ * @returns Array of actionable suggestions
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const suggestions = analytics.suggestOptimizations(
229
+ * currentMetrics,
230
+ * 'v2.0.0',
231
+ * historicalMetrics
232
+ * );
233
+ * suggestions.filter(s => s.priority === 'high').forEach(s => {
234
+ * console.log(`${s.description}`);
235
+ * s.actionItems.forEach(a => console.log(` - ${a}`));
236
+ * });
237
+ * ```
238
+ */
239
+ suggestOptimizations(metrics, _versionId, historicalMetrics) {
240
+ const suggestions = [];
241
+ if (metrics.successRate < 0.7) {
242
+ suggestions.push({
243
+ type: "success_improvement",
244
+ priority: metrics.successRate <= 0.5 ? "critical" : "high",
245
+ metric: "success_rate",
246
+ currentValue: metrics.successRate,
247
+ targetValue: 0.85,
248
+ description: `Success rate is low at ${(metrics.successRate * 100).toFixed(1)}%. Target 85%+ for production readiness.`,
249
+ actionItems: [
250
+ "Review prompt clarity and specificity",
251
+ "Add more context or examples",
252
+ "Check for ambiguous instructions",
253
+ "Consider testing with different prompt variants"
254
+ ],
255
+ estimatedImpact: (0.85 - metrics.successRate) * 100,
256
+ confidence: 0.75
257
+ });
258
+ }
259
+ if (metrics.stdDevCompleteness && metrics.stdDevCompleteness > 20) {
260
+ suggestions.push({
261
+ type: "consistency_improvement",
262
+ priority: metrics.stdDevCompleteness > 30 ? "high" : "medium",
263
+ metric: "completeness_variance",
264
+ currentValue: metrics.stdDevCompleteness,
265
+ targetValue: 10,
266
+ description: `Output quality is inconsistent (\u03C3=${metrics.stdDevCompleteness.toFixed(1)}). Improve consistency for reliable deployments.`,
267
+ actionItems: [
268
+ "Add structure requirements to prompt",
269
+ "Provide more specific examples",
270
+ "Define expected output format clearly",
271
+ "Test with variance-reducing prompt strategies"
272
+ ],
273
+ estimatedImpact: Math.min(15, metrics.stdDevCompleteness - 10),
274
+ confidence: 0.8
275
+ });
276
+ }
277
+ if (metrics.avgCompleteness < 70) {
278
+ suggestions.push({
279
+ type: "completeness_boost",
280
+ priority: metrics.avgCompleteness < 50 ? "critical" : "high",
281
+ metric: "avgCompleteness",
282
+ currentValue: metrics.avgCompleteness,
283
+ targetValue: 85,
284
+ description: `Output completeness is low at ${metrics.avgCompleteness.toFixed(1)}/100. Enhance prompt to get more thorough responses.`,
285
+ actionItems: [
286
+ "Ask for more detailed explanations",
287
+ "Request specific sections or components",
288
+ "Add quality criteria to the prompt",
289
+ "Include examples of desired output level"
290
+ ],
291
+ estimatedImpact: (85 - metrics.avgCompleteness) * 0.5,
292
+ confidence: 0.7
293
+ });
294
+ }
295
+ if (metrics.avgDuration > 120) {
296
+ suggestions.push({
297
+ type: "duration_optimization",
298
+ priority: metrics.avgDuration > 300 ? "high" : "medium",
299
+ metric: "avgDuration",
300
+ currentValue: metrics.avgDuration,
301
+ targetValue: 60,
302
+ description: `Execution takes ${metrics.avgDuration.toFixed(0)}s on average. Optimize for faster iterations.`,
303
+ actionItems: [
304
+ "Simplify prompt scope",
305
+ "Remove unnecessary examples",
306
+ "Use faster provider (check provider analytics)",
307
+ "Consider breaking into smaller prompts"
308
+ ],
309
+ estimatedImpact: (metrics.avgDuration - 60) / metrics.avgDuration * 50,
310
+ confidence: 0.65
311
+ });
312
+ }
313
+ if (historicalMetrics && historicalMetrics.length >= 3) {
314
+ const successTrend = this.detectTrend(historicalMetrics.map((m) => m.successRate));
315
+ const firstMetric = historicalMetrics[0];
316
+ if (successTrend.type === "improving" && successTrend.strength > 0.3 && firstMetric) {
317
+ const improvement = (metrics.successRate - firstMetric.successRate) * 100;
318
+ if (improvement > 3) {
319
+ suggestions.push({
320
+ type: "variant_activation",
321
+ priority: "medium",
322
+ metric: "trend",
323
+ currentValue: improvement,
324
+ targetValue: improvement * 1.5,
325
+ description: `This version shows consistent improvement (${improvement.toFixed(1)}% gain in success rate). Consider activating.`,
326
+ actionItems: [
327
+ "Review recent changes",
328
+ "Validate with additional test runs",
329
+ "Activate if confidence threshold met",
330
+ "Monitor post-activation for regressions"
331
+ ],
332
+ estimatedImpact: improvement,
333
+ confidence: successTrend.strength
334
+ });
335
+ }
336
+ }
337
+ }
338
+ const priorityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
339
+ suggestions.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
340
+ return suggestions;
341
+ }
342
+ /**
343
+ * Calculate trend using linear regression
344
+ *
345
+ * @param x X values (time indices)
346
+ * @param y Y values (metrics)
347
+ * @returns Slope, intercept, and R-squared
348
+ */
349
+ linearRegression(x, y) {
350
+ const n = x.length;
351
+ const sumX = x.reduce((a, b) => a + b, 0);
352
+ const sumY = y.reduce((a, b) => a + b, 0);
353
+ const sumXY = x.reduce((sum, xi, i) => sum + xi * (y[i] ?? 0), 0);
354
+ const sumXX = x.reduce((sum, xi) => sum + xi * xi, 0);
355
+ const sumYY = y.reduce((sum, yi) => sum + yi * yi, 0);
356
+ const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
357
+ const intercept = (sumY - slope * sumX) / n;
358
+ const meanY = sumY / n;
359
+ const ssTotal = sumYY - n * meanY * meanY;
360
+ const ssResidual = y.reduce((sum, yi, i) => {
361
+ const predicted = intercept + slope * (x[i] ?? 0);
362
+ return sum + (yi - predicted) ** 2;
363
+ }, 0);
364
+ const rSquared = ssTotal === 0 ? 0 : 1 - ssResidual / ssTotal;
365
+ return { slope, intercept, rSquared };
366
+ }
367
+ /**
368
+ * Detect regression in a metric
369
+ */
370
+ detectMetricRegression(metrics, metricType) {
371
+ if (metrics.length < 5) {
372
+ return null;
373
+ }
374
+ const cutoff = Math.floor(metrics.length * 0.8);
375
+ const baseline = metrics.slice(0, cutoff);
376
+ const recent = metrics.slice(cutoff);
377
+ const mean = baseline.reduce((a, b) => a + b, 0) / baseline.length;
378
+ const variance = baseline.reduce((sum, v) => sum + (v - mean) ** 2, 0) / baseline.length;
379
+ const stdDev = Math.sqrt(variance);
380
+ const recentMean = recent.reduce((a, b) => a + b, 0) / recent.length;
381
+ const zScore = Math.abs((recentMean - mean) / (stdDev || 1));
382
+ if (zScore >= this.REGRESSION_THRESHOLD) {
383
+ const deviation = metricType === "duration" ? (recentMean - mean) / mean * 100 : (mean - recentMean) / mean * 100;
384
+ return {
385
+ expected: mean,
386
+ actual: recentMean,
387
+ deviation
388
+ };
389
+ }
390
+ return null;
391
+ }
392
+ /**
393
+ * Calculate severity of regression
394
+ */
395
+ calculateSeverity(deviation, metricType) {
396
+ const absDeviation = Math.abs(deviation);
397
+ if (metricType === "duration") {
398
+ if (absDeviation > 50) return "critical";
399
+ if (absDeviation > 30) return "high";
400
+ if (absDeviation > 15) return "medium";
401
+ return "low";
402
+ } else {
403
+ if (absDeviation > 30) return "critical";
404
+ if (absDeviation > 20) return "high";
405
+ if (absDeviation > 10) return "medium";
406
+ return "low";
407
+ }
408
+ }
409
+ /**
410
+ * Aggregate metrics from multiple samples
411
+ *
412
+ * @param metrics Array of performance metrics
413
+ * @returns Aggregated metrics with statistics
414
+ */
415
+ aggregateMetrics(metrics) {
416
+ if (metrics.length === 0) {
417
+ return {
418
+ successRate: 0,
419
+ avgCompleteness: 0,
420
+ avgDuration: 0,
421
+ variance: 0,
422
+ consistency: 0,
423
+ sampleSize: 0,
424
+ compositeScore: 0,
425
+ trend: {
426
+ type: "insufficient_data",
427
+ strength: 0,
428
+ slope: 0,
429
+ direction: "flat",
430
+ lastNValues: []
431
+ }
432
+ };
433
+ }
434
+ const successRates = metrics.map((m) => m.successRate);
435
+ const completeness = metrics.map((m) => m.avgCompleteness);
436
+ const durations = metrics.map((m) => m.avgDuration);
437
+ const avgSuccessRate = successRates.reduce((a, b) => a + b, 0) / metrics.length;
438
+ const avgCompleteness = completeness.reduce((a, b) => a + b, 0) / metrics.length;
439
+ const avgDuration = durations.reduce((a, b) => a + b, 0) / metrics.length;
440
+ const variance = completeness.reduce((sum, v) => sum + (v - avgCompleteness) ** 2, 0) / metrics.length;
441
+ const stdDev = Math.sqrt(variance);
442
+ const coefficientOfVariation = stdDev / (avgCompleteness || 1);
443
+ const consistency = Math.max(0, 1 - coefficientOfVariation / 2);
444
+ const trend = this.detectTrend(completeness);
445
+ const compositeScore = avgSuccessRate * 40 + avgCompleteness / 100 * 40 + Math.max(0, 1 - avgDuration / 300) * 20;
446
+ return {
447
+ successRate: avgSuccessRate,
448
+ avgCompleteness,
449
+ avgDuration,
450
+ variance,
451
+ consistency: Math.max(0, Math.min(1, consistency)),
452
+ sampleSize: metrics.length,
453
+ compositeScore: Math.max(0, Math.min(100, compositeScore)),
454
+ trend
455
+ };
456
+ }
457
+ /**
458
+ * Score a version based on metrics
459
+ *
460
+ * @param metrics Performance metrics
461
+ * @returns Score from 0-100
462
+ *
463
+ * @example
464
+ * ```typescript
465
+ * const score = analytics.scoreVersion(metrics);
466
+ * console.log(`Version score: ${score.toFixed(1)}/100`);
467
+ * ```
468
+ */
469
+ scoreVersion(metrics) {
470
+ const successScore = metrics.successRate * 100 * 0.6;
471
+ const completenessScore = metrics.avgCompleteness * 0.25;
472
+ const durationScore = Math.max(0, 1 - metrics.avgDuration / 300) * 100 * 0.15;
473
+ const score = successScore + completenessScore + durationScore;
474
+ return Math.max(0, Math.min(100, score));
475
+ }
476
+ /**
477
+ * Identify outliers in metrics
478
+ *
479
+ * @param metrics Array of values
480
+ * @param threshold Z-score threshold (default 2.0)
481
+ * @returns Array of detected outliers
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * const values = [0.75, 0.76, 0.77, 0.2, 0.78]; // 0.2 is outlier
486
+ * const outliers = analytics.identifyOutliers(values);
487
+ * outliers.forEach(o => {
488
+ * console.log(`Value ${o.value} at index ${o.index} is an outlier`);
489
+ * });
490
+ * ```
491
+ */
492
+ identifyOutliers(metrics, threshold = 2) {
493
+ if (metrics.length < 3) {
494
+ return [];
495
+ }
496
+ const mean = metrics.reduce((a, b) => a + b, 0) / metrics.length;
497
+ const variance = metrics.reduce((sum, v) => sum + (v - mean) ** 2, 0) / metrics.length;
498
+ const stdDev = Math.sqrt(variance);
499
+ const outliers = [];
500
+ for (let i = 0; i < metrics.length; i++) {
501
+ const value = metrics[i];
502
+ if (value === void 0) continue;
503
+ const zscore = Math.abs((value - mean) / (stdDev || 1));
504
+ const isOutlier = zscore > threshold;
505
+ if (isOutlier) {
506
+ outliers.push({
507
+ index: i,
508
+ value,
509
+ expectedRange: [mean - 2 * stdDev, mean + 2 * stdDev],
510
+ zscore,
511
+ isOutlier: true
512
+ });
513
+ }
514
+ }
515
+ return outliers;
516
+ }
517
+ /**
518
+ * Calculate trend line for visualization
519
+ *
520
+ * @param metrics Array of metric values
521
+ * @returns Array of predicted values matching input length
522
+ */
523
+ calculateTrendLine(metrics) {
524
+ if (metrics.length < 2) {
525
+ return metrics;
526
+ }
527
+ const x = Array.from({ length: metrics.length }, (_, i) => i);
528
+ const { slope, intercept } = this.linearRegression(x, metrics);
529
+ return x.map((xi) => intercept + slope * xi);
530
+ }
531
+ };
532
+
533
+ // src/prompts/prompt-analytics.ts
534
+ var PromptAnalytics = class {
535
+ operations;
536
+ analyticsEngine;
537
+ constructor(operations) {
538
+ this.operations = operations;
539
+ this.analyticsEngine = new AnalyticsEngine();
540
+ }
541
+ /**
542
+ * Auto-tune a prompt by evaluating variants and activating if criteria met
543
+ *
544
+ * Evaluates variant candidates against current version and automatically
545
+ * activates the best performer if improvement meets configured threshold.
546
+ * Includes comprehensive safety checks to prevent bad activations.
547
+ *
548
+ * @param promptId ID of the prompt to auto-tune
549
+ * @param options Auto-tuning configuration
550
+ * @returns Auto-tuning result with decision and rationale
551
+ * @throws Error if prompt not found or auto-tuning fails
552
+ *
553
+ * @example
554
+ * ```ts
555
+ * const result = await analytics.autoTunePrompt('user-auth', {
556
+ * minSampleSize: 10,
557
+ * significanceThreshold: 10,
558
+ * enableAutoActivation: true,
559
+ * });
560
+ * console.log(`Auto-tuning: ${result.shouldAutoTune ? 'activated' : 'skipped'}`);
561
+ * if (result.selectedCandidate) {
562
+ * console.log(`Activated version: ${result.selectedCandidate}`);
563
+ * }
564
+ * ```
565
+ */
566
+ async autoTunePrompt(promptId, options) {
567
+ try {
568
+ this.operations.getOrThrow(promptId);
569
+ const currentVersion = this.operations.getActiveVersionOrThrow(promptId);
570
+ const versions = this.operations.listVersions(promptId);
571
+ const candidates = [];
572
+ for (const version of versions) {
573
+ const metrics = this.operations.getPerformance(version.id);
574
+ const score = metrics ? this.analyticsEngine.scoreVersion(metrics) : 0;
575
+ candidates.push({
576
+ versionId: version.id,
577
+ metrics,
578
+ score
579
+ });
580
+ }
581
+ const minSampleSize = options?.minSampleSize ?? 10;
582
+ const validCandidates = candidates.filter(
583
+ (c) => c.metrics && c.metrics.sampleSize >= minSampleSize
584
+ );
585
+ if (validCandidates.length === 0) {
586
+ return {
587
+ promptId,
588
+ versionId: currentVersion.id,
589
+ shouldAutoTune: false,
590
+ candidates: [],
591
+ reason: `No versions have sufficient sample size (need ${minSampleSize}+ samples)`,
592
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
593
+ };
594
+ }
595
+ const currentScore = candidates.find((c) => c.versionId === currentVersion.id)?.score ?? 0;
596
+ const bestCandidate = validCandidates.reduce(
597
+ (best, current) => current.score > best.score ? current : best
598
+ );
599
+ if (bestCandidate.versionId === currentVersion.id) {
600
+ return {
601
+ promptId,
602
+ versionId: currentVersion.id,
603
+ shouldAutoTune: false,
604
+ candidates: validCandidates.map((c) => ({
605
+ versionId: c.versionId,
606
+ improvementPercentage: 0,
607
+ confidence: 1
608
+ })),
609
+ reason: "Current version is already the best performer",
610
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
611
+ };
612
+ }
613
+ const improvementPercentage = currentScore > 0 ? (bestCandidate.score - currentScore) / currentScore * 100 : bestCandidate.score > 0 ? 100 : 0;
614
+ const significanceThreshold = options?.significanceThreshold ?? 10;
615
+ if (improvementPercentage < significanceThreshold) {
616
+ return {
617
+ promptId,
618
+ versionId: currentVersion.id,
619
+ shouldAutoTune: false,
620
+ candidates: validCandidates.map((c) => ({
621
+ versionId: c.versionId,
622
+ improvementPercentage: (c.score - currentScore) / currentScore * 100,
623
+ confidence: (c.metrics?.sampleSize ?? 0) / 100
624
+ })),
625
+ reason: `Improvement (${improvementPercentage.toFixed(1)}%) below threshold (${significanceThreshold}%)`,
626
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
627
+ };
628
+ }
629
+ const safetyChecks = [];
630
+ const currentMetrics = candidates.find((c) => c.versionId === currentVersion.id)?.metrics;
631
+ if (currentMetrics && bestCandidate.metrics) {
632
+ const successRateChange = (bestCandidate.metrics.successRate - currentMetrics.successRate) * 100;
633
+ safetyChecks.push({
634
+ check: "success_rate",
635
+ passed: successRateChange >= -5,
636
+ message: `Success rate change: ${successRateChange.toFixed(1)}%`
637
+ });
638
+ }
639
+ if (currentMetrics && bestCandidate.metrics) {
640
+ const completenessChange = bestCandidate.metrics.avgCompleteness - currentMetrics.avgCompleteness;
641
+ safetyChecks.push({
642
+ check: "completeness",
643
+ passed: completenessChange >= -10,
644
+ message: `Completeness change: ${completenessChange.toFixed(1)} points`
645
+ });
646
+ }
647
+ const allChecksPassed = safetyChecks.every((c) => c.passed);
648
+ if (!allChecksPassed) {
649
+ return {
650
+ promptId,
651
+ versionId: currentVersion.id,
652
+ shouldAutoTune: false,
653
+ candidates: validCandidates.map((c) => ({
654
+ versionId: c.versionId,
655
+ improvementPercentage: (c.score - currentScore) / currentScore * 100,
656
+ confidence: (c.metrics?.sampleSize ?? 0) / 100
657
+ })),
658
+ reason: `Safety checks failed: ${safetyChecks.filter((c) => !c.passed).map((c) => c.check).join(", ")}`,
659
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
660
+ };
661
+ }
662
+ const enableAutoActivation = options?.enableAutoActivation ?? false;
663
+ let shouldAutoTune = false;
664
+ let selectedCandidate;
665
+ if (enableAutoActivation) {
666
+ shouldAutoTune = true;
667
+ selectedCandidate = bestCandidate.versionId;
668
+ try {
669
+ await this.operations.activateVersion(bestCandidate.versionId, {
670
+ reason: `Auto-tuned: ${improvementPercentage.toFixed(1)}% improvement in composite score`
671
+ });
672
+ } catch (activateError) {
673
+ emitWarning(
674
+ "PR-001",
675
+ {
676
+ taskId: "prompt-analytics",
677
+ subsystem: "prompts",
678
+ executionPhase: "execution"
679
+ },
680
+ {
681
+ severity: "WARN" /* WARN */,
682
+ metadata: {
683
+ error: activateError.message,
684
+ operation: "autoActivateVersion",
685
+ versionId: bestCandidate.versionId,
686
+ promptId
687
+ }
688
+ }
689
+ );
690
+ shouldAutoTune = false;
691
+ selectedCandidate = void 0;
692
+ }
693
+ }
694
+ return {
695
+ promptId,
696
+ versionId: currentVersion.id,
697
+ shouldAutoTune,
698
+ candidates: validCandidates.map((c) => ({
699
+ versionId: c.versionId,
700
+ improvementPercentage: (c.score - currentScore) / currentScore * 100,
701
+ confidence: (c.metrics?.sampleSize ?? 0) / 100
702
+ })),
703
+ selectedCandidate,
704
+ reason: `Significant improvement (${improvementPercentage.toFixed(1)}%) meets activation criteria`,
705
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
706
+ };
707
+ } catch (error) {
708
+ throw new Error(`Failed to auto-tune prompt "${promptId}": ${error.message}`);
709
+ }
710
+ }
711
+ /**
712
+ * Monitor an auto-activated version for regressions
713
+ *
714
+ * Monitors recently activated versions for performance regressions and
715
+ * triggers rollback if necessary. Uses post-activation data to validate
716
+ * that the activation was beneficial.
717
+ *
718
+ * @param promptId ID of the prompt to monitor
719
+ * @param options Monitoring configuration
720
+ * @returns Monitoring result with status and details
721
+ * @throws Error if monitoring fails
722
+ *
723
+ * @example
724
+ * ```ts
725
+ * const result = await analytics.monitorAutoTuning('user-auth');
726
+ * if (result.regressionDetected) {
727
+ * console.log(`[REGRESSION] ${result.details}`);
728
+ * // Automatic rollback handled if needed
729
+ * } else {
730
+ * console.log(`[OK] Performance validated: ${result.details}`);
731
+ * }
732
+ * ```
733
+ */
734
+ async monitorAutoTuning(promptId, options) {
735
+ try {
736
+ this.operations.getOrThrow(promptId);
737
+ const currentVersion = this.operations.getActiveVersionOrThrow(promptId);
738
+ const allVersions = this.operations.listVersions(promptId);
739
+ const currentMetrics = this.operations.getPerformance(currentVersion.id);
740
+ if (!currentMetrics) {
741
+ return {
742
+ promptId,
743
+ versionId: currentVersion.id,
744
+ monitoringStatus: "validating",
745
+ samplesSinceActivation: 0,
746
+ performanceChange: 0,
747
+ regressionDetected: false,
748
+ details: "No performance data available yet",
749
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
750
+ };
751
+ }
752
+ const previousVersions = allVersions.filter((v) => v.id !== currentVersion.id).sort(
753
+ (a, b) => new Date(b.deactivatedAt || "").getTime() - new Date(a.deactivatedAt || "").getTime()
754
+ );
755
+ if (previousVersions.length === 0) {
756
+ return {
757
+ promptId,
758
+ versionId: currentVersion.id,
759
+ monitoringStatus: "validating",
760
+ samplesSinceActivation: currentMetrics.sampleSize,
761
+ performanceChange: 0,
762
+ regressionDetected: false,
763
+ details: "No previous version for comparison",
764
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
765
+ };
766
+ }
767
+ const previousMetrics = previousVersions[0] ? this.operations.getPerformance(previousVersions[0].id) : null;
768
+ if (!previousMetrics) {
769
+ return {
770
+ promptId,
771
+ versionId: currentVersion.id,
772
+ monitoringStatus: "validating",
773
+ samplesSinceActivation: currentMetrics.sampleSize,
774
+ performanceChange: 0,
775
+ regressionDetected: false,
776
+ details: "No performance data for previous version",
777
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
778
+ };
779
+ }
780
+ const minSamplesSinceActivation = options?.minSamplesSinceActivation ?? 5;
781
+ const samplesSinceActivation = currentMetrics.sampleSize - previousMetrics.sampleSize;
782
+ if (samplesSinceActivation < minSamplesSinceActivation) {
783
+ return {
784
+ promptId,
785
+ versionId: currentVersion.id,
786
+ monitoringStatus: "validating",
787
+ samplesSinceActivation,
788
+ performanceChange: 0,
789
+ regressionDetected: false,
790
+ details: `Still collecting data (${samplesSinceActivation}/${minSamplesSinceActivation} samples)`,
791
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
792
+ };
793
+ }
794
+ const currentScore = this.analyticsEngine.scoreVersion(currentMetrics);
795
+ const previousScore = this.analyticsEngine.scoreVersion(previousMetrics);
796
+ const performanceChange = (currentScore - previousScore) / previousScore * 100;
797
+ let regressionDetected = false;
798
+ let details = "";
799
+ if (performanceChange < -15) {
800
+ regressionDetected = true;
801
+ details = `Significant regression detected (${performanceChange.toFixed(1)}% worse than previous version). Consider rollback.`;
802
+ try {
803
+ await this.operations.rollbackVersion(promptId);
804
+ details += " Automatic rollback performed.";
805
+ } catch (rollbackError) {
806
+ details += ` Rollback failed: ${rollbackError.message}`;
807
+ }
808
+ return {
809
+ promptId,
810
+ versionId: currentVersion.id,
811
+ monitoringStatus: "needs_rollback",
812
+ samplesSinceActivation,
813
+ performanceChange,
814
+ regressionDetected,
815
+ details,
816
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
817
+ };
818
+ } else if (performanceChange >= -5) {
819
+ details = `Performance validated (${performanceChange >= 0 ? "+" : ""}${performanceChange.toFixed(1)}%). Version performing as expected.`;
820
+ return {
821
+ promptId,
822
+ versionId: currentVersion.id,
823
+ monitoringStatus: "validated",
824
+ samplesSinceActivation,
825
+ performanceChange,
826
+ regressionDetected: false,
827
+ details,
828
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
829
+ };
830
+ } else {
831
+ details = `Minor deviation (${performanceChange.toFixed(1)}%). Continuing to monitor.`;
832
+ return {
833
+ promptId,
834
+ versionId: currentVersion.id,
835
+ monitoringStatus: "validating",
836
+ samplesSinceActivation,
837
+ performanceChange,
838
+ regressionDetected: false,
839
+ details,
840
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
841
+ };
842
+ }
843
+ } catch (error) {
844
+ throw new Error(
845
+ `Failed to monitor auto-tuning for "${promptId}": ${error.message}`
846
+ );
847
+ }
848
+ }
849
+ /**
850
+ * Get performance analysis for a prompt
851
+ *
852
+ * Analyzes performance metrics and detects trends, regressions, and
853
+ * optimization opportunities. Returns comprehensive analytics including
854
+ * trend detection, forecasting, and suggestions.
855
+ *
856
+ * @param promptId ID of the prompt to analyze
857
+ * @param versionId Optional specific version to analyze
858
+ * @returns Analysis including trends, regressions, and suggestions
859
+ * @throws Error if analysis fails
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * const analysis = await analytics.analyzePerformance('user-auth');
864
+ * console.log(`Trend: ${analysis.trend.type}`);
865
+ * analysis.suggestions.forEach(s => {
866
+ * console.log(`[${s.priority}] ${s.description}`);
867
+ * });
868
+ * ```
869
+ */
870
+ async analyzePerformance(promptId, versionId) {
871
+ try {
872
+ const prompt = this.operations.getOrThrow(promptId);
873
+ let metrics;
874
+ if (versionId) {
875
+ metrics = this.operations.getPerformance(versionId);
876
+ } else {
877
+ const activeVersion = this.operations.getActiveVersion(promptId);
878
+ metrics = activeVersion ? this.operations.getPerformance(activeVersion.id) : null;
879
+ }
880
+ if (!metrics) {
881
+ throw new Error("No performance data available for analysis");
882
+ }
883
+ const allVersions = this.operations.listVersions(promptId);
884
+ const allMetrics = [];
885
+ for (const version of allVersions) {
886
+ const m = this.operations.getPerformance(version.id);
887
+ if (m) {
888
+ allMetrics.push(m);
889
+ }
890
+ }
891
+ const completenessValues = allMetrics.map((m) => m.avgCompleteness);
892
+ const trend = this.analyticsEngine.detectTrend(completenessValues);
893
+ const detectedRegressions = this.analyticsEngine.detectRegressions(
894
+ allMetrics,
895
+ versionId || metrics.versionId
896
+ );
897
+ const suggestions = this.analyticsEngine.suggestOptimizations(
898
+ metrics,
899
+ versionId || metrics.versionId,
900
+ allMetrics.length > 1 ? allMetrics : void 0
901
+ );
902
+ return {
903
+ prompt,
904
+ trend,
905
+ regressions: detectedRegressions.map((r) => ({
906
+ metric: r.metric,
907
+ severity: r.severity,
908
+ details: r.reason
909
+ })),
910
+ suggestions,
911
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
912
+ };
913
+ } catch (error) {
914
+ throw new Error(
915
+ `Failed to analyze performance for "${promptId}": ${error.message}`
916
+ );
917
+ }
918
+ }
919
+ /**
920
+ * Get performance trend for a prompt
921
+ *
922
+ * @param promptId ID of the prompt
923
+ * @param versionId Optional specific version
924
+ * @returns Trend analysis
925
+ *
926
+ * @example
927
+ * ```ts
928
+ * const trend = await analytics.getPerformanceTrend('user-auth');
929
+ * console.log(`Status: ${trend.type} (strength: ${trend.strength})`);
930
+ * ```
931
+ */
932
+ async getPerformanceTrend(promptId, _versionId) {
933
+ try {
934
+ const allVersions = this.operations.listVersions(promptId);
935
+ const metrics = [];
936
+ for (const version of allVersions) {
937
+ const m = this.operations.getPerformance(version.id);
938
+ if (m) {
939
+ metrics.push(m);
940
+ }
941
+ }
942
+ if (metrics.length === 0) {
943
+ return {
944
+ type: "insufficient_data",
945
+ strength: 0,
946
+ slope: 0,
947
+ direction: "flat",
948
+ lastNValues: []
949
+ };
950
+ }
951
+ const completenessValues = metrics.map((m) => m.avgCompleteness);
952
+ return this.analyticsEngine.detectTrend(completenessValues);
953
+ } catch (error) {
954
+ throw new Error(`Failed to get trend for "${promptId}": ${error.message}`);
955
+ }
956
+ }
957
+ /**
958
+ * Get optimization suggestions for a prompt
959
+ *
960
+ * @param promptId ID of the prompt
961
+ * @returns Array of actionable suggestions
962
+ *
963
+ * @example
964
+ * ```ts
965
+ * const suggestions = await analytics.getSuggestions('user-auth');
966
+ * suggestions.filter(s => s.priority === 'critical').forEach(s => {
967
+ * console.log(`ACTION: ${s.description}`);
968
+ * });
969
+ * ```
970
+ */
971
+ async getSuggestions(promptId) {
972
+ try {
973
+ const activeVersion = this.operations.getActiveVersionOrThrow(promptId);
974
+ const metrics = this.operations.getPerformance(activeVersion.id);
975
+ if (!metrics) {
976
+ return [];
977
+ }
978
+ const allVersions = this.operations.listVersions(promptId);
979
+ const allMetrics = [];
980
+ for (const version of allVersions) {
981
+ const m = this.operations.getPerformance(version.id);
982
+ if (m) {
983
+ allMetrics.push(m);
984
+ }
985
+ }
986
+ return this.analyticsEngine.suggestOptimizations(
987
+ metrics,
988
+ activeVersion.id,
989
+ allMetrics.length > 1 ? allMetrics : void 0
990
+ );
991
+ } catch (error) {
992
+ throw new Error(`Failed to get suggestions for "${promptId}": ${error.message}`);
993
+ }
994
+ }
995
+ };
996
+
997
+ // src/prompts/variant-generator.ts
998
+ var VariantGenerator = class {
999
+ /**
1000
+ * Generate variants for A/B testing
1001
+ */
1002
+ async generateVariants(basePrompt, count = 3, _options) {
1003
+ const { strategies, targetMetric = "balanced" } = _options || {};
1004
+ const selectedStrategies = strategies || this.selectOptimalStrategies(targetMetric, count);
1005
+ const variants = [];
1006
+ for (const strategy of selectedStrategies) {
1007
+ const variant = await this.generateVariant(basePrompt, strategy);
1008
+ variants.push(variant);
1009
+ }
1010
+ return variants;
1011
+ }
1012
+ /**
1013
+ * Generate single variant using mutation strategy
1014
+ */
1015
+ async generateVariant(basePrompt, strategy) {
1016
+ const content = basePrompt.content;
1017
+ const mutations = [];
1018
+ let mutatedContent = content;
1019
+ switch (strategy) {
1020
+ case "clarity":
1021
+ mutatedContent = this.improveClarity(content, mutations);
1022
+ break;
1023
+ case "conciseness":
1024
+ mutatedContent = this.improveConciseness(content, mutations);
1025
+ break;
1026
+ case "context":
1027
+ mutatedContent = this.addContext(content, mutations);
1028
+ break;
1029
+ case "examples":
1030
+ mutatedContent = this.addExamples(content, mutations);
1031
+ break;
1032
+ case "structure":
1033
+ mutatedContent = this.improveStructure(content, mutations);
1034
+ break;
1035
+ case "constraints":
1036
+ mutatedContent = this.addConstraints(content, mutations);
1037
+ break;
1038
+ case "tone":
1039
+ mutatedContent = this.adjustTone(content, mutations);
1040
+ break;
1041
+ case "hybrid":
1042
+ mutatedContent = this.hybridMutation(content, mutations);
1043
+ break;
1044
+ }
1045
+ return {
1046
+ content: mutatedContent,
1047
+ mutations,
1048
+ expectedImprovement: this.predictImprovement(strategy),
1049
+ testHypothesis: this.generateHypothesis(strategy),
1050
+ confidence: this.estimateConfidence(strategy, mutations.length)
1051
+ };
1052
+ }
1053
+ /**
1054
+ * Close resources
1055
+ */
1056
+ close() {
1057
+ }
1058
+ // Private methods
1059
+ selectOptimalStrategies(targetMetric, count) {
1060
+ const strategyMap = {
1061
+ success_rate: ["clarity", "examples", "structure"],
1062
+ completeness: ["context", "constraints", "examples"],
1063
+ duration: ["conciseness", "clarity", "structure"],
1064
+ balanced: ["clarity", "context", "structure", "examples", "hybrid"]
1065
+ };
1066
+ const strategies = strategyMap[targetMetric] || strategyMap.balanced;
1067
+ const finalStrategies = strategies || ["clarity", "context", "structure", "examples", "hybrid"];
1068
+ return finalStrategies.slice(0, count);
1069
+ }
1070
+ improveClarity(content, mutations) {
1071
+ let result = content;
1072
+ if (!result.includes("specific")) {
1073
+ const insertion = "\n\nBe specific and explicit in your implementation.";
1074
+ result = result + insertion;
1075
+ mutations.push({
1076
+ strategy: "clarity",
1077
+ description: "Add specificity instruction",
1078
+ before: content,
1079
+ after: insertion,
1080
+ rationale: "Explicit instructions reduce ambiguity"
1081
+ });
1082
+ }
1083
+ if (!result.match(/step|1\.|first/i)) {
1084
+ const insertion = "\n\nSteps:\n1. Analyze requirements\n2. Plan implementation\n3. Write code\n4. Test solution";
1085
+ result = result + insertion;
1086
+ mutations.push({
1087
+ strategy: "clarity",
1088
+ description: "Add step-by-step breakdown",
1089
+ before: content,
1090
+ after: insertion,
1091
+ rationale: "Step-by-step improves success rate"
1092
+ });
1093
+ }
1094
+ return result;
1095
+ }
1096
+ improveConciseness(content, mutations) {
1097
+ let result = content;
1098
+ const redundantPhrases = [
1099
+ /please note that /gi,
1100
+ /it is important to /gi,
1101
+ /you should make sure to /gi
1102
+ ];
1103
+ for (const pattern of redundantPhrases) {
1104
+ if (pattern.test(result)) {
1105
+ const before = result;
1106
+ result = result.replace(pattern, "");
1107
+ mutations.push({
1108
+ strategy: "conciseness",
1109
+ description: "Remove redundant phrase",
1110
+ before,
1111
+ after: result,
1112
+ rationale: "Concise prompts reduce cognitive load"
1113
+ });
1114
+ }
1115
+ }
1116
+ return result;
1117
+ }
1118
+ addContext(content, mutations) {
1119
+ let result = content;
1120
+ if (!result.match(/context|background/i)) {
1121
+ const insertion = "\n\nContext: Consider existing codebase patterns and maintain consistency.";
1122
+ result = result + insertion;
1123
+ mutations.push({
1124
+ strategy: "context",
1125
+ description: "Add background context",
1126
+ before: content,
1127
+ after: insertion,
1128
+ rationale: "Context helps AI make better decisions"
1129
+ });
1130
+ }
1131
+ if (!result.match(/success|criteria/i)) {
1132
+ const insertion = "\n\nSuccess criteria:\n- All tests pass\n- Code follows conventions\n- Complete implementation";
1133
+ result = result + insertion;
1134
+ mutations.push({
1135
+ strategy: "context",
1136
+ description: "Add success criteria",
1137
+ before: content,
1138
+ after: insertion,
1139
+ rationale: "Clear criteria improve completeness"
1140
+ });
1141
+ }
1142
+ return result;
1143
+ }
1144
+ addExamples(content, mutations) {
1145
+ let result = content;
1146
+ if (!result.match(/example|for instance/i)) {
1147
+ const insertion = "\n\nExample:\n```text\n1. Validate inputs at the boundary\n2. Apply the core change following existing patterns\n3. Return or report the result explicitly\n```";
1148
+ result = result + insertion;
1149
+ mutations.push({
1150
+ strategy: "examples",
1151
+ description: "Add illustrative example outline",
1152
+ before: content,
1153
+ after: insertion,
1154
+ rationale: "Examples clarify expected output"
1155
+ });
1156
+ }
1157
+ return result;
1158
+ }
1159
+ improveStructure(content, mutations) {
1160
+ let result = content;
1161
+ if (!result.match(/^#{1,3} /m)) {
1162
+ const lines = result.split("\n");
1163
+ const sections = [
1164
+ "## Objective",
1165
+ lines[0],
1166
+ "\n## Requirements",
1167
+ ...lines.slice(1, 3),
1168
+ "\n## Implementation",
1169
+ ...lines.slice(3)
1170
+ ].join("\n");
1171
+ mutations.push({
1172
+ strategy: "structure",
1173
+ description: "Add section headers",
1174
+ before: content,
1175
+ after: sections,
1176
+ rationale: "Structure improves comprehension"
1177
+ });
1178
+ result = sections;
1179
+ }
1180
+ return result;
1181
+ }
1182
+ addConstraints(content, mutations) {
1183
+ let result = content;
1184
+ if (!result.match(/constraint|must/i)) {
1185
+ const insertion = "\n\nConstraints:\n- Respect the project's type system and compiler/linter settings\n- Follow existing patterns\n- Include error handling";
1186
+ result = result + insertion;
1187
+ mutations.push({
1188
+ strategy: "constraints",
1189
+ description: "Add technical constraints",
1190
+ before: content,
1191
+ after: insertion,
1192
+ rationale: "Constraints guide implementation quality"
1193
+ });
1194
+ }
1195
+ return result;
1196
+ }
1197
+ adjustTone(content, mutations) {
1198
+ let result = content;
1199
+ const passivePatterns = [
1200
+ { pattern: /you could /gi, replacement: "You must " },
1201
+ { pattern: /might want to /gi, replacement: "Should " }
1202
+ ];
1203
+ for (const { pattern, replacement } of passivePatterns) {
1204
+ if (pattern.test(result)) {
1205
+ const before = result;
1206
+ result = result.replace(pattern, replacement);
1207
+ mutations.push({
1208
+ strategy: "tone",
1209
+ description: "Make more directive",
1210
+ before,
1211
+ after: result,
1212
+ rationale: "Directive tone improves completion"
1213
+ });
1214
+ }
1215
+ }
1216
+ return result;
1217
+ }
1218
+ hybridMutation(content, mutations) {
1219
+ let result = content;
1220
+ result = this.improveClarity(result, mutations);
1221
+ result = this.addContext(result, mutations);
1222
+ result = this.improveStructure(result, mutations);
1223
+ return result;
1224
+ }
1225
+ predictImprovement(strategy) {
1226
+ const predictions = {
1227
+ clarity: "10-15% improvement in success rate",
1228
+ conciseness: "5-10% faster execution",
1229
+ context: "15-20% better completeness",
1230
+ examples: "20-25% higher success rate",
1231
+ structure: "10-15% better comprehension",
1232
+ constraints: "15-20% higher code quality",
1233
+ tone: "5-10% better task completion",
1234
+ hybrid: "15-25% overall improvement"
1235
+ };
1236
+ return predictions[strategy];
1237
+ }
1238
+ generateHypothesis(strategy) {
1239
+ const hypotheses = {
1240
+ clarity: "Clearer instructions reduce ambiguity",
1241
+ conciseness: "Concise prompts reduce execution time",
1242
+ context: "Additional context improves quality",
1243
+ examples: "Examples clarify expectations",
1244
+ structure: "Better structure improves comprehension",
1245
+ constraints: "Constraints guide implementation",
1246
+ tone: "Directive tone improves completion",
1247
+ hybrid: "Combined improvements optimize multiple metrics"
1248
+ };
1249
+ return hypotheses[strategy];
1250
+ }
1251
+ estimateConfidence(strategy, mutationCount) {
1252
+ const strategyConfidence = {
1253
+ clarity: 0.85,
1254
+ conciseness: 0.7,
1255
+ context: 0.8,
1256
+ examples: 0.9,
1257
+ structure: 0.75,
1258
+ constraints: 0.8,
1259
+ tone: 0.65,
1260
+ hybrid: 0.75
1261
+ };
1262
+ const base = strategyConfidence[strategy];
1263
+ const mutationBonus = Math.min(mutationCount * 0.05, 0.15);
1264
+ return Math.min(base + mutationBonus, 0.95);
1265
+ }
1266
+ };
1267
+
1268
+ // src/prompts/prompt-operations.ts
1269
+ var PromptOperations = class {
1270
+ store;
1271
+ constructor(options = {}) {
1272
+ this.store = new PromptStore(options);
1273
+ }
1274
+ /**
1275
+ * Get the underlying store instance
1276
+ */
1277
+ getStore() {
1278
+ return this.store;
1279
+ }
1280
+ /**
1281
+ * Create a new prompt with optional initial version
1282
+ */
1283
+ async create(options) {
1284
+ try {
1285
+ const prompt = await this.store.createPrompt({
1286
+ id: options.id,
1287
+ name: options.name,
1288
+ description: options.description,
1289
+ category: options.category,
1290
+ variant: options.variant,
1291
+ tags: options.tags || [],
1292
+ autoOptimize: options.autoOptimize ?? false
1293
+ });
1294
+ let version;
1295
+ if (options.initialContent !== void 0 && options.initialContent !== null) {
1296
+ const versionId = options.initialVersion || "v1.0.0";
1297
+ version = await this.store.createVersion(options.id, versionId, options.initialContent, {
1298
+ changelog: "Initial version",
1299
+ author: options.author,
1300
+ activate: true
1301
+ });
1302
+ }
1303
+ return { prompt, version };
1304
+ } catch (error) {
1305
+ throw new Error(`Failed to create prompt "${options.id}": ${error.message}`);
1306
+ }
1307
+ }
1308
+ /**
1309
+ * Get a prompt by ID
1310
+ */
1311
+ get(id) {
1312
+ try {
1313
+ return this.store.getPrompt(id);
1314
+ } catch (error) {
1315
+ throw new Error(`Failed to get prompt "${id}": ${error.message}`);
1316
+ }
1317
+ }
1318
+ /**
1319
+ * Get a prompt by ID, throwing if not found
1320
+ */
1321
+ getOrThrow(id) {
1322
+ const prompt = this.get(id);
1323
+ if (!prompt) {
1324
+ throw new Error(`Prompt with ID "${id}" not found`);
1325
+ }
1326
+ return prompt;
1327
+ }
1328
+ /**
1329
+ * Update a prompt
1330
+ */
1331
+ async update(id, options) {
1332
+ const result = await this.store.updatePrompt(id, options);
1333
+ if (!result) {
1334
+ throw new Error("Failed to update prompt");
1335
+ }
1336
+ return result;
1337
+ }
1338
+ /**
1339
+ * Delete a prompt and all its versions
1340
+ */
1341
+ async delete(id) {
1342
+ const result = this.store.deletePrompt(id);
1343
+ if (!result) {
1344
+ throw new Error("Failed to delete prompt");
1345
+ }
1346
+ }
1347
+ /**
1348
+ * Archive a prompt
1349
+ */
1350
+ async archive(id) {
1351
+ return this.update(id, { status: "archived" });
1352
+ }
1353
+ /**
1354
+ * Restore an archived prompt
1355
+ */
1356
+ async restore(id) {
1357
+ return this.update(id, { status: "active" });
1358
+ }
1359
+ /**
1360
+ * List prompts with optional filtering
1361
+ */
1362
+ list(criteria) {
1363
+ try {
1364
+ return this.store.listPrompts(criteria);
1365
+ } catch (error) {
1366
+ throw new Error(`Failed to list prompts: ${error.message}`);
1367
+ }
1368
+ }
1369
+ /**
1370
+ * Search prompts by query string
1371
+ */
1372
+ search(query, options) {
1373
+ return this.list({ ...options, query });
1374
+ }
1375
+ /**
1376
+ * Create a new version for a prompt
1377
+ */
1378
+ async createVersion(options) {
1379
+ try {
1380
+ let versionId = options.version;
1381
+ if (!versionId) {
1382
+ versionId = await this.getNextVersion(options.promptId);
1383
+ }
1384
+ return await this.store.createVersion(options.promptId, versionId, options.content, {
1385
+ changelog: options.changelog,
1386
+ author: options.author,
1387
+ activate: options.activate !== false,
1388
+ // Default to true
1389
+ isGenerated: options.isGenerated,
1390
+ generationModel: options.generationModel,
1391
+ generationPrompt: options.generationPrompt
1392
+ });
1393
+ } catch (error) {
1394
+ throw new Error(
1395
+ `Failed to create version for prompt "${options.promptId}": ${error.message}`
1396
+ );
1397
+ }
1398
+ }
1399
+ getVersion(idOrPromptId, versionId) {
1400
+ try {
1401
+ if (versionId === void 0) {
1402
+ return this.store.getVersion(idOrPromptId);
1403
+ }
1404
+ return this.store.getVersion(idOrPromptId, versionId);
1405
+ } catch (error) {
1406
+ const errorMsg = versionId ? `Failed to get version "${versionId}" for prompt "${idOrPromptId}"` : `Failed to get version "${idOrPromptId}"`;
1407
+ throw new Error(`${errorMsg}: ${error.message}`);
1408
+ }
1409
+ }
1410
+ /**
1411
+ * Get active version for a prompt
1412
+ */
1413
+ getActiveVersion(promptId) {
1414
+ try {
1415
+ return this.store.getActiveVersion(promptId);
1416
+ } catch (error) {
1417
+ throw new Error(
1418
+ `Failed to get active version for prompt "${promptId}": ${error.message}`
1419
+ );
1420
+ }
1421
+ }
1422
+ /**
1423
+ * Get active version, throwing if not found
1424
+ */
1425
+ getActiveVersionOrThrow(promptId) {
1426
+ const version = this.getActiveVersion(promptId);
1427
+ if (!version) {
1428
+ throw new Error(`No active version found for prompt "${promptId}"`);
1429
+ }
1430
+ return version;
1431
+ }
1432
+ /**
1433
+ * List all versions for a prompt
1434
+ */
1435
+ listVersions(promptId) {
1436
+ try {
1437
+ return this.store.listVersions(promptId);
1438
+ } catch (error) {
1439
+ throw new Error(
1440
+ `Failed to list versions for prompt "${promptId}": ${error.message}`
1441
+ );
1442
+ }
1443
+ }
1444
+ /**
1445
+ * Deactivate a version
1446
+ */
1447
+ async deactivateVersion(versionId) {
1448
+ try {
1449
+ await this.store.deactivateVersion(versionId);
1450
+ } catch (error) {
1451
+ throw new Error(`Failed to deactivate version "${versionId}": ${error.message}`);
1452
+ }
1453
+ }
1454
+ /**
1455
+ * Get performance metrics for a version
1456
+ */
1457
+ getPerformance(versionId, variant) {
1458
+ try {
1459
+ return this.store.getPerformanceMetrics(versionId, variant);
1460
+ } catch (error) {
1461
+ throw new Error(
1462
+ `Failed to get performance metrics for version "${versionId}": ${error.message}`
1463
+ );
1464
+ }
1465
+ }
1466
+ /**
1467
+ * Increment usage count when a prompt is used
1468
+ */
1469
+ recordUsage(promptId) {
1470
+ try {
1471
+ this.store.incrementUsage(promptId);
1472
+ } catch (error) {
1473
+ emitWarning(
1474
+ "CFG-002",
1475
+ {
1476
+ taskId: "prompt-operations",
1477
+ subsystem: "prompts",
1478
+ executionPhase: "execution"
1479
+ },
1480
+ {
1481
+ severity: "INFO" /* INFO */,
1482
+ metadata: {
1483
+ error: error.message,
1484
+ operation: "recordUsage",
1485
+ promptId
1486
+ }
1487
+ }
1488
+ );
1489
+ }
1490
+ }
1491
+ /**
1492
+ * Batch increment usage counts for multiple prompts
1493
+ * More efficient than calling recordUsage multiple times (prevents N+1 queries)
1494
+ */
1495
+ recordUsageBatch(promptIds) {
1496
+ if (promptIds.length === 0) {
1497
+ return;
1498
+ }
1499
+ try {
1500
+ this.store.incrementUsageBatch(promptIds);
1501
+ } catch (error) {
1502
+ emitWarning(
1503
+ "CFG-002",
1504
+ {
1505
+ taskId: "prompt-operations",
1506
+ subsystem: "prompts",
1507
+ executionPhase: "execution"
1508
+ },
1509
+ {
1510
+ severity: "INFO" /* INFO */,
1511
+ metadata: {
1512
+ error: error.message,
1513
+ operation: "recordUsageBatch",
1514
+ promptCount: promptIds.length
1515
+ }
1516
+ }
1517
+ );
1518
+ }
1519
+ }
1520
+ /**
1521
+ * Compare two prompts or versions
1522
+ */
1523
+ async compare(promptIdA, promptIdB, versionIdA, versionIdB) {
1524
+ try {
1525
+ const promptA = this.getOrThrow(promptIdA);
1526
+ const promptB = this.getOrThrow(promptIdB);
1527
+ const versionA = versionIdA ? this.store.getVersion(promptIdA, versionIdA) : this.getActiveVersion(promptIdA);
1528
+ const versionB = versionIdB ? this.store.getVersion(promptIdB, versionIdB) : this.getActiveVersion(promptIdB);
1529
+ if (!versionA || !versionB) {
1530
+ throw new Error("One or both versions not found");
1531
+ }
1532
+ const metricsA = this.store.getPerformanceMetrics(versionA.id);
1533
+ const metricsB = this.store.getPerformanceMetrics(versionB.id);
1534
+ const lengthDelta = versionB.content.length - versionA.content.length;
1535
+ const wordCountA = versionA.content.split(/\s+/).length;
1536
+ const wordCountB = versionB.content.split(/\s+/).length;
1537
+ const wordCountDelta = wordCountB - wordCountA;
1538
+ const contentDiff = this.generateDiff(versionA.content, versionB.content);
1539
+ let performanceComparison;
1540
+ if (metricsA && metricsB) {
1541
+ const successRateDelta = metricsB.successRate - metricsA.successRate;
1542
+ const completenessDelta = metricsB.avgCompleteness - metricsA.avgCompleteness;
1543
+ const durationDelta = metricsB.avgDuration - metricsA.avgDuration;
1544
+ let recommendation;
1545
+ let rationale;
1546
+ if (metricsA.sampleSize < 10 || metricsB.sampleSize < 10) {
1547
+ recommendation = "test_more";
1548
+ rationale = "Insufficient data for confident recommendation (need 10+ samples)";
1549
+ } else if (successRateDelta > 0.1 && completenessDelta > 5) {
1550
+ recommendation = "use_b";
1551
+ rationale = `Version B shows significantly better performance (+${(successRateDelta * 100).toFixed(1)}% success rate, +${completenessDelta.toFixed(1)} completeness)`;
1552
+ } else if (successRateDelta < -0.1 && completenessDelta < -5) {
1553
+ recommendation = "use_a";
1554
+ rationale = `Version A shows significantly better performance (+${Math.abs(successRateDelta * 100).toFixed(1)}% success rate, +${Math.abs(completenessDelta).toFixed(1)} completeness)`;
1555
+ } else if (Math.abs(successRateDelta) < 0.05 && Math.abs(completenessDelta) < 3) {
1556
+ recommendation = "combine";
1557
+ rationale = "Performance is similar - consider combining best aspects of both";
1558
+ } else {
1559
+ recommendation = "test_more";
1560
+ rationale = "Results are mixed - need more data for clear recommendation";
1561
+ }
1562
+ performanceComparison = {
1563
+ successRateDelta,
1564
+ completenessDelta,
1565
+ durationDelta,
1566
+ recommendation,
1567
+ rationale
1568
+ };
1569
+ }
1570
+ return {
1571
+ promptA,
1572
+ promptB,
1573
+ versionA,
1574
+ versionB,
1575
+ metricsA: metricsA || void 0,
1576
+ metricsB: metricsB || void 0,
1577
+ differences: {
1578
+ contentDiff,
1579
+ lengthDelta,
1580
+ wordCountDelta
1581
+ },
1582
+ performanceComparison
1583
+ };
1584
+ } catch (error) {
1585
+ throw new Error(`Failed to compare prompts: ${error.message}`);
1586
+ }
1587
+ }
1588
+ /**
1589
+ * Clone a prompt with a new ID
1590
+ */
1591
+ async clone(sourceId, newId, newName, options) {
1592
+ try {
1593
+ const source = this.getOrThrow(sourceId);
1594
+ const activeVersion = this.getActiveVersion(sourceId);
1595
+ if (!activeVersion) {
1596
+ throw new Error("Source prompt has no active version");
1597
+ }
1598
+ const result = await this.create({
1599
+ id: newId,
1600
+ name: newName,
1601
+ description: `${source.description} (cloned from ${sourceId})`,
1602
+ category: source.category,
1603
+ variant: source.variant,
1604
+ tags: [...source.tags, "cloned"],
1605
+ initialContent: activeVersion.content,
1606
+ initialVersion: activeVersion.id,
1607
+ author: options?.author
1608
+ });
1609
+ if (options?.cloneVersions) {
1610
+ const versions = this.listVersions(sourceId);
1611
+ const existingVersionIds = /* @__PURE__ */ new Set([result.version?.id || activeVersion.id]);
1612
+ for (const version of versions) {
1613
+ if (version.id !== activeVersion.id && !existingVersionIds.has(version.id)) {
1614
+ await this.store.createVersion(newId, version.id, version.content, {
1615
+ changelog: version.changelog,
1616
+ author: options?.author,
1617
+ activate: false
1618
+ });
1619
+ existingVersionIds.add(version.id);
1620
+ }
1621
+ }
1622
+ }
1623
+ return result;
1624
+ } catch (error) {
1625
+ throw new Error(`Failed to clone prompt "${sourceId}": ${error.message}`);
1626
+ }
1627
+ }
1628
+ /**
1629
+ * Batch archive multiple prompts
1630
+ */
1631
+ async archiveBatch(ids) {
1632
+ const result = {
1633
+ total: ids.length,
1634
+ successful: 0,
1635
+ failed: 0,
1636
+ errors: []
1637
+ };
1638
+ for (const id of ids) {
1639
+ try {
1640
+ await this.archive(id);
1641
+ result.successful++;
1642
+ } catch (error) {
1643
+ result.failed++;
1644
+ result.errors.push({
1645
+ promptId: id,
1646
+ _error: error.message
1647
+ });
1648
+ }
1649
+ }
1650
+ return result;
1651
+ }
1652
+ /**
1653
+ * Batch delete multiple prompts
1654
+ */
1655
+ async deleteBatch(ids) {
1656
+ const result = {
1657
+ total: ids.length,
1658
+ successful: 0,
1659
+ failed: 0,
1660
+ errors: []
1661
+ };
1662
+ for (const id of ids) {
1663
+ try {
1664
+ await this.delete(id);
1665
+ result.successful++;
1666
+ } catch (error) {
1667
+ result.failed++;
1668
+ result.errors.push({
1669
+ promptId: id,
1670
+ _error: error.message
1671
+ });
1672
+ }
1673
+ }
1674
+ return result;
1675
+ }
1676
+ /**
1677
+ * Get statistics for all prompts
1678
+ */
1679
+ getStatistics() {
1680
+ try {
1681
+ const prompts = this.list();
1682
+ const byStatus = {};
1683
+ const byCategory = {};
1684
+ let totalVersions = 0;
1685
+ let totalUsage = 0;
1686
+ for (const prompt of prompts) {
1687
+ byStatus[prompt.status] = (byStatus[prompt.status] || 0) + 1;
1688
+ byCategory[prompt.category] = (byCategory[prompt.category] || 0) + 1;
1689
+ totalVersions += this.listVersions(prompt.id).length;
1690
+ totalUsage += prompt.usageCount;
1691
+ }
1692
+ return {
1693
+ total: prompts.length,
1694
+ byStatus,
1695
+ byCategory,
1696
+ totalVersions,
1697
+ totalUsage
1698
+ };
1699
+ } catch (error) {
1700
+ throw new Error(`Failed to get statistics: ${error.message}`);
1701
+ }
1702
+ }
1703
+ /**
1704
+ * Save a new prompt with initial content
1705
+ *
1706
+ * Creates a new prompt with the given name and content, automatically
1707
+ * setting the initial version to v1. Returns the created prompt ID.
1708
+ *
1709
+ * @param name - Human-readable prompt name (must be unique within category)
1710
+ * @param content - Initial prompt content
1711
+ * @param options - Optional configuration (category, tags, author, autoOptimize)
1712
+ * @returns Promise resolving to the new prompt ID
1713
+ * @throws Error if prompt name already exists or validation fails
1714
+ *
1715
+ * @example
1716
+ * ```ts
1717
+ * const promptId = await operations.savePrompt('auth-system', 'You are an auth specialist...', {
1718
+ * category: 'domain',
1719
+ * tags: ['authentication', 'security'],
1720
+ * author: 'dev-team',
1721
+ * autoOptimize: true,
1722
+ * });
1723
+ * ```
1724
+ */
1725
+ async savePrompt(name, content, options) {
1726
+ try {
1727
+ const id = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
1728
+ if (!id) {
1729
+ throw new Error("Prompt name must contain at least one alphanumeric character");
1730
+ }
1731
+ const existingByName = this.list().find((p) => p.name === name);
1732
+ if (existingByName) {
1733
+ throw new Error(`Prompt with name "${name}" already exists (ID: ${existingByName.id})`);
1734
+ }
1735
+ const result = await this.create({
1736
+ id,
1737
+ name,
1738
+ description: options?.description || name,
1739
+ category: options?.category || "custom",
1740
+ tags: options?.tags,
1741
+ initialContent: content,
1742
+ author: options?.author,
1743
+ autoOptimize: options?.autoOptimize
1744
+ });
1745
+ return result.prompt.id;
1746
+ } catch (error) {
1747
+ throw new Error(`Failed to save prompt "${name}": ${error.message}`);
1748
+ }
1749
+ }
1750
+ /**
1751
+ * Activate a specific version of a prompt with safety checks
1752
+ *
1753
+ * Activates a previously created version after performing safety checks.
1754
+ * Can optionally require user confirmation before activation. Logs the
1755
+ * activation with reason for audit trail.
1756
+ *
1757
+ * Safety checks:
1758
+ * - Version must exist
1759
+ * - Version must have minimum completeness score (if metrics available)
1760
+ * - Version must not have success rate below critical threshold
1761
+ *
1762
+ * @param promptId - ID of the prompt to update or versionId if first param is versionId string
1763
+ * @param versionId - ID of the version to activate, or undefined if using overload
1764
+ * @param options - Activation options (confirmation requirement, reason)
1765
+ * @returns Promise that resolves when activation is complete
1766
+ * @throws Error if safety checks fail or version not found
1767
+ *
1768
+ * @example
1769
+ * ```ts
1770
+ * // With prompt ID and version ID
1771
+ * await operations.activateVersion('user-auth', 'v2.1.0', {
1772
+ * confirm: true,
1773
+ * reason: 'Manual: 15% improvement in success rate',
1774
+ * });
1775
+ *
1776
+ * // With just version ID
1777
+ * await operations.activateVersion('v2.1.0');
1778
+ * ```
1779
+ */
1780
+ async activateVersion(promptIdOrVersionId, versionIdOrOptions, optionsArg) {
1781
+ let promptId = "";
1782
+ let versionId = "";
1783
+ let options;
1784
+ try {
1785
+ if (typeof versionIdOrOptions === "string") {
1786
+ promptId = promptIdOrVersionId;
1787
+ versionId = versionIdOrOptions;
1788
+ options = optionsArg;
1789
+ } else {
1790
+ const version2 = this.store.getVersion(promptIdOrVersionId);
1791
+ if (!version2) {
1792
+ throw new Error(`Version "${promptIdOrVersionId}" not found`);
1793
+ }
1794
+ promptId = version2.promptId;
1795
+ versionId = promptIdOrVersionId;
1796
+ options = versionIdOrOptions;
1797
+ }
1798
+ const prompt = this.getOrThrow(promptId);
1799
+ const version = this.store.getVersion(promptId, versionId);
1800
+ if (!version) {
1801
+ throw new Error(`Version "${versionId}" not found for prompt "${promptId}"`);
1802
+ }
1803
+ const metrics = this.getPerformance(versionId);
1804
+ if (metrics && !options?.skipSafetyChecks) {
1805
+ if (metrics.successRate < 0.5) {
1806
+ emitWarning(
1807
+ "PR-001",
1808
+ {
1809
+ taskId: "prompt-operations",
1810
+ subsystem: "prompts",
1811
+ executionPhase: "execution"
1812
+ },
1813
+ {
1814
+ severity: "WARN" /* WARN */,
1815
+ metadata: {
1816
+ versionId,
1817
+ successRate: metrics.successRate,
1818
+ threshold: 0.5,
1819
+ operation: "activateVersion"
1820
+ }
1821
+ }
1822
+ );
1823
+ }
1824
+ if (metrics.avgCompleteness < 60) {
1825
+ emitWarning(
1826
+ "PR-001",
1827
+ {
1828
+ taskId: "prompt-operations",
1829
+ subsystem: "prompts",
1830
+ executionPhase: "execution"
1831
+ },
1832
+ {
1833
+ severity: "WARN" /* WARN */,
1834
+ metadata: {
1835
+ versionId,
1836
+ avgCompleteness: metrics.avgCompleteness,
1837
+ threshold: 60,
1838
+ operation: "activateVersion"
1839
+ }
1840
+ }
1841
+ );
1842
+ }
1843
+ if (metrics.successRate < 0.2 && metrics.sampleSize >= 10) {
1844
+ throw new Error(
1845
+ `Cannot activate version with critically low success rate: ${(metrics.successRate * 100).toFixed(1)}%`
1846
+ );
1847
+ }
1848
+ }
1849
+ if (options?.confirm) {
1850
+ console.log(`[CONFIRM] Activate version ${versionId} of "${prompt.name}"?`);
1851
+ }
1852
+ const reason = options?.reason || "Manual activation via manager";
1853
+ await this.store.setActiveVersion(promptId, versionId, reason);
1854
+ console.log(`[INFO] Activated version ${versionId} for prompt "${prompt.name}": ${reason}`);
1855
+ } catch (error) {
1856
+ throw new Error(`Failed to activate version "${versionId}": ${error.message}`);
1857
+ }
1858
+ }
1859
+ /**
1860
+ * Rollback to the previous version of a prompt
1861
+ *
1862
+ * Safely reverts a prompt to its previous version. Includes safety checks
1863
+ * to ensure rollback is valid (has previous version, hasn't been rolled back
1864
+ * too many times). Returns the ID of the rolled-back version.
1865
+ *
1866
+ * @param promptId - ID of the prompt to rollback
1867
+ * @returns Promise resolving to the ID of the now-active version
1868
+ * @throws Error if rollback is not possible or safety checks fail
1869
+ *
1870
+ * @example
1871
+ * ```ts
1872
+ * const previousVersionId = await operations.rollbackVersion('user-auth');
1873
+ * console.log(`Rolled back to ${previousVersionId}`);
1874
+ * ```
1875
+ */
1876
+ async rollbackVersion(promptId) {
1877
+ try {
1878
+ const prompt = this.getOrThrow(promptId);
1879
+ const versions = this.listVersions(promptId).sort(
1880
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
1881
+ );
1882
+ if (versions.length < 2) {
1883
+ throw new Error(
1884
+ `Cannot rollback: prompt "${promptId}" has only ${versions.length} version(s)`
1885
+ );
1886
+ }
1887
+ const currentActive = versions.find((v) => v.isActive);
1888
+ if (!currentActive) {
1889
+ throw new Error(`No active version found for prompt "${promptId}"`);
1890
+ }
1891
+ const previousVersion = versions[1];
1892
+ if (!previousVersion) {
1893
+ throw new Error("No previous version available for rollback");
1894
+ }
1895
+ const sevenDaysAgo = new Date(Date.now() - SEVEN_DAYS_MS).toISOString();
1896
+ const recentRollbacks = versions.filter(
1897
+ (v) => v.deactivatedAt && v.deactivatedAt > sevenDaysAgo && !v.isActive
1898
+ ).length;
1899
+ if (recentRollbacks >= 3) {
1900
+ throw new Error(
1901
+ `Too many rollbacks (${recentRollbacks}) in the last 7 days. Consider reviewing prompt strategy.`
1902
+ );
1903
+ }
1904
+ await this.store.activateVersion(promptId, previousVersion.id);
1905
+ console.log(
1906
+ `[INFO] Rolled back "${prompt.name}" from ${currentActive.id} to ${previousVersion.id}`
1907
+ );
1908
+ return previousVersion.id;
1909
+ } catch (error) {
1910
+ throw new Error(`Failed to rollback version: ${error.message}`);
1911
+ }
1912
+ }
1913
+ /**
1914
+ * Create variants of a prompt using specified mutation strategies
1915
+ *
1916
+ * Generates new prompt variants using the VariantGenerator with configured
1917
+ * mutation strategies (clarity, conciseness, context, etc.). The created
1918
+ * variants are saved to the store for A/B testing.
1919
+ *
1920
+ * @param promptId - ID of the prompt to create variants for
1921
+ * @param strategies - Mutation strategies to apply (clarity, conciseness, context, examples, structure, constraints, tone, hybrid)
1922
+ * @param options - Optional configuration (targetMetric for optimization)
1923
+ * @returns Promise resolving to array of created variants
1924
+ * @throws Error if prompt not found or variant generation fails
1925
+ *
1926
+ * @example
1927
+ * ```ts
1928
+ * const variants = await operations.createVariant('user-auth', ['clarity', 'examples'], {
1929
+ * targetMetric: 'success_rate',
1930
+ * });
1931
+ * console.log(`Created ${variants.length} variants for A/B testing`);
1932
+ * ```
1933
+ */
1934
+ async createVariant(promptId, strategies, options) {
1935
+ try {
1936
+ this.getOrThrow(promptId);
1937
+ const baseVersion = this.getActiveVersionOrThrow(promptId);
1938
+ const generator = new VariantGenerator();
1939
+ const generatedVariants = await generator.generateVariants(baseVersion, strategies.length, {
1940
+ strategies,
1941
+ targetMetric: options?.targetMetric || "balanced"
1942
+ });
1943
+ const savedVariants = [];
1944
+ for (let i = 0; i < generatedVariants.length; i++) {
1945
+ const generated = generatedVariants[i];
1946
+ if (!generated) continue;
1947
+ const strategy = strategies[i] || "hybrid";
1948
+ const variantVersionId = await this.getNextVersion(promptId);
1949
+ await this.createVersion({
1950
+ promptId,
1951
+ content: generated.content,
1952
+ version: variantVersionId,
1953
+ changelog: `Variant using ${strategy} strategy: ${generated.expectedImprovement}`,
1954
+ author: "variant-generator",
1955
+ activate: false,
1956
+ isGenerated: true,
1957
+ generationModel: "variant-generator",
1958
+ generationPrompt: `Apply ${strategy} mutation strategy`
1959
+ });
1960
+ const variantId = `${baseVersion.id}-${strategy}-${variantVersionId}`;
1961
+ const variant = {
1962
+ id: variantId,
1963
+ promptId,
1964
+ baseVersionId: baseVersion.id,
1965
+ mutationStrategies: [strategy],
1966
+ confidence: generated.confidence,
1967
+ expectedImprovement: parseFloat(
1968
+ generated.expectedImprovement.match(/[\d.]+/)?.[0] || "0"
1969
+ ),
1970
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1971
+ };
1972
+ try {
1973
+ await this.store.saveVariant(variant);
1974
+ } catch (variantError) {
1975
+ emitWarning(
1976
+ "PR-001",
1977
+ {
1978
+ taskId: "prompt-operations",
1979
+ subsystem: "prompts",
1980
+ executionPhase: "execution"
1981
+ },
1982
+ {
1983
+ severity: "WARN" /* WARN */,
1984
+ metadata: {
1985
+ error: variantError.message,
1986
+ operation: "saveVariant",
1987
+ variantId: variant.id,
1988
+ promptId
1989
+ }
1990
+ }
1991
+ );
1992
+ }
1993
+ savedVariants.push(variant);
1994
+ }
1995
+ console.log(
1996
+ `[INFO] Created ${savedVariants.length} variants for prompt "${promptId}" using strategies: ${strategies.join(", ")}`
1997
+ );
1998
+ return savedVariants;
1999
+ } catch (error) {
2000
+ throw new Error(
2001
+ `Failed to create variants for prompt "${promptId}": ${error.message}`
2002
+ );
2003
+ }
2004
+ }
2005
+ /**
2006
+ * Get human-readable version history for a prompt
2007
+ *
2008
+ * Compiles a complete history of all versions for a prompt including
2009
+ * performance metrics and activation timeline. Returns formatted data
2010
+ * suitable for CLI display or JSON export.
2011
+ *
2012
+ * @param promptId - ID of the prompt to get history for
2013
+ * @returns Promise resolving to formatted version history
2014
+ * @throws Error if prompt not found
2015
+ *
2016
+ * @example
2017
+ * ```ts
2018
+ * const history = await operations.getPromptHistory('user-auth');
2019
+ * console.log(`${history.totalVersions} versions of "${history.promptName}"`);
2020
+ * history.entries.forEach((entry) => {
2021
+ * console.log(` ${entry.versionId}: ${entry.wordCount} words, active=${entry.isActive}`);
2022
+ * });
2023
+ * ```
2024
+ */
2025
+ async getPromptHistory(promptId) {
2026
+ try {
2027
+ const prompt = this.getOrThrow(promptId);
2028
+ const versions = this.listVersions(promptId);
2029
+ const activeVersion = this.getActiveVersion(promptId);
2030
+ const activeVersionId = activeVersion?.id || "";
2031
+ const entries = versions.map((version) => {
2032
+ const metrics = this.getPerformance(version.id);
2033
+ const wordCount = version.content.split(/\s+/).length;
2034
+ const activationReason = activeVersionId === version.id ? "Currently active" : void 0;
2035
+ return {
2036
+ versionId: version.id,
2037
+ content: version.content,
2038
+ contentLength: version.content.length,
2039
+ wordCount,
2040
+ isActive: version.isActive,
2041
+ isGenerated: version.isGenerated,
2042
+ generationModel: version.generationModel,
2043
+ changelog: version.changelog,
2044
+ author: version.author,
2045
+ createdAt: version.createdAt,
2046
+ activatedAt: version.activatedAt,
2047
+ deactivatedAt: version.deactivatedAt,
2048
+ performance: metrics ? {
2049
+ successRate: metrics.successRate,
2050
+ avgCompleteness: metrics.avgCompleteness,
2051
+ avgDuration: metrics.avgDuration,
2052
+ sampleSize: metrics.sampleSize
2053
+ } : void 0,
2054
+ activationReason
2055
+ };
2056
+ });
2057
+ entries.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
2058
+ return {
2059
+ promptId,
2060
+ promptName: prompt.name,
2061
+ totalVersions: versions.length,
2062
+ activeVersionId,
2063
+ entries
2064
+ };
2065
+ } catch (error) {
2066
+ throw new Error(
2067
+ `Failed to get history for prompt "${promptId}": ${error.message}`
2068
+ );
2069
+ }
2070
+ }
2071
+ /**
2072
+ * Export all prompts with versions and metrics
2073
+ *
2074
+ * Exports complete prompt database including all versions and performance
2075
+ * metrics in specified format (JSON or CSV). Useful for backup, migration,
2076
+ * or analysis.
2077
+ *
2078
+ * @param options - Export format and options
2079
+ * @returns Promise resolving to serialized export data
2080
+ * @throws Error if export fails
2081
+ *
2082
+ * @example
2083
+ * ```ts
2084
+ * const json = await operations.exportPrompts({ format: 'json' });
2085
+ * fs.writeFileSync('prompts-backup.json', json);
2086
+ *
2087
+ * const csv = await operations.exportPrompts({ format: 'csv' });
2088
+ * fs.writeFileSync('prompts-export.csv', csv);
2089
+ * ```
2090
+ */
2091
+ async exportPrompts(options) {
2092
+ try {
2093
+ const format = options?.format || "json";
2094
+ const includeMetrics = options?.includeMetrics !== false;
2095
+ const prompts = this.list();
2096
+ if (format === "json") {
2097
+ const exportData = {
2098
+ version: "1.0.0",
2099
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
2100
+ prompts: prompts.map((prompt) => {
2101
+ const versions = this.listVersions(prompt.id);
2102
+ const metrics = includeMetrics ? versions.map((v) => this.getPerformance(v.id)).filter(Boolean) : void 0;
2103
+ return {
2104
+ prompt,
2105
+ versions,
2106
+ metrics
2107
+ };
2108
+ })
2109
+ };
2110
+ return JSON.stringify(exportData, null, 2);
2111
+ } else if (format === "csv") {
2112
+ const lines = [];
2113
+ lines.push(
2114
+ "promptId,promptName,versionId,category,status,author,createdAt,isActive,successRate,avgCompleteness"
2115
+ );
2116
+ for (const prompt of prompts) {
2117
+ const versions = this.listVersions(prompt.id);
2118
+ for (const version of versions) {
2119
+ const metrics = includeMetrics ? this.getPerformance(version.id) : null;
2120
+ const row = [
2121
+ prompt.id,
2122
+ `"${prompt.name.replace(/"/g, '""')}"`,
2123
+ version.id,
2124
+ prompt.category,
2125
+ prompt.status,
2126
+ version.author || "",
2127
+ version.createdAt,
2128
+ version.isActive ? "true" : "false",
2129
+ metrics?.successRate?.toFixed(3) || "",
2130
+ metrics?.avgCompleteness?.toFixed(1) || ""
2131
+ ].join(",");
2132
+ lines.push(row);
2133
+ }
2134
+ }
2135
+ return lines.join("\n");
2136
+ } else {
2137
+ throw new Error(`Unsupported export format: ${format}`);
2138
+ }
2139
+ } catch (error) {
2140
+ throw new Error(`Failed to export prompts: ${error.message}`);
2141
+ }
2142
+ }
2143
+ /**
2144
+ * Import prompts from exported data
2145
+ *
2146
+ * Imports prompts from JSON or CSV export format. Handles conflict resolution
2147
+ * (skip duplicates or update existing) and validates data integrity.
2148
+ *
2149
+ * @param data - Serialized export data (JSON or CSV)
2150
+ * @param options - Import options (format, conflictResolution)
2151
+ * @returns Promise that resolves when import is complete
2152
+ * @throws Error if data format is invalid or import fails
2153
+ *
2154
+ * @example
2155
+ * ```ts
2156
+ * const data = fs.readFileSync('prompts-backup.json', 'utf-8');
2157
+ * await operations.importPrompts(data, {
2158
+ * format: 'json',
2159
+ * conflictResolution: 'skip',
2160
+ * });
2161
+ * ```
2162
+ */
2163
+ async importPrompts(data, options) {
2164
+ try {
2165
+ const format = options?.format || "json";
2166
+ const conflictResolution = options?.conflictResolution || "skip";
2167
+ if (format === "json") {
2168
+ const exportData = parseJsonWithContext(data, "Prompt export data");
2169
+ if (!exportData.version || !Array.isArray(exportData.prompts)) {
2170
+ throw new Error("Invalid export format: missing version or prompts array");
2171
+ }
2172
+ let imported = 0;
2173
+ let skipped = 0;
2174
+ for (const item of exportData.prompts) {
2175
+ const { prompt, versions } = item;
2176
+ const existing = this.get(prompt.id);
2177
+ if (existing && conflictResolution === "skip") {
2178
+ console.log(`[SKIP] Prompt "${prompt.id}" already exists`);
2179
+ skipped++;
2180
+ continue;
2181
+ }
2182
+ try {
2183
+ if (!existing) {
2184
+ if (versions.length === 0) {
2185
+ console.warn(`[WARN] Prompt "${prompt.id}" has no versions, skipping`);
2186
+ skipped++;
2187
+ continue;
2188
+ }
2189
+ const firstVersion = versions[0];
2190
+ if (!firstVersion) {
2191
+ emitWarning(
2192
+ "PR-001",
2193
+ {
2194
+ taskId: "prompt-operations",
2195
+ subsystem: "prompts",
2196
+ executionPhase: "execution"
2197
+ },
2198
+ {
2199
+ severity: "WARN" /* WARN */,
2200
+ metadata: {
2201
+ operation: "importPrompts",
2202
+ promptId: prompt.id,
2203
+ reason: "No first version found"
2204
+ }
2205
+ }
2206
+ );
2207
+ skipped++;
2208
+ continue;
2209
+ }
2210
+ await this.create({
2211
+ id: prompt.id,
2212
+ name: prompt.name,
2213
+ description: prompt.description,
2214
+ category: prompt.category,
2215
+ variant: prompt.variant,
2216
+ tags: prompt.tags,
2217
+ initialContent: firstVersion.content,
2218
+ initialVersion: firstVersion.id,
2219
+ author: firstVersion.author,
2220
+ autoOptimize: prompt.autoOptimize
2221
+ });
2222
+ for (let i = 1; i < versions.length; i++) {
2223
+ const version = versions[i];
2224
+ if (!version) continue;
2225
+ await this.createVersion({
2226
+ promptId: prompt.id,
2227
+ content: version.content,
2228
+ version: version.id,
2229
+ changelog: version.changelog,
2230
+ author: version.author,
2231
+ activate: version.isActive,
2232
+ isGenerated: version.isGenerated,
2233
+ generationModel: version.generationModel
2234
+ });
2235
+ }
2236
+ imported++;
2237
+ console.log(`[OK] Imported prompt "${prompt.id}" with ${versions.length} versions`);
2238
+ } else if (conflictResolution === "overwrite") {
2239
+ await this.update(prompt.id, {
2240
+ name: prompt.name,
2241
+ description: prompt.description,
2242
+ category: prompt.category,
2243
+ tags: prompt.tags,
2244
+ autoOptimize: prompt.autoOptimize
2245
+ });
2246
+ let newVersions = 0;
2247
+ for (const version of versions) {
2248
+ const existing2 = this.getVersion(version.id);
2249
+ if (!existing2) {
2250
+ await this.createVersion({
2251
+ promptId: prompt.id,
2252
+ content: version.content,
2253
+ version: version.id,
2254
+ changelog: version.changelog,
2255
+ author: version.author,
2256
+ activate: version.isActive,
2257
+ isGenerated: version.isGenerated,
2258
+ generationModel: version.generationModel
2259
+ });
2260
+ newVersions++;
2261
+ }
2262
+ }
2263
+ imported++;
2264
+ console.log(`[OK] Updated prompt "${prompt.id}" with ${newVersions} new versions`);
2265
+ }
2266
+ } catch (error) {
2267
+ console.error(
2268
+ `[ERROR] Failed to import prompt "${prompt.id}": ${error.message}`
2269
+ );
2270
+ skipped++;
2271
+ }
2272
+ }
2273
+ console.log(`[INFO] Import complete: ${imported} imported, ${skipped} skipped`);
2274
+ } else if (format === "csv") {
2275
+ const lines = data.split("\n").filter((line) => line.trim());
2276
+ if (lines.length < 2) {
2277
+ throw new Error("CSV import requires at least header + 1 data row");
2278
+ }
2279
+ const dataLines = lines.slice(1);
2280
+ let imported = 0;
2281
+ let skipped = 0;
2282
+ for (const line of dataLines) {
2283
+ try {
2284
+ const parts = line.split(",");
2285
+ if (parts.length < 5) {
2286
+ skipped++;
2287
+ continue;
2288
+ }
2289
+ const promptId = parts[0]?.trim();
2290
+ const promptName = parts[1]?.replace(/^"|"$/g, "").replace('""', '"');
2291
+ if (!promptId || !promptName) {
2292
+ skipped++;
2293
+ continue;
2294
+ }
2295
+ const existing = this.get(promptId);
2296
+ if (existing && conflictResolution === "skip") {
2297
+ skipped++;
2298
+ continue;
2299
+ }
2300
+ if (!existing) {
2301
+ await this.create({
2302
+ id: promptId,
2303
+ name: promptName,
2304
+ description: promptName,
2305
+ category: "custom",
2306
+ initialContent: `Imported from CSV: ${promptName}`
2307
+ });
2308
+ imported++;
2309
+ }
2310
+ } catch (_error) {
2311
+ skipped++;
2312
+ }
2313
+ }
2314
+ console.log(`[INFO] CSV import complete: ${imported} imported, ${skipped} skipped`);
2315
+ } else {
2316
+ throw new Error(`Unsupported import format: ${format}`);
2317
+ }
2318
+ } catch (error) {
2319
+ throw new Error(`Failed to import prompts: ${error.message}`);
2320
+ }
2321
+ }
2322
+ /**
2323
+ * Close database connection
2324
+ */
2325
+ close() {
2326
+ this.store.close();
2327
+ }
2328
+ // Private helper methods
2329
+ /**
2330
+ * Get next semantic version for a prompt
2331
+ */
2332
+ async getNextVersion(promptId) {
2333
+ const versions = this.listVersions(promptId);
2334
+ if (versions.length === 0) {
2335
+ return "v1.0.0";
2336
+ }
2337
+ const versionNumbers = versions.map((v) => v.id).filter((id) => /^v\d+\.\d+\.\d+$/.test(id)).map((id) => {
2338
+ const parts = id.slice(1).split(".").map(Number);
2339
+ return { major: parts[0], minor: parts[1], patch: parts[2] };
2340
+ });
2341
+ if (versionNumbers.length === 0) {
2342
+ return "v1.0.0";
2343
+ }
2344
+ versionNumbers.sort((a, b) => {
2345
+ const aMajor = a.major ?? 0;
2346
+ const bMajor = b.major ?? 0;
2347
+ if (aMajor !== bMajor) return bMajor - aMajor;
2348
+ const aMinor = a.minor ?? 0;
2349
+ const bMinor = b.minor ?? 0;
2350
+ if (aMinor !== bMinor) return bMinor - aMinor;
2351
+ const aPatch = a.patch ?? 0;
2352
+ const bPatch = b.patch ?? 0;
2353
+ return bPatch - aPatch;
2354
+ });
2355
+ const highest = versionNumbers[0];
2356
+ if (!highest) {
2357
+ return "v1.0.0";
2358
+ }
2359
+ return `v${highest.major ?? 1}.${highest.minor ?? 0}.${(highest.patch ?? 0) + 1}`;
2360
+ }
2361
+ /**
2362
+ * Generate simple line-by-line diff
2363
+ */
2364
+ generateDiff(contentA, contentB) {
2365
+ const linesA = contentA.split("\n");
2366
+ const linesB = contentB.split("\n");
2367
+ const diff = [];
2368
+ const maxLines = Math.max(linesA.length, linesB.length);
2369
+ for (let i = 0; i < maxLines; i++) {
2370
+ const lineA = linesA[i];
2371
+ const lineB = linesB[i];
2372
+ if (lineA === lineB) {
2373
+ diff.push(` ${lineA || ""}`);
2374
+ } else {
2375
+ if (lineA !== void 0) {
2376
+ diff.push(`- ${lineA}`);
2377
+ }
2378
+ if (lineB !== void 0) {
2379
+ diff.push(`+ ${lineB}`);
2380
+ }
2381
+ }
2382
+ }
2383
+ return diff.join("\n");
2384
+ }
2385
+ };
2386
+
2387
+ // src/prompts/manager.ts
2388
+ var PromptManager = class {
2389
+ operations;
2390
+ analytics;
2391
+ /**
2392
+ * Create a new PromptManager instance.
2393
+ *
2394
+ * @param options - Configuration options
2395
+ */
2396
+ constructor(options = {}) {
2397
+ this.operations = new PromptOperations(options);
2398
+ this.analytics = new PromptAnalytics(this.operations);
2399
+ }
2400
+ /**
2401
+ * Access the underlying PromptStore (for activation history and other
2402
+ * read-paths that need direct DB access). Mutations should go through
2403
+ * the manager's higher-level methods.
2404
+ */
2405
+ getStore() {
2406
+ return this.operations.getStore();
2407
+ }
2408
+ // ============================================================================
2409
+ // CRUD OPERATIONS (delegate to PromptOperations)
2410
+ // ============================================================================
2411
+ /**
2412
+ * Create a new prompt with optional initial version
2413
+ */
2414
+ async create(options) {
2415
+ return this.operations.create(options);
2416
+ }
2417
+ /**
2418
+ * Get a prompt by ID
2419
+ */
2420
+ get(id) {
2421
+ return this.operations.get(id);
2422
+ }
2423
+ /**
2424
+ * Get a prompt by ID, throwing if not found
2425
+ */
2426
+ getOrThrow(id) {
2427
+ return this.operations.getOrThrow(id);
2428
+ }
2429
+ /**
2430
+ * Update a prompt
2431
+ */
2432
+ async update(id, options) {
2433
+ return this.operations.update(id, options);
2434
+ }
2435
+ /**
2436
+ * Delete a prompt and all its versions
2437
+ */
2438
+ async delete(id) {
2439
+ return this.operations.delete(id);
2440
+ }
2441
+ /**
2442
+ * Archive a prompt
2443
+ */
2444
+ async archive(id) {
2445
+ return this.operations.archive(id);
2446
+ }
2447
+ /**
2448
+ * Restore an archived prompt
2449
+ */
2450
+ async restore(id) {
2451
+ return this.operations.restore(id);
2452
+ }
2453
+ /**
2454
+ * List prompts with optional filtering
2455
+ */
2456
+ list(criteria) {
2457
+ return this.operations.list(criteria);
2458
+ }
2459
+ /**
2460
+ * Search prompts by query string
2461
+ */
2462
+ search(query, options) {
2463
+ return this.operations.search(query, options);
2464
+ }
2465
+ // ============================================================================
2466
+ // VERSION MANAGEMENT (delegate to PromptOperations)
2467
+ // ============================================================================
2468
+ /**
2469
+ * Create a new version for a prompt
2470
+ */
2471
+ async createVersion(options) {
2472
+ return this.operations.createVersion(options);
2473
+ }
2474
+ getVersion(idOrPromptId, versionId) {
2475
+ return this.operations.getVersion(idOrPromptId, versionId);
2476
+ }
2477
+ /**
2478
+ * Get active version for a prompt
2479
+ */
2480
+ getActiveVersion(promptId) {
2481
+ return this.operations.getActiveVersion(promptId);
2482
+ }
2483
+ /**
2484
+ * Get active version, throwing if not found
2485
+ */
2486
+ getActiveVersionOrThrow(promptId) {
2487
+ return this.operations.getActiveVersionOrThrow(promptId);
2488
+ }
2489
+ /**
2490
+ * List all versions for a prompt
2491
+ */
2492
+ listVersions(promptId) {
2493
+ return this.operations.listVersions(promptId);
2494
+ }
2495
+ /**
2496
+ * Deactivate a version
2497
+ */
2498
+ async deactivateVersion(versionId) {
2499
+ return this.operations.deactivateVersion(versionId);
2500
+ }
2501
+ /**
2502
+ * Activate a specific version of a prompt with safety checks
2503
+ */
2504
+ async activateVersion(promptIdOrVersionId, versionIdOrOptions, optionsArg) {
2505
+ return this.operations.activateVersion(promptIdOrVersionId, versionIdOrOptions, optionsArg);
2506
+ }
2507
+ /**
2508
+ * Rollback to the previous version of a prompt
2509
+ */
2510
+ async rollbackVersion(promptId) {
2511
+ return this.operations.rollbackVersion(promptId);
2512
+ }
2513
+ // ============================================================================
2514
+ // PERFORMANCE & METRICS (delegate to PromptOperations)
2515
+ // ============================================================================
2516
+ /**
2517
+ * Get performance metrics for a version
2518
+ */
2519
+ getPerformance(versionId, variant) {
2520
+ return this.operations.getPerformance(versionId, variant);
2521
+ }
2522
+ /**
2523
+ * Increment usage count when a prompt is used
2524
+ */
2525
+ recordUsage(promptId) {
2526
+ this.operations.recordUsage(promptId);
2527
+ }
2528
+ // ============================================================================
2529
+ // COMPARISON & ANALYSIS (delegate to PromptOperations & PromptAnalytics)
2530
+ // ============================================================================
2531
+ /**
2532
+ * Compare two prompts or versions
2533
+ */
2534
+ async compare(promptIdA, promptIdB, versionIdA, versionIdB) {
2535
+ return this.operations.compare(promptIdA, promptIdB, versionIdA, versionIdB);
2536
+ }
2537
+ /**
2538
+ * Get performance analysis for a prompt
2539
+ */
2540
+ async analyzePerformance(promptId, versionId) {
2541
+ return this.analytics.analyzePerformance(promptId, versionId);
2542
+ }
2543
+ /**
2544
+ * Get performance trend for a prompt
2545
+ */
2546
+ async getPerformanceTrend(promptId, versionId) {
2547
+ return this.analytics.getPerformanceTrend(promptId, versionId);
2548
+ }
2549
+ /**
2550
+ * Get optimization suggestions for a prompt
2551
+ */
2552
+ async getSuggestions(promptId) {
2553
+ return this.analytics.getSuggestions(promptId);
2554
+ }
2555
+ // ============================================================================
2556
+ // BATCH OPERATIONS (delegate to PromptOperations)
2557
+ // ============================================================================
2558
+ /**
2559
+ * Clone a prompt with a new ID
2560
+ */
2561
+ async clone(sourceId, newId, newName, options) {
2562
+ return this.operations.clone(sourceId, newId, newName, options);
2563
+ }
2564
+ /**
2565
+ * Batch archive multiple prompts
2566
+ */
2567
+ async archiveBatch(ids) {
2568
+ return this.operations.archiveBatch(ids);
2569
+ }
2570
+ /**
2571
+ * Batch delete multiple prompts
2572
+ */
2573
+ async deleteBatch(ids) {
2574
+ return this.operations.deleteBatch(ids);
2575
+ }
2576
+ // ============================================================================
2577
+ // STATISTICS (delegate to PromptOperations)
2578
+ // ============================================================================
2579
+ /**
2580
+ * Get statistics for all prompts
2581
+ */
2582
+ getStatistics() {
2583
+ return this.operations.getStatistics();
2584
+ }
2585
+ // ============================================================================
2586
+ // HIGH-LEVEL OPERATIONS (delegate to PromptOperations)
2587
+ // ============================================================================
2588
+ /**
2589
+ * Save a new prompt with initial content
2590
+ */
2591
+ async savePrompt(name, content, options) {
2592
+ return this.operations.savePrompt(name, content, options);
2593
+ }
2594
+ /**
2595
+ * Create variants of a prompt using specified mutation strategies
2596
+ */
2597
+ async createVariant(promptId, strategies, options) {
2598
+ return this.operations.createVariant(promptId, strategies, options);
2599
+ }
2600
+ /**
2601
+ * Get human-readable version history for a prompt
2602
+ */
2603
+ async getPromptHistory(promptId) {
2604
+ return this.operations.getPromptHistory(promptId);
2605
+ }
2606
+ // ============================================================================
2607
+ // IMPORT/EXPORT (delegate to PromptOperations)
2608
+ // ============================================================================
2609
+ /**
2610
+ * Export all prompts with versions and metrics
2611
+ */
2612
+ async exportPrompts(options) {
2613
+ return this.operations.exportPrompts(options);
2614
+ }
2615
+ /**
2616
+ * Import prompts from exported data
2617
+ */
2618
+ async importPrompts(data, options) {
2619
+ return this.operations.importPrompts(data, options);
2620
+ }
2621
+ // ============================================================================
2622
+ // AUTO-TUNING & MONITORING (delegate to PromptAnalytics)
2623
+ // ============================================================================
2624
+ /**
2625
+ * Auto-tune a prompt by evaluating variants and activating if criteria met
2626
+ */
2627
+ async autoTunePrompt(promptId, options) {
2628
+ return this.analytics.autoTunePrompt(promptId, options);
2629
+ }
2630
+ /**
2631
+ * Monitor an auto-activated version for regressions
2632
+ */
2633
+ async monitorAutoTuning(promptId, options) {
2634
+ return this.analytics.monitorAutoTuning(promptId, options);
2635
+ }
2636
+ // ============================================================================
2637
+ // LIFECYCLE METHODS
2638
+ // ============================================================================
2639
+ /**
2640
+ * Close all resources and clean up.
2641
+ */
2642
+ close() {
2643
+ this.operations.close();
2644
+ }
2645
+ // ============================================================================
2646
+ // ADVANCED ACCESS (for direct module access if needed)
2647
+ // ============================================================================
2648
+ /**
2649
+ * Get the operations module for advanced usage.
2650
+ *
2651
+ * @returns PromptOperations instance
2652
+ */
2653
+ get operationsModule() {
2654
+ return this.operations;
2655
+ }
2656
+ /**
2657
+ * Get the analytics module for advanced usage.
2658
+ *
2659
+ * @returns PromptAnalytics instance
2660
+ */
2661
+ get analyticsModule() {
2662
+ return this.analytics;
2663
+ }
2664
+ };
2665
+
2666
+ export {
2667
+ VariantGenerator,
2668
+ PromptManager
2669
+ };
2670
+ //# sourceMappingURL=chunk-Q3WIC6GQ.js.map