@wirecat/tg-cli 0.118.0 → 0.119.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 (137) hide show
  1. package/contracts/wirecat.json +7621 -0
  2. package/dist/bin/tg.js +2 -2
  3. package/dist/bot/transport.d.ts.map +1 -1
  4. package/dist/bot/transport.js +15 -8
  5. package/dist/bot/transport.js.map +1 -1
  6. package/dist/bundle/{adapter-4YNP6VCO.js → adapter-NEQQOANM.js} +47 -48
  7. package/dist/bundle/{all-profiles-MIQDYAGO.js → all-profiles-QFT46FTF.js} +10 -10
  8. package/dist/bundle/{anthropic-NTASPJYE.js → anthropic-UJ4RYCWU.js} +10 -8
  9. package/dist/bundle/{app-server-UJZBJ2SK.js → app-server-NE3EL5IK.js} +43 -43
  10. package/dist/bundle/{bot-api-JZAD4L3N.js → bot-api-D4H5SCP5.js} +49 -49
  11. package/dist/bundle/{bot-history-OUDHH3NU.js → bot-history-KF2PUMWA.js} +18 -18
  12. package/dist/bundle/{bun-EC4HDIRD.js → bun-F7MH5YKA.js} +2 -2
  13. package/dist/bundle/{bun-sqlite-A4HJR6KO.js → bun-sqlite-FYDJXUHF.js} +5 -5
  14. package/dist/bundle/{chunk-I4TI5HDJ.js → chunk-23JGV5FQ.js} +11 -11
  15. package/dist/bundle/{chunk-MBH7IKLT.js → chunk-2BAJ6ORN.js} +1 -1
  16. package/dist/bundle/{chunk-EPXVRJAX.js → chunk-3EQ7USKJ.js} +2 -2
  17. package/dist/bundle/{chunk-MZNOASAW.js → chunk-3K65KTXD.js} +16 -3
  18. package/dist/bundle/{chunk-EQJ6NLF5.js → chunk-4AACB23H.js} +13 -13
  19. package/dist/bundle/{chunk-NUCDEOFC.js → chunk-5EHJWIW4.js} +2 -2
  20. package/dist/bundle/{chunk-VW6BF6M7.js → chunk-5FEEFXJA.js} +1 -1
  21. package/dist/bundle/{chunk-6RI4TEIC.js → chunk-65BWMPCI.js} +2 -2
  22. package/dist/bundle/{chunk-PB252TT3.js → chunk-6ERQJRL2.js} +2 -2
  23. package/dist/bundle/{chunk-G3RT2EQI.js → chunk-6K5R3YPN.js} +2 -2
  24. package/dist/bundle/{chunk-OTQDJUES.js → chunk-6OE5I3PR.js} +6 -6
  25. package/dist/bundle/{chunk-FHMK6OK4.js → chunk-72QLHHSO.js} +93 -29
  26. package/dist/bundle/{chunk-YEOSV6JC.js → chunk-7C6POLLO.js} +1 -1
  27. package/dist/bundle/{chunk-JPVFYMSQ.js → chunk-7VUNJDYU.js} +4 -4
  28. package/dist/bundle/{chunk-57LKX6N2.js → chunk-BXIPT2BO.js} +1 -1
  29. package/dist/bundle/{chunk-NKFTZVQU.js → chunk-CIDFV3IT.js} +1 -1
  30. package/dist/bundle/{chunk-4BV4UMBB.js → chunk-CX2WCEQU.js} +264 -195
  31. package/dist/bundle/{chunk-H6S3C3MH.js → chunk-D4Y2KL5V.js} +4 -4
  32. package/dist/bundle/{chunk-YPRUWRKE.js → chunk-D6YTBJY6.js} +1 -1
  33. package/dist/bundle/{chunk-PW3HFIJA.js → chunk-DQELQ7BL.js} +365 -192
  34. package/dist/bundle/{chunk-5IIU7X4S.js → chunk-F223KYWG.js} +1 -1
  35. package/dist/bundle/{chunk-TMTEWOQS.js → chunk-FJKP6MMP.js} +5 -3
  36. package/dist/bundle/{chunk-NMT2VGEI.js → chunk-FQ3C6DFV.js} +3 -3
  37. package/dist/bundle/{chunk-6ZMTEUVU.js → chunk-FQZSS3AB.js} +6 -6
  38. package/dist/bundle/{chunk-CEY43D3A.js → chunk-FRW3CWC7.js} +29 -29
  39. package/dist/bundle/{chunk-65XV5PPI.js → chunk-G3MQOH6Z.js} +3 -3
  40. package/dist/bundle/{chunk-6AXUEJGL.js → chunk-HGMMRT4G.js} +2 -2
  41. package/dist/bundle/{chunk-GLRRCKP6.js → chunk-HPQQ76WF.js} +23 -5
  42. package/dist/bundle/{chunk-RG2E7ZQZ.js → chunk-HV5YYAJX.js} +50 -15
  43. package/dist/bundle/{chunk-3MQOLYAN.js → chunk-IAGX5VFL.js} +4 -4
  44. package/dist/bundle/{chunk-BNEP5EOV.js → chunk-JKKEMVW3.js} +4 -4
  45. package/dist/bundle/{chunk-P3ASN72F.js → chunk-KBHK5UGL.js} +1 -1
  46. package/dist/bundle/{chunk-EPCFXKTX.js → chunk-KC4MQRAB.js} +34 -8
  47. package/dist/bundle/{chunk-GXCJ47SJ.js → chunk-L33G5ARH.js} +2664 -670
  48. package/dist/bundle/{chunk-PO74BDER.js → chunk-MDLSI3EN.js} +23 -23
  49. package/dist/bundle/chunk-NDSRND3E.js +138 -0
  50. package/dist/bundle/{chunk-2KQHUBTV.js → chunk-OG2CG2GS.js} +12 -12
  51. package/dist/bundle/{chunk-JZETEZHC.js → chunk-QD27C3BG.js} +7 -7
  52. package/dist/bundle/{chunk-QOGYHU3Q.js → chunk-QG5U6HCI.js} +61 -21
  53. package/dist/bundle/{chunk-GI4MTNA2.js → chunk-QQ3QZFFD.js} +8 -8
  54. package/dist/bundle/{chunk-76EKXFX2.js → chunk-QTFXYR5W.js} +24 -2
  55. package/dist/bundle/{chunk-ZXXTJF4Z.js → chunk-RGU2G3KL.js} +4 -4
  56. package/dist/bundle/{chunk-JWPSVS6C.js → chunk-ROOUBFUW.js} +2304 -1442
  57. package/dist/bundle/{chunk-5QYU7B27.js → chunk-RUNFFBJU.js} +656 -461
  58. package/dist/bundle/{chunk-DKFC5ZZ3.js → chunk-S3HAFJVC.js} +4 -4
  59. package/dist/bundle/{chunk-BXTDAGM4.js → chunk-SMHLQEE2.js} +2 -2
  60. package/dist/bundle/{chunk-JWIUK3SK.js → chunk-TEZKCH5B.js} +2 -2
  61. package/dist/bundle/{chunk-HJNRIK5X.js → chunk-TKHEVAEG.js} +9 -8
  62. package/dist/bundle/{chunk-JLJKGKU2.js → chunk-TT4CIXVH.js} +6 -6
  63. package/dist/bundle/{chunk-ZMUC3UQO.js → chunk-UBCLVM7C.js} +3 -3
  64. package/dist/bundle/{chunk-YHZFGUAP.js → chunk-V5Z2JO6X.js} +19 -19
  65. package/dist/bundle/{chunk-2NA5KVP6.js → chunk-W2BIBPRU.js} +234 -38
  66. package/dist/bundle/{chunk-PWCQC56A.js → chunk-X5PDWCG7.js} +1 -1
  67. package/dist/bundle/{chunk-GIM37COQ.js → chunk-XDMJVWWR.js} +3 -3
  68. package/dist/bundle/{chunk-KEDHX6XG.js → chunk-XM3P7LLT.js} +2 -2
  69. package/dist/bundle/{chunk-DSZJREEO.js → chunk-YMWPRHXG.js} +1285 -750
  70. package/dist/bundle/{chunk-5LDWBEWU.js → chunk-Z4CGZAFQ.js} +45 -27
  71. package/dist/bundle/{chunk-Y64SI2RO.js → chunk-ZEQ7ONPZ.js} +3 -3
  72. package/dist/bundle/command-contract-7TGMZRBE.js +33 -0
  73. package/dist/bundle/{decode-NMNPLKNR.js → decode-5N4ERCHC.js} +5 -5
  74. package/dist/bundle/{dispatch-OP27MWX5.js → dispatch-TBGXBDHE.js} +10 -10
  75. package/dist/bundle/{echarts-S46LEIPS.js → echarts-YDEBAMXT.js} +2 -2
  76. package/dist/bundle/{embed-I5ZYHGYC.js → embed-T7H62XFR.js} +6 -6
  77. package/dist/bundle/{embedder-LTJI67N2.js → embedder-AW3O2TR3.js} +9 -9
  78. package/dist/bundle/{entry-O6BUPXF7.js → entry-L2LJ2VPY.js} +7 -7
  79. package/dist/bundle/{failure-4JUQFXJT.js → failure-AWHPW2HE.js} +2 -2
  80. package/dist/bundle/{first-run-PMZNCDGD.js → first-run-6PBZSRZU.js} +11 -11
  81. package/dist/bundle/first-screen-UKCD7D2R.js +31 -0
  82. package/dist/bundle/{instructions-AUEGY3VO.js → instructions-C3NJERO7.js} +1 -1
  83. package/dist/bundle/{mcp-M4QN2E7R.js → mcp-CWLASTLV.js} +2 -2
  84. package/dist/bundle/{node-XRA7RBCQ.js → node-P3CIIYWU.js} +2 -2
  85. package/dist/bundle/{node-sqlite-DEZO6LRS.js → node-sqlite-YVHMNRVA.js} +6 -6
  86. package/dist/bundle/{oauth-DAVC7WCD.js → oauth-5OQYA2SV.js} +7 -7
  87. package/dist/bundle/{open-DE2YO4T7.js → open-YGWUVSU7.js} +5 -5
  88. package/dist/bundle/{openai-5BKGAULH.js → openai-U45JBQ6F.js} +16 -37
  89. package/dist/bundle/{process-4ZHPNUIQ.js → process-DCYX5EDG.js} +1 -1
  90. package/dist/bundle/{program-EGTKSNB4.js → program-UZBFH2EZ.js} +55 -52
  91. package/dist/bundle/{prompt-HWCWHHPE.js → prompt-HPVTPTFI.js} +7 -5
  92. package/dist/bundle/{proxy-transport-4DPZB2W2.js → proxy-transport-D7MCHGSV.js} +5 -5
  93. package/dist/bundle/{recognize-NG6RXNGF.js → recognize-IJCPFJ76.js} +4 -4
  94. package/dist/bundle/{remote-ZKXIIGYH.js → remote-MWDYQWFW.js} +7 -7
  95. package/dist/bundle/{rerank-TX5QFURV.js → rerank-SXG64475.js} +7 -7
  96. package/dist/bundle/{serve-XAS6DECW.js → serve-KJQENHEH.js} +9 -9
  97. package/dist/bundle/{server-CNPIWBYU.js → server-MXVXZWN6.js} +35 -35
  98. package/dist/bundle/server-RTMCRKQF.js +60 -0
  99. package/dist/bundle/{state-3HTUETTS.js → state-CKKJWH27.js} +6 -6
  100. package/dist/bundle/{store-B5VZWJHN.js → store-R3BE4V56.js} +36 -13
  101. package/dist/bundle/store-maintenance-command-KDGBSBNU.js +49 -0
  102. package/dist/bundle/tg.js +38 -14
  103. package/dist/commands/account-removal.d.ts +3 -0
  104. package/dist/commands/account-removal.d.ts.map +1 -0
  105. package/dist/commands/account-removal.js +57 -0
  106. package/dist/commands/account-removal.js.map +1 -0
  107. package/dist/commands/context.d.ts.map +1 -1
  108. package/dist/commands/context.js +2 -0
  109. package/dist/commands/context.js.map +1 -1
  110. package/dist/http.d.ts +6 -0
  111. package/dist/http.d.ts.map +1 -0
  112. package/dist/http.js +8 -0
  113. package/dist/http.js.map +1 -0
  114. package/dist/identity.d.ts +4 -0
  115. package/dist/identity.d.ts.map +1 -1
  116. package/dist/identity.js +14 -0
  117. package/dist/identity.js.map +1 -1
  118. package/dist/telegram/map.d.ts.map +1 -1
  119. package/dist/telegram/map.js +3 -0
  120. package/dist/telegram/map.js.map +1 -1
  121. package/dist/telegram/registration.d.ts +1 -1
  122. package/dist/telegram/registration.d.ts.map +1 -1
  123. package/dist/telegram/registration.js +4 -1
  124. package/dist/telegram/registration.js.map +1 -1
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/dist/wcat.d.ts +3 -0
  128. package/dist/wcat.d.ts.map +1 -0
  129. package/dist/wcat.js +4 -0
  130. package/dist/wcat.js.map +1 -0
  131. package/package.json +7 -6
  132. package/dist/bundle/chunk-TSTEZNSX.js +0 -33
  133. package/dist/bundle/command-contract-7GZ6HAA6.js +0 -33
  134. package/dist/bundle/first-screen-BGML5DSO.js +0 -31
  135. package/dist/bundle/server-FRTKLHZF.js +0 -60
  136. package/dist/bundle/store-maintenance-command-VG3CLELA.js +0 -50
  137. /package/dist/bundle/{chunk-VOXIGICJ.js → chunk-DWX4DE2I.js} +0 -0
@@ -3,14 +3,17 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  answerOf,
5
5
  messengerContext
6
- } from "./chunk-PO74BDER.js";
6
+ } from "./chunk-MDLSI3EN.js";
7
7
  import {
8
8
  FETCHING,
9
9
  RULES_VERSION,
10
10
  applyTaskRulesOnArrival,
11
11
  capability,
12
12
  chatEventAnswer,
13
+ embeddingKeys,
14
+ endpointKeyName,
13
15
  memberAnswer,
16
+ modelGateway,
14
17
  newSendId,
15
18
  onlineDeps,
16
19
  openRequestTask,
@@ -24,14 +27,14 @@ import {
24
27
  typedQuery,
25
28
  withQuery,
26
29
  withTimeLimit
27
- } from "./chunk-DSZJREEO.js";
30
+ } from "./chunk-YMWPRHXG.js";
28
31
  import {
29
32
  QUICK_HEALTH_CHECKS,
30
33
  explainDamage,
31
34
  fts5Tables,
32
35
  invalidJson,
33
36
  storeHealth
34
- } from "./chunk-DKFC5ZZ3.js";
37
+ } from "./chunk-S3HAFJVC.js";
35
38
  import {
36
39
  stringWidth,
37
40
  wrapAnsi
@@ -46,7 +49,6 @@ import {
46
49
  codeOf,
47
50
  currentRun,
48
51
  destroysNothing,
49
- endpoint,
50
52
  environmentOf,
51
53
  itemOf,
52
54
  jsonlRecords,
@@ -63,20 +65,17 @@ import {
63
65
  snakeKeys,
64
66
  storeTable,
65
67
  withoutProviderRefs
66
- } from "./chunk-PW3HFIJA.js";
67
- import {
68
- envName
69
- } from "./chunk-PB252TT3.js";
68
+ } from "./chunk-DQELQ7BL.js";
70
69
  import {
71
70
  holdLock,
72
71
  lockPath,
73
72
  releaseLock,
74
73
  servingProfiles,
75
74
  takeLock
76
- } from "./chunk-GIM37COQ.js";
75
+ } from "./chunk-XDMJVWWR.js";
77
76
  import {
78
77
  holdersOf
79
- } from "./chunk-YPRUWRKE.js";
78
+ } from "./chunk-D6YTBJY6.js";
80
79
  import {
81
80
  CORPORA,
82
81
  MIGRATIONS,
@@ -91,6 +90,7 @@ import {
91
90
  fillVectorIndexes,
92
91
  formatLocator,
93
92
  involvementStoreOver,
93
+ isDerivedTable,
94
94
  migrate,
95
95
  noteIndexState,
96
96
  openSqlite,
@@ -112,51 +112,38 @@ import {
112
112
  storeClients,
113
113
  storeContents,
114
114
  vectorIndexCounts
115
- } from "./chunk-JWPSVS6C.js";
115
+ } from "./chunk-ROOUBFUW.js";
116
116
  import {
117
117
  queryFieldsOf,
118
118
  readDamageMark,
119
119
  readHealthMark,
120
120
  recordDeepCheck
121
- } from "./chunk-4BV4UMBB.js";
121
+ } from "./chunk-CX2WCEQU.js";
122
122
  import {
123
123
  failureKey,
124
124
  isStoreDamage
125
- } from "./chunk-Y64SI2RO.js";
125
+ } from "./chunk-ZEQ7ONPZ.js";
126
126
  import {
127
127
  readSecret
128
- } from "./chunk-GLRRCKP6.js";
129
- import {
130
- checkedOptions,
131
- range
132
- } from "./chunk-TSTEZNSX.js";
133
- import {
134
- messagesFor,
135
- systemFor,
136
- validateImages
137
- } from "./chunk-76EKXFX2.js";
128
+ } from "./chunk-HPQQ76WF.js";
138
129
  import {
139
130
  storePath
140
- } from "./chunk-G3RT2EQI.js";
131
+ } from "./chunk-6K5R3YPN.js";
141
132
  import {
142
133
  openCache
143
- } from "./chunk-JLJKGKU2.js";
134
+ } from "./chunk-TT4CIXVH.js";
144
135
  import {
145
- Credentials,
146
- pathsAreOverridden,
147
136
  resolvePaths,
148
137
  writeSecurely
149
- } from "./chunk-YHZFGUAP.js";
138
+ } from "./chunk-V5Z2JO6X.js";
150
139
  import {
151
140
  array,
152
141
  boolean,
153
142
  check,
154
143
  forward,
155
144
  getDotPath,
156
- integer,
157
145
  minLength,
158
146
  nullable,
159
- number,
160
147
  object,
161
148
  optional,
162
149
  parse,
@@ -168,14 +155,13 @@ import {
168
155
  strictObject,
169
156
  string,
170
157
  transform,
171
- trim,
172
- union
173
- } from "./chunk-EPCFXKTX.js";
158
+ trim
159
+ } from "./chunk-KC4MQRAB.js";
174
160
  import {
175
161
  CliError,
176
162
  singleLine,
177
163
  visibleControls
178
- } from "./chunk-BXTDAGM4.js";
164
+ } from "./chunk-SMHLQEE2.js";
179
165
  import {
180
166
  __commonJS,
181
167
  __name,
@@ -353,14 +339,14 @@ var require_liquid_node = __commonJS({
353
339
  return value !== null && (type === "object" || type === "function");
354
340
  }
355
341
  __name(isObject, "isObject");
356
- function range2(start, stop, step = 1) {
342
+ function range(start, stop, step = 1) {
357
343
  const arr = [];
358
344
  for (let i = start; i < stop; i += step) {
359
345
  arr.push(i);
360
346
  }
361
347
  return arr;
362
348
  }
363
- __name(range2, "range");
349
+ __name(range, "range");
364
350
  function padStart(str, length, ch = " ") {
365
351
  return pad(str, length, ch, (str2, ch2) => ch2 + str2);
366
352
  }
@@ -554,7 +540,7 @@ var require_liquid_node = __commonJS({
554
540
  const lines = token.input.split("\n");
555
541
  const begin = Math.max(line - 2, 1);
556
542
  const end = Math.min(line + 3, lines.length);
557
- const context = range2(begin, end + 1).map((lineNumber) => {
543
+ const context = range(begin, end + 1).map((lineNumber) => {
558
544
  const rowIndicator = lineNumber === line ? ">> " : " ";
559
545
  const num = padStart(String(lineNumber), String(end).length);
560
546
  let text = `${rowIndicator}${num}| `;
@@ -1132,8 +1118,8 @@ var require_liquid_node = __commonJS({
1132
1118
  valid() {
1133
1119
  return !isNaN(this.getTime());
1134
1120
  }
1135
- format(options2) {
1136
- return this.DateTimeFormat && this.DateTimeFormat(this.locale, options2).format(this.displayDate);
1121
+ format(options) {
1122
+ return this.DateTimeFormat && this.DateTimeFormat(this.locale, options).format(this.displayDate);
1137
1123
  }
1138
1124
  /**
1139
1125
  * Create a Date object fixed to it's declared Timezone. Both
@@ -1217,11 +1203,11 @@ var require_liquid_node = __commonJS({
1217
1203
  static {
1218
1204
  __name(this, "TagToken");
1219
1205
  }
1220
- constructor(input, begin, end, options2, file2) {
1221
- const { trimTagLeft, trimTagRight, tagDelimiterLeft, tagDelimiterRight } = options2;
1206
+ constructor(input, begin, end, options, file2) {
1207
+ const { trimTagLeft, trimTagRight, tagDelimiterLeft, tagDelimiterRight } = options;
1222
1208
  const [valueBegin, valueEnd] = [begin + tagDelimiterLeft.length, end - tagDelimiterRight.length];
1223
1209
  super(exports.TokenKind.Tag, [valueBegin, valueEnd], input, begin, end, trimTagLeft, trimTagRight, file2);
1224
- this.tokenizer = new Tokenizer(input, options2.operators, file2, this.contentRange, options2.groupedExpressions);
1210
+ this.tokenizer = new Tokenizer(input, options.operators, file2, this.contentRange, options.groupedExpressions);
1225
1211
  this.name = this.tokenizer.readTagName();
1226
1212
  this.tokenizer.assert(this.name, `illegal tag syntax, tag name expected`);
1227
1213
  this.tokenizer.skipBlank();
@@ -1232,8 +1218,8 @@ var require_liquid_node = __commonJS({
1232
1218
  static {
1233
1219
  __name(this, "OutputToken");
1234
1220
  }
1235
- constructor(input, begin, end, options2, file2) {
1236
- const { trimOutputLeft, trimOutputRight, outputDelimiterLeft, outputDelimiterRight } = options2;
1221
+ constructor(input, begin, end, options, file2) {
1222
+ const { trimOutputLeft, trimOutputRight, outputDelimiterLeft, outputDelimiterRight } = options;
1237
1223
  const valueRange = [begin + outputDelimiterLeft.length, end - outputDelimiterRight.length];
1238
1224
  super(exports.TokenKind.Output, valueRange, input, begin, end, trimOutputLeft, trimOutputRight, file2);
1239
1225
  }
@@ -1452,9 +1438,9 @@ var require_liquid_node = __commonJS({
1452
1438
  static {
1453
1439
  __name(this, "LiquidTagToken");
1454
1440
  }
1455
- constructor(input, begin, end, options2, file2) {
1441
+ constructor(input, begin, end, options, file2) {
1456
1442
  super(exports.TokenKind.Tag, [begin, end], input, begin, end, false, false, file2);
1457
- this.tokenizer = new Tokenizer(input, options2.operators, file2, this.contentRange, options2.groupedExpressions);
1443
+ this.tokenizer = new Tokenizer(input, options.operators, file2, this.contentRange, options.groupedExpressions);
1458
1444
  this.name = this.tokenizer.readTagName();
1459
1445
  this.tokenizer.assert(this.name, "illegal liquid tag syntax");
1460
1446
  this.tokenizer.skipBlank();
@@ -1528,11 +1514,11 @@ var require_liquid_node = __commonJS({
1528
1514
  static {
1529
1515
  __name(this, "Filter");
1530
1516
  }
1531
- constructor(token, options2, liquid) {
1517
+ constructor(token, options, liquid) {
1532
1518
  this.token = token;
1533
1519
  this.name = token.name;
1534
- this.handler = isFunction(options2) ? options2 : isFunction(options2?.handler) ? options2.handler : identify;
1535
- this.raw = !isFunction(options2) && !!options2?.raw;
1520
+ this.handler = isFunction(options) ? options : isFunction(options?.handler) ? options.handler : identify;
1521
+ this.raw = !isFunction(options) && !!options?.raw;
1536
1522
  this.args = token.args;
1537
1523
  this.liquid = liquid;
1538
1524
  }
@@ -1635,7 +1621,7 @@ var require_liquid_node = __commonJS({
1635
1621
  const low = yield evalTokenValue(token.lhs, ctx);
1636
1622
  const high = yield evalTokenValue(token.rhs, ctx);
1637
1623
  ctx.memoryLimit.use(high - low + 1);
1638
- return range2(+low, +high + 1);
1624
+ return range(+low, +high + 1);
1639
1625
  }
1640
1626
  __name(evalRangeToken, "evalRangeToken");
1641
1627
  function* toPostfix(tokens) {
@@ -1829,7 +1815,7 @@ var require_liquid_node = __commonJS({
1829
1815
  return readFileAsync(filepath, "utf8");
1830
1816
  }
1831
1817
  __name(readFile, "readFile");
1832
- function existsSync10(filepath) {
1818
+ function existsSync11(filepath) {
1833
1819
  try {
1834
1820
  fs$1.statSync(filepath);
1835
1821
  return true;
@@ -1837,11 +1823,11 @@ var require_liquid_node = __commonJS({
1837
1823
  return false;
1838
1824
  }
1839
1825
  }
1840
- __name(existsSync10, "existsSync");
1841
- function readFileSync5(filepath) {
1826
+ __name(existsSync11, "existsSync");
1827
+ function readFileSync6(filepath) {
1842
1828
  return fs$1.readFileSync(filepath, "utf8");
1843
1829
  }
1844
- __name(readFileSync5, "readFileSync");
1830
+ __name(readFileSync6, "readFileSync");
1845
1831
  function resolve2(root, file2, ext) {
1846
1832
  if (!path.extname(file2))
1847
1833
  file2 += ext;
@@ -1855,10 +1841,10 @@ var require_liquid_node = __commonJS({
1855
1841
  }
1856
1842
  }
1857
1843
  __name(fallback, "fallback");
1858
- function dirname3(filepath) {
1844
+ function dirname4(filepath) {
1859
1845
  return path.dirname(filepath);
1860
1846
  }
1861
- __name(dirname3, "dirname");
1847
+ __name(dirname4, "dirname");
1862
1848
  var realpathAsync = promisify(fs$1.realpath);
1863
1849
  async function contains(root, file2) {
1864
1850
  try {
@@ -1886,11 +1872,11 @@ var require_liquid_node = __commonJS({
1886
1872
  __proto__: null,
1887
1873
  exists,
1888
1874
  readFile,
1889
- existsSync: existsSync10,
1890
- readFileSync: readFileSync5,
1875
+ existsSync: existsSync11,
1876
+ readFileSync: readFileSync6,
1891
1877
  resolve: resolve2,
1892
1878
  fallback,
1893
- dirname: dirname3,
1879
+ dirname: dirname4,
1894
1880
  contains,
1895
1881
  containsSync,
1896
1882
  sep: path.sep
@@ -2116,41 +2102,41 @@ var require_liquid_node = __commonJS({
2116
2102
  parseLimit: Infinity,
2117
2103
  renderLimit: Infinity
2118
2104
  };
2119
- function normalize(options2) {
2120
- if (options2.hasOwnProperty("root")) {
2121
- if (!options2.hasOwnProperty("partials"))
2122
- options2.partials = options2.root;
2123
- if (!options2.hasOwnProperty("layouts"))
2124
- options2.layouts = options2.root;
2125
- }
2126
- if (options2.hasOwnProperty("cache")) {
2105
+ function normalize(options) {
2106
+ if (options.hasOwnProperty("root")) {
2107
+ if (!options.hasOwnProperty("partials"))
2108
+ options.partials = options.root;
2109
+ if (!options.hasOwnProperty("layouts"))
2110
+ options.layouts = options.root;
2111
+ }
2112
+ if (options.hasOwnProperty("cache")) {
2127
2113
  let cache;
2128
- if (typeof options2.cache === "number")
2129
- cache = options2.cache > 0 ? new LRU(options2.cache) : void 0;
2130
- else if (typeof options2.cache === "object")
2131
- cache = options2.cache;
2114
+ if (typeof options.cache === "number")
2115
+ cache = options.cache > 0 ? new LRU(options.cache) : void 0;
2116
+ else if (typeof options.cache === "object")
2117
+ cache = options.cache;
2132
2118
  else
2133
- cache = options2.cache ? new LRU(1024) : void 0;
2134
- options2.cache = cache;
2119
+ cache = options.cache ? new LRU(1024) : void 0;
2120
+ options.cache = cache;
2135
2121
  }
2136
- options2 = { ...defaultOptions, ...options2.jekyllInclude ? { dynamicPartials: false } : {}, ...options2 };
2137
- if ((!options2.fs.dirname || !options2.fs.sep) && options2.relativeReference) {
2122
+ options = { ...defaultOptions, ...options.jekyllInclude ? { dynamicPartials: false } : {}, ...options };
2123
+ if ((!options.fs.dirname || !options.fs.sep) && options.relativeReference) {
2138
2124
  console.warn("[LiquidJS] `fs.dirname` and `fs.sep` are required for relativeReference, set relativeReference to `false` to suppress this warning");
2139
- options2.relativeReference = false;
2125
+ options.relativeReference = false;
2140
2126
  }
2141
- options2.root = normalizeDirectoryList(options2.root);
2142
- options2.partials = normalizeDirectoryList(options2.partials);
2143
- options2.layouts = normalizeDirectoryList(options2.layouts);
2144
- options2.outputEscape = options2.outputEscape && getOutputEscapeFunction(options2.outputEscape);
2145
- if (!options2.locale) {
2146
- options2.locale = getDateTimeFormat()?.().resolvedOptions().locale ?? "en-US";
2127
+ options.root = normalizeDirectoryList(options.root);
2128
+ options.partials = normalizeDirectoryList(options.partials);
2129
+ options.layouts = normalizeDirectoryList(options.layouts);
2130
+ options.outputEscape = options.outputEscape && getOutputEscapeFunction(options.outputEscape);
2131
+ if (!options.locale) {
2132
+ options.locale = getDateTimeFormat()?.().resolvedOptions().locale ?? "en-US";
2147
2133
  }
2148
- if (options2.templates) {
2149
- options2.fs = new MapFS(options2.templates);
2150
- options2.relativeReference = true;
2151
- options2.root = options2.partials = options2.layouts = ".";
2134
+ if (options.templates) {
2135
+ options.fs = new MapFS(options.templates);
2136
+ options.relativeReference = true;
2137
+ options.root = options.partials = options.layouts = ".";
2152
2138
  }
2153
- return options2;
2139
+ return options;
2154
2140
  }
2155
2141
  __name(normalize, "normalize");
2156
2142
  function getOutputEscapeFunction(nameOrFunction) {
@@ -2171,14 +2157,14 @@ var require_liquid_node = __commonJS({
2171
2157
  return list;
2172
2158
  }
2173
2159
  __name(normalizeDirectoryList, "normalizeDirectoryList");
2174
- function whiteSpaceCtrl(tokens, options2) {
2160
+ function whiteSpaceCtrl(tokens, options) {
2175
2161
  let inRaw = false;
2176
2162
  for (let i = 0; i < tokens.length; i++) {
2177
2163
  const token = tokens[i];
2178
2164
  if (!isDelimitedToken(token))
2179
2165
  continue;
2180
2166
  if (!inRaw && token.trimLeft) {
2181
- trimLeft(tokens[i - 1], options2.greedy);
2167
+ trimLeft(tokens[i - 1], options.greedy);
2182
2168
  }
2183
2169
  if (isTagToken(token)) {
2184
2170
  if (token.name === "raw")
@@ -2187,7 +2173,7 @@ var require_liquid_node = __commonJS({
2187
2173
  inRaw = false;
2188
2174
  }
2189
2175
  if (!inRaw && token.trimRight) {
2190
- trimRight(tokens[i + 1], options2.greedy);
2176
+ trimRight(tokens[i + 1], options.greedy);
2191
2177
  }
2192
2178
  }
2193
2179
  }
@@ -2214,12 +2200,12 @@ var require_liquid_node = __commonJS({
2214
2200
  static {
2215
2201
  __name(this, "Tokenizer");
2216
2202
  }
2217
- constructor(input, operators = defaultOptions.operators, file2, range3, groupedExpressions = false) {
2203
+ constructor(input, operators = defaultOptions.operators, file2, range2, groupedExpressions = false) {
2218
2204
  this.input = input;
2219
2205
  this.file = file2;
2220
2206
  this.rawBeginAt = -1;
2221
- this.p = range3 ? range3[0] : 0;
2222
- this.N = range3 ? range3[1] : input.length;
2207
+ this.p = range2 ? range2[0] : 0;
2208
+ this.N = range2 ? range2[1] : input.length;
2223
2209
  this.opTrie = createTrie(operators);
2224
2210
  this.literalTrie = createTrie(literalValues);
2225
2211
  this.groupedExpressions = groupedExpressions;
@@ -2319,23 +2305,23 @@ var require_liquid_node = __commonJS({
2319
2305
  const value = this.readValue();
2320
2306
  return [key.getText(), value];
2321
2307
  }
2322
- readTopLevelTokens(options2 = defaultOptions) {
2308
+ readTopLevelTokens(options = defaultOptions) {
2323
2309
  const tokens = [];
2324
2310
  while (this.p < this.N) {
2325
- const token = this.readTopLevelToken(options2);
2311
+ const token = this.readTopLevelToken(options);
2326
2312
  tokens.push(token);
2327
2313
  }
2328
- whiteSpaceCtrl(tokens, options2);
2314
+ whiteSpaceCtrl(tokens, options);
2329
2315
  return tokens;
2330
2316
  }
2331
- readTopLevelToken(options2) {
2332
- const { tagDelimiterLeft, outputDelimiterLeft } = options2;
2317
+ readTopLevelToken(options) {
2318
+ const { tagDelimiterLeft, outputDelimiterLeft } = options;
2333
2319
  if (this.rawBeginAt > -1)
2334
- return this.readEndrawOrRawContent(options2);
2320
+ return this.readEndrawOrRawContent(options);
2335
2321
  if (this.match(tagDelimiterLeft))
2336
- return this.readTagToken(options2);
2322
+ return this.readTagToken(options);
2337
2323
  if (this.match(outputDelimiterLeft))
2338
- return this.readOutputToken(options2);
2324
+ return this.readOutputToken(options);
2339
2325
  return this.readHTMLToken([tagDelimiterLeft, outputDelimiterLeft]);
2340
2326
  }
2341
2327
  readHTMLToken(stopStrings) {
@@ -2347,13 +2333,13 @@ var require_liquid_node = __commonJS({
2347
2333
  }
2348
2334
  return new HTMLToken(this.input, begin, this.p, this.file);
2349
2335
  }
2350
- readTagToken(options2) {
2336
+ readTagToken(options) {
2351
2337
  const { file: file2, input } = this;
2352
2338
  const begin = this.p;
2353
- if (this.readToDelimiter(options2.tagDelimiterRight) === -1) {
2339
+ if (this.readToDelimiter(options.tagDelimiterRight) === -1) {
2354
2340
  throw this.error(`tag ${this.snapshot(begin)} not closed`, begin);
2355
2341
  }
2356
- const token = new TagToken(input, begin, this.p, options2, file2);
2342
+ const token = new TagToken(input, begin, this.p, options, file2);
2357
2343
  if (token.name === "raw")
2358
2344
  this.rawBeginAt = begin;
2359
2345
  return token;
@@ -2371,17 +2357,17 @@ var require_liquid_node = __commonJS({
2371
2357
  }
2372
2358
  return -1;
2373
2359
  }
2374
- readOutputToken(options2 = defaultOptions) {
2360
+ readOutputToken(options = defaultOptions) {
2375
2361
  const { file: file2, input } = this;
2376
- const { outputDelimiterRight } = options2;
2362
+ const { outputDelimiterRight } = options;
2377
2363
  const begin = this.p;
2378
2364
  if (this.readToDelimiter(outputDelimiterRight, true) === -1) {
2379
2365
  throw this.error(`output ${this.snapshot(begin)} not closed`, begin);
2380
2366
  }
2381
- return new OutputToken(input, begin, this.p, options2, file2);
2367
+ return new OutputToken(input, begin, this.p, options, file2);
2382
2368
  }
2383
- readEndrawOrRawContent(options2) {
2384
- const { tagDelimiterLeft, tagDelimiterRight } = options2;
2369
+ readEndrawOrRawContent(options) {
2370
+ const { tagDelimiterLeft, tagDelimiterRight } = options;
2385
2371
  const begin = this.p;
2386
2372
  let leftPos = this.readTo(tagDelimiterLeft) - tagDelimiterLeft.length;
2387
2373
  while (this.p < this.N) {
@@ -2394,7 +2380,7 @@ var require_liquid_node = __commonJS({
2394
2380
  const end = this.p;
2395
2381
  if (begin === leftPos) {
2396
2382
  this.rawBeginAt = -1;
2397
- return new TagToken(this.input, begin, end, options2, this.file);
2383
+ return new TagToken(this.input, begin, end, options, this.file);
2398
2384
  } else {
2399
2385
  this.p = leftPos;
2400
2386
  return new HTMLToken(this.input, begin, leftPos, this.file);
@@ -2407,22 +2393,22 @@ var require_liquid_node = __commonJS({
2407
2393
  }
2408
2394
  throw this.error(`raw ${this.snapshot(this.rawBeginAt)} not closed`, begin);
2409
2395
  }
2410
- readLiquidTagTokens(options2 = defaultOptions) {
2396
+ readLiquidTagTokens(options = defaultOptions) {
2411
2397
  const tokens = [];
2412
2398
  while (this.p < this.N) {
2413
- const token = this.readLiquidTagToken(options2);
2399
+ const token = this.readLiquidTagToken(options);
2414
2400
  token && tokens.push(token);
2415
2401
  }
2416
2402
  return tokens;
2417
2403
  }
2418
- readLiquidTagToken(options2) {
2404
+ readLiquidTagToken(options) {
2419
2405
  this.skipBlank();
2420
2406
  if (this.end())
2421
2407
  return;
2422
2408
  const begin = this.p;
2423
2409
  this.readToDelimiter("\n");
2424
2410
  const end = this.p;
2425
- return new LiquidTagToken(this.input, begin, end, options2, this.file);
2411
+ return new LiquidTagToken(this.input, begin, end, options, this.file);
2426
2412
  }
2427
2413
  error(msg, pos = this.p) {
2428
2414
  return new TokenizationError(msg, new IdentifierToken(this.input, pos, this.N, this.file));
@@ -2634,12 +2620,12 @@ var require_liquid_node = __commonJS({
2634
2620
  }
2635
2621
  return new QuotedToken(this.input, begin, this.p, this.file);
2636
2622
  }
2637
- *readFileNameTemplate(options2) {
2638
- const { outputDelimiterLeft } = options2;
2623
+ *readFileNameTemplate(options) {
2624
+ const { outputDelimiterLeft } = options;
2639
2625
  const htmlStopStrings = [",", " ", "\r", "\n", " ", outputDelimiterLeft];
2640
2626
  const htmlStopStringSet = new Set(htmlStopStrings);
2641
2627
  while (this.p < this.N && !htmlStopStringSet.has(this.peek())) {
2642
- yield this.match(outputDelimiterLeft) ? this.readOutputToken(options2) : this.readHTMLToken(htmlStopStrings);
2628
+ yield this.match(outputDelimiterLeft) ? this.readOutputToken(options) : this.readHTMLToken(htmlStopStrings);
2643
2629
  }
2644
2630
  }
2645
2631
  match(word) {
@@ -2714,7 +2700,7 @@ var require_liquid_node = __commonJS({
2714
2700
  this.token = token;
2715
2701
  }
2716
2702
  };
2717
- var Tag2 = class extends TemplateImpl {
2703
+ var Tag3 = class extends TemplateImpl {
2718
2704
  static {
2719
2705
  __name(this, "Tag");
2720
2706
  }
@@ -2744,17 +2730,17 @@ var require_liquid_node = __commonJS({
2744
2730
  return hash2;
2745
2731
  }
2746
2732
  };
2747
- function createTagClass(options2) {
2748
- return class extends Tag2 {
2733
+ function createTagClass(options) {
2734
+ return class extends Tag3 {
2749
2735
  constructor(token, tokens, liquid) {
2750
2736
  super(token, tokens, liquid);
2751
- if (isFunction(options2.parse)) {
2752
- options2.parse.call(this, token, tokens);
2737
+ if (isFunction(options.parse)) {
2738
+ options.parse.call(this, token, tokens);
2753
2739
  }
2754
2740
  }
2755
2741
  *render(ctx, emitter) {
2756
2742
  const hash2 = yield new Hash(this.token.args, ctx.opts.keyValueSeparator).render(ctx);
2757
- return yield options2.render.call(this, ctx, emitter, hash2);
2743
+ return yield options.render.call(this, ctx, emitter, hash2);
2758
2744
  }
2759
2745
  };
2760
2746
  }
@@ -2971,13 +2957,13 @@ var require_liquid_node = __commonJS({
2971
2957
  };
2972
2958
  }
2973
2959
  __name(_analyze, "_analyze");
2974
- function analyze(template2, options2 = {}) {
2975
- const opts = { ...defaultStaticAnalysisOptions, ...options2 };
2960
+ function analyze(template2, options = {}) {
2961
+ const opts = { ...defaultStaticAnalysisOptions, ...options };
2976
2962
  return toPromise(_analyze(template2, opts.partials, false));
2977
2963
  }
2978
2964
  __name(analyze, "analyze");
2979
- function analyzeSync(template2, options2 = {}) {
2980
- const opts = { ...defaultStaticAnalysisOptions, ...options2 };
2965
+ function analyzeSync(template2, options = {}) {
2966
+ const opts = { ...defaultStaticAnalysisOptions, ...options };
2981
2967
  return toValueSync(_analyze(template2, opts.partials, true));
2982
2968
  }
2983
2969
  __name(analyzeSync, "analyzeSync");
@@ -3153,17 +3139,17 @@ var require_liquid_node = __commonJS({
3153
3139
  static {
3154
3140
  __name(this, "Loader");
3155
3141
  }
3156
- constructor(options2) {
3157
- this.options = options2;
3158
- if (options2.relativeReference) {
3159
- const sep = options2.fs.sep;
3142
+ constructor(options) {
3143
+ this.options = options;
3144
+ if (options.relativeReference) {
3145
+ const sep = options.fs.sep;
3160
3146
  assert(sep, "`fs.sep` is required for relative reference");
3161
3147
  const prefixes = ["." + sep, ".." + sep, "./", "../"];
3162
3148
  this.shouldLoadRelative = (referencedFile) => prefixes.some((prefix) => referencedFile.startsWith(prefix));
3163
3149
  } else {
3164
3150
  this.shouldLoadRelative = (_referencedFile) => false;
3165
3151
  }
3166
- const fs2 = options2.fs;
3152
+ const fs2 = options.fs;
3167
3153
  this.contains = toLiquidAsync(fs2.contains?.bind(fs2) || (async () => true), fs2.containsSync?.bind(fs2) || (() => true));
3168
3154
  this.exists = toLiquidAsync(fs2.exists?.bind(fs2) || (async () => false), fs2.existsSync?.bind(fs2));
3169
3155
  }
@@ -3615,7 +3601,7 @@ var require_liquid_node = __commonJS({
3615
3601
  uri_escape,
3616
3602
  slugify
3617
3603
  });
3618
- var join5 = argumentsToValue(function(v, arg) {
3604
+ var join6 = argumentsToValue(function(v, arg) {
3619
3605
  const array2 = toArray(v);
3620
3606
  const sep = isNil(arg) ? " " : stringify(arg);
3621
3607
  let outputSize = sep.length * Math.max(array2.length - 1, 0);
@@ -3891,7 +3877,7 @@ var require_liquid_node = __commonJS({
3891
3877
  __name(sample, "sample");
3892
3878
  var arrayFilters = /* @__PURE__ */ Object.freeze({
3893
3879
  __proto__: null,
3894
- join: join5,
3880
+ join: join6,
3895
3881
  last,
3896
3882
  first,
3897
3883
  reverse,
@@ -4313,7 +4299,7 @@ var require_liquid_node = __commonJS({
4313
4299
  ...cryptoFilters,
4314
4300
  ...misc
4315
4301
  };
4316
- var AssignTag = class extends Tag2 {
4302
+ var AssignTag = class extends Tag3 {
4317
4303
  static {
4318
4304
  __name(this, "AssignTag");
4319
4305
  }
@@ -4338,7 +4324,7 @@ var require_liquid_node = __commonJS({
4338
4324
  }
4339
4325
  };
4340
4326
  var MODIFIERS = ["offset", "limit", "reversed"];
4341
- var ForTag = class extends Tag2 {
4327
+ var ForTag = class extends Tag3 {
4342
4328
  static {
4343
4329
  __name(this, "ForTag");
4344
4330
  }
@@ -4431,7 +4417,7 @@ var require_liquid_node = __commonJS({
4431
4417
  return arr.slice(0, count3);
4432
4418
  }
4433
4419
  __name(limit2, "limit");
4434
- var CaptureTag = class extends Tag2 {
4420
+ var CaptureTag = class extends Tag3 {
4435
4421
  static {
4436
4422
  __name(this, "CaptureTag");
4437
4423
  }
@@ -4469,7 +4455,7 @@ var require_liquid_node = __commonJS({
4469
4455
  yield this.identifier;
4470
4456
  }
4471
4457
  };
4472
- var CaseTag = class extends Tag2 {
4458
+ var CaseTag = class extends Tag3 {
4473
4459
  static {
4474
4460
  __name(this, "CaseTag");
4475
4461
  }
@@ -4542,7 +4528,7 @@ var require_liquid_node = __commonJS({
4542
4528
  return templates;
4543
4529
  }
4544
4530
  };
4545
- var CommentTag = class extends Tag2 {
4531
+ var CommentTag = class extends Tag3 {
4546
4532
  static {
4547
4533
  __name(this, "CommentTag");
4548
4534
  }
@@ -4558,7 +4544,7 @@ var require_liquid_node = __commonJS({
4558
4544
  render() {
4559
4545
  }
4560
4546
  };
4561
- var RenderTag = class extends Tag2 {
4547
+ var RenderTag = class extends Tag3 {
4562
4548
  static {
4563
4549
  __name(this, "RenderTag");
4564
4550
  }
@@ -4705,7 +4691,7 @@ var require_liquid_node = __commonJS({
4705
4691
  return yield evalToken(file2, ctx);
4706
4692
  }
4707
4693
  __name(renderFilePath, "renderFilePath");
4708
- var IncludeTag = class extends Tag2 {
4694
+ var IncludeTag = class extends Tag3 {
4709
4695
  static {
4710
4696
  __name(this, "IncludeTag");
4711
4697
  }
@@ -4773,7 +4759,7 @@ var require_liquid_node = __commonJS({
4773
4759
  }
4774
4760
  }
4775
4761
  };
4776
- var DecrementTag = class extends Tag2 {
4762
+ var DecrementTag = class extends Tag3 {
4777
4763
  static {
4778
4764
  __name(this, "DecrementTag");
4779
4765
  }
@@ -4793,7 +4779,7 @@ var require_liquid_node = __commonJS({
4793
4779
  yield this.identifier;
4794
4780
  }
4795
4781
  };
4796
- var CycleTag = class extends Tag2 {
4782
+ var CycleTag = class extends Tag3 {
4797
4783
  static {
4798
4784
  __name(this, "CycleTag");
4799
4785
  }
@@ -4837,7 +4823,7 @@ var require_liquid_node = __commonJS({
4837
4823
  }
4838
4824
  }
4839
4825
  };
4840
- var IfTag = class extends Tag2 {
4826
+ var IfTag = class extends Tag3 {
4841
4827
  static {
4842
4828
  __name(this, "IfTag");
4843
4829
  }
@@ -4887,7 +4873,7 @@ var require_liquid_node = __commonJS({
4887
4873
  return this.branches.map((b) => b.value);
4888
4874
  }
4889
4875
  };
4890
- var IncrementTag = class extends Tag2 {
4876
+ var IncrementTag = class extends Tag3 {
4891
4877
  static {
4892
4878
  __name(this, "IncrementTag");
4893
4879
  }
@@ -4909,7 +4895,7 @@ var require_liquid_node = __commonJS({
4909
4895
  yield this.identifier;
4910
4896
  }
4911
4897
  };
4912
- var LayoutTag = class extends Tag2 {
4898
+ var LayoutTag = class extends Tag3 {
4913
4899
  static {
4914
4900
  __name(this, "LayoutTag");
4915
4901
  }
@@ -4964,7 +4950,7 @@ var require_liquid_node = __commonJS({
4964
4950
  }
4965
4951
  }
4966
4952
  };
4967
- var BlockTag = class extends Tag2 {
4953
+ var BlockTag = class extends Tag3 {
4968
4954
  static {
4969
4955
  __name(this, "BlockTag");
4970
4956
  }
@@ -5013,7 +4999,7 @@ var require_liquid_node = __commonJS({
5013
4999
  return ["block"];
5014
5000
  }
5015
5001
  };
5016
- var RawTag = class extends Tag2 {
5002
+ var RawTag = class extends Tag3 {
5017
5003
  static {
5018
5004
  __name(this, "RawTag");
5019
5005
  }
@@ -5057,7 +5043,7 @@ var require_liquid_node = __commonJS({
5057
5043
  return this.col() === this.cols;
5058
5044
  }
5059
5045
  };
5060
- var TablerowTag = class extends Tag2 {
5046
+ var TablerowTag = class extends Tag3 {
5061
5047
  static {
5062
5048
  __name(this, "TablerowTag");
5063
5049
  }
@@ -5121,7 +5107,7 @@ var require_liquid_node = __commonJS({
5121
5107
  return [this.variable, "tablerowloop"];
5122
5108
  }
5123
5109
  };
5124
- var UnlessTag = class extends Tag2 {
5110
+ var UnlessTag = class extends Tag3 {
5125
5111
  static {
5126
5112
  __name(this, "UnlessTag");
5127
5113
  }
@@ -5180,7 +5166,7 @@ var require_liquid_node = __commonJS({
5180
5166
  return this.branches.map((b) => b.value);
5181
5167
  }
5182
5168
  };
5183
- var BreakTag = class extends Tag2 {
5169
+ var BreakTag = class extends Tag3 {
5184
5170
  static {
5185
5171
  __name(this, "BreakTag");
5186
5172
  }
@@ -5188,7 +5174,7 @@ var require_liquid_node = __commonJS({
5188
5174
  ctx.breakCalled = true;
5189
5175
  }
5190
5176
  };
5191
- var ContinueTag = class extends Tag2 {
5177
+ var ContinueTag = class extends Tag3 {
5192
5178
  static {
5193
5179
  __name(this, "ContinueTag");
5194
5180
  }
@@ -5196,7 +5182,7 @@ var require_liquid_node = __commonJS({
5196
5182
  ctx.continueCalled = true;
5197
5183
  }
5198
5184
  };
5199
- var EchoTag = class extends Tag2 {
5185
+ var EchoTag = class extends Tag3 {
5200
5186
  static {
5201
5187
  __name(this, "EchoTag");
5202
5188
  }
@@ -5219,7 +5205,7 @@ var require_liquid_node = __commonJS({
5219
5205
  }
5220
5206
  }
5221
5207
  };
5222
- var LiquidTag = class extends Tag2 {
5208
+ var LiquidTag = class extends Tag3 {
5223
5209
  static {
5224
5210
  __name(this, "LiquidTag");
5225
5211
  }
@@ -5235,7 +5221,7 @@ var require_liquid_node = __commonJS({
5235
5221
  return this.templates;
5236
5222
  }
5237
5223
  };
5238
- var InlineCommentTag = class extends Tag2 {
5224
+ var InlineCommentTag = class extends Tag3 {
5239
5225
  static {
5240
5226
  __name(this, "InlineCommentTag");
5241
5227
  }
@@ -5378,76 +5364,76 @@ var require_liquid_node = __commonJS({
5378
5364
  self.renderFile(filePath, ctx).then((html) => callback(null, html), callback);
5379
5365
  };
5380
5366
  }
5381
- async analyze(template2, options2 = {}) {
5382
- return analyze(template2, options2);
5367
+ async analyze(template2, options = {}) {
5368
+ return analyze(template2, options);
5383
5369
  }
5384
- analyzeSync(template2, options2 = {}) {
5385
- return analyzeSync(template2, options2);
5370
+ analyzeSync(template2, options = {}) {
5371
+ return analyzeSync(template2, options);
5386
5372
  }
5387
- async parseAndAnalyze(html, filename, options2 = {}) {
5388
- return analyze(this.parse(html, filename), options2);
5373
+ async parseAndAnalyze(html, filename, options = {}) {
5374
+ return analyze(this.parse(html, filename), options);
5389
5375
  }
5390
- parseAndAnalyzeSync(html, filename, options2 = {}) {
5391
- return analyzeSync(this.parse(html, filename), options2);
5376
+ parseAndAnalyzeSync(html, filename, options = {}) {
5377
+ return analyzeSync(this.parse(html, filename), options);
5392
5378
  }
5393
5379
  /** Return an array of all variables without their properties. */
5394
- async variables(template2, options2 = {}) {
5395
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5380
+ async variables(template2, options = {}) {
5381
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5396
5382
  return Object.keys(analysis.variables);
5397
5383
  }
5398
5384
  /** Return an array of all variables without their properties. */
5399
- variablesSync(template2, options2 = {}) {
5400
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5385
+ variablesSync(template2, options = {}) {
5386
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5401
5387
  return Object.keys(analysis.variables);
5402
5388
  }
5403
5389
  /** Return an array of all variables including their properties/paths. */
5404
- async fullVariables(template2, options2 = {}) {
5405
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5390
+ async fullVariables(template2, options = {}) {
5391
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5406
5392
  return Array.from(new Set(Object.values(analysis.variables).flatMap((a) => a.map((v) => String(v)))));
5407
5393
  }
5408
5394
  /** Return an array of all variables including their properties/paths. */
5409
- fullVariablesSync(template2, options2 = {}) {
5410
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5395
+ fullVariablesSync(template2, options = {}) {
5396
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5411
5397
  return Array.from(new Set(Object.values(analysis.variables).flatMap((a) => a.map((v) => String(v)))));
5412
5398
  }
5413
5399
  /** Return an array of all variables, each as an array of properties/segments. */
5414
- async variableSegments(template2, options2 = {}) {
5415
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5400
+ async variableSegments(template2, options = {}) {
5401
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5416
5402
  return Array.from(strictUniq(Object.values(analysis.variables).flatMap((a) => a.map((v) => v.toArray()))));
5417
5403
  }
5418
5404
  /** Return an array of all variables, each as an array of properties/segments. */
5419
- variableSegmentsSync(template2, options2 = {}) {
5420
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5405
+ variableSegmentsSync(template2, options = {}) {
5406
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5421
5407
  return Array.from(strictUniq(Object.values(analysis.variables).flatMap((a) => a.map((v) => v.toArray()))));
5422
5408
  }
5423
5409
  /** Return an array of all expected context variables without their properties. */
5424
- async globalVariables(template2, options2 = {}) {
5425
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5410
+ async globalVariables(template2, options = {}) {
5411
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5426
5412
  return Object.keys(analysis.globals);
5427
5413
  }
5428
5414
  /** Return an array of all expected context variables without their properties. */
5429
- globalVariablesSync(template2, options2 = {}) {
5430
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5415
+ globalVariablesSync(template2, options = {}) {
5416
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5431
5417
  return Object.keys(analysis.globals);
5432
5418
  }
5433
5419
  /** Return an array of all expected context variables including their properties/paths. */
5434
- async globalFullVariables(template2, options2 = {}) {
5435
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5420
+ async globalFullVariables(template2, options = {}) {
5421
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5436
5422
  return Array.from(new Set(Object.values(analysis.globals).flatMap((a) => a.map((v) => String(v)))));
5437
5423
  }
5438
5424
  /** Return an array of all expected context variables including their properties/paths. */
5439
- globalFullVariablesSync(template2, options2 = {}) {
5440
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5425
+ globalFullVariablesSync(template2, options = {}) {
5426
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5441
5427
  return Array.from(new Set(Object.values(analysis.globals).flatMap((a) => a.map((v) => String(v)))));
5442
5428
  }
5443
5429
  /** Return an array of all expected context variables, each as an array of properties/segments. */
5444
- async globalVariableSegments(template2, options2 = {}) {
5445
- const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options2);
5430
+ async globalVariableSegments(template2, options = {}) {
5431
+ const analysis = await analyze(isString(template2) ? this.parse(template2) : template2, options);
5446
5432
  return Array.from(strictUniq(Object.values(analysis.globals).flatMap((a) => a.map((v) => v.toArray()))));
5447
5433
  }
5448
5434
  /** Return an array of all expected context variables, each as an array of properties/segments. */
5449
- globalVariableSegmentsSync(template2, options2 = {}) {
5450
- const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options2);
5435
+ globalVariableSegmentsSync(template2, options = {}) {
5436
+ const analysis = analyzeSync(isString(template2) ? this.parse(template2) : template2, options);
5451
5437
  return Array.from(strictUniq(Object.values(analysis.globals).flatMap((a) => a.map((v) => v.toArray()))));
5452
5438
  }
5453
5439
  };
@@ -5485,7 +5471,7 @@ var require_liquid_node = __commonJS({
5485
5471
  exports.RenderError = RenderError;
5486
5472
  exports.RenderTag = RenderTag;
5487
5473
  exports.TablerowTag = TablerowTag;
5488
- exports.Tag = Tag2;
5474
+ exports.Tag = Tag3;
5489
5475
  exports.TagToken = TagToken;
5490
5476
  exports.Token = Token;
5491
5477
  exports.TokenizationError = TokenizationError;
@@ -5515,11 +5501,11 @@ var require_liquid_node = __commonJS({
5515
5501
  }
5516
5502
  });
5517
5503
 
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
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";
5520
- import { dirname as dirname2, resolve } from "node:path";
5504
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5505
+ import { chmodSync, constants, copyFileSync, existsSync as existsSync10, mkdirSync, realpathSync as realpathSync3, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
5506
+ import { dirname as dirname3, resolve } from "node:path";
5521
5507
 
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
5508
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/sealed.js
5523
5509
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5524
5510
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5525
5511
  import { Transform } from "node:stream";
@@ -5626,7 +5612,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5626
5612
  renameSync(pending, to);
5627
5613
  }, "unsealFile");
5628
5614
 
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
5615
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5630
5616
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5631
5617
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5632
5618
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5650,7 +5636,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5650
5636
  };
5651
5637
  }, "compatibilityOf");
5652
5638
 
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
5639
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/store/repair.js
5654
5640
  import { createHash as createHash2 } from "node:crypto";
5655
5641
  var COPY_MARK = "__repair_";
5656
5642
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5904,17 +5890,99 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5904
5890
  return found;
5905
5891
  }, "deleteCopy");
5906
5892
 
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
5893
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5908
5894
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5909
5895
 
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
5896
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5911
5897
  import { existsSync as existsSync3 } from "node:fs";
5912
5898
 
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
5899
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/store/recover.js
5914
5900
  import { execFileSync, spawn } from "node:child_process";
5915
5901
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5916
5902
  import { basename, dirname, join } from "node:path";
5917
5903
  import { Transform as Transform2 } from "node:stream";
5904
+
5905
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/store/refill.js
5906
+ var REFILL_MARGIN_MS = 864e5;
5907
+ var TIME_KEYS = 1e12;
5908
+ var integerId = `external_id GLOB '[0-9]*' AND NOT external_id GLOB '*[^0-9]*'`;
5909
+ var forgetCoverageSince = /* @__PURE__ */ __name((database, cutoff, now = Date.now()) => {
5910
+ database.exec("BEGIN");
5911
+ try {
5912
+ const refetch = forget(database, cutoff, now);
5913
+ database.exec("COMMIT");
5914
+ return refetch;
5915
+ } catch (error) {
5916
+ database.exec("ROLLBACK");
5917
+ throw error;
5918
+ }
5919
+ }, "forgetCoverageSince");
5920
+ var forget = /* @__PURE__ */ __name((database, cutoff, now) => {
5921
+ const chats = /* @__PURE__ */ new Map();
5922
+ const held = database.prepare(`SELECT c.id, c.account_id, c.external_id AS chat, a.provider, a.external_id AS account,
5923
+ max(r.to_key) AS top FROM sync_ranges r JOIN chats c ON c.id = r.chat_id JOIN accounts a ON a.id = c.account_id
5924
+ GROUP BY c.id`).all();
5925
+ for (const row of held) {
5926
+ const chat = Number(row.id);
5927
+ const top = Number(row.top);
5928
+ const keepTo = cutoff === null ? null : top >= TIME_KEYS ? cutoff : database.prepare(`SELECT max(CAST(external_id AS INTEGER)) AS k FROM messages WHERE chat_id = ? AND sent_at < ? AND ${integerId}`).get(chat, cutoff)?.k;
5929
+ if (keepTo !== null && top <= keepTo)
5930
+ continue;
5931
+ if (keepTo === null)
5932
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ?").run(chat);
5933
+ else {
5934
+ database.prepare("DELETE FROM sync_ranges WHERE chat_id = ? AND from_key > ?").run(chat, keepTo);
5935
+ database.prepare("UPDATE sync_ranges SET to_key = ?, updated_at = ? WHERE chat_id = ? AND to_key > ?").run(keepTo, now, chat, keepTo);
5936
+ }
5937
+ const account = Number(row.account_id);
5938
+ const external = String(row.chat);
5939
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(account, `fetched:${external}`);
5940
+ database.prepare(`DELETE FROM sync_cursors WHERE account_id = ? AND key = ? AND NOT EXISTS
5941
+ (SELECT 1 FROM sync_ranges WHERE chat_id = ? AND from_key <= CAST(sync_cursors.value AS INTEGER))`).run(account, `history_start:${external}`, chat);
5942
+ const key = `${row.provider}\0${row.account}`;
5943
+ const one = chats.get(key) ?? { provider: String(row.provider), account: String(row.account), chats: 0 };
5944
+ one.chats += 1;
5945
+ chats.set(key, one);
5946
+ }
5947
+ return {
5948
+ since: cutoff === null ? null : new Date(cutoff).toISOString(),
5949
+ chats: [...chats.values()],
5950
+ mail: forgetMail(database, cutoff, now)
5951
+ };
5952
+ }, "forget");
5953
+ var forgetMail = /* @__PURE__ */ __name((database, cutoff, now) => {
5954
+ const folders = /* @__PURE__ */ new Map();
5955
+ const points = database.prepare(`SELECT s.account_id, s.key, s.value, a.external_id AS account FROM sync_cursors s
5956
+ JOIN accounts a ON a.id = s.account_id WHERE a.provider = 'email' AND s.key LIKE 'mail_resume:%'`).all();
5957
+ for (const row of points) {
5958
+ let point;
5959
+ try {
5960
+ point = JSON.parse(String(row.value));
5961
+ } catch {
5962
+ continue;
5963
+ }
5964
+ const account = String(row.account);
5965
+ if (!Array.isArray(point.done)) {
5966
+ if (cutoff !== null && Date.parse(point.updatedAt ?? "") < cutoff)
5967
+ continue;
5968
+ database.prepare("DELETE FROM sync_cursors WHERE account_id = ? AND key = ?").run(Number(row.account_id), String(row.key));
5969
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5970
+ continue;
5971
+ }
5972
+ const folder = String(row.key).slice("mail_resume:".length);
5973
+ const last = cutoff === null ? null : database.prepare(`SELECT max(l.uid) AS uid FROM email_locations l JOIN emails e ON e.id = l.email_id
5974
+ WHERE l.mailbox_id = (SELECT id FROM mailboxes WHERE account_id = ? AND external_id = ?)
5975
+ AND l.uidvalidity = ? AND coalesce(e.received_at, e.sent_at) < ?`).get(Number(row.account_id), folder, point.validity ?? "", cutoff)?.uid;
5976
+ const done = last === null ? [] : point.done.filter(([from]) => from <= last).map(([from, to]) => [from, Math.min(to, last)]);
5977
+ if (JSON.stringify(done) === JSON.stringify(point.done))
5978
+ continue;
5979
+ database.prepare("UPDATE sync_cursors SET value = ?, updated_at = ? WHERE account_id = ? AND key = ?").run(JSON.stringify({ ...point, done }), now, Number(row.account_id), String(row.key));
5980
+ folders.set(account, (folders.get(account) ?? 0) + 1);
5981
+ }
5982
+ return [...folders].map(([account, count3]) => ({ account, folders: count3 }));
5983
+ }, "forgetMail");
5984
+
5985
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/store/recover.js
5918
5986
  var SQLITE3_MINIMUM = [3, 43, 0];
5919
5987
  var STORE_PARTS = ["", "-wal", "-shm"];
5920
5988
  var RECOVER_LOCK = ".recover-lock";
@@ -6009,9 +6077,12 @@ var storeHolders = /* @__PURE__ */ __name((path) => {
6009
6077
  return { pid, name };
6010
6078
  });
6011
6079
  }, "storeHolders");
6012
- var tableRows = /* @__PURE__ */ __name((database) => {
6080
+ var dataTables = /* @__PURE__ */ __name((database) => {
6013
6081
  const indexes = fts5Tables(database).map((index) => index.name);
6014
- const tables = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND rootpage > 0 AND name NOT LIKE 'sqlite_%' AND name NOT LIKE 'vector_index_%' ORDER BY name").all().map((row) => String(row.name)).filter((name) => !indexes.some((index) => name.startsWith(`${index}_`)));
6082
+ return database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND rootpage > 0 AND name NOT LIKE 'sqlite_%' AND name NOT LIKE 'vector_index_%' ORDER BY name").all().map((row) => String(row.name)).filter((name) => !indexes.some((index) => name.startsWith(`${index}_`)));
6083
+ }, "dataTables");
6084
+ var tableRows = /* @__PURE__ */ __name((database) => {
6085
+ const tables = dataTables(database);
6015
6086
  return Object.fromEntries(tables.map((table) => {
6016
6087
  try {
6017
6088
  return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
@@ -6020,6 +6091,117 @@ var tableRows = /* @__PURE__ */ __name((database) => {
6020
6091
  }
6021
6092
  }));
6022
6093
  }, "tableRows");
6094
+ var sourceTables = /* @__PURE__ */ __name((database) => {
6095
+ const withoutRowid = new Set(database.prepare("SELECT name FROM pragma_table_list WHERE wr = 1").all().map((row) => String(row.name)));
6096
+ return dataTables(database).filter((table) => table !== LOST_AND_FOUND && !withoutRowid.has(table) && !isDerivedTable(table));
6097
+ }, "sourceTables");
6098
+ var indexedButGone = /* @__PURE__ */ __name((database) => {
6099
+ const found = {};
6100
+ for (const table of sourceTables(database)) {
6101
+ const indexes = database.prepare("SELECT name FROM pragma_index_list(?) WHERE partial = 0 ORDER BY name").all(table).map((row) => String(row.name));
6102
+ for (const index of indexes) {
6103
+ const columns = database.prepare("SELECT cid, name FROM pragma_index_xinfo(?) WHERE key = 1 ORDER BY seqno").all(index);
6104
+ if (columns.some((column) => Number(column.cid) < 0))
6105
+ continue;
6106
+ const keys = columns.map((column) => `"${String(column.name)}"`).join(", ");
6107
+ const grouped = `${keys}, row_id`;
6108
+ let rows;
6109
+ try {
6110
+ rows = Number(database.prepare(`SELECT count(*) AS n FROM (SELECT 1 FROM (SELECT ${keys}, rowid AS row_id, 1 AS side FROM "${table}" INDEXED BY "${index}" UNION ALL SELECT ${keys}, rowid, 2 FROM "${table}" NOT INDEXED) GROUP BY ${grouped} HAVING max(side) = 1)`).get()?.n);
6111
+ } catch {
6112
+ continue;
6113
+ }
6114
+ if (rows > (found[table]?.rows ?? 0))
6115
+ found[table] = { rows, index };
6116
+ }
6117
+ }
6118
+ return found;
6119
+ }, "indexedButGone");
6120
+ var storedAs = /* @__PURE__ */ __name((declared) => {
6121
+ const type = declared.toUpperCase();
6122
+ if (type.includes("INT"))
6123
+ return ["integer"];
6124
+ if (/CHAR|CLOB|TEXT/.test(type))
6125
+ return ["text"];
6126
+ if (type === "" || type.includes("BLOB"))
6127
+ return null;
6128
+ if (/REAL|FLOA|DOUB/.test(type))
6129
+ return ["real", "integer"];
6130
+ return null;
6131
+ }, "storedAs");
6132
+ var columnsOf = /* @__PURE__ */ __name((database, table) => {
6133
+ const all = database.prepare('SELECT name, type, "notnull" AS required, dflt_value, pk FROM pragma_table_info(?)').all(table);
6134
+ const keys = all.filter((column) => Number(column.pk) > 0);
6135
+ return all.map((column) => ({
6136
+ name: String(column.name),
6137
+ type: String(column.type),
6138
+ required: Number(column.required) === 1,
6139
+ hasDefault: column.dflt_value !== null,
6140
+ rowid: keys.length === 1 && Number(column.pk) === 1 && String(column.type).toUpperCase() === "INTEGER"
6141
+ }));
6142
+ }, "columnsOf");
6143
+ var fits = /* @__PURE__ */ __name((columns, fields, types) => fields <= columns.length && columns.every((column, at) => {
6144
+ if (at >= fields)
6145
+ return !column.required || column.hasDefault;
6146
+ const type = types[at];
6147
+ if (column.rowid)
6148
+ return type === "null" || type === "integer";
6149
+ if (type === "null")
6150
+ return !column.required;
6151
+ const allowed = storedAs(column.type);
6152
+ return allowed === null || allowed.includes(type);
6153
+ }), "fits");
6154
+ var placeLostRows = /* @__PURE__ */ __name((database) => {
6155
+ if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND))
6156
+ return {};
6157
+ const fields = database.prepare("SELECT name FROM pragma_table_info(?) WHERE name GLOB 'c[0-9]*'").all(LOST_AND_FOUND).map((row) => String(row.name));
6158
+ const tables = sourceTables(database).map((table) => ({ table, columns: columnsOf(database, table) }));
6159
+ const rows = database.prepare(`SELECT rowid AS at, nfield, ${fields.map((field) => `typeof(${field}) AS "${field}"`).join(", ")} FROM ${LOST_AND_FOUND} WHERE id IS NOT NULL`).all();
6160
+ const placed = {};
6161
+ const triggers = [];
6162
+ const quiet = /* @__PURE__ */ __name((table) => {
6163
+ if (table in placed)
6164
+ return;
6165
+ placed[table] = 0;
6166
+ for (const row of database.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?").all(table)) {
6167
+ triggers.push(String(row.sql));
6168
+ database.exec(`DROP TRIGGER "${String(row.name)}"`);
6169
+ }
6170
+ }, "quiet");
6171
+ database.exec("PRAGMA foreign_keys = OFF");
6172
+ database.exec("BEGIN");
6173
+ try {
6174
+ for (const row of rows) {
6175
+ const count3 = Number(row.nfield);
6176
+ const types = fields.slice(0, count3).map((field) => String(row[field]));
6177
+ const fitting = tables.filter(({ columns: columns2 }) => fits(columns2, count3, types));
6178
+ if (fitting.length !== 1)
6179
+ continue;
6180
+ const { table, columns } = fitting[0];
6181
+ quiet(table);
6182
+ const given = columns.slice(0, count3);
6183
+ const names = [...given.some((column) => column.rowid) ? [] : ["rowid"], ...given.map((column) => column.name)];
6184
+ const values = [
6185
+ ...given.some((column) => column.rowid) ? [] : ["id"],
6186
+ ...given.map((column, at) => column.rowid ? "id" : `c${at}`)
6187
+ ];
6188
+ const inserted = database.prepare(`INSERT OR IGNORE INTO "${table}" (${names.map((name) => `"${name}"`).join(", ")}) SELECT ${values.join(", ")} FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6189
+ if (Number(inserted.changes) === 0)
6190
+ continue;
6191
+ placed[table] = (placed[table] ?? 0) + 1;
6192
+ database.prepare(`DELETE FROM ${LOST_AND_FOUND} WHERE rowid = ?`).run(Number(row.at));
6193
+ }
6194
+ for (const sql of triggers)
6195
+ database.exec(sql);
6196
+ database.exec("COMMIT");
6197
+ } catch (error) {
6198
+ database.exec("ROLLBACK");
6199
+ throw error;
6200
+ } finally {
6201
+ database.exec("PRAGMA foreign_keys = ON");
6202
+ }
6203
+ return Object.fromEntries(Object.entries(placed).filter(([, rows2]) => rows2 > 0));
6204
+ }, "placeLostRows");
6023
6205
  var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
6024
6206
  const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
6025
6207
  stdio: ["ignore", "pipe", "pipe"]
@@ -6216,6 +6398,9 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6216
6398
  throw error;
6217
6399
  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
6400
  }
6401
+ note("looking for rows the indexes list and the tables no longer hold");
6402
+ const gone = indexedButGone(watch);
6403
+ const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
6219
6404
  const before = { data: dataVersion(), inode: statSync2(path).ino };
6220
6405
  const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
6221
6406
  const target = `${path}.recovering-${stamp}`;
@@ -6242,9 +6427,12 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6242
6427
  let kept;
6243
6428
  let dangling;
6244
6429
  let json;
6245
- let fetch2;
6430
+ let fetch;
6246
6431
  let schema;
6432
+ let placed;
6433
+ let refetch;
6247
6434
  try {
6435
+ placed = placeLostRows(opened.database);
6248
6436
  kept = tableRows(opened.database);
6249
6437
  migrate(opened.database, { command, ...version ? { version } : {} });
6250
6438
  note("clearing values that are not valid JSON");
@@ -6252,7 +6440,9 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6252
6440
  rebuilt = rebuildDerived(opened.database, { now, note });
6253
6441
  note("looking for rows that point at rows that were lost");
6254
6442
  dangling = danglingRows(opened.database);
6255
- fetch2 = mailToFetch(opened.database);
6443
+ fetch = mailToFetch(opened.database);
6444
+ const good = lastKnownGood === null ? Number.NaN : Date.parse(lastKnownGood);
6445
+ refetch = forgetCoverageSince(opened.database, Number.isNaN(good) ? null : good - REFILL_MARGIN_MS, now());
6256
6446
  schema = fileSchemaOf(opened.database).version;
6257
6447
  opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
6258
6448
  } catch (error) {
@@ -6282,16 +6472,29 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6282
6472
  if (existsSync2(`${target}${suffix}`))
6283
6473
  renameSync2(`${target}${suffix}`, `${path}${suffix}`);
6284
6474
  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);
6475
+ const lost = Object.entries(rowsBefore).map(([table, before2]) => {
6476
+ const goneAtLeast = Math.max(0, (gone[table]?.rows ?? 0) - (placed[table] ?? 0));
6477
+ return {
6478
+ table,
6479
+ before: before2,
6480
+ read: read[table] ?? 0,
6481
+ kept: kept[table] ?? 0,
6482
+ goneAtLeast,
6483
+ seenIn: goneAtLeast > 0 ? gone[table]?.index ?? null : null
6484
+ };
6485
+ }).filter(({ before: before2, read: read2, kept: kept2, goneAtLeast }) => before2 === null || before2 > kept2 || read2 > kept2 || goneAtLeast > 0);
6286
6486
  const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
6287
6487
  return {
6288
6488
  path,
6289
6489
  keptAt,
6290
6490
  sqlite3: program.version,
6291
6491
  lost,
6492
+ placed,
6493
+ lastKnownGood,
6292
6494
  dangling,
6293
6495
  invalidJson: json,
6294
- mailToFetch: fetch2,
6496
+ mailToFetch: fetch,
6497
+ refetch,
6295
6498
  rebuilt,
6296
6499
  copyErrors,
6297
6500
  health,
@@ -6307,7 +6510,7 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6307
6510
  }
6308
6511
  }, "recoverLocked");
6309
6512
 
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
6513
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6311
6514
  var COUNTED = [
6312
6515
  "accounts",
6313
6516
  "chats",
@@ -6394,12 +6597,28 @@ var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, no
6394
6597
  next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
6395
6598
  };
6396
6599
  }, "storeRecoveryRun");
6600
+ var refetchNotes = /* @__PURE__ */ __name(({ since, chats, mail }) => {
6601
+ const from = since === null ? "from the start" : `from ${since} on`;
6602
+ const marked = [
6603
+ ...chats.map(({ provider, account, chats: chats2 }) => `${chats2} chats of ${provider} ${account}`),
6604
+ ...mail.map(({ account, folders }) => `${folders} mail folders of ${account}`)
6605
+ ];
6606
+ return [
6607
+ marked.length > 0 ? `marked as not fetched ${from}, so the next sync or serve fetches it again: ${marked.join(", ")}` : `nothing held ${from} was marked as fetched, so there is nothing to fetch again`,
6608
+ ...chats.filter(({ provider }) => provider === "whatsapp").map(({ account }) => `whatsapp ${account}: WhatsApp cannot be asked for its chats, so only what the phone pushes while serve runs comes back`),
6609
+ "notes, memories, tags and whatever else only this store held cannot be fetched again"
6610
+ ];
6611
+ }, "refetchNotes");
6397
6612
  var recoveryNotes = /* @__PURE__ */ __name((answer) => {
6398
6613
  if ("keptAt" in answer) {
6399
- const lost = answer.lost.map(({ table, before, read, kept }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}`);
6614
+ const lost = answer.lost.map(({ table, before, read, kept, goneAtLeast, seenIn }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}` + (goneAtLeast > 0 ? `; at least ${goneAtLeast} rows are gone (the index ${seenIn} lists them)` : ""));
6615
+ const since = answer.lastKnownGood ? `since the last deep check that passed (${answer.lastKnownGood})` : "since the store was made (no deep check that passed is on record)";
6400
6616
  return [
6401
6617
  `recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
6402
- ...lost.length ? lost : ["no table lost a row"],
6618
+ ...lost,
6619
+ ...Object.entries(answer.placed).map(([table, rows]) => `${table}: ${rows} rows found on pages no table claimed were put back`),
6620
+ ...refetchNotes(answer.refetch),
6621
+ `${lost.some((line) => line.includes("are gone")) ? "more rows may be gone" : "how many rows were lost is unknown"}: damage can take rows written ${since} without leaving a trace; a sync fetches again what the servers still hold`,
6403
6622
  ...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
6404
6623
  ...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
6405
6624
  ...answer.next.map((line) => `next: ${line}`)
@@ -6440,7 +6659,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6440
6659
  return recover;
6441
6660
  }, "storeRecoverCommand");
6442
6661
 
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
6662
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6444
6663
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6445
6664
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6446
6665
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6486,7 +6705,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6486
6705
  renderAnswer(this, outputFor(this), itemOf(answer));
6487
6706
  }), "storeInfoCommand");
6488
6707
 
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
6708
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6490
6709
  var ENCRYPT_OPTION = [
6491
6710
  "--encrypt",
6492
6711
  "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"
@@ -6505,7 +6724,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6505
6724
  return password;
6506
6725
  }, "passwordOf");
6507
6726
 
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
6727
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/rules.js
6509
6728
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6510
6729
  import { join as join2 } from "node:path";
6511
6730
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6676,7 +6895,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6676
6895
  }, "problem");
6677
6896
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6678
6897
 
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
6898
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/state.js
6680
6899
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6681
6900
  import { join as join3 } from "node:path";
6682
6901
  var ANSWERED_KEPT = 1e3;
@@ -6729,7 +6948,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6729
6948
  }, "recordReply");
6730
6949
  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");
6731
6950
 
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
6951
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/decide.js
6733
6952
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6734
6953
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6735
6954
  const { message, chat, owner, sender } = incoming;
@@ -6835,8 +7054,37 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
6835
7054
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
6836
7055
  }, "filled");
6837
7056
 
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
7057
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/template.js
7058
+ var import_liquidjs2 = __toESM(require_liquid_node(), 1);
7059
+
7060
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/render/liquid.js
6839
7061
  var import_liquidjs = __toESM(require_liquid_node(), 1);
7062
+ var safeLiquid = /* @__PURE__ */ __name((limits) => {
7063
+ const engine = new import_liquidjs.Liquid({
7064
+ ownPropertyOnly: true,
7065
+ strictVariables: true,
7066
+ strictFilters: true,
7067
+ lenientIf: false,
7068
+ parseLimit: limits.parse,
7069
+ renderLimit: limits.milliseconds,
7070
+ memoryLimit: limits.memory,
7071
+ preserveTimezones: true
7072
+ });
7073
+ for (const name of ["include", "render", "layout"]) {
7074
+ engine.registerTag(name, class extends import_liquidjs.Tag {
7075
+ constructor(token, tokens, liquid) {
7076
+ super(token, tokens, liquid);
7077
+ throw new Error("templates cannot read files");
7078
+ }
7079
+ render() {
7080
+ return "";
7081
+ }
7082
+ });
7083
+ }
7084
+ return engine;
7085
+ }, "safeLiquid");
7086
+
7087
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/template.js
6840
7088
  var TEMPLATE_LIMITS = {
6841
7089
  parse: 32768,
6842
7090
  renders: 2e3,
@@ -6890,28 +7138,8 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6890
7138
  hourCycle: "h23"
6891
7139
  }).formatToParts(input.now).map(({ type, value }) => [type, value]));
6892
7140
  const localTime = `${parts2.year}-${parts2.month}-${parts2.day}T${parts2.hour}:${parts2.minute}:${parts2.second}${parts2.timeZoneName?.replace("GMT", "") || "+00:00"}`;
6893
- const engine = new import_liquidjs.Liquid({
6894
- ownPropertyOnly: true,
6895
- strictVariables: true,
6896
- strictFilters: true,
6897
- lenientIf: false,
6898
- parseLimit: limits.parse,
6899
- renderLimit: limits.milliseconds,
6900
- memoryLimit: limits.memory,
6901
- preserveTimezones: true
6902
- });
6903
- for (const name2 of ["include", "render", "layout"]) {
6904
- engine.registerTag(name2, class extends import_liquidjs.Tag {
6905
- constructor(token, tokens, liquid) {
6906
- super(token, tokens, liquid);
6907
- throw new Error("reply templates cannot read files");
6908
- }
6909
- render() {
6910
- return "";
6911
- }
6912
- });
6913
- }
6914
- engine.registerTag("ai", class extends import_liquidjs.Tag {
7141
+ const engine = safeLiquid({ parse: limits.parse, memory: limits.memory, milliseconds: limits.milliseconds });
7142
+ engine.registerTag("ai", class extends import_liquidjs2.Tag {
6915
7143
  body = [];
6916
7144
  fallback = null;
6917
7145
  constructor(token, tokens, liquid, parser) {
@@ -6972,7 +7200,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6972
7200
  });
6973
7201
  const templates = engine.parse(source);
6974
7202
  const name = input.senderName?.trim() ?? "";
6975
- const context = new import_liquidjs.Context({
7203
+ const context = new import_liquidjs2.Context({
6976
7204
  sender: { firstName: name.split(/\s+/)[0] ?? "", name },
6977
7205
  chat: { title: input.chat.title ?? "", kind: input.chat.kind },
6978
7206
  now: localTime
@@ -6995,7 +7223,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
6995
7223
  }
6996
7224
  }, "renderReplyTemplate");
6997
7225
 
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
7226
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
6999
7227
  var DRY_RUN_DAYS = 7;
7000
7228
  var PAGE = 500;
7001
7229
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7109,143 +7337,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7109
7337
  }
7110
7338
  }, "storedSince");
7111
7339
 
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
7113
- var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
7114
- const host = new URL(baseUrl).host;
7115
- return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
7116
- }, "endpointKeyName");
7117
- var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) => {
7118
- const where = { appName: app.appName, prefix: app.envPrefix, env };
7119
- const credentials = /* @__PURE__ */ __name((provider) => new Credentials({
7120
- configDir: resolvePaths(where).config,
7121
- service: app.appName,
7122
- ...["openai", "anthropic"].includes(provider) ? { envVar: envName(app, `${provider.toUpperCase()}_API_KEY`) } : {},
7123
- isolated: pathsAreOverridden(where),
7124
- env,
7125
- ...keyring ? { keyring } : {},
7126
- warn: /* @__PURE__ */ __name((message) => process.stderr.write(`${message}
7127
- `), "warn")
7128
- }), "credentials");
7129
- const account = /* @__PURE__ */ __name((provider) => `embeddings:${provider}`, "account");
7130
- return {
7131
- read: /* @__PURE__ */ __name((provider) => {
7132
- const stored = credentials(provider).read(account(provider));
7133
- if (stored)
7134
- return { key: stored.secret, source: stored.source };
7135
- const shared = ["openai", "anthropic"].includes(provider) ? env[`${provider.toUpperCase()}_API_KEY`]?.trim() : void 0;
7136
- return shared ? { key: shared, source: "env" } : void 0;
7137
- }, "read"),
7138
- write: /* @__PURE__ */ __name((provider, key) => credentials(provider).write(account(provider), key, { signIn: true }), "write"),
7139
- remove: /* @__PURE__ */ __name((provider) => credentials(provider).remove(account(provider)), "remove")
7140
- };
7141
- }, "embeddingKeys");
7142
-
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
7144
- var options = strictObject({
7145
- temperature: range(0, 2),
7146
- top_p: range(0, 1),
7147
- presence_penalty: range(-2, 2),
7148
- frequency_penalty: range(-2, 2),
7149
- seed: optional(pipe(number(), integer())),
7150
- stop: optional(union([string(), array(string())])),
7151
- response_format: optional(strictObject({ type: picklist(["text", "json_object"]) }))
7152
- });
7153
- var openai = {
7154
- images: true,
7155
- baseUrl: "https://api.openai.com/v1",
7156
- validate: /* @__PURE__ */ __name((given) => checkedOptions("openai", options, given), "validate"),
7157
- complete: /* @__PURE__ */ __name((target, request, checked, apiKey, fetcher) => withTimeLimit(12e4, async (deadline) => {
7158
- const response = await fetcher(`${target.baseUrl.replace(/\/+$/, "")}/chat/completions`, {
7159
- method: "POST",
7160
- headers: { "Content-Type": "application/json", ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {} },
7161
- body: JSON.stringify({
7162
- ...checked,
7163
- model: target.model,
7164
- messages: [
7165
- { role: "system", content: systemFor(request) },
7166
- ...messagesFor(request),
7167
- ...request.images === void 0 ? [] : [
7168
- {
7169
- role: "user",
7170
- content: request.images.map((image) => ({
7171
- type: "image_url",
7172
- image_url: { url: `data:${image.mimeType};base64,${image.data}`, detail: "high" }
7173
- }))
7174
- }
7175
- ]
7176
- ],
7177
- ...new URL(target.baseUrl).hostname === "api.openai.com" ? { max_completion_tokens: request.maxTokens } : { max_tokens: request.maxTokens }
7178
- }),
7179
- signal: deadline,
7180
- redirect: "error"
7181
- });
7182
- if (!response.ok)
7183
- throw new Error("provider rejected request");
7184
- const body = await response.json();
7185
- const choice = body.choices?.[0];
7186
- if (choice?.finish_reason !== "stop" || typeof choice.message?.content !== "string" || !Number.isInteger(body.usage?.total_tokens) || (body.usage?.total_tokens ?? 0) < 1)
7187
- throw new Error("incomplete response");
7188
- return { text: choice.message.content, tokens: body.usage?.total_tokens };
7189
- }), "complete")
7190
- };
7191
-
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
7193
- var modelGateway = /* @__PURE__ */ __name((deps) => ({
7194
- complete: /* @__PURE__ */ __name(async (request) => {
7195
- if (deps.signal?.aborted)
7196
- throw new CliError("cancelled", "model request cancelled");
7197
- const target = deps.resolve(request.purpose);
7198
- if (!target || target.provider === "off")
7199
- throw new CliError("configuration_error", `models.${request.purpose}.provider is not configured; no model was called`);
7200
- if (!request.purpose || !Number.isSafeInteger(request.maxTokens) || request.maxTokens < 1 || typeof request.prompt !== "string")
7201
- throw new CliError("validation_error", "a model request needs a purpose, prompt and positive whole maxTokens");
7202
- validateImages(request.images);
7203
- let adapter = deps.adapters?.[target.provider];
7204
- if (!adapter && target.provider === "openai")
7205
- adapter = openai;
7206
- if (!adapter && target.provider === "anthropic")
7207
- adapter = (await import("./anthropic-NTASPJYE.js")).anthropic;
7208
- if (!adapter)
7209
- throw new CliError("validation_error", `no model adapter for ${target.provider}`);
7210
- if (request.images !== void 0 && adapter.images !== true)
7211
- throw new CliError("validation_error", "the model adapter does not support image inputs");
7212
- const options2 = adapter.validate(request.options ?? {});
7213
- const baseUrl = target.baseUrl ?? adapter.baseUrl;
7214
- if (!target.model.trim() || !endpoint(baseUrl))
7215
- throw new CliError("validation_error", "a model target needs a model and an HTTP/S endpoint without credentials, query or fragment");
7216
- if (!await deps.consent(request, { ...target, baseUrl }))
7217
- throw new CliError("permission_error", `model consent for ${request.purpose} is missing; no data was sent`);
7218
- const apiKey = await deps.key?.(target.provider, target);
7219
- if (deps.signal?.aborted)
7220
- throw new CliError("cancelled", "model request cancelled");
7221
- const fetcher = deps.fetch ?? fetch;
7222
- let limited = false;
7223
- const cancellable = /* @__PURE__ */ __name(async (input, init) => {
7224
- const signal = init?.signal ?? (input instanceof Request ? input.signal : void 0);
7225
- const response = await fetcher(input, {
7226
- ...init,
7227
- signal: deps.signal ? AbortSignal.any([deps.signal, ...signal ? [signal] : []]) : signal
7228
- });
7229
- if (response.status === 429)
7230
- limited = true;
7231
- return response;
7232
- }, "cancellable");
7233
- try {
7234
- const answer = await adapter.complete({ ...target, baseUrl }, request, options2, apiKey, cancellable);
7235
- if (deps.signal?.aborted)
7236
- throw new Error("cancelled");
7237
- if (typeof answer.text !== "string" || !Number.isSafeInteger(answer.tokens) || answer.tokens < 1)
7238
- throw new Error("incomplete");
7239
- return { ...answer, provider: target.provider, model: target.model };
7240
- } catch {
7241
- if (limited)
7242
- throw new CliError("rate_limited", `${request.purpose} provider rate limit reached; no result was stored`);
7243
- throw new CliError("invalid_response", `${request.purpose} provider failed or returned an incomplete response; no result was stored`);
7244
- }
7245
- }, "complete")
7246
- }), "modelGateway");
7247
-
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
7340
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/consents.js
7249
7341
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7250
7342
  import { join as join4 } from "node:path";
7251
7343
  var shape = strictObject({
@@ -7270,21 +7362,21 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7270
7362
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7271
7363
  }, "mayModelReply");
7272
7364
 
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
7274
- var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options2 = {
7365
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7366
+ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options = {
7275
7367
  ai: true
7276
7368
  }) => async (rule2, message, chat, now) => {
7277
7369
  let called;
7278
7370
  const gateway = modelGateway({
7279
- signal: options2.signal,
7371
+ signal: options.signal,
7280
7372
  resolve: /* @__PURE__ */ __name((purpose) => {
7281
7373
  called = modelTarget(settings(), purpose);
7282
7374
  return called;
7283
7375
  }, "resolve"),
7284
7376
  consent: /* @__PURE__ */ __name((_request, target) => mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(target.provider, target.baseUrl ?? ""), message.chatId), "consent"),
7285
- key: /* @__PURE__ */ __name((provider, target) => embeddingKeys(app, env, options2.keyring).read(target.baseUrl === void 0 ? provider : endpointKeyName(target.baseUrl))?.key, "key")
7377
+ key: /* @__PURE__ */ __name((provider, target) => embeddingKeys(app, env, options.keyring).read(target.baseUrl === void 0 ? provider : endpointKeyName(target.baseUrl))?.key, "key")
7286
7378
  });
7287
- if (options2.signal?.aborted)
7379
+ if (options.signal?.aborted)
7288
7380
  throw new CliError("cancelled", "reply rendering cancelled");
7289
7381
  const result2 = await renderReplyTemplate(rule2.reply, {
7290
7382
  senderName: message.senderName,
@@ -7292,8 +7384,8 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7292
7384
  now,
7293
7385
  timezone: rule2.when.hours?.timezone,
7294
7386
  data: message.text,
7295
- allowAI: options2.ai === true,
7296
- preview: options2.preview === true,
7387
+ allowAI: options.ai === true,
7388
+ preview: options.preview === true,
7297
7389
  complete: /* @__PURE__ */ __name(async (prompt, data) => {
7298
7390
  const result3 = await gateway.complete({
7299
7391
  purpose: "replies",
@@ -7302,7 +7394,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7302
7394
  data,
7303
7395
  maxTokens: 512
7304
7396
  });
7305
- if (options2.signal?.aborted)
7397
+ if (options.signal?.aborted)
7306
7398
  throw new CliError("cancelled", "reply rendering cancelled");
7307
7399
  const current = modelTarget(settings(), "replies");
7308
7400
  const baseUrl = called?.baseUrl ?? (called?.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
@@ -7317,7 +7409,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7317
7409
  return result2;
7318
7410
  }, "replyRenderer");
7319
7411
 
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
7412
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/replies/serve.js
7321
7413
  var NOT_ALLOWED = "replies.send is not allow";
7322
7414
  var NO_RULES = "no rules";
7323
7415
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7410,12 +7502,12 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7410
7502
  return { skip: why };
7411
7503
  }, "replyTo");
7412
7504
 
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
7505
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7414
7506
  var START_SYNC_DELAY_MS = 3e4;
7415
7507
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7416
7508
  var START_SYNC_WINDOW_MS = 7 * 864e5;
7417
7509
  var START_SYNC_PER_CHAT = 500;
7418
- var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note, warn, delayMs = START_SYNC_DELAY_MS, budgetMs = START_SYNC_BUDGET_MS, windowMs = START_SYNC_WINDOW_MS, now = Date.now }) => {
7510
+ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch, note, warn, delayMs = START_SYNC_DELAY_MS, budgetMs = START_SYNC_BUDGET_MS, windowMs = START_SYNC_WINDOW_MS, now = Date.now }) => {
7419
7511
  const controller = new AbortController();
7420
7512
  let timer;
7421
7513
  let pass = Promise.resolve();
@@ -7443,7 +7535,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
7443
7535
  if (stop.aborted)
7444
7536
  break;
7445
7537
  try {
7446
- summary.fetched += (await fetch2(chat.id, Math.max(held ?? anywhere, floor), stop)).fetched;
7538
+ summary.fetched += (await fetch(chat.id, Math.max(held ?? anywhere, floor), stop)).fetched;
7447
7539
  summary.chats += 1;
7448
7540
  } catch (error) {
7449
7541
  if (stop.aborted)
@@ -7487,10 +7579,10 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
7487
7579
  };
7488
7580
  }, "startSync");
7489
7581
 
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
7582
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7491
7583
  var FIRST_FETCH_MS = 6e4;
7492
7584
  var DAY_MS = 864e5;
7493
- var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
7585
+ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
7494
7586
  let timer;
7495
7587
  let round = Promise.resolve();
7496
7588
  let stopped = false;
@@ -7503,7 +7595,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
7503
7595
  if (lastCount?.day === today)
7504
7596
  continue;
7505
7597
  try {
7506
- await fetch2(store, account, chatId);
7598
+ await fetch(store, account, chatId);
7507
7599
  done.fetched += 1;
7508
7600
  } catch (error) {
7509
7601
  done.failed += 1;
@@ -7541,7 +7633,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
7541
7633
  };
7542
7634
  }, "memberFetches");
7543
7635
 
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
7636
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7545
7637
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7546
7638
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7547
7639
  if (context.format === "pretty") {
@@ -7574,7 +7666,93 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7574
7666
  return context;
7575
7667
  }, "recordDiagnostics");
7576
7668
 
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
7669
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7670
+ import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync2 } from "node:fs";
7671
+ import { dirname as dirname2, join as join5 } from "node:path";
7672
+ var OUTDATED_CHECK_MS = 6e4;
7673
+ var ownPackageRoot = /* @__PURE__ */ __name((running, script = process.argv[1]) => {
7674
+ let dir;
7675
+ try {
7676
+ dir = dirname2(realpathSync2(script ?? ""));
7677
+ } catch {
7678
+ return void 0;
7679
+ }
7680
+ for (let up = 0; up < 8; up++) {
7681
+ const manifest = join5(dir, "package.json");
7682
+ if (existsSync8(manifest))
7683
+ return installedVersion(dir) === running ? dir : void 0;
7684
+ const parent = dirname2(dir);
7685
+ if (parent === dir)
7686
+ return void 0;
7687
+ dir = parent;
7688
+ }
7689
+ return void 0;
7690
+ }, "ownPackageRoot");
7691
+ var installedVersion = /* @__PURE__ */ __name((root) => {
7692
+ try {
7693
+ const { version } = JSON.parse(readFileSync5(join5(root, "package.json"), "utf8"));
7694
+ return typeof version === "string" ? version : void 0;
7695
+ } catch {
7696
+ return void 0;
7697
+ }
7698
+ }, "installedVersion");
7699
+ var newer = /* @__PURE__ */ __name((one, other) => {
7700
+ const parts2 = /* @__PURE__ */ __name((version) => version.split(/[.+-]/, 3).map(Number), "parts");
7701
+ const [a, b] = [parts2(one), parts2(other)];
7702
+ for (let i = 0; i < 3; i++)
7703
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
7704
+ return (a[i] ?? 0) > (b[i] ?? 0);
7705
+ return false;
7706
+ }, "newer");
7707
+ var outdatedReason = /* @__PURE__ */ __name(async ({ command, running, storePath: storePath2, packageRoot, speaks = SPEAKS }) => {
7708
+ const installed = packageRoot === void 0 ? void 0 : installedVersion(packageRoot);
7709
+ if (installed !== void 0 && newer(installed, running))
7710
+ return `${command} ${installed} is installed and this serve runs ${running}: stopping so it starts again on ${installed}`;
7711
+ if (!existsSync8(storePath2))
7712
+ return void 0;
7713
+ let schema;
7714
+ try {
7715
+ const { database } = await openSqlite(storePath2, { readOnly: true });
7716
+ try {
7717
+ schema = fileSchemaOf(database);
7718
+ } finally {
7719
+ database.close();
7720
+ }
7721
+ } catch {
7722
+ return void 0;
7723
+ }
7724
+ if (writableBy(schema, speaks))
7725
+ return void 0;
7726
+ return `the store is at format ${schema.version} and needs at least ${schema.minCompatible}; this serve (${command} ${running}) speaks ${speaks} and can no longer write it: stopping \u2014 \`${command} upgrade\` if it does not start again on a newer version`;
7727
+ }, "outdatedReason");
7728
+ var watchOutdated = /* @__PURE__ */ __name(({ check: check2, onOutdated, everyMs = OUTDATED_CHECK_MS }) => {
7729
+ let busy = false;
7730
+ let done = false;
7731
+ const timer = setInterval(() => {
7732
+ if (busy || done)
7733
+ return;
7734
+ busy = true;
7735
+ check2().then((reason) => {
7736
+ if (reason === void 0 || done)
7737
+ return;
7738
+ done = true;
7739
+ clearInterval(timer);
7740
+ onOutdated(reason);
7741
+ }).catch(() => {
7742
+ }).finally(() => {
7743
+ busy = false;
7744
+ });
7745
+ }, everyMs);
7746
+ timer.unref();
7747
+ return {
7748
+ stop: /* @__PURE__ */ __name(() => {
7749
+ done = true;
7750
+ clearInterval(timer);
7751
+ }, "stop")
7752
+ };
7753
+ }, "watchOutdated");
7754
+
7755
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7578
7756
  var STEMS_EVERY_MS = 3e4;
7579
7757
  var STEMS_SLICE_MS = 2e3;
7580
7758
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7614,17 +7792,17 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7614
7792
  };
7615
7793
  }, "stemFills");
7616
7794
 
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
7795
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/render/messages.js
7618
7796
  import { styleText } from "node:util";
7619
7797
  var TIME_WIDTH = 8;
7620
7798
  var INDENT = " ".repeat(TIME_WIDTH + 2);
7621
7799
  var MIN_WIDTH = 40;
7622
7800
  var SENDER_COLOURS = ["green", "yellow", "magenta", "blue", "red"];
7623
- var renderMessages = /* @__PURE__ */ __name((messages, options2 = {}) => {
7801
+ var renderMessages = /* @__PURE__ */ __name((messages, options = {}) => {
7624
7802
  if (messages.length === 0)
7625
7803
  return "(nothing)";
7626
- const day = dayFormatter(options2);
7627
- const paint = painter(options2);
7804
+ const day = dayFormatter(options);
7805
+ const paint = painter(options);
7628
7806
  let previous;
7629
7807
  const blocks = [];
7630
7808
  for (const message of messages) {
@@ -7632,40 +7810,40 @@ var renderMessages = /* @__PURE__ */ __name((messages, options2 = {}) => {
7632
7810
  if (date !== previous)
7633
7811
  blocks.push(paint("dim", `\u2500\u2500 ${date} \u2500\u2500`));
7634
7812
  previous = date;
7635
- blocks.push(renderMessage(message, options2));
7813
+ blocks.push(renderMessage(message, options));
7636
7814
  }
7637
7815
  return blocks.join("\n\n");
7638
7816
  }, "renderMessages");
7639
- var renderMessage = /* @__PURE__ */ __name((message, options2 = {}) => {
7640
- const paint = painter(options2);
7641
- const width = Math.max(MIN_WIDTH, options2.width ?? 80);
7817
+ var renderMessage = /* @__PURE__ */ __name((message, options = {}) => {
7818
+ const paint = painter(options);
7819
+ const width = Math.max(MIN_WIDTH, options.width ?? 80);
7642
7820
  const room = width - INDENT.length;
7643
- const time = timeFormatter(options2);
7644
- const verbosity = options2.verbosity ?? 0;
7821
+ const time = timeFormatter(options);
7822
+ const verbosity = options.verbosity ?? 0;
7645
7823
  const chat = "chatTitle" in message ? paint("dim", ` \xB7 ${singleLine(message.chatTitle ?? message.chatId)}`) : "";
7646
7824
  const mark = "anchor" in message && message.anchor ? paint("bold", " \u25C0") : "";
7647
- const lines = [`${paint("dim", time(message.timestamp))} ${senderOf(message, options2)}${chat}${mark}`];
7825
+ const lines = [`${paint("dim", time(message.timestamp))} ${senderOf(message, options)}${chat}${mark}`];
7648
7826
  const body = /* @__PURE__ */ __name((text) => wrapAnsi(visibleControls(text), room, { hard: true }).split("\n"), "body");
7649
7827
  const email = message.email;
7650
7828
  if (email)
7651
7829
  lines.push(paint("dim", mailLine(email)));
7652
7830
  if (message.replyTo)
7653
- lines.push(paint("dim", preview("\u21B3", message.replyTo, room, options2)));
7831
+ lines.push(paint("dim", preview("\u21B3", message.replyTo, room, options)));
7654
7832
  if (message.forwardedFrom) {
7655
- lines.push(paint("dim", `\u21AA ${nameOf(message.forwardedFrom, options2)}`));
7833
+ lines.push(paint("dim", `\u21AA ${nameOf(message.forwardedFrom, options)}`));
7656
7834
  if (message.forwardedFrom.text)
7657
7835
  for (const line of body(message.forwardedFrom.text))
7658
7836
  lines.push(line);
7659
- lines.push(...attachmentLines(message.forwardedFrom.attachments, paint, options2));
7837
+ lines.push(...attachmentLines(message.forwardedFrom.attachments, paint, options));
7660
7838
  }
7661
7839
  if (message.text)
7662
7840
  for (const line of body(message.text))
7663
7841
  lines.push(line);
7664
- lines.push(...attachmentLines(message.attachments, paint, options2));
7842
+ lines.push(...attachmentLines(message.attachments, paint, options));
7665
7843
  if (message.reactions && message.reactions.total > 0)
7666
7844
  lines.push(paint("dim", reactionLine(message.reactions)));
7667
7845
  if (message.editedAt)
7668
- lines.push(paint("dim", `edited ${editedAt(message, options2)}`));
7846
+ lines.push(paint("dim", `edited ${editedAt(message, options)}`));
7669
7847
  if (verbosity >= 1) {
7670
7848
  const fields = [
7671
7849
  ["message", message.id],
@@ -7677,7 +7855,7 @@ var renderMessage = /* @__PURE__ */ __name((message, options2 = {}) => {
7677
7855
  ...message.attachments.map((a) => ["link", a.url])
7678
7856
  ];
7679
7857
  if (verbosity >= 2) {
7680
- fields.push(["provider", options2.provider], ["profile", options2.profile], ["sent", message.timestamp], ["edited", message.editedAt], ["outgoing", message.outgoing === null ? "unknown" : String(message.outgoing)], ...message.attachments.map((a) => ["attachment", JSON.stringify(a)]), ["metadata", message.providerMetadata && JSON.stringify(message.providerMetadata)]);
7858
+ fields.push(["provider", options.provider], ["profile", options.profile], ["sent", message.timestamp], ["edited", message.editedAt], ["outgoing", message.outgoing === null ? "unknown" : String(message.outgoing)], ...message.attachments.map((a) => ["attachment", JSON.stringify(a)]), ["metadata", message.providerMetadata && JSON.stringify(message.providerMetadata)]);
7681
7859
  }
7682
7860
  const shown = fields.filter((field) => typeof field[1] === "string");
7683
7861
  const label = Math.max(...shown.map(([key]) => key.length));
@@ -7690,36 +7868,36 @@ var mailLine = /* @__PURE__ */ __name(({ to, cc, labels }) => {
7690
7868
  return [to.length ? `to ${names(to)}` : "", cc.length ? `cc ${names(cc)}` : "", labels.join(", ")].filter(Boolean).join(" \xB7 ");
7691
7869
  }, "mailLine");
7692
7870
  var painter = /* @__PURE__ */ __name(({ color = false }) => (style, text) => color ? styleText(style, text, { validateStream: false }) : text, "painter");
7693
- var senderOf = /* @__PURE__ */ __name((message, options2) => {
7694
- const paint = painter(options2);
7871
+ var senderOf = /* @__PURE__ */ __name((message, options) => {
7872
+ const paint = painter(options);
7695
7873
  if (message.outgoing === true)
7696
- return paint(["bold", "cyan"], you(options2));
7697
- const name = nameOf(message, options2);
7698
- if (!options2.senderColors)
7874
+ return paint(["bold", "cyan"], you(options));
7875
+ const name = nameOf(message, options);
7876
+ if (!options.senderColors)
7699
7877
  return paint("bold", name);
7700
7878
  const colour = SENDER_COLOURS[hash(message.senderId ?? name) % SENDER_COLOURS.length] ?? "green";
7701
7879
  return paint(["bold", colour], name);
7702
7880
  }, "senderOf");
7703
- var nameOf = /* @__PURE__ */ __name(({ senderName, senderId, outgoing }, options2) => outgoing === true ? you(options2) : singleLine(senderName ?? senderId ?? "unknown"), "nameOf");
7881
+ var nameOf = /* @__PURE__ */ __name(({ senderName, senderId, outgoing }, options) => outgoing === true ? you(options) : singleLine(senderName ?? senderId ?? "unknown"), "nameOf");
7704
7882
  var DEFAULT_LOCALE = "ru-RU";
7705
7883
  var you = /* @__PURE__ */ __name(({ locale = DEFAULT_LOCALE }) => locale.startsWith("ru") ? "\u0432\u044B" : "you", "you");
7706
7884
  var hash = /* @__PURE__ */ __name((value) => [...value].reduce((sum, char) => sum * 31 + char.charCodeAt(0) >>> 0, 7), "hash");
7707
- var preview = /* @__PURE__ */ __name((mark, quoted, room, options2) => {
7885
+ var preview = /* @__PURE__ */ __name((mark, quoted, room, options) => {
7708
7886
  const text = singleLine(quoted.text.split("\n")[0] ?? "") || (quoted.attachments[0] ? `\u{1F4CE} ${quoted.attachments[0].kind}` : "");
7709
- const line = text ? `${mark} ${nameOf(quoted, options2)}: ${text}` : `${mark} message ${quoted.id}`;
7887
+ const line = text ? `${mark} ${nameOf(quoted, options)}: ${text}` : `${mark} message ${quoted.id}`;
7710
7888
  if (stringWidth(line) <= room)
7711
7889
  return line;
7712
7890
  return `${wrapAnsi(line, room - 1, { hard: true }).split("\n")[0]}\u2026`;
7713
7891
  }, "preview");
7714
- var attachmentLines = /* @__PURE__ */ __name((attachments, paint, options2) => {
7892
+ var attachmentLines = /* @__PURE__ */ __name((attachments, paint, options) => {
7715
7893
  const link = /* @__PURE__ */ __name((label, raw) => {
7716
7894
  if (raw === void 0)
7717
7895
  return label;
7718
7896
  const url = singleLine(raw);
7719
- return options2.color ? `\x1B]8;;${url}\x07${label}\x1B]8;;\x07` : `${label} ${url}`;
7897
+ return options.color ? `\x1B]8;;${url}\x07${label}\x1B]8;;\x07` : `${label} ${url}`;
7720
7898
  }, "link");
7721
- let number2 = 0;
7722
- const keyboard = attachments.flatMap((attachment) => attachment.buttons ?? []).map((row) => paint("dim", row.map((button) => link(`[${++number2} ${singleLine(button.text)}]`, button.url)).join(" ")));
7899
+ let number = 0;
7900
+ const keyboard = attachments.flatMap((attachment) => attachment.buttons ?? []).map((row) => paint("dim", row.map((button) => link(`[${++number} ${singleLine(button.text)}]`, button.url)).join(" ")));
7723
7901
  const polls = attachments.flatMap((attachment) => attachment.poll ? pollLines(attachment.poll) : []);
7724
7902
  const cards = attachments.flatMap(({ contact }) => contact ? [
7725
7903
  paint("dim", `\u{1F464} ${[contact.name, contact.phone].flatMap((part) => part ? [singleLine(part)] : []).join(" \xB7 ")}`)
@@ -7783,14 +7961,14 @@ var reactionLine = /* @__PURE__ */ __name(({ counts, mine }) => {
7783
7961
  const shown = counts.map(({ reaction, count: count3 }) => `${singleLine(reaction)} ${count3}`).join(" ");
7784
7962
  return mine ? `${shown} (you: ${singleLine(mine)})` : shown;
7785
7963
  }, "reactionLine");
7786
- var editedAt = /* @__PURE__ */ __name((message, options2) => {
7964
+ var editedAt = /* @__PURE__ */ __name((message, options) => {
7787
7965
  const edited = message.editedAt ?? message.timestamp;
7788
- const time = timeFormatter(options2)(edited);
7789
- const day = dayFormatter(options2);
7966
+ const time = timeFormatter(options)(edited);
7967
+ const day = dayFormatter(options);
7790
7968
  return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
7791
7969
  }, "editedAt");
7792
7970
 
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
7971
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7794
7972
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7795
7973
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7796
7974
  kind: attachment.kind,
@@ -7885,7 +8063,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7885
8063
  locale: messenger.app.locale
7886
8064
  }), "viewOf");
7887
8065
 
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
8066
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7889
8067
  var observed = /* @__PURE__ */ __name((value) => ({
7890
8068
  value: value.value,
7891
8069
  observed_at: value.observedAt,
@@ -7952,7 +8130,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7952
8130
  }
7953
8131
  }, "watchEventItem");
7954
8132
 
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
8133
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7956
8134
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7957
8135
  output: { entity: "watch_item" },
7958
8136
  effects: REMOTE_READ,
@@ -8107,7 +8285,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
8107
8285
  }
8108
8286
  }, "describe");
8109
8287
 
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
8288
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8111
8289
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
8112
8290
  const command = annotate(new Command("serve"), {
8113
8291
  output: { entity: "serve_summary" },
@@ -8131,8 +8309,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8131
8309
  }
8132
8310
  let relaying;
8133
8311
  const onReady = /* @__PURE__ */ __name(() => {
8134
- const listening = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8135
- holdLock(path, listening);
8312
+ const listening2 = { pid: process.pid, startedAt, version, listeningAt: (/* @__PURE__ */ new Date()).toISOString() };
8313
+ holdLock(path, listening2);
8136
8314
  note({
8137
8315
  code: "listening",
8138
8316
  text: `listening for profile ${context.profile}, catching up on what arrived while it was down`
@@ -8141,7 +8319,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8141
8319
  return;
8142
8320
  relaying = relay.open(path, context.profile).then((address) => {
8143
8321
  if (address)
8144
- holdLock(path, { ...listening, relay: address });
8322
+ holdLock(path, { ...listening2, relay: address });
8145
8323
  }).catch((error) => {
8146
8324
  const errorCode = failureKey(error);
8147
8325
  warn({ code: "relay_failed", errorCode, text: `commands cannot run through this serve: ${errorCode}` });
@@ -8150,7 +8328,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8150
8328
  const counts = {};
8151
8329
  const rules = replying(context, messenger, Date.parse(startedAt));
8152
8330
  const tasks = tasking(context, warn);
8153
- const { handled, startSyncDelayMs } = environmentOf(this);
8331
+ const { handled, startSyncDelayMs, outdated: outdatedHook } = environmentOf(this);
8154
8332
  const count3 = /* @__PURE__ */ __name((event) => {
8155
8333
  counts[event.event] = (counts[event.event] ?? 0) + 1;
8156
8334
  if (event.event === "message") {
@@ -8222,9 +8400,25 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8222
8400
  withStore: /* @__PURE__ */ __name((work) => context.withStore((store) => work(store), { name: "serve stems" }), "withStore"),
8223
8401
  warn
8224
8402
  });
8403
+ const listening = new AbortController();
8404
+ let outdated;
8405
+ const packageRoot = outdatedHook?.packageRoot ?? ownPackageRoot(version);
8406
+ const watch = watchOutdated({
8407
+ check: /* @__PURE__ */ __name(() => outdatedReason({
8408
+ command: messenger.app.command,
8409
+ running: version,
8410
+ storePath: storePath(context.env),
8411
+ packageRoot
8412
+ }), "check"),
8413
+ onOutdated: /* @__PURE__ */ __name((reason) => {
8414
+ outdated = reason;
8415
+ listening.abort();
8416
+ }, "onOutdated"),
8417
+ ...outdatedHook?.everyMs === void 0 ? {} : { everyMs: outdatedHook.everyMs }
8418
+ });
8225
8419
  try {
8226
8420
  await listenUntilStopped(this, context, relay?.messenger ?? messenger, count3, {
8227
- stop: new AbortController(),
8421
+ stop: listening,
8228
8422
  catchUp: true,
8229
8423
  onReady,
8230
8424
  connected: /* @__PURE__ */ __name((open) => {
@@ -8237,6 +8431,7 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8237
8431
  }, "connected")
8238
8432
  });
8239
8433
  } finally {
8434
+ watch.stop();
8240
8435
  await relaying;
8241
8436
  await relay?.close();
8242
8437
  rules.stop();
@@ -8247,6 +8442,8 @@ var serveCommand = /* @__PURE__ */ __name((messenger) => {
8247
8442
  await tasks.settled();
8248
8443
  releaseLock(path);
8249
8444
  }
8445
+ if (outdated !== void 0)
8446
+ throw new CliError("configuration_error", outdated, { reason: "serve.outdated" });
8250
8447
  renderAnswer(this, context, itemOf({
8251
8448
  profile: context.profile,
8252
8449
  started_at: startedAt,
@@ -8371,8 +8568,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8371
8568
  };
8372
8569
  }, "tasking");
8373
8570
 
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
8375
- import { existsSync as existsSync8 } from "node:fs";
8571
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8572
+ import { existsSync as existsSync9 } from "node:fs";
8376
8573
  var PATH = "store tables list";
8377
8574
  var STORE_TABLES_QUERY = {
8378
8575
  entity: "store_table",
@@ -8401,7 +8598,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8401
8598
  const filter = filterOf(words);
8402
8599
  const { full } = this.optsWithGlobals();
8403
8600
  const path = storePath(environmentOf(this).env ?? process.env);
8404
- if (!existsSync8(path))
8601
+ if (!existsSync9(path))
8405
8602
  throw new CliError("not_found", `no store at ${path}`);
8406
8603
  const items = await readStoreTables(path, { filter, sizes: full === true });
8407
8604
  renderAnswer(this, outputFor(this), listOf(PATH, {
@@ -8414,7 +8611,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8414
8611
  return tables;
8415
8612
  }, "storeTablesCommand");
8416
8613
 
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
8614
+ // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.87.0_commander@15._c25084c4731872baba927966435ce31d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8418
8615
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8419
8616
  var WORD_INDEX = "message_words";
8420
8617
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8423,7 +8620,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
8423
8620
  }, "schemaOf");
8424
8621
  var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
8425
8622
  var pendingIfKnown2 = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
8426
- var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync9(path) ? statSync4(path).size : 0, "bytesOf");
8623
+ var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync10(path) ? statSync4(path).size : 0, "bytesOf");
8427
8624
  var reading = /* @__PURE__ */ __name(async (path, read) => {
8428
8625
  const database = await openCache(path);
8429
8626
  try {
@@ -8450,7 +8647,7 @@ var fileSchema = /* @__PURE__ */ __name(async (path) => {
8450
8647
  }, "fileSchema");
8451
8648
  var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
8452
8649
  const path = storePath(env);
8453
- if (!existsSync9(path))
8650
+ if (!existsSync10(path))
8454
8651
  return { path, exists: false };
8455
8652
  const checked = await storeHealth(path, { deep });
8456
8653
  const recorded = deep ? recordDeepCheck(path, checked, {
@@ -8520,7 +8717,7 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
8520
8717
  const { renderer, format } = outputFor(this);
8521
8718
  const { dryRun: dryRun2 } = this.opts();
8522
8719
  const path = storePath(environmentOf(this).env ?? process.env);
8523
- if (!existsSync9(path)) {
8720
+ if (!existsSync10(path)) {
8524
8721
  result(this, { path, exists: false });
8525
8722
  return;
8526
8723
  }
@@ -8560,7 +8757,7 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
8560
8757
  }, "notesOf");
8561
8758
  var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").description("the tables `store repair` kept as copies").addCommand(annotate(new Command("delete"), { output: { entity: "store_copy_removal" }, effects: LOCAL_WRITE }).description("delete one copy `store repair` kept, named exactly; refuses any other table").argument("<name>", "the copy's name, as `store repair` printed it").action(async function(name) {
8562
8759
  const path = storePath(environmentOf(this).env ?? process.env);
8563
- if (!existsSync9(path))
8760
+ if (!existsSync10(path))
8564
8761
  throw new CliError("not_found", `no store at ${path}`);
8565
8762
  const deleted = await reading(path, (database) => deleteCopy(database, name));
8566
8763
  result(this, { path, deleted });
@@ -8568,7 +8765,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
8568
8765
  var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ }).summary("check the local archive for problems").description("whether the store is healthy \u2014 integrity, search indexes, disk, and which chats are behind").action(async function() {
8569
8766
  const { renderer } = outputFor(this);
8570
8767
  const path = storePath(environmentOf(this).env ?? process.env);
8571
- if (!existsSync9(path)) {
8768
+ if (!existsSync10(path)) {
8572
8769
  result(this, { path, exists: false, ok: true });
8573
8770
  return;
8574
8771
  }
@@ -8631,7 +8828,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
8631
8828
  ...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
8632
8829
  ]);
8633
8830
  const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
8634
- const { bavail, bsize } = statfsSync2(dirname2(path));
8831
+ const { bavail, bsize } = statfsSync2(dirname3(path));
8635
8832
  const free = Number(bavail) * Number(bsize);
8636
8833
  const behind = schema.version > 0 ? chatsBehind(database) : [];
8637
8834
  const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
@@ -8719,7 +8916,7 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
8719
8916
  var migrateCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE }).summary("migrate an older local archive").description("bring the store up to this build's schema, then normalize, index and stem the messages and notes stored before it").action(async function() {
8720
8917
  const { renderer } = outputFor(this);
8721
8918
  const path = storePath(environmentOf(this).env ?? process.env);
8722
- if (!existsSync9(path)) {
8919
+ if (!existsSync10(path)) {
8723
8920
  result(this, { path, exists: false });
8724
8921
  renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
8725
8922
  return;
@@ -8783,7 +8980,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
8783
8980
  var reindexCommand = /* @__PURE__ */ __name((messenger) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE })).summary("rebuild the local archive's search indexes").description("rebuild the word index, its typo vocabulary, the stems, the files' word index, the notes' indexes and who took part in what, from what is stored, and drop the vectors no stored text uses; loses nothing").action(async function() {
8784
8981
  const { renderer } = outputFor(this);
8785
8982
  const path = storePath(environmentOf(this).env ?? process.env);
8786
- if (!existsSync9(path)) {
8983
+ if (!existsSync10(path)) {
8787
8984
  result(this, { path, exists: false });
8788
8985
  return;
8789
8986
  }
@@ -8825,9 +9022,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
8825
9022
  const { encrypt } = this.opts();
8826
9023
  const path = storePath(environmentOf(this).env ?? process.env);
8827
9024
  const target = resolve(file2);
8828
- if (!existsSync9(path))
9025
+ if (!existsSync10(path))
8829
9026
  throw new CliError("not_found", `no store at ${path} to back up`);
8830
- if (existsSync9(target))
9027
+ if (existsSync10(target))
8831
9028
  throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
8832
9029
  const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
8833
9030
  const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
@@ -8860,11 +9057,11 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8860
9057
  const { output } = this.opts();
8861
9058
  const from = resolve(file2);
8862
9059
  const to = resolve(output);
8863
- if (!existsSync9(from))
9060
+ if (!existsSync10(from))
8864
9061
  throw new CliError("not_found", `no file at ${from}`);
8865
9062
  if (!isSealed(from))
8866
9063
  throw new CliError("validation_error", `${from} was not written with --encrypt`);
8867
- if (existsSync9(to))
9064
+ if (existsSync10(to))
8868
9065
  throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
8869
9066
  await unsealFile(from, to, await passwordOf(this, { twice: false }));
8870
9067
  result(this, { path: to, from, bytes: bytesOf2(to) });
@@ -8872,13 +9069,13 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8872
9069
  var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup and keep the current store, or roll back a breaking upgrade").description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools cannot open), put its tables back in the store and return it to that version instead").argument("<file>", "a file `store backup` wrote, or a rollback copy; one written with --encrypt asks for its password").action(async function(file2) {
8873
9070
  const path = storePath(environmentOf(this).env ?? process.env);
8874
9071
  const given = resolve(file2);
8875
- if (!existsSync9(given))
9072
+ if (!existsSync10(given))
8876
9073
  throw new CliError("not_found", `no file at ${given}`);
8877
9074
  refuseWhileServing(this, messenger);
8878
9075
  if (!isSealed(given))
8879
9076
  return restoreFrom(this, messenger, given, given);
8880
9077
  const opened = `${path}.unsealing-${process.pid}`;
8881
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9078
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8882
9079
  try {
8883
9080
  await unsealFile(given, opened, await passwordOf(this, { twice: false }));
8884
9081
  await restoreFrom(this, messenger, opened, given);
@@ -8889,26 +9086,26 @@ var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command(
8889
9086
  var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
8890
9087
  const { renderer } = outputFor(command);
8891
9088
  const path = storePath(environmentOf(command).env ?? process.env);
8892
- if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
9089
+ if (existsSync10(path) && realpathSync3(backup) === realpathSync3(path)) {
8893
9090
  throw new CliError("validation_error", `${backup} is the store itself`);
8894
9091
  }
8895
9092
  if (await isRollbackCopy(backup))
8896
9093
  return rollBackFrom(command, messenger, backup);
8897
9094
  const schema = await backupSchema(backup);
8898
9095
  const stamp = stampNow();
8899
- const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
9096
+ const kept = existsSync10(path) ? `${path}.before-restore-${stamp}` : null;
8900
9097
  if (kept) {
8901
9098
  const waitMs = environmentOf(command).storeLockWaitMs;
8902
9099
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
8903
9100
  } else
8904
- mkdirSync(dirname2(path), { recursive: true, mode: 448 });
9101
+ mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8905
9102
  const incoming = `${path}.restoring-${stamp}`;
8906
9103
  copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
8907
9104
  chmodSync(incoming, 384);
8908
9105
  if (kept) {
8909
9106
  renameSync3(path, kept);
8910
9107
  for (const suffix of ["-wal", "-shm"])
8911
- if (existsSync9(`${path}${suffix}`))
9108
+ if (existsSync10(`${path}${suffix}`))
8912
9109
  renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
8913
9110
  }
8914
9111
  renameSync3(incoming, path);
@@ -8930,7 +9127,7 @@ var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
8930
9127
  var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
8931
9128
  const { renderer } = outputFor(command);
8932
9129
  const path = storePath(environmentOf(command).env ?? process.env);
8933
- if (!existsSync9(path))
9130
+ if (!existsSync10(path))
8934
9131
  throw new CliError("not_found", `no store at ${path} to roll back`);
8935
9132
  const waitMs = environmentOf(command).storeLockWaitMs;
8936
9133
  await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
@@ -8980,7 +9177,7 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
8980
9177
  var STORE_LOCK_WAIT_MS = 1e3;
8981
9178
  var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
8982
9179
  const { command } = messenger.app;
8983
- const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
9180
+ const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync10(file2)).map((file2) => realpathSync3(file2));
8984
9181
  const holders = holdersOf(files);
8985
9182
  if (holders === void 0) {
8986
9183
  warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
@@ -9006,7 +9203,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
9006
9203
  const { command } = messenger.app;
9007
9204
  const env = environmentOf(this).env ?? process.env;
9008
9205
  const path = storePath(env);
9009
- if (!existsSync9(path)) {
9206
+ if (!existsSync10(path)) {
9010
9207
  result(this, { path, exists: false, reset: false });
9011
9208
  renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
9012
9209
  return;
@@ -9051,8 +9248,8 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
9051
9248
  }), "resetCommand");
9052
9249
  var STORE_PARTS2 = ["", "-wal", "-shm"];
9053
9250
  var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
9054
- const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync9(file2));
9055
- const holders = holdersOf(files.map((file2) => realpathSync2(file2)));
9251
+ const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync10(file2));
9252
+ const holders = holdersOf(files.map((file2) => realpathSync3(file2)));
9056
9253
  const serving = servingProfiles(messenger.app, env).length > 0;
9057
9254
  const read = await readingOnly(path, (database) => ({
9058
9255
  schema: schemaOf(database).version,
@@ -9098,11 +9295,9 @@ export {
9098
9295
  readRepliesState,
9099
9296
  writeRepliesState,
9100
9297
  paused,
9298
+ safeLiquid,
9101
9299
  DRY_RUN_DAYS,
9102
9300
  dryRun,
9103
- endpointKeyName,
9104
- embeddingKeys,
9105
- modelGateway,
9106
9301
  replyConsentPathFor,
9107
9302
  readReplyConsent,
9108
9303
  writeReplyConsent,