@wirecat/drive-cli 0.70.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +150 -70
  2. package/contracts/wirecat.json +77 -8
  3. package/dist/bin/drive.js +2 -2
  4. package/dist/bundle/agent-23OB2NZP.js +46 -0
  5. package/dist/bundle/{all-profiles-FW3GK3QO.js → all-profiles-GXGDVNQJ.js} +67 -25
  6. package/dist/bundle/{anthropic-QVKJT3II.js → anthropic-H5C4GQHC.js} +9 -9
  7. package/dist/bundle/{app-server-QU73RD5R.js → app-server-EQ3UK4C7.js} +97 -79
  8. package/dist/bundle/{bun-5XCD5CBB.js → bun-DTJVSRY3.js} +2 -2
  9. package/dist/bundle/{bun-sqlite-TIGSVNSV.js → bun-sqlite-JIFY7MAE.js} +9 -9
  10. package/dist/bundle/chunk-2Q325BBD.js +353 -0
  11. package/dist/bundle/chunk-35FIJGTT.js +52 -0
  12. package/dist/bundle/{chunk-7C5KENNU.js → chunk-3FRQ6V4T.js} +3 -3
  13. package/dist/bundle/chunk-47L262VI.js +340 -0
  14. package/dist/bundle/chunk-4HP6KGBI.js +32 -0
  15. package/dist/bundle/{chunk-GA3URWIF.js → chunk-4HPXWYTE.js} +1 -1
  16. package/dist/bundle/{chunk-HYXXMSVD.js → chunk-4IUNYYYL.js} +4473 -2685
  17. package/dist/bundle/{chunk-FYPW7NMH.js → chunk-4JS32SRX.js} +64 -4
  18. package/dist/bundle/chunk-4ZAQMDLD.js +1308 -0
  19. package/dist/bundle/chunk-4ZTB7LS3.js +87 -0
  20. package/dist/bundle/{chunk-SONPLYV7.js → chunk-55FH6IEL.js} +5 -5
  21. package/dist/bundle/{chunk-VVN6GHAZ.js → chunk-5BNMWSU2.js} +659 -255
  22. package/dist/bundle/{chunk-FVTKFIQH.js → chunk-5H747A76.js} +5496 -3195
  23. package/dist/bundle/{chunk-PR7XD2DI.js → chunk-5KWCO56H.js} +2 -2
  24. package/dist/bundle/{chunk-3AHBZP33.js → chunk-5U3NCE5R.js} +35 -12
  25. package/dist/bundle/{chunk-HRATXUFH.js → chunk-6CCO3JCM.js} +31 -22
  26. package/dist/bundle/{chunk-RLNZ7NX5.js → chunk-6ZW2ZJYC.js} +2 -2
  27. package/dist/bundle/{chunk-RQNRYF6D.js → chunk-75DAHQOV.js} +3 -3
  28. package/dist/bundle/{chunk-7QSRODXM.js → chunk-77OBW43F.js} +6 -6
  29. package/dist/bundle/{chunk-GV5DGHSA.js → chunk-7EFM6AW3.js} +4 -4
  30. package/dist/bundle/{chunk-BXPC5TFG.js → chunk-A3S7QM5L.js} +3 -3
  31. package/dist/bundle/{chunk-IGNIUDI3.js → chunk-AA4LKC6W.js} +251 -565
  32. package/dist/bundle/chunk-ASTKHB6B.js +3233 -0
  33. package/dist/bundle/{chunk-3TCMANIM.js → chunk-BM6V7456.js} +8 -227
  34. package/dist/bundle/chunk-BO6EDBYJ.js +50 -0
  35. package/dist/bundle/{chunk-F5KJWRF5.js → chunk-BPA3R4KN.js} +2 -100
  36. package/dist/bundle/chunk-CIFE4KPX.js +2159 -0
  37. package/dist/bundle/chunk-CKB4XZZJ.js +730 -0
  38. package/dist/bundle/{chunk-YCL3SK4T.js → chunk-COJTCEZP.js} +113 -860
  39. package/dist/bundle/{chunk-BD2K2ONK.js → chunk-CWPYDT73.js} +6 -6
  40. package/dist/bundle/{chunk-6BMTW5A6.js → chunk-D4JNCXS7.js} +9 -9
  41. package/dist/bundle/chunk-DCPWZIOV.js +696 -0
  42. package/dist/bundle/{chunk-P7PLKNPX.js → chunk-DHMNCOQI.js} +415 -272
  43. package/dist/bundle/chunk-DOQMH4DC.js +280 -0
  44. package/dist/bundle/chunk-DQSOYH6N.js +20 -0
  45. package/dist/bundle/{chunk-ML3R2UHV.js → chunk-DWRUOLBF.js} +4 -4
  46. package/dist/bundle/{chunk-5JTB4URG.js → chunk-E3VWZC3K.js} +14 -13
  47. package/dist/bundle/chunk-ECYOTDJM.js +14 -0
  48. package/dist/bundle/{chunk-7IBENBCK.js → chunk-EVG3AA5M.js} +2 -2
  49. package/dist/bundle/chunk-F4BX7TH2.js +15 -0
  50. package/dist/bundle/{chunk-FCSHWUMW.js → chunk-FBEZSA76.js} +5 -5
  51. package/dist/bundle/{chunk-RHSBXOQM.js → chunk-FBQJN74J.js} +1 -1
  52. package/dist/bundle/{chunk-4WK26MPY.js → chunk-FIZOPJYY.js} +1 -1
  53. package/dist/bundle/chunk-FNAYSZWK.js +783 -0
  54. package/dist/bundle/{chunk-LINBDWJK.js → chunk-FRCJHGZM.js} +2 -2
  55. package/dist/bundle/{chunk-RCTOWLCD.js → chunk-FTG5QBSD.js} +41 -33
  56. package/dist/bundle/{chunk-ABZ2NYDT.js → chunk-FUDUXIVG.js} +1 -1
  57. package/dist/bundle/{chunk-NYECVHFH.js → chunk-G4NHRFS7.js} +755 -0
  58. package/dist/bundle/{chunk-PAPY6Q6H.js → chunk-GIEZYBRC.js} +1 -1
  59. package/dist/bundle/chunk-GTPPUBYU.js +1876 -0
  60. package/dist/bundle/chunk-GU6ICH53.js +108 -0
  61. package/dist/bundle/{chunk-REM5WHHQ.js → chunk-GUMKKRE6.js} +107 -71
  62. package/dist/bundle/{chunk-QBAOIMVB.js → chunk-GWCDOYSC.js} +1 -1
  63. package/dist/bundle/{chunk-HHAZ6DCY.js → chunk-GXGSC622.js} +69 -7
  64. package/dist/bundle/chunk-HAGXTGJC.js +188 -0
  65. package/dist/bundle/{chunk-TNKQDS5A.js → chunk-IMAWQC5K.js} +6 -6
  66. package/dist/bundle/{chunk-ZHZYGY5R.js → chunk-IVGVVSPW.js} +4 -4
  67. package/dist/bundle/{chunk-EDO5LZVF.js → chunk-J4NUHSM7.js} +1 -1
  68. package/dist/bundle/{chunk-DVVUJ254.js → chunk-K652FYCO.js} +6 -6
  69. package/dist/bundle/chunk-K6ZWNTXY.js +561 -0
  70. package/dist/bundle/{chunk-FONIFRYI.js → chunk-KF3ZBQJV.js} +4 -4
  71. package/dist/bundle/chunk-KFZCHJRT.js +80 -0
  72. package/dist/bundle/chunk-KLPFDFLI.js +221 -0
  73. package/dist/bundle/{chunk-LMJBQFW6.js → chunk-KP2XMCNT.js} +13 -13
  74. package/dist/bundle/{chunk-FADAOLGB.js → chunk-KWDZ3KVH.js} +4 -4
  75. package/dist/bundle/{chunk-MXNQZAJQ.js → chunk-KX4C32WD.js} +2 -2
  76. package/dist/bundle/chunk-L7P3LUDQ.js +286 -0
  77. package/dist/bundle/{chunk-ILAQIBEO.js → chunk-M2ZWYVWO.js} +1 -1
  78. package/dist/bundle/chunk-MEYYH47C.js +25 -0
  79. package/dist/bundle/{chunk-ZCXWV4XO.js → chunk-ML2QIWX2.js} +4 -4
  80. package/dist/bundle/{chunk-XOL346TJ.js → chunk-MUFF2YTH.js} +2 -2
  81. package/dist/bundle/{chunk-GAHIHE4K.js → chunk-N24YSLED.js} +9166 -9751
  82. package/dist/bundle/chunk-N4GTCPML.js +7 -0
  83. package/dist/bundle/{chunk-DVI72ZQG.js → chunk-NBMGDRP4.js} +1 -1
  84. package/dist/bundle/chunk-NMQRSEZM.js +37 -0
  85. package/dist/bundle/{chunk-I7YSHUPW.js → chunk-NNGA4QDR.js} +13 -26
  86. package/dist/bundle/{chunk-5DPV7X27.js → chunk-NTZWY5R3.js} +321 -0
  87. package/dist/bundle/chunk-O7CZZ36M.js +80 -0
  88. package/dist/bundle/{chunk-HWUPU6WX.js → chunk-OAONP6KI.js} +13 -9
  89. package/dist/bundle/{chunk-3CHW7JGR.js → chunk-OESP4PHB.js} +17 -17
  90. package/dist/bundle/chunk-OHR6IZNH.js +116 -0
  91. package/dist/bundle/{chunk-54NDYVZA.js → chunk-OLCU7Q2B.js} +1 -1
  92. package/dist/bundle/{chunk-FN3RXBO7.js → chunk-OLDQLEPA.js} +6 -6
  93. package/dist/bundle/{chunk-7DJNURKV.js → chunk-OPIPG6AP.js} +16 -9
  94. package/dist/bundle/{chunk-5D4AEUVA.js → chunk-PL5P7UKW.js} +434 -1
  95. package/dist/bundle/chunk-PRYMT3OG.js +30 -0
  96. package/dist/bundle/chunk-QDUIVMEW.js +36 -0
  97. package/dist/bundle/{chunk-66PL7P4C.js → chunk-QKBPCX7Y.js} +1 -1
  98. package/dist/bundle/{chunk-PN4JYURZ.js → chunk-QSLOACDT.js} +201 -423
  99. package/dist/bundle/{chunk-3UWRAIWA.js → chunk-QUZFDU4K.js} +4 -4
  100. package/dist/bundle/{chunk-KSJAFMU5.js → chunk-R32DHS6J.js} +211 -380
  101. package/dist/bundle/{chunk-2SBC4DVV.js → chunk-R57QUYBG.js} +6 -28
  102. package/dist/bundle/{chunk-IFTX7AQU.js → chunk-R64OSDOD.js} +45 -66
  103. package/dist/bundle/{chunk-WJK6KTCS.js → chunk-RSPBVKOC.js} +8 -8
  104. package/dist/bundle/{chunk-GPDPEHYX.js → chunk-SPNPJ3FZ.js} +3 -4
  105. package/dist/bundle/chunk-SQHDSIFL.js +388 -0
  106. package/dist/bundle/{chunk-XZBA6FVH.js → chunk-ST35FIUG.js} +3 -3
  107. package/dist/bundle/{chunk-37MAA6F2.js → chunk-STUPCKAA.js} +11 -2221
  108. package/dist/bundle/chunk-SZ7XJZGH.js +2231 -0
  109. package/dist/bundle/chunk-TRYYWV7J.js +291 -0
  110. package/dist/bundle/{chunk-OY7TNUEC.js → chunk-TTPWKTVR.js} +1 -1
  111. package/dist/bundle/{chunk-3UZ4OH22.js → chunk-U7VEJ3CW.js} +49 -129
  112. package/dist/bundle/{chunk-6Y2BYFXQ.js → chunk-UC7JLE6J.js} +0 -7
  113. package/dist/bundle/{chunk-HK225DAG.js → chunk-UIQ35CA5.js} +1 -1
  114. package/dist/bundle/{chunk-GK3BJMGK.js → chunk-UJY26HW4.js} +1 -1
  115. package/dist/bundle/{chunk-EG62WVR2.js → chunk-UWG3PRY7.js} +9 -60
  116. package/dist/bundle/{chunk-BBRMDMIR.js → chunk-VAR3MJU6.js} +3 -3
  117. package/dist/bundle/{chunk-GJZSVSV3.js → chunk-VPQSI5IU.js} +4 -4
  118. package/dist/bundle/{chunk-YZPE72GE.js → chunk-VQPT3Y7W.js} +12 -12
  119. package/dist/bundle/{chunk-T5D4OGDC.js → chunk-WMG3H2VK.js} +2 -2
  120. package/dist/bundle/{chunk-6DPOWBKA.js → chunk-X5BGAZC5.js} +6 -6
  121. package/dist/bundle/{chunk-DHX27E5M.js → chunk-XC6TRWLZ.js} +3 -3
  122. package/dist/bundle/{chunk-Q5C6YKAY.js → chunk-XQZEMRCU.js} +402 -402
  123. package/dist/bundle/{chunk-54BQWRJL.js → chunk-XZ7MO6EU.js} +7 -7
  124. package/dist/bundle/{chunk-TGS5VPJD.js → chunk-YAIOEPKU.js} +341 -433
  125. package/dist/bundle/chunk-YHWFF6DN.js +39 -0
  126. package/dist/bundle/{chunk-WWE5GO6G.js → chunk-YWOLQEDV.js} +16 -3
  127. package/dist/bundle/{chunk-DR57KDAY.js → chunk-ZFDSJ5YJ.js} +38 -8
  128. package/dist/bundle/{chunk-BBFXQPKD.js → chunk-ZFUZEFU6.js} +3 -3
  129. package/dist/bundle/{chunk-YRUR3E3E.js → chunk-ZJKXSMXK.js} +72 -59
  130. package/dist/bundle/{chunk-BFKFKDPC.js → chunk-ZKWT6HXT.js} +1 -1
  131. package/dist/bundle/chunk-ZPUY3COZ.js +250 -0
  132. package/dist/bundle/{cli-K4D4DIGQ.js → cli-2P5FW2RL.js} +201 -98
  133. package/dist/bundle/command-contract-BMQT2G5X.js +45 -0
  134. package/dist/bundle/{command-server-entry-WREK3QBB.js → command-server-entry-KP2UDGLA.js} +36 -34
  135. package/dist/bundle/{decode-SEETPKBH.js → decode-K2JZ5D6V.js} +10 -10
  136. package/dist/bundle/{dispatch-SQCEURVK.js → dispatch-KOQZA74A.js} +10 -10
  137. package/dist/bundle/dist-PAKDDIBT.js +191 -0
  138. package/dist/bundle/drive.js +11 -11
  139. package/dist/bundle/{echarts-WZ5RKFCX.js → echarts-URO3QGCG.js} +2 -2
  140. package/dist/bundle/{embed-B2UCRZZR.js → embed-JLIPWTNN.js} +10 -10
  141. package/dist/bundle/{embedder-4R6Z7G7L.js → embedder-LUTDO3HS.js} +15 -15
  142. package/dist/bundle/entry-AVF6LMG7.js +25 -0
  143. package/dist/bundle/{failure-CYNXH3RQ.js → failure-GJMQLM7O.js} +4 -4
  144. package/dist/bundle/first-run-VYTIEUDA.js +31 -0
  145. package/dist/bundle/first-screen-QVZPF7KL.js +45 -0
  146. package/dist/bundle/google-VX7IPACN.js +46 -0
  147. package/dist/bundle/{google-api-SAND2F7L.js → google-api-RFXKRLL4.js} +88 -73
  148. package/dist/bundle/grants-4XWJFVD6.js +133 -0
  149. package/dist/bundle/hast-util-from-html-X2DCPS3T.js +10531 -0
  150. package/dist/bundle/hast-util-to-html-VP6XLPKJ.js +998 -0
  151. package/dist/bundle/hast-util-to-mdast-IZ5PRX72.js +2272 -0
  152. package/dist/bundle/{identity-JVVGS4U6.js → identity-FXPB5EMT.js} +7 -6
  153. package/dist/bundle/{instructions-JSMTSB22.js → instructions-IROIUVZI.js} +1 -1
  154. package/dist/bundle/{login-6WG3YBDU.js → login-WIY5VQU7.js} +96 -81
  155. package/dist/bundle/{mcp-VFIOZDVY.js → mcp-NJIOKW3E.js} +2 -2
  156. package/dist/bundle/{mdast-util-from-markdown-FXEPSNER.js → mdast-util-from-markdown-HEZF7KJ4.js} +137 -195
  157. package/dist/bundle/mdast-util-gfm-AQW6R6MG.js +925 -0
  158. package/dist/bundle/mdast-util-to-hast-DF2QVIRV.js +879 -0
  159. package/dist/bundle/mdast-util-to-markdown-XYLXB3Z3.js +18 -0
  160. package/dist/bundle/meeting-combined-JUNV35GM.js +28 -0
  161. package/dist/bundle/meeting-model-XY4UNWWK.js +29 -0
  162. package/dist/bundle/{meeting-semantic-5U7JQCFF.js → meeting-semantic-62QNQMOM.js} +10 -10
  163. package/dist/bundle/{micromark-extension-gfm-GRL24TU6.js → micromark-extension-gfm-OE2GBORZ.js} +11 -78
  164. package/dist/bundle/{node-VJMVHOWD.js → node-IACCI2CW.js} +2 -2
  165. package/dist/bundle/{node-sqlite-DCNT3HVE.js → node-sqlite-WYIRC7C7.js} +10 -10
  166. package/dist/bundle/notes-search-DEDUJKSN.js +70 -0
  167. package/dist/bundle/oauth-HXBXF4VI.js +22 -0
  168. package/dist/bundle/{open-NFOEHVW7.js → open-H32B6BCT.js} +8 -8
  169. package/dist/bundle/{openai-D47WY7EC.js → openai-VHMPJJUG.js} +22 -21
  170. package/dist/bundle/{process-Q2FRU5VA.js → process-RNHPF5OK.js} +1 -1
  171. package/dist/bundle/{program-T2AJJQEM.js → program-GYMJ3DDH.js} +276 -1132
  172. package/dist/bundle/{prompt-YJSDABXN.js → prompt-TOG2CRCE.js} +8 -8
  173. package/dist/bundle/{reasons-WEHPCSJX.js → reasons-TLFQ45YX.js} +6 -5
  174. package/dist/bundle/{recognize-6OBEIEB3.js → recognize-GYGY45EY.js} +7 -7
  175. package/dist/bundle/remote-6XN2QLI5.js +35 -0
  176. package/dist/bundle/{rerank-L6F5SLIB.js → rerank-HJO3O4TW.js} +11 -11
  177. package/dist/bundle/{serve-GYSWIWH4.js → serve-XPCNLHCR.js} +19 -19
  178. package/dist/bundle/server-UBJZ66XE.js +97 -0
  179. package/dist/bundle/{server-GWWP3RIT.js → server-WPT3NC5B.js} +89 -70
  180. package/dist/bundle/{services-BDQBRXT5.js → services-253KKKVU.js} +109 -89
  181. package/dist/bundle/{sqlite-runtime-ZSZGAUYB.js → sqlite-runtime-EZASGJXW.js} +9 -9
  182. package/dist/bundle/{start-BJ275RUK.js → start-UHI35JFL.js} +7 -7
  183. package/dist/bundle/{state-HLNGFI2T.js → state-KJTSPFGK.js} +9 -9
  184. package/dist/bundle/{store-I43KZNJW.js → store-62J2H2A3.js} +36 -25
  185. package/dist/bundle/{store-OSRTGYGI.js → store-G5B7T7M7.js} +38 -23
  186. package/dist/bundle/store-maintenance-command-C6T4YLVF.js +85 -0
  187. package/dist/bundle/surface-3OT64BHS.js +83 -0
  188. package/dist/bundle/tokens-EHYO6D2X.js +133 -0
  189. package/dist/commands/documents.d.ts.map +1 -1
  190. package/dist/commands/documents.js +11 -1
  191. package/dist/commands/documents.js.map +1 -1
  192. package/dist/commands/remote.d.ts.map +1 -1
  193. package/dist/commands/remote.js +8 -22
  194. package/dist/commands/remote.js.map +1 -1
  195. package/dist/commands/sync.d.ts.map +1 -1
  196. package/dist/commands/sync.js +14 -4
  197. package/dist/commands/sync.js.map +1 -1
  198. package/dist/config.d.ts +5 -0
  199. package/dist/config.d.ts.map +1 -1
  200. package/dist/config.js +7 -1
  201. package/dist/config.js.map +1 -1
  202. package/dist/first-screen.d.ts.map +1 -1
  203. package/dist/first-screen.js +2 -1
  204. package/dist/first-screen.js.map +1 -1
  205. package/dist/generated/manifest.d.ts +2 -1
  206. package/dist/generated/manifest.d.ts.map +1 -1
  207. package/dist/generated/manifest.js +782 -0
  208. package/dist/generated/manifest.js.map +1 -1
  209. package/dist/generated/types.d.ts +262 -58
  210. package/dist/generated/types.d.ts.map +1 -1
  211. package/dist/google.d.ts.map +1 -1
  212. package/dist/google.js +5 -5
  213. package/dist/google.js.map +1 -1
  214. package/dist/model.d.ts +5 -2
  215. package/dist/model.d.ts.map +1 -1
  216. package/dist/model.js.map +1 -1
  217. package/dist/policy-keys.js +1 -1
  218. package/dist/policy-keys.js.map +1 -1
  219. package/dist/program.d.ts.map +1 -1
  220. package/dist/program.js +9 -4
  221. package/dist/program.js.map +1 -1
  222. package/dist/state.d.ts.map +1 -1
  223. package/dist/state.js +6 -1
  224. package/dist/state.js.map +1 -1
  225. package/dist/store.d.ts.map +1 -1
  226. package/dist/store.js +2 -7
  227. package/dist/store.js.map +1 -1
  228. package/dist/supported.d.ts +2 -2
  229. package/dist/supported.d.ts.map +1 -1
  230. package/dist/supported.js +2 -3
  231. package/dist/supported.js.map +1 -1
  232. package/dist/sync.d.ts +2 -1
  233. package/dist/sync.d.ts.map +1 -1
  234. package/dist/sync.js +6 -4
  235. package/dist/sync.js.map +1 -1
  236. package/dist/transcripts.d.ts +0 -6
  237. package/dist/transcripts.d.ts.map +1 -1
  238. package/dist/transcripts.js +0 -13
  239. package/dist/transcripts.js.map +1 -1
  240. package/dist/version.d.ts +1 -1
  241. package/dist/version.js +1 -1
  242. package/package.json +3 -3
  243. package/scenarios/find-decision.md +1 -1
  244. package/skills/drive-cli/SKILL.md +4 -2
  245. package/dist/bundle/chunk-AV5UKJZM.js +0 -729
  246. package/dist/bundle/chunk-NP7LJATI.js +0 -598
  247. package/dist/bundle/chunk-P77FL6RY.js +0 -896
  248. package/dist/bundle/chunk-ZI3YTXSF.js +0 -2
  249. package/dist/bundle/command-contract-V3F452QI.js +0 -43
  250. package/dist/bundle/entry-ORZYRJ5N.js +0 -25
  251. package/dist/bundle/first-run-KAKA6KBY.js +0 -31
  252. package/dist/bundle/first-screen-R645UHRH.js +0 -41
  253. package/dist/bundle/google-BSO3YB7N.js +0 -45
  254. package/dist/bundle/grants-PLNFYARD.js +0 -118
  255. package/dist/bundle/mdast-util-gfm-SZM5GBDF.js +0 -2103
  256. package/dist/bundle/meeting-combined-SUKMFK3F.js +0 -27
  257. package/dist/bundle/meeting-model-S4YGKIFI.js +0 -29
  258. package/dist/bundle/oauth-KCMNQ3ZP.js +0 -22
  259. package/dist/bundle/remote-3SL2QJ7T.js +0 -35
  260. package/dist/bundle/server-BI46BSRE.js +0 -80
  261. package/dist/bundle/store-maintenance-command-FO7LEVSL.js +0 -72
  262. package/dist/bundle/tokens-DB7O7QNB.js +0 -118
@@ -1,18 +1,24 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ deadlineMargin
5
+ } from "./chunk-4JS32SRX.js";
3
6
  import {
4
7
  walkQuery
5
- } from "./chunk-Q5C6YKAY.js";
8
+ } from "./chunk-XQZEMRCU.js";
6
9
  import {
7
10
  writeSecurely
8
- } from "./chunk-HRATXUFH.js";
11
+ } from "./chunk-6CCO3JCM.js";
9
12
  import {
10
13
  array,
14
+ boolean,
11
15
  literal,
12
16
  looseObject,
13
17
  maxLength,
14
18
  minLength,
19
+ number,
15
20
  object,
21
+ optional,
16
22
  parse,
17
23
  picklist,
18
24
  pipe,
@@ -21,16 +27,16 @@ import {
21
27
  safeParse,
22
28
  string,
23
29
  trim
24
- } from "./chunk-HHAZ6DCY.js";
30
+ } from "./chunk-GXGSC622.js";
25
31
  import {
26
32
  CliError,
27
33
  isCliError
28
- } from "./chunk-54NDYVZA.js";
34
+ } from "./chunk-OLCU7Q2B.js";
29
35
  import {
30
36
  __name
31
37
  } from "./chunk-ZVVMGPBJ.js";
32
38
 
33
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/documents/blocks.js
39
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/documents/blocks.js
34
40
  var MARKS = ["bold", "italic", "strike", "code", "link"];
35
41
  var sameMarks = /* @__PURE__ */ __name((a, b) => MARKS.every((mark) => a[mark] === b[mark]), "sameMarks");
36
42
  var normalizeInlines = /* @__PURE__ */ __name((inlines) => {
@@ -78,7 +84,7 @@ var key = /* @__PURE__ */ __name((block, withChecked) => {
78
84
  var blockKey = /* @__PURE__ */ __name((block) => JSON.stringify(key(block, true)), "blockKey");
79
85
  var blockShape = /* @__PURE__ */ __name((block) => JSON.stringify(key(block, false)), "blockShape");
80
86
 
81
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/block-diff.js
87
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/block-diff.js
82
88
  var MAX_CELLS = 4e6;
83
89
  var matches = /* @__PURE__ */ __name((a, b, keyOf) => {
84
90
  const ka = a.map(keyOf);
@@ -120,7 +126,7 @@ var matches = /* @__PURE__ */ __name((a, b, keyOf) => {
120
126
  pairs.push([endA + offset, endB + offset]);
121
127
  return pairs;
122
128
  }, "matches");
123
- var diffBlocks = /* @__PURE__ */ __name((base, next, keyOf = blockKey) => {
129
+ var diffSequence = /* @__PURE__ */ __name((base, next, keyOf) => {
124
130
  const hunks = [];
125
131
  let a = 0;
126
132
  let b = 0;
@@ -131,7 +137,8 @@ var diffBlocks = /* @__PURE__ */ __name((base, next, keyOf = blockKey) => {
131
137
  b = j + 1;
132
138
  }
133
139
  return hunks;
134
- }, "diffBlocks");
140
+ }, "diffSequence");
141
+ var diffBlocks = /* @__PURE__ */ __name((base, next, keyOf = blockKey) => diffSequence(base, next, keyOf), "diffBlocks");
135
142
  var isCheck = /* @__PURE__ */ __name((block) => block?.kind === "item" && block.list === "check", "isCheck");
136
143
  var sameKeys = /* @__PURE__ */ __name((a, b) => a.length === b.length && a.every((block, index) => blockKey(block) === blockKey(b[index])), "sameKeys");
137
144
  var touches = /* @__PURE__ */ __name((a, b) => Math.max(a.from, b.from) < Math.min(a.to, b.to) || a.from === b.from || a.from === a.to && b.from < a.from && a.from < b.to || b.from === b.to && a.from < b.from && b.from < a.to, "touches");
@@ -144,7 +151,7 @@ var applied = /* @__PURE__ */ __name((base, from, to, hunks) => {
144
151
  }
145
152
  return out.concat(base.slice(at, to));
146
153
  }, "applied");
147
- var mergeBlocks = /* @__PURE__ */ __name((baseLocal, baseRemote, local, remote, keep) => {
154
+ var mergeBlocks = /* @__PURE__ */ __name((baseLocal, baseRemote, local, remote, keep, overlap = touches) => {
148
155
  if (baseLocal.length !== baseRemote.length || baseLocal.some((block, index) => blockShape(block) !== blockShape(baseRemote[index])))
149
156
  return { status: "unaligned" };
150
157
  const tagged = [
@@ -154,7 +161,7 @@ var mergeBlocks = /* @__PURE__ */ __name((baseLocal, baseRemote, local, remote,
154
161
  const clusters = [];
155
162
  for (const hunk of tagged) {
156
163
  const last = clusters.at(-1);
157
- if (last?.some((other) => touches(other, hunk)))
164
+ if (last?.some((other) => overlap(other, hunk)))
158
165
  last.push(hunk);
159
166
  else
160
167
  clusters.push([hunk]);
@@ -224,7 +231,7 @@ var mergeBlocks = /* @__PURE__ */ __name((baseLocal, baseRemote, local, remote,
224
231
  return { status: "clean", blocks, conflicts };
225
232
  }, "mergeBlocks");
226
233
 
227
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/extraction.js
234
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/extraction.js
228
235
  var Proposal = object({
229
236
  kind: picklist(["summary", "digest", "fact", "preference"]),
230
237
  body: pipe(string(), trim(), minLength(1), maxLength(15e3)),
@@ -259,7 +266,7 @@ var extractMemories = /* @__PURE__ */ __name(async (text, complete) => {
259
266
  return { ...proposals, provider: answer.provider, model: answer.model, tokens: answer.tokens };
260
267
  }, "extractMemories");
261
268
 
262
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/ingestion.js
269
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/ingestion.js
263
270
  var documentIngestion = /* @__PURE__ */ __name((store, options) => {
264
271
  const folder = /* @__PURE__ */ __name(async (principal, create) => {
265
272
  if (options.provider)
@@ -270,6 +277,7 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
270
277
  const found = (await store.notes.folders()).find((item) => item.name === name);
271
278
  return found ?? (create ? await store.notes.addFolder({ name, format: "markdown" }) : void 0);
272
279
  }, "folder");
280
+ const both = /* @__PURE__ */ __name((id) => [.../* @__PURE__ */ new Set([options.externalId(id), id])], "both");
273
281
  const stale = /* @__PURE__ */ __name(async (ref) => {
274
282
  for (const status of ["proposed", "confirmed"]) {
275
283
  for (let batch = 0; ; batch++) {
@@ -283,7 +291,16 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
283
291
  }
284
292
  }
285
293
  }, "stale");
294
+ const { provider, command } = options;
286
295
  return {
296
+ // Only where both are known: a sync calls it whenever it is there and a profile is given.
297
+ ...provider && command ? {
298
+ /** Names the profile's account in the store, so a search hit says `notion`/`work`, not `notes`/`1`. */
299
+ registerProfile: /* @__PURE__ */ __name(async (name, principal) => {
300
+ await folder(principal, true);
301
+ await store.accounts.saveProfile(command, name, { provider, account: principal });
302
+ }, "registerProfile")
303
+ } : {},
287
304
  catalog: {
288
305
  import: /* @__PURE__ */ __name(async (principal, files) => {
289
306
  const selected = await folder(principal, true);
@@ -304,7 +321,10 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
304
321
  }, "import"),
305
322
  get: /* @__PURE__ */ __name(async (principal, id) => {
306
323
  const selected = await folder(principal, false);
307
- return selected ? store.catalog.get(selected.id, options.externalId(id)) : void 0;
324
+ if (!selected)
325
+ return void 0;
326
+ const entry = await store.catalog.get(selected.id, options.externalId(id));
327
+ return entry ?? (options.externalId(id) === id ? void 0 : store.catalog.get(selected.id, id));
308
328
  }, "get"),
309
329
  list: /* @__PURE__ */ __name(async (principal, query = {}) => {
310
330
  const selected = await folder(principal, false);
@@ -317,11 +337,13 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
317
337
  return selected ? store.catalog.list(selected.id, {
318
338
  ...query,
319
339
  ...ast ? { ast } : {},
320
- ...query.parent === void 0 ? {} : { parent: options.externalId(query.parent) }
340
+ ...query.parent === void 0 ? {} : { parent: [query.parent].flat().flatMap(both) }
321
341
  }) : { items: [], hasMore: false };
322
342
  }, "list")
323
343
  },
324
344
  collection: folder,
345
+ // A store fake that predates `indexWritten` leaves the text for the next search to index.
346
+ settle: /* @__PURE__ */ __name(async ({ until }) => store.notes.indexWritten?.({ until }), "settle"),
325
347
  save: /* @__PURE__ */ __name(async (principal, content, hash) => {
326
348
  const selected = await folder(principal, true);
327
349
  if (!selected)
@@ -342,7 +364,7 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
342
364
  await options.observed?.(principal, content.metadata, note.id);
343
365
  return note.ref;
344
366
  }, "save"),
345
- remove: /* @__PURE__ */ __name(async (principal, id) => {
367
+ remove: /* @__PURE__ */ __name(async (principal, id, reason) => {
346
368
  const selected = await folder(principal, false);
347
369
  if (selected) {
348
370
  const path = options.externalId(id);
@@ -351,13 +373,40 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
351
373
  const ref = note?.ref ?? retired?.ref;
352
374
  if (ref)
353
375
  await stale(ref);
354
- await store.notes.deleteFileNotes(selected.id, [path]);
376
+ await store.notes.deleteFileNotes(selected.id, [path], reason);
355
377
  }
356
- }, "remove")
378
+ }, "remove"),
379
+ prune: /* @__PURE__ */ __name(async (principal, before) => {
380
+ const selected = await folder(principal, false);
381
+ return selected ? store.notes.pruneDocumentHistory?.(selected.id, before) : void 0;
382
+ }, "prune"),
383
+ /** The profile's local history: earlier versions of a document and what changed when. */
384
+ history: {
385
+ /** `id` is the source's id, or a `document:<n>` ref; a removed document is found too. */
386
+ reference: /* @__PURE__ */ __name(async (principal, id) => {
387
+ if (/^document:\d+$/.test(id))
388
+ return id;
389
+ const selected = await folder(principal, false);
390
+ if (!selected)
391
+ return void 0;
392
+ for (const path of both(id)) {
393
+ const found = await store.notes.documentAt(selected.id, path);
394
+ if (found)
395
+ return found;
396
+ }
397
+ return void 0;
398
+ }, "reference"),
399
+ versions: /* @__PURE__ */ __name((reference) => store.notes.documentHistory(reference), "versions"),
400
+ version: /* @__PURE__ */ __name((reference, revision) => store.notes.documentVersion(reference, revision), "version"),
401
+ changes: /* @__PURE__ */ __name(async (principal, query) => {
402
+ const selected = await folder(principal, false);
403
+ return selected ? store.notes.documentChanges(selected.id, query) : { items: [], hasMore: false };
404
+ }, "changes")
405
+ }
357
406
  };
358
407
  }, "documentIngestion");
359
408
 
360
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/knowledge.js
409
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/knowledge.js
361
410
  var writer = /* @__PURE__ */ __name((by) => {
362
411
  if (by === void 0)
363
412
  throw new CliError("validation_error", "name who writes it: the owner or an agent; there is no default", {
@@ -385,7 +434,7 @@ var documentKnowledge = /* @__PURE__ */ __name((store, folder) => {
385
434
  const noteFor = /* @__PURE__ */ __name(async (principal, ref, noteRef) => {
386
435
  await document(principal, ref);
387
436
  const note = await store.notes.resolveNote(noteRef);
388
- const linked = (await store.notes.links({ from: noteRef })).some((link) => link.to === ref && link.kind === "about");
437
+ const linked = (await store.notes.links({ from: noteRef })).some((link2) => link2.to === ref && link2.kind === "about");
389
438
  if (note?.source !== "internal" || note.deletedAt)
390
439
  throw new CliError("not_found", "note is not attached to this document");
391
440
  if (linked)
@@ -434,11 +483,23 @@ var documentKnowledge = /* @__PURE__ */ __name((store, folder) => {
434
483
  }, "links"),
435
484
  addLink: /* @__PURE__ */ __name(async (principal, ref, input) => {
436
485
  await document(principal, ref);
437
- return store.notes.addLink({ ...input, from: ref, origin: input.by === "owner" ? "owner" : "suggested" });
486
+ const by = writer(input.by);
487
+ const link2 = await store.notes.addLink({
488
+ ...input,
489
+ from: ref,
490
+ ...by === "owner" ? { origin: "owner" } : { origin: "suggested", confirmed: false, provenance: `agent:${by.bot}: ${by.reason.trim()}` }
491
+ });
492
+ if (by !== "owner" || link2.confirmed)
493
+ return link2;
494
+ return await store.knowledge.decideSuggestedLink(link2.id, { confirm: true, by }) ?? link2;
438
495
  }, "addLink"),
439
496
  removeLink: /* @__PURE__ */ __name(async (principal, ref, id, by) => {
440
- const links = await port.links(principal, ref);
441
- if (!links.some((link) => link.id === id && link.origin === "owner"))
497
+ const link2 = (await port.links(principal, ref)).find((item) => item.id === id);
498
+ if (link2 && !link2.confirmed) {
499
+ await store.knowledge.decideSuggestedLink(id, { confirm: false, by });
500
+ return { id, removed: true };
501
+ }
502
+ if (link2?.origin !== "owner")
442
503
  throw new CliError("not_found", "owner link is not attached to this document");
443
504
  return store.notes.removeLink(id, by);
444
505
  }, "removeLink"),
@@ -512,12 +573,12 @@ var documentKnowledge = /* @__PURE__ */ __name((store, folder) => {
512
573
  return port;
513
574
  }, "documentKnowledge");
514
575
 
515
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/documents/markdown-blocks.js
576
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/documents/markdown-blocks.js
516
577
  var parser;
517
578
  var loadParser = /* @__PURE__ */ __name(() => parser ??= Promise.all([
518
- import("./mdast-util-from-markdown-FXEPSNER.js"),
519
- import("./mdast-util-gfm-SZM5GBDF.js"),
520
- import("./micromark-extension-gfm-GRL24TU6.js")
579
+ import("./mdast-util-from-markdown-HEZF7KJ4.js"),
580
+ import("./mdast-util-gfm-AQW6R6MG.js"),
581
+ import("./micromark-extension-gfm-OE2GBORZ.js")
521
582
  ]).then(([{ fromMarkdown }, { gfmFromMarkdown }, { gfm }]) => (markdown) => fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] })), "loadParser");
522
583
  var markdownBlocks = /* @__PURE__ */ __name(async (markdown) => (await placedMarkdownBlocks(markdown)).map((placed) => placed.block), "markdownBlocks");
523
584
  var FRONT_MATTER = /^---[ \t]*\r?\n(?:[^\n]*\n)*?---[ \t]*(?=\r?\n|$)/;
@@ -637,7 +698,7 @@ var placedMarkdownBlocks = /* @__PURE__ */ __name(async (markdown) => {
637
698
  return blocks(tree.children);
638
699
  }, "placedMarkdownBlocks");
639
700
 
640
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/markdown-splice.js
701
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/markdown-splice.js
641
702
  var escapeText = /* @__PURE__ */ __name((text) => text.replace(/[\\`*_[\]<>~|]/g, "\\$&"), "escapeText");
642
703
  var codeSpan = /* @__PURE__ */ __name((text) => {
643
704
  const longest = (text.match(/`+/g) ?? []).reduce((most, run) => Math.max(most, run.length), 0);
@@ -664,11 +725,11 @@ var inlineMarkdown = /* @__PURE__ */ __name((inlines, indent = "") => {
664
725
  const runs = normalizeInlines(inlines);
665
726
  let out = "";
666
727
  for (let at = 0; at < runs.length; ) {
667
- const link = runs[at]?.link;
728
+ const link2 = runs[at]?.link;
668
729
  let body = "";
669
- for (; at < runs.length && runs[at]?.link === link; at++)
730
+ for (; at < runs.length && runs[at]?.link === link2; at++)
670
731
  body += styled({ ...runs[at], link: void 0 });
671
- out += link ? `[${body}](${linkTarget(link)})` : body;
732
+ out += link2 ? `[${body}](${linkTarget(link2)})` : body;
672
733
  }
673
734
  return out.replace(/^(#{1,6}\s|[-+*>]\s|[=-]+\s*$)/, "\\$1").replace(/^(\d{1,9})([.)]\s)/, "$1\\$2").replaceAll("\n", `\\
674
735
  ${indent}`);
@@ -823,49 +884,118 @@ var columnsBefore = /* @__PURE__ */ __name((placed, index) => {
823
884
  return columns;
824
885
  }, "columnsBefore");
825
886
 
826
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
887
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
827
888
  import { watch } from "node:fs";
828
889
 
829
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
890
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
830
891
  import { createHash as createHash2 } from "node:crypto";
831
892
  import { mkdirSync, readFileSync } from "node:fs";
832
- import { join as join2 } from "node:path";
893
+ import { dirname as dirname2, join as join2 } from "node:path";
833
894
 
834
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/push.js
895
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/push.js
835
896
  import { createHash, randomUUID } from "node:crypto";
836
- import { createReadStream } from "node:fs";
837
- import { chmod, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
897
+ import { createReadStream, createWriteStream } from "node:fs";
898
+ import { chmod, link, lstat, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
838
899
  import { basename, dirname, join, posix } from "node:path";
900
+ import { pipeline } from "node:stream/promises";
839
901
  var SKIPPED = /^(\.|node_modules$|~\$)|(~|\.swp|\.tmp)$/;
840
902
  var skippedName = /* @__PURE__ */ __name((name) => SKIPPED.test(name), "skippedName");
841
903
  var hashFile = /* @__PURE__ */ __name((path) => new Promise((done, fail) => {
842
- const hash = createHash("sha256");
843
- createReadStream(path).on("data", (chunk) => hash.update(chunk)).on("error", fail).on("end", () => done(hash.digest("hex")));
904
+ const sha256 = createHash("sha256");
905
+ const md5 = createHash("md5");
906
+ createReadStream(path).on("data", (chunk) => {
907
+ sha256.update(chunk);
908
+ md5.update(chunk);
909
+ }).on("error", fail).on("end", () => done({ sha256: sha256.digest("hex"), md5: md5.digest("hex") }));
844
910
  }), "hashFile");
845
- var hashText = /* @__PURE__ */ __name((text) => createHash("sha256").update(text).digest("hex"), "hashText");
846
- var replaceLocal = /* @__PURE__ */ __name(async (file, content) => {
847
- const temp = join(dirname(file.absolute), `.${basename(file.absolute)}.${randomUUID().slice(0, 8)}.tmp`);
848
- const { mode } = await stat(file.absolute);
849
- await writeFile(temp, content, { flag: "wx" });
911
+ var placeNew = /* @__PURE__ */ __name(async (from, to) => {
850
912
  try {
851
- await chmod(temp, mode & 511);
852
- if (await hashFile(file.absolute) !== file.hash)
913
+ await link(from, to);
914
+ return;
915
+ } catch (error) {
916
+ if (!["EPERM", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "ENOSYS"].includes(error.code ?? ""))
917
+ throw error;
918
+ }
919
+ const { mode } = await stat(from);
920
+ let created = false;
921
+ const into = createWriteStream(to, { flags: "wx" }).once("open", () => {
922
+ created = true;
923
+ });
924
+ try {
925
+ await pipeline(createReadStream(from), into);
926
+ await chmod(to, mode & 511);
927
+ } catch (error) {
928
+ if (created)
929
+ await rm(to, { force: true });
930
+ throw error;
931
+ }
932
+ }, "placeNew");
933
+ var assertNoLink = /* @__PURE__ */ __name(async (root, path) => {
934
+ let at = root;
935
+ for (const part of path.split("/")) {
936
+ at = join(at, part);
937
+ try {
938
+ if ((await lstat(at)).isSymbolicLink())
939
+ throw new CliError("validation_error", `${path} is under a symbolic link; the sync does not follow links`, {
940
+ reason: "mirror.symlink"
941
+ });
942
+ } catch (error) {
943
+ if (error.code === "ENOENT")
944
+ return;
945
+ throw error;
946
+ }
947
+ }
948
+ }, "assertNoLink");
949
+ var localTemp = /* @__PURE__ */ __name((absolute, tag) => join(dirname(absolute), `.${basename(absolute)}.${tag}.tmp`), "localTemp");
950
+ var replaceLocal = /* @__PURE__ */ __name(async (absolute, hash, content, { tag = randomUUID().slice(0, 8), sha256 } = {}) => {
951
+ const temp = localTemp(absolute, tag);
952
+ const mode = hash === void 0 ? void 0 : (await stat(absolute)).mode;
953
+ try {
954
+ if (typeof content === "function")
955
+ await content(temp);
956
+ else
957
+ await writeFile(temp, content, { flag: "wx" });
958
+ if (mode !== void 0)
959
+ await chmod(temp, mode & 511);
960
+ const written = await hashFile(temp);
961
+ if (sha256 !== void 0 && written.sha256 !== sha256)
962
+ throw new CliError("invalid_response", "the downloaded file has other content than the listing said", {
963
+ reason: "download.mismatch"
964
+ });
965
+ if (hash === void 0) {
966
+ try {
967
+ await placeNew(temp, absolute);
968
+ } catch (error) {
969
+ if (error.code === "EEXIST")
970
+ return void 0;
971
+ throw error;
972
+ }
973
+ return written;
974
+ }
975
+ if ((await hashFile(absolute)).sha256 !== hash)
853
976
  return void 0;
854
- await rename(temp, file.absolute);
977
+ await rename(temp, absolute);
978
+ return written;
855
979
  } finally {
856
980
  await rm(temp, { force: true });
857
981
  }
858
- return hashText(content);
859
982
  }, "replaceLocal");
860
- var scanLocal = /* @__PURE__ */ __name(async (root, kindOf, maxFiles = 1e4) => {
983
+ var scanLocal = /* @__PURE__ */ __name(async (root, kindOf, maxFiles = 1e4, known, skip) => {
861
984
  const files = [];
985
+ const links = [];
862
986
  let unsupported = 0;
863
987
  const walk = /* @__PURE__ */ __name(async (relative) => {
864
988
  const entries = await readdir(join(root, relative), { withFileTypes: true });
865
989
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
866
- if (SKIPPED.test(entry.name) || entry.isSymbolicLink())
990
+ if (SKIPPED.test(entry.name))
867
991
  continue;
868
992
  const path = relative ? posix.join(relative, entry.name) : entry.name;
993
+ if (skip?.(path))
994
+ continue;
995
+ if (entry.isSymbolicLink()) {
996
+ links.push(path);
997
+ continue;
998
+ }
869
999
  if (entry.isDirectory())
870
1000
  await walk(path);
871
1001
  else if (entry.isFile()) {
@@ -879,7 +1009,10 @@ var scanLocal = /* @__PURE__ */ __name(async (root, kindOf, maxFiles = 1e4) => {
879
1009
  reason: "push.too-many-files"
880
1010
  });
881
1011
  const absolute = join(root, path);
882
- files.push({ path, absolute, kind, hash: await hashFile(absolute) });
1012
+ const { size, mtimeMs } = await stat(absolute);
1013
+ const before = known?.(path);
1014
+ const hash = before && before.size === size && before.mtimeMs === mtimeMs ? before.hash : (await hashFile(absolute)).sha256;
1015
+ files.push({ path, absolute, kind, hash, size, mtimeMs });
883
1016
  }
884
1017
  }
885
1018
  }, "walk");
@@ -890,7 +1023,7 @@ var scanLocal = /* @__PURE__ */ __name(async (root, kindOf, maxFiles = 1e4) => {
890
1023
  throw error;
891
1024
  throw new CliError("validation_error", "the folder to push could not be read", { reason: "push.unreadable" });
892
1025
  }
893
- return { files, unsupported };
1026
+ return { files, unsupported, links };
894
1027
  }, "scanLocal");
895
1028
  var planPush = /* @__PURE__ */ __name((files, state) => {
896
1029
  const plan = { create: [], update: [], unchanged: [], orphans: [] };
@@ -1044,12 +1177,13 @@ var pushDocuments = /* @__PURE__ */ __name(async (options) => {
1044
1177
  } else {
1045
1178
  if (prepared.local !== void 0) {
1046
1179
  options.assertHeld();
1047
- const written = await replaceLocal(file, prepared.local);
1180
+ await assertNoLink(root, file.path);
1181
+ const written = await replaceLocal(file.absolute, file.hash, prepared.local);
1048
1182
  if (!written) {
1049
1183
  result.conflicts.push({ path: file.path, url: entry.url, reason: "the local file changed during the sync" });
1050
1184
  continue;
1051
1185
  }
1052
- hash = written;
1186
+ hash = written.sha256;
1053
1187
  result.pulled.push(file.path);
1054
1188
  if (prepared.remote && prepared.afterLocal !== void 0) {
1055
1189
  state.entries[file.path] = { ...entry, snapshot: prepared.afterLocal, hash };
@@ -1083,7 +1217,7 @@ var pushDocuments = /* @__PURE__ */ __name(async (options) => {
1083
1217
  return result;
1084
1218
  }, "pushDocuments");
1085
1219
 
1086
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
1220
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
1087
1221
  var mirrorId = /* @__PURE__ */ __name((root, folder) => createHash2("sha256").update(JSON.stringify([root, folder])).digest("hex").slice(0, 8), "mirrorId");
1088
1222
  var ID = pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/));
1089
1223
  var stateSchema = /* @__PURE__ */ __name((kinds) => object({
@@ -1103,43 +1237,40 @@ var stateSchema = /* @__PURE__ */ __name((kinds) => object({
1103
1237
  })),
1104
1238
  pending: record(string(), object({ origin: string(), operationId: string() }))
1105
1239
  }), "stateSchema");
1106
- var fileMirrorState = /* @__PURE__ */ __name((dir, mirror, principal, kinds) => {
1107
- const path = join2(dir, `${mirror.id}.json`);
1108
- const schema = stateSchema(kinds);
1109
- return {
1110
- read: /* @__PURE__ */ __name(() => {
1111
- let value;
1112
- try {
1113
- value = JSON.parse(readFileSync(path, "utf8"));
1114
- } catch (error) {
1115
- if (error.code === "ENOENT")
1116
- return {
1117
- version: 1,
1118
- principal,
1119
- root: mirror.path,
1120
- target: mirror.folder,
1121
- folders: {},
1122
- entries: {},
1123
- pending: {}
1124
- };
1125
- throw new CliError("configuration_error", "mirror state is unreadable; refusing to reset it", {
1126
- reason: "state.invalid"
1127
- });
1128
- }
1129
- const parsed = safeParse(schema, value);
1130
- if (!parsed.success)
1131
- throw new CliError("configuration_error", "mirror state is invalid; refusing to reset it", {
1132
- reason: "state.invalid"
1133
- });
1134
- return parsed.output;
1135
- }, "read"),
1136
- save: /* @__PURE__ */ __name((state) => {
1137
- mkdirSync(dir, { recursive: true, mode: 448 });
1138
- writeSecurely(path, `${JSON.stringify(state)}
1240
+ var jsonState = /* @__PURE__ */ __name((path, schema, initial) => ({
1241
+ read: /* @__PURE__ */ __name(() => {
1242
+ let value;
1243
+ try {
1244
+ value = JSON.parse(readFileSync(path, "utf8"));
1245
+ } catch (error) {
1246
+ if (error.code === "ENOENT")
1247
+ return initial();
1248
+ throw new CliError("configuration_error", "mirror state is unreadable; refusing to reset it", {
1249
+ reason: "state.invalid"
1250
+ });
1251
+ }
1252
+ const parsed = safeParse(schema, value);
1253
+ if (!parsed.success)
1254
+ throw new CliError("configuration_error", "mirror state is invalid; refusing to reset it", {
1255
+ reason: "state.invalid"
1256
+ });
1257
+ return parsed.output;
1258
+ }, "read"),
1259
+ save: /* @__PURE__ */ __name((state) => {
1260
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
1261
+ writeSecurely(path, `${JSON.stringify(state)}
1139
1262
  `, 384);
1140
- }, "save")
1141
- };
1142
- }, "fileMirrorState");
1263
+ }, "save")
1264
+ }), "jsonState");
1265
+ var fileMirrorState = /* @__PURE__ */ __name((dir, mirror, principal, kinds) => jsonState(join2(dir, `${mirror.id}.json`), stateSchema(kinds), () => ({
1266
+ version: 1,
1267
+ principal,
1268
+ root: mirror.path,
1269
+ target: mirror.folder,
1270
+ folders: {},
1271
+ entries: {},
1272
+ pending: {}
1273
+ })), "fileMirrorState");
1143
1274
  var mirrorStatus = /* @__PURE__ */ __name(async (mirrors, kindOf, stateOf) => {
1144
1275
  const items = [];
1145
1276
  for (const mirror of mirrors) {
@@ -1161,41 +1292,25 @@ var mirrorStatus = /* @__PURE__ */ __name(async (mirrors, kindOf, stateOf) => {
1161
1292
  }, "mirrorStatus");
1162
1293
  var conflictReport = /* @__PURE__ */ __name((conflict, remote) => ({
1163
1294
  path: conflict.path,
1164
- url: conflict.url,
1295
+ ...conflict.url ? { url: conflict.url } : {},
1165
1296
  reason: conflict.reason,
1166
1297
  ...conflict.parts ? { parts: conflict.parts.map((part) => ({ last_sync: part.base, local: part.local, [remote]: part.remote })) } : {},
1167
1298
  ...conflict.localChangedAt ? { local_changed_at: conflict.localChangedAt } : {},
1168
1299
  ...conflict.remoteChangedAt ? { [`${remote}_changed_at`]: conflict.remoteChangedAt } : {},
1169
- ...conflict.remoteChangedBy ? { [`${remote}_changed_by`]: conflict.remoteChangedBy } : {}
1300
+ ...conflict.remoteChangedBy ? { [`${remote}_changed_by`]: conflict.remoteChangedBy } : {},
1301
+ ...conflict.localSize !== void 0 ? { local_size: conflict.localSize } : {},
1302
+ ...conflict.remoteSize !== void 0 ? { [`${remote}_size`]: conflict.remoteSize } : {}
1170
1303
  }), "conflictReport");
1171
- var syncMirrors = /* @__PURE__ */ __name(async (options) => {
1172
- const { mirrors, keep, remote } = options;
1173
- const lock = await options.lock();
1304
+ var eachMirror = /* @__PURE__ */ __name(async (mirrors, lock, remote, sync) => {
1305
+ const held = await lock();
1174
1306
  const results = [];
1175
1307
  try {
1176
1308
  for (const mirror of mirrors)
1177
- results.push({
1178
- id: mirror.id,
1179
- path: mirror.path,
1180
- ...await pushDocuments({
1181
- root: mirror.path,
1182
- folder: mirror.folder,
1183
- target: options.target,
1184
- state: options.stateOf(mirror),
1185
- principal: options.principal,
1186
- ...keep ? { keep } : {},
1187
- recreate: options.recreate === true,
1188
- guard: options.guard,
1189
- operationId: options.operationId,
1190
- errorOf: options.errorOf,
1191
- assertHeld: /* @__PURE__ */ __name(() => lock.assertHeld(), "assertHeld"),
1192
- ...options.signal ? { signal: options.signal } : {}
1193
- })
1194
- });
1309
+ results.push({ id: mirror.id, path: mirror.path, ...await sync(mirror, held) });
1195
1310
  } finally {
1196
- await lock.release();
1311
+ await held.release();
1197
1312
  }
1198
- const issues = results.filter((result) => result.errors.length || result.conflicts.length || result.missing.length).map((result) => ({ code: "provider_error", reason: "mirror.partial", source: `mirror ${result.id}` }));
1313
+ const issues = results.filter((result) => result.errors.length || result.conflicts.length || result.missing?.length || result.unknown?.length).map((result) => ({ code: "provider_error", reason: "mirror.partial", source: `mirror ${result.id}` }));
1199
1314
  return {
1200
1315
  items: results.map(({ conflicts, ...result }) => ({
1201
1316
  ...result,
@@ -1203,9 +1318,23 @@ var syncMirrors = /* @__PURE__ */ __name(async (options) => {
1203
1318
  })),
1204
1319
  issues
1205
1320
  };
1206
- }, "syncMirrors");
1321
+ }, "eachMirror");
1322
+ var syncMirrors = /* @__PURE__ */ __name((options) => eachMirror(options.mirrors, options.lock, options.remote, (mirror, held) => pushDocuments({
1323
+ root: mirror.path,
1324
+ folder: mirror.folder,
1325
+ target: options.target,
1326
+ state: options.stateOf(mirror),
1327
+ principal: options.principal,
1328
+ ...options.keep ? { keep: options.keep } : {},
1329
+ recreate: options.recreate === true,
1330
+ guard: options.guard,
1331
+ operationId: options.operationId,
1332
+ errorOf: options.errorOf,
1333
+ assertHeld: /* @__PURE__ */ __name(() => held.assertHeld(), "assertHeld"),
1334
+ ...options.signal ? { signal: options.signal } : {}
1335
+ })), "syncMirrors");
1207
1336
 
1208
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
1337
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
1209
1338
  var sleep = /* @__PURE__ */ __name((milliseconds, signal) => new Promise((resolve) => {
1210
1339
  const finish = /* @__PURE__ */ __name(() => {
1211
1340
  clearTimeout(timer);
@@ -1248,6 +1377,8 @@ async function* watchMirrors(sync, options) {
1248
1377
  const differs = /* @__PURE__ */ __name(async (ids) => {
1249
1378
  const chosen = [...ids].flatMap((id) => byId.get(id) ?? []);
1250
1379
  try {
1380
+ if ("localChanges" in options)
1381
+ return await options.localChanges(chosen);
1251
1382
  const items = await mirrorStatus(chosen, options.kindOf, options.stateOf);
1252
1383
  return items.filter((item) => item.create.length || item.update.length).map((item) => item.id);
1253
1384
  } catch {
@@ -1344,7 +1475,7 @@ async function* watchMirrors(sync, options) {
1344
1475
  }
1345
1476
  __name(watchMirrors, "watchMirrors");
1346
1477
 
1347
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/proposals.js
1478
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/proposals.js
1348
1479
  var extractDocumentMemories = /* @__PURE__ */ __name(async (options) => {
1349
1480
  const source = options.read();
1350
1481
  const text = options.tab ? source.snapshot.tabs.find((tab) => tab.id === options.tab)?.text : source.snapshot.text;
@@ -1394,11 +1525,11 @@ Snapshot: ${source.hash}`;
1394
1525
  };
1395
1526
  }, "extractDocumentMemories");
1396
1527
 
1397
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1528
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1398
1529
  import { createHash as createHash4 } from "node:crypto";
1399
1530
 
1400
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/documents/scope.js
1401
- var within = /* @__PURE__ */ __name((file, roots, folders, seen = /* @__PURE__ */ new Set()) => {
1531
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/documents/scope.js
1532
+ var within = /* @__PURE__ */ __name((file, roots, folders, seen = /* @__PURE__ */ new Set(), cut) => {
1402
1533
  if (file.trashed)
1403
1534
  return false;
1404
1535
  if (roots.includes(file.id))
@@ -1408,18 +1539,21 @@ var within = /* @__PURE__ */ __name((file, roots, folders, seen = /* @__PURE__ *
1408
1539
  const next = /* @__PURE__ */ new Set([...seen, file.id]);
1409
1540
  return file.parents.some((id) => {
1410
1541
  const folder = folders[id];
1411
- return folder ? within(folder, roots, folders, next) : roots.includes(id);
1542
+ if (!folder)
1543
+ return roots.includes(id);
1544
+ return (roots.includes(id) || !cut?.(folder)) && within(folder, roots, folders, next, cut);
1412
1545
  });
1413
1546
  }, "within");
1414
1547
  var inScope = /* @__PURE__ */ __name((file, roots, folders, matched = /* @__PURE__ */ new Set(), query) => {
1415
1548
  if (file.trashed)
1416
1549
  return false;
1417
- if (query?.mode === "exclude" && query.matches(file))
1550
+ const excluded = query?.mode === "exclude" ? query.matches : void 0;
1551
+ if (excluded?.(file))
1418
1552
  return false;
1419
- return matched.has(file.id) || within(file, roots, folders);
1553
+ return matched.has(file.id) || within(file, roots, folders, /* @__PURE__ */ new Set(), excluded);
1420
1554
  }, "inScope");
1421
1555
 
1422
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/documents/catalog.js
1556
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/documents/catalog.js
1423
1557
  var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1424
1558
  const folders = state.pending?.folders ?? state.folders;
1425
1559
  const matched = new Set(state.pending?.matched ?? state.matched ?? []);
@@ -1438,133 +1572,112 @@ var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1438
1572
  return [...files.values()].filter((file) => inScope(file, roots, folders, matched, query));
1439
1573
  }, "catalogFiles");
1440
1574
 
1441
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/plan.js
1575
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/plan.js
1442
1576
  import { createHash as createHash3 } from "node:crypto";
1577
+
1578
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/documents/model.js
1579
+ var feedOf = /* @__PURE__ */ __name((source) => "changes" in source && typeof source.changes === "function" ? source : void 0, "feedOf");
1580
+
1581
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/plan.js
1443
1582
  var scopeHash = /* @__PURE__ */ __name((roots, query, pages = false) => createHash3("sha256").update(JSON.stringify(query || pages ? [[...roots].sort(), query?.mode, query?.key, ...pages ? ["pages"] : []] : [...roots].sort())).digest("hex"), "scopeHash");
1444
1583
  var changedSince = /* @__PURE__ */ __name((previous, file) => previous.version !== file.version || previous.modifiedAt !== file.modifiedAt || previous.name !== file.name || previous.canDownload !== file.canDownload || JSON.stringify(previous.parents) !== JSON.stringify(file.parents), "changedSince");
1445
1584
  var SAVE_EVERY_MS = 2e3;
1446
- var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots, limit, pictures, abandoned = [], walks) => {
1447
- const { isFolder, skipReason, retryable, maxEntries: MAX_ENTRIES, errorOf, query } = options;
1448
- const tooManyEntries = /* @__PURE__ */ __name(() => options.limitError?.() ?? new CliError("validation_error", `selected folders exceed the ${MAX_ENTRIES} entry limit`), "tooManyEntries");
1585
+ var REREAD_BATCH = 50;
1586
+ var WALKED = "walked";
1587
+ var changesScope = /* @__PURE__ */ __name((scope, cursor) => `${scope}:changes:${cursor}`, "changesScope");
1588
+ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots, limit, pictures, walks) => {
1589
+ const { isFolder, skipReason, retryable, maxEntries, errorOf, query, budget } = options;
1590
+ const answers = /* @__PURE__ */ new Map();
1591
+ const cut = query?.mode === "exclude" ? (file) => {
1592
+ const known = answers.get(file.id);
1593
+ if (known !== void 0)
1594
+ return known;
1595
+ const found2 = query.matches(file);
1596
+ answers.set(file.id, found2);
1597
+ return found2;
1598
+ } : void 0;
1599
+ const scoped = cut && query ? { ...query, matches: cut } : query;
1600
+ const excluded = /* @__PURE__ */ __name((folder) => !roots.includes(folder.id) && cut?.(folder) === true, "excluded");
1449
1601
  const scope = scopeHash(roots, query, options.isDocument !== void 0);
1450
1602
  if (!roots.length && query?.mode !== "include")
1451
1603
  return {
1452
- scope,
1453
- cursor: state.cursor ?? "",
1454
- folders: {},
1455
- skipped: [],
1456
- jobs: [.../* @__PURE__ */ new Set([...Object.keys(state.documents), ...abandoned])].map((id) => ({ id, kind: "remove" }))
1604
+ pending: {
1605
+ scope,
1606
+ cursor: state.cursor ?? "",
1607
+ folders: {},
1608
+ skipped: [],
1609
+ jobs: Object.keys(state.documents).map((id) => ({ id, kind: "remove", reason: "unsynced" }))
1610
+ }
1457
1611
  };
1458
1612
  if (!source)
1459
1613
  throw new CliError("configuration_error", "selected folders or a saved query require an authenticated source");
1460
1614
  if (query?.mode === "include" && !query.list)
1461
1615
  throw new CliError("configuration_error", "a query that includes files must list them");
1462
- const found = query?.mode === "include" && query.list ? await query.list() : [];
1463
1616
  const initial = !state.cursor || scope !== state.scope;
1464
- const resumed = initial ? walks?.read(scope) : void 0;
1465
- const cursor = initial ? resumed?.cursor ?? await source.startToken() : state.cursor;
1466
- const folders = initial ? {} : structuredClone(state.folders);
1617
+ const feed = feedOf(source);
1618
+ const full = initial || !feed;
1619
+ const resumed = walks?.read(full ? scope : changesScope(scope, state.cursor));
1620
+ const folders = full ? {} : structuredClone(state.folders);
1467
1621
  const files = new Map(Object.values(state.documents).map((doc) => [doc.metadata.id, doc.metadata]));
1468
1622
  const changed = /* @__PURE__ */ new Set();
1623
+ const delta = /* @__PURE__ */ new Map();
1469
1624
  for (const skipped2 of state.skipped)
1470
1625
  if (skipped2.file)
1471
1626
  files.set(skipped2.id, skipped2.file);
1627
+ if (full)
1628
+ files.clear();
1629
+ const prior = /* @__PURE__ */ __name((id) => state.documents[id]?.metadata ?? state.skipped.find((item) => item.id === id)?.file, "prior");
1630
+ const moved = /* @__PURE__ */ __name((before, file) => JSON.stringify(before.providerMetadata ?? null) !== JSON.stringify(file.providerMetadata ?? null), "moved");
1472
1631
  const keep = /* @__PURE__ */ __name((file) => {
1473
1632
  files.set(file.id, file);
1474
- changed.add(file.id);
1633
+ const before = feed || initial ? void 0 : prior(file.id);
1634
+ if (!before || changedSince(before, file) || moved(before, file))
1635
+ changed.add(file.id);
1636
+ delta.set(file.id, file);
1475
1637
  }, "keep");
1638
+ const removals = /* @__PURE__ */ new Map();
1639
+ const drop = /* @__PURE__ */ __name((id, reason) => {
1640
+ const known = files.get(id);
1641
+ if (known)
1642
+ delta.set(id, { ...known, trashed: true });
1643
+ files.delete(id);
1644
+ removals.set(id, reason);
1645
+ }, "drop");
1476
1646
  const container = /* @__PURE__ */ __name((file) => {
1477
1647
  if (options.isDocument?.(file))
1478
1648
  keep(file);
1479
1649
  }, "container");
1480
- const visited = /* @__PURE__ */ new Set();
1481
- let discovered = 0;
1482
- const crawl = /* @__PURE__ */ __name(async (folder, ancestry = /* @__PURE__ */ new Set()) => {
1483
- if (ancestry.has(folder.id))
1484
- throw new CliError("invalid_response", "folder traversal contains a cycle");
1485
- if (visited.has(folder.id))
1486
- return;
1487
- visited.add(folder.id);
1488
- folders[folder.id] = folder;
1489
- for (const file of await source.children(folder.id)) {
1490
- if (++discovered > MAX_ENTRIES)
1491
- throw tooManyEntries();
1492
- if (isFolder(file)) {
1493
- container(file);
1494
- await crawl(file, /* @__PURE__ */ new Set([...ancestry, folder.id]));
1495
- } else
1496
- keep(file);
1497
- }
1498
- }, "crawl");
1499
- let finalCursor = cursor;
1500
- if (initial) {
1501
- files.clear();
1502
- const walk = resumed ?? {
1650
+ const walked = /* @__PURE__ */ __name((id) => !full && state.folders[id] !== void 0 && !state.folders[id]?.trashed, "walked");
1651
+ let walk = resumed;
1652
+ let cursor = state.cursor ?? "";
1653
+ const charge = /* @__PURE__ */ __name(() => {
1654
+ const taken = options.signal?.aborted ? "cancelled" : budget?.take();
1655
+ return taken === "deadline" && budget?.first?.() ? null : taken ?? null;
1656
+ }, "charge");
1657
+ if (!walk && full) {
1658
+ const before = charge();
1659
+ if (before)
1660
+ return { walk: { folders_left: roots.length, entries: 0, listed: 0, stopped: before } };
1661
+ const start = feed ? await feed.startToken() : WALKED;
1662
+ walk = {
1503
1663
  scope,
1504
- cursor,
1664
+ cursor: start,
1505
1665
  stack: [...roots].reverse().map((id) => ({ id, ancestry: [] })),
1506
1666
  visited: [],
1507
1667
  folders: {},
1508
1668
  files: [],
1509
1669
  discovered: 0
1510
1670
  };
1511
- for (const id of walk.visited)
1512
- visited.add(id);
1513
- Object.assign(folders, walk.folders);
1514
- for (const file of walk.files) {
1515
- files.set(file.id, file);
1516
- changed.add(file.id);
1517
- }
1518
- discovered = walk.discovered;
1519
- let savedAt = (options.now ?? Date.now)();
1520
- const record2 = /* @__PURE__ */ __name(() => {
1521
- walks?.save({ ...walk, visited: [...visited], folders, files: [...files.values()], discovered });
1522
- savedAt = (options.now ?? Date.now)();
1523
- }, "record");
1524
- try {
1525
- for (let step = walk.stack.at(-1); step; step = walk.stack.at(-1)) {
1526
- if (step.ancestry.includes(step.id))
1527
- throw new CliError("invalid_response", "folder traversal contains a cycle");
1528
- if (visited.has(step.id)) {
1529
- walk.stack.pop();
1530
- continue;
1531
- }
1532
- const folder = step.folder ?? await source.metadata(step.id);
1533
- if (!step.folder && (!isFolder(folder) || folder.trashed))
1534
- throw new CliError("validation_error", "configured root is not an accessible folder");
1535
- if (!step.folder)
1536
- container(folder);
1537
- const children = await source.children(folder.id);
1538
- if (discovered + children.length > MAX_ENTRIES)
1539
- throw tooManyEntries();
1540
- discovered += children.length;
1541
- walk.stack.pop();
1542
- visited.add(folder.id);
1543
- folders[folder.id] = folder;
1544
- const nested = [];
1545
- for (const file of children)
1546
- if (isFolder(file)) {
1547
- container(file);
1548
- nested.push({ id: file.id, ancestry: [...step.ancestry, folder.id], folder: file });
1549
- } else
1550
- keep(file);
1551
- for (const entry of nested.reverse())
1552
- walk.stack.push(entry);
1553
- if ((options.now ?? Date.now)() - savedAt > SAVE_EVERY_MS)
1554
- record2();
1555
- }
1556
- } catch (error) {
1557
- record2();
1558
- throw error;
1559
- }
1560
- } else {
1561
- const page = await source.changes(cursor);
1562
- finalCursor = page.cursor;
1671
+ } else if (!walk) {
1672
+ const before = charge();
1673
+ if (before)
1674
+ return { walk: { folders_left: 0, entries: 0, listed: 0, stopped: before } };
1675
+ const page = await feed.changes(cursor);
1563
1676
  const latest = new Map(page.items.map((change) => [change.id, change]));
1564
1677
  const entering = [];
1565
1678
  for (const change of latest.values()) {
1566
1679
  if (change.removed || change.file?.trashed) {
1567
- files.delete(change.id);
1680
+ drop(change.id, change.file?.trashed ? "deleted" : change.gone ?? "unavailable");
1568
1681
  if (folders[change.id])
1569
1682
  folders[change.id] = { ...folders[change.id], trashed: true };
1570
1683
  } else if (change.file && isFolder(change.file)) {
@@ -1579,7 +1692,7 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1579
1692
  for (const root of roots) {
1580
1693
  const previous = folders[root];
1581
1694
  try {
1582
- const current = await source.metadata(root);
1695
+ const current = await source.metadata(root, folders[root]);
1583
1696
  if (current.id !== root || !isFolder(current))
1584
1697
  throw new CliError("invalid_response", "selected folder metadata is inconsistent");
1585
1698
  folders[root] = current;
@@ -1592,29 +1705,170 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1592
1705
  folders[root] = { ...previous, trashed: true };
1593
1706
  }
1594
1707
  }
1595
- for (const folder of entering)
1596
- if (!visited.has(folder.id) && within(folder, roots, folders))
1597
- await crawl(folder);
1708
+ const stack = entering.filter((folder) => !excluded(folder) && within(folder, roots, folders, /* @__PURE__ */ new Set(), cut)).reverse().map((folder) => ({ id: folder.id, ancestry: [], folder }));
1709
+ if (stack.length)
1710
+ walk = {
1711
+ scope: changesScope(scope, cursor),
1712
+ cursor: page.cursor,
1713
+ stack,
1714
+ visited: [],
1715
+ folders: {},
1716
+ files: [],
1717
+ discovered: 0
1718
+ };
1719
+ else
1720
+ cursor = page.cursor;
1598
1721
  }
1722
+ const vanished = /* @__PURE__ */ __name(async (id, known) => {
1723
+ try {
1724
+ return (await source.metadata(id, known)).trashed;
1725
+ } catch (error) {
1726
+ return errorOf(error).code === "not_found";
1727
+ }
1728
+ }, "vanished");
1729
+ let found = [];
1730
+ if (walk) {
1731
+ const visited = new Set(walk.visited);
1732
+ Object.assign(folders, walk.folders);
1733
+ for (const file of walk.files) {
1734
+ if (file.trashed)
1735
+ drop(file.id, "unavailable");
1736
+ else
1737
+ keep(file);
1738
+ }
1739
+ cursor = walk.cursor;
1740
+ const now = options.now ?? Date.now;
1741
+ let savedAt = now();
1742
+ const current = walk;
1743
+ const record2 = /* @__PURE__ */ __name(() => {
1744
+ walks?.save({ ...current, visited: [...visited], folders, files: [...delta.values()] });
1745
+ savedAt = now();
1746
+ }, "record");
1747
+ let spent = 0;
1748
+ let listed = 0;
1749
+ let stopped = null;
1750
+ try {
1751
+ for (let step = walk.stack.at(-1); step; step = walk.stack.at(-1)) {
1752
+ if (step.ancestry.includes(step.id))
1753
+ throw new CliError("invalid_response", "folder traversal contains a cycle");
1754
+ if (visited.has(step.id)) {
1755
+ walk.stack.pop();
1756
+ continue;
1757
+ }
1758
+ const taken = options.signal?.aborted ? "cancelled" : listed > 0 && spent >= maxEntries ? "entries" : budget?.take();
1759
+ stopped = taken === "deadline" && budget?.first?.() ? null : taken ?? null;
1760
+ if (stopped)
1761
+ break;
1762
+ if (!step.folder) {
1763
+ const known = state.folders[step.id];
1764
+ let root;
1765
+ try {
1766
+ root = await source.metadata(step.id, known);
1767
+ } catch (error) {
1768
+ if (feed || !known || errorOf(error).code !== "not_found")
1769
+ throw error;
1770
+ walk.stack.pop();
1771
+ visited.add(step.id);
1772
+ folders[step.id] = { ...known, trashed: true };
1773
+ spent++;
1774
+ listed++;
1775
+ continue;
1776
+ }
1777
+ if (!isFolder(root) || root.trashed)
1778
+ throw new CliError("validation_error", "configured root is not an accessible folder");
1779
+ container(root);
1780
+ step.folder = root;
1781
+ stopped = charge();
1782
+ if (stopped)
1783
+ break;
1784
+ }
1785
+ const folder = step.folder;
1786
+ let children;
1787
+ let more;
1788
+ try {
1789
+ if (source.childrenPage)
1790
+ ({ files: children, cursor: more } = await source.childrenPage(folder.id, step.listing, folder));
1791
+ else
1792
+ children = await source.children(folder.id, folder);
1793
+ } catch (error) {
1794
+ if (errorOf(error).code !== "not_found")
1795
+ throw error;
1796
+ if (step.listing !== void 0) {
1797
+ delete step.listing;
1798
+ spent++;
1799
+ listed++;
1800
+ continue;
1801
+ }
1802
+ if (!await vanished(folder.id, folder))
1803
+ throw error;
1804
+ walk.stack.pop();
1805
+ visited.add(folder.id);
1806
+ folders[folder.id] = { ...folder, trashed: true };
1807
+ drop(folder.id, "unavailable");
1808
+ spent++;
1809
+ listed++;
1810
+ continue;
1811
+ }
1812
+ spent += 1 + children.length;
1813
+ listed++;
1814
+ walk.discovered += children.length;
1815
+ folders[folder.id] = folder;
1816
+ const nested = [];
1817
+ for (const file of children)
1818
+ if (isFolder(file)) {
1819
+ container(file);
1820
+ if (excluded(file))
1821
+ continue;
1822
+ if (walked(file.id))
1823
+ folders[file.id] = file;
1824
+ else
1825
+ nested.push({ id: file.id, ancestry: [...step.ancestry, folder.id], folder: file });
1826
+ } else
1827
+ keep(file);
1828
+ walk.stack.pop();
1829
+ for (const entry of nested.reverse())
1830
+ walk.stack.push(entry);
1831
+ if (more)
1832
+ walk.stack.push({ ...step, folder, listing: more });
1833
+ else
1834
+ visited.add(folder.id);
1835
+ if (now() - savedAt > SAVE_EVERY_MS)
1836
+ record2();
1837
+ }
1838
+ if (stopped) {
1839
+ record2();
1840
+ return {
1841
+ walk: { folders_left: walk.stack.length, entries: walk.discovered, listed, stopped }
1842
+ };
1843
+ }
1844
+ if (query?.mode === "include" && query.list)
1845
+ found = await query.list();
1846
+ } catch (error) {
1847
+ record2();
1848
+ throw error;
1849
+ }
1850
+ } else if (query?.mode === "include" && query.list)
1851
+ found = await query.list();
1599
1852
  const matched = /* @__PURE__ */ new Set();
1600
1853
  for (const file of found) {
1601
1854
  if (isFolder(file) && !options.isDocument?.(file) || file.trashed || !query?.matches(file) || matched.has(file.id))
1602
1855
  continue;
1603
- if (!files.has(file.id) && ++discovered > MAX_ENTRIES)
1604
- throw tooManyEntries();
1605
- const prior = state.documents[file.id]?.metadata ?? state.skipped.find((item) => item.id === file.id)?.file;
1606
- if (initial || !prior || changedSince(prior, file))
1856
+ const prior2 = state.documents[file.id]?.metadata ?? state.skipped.find((item) => item.id === file.id)?.file;
1857
+ if (initial || !prior2 || changedSince(prior2, file))
1607
1858
  changed.add(file.id);
1608
1859
  files.set(file.id, file);
1609
1860
  matched.add(file.id);
1610
1861
  }
1611
1862
  const jobs = [];
1612
1863
  const skipped = [];
1864
+ const again = [];
1865
+ let rereads = 0;
1866
+ const reread = /* @__PURE__ */ __name((known) => known !== void 0 && !known.notRead && rereads < REREAD_BATCH && source.reread?.(known) === true && ++rereads > 0, "reread");
1613
1867
  for (const root of roots)
1614
1868
  if (folders[root]?.trashed)
1615
1869
  skipped.push({ id: root, reason: "selected folder is unavailable" });
1616
1870
  for (const [id, file] of files) {
1617
- if (!inScope(file, roots, folders, matched, query))
1871
+ if (!inScope(file, roots, folders, matched, scoped))
1618
1872
  continue;
1619
1873
  const previousSkip = state.skipped.find((item) => item.id === id);
1620
1874
  const reason = skipReason(file);
@@ -1632,32 +1886,46 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1632
1886
  continue;
1633
1887
  }
1634
1888
  if (changed.has(id) || retry || known?.notRead) {
1635
- if (!known || known.notRead || changedSince(known.metadata, file) || initial)
1889
+ if (!known || known.notRead || changedSince(known.metadata, file) || initial || !feed && moved(known.metadata, file))
1636
1890
  jobs.push({ id, kind: "save", file });
1637
- }
1891
+ else if (reread(known))
1892
+ again.push({ id, kind: "save", file });
1893
+ } else if (reread(known))
1894
+ again.push({ id, kind: "save", file });
1638
1895
  }
1639
- for (const id of /* @__PURE__ */ new Set([...Object.keys(state.documents), ...abandoned])) {
1896
+ for (const job of again)
1897
+ jobs.push(job);
1898
+ const narrowed = state.scope !== scope;
1899
+ for (const id of Object.keys(state.documents)) {
1640
1900
  const file = files.get(id);
1641
- if (!file || !inScope(file, roots, folders, matched, query))
1642
- jobs.push({ id, kind: "remove" });
1901
+ const known = file ?? state.documents[id]?.metadata;
1902
+ if (file && inScope(file, roots, folders, matched, scoped))
1903
+ continue;
1904
+ const outside = narrowed && known !== void 0 && !inScope(known, roots, folders, matched, scoped);
1905
+ jobs.push({ id, kind: "remove", reason: removals.get(id) ?? (outside ? "unsynced" : "unavailable") });
1643
1906
  }
1644
- const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => within(file, roots, folders) || roots.includes(file.id)));
1907
+ const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => roots.includes(file.id) || !excluded(file) && within(file, roots, folders, /* @__PURE__ */ new Set(), cut)));
1645
1908
  return {
1646
- scope,
1647
- cursor: finalCursor,
1648
- folders: scopedFolders,
1649
- jobs,
1650
- skipped,
1651
- ...query?.mode === "include" ? { matched: [...matched] } : {}
1909
+ pending: {
1910
+ scope,
1911
+ cursor,
1912
+ folders: scopedFolders,
1913
+ jobs,
1914
+ skipped,
1915
+ ...query?.mode === "include" ? { matched: [...matched] } : {}
1916
+ }
1652
1917
  };
1653
1918
  }, "planDocuments");
1654
1919
 
1655
- // node_modules/.pnpm/@wirecat+cli-core@0.666.0_@wirecat+cli-base@0.101.0_commander@15.0.0_esbuild@0.28.2_typ_02b130a271480a962759fcca79b3d7ec/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1920
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1656
1921
  var MAX_PICTURE_BYTES = 25 * 1024 * 1024;
1657
1922
  var SAVE_EVERY_MS2 = 2e3;
1658
1923
  var SAVE_EVERY_ITEMS = 25;
1924
+ var SETTLE_MS = 1e4;
1925
+ var DAY_MS = 24 * 60 * 60 * 1e3;
1926
+ var KEEP_VERSIONS_FOR_DAYS = 365;
1659
1927
  var isPicture = /* @__PURE__ */ __name((file) => file.mime.startsWith("image/") && file.canDownload, "isPicture");
1660
- var hashText2 = /* @__PURE__ */ __name((text) => createHash4("sha256").update(text).digest("hex"), "hashText");
1928
+ var hashText = /* @__PURE__ */ __name((text) => createHash4("sha256").update(text).digest("hex"), "hashText");
1661
1929
  var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1662
1930
  const { source, index, state: statePort, principal, roots, textLimit: limit, max, signal, rescan = false, pictures = false, assertHeld, errorOf, skipReason, storeVersion: VERSION, query } = options;
1663
1931
  if (![max, limit, options.maxEntries].every((value) => Number.isSafeInteger(value) && value > 0))
@@ -1675,6 +1943,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1675
1943
  pending: 0,
1676
1944
  skipped: [],
1677
1945
  errors: [],
1946
+ complete: true,
1678
1947
  coverage: query?.mode === "include" ? "selected folders and the files a saved query finds; unsupported files are reported" : query?.mode === "exclude" ? "selected folders only, without the files a saved query keeps out; unsupported files are reported" : "selected folders only; unsupported files are reported",
1679
1948
  ...profile.picture_search ? { pictures: 0 } : {}
1680
1949
  };
@@ -1688,19 +1957,36 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1688
1957
  const state = statePort.read();
1689
1958
  if (state.principal !== principal)
1690
1959
  throw new CliError("configuration_error", "sync state belongs to another source account");
1960
+ if (options.profile !== void 0)
1961
+ await index.registerProfile?.(options.profile, principal);
1691
1962
  const currentScope = scopeHash(profile.roots, query, options.isDocument !== void 0);
1692
- const abandoned = state.pending && (state.pending.scope !== currentScope || rescan) ? state.pending.jobs.map((job) => job.id) : [];
1693
- if (state.pending?.scope !== currentScope || rescan)
1963
+ if (state.pending && (state.pending.scope !== currentScope || rescan)) {
1964
+ for (const job of state.pending.jobs)
1965
+ if (!state.documents[job.id]) {
1966
+ await index.remove(profile.principal, job.id, "unsynced");
1967
+ statePort.removeSnapshot(job.id);
1968
+ }
1694
1969
  delete state.pending;
1970
+ statePort.save(state);
1971
+ }
1695
1972
  if (rescan) {
1696
1973
  delete state.cursor;
1697
1974
  statePort.removeWalk();
1975
+ statePort.save(state);
1698
1976
  }
1699
1977
  if (!state.pending) {
1700
- state.pending = await planDocuments(options, source, state, profile.roots, limit, profile.picture_search ?? false, abandoned, {
1978
+ const plan = await planDocuments(options, source, state, profile.roots, limit, profile.picture_search ?? false, {
1701
1979
  read: /* @__PURE__ */ __name((scope) => statePort.readWalk(scope), "read"),
1702
1980
  save: /* @__PURE__ */ __name((walk) => statePort.saveWalk(walk), "save")
1703
1981
  });
1982
+ if ("walk" in plan) {
1983
+ result.complete = false;
1984
+ result.stopped = plan.walk.stopped;
1985
+ result.walk = { folders_left: plan.walk.folders_left, entries: plan.walk.entries, listed: plan.walk.listed };
1986
+ result.skipped = state.skipped.map(({ id, reason }) => ({ id, reason }));
1987
+ return result;
1988
+ }
1989
+ state.pending = plan.pending;
1704
1990
  state.skipped = state.pending.skipped;
1705
1991
  statePort.save(state);
1706
1992
  statePort.removeWalk();
@@ -1713,7 +1999,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1713
1999
  result.skipped = state.skipped.map(({ id, reason }) => ({ id, reason }));
1714
2000
  const saveNamesOnly = /* @__PURE__ */ __name(async (file, reason) => {
1715
2001
  const doc = { metadata: file, markdown: "", text: "", tabs: [], notRead: reason };
1716
- const hash = hashText2("");
2002
+ const hash = hashText("");
1717
2003
  const previous = state.documents[file.id];
1718
2004
  const reference = await index.save(profile.principal, doc, hash);
1719
2005
  statePort.saveSnapshot(doc);
@@ -1723,15 +2009,19 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1723
2009
  else
1724
2010
  result.names_only++;
1725
2011
  }, "saveNamesOnly");
2012
+ const ask = /* @__PURE__ */ __name(() => {
2013
+ const taken = options.budget?.take() ?? null;
2014
+ return taken === "deadline" && options.budget?.first?.() ? null : taken;
2015
+ }, "ask");
1726
2016
  let modelMissing = false;
1727
2017
  const savePictureOf = /* @__PURE__ */ __name(async (file) => {
1728
2018
  const entry = state.documents[file.id];
1729
2019
  if (!profile.picture_search || !isPicture(file) || modelMissing)
1730
- return;
2020
+ return null;
1731
2021
  if ((file.size ?? 0) > MAX_PICTURE_BYTES) {
1732
2022
  entry.picture = "too-large";
1733
2023
  result.pictures_too_large = (result.pictures_too_large ?? 0) + 1;
1734
- return;
2024
+ return null;
1735
2025
  }
1736
2026
  if (!source)
1737
2027
  throw new CliError("configuration_error", "a pending picture requires source sign-in");
@@ -1743,18 +2033,22 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1743
2033
  throw error;
1744
2034
  modelMissing = true;
1745
2035
  result.pictures_skipped = error.message;
1746
- return;
2036
+ return null;
1747
2037
  }
1748
2038
  }
1749
- const bytes = await source.bytes(file.id);
2039
+ const stop = ask();
2040
+ if (stop)
2041
+ return stop;
2042
+ const bytes = await source.bytes(file.id, file);
1750
2043
  if (bytes.length > MAX_PICTURE_BYTES) {
1751
2044
  entry.picture = "too-large";
1752
2045
  result.pictures_too_large = (result.pictures_too_large ?? 0) + 1;
1753
- return;
2046
+ return null;
1754
2047
  }
1755
2048
  if (await writer2.save(entry.reference, bytes) === "saved")
1756
2049
  result.pictures = (result.pictures ?? 0) + 1;
1757
2050
  entry.picture = "saved";
2051
+ return null;
1758
2052
  }, "savePictureOf");
1759
2053
  let unsaved = 0;
1760
2054
  let savedAt = now();
@@ -1775,25 +2069,34 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1775
2069
  lock.assertHeld();
1776
2070
  try {
1777
2071
  if (job.kind === "remove") {
1778
- await index.remove(profile.principal, job.id);
2072
+ await index.remove(profile.principal, job.id, job.reason ?? "unavailable");
1779
2073
  statePort.removeSnapshot(job.id);
1780
2074
  delete state.documents[job.id];
1781
2075
  result.removed++;
1782
2076
  } else if (job.file && skipReason(job.file)) {
1783
2077
  await saveNamesOnly(job.file, skipReason(job.file));
1784
- await savePictureOf(job.file);
2078
+ const stop = await savePictureOf(job.file);
2079
+ if (stop) {
2080
+ result.stopped = stop;
2081
+ break;
2082
+ }
1785
2083
  } else {
1786
2084
  if (!source)
1787
2085
  throw new CliError("configuration_error", "a pending save requires source sign-in");
1788
- const content = await source.content(job.id, limit);
2086
+ const stop = ask();
2087
+ if (stop) {
2088
+ result.stopped = stop;
2089
+ break;
2090
+ }
2091
+ const content = await source.content(job.id, limit, job.file);
1789
2092
  const listed = query?.mode === "include" && (pending.matched?.includes(job.id) ?? query.matches(content.metadata));
1790
2093
  if (!listed && !inScope(content.metadata, profile.roots, pending.folders, /* @__PURE__ */ new Set(), query)) {
1791
- await index.remove(profile.principal, job.id);
2094
+ await index.remove(profile.principal, job.id, "unsynced");
1792
2095
  statePort.removeSnapshot(job.id);
1793
2096
  delete state.documents[job.id];
1794
2097
  result.removed++;
1795
2098
  } else {
1796
- const hash = hashText2(content.text);
2099
+ const hash = hashText(content.text);
1797
2100
  const previous = state.documents[job.id];
1798
2101
  const reference = await index.save(profile.principal, content, hash).catch((error) => {
1799
2102
  if (!isCliError(error) || error.code !== "validation_error")
@@ -1817,7 +2120,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1817
2120
  const safe = errorOf(error);
1818
2121
  if (safe.code === "cancelled")
1819
2122
  throw safe;
1820
- if (job.kind === "save" && (safe.code === "not_found" || safe.code === "validation_error")) {
2123
+ if (job.kind === "save" && (safe.code === "not_found" || safe.code === "permission_error" || safe.code === "validation_error")) {
1821
2124
  const skipped = {
1822
2125
  id: job.id,
1823
2126
  reason: safe.message,
@@ -1828,7 +2131,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1828
2131
  if (job.file && safe.code === "validation_error")
1829
2132
  await saveNamesOnly(job.file, skipped.reason);
1830
2133
  else {
1831
- await index.remove(profile.principal, job.id);
2134
+ await index.remove(profile.principal, job.id, "unavailable");
1832
2135
  statePort.removeSnapshot(job.id);
1833
2136
  delete state.documents[job.id];
1834
2137
  }
@@ -1844,6 +2147,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1844
2147
  }
1845
2148
  flush();
1846
2149
  result.pending = pending.jobs.length;
2150
+ result.complete = !pending.jobs.length;
1847
2151
  if (!pending.jobs.length) {
1848
2152
  state.cursor = pending.cursor;
1849
2153
  state.scope = pending.scope;
@@ -1855,7 +2159,13 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1855
2159
  delete state.pending;
1856
2160
  state.lastSync = new Date(now()).toISOString();
1857
2161
  statePort.save(state);
2162
+ const days = options.keepVersionsForDays ?? KEEP_VERSIONS_FOR_DAYS;
2163
+ await index.prune?.(profile.principal, new Date(now() - days * DAY_MS).toISOString());
1858
2164
  }
2165
+ const settleFrom = Date.now();
2166
+ const settleUntil = Math.min(settleFrom + SETTLE_MS, options.deadline ? options.deadline.endsAt - deadlineMargin(options.deadline) : Number.POSITIVE_INFINITY);
2167
+ if (!result.stopped && !options.budget?.stopped && settleUntil > settleFrom)
2168
+ await index.settle?.({ until: /* @__PURE__ */ __name(() => signal?.aborted === true || Date.now() >= settleUntil, "until") }).catch(() => void 0);
1859
2169
  return result;
1860
2170
  } finally {
1861
2171
  flush?.();
@@ -1863,6 +2173,97 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1863
2173
  }
1864
2174
  }, "syncDocuments");
1865
2175
 
2176
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/files/text-merge.js
2177
+ var MAX_MERGE_BYTES = 1024 * 1024;
2178
+
2179
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/files/guarded-write.js
2180
+ var remoteChanged = /* @__PURE__ */ __name((path, why, reread) => new CliError("conflict", `${path} ${why}; nothing was written. Read it again: ${reread}`, {
2181
+ reason: "mirror.remote-changed"
2182
+ }), "remoteChanged");
2183
+ var guardedFileWrite = /* @__PURE__ */ __name(async (write) => {
2184
+ const { target, versions, path, from, expected, reread, direction = "local-to-remote", signal } = write;
2185
+ const there = await target.exists(path, signal);
2186
+ if (there && expected === void 0)
2187
+ throw new CliError("validation_error", `${path} exists; read it first (${reread}) and pass its sha256 as --expected-fingerprint`, { param: "--expected-fingerprint" });
2188
+ if (!there && expected !== void 0)
2189
+ throw remoteChanged(path, "is no longer there", reread);
2190
+ const kept = expected === void 0 ? void 0 : await versions.keep((temp) => target.download(path, temp, signal));
2191
+ if (kept !== expected)
2192
+ throw remoteChanged(path, "changed since it was read", reread);
2193
+ let file;
2194
+ try {
2195
+ file = await target.upload(path, from, kept === void 0 ? { absent: true } : { sha256: kept }, signal);
2196
+ } catch (error) {
2197
+ if (isCliError(error) && error.code === "conflict")
2198
+ throw remoteChanged(path, kept === void 0 ? "appeared since it was read" : "changed since it was read", reread);
2199
+ throw error;
2200
+ }
2201
+ if (kept === void 0)
2202
+ return { file };
2203
+ versions.log({
2204
+ path,
2205
+ event: "changed",
2206
+ direction,
2207
+ old: kept,
2208
+ from: "remote",
2209
+ ...file.sha256 ? { new: file.sha256 } : {},
2210
+ size: file.size
2211
+ });
2212
+ return { file, replaced: { sha256: kept } };
2213
+ }, "guardedFileWrite");
2214
+
2215
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/files/listing.js
2216
+ var MAX_LISTING_AGE_MS = 7 * 24 * 36e5;
2217
+ var remoteFileSchema = object({
2218
+ path: string(),
2219
+ id: string(),
2220
+ size: number(),
2221
+ sha256: optional(string()),
2222
+ md5: optional(string()),
2223
+ modifiedAt: string()
2224
+ });
2225
+ var listingSchema = object({
2226
+ rootId: string(),
2227
+ startedAt: string(),
2228
+ next: string(),
2229
+ files: array(remoteFileSchema)
2230
+ });
2231
+
2232
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/files/mirror-state.js
2233
+ var entrySchema = object({
2234
+ id: string(),
2235
+ size: number(),
2236
+ sha256: string(),
2237
+ md5: optional(string()),
2238
+ remoteModified: string(),
2239
+ localMtimeMs: number(),
2240
+ localSize: number(),
2241
+ syncedAt: string()
2242
+ });
2243
+ var stateSchema2 = object({
2244
+ version: literal(1),
2245
+ principal: string(),
2246
+ root: string(),
2247
+ target: string(),
2248
+ rootId: optional(string()),
2249
+ localRoot: optional(object({ dev: number(), ino: number() })),
2250
+ entries: record(string(), entrySchema),
2251
+ pending: record(string(), object({ op: string(), operationId: string(), created: optional(boolean()) })),
2252
+ listing: optional(listingSchema),
2253
+ conflicts: optional(record(string(), object({
2254
+ reason: string(),
2255
+ at: string(),
2256
+ base: optional(string()),
2257
+ local: optional(string()),
2258
+ remote: optional(string()),
2259
+ remoteFile: optional(remoteFileSchema),
2260
+ kept: optional(boolean())
2261
+ })))
2262
+ });
2263
+
2264
+ // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.128.0_commander@15.0.0_esbuild@0.28.2_typ_a55806ccf2eb39d6be3eaf4c54d1a60a/node_modules/@wirecat/cli-core/dist/services/files/versions.js
2265
+ var RETAIN_MS = 30 * 24 * 60 * 60 * 1e3;
2266
+
1866
2267
  // dist/model.js
1867
2268
  var FOLDER = "application/vnd.google-apps.folder";
1868
2269
  var DOC = "application/vnd.google-apps.document";
@@ -1914,7 +2315,10 @@ export {
1914
2315
  watchMirrors,
1915
2316
  extractDocumentMemories,
1916
2317
  catalogFiles,
2318
+ KEEP_VERSIONS_FOR_DAYS,
1917
2319
  syncDocuments,
2320
+ remoteChanged,
2321
+ guardedFileWrite,
1918
2322
  FOLDER,
1919
2323
  DOC,
1920
2324
  SHEET,