@testmuai/kane-cli 0.10.3 → 0.10.4

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 (424) hide show
  1. package/dist/ChatSurface-DN7VVN3Y.js +2 -0
  2. package/dist/ChromeProfilePicker-TVGWXTUU.js +2 -0
  3. package/dist/{CliFeedbackPrompt-JWCTMIGI.js → CliFeedbackPrompt-L5ILK66U.js} +1 -1
  4. package/dist/{CliUploadProgress-XFRRFRL4.js → CliUploadProgress-IU6BQLMV.js} +1 -1
  5. package/dist/{ConfigView-6JF4DOJN.js → ConfigView-LU5IRRQU.js} +1 -1
  6. package/dist/EvidenceViewOffer-DNTARDEL.js +2 -0
  7. package/dist/FolderPicker-6E5GE2K2.js +2 -0
  8. package/dist/InfoBox-SFFPLWCV.js +2 -0
  9. package/dist/LinksBox-6YDTIO6I.js +2 -0
  10. package/dist/ProfilesView-6C5HJQ3Y.js +2 -0
  11. package/dist/ProjectPicker-YIQIVXGK.js +2 -0
  12. package/dist/SaveSessionPrompt-X3N6OGYB.js +2 -0
  13. package/dist/SingleShotApp-MXNJPU6A.js +2 -0
  14. package/dist/SummaryBox-T7PDXDKS.js +2 -0
  15. package/dist/TestMdRunView-HRJSBP2C.js +2 -0
  16. package/dist/TestrunEvidenceTable-OGMWTJQF.js +2 -0
  17. package/dist/{WhoamiView-H7JNLLCY.js → WhoamiView-WGCWD7GP.js} +1 -1
  18. package/dist/{app-client-U2YYF65L.js → app-client-2RR5ATI6.js} +1 -1
  19. package/dist/app-download-ZS6ZMX2Z.js +2 -0
  20. package/dist/{assurance-job-F4L3T4VJ.js → assurance-job-QO4VJJCL.js} +1 -1
  21. package/dist/{binary-K3XMILST.js → binary-CCCTW3QQ.js} +1 -1
  22. package/dist/bind-JU4XPDN3.js +2 -0
  23. package/dist/bootstrap-BV7HAARR.js +2 -0
  24. package/dist/{bridge-2UHJOVLX.js → bridge-SPGIYAAG.js} +1 -1
  25. package/dist/{catalog-YCU6OHNV.js → catalog-ZAROGOJA.js} +1 -1
  26. package/dist/{catalog-client-MVEEHTG2.js → catalog-client-QLHCEPPZ.js} +1 -1
  27. package/dist/{changelog-5UB3AQT6.js → changelog-6L7W76ZH.js} +1 -1
  28. package/dist/chat-committer-7E3TRZ6P.js +2 -0
  29. package/dist/chat-controller-5ZBG23L6.js +2 -0
  30. package/dist/child-MNLSG77W.js +2 -0
  31. package/dist/{chunk-LRNUGKYH.js → chunk-2CJ75THZ.js} +1 -1
  32. package/dist/{chunk-UWPG5MWM.js → chunk-2EKLTUY2.js} +1 -1
  33. package/dist/{chunk-C4KAPGBS.js → chunk-2KPJ62RZ.js} +3 -3
  34. package/dist/{chunk-SMGRXKXX.js → chunk-2VLM4L3S.js} +1 -1
  35. package/dist/{chunk-ZHAMVLQZ.js → chunk-3A4KK22B.js} +1 -1
  36. package/dist/{chunk-L3BUPFAQ.js → chunk-3CFAE36M.js} +1 -1
  37. package/dist/{chunk-TU2KPOW2.js → chunk-3DFBFYTD.js} +2 -2
  38. package/dist/{chunk-6FFX4S7N.js → chunk-3HGKFRFL.js} +1 -1
  39. package/dist/{chunk-VKVYT6KZ.js → chunk-3JATEWA5.js} +2 -2
  40. package/dist/{chunk-GXQYFOBD.js → chunk-3O2RPYPM.js} +1 -1
  41. package/dist/chunk-3UY4WPMQ.js +8 -0
  42. package/dist/{chunk-6HRNG4CK.js → chunk-3VSAAB2W.js} +1 -1
  43. package/dist/{chunk-RNHSULQM.js → chunk-454IWKHT.js} +1 -1
  44. package/dist/{chunk-ZMWTRXFH.js → chunk-4DRFMDAW.js} +1 -1
  45. package/dist/{chunk-HRIDAK6Y.js → chunk-4FA44D6S.js} +1 -1
  46. package/dist/{chunk-YVVFXBT5.js → chunk-4G2T54FE.js} +1 -1
  47. package/dist/{chunk-N7IWR45S.js → chunk-4KFSSETE.js} +1 -1
  48. package/dist/chunk-4QV2RL6P.js +34 -0
  49. package/dist/{chunk-ERRIDBE7.js → chunk-4WFN23DE.js} +1 -1
  50. package/dist/{chunk-NPAUSUNM.js → chunk-4WKFM72U.js} +1 -1
  51. package/dist/{chunk-BLVDV3QQ.js → chunk-55W3WAAL.js} +1 -1
  52. package/dist/{chunk-YQZ736IQ.js → chunk-56NUPYFG.js} +1 -1
  53. package/dist/{chunk-PI7OXS62.js → chunk-5EAJO372.js} +1 -1
  54. package/dist/{chunk-35WUYKGO.js → chunk-5HJRYEOT.js} +1 -1
  55. package/dist/{chunk-Y3RJHWNK.js → chunk-5OGYXLOR.js} +1 -1
  56. package/dist/{chunk-CQDCNP7V.js → chunk-5ORBAYTU.js} +1 -1
  57. package/dist/{chunk-KKLCXRW6.js → chunk-642LB5R2.js} +1 -1
  58. package/dist/{chunk-OBNVGD5H.js → chunk-662MCICY.js} +1 -1
  59. package/dist/{chunk-PCQK62MP.js → chunk-6CMBA5SG.js} +1 -1
  60. package/dist/{chunk-X6FCXBXU.js → chunk-6FVGPKVX.js} +1 -1
  61. package/dist/{chunk-32HED7X2.js → chunk-6KUUSONE.js} +1 -1
  62. package/dist/{chunk-VCVEZEVS.js → chunk-6PURZLKM.js} +1 -1
  63. package/dist/{chunk-ZCBOHWN3.js → chunk-73EHVDL5.js} +1 -1
  64. package/dist/{chunk-QHH42RH5.js → chunk-7KASYSFM.js} +1 -1
  65. package/dist/{chunk-SJQTTEXQ.js → chunk-7V6JPZBM.js} +1 -1
  66. package/dist/{chunk-WE7HRAGO.js → chunk-7WWCIS2B.js} +1 -1
  67. package/dist/{chunk-M7A66MSK.js → chunk-A74JRNNX.js} +1 -1
  68. package/dist/{chunk-ENRFXGID.js → chunk-ABAUIIPD.js} +1 -1
  69. package/dist/{chunk-YILRYMMG.js → chunk-ABNQL3PQ.js} +1 -1
  70. package/dist/{chunk-GQAWZEA4.js → chunk-ACBNVGVJ.js} +1 -1
  71. package/dist/{chunk-YPGZ5E4I.js → chunk-AFOP7DVG.js} +1 -1
  72. package/dist/{chunk-JTNEF5ZP.js → chunk-AL6IAMYV.js} +1 -1
  73. package/dist/chunk-APXJRWIJ.js +2 -0
  74. package/dist/{chunk-EBJW6POT.js → chunk-ATCJ7EHL.js} +1 -1
  75. package/dist/{chunk-IZ66FKPC.js → chunk-BIGOLVK6.js} +1 -1
  76. package/dist/{chunk-LHJSIHLC.js → chunk-BIXABKSK.js} +1 -1
  77. package/dist/chunk-BK3LWNKB.js +102 -0
  78. package/dist/{chunk-X2MDL6S4.js → chunk-BPTWMV5L.js} +1 -1
  79. package/dist/{chunk-4CJQ7XZP.js → chunk-BV7NUIRT.js} +1 -1
  80. package/dist/{chunk-UJ37XGSP.js → chunk-BXAPTB2H.js} +3 -3
  81. package/dist/{chunk-X7S7IGCV.js → chunk-BXJNL22L.js} +1 -1
  82. package/dist/{chunk-Z24SD2EJ.js → chunk-C3DMMAFP.js} +1 -1
  83. package/dist/chunk-CBEMXSWF.js +2 -0
  84. package/dist/{chunk-IEHJG6J4.js → chunk-CVVZ6NWR.js} +1 -1
  85. package/dist/{chunk-OZNYQONA.js → chunk-DAV4ONGS.js} +3 -3
  86. package/dist/{chunk-MEBEVHGP.js → chunk-DBMDAWTA.js} +1 -1
  87. package/dist/{chunk-CNHKZE4F.js → chunk-DJ76NDW6.js} +1 -1
  88. package/dist/{chunk-ZPU3WAC4.js → chunk-DRWHVVW6.js} +1 -1
  89. package/dist/{chunk-Z47ZEFH7.js → chunk-DXXHCLFC.js} +1 -1
  90. package/dist/{chunk-35BG2EMW.js → chunk-E3C4OWSD.js} +1 -1
  91. package/dist/{chunk-KQ4XKTIZ.js → chunk-ECPSBI2Z.js} +1 -1
  92. package/dist/{chunk-X45RZIAJ.js → chunk-EG3B52WU.js} +1 -1
  93. package/dist/{chunk-EJGCIGQY.js → chunk-EOLMWSLX.js} +1 -1
  94. package/dist/{chunk-GAKBHNC4.js → chunk-EUGFABAS.js} +1 -1
  95. package/dist/{chunk-OTMHCHH6.js → chunk-EWK3UPEN.js} +1 -1
  96. package/dist/{chunk-NI3TIAD7.js → chunk-EWSNJ3IX.js} +1 -1
  97. package/dist/{chunk-SALZ6WSF.js → chunk-F4XCCOWC.js} +1 -1
  98. package/dist/{chunk-YNDELIXL.js → chunk-FH4FWIET.js} +1 -1
  99. package/dist/chunk-FQ2AMM3E.js +3 -0
  100. package/dist/{chunk-5YYCCM6K.js → chunk-FTP2K6RS.js} +1 -1
  101. package/dist/{chunk-JBKHX5ES.js → chunk-GJYMR4RT.js} +1 -1
  102. package/dist/{chunk-NHGPMYM3.js → chunk-GMSWZIAS.js} +1 -1
  103. package/dist/{chunk-AHT2ORJT.js → chunk-GPIVYCHQ.js} +1 -1
  104. package/dist/{chunk-ZDCXWEQG.js → chunk-GRQKMOKE.js} +1 -1
  105. package/dist/{chunk-E4GIGM5V.js → chunk-H6IPGZTP.js} +1 -1
  106. package/dist/{chunk-7Y55CO42.js → chunk-H6QHG62O.js} +1 -1
  107. package/dist/{chunk-MINDIQET.js → chunk-HBGYEA3O.js} +1 -1
  108. package/dist/{chunk-VO2NNXKR.js → chunk-HGKAUG7L.js} +1 -1
  109. package/dist/{chunk-Q4SMITTV.js → chunk-HMGM4KO6.js} +1 -1
  110. package/dist/{chunk-CTHUX7O4.js → chunk-I3G3IUKY.js} +1 -1
  111. package/dist/{chunk-MD3RABID.js → chunk-IDWAG6L4.js} +1 -1
  112. package/dist/{chunk-TM6VLC6V.js → chunk-IPIARGHE.js} +1 -1
  113. package/dist/chunk-IQMJJN52.js +3 -0
  114. package/dist/{chunk-WEJR2V7R.js → chunk-J3XOEMKO.js} +1 -1
  115. package/dist/{chunk-GJXO6FF7.js → chunk-JBUKEIYL.js} +1 -1
  116. package/dist/{chunk-7RELCXRW.js → chunk-JE5M5QIK.js} +1 -1
  117. package/dist/{chunk-QEM5ZRDN.js → chunk-JJDD4HPX.js} +1 -1
  118. package/dist/{chunk-NRAPCFI2.js → chunk-JM45SLKV.js} +2 -2
  119. package/dist/{chunk-GEZVC4S3.js → chunk-JM6AKCN4.js} +1 -1
  120. package/dist/{chunk-3KY7HHQU.js → chunk-JSSM2TWY.js} +1 -1
  121. package/dist/{chunk-3MD2XLE7.js → chunk-JYSIPTX3.js} +9 -8
  122. package/dist/{chunk-AVLYSNEG.js → chunk-KJZD2ADR.js} +1 -1
  123. package/dist/chunk-KLY6IQD5.js +26 -0
  124. package/dist/{chunk-LTPOMMAB.js → chunk-LB5NIDW6.js} +1 -1
  125. package/dist/{chunk-HV2CDY4K.js → chunk-LCBDNZL3.js} +1 -1
  126. package/dist/{chunk-SIHX5FW5.js → chunk-LJKTIKZY.js} +1 -1
  127. package/dist/{chunk-SXBPUUQ5.js → chunk-LLDEAV3W.js} +1 -1
  128. package/dist/{chunk-PTLOOVV4.js → chunk-LV7OWLJK.js} +1 -1
  129. package/dist/{chunk-TUSG7DIL.js → chunk-MNELOQ4J.js} +1 -1
  130. package/dist/{chunk-3ZC7GSMM.js → chunk-MOAZZKIZ.js} +1 -1
  131. package/dist/{chunk-YWWVF5OU.js → chunk-MQU6EA44.js} +1 -1
  132. package/dist/chunk-MTMHB5LF.js +2 -0
  133. package/dist/{chunk-Q4ALB7SH.js → chunk-MWLRLQ27.js} +1 -1
  134. package/dist/{chunk-OHGL4GEJ.js → chunk-MZ4GTIO2.js} +1 -1
  135. package/dist/chunk-NKJRAQ6L.js +6 -0
  136. package/dist/{chunk-LPJKNX6D.js → chunk-NMCE7VR2.js} +1 -1
  137. package/dist/{chunk-7V34ZMMS.js → chunk-OKCVG7AG.js} +1 -1
  138. package/dist/{chunk-LZGAFKYH.js → chunk-OMCJD4LH.js} +1 -1
  139. package/dist/{chunk-OOGKX4Y6.js → chunk-OSEXVHEN.js} +1 -1
  140. package/dist/{chunk-EZMRWXRT.js → chunk-OVB5GVRB.js} +1 -1
  141. package/dist/{chunk-ND6OP3O2.js → chunk-OX3ZAGCH.js} +1 -1
  142. package/dist/{chunk-LXK4B2FE.js → chunk-P43YHCF3.js} +1 -1
  143. package/dist/{chunk-ZMIKNNO6.js → chunk-P7V24ZXP.js} +1 -1
  144. package/dist/{chunk-3NWUXRSI.js → chunk-PBVNX43X.js} +1 -1
  145. package/dist/{chunk-MEMXFTLD.js → chunk-PEHVBCXM.js} +1 -1
  146. package/dist/{chunk-4UX5N7YI.js → chunk-PHKJIJ7D.js} +1 -1
  147. package/dist/{chunk-BBJAKSA7.js → chunk-PMYN3XMN.js} +2 -2
  148. package/dist/{chunk-R6TFRAMZ.js → chunk-PUNFWBRW.js} +1 -1
  149. package/dist/chunk-Q5B54TR5.js +2 -0
  150. package/dist/{chunk-KCXLRR3Q.js → chunk-QEBVYQNC.js} +1 -1
  151. package/dist/{chunk-PB6RXDWQ.js → chunk-QFA6JPVE.js} +2 -2
  152. package/dist/{chunk-TAY7J5VS.js → chunk-QLGQDNA3.js} +1 -1
  153. package/dist/{chunk-7SU53QGU.js → chunk-QOXUGYEA.js} +1 -1
  154. package/dist/{chunk-LV7224DG.js → chunk-QXZGBYGQ.js} +1 -1
  155. package/dist/{chunk-4KL3TSTT.js → chunk-QYWWL7M7.js} +4 -4
  156. package/dist/{chunk-M2E5CPPV.js → chunk-RG3FNO37.js} +1 -1
  157. package/dist/{chunk-YCVEI7BT.js → chunk-RNKJXVG2.js} +1 -1
  158. package/dist/{chunk-HBLHKQR7.js → chunk-S5PIVHPC.js} +1 -1
  159. package/dist/{chunk-LUA25RYS.js → chunk-S74NLCFZ.js} +1 -1
  160. package/dist/chunk-SBW3QVHN.js +7 -0
  161. package/dist/{chunk-2TK4MDF2.js → chunk-SMSQVGLH.js} +1 -1
  162. package/dist/{chunk-Y2HQMJGS.js → chunk-SO3IXFAJ.js} +1 -1
  163. package/dist/{chunk-T77LTLAD.js → chunk-SULRMI2J.js} +1 -1
  164. package/dist/{chunk-KL7XFNSD.js → chunk-SZQNYDST.js} +1 -1
  165. package/dist/chunk-T5FQRUI2.js +47 -0
  166. package/dist/{chunk-HVOXMCKE.js → chunk-TCK7WR3M.js} +1 -1
  167. package/dist/{chunk-OCMPWCKQ.js → chunk-TELSHQ3W.js} +1 -1
  168. package/dist/{chunk-FOLUB336.js → chunk-TFSWG7AS.js} +1 -1
  169. package/dist/{chunk-2JFRN62I.js → chunk-TLYFHPNM.js} +2 -2
  170. package/dist/{chunk-CB2BWDHG.js → chunk-TO2ROHIJ.js} +4 -4
  171. package/dist/{chunk-PRBWZXFA.js → chunk-TOOJTCON.js} +6 -6
  172. package/dist/{chunk-DQXQJJOP.js → chunk-TXRWH6HL.js} +2 -2
  173. package/dist/chunk-U5V3L5QH.js +2 -0
  174. package/dist/{chunk-WIVKLNIO.js → chunk-UVBPUZC4.js} +1 -1
  175. package/dist/{chunk-23DKB2MT.js → chunk-UVL6XQHU.js} +1 -1
  176. package/dist/{chunk-DC5F2ADJ.js → chunk-UZKVV3LW.js} +1 -1
  177. package/dist/{chunk-YDB72F4K.js → chunk-V4SL74TK.js} +1 -1
  178. package/dist/chunk-V57R4X3O.js +5 -0
  179. package/dist/{chunk-LLQWEGXD.js → chunk-W5EDS4DF.js} +1 -1
  180. package/dist/{chunk-6QH75BPJ.js → chunk-WB4JZ67W.js} +1 -1
  181. package/dist/{chunk-W54BX6HC.js → chunk-WCIRLITM.js} +1 -1
  182. package/dist/{chunk-OCVDMZWB.js → chunk-WHMCVH3T.js} +1 -1
  183. package/dist/{chunk-XKOVEMVZ.js → chunk-WMIR4UXG.js} +1 -1
  184. package/dist/chunk-WMXBRC4B.js +21 -0
  185. package/dist/{chunk-RQKMSNEU.js → chunk-WTMCDYR3.js} +1 -1
  186. package/dist/{chunk-DXIQVBMI.js → chunk-WZ3FE5MT.js} +1 -1
  187. package/dist/{chunk-3RO2YGKH.js → chunk-X3O4VGTM.js} +1 -1
  188. package/dist/{chunk-GLM5UGTF.js → chunk-X66NIHT4.js} +1 -1
  189. package/dist/{chunk-B7ZX5HEN.js → chunk-XDAFRUAJ.js} +1 -1
  190. package/dist/{chunk-JNPFEBUR.js → chunk-XDAHKZ4J.js} +1 -1
  191. package/dist/{chunk-ZCL7XIVS.js → chunk-XKJZG4GR.js} +1 -1
  192. package/dist/chunk-XTQUCCJH.js +2 -0
  193. package/dist/{chunk-SVIIUKJ2.js → chunk-Y7GSOKXS.js} +1 -1
  194. package/dist/chunk-YIBLZIXF.js +13 -0
  195. package/dist/{chunk-J4FIESTB.js → chunk-YKOZBFR3.js} +1 -1
  196. package/dist/{chunk-TM45NPWL.js → chunk-YWQNZRJG.js} +1 -1
  197. package/dist/chunk-YZP4F23B.js +18 -0
  198. package/dist/{chunk-QE4AWNOV.js → chunk-Z4O5HOFX.js} +6 -6
  199. package/dist/{chunk-KBGMQYMD.js → chunk-ZFKR5I3J.js} +1 -1
  200. package/dist/{chunk-6QCCTZO3.js → chunk-ZHENGHYZ.js} +1 -1
  201. package/dist/{chunk-SSOUYKVG.js → chunk-ZIRSTOEV.js} +1 -1
  202. package/dist/{chunk-AT7AT3AR.js → chunk-ZVSZ6DIQ.js} +5 -5
  203. package/dist/command-span-HZSKIZH7.js +2 -0
  204. package/dist/commands-X5T6YANK.js +2 -0
  205. package/dist/{committer-UO3B3S5Y.js → committer-L2HXEODA.js} +1 -1
  206. package/dist/{config-7WTZPMAH.js → config-F5Q6QX27.js} +1 -1
  207. package/dist/cover-cmd-PWUZU4HK.js +2 -0
  208. package/dist/{credentials-5WIFF5DG.js → credentials-D5KQMHCK.js} +1 -1
  209. package/dist/{deps-bundle-BLLJ2BQ4.js → deps-bundle-R7FNIV4M.js} +1 -1
  210. package/dist/{deps-resolve-WQ6J6RLI.js → deps-resolve-IF6P6NWI.js} +1 -1
  211. package/dist/design-chat-HYK3HNIM.js +2 -0
  212. package/dist/{design-committer-7YIPFKMO.js → design-committer-ZKNW5LUS.js} +1 -1
  213. package/dist/design-headless-DR7WB37W.js +2 -0
  214. package/dist/design-remote-TGUNEWEM.js +3 -0
  215. package/dist/device-env-LZB3PKMA.js +2 -0
  216. package/dist/dispatch-BGH5PVZ4.js +2 -0
  217. package/dist/doctor-PLFEA2HM.js +2 -0
  218. package/dist/{docx-convert-DO5AQYD3.js → docx-convert-PA5S2S7P.js} +1 -1
  219. package/dist/{dossier-5XKNAK6Q.js → dossier-B6KBSRJY.js} +1 -1
  220. package/dist/evidence-SRWISQMQ.js +2 -0
  221. package/dist/evolve-cmd-2BALEYZU.js +2 -0
  222. package/dist/evolve-remote-OHOUWO65.js +2 -0
  223. package/dist/exit-manager-UZ7DGXS4.js +2 -0
  224. package/dist/{explain-cmd-KNDORU2D.js → explain-cmd-A5YMPXAJ.js} +1 -1
  225. package/dist/explain-cmd-VTDAMXAW.js +12 -0
  226. package/dist/explore-UZWQRJ7H.js +2 -0
  227. package/dist/explore-context-tty-PAKJVDJU.js +2 -0
  228. package/dist/explore-entry-ZOPO7DBZ.js +6 -0
  229. package/dist/{explore-live-XIWWUV52.js → explore-live-RUAAZGX4.js} +1 -1
  230. package/dist/{explore-run-tty-M56I23IF.js → explore-run-tty-DYLMHI7F.js} +2 -2
  231. package/dist/{extract-bind-LZ22VFKB.js → extract-bind-WPICR4IC.js} +3 -3
  232. package/dist/extract-chat-KVUB5HPM.js +2 -0
  233. package/dist/{extract-cmd-46E2XDWZ.js → extract-cmd-OJ7LXSKL.js} +2 -2
  234. package/dist/extract-headless-OQJSUSG4.js +2 -0
  235. package/dist/{feeder-NGWIPZ26.js → feeder-VAY4NYBX.js} +1 -1
  236. package/dist/folder-flags-MEZUAXTT.js +2 -0
  237. package/dist/gaps-cmd-2R4RMWN6.js +3 -0
  238. package/dist/gate-SM4HPJLA.js +2 -0
  239. package/dist/gate-VJ7W5QIH.js +2 -0
  240. package/dist/{generate-headless-HXAVEAEZ.js → generate-headless-XR3RVULC.js} +3 -3
  241. package/dist/hold-passthrough-ZHOC2Q26.js +2 -0
  242. package/dist/identity-66TGWITQ.js +2 -0
  243. package/dist/{impact-cmd-TJTUFAFO.js → impact-cmd-EL3QSOAF.js} +2 -2
  244. package/dist/index.js +185 -184
  245. package/dist/ingest-6UQGSQYU.js +2 -0
  246. package/dist/ingest-cmd-N3USC7TW.js +8 -0
  247. package/dist/ingest-remote-2VKWAFJZ.js +2 -0
  248. package/dist/install-3IEM3I3X.js +2 -0
  249. package/dist/{interactive-bind-SOD7VTAY.js → interactive-bind-F7QTQOKC.js} +4 -4
  250. package/dist/{interactive-remote-7ZSTI66T.js → interactive-remote-A33J4KMP.js} +2 -2
  251. package/dist/lane-EHU4JRRU.js +2 -0
  252. package/dist/lattice-auth-IJT542IF.js +2 -0
  253. package/dist/lifecycle-cmd-OKUFZKEX.js +2 -0
  254. package/dist/list-cmd-7OTI66MQ.js +3 -0
  255. package/dist/list-commands-FZPVH76I.js +2 -0
  256. package/dist/{list-remote-EFCET42K.js → list-remote-BQ4NILCA.js} +1 -1
  257. package/dist/{locks-cmd-AZKCSGHI.js → locks-cmd-76IU4JB7.js} +1 -1
  258. package/dist/{logical-ids-74PLU3VR.js → logical-ids-YMNV2MDB.js} +1 -1
  259. package/dist/login-flow-BYQ7SYGB.js +2 -0
  260. package/dist/maintenance-cmd-BLV7K4RK.js +2 -0
  261. package/dist/mobile-prompts-5TGLJUBV.js +2 -0
  262. package/dist/onboarding-F4EIJ4GD.js +5 -0
  263. package/dist/open-provider-LXCPVNUU.js +2 -0
  264. package/dist/{pdf-convert-YB6PJFMI.js → pdf-convert-N2C3KB4Q.js} +1 -1
  265. package/dist/persist-recorded-session-WYMOHDTB.js +3 -0
  266. package/dist/phase-seed-G5JSYKSL.js +2 -0
  267. package/dist/pipeline-XYM6HIDZ.js +2 -0
  268. package/dist/{policy-commands-4PUGESCW.js → policy-commands-AOLVAZZD.js} +1 -1
  269. package/dist/prepare-target-P4AZWC37.js +2 -0
  270. package/dist/pull-cmd-C4HMYD4I.js +2 -0
  271. package/dist/pull-route-MHW5PWDW.js +2 -0
  272. package/dist/readmodel-FARAAPUU.js +2 -0
  273. package/dist/real-device-run-WAOWKEFJ.js +2 -0
  274. package/dist/reconcile-cmd-VXY737OT.js +5 -0
  275. package/dist/reconcile-deps-TILDRCHG.js +2 -0
  276. package/dist/{reconcile-remote-3W6ZTO3G.js → reconcile-remote-UGW2433E.js} +2 -2
  277. package/dist/recording-banner-EPOTSMYF.js +2 -0
  278. package/dist/registry-WTWTFRXD.js +2 -0
  279. package/dist/remote-entry-SPA4CSJJ.js +2 -0
  280. package/dist/remote-mode-QO6BDGXM.js +4 -0
  281. package/dist/remote-words-TAZT4YBT.js +2 -0
  282. package/dist/{require-project-folder-3DTI2CVB.js → require-project-folder-WBCAVVMB.js} +1 -1
  283. package/dist/resolve-run-intent-RBOCIYEA.js +2 -0
  284. package/dist/{resolver-CDF7QKVD.js → resolver-3BGIXYYJ.js} +1 -1
  285. package/dist/revert-F6MKJ73M.js +2 -0
  286. package/dist/review-cmd-WE6I5XTY.js +5 -0
  287. package/dist/run-EABFRFOF.js +2 -0
  288. package/dist/run-LX3ARF53.js +2 -0
  289. package/dist/run-remote-6Y62RWMJ.js +2 -0
  290. package/dist/run-startup-gate-Q7FP2IRE.js +2 -0
  291. package/dist/run-test-md-24MBKBC6.js +20 -0
  292. package/dist/session-worker.js +2 -2
  293. package/dist/{sessions-cmd-TLUITRG5.js → sessions-cmd-5NS5P4CP.js} +2 -2
  294. package/dist/{sessions-remote-INO7AWKB.js → sessions-remote-75PDRPOY.js} +1 -1
  295. package/dist/{skill-installer-7JH5QCJF.js → skill-installer-7PK64TZE.js} +1 -1
  296. package/dist/store-AVYBL5HB.js +2 -0
  297. package/dist/store-choice-ZWU3PDNL.js +2 -0
  298. package/dist/store-guard-ETUXXG7X.js +2 -0
  299. package/dist/{store-site-K5NHLI7D.js → store-site-AFXB6SBW.js} +1 -1
  300. package/dist/{stream-warnings-GM7YEOVG.js → stream-warnings-I5LUWVFU.js} +1 -1
  301. package/dist/support-id-RISKXA53.js +2 -0
  302. package/dist/sync-cmd-CSTMT6E6.js +2 -0
  303. package/dist/sync-setup-Y53K6TJ6.js +2 -0
  304. package/dist/tcg-generate-VQLI6NGK.js +2 -0
  305. package/dist/{test-definition-53XNBEDE.js → test-definition-GXEKFRRB.js} +1 -1
  306. package/dist/testmd-actions-BE4YJ6ZZ.js +2 -0
  307. package/dist/{testmd-sync-LYHEXWCT.js → testmd-sync-QZWVWTZZ.js} +1 -1
  308. package/dist/token-refresh-PZ3TOKAL.js +2 -0
  309. package/dist/{use-case-ref-44BPIP4N.js → use-case-ref-E3PJDHQB.js} +1 -1
  310. package/dist/{validate-basic-66XDPA3S.js → validate-basic-QWPESO74.js} +1 -1
  311. package/dist/verdicts-KB6YTIY6.js +2 -0
  312. package/dist/{version-check-SHNVYTMU.js → version-check-EOYWTY3Z.js} +1 -1
  313. package/dist/{view-cmd-QOB3O6YW.js → view-cmd-KG4HI334.js} +1 -1
  314. package/dist/walk-session-WM4S2JMV.js +2 -0
  315. package/dist/with-telemetry-RJM3JKL6.js +2 -0
  316. package/package.json +11 -11
  317. package/dist/ChatSurface-Z26BOE5U.js +0 -2
  318. package/dist/ChromeProfilePicker-ODRIAXL3.js +0 -2
  319. package/dist/EvidenceViewOffer-6344EX74.js +0 -2
  320. package/dist/FolderPicker-4PCYHE75.js +0 -2
  321. package/dist/InfoBox-NJ2DL7YC.js +0 -2
  322. package/dist/LinksBox-HNDNFVUT.js +0 -2
  323. package/dist/ProfilesView-DEJKJOHY.js +0 -2
  324. package/dist/ProjectPicker-DTWMWOH7.js +0 -2
  325. package/dist/SaveSessionPrompt-3GCLB3ZT.js +0 -2
  326. package/dist/SingleShotApp-HMOXO5DW.js +0 -2
  327. package/dist/SummaryBox-7PPDMSSM.js +0 -2
  328. package/dist/TestMdRunView-QLKRUU4V.js +0 -2
  329. package/dist/TestrunEvidenceTable-T2JUB4TE.js +0 -2
  330. package/dist/app-download-GKRF2EIM.js +0 -2
  331. package/dist/bind-SSHAZAB3.js +0 -2
  332. package/dist/bootstrap-XGKU4WXB.js +0 -2
  333. package/dist/chat-committer-ZKEKJA2R.js +0 -2
  334. package/dist/chat-controller-FXRJXUG3.js +0 -2
  335. package/dist/child-JHYENXE7.js +0 -2
  336. package/dist/chunk-2RBMQTYS.js +0 -26
  337. package/dist/chunk-5F5IVART.js +0 -8
  338. package/dist/chunk-6SD4XTYC.js +0 -6
  339. package/dist/chunk-7YV2FCN4.js +0 -3
  340. package/dist/chunk-A2DODRHG.js +0 -2
  341. package/dist/chunk-BJO6J5X2.js +0 -3
  342. package/dist/chunk-DIOK3SER.js +0 -34
  343. package/dist/chunk-DREQ3RAA.js +0 -2
  344. package/dist/chunk-HC6VLPUB.js +0 -5
  345. package/dist/chunk-NZJSGINB.js +0 -47
  346. package/dist/chunk-SXRHKXSE.js +0 -2
  347. package/dist/chunk-UJLULWSR.js +0 -21
  348. package/dist/chunk-ULIIYKZB.js +0 -7
  349. package/dist/chunk-UXGMKRS4.js +0 -102
  350. package/dist/chunk-VO66KP2W.js +0 -2
  351. package/dist/chunk-X52YIWGG.js +0 -13
  352. package/dist/chunk-ZIHQ5JGB.js +0 -18
  353. package/dist/commands-JBFLLT7A.js +0 -2
  354. package/dist/cover-cmd-DU6ZYJFL.js +0 -2
  355. package/dist/design-chat-ZICGVYIH.js +0 -2
  356. package/dist/design-headless-HYWZIIDS.js +0 -2
  357. package/dist/design-remote-HPX4VZ63.js +0 -3
  358. package/dist/device-env-4P4GUVBW.js +0 -2
  359. package/dist/dispatch-BV6XMCN3.js +0 -2
  360. package/dist/doctor-Z2YQ2DBX.js +0 -2
  361. package/dist/evidence-BJIID6VT.js +0 -2
  362. package/dist/evolve-cmd-GZCUSCEK.js +0 -2
  363. package/dist/evolve-remote-LILOAHYH.js +0 -2
  364. package/dist/exit-manager-EGWAZHCR.js +0 -2
  365. package/dist/explain-cmd-LXIVHGN7.js +0 -12
  366. package/dist/explore-SA2P3SGX.js +0 -2
  367. package/dist/explore-context-tty-PERKIWXD.js +0 -2
  368. package/dist/explore-entry-E6EY3VV3.js +0 -6
  369. package/dist/extract-chat-Z64LEAJ5.js +0 -2
  370. package/dist/extract-headless-XLS56LMN.js +0 -2
  371. package/dist/folder-flags-ZIDJVDKX.js +0 -2
  372. package/dist/gaps-cmd-XYOBJVTO.js +0 -3
  373. package/dist/gate-AK44VDHC.js +0 -2
  374. package/dist/gate-NB5CJMTN.js +0 -2
  375. package/dist/hold-passthrough-JGHWMYDM.js +0 -2
  376. package/dist/identity-HL5CJJXR.js +0 -2
  377. package/dist/ingest-ZHHHBUXR.js +0 -2
  378. package/dist/ingest-cmd-OJSKTSQK.js +0 -8
  379. package/dist/ingest-remote-2WM6PYUW.js +0 -2
  380. package/dist/install-JBWBF3WX.js +0 -2
  381. package/dist/lane-CNGO7LH5.js +0 -2
  382. package/dist/lattice-auth-UQPFQSG7.js +0 -2
  383. package/dist/lifecycle-cmd-DGIO3VAO.js +0 -2
  384. package/dist/list-cmd-HQIN3HX4.js +0 -3
  385. package/dist/list-commands-OFRRBU3D.js +0 -2
  386. package/dist/login-flow-SYKXXDLH.js +0 -2
  387. package/dist/maintenance-cmd-X5247RSJ.js +0 -2
  388. package/dist/mobile-prompts-I66ENBDW.js +0 -2
  389. package/dist/onboarding-6HIP3KW6.js +0 -5
  390. package/dist/open-provider-XDJKT3W3.js +0 -2
  391. package/dist/persist-recorded-session-RSSMTVF3.js +0 -3
  392. package/dist/phase-seed-ZZSJME7M.js +0 -2
  393. package/dist/pipeline-NTJDH5TC.js +0 -2
  394. package/dist/prepare-target-AI3GGZF6.js +0 -2
  395. package/dist/pull-cmd-NRVB5ZN7.js +0 -2
  396. package/dist/pull-route-FWCZW76M.js +0 -2
  397. package/dist/readmodel-TRV4E3MW.js +0 -2
  398. package/dist/real-device-run-NQ7RNH7C.js +0 -2
  399. package/dist/reconcile-cmd-7B7THAFJ.js +0 -5
  400. package/dist/reconcile-deps-UDQBWSLE.js +0 -2
  401. package/dist/recording-banner-WVDTWTSE.js +0 -2
  402. package/dist/registry-PFOSXOIH.js +0 -2
  403. package/dist/remote-entry-BZU4NFNS.js +0 -2
  404. package/dist/remote-mode-NXUKDUXG.js +0 -4
  405. package/dist/remote-words-JRDDNOZ6.js +0 -2
  406. package/dist/resolve-run-intent-QCL7QXIB.js +0 -2
  407. package/dist/revert-QKHPCRT6.js +0 -2
  408. package/dist/review-cmd-XBK3TGRE.js +0 -5
  409. package/dist/run-CSYGVV3D.js +0 -2
  410. package/dist/run-YUHHD54J.js +0 -2
  411. package/dist/run-remote-SFR3F2T5.js +0 -2
  412. package/dist/run-startup-gate-QSFJRYUY.js +0 -2
  413. package/dist/run-test-md-ZSREINDQ.js +0 -20
  414. package/dist/store-X4UK4AP7.js +0 -2
  415. package/dist/store-choice-27HDIFTU.js +0 -2
  416. package/dist/store-guard-ZXKB5DQH.js +0 -2
  417. package/dist/sync-cmd-2PCO7LZA.js +0 -2
  418. package/dist/sync-setup-5WQO73Y5.js +0 -2
  419. package/dist/tcg-generate-DGJD5KSM.js +0 -2
  420. package/dist/testmd-actions-XE2JPQHB.js +0 -2
  421. package/dist/token-refresh-E4FTJVHY.js +0 -2
  422. package/dist/verdicts-PVB7TV5S.js +0 -2
  423. package/dist/walk-session-WIEROYOT.js +0 -2
  424. package/dist/with-telemetry-T2PWI5CY.js +0 -2
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as A,b as T,c as $,d as x,e as c,h as F}from"./chunk-ZDCXWEQG.js";import{f as k,l as v,q as E}from"./chunk-Z24SD2EJ.js";import{M as S,j as N,m as U,n as O}from"./chunk-PI7OXS62.js";import{d as m}from"./chunk-DBMW3VUN.js";import{existsSync as R,readFileSync as H,statSync as M}from"fs";var B=t=>{try{return R(t)&&M(t).isFile()}catch{return!1}},C=t=>N(t)&&A.test(t);async function y(t,n,o,l){let e=t.manifest.id,s,a=new Promise((r,d)=>{s=setTimeout(()=>d(new $({code:"PLUGIN_HOOK_TIMEOUT",message:`plugin ${e} did not answer ${n} within ${Math.round(o/1e3)} seconds`,plugin:e,hook:n})),o)});try{return await Promise.race([Promise.resolve().then(l),a])}catch(r){throw r instanceof $?r:r instanceof T?new $({code:"PLUGIN_REFUSED",message:r.message,plugin:e,hook:n,...r.remedy?{remedy:r.remedy}:{}}):new $({code:"PLUGIN_HOOK_FAILED",message:`plugin ${e} failed in ${n}: ${r instanceof Error?r.message:String(r)}`,plugin:e,hook:n})}finally{clearTimeout(s)}}async function ee(t){let{plugin:n,ref:o,named:l}=t,e=n.manifest.id,s=t.hookMs??m.hookMs,a=t.isFile??B(o),r=!a&&x(n).includes("remote")&&typeof n.fetch=="function",d=l?`${e}:${o}`:o,I=r?O(d):null;I!==null&&c("PLUGIN_REF_INVALID",`${d.length>80?`${d.slice(0,80)}\u2026`:d} cannot be recorded as a reference: ${I}`,{plugin:e,remedy:`give the source as <scheme>:<rest>, one word of at most ${U} characters`});let h=await y(n,"claim",s,()=>n.claim({ref:o,named:l,isFile:a}));h==null&&c("PLUGIN_NOT_CLAIMED",`plugin ${e} does not read ${o}`,{plugin:e,hook:"claim",remedy:l?`drop the ${e}: prefix, or name the plugin that reads it`:"ingest it as a file of a built-in kind"}),(typeof h!="object"||typeof h.sourceId!="string")&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered claim with something that is not a claim`,{plugin:e,hook:"claim"});let p=t.asId??h.sourceId,b=h.recorded;if(r&&b!==void 0){(typeof b!="string"||b==="")&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered claim with a recorded reference that is not one`,{plugin:e,hook:"claim"});let i=l?`${e}:${b}`:b,u=O(i);u!==null&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${i.length>80?`${i.slice(0,80)}\u2026`:i}, which cannot be recorded as a reference: ${u}`,{plugin:e,hook:"claim"});let f=(t.registry??F()).route(i,()=>!1);(f===null||f.plugin.manifest.id!==e)&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${i.length>80?`${i.slice(0,80)}\u2026`:i}, which ${f===null?"no plugin reads":`plugin ${f.plugin.manifest.id} reads`}: a recorded reference must route back to the plugin that read it`,{plugin:e,hook:"claim"});let w=await y(n,"claim",s,()=>n.claim({ref:f.ref,named:f.named,isFile:!1}));(w==null||typeof w!="object"||w.sourceId!==h.sourceId)&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${b} for ${h.sourceId}, but claiming it again ${w?`gives ${String(w.sourceId)}`:"is refused"}: a recorded reference must name the same source`,{plugin:e,hook:"claim"}),d=i}C(p)||c("PLUGIN_SOURCE_ID_INVALID",`${JSON.stringify(p)} is not an id a source may have: it starts with a letter or digit and holds letters, digits and . _ -, at most 128 characters`,{plugin:e,hook:"claim",remedy:t.asId===void 0?"give the source an id with --as <id>":"give another id with --as <id>"});let g,L;if(!a&&t.supplied!==void 0){r||c("PLUGIN_REMOTE_UNAVAILABLE",`${o} is not a file on this machine, and plugin ${e} has no connection to fetch it through`,{plugin:e,remedy:"save the source to a file and ingest the file"}),g=Buffer.from(t.supplied.bytes),g.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`${o} is ${g.byteLength} bytes; a plugin's source may be at most ${m.contentBytes}`,{plugin:e,hook:"fetch"});let i=t.supplied.cursor??null;L={ref:d,...i!==null?{cursor:i}:{}}}else if(a)g=t.supplied!==void 0?Buffer.from(t.supplied.bytes):H(o),g.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`${o} is ${g.byteLength} bytes; a plugin's source may be at most ${m.contentBytes}`,{plugin:e});else{let i=r?t.connect?.(e):void 0;i===void 0&&c("PLUGIN_REMOTE_UNAVAILABLE",`${o} is not a file on this machine, and plugin ${e} has no connection to fetch it through`,{plugin:e,remedy:"save the source to a file and ingest the file"});let u=t.cursor!==void 0?t.cursor:j(t.store,p,e,d),f=await D(n,i,{ref:o,sourceId:p,cursor:u},s);if(f.kind==="unchanged")return K(t.store,p,e);g=f.bytes,L={ref:d,...f.cursor!==null?{cursor:f.cursor}:{}},t.onFetched?.({bytes:new Uint8Array(g),cursor:f.cursor})}let _={sourceId:p,bytes:new Uint8Array(g)},G=async()=>{let u=(await y(n,"render",s,()=>n.render(_)))?.text;(typeof u!="string"||u===""||u.includes("\0"))&&c("PLUGIN_TEXT_INVALID",`plugin ${e} rendered ${p} to something that is not text: ${typeof u!="string"?"no text":u===""?"empty text":"text holding a NUL"}`,{plugin:e,hook:"render"});let f=await y(n,"index",s,()=>n.index(_,{text:u}));return{projection:u,inventory:[],blobs:new Map,delivered:[],converter:{name:e,version:n.manifest.version,policy:`rules-${n.manifest.rules}`},units:f}},P=x(n);return E({store:t.store,bytes:g,media:k,sourceId:p,label:o,plugin:{id:e,rules:n.manifest.rules,...L!==void 0?{fetch:L}:{},...P.includes("cites-deep")?{citesDeep:!0}:{}},converters:{plugin:G},...P.includes("explain")&&typeof n.explain=="function"?{explain:(i,u)=>y(n,"explain",Math.min(u,s),()=>n.explain(i))}:{},...t.explainMs!==void 0?{explainMs:t.explainMs}:{},...P.includes("context")&&typeof n.context=="function"?{context:(i,u)=>y(n,"context",Math.min(u,s),()=>n.context({..._,text:i.text,units:i.units}))}:{},...P.includes("coverage")&&typeof n.coverage=="function"?{coverage:(i,u)=>y(n,"coverage",Math.min(u,s),()=>n.coverage({sourceId:_.sourceId,units:i.units}))}:{},...t.confirmSameSource?{confirmSameSource:t.confirmSameSource}:{},...t.eventIds?{eventIds:t.eventIds}:{},...t.provenance?{provenance:t.provenance}:{}})}async function D(t,n,o,l){let e=t.manifest.id,s;try{s=await y(t,"fetch",l,()=>t.fetch({...o,connection:n}))}catch(h){throw n.breach?n.breach:h}finally{n.close()}if(n.breach)throw n.breach;let a=s?.kind;if(a==="unchanged")return{kind:"unchanged"};let r=s;(a!=="content"||!(r.bytes instanceof Uint8Array))&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered fetch with something that is not an answer: neither the content, with its bytes, nor "unchanged"`,{plugin:e,hook:"fetch"});let d=Buffer.from(r.bytes);d.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`plugin ${e} fetched ${d.byteLength} bytes for ${o.ref}; a plugin's source may be at most ${m.contentBytes}`,{plugin:e,hook:"fetch"}),r.cursor!==void 0&&typeof r.cursor!="string"&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered fetch with a cursor that is not a string`,{plugin:e,hook:"fetch"});let I=r.cursor===void 0?null:r.cursor;return I!==null&&Buffer.byteLength(I,"utf8")>m.cursorBytes&&c("PLUGIN_CURSOR_TOO_LARGE",`plugin ${e} answered fetch with a cursor of ${Buffer.byteLength(I,"utf8")} bytes; a cursor may be at most ${m.cursorBytes}`,{plugin:e,hook:"fetch",remedy:"the plugin must be fixed: every later fetch of this source starts from the same cursor and is refused the same way"}),{kind:"content",bytes:d,cursor:I}}function K(t,n,o){let l=S(t),e=l.heads.get(n);typeof e!="string"&&c("PLUGIN_HOOK_FAILED",`plugin ${o} answered fetch with "unchanged" for ${n}, which this store holds no current version of`,{plugin:o,hook:"fetch"});let s=l.mediaOf(e),a=v(n,s.format==="plugin"?s.plugin?.id??"":null,o,!1);if(a!==void 0)throw new Error(a);let r=l.getNode(e)?.content.blob;return{status:"unchanged",source_id:n,cid:e,blob:typeof r=="string"?r:""}}function j(t,n,o,l){let e=S(t),s=e.heads.get(n);if(typeof s!="string")return null;let a=e.mediaOf(s).plugin;return a?.id!==o||a.fetch?.ref!==l?null:a.fetch.cursor??null}export{B as a,C as b,y as c,ee as d};
2
+ import{a as A,b as T,c as $,d as x,e as c,h as F}from"./chunk-GRQKMOKE.js";import{f as k,l as v,q as E}from"./chunk-C3DMMAFP.js";import{M as S,j as N,m as U,n as O}from"./chunk-5EAJO372.js";import{d as m}from"./chunk-DBMW3VUN.js";import{existsSync as R,readFileSync as H,statSync as M}from"fs";var B=t=>{try{return R(t)&&M(t).isFile()}catch{return!1}},C=t=>N(t)&&A.test(t);async function y(t,n,o,l){let e=t.manifest.id,s,a=new Promise((r,d)=>{s=setTimeout(()=>d(new $({code:"PLUGIN_HOOK_TIMEOUT",message:`plugin ${e} did not answer ${n} within ${Math.round(o/1e3)} seconds`,plugin:e,hook:n})),o)});try{return await Promise.race([Promise.resolve().then(l),a])}catch(r){throw r instanceof $?r:r instanceof T?new $({code:"PLUGIN_REFUSED",message:r.message,plugin:e,hook:n,...r.remedy?{remedy:r.remedy}:{}}):new $({code:"PLUGIN_HOOK_FAILED",message:`plugin ${e} failed in ${n}: ${r instanceof Error?r.message:String(r)}`,plugin:e,hook:n})}finally{clearTimeout(s)}}async function ee(t){let{plugin:n,ref:o,named:l}=t,e=n.manifest.id,s=t.hookMs??m.hookMs,a=t.isFile??B(o),r=!a&&x(n).includes("remote")&&typeof n.fetch=="function",d=l?`${e}:${o}`:o,I=r?O(d):null;I!==null&&c("PLUGIN_REF_INVALID",`${d.length>80?`${d.slice(0,80)}\u2026`:d} cannot be recorded as a reference: ${I}`,{plugin:e,remedy:`give the source as <scheme>:<rest>, one word of at most ${U} characters`});let h=await y(n,"claim",s,()=>n.claim({ref:o,named:l,isFile:a}));h==null&&c("PLUGIN_NOT_CLAIMED",`plugin ${e} does not read ${o}`,{plugin:e,hook:"claim",remedy:l?`drop the ${e}: prefix, or name the plugin that reads it`:"ingest it as a file of a built-in kind"}),(typeof h!="object"||typeof h.sourceId!="string")&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered claim with something that is not a claim`,{plugin:e,hook:"claim"});let p=t.asId??h.sourceId,b=h.recorded;if(r&&b!==void 0){(typeof b!="string"||b==="")&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered claim with a recorded reference that is not one`,{plugin:e,hook:"claim"});let i=l?`${e}:${b}`:b,u=O(i);u!==null&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${i.length>80?`${i.slice(0,80)}\u2026`:i}, which cannot be recorded as a reference: ${u}`,{plugin:e,hook:"claim"});let f=(t.registry??F()).route(i,()=>!1);(f===null||f.plugin.manifest.id!==e)&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${i.length>80?`${i.slice(0,80)}\u2026`:i}, which ${f===null?"no plugin reads":`plugin ${f.plugin.manifest.id} reads`}: a recorded reference must route back to the plugin that read it`,{plugin:e,hook:"claim"});let w=await y(n,"claim",s,()=>n.claim({ref:f.ref,named:f.named,isFile:!1}));(w==null||typeof w!="object"||w.sourceId!==h.sourceId)&&c("PLUGIN_HOOK_FAILED",`plugin ${e} would record ${b} for ${h.sourceId}, but claiming it again ${w?`gives ${String(w.sourceId)}`:"is refused"}: a recorded reference must name the same source`,{plugin:e,hook:"claim"}),d=i}C(p)||c("PLUGIN_SOURCE_ID_INVALID",`${JSON.stringify(p)} is not an id a source may have: it starts with a letter or digit and holds letters, digits and . _ -, at most 128 characters`,{plugin:e,hook:"claim",remedy:t.asId===void 0?"give the source an id with --as <id>":"give another id with --as <id>"});let g,L;if(!a&&t.supplied!==void 0){r||c("PLUGIN_REMOTE_UNAVAILABLE",`${o} is not a file on this machine, and plugin ${e} has no connection to fetch it through`,{plugin:e,remedy:"save the source to a file and ingest the file"}),g=Buffer.from(t.supplied.bytes),g.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`${o} is ${g.byteLength} bytes; a plugin's source may be at most ${m.contentBytes}`,{plugin:e,hook:"fetch"});let i=t.supplied.cursor??null;L={ref:d,...i!==null?{cursor:i}:{}}}else if(a)g=t.supplied!==void 0?Buffer.from(t.supplied.bytes):H(o),g.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`${o} is ${g.byteLength} bytes; a plugin's source may be at most ${m.contentBytes}`,{plugin:e});else{let i=r?t.connect?.(e):void 0;i===void 0&&c("PLUGIN_REMOTE_UNAVAILABLE",`${o} is not a file on this machine, and plugin ${e} has no connection to fetch it through`,{plugin:e,remedy:"save the source to a file and ingest the file"});let u=t.cursor!==void 0?t.cursor:j(t.store,p,e,d),f=await D(n,i,{ref:o,sourceId:p,cursor:u},s);if(f.kind==="unchanged")return K(t.store,p,e);g=f.bytes,L={ref:d,...f.cursor!==null?{cursor:f.cursor}:{}},t.onFetched?.({bytes:new Uint8Array(g),cursor:f.cursor})}let _={sourceId:p,bytes:new Uint8Array(g)},G=async()=>{let u=(await y(n,"render",s,()=>n.render(_)))?.text;(typeof u!="string"||u===""||u.includes("\0"))&&c("PLUGIN_TEXT_INVALID",`plugin ${e} rendered ${p} to something that is not text: ${typeof u!="string"?"no text":u===""?"empty text":"text holding a NUL"}`,{plugin:e,hook:"render"});let f=await y(n,"index",s,()=>n.index(_,{text:u}));return{projection:u,inventory:[],blobs:new Map,delivered:[],converter:{name:e,version:n.manifest.version,policy:`rules-${n.manifest.rules}`},units:f}},P=x(n);return E({store:t.store,bytes:g,media:k,sourceId:p,label:o,plugin:{id:e,rules:n.manifest.rules,...L!==void 0?{fetch:L}:{},...P.includes("cites-deep")?{citesDeep:!0}:{}},converters:{plugin:G},...P.includes("explain")&&typeof n.explain=="function"?{explain:(i,u)=>y(n,"explain",Math.min(u,s),()=>n.explain(i))}:{},...t.explainMs!==void 0?{explainMs:t.explainMs}:{},...P.includes("context")&&typeof n.context=="function"?{context:(i,u)=>y(n,"context",Math.min(u,s),()=>n.context({..._,text:i.text,units:i.units}))}:{},...P.includes("coverage")&&typeof n.coverage=="function"?{coverage:(i,u)=>y(n,"coverage",Math.min(u,s),()=>n.coverage({sourceId:_.sourceId,units:i.units}))}:{},...t.confirmSameSource?{confirmSameSource:t.confirmSameSource}:{},...t.eventIds?{eventIds:t.eventIds}:{},...t.provenance?{provenance:t.provenance}:{}})}async function D(t,n,o,l){let e=t.manifest.id,s;try{s=await y(t,"fetch",l,()=>t.fetch({...o,connection:n}))}catch(h){throw n.breach?n.breach:h}finally{n.close()}if(n.breach)throw n.breach;let a=s?.kind;if(a==="unchanged")return{kind:"unchanged"};let r=s;(a!=="content"||!(r.bytes instanceof Uint8Array))&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered fetch with something that is not an answer: neither the content, with its bytes, nor "unchanged"`,{plugin:e,hook:"fetch"});let d=Buffer.from(r.bytes);d.byteLength>m.contentBytes&&c("PLUGIN_CONTENT_TOO_LARGE",`plugin ${e} fetched ${d.byteLength} bytes for ${o.ref}; a plugin's source may be at most ${m.contentBytes}`,{plugin:e,hook:"fetch"}),r.cursor!==void 0&&typeof r.cursor!="string"&&c("PLUGIN_HOOK_FAILED",`plugin ${e} answered fetch with a cursor that is not a string`,{plugin:e,hook:"fetch"});let I=r.cursor===void 0?null:r.cursor;return I!==null&&Buffer.byteLength(I,"utf8")>m.cursorBytes&&c("PLUGIN_CURSOR_TOO_LARGE",`plugin ${e} answered fetch with a cursor of ${Buffer.byteLength(I,"utf8")} bytes; a cursor may be at most ${m.cursorBytes}`,{plugin:e,hook:"fetch",remedy:"the plugin must be fixed: every later fetch of this source starts from the same cursor and is refused the same way"}),{kind:"content",bytes:d,cursor:I}}function K(t,n,o){let l=S(t),e=l.heads.get(n);typeof e!="string"&&c("PLUGIN_HOOK_FAILED",`plugin ${o} answered fetch with "unchanged" for ${n}, which this store holds no current version of`,{plugin:o,hook:"fetch"});let s=l.mediaOf(e),a=v(n,s.format==="plugin"?s.plugin?.id??"":null,o,!1);if(a!==void 0)throw new Error(a);let r=l.getNode(e)?.content.blob;return{status:"unchanged",source_id:n,cid:e,blob:typeof r=="string"?r:""}}function j(t,n,o,l){let e=S(t),s=e.heads.get(n);if(typeof s!="string")return null;let a=e.mediaOf(s).plugin;return a?.id!==o||a.fetch?.ref!==l?null:a.fetch.cursor??null}export{B as a,C as b,y as c,ee as d};
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{c as g,d as u}from"./chunk-BJO6J5X2.js";import{a as f}from"./chunk-72KYMWQ5.js";import{readFileSync as E}from"fs";var p=/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g;function h(a){let e=[];for(let o of a){let r=o.trim();if(r){if(r.startsWith("@")){let n=r.slice(1).trim(),t;try{t=E(n,"utf8")}catch(l){throw new Error(`--deps @${n}: ${l.message}`)}let s=t.trim();s&&e.push(s);continue}e.push(r)}}return e.join(`
2
+ import{c as g,d as u}from"./chunk-FQ2AMM3E.js";import{a as f}from"./chunk-72KYMWQ5.js";import{readFileSync as E}from"fs";var p=/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g;function h(a){let e=[];for(let o of a){let r=o.trim();if(r){if(r.startsWith("@")){let n=r.slice(1).trim(),t;try{t=E(n,"utf8")}catch(l){throw new Error(`--deps @${n}: ${l.message}`)}let s=t.trim();s&&e.push(s);continue}e.push(r)}}return e.join(`
3
3
 
4
4
  `)}function y(a,e){let o=a.prompt.trim(),r=a.deps.trim(),n=[["--prompt",o],["--deps",r]];if(!n.some(([,i])=>p.test(i)))return p.lastIndex=0,{prompt:o,deps:r,variables:{},secretNames:[]};p.lastIndex=0;let t=u({objective:[o,r].join(`
5
5
  `),globalDir:e.globalDir,localDir:e.localDir,file:e.file,inline:e.inline,onLoadError:e.onLoadError});for(let[i,x]of n)for(let v of x.matchAll(p)){let c=v[1],b=c.replace(/^(global\.|secrets\.user\.)/,"");if(!(c in t.raw)&&!(b in t.raw))return{error:`${i} uses {{${c}}} but no variable "${b}" is defined (variables files, --variables-file or --variables)`}}let s=o?f(t.raw,o).objective:"",l=r?f(t.raw,r).objective:"",m=g(t.auteur,[s,l].join(`
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as n}from"./chunk-TM45NPWL.js";import{y as s}from"./chunk-J4FIESTB.js";function E(t="prod",r=process.env){let e=s[t];return t!=="stage"?e:{authBaseUrl:r.KANE_STAGE_AUTH_URL??e.authBaseUrl,consentUrl:r.KANE_STAGE_CONSENT_URL??e.consentUrl,controllerBaseUrl:r.TESTMUAI_BASE_URL??e.controllerBaseUrl,tmsBaseUrl:r.KANE_STAGE_TMS_URL??e.tmsBaseUrl,testGeneratorBaseUrl:r.KANE_STAGE_TCG_URL??e.testGeneratorBaseUrl,secretsBaseUrl:r.KANE_STAGE_SECRETS_URL??e.secretsBaseUrl,testManagerUiUrl:r.KANE_STAGE_TEST_MANAGER_UI_URL??e.testManagerUiUrl,shareApiBaseUrl:r.KANE_STAGE_SHARE_API_URL??e.shareApiBaseUrl,v16ServerHost:r.KANE_STAGE_V16_SERVER_HOST??e.v16ServerHost,evidenceViewerUrl:r.KANE_STAGE_EVIDENCE_VIEWER_URL??e.evidenceViewerUrl,mediaArtefactsHost:r.KANE_STAGE_MEDIA_ARTEFACTS_HOST??e.mediaArtefactsHost,mobileAppBaseUrl:r.KANE_STAGE_MOBILE_APP_URL??e.mobileAppBaseUrl,mobileHubUrl:r.KANE_STAGE_MOBILE_HUB_URL??e.mobileHubUrl,lrmaaBaseUrl:r.KANE_STAGE_LRMAA_URL??e.lrmaaBaseUrl,latticeBaseUrl:r.KANE_LATTICE_URL??e.latticeBaseUrl,deviceStreamUrl:r.KANE_STAGE_DEVICE_STREAM_URL??e.deviceStreamUrl}}function U(){let t=process.env.TESTMUAI_ENV;return t!==void 0&&t!==""?t==="stage"?"stage":"prod":new n().getDefaultEnv()==="stage"?"stage":"prod"}function a(){let t=process.env.KANE_LATTICE_URL;return t!==void 0&&t.trim()===""?"":E(U()).latticeBaseUrl.trim()}export{E as a,U as b,a as c};
2
+ import{a as n}from"./chunk-YWQNZRJG.js";import{y as s}from"./chunk-YKOZBFR3.js";function E(t="prod",r=process.env){let e=s[t];return t!=="stage"?e:{authBaseUrl:r.KANE_STAGE_AUTH_URL??e.authBaseUrl,consentUrl:r.KANE_STAGE_CONSENT_URL??e.consentUrl,controllerBaseUrl:r.TESTMUAI_BASE_URL??e.controllerBaseUrl,tmsBaseUrl:r.KANE_STAGE_TMS_URL??e.tmsBaseUrl,testGeneratorBaseUrl:r.KANE_STAGE_TCG_URL??e.testGeneratorBaseUrl,secretsBaseUrl:r.KANE_STAGE_SECRETS_URL??e.secretsBaseUrl,testManagerUiUrl:r.KANE_STAGE_TEST_MANAGER_UI_URL??e.testManagerUiUrl,shareApiBaseUrl:r.KANE_STAGE_SHARE_API_URL??e.shareApiBaseUrl,v16ServerHost:r.KANE_STAGE_V16_SERVER_HOST??e.v16ServerHost,evidenceViewerUrl:r.KANE_STAGE_EVIDENCE_VIEWER_URL??e.evidenceViewerUrl,mediaArtefactsHost:r.KANE_STAGE_MEDIA_ARTEFACTS_HOST??e.mediaArtefactsHost,mobileAppBaseUrl:r.KANE_STAGE_MOBILE_APP_URL??e.mobileAppBaseUrl,mobileHubUrl:r.KANE_STAGE_MOBILE_HUB_URL??e.mobileHubUrl,lrmaaBaseUrl:r.KANE_STAGE_LRMAA_URL??e.lrmaaBaseUrl,latticeBaseUrl:r.KANE_LATTICE_URL??e.latticeBaseUrl,deviceStreamUrl:r.KANE_STAGE_DEVICE_STREAM_URL??e.deviceStreamUrl}}function U(){let t=process.env.TESTMUAI_ENV;return t!==void 0&&t!==""?t==="stage"?"stage":"prod":new n().getDefaultEnv()==="stage"?"stage":"prod"}function a(){let t=process.env.KANE_LATTICE_URL;return t!==void 0&&t.trim()===""?"":E(U()).latticeBaseUrl.trim()}export{E as a,U as b,a as c};
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as qr}from"./chunk-SALZ6WSF.js";import{a as Pr}from"./chunk-ENRFXGID.js";import{e as dt,f as jt,g as Bt,h as qe}from"./chunk-X6FCXBXU.js";import{A as st,B as ve,C as yr,D as oe,E as $e,F as ot,G as br,H as K,I as it,J as Tt,K as at,L as ke,M as wr,N as vr,Q as Te,a as tr,b as nr,c as Se,d as Ee,e as de,f as tt,g as sr,h as or,i as ce,j as cr,k as Ce,l as Ae,m as lr,n as fr,o as hr,p as At,q as Nt,r as Q,s as Ne,t as gr,u as Pt,v as Pe,w as mr,x as qt,y as te,z as rt}from"./chunk-OZNYQONA.js";import{a as R,b as rr,d as X,e as Oe,h as ir,i as ar,k as dr}from"./chunk-CB4ARIHR.js";import{a as Un,b as Vn,e as Wn}from"./chunk-SSOUYKVG.js";import{a as Zn}from"./chunk-HVOXMCKE.js";import{a as Yn,b as zn}from"./chunk-WMGKUERB.js";import{a as Qn}from"./chunk-UWPG5MWM.js";import{a as Jn}from"./chunk-73Y6T2UK.js";import{b as Xn,e as er,h as Ct,i as J}from"./chunk-XMPTFXPW.js";import{e as Ar,f as Nr}from"./chunk-MINDIQET.js";import{a as Er}from"./chunk-IZ66FKPC.js";import{a as Or,b as Lt,c as Cr}from"./chunk-E4GIGM5V.js";import{a as Ir,d as Sr}from"./chunk-3KY7HHQU.js";import{h as _r,i as Rr}from"./chunk-ZHAMVLQZ.js";import{g as Ft,h as $r,q as kr}from"./chunk-Z24SD2EJ.js";import{a as nt,b as le,c as pr,d as ur}from"./chunk-23DKB2MT.js";import{b as Ot,d as Kn}from"./chunk-CQDCNP7V.js";import{b as dn,f as cn,h as ln,k as pn,l as un,q as et}from"./chunk-7V34ZMMS.js";import{b as we}from"./chunk-6PIIUAZF.js";import{Ea as C,Fa as On,Ia as Cn,Ka as An,M as wn,Na as Nn,Oa as Pn,Pa as qn,Qa as ee,Ra as Tn,Sa as jn,Ua as Bn,Va as Qe,Ya as Fn,Za as Ln,a as ae,d as Et,da as vn,ea as $n,eb as xn,fa as kn,fb as Ze,ga as _n,ha as Rn,ia as In,ja as Sn,kb as Mn,mb as Hn,na as Ye,oa as En,ob as Xe,pa as ze,q as mn,r as yn,t as bn,vb as Dn,wb as Gn}from"./chunk-PI7OXS62.js";import{c as hn,n as gn}from"./chunk-DBMW3VUN.js";import{d as fn,f as Je,g as Ke}from"./chunk-KU3YHPWZ.js";import{b as an}from"./chunk-7V4BQSSV.js";import{g as We}from"./chunk-ZCRZFAOT.js";import{existsSync as De,readdirSync as ws,readFileSync as vs,realpathSync as oi,statSync as ii,writeFileSync as ai}from"fs";import{basename as Rt,join as Ge,relative as di,resolve as sn}from"path";import{randomBytes as Fs}from"crypto";var Tr=8,je=()=>dr(Fs(8).toString("hex")),jr=(e,t)=>e!==null&&Buffer.from(e).equals(Buffer.from(t)),Ls=[["P1 exclusive create",async e=>{for(let t=1;t<=2;t++){let n=je(),r=Buffer.from(`probe ${t} first`);if(await e.putIfAbsent(n,r)!=="created")return"a fresh key was reported as existing";if(await e.putIfAbsent(n,Buffer.from(`probe ${t} second`))!=="exists")return"the second write to one key was not refused";if(!jr(await e.get(n),r))return"the second write replaced the first"}return null}],["P2 contention",async e=>{let t=je(),r=(await Promise.all(Array.from({length:Tr},(o,i)=>e.putIfAbsent(t,Buffer.from(`contender ${i}`))))).filter(o=>o==="created").length;return r===1?null:`${r} of ${Tr} concurrent writers were told "created"`}],["P3 read-after-write",async e=>{let t=je(),n=Buffer.from("visible");return await e.putIfAbsent(t,n),await e.head(t)?jr(await e.get(t),n)?(await e.list(t)).includes(t)?null:"list does not show a key just created":"get does not return the bytes just created":"head does not see a key just created"}],["P4 definitive absence",async e=>await e.head(je())?"a never-written key was reported present":null]];async function ct(e){if(e.probe){let r=await e.probe();return{tier:Math.max(r.tier,e.ceilingTier),detail:r.detail}}let t=1,n="all probes passed";for(let[r,o]of Ls){let i;try{i=await o(e)}catch(s){if(s instanceof R){if(!(s.code==="SYNC_LOCATION_REFUSED_WRITE"&&r.startsWith("P1")&&await Br(e)))throw s;n=`${r}: ${s.message}`,t=3;break}n=`${r}: ${s instanceof Error?s.message:String(s)}`,t=r.startsWith("P1")&&await Br(e)?3:2;break}if(i!==null){n=`${r}: ${i}`,t=2;break}}return{tier:Math.max(t,e.ceilingTier),detail:n}}async function Br(e){try{return!await e.head(je())}catch(t){if(t instanceof R)throw t;return!1}}import{existsSync as xs,readFileSync as xr}from"fs";import{join as Ms}from"path";async function xt(e,t,n,r){let i=de(e).entries[n];if(!i)throw new Error(`no sync state for ${n} \u2014 run kane-cli context sync add ${n} <descriptor> first`);if(i.tier!==1)throw new R("SYNC_READ_ONLY",`${n} is a tier ${i.tier} location: it can be cloned and pulled, never pushed`,"push to a location whose probe reached tier 1, or pull from this one");let s=await Ce(e,t,i.witness);switch(s.kind){case"empty-storage":case"ahead":case"up-to-date":break;case"behind":case"empty-local":throw new R("SYNC_BEHIND",`${n} holds ${s.storage.seq} records, this store ${s.local?.seq??0}: it has records this store has not seen`,`kane-cli context pull ${n}`);case"diverged":throw new R("SYNC_DIVERGED",`you and ${n} both added work after position ${s.at-1}; nothing was pushed`,`run kane-cli context pull ${n} --rebase to save your local work, take the team version from ${n}, and then reapply yours`);case"foreign-lineage":throw new R("SYNC_FOREIGN_LINEAGE",`${n} holds a different history (its first record is not this store's)`,`to work on it, clone it: kane-cli context clone <descriptor of ${n}> <dir>; to share this store, add an empty location`)}let a=s.storage,c=qn(e),d;try{An(e),d=Hs(e,a)}catch(M){throw M instanceof Cn?new R("SYNC_REBASE_PENDING",`${M.message.split(";")[0]}; nothing was pushed`,M.remedy):M}finally{c()}let l=d.map(M=>Ds(e,M)),f=0,p=0,g=0,u=0,m=a,y=null,w=null,h=t.beginTransaction?await t.beginTransaction():void 0,b=h?{...t,head:h.head,get:h.get,list:t.list.bind(t),putIfAbsent:t.putIfAbsent.bind(t)}:t,v=h?h.stageIfAbsent.bind(h):t.putIfAbsent.bind(t),q=[],re=M=>h?q.push(M):r(M);try{let M=new Set;for(let S of l){for(let D of S.blobs)if(await v(D.key,D.bytes)!=="exists")p++,M.add(D.key);else if(!M.has(D.key)){let $=await b.get(D.key);if($===null||Ot(Buffer.from($))!==D.fp){w=new R("SYNC_OBJECT_CORRUPT",`the blob ${D.fp} ${n} already holds does not hash to its name (named by record ${S.seq}); the record was not pushed`,"the storage object needs a human look before anything more is pushed to it");break}M.add(D.key)}if(w)break;S.proposal&&await v(S.proposal.key,S.proposal.bytes)!=="exists"&&g++;let Z=Oe(S.seq);if(await v(Z,S.raw)!=="exists")f++;else if((await ce(b,S.seq)).hash===S.hash)re(`position ${S.seq} is already on ${n}`),u++;else{y=S.seq;break}m={seq:S.seq,hash:S.hash}}if(h||await Lr(t,m,a,n),m&&!await b.head(X)){let S=await ce(b,1),Z={layout:1,canonicalizer:"v1",genesis_hash:S.hash};await v(X,Buffer.from(JSON.stringify(Z)+`
2
+ import{a as qr}from"./chunk-F4XCCOWC.js";import{a as Pr}from"./chunk-ABAUIIPD.js";import{e as dt,f as jt,g as Bt,h as qe}from"./chunk-6FVGPKVX.js";import{A as st,B as ve,C as yr,D as oe,E as $e,F as ot,G as br,H as K,I as it,J as Tt,K as at,L as ke,M as wr,N as vr,Q as Te,a as tr,b as nr,c as Se,d as Ee,e as de,f as tt,g as sr,h as or,i as ce,j as cr,k as Ce,l as Ae,m as lr,n as fr,o as hr,p as At,q as Nt,r as Q,s as Ne,t as gr,u as Pt,v as Pe,w as mr,x as qt,y as te,z as rt}from"./chunk-DAV4ONGS.js";import{a as R,b as rr,d as X,e as Oe,h as ir,i as ar,k as dr}from"./chunk-CB4ARIHR.js";import{a as Un,b as Vn,e as Wn}from"./chunk-ZIRSTOEV.js";import{a as Zn}from"./chunk-TCK7WR3M.js";import{a as Yn,b as zn}from"./chunk-WMGKUERB.js";import{a as Qn}from"./chunk-2EKLTUY2.js";import{a as Jn}from"./chunk-73Y6T2UK.js";import{b as Xn,e as er,h as Ct,i as J}from"./chunk-XMPTFXPW.js";import{e as Ar,f as Nr}from"./chunk-HBGYEA3O.js";import{a as Er}from"./chunk-BIGOLVK6.js";import{a as Ir,d as Sr}from"./chunk-JSSM2TWY.js";import{a as Or,b as Lt,c as Cr}from"./chunk-H6IPGZTP.js";import{h as _r,i as Rr}from"./chunk-3A4KK22B.js";import{g as Ft,h as $r,q as kr}from"./chunk-C3DMMAFP.js";import{a as nt,b as le,c as pr,d as ur}from"./chunk-UVL6XQHU.js";import{b as Ot,d as Kn}from"./chunk-5ORBAYTU.js";import{Ea as C,Fa as On,Ia as Cn,Ka as An,M as wn,Na as Nn,Oa as Pn,Pa as qn,Qa as ee,Ra as Tn,Sa as jn,Ua as Bn,Va as Qe,Ya as Fn,Za as Ln,a as ae,d as Et,da as vn,ea as $n,eb as xn,fa as kn,fb as Ze,ga as _n,ha as Rn,ia as In,ja as Sn,kb as Mn,mb as Hn,na as Ye,oa as En,ob as Xe,pa as ze,q as mn,r as yn,t as bn,vb as Dn,wb as Gn}from"./chunk-5EAJO372.js";import{c as hn,n as gn}from"./chunk-DBMW3VUN.js";import{d as fn,f as Je,g as Ke}from"./chunk-KU3YHPWZ.js";import{b as dn,f as cn,h as ln,k as pn,l as un,q as et}from"./chunk-OKCVG7AG.js";import{b as an}from"./chunk-7V4BQSSV.js";import{b as we}from"./chunk-6PIIUAZF.js";import{g as We}from"./chunk-ZCRZFAOT.js";import{existsSync as De,readdirSync as ws,readFileSync as vs,realpathSync as oi,statSync as ii,writeFileSync as ai}from"fs";import{basename as Rt,join as Ge,relative as di,resolve as sn}from"path";import{randomBytes as Fs}from"crypto";var Tr=8,je=()=>dr(Fs(8).toString("hex")),jr=(e,t)=>e!==null&&Buffer.from(e).equals(Buffer.from(t)),Ls=[["P1 exclusive create",async e=>{for(let t=1;t<=2;t++){let n=je(),r=Buffer.from(`probe ${t} first`);if(await e.putIfAbsent(n,r)!=="created")return"a fresh key was reported as existing";if(await e.putIfAbsent(n,Buffer.from(`probe ${t} second`))!=="exists")return"the second write to one key was not refused";if(!jr(await e.get(n),r))return"the second write replaced the first"}return null}],["P2 contention",async e=>{let t=je(),r=(await Promise.all(Array.from({length:Tr},(o,i)=>e.putIfAbsent(t,Buffer.from(`contender ${i}`))))).filter(o=>o==="created").length;return r===1?null:`${r} of ${Tr} concurrent writers were told "created"`}],["P3 read-after-write",async e=>{let t=je(),n=Buffer.from("visible");return await e.putIfAbsent(t,n),await e.head(t)?jr(await e.get(t),n)?(await e.list(t)).includes(t)?null:"list does not show a key just created":"get does not return the bytes just created":"head does not see a key just created"}],["P4 definitive absence",async e=>await e.head(je())?"a never-written key was reported present":null]];async function ct(e){if(e.probe){let r=await e.probe();return{tier:Math.max(r.tier,e.ceilingTier),detail:r.detail}}let t=1,n="all probes passed";for(let[r,o]of Ls){let i;try{i=await o(e)}catch(s){if(s instanceof R){if(!(s.code==="SYNC_LOCATION_REFUSED_WRITE"&&r.startsWith("P1")&&await Br(e)))throw s;n=`${r}: ${s.message}`,t=3;break}n=`${r}: ${s instanceof Error?s.message:String(s)}`,t=r.startsWith("P1")&&await Br(e)?3:2;break}if(i!==null){n=`${r}: ${i}`,t=2;break}}return{tier:Math.max(t,e.ceilingTier),detail:n}}async function Br(e){try{return!await e.head(je())}catch(t){if(t instanceof R)throw t;return!1}}import{existsSync as xs,readFileSync as xr}from"fs";import{join as Ms}from"path";async function xt(e,t,n,r){let i=de(e).entries[n];if(!i)throw new Error(`no sync state for ${n} \u2014 run kane-cli context sync add ${n} <descriptor> first`);if(i.tier!==1)throw new R("SYNC_READ_ONLY",`${n} is a tier ${i.tier} location: it can be cloned and pulled, never pushed`,"push to a location whose probe reached tier 1, or pull from this one");let s=await Ce(e,t,i.witness);switch(s.kind){case"empty-storage":case"ahead":case"up-to-date":break;case"behind":case"empty-local":throw new R("SYNC_BEHIND",`${n} holds ${s.storage.seq} records, this store ${s.local?.seq??0}: it has records this store has not seen`,`kane-cli context pull ${n}`);case"diverged":throw new R("SYNC_DIVERGED",`you and ${n} both added work after position ${s.at-1}; nothing was pushed`,`run kane-cli context pull ${n} --rebase to save your local work, take the team version from ${n}, and then reapply yours`);case"foreign-lineage":throw new R("SYNC_FOREIGN_LINEAGE",`${n} holds a different history (its first record is not this store's)`,`to work on it, clone it: kane-cli context clone <descriptor of ${n}> <dir>; to share this store, add an empty location`)}let a=s.storage,c=qn(e),d;try{An(e),d=Hs(e,a)}catch(M){throw M instanceof Cn?new R("SYNC_REBASE_PENDING",`${M.message.split(";")[0]}; nothing was pushed`,M.remedy):M}finally{c()}let l=d.map(M=>Ds(e,M)),f=0,p=0,g=0,u=0,m=a,y=null,w=null,h=t.beginTransaction?await t.beginTransaction():void 0,b=h?{...t,head:h.head,get:h.get,list:t.list.bind(t),putIfAbsent:t.putIfAbsent.bind(t)}:t,v=h?h.stageIfAbsent.bind(h):t.putIfAbsent.bind(t),q=[],re=M=>h?q.push(M):r(M);try{let M=new Set;for(let S of l){for(let D of S.blobs)if(await v(D.key,D.bytes)!=="exists")p++,M.add(D.key);else if(!M.has(D.key)){let $=await b.get(D.key);if($===null||Ot(Buffer.from($))!==D.fp){w=new R("SYNC_OBJECT_CORRUPT",`the blob ${D.fp} ${n} already holds does not hash to its name (named by record ${S.seq}); the record was not pushed`,"the storage object needs a human look before anything more is pushed to it");break}M.add(D.key)}if(w)break;S.proposal&&await v(S.proposal.key,S.proposal.bytes)!=="exists"&&g++;let Z=Oe(S.seq);if(await v(Z,S.raw)!=="exists")f++;else if((await ce(b,S.seq)).hash===S.hash)re(`position ${S.seq} is already on ${n}`),u++;else{y=S.seq;break}m={seq:S.seq,hash:S.hash}}if(h||await Lr(t,m,a,n),m&&!await b.head(X)){let S=await ce(b,1),Z={layout:1,canonicalizer:"v1",genesis_hash:S.hash};await v(X,Buffer.from(JSON.stringify(Z)+`
3
3
  `,"utf8"))!=="exists"&&re(`wrote ${X} on ${n}`)}if(h){if(m){let $=await b.get(X),ge=await ce(b,1),T={};try{let me=JSON.parse(Buffer.from($??[]).toString("utf8"));me&&typeof me=="object"&&!Array.isArray(me)&&(T=me)}catch{}if(T.layout!==1||T.canonicalizer!=="v1"||T.genesis_hash!==ge.hash)throw new R("SYNC_OBJECT_CORRUPT",`${X} does not describe this context's verified genesis and format.`,"Ask the location owner to inspect the metadata before publishing.")}if(w)throw w;if(y!==null)throw new R("SYNC_POSITION_TAKEN",`position ${y} on ${n} was taken by another writer; this batch was not published`,Fr(n,y));let S=await h.commit(),Z=new Set(S.created),D=l.filter($=>Z.has(Oe($.seq))).length;u+=f-D,f=D,p=new Set(l.flatMap($=>$.blobs.map(ge=>ge.key)).filter($=>Z.has($))).size,g=new Set(l.flatMap($=>$.proposal?[$.proposal.key]:[]).filter($=>Z.has($))).size}h&&await Lr(t,m,a,n);for(let S of q)r(S);let se="";if(m)try{lr(e,n,m,{forwardOnly:!0})}catch(S){if(y===null||!(S instanceof C))throw S;se=" (the witness was not saved; the next pull records it)"}if(w)throw w;if(y!==null)throw new R("SYNC_POSITION_TAKEN",`position ${y} on ${n} was taken by another writer while this push ran; this store's history through position ${m?.seq??0} is confirmed on ${n}${se}`,Fr(n,y))}finally{await h?.abort()}return{pushed:f,from:a?.seq??0,to:m?.seq??0,blobs:p,proposals:g,alreadyThere:u}}function Fr(e,t){return t===1?`${e} holds a different history: to work on it, clone it with kane-cli context clone <descriptor of ${e}> <dir>; to share this store, add an empty location`:`kane-cli context pull ${e} --rebase`}async function Lr(e,t,n,r){if(!t||t.seq<=(n?.seq??0))return;let o=await ce(e,t.seq);if(o.hash!==t.hash)throw new R("SYNC_OBJECT_CORRUPT",`${r} answered "created" for position ${t.seq} but serves a record hashing ${o.hash}, not ${t.hash}`,"The location needs inspection before publishing more context.")}function Hs(e,t){let{records:n,hashes:r}=Ln(e,t?.seq??0,t?.hash??null);return n.map((o,i)=>{let s=r[i],a=xr(Ms(e,"commits",`${String(o.seq).padStart(6,"0")}-${s.slice(7,19)}.json`));if(ee(JSON.parse(a.toString("utf8")))!==s)throw new Error(`record ${o.seq} changed on disk while it was being read \u2014 run kane-cli context fsck`);return{rec:o,hash:s,raw:a}})}function Ds(e,{rec:t,hash:n,raw:r}){{let o=tr(t),i=o.blobs.map(s=>{let a=Kn(e,s);if(a===null)throw new R("SYNC_CLOSURE_MISSING",`record ${t.seq} names blob ${s}, which this store does not hold`,"restore the blob from a copy of this store, or run kane-cli context fsck");if(Ot(a)!==s)throw new R("SYNC_LOCAL_BLOB_CORRUPT",`record ${t.seq} names blob ${s}, but the local file does not hash to that: it is torn`,"restore the blob from a copy of this store, or run kane-cli context fsck");return{key:ir(s),fp:s,bytes:a}});return{seq:t.seq,hash:n,raw:new Uint8Array(r),blobs:i,proposal:Gs(e,o.proposalId)}}}function Gs(e,t){if(t===null)return null;let n=Qn(e,t);if(!xs(n))return null;let r=xr(n);return{key:ar(t,nr(r.toString("utf8"))),bytes:r}}import{existsSync as Us,readdirSync as Vs,readFileSync as Mr}from"fs";import{basename as Ws,join as Mt}from"path";function lt(e){return{id:Ws(e),witness:()=>JSON.parse(Mr(Mt(e,"base-witness.json"),"utf8")),records:t=>Ht(e,t),readIntent:t=>bn(e,t)}}var Js=/^\d{6}-[0-9a-f]{12}\.json$/;function Ht(e,t){let n=Mt(e,"commits"),r=Us(n)?Vs(n).filter(s=>Js.test(s)).sort():[],o=t.hash,i=t.seq;return r.map(s=>{let a;try{a=JSON.parse(Mr(Mt(n,s),"utf8"))}catch(d){throw new C(`backup record ${s} is not JSON: ${String(d)}`)}if(i+=1,a.seq!==i||a.prev_hash!==o)throw new C(`backup record ${s} does not continue the chain at ${i} from ${String(o)}`);let c=ee(a);if(!c.slice(7).startsWith(s.slice(7,19)))throw new C(`backup record ${s} does not match its name`);return o=c,{seq:i,hash:c,body:a}})}function pt(e,t){let n=t.witness(),r=e.recordsSince(null).slice(0,n.base.seq),o=t.records(n.base),i=[...r,...o.map(p=>p.body)],s=[...r.map(ee),...o.map(p=>p.hash)],a=new Map;for(let p of i)for(let g of p.nodes)a.set(g.cid,{label:g.label,content:g.content});let c=Mn();Hn(null,c,i,s,{writeNodeFiles:!1});let d=Gn(null,c,a),l=new Map(o.map(p=>[p.seq,p])),f=p=>d.displayNameOf(p)??p.slice(0,19);return{backup:t,backupId:t.id,from:n.from,base:n.base,index:c,graph:d,records:o,chain:i,recordAt:p=>l.get(p),resolveName:p=>d.resolve(p)?.cid,nameOf:p=>d.displayNameOf(p)??void 0,displayNameFor:p=>{let g=Dt(t,p),u=Object.keys(p.source_head_moves),m=g==="revert"?String(Ks(t,p)??""):g==="names"?(p.names??[]).map(y=>y.slug).join(", "):u.length>0?u.join(", "):p.nodes.length>0?[...new Set(p.nodes.map(y=>f(y.cid)))].join(", "):(p.executions?.length??0)>0?[...new Set(p.executions.map(y=>f(y.about)))].join(", "):p.review.length>0?[...new Set(p.review.map(y=>f(y.id)))].join(", "):p.supersessions.length>0?[...new Set(p.supersessions.map(y=>y.kind==="node"?f(y.old):y.ecid.slice(0,19)))].join(", "):u.join(", ");return m?`${g} ${m}`:g}}}function Ks(e,t){try{let r=e.readIntent(ee(t))?.args?.seq;return typeof r=="number"?r:void 0}catch{return}}function Dt(e,t){let n=null;try{n=e.readIntent(ee(t))}catch{n=null}if(n)return n.verb;if(t.intent_verb)return t.intent_verb;let r=Object.entries(t.source_head_moves);return(t.executions?.length??0)>0?"execution":t.design_of?"design":t.proposal_id!=null?"extract":t.conv?t.conv.turn===0?"conv-mint":"conv-turn":r.length===1&&r[0][1]===null&&t.supersessions.some(o=>o.kind==="node"&&o.new===null)?"retire":r.length===1&&typeof r[0][1]=="string"&&t.nodes.some(o=>o.label==="source")?"ingest":t.review.some(o=>o.resolution==="reset")||t.supersessions.some(o=>o.kind==="node"&&o.new===o.old||o.kind==="edge"&&o.revoke)?"revert":t.nodes.length===0&&t.edges.length===0&&t.supersessions.length===1&&t.supersessions[0].kind==="node"&&t.supersessions[0].new===null?"archive":t.nodes.length===0&&t.edges.length===0&&t.review.length===0&&(t.names?.length??0)>0?"names":t.nodes.length===0&&t.edges.length===0&&t.supersessions.length===0&&t.review.length>0?"review":"unknown"}import{existsSync as Hr,readdirSync as Ys,readFileSync as Gt}from"fs";import{isAbsolute as zs,join as ut,normalize as Qs,relative as Zs,sep as Xs}from"path";var eo=e=>e===""||zs(e)||e.includes("\\")||Qs(e).split(Xs).some(t=>t==="..")||e.startsWith("./")||e.includes("\0");function Fe(e){let t=ut(e,"manifest.json");if(!Hr(t))throw new C(`backup ${e} has no manifest.json \u2014 it was never completed; kane-cli context sync doctor`);let n;try{n=JSON.parse(Gt(t,"utf8"))}catch(s){throw new C(`backup manifest ${t} is not JSON: ${s instanceof Error?s.message:String(s)}`)}if(!Array.isArray(n))throw new C(`backup manifest ${t} is not a list`);let r=new Set,o=[];for(let s of n){let a=typeof s?.name=="string"?s.name:"";if(eo(a))throw new C(`backup manifest names an unsafe path ${JSON.stringify(s?.name)} \u2014 the backup is not trusted`);let c=ut(e,a);if(!Hr(c))throw new C(`backup file ${a} is missing from ${e}`);let d=Gt(c);if("sha256:"+an(d)!==s.hash)throw new C(`backup file ${a} does not match its manifest hash \u2014 the backup was changed after it was written`);if(a.startsWith("commits/"))try{r.add(ee(JSON.parse(d.toString("utf8"))))}catch(l){throw new C(`backup record ${a} is not a record: ${l instanceof Error?l.message:String(l)}`)}a.startsWith("intents/")&&o.push(a)}let i=new Set(n.map(s=>s.name));for(let s of Dr(e)){let a=Zs(e,s);if(a!=="manifest.json"&&!i.has(a))throw new C(`backup ${e} holds ${a}, which its manifest does not name \u2014 the backup was changed after it was written`)}for(let s of o){let a;try{a=JSON.parse(Gt(ut(e,s),"utf8"))}catch(d){throw new C(`backup envelope ${s} is not JSON: ${d instanceof Error?d.message:String(d)}`)}let c=mn(a);if(c!==null)throw new C(`backup envelope ${s} is not a valid intent: ${c}`);if(typeof a.born?.hash!="string"||!r.has(a.born.hash))throw new C(`backup envelope ${s} was born from a record the backup does not hold`)}}function Dr(e){let t=[];for(let n of Ys(e,{withFileTypes:!0})){let r=ut(e,n.name);n.isDirectory()?t.push(...Dr(r)):t.push(r)}return t}import{basename as Oo,join as Co}from"path";import{existsSync as Ao,readFileSync as No}from"fs";var G=class extends Error{},L=(e,t)=>({kind:"apply",inputs:e,...t&&t.length>0?{aliases:t}:{}}),V=e=>({kind:"noop",reason:e}),Vt=e=>({kind:"dedupe",as:e}),k=(e,t,n,r,o={})=>({kind:"hold",hold:{kind:e,mine:t,theirs:n,answers:r,detail:o}}),Gr=(e,t)=>{let n=ft(t.label,t.content);return e.graph.byLabel(t.label).filter(r=>!e.graph.superseded.has(r.cid)&&ft(t.label,r.content)===n).map(r=>r.cid)},z=e=>e?e.slice(0,19):"none",H=(e,t)=>e.maps.cid.rewrite(t);function I(e,t,n){if(typeof t!="string")throw new G(`${n} was not pinned`);let r=H(e,t);if(!e.graph.hasNode(r))throw new G(`${n} ${_(e,t)} has no counterpart on ${e.location}`);return r}var j=(e,t)=>e.graph.tipOf(t),Wt=(e,t)=>e.graph.superseded.has(e.graph.tipOf(t)),_=(e,t)=>e.fold.nameOf(t)??z(t),E=(e,t)=>e.graph.displayNameOf(t)??z(t);function Jt(e,t,n,r){let o=r==="fold"?e.fold.graph:e.graph,i=o.displayNameOf(t);if(i!==null&&i!==n)return i;let s=o.tipOf(t);for(let[d,l]of o.heads)if(l===t||l===s)return d;let a=o.getNode(t);if(a?.label==="source"&&typeof a.content.source_id=="string")return a.content.source_id;let c=a?.content.title??a?.content.text??a?.content.statement;return a&&typeof c=="string"&&c!==""?`${a.label} "${Y(c,32)}"`:z(t)}var F=e=>e.created_by?.by?.id??e.review[0]?.by.id??e.supersessions[0]?.by.id??e.names?.[0]?.by.id??"someone",N=e=>e.ts;function Y(e,t=48){let n=typeof e=="string"?e:JSON.stringify(e);return n.length>t?`${n.slice(0,t-1)}\u2026`:n}var Ut={test_md_blob:"steps",objectives_blob:"checks"},to=/^sha256:[0-9a-f]{64}$/,no=(e,t)=>e==="derived"||Or.includes(e)||/_blob$/.test(e)||/(^|_)id$|Id$/.test(e)||t.some(n=>typeof n=="string"&&to.test(n));function pe(e,t,n,r){let o=[...new Set([...Object.keys(e),...Object.keys(t)])].filter(c=>JSON.stringify(e[c])!==JSON.stringify(t[c])),i=o.filter(c=>Ut[c]===void 0&&!no(c,[e[c],t[c]])).map(c=>`${c} "${Y(e[c]??"")}" \u2192 "${Y(t[c]??"")}"`),s=Object.keys(Ut).filter(c=>o.includes(c)).map(c=>Ut[c]);return`${[...i,...s.length>0?[`${s.join(" and ")} changed`]:[]].join(", ")||"no field changed"} by ${n} ${r===null?"since your last pull":`at ${r}`}`}var ro={usecase:"use case",scenario:"scenario",test:"test",ac:"acceptance criterion",source:"document"};function Ur(e,t){let n=e.graph.getNode(t),r=n?ro[n.label]??n.label:"item",o=n?.label!=="ac"?n?.content.title:void 0;if(typeof o=="string"&&o.trim()!=="")return`the ${r} "${o}"`;let i=e.fold.nameOf(t)??e.graph.displayNameOf(t);return i?`the ${r} ${En(i)}`:`the ${r}`}function ie(e,t){for(let n of e.theirs)for(let r of n.supersessions)if(r.kind==="node"&&r.old===t)return{rec:n,next:r.new}}function Kt(e,t){let n=new Set([t]);for(let o=!0;o;){o=!1;for(let[i,s]of e.graph.superseded)typeof s=="string"&&n.has(s)&&!n.has(i)&&(n.add(i),o=!0)}let r=[];for(let o of e.theirs)for(let i of o.review)n.has(i.id)&&i.resolution!=="pending"&&r.push({rec:o,resolution:i.resolution});return r}var so=new Set(Object.values(Ke).filter(e=>e!==Ke.DERIVES&&e!==Ke.ANNOTATES));function Yt(e,t){let n=new Set,r=[],o=[t,e.graph.tipOf(t)];for(;o.length>0;){let i=o.pop();if(!n.has(i)){n.add(i);for(let s of e.graph.edgesInto(i))!so.has(s.type)||e.graph.superseded.has(s.src)||(!(s.src in e.fold.index.nodeLabel)&&!r.some(a=>a.cid===s.src)&&r.push({cid:s.src,label:e.graph.nodeLabel.get(s.src)??"node"}),o.push(s.src))}}return r}function zt(e){let t=new Map;for(let n of e)t.set(n.label,(t.get(n.label)??0)+1);return[...t].map(([n,r])=>`${r} ${n}${r===1?"":"s"}`).join(", ")}function ht(e,t,n){if(!e.theirs.some(o=>o.edges.some(i=>i.type===t&&i.src===n)))return;let r=e.graph.edgesFrom(n).find(o=>o.type===t);return r?{live:r.dst}:void 0}function _e(e,t){let n=t.event_ids??[],r={token:e.store.parse(e.graph.latestHash)},o=new Map(n.map(a=>[a,e.store.appliedEvent(a,r)?.digest])),i=n.filter(a=>o.get(a)!==void 0);return n.length===0||i.length===0?void 0:i.every(a=>{let c=n.indexOf(a),d=t.event_digests?.[c];return d!==void 0&&d!==""&&o.get(a)===d})&&i.length===n.length?V("already applied: every event id is in the chain with the same intent"):k("ambiguous",`committed ${n.length} event id${n.length===1?"":"s"}`,`${i.length} of them already in the shared chain under another intent`,["keep-theirs"],{event_ids:n})}function oo(e){return String(e??"").toLowerCase().trim().replace(/\s+/g," ")}function ft(e,t){let n=t.question;return`${e}\0${oo(t.title??t.text??t.statement??n?.header??t.source_id??"")}`}function Vr(e,t){let n=[],r=new Set;for(let o of e.nodes){let i=ft(o.label,o.content),s=t.nodes.find(a=>!r.has(a.cid)&&ft(a.label,a.content)===i);s&&(r.add(s.cid),n.push([o.cid,s.cid]))}for(let o of e.nodes){if(n.some(([s])=>s===o.cid))continue;let i=t.nodes.find(s=>!r.has(s.cid)&&s.label===o.label);i&&(r.add(i.cid),n.push([o.cid,i.cid]))}return n}function Wr(e,t){let n=[],r=new Set;for(let o of t.names??[]){if(!Ye.test(o.slug))continue;let i=t.nodes.find(a=>a.cid===o.cid);if(!i||e.graph.nameOf.has(H(e,o.cid)))continue;let s=ze(i.label,a=>r.has(a),e.graph.names.keys());s!==null&&(r.add(s),s!==o.slug&&n.push({from:o.slug,to:s}))}return n}function Jr(e,t,n){let r=[];for(let o of e.names??[]){let i=n.find(([a])=>a===o.cid)?.[1],s=t.names?.find(a=>a.cid===i);s&&s.slug!==o.slug&&r.push({from:o.slug,to:s.slug})}return r}function Kr(e,t,n){let r=e===void 0?void 0:e.split(`
4
4
  `).map(s=>{let a=/^(##\s.*?)\s@verifies\s+(.+?)\s*$/.exec(s);if(a)return`${a[1]} @verifies ${a[2].split(",").map(l=>l.trim()).filter(Boolean).map(n).join(", ")}`;let c=/^(\s*)@import\s+(\S+)\s*$/.exec(s);if(c)return`${c[1]}@import ${n(c[2])}`;let d=/^## Import: (\S+)\s*$/.exec(s);return d?`## Import: ${n(d[1])}`:s}).join(`
5
5
  `),o=null,i=t===void 0?void 0:t.split(`
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as Ye}from"./chunk-X45RZIAJ.js";import{b as Ve}from"./chunk-LV7224DG.js";import{a as qe}from"./chunk-VE3SUJMA.js";import{c as We}from"./chunk-SMXABALN.js";import{a as be}from"./chunk-YCVEI7BT.js";import{a as Ge}from"./chunk-PCQK62MP.js";import{a as He}from"./chunk-ZCBOHWN3.js";import{a as re}from"./chunk-HCBYKLMW.js";import{a as h,b as f,h as Fe,i as Se,k as Ne}from"./chunk-33DWJV67.js";import{a as we}from"./chunk-6YGTRKDT.js";import{b as Le,z as u}from"./chunk-J4FIESTB.js";import{e as $}from"./chunk-UR6MHSHU.js";var je=$(we(),1);import{readFileSync as ct,writeFileSync as ut,mkdirSync as ft}from"fs";import{dirname as dt,join as ze}from"path";var mt=ze(Le,"command-history.json"),Dt=ze(Le,"generate-history.json"),ht=200,De=class{entries;filePath;max;constructor(t=mt,e=ht){this.filePath=t,this.max=e,this.entries=this._load()}push(t){this.entries.length>0&&this.entries[this.entries.length-1]===t||(this.entries.push(t),this.entries.length>this.max&&(this.entries=this.entries.slice(this.entries.length-this.max)),this._save())}getAll(){return[...this.entries]}search(t){let e=t.toLowerCase(),o=[];for(let s=this.entries.length-1;s>=0;s--)this.entries[s].toLowerCase().includes(e)&&o.push(this.entries[s]);return o}_load(){if(this.filePath===null)return[];try{let t=ct(this.filePath,"utf-8"),e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}_save(){if(this.filePath!==null)try{ft(dt(this.filePath),{recursive:!0}),ut(this.filePath,JSON.stringify(this.entries)+`
2
+ import{a as Ye}from"./chunk-EG3B52WU.js";import{c as We}from"./chunk-SMXABALN.js";import{b as Ve}from"./chunk-QXZGBYGQ.js";import{a as qe}from"./chunk-VE3SUJMA.js";import{a as Ge}from"./chunk-6CMBA5SG.js";import{a as be}from"./chunk-RNKJXVG2.js";import{a as re}from"./chunk-HCBYKLMW.js";import{a as He}from"./chunk-73EHVDL5.js";import{b as Le,z as u}from"./chunk-YKOZBFR3.js";import{a as h,b as f,h as Fe,i as Se,k as Ne}from"./chunk-33DWJV67.js";import{a as we}from"./chunk-6YGTRKDT.js";import{e as $}from"./chunk-UR6MHSHU.js";var je=$(we(),1);import{readFileSync as ct,writeFileSync as ut,mkdirSync as ft}from"fs";import{dirname as dt,join as ze}from"path";var mt=ze(Le,"command-history.json"),Dt=ze(Le,"generate-history.json"),ht=200,De=class{entries;filePath;max;constructor(t=mt,e=ht){this.filePath=t,this.max=e,this.entries=this._load()}push(t){this.entries.length>0&&this.entries[this.entries.length-1]===t||(this.entries.push(t),this.entries.length>this.max&&(this.entries=this.entries.slice(this.entries.length-this.max)),this._save())}getAll(){return[...this.entries]}search(t){let e=t.toLowerCase(),o=[];for(let s=this.entries.length-1;s>=0;s--)this.entries[s].toLowerCase().includes(e)&&o.push(this.entries[s]);return o}_load(){if(this.filePath===null)return[];try{let t=ct(this.filePath,"utf-8"),e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}_save(){if(this.filePath!==null)try{ft(dt(this.filePath),{recursive:!0}),ut(this.filePath,JSON.stringify(this.entries)+`
3
3
  `)}catch{}}};function kt(n){let t=(0,je.useRef)(null);return t.current||(t.current=new De(n)),t.current}var D=$(we(),1);var ke=$(we(),1);var Z=$(re(),1);function Xe({history:n,onSelect:t,onClose:e}){let[o,s]=(0,ke.useState)(""),[l,m]=(0,ke.useState)(0),v=o?n.search(o).slice(0,8):[];return Se((b,d)=>{if(d.escape){e();return}if(d.return){v.length>0&&v[l]?t(v[l]):e();return}if(d.upArrow){m(S=>Math.max(0,S-1));return}if(d.downArrow){m(S=>Math.min(v.length-1,S+1));return}if(d.backspace||d.delete){s(S=>S.slice(0,-1)),m(0);return}b&&!d.ctrl&&!d.meta&&(s(S=>S+b),m(0))}),(0,Z.jsxs)(h,{flexDirection:"column",marginLeft:2,borderStyle:"single",paddingX:1,children:[(0,Z.jsx)(f,{color:u.muted,bold:!0,children:"reverse search"}),(0,Z.jsxs)(h,{gap:1,children:[(0,Z.jsx)(f,{color:u.dim,children:"search:"}),(0,Z.jsx)(f,{children:o}),(0,Z.jsx)(f,{color:u.orange,children:"\u2588"})]}),v.length>0&&(0,Z.jsx)(f,{children:" "}),v.map((b,d)=>(0,Z.jsx)(h,{marginLeft:2,children:(0,Z.jsxs)(f,{color:d===l?u.orange:u.dim,bold:d===l,children:[d===l?"\u25B8 ":" ",b]})},`${d}-${b}`))]})}var X=$(re(),1);function Je({commands:n,selectedIndex:t}){return n.length===0?null:(0,X.jsx)(h,{flexDirection:"column",marginBottom:0,children:n.map((e,o)=>{let s=o===t;return e.disabled?(0,X.jsxs)(h,{children:[(0,X.jsx)(f,{color:u.dim,children:s?"\u276F ":" "}),(0,X.jsxs)(f,{color:u.dim,children:["/",e.name]}),(0,X.jsxs)(f,{color:u.dim,children:[" ",e.disabledReason??e.description]})]},e.name):(0,X.jsxs)(h,{children:[(0,X.jsx)(f,{color:s?u.orange:u.dim,children:s?"\u276F ":" "}),(0,X.jsxs)(f,{color:s?u.orange:void 0,bold:s,children:["/",e.name]}),e.args&&(0,X.jsxs)(f,{color:u.dim,children:[" ",e.args]}),(0,X.jsxs)(f,{color:u.dim,children:[" ",e.description]})]},e.name)})})}var Ze=$(we(),1);var q=$(re(),1),et={scenario:"Scenarios",case:"Test Cases",file:"Files",artifact:"Artifact candidates",installed:"Installed on device"};function Qe(n){let t={scenario:0,case:0,file:0,artifact:0,installed:0};for(let e of n)t[e.kind]++;return["scenario","case","file","artifact","installed"].filter(e=>t[e]>0).map(e=>`${t[e]} ${et[e]}`).join(" \xB7 ")}var Pe=7;function tt({items:n,selectedIndex:t,accent:e=u.orange}){let o=n.length;if(o===0)return null;let s=Math.floor(Pe/2),l=o<=Pe?0:Math.max(0,Math.min(t-s,o-Pe)),m=Math.min(o,l+Pe),v=l,b=o-m;return(0,q.jsxs)(h,{flexDirection:"column",marginBottom:0,children:[v>0&&(0,q.jsx)(h,{children:(0,q.jsx)(f,{color:u.dim,children:` \u22EF ${v} above \u2014 ${Qe(n.slice(0,l))}`})}),n.slice(l,m).map((d,S)=>{let U=l+S,F=d.selectable!==!1,E=U===t&&F,R=S===0||n[U-1].kind!==d.kind;return(0,q.jsxs)(Ze.default.Fragment,{children:[R&&(0,q.jsx)(h,{children:(0,q.jsx)(f,{color:u.dim,children:et[d.kind]})}),(0,q.jsxs)(h,{children:[(0,q.jsx)(f,{color:E?e:u.dim,children:E?"\u276F ":" "}),(0,q.jsxs)(f,{color:E?e:F?void 0:u.dim,bold:E,children:[d.label,d.reason?` \u2014 ${d.reason}`:""]})]})]},`${d.kind}:${d.value}:${U}`)}),b>0&&(0,q.jsx)(h,{children:(0,q.jsx)(f,{color:u.dim,children:` \u22EF ${b} more \u2014 ${Qe(n.slice(m))}`})})]})}var Be=$(we(),1);var gt=27,pt=127,xt=11;function bt(n){return n>=64&&n<=126}function Tt(n,t){n===xt&&t({killToEnd:!0,ctrl:!0,raw:String.fromCharCode(n)})}function vt(n,t){n===pt&&t({backspace:!0,meta:!0,raw:"\x1B\x7F"})}function wt(n,t){let e=n.map(s=>String.fromCharCode(s)).join(""),o=/^\[1;([0-9]+)([A-D])$/.exec(e);if(o){let s=parseInt(o[1],10),l=o[2],m={raw:"\x1B"+e};if(s===2)m.shift=!0;else if(s===3)m.meta=!0;else if(s===5)m.ctrl=!0;else return;l==="A"?m.arrowUp=!0:l==="B"?m.arrowDown=!0:l==="C"?m.arrowRight=!0:l==="D"&&(m.arrowLeft=!0),t(m);return}if(e==="[H"||e==="[1~"||e==="[7~"){t({home:!0,raw:"\x1B"+e});return}if(e==="[F"||e==="[4~"||e==="[8~"){t({end:!0,raw:"\x1B"+e});return}if(e==="[3;5~"){t({delete:!0,ctrl:!0,raw:"\x1B"+e});return}if(e==="[3;3~"){t({delete:!0,meta:!0,raw:"\x1B"+e});return}}function St(n,t){n===72?t({home:!0,raw:"\x1BO"+String.fromCharCode(n)}):n===70&&t({end:!0,raw:"\x1BO"+String.fromCharCode(n)})}function Et(){let n="IDLE",t=[];function e(){n="IDLE",t=[]}return{feed(o,s){for(let l of o)n==="IDLE"?l===gt?(n="ESC",t=[]):Tt(l,s):n==="ESC"?l===91?(n="CSI",t=[]):l===79?(n="SS3",t=[]):(vt(l,s),e()):n==="CSI"?(t.push(l),bt(l)&&(wt([91,...t],s),e())):n==="SS3"&&(St(l,s),e())},flushIdle(o){n==="ESC"&&t.length===0&&o({raw:"\x1B"}),e()}}}function nt(n,t={}){let e=(0,Be.useRef)(n);e.current=n;let{stdin:o}=Fe();(0,Be.useEffect)(()=>{if(t.isActive===!1||!o)return;let s=Et(),l=null,m=v=>{l&&(clearTimeout(l),l=null);let b=Buffer.isBuffer(v)?v:Buffer.from(v,"binary");s.feed(b,d=>e.current(d)),l=setTimeout(()=>{s.flushIdle(d=>e.current(d)),l=null},50)};return o.on("data",m),()=>{o.removeListener("data",m),l&&clearTimeout(l)}},[t.isActive,o])}var w=$(re(),1);function yt(n,t){let e=t-1;for(;e>=0&&n[e]!=="@"&&n[e]!==" "&&n[e]!==`
4
4
  `;)e--;return e<0||n[e]!=="@"||e>0&&n[e-1]!==" "&&n[e-1]!==`
5
5
  `?null:{at:e,query:n.slice(e+1,t).join("")}}function rt(n,t,e){for(let o=t+e;o>=0&&o<n.length;o+=e)if(n[o]?.selectable!==!1)return o;return t}function At(n){let t=n.findIndex(e=>e.selectable!==!1);return t===-1?0:t}var Oe=10;function Rt(n){return n.replace(/\x1b?\[200~/g,"").replace(/\x1b?\[201~/g,"").replace(/\r\n/g,`
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as Ee,b as te}from"./chunk-GFLB2SHW.js";import{a as ee}from"./chunk-2TVPA3LL.js";import{c as G}from"./chunk-22PIMG52.js";import{a as z}from"./chunk-RQKMSNEU.js";import{a as v,b as be,d as B,e as Te}from"./chunk-4C7WVQOD.js";import{a as M}from"./chunk-QXQ7KVEN.js";import{a as Se}from"./chunk-Z47ZEFH7.js";import{b as we,c as ye,d as Re,e as Z,f as $e}from"./chunk-7YV2FCN4.js";import{na as ve,oa as P}from"./chunk-PI7OXS62.js";import{g as fe}from"./chunk-UJLULWSR.js";import{basename as wt,relative as ce}from"path";function Vt(e){return e.scope?.state==="finalized"?"saved":e.scope?.state==="discarded"?"discarded":e.ended==="complete"?"ready_to_save":e.ended==="failed"||e.status==="failed"?"failed":e.status==="paused"||e.status==="needs_attention"?"paused":"running"}var ne=["useCases","criteria","scenarios","tests","openQuestions","sources","styleNotes"],H=new Set(["sources","styleNotes"]);function xe(e){return ne.reduce((t,n)=>t+(H.has(n)?0:e[n]??0),0)}var nt=new Set(["NO_CASE","CASE_BROKEN","TEST_FILE_STALE","CASE_ARCHIVED"]),U=e=>typeof e=="string"?e:null;function st(e){let t=e.extra;switch(e.code){case"CASE_BROKEN":return{code:"CASE_BROKEN",session:U(t.session),caseId:U(t.caseId)??"",reason:t.reason==="moved"?"moved":"deleted"};case"CASE_ARCHIVED":return{code:"CASE_ARCHIVED",caseId:U(t.caseId)??"",internalId:U(t.internalId)??""};default:return{code:e.code,session:U(t.session),useCase:U(t.useCase)}}}function Jt(e){return(Array.isArray(e.nodes)?e.nodes:[]).filter(n=>typeof n.cid=="string"&&typeof n.label=="string").map(n=>({cid:n.cid,label:n.label,content:typeof n.content=="object"&&n.content!==null?n.content:{}}))}function qt(e){return(Array.isArray(e.names)?e.names:[]).filter(n=>typeof n.cid=="string"&&typeof n.slug=="string").map(n=>({cid:n.cid,slug:n.slug}))}function Kt(e){return(Array.isArray(e.supersessions)?e.supersessions:[]).filter(n=>n.kind==="node"&&typeof n.old=="string").map(n=>({old:n.old,new:typeof n.new=="string"?n.new:null}))}function Yt(e){let{request:t,exchange:n}=B(e),o=(s,r)=>`/v1/projects/${encodeURIComponent(s)}/uploads/${r}`,d=s=>`/v1/sessions/${encodeURIComponent(s)}`,a=async(s,r=null)=>{let l=[],g=r;do{let c=await t("GET",`${s}${g===null?"":`&after=${encodeURIComponent(g)}`}`);l.push(...c.items),g=c.next}while(g!==null);return l},i=async(s,r)=>{let l=await t("GET",`/v1/projects/${encodeURIComponent(s)}/sessions/${encodeURIComponent(r)}`),{proposes:g,heldChanges:c,changes:p,approves:u,archives:m,removes:w,chatTurns:h,uncounted:f}=l.drafts;return{proposes:g,heldChanges:c??0,changes:p??{},approves:u??{},archives:m??{},removes:w??{},chatTurns:h??0,uncounted:typeof f=="number"?f:null}};return{async*projects(){for(let s=1;s!==null;){let r=await t("GET",`/v1/projects?page=${s}`);r.items.length>0&&(yield r.items.map(({projectId:l,name:g,marked:c})=>({projectId:l,name:g,marked:c}))),s=r.next}},async project(s){let l=(await t("GET",`/v1/projects?projectId=${encodeURIComponent(s)}`)).items.find(g=>g.projectId===s);return l===void 0?null:{projectId:s,marked:l.marked===!0,mainPosition:l.context?.mainPosition??null}},async testCase(s,r,l){try{let g=await t("GET",`/v1/projects/${encodeURIComponent(s)}/tests/${encodeURIComponent(r)}/case?base=${encodeURIComponent(l)}`),{test:c,scenario:p,useCase:u,caseId:m,internalId:w,title:h,current:f,counts:$,canAttach:S}=g;return{linked:{test:c,scenario:p,useCase:u,caseId:m,internalId:w,title:h,current:f,counts:$,canAttach:S}}}catch(g){if(g instanceof v&&g.status===409&&nt.has(g.code))return{refused:st(g)};throw g}},async testCases(s){let r=await t("GET",`/v1/projects/${encodeURIComponent(s)}/graph?project=1&types=testCase`),l=g=>g.linkState==="linked"&&typeof g.internalId=="string"&&/^TC-\d+$/.test(g.internalId)?g.internalId:null;return new Map(r.nodes.filter(g=>g.type==="testCase").map(g=>[g.id,l(g.data)]))},async createSession(s){return(await t("POST","/v1/sessions",s)).session},async sources(s){let r=[],l=null;do{let g=`limit=1000${l===null?"":`&after=${encodeURIComponent(l)}`}`,c=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/sources?${g}`);r.push(...c.items.map(({sourceId:p,head:u,completeness:m,origin:w,media:h})=>({sourceId:p,head:u,completeness:m,...w!==void 0?{origin:w}:{},...h!==void 0?{media:h}:{}}))),l=c.next}while(l!==null);return r},async mainRecord(s,r){let l=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/positions/${r}`);return{position:l.position,record:l.record}},async mainNode(s,r){let l=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/nodes/${encodeURIComponent(r)}`);return{cid:l.cid,name:l.name,label:l.label,content:l.content??{},supersededBy:l.supersededBy??null,edgesOut:(l.edgesOut??[]).map(({type:g,dst:c,other:p})=>({type:g,dst:c,other:p??null}))}},nodes:(s,r)=>a(`/v1/internal/projects/${encodeURIComponent(s)}/nodes?label=${encodeURIComponent(r)}&limit=1000`),async testsWithContent(s){let r=`/v1/internal/projects/${encodeURIComponent(s)}/nodes?label=test&content=1&limit=200`,l;try{l=await t("GET",r)}catch(c){if(c instanceof v&&c.status===400&&c.code==="BAD_REQUEST"&&c.message.includes('Unrecognized key: "content"'))return null;throw c}let g=l.next===null?[]:await a(r,l.next);return[...l.items,...g].map(c=>({...c,content:c.content??{}}))},edges:(s,r)=>a(`/v1/internal/projects/${encodeURIComponent(s)}/edges?type=${encodeURIComponent(r)}&limit=1000`),stale:s=>a(`/v1/internal/projects/${encodeURIComponent(s)}/stale?limit=1000`),async listSessions(s,r={}){let l=[],g=null,c=`${r.sourceId?`&sourceId=${encodeURIComponent(r.sourceId)}`:""}${r.useCase?`&useCase=${encodeURIComponent(r.useCase)}`:""}`;do{let p=`projectId=${encodeURIComponent(s)}${c}${g===null?"":`&after=${encodeURIComponent(g)}`}`,u=await t("GET",`/v1/sessions?${p}`);l.push(...u.items),g=u.next}while(g!==null);return l},getSession:s=>t("GET",d(s)),setStatus:(s,r)=>t("PATCH",d(s),{status:r}),land:(s,r)=>t("POST",`${d(s)}/land`,{generation:r}),discard:(s,r)=>t("POST",`${d(s)}/discard`,r===void 0?{}:{generation:r}),proposes:async(s,r)=>(await i(s,r)).proposes,counts:i,openUpload:(s,r)=>t("POST",`/v1/projects/${encodeURIComponent(s)}/uploads`,r),putUpload:async(s,r,l,g)=>{let{response:c,bytes:p}=await n("PUT",s,l,{headers:r,route:"PUT upload",...g?{onSend:g}:{}}),u=c.headers.get("etag");if(p.length>0)try{let m=JSON.parse(p.toString("utf8"));typeof m.etag=="string"&&(u=m.etag)}catch{}if(!u)throw new v(c.status,"BAD_RESPONSE","the upload's store answered no etag");return{etag:u}},completeUpload:(s,r,l)=>t("POST",`${o(s,r)}/complete`,{etag:l}),getUpload:(s,r)=>t("GET",o(s,r)),uploadResult:(s,r,l)=>t("POST",`${o(s,r)}/result`,l),async projectCoverage(s){let{state:r,doc:l}=await t("GET",`/v1/projects/${encodeURIComponent(s)}/coverage`);return{state:r,doc:l}},async coverageRun(s,r){return{pack:(await t("POST",`/v1/projects/${encodeURIComponent(s)}/coverage/run`,r)).pack}}}}import{isMainThread as lt}from"worker_threads";import{createHash as dt}from"crypto";function se(e){return e instanceof Error?e.message:String(e)}var ke="SUPERSEDED_WRITER",en="LEASE_LAPSED";function tn(e){let t=`/v1/sessions/${encodeURIComponent(e.sessionId)}/host`,{exchange:n,request:o}=B(e),d=i=>i===null?"limit=1000":`after=${encodeURIComponent(i)}&limit=1000`,a=i=>i===void 0?t:`${t}/children/${encodeURIComponent(i)}`;return{claim:()=>o("POST",`${t}/claim`,{forms:1}),session:()=>o("GET",t),renewLease:i=>o("POST",`${t}/lease`,{generation:i}),save:i=>o("PATCH",t,i),checkpointRows:i=>o("GET",`${a(i)}/checkpoints`,void 0,!0),async readCheckpointRow(i,s){return(await o("GET",`${a(s)}/checkpoints/${i}`,void 0,!0)).text},async writeCheckpointRow(i,s,r,{ifAbsent:l=!1,childId:g}={}){let c=`${a(g)}/checkpoints/${s}${l?"?ifAbsent=true":""}`;return(await o("PUT",c,{generation:i,text:r})).stored},async removeCheckpointRow(i,s,r){await o("DELETE",`${a(r)}/checkpoints/${s}?generation=${i}`)},registerChild:(i,s,r)=>o("POST",`${t}/children`,{generation:i,childId:s,...r?{useCase:r}:{}}),async sessionSide(){return(await o("GET",`${t}/side`)).text},async putSessionSide(i,s){await o("PUT",`${t}/side`,{generation:i,text:s})},saveChildPointer:(i,s,r,l)=>o("PATCH",a(s),{generation:i,checkpoint:r,state:l}),async sessionState(i){let{text:s}=await o("GET",`${a(i)}/state`);return s===null?null:JSON.parse(s)},async putSessionState(i,s,r){await o("PUT",`${a(r)}/state`,{generation:i,text:JSON.stringify(s)})},scope:()=>o("GET",`${t}/scope`),draftsPage:i=>o("GET",`${t}/scope/drafts?${d(i)}`,void 0,!0),appendDraft:(i,s)=>o("POST",`${t}/scope/drafts`,{generation:i,...s}),mainNodes:(i,s)=>o("POST",`${t}/main/nodes`,{position:i,cids:s}),async mainHistory(){let{response:i,bytes:s}=await n("GET",`${t}/main/history`,void 0,{headers:{"accept-encoding":"gzip"},bulk:!0}),r=Number(i.headers.get("lattice-history-position")),l=i.headers.get("lattice-history-hash");if(!Number.isInteger(r)||r<0||!l)throw new v(i.status,"UNEXPECTED_ANSWER",`GET ${t}/main/history answered without its Lattice-History-Position and Lattice-History-Hash headers`);return{position:r,hash:l,forms:be(i,"lattice-history-forms"),json:s}},async getBlob(i){try{return(await n("GET",`${t}/blobs/${encodeURIComponent(i)}`,void 0,{bulk:!0})).bytes}catch(s){if(s instanceof v&&s.code==="NOT_FOUND")return null;throw s}},putBlob:(i,s)=>o("PUT",`${t}/blobs?generation=${i}`,s),async files(i){return(await o("GET",`${t}/files?prefix=${encodeURIComponent(i)}`)).items},async readFile(i){try{let{response:s,bytes:r}=await n("GET",`${t}/file?name=${encodeURIComponent(i)}`,void 0,{bulk:!0}),l=Number(s.headers.get("lattice-file-version"));if(!Number.isInteger(l)||l<1)throw new v(s.status,"UNEXPECTED_ANSWER",`GET ${t}/file answered ${i} without a Lattice-File-Version header`);return{text:r.toString("utf8"),version:l}}catch(s){if(s instanceof v&&s.code==="NOT_FOUND")return null;throw s}},async embeddings(i,s){let r=`alias=${encodeURIComponent(i)}&purpose=${encodeURIComponent(s)}`,{bytes:l}=await n("GET",`${t}/embeddings?${r}`,void 0,{headers:{"accept-encoding":"gzip"},bulk:!0});return JSON.parse(l.toString("utf8"))},putEmbeddings:(i,s)=>o("POST",`${t}/embeddings`,{generation:i,...s}),putFile:(i,s,r,l)=>o("PUT",`${t}/file?name=${encodeURIComponent(s)}&generation=${i}&version=${r}`,l),appendEvents:(i,s)=>o("POST",`${t}/events`,{generation:i,events:s}),async eventsAfter(i){let s=[],r=null;do{let l=r===null?`after=${i}&limit=1000`:`after=${encodeURIComponent(r)}&limit=1000`,g=await o("GET",`${t}/events?${l}`);s.push(...g.items),r=g.next}while(r!==null);return s}}}var re="the session cannot go on: the project's context is being imported; it is served once an import of it completes",ot=5*6e4,Ce=2e3,it=15e3;function _e(e){return e instanceof v&&e.code==="CONTEXT_IMPORTING"}function Ie(){return new v(409,"CONTEXT_IMPORTING",re)}function on(e={}){let t=e.sleep??(a=>new Promise(i=>setTimeout(i,a))),n=e.budgetMs??ot,o=0,d=Ce;return{async wait(){let a=n-o;if(a<=0)return!1;let i=Math.min(d,a);return await t(i),o+=i,d=Math.min(d*2,it),!0},answered(){o=0,d=Ce}}}var R={scope:"store.scope",mainNodes:"store.mainNodes",mainNodesAhead:"store.mainNodesAhead",mainHistory:"store.mainHistory",drafts:"store.drafts",appendDraft:"store.appendDraft",vectorsRead:"store.vectorsRead",vectorsWrite:"store.vectorsWrite",getBlob:"store.getBlob",putBlob:"store.putBlob",chainRead:"chain.read",chainList:"chain.list",chainWrite:"chain.write",chainWriteIfAbsent:"chain.writeIfAbsent",chainRemove:"chain.remove",filesRead:"files.read",filesList:"files.list",filesWrite:"files.write",pointer:"session.pointer",stateGet:"session.stateGet",statePut:"session.statePut",acknowledge:"session.acknowledge",registerChild:"session.registerChild",children:"session.children",sideGet:"session.sideGet",sideSave:"session.sideSave"};var Pe=3e4,D=class extends Error{constructor(n,o,d,a=null){super(`Lattice refused ${n} (${o}): ${d}`);this.op=n;this.code=o;this.requestId=a;this.name="StepRefusedError"}};function ct(e){return e.status!==0?"not_ready":/no answer within/.test(e.message)?"timeout":"unreachable"}var Oe=new Set([ke,"SESSION_ENDED","PROJECT_NOT_MARKED"]);function fn(e,t){let n=t.sleep??(c=>new Promise(p=>setTimeout(p,c))),o=t.retryDeadlineMs??12e4,d=new Map((t.children??[]).map(c=>[c.childId,c.checkpoint?.pointer??null]));async function a(c,p){let u=Te(o,n,t.now);for(;;)try{let m=await p();return t.imports?.answered(),m}catch(m){if(!(m instanceof v))throw m;if(_e(m)&&t.imports){if(await t.imports.wait())continue;throw t.onStopped?.(Ie()),te(new Error(`Lattice refused ${c}: ${re}`),m)}if(Oe.has(m.code)&&t.onStopped?.(m),!m.retryable)throw new D(c,m.code,m.message,m.requestId);let w=h=>t.onRetry?.({op:c,attempt:u.attempt,nextInMs:h,giveUpAt:u.endsAt()??0,cause:ct(m)});if(!await u.again(w))throw t.onStopped?.(new v(m.status,m.code,`Lattice did not take ${c} within ${o/1e3} s: ${m.message}`,null,null,{},m.requestId)),te(new Error(`Lattice refused ${c} (${m.code}, still after ${o/1e3} s): ${m.message}`),m)}}async function i(c,p){try{return await p()}catch(u){throw u instanceof v?(Oe.has(u.code)&&t.onStopped?.(u),new D(c,u.code,u.message,u.requestId)):u}}async function s(c,p){let u=R.acknowledge,m=t.log;if(!m)throw new Error("the checkpoint barrier needs the session log, and this host gave it none");let w=Date.now()+Pe;for(;m.lastSeq()<c.eventSeq;){if(Date.now()>w)throw new Error(`the session log reached event ${m.lastSeq()}, not ${c.eventSeq}, within ${Pe/1e3} s; the checkpoint is not acknowledged`);await n(5)}await ut(m.flush(),o),await a(u,()=>e.writeCheckpointRow(t.generation,`side-${c.pointer.seq}.json`,JSON.stringify(c.side),{childId:p}));let h={pointer:c.pointer,covers:{eventSeq:c.eventSeq,scope:c.scope}},f=JSON.stringify(c.state);p===void 0?await a(u,()=>e.save({generation:t.generation,checkpoint:h,state:f})):d.set(p,(await a(u,()=>e.saveChildPointer(t.generation,p,h,f))).checkpoint.pointer)}async function r(){let c=await a(R.mainHistory,()=>e.mainHistory()),p=dt("sha256").update(c.json).digest("hex");if(p!==c.hash)throw new Error(`main's history from Lattice hashes to ${p}, not to ${c.hash}, the hash Lattice gave for it`);if(t.historyForms!==void 0&&c.forms!==t.historyForms){let u=`main's history pack was built at engine forms ${c.forms??"none named"}, not at ${t.historyForms}, the forms of the Lattice that took this host's claim: another Lattice served it`;throw t.onStopped?.(new v(409,"HISTORY_FORMS_MISMATCH",u)),new Error(u)}return c.json.toString("utf8")}let l=new Map,g=c=>`${Number(c.position)}:${c.cids.join(",")}`;return async(c,p)=>{let u=p??{},m=u.after??null,w=typeof u.childId=="string"?u.childId:void 0;switch(c){case R.scope:return await a(c,()=>e.scope());case R.mainHistory:return{json:await r()};case R.mainNodesAhead:{let h=e.mainNodes(Number(u.position),u.cids);return h.catch(()=>{}),l.set(g(u),h),null}case R.mainNodes:{let h=l.get(g(u));if(l.delete(g(u)),h)try{return await h}catch{}return await a(c,()=>e.mainNodes(Number(u.position),u.cids))}case R.drafts:return await a(c,()=>e.draftsPage(m));case R.appendDraft:{let h={eventId:u.eventId??null,record:u.record??null,envelope:u.envelope??null};return await a(c,()=>e.appendDraft(t.generation,h))}case R.filesRead:return(await a(c,()=>e.readFile(W(u.name))))?.text??null;case R.filesList:{let h=`${W(u.folder)}/`;return(await a(c,()=>e.files(h))).map($=>$.name.slice(h.length)).filter($=>!$.includes("/"))}case R.filesWrite:{if(!String(u.name).startsWith("rationale/"))throw new Error(`the host writes only test rationales; ${W(u.name)} is a configuration file, written by an operator`);try{return await a(c,()=>e.putFile(t.generation,W(u.name),0,Buffer.from(String(u.text),"utf8"))),{written:!0}}catch(h){if(/\(FILE_CHANGED\)/.test(se(h)))return{written:!1,message:se(h)};throw h}}case R.vectorsRead:return await i(c,()=>e.embeddings(String(u.alias),String(u.purpose)));case R.vectorsWrite:{let h={alias:String(u.alias),purpose:String(u.purpose),dims:Number(u.dims),vectors:u.vectors??{}};return await i(c,()=>e.putEmbeddings(t.generation,h))}case R.getBlob:{let h=await a(c,()=>e.getBlob(String(u.fingerprint)));return{bytes:h===null?null:h.toString("base64")}}case R.putBlob:return await a(c,()=>e.putBlob(t.generation,Buffer.from(String(u.bytes),"base64")));case R.chainRead:return await a(c,()=>e.readCheckpointRow(String(u.name),w));case R.chainList:return await a(c,()=>e.checkpointRows(w));case R.chainWrite:return await a(c,()=>e.writeCheckpointRow(t.generation,String(u.name),String(u.text),{childId:w})),null;case R.chainWriteIfAbsent:return await a(c,()=>e.writeCheckpointRow(t.generation,String(u.name),String(u.text),{ifAbsent:!0,childId:w}));case R.chainRemove:return await a(c,()=>e.removeCheckpointRow(t.generation,String(u.name),w)),null;case R.pointer:return w!==void 0?d.get(w)??null:(await a(c,()=>e.session())).checkpoint?.pointer??null;case R.stateGet:return await a(c,()=>e.sessionState(w));case R.statePut:return await a(c,()=>e.putSessionState(t.generation,u.state??null,w)),null;case R.acknowledge:return await s(u,w),null;case R.children:return[...(t.children??[]).map(h=>h.childId)];case R.sideGet:return await a(c,()=>e.sessionSide());case R.sideSave:return await a(c,()=>e.putSessionSide(t.generation,String(u.text))),{saved:!0};case R.registerChild:{let h=typeof u.useCase=="string"?u.useCase:void 0,f=await a(c,async()=>{try{return await e.registerChild(t.generation,String(u.childId),h)}catch($){throw $ instanceof v&&$.code==="SESSION_CLASH"?new Ee($.message,$.code,{heldBy:$.extra.heldBy??null},$.requestId):$}});return d.set(f.childId,f.checkpoint?.pointer??null),null}default:throw new Error(`the session thread asked for ${c}, which the main thread does not answer`)}}}function W(e){return`design/${String(e)}`}async function ut(e,t){let n,o=new Promise((d,a)=>{n=setTimeout(()=>a(new Error(`the session's events were not stored within ${t/1e3} s; the checkpoint is not acknowledged`)),t)});try{await Promise.race([e,o])}finally{clearTimeout(n)}}var x={verb:"remote",mode:"interactive"},oe=null,Ne=new Set;function Tn(e){x={...x,...e}}function V(e,t){return Ae(e,t),z()}function Ae(e,t){if(!(!Z()||Ne.has(e))){Ne.add(e);try{oe??=$e({verb:x.verb,mode:x.mode,contextRoot:null,env:Re(),sessionId:z(),errorsOnly:!0}),Object.assign(oe.ids,{...x.projectId?{project_id:x.projectId}:{},...x.latticeSessionId?{lattice_session_id:x.latticeSessionId}:{}}),oe.spoolError(e,t?{request_id:t}:{})}catch{}}}function gt(e){return e instanceof v||e instanceof D?`lattice_${e.code}`:"cli_crash"}function mt(e){let t=e?.requestId;return typeof t=="string"&&t?t:null}async function ht(){!Z()||!lt||await Promise.race([fe(ye()).catch(()=>{}),new Promise(e=>setTimeout(e,we).unref())])}async function xn(e,t){return e instanceof v&&Ae(gt(e),mt(e)),await ht(),t}import{isAbsolute as pt,relative as De}from"path";var k=e=>" ".repeat(e);function ft(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}var J=e=>e===1?"this test runs":"these tests run";function Ue(e,t,n){if(n===void 0||t+e.length<=n)return[k(t)+e];let o=[],d="";for(let a of e.split(" "))d&&t+d.length+1+a.length>n?(o.push(k(t)+d),d=a):d=d?`${d} ${a}`:a;return[...o,k(t)+d]}function _n(e,t){let n=e.variables.length;if(n===0)return[];let o=n===1?`\u2692 1 variable needs a value before ${J(t.tests)}; fill it in:`:`\u2692 ${n} variables need values before ${J(t.tests)}; fill them in:`,d=[k(t.indent)+o,k(t.indent+4)+(De(t.cwd,e.file)||e.file)],a=e.variables.filter(i=>i.start_page).map(i=>i.name);return a.length===1?d.push(...Ue(`${a[0]} is the page ${t.tests===1?"it starts":"they start"} on`,t.indent+4,t.columns)):a.length>1&&d.push(...Ue(`${ft(a)} are the pages they start on`,t.indent+4,t.columns)),d}function Le(e,t){let n=t.cwd??process.cwd(),o=s=>pt(s)&&De(n,s)||s,d=e.length;if(d===0)return[];let a=d===1?"\u2692 1 test has no start page yet, so it can't run as it is:":`\u2692 ${d} tests have no start page yet, so they can't run as they are:`,i=d===1?"name the page in its first step, or run it with --url <the page>":"name the page in each one's first step, or run them with --url <the page>";return[k(t.indent)+a,...e.map(s=>k(t.indent+4)+(s.file?o(s.file):`${s.test} ${s.title}`)),k(t.indent+4)+i]}function je(e,t){let n=e.variables.length,o=e.noStartPage.length;return[...n===0?[]:[n===1?`1 variable needs a value before ${J(t.tests)}`:`${n} variables need values before ${J(t.tests)}`],...o===0?[]:[o===1?"1 test has no start page yet":`${o} tests have no start page yet`]]}function Bn(e,t="--mode agent"){if(!e.next)return e.remedy?{remedy:e.remedy}:{};let n=(e.remedy??"").split(`
2
+ import{a as Ee,b as te}from"./chunk-GFLB2SHW.js";import{a as ee}from"./chunk-2TVPA3LL.js";import{c as G}from"./chunk-22PIMG52.js";import{a as v,b as be,d as B,e as Te}from"./chunk-4C7WVQOD.js";import{na as ve,oa as P}from"./chunk-5EAJO372.js";import{a as M}from"./chunk-QXQ7KVEN.js";import{a as Se}from"./chunk-DXXHCLFC.js";import{d as ye,e as Re,f as Z,h as $e}from"./chunk-IQMJJN52.js";import{a as we}from"./chunk-APXJRWIJ.js";import{a as z}from"./chunk-WTMCDYR3.js";import{e as fe}from"./chunk-WMXBRC4B.js";import{basename as wt,relative as ce}from"path";function Vt(e){return e.scope?.state==="finalized"?"saved":e.scope?.state==="discarded"?"discarded":e.ended==="complete"?"ready_to_save":e.ended==="failed"||e.status==="failed"?"failed":e.status==="paused"||e.status==="needs_attention"?"paused":"running"}var ne=["useCases","criteria","scenarios","tests","openQuestions","sources","styleNotes"],H=new Set(["sources","styleNotes"]);function xe(e){return ne.reduce((t,n)=>t+(H.has(n)?0:e[n]??0),0)}var nt=new Set(["NO_CASE","CASE_BROKEN","TEST_FILE_STALE","CASE_ARCHIVED"]),U=e=>typeof e=="string"?e:null;function st(e){let t=e.extra;switch(e.code){case"CASE_BROKEN":return{code:"CASE_BROKEN",session:U(t.session),caseId:U(t.caseId)??"",reason:t.reason==="moved"?"moved":"deleted"};case"CASE_ARCHIVED":return{code:"CASE_ARCHIVED",caseId:U(t.caseId)??"",internalId:U(t.internalId)??""};default:return{code:e.code,session:U(t.session),useCase:U(t.useCase)}}}function Jt(e){return(Array.isArray(e.nodes)?e.nodes:[]).filter(n=>typeof n.cid=="string"&&typeof n.label=="string").map(n=>({cid:n.cid,label:n.label,content:typeof n.content=="object"&&n.content!==null?n.content:{}}))}function qt(e){return(Array.isArray(e.names)?e.names:[]).filter(n=>typeof n.cid=="string"&&typeof n.slug=="string").map(n=>({cid:n.cid,slug:n.slug}))}function Kt(e){return(Array.isArray(e.supersessions)?e.supersessions:[]).filter(n=>n.kind==="node"&&typeof n.old=="string").map(n=>({old:n.old,new:typeof n.new=="string"?n.new:null}))}function Yt(e){let{request:t,exchange:n}=B(e),o=(s,r)=>`/v1/projects/${encodeURIComponent(s)}/uploads/${r}`,d=s=>`/v1/sessions/${encodeURIComponent(s)}`,a=async(s,r=null)=>{let l=[],g=r;do{let c=await t("GET",`${s}${g===null?"":`&after=${encodeURIComponent(g)}`}`);l.push(...c.items),g=c.next}while(g!==null);return l},i=async(s,r)=>{let l=await t("GET",`/v1/projects/${encodeURIComponent(s)}/sessions/${encodeURIComponent(r)}`),{proposes:g,heldChanges:c,changes:p,approves:u,archives:m,removes:w,chatTurns:h,uncounted:f}=l.drafts;return{proposes:g,heldChanges:c??0,changes:p??{},approves:u??{},archives:m??{},removes:w??{},chatTurns:h??0,uncounted:typeof f=="number"?f:null}};return{async*projects(){for(let s=1;s!==null;){let r=await t("GET",`/v1/projects?page=${s}`);r.items.length>0&&(yield r.items.map(({projectId:l,name:g,marked:c})=>({projectId:l,name:g,marked:c}))),s=r.next}},async project(s){let l=(await t("GET",`/v1/projects?projectId=${encodeURIComponent(s)}`)).items.find(g=>g.projectId===s);return l===void 0?null:{projectId:s,marked:l.marked===!0,mainPosition:l.context?.mainPosition??null}},async testCase(s,r,l){try{let g=await t("GET",`/v1/projects/${encodeURIComponent(s)}/tests/${encodeURIComponent(r)}/case?base=${encodeURIComponent(l)}`),{test:c,scenario:p,useCase:u,caseId:m,internalId:w,title:h,current:f,counts:$,canAttach:S}=g;return{linked:{test:c,scenario:p,useCase:u,caseId:m,internalId:w,title:h,current:f,counts:$,canAttach:S}}}catch(g){if(g instanceof v&&g.status===409&&nt.has(g.code))return{refused:st(g)};throw g}},async testCases(s){let r=await t("GET",`/v1/projects/${encodeURIComponent(s)}/graph?project=1&types=testCase`),l=g=>g.linkState==="linked"&&typeof g.internalId=="string"&&/^TC-\d+$/.test(g.internalId)?g.internalId:null;return new Map(r.nodes.filter(g=>g.type==="testCase").map(g=>[g.id,l(g.data)]))},async createSession(s){return(await t("POST","/v1/sessions",s)).session},async sources(s){let r=[],l=null;do{let g=`limit=1000${l===null?"":`&after=${encodeURIComponent(l)}`}`,c=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/sources?${g}`);r.push(...c.items.map(({sourceId:p,head:u,completeness:m,origin:w,media:h})=>({sourceId:p,head:u,completeness:m,...w!==void 0?{origin:w}:{},...h!==void 0?{media:h}:{}}))),l=c.next}while(l!==null);return r},async mainRecord(s,r){let l=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/positions/${r}`);return{position:l.position,record:l.record}},async mainNode(s,r){let l=await t("GET",`/v1/internal/projects/${encodeURIComponent(s)}/nodes/${encodeURIComponent(r)}`);return{cid:l.cid,name:l.name,label:l.label,content:l.content??{},supersededBy:l.supersededBy??null,edgesOut:(l.edgesOut??[]).map(({type:g,dst:c,other:p})=>({type:g,dst:c,other:p??null}))}},nodes:(s,r)=>a(`/v1/internal/projects/${encodeURIComponent(s)}/nodes?label=${encodeURIComponent(r)}&limit=1000`),async testsWithContent(s){let r=`/v1/internal/projects/${encodeURIComponent(s)}/nodes?label=test&content=1&limit=200`,l;try{l=await t("GET",r)}catch(c){if(c instanceof v&&c.status===400&&c.code==="BAD_REQUEST"&&c.message.includes('Unrecognized key: "content"'))return null;throw c}let g=l.next===null?[]:await a(r,l.next);return[...l.items,...g].map(c=>({...c,content:c.content??{}}))},edges:(s,r)=>a(`/v1/internal/projects/${encodeURIComponent(s)}/edges?type=${encodeURIComponent(r)}&limit=1000`),stale:s=>a(`/v1/internal/projects/${encodeURIComponent(s)}/stale?limit=1000`),async listSessions(s,r={}){let l=[],g=null,c=`${r.sourceId?`&sourceId=${encodeURIComponent(r.sourceId)}`:""}${r.useCase?`&useCase=${encodeURIComponent(r.useCase)}`:""}`;do{let p=`projectId=${encodeURIComponent(s)}${c}${g===null?"":`&after=${encodeURIComponent(g)}`}`,u=await t("GET",`/v1/sessions?${p}`);l.push(...u.items),g=u.next}while(g!==null);return l},getSession:s=>t("GET",d(s)),setStatus:(s,r)=>t("PATCH",d(s),{status:r}),land:(s,r)=>t("POST",`${d(s)}/land`,{generation:r}),discard:(s,r)=>t("POST",`${d(s)}/discard`,r===void 0?{}:{generation:r}),proposes:async(s,r)=>(await i(s,r)).proposes,counts:i,openUpload:(s,r)=>t("POST",`/v1/projects/${encodeURIComponent(s)}/uploads`,r),putUpload:async(s,r,l,g)=>{let{response:c,bytes:p}=await n("PUT",s,l,{headers:r,route:"PUT upload",...g?{onSend:g}:{}}),u=c.headers.get("etag");if(p.length>0)try{let m=JSON.parse(p.toString("utf8"));typeof m.etag=="string"&&(u=m.etag)}catch{}if(!u)throw new v(c.status,"BAD_RESPONSE","the upload's store answered no etag");return{etag:u}},completeUpload:(s,r,l)=>t("POST",`${o(s,r)}/complete`,{etag:l}),getUpload:(s,r)=>t("GET",o(s,r)),uploadResult:(s,r,l)=>t("POST",`${o(s,r)}/result`,l),async projectCoverage(s){let{state:r,doc:l}=await t("GET",`/v1/projects/${encodeURIComponent(s)}/coverage`);return{state:r,doc:l}},async coverageRun(s,r){return{pack:(await t("POST",`/v1/projects/${encodeURIComponent(s)}/coverage/run`,r)).pack}}}}import{isMainThread as lt}from"worker_threads";import{createHash as dt}from"crypto";function se(e){return e instanceof Error?e.message:String(e)}var ke="SUPERSEDED_WRITER",en="LEASE_LAPSED";function tn(e){let t=`/v1/sessions/${encodeURIComponent(e.sessionId)}/host`,{exchange:n,request:o}=B(e),d=i=>i===null?"limit=1000":`after=${encodeURIComponent(i)}&limit=1000`,a=i=>i===void 0?t:`${t}/children/${encodeURIComponent(i)}`;return{claim:()=>o("POST",`${t}/claim`,{forms:1}),session:()=>o("GET",t),renewLease:i=>o("POST",`${t}/lease`,{generation:i}),save:i=>o("PATCH",t,i),checkpointRows:i=>o("GET",`${a(i)}/checkpoints`,void 0,!0),async readCheckpointRow(i,s){return(await o("GET",`${a(s)}/checkpoints/${i}`,void 0,!0)).text},async writeCheckpointRow(i,s,r,{ifAbsent:l=!1,childId:g}={}){let c=`${a(g)}/checkpoints/${s}${l?"?ifAbsent=true":""}`;return(await o("PUT",c,{generation:i,text:r})).stored},async removeCheckpointRow(i,s,r){await o("DELETE",`${a(r)}/checkpoints/${s}?generation=${i}`)},registerChild:(i,s,r)=>o("POST",`${t}/children`,{generation:i,childId:s,...r?{useCase:r}:{}}),async sessionSide(){return(await o("GET",`${t}/side`)).text},async putSessionSide(i,s){await o("PUT",`${t}/side`,{generation:i,text:s})},saveChildPointer:(i,s,r,l)=>o("PATCH",a(s),{generation:i,checkpoint:r,state:l}),async sessionState(i){let{text:s}=await o("GET",`${a(i)}/state`);return s===null?null:JSON.parse(s)},async putSessionState(i,s,r){await o("PUT",`${a(r)}/state`,{generation:i,text:JSON.stringify(s)})},scope:()=>o("GET",`${t}/scope`),draftsPage:i=>o("GET",`${t}/scope/drafts?${d(i)}`,void 0,!0),appendDraft:(i,s)=>o("POST",`${t}/scope/drafts`,{generation:i,...s}),mainNodes:(i,s)=>o("POST",`${t}/main/nodes`,{position:i,cids:s}),async mainHistory(){let{response:i,bytes:s}=await n("GET",`${t}/main/history`,void 0,{headers:{"accept-encoding":"gzip"},bulk:!0}),r=Number(i.headers.get("lattice-history-position")),l=i.headers.get("lattice-history-hash");if(!Number.isInteger(r)||r<0||!l)throw new v(i.status,"UNEXPECTED_ANSWER",`GET ${t}/main/history answered without its Lattice-History-Position and Lattice-History-Hash headers`);return{position:r,hash:l,forms:be(i,"lattice-history-forms"),json:s}},async getBlob(i){try{return(await n("GET",`${t}/blobs/${encodeURIComponent(i)}`,void 0,{bulk:!0})).bytes}catch(s){if(s instanceof v&&s.code==="NOT_FOUND")return null;throw s}},putBlob:(i,s)=>o("PUT",`${t}/blobs?generation=${i}`,s),async files(i){return(await o("GET",`${t}/files?prefix=${encodeURIComponent(i)}`)).items},async readFile(i){try{let{response:s,bytes:r}=await n("GET",`${t}/file?name=${encodeURIComponent(i)}`,void 0,{bulk:!0}),l=Number(s.headers.get("lattice-file-version"));if(!Number.isInteger(l)||l<1)throw new v(s.status,"UNEXPECTED_ANSWER",`GET ${t}/file answered ${i} without a Lattice-File-Version header`);return{text:r.toString("utf8"),version:l}}catch(s){if(s instanceof v&&s.code==="NOT_FOUND")return null;throw s}},async embeddings(i,s){let r=`alias=${encodeURIComponent(i)}&purpose=${encodeURIComponent(s)}`,{bytes:l}=await n("GET",`${t}/embeddings?${r}`,void 0,{headers:{"accept-encoding":"gzip"},bulk:!0});return JSON.parse(l.toString("utf8"))},putEmbeddings:(i,s)=>o("POST",`${t}/embeddings`,{generation:i,...s}),putFile:(i,s,r,l)=>o("PUT",`${t}/file?name=${encodeURIComponent(s)}&generation=${i}&version=${r}`,l),appendEvents:(i,s)=>o("POST",`${t}/events`,{generation:i,events:s}),async eventsAfter(i){let s=[],r=null;do{let l=r===null?`after=${i}&limit=1000`:`after=${encodeURIComponent(r)}&limit=1000`,g=await o("GET",`${t}/events?${l}`);s.push(...g.items),r=g.next}while(r!==null);return s}}}var re="the session cannot go on: the project's context is being imported; it is served once an import of it completes",ot=5*6e4,Ce=2e3,it=15e3;function _e(e){return e instanceof v&&e.code==="CONTEXT_IMPORTING"}function Ie(){return new v(409,"CONTEXT_IMPORTING",re)}function on(e={}){let t=e.sleep??(a=>new Promise(i=>setTimeout(i,a))),n=e.budgetMs??ot,o=0,d=Ce;return{async wait(){let a=n-o;if(a<=0)return!1;let i=Math.min(d,a);return await t(i),o+=i,d=Math.min(d*2,it),!0},answered(){o=0,d=Ce}}}var R={scope:"store.scope",mainNodes:"store.mainNodes",mainNodesAhead:"store.mainNodesAhead",mainHistory:"store.mainHistory",drafts:"store.drafts",appendDraft:"store.appendDraft",vectorsRead:"store.vectorsRead",vectorsWrite:"store.vectorsWrite",getBlob:"store.getBlob",putBlob:"store.putBlob",chainRead:"chain.read",chainList:"chain.list",chainWrite:"chain.write",chainWriteIfAbsent:"chain.writeIfAbsent",chainRemove:"chain.remove",filesRead:"files.read",filesList:"files.list",filesWrite:"files.write",pointer:"session.pointer",stateGet:"session.stateGet",statePut:"session.statePut",acknowledge:"session.acknowledge",registerChild:"session.registerChild",children:"session.children",sideGet:"session.sideGet",sideSave:"session.sideSave"};var Pe=3e4,D=class extends Error{constructor(n,o,d,a=null){super(`Lattice refused ${n} (${o}): ${d}`);this.op=n;this.code=o;this.requestId=a;this.name="StepRefusedError"}};function ct(e){return e.status!==0?"not_ready":/no answer within/.test(e.message)?"timeout":"unreachable"}var Oe=new Set([ke,"SESSION_ENDED","PROJECT_NOT_MARKED"]);function fn(e,t){let n=t.sleep??(c=>new Promise(p=>setTimeout(p,c))),o=t.retryDeadlineMs??12e4,d=new Map((t.children??[]).map(c=>[c.childId,c.checkpoint?.pointer??null]));async function a(c,p){let u=Te(o,n,t.now);for(;;)try{let m=await p();return t.imports?.answered(),m}catch(m){if(!(m instanceof v))throw m;if(_e(m)&&t.imports){if(await t.imports.wait())continue;throw t.onStopped?.(Ie()),te(new Error(`Lattice refused ${c}: ${re}`),m)}if(Oe.has(m.code)&&t.onStopped?.(m),!m.retryable)throw new D(c,m.code,m.message,m.requestId);let w=h=>t.onRetry?.({op:c,attempt:u.attempt,nextInMs:h,giveUpAt:u.endsAt()??0,cause:ct(m)});if(!await u.again(w))throw t.onStopped?.(new v(m.status,m.code,`Lattice did not take ${c} within ${o/1e3} s: ${m.message}`,null,null,{},m.requestId)),te(new Error(`Lattice refused ${c} (${m.code}, still after ${o/1e3} s): ${m.message}`),m)}}async function i(c,p){try{return await p()}catch(u){throw u instanceof v?(Oe.has(u.code)&&t.onStopped?.(u),new D(c,u.code,u.message,u.requestId)):u}}async function s(c,p){let u=R.acknowledge,m=t.log;if(!m)throw new Error("the checkpoint barrier needs the session log, and this host gave it none");let w=Date.now()+Pe;for(;m.lastSeq()<c.eventSeq;){if(Date.now()>w)throw new Error(`the session log reached event ${m.lastSeq()}, not ${c.eventSeq}, within ${Pe/1e3} s; the checkpoint is not acknowledged`);await n(5)}await ut(m.flush(),o),await a(u,()=>e.writeCheckpointRow(t.generation,`side-${c.pointer.seq}.json`,JSON.stringify(c.side),{childId:p}));let h={pointer:c.pointer,covers:{eventSeq:c.eventSeq,scope:c.scope}},f=JSON.stringify(c.state);p===void 0?await a(u,()=>e.save({generation:t.generation,checkpoint:h,state:f})):d.set(p,(await a(u,()=>e.saveChildPointer(t.generation,p,h,f))).checkpoint.pointer)}async function r(){let c=await a(R.mainHistory,()=>e.mainHistory()),p=dt("sha256").update(c.json).digest("hex");if(p!==c.hash)throw new Error(`main's history from Lattice hashes to ${p}, not to ${c.hash}, the hash Lattice gave for it`);if(t.historyForms!==void 0&&c.forms!==t.historyForms){let u=`main's history pack was built at engine forms ${c.forms??"none named"}, not at ${t.historyForms}, the forms of the Lattice that took this host's claim: another Lattice served it`;throw t.onStopped?.(new v(409,"HISTORY_FORMS_MISMATCH",u)),new Error(u)}return c.json.toString("utf8")}let l=new Map,g=c=>`${Number(c.position)}:${c.cids.join(",")}`;return async(c,p)=>{let u=p??{},m=u.after??null,w=typeof u.childId=="string"?u.childId:void 0;switch(c){case R.scope:return await a(c,()=>e.scope());case R.mainHistory:return{json:await r()};case R.mainNodesAhead:{let h=e.mainNodes(Number(u.position),u.cids);return h.catch(()=>{}),l.set(g(u),h),null}case R.mainNodes:{let h=l.get(g(u));if(l.delete(g(u)),h)try{return await h}catch{}return await a(c,()=>e.mainNodes(Number(u.position),u.cids))}case R.drafts:return await a(c,()=>e.draftsPage(m));case R.appendDraft:{let h={eventId:u.eventId??null,record:u.record??null,envelope:u.envelope??null};return await a(c,()=>e.appendDraft(t.generation,h))}case R.filesRead:return(await a(c,()=>e.readFile(W(u.name))))?.text??null;case R.filesList:{let h=`${W(u.folder)}/`;return(await a(c,()=>e.files(h))).map($=>$.name.slice(h.length)).filter($=>!$.includes("/"))}case R.filesWrite:{if(!String(u.name).startsWith("rationale/"))throw new Error(`the host writes only test rationales; ${W(u.name)} is a configuration file, written by an operator`);try{return await a(c,()=>e.putFile(t.generation,W(u.name),0,Buffer.from(String(u.text),"utf8"))),{written:!0}}catch(h){if(/\(FILE_CHANGED\)/.test(se(h)))return{written:!1,message:se(h)};throw h}}case R.vectorsRead:return await i(c,()=>e.embeddings(String(u.alias),String(u.purpose)));case R.vectorsWrite:{let h={alias:String(u.alias),purpose:String(u.purpose),dims:Number(u.dims),vectors:u.vectors??{}};return await i(c,()=>e.putEmbeddings(t.generation,h))}case R.getBlob:{let h=await a(c,()=>e.getBlob(String(u.fingerprint)));return{bytes:h===null?null:h.toString("base64")}}case R.putBlob:return await a(c,()=>e.putBlob(t.generation,Buffer.from(String(u.bytes),"base64")));case R.chainRead:return await a(c,()=>e.readCheckpointRow(String(u.name),w));case R.chainList:return await a(c,()=>e.checkpointRows(w));case R.chainWrite:return await a(c,()=>e.writeCheckpointRow(t.generation,String(u.name),String(u.text),{childId:w})),null;case R.chainWriteIfAbsent:return await a(c,()=>e.writeCheckpointRow(t.generation,String(u.name),String(u.text),{ifAbsent:!0,childId:w}));case R.chainRemove:return await a(c,()=>e.removeCheckpointRow(t.generation,String(u.name),w)),null;case R.pointer:return w!==void 0?d.get(w)??null:(await a(c,()=>e.session())).checkpoint?.pointer??null;case R.stateGet:return await a(c,()=>e.sessionState(w));case R.statePut:return await a(c,()=>e.putSessionState(t.generation,u.state??null,w)),null;case R.acknowledge:return await s(u,w),null;case R.children:return[...(t.children??[]).map(h=>h.childId)];case R.sideGet:return await a(c,()=>e.sessionSide());case R.sideSave:return await a(c,()=>e.putSessionSide(t.generation,String(u.text))),{saved:!0};case R.registerChild:{let h=typeof u.useCase=="string"?u.useCase:void 0,f=await a(c,async()=>{try{return await e.registerChild(t.generation,String(u.childId),h)}catch($){throw $ instanceof v&&$.code==="SESSION_CLASH"?new Ee($.message,$.code,{heldBy:$.extra.heldBy??null},$.requestId):$}});return d.set(f.childId,f.checkpoint?.pointer??null),null}default:throw new Error(`the session thread asked for ${c}, which the main thread does not answer`)}}}function W(e){return`design/${String(e)}`}async function ut(e,t){let n,o=new Promise((d,a)=>{n=setTimeout(()=>a(new Error(`the session's events were not stored within ${t/1e3} s; the checkpoint is not acknowledged`)),t)});try{await Promise.race([e,o])}finally{clearTimeout(n)}}var x={verb:"remote",mode:"interactive"},oe=null,Ne=new Set;function Tn(e){x={...x,...e}}function V(e,t){return Ae(e,t),z()}function Ae(e,t){if(!(!Z()||Ne.has(e))){Ne.add(e);try{oe??=$e({verb:x.verb,mode:x.mode,contextRoot:null,env:Re(),sessionId:z(),errorsOnly:!0}),Object.assign(oe.ids,{...x.projectId?{project_id:x.projectId}:{},...x.latticeSessionId?{lattice_session_id:x.latticeSessionId}:{}}),oe.spoolError(e,t?{request_id:t}:{})}catch{}}}function gt(e){return e instanceof v||e instanceof D?`lattice_${e.code}`:"cli_crash"}function mt(e){let t=e?.requestId;return typeof t=="string"&&t?t:null}async function ht(){!Z()||!lt||await Promise.race([fe(we()).catch(()=>{}),new Promise(e=>setTimeout(e,ye).unref())])}async function xn(e,t){return e instanceof v&&Ae(gt(e),mt(e)),await ht(),t}import{isAbsolute as pt,relative as De}from"path";var k=e=>" ".repeat(e);function ft(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}var J=e=>e===1?"this test runs":"these tests run";function Ue(e,t,n){if(n===void 0||t+e.length<=n)return[k(t)+e];let o=[],d="";for(let a of e.split(" "))d&&t+d.length+1+a.length>n?(o.push(k(t)+d),d=a):d=d?`${d} ${a}`:a;return[...o,k(t)+d]}function _n(e,t){let n=e.variables.length;if(n===0)return[];let o=n===1?`\u2692 1 variable needs a value before ${J(t.tests)}; fill it in:`:`\u2692 ${n} variables need values before ${J(t.tests)}; fill them in:`,d=[k(t.indent)+o,k(t.indent+4)+(De(t.cwd,e.file)||e.file)],a=e.variables.filter(i=>i.start_page).map(i=>i.name);return a.length===1?d.push(...Ue(`${a[0]} is the page ${t.tests===1?"it starts":"they start"} on`,t.indent+4,t.columns)):a.length>1&&d.push(...Ue(`${ft(a)} are the pages they start on`,t.indent+4,t.columns)),d}function Le(e,t){let n=t.cwd??process.cwd(),o=s=>pt(s)&&De(n,s)||s,d=e.length;if(d===0)return[];let a=d===1?"\u2692 1 test has no start page yet, so it can't run as it is:":`\u2692 ${d} tests have no start page yet, so they can't run as they are:`,i=d===1?"name the page in its first step, or run it with --url <the page>":"name the page in each one's first step, or run them with --url <the page>";return[k(t.indent)+a,...e.map(s=>k(t.indent+4)+(s.file?o(s.file):`${s.test} ${s.title}`)),k(t.indent+4)+i]}function je(e,t){let n=e.variables.length,o=e.noStartPage.length;return[...n===0?[]:[n===1?`1 variable needs a value before ${J(t.tests)}`:`${n} variables need values before ${J(t.tests)}`],...o===0?[]:[o===1?"1 test has no start page yet":`${o} tests have no start page yet`]]}function Bn(e,t="--mode agent"){if(!e.next)return e.remedy?{remedy:e.remedy}:{};let n=(e.remedy??"").split(`
3
3
  `).filter(o=>!/^\s+kane-cli /.test(o)).join(" ").replace(/(, run)?:$/,"").replace(/[,;]\s*(then\s+)?run:\s*kane-cli\b.*$/,"").trim();return{...n?{remedy:n}:{},next:e.next.map(o=>({cmd:`${o.cmd} ${t}`,why:o.why}))}}function Gn(e){let t=e;return!t||typeof t.sessionId!="string"||typeof t.verb!="string"?null:{sessionId:t.sessionId,verb:t.verb,useCase:typeof t.useCase=="string"?t.useCase:null,mine:t.mine===!0,status:typeof t.status=="string"?t.status:"running"}}var Hn=e=>({sid:e.sessionId,verb:e.verb,use_case:e.useCase,mine:e.mine,status:e.status}),yt={useCases:["use-case","use-cases"],criteria:["acceptance criterion","acceptance criteria"],scenarios:["scenario","scenarios"],tests:["test","tests"],openQuestions:["open question","open questions"],sources:["source","sources"],styleNotes:["style note","style notes"]},ue=ne.map(e=>[e,...yt[e]]),X=(e,t=H)=>{let n=ue.filter(([d])=>(e[d]??0)>0),o=n.filter(([d])=>!t.has(d));return o.length>0?o:n},Rt=new Set(["styleNotes"]),le=e=>e?ue.filter(([t])=>(e[t]??0)>0).map(([t,n,o])=>`${e[t]} ${e[t]===1?n:o}`):[];function $t(e){let t=o=>o?I(X(o).map(([d,a,i])=>`${o[d]} ${o[d]===1?a:i}`)):"",n=[[t(e),"added"],...Ve.map(({key:o,done:d})=>[t(e[o]),o==="changes"?"changed":d])].filter(([o])=>o!=="").map(([o,d])=>`${o} ${d}`);return N(e)>0&&n.push(Ke(N(e))),n.length>0?n.join(", "):null}function Wn(e){let t=$t(e.counts),n=[G(e.durS),...t?[t]:[],...e.credits!==void 0?[`${e.credits.toFixed(1)} credits`]:[]].join(" \xB7 "),o=e.title?`"${e.title}"`:P(e.id??"");return t||(e.counts.uncounted??0)>0?`\u25CF updated ${o} \u2014 ${n}`:`\u25CF nothing changed in ${o} \u2014 ${n}`}function Vn(e){let t=e.title?`"${e.title}"`:P(e.id??""),n=[G(e.durS),`${e.tests} ${e.tests===1?"test":"tests"}`,...e.credits!==void 0?[`${e.credits.toFixed(1)} credits`]:[]];return`\u25CF designed ${t} \u2014 ${n.join(" \xB7 ")}`}function Jn(e){return`\u25CF finished ${e.title?`"${e.title}"`:P(e.id??"")} \u2014 ${[G(e.durS),...e.credits!==void 0?[`${e.credits.toFixed(1)} credits`]:[]].join(" \xB7 ")}`}var I=e=>e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`,Ve=[{key:"changes",row:"updates",done:"updated",saving:"updates"},{key:"approves",row:"approves",done:"approved",saving:"approves"},{key:"archives",row:"archives",done:"archived",saving:"archives"},{key:"replaces",row:"replaces",done:"replaced",saving:"replaces"},{key:"removes",row:"removes",done:"removed",saving:"removes"}],Q=e=>Ve.filter(({key:t})=>j(e[t])),Je=e=>Q(e).length>0,ge=e=>e===1?"1 test":`${e} tests`,vt=e=>[...Q(e).map(({key:t,done:n})=>`${I(le(e[t]))} ${n}`),...e.keeps?[`${ge(e.keeps)} marked up to date`]:[]],qn=e=>[...Q(e).map(({key:t,saving:n})=>`saving it ${n} ${I(le(e[t]))}${t==="removes"?" from the project":""}`),...e.keeps?[`saving it marks ${ge(e.keeps)} up to date`]:[]],Kn=e=>[...vt(e),...N(e)>0?[Ye(N(e))]:[]],Yn=e=>ue.reduce((t,[n])=>t+(H.has(n)?0:e.changes?.[n]??0),0),Xn=e=>xe(e),bt=e=>F(e)!==""||j(e.changes)||j(e.approves)||j(e.archives),St="this session's work",Qn=e=>F(e)?"throw away what this session added":me(e)?"throw away this session's chat":"throw away this session's work",zn="already discarded \u2014 nothing was saved",Zn=e=>bt(e)?"your team can see it now":me(e)?Et:xt(e)?St:"",Et="this session's chat";function es(e,t){let n=t.removes;if(e==="extract"||!n||!((n.scenarios??0)>0||(n.tests??0)>0))return t;let o={...(n.scenarios??0)>0?{scenarios:n.scenarios}:{},...(n.tests??0)>0?{tests:n.tests}:{}},{scenarios:d,tests:a,...i}=n,{removes:s,...r}=t;return{...r,replaces:o,...j(i)?{removes:i}:{}}}function ts(e){let t=new Map;for(let n of e){if(n.kind!=="evolve_diff")continue;let o=n.payload??n.body;if(typeof o?.use_case!="string")continue;let d=o.repinned?.tests;typeof d=="number"&&d>0?t.set(o.use_case,d):t.delete(o.use_case)}return t}function ns(e,t){let n=[...t.values()].reduce((i,s)=>i+s,0);if(n===0)return e;let o=Math.max(0,(e.uncounted??0)-t.size),{uncounted:d,...a}=e;return{...a,keeps:n,...o>0?{uncounted:o}:{}}}var Tt=["changes","approves","archives","removes"],N=e=>e.heldChanges??0,j=e=>Object.values(e??{}).some(t=>(t??0)>0),qe=e=>!(e.adds??F(e))&&!Je(e)&&N(e)===0&&(e.keeps??0)===0,me=e=>qe(e)&&(e.chatTurns??0)>0&&(e.uncounted??0)===0,xt=e=>qe(e)&&!me(e);async function ss(e,t,n){let o=await e.counts(t,n),{proposes:d,heldChanges:a,chatTurns:i,uncounted:s}=o;return{...d,...a>0?{heldChanges:a}:{},...Object.fromEntries(Tt.flatMap(r=>j(o[r])?[[r,o[r]]]:[])),...i&&i>0?{chatTurns:i}:{},...typeof s=="number"?{exact:!0}:{},...typeof s=="number"&&s>0?{uncounted:s}:{}}}function Ke(e){return e===1?"1 change to an existing use-case":`${e} changes to existing use-cases`}function Ye(e){return`${Ke(e)}, saved but not applied`}var kt=e=>F(e)!==""||Je(e)||N(e)>0||(e.keeps??0)>0||(e.chatTurns??0)>0||(e.uncounted??0)>0,rs=(e,t)=>e.exact?kt(e):t;function os(e,t){let n=F(e),o=N(e),d=[];n&&d.push(["adds",n]);for(let{key:s,row:r}of Q(e))d.push([r,le(e[s]).join(", ")]);e.keeps&&d.push(["keeps",`${ge(e.keeps)}, marked up to date`]),o>0&&d.push(["held",Ye(o)]);let a=(e.chatTurns??0)>0;((e.uncounted??0)>0||!e.exact&&d.length===0&&!a)&&d.push(["other","work not counted here"]),a&&d.push(["chat","saved with the session; your team can read it"]),d.push(["project",t?"changed since this session started":"no changes since this session started"]);let i=s=>(s?.scenarios??0)+(s?.tests??0);return i(e)+i(e.changes)>0&&d.push(["then","its test cases are created or updated in Test Manager"]),d}function F(e){return X(e,Rt).map(([t,n,o])=>`${e[t]} ${e[t]===1?n:o}`).join(", ")}function is(e){let t=X(e);if(t.length!==1)return"your work is";let[n,o,d]=t[0];return e[n]===1?`your ${o} is`:`your ${e[n]} ${d} are`}function Ct(e,t=[]){return t.length>0?`start a new session from the latest project, adding this session's documents again; run:
4
4
  ${Xe(t)}`:`${e.startsWith("kane-cli design tests")?"to design it again from the latest project":"to start a new session from the latest project"}, run:
5
5
  ${e}`}var Xe=e=>`kane-cli context ingest ${e.map(Y).join(" ")}`;function as(e,t){return e.length>0?[...new Set(e)]:_t(t)}function _t(e){return[...new Set((e.uploads??[]).filter(t=>t.outcome==="created"&&t.filename).map(t=>t.filename))]}function It(e){let t=X(e);if(t.length!==1)return"its work";let[n,o,d]=t[0];return e[n]===1?`its ${o}`:`its ${e[n]} ${d}`}function ds(e){return e.replace(/\s*\([^()]*→[^()]*\)/g,"")}function cs(e,t,n){return`kane-cli ${e==="design"?"design tests":"context extract"} --resume ${t}${n?" --mode agent":""}`}var Me=e=>`updating kane-cli won't help \u2014 share this id with support: ${V(`refused_${e}`)}`,q="in a folder linked to a shared project",L="check the file, then run the command again",ie=e=>[`${e} has more inside it than kane-cli can read`,"save a smaller copy, or a PDF of it, then run the command again"],Pt={PDF_ENCRYPTED:e=>[`${e} is password-protected`,"remove the password, then run the command again"],PDF_NO_TEXT_LAYER:e=>[`${e} has no text to read; scanned PDFs aren't supported yet`,"use a PDF with text in it, then run the command again"],PDF_UNREADABLE:e=>[`${e} can't be read as a PDF`,L],DOCX_UNREADABLE:e=>[`${e} can't be read as a Word document`,L],DOCX_NOT_WORDPROCESSING:e=>[`${e} can't be read as a Word document`,L],DOCX_NO_TEXT:e=>[`${e} has no text to add`,L],DOCX_ENCRYPTED_OR_LEGACY:e=>[`${e} is password-protected or in the old Word format`,"save it as a .docx without a password, then run the command again"],DOCX_PART_TOO_LARGE:ie,DOCX_TOO_MANY_PARTS:ie,DOCX_BOMB:ie,SOURCE_ID_OWNED:e=>[`${e} can't become a version of that source: a source plugin reads it`,"add it under another id with --as <id>, then run the command again"]},Ot={changed_both_sides:"it was changed in Test Manager too; choose there which steps to keep",not_pushable:"its steps can't be changed from here; change them in Test Manager",archived:"it's archived in Test Manager; restore it there first",busy:"a test run is using it; wait until the run ends",not_accepted:"Test Manager has different steps for it; choose there which to keep"},O=e=>`${e} ${e===1?"test case":"test cases"}`,Fe={test_on_older_version:"it changed after its test was designed",test_unreadable:"its test can't be read",test_has_no_steps:"its test has no steps"},Qe=e=>ve.test(e)?e.toLowerCase():e,ze=e=>Object.hasOwn(Fe,e)?Fe[e]:void 0,Ze=e=>e.useCase&&ze(e.reason)!==void 0&&e.reason!=="test_unreadable"?Qe(e.useCase):null;function us(e){if(!e||e==="unread")return;let t=new Map([...e.wrote,...e.unchanged??[]].map(n=>[n.id.toLowerCase(),n.path]));for(let n of e.refused)n.file&&t.set(n.id.toLowerCase(),n.file);return n=>t.get(n.toLowerCase())}var de=e=>e.reason==="test_unreadable";function Nt(e,t){let n=ze(e.reason);if(n===void 0)return[{text:" it can't be sent to Test Manager yet",tone:"detail"}];if(e.reason==="test_unreadable"){let d=t?.(e.test);return[{text:` ${n}${d?`: ${pe(d)}`:""}`,tone:"detail"}]}let o=Ze(e);return o===null?[{text:` ${n}`,tone:"detail"}]:[{text:` ${n}; to design its tests again, run:`,tone:"detail"},{text:` kane-cli design tests --use-case ${o}`,tone:"detail",command:!0}]}var K=(e,t)=>t===void 0||typeof e.useCase!="string"||t.has(Qe(e.useCase));function At(e,t,n){let o=e===1,d=`to see ${o?"its use-case":"their use-cases"}, run: kane-cli context list --stale`,a=o?"1 scenario of another use-case":`${e} scenarios of other use-cases`;return n?[{text:` ${a} ${o?"isn't":"aren't"} in Test Manager either`,tone:"detail"},{text:` ${d}`,tone:"detail"}]:[{text:`${a} in ${y(t)} ${o?"isn't":"aren't"} in Test Manager`,tone:"detail"},{text:` ${d}`,tone:"detail"}]}var C="some test cases may not be there yet";function he(e,t){switch(e){case"TEST_MANAGER_TIMEOUT":return{why:`Test Manager took too long, so ${C}`,lead:`Test Manager took too long; ${C}`,next:"to finish them (nothing is saved twice), run:",remedy:!1,support:!1,agentCode:"TEST_MANAGER_TIMED_OUT"};case"FORGE_UNAVAILABLE":return{why:`Test Manager couldn't be reached, so ${C}`,lead:`Test Manager couldn't be reached; ${C}`,next:"to finish them (nothing is saved twice), run:",remedy:!1,support:!0,agentCode:"TEST_MANAGER_UNREACHABLE"};case"FORGE_REFUSED":return{why:`Test Manager refused your account, so ${C}`,lead:`Test Manager refused your account; ${C}`,next:"ask a Test Manager admin to grant your account access, then run:",remedy:!0,support:!1,agentCode:"PROJECT_NO_ACCESS"};case"PROJECT_NOT_MARKED":return{why:`assurance is now off for "${t}", so ${C}`,lead:`assurance is now off for "${t}"; ${C}`,next:"to try them again later (nothing is saved twice), run:",remedy:!0,support:!1,agentCode:"ASSURANCE_OFF"};default:return{why:"some test cases couldn't be created or updated in Test Manager",lead:"some test cases couldn't be created or updated in Test Manager",next:"to try them again (nothing is saved twice), run:",remedy:!1,support:!0,agentCode:"TEST_MANAGER_FAILED"}}}function ls(e,t,n,o,d){let a={receipt:null,summary:null,lines:[],support:!1};if(!e)return a;let{made:i,updated:s,waiting:r,error:l}=e,g=e.nextRun??[],c=e.notCovered??[],p=c.filter(b=>K(b,o)),u=c.length-p.length;if(i===0&&s===0&&r===0&&l===null&&g.length===0&&c.length===0)return a;let m=i>0&&s>0?`${O(i)} created and ${s} updated in Test Manager`:i>0?`${O(i)} created in Test Manager`:s>0?`${O(s)} updated in Test Manager`:null,w={text:` kane-cli context sessions save ${t}`,tone:"plain"},h=b=>b===1?"wasn't":"weren't",f=[];if(g.length>0){let b=g.length===1;f.push({text:`${O(g.length)} in Test Manager ${b?"updates on its":"update on their"} next kane-cli run:`,tone:"plain"});for(let A of g)f.push({text:` "${A.title}"`,tone:"detail"});(r>0||l!==null||c.length>0)&&f.push({text:"",tone:"plain"})}if(r>0){f.push({text:`warning: ${O(r)} in Test Manager ${h(r)} updated`,tone:"warning"});for(let b of e.waitingOn)f.push({text:` "${b.title}"`,tone:"detail"},{text:` ${Ot[b.reason]}`,tone:"detail"})}if(p.length>0){let b=p.length;f.push({text:`warning: ${b} ${b===1?"scenario wasn't":"scenarios weren't"} sent to Test Manager`,tone:"warning"});for(let A of p)f.push({text:` "${A.title}"`,tone:"detail"},...Nt(A,d))}u>0&&f.push(...At(u,n,p.length>0));let $=l===null?null:he(l.code,n);$&&f.push({text:`warning: the session was saved, but ${$.why}`,tone:"warning"});let S=$?$.remedy||r===0?$.next:"then, to finish them (nothing is saved twice), run:":r>0?`then, to update ${r===1?"it":"them"} (nothing is saved twice), run:`:null;S!==null&&f.push({text:`next: ${S}`,tone:"plain"},w);let E=[];if(m!==null&&E.push(m),r>0&&E.push(m!==null?`${r} ${h(r)} updated yet`:`${O(r)} in Test Manager ${h(r)} updated yet`),p.length>0){let b=p.length;E.push(`${E.length>0?b:`${b} ${b===1?"scenario":"scenarios"}`} ${b===1?"wasn't":"weren't"} sent to Test Manager`)}return $&&E.push(E.length>0?"some may not be there yet":$.lead),{receipt:m,summary:E.length>0?E.join("; "):null,...g.length>0?{nextRunSummary:`${O(g.length)} ${g.length===1?"updates on its":"update on their"} next kane-cli run`}:{},lines:f,support:($?.support??!1)||p.some(de)}}function gs(e,t,n,o){if(!e)return;let d=e.notCovered??[],a=[...new Set(d.flatMap(s=>{let r=K(s,n)?Ze(s):null;return r===null?[]:[r]}))],i=[...e.error!==null?[{cmd:`kane-cli context sessions save ${t} --mode agent`,why:"finishes the test cases that may not be there yet"}]:[],...a.map(s=>({cmd:`kane-cli design tests --use-case ${s} --force --mode agent`,why:"designs the use case's tests again, so its scenarios reach Test Manager"}))];return{total:e.total,created:e.made,updated:e.updated,already_there:e.linked,waiting:e.waiting,waiting_on:e.waitingOn.map(({scenario:s,title:r,reason:l})=>({scenario:s,title:r,reason:l})),next_run:(e.nextRun??[]).map(({scenario:s,title:r})=>({scenario:s,title:r})),...d.length>0?{not_covered:d.map(s=>{let r=de(s)?o?.(s.test):void 0;return{scenario:s.scenario,title:s.title,test:s.test,reason:s.reason,in_session:K(s,n),...r?{file:pe(r)}:{}}})}:{},...e.error!==null?{error:he(e.error.code,"").agentCode}:{},...d.some(s=>K(s,n)&&de(s))?{support_id:V("refused_TEST_UNREADABLE")}:{},...i.length>0?{next:i}:{}}}var Be=new Set(["duplicate","unwritable"]),et=e=>Be.has(e.kind)||e.kind==="import"&&e.via!==void 0&&Be.has(e.via),Ut=new Set(["unreadable","unresolved"]);function Dt(e,t){return!e||e.variables.length===0&&e.noStartPage.length===0?{}:{needed:{...e,tests:t},neededFacts:je(e,{tests:t})}}function Lt(e){if(!e||e.length===0)return{};let t=e.length===1?"1 test file here was replaced and won't run any more":`${e.length} test files here were replaced and won't run any more`;return{replacedHead:`\u2692 ${t}:`,replaced:e.map(n=>({file:ce(process.cwd(),n.file)||n.file,by:n.replacedBy.map(o=>wt(o))})),replacedSummary:t}}function jt(e){return e!=null&&e.error===null}var tt=(e,t)=>{if(!jt(t)||t.waitingOn.length>0)return[];let n=new Set((t.notCovered??[]).map(o=>o.test.toLowerCase()));return e.filter(o=>o.file&&!n.has(o.id.toLowerCase()))},pe=e=>M(ce(process.cwd(),e)||e);function ms(e,t,n,o={}){let d={text:` kane-cli context sessions save ${t}`,tone:"plain"};if(e==="unread")return{line:null,lines:[{text:"warning: the session was saved, but its test files couldn't be written here",tone:"warning"},{text:"next: to write them (nothing is saved twice), run:",tone:"plain"},d],support:!0,summary:"its test files aren't written here yet",kept:null,again:"all"};let a=e.wrote.length,i=e.refused.length,s=a+(e.unchanged?.length??0),r=s+i,l=e.saved?new Set(e.saved):null,g=l?e.wrote.filter(S=>!l.has(S.id)).length:0,c=S=>`${g} ${g===1?"test":"tests"} ${S?"it imports":"they import"}`,p=a===0?null:n||i===0&&s>a?`\u2692 wrote ${a===1?"1 test file that was":`${a} test files that were`} missing or out of date here`:i>0?`\u2692 wrote ${a} of the ${r} test files`:g>0?`\u2692 wrote ${a} test files, for ${a-g===1?`the saved test and ${c(!0)}`:`${a-g} saved tests and ${c(!1)}`}`:a===1?"\u2692 wrote 1 test file, for the saved test":`\u2692 wrote ${a} test files, one for each saved test`,u={...Lt(e.replaced),...Dt(e.needed,e.saved?.length??r)};if(i===0)return{line:p,lines:[],support:!1,summary:null,kept:null,again:0,...u};let w=[{text:`warning: ${i===r?`${i===1?"1 test file wasn't":`${i} test files weren't`} written`:`${i} of the ${r} test files ${i===1?"wasn't":"weren't"} written`}`,tone:"warning"}];for(let S of e.refused)w.push({text:S.title?` "${S.title}"`:" a test with no title",tone:"detail"},{text:` ${ee(S)}`,tone:"detail"});let h=e.refused.filter(et).length;h>0&&w.push({text:`next: then, to write ${h===1?"it":"them"} (nothing is saved twice), run:`,tone:"plain"},d);let f=e.refused.filter(S=>S.kind==="edited");if(f.length>0){let S=f.length===1,E=tt(f,o.testManager);if(E.length>0){w.push({text:E.length===1?"next: to send your edit to its test case in Test Manager, run:":"next: to send your edits to their test cases in Test Manager, run:",tone:"plain"});for(let A of E)w.push({text:` kane-cli testmd run ${pe(A.file)}`,tone:"plain"})}let b=`${E.length>0?"or, to":"next: to"} get the project's ${S?"version, move it":"versions, move them"} out of this folder`;h>0?w.push({text:`${b} and save again`,tone:"plain"}):w.push({text:`${b}, then run:`,tone:"plain"},d)}let $=i-f.length;return{line:p,lines:w,support:e.refused.some(S=>Ut.has(S.kind)),summary:s>0?`${s} of the ${r} test files written here`:$===0?null:f.length>0?`${$} of the ${r} test files ${$===1?"isn't":"aren't"} written here yet`:r===1?"its test file isn't written here yet":"its test files aren't written here yet",kept:f.length===0?null:f.length>1?`${f.length} test files here keep your edits`:r===1?"its test file here keeps your edit":"1 test file here keeps your edit",again:h,...u}}function hs(e,t,n){if(!e||!t||t.again===0)return null;let o=`write ${t.again===1?"the test file":"the test files"}`;return e.error!==null?he(e.error.code,n).remedy?null:`next: to finish them and ${o} (nothing is saved twice), run:`:e.waiting>0?`next: then, to update ${e.waiting===1?"the test case":"the test cases"} and ${o} (nothing is saved twice), run:`:null}function ps(e,t,n={}){let o=`kane-cli context sessions save ${t} --mode agent`;if(e==="unread")return{written:[],refused:[],error:"TEST_FILES_NOT_WRITTEN",next:[{cmd:o,why:"writes the test files here"}]};let d=e.refused.some(et),a=e.refused.filter(r=>r.kind==="edited"),i=a.length===0?"":a.length===1?", and the project's version of a kept file once it's moved out of its folder":", and the project's version of the kept files once they're moved out of their folder",s=[...d?[{cmd:o,why:`writes the test files not written here${i}`}]:[],...tt(a,n.testManager).map(r=>({cmd:`kane-cli testmd run ${M(r.file)} --agent`,why:"sends your edit to its test case in Test Manager"})),...a.length>0&&!d?[{cmd:o,why:"writes the project's version, once the file is moved out of its folder"}]:[]];return{written:e.wrote.map(r=>r.path),refused:e.refused.map(r=>({test:r.id,title:r.title,reason:ee(r),...r.kind==="edited"&&r.file?{file:r.file}:{}})),...e.replaced?.length?{replaced:e.replaced.map(r=>({test:r.test,file:r.file,replaced_by:r.replacedBy}))}:{},...e.needed?.variables.length?{variables_needed:{file:e.needed.file,variables:e.needed.variables}}:{},...e.needed?.noStartPage.length?{no_start_page:e.needed.noStartPage.map(r=>({test:r.test,...r.file?{file:r.file}:{}}))}:{},...s.length>0?{next:s}:{}}}var Mt={ac:"an acceptance criterion",scenario:"a scenario",test:"a test",gap:"an open question",source:"a source",stylenote:"a style note"},T=(e,t)=>e?`"${e}"`:P(t),Ge=(e,t,n)=>`${e} ${e===1?t:n}`,fs={trusted:"approved",derived:"proposed",archived:"archived"},ws={yes:"yes",source_changed:"no: its source changed",source_removed:"no: its source was removed",tests_out_of_date:"no: its tests are out of date",designed_from_changed:"no: what it was designed from changed",archived:"-"},ys={source_changed:"its source changed",source_removed:"its source was removed",tests_out_of_date:"changed after its tests were designed"},y=e=>e?`"${e}"`:"this session's project",_=(e,t)=>`kane-cli design tests --use-case ${e}${t}`,ae=e=>e?"its source's change was put off in an earlier review; to take it up":"to review its source's change",He=e=>e.split(`
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{b as B}from"./chunk-S3DAAAE5.js";import{a as g}from"./chunk-YVVFXBT5.js";import{a as w}from"./chunk-HCBYKLMW.js";import{a as x,b as t,c as h,i as P,j as S}from"./chunk-33DWJV67.js";import{a as C}from"./chunk-6YGTRKDT.js";import{z as s}from"./chunk-J4FIESTB.js";import{e as T}from"./chunk-UR6MHSHU.js";var o=T(C(),1);var e=T(w(),1);function D({defaultName:i,onSubmit:c}){let[d,p]=(0,o.useState)("confirm"),[f,a]=(0,o.useState)(""),[m,u]=(0,o.useState)(null),l=(0,o.useMemo)(()=>f.trim()||i,[f,i]);return P((n,r)=>{if(d==="confirm"){if(n==="y"||n==="Y"){a(i),p("name");return}if(n==="n"||n==="N"||r.escape||r.ctrl&&n==="c"){c(null);return}if(r.return){c(i);return}return}if(r.return){if(!B(l)){u(`name "${l}" is invalid; allowed: letters, digits, underscore, hyphen`);return}c(l);return}if(r.escape||r.ctrl&&n==="c"){c(null);return}if(r.backspace||r.delete){a(v=>v.slice(0,-1)),u(null);return}n&&!r.ctrl&&!r.meta&&(a(v=>v+n),u(null))}),d==="confirm"?(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsx)(t,{color:s.orange,children:i})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save with this name"}),(0,e.jsx)(t,{color:s.dim,children:"Y \u2014 edit name"}),(0,e.jsx)(t,{color:s.dim,children:"N/esc \u2014 discard session"})]})}):(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsxs)(x,{children:[(0,e.jsx)(t,{color:s.orange,children:f}),(0,e.jsx)(t,{inverse:!0,children:" "})]})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[m&&(0,e.jsx)(t,{color:s.red,children:m}),(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save \xB7 esc \u2014 discard"})]})})}function V(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}async function Y(i){return new Promise(c=>{function d(){let{exit:a}=S(),[m,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{if(m){let l=setTimeout(()=>a(),50);return()=>clearTimeout(l)}},[m,a]),(0,e.jsx)(D,{defaultName:i,onSubmit:l=>{c(l),u(!0)}})}let{waitUntilExit:p,unmount:f}=h((0,e.jsx)(d,{}),{stdout:process.stderr,exitOnCtrlC:!1});p().then(()=>{try{f()}catch{}})})}export{D as a,V as b,Y as c};
2
+ import{b as B}from"./chunk-S3DAAAE5.js";import{a as g}from"./chunk-4G2T54FE.js";import{a as w}from"./chunk-HCBYKLMW.js";import{z as s}from"./chunk-YKOZBFR3.js";import{a as x,b as t,c as h,i as P,j as S}from"./chunk-33DWJV67.js";import{a as C}from"./chunk-6YGTRKDT.js";import{e as T}from"./chunk-UR6MHSHU.js";var o=T(C(),1);var e=T(w(),1);function D({defaultName:i,onSubmit:c}){let[d,p]=(0,o.useState)("confirm"),[f,a]=(0,o.useState)(""),[m,u]=(0,o.useState)(null),l=(0,o.useMemo)(()=>f.trim()||i,[f,i]);return P((n,r)=>{if(d==="confirm"){if(n==="y"||n==="Y"){a(i),p("name");return}if(n==="n"||n==="N"||r.escape||r.ctrl&&n==="c"){c(null);return}if(r.return){c(i);return}return}if(r.return){if(!B(l)){u(`name "${l}" is invalid; allowed: letters, digits, underscore, hyphen`);return}c(l);return}if(r.escape||r.ctrl&&n==="c"){c(null);return}if(r.backspace||r.delete){a(v=>v.slice(0,-1)),u(null);return}n&&!r.ctrl&&!r.meta&&(a(v=>v+n),u(null))}),d==="confirm"?(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsx)(t,{color:s.orange,children:i})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save with this name"}),(0,e.jsx)(t,{color:s.dim,children:"Y \u2014 edit name"}),(0,e.jsx)(t,{color:s.dim,children:"N/esc \u2014 discard session"})]})}):(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsxs)(x,{children:[(0,e.jsx)(t,{color:s.orange,children:f}),(0,e.jsx)(t,{inverse:!0,children:" "})]})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[m&&(0,e.jsx)(t,{color:s.red,children:m}),(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save \xB7 esc \u2014 discard"})]})})}function V(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}async function Y(i){return new Promise(c=>{function d(){let{exit:a}=S(),[m,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{if(m){let l=setTimeout(()=>a(),50);return()=>clearTimeout(l)}},[m,a]),(0,e.jsx)(D,{defaultName:i,onSubmit:l=>{c(l),u(!0)}})}let{waitUntilExit:p,unmount:f}=h((0,e.jsx)(d,{}),{stdout:process.stderr,exitOnCtrlC:!1});p().then(()=>{try{f()}catch{}})})}export{D as a,V as b,Y as c};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{L as c,r as d}from"./chunk-PI7OXS62.js";function u(a,e,t){let{ref:r,reason:o,by:s}=t;if(!o||o.trim().length===0)return{record:null,errors:[{code:"REASON_REQUIRED",detail:"archiving a node needs a reason \u2014 it becomes the tombstone's provenance"}]};let i=e.resolve(r);if(!i)return{record:null,errors:[{code:"UNKNOWN_REF",detail:`no node '${r}' in the graph`}]};let n=e.tipOf(i.cid);return e.superseded.has(n)?{record:null,errors:[{code:"ALREADY_ARCHIVED",detail:`${r} is already superseded at its tip (${n.slice(0,19)}\u2026)`}]}:{record:c(a,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[{kind:"node",old:n,new:null,reason:o,by:s}],source_head_moves:{}},{graph:e,expectPrev:e.latestHash,intent:{v:1,verb:"archive",args:d({ref:r,reason:o,by:s}),pins:{ref:n}},provenance:t.provenance}).record,errors:null}}export{u as a};
2
+ import{L as c,r as d}from"./chunk-5EAJO372.js";function u(a,e,t){let{ref:r,reason:o,by:s}=t;if(!o||o.trim().length===0)return{record:null,errors:[{code:"REASON_REQUIRED",detail:"archiving a node needs a reason \u2014 it becomes the tombstone's provenance"}]};let i=e.resolve(r);if(!i)return{record:null,errors:[{code:"UNKNOWN_REF",detail:`no node '${r}' in the graph`}]};let n=e.tipOf(i.cid);return e.superseded.has(n)?{record:null,errors:[{code:"ALREADY_ARCHIVED",detail:`${r} is already superseded at its tip (${n.slice(0,19)}\u2026)`}]}:{record:c(a,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[{kind:"node",old:n,new:null,reason:o,by:s}],source_head_moves:{}},{graph:e,expectPrev:e.latestHash,intent:{v:1,verb:"archive",args:d({ref:r,reason:o,by:s}),pins:{ref:n}},provenance:t.provenance}).record,errors:null}}export{u as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{c as h,d as P}from"./chunk-SMXABALN.js";import{a as $}from"./chunk-HCBYKLMW.js";import{a as i,b as t,k as O}from"./chunk-33DWJV67.js";import{z as l}from"./chunk-J4FIESTB.js";import{e as y}from"./chunk-UR6MHSHU.js";var o=y($(),1);function L(a){let c=a.findIndex(m=>m.free);return c>=0?c:null}var v=60,A=100;function N({headline:a,ask:c=!1,rows:m,sel:u,focused:x,freeText:n=null,freeTextNote:d,sublines:B=[],gapAbove:p=!0,accent:s=l.assuranceAccent}){let{stdout:C}=O(),b=C?.columns??80,S=b<v,F=Math.min(b-1,A),f=e=>x&&u===e?(0,o.jsx)(t,{color:s,children:"\u276F"}):" ",T=c?`? ${a}`:a,g=Math.max(4,F-3),R=B.map((e,r)=>(0,o.jsx)(t,{color:l.dim,children:` ${e.length>g?`${e.slice(0,g-1)}\u2026`:e}`},`sub-${r}`)),k=0,w=m.map((e,r)=>e.free?n?(0,o.jsxs)(i,{flexDirection:"column",children:[(0,o.jsxs)(i,{children:[(0,o.jsxs)(t,{children:[(0,o.jsx)(t,{color:s,children:"\u276F"})," ",(0,o.jsx)(t,{color:l.dim,children:"\u270E "})]}),n.keysFromPanel?(0,o.jsx)(P,{value:n.value,placeholder:e.label}):(0,o.jsx)(h,{value:n.value,onChange:n.onChange,onSubmit:n.onSubmit,onCancel:n.onCancel,placeholder:e.label})]}),d?(0,o.jsx)(t,{color:l.muted,children:` ${d}`}):null]},e.key):(0,o.jsxs)(t,{children:[f(r)," ",(0,o.jsx)(t,{color:l.dim,children:`\u270E ${e.label}`})]},e.key):(k+=1,(0,o.jsxs)(t,{bold:x&&u===r,children:[f(r),` ${k}. ${e.label}`,e.detail?(0,o.jsx)(t,{color:l.dim,bold:!1,children:` \u2014 ${e.detail}`}):null]},e.key)));return S?(0,o.jsxs)(i,{marginTop:p?1:0,marginBottom:1,flexDirection:"column",children:[(0,o.jsx)(t,{bold:!0,color:s,children:T}),R,w]}):(0,o.jsxs)(i,{marginTop:p?1:0,marginBottom:1,flexDirection:"column",children:[(0,o.jsx)(t,{bold:!0,color:s,children:T}),R,(0,o.jsx)(t,{children:" "}),w]})}export{L as a,N as b};
2
+ import{c as h,d as P}from"./chunk-SMXABALN.js";import{a as $}from"./chunk-HCBYKLMW.js";import{z as l}from"./chunk-YKOZBFR3.js";import{a as i,b as t,k as O}from"./chunk-33DWJV67.js";import{e as y}from"./chunk-UR6MHSHU.js";var o=y($(),1);function L(a){let c=a.findIndex(m=>m.free);return c>=0?c:null}var v=60,A=100;function N({headline:a,ask:c=!1,rows:m,sel:u,focused:x,freeText:n=null,freeTextNote:d,sublines:B=[],gapAbove:p=!0,accent:s=l.assuranceAccent}){let{stdout:C}=O(),b=C?.columns??80,S=b<v,F=Math.min(b-1,A),f=e=>x&&u===e?(0,o.jsx)(t,{color:s,children:"\u276F"}):" ",T=c?`? ${a}`:a,g=Math.max(4,F-3),R=B.map((e,r)=>(0,o.jsx)(t,{color:l.dim,children:` ${e.length>g?`${e.slice(0,g-1)}\u2026`:e}`},`sub-${r}`)),k=0,w=m.map((e,r)=>e.free?n?(0,o.jsxs)(i,{flexDirection:"column",children:[(0,o.jsxs)(i,{children:[(0,o.jsxs)(t,{children:[(0,o.jsx)(t,{color:s,children:"\u276F"})," ",(0,o.jsx)(t,{color:l.dim,children:"\u270E "})]}),n.keysFromPanel?(0,o.jsx)(P,{value:n.value,placeholder:e.label}):(0,o.jsx)(h,{value:n.value,onChange:n.onChange,onSubmit:n.onSubmit,onCancel:n.onCancel,placeholder:e.label})]}),d?(0,o.jsx)(t,{color:l.muted,children:` ${d}`}):null]},e.key):(0,o.jsxs)(t,{children:[f(r)," ",(0,o.jsx)(t,{color:l.dim,children:`\u270E ${e.label}`})]},e.key):(k+=1,(0,o.jsxs)(t,{bold:x&&u===r,children:[f(r),` ${k}. ${e.label}`,e.detail?(0,o.jsx)(t,{color:l.dim,bold:!1,children:` \u2014 ${e.detail}`}):null]},e.key)));return S?(0,o.jsxs)(i,{marginTop:p?1:0,marginBottom:1,flexDirection:"column",children:[(0,o.jsx)(t,{bold:!0,color:s,children:T}),R,w]}):(0,o.jsxs)(i,{marginTop:p?1:0,marginBottom:1,flexDirection:"column",children:[(0,o.jsx)(t,{bold:!0,color:s,children:T}),R,(0,o.jsx)(t,{children:" "}),w]})}export{L as a,N as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{i as d}from"./chunk-XMPTFXPW.js";import{c as a}from"./chunk-SB26HQO7.js";import{Ha as o}from"./chunk-WE7HRAGO.js";async function p(e,l,s){let n=l.project,i=l.local===!0;if(n===void 0&&!i)return{kind:"none"};if(n!==void 0&&i)return r(o.folderFlagsBoth());if(l.resume!==void 0)return r(o.folderFlagWithResume(n!==void 0?"--project":"--local"));if(e.kind==="refuse")return r(e.refusal);if(e.kind==="local")return i?{kind:"none"}:r(o.folderWorksLocally());if(e.kind==="remote")return i?r(o.folderLinkedNotLocal(e.projectName)):n===e.projectId?{kind:"none"}:r(o.folderLinkedElsewhere(e.projectName));if(i)return{kind:"local"};let c;try{c=await s.getProject(n)}catch(t){if(t instanceof d)return r({code:t.code,message:t.message,...t.remedy?{remedy:t.remedy}:{}});if(t instanceof a)return r(o.noConnection());throw t}return c===null?r(o.projectIdUnknown(n,l.agent===!0)):{kind:"link",projectId:c.id,projectName:c.name}}var r=e=>({kind:"refuse",refusal:e}),g=e=>({...e.project!==void 0?{project:e.project}:{},...e.local===!0?{local:!0}:{}});export{p as a,g as b};
2
+ import{i as d}from"./chunk-XMPTFXPW.js";import{c as a}from"./chunk-SB26HQO7.js";import{Ha as o}from"./chunk-7WWCIS2B.js";async function p(e,l,s){let n=l.project,i=l.local===!0;if(n===void 0&&!i)return{kind:"none"};if(n!==void 0&&i)return r(o.folderFlagsBoth());if(l.resume!==void 0)return r(o.folderFlagWithResume(n!==void 0?"--project":"--local"));if(e.kind==="refuse")return r(e.refusal);if(e.kind==="local")return i?{kind:"none"}:r(o.folderWorksLocally());if(e.kind==="remote")return i?r(o.folderLinkedNotLocal(e.projectName)):n===e.projectId?{kind:"none"}:r(o.folderLinkedElsewhere(e.projectName));if(i)return{kind:"local"};let c;try{c=await s.getProject(n)}catch(t){if(t instanceof d)return r({code:t.code,message:t.message,...t.remedy?{remedy:t.remedy}:{}});if(t instanceof a)return r(o.noConnection());throw t}return c===null?r(o.projectIdUnknown(n,l.agent===!0)):{kind:"link",projectId:c.id,projectName:c.name}}var r=e=>({kind:"refuse",refusal:e}),g=e=>({...e.project!==void 0?{project:e.project}:{},...e.local===!0?{local:!0}:{}});export{p as a,g as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a}from"./chunk-HCBYKLMW.js";import{a as m,b as r,i as d}from"./chunk-33DWJV67.js";import{a as u}from"./chunk-6YGTRKDT.js";import{z as o}from"./chunk-J4FIESTB.js";import{e as s}from"./chunk-UR6MHSHU.js";var l=s(u(),1);var e=s(a(),1);function T({message:t,confirmLabel:c,choice:n}){return(0,e.jsxs)(m,{flexDirection:"column",borderStyle:"round",borderColor:o.dim,paddingX:1,children:[(0,e.jsx)(r,{bold:!0,children:t}),(0,e.jsxs)(m,{marginTop:1,children:[(0,e.jsx)(r,{color:n==="yes"?o.red:o.dim,children:`\u276F ${c}`}),(0,e.jsx)(r,{children:" "}),(0,e.jsx)(r,{color:n==="no"?o.green:o.dim,children:"\u276F No"})]}),(0,e.jsx)(r,{color:o.dim,children:"\u2190 \u2192 choose \xB7 \u21B5 confirm \xB7 esc cancel"})]})}function y({message:t,onConfirm:c,onCancel:n,confirmLabel:p="Yes, end"}){let[f,g]=(0,l.useState)("no");return d((b,i)=>{(i.leftArrow||i.rightArrow)&&g(x=>x==="yes"?"no":"yes"),i.return&&(f==="yes"?c:n)(),i.escape&&n()}),(0,e.jsx)(T,{message:t,confirmLabel:p,choice:f})}export{y as a};
2
+ import{a}from"./chunk-HCBYKLMW.js";import{z as o}from"./chunk-YKOZBFR3.js";import{a as m,b as r,i as d}from"./chunk-33DWJV67.js";import{a as u}from"./chunk-6YGTRKDT.js";import{e as s}from"./chunk-UR6MHSHU.js";var l=s(u(),1);var e=s(a(),1);function T({message:t,confirmLabel:c,choice:n}){return(0,e.jsxs)(m,{flexDirection:"column",borderStyle:"round",borderColor:o.dim,paddingX:1,children:[(0,e.jsx)(r,{bold:!0,children:t}),(0,e.jsxs)(m,{marginTop:1,children:[(0,e.jsx)(r,{color:n==="yes"?o.red:o.dim,children:`\u276F ${c}`}),(0,e.jsx)(r,{children:" "}),(0,e.jsx)(r,{color:n==="no"?o.green:o.dim,children:"\u276F No"})]}),(0,e.jsx)(r,{color:o.dim,children:"\u2190 \u2192 choose \xB7 \u21B5 confirm \xB7 esc cancel"})]})}function y({message:t,onConfirm:c,onCancel:n,confirmLabel:p="Yes, end"}){let[f,g]=(0,l.useState)("no");return d((b,i)=>{(i.leftArrow||i.rightArrow)&&g(x=>x==="yes"?"no":"yes"),i.return&&(f==="yes"?c:n)(),i.escape&&n()}),(0,e.jsx)(T,{message:t,confirmLabel:p,choice:f})}export{y as a};
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{c as Oe}from"./chunk-BWXLZS5O.js";import{a as De,b as Me}from"./chunk-63EKRZKI.js";import{a as qe,c as Ne}from"./chunk-3JLEDSG5.js";import{b as $e,f as de,i as Ee}from"./chunk-ZHAMVLQZ.js";import{A as Ae,D as ae,na as Ie,z as Te}from"./chunk-PI7OXS62.js";import{d as Re}from"./chunk-KU3YHPWZ.js";import{o as $}from"./chunk-HYJVYYAZ.js";var Qe=new Set(["approve","edit","reject"]),Le=new Set(["approve","edit","reject","add","enhance","retract"]);function Fe(i,t){return t?`chatop:${t}:${i}`:`chatop:${i}`}function Ue(i,t,y,w){let k=`${t}:${i.target??"new"}:${i.op}:${i.seq}`,l=i.payload;switch(i.op){case"approve":return{kind:"approve",target:i.target,expectedCid:i.expected_cid,eventId:k};case"edit":{let{reason:C,...a}=l;return{kind:"edit",target:i.target,expectedCid:i.expected_cid,edit:a,reason:C,eventId:k}}case"enhance":return{kind:"enhance",target:i.target,expectedCid:i.expected_cid,edges:l.edges??[],eventId:k};case"retract":{let C=typeof l.reason=="string"?l.reason.trim():"";if(!C)throw new Error("INVALID_RETRACT: a retract needs a non-empty reason");let a=l.edge_ecid!==void 0&&l.edge_ecid!==null,d=l.edge!==void 0&&l.edge!==null;if(a&&d)throw new Error("INVALID_RETRACT: both edge_ecid and edge were sent \u2014 give exactly one");if(!a&&!d)throw new Error("INVALID_RETRACT: neither edge {type, dst, src?} (display refs) nor edge_ecid was sent \u2014 give exactly one");let g={kind:"retract",target:i.target,expectedCid:i.expected_cid,reason:C};if(a){if(typeof l.edge_ecid!="string"||!l.edge_ecid)throw new Error("INVALID_RETRACT: edge_ecid must be a non-empty string");return{...g,edgeEcid:l.edge_ecid,eventId:`${t}:${i.target}:retract:e:${l.edge_ecid}:${i.seq}`}}let f=l.edge;if(typeof f!="object"||typeof f.type!="string"||!f.type||typeof f.dst!="string"||!f.dst)throw new Error("INVALID_RETRACT: edge needs {type, dst} (src optional), all display refs");if(f.src!==void 0&&f.src!==null&&(typeof f.src!="string"||!f.src))throw new Error("INVALID_RETRACT: edge.src, when given, must be a non-empty display ref");let v=typeof f.src=="string"?f.src:void 0;return{...g,edgeRef:{type:f.type,dst:f.dst,...v!==void 0?{src:v}:{}},eventId:`${t}:${i.target}:retract:t:${f.type}:${f.dst}:${v??"-"}:${i.seq}`}}case"reject":return{kind:"reject",target:i.target,expectedCid:i.expected_cid,reason:l.reason??"",redirectTo:l.redirect_to,eventId:k};case"add":{let C=l.proposal_item??{},a=String(C.label??"");if(!y.mint_gate.includes(a))throw new Error(`GATED_LABEL: cannot mint "${a}" (gate: ${y.mint_gate.join(", ")})`);let d=C.cite??{},g=C.conv_source_id??w;if(!g||typeof d.turn!="number"||!d.quote)throw new Error("INVALID_ADD: a chat add requires a conversation cite {turn, quote} and conv_source_id");let f=C.content,v=f&&typeof f=="object"&&!Array.isArray(f)&&Object.keys(f).length>0?f:null,A=new Set(["label","cite","conv_source_id","content","rationale","edges"]),S=v??Object.fromEntries(Object.entries(C).filter(([N])=>!A.has(N)));return{kind:"add",label:a,content:S,cite:{turn:d.turn,quote:d.quote},convSourceId:g,rationale:C.rationale,eventId:k}}}}function je(i,t,y={}){let w=y.turn??0,k=[],l=[];for(let[d,g]of i.entries()){let f=Te(g,`ops[${d}]`);if(f!==null)throw new Error(`NUL_IN_TEXT: ${Ae(f)}`)}for(let d of i){if(!Le.has(d.op))throw new Error(`UNKNOWN_OP: "${d.op}" is not a chat op (accepted: ${[...Le].join(", ")})`);if(d.op!=="add"&&!d.target)throw new Error(`MISSING_TARGET: a ${d.op} op needs a target ref`)}for(let d of i)(d.op==="add"||d.op==="enhance"||d.op==="retract")&&l.push(d);let C=new Map;for(let d of i){if(!Qe.has(d.op)||!d.target)continue;let g=C.get(d.target)??[];g.push(d),C.set(d.target,g)}for(let[d,g]of C){let f=Math.max(...g.map(A=>A.seq)),v=g.filter(A=>A.seq===f);if(v.length>1){k.push({target:d,seq:f,kinds:v.map(A=>A.op)});continue}l.push(v[0])}return{chatOps:l.sort((d,g)=>d.seq-g.seq).map(d=>Ue(d,y.prefix??Fe(w,y.session),t,y.convSourceId)),ambiguous:k}}function Pe(i,t){return i.map(y=>{let w=y.data?.tip;if(y.code!=="EXPECTED_CID_MOVED"||typeof w!="string")return{code:y.code};let k=t?.getNode(w)?.content??{},l=typeof k.title=="string"?k.title:typeof k.text=="string"?k.text:void 0,C=t?.displayNameOf(w)??(typeof y.data?.target=="string"?y.data.target:void 0);return{code:y.code,moved:y.data?.moved===!0,...C?{ref:C}:{},...l?{title:l}:{}}})}function He(i){let t=[];return i.questions.forEach((y,w)=>{if(i.resolution[w])return;let k=y.recommended_index!=null?y.options[y.recommended_index]?.label:void 0;k!=null&&t.push(y.risk==="high"?`${B(k)} \u203C`:B(k))}),t.length>3?`${t.slice(0,3).join(" \xB7 ")} \xB7 +${t.length-3} more`:t.join(" \xB7 ")}function B(i){return i.replace(/\s*\(recommended\)\s*$/i,"")}function Be(i){let t=i.text.replace(/\?+\s*$/,"");return t.length<=36?t:`${t.slice(0,33)}\u2026`}function ze(i,t){let y=new Set;for(let w=t;w&&!y.has(w);w=i.superseded.get(w)){if(i.trust.get(w)==="archived")return!0;y.add(w)}return!1}function Ve(i){return i.use_cases??[]}var Ke={acs:"acceptance criteria",scenarios:"scenarios",exercises:"exercises",tests:"tests",gaps:"gaps"};function Xe(i){let t=[],y=[],w=(a,d)=>{d.length!==0&&(y.push(a),t.push(...d))},k=a=>typeof a=="string"&&/^[a-z]{1,4}\d{1,4}$/i.test(a)?a:null,l=a=>{let d=k(a.automates)??"1 scenario",g=a.verifies??[],f=g.map(k).filter(S=>S!==null).slice(0,2),v=g.length-f.length,A=f.length?`${f.join(" ")}${v>0?` +${v}`:""}`:`${g.length} ACs`;return`covers ${d} \xB7 verifies ${A}`};w("acs",(i.acs??[]).map(a=>({temp_ref:a.temp_ref,title:a.text,kind:"ac",badge:String(a.kind),extra:{...a.expected_answer?{expects:`${String(a.expected_answer.operator??"")} \xB7 ${String(a.expected_answer.operand??"")}`}:{},"scoped to":a.scoped_to??"(use-case)"}}))),w("scenarios",(i.scenarios??[]).map(a=>({temp_ref:a.temp_ref,title:a.title,kind:"scenario",badge:a.case_type,why:a.intent,depends_on_hint:a.depends_on??[],extra:{technique:a.technique_notes}}))),w("exercises",(i.exercises??[]).map(a=>({temp_ref:k(a.scenario)??"wiring",title:`${k(a.scenario)??"scenario"} exercises ${k(a.ac)??"1 AC"}`,kind:"exercise",badge:"wires",why:a.rationale}))),w("tests",(i.tests??[]).map(a=>({temp_ref:a.temp_ref,title:a.title,kind:"test",why:l(a),depends_on_hint:a.reuses??[],extra:{automates:String(a.automates??"?"),verifies:(a.verifies??[]).join(", "),check:a.check?`${String(a.check.kind)} vs ${String(a.check.verified_against)}`:"?"}})));let C={high:"high",medium:"med",med:"med",low:"low"};return w("gaps",(i.gaps??[]).map(a=>{let d=a.question??{};return{temp_ref:a.temp_ref??a.ref??"?",title:String(d.header??a.kind),kind:"gap",badge:C[String(a.risk??"").trim().toLowerCase()]??"",why:d.prompt??d.text??"",question:String(d.prompt??d.text??d.header??""),rationale:String(a.risk_rationale??"")}})),{items:t,heading:y.join(" + ")||"design"}}function ut(i={}){let t={turns:[],thinking:De(),pending:null,confirm:null,status:"idle",ledger:[],activeTurn:null,stream:null,checkpoint:!1},y=e=>{let n=[],r=e.minted.map(u=>u.slug).filter(Boolean);r.length&&n.push(`added ${r.join(", ")}`);let s=e.applied.length-e.minted.length;s>0&&n.push(`${s} change${s===1?"":"s"} applied`);let o=e.staleDelta.length?$().text("chat.stales",{count:e.staleDelta.length}):"";return o&&n.push(o),n.join(" \xB7 ")||"no changes"},w=(e,n)=>{let r=i.refreshGraph?.()??i.graph;return!r?.nodeLabel||n.applied.length===0||n.minted.length>0||n.staleDelta.length>0?!1:e.every(s=>{if(s.kind!=="approve"||!s.target)return!1;let o=r.resolve(s.target);return o!==null&&r.nodeLabel.get(r.tipOf(o.cid))==="usecase"})},k=[];i.onRender&&k.push(i.onRender);let l=0,C=new Map,a=e=>{let n=C.get(e);if(n===void 0){let r=`chatop:${e}:`;n=0;for(let s of(i.refreshGraph?.()??i.graph)?.appliedEvents??[]){if(!s.startsWith(r))continue;let o=Number(s.slice(r.length).split(":")[0]);Number.isInteger(o)&&o>n&&(n=o)}C.set(e,n)}return n},d=0,g=null,f=null,v=null,A=null,S=[],N=null,ee=!1,G=0,te=null,M=null,ne=0,ue=0,le=!1,ce=!1,ge=e=>(le||(le=!0,m({kind:"note",text:$().text("note.turns_unrecorded",{detail:e})}),p()),null),pe=(e,n)=>{if(!v||!i.store||!e.trim())return null;try{let r=i.refreshGraph?.()??i.graph;if(!r)return null;let s=Ee({store:i.store,graph:r,sourceId:v,text:e,speaker:n,by:i.by??{kind:"human",id:"owner"}});return s.errors?ge(s.errors.map(o=>o.detail).join("; ")):s.record!==null?$e(v,s.turn):null}catch(r){return ge(r instanceof Error?r.message:String(r))}},Ge=e=>{if(!v||!i.store)return;let n=i.refreshGraph?.()??i.graph,r=n?.heads.get(v),s=n?.convChains.get(v);if(!n||typeof r!="string"||!s)return;let o=n.getNode(r)?.content?.blob,u=typeof o=="string"?i.store.getBlob(o)?.toString("utf8")??"":"";if(u)for(let h of e){if(h.kind!=="add"||h.convSourceId!==v)continue;let _=de(u,h.cite.turn);if(!(_!==null&&ae(h.cite.quote,_)))for(let R=s.turns;R>=1;R--){let b=de(u,R);if(b!==null&&ae(h.cite.quote,b)){h.cite={...h.cite,turn:R};break}}}},T={startedAt:null,thinkMs:0,toolCalls:0,tools:new Map},W=()=>{T.startedAt??=Date.now()},D=()=>{if(T.toolCalls>0){let e=T.startedAt!=null?Math.max(1,Math.round((Date.now()-T.startedAt)/1e3)):Math.max(1,Math.round(T.thinkMs/1e3));m({kind:"worked",durS:e,toolCalls:T.toolCalls,tools:[...T.tools.entries()].map(([n,r])=>({name:n,n:r}))})}T.startedAt=null,T.thinkMs=0,T.toolCalls=0,T.tools.clear()},Q=null,re=new Map,fe=e=>JSON.stringify([e.id,e.text,e.options.map(n=>n.label)]),F=null,me=new Map,ie=new Map,U=new Map,he=null,p=()=>{H&&(clearTimeout(H),H=null),ke();for(let e of k)e()},ke=()=>{G>0&&g!=null&&g!==te?t.nestedAgent=!0:delete t.nestedAgent},H=null,be=()=>{H||(H=setTimeout(()=>{H=null,ke();for(let e of k)e()},80))},Y=0,m=e=>{e.kind==="childClose"&&Y>0&&(Y-=1),Y>0&&e.kind!=="childOpen"&&e.kind!=="childBack"&&(e.era=Y),e.kind==="childOpen"&&(Y+=1),t.ledger.push(e)},z=null,Z=!1,se=0,V=(e=!1)=>{if(z)m({kind:"agent",text:z});else if(e&&Z){let r=([...t.turns].reverse().find(s=>s.role==="agent")?.items??[]).filter(s=>!s.matches_existing).length;m({kind:"note",text:$().text("chat.refine_hint",{added:r,held:se})})}z=null,Z=!1,se=0,delete t.committing},We=()=>{z=null,Z=!1,delete t.committing},E=null,oe=(e,n=!1,r)=>{if(!E)return;if(e)for(let o of E.items){let u=e.get(o.temp_ref);u&&(o.logical_id=u)}if(r)for(let o of E.items)r.has(o.temp_ref)&&(o.sessionAdded=!0);let s=E.items.filter(o=>o.kind==="test");if(s.length>0){let o;try{o=i.refreshGraph?.()??i.graph}catch{o=i.graph}let u=h=>{if(Ie.test(h))return h;let _=e?.get(h);if(_)return _;let R=h.startsWith("sha256:")?h:U.get(h);return(R?o?.displayNameOf(R):null)??null};for(let h of s){let _=h.extra??{},R=_.verifies?_.verifies.split(", "):[];h.links={covers:_.automates&&_.automates!=="?"?u(_.automates):null,verifies:R.map(u).filter(b=>b!==null),verifiesTotal:R.length}}}if(n)for(let o of E.items)o.logical_id||(o.held=!0);m({kind:"turn",...E}),E=null},ye=()=>{let e=i.refreshGraph?.()??i.graph;if(!i.commitChatTurn||!e?.trust)return!0;let n=[];for(let{item:b}of Oe(t.turns).entries){if(!b.logical_id||b.turnedDown||b.matches_existing||(b.kind??"use-case")!=="use-case")continue;let I=e.names?.get(b.logical_id)??U.get(b.temp_ref);if(!I)continue;let c=e.tipOf(I);e.trust.get(c)==="derived"&&!n.includes(c)&&n.push(c)}let r=new Set(i.addedBefore?.()??[]);for(let b of r){let I=e.tipOf(b);r.has(I)&&e.trust.get(I)==="derived"&&!n.includes(I)&&n.push(I)}if(n.length===0)return!0;l+=1;let s=v||i.session?.state?.sid,o=l+(s?a(s):0),u=s?`chatop:${s}:${o}`:`chatop:${o}`,h=n.map((b,I)=>({kind:"approve",target:b,expectedCid:b,eventId:`${u}:${b}:approve:${I}`})),_;try{_=i.commitChatTurn({graph:e,ops:h,by:i.by??{kind:"human",id:"owner"},...i.descriptor?.mint_gate?{mintable:i.descriptor.mint_gate}:{},...i.session?.state?.sid?{sid:i.session.state.sid}:{}})}catch(b){_={record:null,errors:[{code:"COMMIT_THREW",detail:b instanceof Error?b.message:String(b)}]}}if(_.errors)return t.error=_.errors.map(b=>b.detail).join("; "),m({kind:"commit",ok:!1,line:$().text("chat.commit_failed",{}),warnings:_.errors.map(b=>`${b.code}: ${b.detail}`),refused:Pe(_.errors,e),person:!0}),p(),!1;_.applied.length>0&&i.session?.markApplied(_.applied),m({kind:"commit",ok:!0,line:$().text("chat.approved",{count:_.applied.length})});let R=i.refreshGraph?.();return R&&f&&f(R),xe(R??i.graph),!0},xe=e=>{if(!(!e?.trust||!e.superseded))for(let n of t.turns)for(let r of n.items??[]){let s=r.logical_id&&e.names?.get(r.logical_id)||U.get(r.temp_ref);s&&(ze(e,s)?r.turnedDown=!0:delete r.turnedDown)}},q=()=>{oe(),delete t.committing,t.activeTurn&&(t.activeTurn=null)},ve=(e,n)=>{let r=n.selected_index!=null?e.options[n.selected_index]?.label:void 0;return n.choice||(r!=null?B(r):"?")},K=()=>{let e=t.pending;if(!e)return;if(!e.resolution.every(Boolean)){e.cursor=e.resolution.findIndex(s=>s===null);return}let n=e.questions.map((s,o)=>{let u=e.resolution[o];return u.form==="deferred"?{id:s.id,selected_index:null,free_text:null}:{id:s.id,selected_index:u.selected_index,free_text:u.free_text}});t.pending=null,t.status=t.status==="pausing"?"pausing":"streaming",t.status==="streaming"&&(t.busySince=Date.now());let r=Q;Q=null,r?.(n)},L=(e,n)=>{let r=t.pending,s=r.questions[e],o=r.resolution[e];r.resolution[e]=n;let u=Be(s);o?m({kind:"answer",receipt:{form:"changed",qNum:e+1,stub:u,choice:ve(s,n),prev:o.choice}}):n.form==="deferred"?m({kind:"answer",receipt:{form:"deferred",qNum:e+1,stub:u}}):m({kind:"answer",receipt:{form:n.form,qNum:e+1,stub:u,choice:ve(s,n)}})},we=()=>{let e=t.pending;e&&(e.questions.forEach((n,r)=>{e.resolution[r]||L(r,{form:"deferred",selected_index:null,free_text:null,choice:""})}),K())},X=new Map,_e=e=>{X.clear();let n={high:0,med:1,low:2};return e=e.map((r,s)=>({q:r,i:s})).sort((r,s)=>(n[r.q.risk]??3)-(n[s.q.risk]??3)||r.i-s.i).map(({q:r})=>r),{questions:e,cursor:0,resolution:e.map(()=>null)}},Ce=(e,n)=>{if(t.confirm&&(t.confirm=null),t.pending)return;let r=n==="kane"?{kind:"note",text:$().text("chat.repair_sent",{})}:{kind:"user",text:e};if(!g){t.turns.push({role:"user",text:e}),m(r),t.notice="the agent isn't running \u2014 nothing sent",p();return}t.notice=void 0,ee=!1,t.checkpoint=!1,delete t.resumedParked,V(),t.turns.push({role:"user",text:e}),m(r);let s=pe(e,n);for(t.status="streaming",t.busySince=Date.now(),W(),t.error=void 0,d+=1;S.length>0;)d+=1,g({type:"user_message",message_id:`u${d}-receipt`,text:S.shift()},{by:"kane",receipt:!0});g({type:"user_message",message_id:s??`u${d}`,text:e},{by:n}),p()};return{state:t,explainLines(e){if(!i.explain||!i.graph||!i.store)return null;let n=i.explain(i.store,i.graph,e);return n.target?[`${n.target.label} ${n.target.slug??n.target.cid.slice(0,19)}:`,...n.entries.map(r=>` [${r.kind}] ${r.rationale??r.detail}`)]:null},explainRef(e){if(!i.explain||!i.graph||!i.store){m({kind:"note",text:"explain isn't available here"}),p();return}let n=i.explain(i.store,i.graph,e),r=n.target?[`${n.target.label} ${n.target.slug??n.target.cid.slice(0,19)}:`,...n.entries.map(s=>` [${s.kind}] ${s.rationale??s.detail}`)].join(`
2
+ import{c as Oe}from"./chunk-BWXLZS5O.js";import{a as De,b as Me}from"./chunk-63EKRZKI.js";import{a as qe,c as Ne}from"./chunk-3JLEDSG5.js";import{b as $e,f as de,i as Ee}from"./chunk-3A4KK22B.js";import{A as Ae,D as ae,na as Ie,z as Te}from"./chunk-5EAJO372.js";import{d as Re}from"./chunk-KU3YHPWZ.js";import{o as $}from"./chunk-HYJVYYAZ.js";var Qe=new Set(["approve","edit","reject"]),Le=new Set(["approve","edit","reject","add","enhance","retract"]);function Fe(i,t){return t?`chatop:${t}:${i}`:`chatop:${i}`}function Ue(i,t,y,w){let k=`${t}:${i.target??"new"}:${i.op}:${i.seq}`,l=i.payload;switch(i.op){case"approve":return{kind:"approve",target:i.target,expectedCid:i.expected_cid,eventId:k};case"edit":{let{reason:C,...a}=l;return{kind:"edit",target:i.target,expectedCid:i.expected_cid,edit:a,reason:C,eventId:k}}case"enhance":return{kind:"enhance",target:i.target,expectedCid:i.expected_cid,edges:l.edges??[],eventId:k};case"retract":{let C=typeof l.reason=="string"?l.reason.trim():"";if(!C)throw new Error("INVALID_RETRACT: a retract needs a non-empty reason");let a=l.edge_ecid!==void 0&&l.edge_ecid!==null,d=l.edge!==void 0&&l.edge!==null;if(a&&d)throw new Error("INVALID_RETRACT: both edge_ecid and edge were sent \u2014 give exactly one");if(!a&&!d)throw new Error("INVALID_RETRACT: neither edge {type, dst, src?} (display refs) nor edge_ecid was sent \u2014 give exactly one");let g={kind:"retract",target:i.target,expectedCid:i.expected_cid,reason:C};if(a){if(typeof l.edge_ecid!="string"||!l.edge_ecid)throw new Error("INVALID_RETRACT: edge_ecid must be a non-empty string");return{...g,edgeEcid:l.edge_ecid,eventId:`${t}:${i.target}:retract:e:${l.edge_ecid}:${i.seq}`}}let f=l.edge;if(typeof f!="object"||typeof f.type!="string"||!f.type||typeof f.dst!="string"||!f.dst)throw new Error("INVALID_RETRACT: edge needs {type, dst} (src optional), all display refs");if(f.src!==void 0&&f.src!==null&&(typeof f.src!="string"||!f.src))throw new Error("INVALID_RETRACT: edge.src, when given, must be a non-empty display ref");let v=typeof f.src=="string"?f.src:void 0;return{...g,edgeRef:{type:f.type,dst:f.dst,...v!==void 0?{src:v}:{}},eventId:`${t}:${i.target}:retract:t:${f.type}:${f.dst}:${v??"-"}:${i.seq}`}}case"reject":return{kind:"reject",target:i.target,expectedCid:i.expected_cid,reason:l.reason??"",redirectTo:l.redirect_to,eventId:k};case"add":{let C=l.proposal_item??{},a=String(C.label??"");if(!y.mint_gate.includes(a))throw new Error(`GATED_LABEL: cannot mint "${a}" (gate: ${y.mint_gate.join(", ")})`);let d=C.cite??{},g=C.conv_source_id??w;if(!g||typeof d.turn!="number"||!d.quote)throw new Error("INVALID_ADD: a chat add requires a conversation cite {turn, quote} and conv_source_id");let f=C.content,v=f&&typeof f=="object"&&!Array.isArray(f)&&Object.keys(f).length>0?f:null,A=new Set(["label","cite","conv_source_id","content","rationale","edges"]),S=v??Object.fromEntries(Object.entries(C).filter(([N])=>!A.has(N)));return{kind:"add",label:a,content:S,cite:{turn:d.turn,quote:d.quote},convSourceId:g,rationale:C.rationale,eventId:k}}}}function je(i,t,y={}){let w=y.turn??0,k=[],l=[];for(let[d,g]of i.entries()){let f=Te(g,`ops[${d}]`);if(f!==null)throw new Error(`NUL_IN_TEXT: ${Ae(f)}`)}for(let d of i){if(!Le.has(d.op))throw new Error(`UNKNOWN_OP: "${d.op}" is not a chat op (accepted: ${[...Le].join(", ")})`);if(d.op!=="add"&&!d.target)throw new Error(`MISSING_TARGET: a ${d.op} op needs a target ref`)}for(let d of i)(d.op==="add"||d.op==="enhance"||d.op==="retract")&&l.push(d);let C=new Map;for(let d of i){if(!Qe.has(d.op)||!d.target)continue;let g=C.get(d.target)??[];g.push(d),C.set(d.target,g)}for(let[d,g]of C){let f=Math.max(...g.map(A=>A.seq)),v=g.filter(A=>A.seq===f);if(v.length>1){k.push({target:d,seq:f,kinds:v.map(A=>A.op)});continue}l.push(v[0])}return{chatOps:l.sort((d,g)=>d.seq-g.seq).map(d=>Ue(d,y.prefix??Fe(w,y.session),t,y.convSourceId)),ambiguous:k}}function Pe(i,t){return i.map(y=>{let w=y.data?.tip;if(y.code!=="EXPECTED_CID_MOVED"||typeof w!="string")return{code:y.code};let k=t?.getNode(w)?.content??{},l=typeof k.title=="string"?k.title:typeof k.text=="string"?k.text:void 0,C=t?.displayNameOf(w)??(typeof y.data?.target=="string"?y.data.target:void 0);return{code:y.code,moved:y.data?.moved===!0,...C?{ref:C}:{},...l?{title:l}:{}}})}function He(i){let t=[];return i.questions.forEach((y,w)=>{if(i.resolution[w])return;let k=y.recommended_index!=null?y.options[y.recommended_index]?.label:void 0;k!=null&&t.push(y.risk==="high"?`${B(k)} \u203C`:B(k))}),t.length>3?`${t.slice(0,3).join(" \xB7 ")} \xB7 +${t.length-3} more`:t.join(" \xB7 ")}function B(i){return i.replace(/\s*\(recommended\)\s*$/i,"")}function Be(i){let t=i.text.replace(/\?+\s*$/,"");return t.length<=36?t:`${t.slice(0,33)}\u2026`}function ze(i,t){let y=new Set;for(let w=t;w&&!y.has(w);w=i.superseded.get(w)){if(i.trust.get(w)==="archived")return!0;y.add(w)}return!1}function Ve(i){return i.use_cases??[]}var Ke={acs:"acceptance criteria",scenarios:"scenarios",exercises:"exercises",tests:"tests",gaps:"gaps"};function Xe(i){let t=[],y=[],w=(a,d)=>{d.length!==0&&(y.push(a),t.push(...d))},k=a=>typeof a=="string"&&/^[a-z]{1,4}\d{1,4}$/i.test(a)?a:null,l=a=>{let d=k(a.automates)??"1 scenario",g=a.verifies??[],f=g.map(k).filter(S=>S!==null).slice(0,2),v=g.length-f.length,A=f.length?`${f.join(" ")}${v>0?` +${v}`:""}`:`${g.length} ACs`;return`covers ${d} \xB7 verifies ${A}`};w("acs",(i.acs??[]).map(a=>({temp_ref:a.temp_ref,title:a.text,kind:"ac",badge:String(a.kind),extra:{...a.expected_answer?{expects:`${String(a.expected_answer.operator??"")} \xB7 ${String(a.expected_answer.operand??"")}`}:{},"scoped to":a.scoped_to??"(use-case)"}}))),w("scenarios",(i.scenarios??[]).map(a=>({temp_ref:a.temp_ref,title:a.title,kind:"scenario",badge:a.case_type,why:a.intent,depends_on_hint:a.depends_on??[],extra:{technique:a.technique_notes}}))),w("exercises",(i.exercises??[]).map(a=>({temp_ref:k(a.scenario)??"wiring",title:`${k(a.scenario)??"scenario"} exercises ${k(a.ac)??"1 AC"}`,kind:"exercise",badge:"wires",why:a.rationale}))),w("tests",(i.tests??[]).map(a=>({temp_ref:a.temp_ref,title:a.title,kind:"test",why:l(a),depends_on_hint:a.reuses??[],extra:{automates:String(a.automates??"?"),verifies:(a.verifies??[]).join(", "),check:a.check?`${String(a.check.kind)} vs ${String(a.check.verified_against)}`:"?"}})));let C={high:"high",medium:"med",med:"med",low:"low"};return w("gaps",(i.gaps??[]).map(a=>{let d=a.question??{};return{temp_ref:a.temp_ref??a.ref??"?",title:String(d.header??a.kind),kind:"gap",badge:C[String(a.risk??"").trim().toLowerCase()]??"",why:d.prompt??d.text??"",question:String(d.prompt??d.text??d.header??""),rationale:String(a.risk_rationale??"")}})),{items:t,heading:y.join(" + ")||"design"}}function ut(i={}){let t={turns:[],thinking:De(),pending:null,confirm:null,status:"idle",ledger:[],activeTurn:null,stream:null,checkpoint:!1},y=e=>{let n=[],r=e.minted.map(u=>u.slug).filter(Boolean);r.length&&n.push(`added ${r.join(", ")}`);let s=e.applied.length-e.minted.length;s>0&&n.push(`${s} change${s===1?"":"s"} applied`);let o=e.staleDelta.length?$().text("chat.stales",{count:e.staleDelta.length}):"";return o&&n.push(o),n.join(" \xB7 ")||"no changes"},w=(e,n)=>{let r=i.refreshGraph?.()??i.graph;return!r?.nodeLabel||n.applied.length===0||n.minted.length>0||n.staleDelta.length>0?!1:e.every(s=>{if(s.kind!=="approve"||!s.target)return!1;let o=r.resolve(s.target);return o!==null&&r.nodeLabel.get(r.tipOf(o.cid))==="usecase"})},k=[];i.onRender&&k.push(i.onRender);let l=0,C=new Map,a=e=>{let n=C.get(e);if(n===void 0){let r=`chatop:${e}:`;n=0;for(let s of(i.refreshGraph?.()??i.graph)?.appliedEvents??[]){if(!s.startsWith(r))continue;let o=Number(s.slice(r.length).split(":")[0]);Number.isInteger(o)&&o>n&&(n=o)}C.set(e,n)}return n},d=0,g=null,f=null,v=null,A=null,S=[],N=null,ee=!1,G=0,te=null,M=null,ne=0,ue=0,le=!1,ce=!1,ge=e=>(le||(le=!0,m({kind:"note",text:$().text("note.turns_unrecorded",{detail:e})}),p()),null),pe=(e,n)=>{if(!v||!i.store||!e.trim())return null;try{let r=i.refreshGraph?.()??i.graph;if(!r)return null;let s=Ee({store:i.store,graph:r,sourceId:v,text:e,speaker:n,by:i.by??{kind:"human",id:"owner"}});return s.errors?ge(s.errors.map(o=>o.detail).join("; ")):s.record!==null?$e(v,s.turn):null}catch(r){return ge(r instanceof Error?r.message:String(r))}},Ge=e=>{if(!v||!i.store)return;let n=i.refreshGraph?.()??i.graph,r=n?.heads.get(v),s=n?.convChains.get(v);if(!n||typeof r!="string"||!s)return;let o=n.getNode(r)?.content?.blob,u=typeof o=="string"?i.store.getBlob(o)?.toString("utf8")??"":"";if(u)for(let h of e){if(h.kind!=="add"||h.convSourceId!==v)continue;let _=de(u,h.cite.turn);if(!(_!==null&&ae(h.cite.quote,_)))for(let R=s.turns;R>=1;R--){let b=de(u,R);if(b!==null&&ae(h.cite.quote,b)){h.cite={...h.cite,turn:R};break}}}},T={startedAt:null,thinkMs:0,toolCalls:0,tools:new Map},W=()=>{T.startedAt??=Date.now()},D=()=>{if(T.toolCalls>0){let e=T.startedAt!=null?Math.max(1,Math.round((Date.now()-T.startedAt)/1e3)):Math.max(1,Math.round(T.thinkMs/1e3));m({kind:"worked",durS:e,toolCalls:T.toolCalls,tools:[...T.tools.entries()].map(([n,r])=>({name:n,n:r}))})}T.startedAt=null,T.thinkMs=0,T.toolCalls=0,T.tools.clear()},Q=null,re=new Map,fe=e=>JSON.stringify([e.id,e.text,e.options.map(n=>n.label)]),F=null,me=new Map,ie=new Map,U=new Map,he=null,p=()=>{H&&(clearTimeout(H),H=null),ke();for(let e of k)e()},ke=()=>{G>0&&g!=null&&g!==te?t.nestedAgent=!0:delete t.nestedAgent},H=null,be=()=>{H||(H=setTimeout(()=>{H=null,ke();for(let e of k)e()},80))},Y=0,m=e=>{e.kind==="childClose"&&Y>0&&(Y-=1),Y>0&&e.kind!=="childOpen"&&e.kind!=="childBack"&&(e.era=Y),e.kind==="childOpen"&&(Y+=1),t.ledger.push(e)},z=null,Z=!1,se=0,V=(e=!1)=>{if(z)m({kind:"agent",text:z});else if(e&&Z){let r=([...t.turns].reverse().find(s=>s.role==="agent")?.items??[]).filter(s=>!s.matches_existing).length;m({kind:"note",text:$().text("chat.refine_hint",{added:r,held:se})})}z=null,Z=!1,se=0,delete t.committing},We=()=>{z=null,Z=!1,delete t.committing},E=null,oe=(e,n=!1,r)=>{if(!E)return;if(e)for(let o of E.items){let u=e.get(o.temp_ref);u&&(o.logical_id=u)}if(r)for(let o of E.items)r.has(o.temp_ref)&&(o.sessionAdded=!0);let s=E.items.filter(o=>o.kind==="test");if(s.length>0){let o;try{o=i.refreshGraph?.()??i.graph}catch{o=i.graph}let u=h=>{if(Ie.test(h))return h;let _=e?.get(h);if(_)return _;let R=h.startsWith("sha256:")?h:U.get(h);return(R?o?.displayNameOf(R):null)??null};for(let h of s){let _=h.extra??{},R=_.verifies?_.verifies.split(", "):[];h.links={covers:_.automates&&_.automates!=="?"?u(_.automates):null,verifies:R.map(u).filter(b=>b!==null),verifiesTotal:R.length}}}if(n)for(let o of E.items)o.logical_id||(o.held=!0);m({kind:"turn",...E}),E=null},ye=()=>{let e=i.refreshGraph?.()??i.graph;if(!i.commitChatTurn||!e?.trust)return!0;let n=[];for(let{item:b}of Oe(t.turns).entries){if(!b.logical_id||b.turnedDown||b.matches_existing||(b.kind??"use-case")!=="use-case")continue;let I=e.names?.get(b.logical_id)??U.get(b.temp_ref);if(!I)continue;let c=e.tipOf(I);e.trust.get(c)==="derived"&&!n.includes(c)&&n.push(c)}let r=new Set(i.addedBefore?.()??[]);for(let b of r){let I=e.tipOf(b);r.has(I)&&e.trust.get(I)==="derived"&&!n.includes(I)&&n.push(I)}if(n.length===0)return!0;l+=1;let s=v||i.session?.state?.sid,o=l+(s?a(s):0),u=s?`chatop:${s}:${o}`:`chatop:${o}`,h=n.map((b,I)=>({kind:"approve",target:b,expectedCid:b,eventId:`${u}:${b}:approve:${I}`})),_;try{_=i.commitChatTurn({graph:e,ops:h,by:i.by??{kind:"human",id:"owner"},...i.descriptor?.mint_gate?{mintable:i.descriptor.mint_gate}:{},...i.session?.state?.sid?{sid:i.session.state.sid}:{}})}catch(b){_={record:null,errors:[{code:"COMMIT_THREW",detail:b instanceof Error?b.message:String(b)}]}}if(_.errors)return t.error=_.errors.map(b=>b.detail).join("; "),m({kind:"commit",ok:!1,line:$().text("chat.commit_failed",{}),warnings:_.errors.map(b=>`${b.code}: ${b.detail}`),refused:Pe(_.errors,e),person:!0}),p(),!1;_.applied.length>0&&i.session?.markApplied(_.applied),m({kind:"commit",ok:!0,line:$().text("chat.approved",{count:_.applied.length})});let R=i.refreshGraph?.();return R&&f&&f(R),xe(R??i.graph),!0},xe=e=>{if(!(!e?.trust||!e.superseded))for(let n of t.turns)for(let r of n.items??[]){let s=r.logical_id&&e.names?.get(r.logical_id)||U.get(r.temp_ref);s&&(ze(e,s)?r.turnedDown=!0:delete r.turnedDown)}},q=()=>{oe(),delete t.committing,t.activeTurn&&(t.activeTurn=null)},ve=(e,n)=>{let r=n.selected_index!=null?e.options[n.selected_index]?.label:void 0;return n.choice||(r!=null?B(r):"?")},K=()=>{let e=t.pending;if(!e)return;if(!e.resolution.every(Boolean)){e.cursor=e.resolution.findIndex(s=>s===null);return}let n=e.questions.map((s,o)=>{let u=e.resolution[o];return u.form==="deferred"?{id:s.id,selected_index:null,free_text:null}:{id:s.id,selected_index:u.selected_index,free_text:u.free_text}});t.pending=null,t.status=t.status==="pausing"?"pausing":"streaming",t.status==="streaming"&&(t.busySince=Date.now());let r=Q;Q=null,r?.(n)},L=(e,n)=>{let r=t.pending,s=r.questions[e],o=r.resolution[e];r.resolution[e]=n;let u=Be(s);o?m({kind:"answer",receipt:{form:"changed",qNum:e+1,stub:u,choice:ve(s,n),prev:o.choice}}):n.form==="deferred"?m({kind:"answer",receipt:{form:"deferred",qNum:e+1,stub:u}}):m({kind:"answer",receipt:{form:n.form,qNum:e+1,stub:u,choice:ve(s,n)}})},we=()=>{let e=t.pending;e&&(e.questions.forEach((n,r)=>{e.resolution[r]||L(r,{form:"deferred",selected_index:null,free_text:null,choice:""})}),K())},X=new Map,_e=e=>{X.clear();let n={high:0,med:1,low:2};return e=e.map((r,s)=>({q:r,i:s})).sort((r,s)=>(n[r.q.risk]??3)-(n[s.q.risk]??3)||r.i-s.i).map(({q:r})=>r),{questions:e,cursor:0,resolution:e.map(()=>null)}},Ce=(e,n)=>{if(t.confirm&&(t.confirm=null),t.pending)return;let r=n==="kane"?{kind:"note",text:$().text("chat.repair_sent",{})}:{kind:"user",text:e};if(!g){t.turns.push({role:"user",text:e}),m(r),t.notice="the agent isn't running \u2014 nothing sent",p();return}t.notice=void 0,ee=!1,t.checkpoint=!1,delete t.resumedParked,V(),t.turns.push({role:"user",text:e}),m(r);let s=pe(e,n);for(t.status="streaming",t.busySince=Date.now(),W(),t.error=void 0,d+=1;S.length>0;)d+=1,g({type:"user_message",message_id:`u${d}-receipt`,text:S.shift()},{by:"kane",receipt:!0});g({type:"user_message",message_id:s??`u${d}`,text:e},{by:n}),p()};return{state:t,explainLines(e){if(!i.explain||!i.graph||!i.store)return null;let n=i.explain(i.store,i.graph,e);return n.target?[`${n.target.label} ${n.target.slug??n.target.cid.slice(0,19)}:`,...n.entries.map(r=>` [${r.kind}] ${r.rationale??r.detail}`)]:null},explainRef(e){if(!i.explain||!i.graph||!i.store){m({kind:"note",text:"explain isn't available here"}),p();return}let n=i.explain(i.store,i.graph,e),r=n.target?[`${n.target.label} ${n.target.slug??n.target.cid.slice(0,19)}:`,...n.entries.map(s=>` [${s.kind}] ${s.rationale??s.detail}`)].join(`
3
3
  `):`unknown ref: ${e}`;m({kind:"note",text:r}),p()},subscribe(e){return k.push(e),()=>{let n=k.indexOf(e);n>=0&&k.splice(n,1)}},submit(e){Ce(e,"person")},repair(e){Ce(e,"kane")},attachSender(e){let n=g;return g=e,()=>{g=n}},attachOnCommitted(e){f=e},attachConversationSource(e){v=e},opIdPrefix(e){A=e},attachSession(e){i.session=e},enterNested(e){if(G+=1,G>1)return()=>{G-=1};let n={checkpoint:t.checkpoint,receipts:S.splice(0,S.length)};te=g,M=t.credits?.total??0,t.checkpoint=!1,t.status==="idle"&&(t.status="working",t.workingLabel=e,t.busySince=Date.now()),p();let r=!1;return()=>{r||(r=!0,G-=1,te=null,M!==null&&(ne+=Math.max(0,(t.credits?.total??M)-M)),M=null,S.splice(0,S.length,...n.receipts),t.checkpoint=n.checkpoint,t.status==="working"&&(t.status="idle",t.workingLabel=void 0,t.busySince=void 0),p())}},holdReceipt(e,n){S.push(e),n?.checkIn!==!1&&(t.checkpoint=!0),p()},drainHeldReceipts(){return S.splice(0,S.length)},peekHeldReceipts(){return[...S]},submitAnswer(e,n){let r=t.pending,s=r?.questions[e],o=s?.options[n]?.label;!r||!s||o==null||(L(e,{form:"answered",selected_index:n,free_text:null,choice:B(o)}),K(),p())},submitFreeText(e,n){let r=t.pending,s=r?.questions[e],o=n.trim();!r||!s||!o||(L(e,{form:"answered",selected_index:null,free_text:o,choice:o}),K(),p())},deferBatch(e){let n=t.pending;if(!n||!Q)return;n.questions.forEach((s,o)=>{let u=n.resolution[o];u&&u.form==="answered"&&re.set(fe(s),u)}),t.pending=null,t.status=t.status==="pausing"?"pausing":"streaming",t.status==="streaming"&&(t.busySince=Date.now()),m({kind:"note",text:`questions set aside \u2014 source ${e.source_id} landed; the agent reads it next`});let r=Q;Q=null,r({deferred:!0,ingested:e}),p()},submitAnswerWithText(e,n,r){let s=t.pending,o=s?.questions[e],u=o?.options[n]?.label;if(!s||!o||u==null)return;let h=r.trim();L(e,{form:"answered",selected_index:n,free_text:h||null,choice:h?`${B(u)} \u2014 ${h}`:B(u)}),K(),p()},toggleOption(e,n){let r=t.pending?.questions[e];if(!r||r.options[n]==null)return;let s=X.get(e)??new Set;s.has(n)?s.delete(n):s.add(n),X.set(e,s),p()},multiSelection(e){return[...X.get(e)??[]].sort((n,r)=>n-r)},confirmMulti(e){let n=t.pending,r=n?.questions[e];if(!n||!r)return;let s=[...X.get(e)??[]].sort((u,h)=>u-h).map(u=>r.options[u]?.label).filter(u=>u!=null);if(s.length===0)return;X.delete(e);let o=s.join(", ");L(e,{form:"answered",selected_index:null,free_text:o,choice:o}),K(),p()},goWithRecommendations(){let e=t.pending;if(!e)return{picks:""};let n=He(e),r=null;return e.questions.forEach((s,o)=>{if(e.resolution[o])return;let u=s.recommended_index,h=u!=null?s.options[u]?.label:void 0;if(h==null){r===null&&(r=o);return}L(o,{form:"assumed",selected_index:u,free_text:null,choice:B(h)})}),r!==null?(e.cursor=r,p(),{blocked:r}):(K(),p(),{picks:n})},reopenQuestion(){let e=t.pending;if(!e)return;let n=e.cursor<0?e.questions.length:e.cursor;for(let r=n-1;r>=0;r--)if(e.resolution[r]){e.cursor=r,p();return}},continueParked(){if(g&&!(G>0&&g===te)){for(t.checkpoint=!1,m({kind:"continued"});S.length>0;)d+=1,g({type:"user_message",message_id:`u${d}-receipt`,text:S.shift()},{by:"kane",receipt:!0});d+=1,g({type:"user_message",message_id:`u${d}`,text:"continue"},{by:"person",continued:!0}),t.status="streaming",t.busySince=Date.now(),W(),p()}},note(e){m({kind:"note",text:e}),p()},finalizeForExit(){q(),D(),V(),t.stream=null,p()},aliasOf(e){return U.get(e)},guardOps(e){return N=e,ee=!1,()=>{N===e&&(N=null)}},registerAliases(e,n){for(let r of e)U.set(r.ref,r.cid);if(n?.unchanged){E=null,p();return}oe(new Map(e.filter(r=>r.id).map(r=>[r.ref,r.id])),!1,new Set(e.filter(r=>r.own).map(r=>r.ref))),p()},endUnstartedTurn(){t.status!=="streaming"&&t.status!=="working"||(t.status="idle",t.workingLabel=void 0,t.busySince=void 0,p())},answersHeld(e){ie=new Map(e.map(n=>[n.id,n.digest]))},resumedParked(){t.status="idle",t.workingLabel=void 0,t.busySince=void 0,t.resumedParked=!0,p()},restoreCheckIn(){let e=i.resumedCheckIn?.()??null;e!==null&&(t.resumed=e,t.checkpoint=!0,p())},setWorking(e){if(e!=null){if(t.status!=="idle"&&t.status!=="working")return;t.status==="idle"&&(t.busySince=Date.now()),W(),t.status="working",t.workingLabel=e}else{if(t.status!=="working")return;t.status="idle",t.workingLabel=void 0,t.busySince=void 0}p()},narrated(e,n){q(),t.stream=null,t.busySince=void 0,D(),n&&m(n),e&&m({kind:"agent",text:e}),(t.status==="streaming"||t.status==="working")&&(t.status="idle"),t.workingLabel=void 0,p()},ledger(e){if(e.kind==="commit"&&(oe(void 0,e.held===!0),se+=e.heldChanges??0),e.kind==="error"&&(q(),D(),V()),e.kind==="commit"&&(e.notes!==void 0||e.quiet)){let{notes:n,quiet:r,...s}=e;m(r?{kind:"note",text:s.line}:s);for(let o of n??[])m({kind:"note",text:o})}else m(e);e.kind==="commit"&&(e.ok?V(!0):We()),p()},senderAlive(){return g!=null},approveAdded(){let e=ye();return p(),e},completeSession(e){e?.approveAdded&&!ye()||(we(),g?.({type:"session_complete"}),t.status="idle",t.busySince=void 0,p())},requestPause(){we(),t.status="pausing",t.busySince=void 0;let e=g;Promise.resolve().then(()=>e?.({type:"pause"})),p()},ask(e){t.pending=_e(e),me=new Map(e.map((r,s)=>[r.id,s+1])),t.status="awaiting-input",t.busySince=void 0;let n=new Promise(r=>{Q=r});if(re.size>0){let r=0;e.forEach((s,o)=>{let u=fe(s),h=re.get(u);h&&(re.delete(u),L(o,{...h}),r+=1)}),r>0&&m({kind:"note",text:`your earlier answer${r>1?"s are":" is"} pre-filled \u2014 press enter to send, or pick a different answer`})}return p(),n},attachIngest(e){let n=F;return F=e,()=>{F===e&&(F=n)}},canIngest(){return F!==null},async ingestAttach(e){let n=F,r=e.trim();if(!n||!r)return;let s;try{s=await n(r)}catch(o){s={ok:!1,error:o instanceof Error?o.message:String(o)}}s.ok||(m({kind:"note",text:s.error??"the source could not be ingested"}),p())},noteCoercion(e,n){m({kind:"answer",receipt:{form:"assumed",qNum:me.get(e.id)??0,stub:Be(e),choice:n,note:"your typed answer couldn't be used here"}}),p()},nothingCommitted(){t.committing&&(delete t.committing,p())},creditsCarriedIn(e){e<=0||(t.credits={turn:t.credits?.turn??0,total:(t.credits?.total??0)+e},ne+=e,p())},creditsSoFar(e,n){if(!(e<=0)){if(M!==null){t.credits={turn:0,total:M+e},p();return}t.credits||(t.credits={turn:0,total:e},n!==void 0&&n>0&&(ne=n),p())}},onAgentEvent(e){switch(e.type){case"reasoning_delta":case"reasoning_done":case"tool_activity":case"decision_activity":{let n=t.thinking;if(t.thinking=Me(n,e),t.thinking!==n&&(e.type==="reasoning_done"&&e.present?(W(),T.thinkMs+=e.took_ms):e.type==="tool_activity"&&e.status!=="started"&&(W(),T.toolCalls+=1,T.tools.set(e.name,(T.tools.get(e.name)??0)+1))),e.type==="reasoning_delta"){be();return}break}case"usage":t.credits={turn:e.credits,total:(M??ne)+e.total_credits};break;case"text_delta":{let n=he;if(n&&(e.turn_id<n.turn_id||e.turn_id===n.turn_id&&e.attempt<n.attempt))return;(!n||n.turn_id!==e.turn_id||n.attempt!==e.attempt)&&(he={turn_id:e.turn_id,attempt:e.attempt},t.stream={text:""}),t.stream={text:(t.stream?.text??"")+e.text},be();return}case"progress":break;case"proposal":{l+=1,q(),t.stream=null,t.busySince=void 0,D();let n=Ve(e.proposal),r=i.dedupFlags?.(e.proposal);if(r)for(let o of n){let u=r.get(o.temp_ref);u&&(o.matches_existing=u)}let s=i.refreshGraph?.()??i.graph;if(s)for(let o of n){let u=o.matches_existing?.cid,h=typeof u=="string"?s.displayNameOf(u):null;h&&(o.matched_id=h)}t.turns.push({role:"agent",turnIndex:l,items:n,text:e.narrative}),z=e.narrative??null,Z=!0,t.committing=!0,t.activeTurn={turnIndex:l,heading:"use-cases",items:n},E={turnIndex:l,heading:"use-cases",items:n},(t.status==="streaming"||t.status==="working")&&(t.status="idle"),t.workingLabel=void 0;break}case"design":{l+=1,q(),t.stream=null,t.busySince=void 0,D();let{items:n,heading:r}=Xe(e.design),s=e.design.phase==="wiring"?"acceptance criteria + exercises":r.split(" + ").map(o=>Ke[o]??o).join(" + ");m({kind:"banner",text:`designing: ${s}`}),t.turns.push({role:"agent",turnIndex:l,items:n,itemsHeading:r,text:e.narrative}),z=e.narrative??null,Z=!0,t.committing=!0,t.activeTurn={turnIndex:l,heading:r,items:n},E={turnIndex:l,heading:r,items:n},(t.status==="streaming"||t.status==="working")&&(t.status="idle"),t.workingLabel=void 0;break}case"ask_user":if(D(),e.questions.length>0&&e.questions.every(n=>ie.get(n.id)===Ne(n))){for(let n of e.questions)ie.delete(n.id);break}t.pending=_e(e.questions),t.status="awaiting-input",t.busySince=void 0;break;case"chat_ops":{l+=1,q(),D(),t.stream=null,(t.status==="streaming"||t.status==="working")&&(t.status="idle",t.busySince=void 0,t.workingLabel=void 0);let n=e.chat_ops??e,r=Array.isArray(n.ops)?n.ops:[],s=n.text??e.text??"",o=i.refreshGraph?.()??i.graph,u=c=>U.get(c)??c,h=r.map(c=>{if(!c.target)return c;let x=u(c.target),O=c.expected_cid;if(O==null&&o){let Se=o.resolve(x);Se&&(O=o.tipOf(Se.cid))}let j=c.payload?.redirect_to,P=j&&u(j);return x===c.target&&O===c.expected_cid&&P===j?c:{...c,target:x,expected_cid:O,...P!==j?{payload:{...c.payload,redirect_to:P}}:{}}}),_;try{if(!Array.isArray(n.ops))throw new Error("the agent sent an unreadable change set (no ops array) \u2014 say it again in different words");let c=v||i.session?.state?.sid,x=A;A=null,_=je(h,i.descriptor??{mint_gate:[]},{turn:l+(c?a(c):0),...c?{session:c}:{},...x?{prefix:x}:{},...v?{convSourceId:v}:{}})}catch(c){t.error=c instanceof Error?c.message:String(c),t.turns.push({role:"agent",turnIndex:l,text:s,narration:t.error}),s&&m({kind:"agent",text:s}),m({kind:"error",title:t.error,detail:[]}),S.push(`OPS REJECTED (did not compile) \u2014 nothing landed; do not assume any of your last ops applied.
4
4
  - `+t.error);break}let{chatOps:R,ambiguous:b}=_;if(b.length>0){let c=b[0];t.confirm={kind:"ambiguity-confirm",prompt:`did you mean edit or ${c.kinds.filter(x=>x!=="edit").join("/")} on ${c.target}?`},t.turns.push({role:"agent",turnIndex:l,text:s}),s&&m({kind:"agent",text:s});break}Ge(R);let I=R.length>0&&N?N(R):null;if(I){if(t.turns.push({role:"agent",turnIndex:l,text:s}),S.push(I),g&&!ee)for(ee=!0,t.status="streaming",t.busySince=Date.now(),W();S.length>0;)d+=1,g({type:"user_message",message_id:`u${d}-receipt`,text:S.shift()},{by:"kane",receipt:!0});break}if(i.commitChatTurn&&R.length>0){let c;try{c=i.commitChatTurn({graph:i.refreshGraph?.()??i.graph,ops:R,by:i.by??{kind:"human",id:"owner"},...i.descriptor?.mint_gate?{mintable:i.descriptor.mint_gate}:{},...i.session?.state?.sid?{sid:i.session.state.sid}:{}})}catch(x){c={record:null,errors:[{code:"COMMIT_THREW",detail:x instanceof Error?x.message:String(x)}]}}if(c.errors)t.error=c.errors.map(x=>x.detail).join("; "),t.turns.push({role:"agent",turnIndex:l,text:s}),m({kind:"commit",ok:!1,line:$().text("chat.commit_failed",{}),warnings:c.errors.map(x=>`${x.code}: ${x.detail}`),refused:Pe(c.errors,o)}),S.push(["COMMIT FAILED (chat turn) \u2014 nothing landed; do not assume any of your last ops applied.",...c.errors.map(x=>`- ${x.code}: ${x.detail}${x.code==="EXPECTED_CID_MOVED"&&typeof x.data?.tip=="string"?`; its current cid is ${x.data.tip}`:""}`),...c.errors.some(x=>x.code==="UNKNOWN_FIELD")?["If you were changing citations or matched-existing content, that is proposal territory (approve/re-propose) \u2014 a chat edit can only replace a node's own schema fields."]:[]].join(`
5
5
  `)),s&&m({kind:"agent",text:s});else{c.applied.length>0&&i.session?.markApplied(c.applied);let x=w(R,c)?$().text("chat.approved",{count:c.applied.length}):y(c);t.turns.push({role:"agent",turnIndex:l,text:s,narration:x}),m({kind:"commit",ok:!0,line:x});let O=i.refreshGraph?.();if(O&&f&&f(O),xe(O??i.graph),O)try{ue+=1;let J=i.descriptor?.mint_gate?.includes("usecase")?"extract":"design",j=qe({verb:J,commitN:ue,phase:"chat",committed:c.minted.map(P=>({cid:P.cid,...P.slug?{logical_id:P.slug}:{}})),...Re(i.templateVersion?.()??null)>=8?{typedBlockers:!0,...i.ucRef?{ucRef:i.ucRef}:{}}:{},...(i.pendingForceScope?.()??[]).length?{ignoreGaps:new Set(i.pendingForceScope())}:{}},O);S.push(j.text)}catch(J){ce||(ce=!0,m({kind:"note",text:$().text("note.receipt_unbuilt",{detail:J instanceof Error?J.message:String(J)})}))}s&&m({kind:"agent",text:s})}}else t.turns.push({role:"agent",turnIndex:l,text:s}),s&&m({kind:"agent",text:s});pe(s,"agent");break}case"done":case"session_complete":q(),D(),V(),t.status="idle",t.busySince=void 0,g=null;break;case"error":q(),D(),V(),t.stream=null,t.status="idle",t.busySince=void 0,t.error=e.message,g=null,m({kind:"error",title:e.message,detail:[]});break;case"session_paused":break;case"turn_retry":m({kind:"note",text:$().text("note.model_retry",{seconds:Math.round(e.wait_s)})});break;default:break}p()}}}export{He as a,B as b,Be as c,ut as d};
@@ -0,0 +1,2 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{i as r}from"./chunk-YKOZBFR3.js";var o=()=>process.env.KANE_TELEMETRY_URL||r;export{o as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as m}from"./chunk-PVN64537.js";import{e as y}from"./chunk-ZAQGIC33.js";import{b as d}from"./chunk-ZCBOHWN3.js";function g(t={}){let a=t.readStore??C,s=t.readLis??w;return{async controller(){let e=await a();return{token:e.token,...e.basic?{basic:e.basic}:{}}},async lis(){return s()}}}var A=()=>C(!0),_=g(),P=8e3;function f(){return y("warn: session auth may expire during long runs \u2014 if that happens, run `kane-cli login` and retry","AUTH_EXCHANGE_FAILED"),null}async function h(t,a,s=!1){try{let[{getEnvironment:e},{ControllerClient:r}]=await Promise.all([import("./config-7WTZPMAH.js"),import("./controller-client-PB3AZAGG.js")]),o=new r(e(t).controllerBaseUrl,a),i;try{let n=await Promise.race([o.getTmsCredentials().catch(()=>null),new Promise(c=>{i=setTimeout(()=>c(null),P)})]);if(typeof n?.username!="string"||!n.username||typeof n.access_key!="string"||!n.access_key)return s?null:f();try{let[{refreshIdentitySnapshot:c},{telemetryEnvName:u}]=await Promise.all([import("./identity-HL5CJJXR.js"),import("./bootstrap-XGKU4WXB.js")]);await c(u(),n)}catch{}return{username:n.username,accessKey:n.access_key}}finally{clearTimeout(i)}}catch{return s?null:f()}}var l=null;function E(t){l=t===null?null:{username:t.username,accessKey:t.accessKey}}async function C(t=!1){if(l!==null)return{token:null,basic:{...l}};let[{CredentialsManager:a},{refreshOAuthToken:s}]=await Promise.all([import("./credentials-5WIFF5DG.js"),import("./token-refresh-E4FTJVHY.js")]),e=new a,r=d(),o=e.getActiveProfile()??"default",i=e.loadBasicAuth(o,r);if(i)return{token:null,basic:{username:i.username,accessKey:i.access_key}};let n=e.loadCredentials(o,r);if(!n)throw new m("Not authenticated \u2014 no credentials found","not_authenticated");try{await s({creds:e,profile:o,env:r,credentials:n})}catch{}let c=e.loadCredentials(o,r)??n;if(typeof c.access_token!="string")throw new m("Not authenticated \u2014 no credentials found","not_authenticated");let u=c.access_token,p=await h(r,u,t);return{token:u,...p?{basic:p}:{}}}async function w(){if(l!==null)return{basic:Buffer.from(`${l.username}:${l.accessKey}`,"utf8").toString("base64")};let{CredentialsManager:t}=await import("./credentials-5WIFF5DG.js"),a=new t,s=d(),e=a.loadCredentials(a.getActiveProfile()??"default",s);if(typeof e?.access_token!="string")return{};let r=await h(s,e.access_token,!0);return r?{basic:Buffer.from(`${r.username}:${r.accessKey}`,"utf8").toString("base64")}:{}}export{A as a,_ as b,E as c};
2
+ import{a as m}from"./chunk-PVN64537.js";import{e as y}from"./chunk-ZAQGIC33.js";import{b as d}from"./chunk-73EHVDL5.js";function g(t={}){let a=t.readStore??C,s=t.readLis??w;return{async controller(){let e=await a();return{token:e.token,...e.basic?{basic:e.basic}:{}}},async lis(){return s()}}}var A=()=>C(!0),_=g(),P=8e3;function f(){return y("warn: session auth may expire during long runs \u2014 if that happens, run `kane-cli login` and retry","AUTH_EXCHANGE_FAILED"),null}async function h(t,a,s=!1){try{let[{getEnvironment:e},{ControllerClient:r}]=await Promise.all([import("./config-F5Q6QX27.js"),import("./controller-client-PB3AZAGG.js")]),o=new r(e(t).controllerBaseUrl,a),i;try{let n=await Promise.race([o.getTmsCredentials().catch(()=>null),new Promise(c=>{i=setTimeout(()=>c(null),P)})]);if(typeof n?.username!="string"||!n.username||typeof n.access_key!="string"||!n.access_key)return s?null:f();try{let[{refreshIdentitySnapshot:c},{telemetryEnvName:u}]=await Promise.all([import("./identity-66TGWITQ.js"),import("./bootstrap-BV7HAARR.js")]);await c(u(),n)}catch{}return{username:n.username,accessKey:n.access_key}}finally{clearTimeout(i)}}catch{return s?null:f()}}var l=null;function E(t){l=t===null?null:{username:t.username,accessKey:t.accessKey}}async function C(t=!1){if(l!==null)return{token:null,basic:{...l}};let[{CredentialsManager:a},{refreshOAuthToken:s}]=await Promise.all([import("./credentials-D5KQMHCK.js"),import("./token-refresh-PZ3TOKAL.js")]),e=new a,r=d(),o=e.getActiveProfile()??"default",i=e.loadBasicAuth(o,r);if(i)return{token:null,basic:{username:i.username,accessKey:i.access_key}};let n=e.loadCredentials(o,r);if(!n)throw new m("Not authenticated \u2014 no credentials found","not_authenticated");try{await s({creds:e,profile:o,env:r,credentials:n})}catch{}let c=e.loadCredentials(o,r)??n;if(typeof c.access_token!="string")throw new m("Not authenticated \u2014 no credentials found","not_authenticated");let u=c.access_token,p=await h(r,u,t);return{token:u,...p?{basic:p}:{}}}async function w(){if(l!==null)return{basic:Buffer.from(`${l.username}:${l.accessKey}`,"utf8").toString("base64")};let{CredentialsManager:t}=await import("./credentials-D5KQMHCK.js"),a=new t,s=d(),e=a.loadCredentials(a.getActiveProfile()??"default",s);if(typeof e?.access_token!="string")return{};let r=await h(s,e.access_token,!0);return r?{basic:Buffer.from(`${r.username}:${r.accessKey}`,"utf8").toString("base64")}:{}}export{A as a,_ as b,E as c};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{L as N,a as k,pa as S,r as w}from"./chunk-PI7OXS62.js";import{f as _,h as $}from"./chunk-KU3YHPWZ.js";var T=3,F={edit:"edit",reject:"mistake",dedup_dropped:"mistake",approve:"usage",enhance:"directed-edit",add:"directed-edit",default_accepted:"usage",default_overridden:"edit",gap_resolution:"usage",dedup_kept:"usage"};function P(m){let{store:u,graph:s,watermark:v,by:f}=m,{signals:b}=u.signals().snapshot(v),E=b.filter(e=>e.event_id===void 0||s.appliedEvents.has(e.event_id)),n=new Map;for(let e of E){let t=e.event_id??`${e.ts}|${e.id}|${e.verdict}|${e.polarity}`;n.has(`${t}|${e.polarity}|${e.verdict}`)||n.set(`${t}|${e.polarity}|${e.verdict}`,e)}let j=[...n.values()].sort((e,t)=>(e.event_id??e.ts)<(t.event_id??t.ts)?-1:1),i=new Map;for(let e of j){let t=`${e.verdict}|${e.tag??""}`,r=i.get(t)??{verdict:e.verdict,tag:e.tag,events:new Set};r.events.add(e.event_id??e.ts),i.set(t,r)}let d=[],a=[],g=new Set,c=[],y=0;for(let[,e]of[...i.entries()].sort(([t],[r])=>t<r?-1:1)){if(e.events.size<T)continue;let r={derived:!0,statement:`${e.verdict}${e.tag?`/${e.tag}`:""} recurs (${e.events.size} distinct events) \u2014 bias future proposals ${e.verdict==="approve"?"toward":"away from"} this pattern`,learned_from_kind:F[e.verdict]??"usage",learned_from:[...e.events].sort()},h=$("stylenote",r);if(h.length>0)return{record:null,errors:h.map(o=>({code:o.code,detail:o.detail})),minted:0};let p=k("stylenote",r);if(s.hasNode(p))continue;d.push({cid:p,label:_.STYLENOTE,content:r});for(let o of r.learned_from)c.includes(o)||c.push(o);let l=S("stylenote",o=>g.has(o),s.names.keys());l!==null&&(g.add(l),a.push({cid:p,slug:l,by:f})),y+=1}return d.length===0?{record:null,errors:null,minted:0}:{record:N(u,{ts:new Date().toISOString(),proposal_id:null,nodes:d,edges:[],review:[],supersessions:[],source_head_moves:{},...a.length>0?{names:a}:{}},{graph:s,expectPrev:s.latestHash,intent:{v:1,verb:"distill",args:w({watermark:v,by:f}),pins:{events:c}},provenance:m.provenance}).record,errors:null,minted:y}}export{P as a};
2
+ import{L as N,a as k,pa as S,r as w}from"./chunk-5EAJO372.js";import{f as _,h as $}from"./chunk-KU3YHPWZ.js";var T=3,F={edit:"edit",reject:"mistake",dedup_dropped:"mistake",approve:"usage",enhance:"directed-edit",add:"directed-edit",default_accepted:"usage",default_overridden:"edit",gap_resolution:"usage",dedup_kept:"usage"};function P(m){let{store:u,graph:s,watermark:v,by:f}=m,{signals:b}=u.signals().snapshot(v),E=b.filter(e=>e.event_id===void 0||s.appliedEvents.has(e.event_id)),n=new Map;for(let e of E){let t=e.event_id??`${e.ts}|${e.id}|${e.verdict}|${e.polarity}`;n.has(`${t}|${e.polarity}|${e.verdict}`)||n.set(`${t}|${e.polarity}|${e.verdict}`,e)}let j=[...n.values()].sort((e,t)=>(e.event_id??e.ts)<(t.event_id??t.ts)?-1:1),i=new Map;for(let e of j){let t=`${e.verdict}|${e.tag??""}`,r=i.get(t)??{verdict:e.verdict,tag:e.tag,events:new Set};r.events.add(e.event_id??e.ts),i.set(t,r)}let d=[],a=[],g=new Set,c=[],y=0;for(let[,e]of[...i.entries()].sort(([t],[r])=>t<r?-1:1)){if(e.events.size<T)continue;let r={derived:!0,statement:`${e.verdict}${e.tag?`/${e.tag}`:""} recurs (${e.events.size} distinct events) \u2014 bias future proposals ${e.verdict==="approve"?"toward":"away from"} this pattern`,learned_from_kind:F[e.verdict]??"usage",learned_from:[...e.events].sort()},h=$("stylenote",r);if(h.length>0)return{record:null,errors:h.map(o=>({code:o.code,detail:o.detail})),minted:0};let p=k("stylenote",r);if(s.hasNode(p))continue;d.push({cid:p,label:_.STYLENOTE,content:r});for(let o of r.learned_from)c.includes(o)||c.push(o);let l=S("stylenote",o=>g.has(o),s.names.keys());l!==null&&(g.add(l),a.push({cid:p,slug:l,by:f})),y+=1}return d.length===0?{record:null,errors:null,minted:0}:{record:N(u,{ts:new Date().toISOString(),proposal_id:null,nodes:d,edges:[],review:[],supersessions:[],source_head_moves:{},...a.length>0?{names:a}:{}},{graph:s,expectPrev:s.latestHash,intent:{v:1,verb:"distill",args:w({watermark:v,by:f}),pins:{events:c}},provenance:m.provenance}).record,errors:null,minted:y}}export{P as a};