@wirecat/tg-cli 0.117.0 → 0.118.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 (90) hide show
  1. package/dist/bin/tg.js +2 -2
  2. package/dist/bundle/{adapter-VNQ72MBK.js → adapter-4YNP6VCO.js} +39 -39
  3. package/dist/bundle/{all-profiles-3W2UQTCK.js → all-profiles-MIQDYAGO.js} +6 -6
  4. package/dist/bundle/{anthropic-DFUW2KTG.js → anthropic-NTASPJYE.js} +3 -3
  5. package/dist/bundle/{app-server-5XJIMLHB.js → app-server-UJZBJ2SK.js} +36 -36
  6. package/dist/bundle/{bot-api-HRRBF3W6.js → bot-api-JZAD4L3N.js} +40 -40
  7. package/dist/bundle/{bot-history-GBH5XE4N.js → bot-history-OUDHH3NU.js} +12 -12
  8. package/dist/bundle/{bun-ZMOYGG6F.js → bun-EC4HDIRD.js} +2 -2
  9. package/dist/bundle/{bun-sqlite-6FZFMA7K.js → bun-sqlite-A4HJR6KO.js} +2 -2
  10. package/dist/bundle/{chunk-HORGORHK.js → chunk-2KQHUBTV.js} +10 -10
  11. package/dist/bundle/{chunk-6GFUL4OU.js → chunk-2NA5KVP6.js} +15 -12
  12. package/dist/bundle/{chunk-C6TUVV7E.js → chunk-4BV4UMBB.js} +470 -209
  13. package/dist/bundle/{chunk-EZTYJ43A.js → chunk-57LKX6N2.js} +1 -1
  14. package/dist/bundle/{chunk-4JDGN6OD.js → chunk-5IIU7X4S.js} +1 -1
  15. package/dist/bundle/{chunk-2XLKZL6K.js → chunk-5LDWBEWU.js} +42 -26
  16. package/dist/bundle/{chunk-MLHKQDUN.js → chunk-5QYU7B27.js} +268 -153
  17. package/dist/bundle/{chunk-AG6HWPQP.js → chunk-65XV5PPI.js} +2 -2
  18. package/dist/bundle/{chunk-RDSLSV4M.js → chunk-6AXUEJGL.js} +1 -1
  19. package/dist/bundle/{chunk-HWYSRB64.js → chunk-6RI4TEIC.js} +2 -2
  20. package/dist/bundle/{chunk-7Y3RUEVY.js → chunk-6ZMTEUVU.js} +4 -4
  21. package/dist/bundle/{chunk-56Q5JV3Z.js → chunk-76EKXFX2.js} +1 -1
  22. package/dist/bundle/{chunk-TFBHDIGY.js → chunk-BNEP5EOV.js} +17 -3
  23. package/dist/bundle/{chunk-V47NPSSV.js → chunk-CEY43D3A.js} +29 -27
  24. package/dist/bundle/{chunk-G7B5UIE7.js → chunk-DKFC5ZZ3.js} +37 -11
  25. package/dist/bundle/{chunk-UGPZCNYC.js → chunk-DSZJREEO.js} +353 -286
  26. package/dist/bundle/{chunk-L5WNE4WS.js → chunk-EPXVRJAX.js} +1 -1
  27. package/dist/bundle/{chunk-66FZBLRJ.js → chunk-EQJ6NLF5.js} +12 -12
  28. package/dist/bundle/{chunk-B2YPB5AE.js → chunk-FHMK6OK4.js} +8 -8
  29. package/dist/bundle/{chunk-3GRX7WP6.js → chunk-G3RT2EQI.js} +1 -1
  30. package/dist/bundle/{chunk-TG6ZYL4B.js → chunk-GI4MTNA2.js} +7 -7
  31. package/dist/bundle/{chunk-AUBRELCM.js → chunk-GIM37COQ.js} +2 -2
  32. package/dist/bundle/{chunk-SQXB5ZUZ.js → chunk-GLRRCKP6.js} +2 -2
  33. package/dist/bundle/{chunk-VMCQGZIA.js → chunk-GXCJ47SJ.js} +381 -292
  34. package/dist/bundle/{chunk-UYK5AXSW.js → chunk-H6S3C3MH.js} +2 -2
  35. package/dist/bundle/{chunk-VRDVXXXD.js → chunk-HJNRIK5X.js} +6 -6
  36. package/dist/bundle/{chunk-HZZGOLGP.js → chunk-I4TI5HDJ.js} +9 -9
  37. package/dist/bundle/{chunk-MP7M6FFU.js → chunk-JLJKGKU2.js} +5 -5
  38. package/dist/bundle/{chunk-F6KBVIJP.js → chunk-JPVFYMSQ.js} +21 -13
  39. package/dist/bundle/{chunk-Z4QKLHJW.js → chunk-JWPSVS6C.js} +8692 -3312
  40. package/dist/bundle/{chunk-ZPILMEFY.js → chunk-JZETEZHC.js} +7 -20
  41. package/dist/bundle/{chunk-EA2PGDER.js → chunk-KEDHX6XG.js} +2 -2
  42. package/dist/bundle/{chunk-PTIB7NEE.js → chunk-MBH7IKLT.js} +1 -1
  43. package/dist/bundle/{chunk-YIXXH74F.js → chunk-MZNOASAW.js} +1 -1
  44. package/dist/bundle/{chunk-GFHNQBD2.js → chunk-NKFTZVQU.js} +1 -1
  45. package/dist/bundle/{chunk-2452HCIV.js → chunk-NMT2VGEI.js} +2 -2
  46. package/dist/bundle/{chunk-KVTLT4V7.js → chunk-OTQDJUES.js} +5 -5
  47. package/dist/bundle/{chunk-Q7O4CQDO.js → chunk-PB252TT3.js} +1 -1
  48. package/dist/bundle/{chunk-V2T7NYNU.js → chunk-PO74BDER.js} +23 -21
  49. package/dist/bundle/{chunk-X3CD475M.js → chunk-PW3HFIJA.js} +203 -155
  50. package/dist/bundle/{chunk-6HRN7BW6.js → chunk-PWCQC56A.js} +1 -1
  51. package/dist/bundle/{chunk-3RJYLN5V.js → chunk-RG2E7ZQZ.js} +117 -14
  52. package/dist/bundle/{chunk-RDH2QBUE.js → chunk-TMTEWOQS.js} +1 -1
  53. package/dist/bundle/{chunk-7NBUT62O.js → chunk-TSTEZNSX.js} +1 -1
  54. package/dist/bundle/{chunk-XW5C4TI7.js → chunk-Y64SI2RO.js} +47 -1
  55. package/dist/bundle/{chunk-FEKXHILZ.js → chunk-YEOSV6JC.js} +1 -1
  56. package/dist/bundle/{chunk-EL6I4WTB.js → chunk-YPRUWRKE.js} +1 -1
  57. package/dist/bundle/{chunk-M7V5XRM6.js → chunk-ZMUC3UQO.js} +2 -2
  58. package/dist/bundle/{chunk-FAHHERJ7.js → chunk-ZXXTJF4Z.js} +4 -4
  59. package/dist/bundle/{command-contract-KMMHARMR.js → command-contract-7GZ6HAA6.js} +12 -12
  60. package/dist/bundle/{decode-YMSOY2AY.js → decode-NMNPLKNR.js} +2 -2
  61. package/dist/bundle/{echarts-7XS55TQY.js → echarts-S46LEIPS.js} +2 -2
  62. package/dist/bundle/{embed-QTOE7NN3.js → embed-I5ZYHGYC.js} +3 -3
  63. package/dist/bundle/{embedder-KBBRYSNH.js → embedder-LTJI67N2.js} +6 -6
  64. package/dist/bundle/{entry-HGEUYYMX.js → entry-O6BUPXF7.js} +4 -4
  65. package/dist/bundle/{first-run-CSGMEJXY.js → first-run-PMZNCDGD.js} +5 -5
  66. package/dist/bundle/{first-screen-K2PBNJNE.js → first-screen-BGML5DSO.js} +13 -13
  67. package/dist/bundle/{instructions-S6ZXCTFH.js → instructions-AUEGY3VO.js} +1 -1
  68. package/dist/bundle/{node-LCIUWXXG.js → node-XRA7RBCQ.js} +2 -2
  69. package/dist/bundle/{node-sqlite-HL4WY4N2.js → node-sqlite-DEZO6LRS.js} +3 -3
  70. package/dist/bundle/{oauth-U4KIMDKG.js → oauth-DAVC7WCD.js} +4 -4
  71. package/dist/bundle/{open-EH7OS7M7.js → open-DE2YO4T7.js} +2 -2
  72. package/dist/bundle/{openai-W5TB3NA5.js → openai-5BKGAULH.js} +10 -10
  73. package/dist/bundle/{process-3CVLTCTA.js → process-4ZHPNUIQ.js} +1 -1
  74. package/dist/bundle/{program-LOIZTK2P.js → program-EGTKSNB4.js} +42 -42
  75. package/dist/bundle/{prompt-IDNH7N3W.js → prompt-HWCWHHPE.js} +2 -2
  76. package/dist/bundle/{recognize-G5EWYXIF.js → recognize-NG6RXNGF.js} +1 -1
  77. package/dist/bundle/{remote-4XTBZVZD.js → remote-ZKXIIGYH.js} +4 -4
  78. package/dist/bundle/{rerank-OWSTDLZN.js → rerank-TX5QFURV.js} +4 -4
  79. package/dist/bundle/{serve-YCPSEWP3.js → serve-XAS6DECW.js} +6 -6
  80. package/dist/bundle/{server-ODG4A2KK.js → server-CNPIWBYU.js} +28 -28
  81. package/dist/bundle/server-FRTKLHZF.js +60 -0
  82. package/dist/bundle/{state-OL2235G5.js → state-3HTUETTS.js} +3 -3
  83. package/dist/bundle/{store-5AACYNDM.js → store-B5VZWJHN.js} +17 -9
  84. package/dist/bundle/store-maintenance-command-VG3CLELA.js +50 -0
  85. package/dist/bundle/tg.js +3 -3
  86. package/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/package.json +2 -2
  89. package/dist/bundle/server-KELKX6S3.js +0 -60
  90. package/dist/bundle/store-maintenance-command-3J7WZYVN.js +0 -50
@@ -3,7 +3,7 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  answerOf,
5
5
  messengerContext
6
- } from "./chunk-V2T7NYNU.js";
6
+ } from "./chunk-PO74BDER.js";
7
7
  import {
8
8
  FETCHING,
9
9
  RULES_VERSION,
@@ -24,13 +24,14 @@ import {
24
24
  typedQuery,
25
25
  withQuery,
26
26
  withTimeLimit
27
- } from "./chunk-UGPZCNYC.js";
27
+ } from "./chunk-DSZJREEO.js";
28
28
  import {
29
29
  QUICK_HEALTH_CHECKS,
30
30
  explainDamage,
31
31
  fts5Tables,
32
+ invalidJson,
32
33
  storeHealth
33
- } from "./chunk-G7B5UIE7.js";
34
+ } from "./chunk-DKFC5ZZ3.js";
34
35
  import {
35
36
  stringWidth,
36
37
  wrapAnsi
@@ -62,23 +63,20 @@ import {
62
63
  snakeKeys,
63
64
  storeTable,
64
65
  withoutProviderRefs
65
- } from "./chunk-X3CD475M.js";
66
- import {
67
- failureKey
68
- } from "./chunk-ZPILMEFY.js";
66
+ } from "./chunk-PW3HFIJA.js";
69
67
  import {
70
68
  envName
71
- } from "./chunk-Q7O4CQDO.js";
69
+ } from "./chunk-PB252TT3.js";
72
70
  import {
73
71
  holdLock,
74
72
  lockPath,
75
73
  releaseLock,
76
74
  servingProfiles,
77
75
  takeLock
78
- } from "./chunk-AUBRELCM.js";
76
+ } from "./chunk-GIM37COQ.js";
79
77
  import {
80
78
  holdersOf
81
- } from "./chunk-EL6I4WTB.js";
79
+ } from "./chunk-YPRUWRKE.js";
82
80
  import {
83
81
  CORPORA,
84
82
  MIGRATIONS,
@@ -114,28 +112,35 @@ import {
114
112
  storeClients,
115
113
  storeContents,
116
114
  vectorIndexCounts
117
- } from "./chunk-Z4QKLHJW.js";
115
+ } from "./chunk-JWPSVS6C.js";
116
+ import {
117
+ queryFieldsOf,
118
+ readDamageMark,
119
+ readHealthMark,
120
+ recordDeepCheck
121
+ } from "./chunk-4BV4UMBB.js";
118
122
  import {
119
- queryFieldsOf
120
- } from "./chunk-C6TUVV7E.js";
123
+ failureKey,
124
+ isStoreDamage
125
+ } from "./chunk-Y64SI2RO.js";
121
126
  import {
122
127
  readSecret
123
- } from "./chunk-SQXB5ZUZ.js";
128
+ } from "./chunk-GLRRCKP6.js";
124
129
  import {
125
130
  checkedOptions,
126
131
  range
127
- } from "./chunk-7NBUT62O.js";
132
+ } from "./chunk-TSTEZNSX.js";
128
133
  import {
129
134
  messagesFor,
130
135
  systemFor,
131
136
  validateImages
132
- } from "./chunk-56Q5JV3Z.js";
137
+ } from "./chunk-76EKXFX2.js";
133
138
  import {
134
139
  storePath
135
- } from "./chunk-3GRX7WP6.js";
140
+ } from "./chunk-G3RT2EQI.js";
136
141
  import {
137
142
  openCache
138
- } from "./chunk-MP7M6FFU.js";
143
+ } from "./chunk-JLJKGKU2.js";
139
144
  import {
140
145
  Credentials,
141
146
  pathsAreOverridden,
@@ -4814,15 +4819,15 @@ var require_liquid_node = __commonJS({
4814
4819
  }
4815
4820
  *render(ctx, emitter) {
4816
4821
  const group = yield evalToken(this.group, ctx);
4817
- const fingerprint2 = `cycle:${group}:` + this.candidates.join(",");
4822
+ const fingerprint = `cycle:${group}:` + this.candidates.join(",");
4818
4823
  const groups = ctx.getRegister("cycle", {});
4819
- let idx = groups[fingerprint2];
4824
+ let idx = groups[fingerprint];
4820
4825
  if (idx === void 0) {
4821
- idx = groups[fingerprint2] = 0;
4826
+ idx = groups[fingerprint] = 0;
4822
4827
  }
4823
4828
  const candidate = this.candidates[idx];
4824
4829
  idx = (idx + 1) % this.candidates.length;
4825
- groups[fingerprint2] = idx;
4830
+ groups[fingerprint] = idx;
4826
4831
  return yield evalToken(candidate, ctx);
4827
4832
  }
4828
4833
  *arguments() {
@@ -5510,11 +5515,11 @@ var require_liquid_node = __commonJS({
5510
5515
  }
5511
5516
  });
5512
5517
 
5513
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5518
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5514
5519
  import { chmodSync, constants, copyFileSync, existsSync as existsSync9, mkdirSync, realpathSync as realpathSync2, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
5515
5520
  import { dirname as dirname2, resolve } from "node:path";
5516
5521
 
5517
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/sealed.js
5522
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/sealed.js
5518
5523
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5519
5524
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5520
5525
  import { Transform } from "node:stream";
@@ -5621,7 +5626,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5621
5626
  renameSync(pending, to);
5622
5627
  }, "unsealFile");
5623
5628
 
5624
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5629
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5625
5630
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5626
5631
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5627
5632
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5645,7 +5650,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5645
5650
  };
5646
5651
  }, "compatibilityOf");
5647
5652
 
5648
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/store/repair.js
5653
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/store/repair.js
5649
5654
  import { createHash as createHash2 } from "node:crypto";
5650
5655
  var COPY_MARK = "__repair_";
5651
5656
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5899,19 +5904,20 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5899
5904
  return found;
5900
5905
  }, "deleteCopy");
5901
5906
 
5902
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5907
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5903
5908
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5904
5909
 
5905
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5910
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5906
5911
  import { existsSync as existsSync3 } from "node:fs";
5907
5912
 
5908
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/store/recover.js
5913
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/store/recover.js
5909
5914
  import { execFileSync, spawn } from "node:child_process";
5910
5915
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5911
5916
  import { basename, dirname, join } from "node:path";
5912
5917
  import { Transform as Transform2 } from "node:stream";
5913
5918
  var SQLITE3_MINIMUM = [3, 43, 0];
5914
5919
  var STORE_PARTS = ["", "-wal", "-shm"];
5920
+ var RECOVER_LOCK = ".recover-lock";
5915
5921
  var INSERTED = /^INSERT OR IGNORE INTO '([^']+)'/;
5916
5922
  var LOST_AND_FOUND = "recover_lost_and_found";
5917
5923
  var recovers = /* @__PURE__ */ __name((program) => {
@@ -5946,11 +5952,55 @@ var activeTimers = /* @__PURE__ */ __name(() => {
5946
5952
  return void 0;
5947
5953
  }
5948
5954
  }, "activeTimers");
5955
+ var alive = /* @__PURE__ */ __name((pid) => {
5956
+ try {
5957
+ process.kill(pid, 0);
5958
+ return true;
5959
+ } catch (error) {
5960
+ return error.code === "EPERM";
5961
+ }
5962
+ }, "alive");
5963
+ var runningRecovery = /* @__PURE__ */ __name((path) => {
5964
+ let pid;
5965
+ try {
5966
+ pid = Number(readFileSync(`${path}${RECOVER_LOCK}`, "utf8").trim());
5967
+ } catch {
5968
+ return null;
5969
+ }
5970
+ return Number.isInteger(pid) && pid > 0 && alive(pid) ? pid : null;
5971
+ }, "runningRecovery");
5972
+ var takeRecoverLock = /* @__PURE__ */ __name((path) => {
5973
+ const lock = `${path}${RECOVER_LOCK}`;
5974
+ const take = /* @__PURE__ */ __name(() => writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 }), "take");
5975
+ try {
5976
+ take();
5977
+ } catch (error) {
5978
+ if (error.code !== "EEXIST")
5979
+ throw error;
5980
+ const pid = runningRecovery(path);
5981
+ if (pid === null) {
5982
+ rmSync2(lock, { force: true });
5983
+ take();
5984
+ } else {
5985
+ throw new CliError("validation_error", `the store is being recovered by process ${pid} \u2014 wait for it to finish`, {
5986
+ reason: "store.recovering"
5987
+ });
5988
+ }
5989
+ }
5990
+ return () => rmSync2(lock, { force: true });
5991
+ }, "takeRecoverLock");
5949
5992
  var storeHolders = /* @__PURE__ */ __name((path) => {
5950
5993
  const folder = realpathSync(dirname(path));
5951
5994
  const files = STORE_PARTS.map((suffix) => join(folder, `${basename(path)}${suffix}`));
5952
5995
  const wanted = process.platform === "linux" ? files.flatMap((file2) => [file2, `${file2} (deleted)`]) : files.filter(existsSync2);
5953
- return holdersOf(wanted)?.map((pid) => {
5996
+ const recovering = runningRecovery(path);
5997
+ const pids = holdersOf(wanted);
5998
+ if (pids === void 0 && recovering === null)
5999
+ return void 0;
6000
+ const all = [
6001
+ .../* @__PURE__ */ new Set([...pids ?? [], ...recovering !== null && recovering !== process.pid ? [recovering] : []])
6002
+ ];
6003
+ return all.map((pid) => {
5954
6004
  let name = "?";
5955
6005
  try {
5956
6006
  name = readFileSync(`/proc/${pid}/comm`, "utf8").trim();
@@ -6112,10 +6162,14 @@ var mailToFetch = /* @__PURE__ */ __name((database) => {
6112
6162
  return [];
6113
6163
  }
6114
6164
  }, "mailToFetch");
6115
- var fingerprint = /* @__PURE__ */ __name((path) => ["", "-wal"].map((suffix) => {
6116
- const stat = statSync2(`${path}${suffix}`, { throwIfNoEntry: false });
6117
- return stat ? `${stat.size}:${stat.mtimeMs}` : "-";
6118
- }).join("|"), "fingerprint");
6165
+ var clearInvalidJson = /* @__PURE__ */ __name((database) => {
6166
+ const found = invalidJson(database);
6167
+ for (const { table, column, required } of found) {
6168
+ const invalid = `"${column}" IS NOT NULL AND NOT json_valid("${column}")`;
6169
+ database.exec(required ? `DELETE FROM "${table}" WHERE ${invalid}` : `UPDATE "${table}" SET "${column}" = NULL WHERE ${invalid}`);
6170
+ }
6171
+ return found;
6172
+ }, "clearInvalidJson");
6119
6173
  var refuseInUse = /* @__PURE__ */ __name((path) => {
6120
6174
  const holders = storeHolders(path);
6121
6175
  if (holders && holders.length > 0) {
@@ -6132,98 +6186,128 @@ var recoverStore = /* @__PURE__ */ __name(async ({ path, command, version, sqlit
6132
6186
  if (!program.usable) {
6133
6187
  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" });
6134
6188
  }
6135
- refuseInUse(path);
6136
- const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
6137
- const { bavail, bsize } = statfsSync(dirname(path));
6138
- if (Number(bavail) * Number(bsize) < bytes * 1.2)
6139
- throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
6140
- const old = await openSqlite(path, { readOnly: true });
6141
- let rowsBefore;
6189
+ const releaseLock2 = takeRecoverLock(path);
6142
6190
  try {
6143
- rowsBefore = tableRows(old.database);
6191
+ refuseInUse(path);
6192
+ const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
6193
+ const { bavail, bsize } = statfsSync(dirname(path));
6194
+ if (Number(bavail) * Number(bsize) < bytes * 1.2)
6195
+ throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
6196
+ return await recoverLocked({ path, command, version, sqlite3, now, note, copy, started, program });
6144
6197
  } finally {
6145
- old.database.close();
6198
+ releaseLock2();
6146
6199
  }
6147
- const before = fingerprint(path);
6148
- const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6149
- const target = `${path}.recovering-${stamp}`;
6150
- writeFileSync(target, "", { flag: "wx", mode: 384 });
6151
- const dropTarget = /* @__PURE__ */ __name(() => {
6152
- for (const suffix of [...STORE_PARTS, "-journal"])
6153
- rmSync2(`${target}${suffix}`, { force: true });
6154
- }, "dropTarget");
6155
- note(`copying the readable rows into ${target}`);
6156
- let copied;
6157
- let copyErrors;
6158
- let read;
6159
- let opened;
6160
- try {
6161
- ;
6162
- ({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
6163
- copied = Date.now();
6164
- opened = await openSqlite(target);
6165
- } catch (error) {
6166
- dropTarget();
6167
- throw error;
6168
- }
6169
- let rebuilt;
6170
- let kept;
6171
- let dangling;
6172
- let fetch2;
6200
+ }, "recoverStore");
6201
+ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqlite3, now, note, copy, started, program }) => {
6202
+ const watch = (await openSqlite(path, { readOnly: true })).database;
6203
+ let watching = true;
6204
+ const stopWatching = /* @__PURE__ */ __name(() => {
6205
+ if (watching)
6206
+ watch.close();
6207
+ watching = false;
6208
+ }, "stopWatching");
6173
6209
  try {
6174
- kept = tableRows(opened.database);
6175
- migrate(opened.database, { command, ...version ? { version } : {} });
6176
- rebuilt = rebuildDerived(opened.database, { now, note });
6177
- note("looking for rows that point at rows that were lost");
6178
- dangling = danglingRows(opened.database);
6179
- fetch2 = mailToFetch(opened.database);
6180
- opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6181
- } catch (error) {
6210
+ const dataVersion = /* @__PURE__ */ __name(() => Number(watch.prepare("PRAGMA data_version").get()?.data_version), "dataVersion");
6211
+ let rowsBefore;
6212
+ try {
6213
+ rowsBefore = tableRows(watch);
6214
+ } catch (error) {
6215
+ if (!isStoreDamage(error))
6216
+ throw error;
6217
+ 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" });
6218
+ }
6219
+ const before = { data: dataVersion(), inode: statSync2(path).ino };
6220
+ const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6221
+ const target = `${path}.recovering-${stamp}`;
6222
+ writeFileSync(target, "", { flag: "wx", mode: 384 });
6223
+ const dropTarget = /* @__PURE__ */ __name(() => {
6224
+ for (const suffix of [...STORE_PARTS, "-journal"])
6225
+ rmSync2(`${target}${suffix}`, { force: true });
6226
+ }, "dropTarget");
6227
+ note(`copying the readable rows into ${target}`);
6228
+ let copied;
6229
+ let copyErrors;
6230
+ let read;
6231
+ let opened;
6232
+ try {
6233
+ ;
6234
+ ({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
6235
+ copied = Date.now();
6236
+ opened = await openSqlite(target);
6237
+ } catch (error) {
6238
+ dropTarget();
6239
+ throw error;
6240
+ }
6241
+ let rebuilt;
6242
+ let kept;
6243
+ let dangling;
6244
+ let json;
6245
+ let fetch2;
6246
+ let schema;
6247
+ try {
6248
+ kept = tableRows(opened.database);
6249
+ migrate(opened.database, { command, ...version ? { version } : {} });
6250
+ note("clearing values that are not valid JSON");
6251
+ json = clearInvalidJson(opened.database);
6252
+ rebuilt = rebuildDerived(opened.database, { now, note });
6253
+ note("looking for rows that point at rows that were lost");
6254
+ dangling = danglingRows(opened.database);
6255
+ fetch2 = mailToFetch(opened.database);
6256
+ schema = fileSchemaOf(opened.database).version;
6257
+ opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6258
+ } catch (error) {
6259
+ opened.database.close();
6260
+ dropTarget();
6261
+ throw error;
6262
+ }
6182
6263
  opened.database.close();
6183
- dropTarget();
6184
- throw error;
6185
- }
6186
- opened.database.close();
6187
- const rebuiltAt = Date.now();
6188
- note("checking the recovered file");
6189
- const health = await storeHealth(target, { deep: true });
6190
- const checkedAt = Date.now();
6191
- if (!health.ok) {
6192
- 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" });
6193
- }
6194
- refuseInUse(path);
6195
- if (fingerprint(path) !== before) {
6196
- 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" });
6264
+ const rebuiltAt = Date.now();
6265
+ note("checking the recovered file");
6266
+ const health = await storeHealth(target, { deep: true });
6267
+ const checkedAt = Date.now();
6268
+ if (!health.ok) {
6269
+ 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" });
6270
+ }
6271
+ refuseInUse(path);
6272
+ const changed = dataVersion() !== before.data || statSync2(path, { throwIfNoEntry: false })?.ino !== before.inode;
6273
+ stopWatching();
6274
+ if (changed) {
6275
+ 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" });
6276
+ }
6277
+ const keptAt = `${path}.before-recover-${stamp}`;
6278
+ for (const suffix of STORE_PARTS)
6279
+ if (existsSync2(`${path}${suffix}`))
6280
+ renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
6281
+ for (const suffix of STORE_PARTS)
6282
+ if (existsSync2(`${target}${suffix}`))
6283
+ renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6284
+ recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema, now });
6285
+ 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);
6286
+ const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6287
+ return {
6288
+ path,
6289
+ keptAt,
6290
+ sqlite3: program.version,
6291
+ lost,
6292
+ dangling,
6293
+ invalidJson: json,
6294
+ mailToFetch: fetch2,
6295
+ rebuilt,
6296
+ copyErrors,
6297
+ health,
6298
+ seconds: {
6299
+ copy: seconds(started, copied),
6300
+ rebuild: seconds(copied, rebuiltAt),
6301
+ check: seconds(rebuiltAt, checkedAt),
6302
+ total: seconds(started, Date.now())
6303
+ }
6304
+ };
6305
+ } finally {
6306
+ stopWatching();
6197
6307
  }
6198
- const keptAt = `${path}.before-recover-${stamp}`;
6199
- for (const suffix of STORE_PARTS)
6200
- if (existsSync2(`${path}${suffix}`))
6201
- renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
6202
- for (const suffix of STORE_PARTS)
6203
- if (existsSync2(`${target}${suffix}`))
6204
- renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6205
- 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);
6206
- const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6207
- return {
6208
- path,
6209
- keptAt,
6210
- sqlite3: program.version,
6211
- lost,
6212
- dangling,
6213
- mailToFetch: fetch2,
6214
- rebuilt,
6215
- copyErrors,
6216
- health,
6217
- seconds: {
6218
- copy: seconds(started, copied),
6219
- rebuild: seconds(copied, rebuiltAt),
6220
- check: seconds(rebuiltAt, checkedAt),
6221
- total: seconds(started, Date.now())
6222
- }
6223
- };
6224
- }, "recoverStore");
6308
+ }, "recoverLocked");
6225
6309
 
6226
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6310
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6227
6311
  var COUNTED = [
6228
6312
  "accounts",
6229
6313
  "chats",
@@ -6238,15 +6322,17 @@ var COUNTED = [
6238
6322
  "mentions"
6239
6323
  ];
6240
6324
  var stopTimers = /* @__PURE__ */ __name((timers) => `systemctl --user stop ${timers.join(" ")}`, "stopTimers");
6241
- var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6325
+ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) => {
6242
6326
  const path = storePath(env);
6243
6327
  if (!existsSync3(path))
6244
6328
  return { path, exists: false, ok: true, next: [] };
6245
6329
  const health = await storeHealth(path, { deep: true });
6246
6330
  let rows = {};
6331
+ let schema = null;
6247
6332
  try {
6248
6333
  const { database } = await openSqlite(path, { readOnly: true });
6249
6334
  try {
6335
+ schema = fileSchemaOf(database).version;
6250
6336
  const all = tableRows(database);
6251
6337
  rows = Object.fromEntries(COUNTED.filter((table) => table in all).map((table) => [table, all[table] ?? null]));
6252
6338
  } finally {
@@ -6254,7 +6340,9 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6254
6340
  }
6255
6341
  } catch {
6256
6342
  }
6257
- const explanation = explainDamage(health, command);
6343
+ recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
6344
+ const mark = readDamageMark(path);
6345
+ const explanation = explainDamage(health, command, mark);
6258
6346
  const inUse = storeHolders(path) ?? null;
6259
6347
  const timers = activeTimers() ?? null;
6260
6348
  const sqlite3 = sqlite3Program();
@@ -6272,8 +6360,11 @@ var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
6272
6360
  problems: health.problems ?? 0,
6273
6361
  damagedTables: health.damagedTables ?? [],
6274
6362
  damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
6363
+ invalidJson: health.invalidJson ?? [],
6275
6364
  rows,
6276
6365
  explanation,
6366
+ damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
6367
+ lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
6277
6368
  inUse,
6278
6369
  timers,
6279
6370
  sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
@@ -6310,6 +6401,7 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6310
6401
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6311
6402
  ...lost.length ? lost : ["no table lost a row"],
6312
6403
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6404
+ ...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
6313
6405
  ...answer.next.map((line) => `next: ${line}`)
6314
6406
  ];
6315
6407
  }
@@ -6320,13 +6412,14 @@ var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6320
6412
  const why = answer.explanation;
6321
6413
  return [
6322
6414
  ...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
6415
+ answer.lastKnownGood ? `the store last passed a deep check at ${answer.lastKnownGood}` : "no deep check that passed is on record for this store",
6323
6416
  ...answer.next.map((line) => `next: ${line}`)
6324
6417
  ];
6325
6418
  }, "recoveryNotes");
6326
6419
  var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6327
6420
  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() {
6328
6421
  const output = outputFor(this);
6329
- const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command);
6422
+ const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command, version);
6330
6423
  renderAnswer(this, output, itemOf(snakeKeys(answer)));
6331
6424
  if (output.format === "pretty")
6332
6425
  for (const line of recoveryNotes(answer))
@@ -6347,7 +6440,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6347
6440
  return recover;
6348
6441
  }, "storeRecoverCommand");
6349
6442
 
6350
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6443
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6351
6444
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6352
6445
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6353
6446
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6393,7 +6486,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6393
6486
  renderAnswer(this, outputFor(this), itemOf(answer));
6394
6487
  }), "storeInfoCommand");
6395
6488
 
6396
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6489
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6397
6490
  var ENCRYPT_OPTION = [
6398
6491
  "--encrypt",
6399
6492
  "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"
@@ -6412,7 +6505,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6412
6505
  return password;
6413
6506
  }, "passwordOf");
6414
6507
 
6415
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/rules.js
6508
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/rules.js
6416
6509
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6417
6510
  import { join as join2 } from "node:path";
6418
6511
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6583,7 +6676,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6583
6676
  }, "problem");
6584
6677
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6585
6678
 
6586
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/state.js
6679
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/state.js
6587
6680
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6588
6681
  import { join as join3 } from "node:path";
6589
6682
  var ANSWERED_KEPT = 1e3;
@@ -6636,7 +6729,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6636
6729
  }, "recordReply");
6637
6730
  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");
6638
6731
 
6639
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/decide.js
6732
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/decide.js
6640
6733
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6641
6734
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6642
6735
  const { message, chat, owner, sender } = incoming;
@@ -6742,7 +6835,7 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6742
6835
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6743
6836
  }, "filled");
6744
6837
 
6745
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/template.js
6838
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/template.js
6746
6839
  var import_liquidjs = __toESM(require_liquid_node(), 1);
6747
6840
  var TEMPLATE_LIMITS = {
6748
6841
  parse: 32768,
@@ -6902,7 +6995,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6902
6995
  }
6903
6996
  }, "renderReplyTemplate");
6904
6997
 
6905
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6998
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6906
6999
  var DRY_RUN_DAYS = 7;
6907
7000
  var PAGE = 500;
6908
7001
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7016,7 +7109,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7016
7109
  }
7017
7110
  }, "storedSince");
7018
7111
 
7019
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
7112
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
7020
7113
  var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
7021
7114
  const host = new URL(baseUrl).host;
7022
7115
  return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
@@ -7047,7 +7140,7 @@ var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) =>
7047
7140
  };
7048
7141
  }, "embeddingKeys");
7049
7142
 
7050
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/models/openai.js
7143
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/models/openai.js
7051
7144
  var options = strictObject({
7052
7145
  temperature: range(0, 2),
7053
7146
  top_p: range(0, 1),
@@ -7096,7 +7189,7 @@ var openai = {
7096
7189
  }), "complete")
7097
7190
  };
7098
7191
 
7099
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/models/index.js
7192
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/models/index.js
7100
7193
  var modelGateway = /* @__PURE__ */ __name((deps) => ({
7101
7194
  complete: /* @__PURE__ */ __name(async (request) => {
7102
7195
  if (deps.signal?.aborted)
@@ -7111,7 +7204,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
7111
7204
  if (!adapter && target.provider === "openai")
7112
7205
  adapter = openai;
7113
7206
  if (!adapter && target.provider === "anthropic")
7114
- adapter = (await import("./anthropic-DFUW2KTG.js")).anthropic;
7207
+ adapter = (await import("./anthropic-NTASPJYE.js")).anthropic;
7115
7208
  if (!adapter)
7116
7209
  throw new CliError("validation_error", `no model adapter for ${target.provider}`);
7117
7210
  if (request.images !== void 0 && adapter.images !== true)
@@ -7152,7 +7245,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
7152
7245
  }, "complete")
7153
7246
  }), "modelGateway");
7154
7247
 
7155
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/consents.js
7248
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/consents.js
7156
7249
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7157
7250
  import { join as join4 } from "node:path";
7158
7251
  var shape = strictObject({
@@ -7177,7 +7270,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7177
7270
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7178
7271
  }, "mayModelReply");
7179
7272
 
7180
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7273
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7181
7274
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options2 = {
7182
7275
  ai: true
7183
7276
  }) => async (rule2, message, chat, now) => {
@@ -7224,7 +7317,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7224
7317
  return result2;
7225
7318
  }, "replyRenderer");
7226
7319
 
7227
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/replies/serve.js
7320
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/replies/serve.js
7228
7321
  var NOT_ALLOWED = "replies.send is not allow";
7229
7322
  var NO_RULES = "no rules";
7230
7323
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7317,7 +7410,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7317
7410
  return { skip: why };
7318
7411
  }, "replyTo");
7319
7412
 
7320
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7413
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7321
7414
  var START_SYNC_DELAY_MS = 3e4;
7322
7415
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7323
7416
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7394,7 +7487,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
7394
7487
  };
7395
7488
  }, "startSync");
7396
7489
 
7397
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7490
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7398
7491
  var FIRST_FETCH_MS = 6e4;
7399
7492
  var DAY_MS = 864e5;
7400
7493
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7448,7 +7541,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
7448
7541
  };
7449
7542
  }, "memberFetches");
7450
7543
 
7451
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7544
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7452
7545
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7453
7546
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7454
7547
  if (context.format === "pretty") {
@@ -7481,7 +7574,7 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7481
7574
  return context;
7482
7575
  }, "recordDiagnostics");
7483
7576
 
7484
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7577
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7485
7578
  var STEMS_EVERY_MS = 3e4;
7486
7579
  var STEMS_SLICE_MS = 2e3;
7487
7580
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7521,7 +7614,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7521
7614
  };
7522
7615
  }, "stemFills");
7523
7616
 
7524
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/render/messages.js
7617
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/render/messages.js
7525
7618
  import { styleText } from "node:util";
7526
7619
  var TIME_WIDTH = 8;
7527
7620
  var INDENT = " ".repeat(TIME_WIDTH + 2);
@@ -7697,7 +7790,7 @@ var editedAt = /* @__PURE__ */ __name((message, options2) => {
7697
7790
  return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
7698
7791
  }, "editedAt");
7699
7792
 
7700
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7793
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7701
7794
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7702
7795
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7703
7796
  kind: attachment.kind,
@@ -7792,7 +7885,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7792
7885
  locale: messenger.app.locale
7793
7886
  }), "viewOf");
7794
7887
 
7795
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7888
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7796
7889
  var observed = /* @__PURE__ */ __name((value) => ({
7797
7890
  value: value.value,
7798
7891
  observed_at: value.observedAt,
@@ -7859,7 +7952,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7859
7952
  }
7860
7953
  }, "watchEventItem");
7861
7954
 
7862
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7955
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7863
7956
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7864
7957
  output: { entity: "watch_item" },
7865
7958
  effects: REMOTE_READ,
@@ -8014,7 +8107,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
8014
8107
  }
8015
8108
  }, "describe");
8016
8109
 
8017
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8110
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8018
8111
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
8019
8112
  const command = annotate(new Command("serve"), {
8020
8113
  output: { entity: "serve_summary" },
@@ -8278,7 +8371,7 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8278
8371
  };
8279
8372
  }, "tasking");
8280
8373
 
8281
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8374
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8282
8375
  import { existsSync as existsSync8 } from "node:fs";
8283
8376
  var PATH = "store tables list";
8284
8377
  var STORE_TABLES_QUERY = {
@@ -8321,7 +8414,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8321
8414
  return tables;
8322
8415
  }, "storeTablesCommand");
8323
8416
 
8324
- // node_modules/.pnpm/@wirecat+cli-core@0.600.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._6a3165a3e9bffd3483d86046d9ef2956/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8417
+ // node_modules/.pnpm/@wirecat+cli-core@0.608.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.80.8_commander@15._981e87e6afb3f510e9b2b59ded3c7286/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8325
8418
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8326
8419
  var WORD_INDEX = "message_words";
8327
8420
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8347,11 +8440,26 @@ var readingOnly = /* @__PURE__ */ __name(async (path, read) => {
8347
8440
  database.close();
8348
8441
  }
8349
8442
  }, "readingOnly");
8350
- var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command } = {}) => {
8443
+ var withoutInode = /* @__PURE__ */ __name(({ inode: _, ...mark }) => mark, "withoutInode");
8444
+ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8445
+ try {
8446
+ return await readingOnly(path, (database) => fileSchemaOf(database).version);
8447
+ } catch {
8448
+ return null;
8449
+ }
8450
+ }, "fileSchema");
8451
+ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8351
8452
  const path = storePath(env);
8352
8453
  if (!existsSync9(path))
8353
8454
  return { path, exists: false };
8354
8455
  const checked = await storeHealth(path, { deep });
8456
+ const recorded = deep ? recordDeepCheck(path, checked, {
8457
+ cli: command ?? "unknown",
8458
+ ...version ? { version } : {},
8459
+ schema: await fileSchema(path)
8460
+ }) : null;
8461
+ const mark = readDamageMark(path);
8462
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
8355
8463
  const health = {
8356
8464
  checked: checked.checked,
8357
8465
  covers: deep ? "every page and every search index" : QUICK_HEALTH_CHECKS,
@@ -8359,20 +8467,27 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command }
8359
8467
  ms: checked.ms,
8360
8468
  ...checked.problems ? { problems: checked.problems } : {},
8361
8469
  ...checked.damagedTables?.length ? { damagedTables: checked.damagedTables } : {},
8470
+ ...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
8362
8471
  ...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
8363
8472
  };
8364
- const damage = command ? explainDamage(checked, command) : null;
8365
- const healthOf = { health, ...damage ? { damage } : {} };
8473
+ const damage = command ? explainDamage(checked, command, mark) : null;
8474
+ const healthOf = {
8475
+ health,
8476
+ lastKnownGood,
8477
+ ...mark ? { damageMark: withoutInode(mark) } : {},
8478
+ ...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
8479
+ ...damage ? { damage } : {}
8480
+ };
8366
8481
  try {
8367
8482
  return await reading(path, (database) => {
8368
- const { version, writable } = schemaOf(database);
8483
+ const { version: version2, writable } = schemaOf(database);
8369
8484
  return {
8370
8485
  path,
8371
8486
  exists: true,
8372
- schema: version,
8487
+ schema: version2,
8373
8488
  speaks: SPEAKS,
8374
8489
  writable,
8375
- ...version > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
8490
+ ...version2 > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
8376
8491
  ...healthOf
8377
8492
  };
8378
8493
  });