@wirecat/mail-cli 0.23.0 → 0.24.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 (121) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/bin/mail.js +2 -2
  3. package/dist/bundle/{all-profiles-CI32WFEV.js → all-profiles-VS7P6DJY.js} +11 -11
  4. package/dist/bundle/{anthropic-ICSOMJIN.js → anthropic-C5JXKGBS.js} +16 -7
  5. package/dist/bundle/{app-server-3F4ZB7DH.js → app-server-HU3LVU42.js} +51 -50
  6. package/dist/bundle/{bun-7AHNFZMZ.js → bun-QLFX47WZ.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-UIWRS4HI.js → bun-sqlite-W4PGAKVY.js} +5 -5
  8. package/dist/bundle/{chunk-ETIUB2DF.js → chunk-3FD3IATT.js} +6 -6
  9. package/dist/bundle/{chunk-6FSLEARF.js → chunk-3KSK5BBB.js} +2 -2
  10. package/dist/bundle/{chunk-I3YNNSGB.js → chunk-4QNHAM3J.js} +2 -2
  11. package/dist/bundle/{chunk-7SWWVDEZ.js → chunk-4W4EVVL4.js} +61 -21
  12. package/dist/bundle/{chunk-JDKC7EXM.js → chunk-5NLHDK7P.js} +50 -46
  13. package/dist/bundle/{chunk-AHRHP2H2.js → chunk-5X3GU5LI.js} +6 -6
  14. package/dist/bundle/{chunk-KNRONMVG.js → chunk-64ZG5ERD.js} +2 -2
  15. package/dist/bundle/{chunk-RIAZTS6C.js → chunk-6PWCQKMD.js} +12 -12
  16. package/dist/bundle/{chunk-4PNIZUEC.js → chunk-6VV7J2TN.js} +36 -57
  17. package/dist/bundle/{chunk-5AS5N7V5.js → chunk-A6J4MPTI.js} +3 -1
  18. package/dist/bundle/{chunk-ZYHBMDNU.js → chunk-AUTX2MLF.js} +11 -9
  19. package/dist/bundle/{chunk-5Y2WRUYP.js → chunk-B72343TK.js} +2 -2
  20. package/dist/bundle/{chunk-7SIWMF77.js → chunk-BFQQV22T.js} +1 -1
  21. package/dist/bundle/chunk-C3NYJW6B.js +1542 -0
  22. package/dist/bundle/{chunk-7ZDH2XEY.js → chunk-C5BMCLCQ.js} +4 -4
  23. package/dist/bundle/{chunk-JO4BJYVE.js → chunk-DW3F6DUW.js} +1 -1
  24. package/dist/bundle/chunk-EKGRNFYQ.js +18 -0
  25. package/dist/bundle/{chunk-4YTX5YAU.js → chunk-FKWUUCX2.js} +1361 -1539
  26. package/dist/bundle/{chunk-LLYVBO3R.js → chunk-FNLUKODV.js} +19 -19
  27. package/dist/bundle/{chunk-HGV7DSSA.js → chunk-H5FJTHVA.js} +2 -2
  28. package/dist/bundle/{chunk-3QVGB2CI.js → chunk-HBZAJINU.js} +4 -4
  29. package/dist/bundle/{chunk-BT7UUI6E.js → chunk-IRUN4XOV.js} +2 -2
  30. package/dist/bundle/{chunk-4TKQIXND.js → chunk-JMLIKXFO.js} +2 -2
  31. package/dist/bundle/{chunk-XV3M3NAN.js → chunk-JOQGJUFT.js} +1 -1
  32. package/dist/bundle/{chunk-NEDYKKJJ.js → chunk-JWMLMAHP.js} +4 -4
  33. package/dist/bundle/{chunk-5QQOUYNA.js → chunk-KGOVFEWZ.js} +3 -3
  34. package/dist/bundle/{chunk-NKDYHAHP.js → chunk-KV4VTKF3.js} +3 -3
  35. package/dist/bundle/chunk-LVGX7VTD.js +138 -0
  36. package/dist/bundle/{chunk-3DQYO7FB.js → chunk-MCPOZNWG.js} +1 -1
  37. package/dist/bundle/{chunk-SCH3NC5X.js → chunk-MTO6YVMN.js} +3 -3
  38. package/dist/bundle/{chunk-R4RAWEMV.js → chunk-NCRSE647.js} +286 -48
  39. package/dist/bundle/{chunk-UTLJQG6Q.js → chunk-NSIN5IM4.js} +8 -8
  40. package/dist/bundle/{chunk-IMIY7HQB.js → chunk-NWKKPDZV.js} +2 -2
  41. package/dist/bundle/chunk-O373QEAJ.js +1243 -0
  42. package/dist/bundle/{chunk-OMW37FXK.js → chunk-OQW6GHUA.js} +1 -1
  43. package/dist/bundle/{chunk-D6WTKSRA.js → chunk-PRQ2U7HF.js} +2 -2
  44. package/dist/bundle/{chunk-HRIYU2HJ.js → chunk-PT6MF2VU.js} +469 -120
  45. package/dist/bundle/{chunk-B6GITVDX.js → chunk-Q4OKEN3B.js} +7 -7
  46. package/dist/bundle/{chunk-ELGEHZK2.js → chunk-Q6K2XUGU.js} +1 -1
  47. package/dist/bundle/{chunk-CNYQ3TTZ.js → chunk-QI3PXUOJ.js} +43 -595
  48. package/dist/bundle/{chunk-SGMENSI6.js → chunk-QVMOEB3I.js} +391 -16
  49. package/dist/bundle/{chunk-S2U5BXWS.js → chunk-RLQZFZLK.js} +80 -5
  50. package/dist/bundle/{chunk-SETCGPFG.js → chunk-RN7OI5KL.js} +9 -8
  51. package/dist/bundle/{chunk-5J4WNTTM.js → chunk-RNZKQMFY.js} +14 -14
  52. package/dist/bundle/{chunk-WQRX4RQS.js → chunk-RUASZW3M.js} +5 -5
  53. package/dist/bundle/{chunk-UHC5I3JV.js → chunk-RX5CJ55S.js} +1 -1
  54. package/dist/bundle/{chunk-FHCOGR7S.js → chunk-SWKQ6IAR.js} +3 -3
  55. package/dist/bundle/{chunk-KJQZXCNK.js → chunk-TI7ZIPA2.js} +4 -4
  56. package/dist/bundle/{chunk-7DFWXIY5.js → chunk-TLEBSMC7.js} +1997 -768
  57. package/dist/bundle/{chunk-5Z7LZAVP.js → chunk-U6MMQNNK.js} +6 -6
  58. package/dist/bundle/{chunk-HN6PB7F5.js → chunk-VNKWSCN7.js} +99 -42
  59. package/dist/bundle/{chunk-DALBYUPC.js → chunk-VUBZFMGP.js} +2 -2
  60. package/dist/bundle/{chunk-XP5FBDIG.js → chunk-VVL4MKYH.js} +1 -1
  61. package/dist/bundle/{chunk-TEL2OMS5.js → chunk-WOX7FZJP.js} +686 -220
  62. package/dist/bundle/{chunk-2BAO4T4Z.js → chunk-X47BL4M5.js} +13 -13
  63. package/dist/bundle/{chunk-GOMJNH56.js → chunk-X7J3TTDO.js} +8 -8
  64. package/dist/bundle/{chunk-FVKZ55I2.js → chunk-XBEO472U.js} +29976 -16640
  65. package/dist/bundle/{chunk-UA4BOLIY.js → chunk-YA45XV6G.js} +4 -4
  66. package/dist/bundle/{chunk-FIZWQTUC.js → chunk-YBQ5AYLZ.js} +3 -3
  67. package/dist/bundle/{chunk-AFPETMXZ.js → chunk-YI544LHI.js} +13 -136
  68. package/dist/bundle/chunk-ZO4MQWIK.js +188 -0
  69. package/dist/bundle/{chunk-7OVVX4F4.js → chunk-ZR2BDNGG.js} +1 -1
  70. package/dist/bundle/command-contract-ERYYPAD2.js +35 -0
  71. package/dist/bundle/command-server-entry-5E3PPDE5.js +164 -0
  72. package/dist/bundle/{decode-BJXABRAN.js → decode-AVWV7SVZ.js} +5 -5
  73. package/dist/bundle/{dispatch-G4CYFWQ2.js → dispatch-BXPHSNK5.js} +10 -10
  74. package/dist/bundle/{dist-LLEA6R4V.js → dist-PIOOKBWT.js} +78 -44
  75. package/dist/bundle/{echarts-YPTKBOZV.js → echarts-7K6YQV52.js} +2 -2
  76. package/dist/bundle/{embed-DMROTI5M.js → embed-4NT76GJK.js} +6 -6
  77. package/dist/bundle/{embedder-DWMHXCHJ.js → embedder-ITQFF7EN.js} +9 -9
  78. package/dist/bundle/{failure-FFPK2WYB.js → failure-3Q65JOPD.js} +2 -2
  79. package/dist/bundle/{first-run-FQOEF2IO.js → first-run-PM74YU4X.js} +11 -11
  80. package/dist/bundle/first-screen-WBVGVSMY.js +33 -0
  81. package/dist/bundle/{instructions-OGKMROLD.js → instructions-JDSITYHV.js} +1 -1
  82. package/dist/bundle/mail.js +37 -13
  83. package/dist/bundle/{mcp-CFVG2OUS.js → mcp-7KQUJNFN.js} +2 -2
  84. package/dist/bundle/{node-HIKYE546.js → node-D6YIJOJI.js} +2 -2
  85. package/dist/bundle/{node-sqlite-3GJAG7VO.js → node-sqlite-PJOHHB4X.js} +6 -6
  86. package/dist/bundle/{oauth-H3DB6IHI.js → oauth-BOWJ3IBT.js} +7 -7
  87. package/dist/bundle/{open-DJ2PRG74.js → open-FIAKKZMW.js} +5 -5
  88. package/dist/bundle/{openai-MDBRYB55.js → openai-QL54VVLC.js} +16 -37
  89. package/dist/bundle/{process-4LBD72JH.js → process-AYHK7WRC.js} +1 -1
  90. package/dist/bundle/{program-F6WK6RX4.js → program-6FKWOTBK.js} +3206 -1603
  91. package/dist/bundle/{prompt-UNPUG6SO.js → prompt-XJZCBELC.js} +5 -5
  92. package/dist/bundle/{recognize-DMIO4PDB.js → recognize-OQKWAHBY.js} +4 -4
  93. package/dist/bundle/{remote-24HJA72D.js → remote-NLVUZ5WK.js} +7 -7
  94. package/dist/bundle/{rerank-PTNCHHIU.js → rerank-NRPZDTJ7.js} +7 -7
  95. package/dist/bundle/{serve-T6JHM2YD.js → serve-O4YUI7F6.js} +9 -9
  96. package/dist/bundle/server-6OT5ZEWL.js +66 -0
  97. package/dist/bundle/{server-BWEYRUR3.js → server-WAL3M4OO.js} +40 -40
  98. package/dist/bundle/{sqlite-runtime-ZJ4EH5ZM.js → sqlite-runtime-5YHGI4D4.js} +6 -6
  99. package/dist/bundle/{state-KSN4OFYW.js → state-WYYOJ7KK.js} +6 -6
  100. package/dist/bundle/{store-OIEZJEA7.js → store-6BJO3F2J.js} +22 -16
  101. package/dist/bundle/{store-GVBW2ZFK.js → store-X72GOJHD.js} +50 -22
  102. package/dist/bundle/store-maintenance-command-ASS7RBYC.js +54 -0
  103. package/dist/commands/rules.d.ts.map +1 -1
  104. package/dist/commands/rules.js +29 -7
  105. package/dist/commands/rules.js.map +1 -1
  106. package/dist/commands/sync.d.ts +0 -1
  107. package/dist/commands/sync.d.ts.map +1 -1
  108. package/dist/commands/sync.js +8 -2
  109. package/dist/commands/sync.js.map +1 -1
  110. package/dist/config.d.ts +4 -0
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/version.d.ts +1 -1
  113. package/dist/version.js +1 -1
  114. package/package.json +4 -4
  115. package/dist/bundle/chunk-5AQ4S4TZ.js +0 -12172
  116. package/dist/bundle/chunk-B4MWHI2V.js +0 -380
  117. package/dist/bundle/command-contract-UIRWJVEY.js +0 -35
  118. package/dist/bundle/first-screen-B6LF5464.js +0 -33
  119. package/dist/bundle/server-VUQNR5ZD.js +0 -65
  120. package/dist/bundle/store-maintenance-command-KJ54HLUQ.js +0 -54
  121. /package/dist/bundle/{chunk-QZLK2ISN.js → chunk-YVNHQFLC.js} +0 -0
@@ -2,11 +2,11 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  renderMessages
5
- } from "./chunk-I3YNNSGB.js";
5
+ } from "./chunk-4QNHAM3J.js";
6
6
  import {
7
7
  answerOf,
8
8
  messengerContext
9
- } from "./chunk-CNYQ3TTZ.js";
9
+ } from "./chunk-QI3PXUOJ.js";
10
10
  import {
11
11
  FETCHING,
12
12
  RULES_VERSION,
@@ -30,17 +30,17 @@ import {
30
30
  typedQuery,
31
31
  withQuery,
32
32
  withTimeLimit
33
- } from "./chunk-7DFWXIY5.js";
33
+ } from "./chunk-TLEBSMC7.js";
34
34
  import {
35
35
  holdLock,
36
36
  lockPath,
37
37
  releaseLock,
38
38
  servingProfiles,
39
39
  takeLock
40
- } from "./chunk-FIZWQTUC.js";
40
+ } from "./chunk-YBQ5AYLZ.js";
41
41
  import {
42
42
  readSecret
43
- } from "./chunk-5QQOUYNA.js";
43
+ } from "./chunk-KGOVFEWZ.js";
44
44
  import {
45
45
  Command,
46
46
  LOCAL_READ,
@@ -49,7 +49,6 @@ import {
49
49
  REMOTE_WRITE,
50
50
  annotate,
51
51
  codeOf,
52
- currentRun,
53
52
  destroysNothing,
54
53
  environmentOf,
55
54
  itemOf,
@@ -66,20 +65,21 @@ import {
66
65
  snakeKeys,
67
66
  storeTable,
68
67
  withoutProviderRefs
69
- } from "./chunk-4YTX5YAU.js";
68
+ } from "./chunk-FKWUUCX2.js";
70
69
  import {
71
70
  levelFor
72
- } from "./chunk-B6GITVDX.js";
71
+ } from "./chunk-Q4OKEN3B.js";
73
72
  import {
74
73
  holdersOf
75
- } from "./chunk-JO4BJYVE.js";
74
+ } from "./chunk-DW3F6DUW.js";
76
75
  import {
77
76
  QUICK_HEALTH_CHECKS,
78
- explainDamage,
79
77
  fts5Tables,
80
78
  invalidJson,
79
+ lossUnknown,
80
+ storeDamageReport,
81
81
  storeHealth
82
- } from "./chunk-HN6PB7F5.js";
82
+ } from "./chunk-VNKWSCN7.js";
83
83
  import {
84
84
  CORPORA,
85
85
  MIGRATIONS,
@@ -93,6 +93,7 @@ import {
93
93
  fillTrigrams,
94
94
  fillVectorIndexes,
95
95
  involvementStoreOver,
96
+ isDerivedTable,
96
97
  migrate,
97
98
  noteIndexState,
98
99
  openSqlite,
@@ -113,33 +114,33 @@ import {
113
114
  storeClients,
114
115
  storeContents,
115
116
  vectorIndexCounts
116
- } from "./chunk-FVKZ55I2.js";
117
- import {
118
- formatLocator,
119
- parseLocator
120
- } from "./chunk-5AQ4S4TZ.js";
117
+ } from "./chunk-XBEO472U.js";
121
118
  import {
119
+ currentRun,
122
120
  readDamageMark,
123
121
  readHealthMark,
122
+ readJournalMark,
124
123
  recordDeepCheck
125
- } from "./chunk-B4MWHI2V.js";
124
+ } from "./chunk-O373QEAJ.js";
126
125
  import {
126
+ formatLocator,
127
+ parseLocator,
127
128
  queryFieldsOf
128
- } from "./chunk-TEL2OMS5.js";
129
+ } from "./chunk-WOX7FZJP.js";
129
130
  import {
130
131
  failureKey,
131
132
  isStoreDamage
132
- } from "./chunk-6FSLEARF.js";
133
+ } from "./chunk-3KSK5BBB.js";
133
134
  import {
134
135
  storePath
135
- } from "./chunk-5Y2WRUYP.js";
136
+ } from "./chunk-B72343TK.js";
136
137
  import {
137
138
  openCache
138
- } from "./chunk-5Z7LZAVP.js";
139
+ } from "./chunk-U6MMQNNK.js";
139
140
  import {
140
141
  resolvePaths,
141
142
  writeSecurely
142
- } from "./chunk-LLYVBO3R.js";
143
+ } from "./chunk-FNLUKODV.js";
143
144
  import {
144
145
  array,
145
146
  boolean,
@@ -160,10 +161,10 @@ import {
160
161
  string,
161
162
  transform,
162
163
  trim
163
- } from "./chunk-GOMJNH56.js";
164
+ } from "./chunk-X7J3TTDO.js";
164
165
  import {
165
166
  CliError
166
- } from "./chunk-DALBYUPC.js";
167
+ } from "./chunk-VUBZFMGP.js";
167
168
  import {
168
169
  __commonJS,
169
170
  __name,
@@ -1817,7 +1818,7 @@ var require_liquid_node = __commonJS({
1817
1818
  return readFileAsync(filepath, "utf8");
1818
1819
  }
1819
1820
  __name(readFile, "readFile");
1820
- function existsSync10(filepath) {
1821
+ function existsSync11(filepath) {
1821
1822
  try {
1822
1823
  fs$1.statSync(filepath);
1823
1824
  return true;
@@ -1825,11 +1826,11 @@ var require_liquid_node = __commonJS({
1825
1826
  return false;
1826
1827
  }
1827
1828
  }
1828
- __name(existsSync10, "existsSync");
1829
- function readFileSync5(filepath) {
1829
+ __name(existsSync11, "existsSync");
1830
+ function readFileSync6(filepath) {
1830
1831
  return fs$1.readFileSync(filepath, "utf8");
1831
1832
  }
1832
- __name(readFileSync5, "readFileSync");
1833
+ __name(readFileSync6, "readFileSync");
1833
1834
  function resolve2(root, file2, ext) {
1834
1835
  if (!path.extname(file2))
1835
1836
  file2 += ext;
@@ -1843,10 +1844,10 @@ var require_liquid_node = __commonJS({
1843
1844
  }
1844
1845
  }
1845
1846
  __name(fallback, "fallback");
1846
- function dirname3(filepath) {
1847
+ function dirname4(filepath) {
1847
1848
  return path.dirname(filepath);
1848
1849
  }
1849
- __name(dirname3, "dirname");
1850
+ __name(dirname4, "dirname");
1850
1851
  var realpathAsync = promisify(fs$1.realpath);
1851
1852
  async function contains(root, file2) {
1852
1853
  try {
@@ -1874,11 +1875,11 @@ var require_liquid_node = __commonJS({
1874
1875
  __proto__: null,
1875
1876
  exists,
1876
1877
  readFile,
1877
- existsSync: existsSync10,
1878
- readFileSync: readFileSync5,
1878
+ existsSync: existsSync11,
1879
+ readFileSync: readFileSync6,
1879
1880
  resolve: resolve2,
1880
1881
  fallback,
1881
- dirname: dirname3,
1882
+ dirname: dirname4,
1882
1883
  contains,
1883
1884
  containsSync,
1884
1885
  sep: path.sep
@@ -3603,7 +3604,7 @@ var require_liquid_node = __commonJS({
3603
3604
  uri_escape,
3604
3605
  slugify
3605
3606
  });
3606
- var join5 = argumentsToValue(function(v, arg) {
3607
+ var join6 = argumentsToValue(function(v, arg) {
3607
3608
  const array2 = toArray(v);
3608
3609
  const sep = isNil(arg) ? " " : stringify(arg);
3609
3610
  let outputSize = sep.length * Math.max(array2.length - 1, 0);
@@ -3879,7 +3880,7 @@ var require_liquid_node = __commonJS({
3879
3880
  __name(sample, "sample");
3880
3881
  var arrayFilters = /* @__PURE__ */ Object.freeze({
3881
3882
  __proto__: null,
3882
- join: join5,
3883
+ join: join6,
3883
3884
  last,
3884
3885
  first,
3885
3886
  reverse,
@@ -5503,11 +5504,11 @@ var require_liquid_node = __commonJS({
5503
5504
  }
5504
5505
  });
5505
5506
 
5506
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5507
- 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";
5508
- import { dirname as dirname2, resolve } from "node:path";
5507
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5508
+ 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";
5509
+ import { dirname as dirname3, resolve } from "node:path";
5509
5510
 
5510
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/sealed.js
5511
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/sealed.js
5511
5512
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5512
5513
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5513
5514
  import { Transform } from "node:stream";
@@ -5614,7 +5615,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5614
5615
  renameSync(pending, to);
5615
5616
  }, "unsealFile");
5616
5617
 
5617
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5618
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5618
5619
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5619
5620
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5620
5621
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5638,7 +5639,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5638
5639
  };
5639
5640
  }, "compatibilityOf");
5640
5641
 
5641
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/store/repair.js
5642
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/repair.js
5642
5643
  import { createHash as createHash2 } from "node:crypto";
5643
5644
  var COPY_MARK = "__repair_";
5644
5645
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5892,17 +5893,99 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5892
5893
  return found;
5893
5894
  }, "deleteCopy");
5894
5895
 
5895
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5896
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5896
5897
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5897
5898
 
5898
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5899
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5899
5900
  import { existsSync as existsSync3 } from "node:fs";
5900
5901
 
5901
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/store/recover.js
5902
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/recover.js
5902
5903
  import { execFileSync, spawn } from "node:child_process";
5903
5904
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5904
5905
  import { basename, dirname, join } from "node:path";
5905
5906
  import { Transform as Transform2 } from "node:stream";
5907
+
5908
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/refill.js
5909
+ var REFILL_MARGIN_MS = 864e5;
5910
+ var TIME_KEYS = 1e12;
5911
+ var integerId = `external_id GLOB '[0-9]*' AND NOT external_id GLOB '*[^0-9]*'`;
5912
+ var forgetCoverageSince = /* @__PURE__ */ __name((database, cutoff, now = Date.now()) => {
5913
+ database.exec("BEGIN");
5914
+ try {
5915
+ const refetch = forget(database, cutoff, now);
5916
+ database.exec("COMMIT");
5917
+ return refetch;
5918
+ } catch (error) {
5919
+ database.exec("ROLLBACK");
5920
+ throw error;
5921
+ }
5922
+ }, "forgetCoverageSince");
5923
+ var forget = /* @__PURE__ */ __name((database, cutoff, now) => {
5924
+ const chats = /* @__PURE__ */ new Map();
5925
+ const held = database.prepare(`SELECT c.id, c.account_id, c.external_id AS chat, a.provider, a.external_id AS account,
5926
+ 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
5927
+ GROUP BY c.id`).all();
5928
+ for (const row of held) {
5929
+ const chat = Number(row.id);
5930
+ const top = Number(row.top);
5931
+ 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;
5932
+ if (keepTo !== null && top <= keepTo)
5933
+ continue;
5934
+ if (keepTo === null)
5935
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ?").run(chat);
5936
+ else {
5937
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ? AND from_key > ?").run(chat, keepTo);
5938
+ database.prepare("UPDATE sync_ranges SET to_key = ?, updated_at = ? WHERE chat_id = ? AND to_key > ?").run(keepTo, now, chat, keepTo);
5939
+ }
5940
+ const account = Number(row.account_id);
5941
+ const external = String(row.chat);
5942
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(account, `fetched:${external}`);
5943
+ database.prepare(`DELETE FROM sync_cursors WHERE account_id = ? AND key = ? AND NOT EXISTS
5944
+ (SELECT 1 FROM sync_ranges WHERE chat_id = ? AND from_key <= CAST(sync_cursors.value AS INTEGER))`).run(account, `history_start:${external}`, chat);
5945
+ const key = `${row.provider}\0${row.account}`;
5946
+ const one = chats.get(key) ?? { provider: String(row.provider), account: String(row.account), chats: 0 };
5947
+ one.chats += 1;
5948
+ chats.set(key, one);
5949
+ }
5950
+ return {
5951
+ since: cutoff === null ? null : new Date(cutoff).toISOString(),
5952
+ chats: [...chats.values()],
5953
+ mail: forgetMail(database, cutoff, now)
5954
+ };
5955
+ }, "forget");
5956
+ var forgetMail = /* @__PURE__ */ __name((database, cutoff, now) => {
5957
+ const folders = /* @__PURE__ */ new Map();
5958
+ const points = database.prepare(`SELECT s.account_id, s.key, s.value, a.external_id AS account FROM sync_cursors s
5959
+ JOIN accounts a ON a.id = s.account_id WHERE a.provider = 'email' AND s.key LIKE 'mail_resume:%'`).all();
5960
+ for (const row of points) {
5961
+ let point;
5962
+ try {
5963
+ point = JSON.parse(String(row.value));
5964
+ } catch {
5965
+ continue;
5966
+ }
5967
+ const account = String(row.account);
5968
+ if (!Array.isArray(point.done)) {
5969
+ if (cutoff !== null && Date.parse(point.updatedAt ?? "") < cutoff)
5970
+ continue;
5971
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(Number(row.account_id), String(row.key));
5972
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5973
+ continue;
5974
+ }
5975
+ const folder = String(row.key).slice("mail_resume:".length);
5976
+ 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
5977
+ WHERE l.mailbox_id = (SELECT id FROM mailboxes WHERE account_id = ? AND external_id = ?)
5978
+ AND l.uidvalidity = ? AND coalesce(e.received_at, e.sent_at) < ?`).get(Number(row.account_id), folder, point.validity ?? "", cutoff)?.uid;
5979
+ const done = last === null ? [] : point.done.filter(([from]) => from <= last).map(([from, to]) => [from, Math.min(to, last)]);
5980
+ if (JSON.stringify(done) === JSON.stringify(point.done))
5981
+ continue;
5982
+ 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));
5983
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5984
+ }
5985
+ return [...folders].map(([account, count3]) => ({ account, folders: count3 }));
5986
+ }, "forgetMail");
5987
+
5988
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/recover.js
5906
5989
  var SQLITE3_MINIMUM = [3, 43, 0];
5907
5990
  var STORE_PARTS = ["", "-wal", "-shm"];
5908
5991
  var RECOVER_LOCK = ".recover-lock";
@@ -5997,9 +6080,12 @@ var storeHolders = /* @__PURE__ */ __name((path) => {
5997
6080
  return { pid, name };
5998
6081
  });
5999
6082
  }, "storeHolders");
6000
- var tableRows = /* @__PURE__ */ __name((database) => {
6083
+ var dataTables = /* @__PURE__ */ __name((database) => {
6001
6084
  const indexes = fts5Tables(database).map((index) => index.name);
6002
- 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}_`)));
6085
+ 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}_`)));
6086
+ }, "dataTables");
6087
+ var tableRows = /* @__PURE__ */ __name((database) => {
6088
+ const tables = dataTables(database);
6003
6089
  return Object.fromEntries(tables.map((table) => {
6004
6090
  try {
6005
6091
  return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
@@ -6008,6 +6094,117 @@ var tableRows = /* @__PURE__ */ __name((database) => {
6008
6094
  }
6009
6095
  }));
6010
6096
  }, "tableRows");
6097
+ var sourceTables = /* @__PURE__ */ __name((database) => {
6098
+ const withoutRowid = new Set(database.prepare("SELECT name FROM pragma_table_list WHERE wr = 1").all().map((row) => String(row.name)));
6099
+ return dataTables(database).filter((table) => table !== LOST_AND_FOUND && !withoutRowid.has(table) && !isDerivedTable(table));
6100
+ }, "sourceTables");
6101
+ var indexedButGone = /* @__PURE__ */ __name((database) => {
6102
+ const found = {};
6103
+ for (const table of sourceTables(database)) {
6104
+ const indexes = database.prepare("SELECT name FROM pragma_index_list(?) WHERE partial = 0 ORDER BY name").all(table).map((row) => String(row.name));
6105
+ for (const index of indexes) {
6106
+ const columns = database.prepare("SELECT cid, name FROM pragma_index_xinfo(?) WHERE key = 1 ORDER BY seqno").all(index);
6107
+ if (columns.some((column) => Number(column.cid) < 0))
6108
+ continue;
6109
+ const keys = columns.map((column) => `"${String(column.name)}"`).join(", ");
6110
+ const grouped = `${keys}, row_id`;
6111
+ let rows;
6112
+ try {
6113
+ 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);
6114
+ } catch {
6115
+ continue;
6116
+ }
6117
+ if (rows > (found[table]?.rows ?? 0))
6118
+ found[table] = { rows, index };
6119
+ }
6120
+ }
6121
+ return found;
6122
+ }, "indexedButGone");
6123
+ var storedAs = /* @__PURE__ */ __name((declared) => {
6124
+ const type = declared.toUpperCase();
6125
+ if (type.includes("INT"))
6126
+ return ["integer"];
6127
+ if (/CHAR|CLOB|TEXT/.test(type))
6128
+ return ["text"];
6129
+ if (type === "" || type.includes("BLOB"))
6130
+ return null;
6131
+ if (/REAL|FLOA|DOUB/.test(type))
6132
+ return ["real", "integer"];
6133
+ return null;
6134
+ }, "storedAs");
6135
+ var columnsOf = /* @__PURE__ */ __name((database, table) => {
6136
+ const all = database.prepare('SELECT name, type, "notnull" AS required, dflt_value, pk FROM pragma_table_info(?)').all(table);
6137
+ const keys = all.filter((column) => Number(column.pk) > 0);
6138
+ return all.map((column) => ({
6139
+ name: String(column.name),
6140
+ type: String(column.type),
6141
+ required: Number(column.required) === 1,
6142
+ hasDefault: column.dflt_value !== null,
6143
+ rowid: keys.length === 1 && Number(column.pk) === 1 && String(column.type).toUpperCase() === "INTEGER"
6144
+ }));
6145
+ }, "columnsOf");
6146
+ var fits = /* @__PURE__ */ __name((columns, fields, types) => fields <= columns.length && columns.every((column, at) => {
6147
+ if (at >= fields)
6148
+ return !column.required || column.hasDefault;
6149
+ const type = types[at];
6150
+ if (column.rowid)
6151
+ return type === "null" || type === "integer";
6152
+ if (type === "null")
6153
+ return !column.required;
6154
+ const allowed = storedAs(column.type);
6155
+ return allowed === null || allowed.includes(type);
6156
+ }), "fits");
6157
+ var placeLostRows = /* @__PURE__ */ __name((database) => {
6158
+ if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND))
6159
+ return {};
6160
+ 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));
6161
+ const tables = sourceTables(database).map((table) => ({ table, columns: columnsOf(database, table) }));
6162
+ 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();
6163
+ const placed = {};
6164
+ const triggers = [];
6165
+ const quiet = /* @__PURE__ */ __name((table) => {
6166
+ if (table in placed)
6167
+ return;
6168
+ placed[table] = 0;
6169
+ for (const row of database.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?").all(table)) {
6170
+ triggers.push(String(row.sql));
6171
+ database.exec(`DROP TRIGGER "${String(row.name)}"`);
6172
+ }
6173
+ }, "quiet");
6174
+ database.exec("PRAGMA foreign_keys = OFF");
6175
+ database.exec("BEGIN");
6176
+ try {
6177
+ for (const row of rows) {
6178
+ const count3 = Number(row.nfield);
6179
+ const types = fields.slice(0, count3).map((field) => String(row[field]));
6180
+ const fitting = tables.filter(({ columns: columns2 }) => fits(columns2, count3, types));
6181
+ if (fitting.length !== 1)
6182
+ continue;
6183
+ const { table, columns } = fitting[0];
6184
+ quiet(table);
6185
+ const given = columns.slice(0, count3);
6186
+ const names = [...given.some((column) => column.rowid) ? [] : ["rowid"], ...given.map((column) => column.name)];
6187
+ const values = [
6188
+ ...given.some((column) => column.rowid) ? [] : ["id"],
6189
+ ...given.map((column, at) => column.rowid ? "id" : `c${at}`)
6190
+ ];
6191
+ 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));
6192
+ if (Number(inserted.changes) === 0)
6193
+ continue;
6194
+ placed[table] = (placed[table] ?? 0) + 1;
6195
+ database.prepare(`DELETE FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6196
+ }
6197
+ for (const sql of triggers)
6198
+ database.exec(sql);
6199
+ database.exec("COMMIT");
6200
+ } catch (error) {
6201
+ database.exec("ROLLBACK");
6202
+ throw error;
6203
+ } finally {
6204
+ database.exec("PRAGMA foreign_keys = ON");
6205
+ }
6206
+ return Object.fromEntries(Object.entries(placed).filter(([, rows2]) => rows2 > 0));
6207
+ }, "placeLostRows");
6011
6208
  var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
6012
6209
  const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
6013
6210
  stdio: ["ignore", "pipe", "pipe"]
@@ -6204,6 +6401,9 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6204
6401
  throw error;
6205
6402
  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" });
6206
6403
  }
6404
+ note("looking for rows the indexes list and the tables no longer hold");
6405
+ const gone = indexedButGone(watch);
6406
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6207
6407
  const before = { data: dataVersion(), inode: statSync2(path).ino };
6208
6408
  const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6209
6409
  const target = `${path}.recovering-${stamp}`;
@@ -6232,7 +6432,10 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6232
6432
  let json;
6233
6433
  let fetch;
6234
6434
  let schema;
6435
+ let placed;
6436
+ let refetch;
6235
6437
  try {
6438
+ placed = placeLostRows(opened.database);
6236
6439
  kept = tableRows(opened.database);
6237
6440
  migrate(opened.database, { command, ...version ? { version } : {} });
6238
6441
  note("clearing values that are not valid JSON");
@@ -6241,6 +6444,8 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6241
6444
  note("looking for rows that point at rows that were lost");
6242
6445
  dangling = danglingRows(opened.database);
6243
6446
  fetch = mailToFetch(opened.database);
6447
+ const good = lastKnownGood === null ? Number.NaN : Date.parse(lastKnownGood);
6448
+ refetch = forgetCoverageSince(opened.database, Number.isNaN(good) ? null : good - REFILL_MARGIN_MS, now());
6244
6449
  schema = fileSchemaOf(opened.database).version;
6245
6450
  opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6246
6451
  } catch (error) {
@@ -6270,16 +6475,29 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6270
6475
  if (existsSync2(`${target}${suffix}`))
6271
6476
  renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6272
6477
  recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema, now });
6273
- 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);
6478
+ const lost = Object.entries(rowsBefore).map(([table, before2]) => {
6479
+ const goneAtLeast = Math.max(0, (gone[table]?.rows ?? 0) - (placed[table] ?? 0));
6480
+ return {
6481
+ table,
6482
+ before: before2,
6483
+ read: read[table] ?? 0,
6484
+ kept: kept[table] ?? 0,
6485
+ goneAtLeast,
6486
+ seenIn: goneAtLeast > 0 ? gone[table]?.index ?? null : null
6487
+ };
6488
+ }).filter(({ before: before2, read: read2, kept: kept2, goneAtLeast }) => before2 === null || before2 > kept2 || read2 > kept2 || goneAtLeast > 0);
6274
6489
  const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6275
6490
  return {
6276
6491
  path,
6277
6492
  keptAt,
6278
6493
  sqlite3: program.version,
6279
6494
  lost,
6495
+ placed,
6496
+ lastKnownGood,
6280
6497
  dangling,
6281
6498
  invalidJson: json,
6282
6499
  mailToFetch: fetch,
6500
+ refetch,
6283
6501
  rebuilt,
6284
6502
  copyErrors,
6285
6503
  health,
@@ -6295,7 +6513,7 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6295
6513
  }
6296
6514
  }, "recoverLocked");
6297
6515
 
6298
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6516
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6299
6517
  var COUNTED = [
6300
6518
  "accounts",
6301
6519
  "chats",
@@ -6328,18 +6546,23 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6328
6546
  }
6329
6547
  } catch {
6330
6548
  }
6549
+ const journal = readJournalMark(path);
6331
6550
  recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
6332
6551
  const mark = readDamageMark(path);
6333
- const explanation = explainDamage(health, command, mark);
6552
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6334
6553
  const inUse = storeHolders(path) ?? null;
6335
6554
  const timers = activeTimers() ?? null;
6336
6555
  const sqlite3 = sqlite3Program();
6337
- const next = health.ok ? [] : [
6338
- ...timers?.length ? [stopTimers(timers)] : [],
6339
- ...(inUse ?? []).map(({ pid, name }) => `stop ${name} (process ${pid}): it has the store open`),
6340
- ...sqlite3.usable ? [] : ["install sqlite3 3.43 or newer (apt install sqlite3, brew install sqlite)"],
6341
- `${command} store recover run`
6342
- ];
6556
+ const report = storeDamageReport({
6557
+ health,
6558
+ command,
6559
+ mark,
6560
+ journal,
6561
+ lastOkAt: lastKnownGood,
6562
+ holders: inUse,
6563
+ timers,
6564
+ sqlite3Usable: sqlite3.usable
6565
+ });
6343
6566
  return {
6344
6567
  path,
6345
6568
  exists: true,
@@ -6350,13 +6573,13 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) =>
6350
6573
  damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
6351
6574
  invalidJson: health.invalidJson ?? [],
6352
6575
  rows,
6353
- explanation,
6576
+ report,
6354
6577
  damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
6355
- lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
6578
+ lastKnownGood,
6356
6579
  inUse,
6357
6580
  timers,
6358
6581
  sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
6359
- next
6582
+ next: report?.steps.map((step) => step.command) ?? []
6360
6583
  };
6361
6584
  }, "storeRecoveryCheck");
6362
6585
  var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, note, timers: scheduled = activeTimers, copy }) => {
@@ -6382,12 +6605,27 @@ var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, no
6382
6605
  next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
6383
6606
  };
6384
6607
  }, "storeRecoveryRun");
6608
+ var refetchNotes = /* @__PURE__ */ __name(({ since, chats, mail }) => {
6609
+ const from = since === null ? "from the start" : `from ${since} on`;
6610
+ const marked = [
6611
+ ...chats.map(({ provider, account, chats: chats2 }) => `${chats2} chats of ${provider} ${account}`),
6612
+ ...mail.map(({ account, folders }) => `${folders} mail folders of ${account}`)
6613
+ ];
6614
+ return [
6615
+ 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`,
6616
+ ...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`),
6617
+ "notes, memories, tags and whatever else only this store held cannot be fetched again"
6618
+ ];
6619
+ }, "refetchNotes");
6385
6620
  var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6386
6621
  if ("keptAt" in answer) {
6387
- const lost = answer.lost.map(({ table, before, read, kept }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}`);
6622
+ 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)` : ""));
6388
6623
  return [
6389
6624
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6390
- ...lost.length ? lost : ["no table lost a row"],
6625
+ ...lost,
6626
+ ...Object.entries(answer.placed).map(([table, rows]) => `${table}: ${rows} rows found on pages no table claimed were put back`),
6627
+ ...refetchNotes(answer.refetch),
6628
+ lossUnknown(answer.lastKnownGood, lost.some((line) => line.includes("are gone"))),
6391
6629
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6392
6630
  ...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
6393
6631
  ...answer.next.map((line) => `next: ${line}`)
@@ -6395,13 +6633,16 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6395
6633
  }
6396
6634
  if (!answer.exists)
6397
6635
  return ["no store yet"];
6398
- if (answer.ok)
6636
+ const report = answer.report;
6637
+ if (!report)
6399
6638
  return [`the store is healthy (checked every page and search index in ${answer.seconds} s)`];
6400
- const why = answer.explanation;
6401
6639
  return [
6402
- ...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
6403
- answer.lastKnownGood ? `the store last passed a deep check at ${answer.lastKnownGood}` : "no deep check that passed is on record for this store",
6404
- ...answer.next.map((line) => `next: ${line}`)
6640
+ report.whatHappened,
6641
+ ...report.impact,
6642
+ report.externalDataSafe,
6643
+ report.loss,
6644
+ ...report.likelyCauses.map(({ cause, check: check2 }) => `maybe: ${cause} \u2014 check: ${check2}`),
6645
+ ...report.steps.map(({ command, why, destructive }) => `next: ${command} # ${destructive ? "changes things: " : ""}${why}`)
6405
6646
  ];
6406
6647
  }, "recoveryNotes");
6407
6648
  var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
@@ -6428,7 +6669,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6428
6669
  return recover;
6429
6670
  }, "storeRecoverCommand");
6430
6671
 
6431
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6672
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6432
6673
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6433
6674
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6434
6675
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6474,7 +6715,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6474
6715
  renderAnswer(this, outputFor(this), itemOf(answer));
6475
6716
  }), "storeInfoCommand");
6476
6717
 
6477
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6718
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6478
6719
  var ENCRYPT_OPTION = [
6479
6720
  "--encrypt",
6480
6721
  "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"
@@ -6493,7 +6734,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6493
6734
  return password;
6494
6735
  }, "passwordOf");
6495
6736
 
6496
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/rules.js
6737
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/rules.js
6497
6738
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6498
6739
  import { join as join2 } from "node:path";
6499
6740
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6664,7 +6905,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6664
6905
  }, "problem");
6665
6906
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6666
6907
 
6667
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/state.js
6908
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/state.js
6668
6909
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6669
6910
  import { join as join3 } from "node:path";
6670
6911
  var ANSWERED_KEPT = 1e3;
@@ -6717,7 +6958,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6717
6958
  }, "recordReply");
6718
6959
  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");
6719
6960
 
6720
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/decide.js
6961
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/decide.js
6721
6962
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6722
6963
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6723
6964
  const { message, chat, owner, sender } = incoming;
@@ -6823,10 +7064,10 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6823
7064
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6824
7065
  }, "filled");
6825
7066
 
6826
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/template.js
7067
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/template.js
6827
7068
  var import_liquidjs2 = __toESM(require_liquid_node(), 1);
6828
7069
 
6829
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/render/liquid.js
7070
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/render/liquid.js
6830
7071
  var import_liquidjs = __toESM(require_liquid_node(), 1);
6831
7072
  var safeLiquid = /* @__PURE__ */ __name((limits) => {
6832
7073
  const engine = new import_liquidjs.Liquid({
@@ -6853,7 +7094,7 @@ var safeLiquid = /* @__PURE__ */ __name((limits) => {
6853
7094
  return engine;
6854
7095
  }, "safeLiquid");
6855
7096
 
6856
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/template.js
7097
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/template.js
6857
7098
  var TEMPLATE_LIMITS = {
6858
7099
  parse: 32768,
6859
7100
  renders: 2e3,
@@ -6992,7 +7233,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6992
7233
  }
6993
7234
  }, "renderReplyTemplate");
6994
7235
 
6995
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7236
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6996
7237
  var DRY_RUN_DAYS = 7;
6997
7238
  var PAGE = 500;
6998
7239
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7106,7 +7347,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7106
7347
  }
7107
7348
  }, "storedSince");
7108
7349
 
7109
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/consents.js
7350
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/consents.js
7110
7351
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7111
7352
  import { join as join4 } from "node:path";
7112
7353
  var shape = strictObject({
@@ -7131,7 +7372,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7131
7372
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7132
7373
  }, "mayModelReply");
7133
7374
 
7134
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7375
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7135
7376
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options = {
7136
7377
  ai: true
7137
7378
  }) => async (rule2, message, chat, now) => {
@@ -7178,7 +7419,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7178
7419
  return result2;
7179
7420
  }, "replyRenderer");
7180
7421
 
7181
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/replies/serve.js
7422
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/serve.js
7182
7423
  var NOT_ALLOWED = "replies.send is not allow";
7183
7424
  var NO_RULES = "no rules";
7184
7425
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7271,7 +7512,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7271
7512
  return { skip: why };
7272
7513
  }, "replyTo");
7273
7514
 
7274
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7515
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7275
7516
  var START_SYNC_DELAY_MS = 3e4;
7276
7517
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7277
7518
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7348,7 +7589,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch, note, warn,
7348
7589
  };
7349
7590
  }, "startSync");
7350
7591
 
7351
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7592
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7352
7593
  var FIRST_FETCH_MS = 6e4;
7353
7594
  var DAY_MS = 864e5;
7354
7595
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7402,7 +7643,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs =
7402
7643
  };
7403
7644
  }, "memberFetches");
7404
7645
 
7405
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7646
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7406
7647
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7407
7648
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7408
7649
  if (context.format === "pretty") {
@@ -7435,7 +7676,93 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7435
7676
  return context;
7436
7677
  }, "recordDiagnostics");
7437
7678
 
7438
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7679
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7680
+ import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync2 } from "node:fs";
7681
+ import { dirname as dirname2, join as join5 } from "node:path";
7682
+ var OUTDATED_CHECK_MS = 6e4;
7683
+ var ownPackageRoot = /* @__PURE__ */ __name((running, script = process.argv[1]) => {
7684
+ let dir;
7685
+ try {
7686
+ dir = dirname2(realpathSync2(script ?? ""));
7687
+ } catch {
7688
+ return void 0;
7689
+ }
7690
+ for (let up = 0; up < 8; up++) {
7691
+ const manifest = join5(dir, "package.json");
7692
+ if (existsSync8(manifest))
7693
+ return installedVersion(dir) === running ? dir : void 0;
7694
+ const parent = dirname2(dir);
7695
+ if (parent === dir)
7696
+ return void 0;
7697
+ dir = parent;
7698
+ }
7699
+ return void 0;
7700
+ }, "ownPackageRoot");
7701
+ var installedVersion = /* @__PURE__ */ __name((root) => {
7702
+ try {
7703
+ const { version } = JSON.parse(readFileSync5(join5(root, "package.json"), "utf8"));
7704
+ return typeof version === "string" ? version : void 0;
7705
+ } catch {
7706
+ return void 0;
7707
+ }
7708
+ }, "installedVersion");
7709
+ var newer = /* @__PURE__ */ __name((one, other) => {
7710
+ const parts = /* @__PURE__ */ __name((version) => version.split(/[.+-]/, 3).map(Number), "parts");
7711
+ const [a, b] = [parts(one), parts(other)];
7712
+ for (let i = 0; i < 3; i++)
7713
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
7714
+ return (a[i] ?? 0) > (b[i] ?? 0);
7715
+ return false;
7716
+ }, "newer");
7717
+ var outdatedReason = /* @__PURE__ */ __name(async ({ command, running, storePath: storePath2, packageRoot, speaks = SPEAKS }) => {
7718
+ const installed = packageRoot === void 0 ? void 0 : installedVersion(packageRoot);
7719
+ if (installed !== void 0 && newer(installed, running))
7720
+ return `${command} ${installed} is installed and this serve runs ${running}: stopping so it starts again on ${installed}`;
7721
+ if (!existsSync8(storePath2))
7722
+ return void 0;
7723
+ let schema;
7724
+ try {
7725
+ const { database } = await openSqlite(storePath2, { readOnly: true });
7726
+ try {
7727
+ schema = fileSchemaOf(database);
7728
+ } finally {
7729
+ database.close();
7730
+ }
7731
+ } catch {
7732
+ return void 0;
7733
+ }
7734
+ if (writableBy(schema, speaks))
7735
+ return void 0;
7736
+ 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`;
7737
+ }, "outdatedReason");
7738
+ var watchOutdated = /* @__PURE__ */ __name(({ check: check2, onOutdated, everyMs = OUTDATED_CHECK_MS }) => {
7739
+ let busy = false;
7740
+ let done = false;
7741
+ const timer = setInterval(() => {
7742
+ if (busy || done)
7743
+ return;
7744
+ busy = true;
7745
+ check2().then((reason) => {
7746
+ if (reason === void 0 || done)
7747
+ return;
7748
+ done = true;
7749
+ clearInterval(timer);
7750
+ onOutdated(reason);
7751
+ }).catch(() => {
7752
+ }).finally(() => {
7753
+ busy = false;
7754
+ });
7755
+ }, everyMs);
7756
+ timer.unref();
7757
+ return {
7758
+ stop: /* @__PURE__ */ __name(() => {
7759
+ done = true;
7760
+ clearInterval(timer);
7761
+ }, "stop")
7762
+ };
7763
+ }, "watchOutdated");
7764
+
7765
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7439
7766
  var STEMS_EVERY_MS = 3e4;
7440
7767
  var STEMS_SLICE_MS = 2e3;
7441
7768
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7475,7 +7802,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7475
7802
  };
7476
7803
  }, "stemFills");
7477
7804
 
7478
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7805
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7479
7806
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7480
7807
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7481
7808
  kind: attachment.kind,
@@ -7494,7 +7821,7 @@ var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7494
7821
  phone: attachment.contact.phone,
7495
7822
  user_id: attachment.contact.userId
7496
7823
  }),
7497
- buttons: attachment.buttons
7824
+ buttons: attachment.buttons?.map((row) => row.map(({ data: _data, ...button }) => button))
7498
7825
  }), "attachmentItem");
7499
7826
  var quotedItem = /* @__PURE__ */ __name((quoted) => quoted === null ? null : {
7500
7827
  id: quoted.id,
@@ -7570,7 +7897,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7570
7897
  locale: messenger.app.locale
7571
7898
  }), "viewOf");
7572
7899
 
7573
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7900
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7574
7901
  var observed = /* @__PURE__ */ __name((value) => ({
7575
7902
  value: value.value,
7576
7903
  observed_at: value.observedAt,
@@ -7637,7 +7964,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7637
7964
  }
7638
7965
  }, "watchEventItem");
7639
7966
 
7640
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7967
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7641
7968
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7642
7969
  output: { entity: "watch_item" },
7643
7970
  effects: REMOTE_READ,
@@ -7792,7 +8119,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
7792
8119
  }
7793
8120
  }, "describe");
7794
8121
 
7795
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8122
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
7796
8123
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
7797
8124
  const command = annotate(new Command("serve"), {
7798
8125
  output: { entity: "serve_summary" },
@@ -7816,8 +8143,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7816
8143
  }
7817
8144
  let relaying;
7818
8145
  const onReady = /* @__PURE__ */ __name(() => {
7819
- const listening = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
7820
- holdLock(path, listening);
8146
+ const listening2 = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8147
+ holdLock(path, listening2);
7821
8148
  note({
7822
8149
  code: "listening",
7823
8150
  text: `listening for profile ${context.profile}, catching up on what arrived while it was down`
@@ -7826,7 +8153,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7826
8153
  return;
7827
8154
  relaying = relay.open(path, context.profile).then((address) => {
7828
8155
  if (address)
7829
- holdLock(path, { ...listening, relay: address });
8156
+ holdLock(path, { ...listening2, relay: address });
7830
8157
  }).catch((error) => {
7831
8158
  const errorCode = failureKey(error);
7832
8159
  warn({ code: "relay_failed", errorCode, text: `commands cannot run through this serve: ${errorCode}` });
@@ -7835,7 +8162,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7835
8162
  const counts = {};
7836
8163
  const rules = replying(context, messenger, Date.parse(startedAt));
7837
8164
  const tasks = tasking(context, warn);
7838
- const { handled, startSyncDelayMs } = environmentOf(this);
8165
+ const { handled, startSyncDelayMs, outdated: outdatedHook } = environmentOf(this);
7839
8166
  const count3 = /* @__PURE__ */ __name((event) => {
7840
8167
  counts[event.event] = (counts[event.event] ?? 0) + 1;
7841
8168
  if (event.event === "message") {
@@ -7907,9 +8234,25 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7907
8234
  withStore: /* @__PURE__ */ __name((work) => context.withStore((store) => work(store), { name: "serve stems" }), "withStore"),
7908
8235
  warn
7909
8236
  });
8237
+ const listening = new AbortController();
8238
+ let outdated;
8239
+ const packageRoot = outdatedHook?.packageRoot ?? ownPackageRoot(version);
8240
+ const watch = watchOutdated({
8241
+ check: /* @__PURE__ */ __name(() => outdatedReason({
8242
+ command: messenger.app.command,
8243
+ running: version,
8244
+ storePath: storePath(context.env),
8245
+ packageRoot
8246
+ }), "check"),
8247
+ onOutdated: /* @__PURE__ */ __name((reason) => {
8248
+ outdated = reason;
8249
+ listening.abort();
8250
+ }, "onOutdated"),
8251
+ ...outdatedHook?.everyMs === void 0 ? {} : { everyMs: outdatedHook.everyMs }
8252
+ });
7910
8253
  try {
7911
8254
  await listenUntilStopped(this, context, relay?.messenger ?? messenger, count3, {
7912
- stop: new AbortController(),
8255
+ stop: listening,
7913
8256
  catchUp: true,
7914
8257
  onReady,
7915
8258
  connected: /* @__PURE__ */ __name((open) => {
@@ -7922,6 +8265,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7922
8265
  }, "connected")
7923
8266
  });
7924
8267
  } finally {
8268
+ watch.stop();
7925
8269
  await relaying;
7926
8270
  await relay?.close();
7927
8271
  rules.stop();
@@ -7932,6 +8276,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
7932
8276
  await tasks.settled();
7933
8277
  releaseLock(path);
7934
8278
  }
8279
+ if (outdated !== void 0)
8280
+ throw new CliError("configuration_error", outdated, { reason: "serve.outdated" });
7935
8281
  renderAnswer(this, context, itemOf({
7936
8282
  profile: context.profile,
7937
8283
  started_at: startedAt,
@@ -8056,8 +8402,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8056
8402
  };
8057
8403
  }, "tasking");
8058
8404
 
8059
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8060
- import { existsSync as existsSync8 } from "node:fs";
8405
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8406
+ import { existsSync as existsSync9 } from "node:fs";
8061
8407
  var PATH = "store tables list";
8062
8408
  var STORE_TABLES_QUERY = {
8063
8409
  entity: "store_table",
@@ -8086,7 +8432,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8086
8432
  const filter = filterOf(words);
8087
8433
  const { full } = this.optsWithGlobals();
8088
8434
  const path = storePath(environmentOf(this).env ?? process.env);
8089
- if (!existsSync8(path))
8435
+ if (!existsSync9(path))
8090
8436
  throw new CliError("not_found", `no store at ${path}`);
8091
8437
  const items = await readStoreTables(path, { filter, sizes: full === true });
8092
8438
  renderAnswer(this, outputFor(this), listOf(PATH, {
@@ -8099,7 +8445,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8099
8445
  return tables;
8100
8446
  }, "storeTablesCommand");
8101
8447
 
8102
- // node_modules/.pnpm/@wirecat+cli-core@0.614.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_af5f2db22f61976c09fb28de9c7dc33e/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8448
+ // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8103
8449
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8104
8450
  var WORD_INDEX = "message_words";
8105
8451
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8108,7 +8454,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
8108
8454
  }, "schemaOf");
8109
8455
  var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
8110
8456
  var pendingIfKnown2 = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
8111
- var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync9(path) ? statSync4(path).size : 0, "bytesOf");
8457
+ var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync10(path) ? statSync4(path).size : 0, "bytesOf");
8112
8458
  var reading = /* @__PURE__ */ __name(async (path, read) => {
8113
8459
  const database = await openCache(path);
8114
8460
  try {
@@ -8135,9 +8481,10 @@ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8135
8481
  }, "fileSchema");
8136
8482
  var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8137
8483
  const path = storePath(env);
8138
- if (!existsSync9(path))
8484
+ if (!existsSync10(path))
8139
8485
  return { path, exists: false };
8140
8486
  const checked = await storeHealth(path, { deep });
8487
+ const journal = readJournalMark(path);
8141
8488
  const recorded = deep ? recordDeepCheck(path, checked, {
8142
8489
  cli: command ?? "unknown",
8143
8490
  ...version ? { version } : {},
@@ -8155,13 +8502,15 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, v
8155
8502
  ...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
8156
8503
  ...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
8157
8504
  };
8158
- const damage = command ? explainDamage(checked, command, mark) : null;
8505
+ const damage = command ? storeDamageReport({ health: checked, command, mark, journal, lastOkAt: lastKnownGood }) : null;
8159
8506
  const healthOf = {
8160
8507
  health,
8161
8508
  lastKnownGood,
8162
8509
  ...mark ? { damageMark: withoutInode(mark) } : {},
8510
+ ...journal ? { journalMark: journal } : {},
8163
8511
  ...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
8164
- ...damage ? { damage } : {}
8512
+ // `what` keeps memo's doctor, which reads it, compiling until it moves to `whatHappened`.
8513
+ ...damage ? { damage: { what: damage.whatHappened, ...damage } } : {}
8165
8514
  };
8166
8515
  try {
8167
8516
  return await reading(path, (database) => {
@@ -8205,7 +8554,7 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
8205
8554
  const { renderer, format } = outputFor(this);
8206
8555
  const { dryRun: dryRun2 } = this.opts();
8207
8556
  const path = storePath(environmentOf(this).env ?? process.env);
8208
- if (!existsSync9(path)) {
8557
+ if (!existsSync10(path)) {
8209
8558
  result(this, { path, exists: false });
8210
8559
  return;
8211
8560
  }
@@ -8245,7 +8594,7 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
8245
8594
  }, "notesOf");
8246
8595
  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) {
8247
8596
  const path = storePath(environmentOf(this).env ?? process.env);
8248
- if (!existsSync9(path))
8597
+ if (!existsSync10(path))
8249
8598
  throw new CliError("not_found", `no store at ${path}`);
8250
8599
  const deleted = await reading(path, (database) => deleteCopy(database, name));
8251
8600
  result(this, { path, deleted });
@@ -8253,7 +8602,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
8253
8602
  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() {
8254
8603
  const { renderer } = outputFor(this);
8255
8604
  const path = storePath(environmentOf(this).env ?? process.env);
8256
- if (!existsSync9(path)) {
8605
+ if (!existsSync10(path)) {
8257
8606
  result(this, { path, exists: false, ok: true });
8258
8607
  return;
8259
8608
  }
@@ -8316,7 +8665,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
8316
8665
  ...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
8317
8666
  ]);
8318
8667
  const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
8319
- const { bavail, bsize } = statfsSync2(dirname2(path));
8668
+ const { bavail, bsize } = statfsSync2(dirname3(path));
8320
8669
  const free = Number(bavail) * Number(bsize);
8321
8670
  const behind = schema.version > 0 ? chatsBehind(database) : [];
8322
8671
  const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
@@ -8404,7 +8753,7 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
8404
8753
  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() {
8405
8754
  const { renderer } = outputFor(this);
8406
8755
  const path = storePath(environmentOf(this).env ?? process.env);
8407
- if (!existsSync9(path)) {
8756
+ if (!existsSync10(path)) {
8408
8757
  result(this, { path, exists: false });
8409
8758
  renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
8410
8759
  return;
@@ -8468,7 +8817,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
8468
8817
  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() {
8469
8818
  const { renderer } = outputFor(this);
8470
8819
  const path = storePath(environmentOf(this).env ?? process.env);
8471
- if (!existsSync9(path)) {
8820
+ if (!existsSync10(path)) {
8472
8821
  result(this, { path, exists: false });
8473
8822
  return;
8474
8823
  }
@@ -8510,9 +8859,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
8510
8859
  const { encrypt } = this.opts();
8511
8860
  const path = storePath(environmentOf(this).env ?? process.env);
8512
8861
  const target = resolve(file2);
8513
- if (!existsSync9(path))
8862
+ if (!existsSync10(path))
8514
8863
  throw new CliError("not_found", `no store at ${path} to back up`);
8515
- if (existsSync9(target))
8864
+ if (existsSync10(target))
8516
8865
  throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
8517
8866
  const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
8518
8867
  const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
@@ -8545,11 +8894,11 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8545
8894
  const { output } = this.opts();
8546
8895
  const from = resolve(file2);
8547
8896
  const to = resolve(output);
8548
- if (!existsSync9(from))
8897
+ if (!existsSync10(from))
8549
8898
  throw new CliError("not_found", `no file at ${from}`);
8550
8899
  if (!isSealed(from))
8551
8900
  throw new CliError("validation_error", `${from} was not written with --encrypt`);
8552
- if (existsSync9(to))
8901
+ if (existsSync10(to))
8553
8902
  throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
8554
8903
  await unsealFile(from, to, await passwordOf(this, { twice: false }));
8555
8904
  result(this, { path: to, from, bytes: bytesOf2(to) });
@@ -8557,13 +8906,13 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8557
8906
  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) {
8558
8907
  const path = storePath(environmentOf(this).env ?? process.env);
8559
8908
  const given = resolve(file2);
8560
- if (!existsSync9(given))
8909
+ if (!existsSync10(given))
8561
8910
  throw new CliError("not_found", `no file at ${given}`);
8562
8911
  refuseWhileServing(this, messenger);
8563
8912
  if (!isSealed(given))
8564
8913
  return restoreFrom(this, messenger, given, given);
8565
8914
  const opened = `${path}.unsealing-${process.pid}`;
8566
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
8915
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8567
8916
  try {
8568
8917
  await unsealFile(given, opened, await passwordOf(this, { twice: false }));
8569
8918
  await restoreFrom(this, messenger, opened, given);
@@ -8574,26 +8923,26 @@ var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command(
8574
8923
  var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
8575
8924
  const { renderer } = outputFor(command);
8576
8925
  const path = storePath(environmentOf(command).env ?? process.env);
8577
- if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
8926
+ if (existsSync10(path) && realpathSync3(backup) === realpathSync3(path)) {
8578
8927
  throw new CliError("validation_error", `${backup} is the store itself`);
8579
8928
  }
8580
8929
  if (await isRollbackCopy(backup))
8581
8930
  return rollBackFrom(command, messenger, backup);
8582
8931
  const schema = await backupSchema(backup);
8583
8932
  const stamp = stampNow();
8584
- const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
8933
+ const kept = existsSync10(path) ? `${path}.before-restore-${stamp}` : null;
8585
8934
  if (kept) {
8586
8935
  const waitMs = environmentOf(command).storeLockWaitMs;
8587
8936
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
8588
8937
  } else
8589
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
8938
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8590
8939
  const incoming = `${path}.restoring-${stamp}`;
8591
8940
  copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
8592
8941
  chmodSync(incoming, 384);
8593
8942
  if (kept) {
8594
8943
  renameSync3(path, kept);
8595
8944
  for (const suffix of ["-wal", "-shm"])
8596
- if (existsSync9(`${path}${suffix}`))
8945
+ if (existsSync10(`${path}${suffix}`))
8597
8946
  renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
8598
8947
  }
8599
8948
  renameSync3(incoming, path);
@@ -8615,7 +8964,7 @@ var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
8615
8964
  var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
8616
8965
  const { renderer } = outputFor(command);
8617
8966
  const path = storePath(environmentOf(command).env ?? process.env);
8618
- if (!existsSync9(path))
8967
+ if (!existsSync10(path))
8619
8968
  throw new CliError("not_found", `no store at ${path} to roll back`);
8620
8969
  const waitMs = environmentOf(command).storeLockWaitMs;
8621
8970
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
@@ -8665,7 +9014,7 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
8665
9014
  var STORE_LOCK_WAIT_MS = 1e3;
8666
9015
  var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
8667
9016
  const { command } = messenger.app;
8668
- const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
9017
+ const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync10(file2)).map((file2) => realpathSync3(file2));
8669
9018
  const holders = holdersOf(files);
8670
9019
  if (holders === void 0) {
8671
9020
  warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
@@ -8691,7 +9040,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8691
9040
  const { command } = messenger.app;
8692
9041
  const env = environmentOf(this).env ?? process.env;
8693
9042
  const path = storePath(env);
8694
- if (!existsSync9(path)) {
9043
+ if (!existsSync10(path)) {
8695
9044
  result(this, { path, exists: false, reset: false });
8696
9045
  renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
8697
9046
  return;
@@ -8736,8 +9085,8 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
8736
9085
  }), "resetCommand");
8737
9086
  var STORE_PARTS2 = ["", "-wal", "-shm"];
8738
9087
  var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
8739
- const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync9(file2));
8740
- const holders = holdersOf(files.map((file2) => realpathSync2(file2)));
9088
+ const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync10(file2));
9089
+ const holders = holdersOf(files.map((file2) => realpathSync3(file2)));
8741
9090
  const serving = servingProfiles(messenger.app, env).length > 0;
8742
9091
  const read = await readingOnly(path, (database) => ({
8743
9092
  schema: schemaOf(database).version,