@wirecat/drive-cli 0.70.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 (164) hide show
  1. package/README.md +3 -2
  2. package/dist/bin/drive.js +2 -2
  3. package/dist/bundle/{all-profiles-FW3GK3QO.js → all-profiles-3QJG2NAN.js} +13 -13
  4. package/dist/bundle/{anthropic-QVKJT3II.js → anthropic-PSWTEU6G.js} +8 -8
  5. package/dist/bundle/{app-server-QU73RD5R.js → app-server-PVTA6ABR.js} +62 -62
  6. package/dist/bundle/{bun-5XCD5CBB.js → bun-LU5LP3JI.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-TIGSVNSV.js → bun-sqlite-PYMKLBRU.js} +9 -9
  8. package/dist/bundle/{chunk-BFKFKDPC.js → chunk-22QQUKWA.js} +1 -1
  9. package/dist/bundle/{chunk-RLNZ7NX5.js → chunk-26DHFMGZ.js} +2 -2
  10. package/dist/bundle/{chunk-RHSBXOQM.js → chunk-2BVVU7GG.js} +1 -1
  11. package/dist/bundle/{chunk-ILAQIBEO.js → chunk-2LHAVY4U.js} +1 -1
  12. package/dist/bundle/{chunk-GAHIHE4K.js → chunk-2PUNKUYJ.js} +3177 -3043
  13. package/dist/bundle/{chunk-DHX27E5M.js → chunk-2UUWXPOB.js} +3 -3
  14. package/dist/bundle/{chunk-RCTOWLCD.js → chunk-35SCQ4VI.js} +26 -26
  15. package/dist/bundle/{chunk-ZCXWV4XO.js → chunk-3EBBLKIT.js} +4 -4
  16. package/dist/bundle/{chunk-SONPLYV7.js → chunk-3N2OFXB5.js} +5 -5
  17. package/dist/bundle/{chunk-KSJAFMU5.js → chunk-3UGYFXH6.js} +42 -19
  18. package/dist/bundle/{chunk-HK225DAG.js → chunk-4HWJOU7N.js} +1 -1
  19. package/dist/bundle/{chunk-6DPOWBKA.js → chunk-4PA4DHYV.js} +6 -6
  20. package/dist/bundle/{chunk-54NDYVZA.js → chunk-4QNW4NK6.js} +1 -1
  21. package/dist/bundle/{chunk-2SBC4DVV.js → chunk-6SJOTNHF.js} +4 -4
  22. package/dist/bundle/{chunk-VVN6GHAZ.js → chunk-6TNNT2MQ.js} +223 -126
  23. package/dist/bundle/{chunk-5JTB4URG.js → chunk-6W763DZN.js} +12 -12
  24. package/dist/bundle/{chunk-FVTKFIQH.js → chunk-6XFIITOG.js} +383 -349
  25. package/dist/bundle/{chunk-54BQWRJL.js → chunk-72C4YOCH.js} +7 -7
  26. package/dist/bundle/{chunk-3UWRAIWA.js → chunk-7PDHGZN4.js} +4 -4
  27. package/dist/bundle/{chunk-REM5WHHQ.js → chunk-ACUAV6VX.js} +56 -56
  28. package/dist/bundle/{chunk-IGNIUDI3.js → chunk-ASMMG72J.js} +40 -33
  29. package/dist/bundle/{chunk-DVI72ZQG.js → chunk-B5KSXHJ7.js} +1 -1
  30. package/dist/bundle/{chunk-6BMTW5A6.js → chunk-BKSQBBYG.js} +7 -7
  31. package/dist/bundle/{chunk-HRATXUFH.js → chunk-CJLVYIOP.js} +21 -21
  32. package/dist/bundle/{chunk-RQNRYF6D.js → chunk-COJSWDNU.js} +3 -3
  33. package/dist/bundle/{chunk-FONIFRYI.js → chunk-COOOO5B3.js} +4 -4
  34. package/dist/bundle/{chunk-EG62WVR2.js → chunk-D5TGYUVU.js} +6 -6
  35. package/dist/bundle/{chunk-LMJBQFW6.js → chunk-EOEU3AZN.js} +6 -6
  36. package/dist/bundle/{chunk-GV5DGHSA.js → chunk-FCS26CYQ.js} +4 -4
  37. package/dist/bundle/{chunk-BD2K2ONK.js → chunk-FJH7DJWK.js} +4 -4
  38. package/dist/bundle/{chunk-FADAOLGB.js → chunk-FP54WSIR.js} +4 -4
  39. package/dist/bundle/{chunk-PAPY6Q6H.js → chunk-FT3LN3HP.js} +1 -1
  40. package/dist/bundle/{chunk-WJK6KTCS.js → chunk-GBKNJWOZ.js} +8 -8
  41. package/dist/bundle/{chunk-GJZSVSV3.js → chunk-GOWXXYEF.js} +2 -2
  42. package/dist/bundle/{chunk-LINBDWJK.js → chunk-GPQ44Y2R.js} +2 -2
  43. package/dist/bundle/{chunk-3AHBZP33.js → chunk-GZ2D4KXG.js} +8 -8
  44. package/dist/bundle/{chunk-ZHZYGY5R.js → chunk-HKY7X6NY.js} +4 -4
  45. package/dist/bundle/{chunk-GPDPEHYX.js → chunk-HL52XXZX.js} +1 -1
  46. package/dist/bundle/{chunk-BBFXQPKD.js → chunk-HMS6EEQL.js} +3 -3
  47. package/dist/bundle/{chunk-FYPW7NMH.js → chunk-I4RWW3UD.js} +49 -4
  48. package/dist/bundle/{chunk-HWUPU6WX.js → chunk-ICDCAQ6K.js} +8 -8
  49. package/dist/bundle/{chunk-NP7LJATI.js → chunk-J5Q5FS2N.js} +17 -22
  50. package/dist/bundle/{chunk-I7YSHUPW.js → chunk-JDV7HNNQ.js} +13 -13
  51. package/dist/bundle/{chunk-BBRMDMIR.js → chunk-JZHBZOJR.js} +3 -3
  52. package/dist/bundle/{chunk-QBAOIMVB.js → chunk-KGERXYTV.js} +1 -1
  53. package/dist/bundle/{chunk-7IBENBCK.js → chunk-KGYVHPGE.js} +2 -2
  54. package/dist/bundle/{chunk-ABZ2NYDT.js → chunk-KYKW2W6X.js} +1 -1
  55. package/dist/bundle/{chunk-AV5UKJZM.js → chunk-L46C6HQ7.js} +12 -12
  56. package/dist/bundle/{chunk-3TCMANIM.js → chunk-LXKYKRHD.js} +11 -11
  57. package/dist/bundle/{chunk-DVVUJ254.js → chunk-MIA7P6FZ.js} +2 -2
  58. package/dist/bundle/{chunk-PR7XD2DI.js → chunk-MNLL5YLM.js} +2 -2
  59. package/dist/bundle/{chunk-Q5C6YKAY.js → chunk-OF422U5D.js} +10 -10
  60. package/dist/bundle/{chunk-HHAZ6DCY.js → chunk-OJSBWP3F.js} +6 -6
  61. package/dist/bundle/{chunk-EDO5LZVF.js → chunk-P7CUM5IB.js} +1 -1
  62. package/dist/bundle/{chunk-P7PLKNPX.js → chunk-PRW6SYA3.js} +157 -70
  63. package/dist/bundle/{chunk-7QSRODXM.js → chunk-Q7DOMFJ4.js} +6 -6
  64. package/dist/bundle/{chunk-HYXXMSVD.js → chunk-QETR5HIZ.js} +503 -416
  65. package/dist/bundle/{chunk-YZPE72GE.js → chunk-QFR2PNJN.js} +12 -12
  66. package/dist/bundle/{chunk-MXNQZAJQ.js → chunk-QNRRK3CN.js} +2 -2
  67. package/dist/bundle/{chunk-PN4JYURZ.js → chunk-QXC6IEH6.js} +45 -45
  68. package/dist/bundle/{chunk-WWE5GO6G.js → chunk-RESDD3Q4.js} +3 -3
  69. package/dist/bundle/{chunk-YCL3SK4T.js → chunk-RJOQH5YY.js} +39 -38
  70. package/dist/bundle/{chunk-7C5KENNU.js → chunk-RWDKMU74.js} +3 -3
  71. package/dist/bundle/{chunk-GK3BJMGK.js → chunk-SAKO3P4H.js} +1 -1
  72. package/dist/bundle/{chunk-FN3RXBO7.js → chunk-SDKQNOL5.js} +6 -6
  73. package/dist/bundle/{chunk-TGS5VPJD.js → chunk-SERXSCN3.js} +167 -206
  74. package/dist/bundle/{chunk-3UZ4OH22.js → chunk-TAFHYHKA.js} +18 -116
  75. package/dist/bundle/{chunk-YRUR3E3E.js → chunk-TAUBRNC5.js} +35 -35
  76. package/dist/bundle/{chunk-P77FL6RY.js → chunk-UDMNY63V.js} +20 -17
  77. package/dist/bundle/{chunk-IFTX7AQU.js → chunk-UTO2GO4P.js} +5 -5
  78. package/dist/bundle/{chunk-3CHW7JGR.js → chunk-WVDCCYS3.js} +17 -17
  79. package/dist/bundle/{chunk-OY7TNUEC.js → chunk-X4TIMMKJ.js} +1 -1
  80. package/dist/bundle/{chunk-TNKQDS5A.js → chunk-XF4EXO2C.js} +6 -6
  81. package/dist/bundle/{chunk-BXPC5TFG.js → chunk-XMMFBPGC.js} +2 -2
  82. package/dist/bundle/{chunk-FCSHWUMW.js → chunk-Y2NWGNUB.js} +5 -5
  83. package/dist/bundle/{chunk-ML3R2UHV.js → chunk-YJIGGUPI.js} +4 -4
  84. package/dist/bundle/{chunk-DR57KDAY.js → chunk-YMJ6IDGT.js} +6 -6
  85. package/dist/bundle/{chunk-F5KJWRF5.js → chunk-YPFWNVHV.js} +3 -3
  86. package/dist/bundle/{chunk-XZBA6FVH.js → chunk-YPNWIB6H.js} +3 -3
  87. package/dist/bundle/{chunk-GA3URWIF.js → chunk-YVI5SQPY.js} +1 -1
  88. package/dist/bundle/{chunk-T5D4OGDC.js → chunk-Z3KUSRCF.js} +2 -2
  89. package/dist/bundle/{chunk-4WK26MPY.js → chunk-Z56QFOBR.js} +1 -1
  90. package/dist/bundle/{chunk-7DJNURKV.js → chunk-ZCR3IRZ2.js} +8 -8
  91. package/dist/bundle/{chunk-XOL346TJ.js → chunk-ZM63SUHG.js} +2 -2
  92. package/dist/bundle/{chunk-66PL7P4C.js → chunk-ZZ32DXTH.js} +1 -1
  93. package/dist/bundle/{cli-K4D4DIGQ.js → cli-556DERZL.js} +68 -68
  94. package/dist/bundle/command-contract-VRTOAV6W.js +43 -0
  95. package/dist/bundle/{command-server-entry-WREK3QBB.js → command-server-entry-AYLGNZWD.js} +33 -33
  96. package/dist/bundle/{decode-SEETPKBH.js → decode-QU24MWMN.js} +8 -8
  97. package/dist/bundle/{dispatch-SQCEURVK.js → dispatch-4KODNOXV.js} +9 -9
  98. package/dist/bundle/drive.js +11 -11
  99. package/dist/bundle/{echarts-WZ5RKFCX.js → echarts-BXX4OQWC.js} +2 -2
  100. package/dist/bundle/{embed-B2UCRZZR.js → embed-KG27KG3D.js} +9 -9
  101. package/dist/bundle/{embedder-4R6Z7G7L.js → embedder-IPAVUQUV.js} +12 -12
  102. package/dist/bundle/entry-MVXQETWS.js +25 -0
  103. package/dist/bundle/{failure-CYNXH3RQ.js → failure-ESL7ETL4.js} +4 -4
  104. package/dist/bundle/first-run-4UVLW2WR.js +31 -0
  105. package/dist/bundle/first-screen-JAKAIINI.js +41 -0
  106. package/dist/bundle/google-22NXXJX5.js +45 -0
  107. package/dist/bundle/{google-api-SAND2F7L.js → google-api-VCDBSNOW.js} +70 -70
  108. package/dist/bundle/grants-MQMTVCRQ.js +118 -0
  109. package/dist/bundle/{identity-JVVGS4U6.js → identity-LOWMVGZY.js} +6 -6
  110. package/dist/bundle/{instructions-JSMTSB22.js → instructions-2VECIDXF.js} +1 -1
  111. package/dist/bundle/{login-6WG3YBDU.js → login-7GBONT7V.js} +76 -76
  112. package/dist/bundle/{mcp-VFIOZDVY.js → mcp-O6ACR2DX.js} +2 -2
  113. package/dist/bundle/meeting-combined-LVP4AZKA.js +27 -0
  114. package/dist/bundle/meeting-model-RAY5XDXZ.js +29 -0
  115. package/dist/bundle/{meeting-semantic-5U7JQCFF.js → meeting-semantic-G7PFOKU7.js} +10 -10
  116. package/dist/bundle/{node-VJMVHOWD.js → node-MPEQSFI3.js} +2 -2
  117. package/dist/bundle/{node-sqlite-DCNT3HVE.js → node-sqlite-OLQMAYB4.js} +10 -10
  118. package/dist/bundle/oauth-SGH2I2BY.js +22 -0
  119. package/dist/bundle/{open-NFOEHVW7.js → open-OXTE672W.js} +8 -8
  120. package/dist/bundle/{openai-D47WY7EC.js → openai-EB3TPIZY.js} +19 -19
  121. package/dist/bundle/{process-Q2FRU5VA.js → process-F6TKXWWA.js} +1 -1
  122. package/dist/bundle/{program-T2AJJQEM.js → program-4IFDZ7FM.js} +142 -125
  123. package/dist/bundle/{prompt-YJSDABXN.js → prompt-F5RRHPN2.js} +8 -8
  124. package/dist/bundle/{reasons-WEHPCSJX.js → reasons-UORHJDHK.js} +5 -5
  125. package/dist/bundle/{recognize-6OBEIEB3.js → recognize-DAVNZND3.js} +7 -7
  126. package/dist/bundle/{remote-3SL2QJ7T.js → remote-D5EYYIAU.js} +13 -13
  127. package/dist/bundle/{rerank-L6F5SLIB.js → rerank-CND2GVLZ.js} +10 -10
  128. package/dist/bundle/{serve-GYSWIWH4.js → serve-ZHSPUIGX.js} +12 -12
  129. package/dist/bundle/server-DUVJWP3Q.js +80 -0
  130. package/dist/bundle/{server-GWWP3RIT.js → server-YMAK4LHC.js} +54 -54
  131. package/dist/bundle/{services-BDQBRXT5.js → services-ZILSFJ6E.js} +47 -47
  132. package/dist/bundle/{sqlite-runtime-ZSZGAUYB.js → sqlite-runtime-S5VPMZQH.js} +9 -9
  133. package/dist/bundle/{start-BJ275RUK.js → start-CR6X25RT.js} +7 -7
  134. package/dist/bundle/{state-HLNGFI2T.js → state-YFPHVIIJ.js} +9 -9
  135. package/dist/bundle/{store-OSRTGYGI.js → store-CL4ZJZRI.js} +23 -23
  136. package/dist/bundle/{store-I43KZNJW.js → store-UODRT6X4.js} +25 -25
  137. package/dist/bundle/store-maintenance-command-DY5XIBWR.js +72 -0
  138. package/dist/bundle/tokens-AF7QOFOF.js +118 -0
  139. package/dist/config.d.ts.map +1 -1
  140. package/dist/config.js +2 -1
  141. package/dist/config.js.map +1 -1
  142. package/dist/sync.d.ts.map +1 -1
  143. package/dist/sync.js +1 -2
  144. package/dist/sync.js.map +1 -1
  145. package/dist/transcripts.d.ts +0 -6
  146. package/dist/transcripts.d.ts.map +1 -1
  147. package/dist/transcripts.js +0 -13
  148. package/dist/transcripts.js.map +1 -1
  149. package/dist/version.d.ts +1 -1
  150. package/dist/version.js +1 -1
  151. package/package.json +3 -3
  152. package/dist/bundle/command-contract-V3F452QI.js +0 -43
  153. package/dist/bundle/entry-ORZYRJ5N.js +0 -25
  154. package/dist/bundle/first-run-KAKA6KBY.js +0 -31
  155. package/dist/bundle/first-screen-R645UHRH.js +0 -41
  156. package/dist/bundle/google-BSO3YB7N.js +0 -45
  157. package/dist/bundle/grants-PLNFYARD.js +0 -118
  158. package/dist/bundle/meeting-combined-SUKMFK3F.js +0 -27
  159. package/dist/bundle/meeting-model-S4YGKIFI.js +0 -29
  160. package/dist/bundle/oauth-KCMNQ3ZP.js +0 -22
  161. package/dist/bundle/server-BI46BSRE.js +0 -80
  162. package/dist/bundle/store-maintenance-command-FO7LEVSL.js +0 -72
  163. package/dist/bundle/tokens-DB7O7QNB.js +0 -118
  164. /package/dist/bundle/{chunk-ZI3YTXSF.js → chunk-VKE77B3F.js} +0 -0
@@ -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-Q5C6YKAY.js";
8
+ } from "./chunk-OF422U5D.js";
6
9
  import {
7
10
  writeSecurely
8
- } from "./chunk-HRATXUFH.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-HHAZ6DCY.js";
27
+ } from "./chunk-OJSBWP3F.js";
25
28
  import {
26
29
  CliError,
27
30
  isCliError
28
- } from "./chunk-54NDYVZA.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.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
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.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
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.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
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.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
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,6 +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");
276
+ const both = /* @__PURE__ */ __name((id) => [.../* @__PURE__ */ new Set([options.externalId(id), id])], "both");
273
277
  const stale = /* @__PURE__ */ __name(async (ref) => {
274
278
  for (const status of ["proposed", "confirmed"]) {
275
279
  for (let batch = 0; ; batch++) {
@@ -304,7 +308,10 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
304
308
  }, "import"),
305
309
  get: /* @__PURE__ */ __name(async (principal, id) => {
306
310
  const selected = await folder(principal, false);
307
- 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));
308
315
  }, "get"),
309
316
  list: /* @__PURE__ */ __name(async (principal, query = {}) => {
310
317
  const selected = await folder(principal, false);
@@ -317,11 +324,13 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
317
324
  return selected ? store.catalog.list(selected.id, {
318
325
  ...query,
319
326
  ...ast ? { ast } : {},
320
- ...query.parent === void 0 ? {} : { parent: options.externalId(query.parent) }
327
+ ...query.parent === void 0 ? {} : { parent: [query.parent].flat().flatMap(both) }
321
328
  }) : { items: [], hasMore: false };
322
329
  }, "list")
323
330
  },
324
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"),
325
334
  save: /* @__PURE__ */ __name(async (principal, content, hash) => {
326
335
  const selected = await folder(principal, true);
327
336
  if (!selected)
@@ -357,7 +366,7 @@ var documentIngestion = /* @__PURE__ */ __name((store, options) => {
357
366
  };
358
367
  }, "documentIngestion");
359
368
 
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
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
361
370
  var writer = /* @__PURE__ */ __name((by) => {
362
371
  if (by === void 0)
363
372
  throw new CliError("validation_error", "name who writes it: the owner or an agent; there is no default", {
@@ -512,7 +521,7 @@ var documentKnowledge = /* @__PURE__ */ __name((store, folder) => {
512
521
  return port;
513
522
  }, "documentKnowledge");
514
523
 
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
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
516
525
  var parser;
517
526
  var loadParser = /* @__PURE__ */ __name(() => parser ??= Promise.all([
518
527
  import("./mdast-util-from-markdown-FXEPSNER.js"),
@@ -637,7 +646,7 @@ var placedMarkdownBlocks = /* @__PURE__ */ __name(async (markdown) => {
637
646
  return blocks(tree.children);
638
647
  }, "placedMarkdownBlocks");
639
648
 
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
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
641
650
  var escapeText = /* @__PURE__ */ __name((text) => text.replace(/[\\`*_[\]<>~|]/g, "\\$&"), "escapeText");
642
651
  var codeSpan = /* @__PURE__ */ __name((text) => {
643
652
  const longest = (text.match(/`+/g) ?? []).reduce((most, run) => Math.max(most, run.length), 0);
@@ -823,15 +832,15 @@ var columnsBefore = /* @__PURE__ */ __name((placed, index) => {
823
832
  return columns;
824
833
  }, "columnsBefore");
825
834
 
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
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
827
836
  import { watch } from "node:fs";
828
837
 
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
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
830
839
  import { createHash as createHash2 } from "node:crypto";
831
840
  import { mkdirSync, readFileSync } from "node:fs";
832
841
  import { join as join2 } from "node:path";
833
842
 
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
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
835
844
  import { createHash, randomUUID } from "node:crypto";
836
845
  import { createReadStream } from "node:fs";
837
846
  import { chmod, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
@@ -1083,7 +1092,7 @@ var pushDocuments = /* @__PURE__ */ __name(async (options) => {
1083
1092
  return result;
1084
1093
  }, "pushDocuments");
1085
1094
 
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
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
1087
1096
  var mirrorId = /* @__PURE__ */ __name((root, folder) => createHash2("sha256").update(JSON.stringify([root, folder])).digest("hex").slice(0, 8), "mirrorId");
1088
1097
  var ID = pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/));
1089
1098
  var stateSchema = /* @__PURE__ */ __name((kinds) => object({
@@ -1205,7 +1214,7 @@ var syncMirrors = /* @__PURE__ */ __name(async (options) => {
1205
1214
  };
1206
1215
  }, "syncMirrors");
1207
1216
 
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
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
1209
1218
  var sleep = /* @__PURE__ */ __name((milliseconds, signal) => new Promise((resolve) => {
1210
1219
  const finish = /* @__PURE__ */ __name(() => {
1211
1220
  clearTimeout(timer);
@@ -1344,7 +1353,7 @@ async function* watchMirrors(sync, options) {
1344
1353
  }
1345
1354
  __name(watchMirrors, "watchMirrors");
1346
1355
 
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
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
1348
1357
  var extractDocumentMemories = /* @__PURE__ */ __name(async (options) => {
1349
1358
  const source = options.read();
1350
1359
  const text = options.tab ? source.snapshot.tabs.find((tab) => tab.id === options.tab)?.text : source.snapshot.text;
@@ -1394,10 +1403,10 @@ Snapshot: ${source.hash}`;
1394
1403
  };
1395
1404
  }, "extractDocumentMemories");
1396
1405
 
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
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
1398
1407
  import { createHash as createHash4 } from "node:crypto";
1399
1408
 
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
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
1401
1410
  var within = /* @__PURE__ */ __name((file, roots, folders, seen = /* @__PURE__ */ new Set()) => {
1402
1411
  if (file.trashed)
1403
1412
  return false;
@@ -1419,7 +1428,7 @@ var inScope = /* @__PURE__ */ __name((file, roots, folders, matched = /* @__PURE
1419
1428
  return matched.has(file.id) || within(file, roots, folders);
1420
1429
  }, "inScope");
1421
1430
 
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
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
1423
1432
  var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1424
1433
  const folders = state.pending?.folders ?? state.folders;
1425
1434
  const matched = new Set(state.pending?.matched ?? state.matched ?? []);
@@ -1438,133 +1447,76 @@ var catalogFiles = /* @__PURE__ */ __name((state, roots, query) => {
1438
1447
  return [...files.values()].filter((file) => inScope(file, roots, folders, matched, query));
1439
1448
  }, "catalogFiles");
1440
1449
 
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
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
1442
1451
  import { createHash as createHash3 } from "node:crypto";
1443
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");
1444
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");
1445
1454
  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");
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;
1449
1458
  const scope = scopeHash(roots, query, options.isDocument !== void 0);
1450
1459
  if (!roots.length && query?.mode !== "include")
1451
1460
  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" }))
1461
+ pending: {
1462
+ scope,
1463
+ cursor: state.cursor ?? "",
1464
+ folders: {},
1465
+ skipped: [],
1466
+ jobs: Object.keys(state.documents).map((id) => ({ id, kind: "remove" }))
1467
+ }
1457
1468
  };
1458
1469
  if (!source)
1459
1470
  throw new CliError("configuration_error", "selected folders or a saved query require an authenticated source");
1460
1471
  if (query?.mode === "include" && !query.list)
1461
1472
  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
1473
  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;
1474
+ const resumed = walks?.read(initial ? scope : changesScope(scope, state.cursor));
1466
1475
  const folders = initial ? {} : structuredClone(state.folders);
1467
1476
  const files = new Map(Object.values(state.documents).map((doc) => [doc.metadata.id, doc.metadata]));
1468
1477
  const changed = /* @__PURE__ */ new Set();
1478
+ const delta = /* @__PURE__ */ new Map();
1469
1479
  for (const skipped2 of state.skipped)
1470
1480
  if (skipped2.file)
1471
1481
  files.set(skipped2.id, skipped2.file);
1482
+ if (initial)
1483
+ files.clear();
1472
1484
  const keep = /* @__PURE__ */ __name((file) => {
1473
1485
  files.set(file.id, file);
1474
1486
  changed.add(file.id);
1487
+ delta.set(file.id, file);
1475
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");
1476
1495
  const container = /* @__PURE__ */ __name((file) => {
1477
1496
  if (options.isDocument?.(file))
1478
1497
  keep(file);
1479
1498
  }, "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 ?? {
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 = {
1503
1505
  scope,
1504
- cursor,
1506
+ cursor: start,
1505
1507
  stack: [...roots].reverse().map((id) => ({ id, ancestry: [] })),
1506
1508
  visited: [],
1507
1509
  folders: {},
1508
1510
  files: [],
1509
1511
  discovered: 0
1510
1512
  };
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 {
1513
+ } else if (!walk) {
1561
1514
  const page = await source.changes(cursor);
1562
- finalCursor = page.cursor;
1563
1515
  const latest = new Map(page.items.map((change) => [change.id, change]));
1564
1516
  const entering = [];
1565
1517
  for (const change of latest.values()) {
1566
1518
  if (change.removed || change.file?.trashed) {
1567
- files.delete(change.id);
1519
+ drop(change.id);
1568
1520
  if (folders[change.id])
1569
1521
  folders[change.id] = { ...folders[change.id], trashed: true };
1570
1522
  } else if (change.file && isFolder(change.file)) {
@@ -1592,16 +1544,132 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1592
1544
  folders[root] = { ...previous, trashed: true };
1593
1545
  }
1594
1546
  }
1595
- for (const folder of entering)
1596
- if (!visited.has(folder.id) && within(folder, roots, folders))
1597
- 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;
1598
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();
1599
1669
  const matched = /* @__PURE__ */ new Set();
1600
1670
  for (const file of found) {
1601
1671
  if (isFolder(file) && !options.isDocument?.(file) || file.trashed || !query?.matches(file) || matched.has(file.id))
1602
1672
  continue;
1603
- if (!files.has(file.id) && ++discovered > MAX_ENTRIES)
1604
- throw tooManyEntries();
1605
1673
  const prior = state.documents[file.id]?.metadata ?? state.skipped.find((item) => item.id === file.id)?.file;
1606
1674
  if (initial || !prior || changedSince(prior, file))
1607
1675
  changed.add(file.id);
@@ -1636,26 +1704,29 @@ var planDocuments = /* @__PURE__ */ __name(async (options, source, state, roots,
1636
1704
  jobs.push({ id, kind: "save", file });
1637
1705
  }
1638
1706
  }
1639
- for (const id of /* @__PURE__ */ new Set([...Object.keys(state.documents), ...abandoned])) {
1707
+ for (const id of Object.keys(state.documents)) {
1640
1708
  const file = files.get(id);
1641
1709
  if (!file || !inScope(file, roots, folders, matched, query))
1642
1710
  jobs.push({ id, kind: "remove" });
1643
1711
  }
1644
1712
  const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => within(file, roots, folders) || roots.includes(file.id)));
1645
1713
  return {
1646
- scope,
1647
- cursor: finalCursor,
1648
- folders: scopedFolders,
1649
- jobs,
1650
- skipped,
1651
- ...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
+ }
1652
1722
  };
1653
1723
  }, "planDocuments");
1654
1724
 
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
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
1656
1726
  var MAX_PICTURE_BYTES = 25 * 1024 * 1024;
1657
1727
  var SAVE_EVERY_MS2 = 2e3;
1658
1728
  var SAVE_EVERY_ITEMS = 25;
1729
+ var SETTLE_MS = 1e4;
1659
1730
  var isPicture = /* @__PURE__ */ __name((file) => file.mime.startsWith("image/") && file.canDownload, "isPicture");
1660
1731
  var hashText2 = /* @__PURE__ */ __name((text) => createHash4("sha256").update(text).digest("hex"), "hashText");
1661
1732
  var syncDocuments = /* @__PURE__ */ __name(async (options) => {
@@ -1675,6 +1746,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1675
1746
  pending: 0,
1676
1747
  skipped: [],
1677
1748
  errors: [],
1749
+ complete: true,
1678
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",
1679
1751
  ...profile.picture_search ? { pictures: 0 } : {}
1680
1752
  };
@@ -1689,18 +1761,33 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1689
1761
  if (state.principal !== principal)
1690
1762
  throw new CliError("configuration_error", "sync state belongs to another source account");
1691
1763
  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)
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
+ }
1694
1770
  delete state.pending;
1771
+ statePort.save(state);
1772
+ }
1695
1773
  if (rescan) {
1696
1774
  delete state.cursor;
1697
1775
  statePort.removeWalk();
1776
+ statePort.save(state);
1698
1777
  }
1699
1778
  if (!state.pending) {
1700
- 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, {
1701
1780
  read: /* @__PURE__ */ __name((scope) => statePort.readWalk(scope), "read"),
1702
1781
  save: /* @__PURE__ */ __name((walk) => statePort.saveWalk(walk), "save")
1703
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;
1704
1791
  state.skipped = state.pending.skipped;
1705
1792
  statePort.save(state);
1706
1793
  statePort.removeWalk();
@@ -1785,6 +1872,11 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1785
1872
  } else {
1786
1873
  if (!source)
1787
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
+ }
1788
1880
  const content = await source.content(job.id, limit);
1789
1881
  const listed = query?.mode === "include" && (pending.matched?.includes(job.id) ?? query.matches(content.metadata));
1790
1882
  if (!listed && !inScope(content.metadata, profile.roots, pending.folders, /* @__PURE__ */ new Set(), query)) {
@@ -1844,6 +1936,7 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1844
1936
  }
1845
1937
  flush();
1846
1938
  result.pending = pending.jobs.length;
1939
+ result.complete = !pending.jobs.length;
1847
1940
  if (!pending.jobs.length) {
1848
1941
  state.cursor = pending.cursor;
1849
1942
  state.scope = pending.scope;
@@ -1856,6 +1949,10 @@ var syncDocuments = /* @__PURE__ */ __name(async (options) => {
1856
1949
  state.lastSync = new Date(now()).toISOString();
1857
1950
  statePort.save(state);
1858
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);
1859
1956
  return result;
1860
1957
  } finally {
1861
1958
  flush?.();