@wirecat/tg-cli 0.116.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 (125) hide show
  1. package/dist/bin/tg.js +2 -2
  2. package/dist/bot/transport.d.ts +1 -1
  3. package/dist/bot/transport.d.ts.map +1 -1
  4. package/dist/bot/transport.js +42 -30
  5. package/dist/bot/transport.js.map +1 -1
  6. package/dist/bundle/{adapter-6CLMTQOV.js → adapter-4YNP6VCO.js} +70 -61
  7. package/dist/bundle/{all-profiles-R2UZMH24.js → all-profiles-MIQDYAGO.js} +10 -10
  8. package/dist/bundle/{anthropic-QKIPHV2Z.js → anthropic-NTASPJYE.js} +6 -6
  9. package/dist/bundle/{app-server-AZB2MFK6.js → app-server-UJZBJ2SK.js} +49 -46
  10. package/dist/bundle/{bot-api-2IM243J4.js → bot-api-JZAD4L3N.js} +49 -49
  11. package/dist/bundle/{bot-history-G6CRVCL2.js → bot-history-OUDHH3NU.js} +18 -18
  12. package/dist/bundle/{bun-JDKPISPX.js → bun-EC4HDIRD.js} +2 -2
  13. package/dist/bundle/{bun-sqlite-X5PY5IQT.js → bun-sqlite-A4HJR6KO.js} +5 -5
  14. package/dist/bundle/{chunk-SD5PUYKF.js → chunk-2KQHUBTV.js} +12 -12
  15. package/dist/bundle/{chunk-QHBVGKC3.js → chunk-2NA5KVP6.js} +210 -82
  16. package/dist/bundle/{chunk-PPLFOIYX.js → chunk-3MQOLYAN.js} +4 -4
  17. package/dist/bundle/{chunk-QGL2UGML.js → chunk-4BV4UMBB.js} +738 -235
  18. package/dist/bundle/{chunk-Y6VWGJ4Q.js → chunk-57LKX6N2.js} +4 -2
  19. package/dist/bundle/{chunk-BGMV66FC.js → chunk-5IIU7X4S.js} +1 -1
  20. package/dist/bundle/{chunk-H72UEHNG.js → chunk-5LDWBEWU.js} +55 -33
  21. package/dist/bundle/{chunk-XQUTJITP.js → chunk-5QYU7B27.js} +763 -130
  22. package/dist/bundle/chunk-65XV5PPI.js +64 -0
  23. package/dist/bundle/{chunk-NUYRMU56.js → chunk-6AXUEJGL.js} +2 -2
  24. package/dist/bundle/{chunk-N42VUNTO.js → chunk-6RI4TEIC.js} +2 -2
  25. package/dist/bundle/{chunk-VQPLHOVQ.js → chunk-6ZMTEUVU.js} +6 -6
  26. package/dist/bundle/{chunk-MQ7MCVZV.js → chunk-76EKXFX2.js} +2 -2
  27. package/dist/bundle/{chunk-K62YATVD.js → chunk-BNEP5EOV.js} +18 -4
  28. package/dist/bundle/{chunk-EB2IULWB.js → chunk-BXTDAGM4.js} +2 -2
  29. package/dist/bundle/{chunk-HBUJNNZD.js → chunk-CEY43D3A.js} +31 -29
  30. package/dist/bundle/chunk-DKFC5ZZ3.js +208 -0
  31. package/dist/bundle/{chunk-FDI4GOIP.js → chunk-DSZJREEO.js} +463 -358
  32. package/dist/bundle/{chunk-76CX2YPT.js → chunk-EPCFXKTX.js} +8 -8
  33. package/dist/bundle/{chunk-KA6EGOJY.js → chunk-EPXVRJAX.js} +2 -2
  34. package/dist/bundle/{chunk-4IQZRW4O.js → chunk-EQJ6NLF5.js} +13 -13
  35. package/dist/bundle/{chunk-4D5AUWAY.js → chunk-FHMK6OK4.js} +43 -25
  36. package/dist/bundle/{chunk-RSDIPQXP.js → chunk-G3RT2EQI.js} +2 -2
  37. package/dist/bundle/{chunk-IR4S7POE.js → chunk-GI4MTNA2.js} +8 -8
  38. package/dist/bundle/{chunk-HK6SIIGG.js → chunk-GIM37COQ.js} +3 -3
  39. package/dist/bundle/{chunk-UCSFO5GW.js → chunk-GLRRCKP6.js} +3 -3
  40. package/dist/bundle/{chunk-YYKJN6H5.js → chunk-GXCJ47SJ.js} +1499 -710
  41. package/dist/bundle/{chunk-GV7ZJ33M.js → chunk-H6S3C3MH.js} +4 -4
  42. package/dist/bundle/{chunk-LXH3SKY3.js → chunk-HJNRIK5X.js} +8 -8
  43. package/dist/bundle/{chunk-5VFPUOJO.js → chunk-I4TI5HDJ.js} +11 -11
  44. package/dist/bundle/{chunk-RSNGMNU5.js → chunk-JLJKGKU2.js} +6 -6
  45. package/dist/bundle/{chunk-T7CDLV33.js → chunk-JPVFYMSQ.js} +22 -14
  46. package/dist/bundle/{chunk-B4UOCWM4.js → chunk-JWIUK3SK.js} +2 -2
  47. package/dist/bundle/{chunk-LSKGCJWD.js → chunk-JWPSVS6C.js} +21246 -4044
  48. package/dist/bundle/{chunk-JJMQA272.js → chunk-JZETEZHC.js} +8 -21
  49. package/dist/bundle/{chunk-42GK3XRS.js → chunk-KEDHX6XG.js} +2 -2
  50. package/dist/bundle/{chunk-QAKL3GXB.js → chunk-MBH7IKLT.js} +1 -1
  51. package/dist/bundle/{chunk-HLNYJPAB.js → chunk-MZNOASAW.js} +2 -2
  52. package/dist/bundle/{chunk-YLRTLZF6.js → chunk-NKFTZVQU.js} +1 -1
  53. package/dist/bundle/{chunk-577MFPCP.js → chunk-NMT2VGEI.js} +3 -3
  54. package/dist/bundle/{chunk-5ZIBAYIZ.js → chunk-NUCDEOFC.js} +2 -2
  55. package/dist/bundle/{chunk-NL3PAFAE.js → chunk-OTQDJUES.js} +6 -6
  56. package/dist/bundle/{chunk-KV4267S4.js → chunk-P3ASN72F.js} +1 -1
  57. package/dist/bundle/{chunk-TZVL4U7U.js → chunk-PB252TT3.js} +4 -2
  58. package/dist/bundle/{chunk-HUOXUI2M.js → chunk-PO74BDER.js} +58 -47
  59. package/dist/bundle/{chunk-LFKEKSI5.js → chunk-PW3HFIJA.js} +523 -239
  60. package/dist/bundle/{chunk-5FCONCJO.js → chunk-PWCQC56A.js} +1 -1
  61. package/dist/bundle/{chunk-XBIPSSKI.js → chunk-QOGYHU3Q.js} +4 -4
  62. package/dist/bundle/{chunk-JFTCOV37.js → chunk-RG2E7ZQZ.js} +180 -25
  63. package/dist/bundle/{chunk-R52RMHWF.js → chunk-TMTEWOQS.js} +3 -3
  64. package/dist/bundle/{chunk-I6JF43YP.js → chunk-TSTEZNSX.js} +3 -3
  65. package/dist/bundle/{chunk-YPF6OS37.js → chunk-VW6BF6M7.js} +1 -1
  66. package/dist/bundle/{chunk-SKZ2E3WC.js → chunk-Y64SI2RO.js} +47 -1
  67. package/dist/bundle/{chunk-DP5LRU7K.js → chunk-YEOSV6JC.js} +1 -1
  68. package/dist/bundle/{chunk-OX6EWGSG.js → chunk-YHZFGUAP.js} +19 -19
  69. package/dist/bundle/{chunk-N6TIFJHW.js → chunk-YPRUWRKE.js} +1 -1
  70. package/dist/bundle/{chunk-PPSUA3IZ.js → chunk-ZMUC3UQO.js} +3 -3
  71. package/dist/bundle/{chunk-PXMHBTK3.js → chunk-ZXXTJF4Z.js} +4 -4
  72. package/dist/bundle/command-contract-7GZ6HAA6.js +33 -0
  73. package/dist/bundle/{decode-W6YPTGJA.js → decode-NMNPLKNR.js} +5 -5
  74. package/dist/bundle/{dispatch-H7EFNBEH.js → dispatch-OP27MWX5.js} +8 -8
  75. package/dist/bundle/{echarts-YAWDIC5D.js → echarts-S46LEIPS.js} +2 -2
  76. package/dist/bundle/{embed-EN4UTLV5.js → embed-I5ZYHGYC.js} +6 -6
  77. package/dist/bundle/{embedder-HEKHRL7E.js → embedder-LTJI67N2.js} +9 -9
  78. package/dist/bundle/{entry-2KB6MTCG.js → entry-O6BUPXF7.js} +7 -7
  79. package/dist/bundle/{failure-3DU3HLBQ.js → failure-4JUQFXJT.js} +2 -2
  80. package/dist/bundle/{first-run-LBG26WWO.js → first-run-PMZNCDGD.js} +11 -11
  81. package/dist/bundle/first-screen-BGML5DSO.js +31 -0
  82. package/dist/bundle/{instructions-HA62QNPR.js → instructions-AUEGY3VO.js} +1 -1
  83. package/dist/bundle/{mcp-PPVOM4SE.js → mcp-M4QN2E7R.js} +2 -2
  84. package/dist/bundle/{node-MZ2VWSQQ.js → node-XRA7RBCQ.js} +2 -2
  85. package/dist/bundle/{node-sqlite-KNNS6DCM.js → node-sqlite-DEZO6LRS.js} +6 -6
  86. package/dist/bundle/{oauth-KWUABBSQ.js → oauth-DAVC7WCD.js} +7 -7
  87. package/dist/bundle/{open-JXMCYCIV.js → open-DE2YO4T7.js} +5 -5
  88. package/dist/bundle/{openai-HL3IR4VT.js → openai-5BKGAULH.js} +14 -14
  89. package/dist/bundle/{process-K2FICLWY.js → process-4ZHPNUIQ.js} +1 -1
  90. package/dist/bundle/{program-IFOMT4JS.js → program-EGTKSNB4.js} +51 -51
  91. package/dist/bundle/{prompt-HVD3Q77P.js → prompt-HWCWHHPE.js} +5 -5
  92. package/dist/bundle/{proxy-transport-PA5SGMRY.js → proxy-transport-4DPZB2W2.js} +5 -5
  93. package/dist/bundle/{recognize-HHLVETKI.js → recognize-NG6RXNGF.js} +4 -4
  94. package/dist/bundle/{remote-HUAKXJCS.js → remote-ZKXIIGYH.js} +7 -7
  95. package/dist/bundle/{rerank-NWFIV7OF.js → rerank-TX5QFURV.js} +7 -7
  96. package/dist/bundle/{serve-ANUKAJJN.js → serve-XAS6DECW.js} +9 -9
  97. package/dist/bundle/{server-7Q7WAOHO.js → server-CNPIWBYU.js} +35 -35
  98. package/dist/bundle/server-FRTKLHZF.js +60 -0
  99. package/dist/bundle/{state-Y2AJ5XTP.js → state-3HTUETTS.js} +6 -6
  100. package/dist/bundle/{store-S3IG5KWL.js → store-B5VZWJHN.js} +23 -13
  101. package/dist/bundle/store-maintenance-command-VG3CLELA.js +50 -0
  102. package/dist/bundle/tg.js +13 -13
  103. package/dist/telegram/account.d.ts.map +1 -1
  104. package/dist/telegram/account.js +4 -1
  105. package/dist/telegram/account.js.map +1 -1
  106. package/dist/telegram/errors.d.ts.map +1 -1
  107. package/dist/telegram/errors.js +2 -1
  108. package/dist/telegram/errors.js.map +1 -1
  109. package/dist/telegram/feature.d.ts +4 -1
  110. package/dist/telegram/feature.d.ts.map +1 -1
  111. package/dist/telegram/feature.js +5 -2
  112. package/dist/telegram/feature.js.map +1 -1
  113. package/dist/telegram/sending.d.ts.map +1 -1
  114. package/dist/telegram/sending.js +24 -10
  115. package/dist/telegram/sending.js.map +1 -1
  116. package/dist/version.d.ts +1 -1
  117. package/dist/version.js +1 -1
  118. package/package.json +3 -3
  119. package/dist/bundle/chunk-K2RYCCTP.js +0 -48
  120. package/dist/bundle/chunk-ZDIAPICE.js +0 -132
  121. package/dist/bundle/command-contract-DPXM4SZT.js +0 -33
  122. package/dist/bundle/first-screen-TGTSLUI6.js +0 -31
  123. package/dist/bundle/server-HCQS4YDQ.js +0 -60
  124. package/dist/bundle/store-maintenance-command-V2WC4G6J.js +0 -50
  125. /package/dist/bundle/{chunk-LU3WKZBA.js → chunk-VOXIGICJ.js} +0 -0
@@ -0,0 +1,64 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ count,
5
+ id,
6
+ text,
7
+ time
8
+ } from "./chunk-4BV4UMBB.js";
9
+ import {
10
+ array,
11
+ nullable,
12
+ optional,
13
+ picklist,
14
+ record,
15
+ reference,
16
+ strictObject,
17
+ string,
18
+ unknown
19
+ } from "./chunk-EPCFXKTX.js";
20
+
21
+ // 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/entities/note.js
22
+ var link = {
23
+ target_text: nullable(text),
24
+ kind: text,
25
+ anchor: nullable(text)
26
+ };
27
+ var note = strictObject({
28
+ ref: reference,
29
+ kind: optional(picklist(["note", "document"])),
30
+ provider: optional(text),
31
+ account: optional(text),
32
+ url: optional(text),
33
+ id,
34
+ source: picklist(["file", "internal"]),
35
+ folder_id: nullable(id),
36
+ path: nullable(text),
37
+ title: nullable(text),
38
+ text,
39
+ /** Raises on every edit; `notes edit --revision` takes it, so an edit made meanwhile is refused, not lost. */
40
+ revision: count,
41
+ /** A file's front matter as parsed, keys as the file writes them; null for a note without it. */
42
+ front_matter: nullable(record(string(), unknown())),
43
+ /** The hash of a file's bytes when last imported; null for a note written here. */
44
+ content_hash: nullable(text),
45
+ /** The file the note was exported to, where that is known; null otherwise. */
46
+ export_path: nullable(text),
47
+ created_at: time,
48
+ /** When the store's copy last changed. */
49
+ updated_at: time,
50
+ deleted_at: optional(nullable(time)),
51
+ tags: optional(array(text)),
52
+ /** The first line holding a word of a search. */
53
+ excerpt: optional(text),
54
+ /** Which halves of a search found it. */
55
+ found_by: optional(array(picklist(["title", "words", "meaning"]))),
56
+ /** What the note links to; `to` is null while the name written matches nothing stored. */
57
+ links: optional(array(strictObject({ to: nullable(reference), ...link }))),
58
+ /** The notes and messages that link to it. */
59
+ backlinks: optional(array(strictObject({ from: reference, ...link })))
60
+ });
61
+
62
+ export {
63
+ note
64
+ };
@@ -2,12 +2,12 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  CliError
5
- } from "./chunk-EB2IULWB.js";
5
+ } from "./chunk-BXTDAGM4.js";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-ZVVMGPBJ.js";
9
9
 
10
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/cli/input-policy.js
10
+ // 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/input-policy.js
11
11
  var MAX_BUFFERED_INPUT = 16 * 1024 * 1024;
12
12
  var MAX_SECRET_INPUT = 64 * 1024;
13
13
  var policies = /* @__PURE__ */ new WeakMap();
@@ -8,12 +8,12 @@ import {
8
8
  ACCESS_SECONDS,
9
9
  REFRESH_SECONDS,
10
10
  readStored
11
- } from "./chunk-PXMHBTK3.js";
11
+ } from "./chunk-ZXXTJF4Z.js";
12
12
  import {
13
13
  __name
14
14
  } from "./chunk-ZVVMGPBJ.js";
15
15
 
16
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/http/oauth.js
16
+ // 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/mcp/http/oauth.js
17
17
  import { createHash, randomBytes, randomInt, timingSafeEqual } from "node:crypto";
18
18
  import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
19
19
  import { dirname } from "node:path";
@@ -2,23 +2,23 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  storePath
5
- } from "./chunk-RSDIPQXP.js";
5
+ } from "./chunk-G3RT2EQI.js";
6
6
  import {
7
7
  resolvePaths
8
- } from "./chunk-OX6EWGSG.js";
8
+ } from "./chunk-YHZFGUAP.js";
9
9
  import {
10
10
  CliError,
11
11
  singleLine
12
- } from "./chunk-EB2IULWB.js";
12
+ } from "./chunk-BXTDAGM4.js";
13
13
  import {
14
14
  __name
15
15
  } from "./chunk-ZVVMGPBJ.js";
16
16
 
17
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/store/shared-config.js
17
+ // 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/shared-config.js
18
18
  import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
19
19
  import { dirname, join, resolve } from "node:path";
20
20
 
21
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/domain/task-categories.js
21
+ // 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/domain/task-categories.js
22
22
  var DEFAULT_TASK_CATEGORIES = [
23
23
  {
24
24
  name: "taxes",
@@ -773,7 +773,7 @@ var storedTaskCategories = /* @__PURE__ */ __name((json) => {
773
773
  }
774
774
  }, "storedTaskCategories");
775
775
 
776
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/store/shared-config.js
776
+ // 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/shared-config.js
777
777
  var SECTION = "task_categories";
778
778
  var sharedConfigPath = /* @__PURE__ */ __name((store, env = process.env) => {
779
779
  const paths = resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env });
@@ -2,12 +2,12 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  CliError
5
- } from "./chunk-EB2IULWB.js";
5
+ } from "./chunk-BXTDAGM4.js";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-ZVVMGPBJ.js";
9
9
 
10
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/models/types.js
10
+ // 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/types.js
11
11
  var MAX_MODEL_IMAGE_BYTES = 4 * 1024 * 1024;
12
12
  var validateImages = /* @__PURE__ */ __name((images) => {
13
13
  if (images === void 0)
@@ -5,15 +5,15 @@ import {
5
5
  } from "./chunk-Y5E2WNWB.js";
6
6
  import {
7
7
  CliError
8
- } from "./chunk-EB2IULWB.js";
8
+ } from "./chunk-BXTDAGM4.js";
9
9
  import {
10
10
  __name
11
11
  } from "./chunk-ZVVMGPBJ.js";
12
12
 
13
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/speech/recognize.js
13
+ // 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/speech/recognize.js
14
14
  import { createRequire } from "node:module";
15
15
 
16
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/speech/ogg-limit.js
16
+ // 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/speech/ogg-limit.js
17
17
  var invalid = /* @__PURE__ */ __name(() => new CliError("validation_error", "local transcription needs a complete mono or stereo Ogg Opus recording"), "invalid");
18
18
  var checkOggDuration = /* @__PURE__ */ __name((bytes) => {
19
19
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -70,7 +70,7 @@ var checkOggDuration = /* @__PURE__ */ __name((bytes) => {
70
70
  throw invalid();
71
71
  }, "checkOggDuration");
72
72
 
73
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/speech/recognize.js
73
+ // 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/speech/recognize.js
74
74
  var SAMPLE_RATE = 16e3;
75
75
  var LEAD = SAMPLE_RATE / 2;
76
76
  var toModelRate = /* @__PURE__ */ __name((samples, rate) => {
@@ -195,9 +195,23 @@ var openRecognizer = /* @__PURE__ */ __name((model, path, vadModel) => {
195
195
  });
196
196
  return heard;
197
197
  }, "pieces");
198
+ const piecesUntil = /* @__PURE__ */ __name(async (pcm, signal) => {
199
+ const spans = [];
200
+ cut(vad, pcm, (span) => spans.push(span));
201
+ const heard = [];
202
+ for (const { start, end, samples } of spans) {
203
+ await new Promise((resolve) => setImmediate(resolve));
204
+ signal.throwIfAborted();
205
+ const text = piece(samples);
206
+ if (text)
207
+ heard.push({ start, end, text });
208
+ }
209
+ return heard;
210
+ }, "piecesUntil");
198
211
  return {
199
212
  recognize: /* @__PURE__ */ __name((pcm) => pieces(pcm).map(({ text }) => text).join(" "), "recognize"),
200
213
  pieces,
214
+ piecesUntil,
201
215
  free: /* @__PURE__ */ __name(() => {
202
216
  vad.free();
203
217
  engine.free();
@@ -4,7 +4,7 @@ import {
4
4
  __name
5
5
  } from "./chunk-ZVVMGPBJ.js";
6
6
 
7
- // node_modules/.pnpm/@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/errors.js
7
+ // node_modules/.pnpm/@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/errors.js
8
8
  var errorCodes = [
9
9
  "validation_error",
10
10
  "configuration_error",
@@ -39,7 +39,7 @@ var CliError = class extends Error {
39
39
  };
40
40
  var isCliError = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && value[BRAND] === true, "isCliError");
41
41
 
42
- // node_modules/.pnpm/@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/sanitize.js
42
+ // node_modules/.pnpm/@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/sanitize.js
43
43
  var CONTROL = (
44
44
  // biome-ignore lint/suspicious/noControlCharactersInRegex: matching them is the whole point
45
45
  /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u200B\u200E\u200F\u202A-\u202E\u2066-\u2069\uFEFF\u{E0000}-\u{E007F}]/gu
@@ -20,7 +20,7 @@ import {
20
20
  tool,
21
21
  toolKey,
22
22
  toolsFromCommands
23
- } from "./chunk-QHBVGKC3.js";
23
+ } from "./chunk-2NA5KVP6.js";
24
24
  import {
25
25
  CHART_KINDS,
26
26
  CHART_SIZE,
@@ -34,23 +34,23 @@ import {
34
34
  registerPrompts,
35
35
  stdinFieldOf,
36
36
  syncsFirst
37
- } from "./chunk-H72UEHNG.js";
37
+ } from "./chunk-5LDWBEWU.js";
38
38
  import {
39
39
  agentJson,
40
40
  skillResource
41
- } from "./chunk-JFTCOV37.js";
41
+ } from "./chunk-RG2E7ZQZ.js";
42
42
  import {
43
43
  instructions
44
- } from "./chunk-YLRTLZF6.js";
44
+ } from "./chunk-NKFTZVQU.js";
45
45
  import {
46
46
  answeredWire
47
- } from "./chunk-QAKL3GXB.js";
47
+ } from "./chunk-MBH7IKLT.js";
48
48
  import {
49
49
  StdioServerTransport,
50
50
  callerOf,
51
51
  callingAgent,
52
52
  serveStdio
53
- } from "./chunk-42GK3XRS.js";
53
+ } from "./chunk-KEDHX6XG.js";
54
54
  import {
55
55
  McpServer,
56
56
  ResourceTemplate
@@ -58,7 +58,7 @@ import {
58
58
  import {
59
59
  connectedFor,
60
60
  guardFor
61
- } from "./chunk-HUOXUI2M.js";
61
+ } from "./chunk-PO74BDER.js";
62
62
  import {
63
63
  capability,
64
64
  dateWindow,
@@ -67,10 +67,10 @@ import {
67
67
  servicesFor,
68
68
  storedDeps,
69
69
  wholeList
70
- } from "./chunk-FDI4GOIP.js";
70
+ } from "./chunk-DSZJREEO.js";
71
71
  import {
72
72
  findCommand
73
- } from "./chunk-GV7ZJ33M.js";
73
+ } from "./chunk-H6S3C3MH.js";
74
74
  import {
75
75
  DEFAULT_OUTPUT_BYTES,
76
76
  changesAuthorityAt,
@@ -86,27 +86,29 @@ import {
86
86
  sealed,
87
87
  snakeKeys,
88
88
  typedCommand
89
- } from "./chunk-LFKEKSI5.js";
89
+ } from "./chunk-PW3HFIJA.js";
90
90
  import {
91
- isCliFailure,
92
91
  withCaller
93
- } from "./chunk-JJMQA272.js";
92
+ } from "./chunk-JZETEZHC.js";
94
93
  import {
95
94
  readOnlyLockOf
96
- } from "./chunk-TZVL4U7U.js";
95
+ } from "./chunk-PB252TT3.js";
97
96
  import {
98
97
  mcpHttpMarker
99
- } from "./chunk-PXMHBTK3.js";
98
+ } from "./chunk-ZXXTJF4Z.js";
100
99
  import {
101
100
  openStore,
102
101
  pdfPreviewLimits
103
- } from "./chunk-LSKGCJWD.js";
102
+ } from "./chunk-JWPSVS6C.js";
104
103
  import {
105
104
  timezoneOf
106
- } from "./chunk-QGL2UGML.js";
105
+ } from "./chunk-4BV4UMBB.js";
106
+ import {
107
+ isCliFailure
108
+ } from "./chunk-Y64SI2RO.js";
107
109
  import {
108
110
  warmEmbedders
109
- } from "./chunk-NL3PAFAE.js";
111
+ } from "./chunk-OTQDJUES.js";
110
112
  import {
111
113
  description,
112
114
  integer,
@@ -122,19 +124,19 @@ import {
122
124
  regex,
123
125
  strictObject,
124
126
  string
125
- } from "./chunk-76CX2YPT.js";
127
+ } from "./chunk-EPCFXKTX.js";
126
128
  import {
127
129
  CliError,
128
130
  visibleControls
129
- } from "./chunk-EB2IULWB.js";
131
+ } from "./chunk-BXTDAGM4.js";
130
132
  import {
131
133
  __name
132
134
  } from "./chunk-ZVVMGPBJ.js";
133
135
 
134
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/server.js
136
+ // 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/mcp/server.js
135
137
  import { randomUUID } from "node:crypto";
136
138
 
137
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/agent-log.js
139
+ // 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/mcp/agent-log.js
138
140
  var agentLog = /* @__PURE__ */ __name((open) => {
139
141
  let held;
140
142
  return {
@@ -153,7 +155,7 @@ var agentLog = /* @__PURE__ */ __name((open) => {
153
155
  };
154
156
  }, "agentLog");
155
157
 
156
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/resources.js
158
+ // 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/mcp/resources.js
157
159
  var LISTED = 100;
158
160
  var registerResources = /* @__PURE__ */ __name((server, session, { command, name, limit, recorded, withStore, messenger, guard, assertRead }) => {
159
161
  server.registerResource("chat", new ResourceTemplate(`${command}://chat/{id}`, {
@@ -191,7 +193,7 @@ var registerResources = /* @__PURE__ */ __name((server, session, { command, name
191
193
  });
192
194
  }, "registerResources");
193
195
 
194
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/session.js
196
+ // 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/mcp/session.js
195
197
  var HARMLESS = /* @__PURE__ */ new Set(["validation_error", "not_found", "permission_error", "confirmation_required", "rate_limited"]);
196
198
  var harmless = /* @__PURE__ */ __name((code) => HARMLESS.has(code), "harmless");
197
199
  var MessengerSession = class {
@@ -266,7 +268,7 @@ var MessengerSession = class {
266
268
  }
267
269
  };
268
270
 
269
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/tools/attachments.js
271
+ // 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/mcp/tools/attachments.js
270
272
  var attachmentsTools = /* @__PURE__ */ __name((messenger) => {
271
273
  const _command = messenger.app.command;
272
274
  return {
@@ -320,7 +322,7 @@ var attachmentsTools = /* @__PURE__ */ __name((messenger) => {
320
322
  };
321
323
  }, "attachmentsTools");
322
324
 
323
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/tools/messages-photo.js
325
+ // 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/mcp/tools/messages-photo.js
324
326
  var PHOTO_LIMIT = 512 * 1024;
325
327
  var IMAGE_TYPES = [
326
328
  ["image/jpeg", (b) => b[0] === 255 && b[1] === 216 && b[2] === 255],
@@ -374,7 +376,7 @@ var readUpTo = /* @__PURE__ */ __name(async (file, limit, saveIt) => {
374
376
  return new Uint8Array(Buffer.concat(chunks));
375
377
  }, "readUpTo");
376
378
 
377
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/tools/stats.js
379
+ // 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/mcp/tools/stats.js
378
380
  var statsTools = /* @__PURE__ */ __name((messenger) => ({
379
381
  stats_charts: tool({
380
382
  title: "A chart from a chat's statistics",
@@ -411,14 +413,14 @@ var statsTools = /* @__PURE__ */ __name((messenger) => ({
411
413
  })
412
414
  }), "statsTools");
413
415
 
414
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/tools.js
416
+ // 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/mcp/tools.js
415
417
  var pictureTools = /* @__PURE__ */ __name((messenger) => Object.fromEntries(Object.entries({
416
418
  ...messagesPhotoTools(messenger),
417
419
  ...attachmentsTools(messenger),
418
420
  ...statsTools(messenger)
419
421
  }).map(([name, definition]) => [name, { ...definition, input: strictObject(definition.input.entries) }])), "pictureTools");
420
422
 
421
- // node_modules/.pnpm/@wirecat+cli-core@0.567.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.77.1_commander@15._f1cdf35b93ce465cee2c32ebaca13ce7/node_modules/@wirecat/cli-core/dist/mcp/server.js
423
+ // 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/mcp/server.js
422
424
  var PER_RUN = /* @__PURE__ */ new Set([
423
425
  "streams",
424
426
  "stdin",
@@ -742,7 +744,7 @@ var serveOverStdio = /* @__PURE__ */ __name(async (command, context, messenger,
742
744
  }, "serveOverStdio");
743
745
  var serveOverHttpUntilStopped = /* @__PURE__ */ __name(async (command, context, messenger, options, http) => {
744
746
  const { session, embedders, build, log } = createServer(command, context, messenger, options);
745
- const { serveOverHttp } = await import("./serve-ANUKAJJN.js");
747
+ const { serveOverHttp } = await import("./serve-XAS6DECW.js");
746
748
  const appName = messenger.app.command;
747
749
  const appEnvPrefix = messenger.app.envPrefix;
748
750
  const listening = await serveOverHttp(build, {
@@ -0,0 +1,208 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ openSqlite
5
+ } from "./chunk-JWPSVS6C.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-ZVVMGPBJ.js";
9
+
10
+ // 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/damage.js
11
+ var DERIVED = /* @__PURE__ */ new Set(["mentions", "involvements", "embeddings"]);
12
+ var named = /* @__PURE__ */ __name((tables) => tables.length <= 5 ? tables.join(", ") : `${tables.slice(0, 5).join(", ")} and ${tables.length - 5} more`, "named");
13
+ var isDerivedTable = /* @__PURE__ */ __name((table, searchIndexes) => DERIVED.has(table) || table.startsWith("vector_index_") || searchIndexes.some((index) => table === index || table.startsWith(`${index}_`)), "isDerivedTable");
14
+ var WIRECAT_UNITS = ["memo-*", "mail-*", "tg-*", "max-*", "wirecat-*"];
15
+ var seen = /* @__PURE__ */ __name((mark) => `\`${mark.command}\` found the store damaged at ${mark.at} (${mark.error})`, "seen");
16
+ var explainDamage = /* @__PURE__ */ __name((health, command, mark = null) => {
17
+ if (health.ok && !mark)
18
+ return null;
19
+ const indexNames = (health.searchIndexes ?? []).map((index) => index.name);
20
+ const badIndexes = (health.searchIndexes ?? []).filter((index) => !index.ok).map((index) => index.name);
21
+ const tables = (health.damagedTables ?? []).map((one) => one.table).filter((table) => table !== null);
22
+ const sources = tables.filter((table) => !isDerivedTable(table, indexNames));
23
+ const derived = [.../* @__PURE__ */ new Set([...tables.filter((table) => isDerivedTable(table, indexNames)), ...badIndexes])];
24
+ const unopened = health.error !== void 0;
25
+ const json = (health.invalidJson ?? []).map(({ table, column }) => `${table}.${column}`);
26
+ const checked = health.ok ? `${seen(mark)}; the quick check reads too little to see it, and a deep check that passes clears it` : unopened ? `the store file cannot be opened: ${health.error}` : health.checked === "quick" ? "the store file's header or schema is damaged" : `the store file is damaged: ${health.problems ?? 0} problems` + (sources.length ? ` in the data of ${named(sources)}` : "") + (derived.length ? `${sources.length ? ", and" : " in"} the search data of ${named(derived)}` : "") + (json.length ? `; values that are not valid JSON in ${named(json)}` : "");
27
+ const what = mark && !health.ok ? `${checked}; ${seen(mark)}` : checked;
28
+ const impact = [
29
+ ...sources.length ? [`some rows of ${named(sources)} cannot be read; a recovery keeps every row it can read and names the rest`] : [],
30
+ ...derived.length ? [`searches may miss results or fail; ${named(derived)} hold nothing that is not elsewhere, and are rebuilt`] : [],
31
+ ...json.length ? [`a read of a row with a broken JSON value fails ("malformed JSON"); a recovery clears those values`] : [],
32
+ mark ? "reads that do not touch a damaged page work; every command that writes the store refuses until it is recovered" : "reads that do not touch a damaged page work; a write that touches one fails until the store is recovered"
33
+ ];
34
+ return {
35
+ what,
36
+ causes: [
37
+ "the computer lost power or crashed, or the disk filled up, while a tool was writing",
38
+ "the file was copied, restored or synced while a tool had it open, or it sits in a synced or network folder",
39
+ "a fault of the disk itself"
40
+ ],
41
+ investigate: [
42
+ `journalctl --user ${WIRECAT_UNITS.map((unit) => `-u '${unit}'`).join(" ")} --since -14d | grep -i -e malformed -e corrupt -e 'disk full'`,
43
+ "journalctl -k --since -14d | grep -i -e 'I/O error' -e nvme -e ata",
44
+ `df -h ${health.path.replace(/\/[^/]*$/, "")}`,
45
+ ...health.checked === "quick" || health.ok ? [`${command} store recover`] : []
46
+ ],
47
+ impact,
48
+ externalUnaffected: "only this computer's copy is damaged: Telegram, MAX, the mail servers and Google Drive keep their own data, so whatever is lost here can be fetched again by a sync",
49
+ steps: [
50
+ "stop every timer and server of the WireCat tools; `store recover run` lists the ones still running",
51
+ `${command} store recover run`,
52
+ "run the fetch commands it prints, then start the timers again"
53
+ ]
54
+ };
55
+ }, "explainDamage");
56
+
57
+ // 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/health.js
58
+ import { existsSync, statSync } from "node:fs";
59
+ var JSON_COLUMNS = {
60
+ accounts: ["settings"],
61
+ account_identities: ["mail_signals"],
62
+ bot_updates: ["payload"],
63
+ documents: ["front_matter"],
64
+ emails: ["headers"],
65
+ meeting_participants: ["sessions"],
66
+ messages: ["mentions", "reply_to"],
67
+ proposed_actions: ["payload", "result"],
68
+ searches: ["params"],
69
+ tag_consolidations: ["source_member_ids", "survivor_member_ids"],
70
+ task_events: ["changes"]
71
+ };
72
+ var jsonColumns = /* @__PURE__ */ __name((database) => database.prepare(`SELECT m.name AS "table", c.name AS "column", c."notnull" AS required FROM sqlite_master m, pragma_table_info(m.name) c
73
+ WHERE m.type = 'table' AND m.sql NOT LIKE 'CREATE VIRTUAL%' ORDER BY 1, 2`).all().map((row) => ({ table: String(row.table), column: String(row.column), required: Number(row.required) === 1 })).filter(({ table, column }) => column === "metadata" || JSON_COLUMNS[table]?.includes(column)), "jsonColumns");
74
+ var invalidJson = /* @__PURE__ */ __name((database) => jsonColumns(database).map((one) => ({
75
+ ...one,
76
+ rows: Number(database.prepare(`SELECT count(*) AS n FROM "${one.table}" WHERE "${one.column}" IS NOT NULL AND NOT json_valid("${one.column}")`).get()?.n)
77
+ })).filter(({ rows }) => rows > 0), "invalidJson");
78
+ var QUICK_CHECK_LIMIT = 1e4;
79
+ var QUICK_HEALTH_CHECKS = "the file header, its size against its page count, and the schema's own pages";
80
+ var FTS5 = /^\s*CREATE\s+VIRTUAL\s+TABLE\s+\S+\s+USING\s+fts5\s*\(/i;
81
+ var fts5Tables = /* @__PURE__ */ __name((database) => database.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'table' AND sql LIKE 'CREATE VIRTUAL TABLE%' ORDER BY name").all().filter((row) => FTS5.test(String(row.sql))).map((row) => {
82
+ const sql = String(row.sql);
83
+ return { name: String(row.name), sql, external: /content\s*=\s*'[^']+'/i.test(sql) };
84
+ }), "fts5Tables");
85
+ var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
86
+ var bytesOf = /* @__PURE__ */ __name((path) => statSync(path, { throwIfNoEntry: false })?.size ?? 0, "bytesOf");
87
+ var damagedTables = /* @__PURE__ */ __name((database, lines) => {
88
+ const roots = new Map(database.prepare("SELECT rootpage, tbl_name FROM sqlite_master WHERE rootpage > 0").all().map((row) => [Number(row.rootpage), String(row.tbl_name)]));
89
+ const owners = new Map(database.prepare("SELECT name, tbl_name FROM sqlite_master WHERE type = 'index'").all().map((row) => [String(row.name), String(row.tbl_name)]));
90
+ const virtual = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND sql LIKE 'CREATE VIRTUAL TABLE%'").all().map((row) => String(row.name));
91
+ const ownerOf = /* @__PURE__ */ __name((table) => table === null ? null : virtual.find((name) => table.startsWith(`${name}_`)) ?? table, "ownerOf");
92
+ const tables = /* @__PURE__ */ new Map();
93
+ for (const raw of lines) {
94
+ const line = raw.replace(/^\*\*\* in database \w+ \*\*\*\s*/, "");
95
+ const tree = /^Tree (\d+) /.exec(line);
96
+ const column = /value in (\w+)\.\w+/.exec(line) ?? /^table (\w+): /.exec(line);
97
+ const index = /index (\w+)/.exec(line)?.[1];
98
+ const table = ownerOf(tree ? roots.get(Number(tree[1])) ?? null : column ? column[1] ?? null : index ? owners.get(index) ?? null : null);
99
+ const known = tables.get(table);
100
+ if (known)
101
+ known.problems += 1;
102
+ else
103
+ tables.set(table, { table, problems: 1, sample: line.slice(0, 200) });
104
+ }
105
+ return [...tables.values()].sort((a, b) => b.problems - a.problems);
106
+ }, "damagedTables");
107
+ var searchIndexHealth = /* @__PURE__ */ __name((database) => fts5Tables(database).map(({ name }) => {
108
+ try {
109
+ database.exec("BEGIN");
110
+ try {
111
+ database.exec(`INSERT INTO "${name}" ("${name}", rank) VALUES ('integrity-check', 0)`);
112
+ } finally {
113
+ database.exec("ROLLBACK");
114
+ }
115
+ return { name, ok: true };
116
+ } catch (error) {
117
+ return { name, ok: false, error: messageOf(error) };
118
+ }
119
+ }), "searchIndexHealth");
120
+ var pragmaLines = /* @__PURE__ */ __name((database, sql) => database.prepare(sql).all().flatMap((row) => String(Object.values(row)[0]).split("\n")), "pragmaLines");
121
+ var checkLines = /* @__PURE__ */ __name((database) => {
122
+ try {
123
+ return pragmaLines(database, `PRAGMA quick_check(${QUICK_CHECK_LIMIT})`);
124
+ } catch {
125
+ const tables = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND rootpage > 0 ORDER BY name").all().map((row) => String(row.name));
126
+ return tables.flatMap((table) => {
127
+ try {
128
+ return pragmaLines(database, `PRAGMA quick_check("${table}")`).filter((line) => line !== "ok");
129
+ } catch (error) {
130
+ return [`table ${table}: ${messageOf(error)}`];
131
+ }
132
+ });
133
+ }
134
+ }, "checkLines");
135
+ var quickHealth = /* @__PURE__ */ __name((database, path) => {
136
+ const pragma = /* @__PURE__ */ __name((name) => Number(Object.values(database.prepare(`PRAGMA ${name}`).get() ?? {})[0] ?? 0), "pragma");
137
+ const file = {
138
+ bytes: bytesOf(path),
139
+ pages: pragma("page_count"),
140
+ pageSize: pragma("page_size"),
141
+ freePages: pragma("freelist_count")
142
+ };
143
+ const schema = database.prepare("PRAGMA quick_check('sqlite_schema')").all().map((row) => String(Object.values(row)[0]));
144
+ const walFrames = existsSync(`${path}-wal`) && bytesOf(`${path}-wal`) > 0;
145
+ const sized = walFrames || file.bytes === file.pages * file.pageSize;
146
+ const problems = [
147
+ ...schema.length === 1 && schema[0] === "ok" ? [] : schema,
148
+ ...sized ? [] : [`the file holds ${file.bytes} bytes, its header says ${file.pages * file.pageSize}`]
149
+ ];
150
+ return { file, problems };
151
+ }, "quickHealth");
152
+ var storeHealth = /* @__PURE__ */ __name(async (path, { deep = false } = {}) => {
153
+ const started = Date.now();
154
+ const checked = deep ? "deep" : "quick";
155
+ const done = /* @__PURE__ */ __name((health) => ({
156
+ path,
157
+ checked,
158
+ ...health,
159
+ ms: Date.now() - started
160
+ }), "done");
161
+ let database;
162
+ try {
163
+ database = (await openSqlite(path, { readOnly: !deep })).database;
164
+ } catch (error) {
165
+ return done({ ok: false, error: messageOf(error) });
166
+ }
167
+ try {
168
+ const { file, problems } = quickHealth(database, path);
169
+ if (!deep) {
170
+ return done({
171
+ ok: problems.length === 0,
172
+ file,
173
+ ...problems.length ? {
174
+ problems: problems.length,
175
+ damagedTables: [{ table: null, problems: problems.length, sample: problems[0] }]
176
+ } : {}
177
+ });
178
+ }
179
+ database.exec("PRAGMA busy_timeout = 30000");
180
+ const lines = checkLines(database);
181
+ const pagesOk = lines.length === 1 && lines[0] === "ok";
182
+ const indexes = searchIndexHealth(database);
183
+ const json = pagesOk ? invalidJson(database) : [];
184
+ return done({
185
+ ok: pagesOk && problems.length === 0 && indexes.every((index) => index.ok) && json.length === 0,
186
+ file,
187
+ problems: pagesOk ? 0 : lines.length,
188
+ damagedTables: pagesOk ? [] : damagedTables(database, lines),
189
+ searchIndexes: indexes,
190
+ invalidJson: json
191
+ });
192
+ } catch (error) {
193
+ return done({ ok: false, error: messageOf(error) });
194
+ } finally {
195
+ database.close();
196
+ }
197
+ }, "storeHealth");
198
+
199
+ // 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/sqlite/document-transfer/snapshot.js
200
+ var MAX_BYTES = 16 * 1024 * 1024;
201
+
202
+ export {
203
+ explainDamage,
204
+ invalidJson,
205
+ QUICK_HEALTH_CHECKS,
206
+ fts5Tables,
207
+ storeHealth
208
+ };