@wirecat/mail-cli 0.18.0 → 0.20.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 (112) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/bin/mail.js +2 -2
  3. package/dist/bundle/{all-profiles-4CVOXA5Y.js → all-profiles-DTUWUCQQ.js} +7 -6
  4. package/dist/bundle/{anthropic-5VIKYINO.js → anthropic-YJAEQSNT.js} +3 -3
  5. package/dist/bundle/{app-server-LTSQBDPF.js → app-server-3ZXSTBA3.js} +41 -40
  6. package/dist/bundle/{bun-C7DBRUW2.js → bun-34VBM7C5.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-Y5JKT62B.js → bun-sqlite-GCT7ROCK.js} +2 -2
  8. package/dist/bundle/{chunk-A5OMARL4.js → chunk-2PPEDB67.js} +31 -29
  9. package/dist/bundle/{chunk-IANOK5SE.js → chunk-3DSYLE5N.js} +2 -2
  10. package/dist/bundle/{chunk-QPF4LTK5.js → chunk-3HDQVTND.js} +4 -4
  11. package/dist/bundle/{chunk-ZLH465EU.js → chunk-4FWJNIPH.js} +1 -1
  12. package/dist/bundle/{chunk-C4RUKMDT.js → chunk-4WIEVQ2Q.js} +8 -14
  13. package/dist/bundle/{chunk-SMS5YNPB.js → chunk-566MEXK5.js} +2 -2
  14. package/dist/bundle/{chunk-GRP67IQ4.js → chunk-72N26BQM.js} +24 -22
  15. package/dist/bundle/{chunk-6RO5RDNR.js → chunk-7XLOWYGD.js} +109 -6
  16. package/dist/bundle/{chunk-AOMSP4EI.js → chunk-AF62BPIW.js} +5 -5
  17. package/dist/bundle/{chunk-U43HUE35.js → chunk-B74SOC4R.js} +9 -20
  18. package/dist/bundle/{chunk-TVZ77ZOV.js → chunk-FTI73RLC.js} +2 -2
  19. package/dist/bundle/{chunk-EFP5NN7I.js → chunk-GAPQENMY.js} +2 -2
  20. package/dist/bundle/{chunk-N5VEJ3E7.js → chunk-HJ2CXDKJ.js} +130 -11
  21. package/dist/bundle/{chunk-P6WCG6X2.js → chunk-HN43G27G.js} +43 -27
  22. package/dist/bundle/{chunk-L3YX7A5M.js → chunk-HRRSTIGP.js} +4 -4
  23. package/dist/bundle/{chunk-NDJZQCF3.js → chunk-HSBGNVEL.js} +210 -171
  24. package/dist/bundle/{chunk-2NWOYXPJ.js → chunk-I2SDXWLR.js} +206 -56
  25. package/dist/bundle/{chunk-BMFPCW6Q.js → chunk-J2U6LUT5.js} +17 -3
  26. package/dist/bundle/{chunk-UXD5JMS5.js → chunk-J4UZXBEV.js} +1 -1
  27. package/dist/bundle/{chunk-OUGGAAXI.js → chunk-KMQAHDBM.js} +7539 -13576
  28. package/dist/bundle/{chunk-CPEN6BZZ.js → chunk-LF5XM4HE.js} +1 -1
  29. package/dist/bundle/chunk-LTXYJAJK.js +12211 -0
  30. package/dist/bundle/{chunk-7P4ICYJT.js → chunk-MD64ITYO.js} +1 -1
  31. package/dist/bundle/{chunk-WA3DQSAZ.js → chunk-MDDB7M7Z.js} +1 -1
  32. package/dist/bundle/{chunk-OLJDZTHB.js → chunk-NOVBK4SY.js} +12 -12
  33. package/dist/bundle/{chunk-MCR43SWG.js → chunk-O3M2S62X.js} +21 -13
  34. package/dist/bundle/{chunk-5S6Q3SWU.js → chunk-ODFHIXMA.js} +1 -1
  35. package/dist/bundle/{chunk-ZT2Y267T.js → chunk-OKO2Q6H6.js} +2 -2
  36. package/dist/bundle/{chunk-RQSF7X22.js → chunk-P2QJA7S5.js} +1 -1
  37. package/dist/bundle/{chunk-C5T5K7HW.js → chunk-P6FT6YYT.js} +17 -14
  38. package/dist/bundle/{chunk-RIO3TD3I.js → chunk-QE72KTS7.js} +1 -1
  39. package/dist/bundle/{chunk-JO3BIMYK.js → chunk-QPRXTLMD.js} +1 -1
  40. package/dist/bundle/{chunk-23HWKHPZ.js → chunk-QTMVGOSF.js} +352 -290
  41. package/dist/bundle/{chunk-SW2KERUB.js → chunk-R3WPMQYZ.js} +270 -153
  42. package/dist/bundle/{chunk-XGTW3GRX.js → chunk-RFB27ACZ.js} +2 -2
  43. package/dist/bundle/{chunk-HTFBXGJF.js → chunk-RPCKBXKN.js} +1 -1
  44. package/dist/bundle/{chunk-43I5XD7S.js → chunk-RT6SLZBI.js} +1 -1
  45. package/dist/bundle/{chunk-3W5H4TM7.js → chunk-RY7PBP4F.js} +71 -31
  46. package/dist/bundle/{chunk-BMGVKULS.js → chunk-SCIC2CJS.js} +4 -4
  47. package/dist/bundle/{chunk-SIYT2BBI.js → chunk-SFC46MP2.js} +250 -9
  48. package/dist/bundle/chunk-SYEICLTR.js +66 -0
  49. package/dist/bundle/{chunk-HFUS33UT.js → chunk-T2GQA2E4.js} +4 -1
  50. package/dist/bundle/{chunk-ITUC5WAV.js → chunk-T3DTYJTG.js} +1 -1
  51. package/dist/bundle/{chunk-OMKPALMX.js → chunk-TCCN5TON.js} +1 -1
  52. package/dist/bundle/{chunk-FLOOPXOT.js → chunk-V6OIIVH3.js} +10 -10
  53. package/dist/bundle/{chunk-ACLILULA.js → chunk-VDUGE6TH.js} +2 -2
  54. package/dist/bundle/{chunk-3YRE6DNM.js → chunk-VINSQR4X.js} +7 -7
  55. package/dist/bundle/{chunk-UEGABYXI.js → chunk-VQZCIDSO.js} +2 -2
  56. package/dist/bundle/{chunk-ERBEBORA.js → chunk-WBAA2X3E.js} +10 -10
  57. package/dist/bundle/{chunk-M7C4IGJ6.js → chunk-Z75WYAX6.js} +6 -6
  58. package/dist/bundle/{chunk-GLLLYACZ.js → chunk-Z7N4MGOQ.js} +5 -5
  59. package/dist/bundle/{chunk-YA2JPMYX.js → chunk-ZKLXSVIO.js} +1 -1
  60. package/dist/bundle/{chunk-DPSH46NO.js → chunk-ZZSHGCRC.js} +3 -3
  61. package/dist/bundle/{command-contract-Y3GIKCPB.js → command-contract-Y4ZQAJEC.js} +14 -13
  62. package/dist/bundle/{decode-WVIDLK4E.js → decode-BIOOL5E4.js} +2 -2
  63. package/dist/bundle/{dist-KGQWS3XL.js → dist-TJVIRLE5.js} +79 -17
  64. package/dist/bundle/{echarts-VMKACZBF.js → echarts-ECPGMKXO.js} +2 -2
  65. package/dist/bundle/{embed-EQINOOST.js → embed-F7JFSLHN.js} +3 -3
  66. package/dist/bundle/{embedder-LM52TDRN.js → embedder-U4G74HV3.js} +6 -6
  67. package/dist/bundle/{first-run-H4VXZAAF.js → first-run-JTYPUYQP.js} +5 -5
  68. package/dist/bundle/first-screen-W6RWTAU7.js +33 -0
  69. package/dist/bundle/{instructions-NLSME663.js → instructions-WNCGZ7OJ.js} +1 -1
  70. package/dist/bundle/mail.js +2 -2
  71. package/dist/bundle/{node-FGMSXLTA.js → node-UIRGGMGT.js} +2 -2
  72. package/dist/bundle/{node-sqlite-K3T3ZRBY.js → node-sqlite-4ZM7OPRF.js} +3 -3
  73. package/dist/bundle/{oauth-OJKJ6JLH.js → oauth-5RAJZPBW.js} +4 -4
  74. package/dist/bundle/{open-DCYIXHXS.js → open-7ORCHOAI.js} +2 -2
  75. package/dist/bundle/{openai-C4H4W57J.js → openai-XSJNXJA7.js} +10 -10
  76. package/dist/bundle/{process-MN4NSYGA.js → process-ZLO72UVZ.js} +1 -1
  77. package/dist/bundle/{program-ZZZOKWCX.js → program-PFVJDKM4.js} +1911 -1655
  78. package/dist/bundle/{prompt-ELEJUDAU.js → prompt-IDUPCUGM.js} +2 -2
  79. package/dist/bundle/{recognize-G2FVMI5M.js → recognize-OS3EZKIM.js} +1 -1
  80. package/dist/bundle/{remote-F4YVSEYM.js → remote-PF4LZR65.js} +4 -4
  81. package/dist/bundle/{rerank-7VM5R5N6.js → rerank-CQNZF3JI.js} +4 -4
  82. package/dist/bundle/{serve-A7NRFPRN.js → serve-Y2DDLGBT.js} +6 -6
  83. package/dist/bundle/server-I3IALQMC.js +65 -0
  84. package/dist/bundle/{server-7R2BEIRY.js → server-TVRT7YEY.js} +33 -32
  85. package/dist/bundle/{sqlite-runtime-4SKUB4EN.js → sqlite-runtime-5343C3OE.js} +3 -3
  86. package/dist/bundle/{state-S2FKK2XB.js → state-4GBTMPIV.js} +3 -3
  87. package/dist/bundle/{store-4HAARQVR.js → store-OLBLTQPT.js} +56 -13
  88. package/dist/bundle/{store-FLHO3UMA.js → store-QA6QJ5BB.js} +20 -11
  89. package/dist/bundle/store-maintenance-command-LB6CMGP4.js +55 -0
  90. package/dist/commands/login.d.ts.map +1 -1
  91. package/dist/commands/login.js +19 -4
  92. package/dist/commands/login.js.map +1 -1
  93. package/dist/commands/session-start.d.ts.map +1 -1
  94. package/dist/commands/session-start.js +86 -11
  95. package/dist/commands/session-start.js.map +1 -1
  96. package/dist/mail/imap/errors.d.ts.map +1 -1
  97. package/dist/mail/imap/errors.js +14 -1
  98. package/dist/mail/imap/errors.js.map +1 -1
  99. package/dist/providers.d.ts +7 -0
  100. package/dist/providers.d.ts.map +1 -1
  101. package/dist/providers.js +5 -0
  102. package/dist/providers.js.map +1 -1
  103. package/dist/reasons.d.ts.map +1 -1
  104. package/dist/reasons.js +3 -0
  105. package/dist/reasons.js.map +1 -1
  106. package/dist/version.d.ts +1 -1
  107. package/dist/version.js +1 -1
  108. package/package.json +3 -3
  109. package/dist/bundle/chunk-KVSC657S.js +0 -656
  110. package/dist/bundle/first-screen-ZP74TJLK.js +0 -32
  111. package/dist/bundle/server-DFJA2HBO.js +0 -64
  112. package/dist/bundle/store-maintenance-command-BINJIQ6F.js +0 -54
@@ -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-YA2JPMYX.js";
5
+ } from "./chunk-ZKLXSVIO.js";
6
6
  import {
7
7
  answerOf,
8
8
  messengerContext
9
- } from "./chunk-GRP67IQ4.js";
9
+ } from "./chunk-72N26BQM.js";
10
10
  import {
11
11
  FETCHING,
12
12
  RULES_VERSION,
@@ -27,19 +27,19 @@ import {
27
27
  typedQuery,
28
28
  withQuery,
29
29
  withTimeLimit
30
- } from "./chunk-23HWKHPZ.js";
30
+ } from "./chunk-QTMVGOSF.js";
31
31
  import {
32
32
  checkedOptions,
33
33
  range
34
- } from "./chunk-JO3BIMYK.js";
34
+ } from "./chunk-QPRXTLMD.js";
35
35
  import {
36
36
  messagesFor,
37
37
  systemFor,
38
38
  validateImages
39
- } from "./chunk-OMKPALMX.js";
39
+ } from "./chunk-TCCN5TON.js";
40
40
  import {
41
41
  readSecret
42
- } from "./chunk-EFP5NN7I.js";
42
+ } from "./chunk-GAPQENMY.js";
43
43
  import {
44
44
  Command,
45
45
  LOCAL_READ,
@@ -67,29 +67,27 @@ import {
67
67
  snakeKeys,
68
68
  storeTable,
69
69
  withoutProviderRefs
70
- } from "./chunk-NDJZQCF3.js";
70
+ } from "./chunk-HSBGNVEL.js";
71
71
  import {
72
72
  levelFor
73
- } from "./chunk-L3YX7A5M.js";
74
- import {
75
- failureKey
76
- } from "./chunk-U43HUE35.js";
73
+ } from "./chunk-HRRSTIGP.js";
77
74
  import {
78
75
  holdLock,
79
76
  lockPath,
80
77
  releaseLock,
81
78
  servingProfiles,
82
79
  takeLock
83
- } from "./chunk-UEGABYXI.js";
80
+ } from "./chunk-VQZCIDSO.js";
84
81
  import {
85
82
  holdersOf
86
- } from "./chunk-ITUC5WAV.js";
83
+ } from "./chunk-T3DTYJTG.js";
87
84
  import {
88
85
  QUICK_HEALTH_CHECKS,
89
86
  explainDamage,
90
87
  fts5Tables,
88
+ invalidJson,
91
89
  storeHealth
92
- } from "./chunk-3W5H4TM7.js";
90
+ } from "./chunk-RY7PBP4F.js";
93
91
  import {
94
92
  CORPORA,
95
93
  MIGRATIONS,
@@ -123,20 +121,29 @@ import {
123
121
  storeClients,
124
122
  storeContents,
125
123
  vectorIndexCounts
126
- } from "./chunk-OUGGAAXI.js";
124
+ } from "./chunk-KMQAHDBM.js";
127
125
  import {
128
126
  formatLocator,
129
127
  parseLocator
130
- } from "./chunk-KVSC657S.js";
128
+ } from "./chunk-LTXYJAJK.js";
129
+ import {
130
+ readDamageMark,
131
+ readHealthMark,
132
+ recordDeepCheck
133
+ } from "./chunk-HJ2CXDKJ.js";
131
134
  import {
132
135
  queryFieldsOf
133
- } from "./chunk-2NWOYXPJ.js";
136
+ } from "./chunk-I2SDXWLR.js";
137
+ import {
138
+ failureKey,
139
+ isStoreDamage
140
+ } from "./chunk-SYEICLTR.js";
134
141
  import {
135
142
  storePath
136
- } from "./chunk-HTFBXGJF.js";
143
+ } from "./chunk-RPCKBXKN.js";
137
144
  import {
138
145
  openCache
139
- } from "./chunk-AOMSP4EI.js";
146
+ } from "./chunk-AF62BPIW.js";
140
147
  import {
141
148
  Credentials,
142
149
  pathsAreOverridden,
@@ -4813,15 +4820,15 @@ var require_liquid_node = __commonJS({
4813
4820
  }
4814
4821
  *render(ctx, emitter) {
4815
4822
  const group = yield evalToken(this.group, ctx);
4816
- const fingerprint2 = `cycle:${group}:` + this.candidates.join(",");
4823
+ const fingerprint = `cycle:${group}:` + this.candidates.join(",");
4817
4824
  const groups = ctx.getRegister("cycle", {});
4818
- let idx = groups[fingerprint2];
4825
+ let idx = groups[fingerprint];
4819
4826
  if (idx === void 0) {
4820
- idx = groups[fingerprint2] = 0;
4827
+ idx = groups[fingerprint] = 0;
4821
4828
  }
4822
4829
  const candidate = this.candidates[idx];
4823
4830
  idx = (idx + 1) % this.candidates.length;
4824
- groups[fingerprint2] = idx;
4831
+ groups[fingerprint] = idx;
4825
4832
  return yield evalToken(candidate, ctx);
4826
4833
  }
4827
4834
  *arguments() {
@@ -5509,11 +5516,11 @@ var require_liquid_node = __commonJS({
5509
5516
  }
5510
5517
  });
5511
5518
 
5512
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5519
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5513
5520
  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";
5514
5521
  import { dirname as dirname2, resolve } from "node:path";
5515
5522
 
5516
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/sealed.js
5523
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/sealed.js
5517
5524
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5518
5525
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5519
5526
  import { Transform } from "node:stream";
@@ -5620,7 +5627,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5620
5627
  renameSync(pending, to);
5621
5628
  }, "unsealFile");
5622
5629
 
5623
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5630
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5624
5631
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5625
5632
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5626
5633
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5644,7 +5651,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5644
5651
  };
5645
5652
  }, "compatibilityOf");
5646
5653
 
5647
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/repair.js
5654
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/store/repair.js
5648
5655
  import { createHash as createHash2 } from "node:crypto";
5649
5656
  var COPY_MARK = "__repair_";
5650
5657
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5898,19 +5905,20 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5898
5905
  return found;
5899
5906
  }, "deleteCopy");
5900
5907
 
5901
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5908
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5902
5909
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5903
5910
 
5904
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5911
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5905
5912
  import { existsSync as existsSync3 } from "node:fs";
5906
5913
 
5907
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/recover.js
5914
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/store/recover.js
5908
5915
  import { execFileSync, spawn } from "node:child_process";
5909
5916
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5910
5917
  import { basename, dirname, join } from "node:path";
5911
5918
  import { Transform as Transform2 } from "node:stream";
5912
5919
  var SQLITE3_MINIMUM = [3, 43, 0];
5913
5920
  var STORE_PARTS = ["", "-wal", "-shm"];
5921
+ var RECOVER_LOCK = ".recover-lock";
5914
5922
  var INSERTED = /^INSERT OR IGNORE INTO '([^']+)'/;
5915
5923
  var LOST_AND_FOUND = "recover_lost_and_found";
5916
5924
  var recovers = /* @__PURE__ */ __name((program) => {
@@ -5945,11 +5953,55 @@ var activeTimers = /* @__PURE__ */ __name(() => {
5945
5953
  return void 0;
5946
5954
  }
5947
5955
  }, "activeTimers");
5956
+ var alive = /* @__PURE__ */ __name((pid) => {
5957
+ try {
5958
+ process.kill(pid, 0);
5959
+ return true;
5960
+ } catch (error) {
5961
+ return error.code === "EPERM";
5962
+ }
5963
+ }, "alive");
5964
+ var runningRecovery = /* @__PURE__ */ __name((path) => {
5965
+ let pid;
5966
+ try {
5967
+ pid = Number(readFileSync(`${path}${RECOVER_LOCK}`, "utf8").trim());
5968
+ } catch {
5969
+ return null;
5970
+ }
5971
+ return Number.isInteger(pid) && pid > 0 && alive(pid) ? pid : null;
5972
+ }, "runningRecovery");
5973
+ var takeRecoverLock = /* @__PURE__ */ __name((path) => {
5974
+ const lock = `${path}${RECOVER_LOCK}`;
5975
+ const take = /* @__PURE__ */ __name(() => writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 }), "take");
5976
+ try {
5977
+ take();
5978
+ } catch (error) {
5979
+ if (error.code !== "EEXIST")
5980
+ throw error;
5981
+ const pid = runningRecovery(path);
5982
+ if (pid === null) {
5983
+ rmSync2(lock, { force: true });
5984
+ take();
5985
+ } else {
5986
+ throw new CliError("validation_error", `the store is being recovered by process ${pid} \u2014 wait for it to finish`, {
5987
+ reason: "store.recovering"
5988
+ });
5989
+ }
5990
+ }
5991
+ return () => rmSync2(lock, { force: true });
5992
+ }, "takeRecoverLock");
5948
5993
  var storeHolders = /* @__PURE__ */ __name((path) => {
5949
5994
  const folder = realpathSync(dirname(path));
5950
5995
  const files = STORE_PARTS.map((suffix) => join(folder, `${basename(path)}${suffix}`));
5951
5996
  const wanted = process.platform === "linux" ? files.flatMap((file2) => [file2, `${file2} (deleted)`]) : files.filter(existsSync2);
5952
- return holdersOf(wanted)?.map((pid) => {
5997
+ const recovering = runningRecovery(path);
5998
+ const pids = holdersOf(wanted);
5999
+ if (pids === void 0 && recovering === null)
6000
+ return void 0;
6001
+ const all = [
6002
+ .../* @__PURE__ */ new Set([...pids ?? [], ...recovering !== null && recovering !== process.pid ? [recovering] : []])
6003
+ ];
6004
+ return all.map((pid) => {
5953
6005
  let name = "?";
5954
6006
  try {
5955
6007
  name = readFileSync(`/proc/${pid}/comm`, "utf8").trim();
@@ -6111,10 +6163,14 @@ var mailToFetch = /* @__PURE__ */ __name((database) => {
6111
6163
  return [];
6112
6164
  }
6113
6165
  }, "mailToFetch");
6114
- var fingerprint = /* @__PURE__ */ __name((path) => ["", "-wal"].map((suffix) => {
6115
- const stat = statSync2(`${path}${suffix}`, { throwIfNoEntry: false });
6116
- return stat ? `${stat.size}:${stat.mtimeMs}` : "-";
6117
- }).join("|"), "fingerprint");
6166
+ var clearInvalidJson = /* @__PURE__ */ __name((database) => {
6167
+ const found = invalidJson(database);
6168
+ for (const { table, column, required } of found) {
6169
+ const invalid = `"${column}" IS NOT NULL AND NOT json_valid("${column}")`;
6170
+ database.exec(required ? `DELETE FROM "${table}" WHERE ${invalid}` : `UPDATE "${table}" SET "${column}" = NULL WHERE ${invalid}`);
6171
+ }
6172
+ return found;
6173
+ }, "clearInvalidJson");
6118
6174
  var refuseInUse = /* @__PURE__ */ __name((path) => {
6119
6175
  const holders = storeHolders(path);
6120
6176
  if (holders && holders.length > 0) {
@@ -6131,98 +6187,128 @@ var recoverStore = /* @__PURE__ */ __name(async ({ path, command, version, sqlit
6131
6187
  if (!program.usable) {
6132
6188
  throw new CliError("configuration_error", program.version ? `sqlite3 ${program.version} cannot recover: the recovery needs ${SQLITE3_MINIMUM.join(".")} or newer, built with .recover` : "the recovery needs the sqlite3 program with its .recover command: install it (apt install sqlite3, brew install sqlite)", { reason: "store.sqlite3-missing" });
6133
6189
  }
6134
- refuseInUse(path);
6135
- const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
6136
- const { bavail, bsize } = statfsSync(dirname(path));
6137
- if (Number(bavail) * Number(bsize) < bytes * 1.2)
6138
- throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
6139
- const old = await openSqlite(path, { readOnly: true });
6140
- let rowsBefore;
6190
+ const releaseLock2 = takeRecoverLock(path);
6141
6191
  try {
6142
- rowsBefore = tableRows(old.database);
6192
+ refuseInUse(path);
6193
+ const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
6194
+ const { bavail, bsize } = statfsSync(dirname(path));
6195
+ if (Number(bavail) * Number(bsize) < bytes * 1.2)
6196
+ throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
6197
+ return await recoverLocked({ path, command, version, sqlite3, now, note, copy, started, program });
6143
6198
  } finally {
6144
- old.database.close();
6199
+ releaseLock2();
6145
6200
  }
6146
- const before = fingerprint(path);
6147
- const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6148
- const target = `${path}.recovering-${stamp}`;
6149
- writeFileSync(target, "", { flag: "wx", mode: 384 });
6150
- const dropTarget = /* @__PURE__ */ __name(() => {
6151
- for (const suffix of [...STORE_PARTS, "-journal"])
6152
- rmSync2(`${target}${suffix}`, { force: true });
6153
- }, "dropTarget");
6154
- note(`copying the readable rows into ${target}`);
6155
- let copied;
6156
- let copyErrors;
6157
- let read;
6158
- let opened;
6159
- try {
6160
- ;
6161
- ({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
6162
- copied = Date.now();
6163
- opened = await openSqlite(target);
6164
- } catch (error) {
6165
- dropTarget();
6166
- throw error;
6167
- }
6168
- let rebuilt;
6169
- let kept;
6170
- let dangling;
6171
- let fetch2;
6201
+ }, "recoverStore");
6202
+ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqlite3, now, note, copy, started, program }) => {
6203
+ const watch = (await openSqlite(path, { readOnly: true })).database;
6204
+ let watching = true;
6205
+ const stopWatching = /* @__PURE__ */ __name(() => {
6206
+ if (watching)
6207
+ watch.close();
6208
+ watching = false;
6209
+ }, "stopWatching");
6172
6210
  try {
6173
- kept = tableRows(opened.database);
6174
- migrate(opened.database, { command, ...version ? { version } : {} });
6175
- rebuilt = rebuildDerived(opened.database, { now, note });
6176
- note("looking for rows that point at rows that were lost");
6177
- dangling = danglingRows(opened.database);
6178
- fetch2 = mailToFetch(opened.database);
6179
- opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6180
- } catch (error) {
6211
+ const dataVersion = /* @__PURE__ */ __name(() => Number(watch.prepare("PRAGMA data_version").get()?.data_version), "dataVersion");
6212
+ let rowsBefore;
6213
+ try {
6214
+ rowsBefore = tableRows(watch);
6215
+ } catch (error) {
6216
+ if (!isStoreDamage(error))
6217
+ throw error;
6218
+ 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" });
6219
+ }
6220
+ const before = { data: dataVersion(), inode: statSync2(path).ino };
6221
+ const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6222
+ const target = `${path}.recovering-${stamp}`;
6223
+ writeFileSync(target, "", { flag: "wx", mode: 384 });
6224
+ const dropTarget = /* @__PURE__ */ __name(() => {
6225
+ for (const suffix of [...STORE_PARTS, "-journal"])
6226
+ rmSync2(`${target}${suffix}`, { force: true });
6227
+ }, "dropTarget");
6228
+ note(`copying the readable rows into ${target}`);
6229
+ let copied;
6230
+ let copyErrors;
6231
+ let read;
6232
+ let opened;
6233
+ try {
6234
+ ;
6235
+ ({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
6236
+ copied = Date.now();
6237
+ opened = await openSqlite(target);
6238
+ } catch (error) {
6239
+ dropTarget();
6240
+ throw error;
6241
+ }
6242
+ let rebuilt;
6243
+ let kept;
6244
+ let dangling;
6245
+ let json;
6246
+ let fetch2;
6247
+ let schema;
6248
+ try {
6249
+ kept = tableRows(opened.database);
6250
+ migrate(opened.database, { command, ...version ? { version } : {} });
6251
+ note("clearing values that are not valid JSON");
6252
+ json = clearInvalidJson(opened.database);
6253
+ rebuilt = rebuildDerived(opened.database, { now, note });
6254
+ note("looking for rows that point at rows that were lost");
6255
+ dangling = danglingRows(opened.database);
6256
+ fetch2 = mailToFetch(opened.database);
6257
+ schema = fileSchemaOf(opened.database).version;
6258
+ opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6259
+ } catch (error) {
6260
+ opened.database.close();
6261
+ dropTarget();
6262
+ throw error;
6263
+ }
6181
6264
  opened.database.close();
6182
- dropTarget();
6183
- throw error;
6184
- }
6185
- opened.database.close();
6186
- const rebuiltAt = Date.now();
6187
- note("checking the recovered file");
6188
- const health = await storeHealth(target, { deep: true });
6189
- const checkedAt = Date.now();
6190
- if (!health.ok) {
6191
- throw new CliError("validation_error", `the recovered file did not pass its check, so the store was left as it was; the file is kept at ${target}`, { reason: "store.recovery-failed" });
6192
- }
6193
- refuseInUse(path);
6194
- if (fingerprint(path) !== before) {
6195
- throw new CliError("validation_error", `the store was written to during the recovery, so it was left as it was \u2014 stop every timer and run it again; ${target} can be deleted`, { reason: "store.changed-during-recovery" });
6265
+ const rebuiltAt = Date.now();
6266
+ note("checking the recovered file");
6267
+ const health = await storeHealth(target, { deep: true });
6268
+ const checkedAt = Date.now();
6269
+ if (!health.ok) {
6270
+ throw new CliError("validation_error", `the recovered file did not pass its check, so the store was left as it was; the file is kept at ${target}`, { reason: "store.recovery-failed" });
6271
+ }
6272
+ refuseInUse(path);
6273
+ const changed = dataVersion() !== before.data || statSync2(path, { throwIfNoEntry: false })?.ino !== before.inode;
6274
+ stopWatching();
6275
+ if (changed) {
6276
+ throw new CliError("validation_error", `the store was written to during the recovery, so it was left as it was \u2014 stop every timer and run it again; ${target} can be deleted`, { reason: "store.changed-during-recovery" });
6277
+ }
6278
+ const keptAt = `${path}.before-recover-${stamp}`;
6279
+ for (const suffix of STORE_PARTS)
6280
+ if (existsSync2(`${path}${suffix}`))
6281
+ renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
6282
+ for (const suffix of STORE_PARTS)
6283
+ if (existsSync2(`${target}${suffix}`))
6284
+ renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6285
+ recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema, now });
6286
+ 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);
6287
+ const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6288
+ return {
6289
+ path,
6290
+ keptAt,
6291
+ sqlite3: program.version,
6292
+ lost,
6293
+ dangling,
6294
+ invalidJson: json,
6295
+ mailToFetch: fetch2,
6296
+ rebuilt,
6297
+ copyErrors,
6298
+ health,
6299
+ seconds: {
6300
+ copy: seconds(started, copied),
6301
+ rebuild: seconds(copied, rebuiltAt),
6302
+ check: seconds(rebuiltAt, checkedAt),
6303
+ total: seconds(started, Date.now())
6304
+ }
6305
+ };
6306
+ } finally {
6307
+ stopWatching();
6196
6308
  }
6197
- const keptAt = `${path}.before-recover-${stamp}`;
6198
- for (const suffix of STORE_PARTS)
6199
- if (existsSync2(`${path}${suffix}`))
6200
- renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
6201
- for (const suffix of STORE_PARTS)
6202
- if (existsSync2(`${target}${suffix}`))
6203
- renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6204
- 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);
6205
- const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6206
- return {
6207
- path,
6208
- keptAt,
6209
- sqlite3: program.version,
6210
- lost,
6211
- dangling,
6212
- mailToFetch: fetch2,
6213
- rebuilt,
6214
- copyErrors,
6215
- health,
6216
- seconds: {
6217
- copy: seconds(started, copied),
6218
- rebuild: seconds(copied, rebuiltAt),
6219
- check: seconds(rebuiltAt, checkedAt),
6220
- total: seconds(started, Date.now())
6221
- }
6222
- };
6223
- }, "recoverStore");
6309
+ }, "recoverLocked");
6224
6310
 
6225
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6311
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6226
6312
  var COUNTED = [
6227
6313
  "accounts",
6228
6314
  "chats",
@@ -6237,15 +6323,17 @@ var COUNTED = [
6237
6323
  "mentions"
6238
6324
  ];
6239
6325
  var stopTimers = /* @__PURE__ */ __name((timers) => `systemctl --user stop ${timers.join(" ")}`, "stopTimers");
6240
- var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6326
+ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) => {
6241
6327
  const path = storePath(env);
6242
6328
  if (!existsSync3(path))
6243
6329
  return { path, exists: false, ok: true, next: [] };
6244
6330
  const health = await storeHealth(path, { deep: true });
6245
6331
  let rows = {};
6332
+ let schema = null;
6246
6333
  try {
6247
6334
  const { database } = await openSqlite(path, { readOnly: true });
6248
6335
  try {
6336
+ schema = fileSchemaOf(database).version;
6249
6337
  const all = tableRows(database);
6250
6338
  rows = Object.fromEntries(COUNTED.filter((table) => table in all).map((table) => [table, all[table] ?? null]));
6251
6339
  } finally {
@@ -6253,7 +6341,9 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6253
6341
  }
6254
6342
  } catch {
6255
6343
  }
6256
- const explanation = explainDamage(health, command);
6344
+ recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
6345
+ const mark = readDamageMark(path);
6346
+ const explanation = explainDamage(health, command, mark);
6257
6347
  const inUse = storeHolders(path) ?? null;
6258
6348
  const timers = activeTimers() ?? null;
6259
6349
  const sqlite3 = sqlite3Program();
@@ -6271,8 +6361,11 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6271
6361
  problems: health.problems ?? 0,
6272
6362
  damagedTables: health.damagedTables ?? [],
6273
6363
  damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
6364
+ invalidJson: health.invalidJson ?? [],
6274
6365
  rows,
6275
6366
  explanation,
6367
+ damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
6368
+ lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
6276
6369
  inUse,
6277
6370
  timers,
6278
6371
  sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
@@ -6309,6 +6402,7 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6309
6402
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6310
6403
  ...lost.length ? lost : ["no table lost a row"],
6311
6404
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6405
+ ...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
6312
6406
  ...answer.next.map((line) => `next: ${line}`)
6313
6407
  ];
6314
6408
  }
@@ -6319,13 +6413,14 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6319
6413
  const why = answer.explanation;
6320
6414
  return [
6321
6415
  ...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
6416
+ answer.lastKnownGood ? `the store last passed a deep check at ${answer.lastKnownGood}` : "no deep check that passed is on record for this store",
6322
6417
  ...answer.next.map((line) => `next: ${line}`)
6323
6418
  ];
6324
6419
  }, "recoveryNotes");
6325
6420
  var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6326
6421
  const recover = annotate(new Command("recover"), { effects: LOCAL_READ, examples: [`${command} store recover`] }).summary("what is damaged in the store and how to recover it").description("check every page and search index of the store, say what is damaged, what it means and the commands that recover it; changes nothing").action(async function() {
6327
6422
  const output = outputFor(this);
6328
- const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command);
6423
+ const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command, version);
6329
6424
  renderAnswer(this, output, itemOf(snakeKeys(answer)));
6330
6425
  if (output.format === "pretty")
6331
6426
  for (const line of recoveryNotes(answer))
@@ -6346,7 +6441,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6346
6441
  return recover;
6347
6442
  }, "storeRecoverCommand");
6348
6443
 
6349
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6444
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6350
6445
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6351
6446
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6352
6447
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6392,7 +6487,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6392
6487
  renderAnswer(this, outputFor(this), itemOf(answer));
6393
6488
  }), "storeInfoCommand");
6394
6489
 
6395
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6490
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6396
6491
  var ENCRYPT_OPTION = [
6397
6492
  "--encrypt",
6398
6493
  "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"
@@ -6411,7 +6506,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6411
6506
  return password;
6412
6507
  }, "passwordOf");
6413
6508
 
6414
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/rules.js
6509
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/rules.js
6415
6510
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6416
6511
  import { join as join2 } from "node:path";
6417
6512
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6582,7 +6677,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6582
6677
  }, "problem");
6583
6678
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6584
6679
 
6585
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/state.js
6680
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/state.js
6586
6681
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6587
6682
  import { join as join3 } from "node:path";
6588
6683
  var ANSWERED_KEPT = 1e3;
@@ -6635,7 +6730,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6635
6730
  }, "recordReply");
6636
6731
  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");
6637
6732
 
6638
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/decide.js
6733
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/decide.js
6639
6734
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6640
6735
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6641
6736
  const { message, chat, owner, sender } = incoming;
@@ -6741,7 +6836,7 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6741
6836
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6742
6837
  }, "filled");
6743
6838
 
6744
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/template.js
6839
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/template.js
6745
6840
  var import_liquidjs = __toESM(require_liquid_node(), 1);
6746
6841
  var TEMPLATE_LIMITS = {
6747
6842
  parse: 32768,
@@ -6901,7 +6996,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6901
6996
  }
6902
6997
  }, "renderReplyTemplate");
6903
6998
 
6904
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6999
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6905
7000
  var DRY_RUN_DAYS = 7;
6906
7001
  var PAGE = 500;
6907
7002
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7015,7 +7110,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7015
7110
  }
7016
7111
  }, "storedSince");
7017
7112
 
7018
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
7113
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
7019
7114
  var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
7020
7115
  const host = new URL(baseUrl).host;
7021
7116
  return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
@@ -7046,7 +7141,7 @@ var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) =>
7046
7141
  };
7047
7142
  }, "embeddingKeys");
7048
7143
 
7049
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/models/openai.js
7144
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/models/openai.js
7050
7145
  var options = strictObject({
7051
7146
  temperature: range(0, 2),
7052
7147
  top_p: range(0, 1),
@@ -7095,7 +7190,7 @@ var openai = {
7095
7190
  }), "complete")
7096
7191
  };
7097
7192
 
7098
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/models/index.js
7193
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/models/index.js
7099
7194
  var modelGateway = /* @__PURE__ */ __name((deps) => ({
7100
7195
  complete: /* @__PURE__ */ __name(async (request) => {
7101
7196
  if (deps.signal?.aborted)
@@ -7110,7 +7205,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
7110
7205
  if (!adapter && target.provider === "openai")
7111
7206
  adapter = openai;
7112
7207
  if (!adapter && target.provider === "anthropic")
7113
- adapter = (await import("./anthropic-5VIKYINO.js")).anthropic;
7208
+ adapter = (await import("./anthropic-YJAEQSNT.js")).anthropic;
7114
7209
  if (!adapter)
7115
7210
  throw new CliError("validation_error", `no model adapter for ${target.provider}`);
7116
7211
  if (request.images !== void 0 && adapter.images !== true)
@@ -7151,7 +7246,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
7151
7246
  }, "complete")
7152
7247
  }), "modelGateway");
7153
7248
 
7154
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/consents.js
7249
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/consents.js
7155
7250
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7156
7251
  import { join as join4 } from "node:path";
7157
7252
  var shape = strictObject({
@@ -7176,7 +7271,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7176
7271
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7177
7272
  }, "mayModelReply");
7178
7273
 
7179
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7274
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7180
7275
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options2 = {
7181
7276
  ai: true
7182
7277
  }) => async (rule2, message, chat, now) => {
@@ -7223,7 +7318,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7223
7318
  return result2;
7224
7319
  }, "replyRenderer");
7225
7320
 
7226
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/serve.js
7321
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/replies/serve.js
7227
7322
  var NOT_ALLOWED = "replies.send is not allow";
7228
7323
  var NO_RULES = "no rules";
7229
7324
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7316,7 +7411,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7316
7411
  return { skip: why };
7317
7412
  }, "replyTo");
7318
7413
 
7319
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7414
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7320
7415
  var START_SYNC_DELAY_MS = 3e4;
7321
7416
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7322
7417
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7393,7 +7488,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
7393
7488
  };
7394
7489
  }, "startSync");
7395
7490
 
7396
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7491
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7397
7492
  var FIRST_FETCH_MS = 6e4;
7398
7493
  var DAY_MS = 864e5;
7399
7494
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7447,7 +7542,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
7447
7542
  };
7448
7543
  }, "memberFetches");
7449
7544
 
7450
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7545
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7451
7546
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7452
7547
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7453
7548
  if (context.format === "pretty") {
@@ -7480,7 +7575,7 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7480
7575
  return context;
7481
7576
  }, "recordDiagnostics");
7482
7577
 
7483
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7578
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7484
7579
  var STEMS_EVERY_MS = 3e4;
7485
7580
  var STEMS_SLICE_MS = 2e3;
7486
7581
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7520,7 +7615,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7520
7615
  };
7521
7616
  }, "stemFills");
7522
7617
 
7523
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7618
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7524
7619
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7525
7620
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7526
7621
  kind: attachment.kind,
@@ -7615,7 +7710,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7615
7710
  locale: messenger.app.locale
7616
7711
  }), "viewOf");
7617
7712
 
7618
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7713
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7619
7714
  var observed = /* @__PURE__ */ __name((value) => ({
7620
7715
  value: value.value,
7621
7716
  observed_at: value.observedAt,
@@ -7682,7 +7777,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7682
7777
  }
7683
7778
  }, "watchEventItem");
7684
7779
 
7685
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7780
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7686
7781
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7687
7782
  output: { entity: "watch_item" },
7688
7783
  effects: REMOTE_READ,
@@ -7837,7 +7932,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
7837
7932
  }
7838
7933
  }, "describe");
7839
7934
 
7840
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
7935
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
7841
7936
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
7842
7937
  const command = annotate(new Command("serve"), {
7843
7938
  output: { entity: "serve_summary" },
@@ -8101,7 +8196,7 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8101
8196
  };
8102
8197
  }, "tasking");
8103
8198
 
8104
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8199
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8105
8200
  import { existsSync as existsSync8 } from "node:fs";
8106
8201
  var PATH = "store tables list";
8107
8202
  var STORE_TABLES_QUERY = {
@@ -8144,7 +8239,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8144
8239
  return tables;
8145
8240
  }, "storeTablesCommand");
8146
8241
 
8147
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8242
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_2045f8d992dff370989171c93240f8d7/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8148
8243
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8149
8244
  var WORD_INDEX = "message_words";
8150
8245
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8170,11 +8265,26 @@ var readingOnly = /* @__PURE__ */ __name(async (path, read) => {
8170
8265
  database.close();
8171
8266
  }
8172
8267
  }, "readingOnly");
8173
- var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command } = {}) => {
8268
+ var withoutInode = /* @__PURE__ */ __name(({ inode: _, ...mark }) => mark, "withoutInode");
8269
+ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8270
+ try {
8271
+ return await readingOnly(path, (database) => fileSchemaOf(database).version);
8272
+ } catch {
8273
+ return null;
8274
+ }
8275
+ }, "fileSchema");
8276
+ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8174
8277
  const path = storePath(env);
8175
8278
  if (!existsSync9(path))
8176
8279
  return { path, exists: false };
8177
8280
  const checked = await storeHealth(path, { deep });
8281
+ const recorded = deep ? recordDeepCheck(path, checked, {
8282
+ cli: command ?? "unknown",
8283
+ ...version ? { version } : {},
8284
+ schema: await fileSchema(path)
8285
+ }) : null;
8286
+ const mark = readDamageMark(path);
8287
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
8178
8288
  const health = {
8179
8289
  checked: checked.checked,
8180
8290
  covers: deep ? "every page and every search index" : QUICK_HEALTH_CHECKS,
@@ -8182,20 +8292,27 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command }
8182
8292
  ms: checked.ms,
8183
8293
  ...checked.problems ? { problems: checked.problems } : {},
8184
8294
  ...checked.damagedTables?.length ? { damagedTables: checked.damagedTables } : {},
8295
+ ...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
8185
8296
  ...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
8186
8297
  };
8187
- const damage = command ? explainDamage(checked, command) : null;
8188
- const healthOf = { health, ...damage ? { damage } : {} };
8298
+ const damage = command ? explainDamage(checked, command, mark) : null;
8299
+ const healthOf = {
8300
+ health,
8301
+ lastKnownGood,
8302
+ ...mark ? { damageMark: withoutInode(mark) } : {},
8303
+ ...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
8304
+ ...damage ? { damage } : {}
8305
+ };
8189
8306
  try {
8190
8307
  return await reading(path, (database) => {
8191
- const { version, writable } = schemaOf(database);
8308
+ const { version: version2, writable } = schemaOf(database);
8192
8309
  return {
8193
8310
  path,
8194
8311
  exists: true,
8195
- schema: version,
8312
+ schema: version2,
8196
8313
  speaks: SPEAKS,
8197
8314
  writable,
8198
- ...version > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
8315
+ ...version2 > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
8199
8316
  ...healthOf
8200
8317
  };
8201
8318
  });