@wirecat/drive-cli 0.64.0 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/contracts/wirecat.json +2871 -0
  2. package/dist/bin/drive.js +2 -2
  3. package/dist/bin/drive.js.map +1 -1
  4. package/dist/browse.d.ts +1 -1
  5. package/dist/browse.d.ts.map +1 -1
  6. package/dist/browse.js +1 -1
  7. package/dist/bundle/{all-profiles-BPPT2AK5.js → all-profiles-WCQLIHUG.js} +14 -13
  8. package/dist/bundle/{anthropic-JW6GOJUD.js → anthropic-5RJMB6O7.js} +32 -16
  9. package/dist/bundle/{app-server-KAQIOJMZ.js → app-server-3RGYXPKG.js} +72 -58
  10. package/dist/bundle/{bun-UT7GNTPV.js → bun-L34VEKGG.js} +2 -2
  11. package/dist/bundle/{bun-sqlite-2OIVV3LS.js → bun-sqlite-H6IAXQXI.js} +12 -8
  12. package/dist/bundle/chunk-2AF77WMH.js +13 -0
  13. package/dist/bundle/{chunk-KVW4XNKB.js → chunk-2S3E2HVV.js} +107 -48
  14. package/dist/bundle/{chunk-IX7NQJLY.js → chunk-3NYH756U.js} +49 -116
  15. package/dist/bundle/chunk-3QFUDXMQ.js +53 -0
  16. package/dist/bundle/{chunk-5ZBR55US.js → chunk-3SDJIMZB.js} +1 -1
  17. package/dist/bundle/{chunk-AHB4OJCI.js → chunk-4UHBJSMI.js} +21735 -27143
  18. package/dist/bundle/chunk-5HVJK3ZJ.js +101 -0
  19. package/dist/bundle/{chunk-GSMYXGFR.js → chunk-5K54RZBK.js} +13 -5
  20. package/dist/bundle/{chunk-LOMW6F2E.js → chunk-5PLINHEY.js} +5403 -4847
  21. package/dist/bundle/{chunk-J62DI53V.js → chunk-5VDVGDOC.js} +1 -1
  22. package/dist/bundle/{chunk-66AF4FBW.js → chunk-5XLU4NN6.js} +4 -4
  23. package/dist/bundle/{chunk-4CNTID2X.js → chunk-6UJCCOZC.js} +4 -4
  24. package/dist/bundle/{chunk-G4KEKKDE.js → chunk-6X3KUFRQ.js} +60 -29
  25. package/dist/bundle/{chunk-QEAD2LF4.js → chunk-7EP4AU6A.js} +3 -3
  26. package/dist/bundle/{chunk-ZRZ4HTCK.js → chunk-7LT2G5BC.js} +171 -174
  27. package/dist/bundle/{chunk-2W464HAE.js → chunk-7ZGJRVBH.js} +7 -5
  28. package/dist/bundle/{chunk-FXBHOCJK.js → chunk-ADLS6FVG.js} +1 -1
  29. package/dist/bundle/{chunk-KG2XKEHL.js → chunk-ALE67WRR.js} +5 -5
  30. package/dist/bundle/{chunk-ZSZJLJIA.js → chunk-AP4MX247.js} +38 -28
  31. package/dist/bundle/{chunk-EWGVDFPT.js → chunk-BIJW6AYA.js} +41873 -36466
  32. package/dist/bundle/{chunk-B7XBIOMR.js → chunk-BQXSE645.js} +16 -16
  33. package/dist/bundle/{chunk-F2VDAG32.js → chunk-COGWKO2T.js} +3 -3
  34. package/dist/bundle/{chunk-EZ6O3ST3.js → chunk-D4MIMH2N.js} +12 -6
  35. package/dist/bundle/{chunk-4YRENUB5.js → chunk-D7KOAPG6.js} +2 -2
  36. package/dist/bundle/chunk-E2F2XIX6.js +224 -0
  37. package/dist/bundle/{chunk-36GPBPWM.js → chunk-FA2TNA5X.js} +3 -1
  38. package/dist/bundle/{chunk-SIOIMO62.js → chunk-FHBTQPA3.js} +69 -63
  39. package/dist/bundle/{chunk-34BIDKF4.js → chunk-FKKPVPZR.js} +649 -212
  40. package/dist/bundle/chunk-G4TNKBDX.js +185 -0
  41. package/dist/bundle/{chunk-2FEZ24DK.js → chunk-GVA3KTCD.js} +20 -20
  42. package/dist/bundle/chunk-GY4DAJSK.js +167 -0
  43. package/dist/bundle/{chunk-5OFA5EXE.js → chunk-H7XL6WTW.js} +2 -2
  44. package/dist/bundle/{chunk-K6BSB53R.js → chunk-HHRJPLFO.js} +1 -1
  45. package/dist/bundle/{chunk-P7DEGRZA.js → chunk-HPKE2GDP.js} +49 -28
  46. package/dist/bundle/{chunk-QXCKJUZY.js → chunk-HPSHQVJU.js} +633 -465
  47. package/dist/bundle/{chunk-BEZJA44H.js → chunk-HQBLJLYH.js} +7 -7
  48. package/dist/bundle/{chunk-JRXFW7HE.js → chunk-I5R5CMQR.js} +5 -5
  49. package/dist/bundle/{chunk-EJ4PNHPP.js → chunk-IIHZTV6V.js} +1 -1
  50. package/dist/bundle/{chunk-G3NULXOM.js → chunk-IRNDYNQX.js} +4 -4
  51. package/dist/bundle/{chunk-N622LRPM.js → chunk-JCHF7LZT.js} +4 -4
  52. package/dist/bundle/{chunk-WWCYTMAV.js → chunk-JHMEETXI.js} +2 -2
  53. package/dist/bundle/{chunk-ZF6GUZCE.js → chunk-JLCR24UM.js} +1 -1
  54. package/dist/bundle/{chunk-IDAK4DDK.js → chunk-JQXK3M5M.js} +1 -1
  55. package/dist/bundle/{chunk-KIN6PDFE.js → chunk-KOY5HUBY.js} +14 -5
  56. package/dist/bundle/{chunk-5HSRQ53R.js → chunk-KRG5X5PH.js} +2 -2
  57. package/dist/bundle/{chunk-VIJ6ACYB.js → chunk-LVAPSAHF.js} +8 -8
  58. package/dist/bundle/{chunk-OEVHZOHC.js → chunk-M7543RUJ.js} +50 -18
  59. package/dist/bundle/{chunk-BZ2ZKILM.js → chunk-MZWXTJ4O.js} +3 -3
  60. package/dist/bundle/{chunk-EC2XGDKJ.js → chunk-NK4GVFJH.js} +4 -4
  61. package/dist/bundle/chunk-NYECVHFH.js +10283 -0
  62. package/dist/bundle/{chunk-HW4UPST2.js → chunk-NYZS2LKF.js} +2 -2
  63. package/dist/bundle/chunk-O53WLYX3.js +72 -0
  64. package/dist/bundle/{chunk-IK6KH3RE.js → chunk-OIF4B526.js} +1 -1
  65. package/dist/bundle/{chunk-UJR272CP.js → chunk-OT7SQQJK.js} +359 -903
  66. package/dist/bundle/chunk-OZOQLAWK.js +72 -0
  67. package/dist/bundle/{chunk-VT2UFYPJ.js → chunk-P7HQFII6.js} +22 -15
  68. package/dist/bundle/{chunk-6G53ZFUT.js → chunk-PJGOQSE5.js} +1 -1
  69. package/dist/bundle/{chunk-OH3K2E7X.js → chunk-PKM55ZRR.js} +704 -1214
  70. package/dist/bundle/{chunk-GW3U6OLD.js → chunk-PUMDOCAF.js} +1 -1
  71. package/dist/bundle/{chunk-EQEGJVO2.js → chunk-QF7VL4C3.js} +1 -1
  72. package/dist/bundle/{chunk-CPMRM3GQ.js → chunk-QJ57PV55.js} +1941 -662
  73. package/dist/bundle/{chunk-O2QO5UZC.js → chunk-QSELSDWE.js} +13 -13
  74. package/dist/bundle/{chunk-BEUAICUD.js → chunk-SOOU5WO6.js} +2 -2
  75. package/dist/bundle/{chunk-46CD64J2.js → chunk-SZ6JFOL4.js} +269 -64
  76. package/dist/bundle/{chunk-UD55VB2N.js → chunk-T3ULDA7C.js} +3 -3
  77. package/dist/bundle/{chunk-E2LBCCTG.js → chunk-TAHISPDE.js} +5 -5
  78. package/dist/bundle/{chunk-6B37XO6B.js → chunk-TYLEICTX.js} +3 -3
  79. package/dist/bundle/{chunk-TNV2FXVK.js → chunk-UAKX6DP4.js} +5 -5
  80. package/dist/bundle/{chunk-VPLFD5RJ.js → chunk-UG3GHFGY.js} +4 -4
  81. package/dist/bundle/{chunk-B67BLRAI.js → chunk-ULXEW6FT.js} +3 -60
  82. package/dist/bundle/{chunk-C7WBNOYW.js → chunk-UNTIVT47.js} +26 -2
  83. package/dist/bundle/chunk-UQPW42HF.js +18 -0
  84. package/dist/bundle/{chunk-USLZE36C.js → chunk-V2WXTILT.js} +6 -6
  85. package/dist/bundle/{chunk-BDYWZ7JE.js → chunk-VQKNKJYL.js} +46 -7
  86. package/dist/bundle/{chunk-XPXKD63J.js → chunk-VR3YKXHL.js} +93 -31
  87. package/dist/bundle/{chunk-UIEA6FIV.js → chunk-VUUPFDRU.js} +27 -28
  88. package/dist/bundle/{chunk-KE4XPPRQ.js → chunk-WYTYHUFH.js} +1750 -138
  89. package/dist/bundle/{chunk-PBMSBCVB.js → chunk-XLGDNI4S.js} +1 -1
  90. package/dist/bundle/{chunk-3J5KAFNA.js → chunk-XVZNFA2P.js} +4935 -3623
  91. package/dist/bundle/chunk-Y5U4HIZS.js +71 -0
  92. package/dist/bundle/chunk-YTIPTHEE.js +47 -0
  93. package/dist/bundle/cli-KW6QQVS5.js +1101 -0
  94. package/dist/bundle/command-contract-CE543JBN.js +41 -0
  95. package/dist/bundle/command-server-entry-OC4E4DED.js +171 -0
  96. package/dist/bundle/{decode-HTOQ6S3V.js → decode-AH5ZLLDK.js} +8 -8
  97. package/dist/bundle/{dispatch-SH5SP6LA.js → dispatch-CDWZZ54Q.js} +9 -9
  98. package/dist/bundle/drive.js +13 -13
  99. package/dist/bundle/{echarts-KFHB6SLX.js → echarts-VC7MTXWY.js} +2 -2
  100. package/dist/bundle/{embed-YATFB2PN.js → embed-EPSQY6QG.js} +9 -9
  101. package/dist/bundle/{embedder-MQPDFGTJ.js → embedder-TK4U4TJR.js} +12 -12
  102. package/dist/bundle/entry-3VN23M7M.js +25 -0
  103. package/dist/bundle/{failure-4FQL4XJI.js → failure-WSVZOPFE.js} +4 -4
  104. package/dist/bundle/first-run-7ZYJ7EB3.js +30 -0
  105. package/dist/bundle/first-screen-CZDH7QY3.js +39 -0
  106. package/dist/bundle/google-OBZMWA7J.js +45 -0
  107. package/dist/bundle/{google-api-QMFGCXBM.js → google-api-AV4X2JH3.js} +68 -57
  108. package/dist/bundle/grants-WTRLN4ZI.js +111 -0
  109. package/dist/bundle/{identity-FYVDK4M2.js → identity-CGHHF7AK.js} +8 -6
  110. package/dist/bundle/{instructions-D3GF3B7M.js → instructions-24PHDBBE.js} +1 -1
  111. package/dist/bundle/{login-COFZ2IWP.js → login-XHFESAFM.js} +73 -64
  112. package/dist/bundle/{mcp-RKJG22KM.js → mcp-M5YCSWJJ.js} +2 -2
  113. package/dist/bundle/{node-OFICOKX3.js → node-GIDULTV5.js} +2 -2
  114. package/dist/bundle/{node-KM3CUABH.js → node-P4E63KXA.js} +9 -9
  115. package/dist/bundle/{node-sqlite-DNBTDOXD.js → node-sqlite-LINBOAWK.js} +13 -9
  116. package/dist/bundle/oauth-JHUX3KE3.js +22 -0
  117. package/dist/bundle/{open-PTPR2YWX.js → open-RYFKPNCJ.js} +8 -8
  118. package/dist/bundle/{openai-2KV5LUW4.js → openai-Q7YYUHJF.js} +28 -42
  119. package/dist/bundle/{process-EAW6NST2.js → process-VPIZTIJR.js} +1 -1
  120. package/dist/bundle/{program-6UV5Q5YN.js → program-IUXFRBZA.js} +419 -604
  121. package/dist/bundle/{prompt-634TPMJK.js → prompt-LF4KX3XL.js} +8 -8
  122. package/dist/bundle/{reasons-DDWCEYSQ.js → reasons-JPYOU5GV.js} +5 -5
  123. package/dist/bundle/{recognize-SJO6QUDW.js → recognize-KEWTJXFH.js} +7 -7
  124. package/dist/bundle/{remote-6JXZITKF.js → remote-HGGLB76S.js} +13 -10
  125. package/dist/bundle/{rerank-MD5VOPQ6.js → rerank-TDUKETFT.js} +10 -10
  126. package/dist/bundle/{serve-LZTROA2M.js → serve-XFYMKW5W.js} +12 -12
  127. package/dist/bundle/server-BDEV3CZJ.js +74 -0
  128. package/dist/bundle/{server-NSA3UAFY.js → server-PXIPSGFP.js} +48 -44
  129. package/dist/bundle/{services-F5A6XQCV.js → services-2BOCGMJU.js} +111 -41
  130. package/dist/bundle/{sqlite-runtime-7YF6REKS.js → sqlite-runtime-R7M5XUMW.js} +9 -9
  131. package/dist/bundle/{start-MUFLE6FA.js → start-YRLT4MQZ.js} +7 -7
  132. package/dist/bundle/{state-UC54F3YZ.js → state-NZ7WRJWH.js} +9 -9
  133. package/dist/bundle/{store-F5FJGWMR.js → store-7LCVDO7G.js} +63 -28
  134. package/dist/bundle/{store-J53YNAH6.js → store-ICDGPSEN.js} +27 -18
  135. package/dist/bundle/store-maintenance-command-SJPLY6IH.js +65 -0
  136. package/dist/bundle/tokens-FGTBE7VW.js +111 -0
  137. package/dist/commands/config.d.ts.map +1 -1
  138. package/dist/commands/config.js +6 -5
  139. package/dist/commands/config.js.map +1 -1
  140. package/dist/commands/context.d.ts +4 -2
  141. package/dist/commands/context.d.ts.map +1 -1
  142. package/dist/commands/context.js.map +1 -1
  143. package/dist/commands/discovery.d.ts +0 -1
  144. package/dist/commands/discovery.d.ts.map +1 -1
  145. package/dist/commands/discovery.js +6 -26
  146. package/dist/commands/discovery.js.map +1 -1
  147. package/dist/commands/documents.d.ts +2 -0
  148. package/dist/commands/documents.d.ts.map +1 -1
  149. package/dist/commands/documents.js +39 -3
  150. package/dist/commands/documents.js.map +1 -1
  151. package/dist/commands/knowledge.d.ts.map +1 -1
  152. package/dist/commands/knowledge.js +7 -6
  153. package/dist/commands/knowledge.js.map +1 -1
  154. package/dist/commands/search.d.ts.map +1 -1
  155. package/dist/commands/search.js +11 -8
  156. package/dist/commands/search.js.map +1 -1
  157. package/dist/config.d.ts +14 -0
  158. package/dist/config.d.ts.map +1 -1
  159. package/dist/config.js +35 -4
  160. package/dist/config.js.map +1 -1
  161. package/dist/contract-overrides.d.ts +16 -4
  162. package/dist/contract-overrides.d.ts.map +1 -1
  163. package/dist/contract-overrides.js +86 -410
  164. package/dist/contract-overrides.js.map +1 -1
  165. package/dist/documents-add.d.ts +49 -0
  166. package/dist/documents-add.d.ts.map +1 -0
  167. package/dist/documents-add.js +122 -0
  168. package/dist/documents-add.js.map +1 -0
  169. package/dist/errors.d.ts +1 -0
  170. package/dist/errors.d.ts.map +1 -1
  171. package/dist/errors.js +13 -1
  172. package/dist/errors.js.map +1 -1
  173. package/dist/google-api.d.ts.map +1 -1
  174. package/dist/google-api.js +4 -1
  175. package/dist/google-api.js.map +1 -1
  176. package/dist/identity.d.ts +4 -0
  177. package/dist/identity.d.ts.map +1 -1
  178. package/dist/identity.js +22 -0
  179. package/dist/identity.js.map +1 -1
  180. package/dist/knowledge.d.ts +1 -1
  181. package/dist/knowledge.d.ts.map +1 -1
  182. package/dist/knowledge.js +17 -19
  183. package/dist/knowledge.js.map +1 -1
  184. package/dist/login.d.ts.map +1 -1
  185. package/dist/login.js +2 -2
  186. package/dist/login.js.map +1 -1
  187. package/dist/model.d.ts +3 -0
  188. package/dist/model.d.ts.map +1 -1
  189. package/dist/model.js.map +1 -1
  190. package/dist/program.d.ts.map +1 -1
  191. package/dist/program.js +30 -21
  192. package/dist/program.js.map +1 -1
  193. package/dist/reasons.d.ts.map +1 -1
  194. package/dist/reasons.js +25 -1
  195. package/dist/reasons.js.map +1 -1
  196. package/dist/store-transition.js +2 -2
  197. package/dist/store-transition.js.map +1 -1
  198. package/dist/store.d.ts.map +1 -1
  199. package/dist/store.js +27 -7
  200. package/dist/store.js.map +1 -1
  201. package/dist/tokens.d.ts +9 -2
  202. package/dist/tokens.d.ts.map +1 -1
  203. package/dist/tokens.js +18 -15
  204. package/dist/tokens.js.map +1 -1
  205. package/dist/version.d.ts +1 -1
  206. package/dist/version.js +1 -1
  207. package/dist/wcat.d.ts +3 -0
  208. package/dist/wcat.d.ts.map +1 -0
  209. package/dist/wcat.js +4 -0
  210. package/dist/wcat.js.map +1 -0
  211. package/package.json +8 -8
  212. package/dist/bundle/chunk-3NULZGQU.js +0 -27
  213. package/dist/bundle/chunk-DD7EFG6B.js +0 -35
  214. package/dist/bundle/chunk-M73NNJ3X.js +0 -26
  215. package/dist/bundle/chunk-SBZB7HMU.js +0 -1055
  216. package/dist/bundle/command-contract-H5OYJOPF.js +0 -38
  217. package/dist/bundle/dist-PY3MVR3G.js +0 -21
  218. package/dist/bundle/entry-YZBB647C.js +0 -22
  219. package/dist/bundle/first-run-5JT3UQZB.js +0 -30
  220. package/dist/bundle/first-screen-BEMDEWO7.js +0 -36
  221. package/dist/bundle/google-DVADVICN.js +0 -36
  222. package/dist/bundle/grants-WKB2E4TA.js +0 -103
  223. package/dist/bundle/oauth-PDQHWFBF.js +0 -22
  224. package/dist/bundle/server-GT7X666D.js +0 -69
  225. package/dist/bundle/store-maintenance-command-GJVXLBAB.js +0 -58
  226. package/dist/bundle/tokens-H2EJKGA5.js +0 -101
  227. package/dist/bundle/{chunk-SW6C6WH5.js → chunk-HVJJWJYQ.js} +0 -0
  228. package/dist/bundle/{mdast-util-from-markdown-FXEPSNER.js → mdast-util-from-markdown-CE73EWJ2.js} +3 -3
@@ -1,9 +1,12 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ sharedModel
5
+ } from "./chunk-E2F2XIX6.js";
3
6
  import {
4
7
  answerOf,
5
8
  messengerContext
6
- } from "./chunk-UJR272CP.js";
9
+ } from "./chunk-OT7SQQJK.js";
7
10
  import {
8
11
  chatEventAnswer,
9
12
  memberAnswer,
@@ -12,11 +15,46 @@ import {
12
15
  serveRelay,
13
16
  typedQuery,
14
17
  withQuery
15
- } from "./chunk-P7DEGRZA.js";
18
+ } from "./chunk-HPKE2GDP.js";
19
+ import {
20
+ FETCHING,
21
+ RULES_VERSION,
22
+ applyTaskRulesOnArrival,
23
+ capability,
24
+ newSendId,
25
+ onlineDeps,
26
+ openRequestTask,
27
+ patiently,
28
+ refuseLockedOutput,
29
+ senderIsMe,
30
+ servicesFor,
31
+ syncsOneChat
32
+ } from "./chunk-XVZNFA2P.js";
33
+ import {
34
+ embeddingKeys,
35
+ endpointKeyName,
36
+ modelGateway,
37
+ withTimeLimit
38
+ } from "./chunk-WYTYHUFH.js";
16
39
  import {
17
40
  stringWidth,
18
41
  wrapAnsi
19
42
  } from "./chunk-HTQTIKWP.js";
43
+ import {
44
+ holdLock,
45
+ lockPath,
46
+ releaseLock,
47
+ servingProfiles,
48
+ takeLock
49
+ } from "./chunk-COGWKO2T.js";
50
+ import {
51
+ QUICK_HEALTH_CHECKS,
52
+ fts5Tables,
53
+ invalidJson,
54
+ lossUnknown,
55
+ storeDamageReport,
56
+ storeHealth
57
+ } from "./chunk-2S3E2HVV.js";
20
58
  import {
21
59
  Command,
22
60
  LOCAL_READ,
@@ -24,8 +62,10 @@ import {
24
62
  REMOTE_READ,
25
63
  REMOTE_WRITE,
26
64
  annotate,
65
+ commandAt,
27
66
  destroysNothing,
28
67
  environmentOf,
68
+ grantsAuthority,
29
69
  itemOf,
30
70
  jsonlRecords,
31
71
  lineOf,
@@ -38,50 +78,21 @@ import {
38
78
  snakeKeys,
39
79
  storeTable,
40
80
  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";
81
+ } from "./chunk-5PLINHEY.js";
71
82
  import {
72
83
  codeOf,
73
- currentRun,
74
84
  levelFor,
75
- modelTarget,
76
85
  parseDuration
77
- } from "./chunk-OH3K2E7X.js";
86
+ } from "./chunk-PKM55ZRR.js";
78
87
  import {
79
- QUICK_HEALTH_CHECKS,
80
- explainDamage,
81
- fts5Tables,
82
- invalidJson,
83
- storeHealth
84
- } from "./chunk-KVW4XNKB.js";
88
+ modelTarget
89
+ } from "./chunk-5HVJK3ZJ.js";
90
+ import {
91
+ holdersOf
92
+ } from "./chunk-5VDVGDOC.js";
93
+ import {
94
+ readSecret
95
+ } from "./chunk-TYLEICTX.js";
85
96
  import {
86
97
  CORPORA,
87
98
  MIGRATIONS,
@@ -94,14 +105,13 @@ import {
94
105
  fillStems,
95
106
  fillTrigrams,
96
107
  fillVectorIndexes,
97
- formatLocator,
98
108
  involvementStoreOver,
109
+ isDerivedTable,
99
110
  migrate,
100
111
  noteIndexState,
101
112
  openSqlite,
102
113
  openStore,
103
114
  orphanPointers,
104
- parseLocator,
105
115
  pendingNormalization,
106
116
  readStoreTables,
107
117
  rebuildMentions,
@@ -117,36 +127,37 @@ import {
117
127
  storeClients,
118
128
  storeContents,
119
129
  vectorIndexCounts
120
- } from "./chunk-EWGVDFPT.js";
130
+ } from "./chunk-BIJW6AYA.js";
131
+ import {
132
+ openCache
133
+ } from "./chunk-V2WXTILT.js";
121
134
  import {
135
+ currentRun,
136
+ formatLocator,
137
+ parseLocator,
122
138
  readDamageMark,
123
139
  readHealthMark,
140
+ readJournalMark,
124
141
  recordDeepCheck
125
- } from "./chunk-CPMRM3GQ.js";
142
+ } from "./chunk-QJ57PV55.js";
126
143
  import {
127
144
  queryFieldsOf
128
- } from "./chunk-2FEZ24DK.js";
145
+ } from "./chunk-GVA3KTCD.js";
129
146
  import {
130
147
  failureKey,
131
148
  isStoreDamage
132
- } from "./chunk-B67BLRAI.js";
149
+ } from "./chunk-O53WLYX3.js";
133
150
  import {
134
151
  storePath
135
- } from "./chunk-DD7EFG6B.js";
136
- import {
137
- openCache
138
- } from "./chunk-USLZE36C.js";
139
- import {
140
- readSecret
141
- } from "./chunk-6B37XO6B.js";
152
+ } from "./chunk-3QFUDXMQ.js";
142
153
  import {
143
154
  resolvePaths,
144
155
  writeSecurely
145
- } from "./chunk-G4KEKKDE.js";
156
+ } from "./chunk-6X3KUFRQ.js";
146
157
  import {
147
158
  singleLine,
148
159
  visibleControls
149
- } from "./chunk-IDAK4DDK.js";
160
+ } from "./chunk-JQXK3M5M.js";
150
161
  import {
151
162
  array,
152
163
  boolean,
@@ -167,10 +178,10 @@ import {
167
178
  string,
168
179
  transform,
169
180
  trim
170
- } from "./chunk-BDYWZ7JE.js";
181
+ } from "./chunk-VQKNKJYL.js";
171
182
  import {
172
183
  CliError
173
- } from "./chunk-EJ4PNHPP.js";
184
+ } from "./chunk-IIHZTV6V.js";
174
185
  import {
175
186
  __commonJS,
176
187
  __name,
@@ -1824,7 +1835,7 @@ var require_liquid_node = __commonJS({
1824
1835
  return readFileAsync(filepath, "utf8");
1825
1836
  }
1826
1837
  __name(readFile, "readFile");
1827
- function existsSync10(filepath) {
1838
+ function existsSync11(filepath) {
1828
1839
  try {
1829
1840
  fs$1.statSync(filepath);
1830
1841
  return true;
@@ -1832,11 +1843,11 @@ var require_liquid_node = __commonJS({
1832
1843
  return false;
1833
1844
  }
1834
1845
  }
1835
- __name(existsSync10, "existsSync");
1836
- function readFileSync5(filepath) {
1846
+ __name(existsSync11, "existsSync");
1847
+ function readFileSync6(filepath) {
1837
1848
  return fs$1.readFileSync(filepath, "utf8");
1838
1849
  }
1839
- __name(readFileSync5, "readFileSync");
1850
+ __name(readFileSync6, "readFileSync");
1840
1851
  function resolve2(root, file2, ext) {
1841
1852
  if (!path.extname(file2))
1842
1853
  file2 += ext;
@@ -1850,10 +1861,10 @@ var require_liquid_node = __commonJS({
1850
1861
  }
1851
1862
  }
1852
1863
  __name(fallback, "fallback");
1853
- function dirname3(filepath) {
1864
+ function dirname4(filepath) {
1854
1865
  return path.dirname(filepath);
1855
1866
  }
1856
- __name(dirname3, "dirname");
1867
+ __name(dirname4, "dirname");
1857
1868
  var realpathAsync = promisify(fs$1.realpath);
1858
1869
  async function contains(root, file2) {
1859
1870
  try {
@@ -1881,11 +1892,11 @@ var require_liquid_node = __commonJS({
1881
1892
  __proto__: null,
1882
1893
  exists,
1883
1894
  readFile,
1884
- existsSync: existsSync10,
1885
- readFileSync: readFileSync5,
1895
+ existsSync: existsSync11,
1896
+ readFileSync: readFileSync6,
1886
1897
  resolve: resolve2,
1887
1898
  fallback,
1888
- dirname: dirname3,
1899
+ dirname: dirname4,
1889
1900
  contains,
1890
1901
  containsSync,
1891
1902
  sep: path.sep
@@ -3610,7 +3621,7 @@ var require_liquid_node = __commonJS({
3610
3621
  uri_escape,
3611
3622
  slugify
3612
3623
  });
3613
- var join5 = argumentsToValue(function(v, arg) {
3624
+ var join6 = argumentsToValue(function(v, arg) {
3614
3625
  const array2 = toArray(v);
3615
3626
  const sep = isNil(arg) ? " " : stringify(arg);
3616
3627
  let outputSize = sep.length * Math.max(array2.length - 1, 0);
@@ -3886,7 +3897,7 @@ var require_liquid_node = __commonJS({
3886
3897
  __name(sample, "sample");
3887
3898
  var arrayFilters = /* @__PURE__ */ Object.freeze({
3888
3899
  __proto__: null,
3889
- join: join5,
3900
+ join: join6,
3890
3901
  last,
3891
3902
  first,
3892
3903
  reverse,
@@ -5510,11 +5521,11 @@ var require_liquid_node = __commonJS({
5510
5521
  }
5511
5522
  });
5512
5523
 
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";
5524
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5525
+ 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";
5526
+ import { dirname as dirname3, resolve } from "node:path";
5516
5527
 
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
5528
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/sealed.js
5518
5529
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5519
5530
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5520
5531
  import { Transform } from "node:stream";
@@ -5621,7 +5632,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5621
5632
  renameSync(pending, to);
5622
5633
  }, "unsealFile");
5623
5634
 
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
5635
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5625
5636
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5626
5637
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5627
5638
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5645,7 +5656,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5645
5656
  };
5646
5657
  }, "compatibilityOf");
5647
5658
 
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
5659
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/store/repair.js
5649
5660
  import { createHash as createHash2 } from "node:crypto";
5650
5661
  var COPY_MARK = "__repair_";
5651
5662
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5899,17 +5910,99 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5899
5910
  return found;
5900
5911
  }, "deleteCopy");
5901
5912
 
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
5913
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5903
5914
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5904
5915
 
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
5916
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5906
5917
  import { existsSync as existsSync3 } from "node:fs";
5907
5918
 
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
5919
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/store/recover.js
5909
5920
  import { execFileSync, spawn } from "node:child_process";
5910
5921
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5911
5922
  import { basename, dirname, join } from "node:path";
5912
5923
  import { Transform as Transform2 } from "node:stream";
5924
+
5925
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/store/refill.js
5926
+ var REFILL_MARGIN_MS = 864e5;
5927
+ var TIME_KEYS = 1e12;
5928
+ var integerId = `external_id GLOB '[0-9]*' AND NOT external_id GLOB '*[^0-9]*'`;
5929
+ var forgetCoverageSince = /* @__PURE__ */ __name((database, cutoff, now = Date.now()) => {
5930
+ database.exec("BEGIN");
5931
+ try {
5932
+ const refetch = forget(database, cutoff, now);
5933
+ database.exec("COMMIT");
5934
+ return refetch;
5935
+ } catch (error) {
5936
+ database.exec("ROLLBACK");
5937
+ throw error;
5938
+ }
5939
+ }, "forgetCoverageSince");
5940
+ var forget = /* @__PURE__ */ __name((database, cutoff, now) => {
5941
+ const chats = /* @__PURE__ */ new Map();
5942
+ const held = database.prepare(`SELECT c.id, c.account_id, c.external_id AS chat, a.provider, a.external_id AS account,
5943
+ 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
5944
+ GROUP BY c.id`).all();
5945
+ for (const row of held) {
5946
+ const chat = Number(row.id);
5947
+ const top = Number(row.top);
5948
+ 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;
5949
+ if (keepTo !== null && top <= keepTo)
5950
+ continue;
5951
+ if (keepTo === null)
5952
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ?").run(chat);
5953
+ else {
5954
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ? AND from_key > ?").run(chat, keepTo);
5955
+ database.prepare("UPDATE sync_ranges SET to_key = ?, updated_at = ? WHERE chat_id = ? AND to_key > ?").run(keepTo, now, chat, keepTo);
5956
+ }
5957
+ const account = Number(row.account_id);
5958
+ const external = String(row.chat);
5959
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(account, `fetched:${external}`);
5960
+ database.prepare(`DELETE FROM sync_cursors WHERE account_id = ? AND key = ? AND NOT EXISTS
5961
+ (SELECT 1 FROM sync_ranges WHERE chat_id = ? AND from_key <= CAST(sync_cursors.value AS INTEGER))`).run(account, `history_start:${external}`, chat);
5962
+ const key = `${row.provider}\0${row.account}`;
5963
+ const one = chats.get(key) ?? { provider: String(row.provider), account: String(row.account), chats: 0 };
5964
+ one.chats += 1;
5965
+ chats.set(key, one);
5966
+ }
5967
+ return {
5968
+ since: cutoff === null ? null : new Date(cutoff).toISOString(),
5969
+ chats: [...chats.values()],
5970
+ mail: forgetMail(database, cutoff, now)
5971
+ };
5972
+ }, "forget");
5973
+ var forgetMail = /* @__PURE__ */ __name((database, cutoff, now) => {
5974
+ const folders = /* @__PURE__ */ new Map();
5975
+ const points = database.prepare(`SELECT s.account_id, s.key, s.value, a.external_id AS account FROM sync_cursors s
5976
+ JOIN accounts a ON a.id = s.account_id WHERE a.provider = 'email' AND s.key LIKE 'mail_resume:%'`).all();
5977
+ for (const row of points) {
5978
+ let point;
5979
+ try {
5980
+ point = JSON.parse(String(row.value));
5981
+ } catch {
5982
+ continue;
5983
+ }
5984
+ const account = String(row.account);
5985
+ if (!Array.isArray(point.done)) {
5986
+ if (cutoff !== null && Date.parse(point.updatedAt ?? "") < cutoff)
5987
+ continue;
5988
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(Number(row.account_id), String(row.key));
5989
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5990
+ continue;
5991
+ }
5992
+ const folder = String(row.key).slice("mail_resume:".length);
5993
+ 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
5994
+ WHERE l.mailbox_id = (SELECT id FROM mailboxes WHERE account_id = ? AND external_id = ?)
5995
+ AND l.uidvalidity = ? AND coalesce(e.received_at, e.sent_at) < ?`).get(Number(row.account_id), folder, point.validity ?? "", cutoff)?.uid;
5996
+ const done = last === null ? [] : point.done.filter(([from]) => from <= last).map(([from, to]) => [from, Math.min(to, last)]);
5997
+ if (JSON.stringify(done) === JSON.stringify(point.done))
5998
+ continue;
5999
+ 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));
6000
+ folders.set(account, (folders.get(account) ?? 0) + 1);
6001
+ }
6002
+ return [...folders].map(([account, count3]) => ({ account, folders: count3 }));
6003
+ }, "forgetMail");
6004
+
6005
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/store/recover.js
5913
6006
  var SQLITE3_MINIMUM = [3, 43, 0];
5914
6007
  var STORE_PARTS = ["", "-wal", "-shm"];
5915
6008
  var RECOVER_LOCK = ".recover-lock";
@@ -6004,9 +6097,12 @@ var storeHolders = /* @__PURE__ */ __name((path) => {
6004
6097
  return { pid, name };
6005
6098
  });
6006
6099
  }, "storeHolders");
6007
- var tableRows = /* @__PURE__ */ __name((database) => {
6100
+ var dataTables = /* @__PURE__ */ __name((database) => {
6008
6101
  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}_`)));
6102
+ 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}_`)));
6103
+ }, "dataTables");
6104
+ var tableRows = /* @__PURE__ */ __name((database) => {
6105
+ const tables = dataTables(database);
6010
6106
  return Object.fromEntries(tables.map((table) => {
6011
6107
  try {
6012
6108
  return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
@@ -6015,6 +6111,117 @@ var tableRows = /* @__PURE__ */ __name((database) => {
6015
6111
  }
6016
6112
  }));
6017
6113
  }, "tableRows");
6114
+ var sourceTables = /* @__PURE__ */ __name((database) => {
6115
+ const withoutRowid = new Set(database.prepare("SELECT name FROM pragma_table_list WHERE wr = 1").all().map((row) => String(row.name)));
6116
+ return dataTables(database).filter((table) => table !== LOST_AND_FOUND && !withoutRowid.has(table) && !isDerivedTable(table));
6117
+ }, "sourceTables");
6118
+ var indexedButGone = /* @__PURE__ */ __name((database) => {
6119
+ const found = {};
6120
+ for (const table of sourceTables(database)) {
6121
+ const indexes = database.prepare("SELECT name FROM pragma_index_list(?) WHERE partial = 0 ORDER BY name").all(table).map((row) => String(row.name));
6122
+ for (const index of indexes) {
6123
+ const columns = database.prepare("SELECT cid, name FROM pragma_index_xinfo(?) WHERE key = 1 ORDER BY seqno").all(index);
6124
+ if (columns.some((column) => Number(column.cid) < 0))
6125
+ continue;
6126
+ const keys = columns.map((column) => `"${String(column.name)}"`).join(", ");
6127
+ const grouped = `${keys}, row_id`;
6128
+ let rows;
6129
+ try {
6130
+ 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);
6131
+ } catch {
6132
+ continue;
6133
+ }
6134
+ if (rows > (found[table]?.rows ?? 0))
6135
+ found[table] = { rows, index };
6136
+ }
6137
+ }
6138
+ return found;
6139
+ }, "indexedButGone");
6140
+ var storedAs = /* @__PURE__ */ __name((declared) => {
6141
+ const type = declared.toUpperCase();
6142
+ if (type.includes("INT"))
6143
+ return ["integer"];
6144
+ if (/CHAR|CLOB|TEXT/.test(type))
6145
+ return ["text"];
6146
+ if (type === "" || type.includes("BLOB"))
6147
+ return null;
6148
+ if (/REAL|FLOA|DOUB/.test(type))
6149
+ return ["real", "integer"];
6150
+ return null;
6151
+ }, "storedAs");
6152
+ var columnsOf = /* @__PURE__ */ __name((database, table) => {
6153
+ const all = database.prepare('SELECT name, type, "notnull" AS required, dflt_value, pk FROM pragma_table_info(?)').all(table);
6154
+ const keys = all.filter((column) => Number(column.pk) > 0);
6155
+ return all.map((column) => ({
6156
+ name: String(column.name),
6157
+ type: String(column.type),
6158
+ required: Number(column.required) === 1,
6159
+ hasDefault: column.dflt_value !== null,
6160
+ rowid: keys.length === 1 && Number(column.pk) === 1 && String(column.type).toUpperCase() === "INTEGER"
6161
+ }));
6162
+ }, "columnsOf");
6163
+ var fits = /* @__PURE__ */ __name((columns, fields, types) => fields <= columns.length && columns.every((column, at) => {
6164
+ if (at >= fields)
6165
+ return !column.required || column.hasDefault;
6166
+ const type = types[at];
6167
+ if (column.rowid)
6168
+ return type === "null" || type === "integer";
6169
+ if (type === "null")
6170
+ return !column.required;
6171
+ const allowed = storedAs(column.type);
6172
+ return allowed === null || allowed.includes(type);
6173
+ }), "fits");
6174
+ var placeLostRows = /* @__PURE__ */ __name((database) => {
6175
+ if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND))
6176
+ return {};
6177
+ 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));
6178
+ const tables = sourceTables(database).map((table) => ({ table, columns: columnsOf(database, table) }));
6179
+ 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();
6180
+ const placed = {};
6181
+ const triggers = [];
6182
+ const quiet = /* @__PURE__ */ __name((table) => {
6183
+ if (table in placed)
6184
+ return;
6185
+ placed[table] = 0;
6186
+ for (const row of database.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?").all(table)) {
6187
+ triggers.push(String(row.sql));
6188
+ database.exec(`DROP TRIGGER "${String(row.name)}"`);
6189
+ }
6190
+ }, "quiet");
6191
+ database.exec("PRAGMA foreign_keys = OFF");
6192
+ database.exec("BEGIN");
6193
+ try {
6194
+ for (const row of rows) {
6195
+ const count3 = Number(row.nfield);
6196
+ const types = fields.slice(0, count3).map((field) => String(row[field]));
6197
+ const fitting = tables.filter(({ columns: columns2 }) => fits(columns2, count3, types));
6198
+ if (fitting.length !== 1)
6199
+ continue;
6200
+ const { table, columns } = fitting[0];
6201
+ quiet(table);
6202
+ const given = columns.slice(0, count3);
6203
+ const names = [...given.some((column) => column.rowid) ? [] : ["rowid"], ...given.map((column) => column.name)];
6204
+ const values = [
6205
+ ...given.some((column) => column.rowid) ? [] : ["id"],
6206
+ ...given.map((column, at) => column.rowid ? "id" : `c${at}`)
6207
+ ];
6208
+ 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));
6209
+ if (Number(inserted.changes) === 0)
6210
+ continue;
6211
+ placed[table] = (placed[table] ?? 0) + 1;
6212
+ database.prepare(`DELETE FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6213
+ }
6214
+ for (const sql of triggers)
6215
+ database.exec(sql);
6216
+ database.exec("COMMIT");
6217
+ } catch (error) {
6218
+ database.exec("ROLLBACK");
6219
+ throw error;
6220
+ } finally {
6221
+ database.exec("PRAGMA foreign_keys = ON");
6222
+ }
6223
+ return Object.fromEntries(Object.entries(placed).filter(([, rows2]) => rows2 > 0));
6224
+ }, "placeLostRows");
6018
6225
  var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
6019
6226
  const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
6020
6227
  stdio: ["ignore", "pipe", "pipe"]
@@ -6211,6 +6418,9 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6211
6418
  throw error;
6212
6419
  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
6420
  }
6421
+ note("looking for rows the indexes list and the tables no longer hold");
6422
+ const gone = indexedButGone(watch);
6423
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6214
6424
  const before = { data: dataVersion(), inode: statSync2(path).ino };
6215
6425
  const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6216
6426
  const target = `${path}.recovering-${stamp}`;
@@ -6239,7 +6449,10 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6239
6449
  let json;
6240
6450
  let fetch;
6241
6451
  let schema;
6452
+ let placed;
6453
+ let refetch;
6242
6454
  try {
6455
+ placed = placeLostRows(opened.database);
6243
6456
  kept = tableRows(opened.database);
6244
6457
  migrate(opened.database, { command, ...version ? { version } : {} });
6245
6458
  note("clearing values that are not valid JSON");
@@ -6248,6 +6461,8 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6248
6461
  note("looking for rows that point at rows that were lost");
6249
6462
  dangling = danglingRows(opened.database);
6250
6463
  fetch = mailToFetch(opened.database);
6464
+ const good = lastKnownGood === null ? Number.NaN : Date.parse(lastKnownGood);
6465
+ refetch = forgetCoverageSince(opened.database, Number.isNaN(good) ? null : good - REFILL_MARGIN_MS, now());
6251
6466
  schema = fileSchemaOf(opened.database).version;
6252
6467
  opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6253
6468
  } catch (error) {
@@ -6277,16 +6492,29 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6277
6492
  if (existsSync2(`${target}${suffix}`))
6278
6493
  renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6279
6494
  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);
6495
+ const lost = Object.entries(rowsBefore).map(([table, before2]) => {
6496
+ const goneAtLeast = Math.max(0, (gone[table]?.rows ?? 0) - (placed[table] ?? 0));
6497
+ return {
6498
+ table,
6499
+ before: before2,
6500
+ read: read[table] ?? 0,
6501
+ kept: kept[table] ?? 0,
6502
+ goneAtLeast,
6503
+ seenIn: goneAtLeast > 0 ? gone[table]?.index ?? null : null
6504
+ };
6505
+ }).filter(({ before: before2, read: read2, kept: kept2, goneAtLeast }) => before2 === null || before2 > kept2 || read2 > kept2 || goneAtLeast > 0);
6281
6506
  const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6282
6507
  return {
6283
6508
  path,
6284
6509
  keptAt,
6285
6510
  sqlite3: program.version,
6286
6511
  lost,
6512
+ placed,
6513
+ lastKnownGood,
6287
6514
  dangling,
6288
6515
  invalidJson: json,
6289
6516
  mailToFetch: fetch,
6517
+ refetch,
6290
6518
  rebuilt,
6291
6519
  copyErrors,
6292
6520
  health,
@@ -6302,7 +6530,7 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6302
6530
  }
6303
6531
  }, "recoverLocked");
6304
6532
 
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
6533
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6306
6534
  var COUNTED = [
6307
6535
  "accounts",
6308
6536
  "chats",
@@ -6335,18 +6563,23 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6335
6563
  }
6336
6564
  } catch {
6337
6565
  }
6566
+ const journal = readJournalMark(path);
6338
6567
  recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
6339
6568
  const mark = readDamageMark(path);
6340
- const explanation = explainDamage(health, command, mark);
6569
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6341
6570
  const inUse = storeHolders(path) ?? null;
6342
6571
  const timers = activeTimers() ?? null;
6343
6572
  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
- ];
6573
+ const report = storeDamageReport({
6574
+ health,
6575
+ command,
6576
+ mark,
6577
+ journal,
6578
+ lastOkAt: lastKnownGood,
6579
+ holders: inUse,
6580
+ timers,
6581
+ sqlite3Usable: sqlite3.usable
6582
+ });
6350
6583
  return {
6351
6584
  path,
6352
6585
  exists: true,
@@ -6357,13 +6590,13 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6357
6590
  damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
6358
6591
  invalidJson: health.invalidJson ?? [],
6359
6592
  rows,
6360
- explanation,
6593
+ report,
6361
6594
  damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
6362
- lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
6595
+ lastKnownGood,
6363
6596
  inUse,
6364
6597
  timers,
6365
6598
  sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
6366
- next
6599
+ next: report?.steps.map((step) => step.command) ?? []
6367
6600
  };
6368
6601
  }, "storeRecoveryCheck");
6369
6602
  var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, note, timers: scheduled = activeTimers, copy }) => {
@@ -6389,12 +6622,27 @@ var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, no
6389
6622
  next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
6390
6623
  };
6391
6624
  }, "storeRecoveryRun");
6625
+ var refetchNotes = /* @__PURE__ */ __name(({ since, chats, mail }) => {
6626
+ const from = since === null ? "from the start" : `from ${since} on`;
6627
+ const marked = [
6628
+ ...chats.map(({ provider, account, chats: chats2 }) => `${chats2} chats of ${provider} ${account}`),
6629
+ ...mail.map(({ account, folders }) => `${folders} mail folders of ${account}`)
6630
+ ];
6631
+ return [
6632
+ 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`,
6633
+ ...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`),
6634
+ "notes, memories, tags and whatever else only this store held cannot be fetched again"
6635
+ ];
6636
+ }, "refetchNotes");
6392
6637
  var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6393
6638
  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` : ""}`);
6639
+ 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
6640
  return [
6396
6641
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6397
- ...lost.length ? lost : ["no table lost a row"],
6642
+ ...lost,
6643
+ ...Object.entries(answer.placed).map(([table, rows]) => `${table}: ${rows} rows found on pages no table claimed were put back`),
6644
+ ...refetchNotes(answer.refetch),
6645
+ lossUnknown(answer.lastKnownGood, lost.some((line) => line.includes("are gone"))),
6398
6646
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6399
6647
  ...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
6648
  ...answer.next.map((line) => `next: ${line}`)
@@ -6402,13 +6650,16 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6402
6650
  }
6403
6651
  if (!answer.exists)
6404
6652
  return ["no store yet"];
6405
- if (answer.ok)
6653
+ const report = answer.report;
6654
+ if (!report)
6406
6655
  return [`the store is healthy (checked every page and search index in ${answer.seconds} s)`];
6407
- const why = answer.explanation;
6408
6656
  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}`)
6657
+ report.whatHappened,
6658
+ ...report.impact,
6659
+ report.externalDataSafe,
6660
+ report.loss,
6661
+ ...report.likelyCauses.map(({ cause, check: check2 }) => `maybe: ${cause} \u2014 check: ${check2}`),
6662
+ ...report.steps.map(({ command, why, destructive }) => `next: ${command} # ${destructive ? "changes things: " : ""}${why}`)
6412
6663
  ];
6413
6664
  }, "recoveryNotes");
6414
6665
  var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
@@ -6420,7 +6671,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6420
6671
  for (const line of recoveryNotes(answer))
6421
6672
  output.renderer.note(line);
6422
6673
  });
6423
- recover.addCommand(annotate(new Command("run"), { effects: LOCAL_WRITE, examples: [`${command} store recover run`] }).summary("rebuild a damaged store from every row it can read").description("copy every readable row into a new file with the sqlite3 program, rebuild the search indexes, mentions and vector index, check it, and put it in place of the store; the damaged file is kept beside it. Refuses while a WireCat timer or process has the store").action(async function() {
6674
+ recover.addCommand(grantsAuthority(annotate(new Command("run"), { effects: LOCAL_WRITE, examples: [`${command} store recover run`] })).summary("rebuild a damaged store from every row it can read").description("copy every readable row into a new file with the sqlite3 program, rebuild the search indexes, mentions and vector index, check it, and put it in place of the store; the damaged file is kept beside it. Refuses while a WireCat timer or process has the store").action(async function() {
6424
6675
  const output = outputFor(this);
6425
6676
  const answer = await storeRecoveryRun(environmentOf(this).env ?? process.env, {
6426
6677
  command,
@@ -6435,7 +6686,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6435
6686
  return recover;
6436
6687
  }, "storeRecoverCommand");
6437
6688
 
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
6689
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6439
6690
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6440
6691
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6441
6692
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6480,8 +6731,12 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6480
6731
  const answer = await storeInfo(environmentOf(this).env ?? process.env);
6481
6732
  renderAnswer(this, outputFor(this), itemOf(answer));
6482
6733
  }), "storeInfoCommand");
6734
+ var sharedStoreCommand = /* @__PURE__ */ __name((app) => {
6735
+ const store = annotate(new Command("store"), { effects: LOCAL_READ }).description("the shared local store every WireCat tool reads").addCommand(storeInfoCommand());
6736
+ return app ? store.addCommand(storeRecoverCommand(app)) : store;
6737
+ }, "sharedStoreCommand");
6483
6738
 
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
6739
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6485
6740
  var ENCRYPT_OPTION = [
6486
6741
  "--encrypt",
6487
6742
  "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 +6755,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6500
6755
  return password;
6501
6756
  }, "passwordOf");
6502
6757
 
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
6758
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/rules.js
6504
6759
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6505
6760
  import { join as join2 } from "node:path";
6506
6761
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6671,7 +6926,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6671
6926
  }, "problem");
6672
6927
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6673
6928
 
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
6929
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/state.js
6675
6930
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6676
6931
  import { join as join3 } from "node:path";
6677
6932
  var ANSWERED_KEPT = 1e3;
@@ -6724,7 +6979,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6724
6979
  }, "recordReply");
6725
6980
  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
6981
 
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
6982
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/decide.js
6728
6983
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6729
6984
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6730
6985
  const { message, chat, owner, sender } = incoming;
@@ -6830,10 +7085,10 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6830
7085
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6831
7086
  }, "filled");
6832
7087
 
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
7088
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/template.js
6834
7089
  var import_liquidjs2 = __toESM(require_liquid_node(), 1);
6835
7090
 
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
7091
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/render/liquid.js
6837
7092
  var import_liquidjs = __toESM(require_liquid_node(), 1);
6838
7093
  var safeLiquid = /* @__PURE__ */ __name((limits) => {
6839
7094
  const engine = new import_liquidjs.Liquid({
@@ -6860,7 +7115,7 @@ var safeLiquid = /* @__PURE__ */ __name((limits) => {
6860
7115
  return engine;
6861
7116
  }, "safeLiquid");
6862
7117
 
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
7118
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/template.js
6864
7119
  var TEMPLATE_LIMITS = {
6865
7120
  parse: 32768,
6866
7121
  renders: 2e3,
@@ -6999,7 +7254,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6999
7254
  }
7000
7255
  }, "renderReplyTemplate");
7001
7256
 
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
7257
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7003
7258
  var DRY_RUN_DAYS = 7;
7004
7259
  var PAGE = 500;
7005
7260
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7113,7 +7368,28 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7113
7368
  }
7114
7369
  }, "storedSince");
7115
7370
 
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
7371
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/models/purpose.js
7372
+ var HOSTED = {
7373
+ openai: "https://api.openai.com/v1",
7374
+ anthropic: "https://api.anthropic.com"
7375
+ };
7376
+ var purposeModel = /* @__PURE__ */ __name((settings, purpose, deps) => {
7377
+ const configured = modelTarget(settings, purpose);
7378
+ if (configured) {
7379
+ const baseUrl = configured.baseUrl ?? HOSTED[configured.provider] ?? "";
7380
+ return {
7381
+ target: { ...configured, baseUrl },
7382
+ key: /* @__PURE__ */ __name(() => embeddingKeys(deps.app, deps.env, deps.keyring).read(configured.baseUrl === void 0 ? configured.provider : endpointKeyName(configured.baseUrl))?.key, "key")
7383
+ };
7384
+ }
7385
+ const provider = settings.models?.[purpose]?.provider ?? settings.models?.default?.provider;
7386
+ if (provider === "off")
7387
+ return void 0;
7388
+ const shared = sharedModel(deps);
7389
+ return shared ? { target: shared.target, key: /* @__PURE__ */ __name(() => shared.key, "key"), shared: shared.setting } : void 0;
7390
+ }, "purposeModel");
7391
+
7392
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/consents.js
7117
7393
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7118
7394
  import { join as join4 } from "node:path";
7119
7395
  var shape = strictObject({
@@ -7138,19 +7414,21 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7138
7414
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7139
7415
  }, "mayModelReply");
7140
7416
 
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
7417
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7142
7418
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options = {
7143
7419
  ai: true
7144
7420
  }) => async (rule2, message, chat, now) => {
7421
+ const deps = { app, env, keyring: options.keyring };
7145
7422
  let called;
7146
7423
  const gateway = modelGateway({
7147
7424
  signal: options.signal,
7425
+ env,
7148
7426
  resolve: /* @__PURE__ */ __name((purpose) => {
7149
- called = modelTarget(settings(), purpose);
7150
- return called;
7427
+ called = purposeModel(settings(), purpose, deps);
7428
+ return called?.target;
7151
7429
  }, "resolve"),
7152
7430
  consent: /* @__PURE__ */ __name((_request, target) => mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(target.provider, target.baseUrl ?? ""), message.chatId), "consent"),
7153
- key: /* @__PURE__ */ __name((provider, target) => embeddingKeys(app, env, options.keyring).read(target.baseUrl === void 0 ? provider : endpointKeyName(target.baseUrl))?.key, "key")
7431
+ key: /* @__PURE__ */ __name(() => called?.key(), "key")
7154
7432
  });
7155
7433
  if (options.signal?.aborted)
7156
7434
  throw new CliError("cancelled", "reply rendering cancelled");
@@ -7172,9 +7450,8 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7172
7450
  });
7173
7451
  if (options.signal?.aborted)
7174
7452
  throw new CliError("cancelled", "reply rendering cancelled");
7175
- const current = modelTarget(settings(), "replies");
7176
- const baseUrl = called?.baseUrl ?? (called?.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
7177
- if (!called || JSON.stringify(current) !== JSON.stringify(called) || !mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.provider, baseUrl), message.chatId)) {
7453
+ const current = purposeModel(settings(), "replies", deps)?.target;
7454
+ if (!called || JSON.stringify(current) !== JSON.stringify(called.target) || !mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.target.provider, called.target.baseUrl), message.chatId)) {
7178
7455
  throw new CliError("permission_error", "reply model consent or configuration changed during rendering");
7179
7456
  }
7180
7457
  return result3;
@@ -7185,7 +7462,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7185
7462
  return result2;
7186
7463
  }, "replyRenderer");
7187
7464
 
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
7465
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/replies/serve.js
7189
7466
  var NOT_ALLOWED = "replies.send is not allow";
7190
7467
  var NO_RULES = "no rules";
7191
7468
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7278,7 +7555,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7278
7555
  return { skip: why };
7279
7556
  }, "replyTo");
7280
7557
 
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
7558
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7282
7559
  var START_SYNC_DELAY_MS = 3e4;
7283
7560
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7284
7561
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7355,7 +7632,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch, note, warn,
7355
7632
  };
7356
7633
  }, "startSync");
7357
7634
 
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
7635
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7359
7636
  var FIRST_FETCH_MS = 6e4;
7360
7637
  var DAY_MS = 864e5;
7361
7638
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7409,7 +7686,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs =
7409
7686
  };
7410
7687
  }, "memberFetches");
7411
7688
 
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
7689
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7413
7690
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7414
7691
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7415
7692
  if (context.format === "pretty") {
@@ -7442,7 +7719,93 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7442
7719
  return context;
7443
7720
  }, "recordDiagnostics");
7444
7721
 
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
7722
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7723
+ import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync2 } from "node:fs";
7724
+ import { dirname as dirname2, join as join5 } from "node:path";
7725
+ var OUTDATED_CHECK_MS = 6e4;
7726
+ var ownPackageRoot = /* @__PURE__ */ __name((running, script = process.argv[1]) => {
7727
+ let dir;
7728
+ try {
7729
+ dir = dirname2(realpathSync2(script ?? ""));
7730
+ } catch {
7731
+ return void 0;
7732
+ }
7733
+ for (let up = 0; up < 8; up++) {
7734
+ const manifest = join5(dir, "package.json");
7735
+ if (existsSync8(manifest))
7736
+ return installedVersion(dir) === running ? dir : void 0;
7737
+ const parent = dirname2(dir);
7738
+ if (parent === dir)
7739
+ return void 0;
7740
+ dir = parent;
7741
+ }
7742
+ return void 0;
7743
+ }, "ownPackageRoot");
7744
+ var installedVersion = /* @__PURE__ */ __name((root) => {
7745
+ try {
7746
+ const { version } = JSON.parse(readFileSync5(join5(root, "package.json"), "utf8"));
7747
+ return typeof version === "string" ? version : void 0;
7748
+ } catch {
7749
+ return void 0;
7750
+ }
7751
+ }, "installedVersion");
7752
+ var newer = /* @__PURE__ */ __name((one, other) => {
7753
+ const parts2 = /* @__PURE__ */ __name((version) => version.split(/[.+-]/, 3).map(Number), "parts");
7754
+ const [a, b] = [parts2(one), parts2(other)];
7755
+ for (let i = 0; i < 3; i++)
7756
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
7757
+ return (a[i] ?? 0) > (b[i] ?? 0);
7758
+ return false;
7759
+ }, "newer");
7760
+ var outdatedReason = /* @__PURE__ */ __name(async ({ command, running, storePath: storePath2, packageRoot, speaks = SPEAKS }) => {
7761
+ const installed = packageRoot === void 0 ? void 0 : installedVersion(packageRoot);
7762
+ if (installed !== void 0 && newer(installed, running))
7763
+ return `${command} ${installed} is installed and this serve runs ${running}: stopping so it starts again on ${installed}`;
7764
+ if (!existsSync8(storePath2))
7765
+ return void 0;
7766
+ let schema;
7767
+ try {
7768
+ const { database } = await openSqlite(storePath2, { readOnly: true });
7769
+ try {
7770
+ schema = fileSchemaOf(database);
7771
+ } finally {
7772
+ database.close();
7773
+ }
7774
+ } catch {
7775
+ return void 0;
7776
+ }
7777
+ if (writableBy(schema, speaks))
7778
+ return void 0;
7779
+ 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`;
7780
+ }, "outdatedReason");
7781
+ var watchOutdated = /* @__PURE__ */ __name(({ check: check2, onOutdated, everyMs = OUTDATED_CHECK_MS }) => {
7782
+ let busy = false;
7783
+ let done = false;
7784
+ const timer = setInterval(() => {
7785
+ if (busy || done)
7786
+ return;
7787
+ busy = true;
7788
+ check2().then((reason) => {
7789
+ if (reason === void 0 || done)
7790
+ return;
7791
+ done = true;
7792
+ clearInterval(timer);
7793
+ onOutdated(reason);
7794
+ }).catch(() => {
7795
+ }).finally(() => {
7796
+ busy = false;
7797
+ });
7798
+ }, everyMs);
7799
+ timer.unref();
7800
+ return {
7801
+ stop: /* @__PURE__ */ __name(() => {
7802
+ done = true;
7803
+ clearInterval(timer);
7804
+ }, "stop")
7805
+ };
7806
+ }, "watchOutdated");
7807
+
7808
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7446
7809
  var STEMS_EVERY_MS = 3e4;
7447
7810
  var STEMS_SLICE_MS = 2e3;
7448
7811
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7482,7 +7845,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7482
7845
  };
7483
7846
  }, "stemFills");
7484
7847
 
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
7848
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/render/messages.js
7486
7849
  import { styleText } from "node:util";
7487
7850
  var TIME_WIDTH = 8;
7488
7851
  var INDENT = " ".repeat(TIME_WIDTH + 2);
@@ -7658,7 +8021,7 @@ var editedAt = /* @__PURE__ */ __name((message, options) => {
7658
8021
  return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
7659
8022
  }, "editedAt");
7660
8023
 
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
8024
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7662
8025
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7663
8026
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7664
8027
  kind: attachment.kind,
@@ -7670,6 +8033,7 @@ var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7670
8033
  width: attachment.width,
7671
8034
  height: attachment.height,
7672
8035
  duration: attachment.duration,
8036
+ local_path: attachment.localPath,
7673
8037
  contact: attachment.contact && defined({
7674
8038
  name: attachment.contact.name,
7675
8039
  first_name: attachment.contact.firstName,
@@ -7677,7 +8041,7 @@ var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7677
8041
  phone: attachment.contact.phone,
7678
8042
  user_id: attachment.contact.userId
7679
8043
  }),
7680
- buttons: attachment.buttons
8044
+ buttons: attachment.buttons?.map((row) => row.map(({ data: _data, ...button }) => button))
7681
8045
  }), "attachmentItem");
7682
8046
  var quotedItem = /* @__PURE__ */ __name((quoted) => quoted === null ? null : {
7683
8047
  id: quoted.id,
@@ -7753,7 +8117,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7753
8117
  locale: messenger.app.locale
7754
8118
  }), "viewOf");
7755
8119
 
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
8120
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7757
8121
  var observed = /* @__PURE__ */ __name((value) => ({
7758
8122
  value: value.value,
7759
8123
  observed_at: value.observedAt,
@@ -7820,7 +8184,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7820
8184
  }
7821
8185
  }, "watchEventItem");
7822
8186
 
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
8187
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7824
8188
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7825
8189
  output: { entity: "watch_item" },
7826
8190
  effects: REMOTE_READ,
@@ -7975,7 +8339,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
7975
8339
  }
7976
8340
  }, "describe");
7977
8341
 
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
8342
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
7979
8343
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
7980
8344
  const command = annotate(new Command("serve"), {
7981
8345
  output: { entity: "serve_summary" },
@@ -7999,8 +8363,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7999
8363
  }
8000
8364
  let relaying;
8001
8365
  const onReady = /* @__PURE__ */ __name(() => {
8002
- const listening = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8003
- holdLock(path, listening);
8366
+ const listening2 = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8367
+ holdLock(path, listening2);
8004
8368
  note({
8005
8369
  code: "listening",
8006
8370
  text: `listening for profile ${context.profile}, catching up on what arrived while it was down`
@@ -8009,7 +8373,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8009
8373
  return;
8010
8374
  relaying = relay.open(path, context.profile).then((address) => {
8011
8375
  if (address)
8012
- holdLock(path, { ...listening, relay: address });
8376
+ holdLock(path, { ...listening2, relay: address });
8013
8377
  }).catch((error) => {
8014
8378
  const errorCode = failureKey(error);
8015
8379
  warn({ code: "relay_failed", errorCode, text: `commands cannot run through this serve: ${errorCode}` });
@@ -8018,7 +8382,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8018
8382
  const counts = {};
8019
8383
  const rules = replying(context, messenger, Date.parse(startedAt));
8020
8384
  const tasks = tasking(context, warn);
8021
- const { handled, startSyncDelayMs } = environmentOf(this);
8385
+ const { handled, startSyncDelayMs, outdated: outdatedHook } = environmentOf(this);
8022
8386
  const count3 = /* @__PURE__ */ __name((event) => {
8023
8387
  counts[event.event] = (counts[event.event] ?? 0) + 1;
8024
8388
  if (event.event === "message") {
@@ -8090,9 +8454,25 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8090
8454
  withStore: /* @__PURE__ */ __name((work) => context.withStore((store) => work(store), { name: "serve stems" }), "withStore"),
8091
8455
  warn
8092
8456
  });
8457
+ const listening = new AbortController();
8458
+ let outdated;
8459
+ const packageRoot = outdatedHook?.packageRoot ?? ownPackageRoot(version);
8460
+ const watch = watchOutdated({
8461
+ check: /* @__PURE__ */ __name(() => outdatedReason({
8462
+ command: messenger.app.command,
8463
+ running: version,
8464
+ storePath: storePath(context.env),
8465
+ packageRoot
8466
+ }), "check"),
8467
+ onOutdated: /* @__PURE__ */ __name((reason) => {
8468
+ outdated = reason;
8469
+ listening.abort();
8470
+ }, "onOutdated"),
8471
+ ...outdatedHook?.everyMs === void 0 ? {} : { everyMs: outdatedHook.everyMs }
8472
+ });
8093
8473
  try {
8094
8474
  await listenUntilStopped(this, context, relay?.messenger ?? messenger, count3, {
8095
- stop: new AbortController(),
8475
+ stop: listening,
8096
8476
  catchUp: true,
8097
8477
  onReady,
8098
8478
  connected: /* @__PURE__ */ __name((open) => {
@@ -8105,6 +8485,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8105
8485
  }, "connected")
8106
8486
  });
8107
8487
  } finally {
8488
+ watch.stop();
8108
8489
  await relaying;
8109
8490
  await relay?.close();
8110
8491
  rules.stop();
@@ -8115,6 +8496,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8115
8496
  await tasks.settled();
8116
8497
  releaseLock(path);
8117
8498
  }
8499
+ if (outdated !== void 0)
8500
+ throw new CliError("configuration_error", outdated, { reason: "serve.outdated" });
8118
8501
  renderAnswer(this, context, itemOf({
8119
8502
  profile: context.profile,
8120
8503
  started_at: startedAt,
@@ -8239,8 +8622,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8239
8622
  };
8240
8623
  }, "tasking");
8241
8624
 
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";
8625
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8626
+ import { existsSync as existsSync9 } from "node:fs";
8244
8627
  var PATH = "store tables list";
8245
8628
  var STORE_TABLES_QUERY = {
8246
8629
  entity: "store_table",
@@ -8256,20 +8639,20 @@ var filterOf = /* @__PURE__ */ __name((words) => {
8256
8639
  const kind = terms.get("kind");
8257
8640
  return { ...name === void 0 ? {} : { name }, ...kind === void 0 ? {} : { kind } };
8258
8641
  }, "filterOf");
8259
- var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8260
- const tables = new Command("tables").description("the tables of the local archive");
8642
+ var storeTablesCommand = /* @__PURE__ */ __name((owner) => {
8643
+ const tables = new Command("tables").description("the tables of the local store");
8261
8644
  withQuery(annotate(tables.command("list"), {
8262
8645
  effects: LOCAL_READ,
8263
8646
  examples: [
8264
- `${messenger.app.command} store tables list`,
8265
- `${messenger.app.command} store tables list kind:data`,
8266
- `${messenger.app.command} store tables list --full --json`
8647
+ `${owner.app.command} store tables list`,
8648
+ `${owner.app.command} store tables list kind:data`,
8649
+ `${owner.app.command} store tables list --full --json`
8267
8650
  ]
8268
8651
  }), STORE_TABLES_QUERY).summary("every table of the local archive, with its kind and row count").description("every table of the local archive: its kind (data, search index, part of a search index, internal) and its rows, a search index's rows not counted; --full adds each table's size on disk, which reads the whole file (about ten seconds for 3 GB); changes nothing").action(async function(words) {
8269
8652
  const filter = filterOf(words);
8270
8653
  const { full } = this.optsWithGlobals();
8271
8654
  const path = storePath(environmentOf(this).env ?? process.env);
8272
- if (!existsSync8(path))
8655
+ if (!existsSync9(path))
8273
8656
  throw new CliError("not_found", `no store at ${path}`);
8274
8657
  const items = await readStoreTables(path, { filter, sizes: full === true });
8275
8658
  renderAnswer(this, outputFor(this), listOf(PATH, {
@@ -8282,7 +8665,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8282
8665
  return tables;
8283
8666
  }, "storeTablesCommand");
8284
8667
 
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
8668
+ // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@wirecat+cli-base@0.98.0_commander@15.0.0_esbuild@0.28.2_type_7618ae642a1b316105e0e055c769f604/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8286
8669
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8287
8670
  var WORD_INDEX = "message_words";
8288
8671
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8291,7 +8674,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
8291
8674
  }, "schemaOf");
8292
8675
  var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
8293
8676
  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");
8677
+ var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync10(path) ? statSync4(path).size : 0, "bytesOf");
8295
8678
  var reading = /* @__PURE__ */ __name(async (path, read) => {
8296
8679
  const database = await openCache(path);
8297
8680
  try {
@@ -8318,9 +8701,10 @@ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8318
8701
  }, "fileSchema");
8319
8702
  var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8320
8703
  const path = storePath(env);
8321
- if (!existsSync9(path))
8704
+ if (!existsSync10(path))
8322
8705
  return { path, exists: false };
8323
8706
  const checked = await storeHealth(path, { deep });
8707
+ const journal = readJournalMark(path);
8324
8708
  const recorded = deep ? recordDeepCheck(path, checked, {
8325
8709
  cli: command ?? "unknown",
8326
8710
  ...version ? { version } : {},
@@ -8338,13 +8722,15 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, v
8338
8722
  ...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
8339
8723
  ...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
8340
8724
  };
8341
- const damage = command ? explainDamage(checked, command, mark) : null;
8725
+ const damage = command ? storeDamageReport({ health: checked, command, mark, journal, lastOkAt: lastKnownGood }) : null;
8342
8726
  const healthOf = {
8343
8727
  health,
8344
8728
  lastKnownGood,
8345
8729
  ...mark ? { damageMark: withoutInode(mark) } : {},
8730
+ ...journal ? { journalMark: journal } : {},
8346
8731
  ...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
8347
- ...damage ? { damage } : {}
8732
+ // `what` keeps memo's doctor, which reads it, compiling until it moves to `whatHappened`.
8733
+ ...damage ? { damage: { what: damage.whatHappened, ...damage } } : {}
8348
8734
  };
8349
8735
  try {
8350
8736
  return await reading(path, (database) => {
@@ -8364,42 +8750,67 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, v
8364
8750
  }
8365
8751
  }, "storeSummary");
8366
8752
  var result = /* @__PURE__ */ __name((command, value, next = []) => renderAnswer(command, outputFor(command), itemOf(snakeKeys(value), { next })), "result");
8367
- var storeMaintenanceCommands = /* @__PURE__ */ __name((messenger) => [
8753
+ var chatty = /* @__PURE__ */ __name((owner) => owner.provider !== void 0, "chatty");
8754
+ var archive = /* @__PURE__ */ __name((owner) => chatty(owner) ? "local archive" : "local store", "archive");
8755
+ var createdBy = /* @__PURE__ */ __name((owner) => chatty(owner) ? `the first \`${owner.app.command}\` command that reads a chat creates it` : `the first \`${owner.app.command}\` command that saves anything creates it`, "createdBy");
8756
+ var storeMaintenanceCommands = /* @__PURE__ */ __name((owner) => [
8368
8757
  storeInfoCommand(),
8369
- checkCommand(messenger),
8370
- migrateCommand(messenger),
8371
- reindexCommand(messenger),
8758
+ checkCommand(owner),
8759
+ migrateCommand(owner),
8760
+ reindexCommand(owner),
8372
8761
  backupCommand(),
8373
- restoreCommand(messenger),
8762
+ restoreCommand(owner),
8374
8763
  decryptCommand(),
8375
- repairCommand(messenger),
8376
- resetCommand(messenger),
8764
+ repairCommand(owner),
8765
+ resetCommand(owner),
8377
8766
  copiesCommand(),
8378
- storeTablesCommand(messenger),
8379
- storeRecoverCommand({ command: messenger.app.command, version: messenger.app.version })
8767
+ storeTablesCommand(owner),
8768
+ storeRecoverCommand({ command: owner.app.command, version: owner.app.version })
8380
8769
  ], "storeMaintenanceCommands");
8381
- var refuseWhileServing = /* @__PURE__ */ __name((command, messenger) => {
8382
- const serving = servingProfiles(messenger.app, environmentOf(command).env ?? process.env);
8770
+ var EXAMPLES = {
8771
+ backup: "./backup.db",
8772
+ check: "",
8773
+ "copies delete": "messages_copy_1",
8774
+ decrypt: "./backup.enc --output ./restored.db",
8775
+ info: "",
8776
+ migrate: "",
8777
+ rebuild: "",
8778
+ repair: "--dry-run",
8779
+ reset: "",
8780
+ restore: "./backup.db"
8781
+ };
8782
+ var addStoreMaintenanceCommands = /* @__PURE__ */ __name((store, owner, profile) => {
8783
+ for (const command of storeMaintenanceCommands(owner))
8784
+ store.addCommand(command);
8785
+ for (const [path, args] of Object.entries(EXAMPLES)) {
8786
+ const command = commandAt(store, path);
8787
+ if (command)
8788
+ annotate(command, { examples: [`${owner.app.command} ${profile} store ${path} ${args}`.trimEnd()] });
8789
+ }
8790
+ return store;
8791
+ }, "addStoreMaintenanceCommands");
8792
+ var refuseWhileServing = /* @__PURE__ */ __name((command, owner) => {
8793
+ const serving = servingProfiles(owner.app, environmentOf(command).env ?? process.env);
8383
8794
  if (serving.length > 0) {
8384
- throw new CliError("validation_error", `${messenger.app.command} serve is running for ${serving.join(", ")} \u2014 ${serving.map((profile) => `\`${messenger.app.command} ${profile} server stop\``).join(", ")} first`);
8795
+ throw new CliError("validation_error", `${owner.app.command} serve is running for ${serving.join(", ")} \u2014 ${serving.map((profile) => `\`${owner.app.command} ${profile} server stop\``).join(", ")} first`);
8385
8796
  }
8386
8797
  }, "refuseWhileServing");
8387
- var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("repair"), { output: { entity: "store_repair" }, effects: LOCAL_WRITE }).summary("repair table shapes while keeping the old tables").description("bring every table to this build's shape, deleting nothing: a table of the wrong shape is kept as a copy beside a new one").option("--dry-run", "say what it would do, and change nothing").action(async function() {
8798
+ var repairCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("repair"), { output: { entity: "store_repair" }, effects: LOCAL_WRITE }).summary("repair table shapes while keeping the old tables").description("bring every table to this build's shape, deleting nothing: a table of the wrong shape is kept as a copy beside a new one").option("--dry-run", "say what it would do, and change nothing").action(async function() {
8388
8799
  const { renderer, format } = outputFor(this);
8389
8800
  const { dryRun: dryRun2 } = this.opts();
8390
8801
  const path = storePath(environmentOf(this).env ?? process.env);
8391
- if (!existsSync9(path)) {
8802
+ if (!existsSync10(path)) {
8392
8803
  result(this, { path, exists: false });
8393
8804
  return;
8394
8805
  }
8395
8806
  if (!dryRun2)
8396
- refuseWhileServing(this, messenger);
8807
+ refuseWhileServing(this, owner);
8397
8808
  const fresh = await openCache(":memory:");
8398
8809
  try {
8399
8810
  const report = await reading(path, (database) => repairStore(database, fresh, { dryRun: dryRun2 === true }));
8400
8811
  result(this, { path, ...report });
8401
8812
  if (format === "pretty")
8402
- for (const note of notesOf(report, messenger.app.command))
8813
+ for (const note of notesOf(report, owner.app.command))
8403
8814
  renderer.note(note);
8404
8815
  } finally {
8405
8816
  fresh.close();
@@ -8428,15 +8839,15 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
8428
8839
  }, "notesOf");
8429
8840
  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
8841
  const path = storePath(environmentOf(this).env ?? process.env);
8431
- if (!existsSync9(path))
8842
+ if (!existsSync10(path))
8432
8843
  throw new CliError("not_found", `no store at ${path}`);
8433
8844
  const deleted = await reading(path, (database) => deleteCopy(database, name));
8434
8845
  result(this, { path, deleted });
8435
8846
  })), "copiesCommand");
8436
- 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() {
8847
+ var checkCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ }).summary(`check the ${archive(owner)} for problems`).description(`whether the store is healthy \u2014 integrity, search indexes, disk${chatty(owner) ? ", and which chats are behind" : ""}`).action(async function() {
8437
8848
  const { renderer } = outputFor(this);
8438
8849
  const path = storePath(environmentOf(this).env ?? process.env);
8439
- if (!existsSync9(path)) {
8850
+ if (!existsSync10(path)) {
8440
8851
  result(this, { path, exists: false, ok: true });
8441
8852
  return;
8442
8853
  }
@@ -8447,7 +8858,7 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8447
8858
  result(this, { path, exists: true, ok: false, opens: false, error: messageOf2(error) });
8448
8859
  return;
8449
8860
  }
8450
- const { command } = messenger.app;
8861
+ const { command } = owner.app;
8451
8862
  const next = /* @__PURE__ */ new Map();
8452
8863
  const step = /* @__PURE__ */ __name((id, args = {}) => {
8453
8864
  if (!next.has(id))
@@ -8463,10 +8874,10 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8463
8874
  step("store.reindex");
8464
8875
  else if (stems && !stems.ready)
8465
8876
  step("store.migrate");
8466
- const behind = answer.chatsBehind.find((chat) => chat.provider === messenger.provider);
8467
- if (behind && messenger.history !== "store")
8877
+ const behind = answer.chatsBehind.find((chat) => chat.provider === owner.provider);
8878
+ if (behind && owner.history !== "store")
8468
8879
  step("messages.sync");
8469
- else if (behind && syncsOneChat(messenger))
8880
+ else if (behind && syncsOneChat(owner))
8470
8881
  step("messages.sync", { chat: behind.chat });
8471
8882
  result(this, answer, [...next.values()]);
8472
8883
  if (answer.schema.version < SPEAKS) {
@@ -8481,7 +8892,7 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8481
8892
  renderer.note(`${orphans} pointers name a row that is gone or a type the store does not know \u2014 see orphan_pointers`);
8482
8893
  if (answer.vectors && answer.vectors.unused > 0)
8483
8894
  renderer.note(`${answer.vectors.unused} vectors belong to no text the store still holds \u2014 \`${command} store rebuild\` drops them`);
8484
- const older = answer.conversations.filter((chat) => chat.provider === messenger.provider && !chat.current).length;
8895
+ const older = answer.conversations.filter((chat) => chat.provider === owner.provider && !chat.current).length;
8485
8896
  if (older > 0) {
8486
8897
  renderer.note(`${older} chats' conversations were built by older rules \u2014 \`${command} conversations links rebuild --chat <chat>\``);
8487
8898
  }
@@ -8499,7 +8910,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
8499
8910
  ...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
8500
8911
  ]);
8501
8912
  const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
8502
- const { bavail, bsize } = statfsSync2(dirname2(path));
8913
+ const { bavail, bsize } = statfsSync2(dirname3(path));
8503
8914
  const free = Number(bavail) * Number(bsize);
8504
8915
  const behind = schema.version > 0 ? chatsBehind(database) : [];
8505
8916
  const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
@@ -8584,19 +8995,19 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
8584
8995
  held: row.held === null ? null : isoOf(row.held),
8585
8996
  refreshed: isoOf(row.refreshed)
8586
8997
  })), "chatsBehind");
8587
- 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() {
8998
+ var migrateCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE }).summary(`migrate an older ${archive(owner)}`).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
8999
  const { renderer } = outputFor(this);
8589
9000
  const path = storePath(environmentOf(this).env ?? process.env);
8590
- if (!existsSync9(path)) {
9001
+ if (!existsSync10(path)) {
8591
9002
  result(this, { path, exists: false });
8592
- renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
9003
+ renderer.note(`no store yet \u2014 ${createdBy(owner)}`);
8593
9004
  return;
8594
9005
  }
8595
9006
  const answer = await reading(path, (database) => {
8596
9007
  const from = schemaOf(database).version;
8597
9008
  migrate(database, {
8598
- command: messenger.app.command,
8599
- version: messenger.app.version,
9009
+ command: owner.app.command,
9010
+ version: owner.app.version,
8600
9011
  rollback: { store: path, warn: /* @__PURE__ */ __name((line) => renderer.warn(line), "warn") }
8601
9012
  });
8602
9013
  const { normalized, indexed, terms } = buildWordIndex(database, (note) => renderer.note(note));
@@ -8648,10 +9059,10 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
8648
9059
  note(`indexing ${pending} notes`);
8649
9060
  return { notesIndexed: drainNoteIndex(database, stemmerCache()) };
8650
9061
  }, "buildNoteIndex");
8651
- 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() {
9062
+ var reindexCommand = /* @__PURE__ */ __name((owner) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE })).summary(`rebuild the ${archive(owner)}'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
9063
  const { renderer } = outputFor(this);
8653
9064
  const path = storePath(environmentOf(this).env ?? process.env);
8654
- if (!existsSync9(path)) {
9065
+ if (!existsSync10(path)) {
8655
9066
  result(this, { path, exists: false });
8656
9067
  return;
8657
9068
  }
@@ -8693,9 +9104,12 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
8693
9104
  const { encrypt } = this.opts();
8694
9105
  const path = storePath(environmentOf(this).env ?? process.env);
8695
9106
  const target = resolve(file2);
8696
- if (!existsSync9(path))
9107
+ const { app, env } = environmentOf(this);
9108
+ if (app)
9109
+ refuseLockedOutput(target, app, env ?? process.env, "<file>");
9110
+ if (!existsSync10(path))
8697
9111
  throw new CliError("not_found", `no store at ${path} to back up`);
8698
- if (existsSync9(target))
9112
+ if (existsSync10(target))
8699
9113
  throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
8700
9114
  const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
8701
9115
  const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
@@ -8728,55 +9142,55 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8728
9142
  const { output } = this.opts();
8729
9143
  const from = resolve(file2);
8730
9144
  const to = resolve(output);
8731
- if (!existsSync9(from))
9145
+ if (!existsSync10(from))
8732
9146
  throw new CliError("not_found", `no file at ${from}`);
8733
9147
  if (!isSealed(from))
8734
9148
  throw new CliError("validation_error", `${from} was not written with --encrypt`);
8735
- if (existsSync9(to))
9149
+ if (existsSync10(to))
8736
9150
  throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
8737
9151
  await unsealFile(from, to, await passwordOf(this, { twice: false }));
8738
9152
  result(this, { path: to, from, bytes: bytesOf2(to) });
8739
9153
  }), "decryptCommand");
8740
- 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) {
9154
+ var restoreCommand = /* @__PURE__ */ __name((owner) => grantsAuthority(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
9155
  const path = storePath(environmentOf(this).env ?? process.env);
8742
9156
  const given = resolve(file2);
8743
- if (!existsSync9(given))
9157
+ if (!existsSync10(given))
8744
9158
  throw new CliError("not_found", `no file at ${given}`);
8745
- refuseWhileServing(this, messenger);
9159
+ refuseWhileServing(this, owner);
8746
9160
  if (!isSealed(given))
8747
- return restoreFrom(this, messenger, given, given);
9161
+ return restoreFrom(this, owner, given, given);
8748
9162
  const opened = `${path}.unsealing-${process.pid}`;
8749
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9163
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8750
9164
  try {
8751
9165
  await unsealFile(given, opened, await passwordOf(this, { twice: false }));
8752
- await restoreFrom(this, messenger, opened, given);
9166
+ await restoreFrom(this, owner, opened, given);
8753
9167
  } finally {
8754
9168
  rmSync3(opened, { force: true });
8755
9169
  }
8756
9170
  }), "restoreCommand");
8757
- var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
9171
+ var restoreFrom = /* @__PURE__ */ __name(async (command, owner, backup, given) => {
8758
9172
  const { renderer } = outputFor(command);
8759
9173
  const path = storePath(environmentOf(command).env ?? process.env);
8760
- if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
9174
+ if (existsSync10(path) && realpathSync3(backup) === realpathSync3(path)) {
8761
9175
  throw new CliError("validation_error", `${backup} is the store itself`);
8762
9176
  }
8763
9177
  if (await isRollbackCopy(backup))
8764
- return rollBackFrom(command, messenger, backup);
9178
+ return rollBackFrom(command, owner, backup);
8765
9179
  const schema = await backupSchema(backup);
8766
9180
  const stamp = stampNow();
8767
- const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
9181
+ const kept = existsSync10(path) ? `${path}.before-restore-${stamp}` : null;
8768
9182
  if (kept) {
8769
9183
  const waitMs = environmentOf(command).storeLockWaitMs;
8770
- await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
9184
+ await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
8771
9185
  } else
8772
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9186
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8773
9187
  const incoming = `${path}.restoring-${stamp}`;
8774
9188
  copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
8775
9189
  chmodSync(incoming, 384);
8776
9190
  if (kept) {
8777
9191
  renameSync3(path, kept);
8778
9192
  for (const suffix of ["-wal", "-shm"])
8779
- if (existsSync9(`${path}${suffix}`))
9193
+ if (existsSync10(`${path}${suffix}`))
8780
9194
  renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
8781
9195
  }
8782
9196
  renameSync3(incoming, path);
@@ -8795,13 +9209,13 @@ var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
8795
9209
  return false;
8796
9210
  }
8797
9211
  }, "isRollbackCopy");
8798
- var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
9212
+ var rollBackFrom = /* @__PURE__ */ __name(async (command, owner, copy) => {
8799
9213
  const { renderer } = outputFor(command);
8800
9214
  const path = storePath(environmentOf(command).env ?? process.env);
8801
- if (!existsSync9(path))
9215
+ if (!existsSync10(path))
8802
9216
  throw new CliError("not_found", `no store at ${path} to roll back`);
8803
9217
  const waitMs = environmentOf(command).storeLockWaitMs;
8804
- await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
9218
+ await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
8805
9219
  const { database } = await openSqlite(path);
8806
9220
  let rolled;
8807
9221
  try {
@@ -8846,9 +9260,9 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
8846
9260
  return schema;
8847
9261
  }, "backupSchema");
8848
9262
  var STORE_LOCK_WAIT_MS = 1e3;
8849
- var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
8850
- const { command } = messenger.app;
8851
- const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
9263
+ var quiesce = /* @__PURE__ */ __name(async (path, owner, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
9264
+ const { command } = owner.app;
9265
+ const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync10(file2)).map((file2) => realpathSync3(file2));
8852
9266
  const holders = holdersOf(files);
8853
9267
  if (holders === void 0) {
8854
9268
  warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
@@ -8869,21 +9283,21 @@ var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs
8869
9283
  database.close();
8870
9284
  }
8871
9285
  }, "quiesce");
8872
- var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE }).summary("back up the local archive and replace it with an empty one").description("back the store up beside itself, then delete it and start an empty one at this build's schema; asks first, or --yes").option("--no-backup", "delete the store without backing it up first").option("--dry-run", "list every table it would empty, with its rows, and delete nothing").action(async function({ backup: keep, dryRun: dryRun2 }) {
9286
+ var resetCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE, mcp: false }).summary(`back up the ${archive(owner)} and replace it with an empty one`).description("back the store up beside itself, then delete it and start an empty one at this build's schema; asks first, or --yes").option("--no-backup", "delete the store without backing it up first").option("--dry-run", "list every table it would empty, with its rows, and delete nothing").action(async function({ backup: keep, dryRun: dryRun2 }) {
8873
9287
  const { renderer } = outputFor(this);
8874
- const { command } = messenger.app;
9288
+ const { command } = owner.app;
8875
9289
  const env = environmentOf(this).env ?? process.env;
8876
9290
  const path = storePath(env);
8877
- if (!existsSync9(path)) {
9291
+ if (!existsSync10(path)) {
8878
9292
  result(this, { path, exists: false, reset: false });
8879
- renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
9293
+ renderer.note(`no store at ${path} \u2014 nothing to reset; ${createdBy(owner)}`);
8880
9294
  return;
8881
9295
  }
8882
9296
  if (dryRun2) {
8883
- result(this, await resetPreview(path, messenger, env, keep));
9297
+ result(this, await resetPreview(path, owner, env, keep));
8884
9298
  return;
8885
9299
  }
8886
- refuseWhileServing(this, messenger);
9300
+ refuseWhileServing(this, owner);
8887
9301
  if (this.optsWithGlobals().yes !== true) {
8888
9302
  const what = `this deletes the store at ${path} and starts an empty one, ${keep ? "after a backup beside it" : "with no backup"}`;
8889
9303
  const answer = await answerOf(this, `${what}. Go ahead? [y/N] `);
@@ -8892,7 +9306,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8892
9306
  if (!/^\s*y(es)?\s*$/i.test(answer))
8893
9307
  throw new CliError("cancelled", "cancelled \u2014 the store is unchanged");
8894
9308
  }
8895
- await quiesce(path, messenger, "reset", (message) => renderer.warn(message), environmentOf(this).storeLockWaitMs);
9309
+ await quiesce(path, owner, "reset", (message) => renderer.warn(message), environmentOf(this).storeLockWaitMs);
8896
9310
  const backup = keep ? `${path}.backup-${stampNow()}` : null;
8897
9311
  let backedUp = null;
8898
9312
  if (backup) {
@@ -8918,10 +9332,10 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8918
9332
  renderer.note(backup ? `the store is empty at schema ${schema}; \`${command} store restore ${backup}\` puts the old one back once a build can read it` : `the store is empty at schema ${schema}; there is no backup`);
8919
9333
  }), "resetCommand");
8920
9334
  var STORE_PARTS2 = ["", "-wal", "-shm"];
8921
- 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)));
8924
- const serving = servingProfiles(messenger.app, env).length > 0;
9335
+ var resetPreview = /* @__PURE__ */ __name(async (path, owner, env, keep) => {
9336
+ const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync10(file2));
9337
+ const holders = holdersOf(files.map((file2) => realpathSync3(file2)));
9338
+ const serving = servingProfiles(owner.app, env).length > 0;
8925
9339
  const read = await readingOnly(path, (database) => ({
8926
9340
  schema: schemaOf(database).version,
8927
9341
  tables: emptiedTables(database)
@@ -8951,7 +9365,13 @@ export {
8951
9365
  checkFor,
8952
9366
  passes,
8953
9367
  seal,
9368
+ storeRecoveryCheck,
9369
+ storeRecoveryRun,
9370
+ recoveryNotes,
9371
+ storeRecoverCommand,
8954
9372
  storeInfo,
9373
+ storeInfoCommand,
9374
+ sharedStoreCommand,
8955
9375
  ENCRYPT_OPTION,
8956
9376
  passwordOf,
8957
9377
  REPLY_ACTIONS,
@@ -8970,12 +9390,28 @@ export {
8970
9390
  safeLiquid,
8971
9391
  DRY_RUN_DAYS,
8972
9392
  dryRun,
9393
+ senderFacts,
9394
+ purposeModel,
8973
9395
  replyConsentPathFor,
8974
9396
  readReplyConsent,
8975
9397
  writeReplyConsent,
8976
9398
  replyModelIdentity,
8977
9399
  replyRenderer,
9400
+ NOT_ALLOWED,
9401
+ NO_RULES,
9402
+ ONLY_TASK,
9403
+ NO_TASKS,
9404
+ replyTo,
9405
+ FIRST_FETCH_MS,
8978
9406
  DAY_MS,
9407
+ memberFetches,
9408
+ OUTDATED_CHECK_MS,
9409
+ ownPackageRoot,
9410
+ outdatedReason,
9411
+ watchOutdated,
9412
+ STEMS_EVERY_MS,
9413
+ STEMS_SLICE_MS,
9414
+ stemFills,
8979
9415
  renderMessages,
8980
9416
  messageItem,
8981
9417
  messageItems,
@@ -8985,5 +9421,6 @@ export {
8985
9421
  serveCommand,
8986
9422
  storeSummary,
8987
9423
  storeMaintenanceCommands,
9424
+ addStoreMaintenanceCommands,
8988
9425
  buildStems
8989
9426
  };