@wirecat/drive-cli 0.69.0 → 0.71.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 (228) hide show
  1. package/README.md +3 -2
  2. package/contracts/wirecat.json +14 -13
  3. package/dist/age.d.ts +0 -36
  4. package/dist/age.d.ts.map +1 -1
  5. package/dist/age.js +0 -22
  6. package/dist/age.js.map +1 -1
  7. package/dist/bin/drive.js +2 -2
  8. package/dist/bundle/{all-profiles-B4A737YW.js → all-profiles-3QJG2NAN.js} +13 -13
  9. package/dist/bundle/{anthropic-RZGPDESM.js → anthropic-PSWTEU6G.js} +8 -8
  10. package/dist/bundle/{app-server-OWEW7DY5.js → app-server-PVTA6ABR.js} +66 -58
  11. package/dist/bundle/{bun-V5QLYBZU.js → bun-LU5LP3JI.js} +2 -2
  12. package/dist/bundle/{bun-sqlite-KHLHXXGH.js → bun-sqlite-PYMKLBRU.js} +9 -9
  13. package/dist/bundle/{chunk-CAQ5GW3A.js → chunk-22QQUKWA.js} +1 -1
  14. package/dist/bundle/{chunk-3YKAFLXY.js → chunk-26DHFMGZ.js} +2 -2
  15. package/dist/bundle/{chunk-Y2QVNVHK.js → chunk-2BVVU7GG.js} +1 -1
  16. package/dist/bundle/{chunk-7JKECODO.js → chunk-2LHAVY4U.js} +1 -11
  17. package/dist/bundle/{chunk-HEBZCKMU.js → chunk-2PUNKUYJ.js} +4389 -4709
  18. package/dist/bundle/chunk-2UUWXPOB.js +31 -0
  19. package/dist/bundle/{chunk-KUQDBWPU.js → chunk-35SCQ4VI.js} +31 -32
  20. package/dist/bundle/{chunk-O6PD7RZY.js → chunk-3EBBLKIT.js} +4 -4
  21. package/dist/bundle/{chunk-PV3AWPHR.js → chunk-3N2OFXB5.js} +5 -5
  22. package/dist/bundle/{chunk-SY2HLH5R.js → chunk-3UGYFXH6.js} +82 -25
  23. package/dist/bundle/{chunk-OUM4ZO53.js → chunk-4HWJOU7N.js} +1 -1
  24. package/dist/bundle/{chunk-6D44YQ5X.js → chunk-4PA4DHYV.js} +6 -6
  25. package/dist/bundle/{chunk-EA2OB75T.js → chunk-4QNW4NK6.js} +1 -1
  26. package/dist/bundle/{chunk-GK6KXBL6.js → chunk-6SJOTNHF.js} +4 -4
  27. package/dist/bundle/{chunk-NVDR72GP.js → chunk-6TNNT2MQ.js} +250 -174
  28. package/dist/bundle/{chunk-4YECZ6CN.js → chunk-6W763DZN.js} +12 -12
  29. package/dist/bundle/{chunk-IQ2QU2X6.js → chunk-6XFIITOG.js} +1024 -598
  30. package/dist/bundle/{chunk-AD7VI3XU.js → chunk-72C4YOCH.js} +7 -7
  31. package/dist/bundle/{chunk-6EL5AVXX.js → chunk-7PDHGZN4.js} +4 -4
  32. package/dist/bundle/{chunk-22SH77TG.js → chunk-ACUAV6VX.js} +64 -64
  33. package/dist/bundle/{chunk-BBJVV4E2.js → chunk-ASMMG72J.js} +68 -38
  34. package/dist/bundle/{chunk-XUHQ7DVT.js → chunk-B5KSXHJ7.js} +1 -1
  35. package/dist/bundle/{chunk-BVVXYZSU.js → chunk-BKSQBBYG.js} +9 -9
  36. package/dist/bundle/{chunk-5SJZDEIO.js → chunk-CJLVYIOP.js} +21 -21
  37. package/dist/bundle/chunk-COJSWDNU.js +170 -0
  38. package/dist/bundle/{chunk-GTDCP5OG.js → chunk-COOOO5B3.js} +4 -4
  39. package/dist/bundle/{chunk-LUZRVBQR.js → chunk-D5TGYUVU.js} +6 -6
  40. package/dist/bundle/{chunk-CZ4UEXCE.js → chunk-EOEU3AZN.js} +6 -6
  41. package/dist/bundle/{chunk-CU6RATZH.js → chunk-FCS26CYQ.js} +4 -4
  42. package/dist/bundle/{chunk-LRCSDAYK.js → chunk-FJH7DJWK.js} +4 -4
  43. package/dist/bundle/{chunk-U3RXH6RY.js → chunk-FP54WSIR.js} +4 -4
  44. package/dist/bundle/{chunk-3URYKAJP.js → chunk-FT3LN3HP.js} +1 -1
  45. package/dist/bundle/{chunk-CDSB7WVG.js → chunk-GBKNJWOZ.js} +8 -8
  46. package/dist/bundle/{chunk-4J5GJJ2I.js → chunk-GOWXXYEF.js} +2 -2
  47. package/dist/bundle/{chunk-PB6NWKH3.js → chunk-GPQ44Y2R.js} +2 -2
  48. package/dist/bundle/{chunk-E7URRFBB.js → chunk-GZ2D4KXG.js} +10 -15
  49. package/dist/bundle/{chunk-376ZGVUZ.js → chunk-HKY7X6NY.js} +4 -4
  50. package/dist/bundle/{chunk-6XNTELM5.js → chunk-HL52XXZX.js} +1 -1
  51. package/dist/bundle/{chunk-533XOW74.js → chunk-HMS6EEQL.js} +3 -3
  52. package/dist/bundle/{chunk-F5UUJU6R.js → chunk-I4RWW3UD.js} +49 -4
  53. package/dist/bundle/{chunk-TZ75K6R7.js → chunk-ICDCAQ6K.js} +8 -8
  54. package/dist/bundle/{chunk-WOUIHZRI.js → chunk-J5Q5FS2N.js} +18 -75
  55. package/dist/bundle/{chunk-EL2E3ABX.js → chunk-JDV7HNNQ.js} +13 -13
  56. package/dist/bundle/{chunk-ZUG67442.js → chunk-JZHBZOJR.js} +3 -3
  57. package/dist/bundle/{chunk-SEJBS7SI.js → chunk-KGERXYTV.js} +1 -1
  58. package/dist/bundle/{chunk-5TK2YQCO.js → chunk-KGYVHPGE.js} +2 -2
  59. package/dist/bundle/{chunk-HCZYJMBP.js → chunk-KYKW2W6X.js} +1 -1
  60. package/dist/bundle/{chunk-RLGQMMYE.js → chunk-L46C6HQ7.js} +35 -13
  61. package/dist/bundle/chunk-LXKYKRHD.js +387 -0
  62. package/dist/bundle/{chunk-N4ACIIQB.js → chunk-MIA7P6FZ.js} +2 -2
  63. package/dist/bundle/{chunk-ZBYKCVSV.js → chunk-MNLL5YLM.js} +2 -2
  64. package/dist/bundle/{chunk-UPCEHSIZ.js → chunk-OF422U5D.js} +21 -16
  65. package/dist/bundle/{chunk-JRFKCYMW.js → chunk-OJSBWP3F.js} +23 -6
  66. package/dist/bundle/{chunk-MHXZ62CU.js → chunk-P7CUM5IB.js} +1 -1
  67. package/dist/bundle/{chunk-I55XYREN.js → chunk-PRW6SYA3.js} +1094 -2526
  68. package/dist/bundle/chunk-Q7DOMFJ4.js +259 -0
  69. package/dist/bundle/{chunk-3RLRJHAI.js → chunk-QETR5HIZ.js} +12081 -12607
  70. package/dist/bundle/{chunk-QJGFQRTL.js → chunk-QFR2PNJN.js} +12 -12
  71. package/dist/bundle/{chunk-2Q4CB4EI.js → chunk-QNRRK3CN.js} +2 -2
  72. package/dist/bundle/{chunk-5B5NOAIA.js → chunk-QXC6IEH6.js} +45 -45
  73. package/dist/bundle/{chunk-T6X6EZ5N.js → chunk-RESDD3Q4.js} +3 -3
  74. package/dist/bundle/chunk-RJOQH5YY.js +1979 -0
  75. package/dist/bundle/{chunk-AMQGKMLZ.js → chunk-RWDKMU74.js} +3 -3
  76. package/dist/bundle/{chunk-VUPWDCYV.js → chunk-SAKO3P4H.js} +1 -1
  77. package/dist/bundle/{chunk-GHFBT2ZM.js → chunk-SDKQNOL5.js} +6 -6
  78. package/dist/bundle/{chunk-25FT44S3.js → chunk-SERXSCN3.js} +287 -569
  79. package/dist/bundle/{chunk-2DS2TDGW.js → chunk-TAFHYHKA.js} +20 -118
  80. package/dist/bundle/{chunk-XVH3WZSZ.js → chunk-TAUBRNC5.js} +53 -53
  81. package/dist/bundle/{chunk-2VFAXC6O.js → chunk-UDMNY63V.js} +22 -19
  82. package/dist/bundle/{chunk-EWUQIUTB.js → chunk-UTO2GO4P.js} +5 -5
  83. package/dist/bundle/{chunk-V4FMN5A6.js → chunk-WVDCCYS3.js} +17 -17
  84. package/dist/bundle/chunk-X4TIMMKJ.js +16 -0
  85. package/dist/bundle/chunk-XF4EXO2C.js +335 -0
  86. package/dist/bundle/{chunk-OOIAJRKQ.js → chunk-XMMFBPGC.js} +2 -2
  87. package/dist/bundle/{chunk-4ZFO2CVH.js → chunk-Y2NWGNUB.js} +5 -5
  88. package/dist/bundle/{chunk-IJCUAKR5.js → chunk-YJIGGUPI.js} +4 -4
  89. package/dist/bundle/{chunk-L342KHIZ.js → chunk-YMJ6IDGT.js} +6 -6
  90. package/dist/bundle/{chunk-WNMPIRRF.js → chunk-YPFWNVHV.js} +3 -3
  91. package/dist/bundle/{chunk-T4FMXDDV.js → chunk-YPNWIB6H.js} +3 -3
  92. package/dist/bundle/{chunk-FIVFP53N.js → chunk-YVI5SQPY.js} +1 -1
  93. package/dist/bundle/{chunk-RWQ7T4Y5.js → chunk-Z3KUSRCF.js} +2 -2
  94. package/dist/bundle/{chunk-WQOGHND4.js → chunk-Z56QFOBR.js} +1 -1
  95. package/dist/bundle/chunk-ZCR3IRZ2.js +823 -0
  96. package/dist/bundle/{chunk-SYUXKV2E.js → chunk-ZM63SUHG.js} +2 -2
  97. package/dist/bundle/{chunk-M4OP5ASJ.js → chunk-ZZ32DXTH.js} +1 -1
  98. package/dist/bundle/{cli-BS4L3HAP.js → cli-556DERZL.js} +88 -69
  99. package/dist/bundle/command-contract-VRTOAV6W.js +43 -0
  100. package/dist/bundle/{command-server-entry-CJ2CV7ZV.js → command-server-entry-AYLGNZWD.js} +33 -30
  101. package/dist/bundle/decode-QU24MWMN.js +299 -0
  102. package/dist/bundle/{dispatch-WBEOHZDV.js → dispatch-4KODNOXV.js} +9 -9
  103. package/dist/bundle/drive.js +11 -11
  104. package/dist/bundle/{echarts-QIXLXS3G.js → echarts-BXX4OQWC.js} +2 -2
  105. package/dist/bundle/{embed-YNZW5X6M.js → embed-KG27KG3D.js} +9 -9
  106. package/dist/bundle/{embedder-LRC2PKTS.js → embedder-IPAVUQUV.js} +12 -12
  107. package/dist/bundle/entry-MVXQETWS.js +25 -0
  108. package/dist/bundle/{failure-X6PSLVSO.js → failure-ESL7ETL4.js} +4 -4
  109. package/dist/bundle/first-run-4UVLW2WR.js +31 -0
  110. package/dist/bundle/first-screen-JAKAIINI.js +41 -0
  111. package/dist/bundle/google-22NXXJX5.js +45 -0
  112. package/dist/bundle/{google-api-7JDZDCWE.js → google-api-VCDBSNOW.js} +70 -62
  113. package/dist/bundle/grants-MQMTVCRQ.js +118 -0
  114. package/dist/bundle/{identity-E43WKN5F.js → identity-LOWMVGZY.js} +6 -6
  115. package/dist/bundle/{instructions-MD2RZT5Z.js → instructions-2VECIDXF.js} +1 -1
  116. package/dist/bundle/{login-RBDJPQAG.js → login-7GBONT7V.js} +78 -70
  117. package/dist/bundle/{mcp-TDKGDB4V.js → mcp-O6ACR2DX.js} +2 -2
  118. package/dist/bundle/meeting-combined-LVP4AZKA.js +27 -0
  119. package/dist/bundle/meeting-model-RAY5XDXZ.js +29 -0
  120. package/dist/bundle/meeting-semantic-G7PFOKU7.js +25 -0
  121. package/dist/bundle/{node-IEVT2FSJ.js → node-MPEQSFI3.js} +2 -2
  122. package/dist/bundle/{node-sqlite-IENH4TRX.js → node-sqlite-OLQMAYB4.js} +10 -10
  123. package/dist/bundle/oauth-SGH2I2BY.js +22 -0
  124. package/dist/bundle/{open-TZ5H7NYM.js → open-OXTE672W.js} +8 -8
  125. package/dist/bundle/{openai-XF2KB7W2.js → openai-EB3TPIZY.js} +32 -30
  126. package/dist/bundle/{process-6Q23D3TO.js → process-F6TKXWWA.js} +1 -1
  127. package/dist/bundle/{program-D5XWOHV5.js → program-4IFDZ7FM.js} +1356 -1338
  128. package/dist/bundle/{prompt-KUC5D4GX.js → prompt-F5RRHPN2.js} +8 -8
  129. package/dist/bundle/{reasons-KSYP5VDJ.js → reasons-UORHJDHK.js} +5 -5
  130. package/dist/bundle/{recognize-DPFW7HO3.js → recognize-DAVNZND3.js} +7 -7
  131. package/dist/bundle/{remote-MODTSUNH.js → remote-D5EYYIAU.js} +13 -13
  132. package/dist/bundle/{rerank-JK7SERLE.js → rerank-CND2GVLZ.js} +10 -10
  133. package/dist/bundle/{serve-BV2WHZLW.js → serve-ZHSPUIGX.js} +12 -12
  134. package/dist/bundle/server-DUVJWP3Q.js +80 -0
  135. package/dist/bundle/{server-N3WPEU7Z.js → server-YMAK4LHC.js} +54 -46
  136. package/dist/bundle/{services-SV6CFUCS.js → services-ZILSFJ6E.js} +79 -54
  137. package/dist/bundle/{sqlite-runtime-RZ5PLZVQ.js → sqlite-runtime-S5VPMZQH.js} +9 -9
  138. package/dist/bundle/{start-C6EXYXAL.js → start-CR6X25RT.js} +7 -7
  139. package/dist/bundle/{state-RAZIREVG.js → state-YFPHVIIJ.js} +9 -9
  140. package/dist/bundle/{store-DQKJKX2G.js → store-CL4ZJZRI.js} +23 -19
  141. package/dist/bundle/{store-2DLGLYS6.js → store-UODRT6X4.js} +31 -26
  142. package/dist/bundle/store-maintenance-command-DY5XIBWR.js +72 -0
  143. package/dist/bundle/tokens-AF7QOFOF.js +118 -0
  144. package/dist/catalog.d.ts +0 -28
  145. package/dist/catalog.d.ts.map +1 -1
  146. package/dist/catalog.js +0 -82
  147. package/dist/catalog.js.map +1 -1
  148. package/dist/commands/catalog.d.ts +3 -8
  149. package/dist/commands/catalog.d.ts.map +1 -1
  150. package/dist/commands/catalog.js +36 -109
  151. package/dist/commands/catalog.js.map +1 -1
  152. package/dist/commands/context.d.ts +3 -0
  153. package/dist/commands/context.d.ts.map +1 -1
  154. package/dist/commands/context.js +20 -0
  155. package/dist/commands/context.js.map +1 -1
  156. package/dist/commands/documents.d.ts.map +1 -1
  157. package/dist/commands/documents.js +30 -72
  158. package/dist/commands/documents.js.map +1 -1
  159. package/dist/commands/folders.d.ts +1 -1
  160. package/dist/commands/folders.d.ts.map +1 -1
  161. package/dist/commands/folders.js +45 -48
  162. package/dist/commands/folders.js.map +1 -1
  163. package/dist/commands/knowledge.d.ts +4 -21
  164. package/dist/commands/knowledge.d.ts.map +1 -1
  165. package/dist/commands/knowledge.js +3 -241
  166. package/dist/commands/knowledge.js.map +1 -1
  167. package/dist/commands/mirrors.d.ts +2 -2
  168. package/dist/commands/mirrors.d.ts.map +1 -1
  169. package/dist/commands/mirrors.js +46 -202
  170. package/dist/commands/mirrors.js.map +1 -1
  171. package/dist/commands/search.d.ts +1 -3
  172. package/dist/commands/search.d.ts.map +1 -1
  173. package/dist/commands/search.js +20 -42
  174. package/dist/commands/search.js.map +1 -1
  175. package/dist/commands/sync.d.ts.map +1 -1
  176. package/dist/commands/sync.js +36 -53
  177. package/dist/commands/sync.js.map +1 -1
  178. package/dist/config.d.ts.map +1 -1
  179. package/dist/config.js +2 -1
  180. package/dist/config.js.map +1 -1
  181. package/dist/contract-overrides.d.ts +0 -2
  182. package/dist/contract-overrides.d.ts.map +1 -1
  183. package/dist/contract-overrides.js +0 -317
  184. package/dist/contract-overrides.js.map +1 -1
  185. package/dist/knowledge.d.ts +1 -1
  186. package/dist/knowledge.d.ts.map +1 -1
  187. package/dist/knowledge.js +4 -3
  188. package/dist/knowledge.js.map +1 -1
  189. package/dist/list-queries.d.ts +0 -31
  190. package/dist/list-queries.d.ts.map +1 -1
  191. package/dist/list-queries.js +0 -36
  192. package/dist/list-queries.js.map +1 -1
  193. package/dist/program.d.ts.map +1 -1
  194. package/dist/program.js +2 -3
  195. package/dist/program.js.map +1 -1
  196. package/dist/provider-json.d.ts.map +1 -1
  197. package/dist/provider-json.js +5 -5
  198. package/dist/provider-json.js.map +1 -1
  199. package/dist/reasons.d.ts.map +1 -1
  200. package/dist/reasons.js +0 -10
  201. package/dist/reasons.js.map +1 -1
  202. package/dist/sync.d.ts.map +1 -1
  203. package/dist/sync.js +1 -2
  204. package/dist/sync.js.map +1 -1
  205. package/dist/transcripts.d.ts +0 -6
  206. package/dist/transcripts.d.ts.map +1 -1
  207. package/dist/transcripts.js +0 -13
  208. package/dist/transcripts.js.map +1 -1
  209. package/dist/version.d.ts +1 -1
  210. package/dist/version.js +1 -1
  211. package/package.json +3 -3
  212. package/dist/bundle/command-contract-HYURWSD6.js +0 -40
  213. package/dist/bundle/decode-E2NM5SSM.js +0 -165
  214. package/dist/bundle/entry-2IMSWRJU.js +0 -25
  215. package/dist/bundle/first-run-7CPHQDM5.js +0 -30
  216. package/dist/bundle/first-screen-OKZ7GMFR.js +0 -38
  217. package/dist/bundle/google-WDKDBDD4.js +0 -45
  218. package/dist/bundle/grants-AU25GWKF.js +0 -110
  219. package/dist/bundle/oauth-3JGSN47Z.js +0 -22
  220. package/dist/bundle/server-6YDI4Y36.js +0 -72
  221. package/dist/bundle/store-maintenance-command-UJ5F5L4H.js +0 -64
  222. package/dist/bundle/tokens-LY3WML55.js +0 -110
  223. package/dist/knowledge-query.d.ts +0 -77
  224. package/dist/knowledge-query.d.ts.map +0 -1
  225. package/dist/knowledge-query.js +0 -104
  226. package/dist/knowledge-query.js.map +0 -1
  227. package/dist/bundle/{chunk-XWBPP2HX.js → chunk-VKE77B3F.js} +0 -0
  228. package/dist/bundle/{mdast-util-from-markdown-CE73EWJ2.js → mdast-util-from-markdown-FXEPSNER.js} +3 -3
@@ -1,11 +1,14 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ deadlineMargin
5
+ } from "./chunk-I4RWW3UD.js";
3
6
  import {
4
7
  walkQuery
5
- } from "./chunk-UPCEHSIZ.js";
8
+ } from "./chunk-OF422U5D.js";
6
9
  import {
7
10
  writeSecurely
8
- } from "./chunk-5SJZDEIO.js";
11
+ } from "./chunk-CJLVYIOP.js";
9
12
  import {
10
13
  array,
11
14
  literal,
@@ -21,16 +24,16 @@ import {
21
24
  safeParse,
22
25
  string,
23
26
  trim
24
- } from "./chunk-JRFKCYMW.js";
27
+ } from "./chunk-OJSBWP3F.js";
25
28
  import {
26
29
  CliError,
27
30
  isCliError
28
- } from "./chunk-EA2OB75T.js";
31
+ } from "./chunk-4QNW4NK6.js";
29
32
  import {
30
33
  __name
31
34
  } from "./chunk-ZVVMGPBJ.js";
32
35
 
33
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/documents/blocks.js
36
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/documents/blocks.js
34
37
  var MARKS = ["bold", "italic", "strike", "code", "link"];
35
38
  var sameMarks = /* @__PURE__ */ __name((a, b) => MARKS.every((mark) => a[mark] === b[mark]), "sameMarks");
36
39
  var normalizeInlines = /* @__PURE__ */ __name((inlines) => {
@@ -78,7 +81,7 @@ var key = /* @__PURE__ */ __name((block, withChecked) => {
78
81
  var blockKey = /* @__PURE__ */ __name((block) => JSON.stringify(key(block, true)), "blockKey");
79
82
  var blockShape = /* @__PURE__ */ __name((block) => JSON.stringify(key(block, false)), "blockShape");
80
83
 
81
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/block-diff.js
84
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/block-diff.js
82
85
  var MAX_CELLS = 4e6;
83
86
  var matches = /* @__PURE__ */ __name((a, b, keyOf) => {
84
87
  const ka = a.map(keyOf);
@@ -224,7 +227,7 @@ var mergeBlocks = /* @__PURE__ */ __name((baseLocal, baseRemote, local, remote,
224
227
  return { status: "clean", blocks, conflicts };
225
228
  }, "mergeBlocks");
226
229
 
227
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/extraction.js
230
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/extraction.js
228
231
  var Proposal = object({
229
232
  kind: picklist(["summary", "digest", "fact", "preference"]),
230
233
  body: pipe(string(), trim(), minLength(1), maxLength(15e3)),
@@ -259,7 +262,7 @@ var extractMemories = /* @__PURE__ */ __name(async (text, complete) => {
259
262
  return { ...proposals, provider: answer.provider, model: answer.model, tokens: answer.tokens };
260
263
  }, "extractMemories");
261
264
 
262
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/ingestion.js
265
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/ingestion.js
263
266
  var documentIngestion = /* @__PURE__ */ __name((store, options) => {
264
267
  const folder = /* @__PURE__ */ __name(async (principal, create) => {
265
268
  if (options.provider)
@@ -270,28 +273,7 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
270
273
  const found = (await store.notes.folders()).find((item) => item.name === name);
271
274
  return found ?? (create ? await store.notes.addFolder({ name, format: "markdown" }) : void 0);
272
275
  }, "folder");
273
- const documents = /* @__PURE__ */ new Map();
274
- const cached = /* @__PURE__ */ __name(async (principal) => {
275
- const known = documents.get(principal);
276
- if (known)
277
- return known;
278
- const notes = /* @__PURE__ */ new Map();
279
- const selected = await folder(principal, false);
280
- if (selected) {
281
- for (let offset = 0; ; offset += 500) {
282
- const page = await store.notes.notes({ folderId: selected.id, source: "file", limit: 500, offset });
283
- for (const note of page.items)
284
- if (note.path)
285
- notes.set(note.path, note);
286
- if (!page.hasMore)
287
- break;
288
- if (offset >= 1e4)
289
- throw new CliError("provider_error", "local document listing exceeded its bound");
290
- }
291
- }
292
- documents.set(principal, notes);
293
- return notes;
294
- }, "cached");
276
+ const both = /* @__PURE__ */ __name((id) => [.../* @__PURE__ */ new Set([options.externalId(id), id])], "both");
295
277
  const stale = /* @__PURE__ */ __name(async (ref) => {
296
278
  for (const status of ["proposed", "confirmed"]) {
297
279
  for (let batch = 0; ; batch++) {
@@ -308,28 +290,28 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
308
290
  return {
309
291
  catalog: {
310
292
  import: /* @__PURE__ */ __name(async (principal, files) => {
311
- if (files.length > 1e4)
312
- throw new CliError("validation_error", "catalog scope exceeds 10000 entries", {
313
- reason: "catalog.scope-limit"
314
- });
315
293
  const selected = await folder(principal, true);
316
294
  if (!selected)
317
295
  throw new CliError("configuration_error", "catalog collection could not be registered");
318
296
  for (let start = 0; start < files.length; start += 200) {
319
- await store.catalog.upsert(selected.id, files.slice(start, start + 200).map(options.catalogInput));
320
- }
321
- for (const file of files) {
322
- const entry = await store.catalog.get(selected.id, options.externalId(file.id));
323
- if (entry)
324
- await options.observed?.(principal, file, entry.ref.slice("document:".length));
297
+ const chunk = files.slice(start, start + 200);
298
+ await store.catalog.upsert(selected.id, chunk.map(options.catalogInput));
299
+ if (options.observed)
300
+ for (const file of chunk) {
301
+ const entry = await store.catalog.get(selected.id, options.externalId(file.id));
302
+ if (entry)
303
+ await options.observed(principal, file, entry.ref.slice("document:".length));
304
+ }
325
305
  }
326
306
  const retired = await store.catalog.reconcile(selected.id, files.map((file) => options.externalId(file.id)));
327
- documents.delete(principal);
328
307
  return { entries: files.length, retired };
329
308
  }, "import"),
330
309
  get: /* @__PURE__ */ __name(async (principal, id) => {
331
310
  const selected = await folder(principal, false);
332
- return selected ? store.catalog.get(selected.id, options.externalId(id)) : void 0;
311
+ if (!selected)
312
+ return void 0;
313
+ const entry = await store.catalog.get(selected.id, options.externalId(id));
314
+ return entry ?? (options.externalId(id) === id ? void 0 : store.catalog.get(selected.id, id));
333
315
  }, "get"),
334
316
  list: /* @__PURE__ */ __name(async (principal, query = {}) => {
335
317
  const selected = await folder(principal, false);
@@ -342,23 +324,24 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
342
324
  return selected ? store.catalog.list(selected.id, {
343
325
  ...query,
344
326
  ...ast ? { ast } : {},
345
- ...query.parent === void 0 ? {} : { parent: options.externalId(query.parent) }
327
+ ...query.parent === void 0 ? {} : { parent: [query.parent].flat().flatMap(both) }
346
328
  }) : { items: [], hasMore: false };
347
329
  }, "list")
348
330
  },
349
331
  collection: folder,
332
+ // A store fake that predates `indexWritten` leaves the text for the next search to index.
333
+ settle: /* @__PURE__ */ __name(async ({ until }) => store.notes.indexWritten?.({ until }), "settle"),
350
334
  save: /* @__PURE__ */ __name(async (principal, content, hash) => {
351
335
  const selected = await folder(principal, true);
352
336
  if (!selected)
353
337
  throw new Error("folder registration failed");
354
- const notes = await cached(principal);
355
338
  const path = options.externalId(content.metadata.id);
356
- const before = notes.get(path);
339
+ const before = await store.notes.fileNote(selected.id, path);
357
340
  if (before && before.contentHash !== hash)
358
341
  await stale(before.ref);
359
342
  const { note } = await store.notes.saveFileNote({
360
343
  folderId: selected.id,
361
- path: options.externalId(content.metadata.id),
344
+ path,
362
345
  title: content.metadata.name,
363
346
  text: content.text,
364
347
  contentHash: hash,
@@ -366,27 +349,24 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
366
349
  });
367
350
  await store.catalog.upsert(selected.id, [options.catalogInput(content.metadata)]);
368
351
  await options.observed?.(principal, content.metadata, note.id);
369
- notes.set(path, note);
370
352
  return note.ref;
371
353
  }, "save"),
372
354
  remove: /* @__PURE__ */ __name(async (principal, id) => {
373
355
  const selected = await folder(principal, false);
374
356
  if (selected) {
375
- const notes = await cached(principal);
376
357
  const path = options.externalId(id);
377
- const note = notes.get(path);
358
+ const note = await store.notes.fileNote(selected.id, path);
378
359
  const retired = note ? void 0 : await store.catalog.get(selected.id, path, true);
379
360
  const ref = note?.ref ?? retired?.ref;
380
361
  if (ref)
381
362
  await stale(ref);
382
363
  await store.notes.deleteFileNotes(selected.id, [path]);
383
- notes.delete(path);
384
364
  }
385
365
  }, "remove")
386
366
  };
387
367
  }, "documentIngestion");
388
368
 
389
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/knowledge.js
369
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/knowledge.js
390
370
  var writer = /* @__PURE__ */ __name((by) => {
391
371
  if (by === void 0)
392
372
  throw new CliError("validation_error", "name who writes it: the owner or an agent; there is no default", {
@@ -541,10 +521,10 @@ var documentKnowledge = /* @__PURE__ */ __name((store, folder) => {
541
521
  return port;
542
522
  }, "documentKnowledge");
543
523
 
544
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/documents/markdown-blocks.js
524
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/documents/markdown-blocks.js
545
525
  var parser;
546
526
  var loadParser = /* @__PURE__ */ __name(() => parser ??= Promise.all([
547
- import("./mdast-util-from-markdown-CE73EWJ2.js"),
527
+ import("./mdast-util-from-markdown-FXEPSNER.js"),
548
528
  import("./mdast-util-gfm-SZM5GBDF.js"),
549
529
  import("./micromark-extension-gfm-GRL24TU6.js")
550
530
  ]).then(([{ fromMarkdown }, { gfmFromMarkdown }, { gfm }]) => (markdown) => fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] })), "loadParser");
@@ -666,7 +646,7 @@ var placedMarkdownBlocks = /* @__PURE__ */ __name(async (markdown) => {
666
646
  return blocks(tree.children);
667
647
  }, "placedMarkdownBlocks");
668
648
 
669
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/markdown-splice.js
649
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/markdown-splice.js
670
650
  var escapeText = /* @__PURE__ */ __name((text) => text.replace(/[\\`*_[\]<>~|]/g, "\\$&"), "escapeText");
671
651
  var codeSpan = /* @__PURE__ */ __name((text) => {
672
652
  const longest = (text.match(/`+/g) ?? []).reduce((most, run) => Math.max(most, run.length), 0);
@@ -852,15 +832,15 @@ var columnsBefore = /* @__PURE__ */ __name((placed, index) => {
852
832
  return columns;
853
833
  }, "columnsBefore");
854
834
 
855
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
835
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
856
836
  import { watch } from "node:fs";
857
837
 
858
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
838
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
859
839
  import { createHash as createHash2 } from "node:crypto";
860
840
  import { mkdirSync, readFileSync } from "node:fs";
861
841
  import { join as join2 } from "node:path";
862
842
 
863
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/push.js
843
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/push.js
864
844
  import { createHash, randomUUID } from "node:crypto";
865
845
  import { createReadStream } from "node:fs";
866
846
  import { chmod, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
@@ -1112,7 +1092,7 @@ var pushDocuments = /* @__PURE__ */ __name(async (options) => {
1112
1092
  return result;
1113
1093
  }, "pushDocuments");
1114
1094
 
1115
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
1095
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/mirrors.js
1116
1096
  var mirrorId = /* @__PURE__ */ __name((root, folder) => createHash2("sha256").update(JSON.stringify([root, folder])).digest("hex").slice(0, 8), "mirrorId");
1117
1097
  var ID = pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/));
1118
1098
  var stateSchema = /* @__PURE__ */ __name((kinds) => object({
@@ -1234,7 +1214,7 @@ var syncMirrors = /* @__PURE__ */ __name(async (options) => {
1234
1214
  };
1235
1215
  }, "syncMirrors");
1236
1216
 
1237
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
1217
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/mirror-watch.js
1238
1218
  var sleep = /* @__PURE__ */ __name((milliseconds, signal) => new Promise((resolve) => {
1239
1219
  const finish = /* @__PURE__ */ __name(() => {
1240
1220
  clearTimeout(timer);
@@ -1373,7 +1353,7 @@ async function* watchMirrors(sync, options) {
1373
1353
  }
1374
1354
  __name(watchMirrors, "watchMirrors");
1375
1355
 
1376
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/proposals.js
1356
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/proposals.js
1377
1357
  var extractDocumentMemories = /* @__PURE__ */ __name(async (options) => {
1378
1358
  const source = options.read();
1379
1359
  const text = options.tab ? source.snapshot.tabs.find((tab) => tab.id === options.tab)?.text : source.snapshot.text;
@@ -1423,10 +1403,10 @@ Snapshot: ${source.hash}`;
1423
1403
  };
1424
1404
  }, "extractDocumentMemories");
1425
1405
 
1426
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1406
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1427
1407
  import { createHash as createHash4 } from "node:crypto";
1428
1408
 
1429
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/documents/scope.js
1409
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/documents/scope.js
1430
1410
  var within = /* @__PURE__ */ __name((file, roots, folders, seen = /* @__PURE__ */ new Set()) => {
1431
1411
  if (file.trashed)
1432
1412
  return false;
@@ -1448,7 +1428,7 @@ var inScope = /* @__PURE__ */ __name((file, roots, folders, matched = /* @__PURE
1448
1428
  return matched.has(file.id) || within(file, roots, folders);
1449
1429
  }, "inScope");
1450
1430
 
1451
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/documents/catalog.js
1431
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/documents/catalog.js
1452
1432
  var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1453
1433
  const folders = state.pending?.folders ?? state.folders;
1454
1434
  const matched = new Set(state.pending?.matched ?? state.matched ?? []);
@@ -1467,134 +1447,85 @@ var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1467
1447
  return [...files.values()].filter((file) => inScope(file, roots, folders, matched, query));
1468
1448
  }, "catalogFiles");
1469
1449
 
1470
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/plan.js
1450
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/plan.js
1471
1451
  import { createHash as createHash3 } from "node:crypto";
1472
- var scopeHash = /* @__PURE__ */ __name((roots, query) => createHash3("sha256").update(JSON.stringify(query ? [[...roots].sort(), query.mode, query.key] : [...roots].sort())).digest("hex"), "scopeHash");
1452
+ 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");
1473
1453
  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");
1474
1454
  var SAVE_EVERY_MS = 2e3;
1475
- var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots, limit, pictures, abandoned = [], walks) => {
1476
- const { isFolder, skipReason, retryable, maxEntries: MAX_ENTRIES, errorOf, query } = options;
1477
- const tooManyEntries = /* @__PURE__ */ __name(() => options.limitError?.() ?? new CliError("validation_error", `selected folders exceed the ${MAX_ENTRIES} entry limit`), "tooManyEntries");
1478
- const scope = scopeHash(roots, query);
1455
+ var changesScope = /* @__PURE__ */ __name((scope, cursor) => `${scope}:changes:${cursor}`, "changesScope");
1456
+ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots, limit, pictures, walks) => {
1457
+ const { isFolder, skipReason, retryable, maxEntries, errorOf, query, budget } = options;
1458
+ const scope = scopeHash(roots, query, options.isDocument !== void 0);
1479
1459
  if (!roots.length && query?.mode !== "include")
1480
1460
  return {
1481
- scope,
1482
- cursor: state.cursor ?? "",
1483
- folders: {},
1484
- skipped: [],
1485
- jobs: [.../* @__PURE__ */ new Set([...Object.keys(state.documents), ...abandoned])].map((id) => ({ id, kind: "remove" }))
1461
+ pending: {
1462
+ scope,
1463
+ cursor: state.cursor ?? "",
1464
+ folders: {},
1465
+ skipped: [],
1466
+ jobs: Object.keys(state.documents).map((id) => ({ id, kind: "remove" }))
1467
+ }
1486
1468
  };
1487
1469
  if (!source)
1488
1470
  throw new CliError("configuration_error", "selected folders or a saved query require an authenticated source");
1489
1471
  if (query?.mode === "include" && !query.list)
1490
1472
  throw new CliError("configuration_error", "a query that includes files must list them");
1491
- const found = query?.mode === "include" && query.list ? await query.list() : [];
1492
1473
  const initial = !state.cursor || scope !== state.scope;
1493
- const resumed = initial ? walks?.read(scope) : void 0;
1494
- const cursor = initial ? resumed?.cursor ?? await source.startToken() : state.cursor;
1474
+ const resumed = walks?.read(initial ? scope : changesScope(scope, state.cursor));
1495
1475
  const folders = initial ? {} : structuredClone(state.folders);
1496
1476
  const files = new Map(Object.values(state.documents).map((doc) => [doc.metadata.id, doc.metadata]));
1497
1477
  const changed = /* @__PURE__ */ new Set();
1478
+ const delta = /* @__PURE__ */ new Map();
1498
1479
  for (const skipped2 of state.skipped)
1499
1480
  if (skipped2.file)
1500
1481
  files.set(skipped2.id, skipped2.file);
1501
- const visited = /* @__PURE__ */ new Set();
1502
- let discovered = 0;
1503
- const crawl = /* @__PURE__ */ __name(async (folder, ancestry = /* @__PURE__ */ new Set()) => {
1504
- if (ancestry.has(folder.id))
1505
- throw new CliError("invalid_response", "folder traversal contains a cycle");
1506
- if (visited.has(folder.id))
1507
- return;
1508
- visited.add(folder.id);
1509
- folders[folder.id] = folder;
1510
- for (const file of await source.children(folder.id)) {
1511
- if (++discovered > MAX_ENTRIES)
1512
- throw tooManyEntries();
1513
- if (isFolder(file))
1514
- await crawl(file, /* @__PURE__ */ new Set([...ancestry, folder.id]));
1515
- else {
1516
- files.set(file.id, file);
1517
- changed.add(file.id);
1518
- }
1519
- }
1520
- }, "crawl");
1521
- let finalCursor = cursor;
1522
- if (initial) {
1482
+ if (initial)
1523
1483
  files.clear();
1524
- const walk = resumed ?? {
1484
+ const keep = /* @__PURE__ */ __name((file) => {
1485
+ files.set(file.id, file);
1486
+ changed.add(file.id);
1487
+ delta.set(file.id, file);
1488
+ }, "keep");
1489
+ const drop = /* @__PURE__ */ __name((id) => {
1490
+ const known = files.get(id);
1491
+ if (known)
1492
+ delta.set(id, { ...known, trashed: true });
1493
+ files.delete(id);
1494
+ }, "drop");
1495
+ const container = /* @__PURE__ */ __name((file) => {
1496
+ if (options.isDocument?.(file))
1497
+ keep(file);
1498
+ }, "container");
1499
+ const walked = /* @__PURE__ */ __name((id) => !initial && state.folders[id] !== void 0 && !state.folders[id]?.trashed, "walked");
1500
+ let walk = resumed;
1501
+ let cursor = state.cursor ?? "";
1502
+ if (!walk && initial) {
1503
+ const start = await source.startToken();
1504
+ walk = {
1525
1505
  scope,
1526
- cursor,
1506
+ cursor: start,
1527
1507
  stack: [...roots].reverse().map((id) => ({ id, ancestry: [] })),
1528
1508
  visited: [],
1529
1509
  folders: {},
1530
1510
  files: [],
1531
1511
  discovered: 0
1532
1512
  };
1533
- for (const id of walk.visited)
1534
- visited.add(id);
1535
- Object.assign(folders, walk.folders);
1536
- for (const file of walk.files) {
1537
- files.set(file.id, file);
1538
- changed.add(file.id);
1539
- }
1540
- discovered = walk.discovered;
1541
- let savedAt = (options.now ?? Date.now)();
1542
- const record2 = /* @__PURE__ */ __name(() => {
1543
- walks?.save({ ...walk, visited: [...visited], folders, files: [...files.values()], discovered });
1544
- savedAt = (options.now ?? Date.now)();
1545
- }, "record");
1546
- try {
1547
- for (let step = walk.stack.at(-1); step; step = walk.stack.at(-1)) {
1548
- if (step.ancestry.includes(step.id))
1549
- throw new CliError("invalid_response", "folder traversal contains a cycle");
1550
- if (visited.has(step.id)) {
1551
- walk.stack.pop();
1552
- continue;
1553
- }
1554
- const folder = step.folder ?? await source.metadata(step.id);
1555
- if (!step.folder && (!isFolder(folder) || folder.trashed))
1556
- throw new CliError("validation_error", "configured root is not an accessible folder");
1557
- const children = await source.children(folder.id);
1558
- if (discovered + children.length > MAX_ENTRIES)
1559
- throw tooManyEntries();
1560
- discovered += children.length;
1561
- walk.stack.pop();
1562
- visited.add(folder.id);
1563
- folders[folder.id] = folder;
1564
- const nested = [];
1565
- for (const file of children)
1566
- if (isFolder(file))
1567
- nested.push({ id: file.id, ancestry: [...step.ancestry, folder.id], folder: file });
1568
- else {
1569
- files.set(file.id, file);
1570
- changed.add(file.id);
1571
- }
1572
- for (const entry of nested.reverse())
1573
- walk.stack.push(entry);
1574
- if ((options.now ?? Date.now)() - savedAt > SAVE_EVERY_MS)
1575
- record2();
1576
- }
1577
- } catch (error) {
1578
- record2();
1579
- throw error;
1580
- }
1581
- } else {
1513
+ } else if (!walk) {
1582
1514
  const page = await source.changes(cursor);
1583
- finalCursor = page.cursor;
1584
1515
  const latest = new Map(page.items.map((change) => [change.id, change]));
1585
1516
  const entering = [];
1586
1517
  for (const change of latest.values()) {
1587
1518
  if (change.removed || change.file?.trashed) {
1588
- files.delete(change.id);
1519
+ drop(change.id);
1589
1520
  if (folders[change.id])
1590
1521
  folders[change.id] = { ...folders[change.id], trashed: true };
1591
1522
  } else if (change.file && isFolder(change.file)) {
1592
1523
  folders[change.id] = change.file;
1593
1524
  entering.push(change.file);
1594
- } else if (change.file) {
1595
- files.set(change.id, change.file);
1596
- changed.add(change.id);
1597
- } else if (state.documents[change.id] || folders[change.id])
1525
+ container(change.file);
1526
+ } else if (change.file)
1527
+ keep(change.file);
1528
+ else if (state.documents[change.id] || folders[change.id])
1598
1529
  throw new CliError("invalid_response", "known source changed without metadata; checkpoint preserved");
1599
1530
  }
1600
1531
  for (const root of roots) {
@@ -1613,16 +1544,132 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1613
1544
  folders[root] = { ...previous, trashed: true };
1614
1545
  }
1615
1546
  }
1616
- for (const folder of entering)
1617
- if (!visited.has(folder.id) && within(folder, roots, folders))
1618
- await crawl(folder);
1547
+ const stack = entering.filter((folder) => within(folder, roots, folders)).reverse().map((folder) => ({ id: folder.id, ancestry: [], folder }));
1548
+ if (stack.length)
1549
+ walk = {
1550
+ scope: changesScope(scope, cursor),
1551
+ cursor: page.cursor,
1552
+ stack,
1553
+ visited: [],
1554
+ folders: {},
1555
+ files: [],
1556
+ discovered: 0
1557
+ };
1558
+ else
1559
+ cursor = page.cursor;
1619
1560
  }
1561
+ const vanished = /* @__PURE__ */ __name(async (id) => {
1562
+ try {
1563
+ return (await source.metadata(id)).trashed;
1564
+ } catch (error) {
1565
+ return errorOf(error).code === "not_found";
1566
+ }
1567
+ }, "vanished");
1568
+ let found = [];
1569
+ if (walk) {
1570
+ const visited = new Set(walk.visited);
1571
+ Object.assign(folders, walk.folders);
1572
+ for (const file of walk.files) {
1573
+ if (file.trashed)
1574
+ drop(file.id);
1575
+ else
1576
+ keep(file);
1577
+ }
1578
+ cursor = walk.cursor;
1579
+ const now = options.now ?? Date.now;
1580
+ let savedAt = now();
1581
+ const current = walk;
1582
+ const record2 = /* @__PURE__ */ __name(() => {
1583
+ walks?.save({ ...current, visited: [...visited], folders, files: [...delta.values()] });
1584
+ savedAt = now();
1585
+ }, "record");
1586
+ let spent = 0;
1587
+ let listed = 0;
1588
+ let stopped = null;
1589
+ try {
1590
+ for (let step = walk.stack.at(-1); step; step = walk.stack.at(-1)) {
1591
+ if (step.ancestry.includes(step.id))
1592
+ throw new CliError("invalid_response", "folder traversal contains a cycle");
1593
+ if (visited.has(step.id)) {
1594
+ walk.stack.pop();
1595
+ continue;
1596
+ }
1597
+ stopped = options.signal?.aborted ? "cancelled" : listed > 0 && spent >= maxEntries ? "entries" : budget?.take() ?? null;
1598
+ if (stopped)
1599
+ break;
1600
+ const folder = step.folder ?? await source.metadata(step.id);
1601
+ if (!step.folder && (!isFolder(folder) || folder.trashed))
1602
+ throw new CliError("validation_error", "configured root is not an accessible folder");
1603
+ if (!step.folder)
1604
+ container(folder);
1605
+ let children;
1606
+ let more;
1607
+ try {
1608
+ if (source.childrenPage)
1609
+ ({ files: children, cursor: more } = await source.childrenPage(folder.id, step.listing));
1610
+ else
1611
+ children = await source.children(folder.id);
1612
+ } catch (error) {
1613
+ if (errorOf(error).code !== "not_found")
1614
+ throw error;
1615
+ if (step.listing !== void 0) {
1616
+ delete step.listing;
1617
+ spent++;
1618
+ listed++;
1619
+ continue;
1620
+ }
1621
+ if (!await vanished(folder.id))
1622
+ throw error;
1623
+ walk.stack.pop();
1624
+ visited.add(folder.id);
1625
+ folders[folder.id] = { ...folder, trashed: true };
1626
+ drop(folder.id);
1627
+ spent++;
1628
+ listed++;
1629
+ continue;
1630
+ }
1631
+ spent += 1 + children.length;
1632
+ listed++;
1633
+ walk.discovered += children.length;
1634
+ folders[folder.id] = folder;
1635
+ const nested = [];
1636
+ for (const file of children)
1637
+ if (isFolder(file)) {
1638
+ container(file);
1639
+ if (walked(file.id))
1640
+ folders[file.id] = file;
1641
+ else
1642
+ nested.push({ id: file.id, ancestry: [...step.ancestry, folder.id], folder: file });
1643
+ } else
1644
+ keep(file);
1645
+ walk.stack.pop();
1646
+ for (const entry of nested.reverse())
1647
+ walk.stack.push(entry);
1648
+ if (more)
1649
+ walk.stack.push({ ...step, folder, listing: more });
1650
+ else
1651
+ visited.add(folder.id);
1652
+ if (now() - savedAt > SAVE_EVERY_MS)
1653
+ record2();
1654
+ }
1655
+ if (stopped) {
1656
+ record2();
1657
+ return {
1658
+ walk: { folders_left: walk.stack.length, entries: walk.discovered, listed, stopped }
1659
+ };
1660
+ }
1661
+ if (query?.mode === "include" && query.list)
1662
+ found = await query.list();
1663
+ } catch (error) {
1664
+ record2();
1665
+ throw error;
1666
+ }
1667
+ } else if (query?.mode === "include" && query.list)
1668
+ found = await query.list();
1620
1669
  const matched = /* @__PURE__ */ new Set();
1621
1670
  for (const file of found) {
1622
- if (isFolder(file) || file.trashed || !query?.matches(file) || matched.has(file.id))
1671
+ if (isFolder(file) && !options.isDocument?.(file) || file.trashed || !query?.matches(file) || matched.has(file.id))
1623
1672
  continue;
1624
- if (!files.has(file.id) && ++discovered > MAX_ENTRIES)
1625
- throw tooManyEntries();
1626
1673
  const prior = state.documents[file.id]?.metadata ?? state.skipped.find((item) => item.id === file.id)?.file;
1627
1674
  if (initial || !prior || changedSince(prior, file))
1628
1675
  changed.add(file.id);
@@ -1657,26 +1704,29 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1657
1704
  jobs.push({ id, kind: "save", file });
1658
1705
  }
1659
1706
  }
1660
- for (const id of /* @__PURE__ */ new Set([...Object.keys(state.documents), ...abandoned])) {
1707
+ for (const id of Object.keys(state.documents)) {
1661
1708
  const file = files.get(id);
1662
1709
  if (!file || !inScope(file, roots, folders, matched, query))
1663
1710
  jobs.push({ id, kind: "remove" });
1664
1711
  }
1665
1712
  const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => within(file, roots, folders) || roots.includes(file.id)));
1666
1713
  return {
1667
- scope,
1668
- cursor: finalCursor,
1669
- folders: scopedFolders,
1670
- jobs,
1671
- skipped,
1672
- ...query?.mode === "include" ? { matched: [...matched] } : {}
1714
+ pending: {
1715
+ scope,
1716
+ cursor,
1717
+ folders: scopedFolders,
1718
+ jobs,
1719
+ skipped,
1720
+ ...query?.mode === "include" ? { matched: [...matched] } : {}
1721
+ }
1673
1722
  };
1674
1723
  }, "planDocuments");
1675
1724
 
1676
- // node_modules/.pnpm/@wirecat+cli-core@0.662.0_@wirecat+cli-base@0.99.0_commander@15.0.0_esbuild@0.28.2_type_b96f03b0a44798bffec19d0b8a7273db/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1725
+ // node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/services/documents/sync.js
1677
1726
  var MAX_PICTURE_BYTES = 25 * 1024 * 1024;
1678
1727
  var SAVE_EVERY_MS2 = 2e3;
1679
1728
  var SAVE_EVERY_ITEMS = 25;
1729
+ var SETTLE_MS = 1e4;
1680
1730
  var isPicture = /* @__PURE__ */ __name((file) => file.mime.startsWith("image/") && file.canDownload, "isPicture");
1681
1731
  var hashText2 = /* @__PURE__ */ __name((text) => createHash4("sha256").update(text).digest("hex"), "hashText");
1682
1732
  var syncDocuments = /* @__PURE__ */ __name(async (options) => {
@@ -1696,6 +1746,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1696
1746
  pending: 0,
1697
1747
  skipped: [],
1698
1748
  errors: [],
1749
+ complete: true,
1699
1750
  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",
1700
1751
  ...profile.picture_search ? { pictures: 0 } : {}
1701
1752
  };
@@ -1709,19 +1760,34 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1709
1760
  const state = statePort.read();
1710
1761
  if (state.principal !== principal)
1711
1762
  throw new CliError("configuration_error", "sync state belongs to another source account");
1712
- const currentScope = scopeHash(profile.roots, query);
1713
- const abandoned = state.pending && (state.pending.scope !== currentScope || rescan) ? state.pending.jobs.map((job) => job.id) : [];
1714
- if (state.pending?.scope !== currentScope || rescan)
1763
+ const currentScope = scopeHash(profile.roots, query, options.isDocument !== void 0);
1764
+ if (state.pending && (state.pending.scope !== currentScope || rescan)) {
1765
+ for (const job of state.pending.jobs)
1766
+ if (!state.documents[job.id]) {
1767
+ await index.remove(profile.principal, job.id);
1768
+ statePort.removeSnapshot(job.id);
1769
+ }
1715
1770
  delete state.pending;
1771
+ statePort.save(state);
1772
+ }
1716
1773
  if (rescan) {
1717
1774
  delete state.cursor;
1718
1775
  statePort.removeWalk();
1776
+ statePort.save(state);
1719
1777
  }
1720
1778
  if (!state.pending) {
1721
- state.pending = await planDocuments(options, source, state, profile.roots, limit, profile.picture_search ?? false, abandoned, {
1779
+ const plan = await planDocuments(options, source, state, profile.roots, limit, profile.picture_search ?? false, {
1722
1780
  read: /* @__PURE__ */ __name((scope) => statePort.readWalk(scope), "read"),
1723
1781
  save: /* @__PURE__ */ __name((walk) => statePort.saveWalk(walk), "save")
1724
1782
  });
1783
+ if ("walk" in plan) {
1784
+ result.complete = false;
1785
+ result.stopped = plan.walk.stopped;
1786
+ result.walk = { folders_left: plan.walk.folders_left, entries: plan.walk.entries, listed: plan.walk.listed };
1787
+ result.skipped = state.skipped.map(({ id, reason }) => ({ id, reason }));
1788
+ return result;
1789
+ }
1790
+ state.pending = plan.pending;
1725
1791
  state.skipped = state.pending.skipped;
1726
1792
  statePort.save(state);
1727
1793
  statePort.removeWalk();
@@ -1806,6 +1872,11 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1806
1872
  } else {
1807
1873
  if (!source)
1808
1874
  throw new CliError("configuration_error", "a pending save requires source sign-in");
1875
+ const stop = options.budget?.take();
1876
+ if (stop) {
1877
+ result.stopped = stop;
1878
+ break;
1879
+ }
1809
1880
  const content = await source.content(job.id, limit);
1810
1881
  const listed = query?.mode === "include" && (pending.matched?.includes(job.id) ?? query.matches(content.metadata));
1811
1882
  if (!listed && !inScope(content.metadata, profile.roots, pending.folders, /* @__PURE__ */ new Set(), query)) {
@@ -1865,6 +1936,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1865
1936
  }
1866
1937
  flush();
1867
1938
  result.pending = pending.jobs.length;
1939
+ result.complete = !pending.jobs.length;
1868
1940
  if (!pending.jobs.length) {
1869
1941
  state.cursor = pending.cursor;
1870
1942
  state.scope = pending.scope;
@@ -1877,6 +1949,10 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1877
1949
  state.lastSync = new Date(now()).toISOString();
1878
1950
  statePort.save(state);
1879
1951
  }
1952
+ const settleFrom = Date.now();
1953
+ const settleUntil = Math.min(settleFrom + SETTLE_MS, options.deadline ? options.deadline.endsAt - deadlineMargin(options.deadline) : Number.POSITIVE_INFINITY);
1954
+ if (!result.stopped && !options.budget?.stopped && settleUntil > settleFrom)
1955
+ await index.settle?.({ until: /* @__PURE__ */ __name(() => signal?.aborted === true || Date.now() >= settleUntil, "until") }).catch(() => void 0);
1880
1956
  return result;
1881
1957
  } finally {
1882
1958
  flush?.();