@wirecat/drive-cli 0.64.0 → 0.65.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 (182) hide show
  1. package/dist/bin/drive.js +2 -2
  2. package/dist/bundle/{all-profiles-BPPT2AK5.js → all-profiles-PD7GJHFA.js} +14 -13
  3. package/dist/bundle/{anthropic-JW6GOJUD.js → anthropic-PJKFON5H.js} +20 -11
  4. package/dist/bundle/{app-server-KAQIOJMZ.js → app-server-6ELQA6FJ.js} +59 -56
  5. package/dist/bundle/{bun-UT7GNTPV.js → bun-P54TGES2.js} +2 -2
  6. package/dist/bundle/{bun-sqlite-2OIVV3LS.js → bun-sqlite-TND5ZRJH.js} +12 -8
  7. package/dist/bundle/chunk-2AFI4KGI.js +185 -0
  8. package/dist/bundle/{chunk-WWCYTMAV.js → chunk-3HXNDF6Q.js} +2 -2
  9. package/dist/bundle/{chunk-46CD64J2.js → chunk-3ONWN3IA.js} +166 -53
  10. package/dist/bundle/{chunk-4YRENUB5.js → chunk-42G2XNPN.js} +2 -2
  11. package/dist/bundle/chunk-4AOINPN2.js +66 -0
  12. package/dist/bundle/{chunk-ZF6GUZCE.js → chunk-4EDWLR22.js} +1 -1
  13. package/dist/bundle/{chunk-BEZJA44H.js → chunk-4Y5YBFMS.js} +7 -7
  14. package/dist/bundle/{chunk-B7XBIOMR.js → chunk-54V4H6PM.js} +16 -16
  15. package/dist/bundle/{chunk-4CNTID2X.js → chunk-5XSBCMAF.js} +4 -4
  16. package/dist/bundle/{chunk-IDAK4DDK.js → chunk-6DCLZLGX.js} +1 -1
  17. package/dist/bundle/{chunk-G4KEKKDE.js → chunk-7AQGVX5O.js} +20 -20
  18. package/dist/bundle/{chunk-34BIDKF4.js → chunk-7TAP7Y2E.js} +508 -155
  19. package/dist/bundle/{chunk-BZ2ZKILM.js → chunk-A27UVLPK.js} +3 -3
  20. package/dist/bundle/{chunk-SIOIMO62.js → chunk-A4QNADEX.js} +57 -51
  21. package/dist/bundle/{chunk-FXBHOCJK.js → chunk-ADLS6FVG.js} +1 -1
  22. package/dist/bundle/{chunk-66AF4FBW.js → chunk-B2LPCHQN.js} +4 -4
  23. package/dist/bundle/{chunk-M73NNJ3X.js → chunk-CGQRZRTH.js} +2 -2
  24. package/dist/bundle/{chunk-KVW4XNKB.js → chunk-CWLL63JD.js} +107 -48
  25. package/dist/bundle/{chunk-CPMRM3GQ.js → chunk-D6Z43SOG.js} +1592 -335
  26. package/dist/bundle/{chunk-QXCKJUZY.js → chunk-D7WB54P7.js} +111 -27
  27. package/dist/bundle/{chunk-VT2UFYPJ.js → chunk-DA63E2UM.js} +13 -9
  28. package/dist/bundle/{chunk-2FEZ24DK.js → chunk-ECEP4SO3.js} +20 -20
  29. package/dist/bundle/{chunk-ZSZJLJIA.js → chunk-EHU6EYGO.js} +38 -28
  30. package/dist/bundle/{chunk-EJ4PNHPP.js → chunk-ELJUBPY4.js} +1 -1
  31. package/dist/bundle/{chunk-F2VDAG32.js → chunk-EM7NL5ES.js} +3 -3
  32. package/dist/bundle/{chunk-O2QO5UZC.js → chunk-EU5MD24W.js} +13 -13
  33. package/dist/bundle/{chunk-KIN6PDFE.js → chunk-EZ2OLYEK.js} +4 -4
  34. package/dist/bundle/{chunk-OH3K2E7X.js → chunk-F56DRBGY.js} +655 -1220
  35. package/dist/bundle/{chunk-VIJ6ACYB.js → chunk-FA6JNXCC.js} +8 -8
  36. package/dist/bundle/{chunk-KE4XPPRQ.js → chunk-FBHSWQU7.js} +1531 -136
  37. package/dist/bundle/{chunk-ZRZ4HTCK.js → chunk-GW3LBY3T.js} +51 -67
  38. package/dist/bundle/{chunk-6B37XO6B.js → chunk-HP3NT6JJ.js} +3 -3
  39. package/dist/bundle/{chunk-IX7NQJLY.js → chunk-I272E6UR.js} +9 -8
  40. package/dist/bundle/{chunk-5HSRQ53R.js → chunk-IBO23OID.js} +2 -2
  41. package/dist/bundle/{chunk-EZ6O3ST3.js → chunk-II4S2DBJ.js} +3 -3
  42. package/dist/bundle/{chunk-3NULZGQU.js → chunk-IKHOIXJR.js} +2 -2
  43. package/dist/bundle/{chunk-JRXFW7HE.js → chunk-IMHW7VIV.js} +5 -5
  44. package/dist/bundle/{chunk-USLZE36C.js → chunk-JMJIH6JH.js} +6 -6
  45. package/dist/bundle/{chunk-C7WBNOYW.js → chunk-JPPPLKAO.js} +26 -1
  46. package/dist/bundle/{chunk-EQEGJVO2.js → chunk-LMKPP2JP.js} +1 -1
  47. package/dist/bundle/{chunk-G3NULXOM.js → chunk-M7ELUGU6.js} +4 -4
  48. package/dist/bundle/{chunk-6G53ZFUT.js → chunk-MCPOZNWG.js} +1 -1
  49. package/dist/bundle/{chunk-EWGVDFPT.js → chunk-NI5PD5KM.js} +39203 -35871
  50. package/dist/bundle/{chunk-AHB4OJCI.js → chunk-NQ5XMSLA.js} +3678 -2049
  51. package/dist/bundle/chunk-NQRTKYJB.js +257 -0
  52. package/dist/bundle/{chunk-3J5KAFNA.js → chunk-O6K2E7OA.js} +3917 -3005
  53. package/dist/bundle/{chunk-J62DI53V.js → chunk-O7ZDCOZE.js} +1 -1
  54. package/dist/bundle/{chunk-XPXKD63J.js → chunk-OFJXHEFT.js} +13 -13
  55. package/dist/bundle/chunk-OWMZUWCM.js +109 -0
  56. package/dist/bundle/chunk-PHOL2DZM.js +138 -0
  57. package/dist/bundle/{chunk-KG2XKEHL.js → chunk-PLP5527C.js} +5 -5
  58. package/dist/bundle/{chunk-5ZBR55US.js → chunk-RNHGQ35R.js} +1 -1
  59. package/dist/bundle/{chunk-IK6KH3RE.js → chunk-RX5CJ55S.js} +1 -1
  60. package/dist/bundle/{chunk-K6BSB53R.js → chunk-SE352DBY.js} +1 -1
  61. package/dist/bundle/chunk-SEQWBZYH.js +18 -0
  62. package/dist/bundle/{chunk-LOMW6F2E.js → chunk-SIWXYB4E.js} +3734 -3448
  63. package/dist/bundle/{chunk-GW3U6OLD.js → chunk-SNLSEYJO.js} +1 -1
  64. package/dist/bundle/{chunk-UJR272CP.js → chunk-SS4LKLD7.js} +52 -605
  65. package/dist/bundle/{chunk-BEUAICUD.js → chunk-TMHF4BCL.js} +2 -2
  66. package/dist/bundle/{chunk-BDYWZ7JE.js → chunk-TOVWMURV.js} +30 -6
  67. package/dist/bundle/{chunk-N622LRPM.js → chunk-TTP4NOP3.js} +4 -4
  68. package/dist/bundle/chunk-UTNRBOEN.js +53 -0
  69. package/dist/bundle/{chunk-36GPBPWM.js → chunk-VDZY3L7U.js} +3 -1
  70. package/dist/bundle/chunk-VHQYWFWV.js +13 -0
  71. package/dist/bundle/{chunk-VPLFD5RJ.js → chunk-VLXWAH5E.js} +4 -4
  72. package/dist/bundle/{chunk-UIEA6FIV.js → chunk-VMAMRFFC.js} +23 -23
  73. package/dist/bundle/{chunk-HW4UPST2.js → chunk-W2XY6C5S.js} +2 -2
  74. package/dist/bundle/{chunk-P7DEGRZA.js → chunk-WRAUO5EJ.js} +22 -24
  75. package/dist/bundle/{chunk-QEAD2LF4.js → chunk-WRMJN6UQ.js} +3 -3
  76. package/dist/bundle/{chunk-UD55VB2N.js → chunk-WVJHZIDH.js} +3 -3
  77. package/dist/bundle/{chunk-B67BLRAI.js → chunk-X7YGGWXI.js} +1 -59
  78. package/dist/bundle/{chunk-EC2XGDKJ.js → chunk-XPWZSW6Y.js} +4 -4
  79. package/dist/bundle/{chunk-E2LBCCTG.js → chunk-XYE7XZPB.js} +5 -5
  80. package/dist/bundle/{chunk-TNV2FXVK.js → chunk-Y5PKRITX.js} +5 -5
  81. package/dist/bundle/{chunk-5OFA5EXE.js → chunk-Z2ADO6UA.js} +2 -2
  82. package/dist/bundle/{chunk-PBMSBCVB.js → chunk-ZD4MB7NH.js} +1 -1
  83. package/dist/bundle/{chunk-2W464HAE.js → chunk-ZILALBYQ.js} +4 -4
  84. package/dist/bundle/{chunk-OEVHZOHC.js → chunk-ZR2EJPMQ.js} +44 -15
  85. package/dist/bundle/command-contract-25E4PYMD.js +40 -0
  86. package/dist/bundle/command-server-entry-36JXYIJB.js +170 -0
  87. package/dist/bundle/{decode-HTOQ6S3V.js → decode-T5ZW57WZ.js} +8 -8
  88. package/dist/bundle/{dispatch-SH5SP6LA.js → dispatch-RMA2XFYA.js} +9 -9
  89. package/dist/bundle/drive.js +11 -11
  90. package/dist/bundle/{echarts-KFHB6SLX.js → echarts-KQ44LPSF.js} +2 -2
  91. package/dist/bundle/{embed-YATFB2PN.js → embed-Q7XST53J.js} +9 -9
  92. package/dist/bundle/{embedder-MQPDFGTJ.js → embedder-RWZSBVW2.js} +12 -12
  93. package/dist/bundle/entry-HPLW4QL2.js +25 -0
  94. package/dist/bundle/{failure-4FQL4XJI.js → failure-7NP4QPIN.js} +4 -4
  95. package/dist/bundle/first-run-RL3RKYZW.js +30 -0
  96. package/dist/bundle/first-screen-NX3TM2VJ.js +38 -0
  97. package/dist/bundle/google-DPD5N6AQ.js +42 -0
  98. package/dist/bundle/{google-api-QMFGCXBM.js → google-api-P5DRHD7L.js} +61 -55
  99. package/dist/bundle/grants-TX4MHLI4.js +109 -0
  100. package/dist/bundle/{identity-FYVDK4M2.js → identity-VDV6CHRW.js} +6 -6
  101. package/dist/bundle/{instructions-D3GF3B7M.js → instructions-Q45FVY6H.js} +1 -1
  102. package/dist/bundle/{login-COFZ2IWP.js → login-XKN3NI6X.js} +67 -61
  103. package/dist/bundle/{mcp-RKJG22KM.js → mcp-7KQUJNFN.js} +2 -2
  104. package/dist/bundle/{node-OFICOKX3.js → node-MSW565D3.js} +2 -2
  105. package/dist/bundle/{node-KM3CUABH.js → node-P4E63KXA.js} +9 -9
  106. package/dist/bundle/{node-sqlite-DNBTDOXD.js → node-sqlite-S74XVVHL.js} +13 -9
  107. package/dist/bundle/oauth-6R7AWAES.js +22 -0
  108. package/dist/bundle/{open-PTPR2YWX.js → open-P7UQG7XJ.js} +8 -8
  109. package/dist/bundle/{openai-2KV5LUW4.js → openai-DDHJ57KZ.js} +19 -40
  110. package/dist/bundle/{process-EAW6NST2.js → process-NMUB5SHK.js} +1 -1
  111. package/dist/bundle/{program-6UV5Q5YN.js → program-PJNWP6JW.js} +294 -137
  112. package/dist/bundle/{prompt-634TPMJK.js → prompt-VOSMK4C2.js} +8 -8
  113. package/dist/bundle/{reasons-DDWCEYSQ.js → reasons-KDAXOC5S.js} +5 -5
  114. package/dist/bundle/{recognize-SJO6QUDW.js → recognize-GZIY63HS.js} +7 -7
  115. package/dist/bundle/{remote-6JXZITKF.js → remote-V3YGN7LN.js} +10 -10
  116. package/dist/bundle/{rerank-MD5VOPQ6.js → rerank-XRU6AVN7.js} +10 -10
  117. package/dist/bundle/{serve-LZTROA2M.js → serve-NDOAFA57.js} +12 -12
  118. package/dist/bundle/{server-NSA3UAFY.js → server-BKGWJYMC.js} +46 -44
  119. package/dist/bundle/server-QD2MUJJZ.js +72 -0
  120. package/dist/bundle/{services-F5A6XQCV.js → services-TYDMFQCA.js} +101 -41
  121. package/dist/bundle/{sqlite-runtime-7YF6REKS.js → sqlite-runtime-UAFJKSJR.js} +9 -9
  122. package/dist/bundle/{start-MUFLE6FA.js → start-2ZLDP2OE.js} +7 -7
  123. package/dist/bundle/{state-UC54F3YZ.js → state-6SP27J2K.js} +9 -9
  124. package/dist/bundle/{store-J53YNAH6.js → store-4UUY545Q.js} +25 -18
  125. package/dist/bundle/{store-F5FJGWMR.js → store-EJN27MXI.js} +61 -28
  126. package/dist/bundle/store-maintenance-command-LETURZDC.js +60 -0
  127. package/dist/bundle/tokens-MTFJPTYT.js +107 -0
  128. package/dist/commands/config.d.ts.map +1 -1
  129. package/dist/commands/config.js +6 -5
  130. package/dist/commands/config.js.map +1 -1
  131. package/dist/commands/context.d.ts +4 -2
  132. package/dist/commands/context.d.ts.map +1 -1
  133. package/dist/commands/context.js.map +1 -1
  134. package/dist/commands/documents.d.ts +2 -0
  135. package/dist/commands/documents.d.ts.map +1 -1
  136. package/dist/commands/documents.js +39 -3
  137. package/dist/commands/documents.js.map +1 -1
  138. package/dist/config.d.ts +13 -0
  139. package/dist/config.d.ts.map +1 -1
  140. package/dist/config.js +32 -2
  141. package/dist/config.js.map +1 -1
  142. package/dist/documents-add.d.ts +49 -0
  143. package/dist/documents-add.d.ts.map +1 -0
  144. package/dist/documents-add.js +122 -0
  145. package/dist/documents-add.js.map +1 -0
  146. package/dist/errors.d.ts +1 -0
  147. package/dist/errors.d.ts.map +1 -1
  148. package/dist/errors.js +9 -1
  149. package/dist/errors.js.map +1 -1
  150. package/dist/knowledge.d.ts +1 -1
  151. package/dist/knowledge.d.ts.map +1 -1
  152. package/dist/knowledge.js +15 -17
  153. package/dist/knowledge.js.map +1 -1
  154. package/dist/model.d.ts +3 -0
  155. package/dist/model.d.ts.map +1 -1
  156. package/dist/model.js.map +1 -1
  157. package/dist/program.d.ts.map +1 -1
  158. package/dist/program.js +22 -15
  159. package/dist/program.js.map +1 -1
  160. package/dist/reasons.d.ts.map +1 -1
  161. package/dist/reasons.js +25 -0
  162. package/dist/reasons.js.map +1 -1
  163. package/dist/store.d.ts.map +1 -1
  164. package/dist/store.js +20 -0
  165. package/dist/store.js.map +1 -1
  166. package/dist/version.d.ts +1 -1
  167. package/dist/version.js +1 -1
  168. package/package.json +4 -4
  169. package/dist/bundle/chunk-DD7EFG6B.js +0 -35
  170. package/dist/bundle/chunk-GSMYXGFR.js +0 -62
  171. package/dist/bundle/command-contract-H5OYJOPF.js +0 -38
  172. package/dist/bundle/entry-YZBB647C.js +0 -22
  173. package/dist/bundle/first-run-5JT3UQZB.js +0 -30
  174. package/dist/bundle/first-screen-BEMDEWO7.js +0 -36
  175. package/dist/bundle/google-DVADVICN.js +0 -36
  176. package/dist/bundle/grants-WKB2E4TA.js +0 -103
  177. package/dist/bundle/oauth-PDQHWFBF.js +0 -22
  178. package/dist/bundle/server-GT7X666D.js +0 -69
  179. package/dist/bundle/store-maintenance-command-GJVXLBAB.js +0 -58
  180. package/dist/bundle/tokens-H2EJKGA5.js +0 -101
  181. package/dist/bundle/{chunk-SW6C6WH5.js → chunk-YVNHQFLC.js} +0 -0
  182. package/dist/bundle/{mdast-util-from-markdown-FXEPSNER.js → mdast-util-from-markdown-CE73EWJ2.js} +3 -3
@@ -3,7 +3,7 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  answerOf,
5
5
  messengerContext
6
- } from "./chunk-UJR272CP.js";
6
+ } from "./chunk-SS4LKLD7.js";
7
7
  import {
8
8
  chatEventAnswer,
9
9
  memberAnswer,
@@ -12,11 +12,45 @@ import {
12
12
  serveRelay,
13
13
  typedQuery,
14
14
  withQuery
15
- } from "./chunk-P7DEGRZA.js";
15
+ } from "./chunk-WRAUO5EJ.js";
16
+ import {
17
+ FETCHING,
18
+ RULES_VERSION,
19
+ applyTaskRulesOnArrival,
20
+ capability,
21
+ newSendId,
22
+ onlineDeps,
23
+ openRequestTask,
24
+ patiently,
25
+ senderIsMe,
26
+ servicesFor,
27
+ syncsOneChat
28
+ } from "./chunk-O6K2E7OA.js";
29
+ import {
30
+ embeddingKeys,
31
+ endpointKeyName,
32
+ modelGateway,
33
+ withTimeLimit
34
+ } from "./chunk-FBHSWQU7.js";
16
35
  import {
17
36
  stringWidth,
18
37
  wrapAnsi
19
38
  } from "./chunk-HTQTIKWP.js";
39
+ import {
40
+ holdLock,
41
+ lockPath,
42
+ releaseLock,
43
+ servingProfiles,
44
+ takeLock
45
+ } from "./chunk-EM7NL5ES.js";
46
+ import {
47
+ QUICK_HEALTH_CHECKS,
48
+ fts5Tables,
49
+ invalidJson,
50
+ lossUnknown,
51
+ storeDamageReport,
52
+ storeHealth
53
+ } from "./chunk-CWLL63JD.js";
20
54
  import {
21
55
  Command,
22
56
  LOCAL_READ,
@@ -38,50 +72,21 @@ import {
38
72
  snakeKeys,
39
73
  storeTable,
40
74
  withoutProviderRefs
41
- } from "./chunk-LOMW6F2E.js";
42
- import {
43
- holdLock,
44
- lockPath,
45
- releaseLock,
46
- servingProfiles,
47
- takeLock
48
- } from "./chunk-F2VDAG32.js";
49
- import {
50
- holdersOf
51
- } from "./chunk-J62DI53V.js";
52
- import {
53
- FETCHING,
54
- RULES_VERSION,
55
- applyTaskRulesOnArrival,
56
- capability,
57
- embeddingKeys,
58
- endpointKeyName,
59
- modelGateway,
60
- newSendId,
61
- onlineDeps,
62
- openRequestTask,
63
- patiently,
64
- senderIsMe,
65
- servicesFor,
66
- syncsOneChat
67
- } from "./chunk-3J5KAFNA.js";
68
- import {
69
- withTimeLimit
70
- } from "./chunk-KE4XPPRQ.js";
75
+ } from "./chunk-SIWXYB4E.js";
71
76
  import {
72
77
  codeOf,
73
- currentRun,
74
78
  levelFor,
75
- modelTarget,
76
79
  parseDuration
77
- } from "./chunk-OH3K2E7X.js";
80
+ } from "./chunk-F56DRBGY.js";
78
81
  import {
79
- QUICK_HEALTH_CHECKS,
80
- explainDamage,
81
- fts5Tables,
82
- invalidJson,
83
- storeHealth
84
- } from "./chunk-KVW4XNKB.js";
82
+ modelTarget
83
+ } from "./chunk-OWMZUWCM.js";
84
+ import {
85
+ holdersOf
86
+ } from "./chunk-O7ZDCOZE.js";
87
+ import {
88
+ readSecret
89
+ } from "./chunk-HP3NT6JJ.js";
85
90
  import {
86
91
  CORPORA,
87
92
  MIGRATIONS,
@@ -94,14 +99,13 @@ import {
94
99
  fillStems,
95
100
  fillTrigrams,
96
101
  fillVectorIndexes,
97
- formatLocator,
98
102
  involvementStoreOver,
103
+ isDerivedTable,
99
104
  migrate,
100
105
  noteIndexState,
101
106
  openSqlite,
102
107
  openStore,
103
108
  orphanPointers,
104
- parseLocator,
105
109
  pendingNormalization,
106
110
  readStoreTables,
107
111
  rebuildMentions,
@@ -117,36 +121,37 @@ import {
117
121
  storeClients,
118
122
  storeContents,
119
123
  vectorIndexCounts
120
- } from "./chunk-EWGVDFPT.js";
124
+ } from "./chunk-NI5PD5KM.js";
125
+ import {
126
+ openCache
127
+ } from "./chunk-JMJIH6JH.js";
121
128
  import {
129
+ currentRun,
130
+ formatLocator,
131
+ parseLocator,
122
132
  readDamageMark,
123
133
  readHealthMark,
134
+ readJournalMark,
124
135
  recordDeepCheck
125
- } from "./chunk-CPMRM3GQ.js";
136
+ } from "./chunk-D6Z43SOG.js";
126
137
  import {
127
138
  queryFieldsOf
128
- } from "./chunk-2FEZ24DK.js";
139
+ } from "./chunk-ECEP4SO3.js";
129
140
  import {
130
141
  failureKey,
131
142
  isStoreDamage
132
- } from "./chunk-B67BLRAI.js";
143
+ } from "./chunk-4AOINPN2.js";
133
144
  import {
134
145
  storePath
135
- } from "./chunk-DD7EFG6B.js";
136
- import {
137
- openCache
138
- } from "./chunk-USLZE36C.js";
139
- import {
140
- readSecret
141
- } from "./chunk-6B37XO6B.js";
146
+ } from "./chunk-UTNRBOEN.js";
142
147
  import {
143
148
  resolvePaths,
144
149
  writeSecurely
145
- } from "./chunk-G4KEKKDE.js";
150
+ } from "./chunk-7AQGVX5O.js";
146
151
  import {
147
152
  singleLine,
148
153
  visibleControls
149
- } from "./chunk-IDAK4DDK.js";
154
+ } from "./chunk-6DCLZLGX.js";
150
155
  import {
151
156
  array,
152
157
  boolean,
@@ -167,10 +172,10 @@ import {
167
172
  string,
168
173
  transform,
169
174
  trim
170
- } from "./chunk-BDYWZ7JE.js";
175
+ } from "./chunk-TOVWMURV.js";
171
176
  import {
172
177
  CliError
173
- } from "./chunk-EJ4PNHPP.js";
178
+ } from "./chunk-ELJUBPY4.js";
174
179
  import {
175
180
  __commonJS,
176
181
  __name,
@@ -1824,7 +1829,7 @@ var require_liquid_node = __commonJS({
1824
1829
  return readFileAsync(filepath, "utf8");
1825
1830
  }
1826
1831
  __name(readFile, "readFile");
1827
- function existsSync10(filepath) {
1832
+ function existsSync11(filepath) {
1828
1833
  try {
1829
1834
  fs$1.statSync(filepath);
1830
1835
  return true;
@@ -1832,11 +1837,11 @@ var require_liquid_node = __commonJS({
1832
1837
  return false;
1833
1838
  }
1834
1839
  }
1835
- __name(existsSync10, "existsSync");
1836
- function readFileSync5(filepath) {
1840
+ __name(existsSync11, "existsSync");
1841
+ function readFileSync6(filepath) {
1837
1842
  return fs$1.readFileSync(filepath, "utf8");
1838
1843
  }
1839
- __name(readFileSync5, "readFileSync");
1844
+ __name(readFileSync6, "readFileSync");
1840
1845
  function resolve2(root, file2, ext) {
1841
1846
  if (!path.extname(file2))
1842
1847
  file2 += ext;
@@ -1850,10 +1855,10 @@ var require_liquid_node = __commonJS({
1850
1855
  }
1851
1856
  }
1852
1857
  __name(fallback, "fallback");
1853
- function dirname3(filepath) {
1858
+ function dirname4(filepath) {
1854
1859
  return path.dirname(filepath);
1855
1860
  }
1856
- __name(dirname3, "dirname");
1861
+ __name(dirname4, "dirname");
1857
1862
  var realpathAsync = promisify(fs$1.realpath);
1858
1863
  async function contains(root, file2) {
1859
1864
  try {
@@ -1881,11 +1886,11 @@ var require_liquid_node = __commonJS({
1881
1886
  __proto__: null,
1882
1887
  exists,
1883
1888
  readFile,
1884
- existsSync: existsSync10,
1885
- readFileSync: readFileSync5,
1889
+ existsSync: existsSync11,
1890
+ readFileSync: readFileSync6,
1886
1891
  resolve: resolve2,
1887
1892
  fallback,
1888
- dirname: dirname3,
1893
+ dirname: dirname4,
1889
1894
  contains,
1890
1895
  containsSync,
1891
1896
  sep: path.sep
@@ -3610,7 +3615,7 @@ var require_liquid_node = __commonJS({
3610
3615
  uri_escape,
3611
3616
  slugify
3612
3617
  });
3613
- var join5 = argumentsToValue(function(v, arg) {
3618
+ var join6 = argumentsToValue(function(v, arg) {
3614
3619
  const array2 = toArray(v);
3615
3620
  const sep = isNil(arg) ? " " : stringify(arg);
3616
3621
  let outputSize = sep.length * Math.max(array2.length - 1, 0);
@@ -3886,7 +3891,7 @@ var require_liquid_node = __commonJS({
3886
3891
  __name(sample, "sample");
3887
3892
  var arrayFilters = /* @__PURE__ */ Object.freeze({
3888
3893
  __proto__: null,
3889
- join: join5,
3894
+ join: join6,
3890
3895
  last,
3891
3896
  first,
3892
3897
  reverse,
@@ -5510,11 +5515,11 @@ var require_liquid_node = __commonJS({
5510
5515
  }
5511
5516
  });
5512
5517
 
5513
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5514
- import { chmodSync, constants, copyFileSync, existsSync as existsSync9, mkdirSync, realpathSync as realpathSync2, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
5515
- import { dirname as dirname2, resolve } from "node:path";
5518
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5519
+ import { chmodSync, constants, copyFileSync, existsSync as existsSync10, mkdirSync, realpathSync as realpathSync3, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
5520
+ import { dirname as dirname3, resolve } from "node:path";
5516
5521
 
5517
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/sealed.js
5522
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/sealed.js
5518
5523
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5519
5524
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5520
5525
  import { Transform } from "node:stream";
@@ -5621,7 +5626,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5621
5626
  renameSync(pending, to);
5622
5627
  }, "unsealFile");
5623
5628
 
5624
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5629
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5625
5630
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5626
5631
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5627
5632
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5645,7 +5650,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5645
5650
  };
5646
5651
  }, "compatibilityOf");
5647
5652
 
5648
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/store/repair.js
5653
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/store/repair.js
5649
5654
  import { createHash as createHash2 } from "node:crypto";
5650
5655
  var COPY_MARK = "__repair_";
5651
5656
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5899,17 +5904,99 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5899
5904
  return found;
5900
5905
  }, "deleteCopy");
5901
5906
 
5902
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5907
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5903
5908
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5904
5909
 
5905
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5910
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5906
5911
  import { existsSync as existsSync3 } from "node:fs";
5907
5912
 
5908
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/store/recover.js
5913
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/store/recover.js
5909
5914
  import { execFileSync, spawn } from "node:child_process";
5910
5915
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5911
5916
  import { basename, dirname, join } from "node:path";
5912
5917
  import { Transform as Transform2 } from "node:stream";
5918
+
5919
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/store/refill.js
5920
+ var REFILL_MARGIN_MS = 864e5;
5921
+ var TIME_KEYS = 1e12;
5922
+ var integerId = `external_id GLOB '[0-9]*' AND NOT external_id GLOB '*[^0-9]*'`;
5923
+ var forgetCoverageSince = /* @__PURE__ */ __name((database, cutoff, now = Date.now()) => {
5924
+ database.exec("BEGIN");
5925
+ try {
5926
+ const refetch = forget(database, cutoff, now);
5927
+ database.exec("COMMIT");
5928
+ return refetch;
5929
+ } catch (error) {
5930
+ database.exec("ROLLBACK");
5931
+ throw error;
5932
+ }
5933
+ }, "forgetCoverageSince");
5934
+ var forget = /* @__PURE__ */ __name((database, cutoff, now) => {
5935
+ const chats = /* @__PURE__ */ new Map();
5936
+ const held = database.prepare(`SELECT c.id, c.account_id, c.external_id AS chat, a.provider, a.external_id AS account,
5937
+ max(r.to_key) AS top FROM sync_ranges r JOIN chats c ON c.id = r.chat_id JOIN accounts a ON a.id = c.account_id
5938
+ GROUP BY c.id`).all();
5939
+ for (const row of held) {
5940
+ const chat = Number(row.id);
5941
+ const top = Number(row.top);
5942
+ const keepTo = cutoff === null ? null : top >= TIME_KEYS ? cutoff : database.prepare(`SELECT max(CAST(external_id AS INTEGER)) AS k FROM messages WHERE chat_id = ? AND sent_at < ? AND ${integerId}`).get(chat, cutoff)?.k;
5943
+ if (keepTo !== null && top <= keepTo)
5944
+ continue;
5945
+ if (keepTo === null)
5946
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ?").run(chat);
5947
+ else {
5948
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ? AND from_key > ?").run(chat, keepTo);
5949
+ database.prepare("UPDATE sync_ranges SET to_key = ?, updated_at = ? WHERE chat_id = ? AND to_key > ?").run(keepTo, now, chat, keepTo);
5950
+ }
5951
+ const account = Number(row.account_id);
5952
+ const external = String(row.chat);
5953
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(account, `fetched:${external}`);
5954
+ database.prepare(`DELETE FROM sync_cursors WHERE account_id = ? AND key = ? AND NOT EXISTS
5955
+ (SELECT 1 FROM sync_ranges WHERE chat_id = ? AND from_key <= CAST(sync_cursors.value AS INTEGER))`).run(account, `history_start:${external}`, chat);
5956
+ const key = `${row.provider}\0${row.account}`;
5957
+ const one = chats.get(key) ?? { provider: String(row.provider), account: String(row.account), chats: 0 };
5958
+ one.chats += 1;
5959
+ chats.set(key, one);
5960
+ }
5961
+ return {
5962
+ since: cutoff === null ? null : new Date(cutoff).toISOString(),
5963
+ chats: [...chats.values()],
5964
+ mail: forgetMail(database, cutoff, now)
5965
+ };
5966
+ }, "forget");
5967
+ var forgetMail = /* @__PURE__ */ __name((database, cutoff, now) => {
5968
+ const folders = /* @__PURE__ */ new Map();
5969
+ const points = database.prepare(`SELECT s.account_id, s.key, s.value, a.external_id AS account FROM sync_cursors s
5970
+ JOIN accounts a ON a.id = s.account_id WHERE a.provider = 'email' AND s.key LIKE 'mail_resume:%'`).all();
5971
+ for (const row of points) {
5972
+ let point;
5973
+ try {
5974
+ point = JSON.parse(String(row.value));
5975
+ } catch {
5976
+ continue;
5977
+ }
5978
+ const account = String(row.account);
5979
+ if (!Array.isArray(point.done)) {
5980
+ if (cutoff !== null && Date.parse(point.updatedAt ?? "") < cutoff)
5981
+ continue;
5982
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(Number(row.account_id), String(row.key));
5983
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5984
+ continue;
5985
+ }
5986
+ const folder = String(row.key).slice("mail_resume:".length);
5987
+ const last = cutoff === null ? null : database.prepare(`SELECT max(l.uid) AS uid FROM email_locations l JOIN emails e ON e.id = l.email_id
5988
+ WHERE l.mailbox_id = (SELECT id FROM mailboxes WHERE account_id = ? AND external_id = ?)
5989
+ AND l.uidvalidity = ? AND coalesce(e.received_at, e.sent_at) < ?`).get(Number(row.account_id), folder, point.validity ?? "", cutoff)?.uid;
5990
+ const done = last === null ? [] : point.done.filter(([from]) => from <= last).map(([from, to]) => [from, Math.min(to, last)]);
5991
+ if (JSON.stringify(done) === JSON.stringify(point.done))
5992
+ continue;
5993
+ database.prepare("UPDATE sync_cursors SET value = ?, updated_at = ? WHERE account_id = ? AND key = ?").run(JSON.stringify({ ...point, done }), now, Number(row.account_id), String(row.key));
5994
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5995
+ }
5996
+ return [...folders].map(([account, count3]) => ({ account, folders: count3 }));
5997
+ }, "forgetMail");
5998
+
5999
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/store/recover.js
5913
6000
  var SQLITE3_MINIMUM = [3, 43, 0];
5914
6001
  var STORE_PARTS = ["", "-wal", "-shm"];
5915
6002
  var RECOVER_LOCK = ".recover-lock";
@@ -6004,9 +6091,12 @@ var storeHolders = /* @__PURE__ */ __name((path) => {
6004
6091
  return { pid, name };
6005
6092
  });
6006
6093
  }, "storeHolders");
6007
- var tableRows = /* @__PURE__ */ __name((database) => {
6094
+ var dataTables = /* @__PURE__ */ __name((database) => {
6008
6095
  const indexes = fts5Tables(database).map((index) => index.name);
6009
- const tables = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND rootpage > 0 AND name NOT LIKE 'sqlite_%' AND name NOT LIKE 'vector_index_%' ORDER BY name").all().map((row) => String(row.name)).filter((name) => !indexes.some((index) => name.startsWith(`${index}_`)));
6096
+ return database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND rootpage > 0 AND name NOT LIKE 'sqlite_%' AND name NOT LIKE 'vector_index_%' ORDER BY name").all().map((row) => String(row.name)).filter((name) => !indexes.some((index) => name.startsWith(`${index}_`)));
6097
+ }, "dataTables");
6098
+ var tableRows = /* @__PURE__ */ __name((database) => {
6099
+ const tables = dataTables(database);
6010
6100
  return Object.fromEntries(tables.map((table) => {
6011
6101
  try {
6012
6102
  return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
@@ -6015,6 +6105,117 @@ var tableRows = /* @__PURE__ */ __name((database) => {
6015
6105
  }
6016
6106
  }));
6017
6107
  }, "tableRows");
6108
+ var sourceTables = /* @__PURE__ */ __name((database) => {
6109
+ const withoutRowid = new Set(database.prepare("SELECT name FROM pragma_table_list WHERE wr = 1").all().map((row) => String(row.name)));
6110
+ return dataTables(database).filter((table) => table !== LOST_AND_FOUND && !withoutRowid.has(table) && !isDerivedTable(table));
6111
+ }, "sourceTables");
6112
+ var indexedButGone = /* @__PURE__ */ __name((database) => {
6113
+ const found = {};
6114
+ for (const table of sourceTables(database)) {
6115
+ const indexes = database.prepare("SELECT name FROM pragma_index_list(?) WHERE partial = 0 ORDER BY name").all(table).map((row) => String(row.name));
6116
+ for (const index of indexes) {
6117
+ const columns = database.prepare("SELECT cid, name FROM pragma_index_xinfo(?) WHERE key = 1 ORDER BY seqno").all(index);
6118
+ if (columns.some((column) => Number(column.cid) < 0))
6119
+ continue;
6120
+ const keys = columns.map((column) => `"${String(column.name)}"`).join(", ");
6121
+ const grouped = `${keys}, row_id`;
6122
+ let rows;
6123
+ try {
6124
+ rows = Number(database.prepare(`SELECT count(*) AS n FROM (SELECT 1 FROM (SELECT ${keys}, rowid AS row_id, 1 AS side FROM "${table}" INDEXED BY "${index}" UNION ALL SELECT ${keys}, rowid, 2 FROM "${table}" NOT INDEXED) GROUP BY ${grouped} HAVING max(side) = 1)`).get()?.n);
6125
+ } catch {
6126
+ continue;
6127
+ }
6128
+ if (rows > (found[table]?.rows ?? 0))
6129
+ found[table] = { rows, index };
6130
+ }
6131
+ }
6132
+ return found;
6133
+ }, "indexedButGone");
6134
+ var storedAs = /* @__PURE__ */ __name((declared) => {
6135
+ const type = declared.toUpperCase();
6136
+ if (type.includes("INT"))
6137
+ return ["integer"];
6138
+ if (/CHAR|CLOB|TEXT/.test(type))
6139
+ return ["text"];
6140
+ if (type === "" || type.includes("BLOB"))
6141
+ return null;
6142
+ if (/REAL|FLOA|DOUB/.test(type))
6143
+ return ["real", "integer"];
6144
+ return null;
6145
+ }, "storedAs");
6146
+ var columnsOf = /* @__PURE__ */ __name((database, table) => {
6147
+ const all = database.prepare('SELECT name, type, "notnull" AS required, dflt_value, pk FROM pragma_table_info(?)').all(table);
6148
+ const keys = all.filter((column) => Number(column.pk) > 0);
6149
+ return all.map((column) => ({
6150
+ name: String(column.name),
6151
+ type: String(column.type),
6152
+ required: Number(column.required) === 1,
6153
+ hasDefault: column.dflt_value !== null,
6154
+ rowid: keys.length === 1 && Number(column.pk) === 1 && String(column.type).toUpperCase() === "INTEGER"
6155
+ }));
6156
+ }, "columnsOf");
6157
+ var fits = /* @__PURE__ */ __name((columns, fields, types) => fields <= columns.length && columns.every((column, at) => {
6158
+ if (at >= fields)
6159
+ return !column.required || column.hasDefault;
6160
+ const type = types[at];
6161
+ if (column.rowid)
6162
+ return type === "null" || type === "integer";
6163
+ if (type === "null")
6164
+ return !column.required;
6165
+ const allowed = storedAs(column.type);
6166
+ return allowed === null || allowed.includes(type);
6167
+ }), "fits");
6168
+ var placeLostRows = /* @__PURE__ */ __name((database) => {
6169
+ if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND))
6170
+ return {};
6171
+ const fields = database.prepare("SELECT name FROM pragma_table_info(?) WHERE name GLOB 'c[0-9]*'").all(LOST_AND_FOUND).map((row) => String(row.name));
6172
+ const tables = sourceTables(database).map((table) => ({ table, columns: columnsOf(database, table) }));
6173
+ const rows = database.prepare(`SELECT rowid AS at, nfield, ${fields.map((field) => `typeof(${field}) AS "${field}"`).join(", ")} FROM ${LOST_AND_FOUND} WHERE id IS NOT NULL`).all();
6174
+ const placed = {};
6175
+ const triggers = [];
6176
+ const quiet = /* @__PURE__ */ __name((table) => {
6177
+ if (table in placed)
6178
+ return;
6179
+ placed[table] = 0;
6180
+ for (const row of database.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?").all(table)) {
6181
+ triggers.push(String(row.sql));
6182
+ database.exec(`DROP TRIGGER "${String(row.name)}"`);
6183
+ }
6184
+ }, "quiet");
6185
+ database.exec("PRAGMA foreign_keys = OFF");
6186
+ database.exec("BEGIN");
6187
+ try {
6188
+ for (const row of rows) {
6189
+ const count3 = Number(row.nfield);
6190
+ const types = fields.slice(0, count3).map((field) => String(row[field]));
6191
+ const fitting = tables.filter(({ columns: columns2 }) => fits(columns2, count3, types));
6192
+ if (fitting.length !== 1)
6193
+ continue;
6194
+ const { table, columns } = fitting[0];
6195
+ quiet(table);
6196
+ const given = columns.slice(0, count3);
6197
+ const names = [...given.some((column) => column.rowid) ? [] : ["rowid"], ...given.map((column) => column.name)];
6198
+ const values = [
6199
+ ...given.some((column) => column.rowid) ? [] : ["id"],
6200
+ ...given.map((column, at) => column.rowid ? "id" : `c${at}`)
6201
+ ];
6202
+ const inserted = database.prepare(`INSERT OR IGNORE INTO "${table}" (${names.map((name) => `"${name}"`).join(", ")}) SELECT ${values.join(", ")} FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6203
+ if (Number(inserted.changes) === 0)
6204
+ continue;
6205
+ placed[table] = (placed[table] ?? 0) + 1;
6206
+ database.prepare(`DELETE FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6207
+ }
6208
+ for (const sql of triggers)
6209
+ database.exec(sql);
6210
+ database.exec("COMMIT");
6211
+ } catch (error) {
6212
+ database.exec("ROLLBACK");
6213
+ throw error;
6214
+ } finally {
6215
+ database.exec("PRAGMA foreign_keys = ON");
6216
+ }
6217
+ return Object.fromEntries(Object.entries(placed).filter(([, rows2]) => rows2 > 0));
6218
+ }, "placeLostRows");
6018
6219
  var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
6019
6220
  const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
6020
6221
  stdio: ["ignore", "pipe", "pipe"]
@@ -6211,6 +6412,9 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6211
6412
  throw error;
6212
6413
  throw new CliError("configuration_error", "the store file's header or schema is damaged, so its tables cannot be listed and it cannot be recovered; the file was left as it was", { reason: "store.unreadable" });
6213
6414
  }
6415
+ note("looking for rows the indexes list and the tables no longer hold");
6416
+ const gone = indexedButGone(watch);
6417
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6214
6418
  const before = { data: dataVersion(), inode: statSync2(path).ino };
6215
6419
  const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6216
6420
  const target = `${path}.recovering-${stamp}`;
@@ -6239,7 +6443,10 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6239
6443
  let json;
6240
6444
  let fetch;
6241
6445
  let schema;
6446
+ let placed;
6447
+ let refetch;
6242
6448
  try {
6449
+ placed = placeLostRows(opened.database);
6243
6450
  kept = tableRows(opened.database);
6244
6451
  migrate(opened.database, { command, ...version ? { version } : {} });
6245
6452
  note("clearing values that are not valid JSON");
@@ -6248,6 +6455,8 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6248
6455
  note("looking for rows that point at rows that were lost");
6249
6456
  dangling = danglingRows(opened.database);
6250
6457
  fetch = mailToFetch(opened.database);
6458
+ const good = lastKnownGood === null ? Number.NaN : Date.parse(lastKnownGood);
6459
+ refetch = forgetCoverageSince(opened.database, Number.isNaN(good) ? null : good - REFILL_MARGIN_MS, now());
6251
6460
  schema = fileSchemaOf(opened.database).version;
6252
6461
  opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6253
6462
  } catch (error) {
@@ -6277,16 +6486,29 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6277
6486
  if (existsSync2(`${target}${suffix}`))
6278
6487
  renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6279
6488
  recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema, now });
6280
- const lost = Object.entries(rowsBefore).map(([table, before2]) => ({ table, before: before2, read: read[table] ?? 0, kept: kept[table] ?? 0 })).filter(({ before: before2, read: read2, kept: kept2 }) => before2 === null || before2 > kept2 || read2 > kept2);
6489
+ const lost = Object.entries(rowsBefore).map(([table, before2]) => {
6490
+ const goneAtLeast = Math.max(0, (gone[table]?.rows ?? 0) - (placed[table] ?? 0));
6491
+ return {
6492
+ table,
6493
+ before: before2,
6494
+ read: read[table] ?? 0,
6495
+ kept: kept[table] ?? 0,
6496
+ goneAtLeast,
6497
+ seenIn: goneAtLeast > 0 ? gone[table]?.index ?? null : null
6498
+ };
6499
+ }).filter(({ before: before2, read: read2, kept: kept2, goneAtLeast }) => before2 === null || before2 > kept2 || read2 > kept2 || goneAtLeast > 0);
6281
6500
  const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6282
6501
  return {
6283
6502
  path,
6284
6503
  keptAt,
6285
6504
  sqlite3: program.version,
6286
6505
  lost,
6506
+ placed,
6507
+ lastKnownGood,
6287
6508
  dangling,
6288
6509
  invalidJson: json,
6289
6510
  mailToFetch: fetch,
6511
+ refetch,
6290
6512
  rebuilt,
6291
6513
  copyErrors,
6292
6514
  health,
@@ -6302,7 +6524,7 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6302
6524
  }
6303
6525
  }, "recoverLocked");
6304
6526
 
6305
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6527
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6306
6528
  var COUNTED = [
6307
6529
  "accounts",
6308
6530
  "chats",
@@ -6335,18 +6557,23 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6335
6557
  }
6336
6558
  } catch {
6337
6559
  }
6560
+ const journal = readJournalMark(path);
6338
6561
  recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
6339
6562
  const mark = readDamageMark(path);
6340
- const explanation = explainDamage(health, command, mark);
6563
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6341
6564
  const inUse = storeHolders(path) ?? null;
6342
6565
  const timers = activeTimers() ?? null;
6343
6566
  const sqlite3 = sqlite3Program();
6344
- const next = health.ok ? [] : [
6345
- ...timers?.length ? [stopTimers(timers)] : [],
6346
- ...(inUse ?? []).map(({ pid, name }) => `stop ${name} (process ${pid}): it has the store open`),
6347
- ...sqlite3.usable ? [] : ["install sqlite3 3.43 or newer (apt install sqlite3, brew install sqlite)"],
6348
- `${command} store recover run`
6349
- ];
6567
+ const report = storeDamageReport({
6568
+ health,
6569
+ command,
6570
+ mark,
6571
+ journal,
6572
+ lastOkAt: lastKnownGood,
6573
+ holders: inUse,
6574
+ timers,
6575
+ sqlite3Usable: sqlite3.usable
6576
+ });
6350
6577
  return {
6351
6578
  path,
6352
6579
  exists: true,
@@ -6357,13 +6584,13 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6357
6584
  damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
6358
6585
  invalidJson: health.invalidJson ?? [],
6359
6586
  rows,
6360
- explanation,
6587
+ report,
6361
6588
  damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
6362
- lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
6589
+ lastKnownGood,
6363
6590
  inUse,
6364
6591
  timers,
6365
6592
  sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
6366
- next
6593
+ next: report?.steps.map((step) => step.command) ?? []
6367
6594
  };
6368
6595
  }, "storeRecoveryCheck");
6369
6596
  var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, note, timers: scheduled = activeTimers, copy }) => {
@@ -6389,12 +6616,27 @@ var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, no
6389
6616
  next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
6390
6617
  };
6391
6618
  }, "storeRecoveryRun");
6619
+ var refetchNotes = /* @__PURE__ */ __name(({ since, chats, mail }) => {
6620
+ const from = since === null ? "from the start" : `from ${since} on`;
6621
+ const marked = [
6622
+ ...chats.map(({ provider, account, chats: chats2 }) => `${chats2} chats of ${provider} ${account}`),
6623
+ ...mail.map(({ account, folders }) => `${folders} mail folders of ${account}`)
6624
+ ];
6625
+ return [
6626
+ marked.length > 0 ? `marked as not fetched ${from}, so the next sync or serve fetches it again: ${marked.join(", ")}` : `nothing held ${from} was marked as fetched, so there is nothing to fetch again`,
6627
+ ...chats.filter(({ provider }) => provider === "whatsapp").map(({ account }) => `whatsapp ${account}: WhatsApp cannot be asked for its chats, so only what the phone pushes while serve runs comes back`),
6628
+ "notes, memories, tags and whatever else only this store held cannot be fetched again"
6629
+ ];
6630
+ }, "refetchNotes");
6392
6631
  var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6393
6632
  if ("keptAt" in answer) {
6394
- const lost = answer.lost.map(({ table, before, read, kept }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}`);
6633
+ const lost = answer.lost.map(({ table, before, read, kept, goneAtLeast, seenIn }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}` + (goneAtLeast > 0 ? `; at least ${goneAtLeast} rows are gone (the index ${seenIn} lists them)` : ""));
6395
6634
  return [
6396
6635
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6397
- ...lost.length ? lost : ["no table lost a row"],
6636
+ ...lost,
6637
+ ...Object.entries(answer.placed).map(([table, rows]) => `${table}: ${rows} rows found on pages no table claimed were put back`),
6638
+ ...refetchNotes(answer.refetch),
6639
+ lossUnknown(answer.lastKnownGood, lost.some((line) => line.includes("are gone"))),
6398
6640
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6399
6641
  ...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
6400
6642
  ...answer.next.map((line) => `next: ${line}`)
@@ -6402,13 +6644,16 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6402
6644
  }
6403
6645
  if (!answer.exists)
6404
6646
  return ["no store yet"];
6405
- if (answer.ok)
6647
+ const report = answer.report;
6648
+ if (!report)
6406
6649
  return [`the store is healthy (checked every page and search index in ${answer.seconds} s)`];
6407
- const why = answer.explanation;
6408
6650
  return [
6409
- ...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
6410
- answer.lastKnownGood ? `the store last passed a deep check at ${answer.lastKnownGood}` : "no deep check that passed is on record for this store",
6411
- ...answer.next.map((line) => `next: ${line}`)
6651
+ report.whatHappened,
6652
+ ...report.impact,
6653
+ report.externalDataSafe,
6654
+ report.loss,
6655
+ ...report.likelyCauses.map(({ cause, check: check2 }) => `maybe: ${cause} \u2014 check: ${check2}`),
6656
+ ...report.steps.map(({ command, why, destructive }) => `next: ${command} # ${destructive ? "changes things: " : ""}${why}`)
6412
6657
  ];
6413
6658
  }, "recoveryNotes");
6414
6659
  var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
@@ -6435,7 +6680,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6435
6680
  return recover;
6436
6681
  }, "storeRecoverCommand");
6437
6682
 
6438
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6683
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6439
6684
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6440
6685
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6441
6686
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6481,7 +6726,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6481
6726
  renderAnswer(this, outputFor(this), itemOf(answer));
6482
6727
  }), "storeInfoCommand");
6483
6728
 
6484
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6729
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6485
6730
  var ENCRYPT_OPTION = [
6486
6731
  "--encrypt",
6487
6732
  "compress and encrypt with a password, typed at a hidden prompt or piped on stdin; it is never kept \u2014 lose it and the file cannot be opened"
@@ -6500,7 +6745,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6500
6745
  return password;
6501
6746
  }, "passwordOf");
6502
6747
 
6503
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/rules.js
6748
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/rules.js
6504
6749
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6505
6750
  import { join as join2 } from "node:path";
6506
6751
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6671,7 +6916,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6671
6916
  }, "problem");
6672
6917
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6673
6918
 
6674
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/state.js
6919
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/state.js
6675
6920
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6676
6921
  import { join as join3 } from "node:path";
6677
6922
  var ANSWERED_KEPT = 1e3;
@@ -6724,7 +6969,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6724
6969
  }, "recordReply");
6725
6970
  var broken2 = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply state ${path} cannot be read (${why}) \u2014 fix or move the file`), "broken");
6726
6971
 
6727
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/decide.js
6972
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/decide.js
6728
6973
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6729
6974
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6730
6975
  const { message, chat, owner, sender } = incoming;
@@ -6830,10 +7075,10 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6830
7075
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6831
7076
  }, "filled");
6832
7077
 
6833
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/template.js
7078
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/template.js
6834
7079
  var import_liquidjs2 = __toESM(require_liquid_node(), 1);
6835
7080
 
6836
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/render/liquid.js
7081
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/render/liquid.js
6837
7082
  var import_liquidjs = __toESM(require_liquid_node(), 1);
6838
7083
  var safeLiquid = /* @__PURE__ */ __name((limits) => {
6839
7084
  const engine = new import_liquidjs.Liquid({
@@ -6860,7 +7105,7 @@ var safeLiquid = /* @__PURE__ */ __name((limits) => {
6860
7105
  return engine;
6861
7106
  }, "safeLiquid");
6862
7107
 
6863
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/template.js
7108
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/template.js
6864
7109
  var TEMPLATE_LIMITS = {
6865
7110
  parse: 32768,
6866
7111
  renders: 2e3,
@@ -6999,7 +7244,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6999
7244
  }
7000
7245
  }, "renderReplyTemplate");
7001
7246
 
7002
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7247
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7003
7248
  var DRY_RUN_DAYS = 7;
7004
7249
  var PAGE = 500;
7005
7250
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7113,7 +7358,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7113
7358
  }
7114
7359
  }, "storedSince");
7115
7360
 
7116
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/consents.js
7361
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/consents.js
7117
7362
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7118
7363
  import { join as join4 } from "node:path";
7119
7364
  var shape = strictObject({
@@ -7138,7 +7383,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7138
7383
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7139
7384
  }, "mayModelReply");
7140
7385
 
7141
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7386
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7142
7387
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options = {
7143
7388
  ai: true
7144
7389
  }) => async (rule2, message, chat, now) => {
@@ -7185,7 +7430,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7185
7430
  return result2;
7186
7431
  }, "replyRenderer");
7187
7432
 
7188
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/replies/serve.js
7433
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/replies/serve.js
7189
7434
  var NOT_ALLOWED = "replies.send is not allow";
7190
7435
  var NO_RULES = "no rules";
7191
7436
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7278,7 +7523,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7278
7523
  return { skip: why };
7279
7524
  }, "replyTo");
7280
7525
 
7281
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7526
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7282
7527
  var START_SYNC_DELAY_MS = 3e4;
7283
7528
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7284
7529
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7355,7 +7600,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch, note, warn,
7355
7600
  };
7356
7601
  }, "startSync");
7357
7602
 
7358
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7603
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7359
7604
  var FIRST_FETCH_MS = 6e4;
7360
7605
  var DAY_MS = 864e5;
7361
7606
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7409,7 +7654,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs =
7409
7654
  };
7410
7655
  }, "memberFetches");
7411
7656
 
7412
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7657
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7413
7658
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7414
7659
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7415
7660
  if (context.format === "pretty") {
@@ -7442,7 +7687,93 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7442
7687
  return context;
7443
7688
  }, "recordDiagnostics");
7444
7689
 
7445
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7690
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7691
+ import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync2 } from "node:fs";
7692
+ import { dirname as dirname2, join as join5 } from "node:path";
7693
+ var OUTDATED_CHECK_MS = 6e4;
7694
+ var ownPackageRoot = /* @__PURE__ */ __name((running, script = process.argv[1]) => {
7695
+ let dir;
7696
+ try {
7697
+ dir = dirname2(realpathSync2(script ?? ""));
7698
+ } catch {
7699
+ return void 0;
7700
+ }
7701
+ for (let up = 0; up < 8; up++) {
7702
+ const manifest = join5(dir, "package.json");
7703
+ if (existsSync8(manifest))
7704
+ return installedVersion(dir) === running ? dir : void 0;
7705
+ const parent = dirname2(dir);
7706
+ if (parent === dir)
7707
+ return void 0;
7708
+ dir = parent;
7709
+ }
7710
+ return void 0;
7711
+ }, "ownPackageRoot");
7712
+ var installedVersion = /* @__PURE__ */ __name((root) => {
7713
+ try {
7714
+ const { version } = JSON.parse(readFileSync5(join5(root, "package.json"), "utf8"));
7715
+ return typeof version === "string" ? version : void 0;
7716
+ } catch {
7717
+ return void 0;
7718
+ }
7719
+ }, "installedVersion");
7720
+ var newer = /* @__PURE__ */ __name((one, other) => {
7721
+ const parts2 = /* @__PURE__ */ __name((version) => version.split(/[.+-]/, 3).map(Number), "parts");
7722
+ const [a, b] = [parts2(one), parts2(other)];
7723
+ for (let i = 0; i < 3; i++)
7724
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
7725
+ return (a[i] ?? 0) > (b[i] ?? 0);
7726
+ return false;
7727
+ }, "newer");
7728
+ var outdatedReason = /* @__PURE__ */ __name(async ({ command, running, storePath: storePath2, packageRoot, speaks = SPEAKS }) => {
7729
+ const installed = packageRoot === void 0 ? void 0 : installedVersion(packageRoot);
7730
+ if (installed !== void 0 && newer(installed, running))
7731
+ return `${command} ${installed} is installed and this serve runs ${running}: stopping so it starts again on ${installed}`;
7732
+ if (!existsSync8(storePath2))
7733
+ return void 0;
7734
+ let schema;
7735
+ try {
7736
+ const { database } = await openSqlite(storePath2, { readOnly: true });
7737
+ try {
7738
+ schema = fileSchemaOf(database);
7739
+ } finally {
7740
+ database.close();
7741
+ }
7742
+ } catch {
7743
+ return void 0;
7744
+ }
7745
+ if (writableBy(schema, speaks))
7746
+ return void 0;
7747
+ return `the store is at format ${schema.version} and needs at least ${schema.minCompatible}; this serve (${command} ${running}) speaks ${speaks} and can no longer write it: stopping \u2014 \`${command} upgrade\` if it does not start again on a newer version`;
7748
+ }, "outdatedReason");
7749
+ var watchOutdated = /* @__PURE__ */ __name(({ check: check2, onOutdated, everyMs = OUTDATED_CHECK_MS }) => {
7750
+ let busy = false;
7751
+ let done = false;
7752
+ const timer = setInterval(() => {
7753
+ if (busy || done)
7754
+ return;
7755
+ busy = true;
7756
+ check2().then((reason) => {
7757
+ if (reason === void 0 || done)
7758
+ return;
7759
+ done = true;
7760
+ clearInterval(timer);
7761
+ onOutdated(reason);
7762
+ }).catch(() => {
7763
+ }).finally(() => {
7764
+ busy = false;
7765
+ });
7766
+ }, everyMs);
7767
+ timer.unref();
7768
+ return {
7769
+ stop: /* @__PURE__ */ __name(() => {
7770
+ done = true;
7771
+ clearInterval(timer);
7772
+ }, "stop")
7773
+ };
7774
+ }, "watchOutdated");
7775
+
7776
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7446
7777
  var STEMS_EVERY_MS = 3e4;
7447
7778
  var STEMS_SLICE_MS = 2e3;
7448
7779
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7482,7 +7813,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7482
7813
  };
7483
7814
  }, "stemFills");
7484
7815
 
7485
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/render/messages.js
7816
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/render/messages.js
7486
7817
  import { styleText } from "node:util";
7487
7818
  var TIME_WIDTH = 8;
7488
7819
  var INDENT = " ".repeat(TIME_WIDTH + 2);
@@ -7658,7 +7989,7 @@ var editedAt = /* @__PURE__ */ __name((message, options) => {
7658
7989
  return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
7659
7990
  }, "editedAt");
7660
7991
 
7661
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7992
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7662
7993
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7663
7994
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7664
7995
  kind: attachment.kind,
@@ -7677,7 +8008,7 @@ var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7677
8008
  phone: attachment.contact.phone,
7678
8009
  user_id: attachment.contact.userId
7679
8010
  }),
7680
- buttons: attachment.buttons
8011
+ buttons: attachment.buttons?.map((row) => row.map(({ data: _data, ...button }) => button))
7681
8012
  }), "attachmentItem");
7682
8013
  var quotedItem = /* @__PURE__ */ __name((quoted) => quoted === null ? null : {
7683
8014
  id: quoted.id,
@@ -7753,7 +8084,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7753
8084
  locale: messenger.app.locale
7754
8085
  }), "viewOf");
7755
8086
 
7756
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
8087
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7757
8088
  var observed = /* @__PURE__ */ __name((value) => ({
7758
8089
  value: value.value,
7759
8090
  observed_at: value.observedAt,
@@ -7820,7 +8151,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7820
8151
  }
7821
8152
  }, "watchEventItem");
7822
8153
 
7823
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
8154
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7824
8155
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7825
8156
  output: { entity: "watch_item" },
7826
8157
  effects: REMOTE_READ,
@@ -7975,7 +8306,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
7975
8306
  }
7976
8307
  }, "describe");
7977
8308
 
7978
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8309
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
7979
8310
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
7980
8311
  const command = annotate(new Command("serve"), {
7981
8312
  output: { entity: "serve_summary" },
@@ -7999,8 +8330,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7999
8330
  }
8000
8331
  let relaying;
8001
8332
  const onReady = /* @__PURE__ */ __name(() => {
8002
- const listening = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8003
- holdLock(path, listening);
8333
+ const listening2 = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8334
+ holdLock(path, listening2);
8004
8335
  note({
8005
8336
  code: "listening",
8006
8337
  text: `listening for profile ${context.profile}, catching up on what arrived while it was down`
@@ -8009,7 +8340,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8009
8340
  return;
8010
8341
  relaying = relay.open(path, context.profile).then((address) => {
8011
8342
  if (address)
8012
- holdLock(path, { ...listening, relay: address });
8343
+ holdLock(path, { ...listening2, relay: address });
8013
8344
  }).catch((error) => {
8014
8345
  const errorCode = failureKey(error);
8015
8346
  warn({ code: "relay_failed", errorCode, text: `commands cannot run through this serve: ${errorCode}` });
@@ -8018,7 +8349,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8018
8349
  const counts = {};
8019
8350
  const rules = replying(context, messenger, Date.parse(startedAt));
8020
8351
  const tasks = tasking(context, warn);
8021
- const { handled, startSyncDelayMs } = environmentOf(this);
8352
+ const { handled, startSyncDelayMs, outdated: outdatedHook } = environmentOf(this);
8022
8353
  const count3 = /* @__PURE__ */ __name((event) => {
8023
8354
  counts[event.event] = (counts[event.event] ?? 0) + 1;
8024
8355
  if (event.event === "message") {
@@ -8090,9 +8421,25 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8090
8421
  withStore: /* @__PURE__ */ __name((work) => context.withStore((store) => work(store), { name: "serve stems" }), "withStore"),
8091
8422
  warn
8092
8423
  });
8424
+ const listening = new AbortController();
8425
+ let outdated;
8426
+ const packageRoot = outdatedHook?.packageRoot ?? ownPackageRoot(version);
8427
+ const watch = watchOutdated({
8428
+ check: /* @__PURE__ */ __name(() => outdatedReason({
8429
+ command: messenger.app.command,
8430
+ running: version,
8431
+ storePath: storePath(context.env),
8432
+ packageRoot
8433
+ }), "check"),
8434
+ onOutdated: /* @__PURE__ */ __name((reason) => {
8435
+ outdated = reason;
8436
+ listening.abort();
8437
+ }, "onOutdated"),
8438
+ ...outdatedHook?.everyMs === void 0 ? {} : { everyMs: outdatedHook.everyMs }
8439
+ });
8093
8440
  try {
8094
8441
  await listenUntilStopped(this, context, relay?.messenger ?? messenger, count3, {
8095
- stop: new AbortController(),
8442
+ stop: listening,
8096
8443
  catchUp: true,
8097
8444
  onReady,
8098
8445
  connected: /* @__PURE__ */ __name((open) => {
@@ -8105,6 +8452,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8105
8452
  }, "connected")
8106
8453
  });
8107
8454
  } finally {
8455
+ watch.stop();
8108
8456
  await relaying;
8109
8457
  await relay?.close();
8110
8458
  rules.stop();
@@ -8115,6 +8463,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8115
8463
  await tasks.settled();
8116
8464
  releaseLock(path);
8117
8465
  }
8466
+ if (outdated !== void 0)
8467
+ throw new CliError("configuration_error", outdated, { reason: "serve.outdated" });
8118
8468
  renderAnswer(this, context, itemOf({
8119
8469
  profile: context.profile,
8120
8470
  started_at: startedAt,
@@ -8239,8 +8589,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8239
8589
  };
8240
8590
  }, "tasking");
8241
8591
 
8242
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8243
- import { existsSync as existsSync8 } from "node:fs";
8592
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8593
+ import { existsSync as existsSync9 } from "node:fs";
8244
8594
  var PATH = "store tables list";
8245
8595
  var STORE_TABLES_QUERY = {
8246
8596
  entity: "store_table",
@@ -8269,7 +8619,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8269
8619
  const filter = filterOf(words);
8270
8620
  const { full } = this.optsWithGlobals();
8271
8621
  const path = storePath(environmentOf(this).env ?? process.env);
8272
- if (!existsSync8(path))
8622
+ if (!existsSync9(path))
8273
8623
  throw new CliError("not_found", `no store at ${path}`);
8274
8624
  const items = await readStoreTables(path, { filter, sizes: full === true });
8275
8625
  renderAnswer(this, outputFor(this), listOf(PATH, {
@@ -8282,7 +8632,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8282
8632
  return tables;
8283
8633
  }, "storeTablesCommand");
8284
8634
 
8285
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.82.0_commander@15.0.0_esbuild@0.28.2_type_e0755e4bb52a6ea6d9033617574418d1/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8635
+ // node_modules/.pnpm/@wirecat+cli-core@0.634.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_795ed7a67bda78d624888739490b3720/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8286
8636
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8287
8637
  var WORD_INDEX = "message_words";
8288
8638
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8291,7 +8641,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
8291
8641
  }, "schemaOf");
8292
8642
  var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
8293
8643
  var pendingIfKnown2 = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
8294
- var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync9(path) ? statSync4(path).size : 0, "bytesOf");
8644
+ var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync10(path) ? statSync4(path).size : 0, "bytesOf");
8295
8645
  var reading = /* @__PURE__ */ __name(async (path, read) => {
8296
8646
  const database = await openCache(path);
8297
8647
  try {
@@ -8318,9 +8668,10 @@ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8318
8668
  }, "fileSchema");
8319
8669
  var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8320
8670
  const path = storePath(env);
8321
- if (!existsSync9(path))
8671
+ if (!existsSync10(path))
8322
8672
  return { path, exists: false };
8323
8673
  const checked = await storeHealth(path, { deep });
8674
+ const journal = readJournalMark(path);
8324
8675
  const recorded = deep ? recordDeepCheck(path, checked, {
8325
8676
  cli: command ?? "unknown",
8326
8677
  ...version ? { version } : {},
@@ -8338,13 +8689,15 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, v
8338
8689
  ...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
8339
8690
  ...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
8340
8691
  };
8341
- const damage = command ? explainDamage(checked, command, mark) : null;
8692
+ const damage = command ? storeDamageReport({ health: checked, command, mark, journal, lastOkAt: lastKnownGood }) : null;
8342
8693
  const healthOf = {
8343
8694
  health,
8344
8695
  lastKnownGood,
8345
8696
  ...mark ? { damageMark: withoutInode(mark) } : {},
8697
+ ...journal ? { journalMark: journal } : {},
8346
8698
  ...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
8347
- ...damage ? { damage } : {}
8699
+ // `what` keeps memo's doctor, which reads it, compiling until it moves to `whatHappened`.
8700
+ ...damage ? { damage: { what: damage.whatHappened, ...damage } } : {}
8348
8701
  };
8349
8702
  try {
8350
8703
  return await reading(path, (database) => {
@@ -8388,7 +8741,7 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
8388
8741
  const { renderer, format } = outputFor(this);
8389
8742
  const { dryRun: dryRun2 } = this.opts();
8390
8743
  const path = storePath(environmentOf(this).env ?? process.env);
8391
- if (!existsSync9(path)) {
8744
+ if (!existsSync10(path)) {
8392
8745
  result(this, { path, exists: false });
8393
8746
  return;
8394
8747
  }
@@ -8428,7 +8781,7 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
8428
8781
  }, "notesOf");
8429
8782
  var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").description("the tables `store repair` kept as copies").addCommand(annotate(new Command("delete"), { output: { entity: "store_copy_removal" }, effects: LOCAL_WRITE }).description("delete one copy `store repair` kept, named exactly; refuses any other table").argument("<name>", "the copy's name, as `store repair` printed it").action(async function(name) {
8430
8783
  const path = storePath(environmentOf(this).env ?? process.env);
8431
- if (!existsSync9(path))
8784
+ if (!existsSync10(path))
8432
8785
  throw new CliError("not_found", `no store at ${path}`);
8433
8786
  const deleted = await reading(path, (database) => deleteCopy(database, name));
8434
8787
  result(this, { path, deleted });
@@ -8436,7 +8789,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
8436
8789
  var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ }).summary("check the local archive for problems").description("whether the store is healthy \u2014 integrity, search indexes, disk, and which chats are behind").action(async function() {
8437
8790
  const { renderer } = outputFor(this);
8438
8791
  const path = storePath(environmentOf(this).env ?? process.env);
8439
- if (!existsSync9(path)) {
8792
+ if (!existsSync10(path)) {
8440
8793
  result(this, { path, exists: false, ok: true });
8441
8794
  return;
8442
8795
  }
@@ -8499,7 +8852,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
8499
8852
  ...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
8500
8853
  ]);
8501
8854
  const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
8502
- const { bavail, bsize } = statfsSync2(dirname2(path));
8855
+ const { bavail, bsize } = statfsSync2(dirname3(path));
8503
8856
  const free = Number(bavail) * Number(bsize);
8504
8857
  const behind = schema.version > 0 ? chatsBehind(database) : [];
8505
8858
  const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
@@ -8587,7 +8940,7 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
8587
8940
  var migrateCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE }).summary("migrate an older local archive").description("bring the store up to this build's schema, then normalize, index and stem the messages and notes stored before it").action(async function() {
8588
8941
  const { renderer } = outputFor(this);
8589
8942
  const path = storePath(environmentOf(this).env ?? process.env);
8590
- if (!existsSync9(path)) {
8943
+ if (!existsSync10(path)) {
8591
8944
  result(this, { path, exists: false });
8592
8945
  renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
8593
8946
  return;
@@ -8651,7 +9004,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
8651
9004
  var reindexCommand = /* @__PURE__ */ __name((messenger) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE })).summary("rebuild the local archive's search indexes").description("rebuild the word index, its typo vocabulary, the stems, the files' word index, the notes' indexes and who took part in what, from what is stored, and drop the vectors no stored text uses; loses nothing").action(async function() {
8652
9005
  const { renderer } = outputFor(this);
8653
9006
  const path = storePath(environmentOf(this).env ?? process.env);
8654
- if (!existsSync9(path)) {
9007
+ if (!existsSync10(path)) {
8655
9008
  result(this, { path, exists: false });
8656
9009
  return;
8657
9010
  }
@@ -8693,9 +9046,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
8693
9046
  const { encrypt } = this.opts();
8694
9047
  const path = storePath(environmentOf(this).env ?? process.env);
8695
9048
  const target = resolve(file2);
8696
- if (!existsSync9(path))
9049
+ if (!existsSync10(path))
8697
9050
  throw new CliError("not_found", `no store at ${path} to back up`);
8698
- if (existsSync9(target))
9051
+ if (existsSync10(target))
8699
9052
  throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
8700
9053
  const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
8701
9054
  const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
@@ -8728,11 +9081,11 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8728
9081
  const { output } = this.opts();
8729
9082
  const from = resolve(file2);
8730
9083
  const to = resolve(output);
8731
- if (!existsSync9(from))
9084
+ if (!existsSync10(from))
8732
9085
  throw new CliError("not_found", `no file at ${from}`);
8733
9086
  if (!isSealed(from))
8734
9087
  throw new CliError("validation_error", `${from} was not written with --encrypt`);
8735
- if (existsSync9(to))
9088
+ if (existsSync10(to))
8736
9089
  throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
8737
9090
  await unsealFile(from, to, await passwordOf(this, { twice: false }));
8738
9091
  result(this, { path: to, from, bytes: bytesOf2(to) });
@@ -8740,13 +9093,13 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8740
9093
  var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup and keep the current store, or roll back a breaking upgrade").description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools cannot open), put its tables back in the store and return it to that version instead").argument("<file>", "a file `store backup` wrote, or a rollback copy; one written with --encrypt asks for its password").action(async function(file2) {
8741
9094
  const path = storePath(environmentOf(this).env ?? process.env);
8742
9095
  const given = resolve(file2);
8743
- if (!existsSync9(given))
9096
+ if (!existsSync10(given))
8744
9097
  throw new CliError("not_found", `no file at ${given}`);
8745
9098
  refuseWhileServing(this, messenger);
8746
9099
  if (!isSealed(given))
8747
9100
  return restoreFrom(this, messenger, given, given);
8748
9101
  const opened = `${path}.unsealing-${process.pid}`;
8749
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9102
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8750
9103
  try {
8751
9104
  await unsealFile(given, opened, await passwordOf(this, { twice: false }));
8752
9105
  await restoreFrom(this, messenger, opened, given);
@@ -8757,26 +9110,26 @@ var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command(
8757
9110
  var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
8758
9111
  const { renderer } = outputFor(command);
8759
9112
  const path = storePath(environmentOf(command).env ?? process.env);
8760
- if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
9113
+ if (existsSync10(path) && realpathSync3(backup) === realpathSync3(path)) {
8761
9114
  throw new CliError("validation_error", `${backup} is the store itself`);
8762
9115
  }
8763
9116
  if (await isRollbackCopy(backup))
8764
9117
  return rollBackFrom(command, messenger, backup);
8765
9118
  const schema = await backupSchema(backup);
8766
9119
  const stamp = stampNow();
8767
- const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
9120
+ const kept = existsSync10(path) ? `${path}.before-restore-${stamp}` : null;
8768
9121
  if (kept) {
8769
9122
  const waitMs = environmentOf(command).storeLockWaitMs;
8770
9123
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
8771
9124
  } else
8772
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9125
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8773
9126
  const incoming = `${path}.restoring-${stamp}`;
8774
9127
  copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
8775
9128
  chmodSync(incoming, 384);
8776
9129
  if (kept) {
8777
9130
  renameSync3(path, kept);
8778
9131
  for (const suffix of ["-wal", "-shm"])
8779
- if (existsSync9(`${path}${suffix}`))
9132
+ if (existsSync10(`${path}${suffix}`))
8780
9133
  renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
8781
9134
  }
8782
9135
  renameSync3(incoming, path);
@@ -8798,7 +9151,7 @@ var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
8798
9151
  var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
8799
9152
  const { renderer } = outputFor(command);
8800
9153
  const path = storePath(environmentOf(command).env ?? process.env);
8801
- if (!existsSync9(path))
9154
+ if (!existsSync10(path))
8802
9155
  throw new CliError("not_found", `no store at ${path} to roll back`);
8803
9156
  const waitMs = environmentOf(command).storeLockWaitMs;
8804
9157
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
@@ -8848,7 +9201,7 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
8848
9201
  var STORE_LOCK_WAIT_MS = 1e3;
8849
9202
  var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
8850
9203
  const { command } = messenger.app;
8851
- const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
9204
+ const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync10(file2)).map((file2) => realpathSync3(file2));
8852
9205
  const holders = holdersOf(files);
8853
9206
  if (holders === void 0) {
8854
9207
  warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
@@ -8874,7 +9227,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8874
9227
  const { command } = messenger.app;
8875
9228
  const env = environmentOf(this).env ?? process.env;
8876
9229
  const path = storePath(env);
8877
- if (!existsSync9(path)) {
9230
+ if (!existsSync10(path)) {
8878
9231
  result(this, { path, exists: false, reset: false });
8879
9232
  renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
8880
9233
  return;
@@ -8919,8 +9272,8 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8919
9272
  }), "resetCommand");
8920
9273
  var STORE_PARTS2 = ["", "-wal", "-shm"];
8921
9274
  var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
8922
- const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync9(file2));
8923
- const holders = holdersOf(files.map((file2) => realpathSync2(file2)));
9275
+ const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync10(file2));
9276
+ const holders = holdersOf(files.map((file2) => realpathSync3(file2)));
8924
9277
  const serving = servingProfiles(messenger.app, env).length > 0;
8925
9278
  const read = await readingOnly(path, (database) => ({
8926
9279
  schema: schemaOf(database).version,