@wirecat/mail-cli 0.17.0 → 0.18.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.
- package/CHANGELOG.md +14 -0
- package/dist/bin/mail.js +2 -2
- package/dist/bundle/{all-profiles-55AU2Q2N.js → all-profiles-4CVOXA5Y.js} +10 -10
- package/dist/bundle/{anthropic-I7RI7YPK.js → anthropic-5VIKYINO.js} +6 -6
- package/dist/bundle/{app-server-NY72GTQA.js → app-server-LTSQBDPF.js} +53 -50
- package/dist/bundle/{bun-C2R7UPM2.js → bun-C7DBRUW2.js} +2 -2
- package/dist/bundle/{bun-sqlite-RNPHH3KC.js → bun-sqlite-Y5JKT62B.js} +5 -5
- package/dist/bundle/{chunk-YO7BLBVE.js → chunk-23HWKHPZ.js} +301 -259
- package/dist/bundle/{chunk-OHS5CYZI.js → chunk-2NWOYXPJ.js} +56 -56
- package/dist/bundle/{chunk-JSB6BTPT.js → chunk-3DQYO7FB.js} +1 -1
- package/dist/bundle/{chunk-B73I6KLW.js → chunk-3W5H4TM7.js} +184 -16
- package/dist/bundle/{chunk-2EVM7GV5.js → chunk-3YRE6DNM.js} +8 -8
- package/dist/bundle/{chunk-YIJRPPF5.js → chunk-43I5XD7S.js} +1 -1
- package/dist/bundle/{chunk-HZL42476.js → chunk-5S6Q3SWU.js} +4 -2
- package/dist/bundle/{chunk-DG43I7MC.js → chunk-6RO5RDNR.js} +27 -9
- package/dist/bundle/{chunk-J7XH6CJC.js → chunk-7P4ICYJT.js} +1 -1
- package/dist/bundle/{chunk-BWCYUXF7.js → chunk-7SWWVDEZ.js} +4 -4
- package/dist/bundle/{chunk-24H2KUGW.js → chunk-A5OMARL4.js} +28 -28
- package/dist/bundle/{chunk-QDX2O5BN.js → chunk-ACLILULA.js} +3 -3
- package/dist/bundle/{chunk-QRNL5DIS.js → chunk-AOMSP4EI.js} +6 -6
- package/dist/bundle/{chunk-XJQJ3ZIY.js → chunk-BHNBWFT5.js} +8 -8
- package/dist/bundle/{chunk-LNC7XMEQ.js → chunk-BMFPCW6Q.js} +4 -4
- package/dist/bundle/{chunk-MG4NWXWI.js → chunk-BMGVKULS.js} +4 -4
- package/dist/bundle/{chunk-4HTTN4NO.js → chunk-BMV56JCL.js} +19 -19
- package/dist/bundle/{chunk-22WVQJW3.js → chunk-C4RUKMDT.js} +16 -10
- package/dist/bundle/{chunk-QU5TWVG5.js → chunk-C5T5K7HW.js} +127 -27
- package/dist/bundle/{chunk-KJKRLI2S.js → chunk-CPEN6BZZ.js} +2 -2
- package/dist/bundle/{chunk-YHUCNI2W.js → chunk-DALBYUPC.js} +2 -2
- package/dist/bundle/{chunk-6NN5ZX5T.js → chunk-DPSH46NO.js} +5 -5
- package/dist/bundle/{chunk-CHVHIDNK.js → chunk-EFP5NN7I.js} +3 -3
- package/dist/bundle/{chunk-22IKW3TY.js → chunk-ERBEBORA.js} +14 -14
- package/dist/bundle/{chunk-YCOBSDZY.js → chunk-FLOOPXOT.js} +12 -12
- package/dist/bundle/{chunk-F4P3VDJZ.js → chunk-GLLLYACZ.js} +6 -6
- package/dist/bundle/{chunk-S4NIDBLI.js → chunk-GRP67IQ4.js} +56 -47
- package/dist/bundle/{chunk-T4RRZILQ.js → chunk-HFUS33UT.js} +2 -2
- package/dist/bundle/{chunk-RFFE5ACS.js → chunk-HTFBXGJF.js} +2 -2
- package/dist/bundle/{chunk-MTFTMPB6.js → chunk-IANOK5SE.js} +2 -2
- package/dist/bundle/{chunk-WHI3LTAW.js → chunk-ITUC5WAV.js} +1 -1
- package/dist/bundle/{chunk-VMXMHC6E.js → chunk-JO3BIMYK.js} +3 -3
- package/dist/bundle/{chunk-45JQ72CH.js → chunk-KVSC657S.js} +19 -12
- package/dist/bundle/{chunk-OFZDCUUJ.js → chunk-L3YX7A5M.js} +7 -7
- package/dist/bundle/{chunk-2CY44MKY.js → chunk-M7C4IGJ6.js} +8 -8
- package/dist/bundle/{chunk-GBM7FFFI.js → chunk-MCR43SWG.js} +4 -4
- package/dist/bundle/{chunk-YB47AQWE.js → chunk-N5VEJ3E7.js} +10 -10
- package/dist/bundle/{chunk-IPFFPD3M.js → chunk-NDJZQCF3.js} +297 -174
- package/dist/bundle/{chunk-R3G33QIV.js → chunk-OLJDZTHB.js} +13 -13
- package/dist/bundle/{chunk-CHC2LWKY.js → chunk-OMKPALMX.js} +2 -2
- package/dist/bundle/{chunk-MRTSDBTN.js → chunk-OUGGAAXI.js} +1508 -559
- package/dist/bundle/{chunk-SHEVFBZT.js → chunk-P6WCG6X2.js} +36 -30
- package/dist/bundle/{chunk-GYCJQGFO.js → chunk-QPF4LTK5.js} +6 -6
- package/dist/bundle/{chunk-WOFGEJ6W.js → chunk-RIO3TD3I.js} +1 -1
- package/dist/bundle/{chunk-RIAHISWA.js → chunk-RQSF7X22.js} +1 -1
- package/dist/bundle/{chunk-2ON2PDHC.js → chunk-SIYT2BBI.js} +10 -10
- package/dist/bundle/{chunk-M6GLFDWV.js → chunk-SMS5YNPB.js} +3 -3
- package/dist/bundle/{chunk-H32SKDF2.js → chunk-SW2KERUB.js} +640 -123
- package/dist/bundle/{chunk-BPDUVWL2.js → chunk-TVZ77ZOV.js} +2 -2
- package/dist/bundle/{chunk-SQAAOEGI.js → chunk-U43HUE35.js} +9 -9
- package/dist/bundle/{chunk-RQGTRB73.js → chunk-UEGABYXI.js} +3 -3
- package/dist/bundle/{chunk-TCYLDGRA.js → chunk-UHC5I3JV.js} +1 -1
- package/dist/bundle/{chunk-XOJ5E777.js → chunk-UWL2IOII.js} +4 -4
- package/dist/bundle/{chunk-ITMGJX7I.js → chunk-UXD5JMS5.js} +1 -1
- package/dist/bundle/{chunk-JI225TBX.js → chunk-WA3DQSAZ.js} +2 -2
- package/dist/bundle/{chunk-VXBUDZV3.js → chunk-XGTW3GRX.js} +2 -2
- package/dist/bundle/{chunk-QEO7MI3E.js → chunk-YA2JPMYX.js} +2 -2
- package/dist/bundle/{chunk-A3PKKY24.js → chunk-ZLH465EU.js} +1 -1
- package/dist/bundle/{chunk-BD7OK4P5.js → chunk-ZT2Y267T.js} +3 -3
- package/dist/bundle/command-contract-Y3GIKCPB.js +34 -0
- package/dist/bundle/{decode-5AYG6LLW.js → decode-WVIDLK4E.js} +5 -5
- package/dist/bundle/{dispatch-EVLWT6N3.js → dispatch-R5OF2FVZ.js} +8 -8
- package/dist/bundle/{dist-JRTLLLLG.js → dist-KGQWS3XL.js} +24 -14
- package/dist/bundle/{echarts-EFAEE4D2.js → echarts-VMKACZBF.js} +2 -2
- package/dist/bundle/{embed-6SSOYGZQ.js → embed-EQINOOST.js} +6 -6
- package/dist/bundle/{embedder-VFSLGHBO.js → embedder-LM52TDRN.js} +9 -9
- package/dist/bundle/{failure-RBBZ7F3L.js → failure-WYKVF6RH.js} +2 -2
- package/dist/bundle/{first-run-PVEHOQOD.js → first-run-H4VXZAAF.js} +11 -11
- package/dist/bundle/first-screen-ZP74TJLK.js +32 -0
- package/dist/bundle/{instructions-EOLC3GYB.js → instructions-NLSME663.js} +1 -1
- package/dist/bundle/mail.js +12 -12
- package/dist/bundle/{mcp-JYLZR5LQ.js → mcp-CFVG2OUS.js} +2 -2
- package/dist/bundle/{node-2ZRMQAYF.js → node-FGMSXLTA.js} +2 -2
- package/dist/bundle/{node-sqlite-UKWOBONA.js → node-sqlite-K3T3ZRBY.js} +6 -6
- package/dist/bundle/{oauth-HFD46WAY.js → oauth-OJKJ6JLH.js} +7 -7
- package/dist/bundle/{open-2DLCQUC4.js → open-DCYIXHXS.js} +5 -5
- package/dist/bundle/{openai-A7YLLQEE.js → openai-C4H4W57J.js} +14 -14
- package/dist/bundle/{process-I3INVLFQ.js → process-MN4NSYGA.js} +1 -1
- package/dist/bundle/{program-4ZCATQND.js → program-ZZZOKWCX.js} +1028 -642
- package/dist/bundle/{prompt-R636OFYK.js → prompt-ELEJUDAU.js} +5 -5
- package/dist/bundle/{recognize-G4WUSU5I.js → recognize-G2FVMI5M.js} +4 -4
- package/dist/bundle/{remote-BMXVVYTN.js → remote-F4YVSEYM.js} +7 -7
- package/dist/bundle/{rerank-7W3QEZ3Q.js → rerank-7VM5R5N6.js} +7 -7
- package/dist/bundle/{serve-JQCPQYOJ.js → serve-A7NRFPRN.js} +9 -9
- package/dist/bundle/{server-IMOCOYXH.js → server-7R2BEIRY.js} +39 -39
- package/dist/bundle/server-DFJA2HBO.js +64 -0
- package/dist/bundle/{sqlite-runtime-H2IEHDRZ.js → sqlite-runtime-4SKUB4EN.js} +6 -6
- package/dist/bundle/{state-J5N3Y4LX.js → state-S2FKK2XB.js} +6 -6
- package/dist/bundle/{store-C4TIYTGI.js → store-4HAARQVR.js} +26 -18
- package/dist/bundle/{store-U5WIT3P4.js → store-FLHO3UMA.js} +17 -15
- package/dist/bundle/store-maintenance-command-BINJIQ6F.js +54 -0
- package/dist/commands/restore.js +1 -1
- package/dist/commands/restore.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +2 -8
- package/dist/commands/status.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/dist/bundle/command-contract-AUPKK5Y4.js +0 -34
- package/dist/bundle/first-screen-7ONKJ7QW.js +0 -32
- package/dist/bundle/server-GYVOIGF5.js +0 -64
- package/dist/bundle/store-maintenance-command-WRRZ7Q7B.js +0 -54
- /package/dist/bundle/{chunk-CNMSF5QU.js → chunk-QZLK2ISN.js} +0 -0
|
@@ -2,11 +2,11 @@ import { createRequire as __bundleRequire } from "node:module";
|
|
|
2
2
|
const require = __bundleRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
renderMessages
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-YA2JPMYX.js";
|
|
6
6
|
import {
|
|
7
7
|
answerOf,
|
|
8
8
|
messengerContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-GRP67IQ4.js";
|
|
10
10
|
import {
|
|
11
11
|
FETCHING,
|
|
12
12
|
RULES_VERSION,
|
|
@@ -27,19 +27,19 @@ import {
|
|
|
27
27
|
typedQuery,
|
|
28
28
|
withQuery,
|
|
29
29
|
withTimeLimit
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-23HWKHPZ.js";
|
|
31
31
|
import {
|
|
32
32
|
checkedOptions,
|
|
33
33
|
range
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-JO3BIMYK.js";
|
|
35
35
|
import {
|
|
36
36
|
messagesFor,
|
|
37
37
|
systemFor,
|
|
38
38
|
validateImages
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-OMKPALMX.js";
|
|
40
40
|
import {
|
|
41
41
|
readSecret
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-EFP5NN7I.js";
|
|
43
43
|
import {
|
|
44
44
|
Command,
|
|
45
45
|
LOCAL_READ,
|
|
@@ -67,30 +67,41 @@ import {
|
|
|
67
67
|
snakeKeys,
|
|
68
68
|
storeTable,
|
|
69
69
|
withoutProviderRefs
|
|
70
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-NDJZQCF3.js";
|
|
71
71
|
import {
|
|
72
72
|
levelFor
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-L3YX7A5M.js";
|
|
74
74
|
import {
|
|
75
75
|
failureKey
|
|
76
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-U43HUE35.js";
|
|
77
77
|
import {
|
|
78
78
|
holdLock,
|
|
79
79
|
lockPath,
|
|
80
80
|
releaseLock,
|
|
81
81
|
servingProfiles,
|
|
82
82
|
takeLock
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-UEGABYXI.js";
|
|
84
84
|
import {
|
|
85
85
|
holdersOf
|
|
86
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-ITUC5WAV.js";
|
|
87
87
|
import {
|
|
88
|
+
QUICK_HEALTH_CHECKS,
|
|
89
|
+
explainDamage,
|
|
90
|
+
fts5Tables,
|
|
91
|
+
storeHealth
|
|
92
|
+
} from "./chunk-3W5H4TM7.js";
|
|
93
|
+
import {
|
|
94
|
+
CORPORA,
|
|
88
95
|
MIGRATIONS,
|
|
96
|
+
drainCorpus,
|
|
97
|
+
drainMeetingIndex,
|
|
89
98
|
drainNoteIndex,
|
|
90
99
|
dropAllUnusedVectors,
|
|
91
100
|
fileFacts,
|
|
92
101
|
fillSearchIndex,
|
|
93
102
|
fillStems,
|
|
103
|
+
fillTrigrams,
|
|
104
|
+
fillVectorIndexes,
|
|
94
105
|
involvementStoreOver,
|
|
95
106
|
migrate,
|
|
96
107
|
noteIndexState,
|
|
@@ -99,10 +110,12 @@ import {
|
|
|
99
110
|
orphanPointers,
|
|
100
111
|
pendingNormalization,
|
|
101
112
|
readStoreTables,
|
|
113
|
+
rebuildMentions,
|
|
102
114
|
resetAttachmentWords,
|
|
103
115
|
resetNoteIndex,
|
|
104
116
|
resetSearchIndex,
|
|
105
117
|
resetStems,
|
|
118
|
+
rollBack,
|
|
106
119
|
rowCounts,
|
|
107
120
|
searchIndexState,
|
|
108
121
|
stemmerCache,
|
|
@@ -110,26 +123,26 @@ import {
|
|
|
110
123
|
storeClients,
|
|
111
124
|
storeContents,
|
|
112
125
|
vectorIndexCounts
|
|
113
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-OUGGAAXI.js";
|
|
114
127
|
import {
|
|
115
128
|
formatLocator,
|
|
116
129
|
parseLocator
|
|
117
|
-
} from "./chunk-
|
|
130
|
+
} from "./chunk-KVSC657S.js";
|
|
118
131
|
import {
|
|
119
132
|
queryFieldsOf
|
|
120
|
-
} from "./chunk-
|
|
133
|
+
} from "./chunk-2NWOYXPJ.js";
|
|
121
134
|
import {
|
|
122
135
|
storePath
|
|
123
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-HTFBXGJF.js";
|
|
124
137
|
import {
|
|
125
138
|
openCache
|
|
126
|
-
} from "./chunk-
|
|
139
|
+
} from "./chunk-AOMSP4EI.js";
|
|
127
140
|
import {
|
|
128
141
|
Credentials,
|
|
129
142
|
pathsAreOverridden,
|
|
130
143
|
resolvePaths,
|
|
131
144
|
writeSecurely
|
|
132
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-BMV56JCL.js";
|
|
133
146
|
import {
|
|
134
147
|
array,
|
|
135
148
|
boolean,
|
|
@@ -153,10 +166,10 @@ import {
|
|
|
153
166
|
transform,
|
|
154
167
|
trim,
|
|
155
168
|
union
|
|
156
|
-
} from "./chunk-
|
|
169
|
+
} from "./chunk-BHNBWFT5.js";
|
|
157
170
|
import {
|
|
158
171
|
CliError
|
|
159
|
-
} from "./chunk-
|
|
172
|
+
} from "./chunk-DALBYUPC.js";
|
|
160
173
|
import {
|
|
161
174
|
__commonJS,
|
|
162
175
|
__name,
|
|
@@ -1810,7 +1823,7 @@ var require_liquid_node = __commonJS({
|
|
|
1810
1823
|
return readFileAsync(filepath, "utf8");
|
|
1811
1824
|
}
|
|
1812
1825
|
__name(readFile, "readFile");
|
|
1813
|
-
function
|
|
1826
|
+
function existsSync10(filepath) {
|
|
1814
1827
|
try {
|
|
1815
1828
|
fs$1.statSync(filepath);
|
|
1816
1829
|
return true;
|
|
@@ -1818,11 +1831,11 @@ var require_liquid_node = __commonJS({
|
|
|
1818
1831
|
return false;
|
|
1819
1832
|
}
|
|
1820
1833
|
}
|
|
1821
|
-
__name(
|
|
1822
|
-
function
|
|
1834
|
+
__name(existsSync10, "existsSync");
|
|
1835
|
+
function readFileSync5(filepath) {
|
|
1823
1836
|
return fs$1.readFileSync(filepath, "utf8");
|
|
1824
1837
|
}
|
|
1825
|
-
__name(
|
|
1838
|
+
__name(readFileSync5, "readFileSync");
|
|
1826
1839
|
function resolve2(root, file2, ext) {
|
|
1827
1840
|
if (!path.extname(file2))
|
|
1828
1841
|
file2 += ext;
|
|
@@ -1836,10 +1849,10 @@ var require_liquid_node = __commonJS({
|
|
|
1836
1849
|
}
|
|
1837
1850
|
}
|
|
1838
1851
|
__name(fallback, "fallback");
|
|
1839
|
-
function
|
|
1852
|
+
function dirname3(filepath) {
|
|
1840
1853
|
return path.dirname(filepath);
|
|
1841
1854
|
}
|
|
1842
|
-
__name(
|
|
1855
|
+
__name(dirname3, "dirname");
|
|
1843
1856
|
var realpathAsync = promisify(fs$1.realpath);
|
|
1844
1857
|
async function contains(root, file2) {
|
|
1845
1858
|
try {
|
|
@@ -1867,11 +1880,11 @@ var require_liquid_node = __commonJS({
|
|
|
1867
1880
|
__proto__: null,
|
|
1868
1881
|
exists,
|
|
1869
1882
|
readFile,
|
|
1870
|
-
existsSync:
|
|
1871
|
-
readFileSync:
|
|
1883
|
+
existsSync: existsSync10,
|
|
1884
|
+
readFileSync: readFileSync5,
|
|
1872
1885
|
resolve: resolve2,
|
|
1873
1886
|
fallback,
|
|
1874
|
-
dirname:
|
|
1887
|
+
dirname: dirname3,
|
|
1875
1888
|
contains,
|
|
1876
1889
|
containsSync,
|
|
1877
1890
|
sep: path.sep
|
|
@@ -3596,7 +3609,7 @@ var require_liquid_node = __commonJS({
|
|
|
3596
3609
|
uri_escape,
|
|
3597
3610
|
slugify
|
|
3598
3611
|
});
|
|
3599
|
-
var
|
|
3612
|
+
var join5 = argumentsToValue(function(v, arg) {
|
|
3600
3613
|
const array2 = toArray(v);
|
|
3601
3614
|
const sep = isNil(arg) ? " " : stringify(arg);
|
|
3602
3615
|
let outputSize = sep.length * Math.max(array2.length - 1, 0);
|
|
@@ -3872,7 +3885,7 @@ var require_liquid_node = __commonJS({
|
|
|
3872
3885
|
__name(sample, "sample");
|
|
3873
3886
|
var arrayFilters = /* @__PURE__ */ Object.freeze({
|
|
3874
3887
|
__proto__: null,
|
|
3875
|
-
join:
|
|
3888
|
+
join: join5,
|
|
3876
3889
|
last,
|
|
3877
3890
|
first,
|
|
3878
3891
|
reverse,
|
|
@@ -4800,15 +4813,15 @@ var require_liquid_node = __commonJS({
|
|
|
4800
4813
|
}
|
|
4801
4814
|
*render(ctx, emitter) {
|
|
4802
4815
|
const group = yield evalToken(this.group, ctx);
|
|
4803
|
-
const
|
|
4816
|
+
const fingerprint2 = `cycle:${group}:` + this.candidates.join(",");
|
|
4804
4817
|
const groups = ctx.getRegister("cycle", {});
|
|
4805
|
-
let idx = groups[
|
|
4818
|
+
let idx = groups[fingerprint2];
|
|
4806
4819
|
if (idx === void 0) {
|
|
4807
|
-
idx = groups[
|
|
4820
|
+
idx = groups[fingerprint2] = 0;
|
|
4808
4821
|
}
|
|
4809
4822
|
const candidate = this.candidates[idx];
|
|
4810
4823
|
idx = (idx + 1) % this.candidates.length;
|
|
4811
|
-
groups[
|
|
4824
|
+
groups[fingerprint2] = idx;
|
|
4812
4825
|
return yield evalToken(candidate, ctx);
|
|
4813
4826
|
}
|
|
4814
4827
|
*arguments() {
|
|
@@ -5496,11 +5509,11 @@ var require_liquid_node = __commonJS({
|
|
|
5496
5509
|
}
|
|
5497
5510
|
});
|
|
5498
5511
|
|
|
5499
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5500
|
-
import { chmodSync, constants, copyFileSync, existsSync as
|
|
5501
|
-
import { dirname, resolve } from "node:path";
|
|
5512
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
|
|
5513
|
+
import { chmodSync, constants, copyFileSync, existsSync as existsSync9, mkdirSync, realpathSync as realpathSync2, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5514
|
+
import { dirname as dirname2, resolve } from "node:path";
|
|
5502
5515
|
|
|
5503
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5516
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/sealed.js
|
|
5504
5517
|
import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
5505
5518
|
import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
|
|
5506
5519
|
import { Transform } from "node:stream";
|
|
@@ -5607,7 +5620,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
|
|
|
5607
5620
|
renameSync(pending, to);
|
|
5608
5621
|
}, "unsealFile");
|
|
5609
5622
|
|
|
5610
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5623
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/compatibility.js
|
|
5611
5624
|
var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
|
|
5612
5625
|
var fileSchemaOf = /* @__PURE__ */ __name((database) => {
|
|
5613
5626
|
const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
|
|
@@ -5631,7 +5644,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
|
|
|
5631
5644
|
};
|
|
5632
5645
|
}, "compatibilityOf");
|
|
5633
5646
|
|
|
5634
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5647
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/repair.js
|
|
5635
5648
|
import { createHash as createHash2 } from "node:crypto";
|
|
5636
5649
|
var COPY_MARK = "__repair_";
|
|
5637
5650
|
var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
|
|
@@ -5885,10 +5898,457 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
|
|
|
5885
5898
|
return found;
|
|
5886
5899
|
}, "deleteCopy");
|
|
5887
5900
|
|
|
5888
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5889
|
-
import { existsSync as
|
|
5901
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
|
|
5902
|
+
import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
|
|
5903
|
+
|
|
5904
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
|
|
5905
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
5906
|
+
|
|
5907
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/store/recover.js
|
|
5908
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
5909
|
+
import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
|
|
5910
|
+
import { basename, dirname, join } from "node:path";
|
|
5911
|
+
import { Transform as Transform2 } from "node:stream";
|
|
5912
|
+
var SQLITE3_MINIMUM = [3, 43, 0];
|
|
5913
|
+
var STORE_PARTS = ["", "-wal", "-shm"];
|
|
5914
|
+
var INSERTED = /^INSERT OR IGNORE INTO '([^']+)'/;
|
|
5915
|
+
var LOST_AND_FOUND = "recover_lost_and_found";
|
|
5916
|
+
var recovers = /* @__PURE__ */ __name((program) => {
|
|
5917
|
+
try {
|
|
5918
|
+
execFileSync(program, [":memory:", ".recover"], { stdio: ["ignore", "ignore", "pipe"] });
|
|
5919
|
+
return true;
|
|
5920
|
+
} catch {
|
|
5921
|
+
return false;
|
|
5922
|
+
}
|
|
5923
|
+
}, "recovers");
|
|
5924
|
+
var sqlite3Program = /* @__PURE__ */ __name((program = "sqlite3") => {
|
|
5925
|
+
let version = null;
|
|
5926
|
+
try {
|
|
5927
|
+
version = execFileSync(program, ["--version"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).split(" ")[0] ?? null;
|
|
5928
|
+
} catch {
|
|
5929
|
+
return { program, version: null, usable: false };
|
|
5930
|
+
}
|
|
5931
|
+
const parts = (version ?? "").split(".").map(Number);
|
|
5932
|
+
const at = SQLITE3_MINIMUM.findIndex((wanted, i) => (parts[i] ?? 0) !== wanted);
|
|
5933
|
+
const recent = at === -1 || (parts[at] ?? 0) > (SQLITE3_MINIMUM[at] ?? 0);
|
|
5934
|
+
return { program, version, usable: recent && recovers(program) };
|
|
5935
|
+
}, "sqlite3Program");
|
|
5936
|
+
var activeTimers = /* @__PURE__ */ __name(() => {
|
|
5937
|
+
if (process.platform !== "linux")
|
|
5938
|
+
return void 0;
|
|
5939
|
+
try {
|
|
5940
|
+
return execFileSync("systemctl", ["--user", "list-timers", "--plain", "--no-legend"], {
|
|
5941
|
+
encoding: "utf8",
|
|
5942
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
5943
|
+
}).split("\n").map((line) => line.trim().split(/\s+/).at(-2) ?? "").filter((unit) => /^(memo|mail|tg|max|whatsapp|zoom|drive|gcal|wirecat)-.*\.timer$/.test(unit));
|
|
5944
|
+
} catch {
|
|
5945
|
+
return void 0;
|
|
5946
|
+
}
|
|
5947
|
+
}, "activeTimers");
|
|
5948
|
+
var storeHolders = /* @__PURE__ */ __name((path) => {
|
|
5949
|
+
const folder = realpathSync(dirname(path));
|
|
5950
|
+
const files = STORE_PARTS.map((suffix) => join(folder, `${basename(path)}${suffix}`));
|
|
5951
|
+
const wanted = process.platform === "linux" ? files.flatMap((file2) => [file2, `${file2} (deleted)`]) : files.filter(existsSync2);
|
|
5952
|
+
return holdersOf(wanted)?.map((pid) => {
|
|
5953
|
+
let name = "?";
|
|
5954
|
+
try {
|
|
5955
|
+
name = readFileSync(`/proc/${pid}/comm`, "utf8").trim();
|
|
5956
|
+
} catch {
|
|
5957
|
+
}
|
|
5958
|
+
return { pid, name };
|
|
5959
|
+
});
|
|
5960
|
+
}, "storeHolders");
|
|
5961
|
+
var tableRows = /* @__PURE__ */ __name((database) => {
|
|
5962
|
+
const indexes = fts5Tables(database).map((index) => index.name);
|
|
5963
|
+
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}_`)));
|
|
5964
|
+
return Object.fromEntries(tables.map((table) => {
|
|
5965
|
+
try {
|
|
5966
|
+
return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
|
|
5967
|
+
} catch {
|
|
5968
|
+
return [table, null];
|
|
5969
|
+
}
|
|
5970
|
+
}));
|
|
5971
|
+
}, "tableRows");
|
|
5972
|
+
var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
|
|
5973
|
+
const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
|
|
5974
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
5975
|
+
});
|
|
5976
|
+
const writer = spawn(program, ["-cmd", ".dbconfig defensive off", target], { stdio: ["pipe", "ignore", "pipe"] });
|
|
5977
|
+
const errors = [];
|
|
5978
|
+
const collect = /* @__PURE__ */ __name((chunk) => {
|
|
5979
|
+
for (const line of chunk.toString("utf8").split("\n"))
|
|
5980
|
+
if (line && errors.length < 50)
|
|
5981
|
+
errors.push(line.slice(0, 300));
|
|
5982
|
+
}, "collect");
|
|
5983
|
+
reader.stderr.on("data", collect);
|
|
5984
|
+
writer.stderr.on("data", collect);
|
|
5985
|
+
const read = {};
|
|
5986
|
+
let rest = "";
|
|
5987
|
+
const counter = new Transform2({
|
|
5988
|
+
transform(chunk, _encoding, done) {
|
|
5989
|
+
const lines = (rest + chunk.toString("latin1")).split("\n");
|
|
5990
|
+
rest = lines.pop() ?? "";
|
|
5991
|
+
for (const line of lines) {
|
|
5992
|
+
const table = INSERTED.exec(line)?.[1];
|
|
5993
|
+
if (table)
|
|
5994
|
+
read[table] = (read[table] ?? 0) + 1;
|
|
5995
|
+
}
|
|
5996
|
+
done(null, chunk);
|
|
5997
|
+
}
|
|
5998
|
+
});
|
|
5999
|
+
reader.stdout.pipe(counter).pipe(writer.stdin);
|
|
6000
|
+
let exits = 0;
|
|
6001
|
+
let readerCode = null;
|
|
6002
|
+
const exited = /* @__PURE__ */ __name(() => {
|
|
6003
|
+
exits += 1;
|
|
6004
|
+
if (exits < 2)
|
|
6005
|
+
return;
|
|
6006
|
+
if (readerCode !== 0)
|
|
6007
|
+
reject(new CliError("validation_error", `sqlite3 could not read the store: ${errors.join("; ")}`));
|
|
6008
|
+
else
|
|
6009
|
+
resolve2({ errors, read });
|
|
6010
|
+
}, "exited");
|
|
6011
|
+
reader.on("error", reject);
|
|
6012
|
+
writer.on("error", reject);
|
|
6013
|
+
reader.on("close", (code) => {
|
|
6014
|
+
readerCode = code;
|
|
6015
|
+
exited();
|
|
6016
|
+
});
|
|
6017
|
+
writer.on("close", exited);
|
|
6018
|
+
}), "copyReadableRows");
|
|
6019
|
+
var FILLERS = {
|
|
6020
|
+
message_words: /* @__PURE__ */ __name((database, now) => {
|
|
6021
|
+
resetSearchIndex(database);
|
|
6022
|
+
fillSearchIndex(database, { now });
|
|
6023
|
+
}, "message_words"),
|
|
6024
|
+
message_stems: /* @__PURE__ */ __name((database, now) => {
|
|
6025
|
+
resetStems(database, { force: true, now });
|
|
6026
|
+
fillStems(database, { now });
|
|
6027
|
+
}, "message_stems"),
|
|
6028
|
+
attachment_words: /* @__PURE__ */ __name((database) => void resetAttachmentWords(database), "attachment_words"),
|
|
6029
|
+
attachment_name_words: /* @__PURE__ */ __name((database) => (
|
|
6030
|
+
// As migration 20 filled it: й and ё fold as the triggers fold them.
|
|
6031
|
+
database.exec("INSERT INTO attachment_name_words (rowid, name) SELECT id, replace(replace(replace(replace(name, '\u0439', '\u0438'), '\u0419', '\u0418'), '\u0451', '\u0435'), '\u0401', '\u0415') FROM attachments WHERE name IS NOT NULL")
|
|
6032
|
+
), "attachment_name_words"),
|
|
6033
|
+
meeting_words: /* @__PURE__ */ __name((database) => {
|
|
6034
|
+
database.exec("INSERT OR IGNORE INTO meeting_index_pending (indexable_type, id) SELECT 'meeting_transcript_row', id FROM meeting_transcript_rows UNION ALL SELECT 'meeting_chat_message', id FROM meeting_chat_messages UNION ALL SELECT 'meeting_summary', id FROM meeting_summaries");
|
|
6035
|
+
drainMeetingIndex(database);
|
|
6036
|
+
}, "meeting_words"),
|
|
6037
|
+
// Built per account by the first search that needs them.
|
|
6038
|
+
meeting_stems: /* @__PURE__ */ __name((database) => database.exec("UPDATE search_index_state SET filled_through = 0, built_at = NULL WHERE name LIKE 'meeting_stems:%'"), "meeting_stems")
|
|
6039
|
+
};
|
|
6040
|
+
var CORPUS_TABLES = new Set(Object.values(CORPORA).flatMap((corpus) => [`${corpus.type}_words`, `${corpus.type}_stems`]));
|
|
6041
|
+
var TRIGRAMS = ["note_trigrams", "document_trigrams"];
|
|
6042
|
+
var rebuildDerived = /* @__PURE__ */ __name((database, { now = Date.now, note = /* @__PURE__ */ __name(() => {
|
|
6043
|
+
}, "note") } = {}) => {
|
|
6044
|
+
const lost = database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND);
|
|
6045
|
+
const lostAndFound = lost ? Number(database.prepare(`SELECT count(*) AS n FROM ${LOST_AND_FOUND}`).get()?.n) : 0;
|
|
6046
|
+
if (lost)
|
|
6047
|
+
database.exec(`DROP TABLE ${LOST_AND_FOUND}`);
|
|
6048
|
+
const indexes = fts5Tables(database);
|
|
6049
|
+
for (const { name, sql } of indexes) {
|
|
6050
|
+
database.exec(`DROP TABLE "${name}"`);
|
|
6051
|
+
database.exec(sql);
|
|
6052
|
+
}
|
|
6053
|
+
const vectors = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name GLOB 'vector_index_[0-9]*' AND sql LIKE 'CREATE VIRTUAL%'").all().map((row) => String(row.name));
|
|
6054
|
+
for (const table of vectors) {
|
|
6055
|
+
database.exec(`DROP TRIGGER IF EXISTS "${table}_redo"`);
|
|
6056
|
+
database.exec(`DROP TABLE "${table}"`);
|
|
6057
|
+
database.prepare("DELETE FROM vector_indexes WHERE id = ?").run(Number(table.replace("vector_index_", "")));
|
|
6058
|
+
}
|
|
6059
|
+
const unfilled = [];
|
|
6060
|
+
const stemmerFor = stemmerCache();
|
|
6061
|
+
for (const { name, external } of indexes) {
|
|
6062
|
+
note(`rebuilding ${name}`);
|
|
6063
|
+
if (external)
|
|
6064
|
+
database.exec(`INSERT INTO "${name}" ("${name}") VALUES ('rebuild')`);
|
|
6065
|
+
else if (FILLERS[name])
|
|
6066
|
+
FILLERS[name](database, now);
|
|
6067
|
+
else if (!CORPUS_TABLES.has(name) && !TRIGRAMS.includes(name))
|
|
6068
|
+
unfilled.push(name);
|
|
6069
|
+
}
|
|
6070
|
+
note("rebuilding the words of notes, documents, memories, mail, tasks, transcripts and events");
|
|
6071
|
+
resetNoteIndex(database);
|
|
6072
|
+
for (const corpus of Object.values(CORPORA))
|
|
6073
|
+
drainCorpus(database, corpus, stemmerFor);
|
|
6074
|
+
for (const name of TRIGRAMS) {
|
|
6075
|
+
const type = name.replace("_trigrams", "");
|
|
6076
|
+
database.prepare(`UPDATE search_index_state SET filled_through = 0, watermark = (SELECT coalesce(max(id), 0) FROM ${type}s) WHERE name = ?`).run(name);
|
|
6077
|
+
}
|
|
6078
|
+
fillTrigrams(database);
|
|
6079
|
+
note("finding mentions again");
|
|
6080
|
+
const mentions = rebuildMentions(database, { now: now() }).mentions;
|
|
6081
|
+
involvementStoreOver({ database, now }).rebuild();
|
|
6082
|
+
note("indexing the stored vectors");
|
|
6083
|
+
const vectorModels = fillVectorIndexes(database);
|
|
6084
|
+
const without = database.prepare("SELECT count(*) AS n FROM chunks k WHERE NOT EXISTS (SELECT 1 FROM embeddings v WHERE v.model = ? AND v.content_hash = k.content_hash)");
|
|
6085
|
+
const chunksWithoutVector = Object.fromEntries(database.prepare("SELECT model FROM vector_indexes ORDER BY model").all().map((row) => [String(row.model), Number(without.get(String(row.model))?.n)]));
|
|
6086
|
+
return {
|
|
6087
|
+
lostAndFound,
|
|
6088
|
+
searchIndexes: indexes.map((index) => index.name),
|
|
6089
|
+
unfilled,
|
|
6090
|
+
mentions,
|
|
6091
|
+
vectorModels,
|
|
6092
|
+
chunksWithoutVector
|
|
6093
|
+
};
|
|
6094
|
+
}, "rebuildDerived");
|
|
6095
|
+
var danglingRows = /* @__PURE__ */ __name((database) => database.prepare(`SELECT "table" AS child, parent, fkid, count(*) AS n FROM pragma_foreign_key_check GROUP BY 1, 2, 3 ORDER BY 4 DESC`).all().map((group) => {
|
|
6096
|
+
const child = String(group.child);
|
|
6097
|
+
const column = database.prepare(`SELECT "from" AS name FROM pragma_foreign_key_list(?) WHERE id = ? ORDER BY seq LIMIT 1`).get(child, Number(group.fkid))?.name;
|
|
6098
|
+
let missing = [];
|
|
6099
|
+
try {
|
|
6100
|
+
missing = database.prepare(`SELECT DISTINCT "${String(column)}" AS id FROM "${child}" WHERE rowid IN (SELECT rowid FROM pragma_foreign_key_check(?) WHERE fkid = ?) ORDER BY 1 LIMIT 20`).all(child, Number(group.fkid)).map((row) => typeof row.id === "number" ? row.id : String(row.id));
|
|
6101
|
+
} catch {
|
|
6102
|
+
}
|
|
6103
|
+
return { table: child, parent: String(group.parent), rows: Number(group.n), missing };
|
|
6104
|
+
}), "danglingRows");
|
|
6105
|
+
var mailToFetch = /* @__PURE__ */ __name((database) => {
|
|
6106
|
+
try {
|
|
6107
|
+
return database.prepare(`SELECT a.external_id AS account, count(DISTINCT l.email_id) AS n FROM email_locations l
|
|
6108
|
+
JOIN mailboxes b ON b.id = l.mailbox_id JOIN accounts a ON a.id = b.account_id
|
|
6109
|
+
WHERE NOT EXISTS (SELECT 1 FROM emails e WHERE e.id = l.email_id) GROUP BY a.id ORDER BY a.external_id`).all().map((row) => ({ account: String(row.account), emails: Number(row.n) }));
|
|
6110
|
+
} catch {
|
|
6111
|
+
return [];
|
|
6112
|
+
}
|
|
6113
|
+
}, "mailToFetch");
|
|
6114
|
+
var fingerprint = /* @__PURE__ */ __name((path) => ["", "-wal"].map((suffix) => {
|
|
6115
|
+
const stat = statSync2(`${path}${suffix}`, { throwIfNoEntry: false });
|
|
6116
|
+
return stat ? `${stat.size}:${stat.mtimeMs}` : "-";
|
|
6117
|
+
}).join("|"), "fingerprint");
|
|
6118
|
+
var refuseInUse = /* @__PURE__ */ __name((path) => {
|
|
6119
|
+
const holders = storeHolders(path);
|
|
6120
|
+
if (holders && holders.length > 0) {
|
|
6121
|
+
const timers = activeTimers() ?? [];
|
|
6122
|
+
throw new CliError("validation_error", `the store is open in ${holders.map(({ pid, name }) => `${name} (process ${pid})`).join(", ")} \u2014 stop it first` + (timers.length ? `, and the timers: systemctl --user stop ${timers.join(" ")}` : ""), { reason: "store.in-use" });
|
|
6123
|
+
}
|
|
6124
|
+
}, "refuseInUse");
|
|
6125
|
+
var recoverStore = /* @__PURE__ */ __name(async ({ path, command, version, sqlite3 = "sqlite3", now = Date.now, note = /* @__PURE__ */ __name(() => {
|
|
6126
|
+
}, "note"), copy }) => {
|
|
6127
|
+
const started = Date.now();
|
|
6128
|
+
if (!existsSync2(path))
|
|
6129
|
+
throw new CliError("not_found", `no store at ${path}`);
|
|
6130
|
+
const program = copy ? { program: sqlite3, version: "given", usable: true } : sqlite3Program(sqlite3);
|
|
6131
|
+
if (!program.usable) {
|
|
6132
|
+
throw new CliError("configuration_error", program.version ? `sqlite3 ${program.version} cannot recover: the recovery needs ${SQLITE3_MINIMUM.join(".")} or newer, built with .recover` : "the recovery needs the sqlite3 program with its .recover command: install it (apt install sqlite3, brew install sqlite)", { reason: "store.sqlite3-missing" });
|
|
6133
|
+
}
|
|
6134
|
+
refuseInUse(path);
|
|
6135
|
+
const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
|
|
6136
|
+
const { bavail, bsize } = statfsSync(dirname(path));
|
|
6137
|
+
if (Number(bavail) * Number(bsize) < bytes * 1.2)
|
|
6138
|
+
throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
|
|
6139
|
+
const old = await openSqlite(path, { readOnly: true });
|
|
6140
|
+
let rowsBefore;
|
|
6141
|
+
try {
|
|
6142
|
+
rowsBefore = tableRows(old.database);
|
|
6143
|
+
} finally {
|
|
6144
|
+
old.database.close();
|
|
6145
|
+
}
|
|
6146
|
+
const before = fingerprint(path);
|
|
6147
|
+
const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
|
|
6148
|
+
const target = `${path}.recovering-${stamp}`;
|
|
6149
|
+
writeFileSync(target, "", { flag: "wx", mode: 384 });
|
|
6150
|
+
const dropTarget = /* @__PURE__ */ __name(() => {
|
|
6151
|
+
for (const suffix of [...STORE_PARTS, "-journal"])
|
|
6152
|
+
rmSync2(`${target}${suffix}`, { force: true });
|
|
6153
|
+
}, "dropTarget");
|
|
6154
|
+
note(`copying the readable rows into ${target}`);
|
|
6155
|
+
let copied;
|
|
6156
|
+
let copyErrors;
|
|
6157
|
+
let read;
|
|
6158
|
+
let opened;
|
|
6159
|
+
try {
|
|
6160
|
+
;
|
|
6161
|
+
({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
|
|
6162
|
+
copied = Date.now();
|
|
6163
|
+
opened = await openSqlite(target);
|
|
6164
|
+
} catch (error) {
|
|
6165
|
+
dropTarget();
|
|
6166
|
+
throw error;
|
|
6167
|
+
}
|
|
6168
|
+
let rebuilt;
|
|
6169
|
+
let kept;
|
|
6170
|
+
let dangling;
|
|
6171
|
+
let fetch2;
|
|
6172
|
+
try {
|
|
6173
|
+
kept = tableRows(opened.database);
|
|
6174
|
+
migrate(opened.database, { command, ...version ? { version } : {} });
|
|
6175
|
+
rebuilt = rebuildDerived(opened.database, { now, note });
|
|
6176
|
+
note("looking for rows that point at rows that were lost");
|
|
6177
|
+
dangling = danglingRows(opened.database);
|
|
6178
|
+
fetch2 = mailToFetch(opened.database);
|
|
6179
|
+
opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
6180
|
+
} catch (error) {
|
|
6181
|
+
opened.database.close();
|
|
6182
|
+
dropTarget();
|
|
6183
|
+
throw error;
|
|
6184
|
+
}
|
|
6185
|
+
opened.database.close();
|
|
6186
|
+
const rebuiltAt = Date.now();
|
|
6187
|
+
note("checking the recovered file");
|
|
6188
|
+
const health = await storeHealth(target, { deep: true });
|
|
6189
|
+
const checkedAt = Date.now();
|
|
6190
|
+
if (!health.ok) {
|
|
6191
|
+
throw new CliError("validation_error", `the recovered file did not pass its check, so the store was left as it was; the file is kept at ${target}`, { reason: "store.recovery-failed" });
|
|
6192
|
+
}
|
|
6193
|
+
refuseInUse(path);
|
|
6194
|
+
if (fingerprint(path) !== before) {
|
|
6195
|
+
throw new CliError("validation_error", `the store was written to during the recovery, so it was left as it was \u2014 stop every timer and run it again; ${target} can be deleted`, { reason: "store.changed-during-recovery" });
|
|
6196
|
+
}
|
|
6197
|
+
const keptAt = `${path}.before-recover-${stamp}`;
|
|
6198
|
+
for (const suffix of STORE_PARTS)
|
|
6199
|
+
if (existsSync2(`${path}${suffix}`))
|
|
6200
|
+
renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
|
|
6201
|
+
for (const suffix of STORE_PARTS)
|
|
6202
|
+
if (existsSync2(`${target}${suffix}`))
|
|
6203
|
+
renameSync2(`${target}${suffix}`, `${path}${suffix}`);
|
|
6204
|
+
const lost = Object.entries(rowsBefore).map(([table, before2]) => ({ table, before: before2, read: read[table] ?? 0, kept: kept[table] ?? 0 })).filter(({ before: before2, read: read2, kept: kept2 }) => before2 === null || before2 > kept2 || read2 > kept2);
|
|
6205
|
+
const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
|
|
6206
|
+
return {
|
|
6207
|
+
path,
|
|
6208
|
+
keptAt,
|
|
6209
|
+
sqlite3: program.version,
|
|
6210
|
+
lost,
|
|
6211
|
+
dangling,
|
|
6212
|
+
mailToFetch: fetch2,
|
|
6213
|
+
rebuilt,
|
|
6214
|
+
copyErrors,
|
|
6215
|
+
health,
|
|
6216
|
+
seconds: {
|
|
6217
|
+
copy: seconds(started, copied),
|
|
6218
|
+
rebuild: seconds(copied, rebuiltAt),
|
|
6219
|
+
check: seconds(rebuiltAt, checkedAt),
|
|
6220
|
+
total: seconds(started, Date.now())
|
|
6221
|
+
}
|
|
6222
|
+
};
|
|
6223
|
+
}, "recoverStore");
|
|
6224
|
+
|
|
6225
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
|
|
6226
|
+
var COUNTED = [
|
|
6227
|
+
"accounts",
|
|
6228
|
+
"chats",
|
|
6229
|
+
"messages",
|
|
6230
|
+
"attachments",
|
|
6231
|
+
"emails",
|
|
6232
|
+
"documents",
|
|
6233
|
+
"notes",
|
|
6234
|
+
"meetings",
|
|
6235
|
+
"chunks",
|
|
6236
|
+
"embeddings",
|
|
6237
|
+
"mentions"
|
|
6238
|
+
];
|
|
6239
|
+
var stopTimers = /* @__PURE__ */ __name((timers) => `systemctl --user stop ${timers.join(" ")}`, "stopTimers");
|
|
6240
|
+
var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command) => {
|
|
6241
|
+
const path = storePath(env);
|
|
6242
|
+
if (!existsSync3(path))
|
|
6243
|
+
return { path, exists: false, ok: true, next: [] };
|
|
6244
|
+
const health = await storeHealth(path, { deep: true });
|
|
6245
|
+
let rows = {};
|
|
6246
|
+
try {
|
|
6247
|
+
const { database } = await openSqlite(path, { readOnly: true });
|
|
6248
|
+
try {
|
|
6249
|
+
const all = tableRows(database);
|
|
6250
|
+
rows = Object.fromEntries(COUNTED.filter((table) => table in all).map((table) => [table, all[table] ?? null]));
|
|
6251
|
+
} finally {
|
|
6252
|
+
database.close();
|
|
6253
|
+
}
|
|
6254
|
+
} catch {
|
|
6255
|
+
}
|
|
6256
|
+
const explanation = explainDamage(health, command);
|
|
6257
|
+
const inUse = storeHolders(path) ?? null;
|
|
6258
|
+
const timers = activeTimers() ?? null;
|
|
6259
|
+
const sqlite3 = sqlite3Program();
|
|
6260
|
+
const next = health.ok ? [] : [
|
|
6261
|
+
...timers?.length ? [stopTimers(timers)] : [],
|
|
6262
|
+
...(inUse ?? []).map(({ pid, name }) => `stop ${name} (process ${pid}): it has the store open`),
|
|
6263
|
+
...sqlite3.usable ? [] : ["install sqlite3 3.43 or newer (apt install sqlite3, brew install sqlite)"],
|
|
6264
|
+
`${command} store recover run`
|
|
6265
|
+
];
|
|
6266
|
+
return {
|
|
6267
|
+
path,
|
|
6268
|
+
exists: true,
|
|
6269
|
+
ok: health.ok,
|
|
6270
|
+
seconds: Math.round(health.ms / 100) / 10,
|
|
6271
|
+
problems: health.problems ?? 0,
|
|
6272
|
+
damagedTables: health.damagedTables ?? [],
|
|
6273
|
+
damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
|
|
6274
|
+
rows,
|
|
6275
|
+
explanation,
|
|
6276
|
+
inUse,
|
|
6277
|
+
timers,
|
|
6278
|
+
sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
|
|
6279
|
+
next
|
|
6280
|
+
};
|
|
6281
|
+
}, "storeRecoveryCheck");
|
|
6282
|
+
var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, note, timers: scheduled = activeTimers, copy }) => {
|
|
6283
|
+
const timers = scheduled() ?? [];
|
|
6284
|
+
if (timers.length > 0)
|
|
6285
|
+
throw new CliError("validation_error", `stop the timers first, they open the store: ${stopTimers(timers)}`, {
|
|
6286
|
+
reason: "store.in-use"
|
|
6287
|
+
});
|
|
6288
|
+
const recovery = await recoverStore({
|
|
6289
|
+
path: storePath(env),
|
|
6290
|
+
command,
|
|
6291
|
+
...version ? { version } : {},
|
|
6292
|
+
...note ? { note } : {},
|
|
6293
|
+
...copy ? { copy } : {}
|
|
6294
|
+
});
|
|
6295
|
+
const mail = recovery.mailToFetch.map(({ account, emails }) => `mail <profile of ${account}> sync --rescan # ${emails} emails`);
|
|
6296
|
+
const lostMail = recovery.lost.some(({ table }) => table === "emails") && mail.length === 0 ? ["mail <profile> sync --rescan # each mail profile"] : [];
|
|
6297
|
+
const { health, copyErrors, ...kept } = recovery;
|
|
6298
|
+
return {
|
|
6299
|
+
...kept,
|
|
6300
|
+
copyErrors: copyErrors.length,
|
|
6301
|
+
checkedOk: health.ok,
|
|
6302
|
+
next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
|
|
6303
|
+
};
|
|
6304
|
+
}, "storeRecoveryRun");
|
|
6305
|
+
var recoveryNotes = /* @__PURE__ */ __name((answer) => {
|
|
6306
|
+
if ("keptAt" in answer) {
|
|
6307
|
+
const lost = answer.lost.map(({ table, before, read, kept }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}`);
|
|
6308
|
+
return [
|
|
6309
|
+
`recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
|
|
6310
|
+
...lost.length ? lost : ["no table lost a row"],
|
|
6311
|
+
...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
|
|
6312
|
+
...answer.next.map((line) => `next: ${line}`)
|
|
6313
|
+
];
|
|
6314
|
+
}
|
|
6315
|
+
if (!answer.exists)
|
|
6316
|
+
return ["no store yet"];
|
|
6317
|
+
if (answer.ok)
|
|
6318
|
+
return [`the store is healthy (checked every page and search index in ${answer.seconds} s)`];
|
|
6319
|
+
const why = answer.explanation;
|
|
6320
|
+
return [
|
|
6321
|
+
...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
|
|
6322
|
+
...answer.next.map((line) => `next: ${line}`)
|
|
6323
|
+
];
|
|
6324
|
+
}, "recoveryNotes");
|
|
6325
|
+
var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
|
|
6326
|
+
const recover = annotate(new Command("recover"), { effects: LOCAL_READ, examples: [`${command} store recover`] }).summary("what is damaged in the store and how to recover it").description("check every page and search index of the store, say what is damaged, what it means and the commands that recover it; changes nothing").action(async function() {
|
|
6327
|
+
const output = outputFor(this);
|
|
6328
|
+
const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command);
|
|
6329
|
+
renderAnswer(this, output, itemOf(snakeKeys(answer)));
|
|
6330
|
+
if (output.format === "pretty")
|
|
6331
|
+
for (const line of recoveryNotes(answer))
|
|
6332
|
+
output.renderer.note(line);
|
|
6333
|
+
});
|
|
6334
|
+
recover.addCommand(annotate(new Command("run"), { effects: LOCAL_WRITE, examples: [`${command} store recover run`] }).summary("rebuild a damaged store from every row it can read").description("copy every readable row into a new file with the sqlite3 program, rebuild the search indexes, mentions and vector index, check it, and put it in place of the store; the damaged file is kept beside it. Refuses while a WireCat timer or process has the store").action(async function() {
|
|
6335
|
+
const output = outputFor(this);
|
|
6336
|
+
const answer = await storeRecoveryRun(environmentOf(this).env ?? process.env, {
|
|
6337
|
+
command,
|
|
6338
|
+
...version ? { version } : {},
|
|
6339
|
+
note: /* @__PURE__ */ __name((text) => output.renderer.note(text), "note")
|
|
6340
|
+
});
|
|
6341
|
+
renderAnswer(this, output, itemOf(snakeKeys(answer)));
|
|
6342
|
+
if (output.format === "pretty")
|
|
6343
|
+
for (const line of recoveryNotes(answer))
|
|
6344
|
+
output.renderer.note(line);
|
|
6345
|
+
}));
|
|
6346
|
+
return recover;
|
|
6347
|
+
}, "storeRecoverCommand");
|
|
6348
|
+
|
|
6349
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/store-info.js
|
|
5890
6350
|
var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
|
|
5891
|
-
var bytesOf = /* @__PURE__ */ __name((path) =>
|
|
6351
|
+
var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
|
|
5892
6352
|
var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
|
|
5893
6353
|
var contentsOf = /* @__PURE__ */ __name((database, version, writable) => version > 0 && writable ? {
|
|
5894
6354
|
rows: rowCounts(database),
|
|
@@ -5899,7 +6359,7 @@ var contentsOf = /* @__PURE__ */ __name((database, version, writable) => version
|
|
|
5899
6359
|
} : { rows: {}, pendingNormalization: null, wordIndex: null, stemIndex: null }, "contentsOf");
|
|
5900
6360
|
var storeInfo = /* @__PURE__ */ __name(async (env) => {
|
|
5901
6361
|
const path = storePath(env);
|
|
5902
|
-
if (!
|
|
6362
|
+
if (!existsSync4(path))
|
|
5903
6363
|
return snakeKeys({ path, exists: false, schema: compatibilityOf(void 0) });
|
|
5904
6364
|
let schema = compatibilityOf(void 0);
|
|
5905
6365
|
try {
|
|
@@ -5932,7 +6392,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
|
|
|
5932
6392
|
renderAnswer(this, outputFor(this), itemOf(answer));
|
|
5933
6393
|
}), "storeInfoCommand");
|
|
5934
6394
|
|
|
5935
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6395
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
|
|
5936
6396
|
var ENCRYPT_OPTION = [
|
|
5937
6397
|
"--encrypt",
|
|
5938
6398
|
"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"
|
|
@@ -5951,9 +6411,9 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
|
|
|
5951
6411
|
return password;
|
|
5952
6412
|
}, "passwordOf");
|
|
5953
6413
|
|
|
5954
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5955
|
-
import { existsSync as
|
|
5956
|
-
import { join } from "node:path";
|
|
6414
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/rules.js
|
|
6415
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
6416
|
+
import { join as join2 } from "node:path";
|
|
5957
6417
|
var REPLY_ACTIONS = ["reply", "task"];
|
|
5958
6418
|
var REPLY_MODELS = ["fill-only", "may-reword"];
|
|
5959
6419
|
var REPLY_KINDS = ["dialog", "group"];
|
|
@@ -6039,7 +6499,7 @@ var defaultRule = /* @__PURE__ */ __name((id) => ({
|
|
|
6039
6499
|
reply: { template: "", asReply: true },
|
|
6040
6500
|
limits: { perChat: "1/1d", perPerson: "1/1d" }
|
|
6041
6501
|
}), "defaultRule");
|
|
6042
|
-
var repliesPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
6502
|
+
var repliesPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).config, `${profile}.replies.json`), "repliesPathFor");
|
|
6043
6503
|
var EVERYONE = { reply: "all", allow: { people: [], chats: [] }, deny: { people: [], chats: [] } };
|
|
6044
6504
|
var outsideAudience = /* @__PURE__ */ __name((audience, person, chat) => {
|
|
6045
6505
|
if (person !== null && audience.deny.people.includes(person))
|
|
@@ -6069,11 +6529,11 @@ var readReplies = /* @__PURE__ */ __name((path, provider) => {
|
|
|
6069
6529
|
return parseReplies(readRepliesFile(path, provider), path, provider);
|
|
6070
6530
|
}, "readReplies");
|
|
6071
6531
|
var readRepliesFile = /* @__PURE__ */ __name((path, provider) => {
|
|
6072
|
-
if (!
|
|
6532
|
+
if (!existsSync5(path))
|
|
6073
6533
|
return { audience: structuredClone(EVERYONE), rules: [] };
|
|
6074
6534
|
let parsed;
|
|
6075
6535
|
try {
|
|
6076
|
-
parsed = JSON.parse(
|
|
6536
|
+
parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
6077
6537
|
} catch (error) {
|
|
6078
6538
|
throw broken(path, error instanceof Error ? error.message : String(error));
|
|
6079
6539
|
}
|
|
@@ -6122,9 +6582,9 @@ var problem = /* @__PURE__ */ __name((issue) => {
|
|
|
6122
6582
|
}, "problem");
|
|
6123
6583
|
var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
|
|
6124
6584
|
|
|
6125
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6126
|
-
import { existsSync as
|
|
6127
|
-
import { join as
|
|
6585
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/state.js
|
|
6586
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
6587
|
+
import { join as join3 } from "node:path";
|
|
6128
6588
|
var ANSWERED_KEPT = 1e3;
|
|
6129
6589
|
var times = record(string(), array(string()));
|
|
6130
6590
|
var stateFile = object({
|
|
@@ -6136,13 +6596,13 @@ var stateFile = object({
|
|
|
6136
6596
|
});
|
|
6137
6597
|
var emptyState = /* @__PURE__ */ __name(() => ({ paused: false, answered: [], sent: {} }), "emptyState");
|
|
6138
6598
|
var answeredKey = /* @__PURE__ */ __name((message) => `${message.chatId}:${message.id}`, "answeredKey");
|
|
6139
|
-
var repliesStatePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
6599
|
+
var repliesStatePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, `${profile}.replies-state.json`), "repliesStatePathFor");
|
|
6140
6600
|
var readRepliesState = /* @__PURE__ */ __name((path) => {
|
|
6141
|
-
if (!
|
|
6601
|
+
if (!existsSync6(path))
|
|
6142
6602
|
return emptyState();
|
|
6143
6603
|
let parsed;
|
|
6144
6604
|
try {
|
|
6145
|
-
parsed = JSON.parse(
|
|
6605
|
+
parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
6146
6606
|
} catch (error) {
|
|
6147
6607
|
throw broken2(path, error instanceof Error ? error.message : String(error));
|
|
6148
6608
|
}
|
|
@@ -6175,7 +6635,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
|
|
|
6175
6635
|
}, "recordReply");
|
|
6176
6636
|
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");
|
|
6177
6637
|
|
|
6178
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6638
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/decide.js
|
|
6179
6639
|
var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
|
|
6180
6640
|
var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
|
|
6181
6641
|
const { message, chat, owner, sender } = incoming;
|
|
@@ -6281,7 +6741,7 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
|
|
|
6281
6741
|
return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
|
|
6282
6742
|
}, "filled");
|
|
6283
6743
|
|
|
6284
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6744
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/template.js
|
|
6285
6745
|
var import_liquidjs = __toESM(require_liquid_node(), 1);
|
|
6286
6746
|
var TEMPLATE_LIMITS = {
|
|
6287
6747
|
parse: 32768,
|
|
@@ -6441,7 +6901,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
|
|
|
6441
6901
|
}
|
|
6442
6902
|
}, "renderReplyTemplate");
|
|
6443
6903
|
|
|
6444
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6904
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
|
|
6445
6905
|
var DRY_RUN_DAYS = 7;
|
|
6446
6906
|
var PAGE = 500;
|
|
6447
6907
|
var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
|
|
@@ -6555,7 +7015,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
|
|
|
6555
7015
|
}
|
|
6556
7016
|
}, "storedSince");
|
|
6557
7017
|
|
|
6558
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7018
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
|
|
6559
7019
|
var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
|
|
6560
7020
|
const host = new URL(baseUrl).host;
|
|
6561
7021
|
return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
|
|
@@ -6586,7 +7046,7 @@ var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) =>
|
|
|
6586
7046
|
};
|
|
6587
7047
|
}, "embeddingKeys");
|
|
6588
7048
|
|
|
6589
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7049
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/models/openai.js
|
|
6590
7050
|
var options = strictObject({
|
|
6591
7051
|
temperature: range(0, 2),
|
|
6592
7052
|
top_p: range(0, 1),
|
|
@@ -6635,7 +7095,7 @@ var openai = {
|
|
|
6635
7095
|
}), "complete")
|
|
6636
7096
|
};
|
|
6637
7097
|
|
|
6638
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7098
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/models/index.js
|
|
6639
7099
|
var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
6640
7100
|
complete: /* @__PURE__ */ __name(async (request) => {
|
|
6641
7101
|
if (deps.signal?.aborted)
|
|
@@ -6650,7 +7110,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
|
6650
7110
|
if (!adapter && target.provider === "openai")
|
|
6651
7111
|
adapter = openai;
|
|
6652
7112
|
if (!adapter && target.provider === "anthropic")
|
|
6653
|
-
adapter = (await import("./anthropic-
|
|
7113
|
+
adapter = (await import("./anthropic-5VIKYINO.js")).anthropic;
|
|
6654
7114
|
if (!adapter)
|
|
6655
7115
|
throw new CliError("validation_error", `no model adapter for ${target.provider}`);
|
|
6656
7116
|
if (request.images !== void 0 && adapter.images !== true)
|
|
@@ -6691,19 +7151,19 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
|
6691
7151
|
}, "complete")
|
|
6692
7152
|
}), "modelGateway");
|
|
6693
7153
|
|
|
6694
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6695
|
-
import { existsSync as
|
|
6696
|
-
import { join as
|
|
7154
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/consents.js
|
|
7155
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
|
|
7156
|
+
import { join as join4 } from "node:path";
|
|
6697
7157
|
var shape = strictObject({
|
|
6698
7158
|
provider: nullable(pipe(string(), minLength(1))),
|
|
6699
7159
|
deniedChats: array(pipe(string(), minLength(1)))
|
|
6700
7160
|
});
|
|
6701
|
-
var replyConsentPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
7161
|
+
var replyConsentPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).config, `${profile}.replies-consents.json`), "replyConsentPathFor");
|
|
6702
7162
|
var readReplyConsent = /* @__PURE__ */ __name((path) => {
|
|
6703
|
-
if (!
|
|
7163
|
+
if (!existsSync7(path))
|
|
6704
7164
|
return { provider: null, deniedChats: [] };
|
|
6705
7165
|
try {
|
|
6706
|
-
return parse(shape, JSON.parse(
|
|
7166
|
+
return parse(shape, JSON.parse(readFileSync4(path, "utf8")));
|
|
6707
7167
|
} catch {
|
|
6708
7168
|
throw new CliError("configuration_error", "reply model consent is invalid; fix its file before granting consent");
|
|
6709
7169
|
}
|
|
@@ -6716,7 +7176,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
|
|
|
6716
7176
|
return consent.provider === provider && !consent.deniedChats.includes(chat);
|
|
6717
7177
|
}, "mayModelReply");
|
|
6718
7178
|
|
|
6719
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7179
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/rendering.js
|
|
6720
7180
|
var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options2 = {
|
|
6721
7181
|
ai: true
|
|
6722
7182
|
}) => async (rule2, message, chat, now) => {
|
|
@@ -6763,7 +7223,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
|
|
|
6763
7223
|
return result2;
|
|
6764
7224
|
}, "replyRenderer");
|
|
6765
7225
|
|
|
6766
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7226
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/replies/serve.js
|
|
6767
7227
|
var NOT_ALLOWED = "replies.send is not allow";
|
|
6768
7228
|
var NO_RULES = "no rules";
|
|
6769
7229
|
var ONLY_TASK = "opened a task, sent nothing";
|
|
@@ -6856,7 +7316,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
|
|
|
6856
7316
|
return { skip: why };
|
|
6857
7317
|
}, "replyTo");
|
|
6858
7318
|
|
|
6859
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7319
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
|
|
6860
7320
|
var START_SYNC_DELAY_MS = 3e4;
|
|
6861
7321
|
var START_SYNC_BUDGET_MS = 5 * 6e4;
|
|
6862
7322
|
var START_SYNC_WINDOW_MS = 7 * 864e5;
|
|
@@ -6933,7 +7393,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
|
|
|
6933
7393
|
};
|
|
6934
7394
|
}, "startSync");
|
|
6935
7395
|
|
|
6936
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7396
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
|
|
6937
7397
|
var FIRST_FETCH_MS = 6e4;
|
|
6938
7398
|
var DAY_MS = 864e5;
|
|
6939
7399
|
var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
|
|
@@ -6987,7 +7447,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
|
|
|
6987
7447
|
};
|
|
6988
7448
|
}, "memberFetches");
|
|
6989
7449
|
|
|
6990
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7450
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
|
|
6991
7451
|
var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
|
|
6992
7452
|
var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
|
|
6993
7453
|
if (context.format === "pretty") {
|
|
@@ -7020,7 +7480,7 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
|
|
|
7020
7480
|
return context;
|
|
7021
7481
|
}, "recordDiagnostics");
|
|
7022
7482
|
|
|
7023
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7483
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
|
|
7024
7484
|
var STEMS_EVERY_MS = 3e4;
|
|
7025
7485
|
var STEMS_SLICE_MS = 2e3;
|
|
7026
7486
|
var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
|
|
@@ -7060,7 +7520,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
|
|
|
7060
7520
|
};
|
|
7061
7521
|
}, "stemFills");
|
|
7062
7522
|
|
|
7063
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7523
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
|
|
7064
7524
|
var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
|
|
7065
7525
|
var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
|
|
7066
7526
|
kind: attachment.kind,
|
|
@@ -7155,7 +7615,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
|
|
|
7155
7615
|
locale: messenger.app.locale
|
|
7156
7616
|
}), "viewOf");
|
|
7157
7617
|
|
|
7158
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7618
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
|
|
7159
7619
|
var observed = /* @__PURE__ */ __name((value) => ({
|
|
7160
7620
|
value: value.value,
|
|
7161
7621
|
observed_at: value.observedAt,
|
|
@@ -7222,7 +7682,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
|
|
|
7222
7682
|
}
|
|
7223
7683
|
}, "watchEventItem");
|
|
7224
7684
|
|
|
7225
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7685
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
|
|
7226
7686
|
var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
|
|
7227
7687
|
output: { entity: "watch_item" },
|
|
7228
7688
|
effects: REMOTE_READ,
|
|
@@ -7377,7 +7837,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
|
|
|
7377
7837
|
}
|
|
7378
7838
|
}, "describe");
|
|
7379
7839
|
|
|
7380
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7840
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
|
|
7381
7841
|
var serveCommand = /* @__PURE__ */ __name((messenger) => {
|
|
7382
7842
|
const command = annotate(new Command("serve"), {
|
|
7383
7843
|
output: { entity: "serve_summary" },
|
|
@@ -7641,8 +8101,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
|
|
|
7641
8101
|
};
|
|
7642
8102
|
}, "tasking");
|
|
7643
8103
|
|
|
7644
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7645
|
-
import { existsSync as
|
|
8104
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
|
|
8105
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
7646
8106
|
var PATH = "store tables list";
|
|
7647
8107
|
var STORE_TABLES_QUERY = {
|
|
7648
8108
|
entity: "store_table",
|
|
@@ -7671,7 +8131,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
|
|
|
7671
8131
|
const filter = filterOf(words);
|
|
7672
8132
|
const { full } = this.optsWithGlobals();
|
|
7673
8133
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7674
|
-
if (!
|
|
8134
|
+
if (!existsSync8(path))
|
|
7675
8135
|
throw new CliError("not_found", `no store at ${path}`);
|
|
7676
8136
|
const items = await readStoreTables(path, { filter, sizes: full === true });
|
|
7677
8137
|
renderAnswer(this, outputFor(this), listOf(PATH, {
|
|
@@ -7684,7 +8144,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
|
|
|
7684
8144
|
return tables;
|
|
7685
8145
|
}, "storeTablesCommand");
|
|
7686
8146
|
|
|
7687
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
8147
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.600.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_b9e89c8ee4e42a523b0faff8db1d3e1d/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
|
|
7688
8148
|
var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
|
|
7689
8149
|
var WORD_INDEX = "message_words";
|
|
7690
8150
|
var schemaOf = /* @__PURE__ */ __name((database) => {
|
|
@@ -7693,7 +8153,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
|
|
|
7693
8153
|
}, "schemaOf");
|
|
7694
8154
|
var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
|
|
7695
8155
|
var pendingIfKnown2 = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
|
|
7696
|
-
var bytesOf2 = /* @__PURE__ */ __name((path) =>
|
|
8156
|
+
var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync9(path) ? statSync4(path).size : 0, "bytesOf");
|
|
7697
8157
|
var reading = /* @__PURE__ */ __name(async (path, read) => {
|
|
7698
8158
|
const database = await openCache(path);
|
|
7699
8159
|
try {
|
|
@@ -7710,10 +8170,22 @@ var readingOnly = /* @__PURE__ */ __name(async (path, read) => {
|
|
|
7710
8170
|
database.close();
|
|
7711
8171
|
}
|
|
7712
8172
|
}, "readingOnly");
|
|
7713
|
-
var storeSummary = /* @__PURE__ */ __name(async (env) => {
|
|
8173
|
+
var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command } = {}) => {
|
|
7714
8174
|
const path = storePath(env);
|
|
7715
|
-
if (!
|
|
8175
|
+
if (!existsSync9(path))
|
|
7716
8176
|
return { path, exists: false };
|
|
8177
|
+
const checked = await storeHealth(path, { deep });
|
|
8178
|
+
const health = {
|
|
8179
|
+
checked: checked.checked,
|
|
8180
|
+
covers: deep ? "every page and every search index" : QUICK_HEALTH_CHECKS,
|
|
8181
|
+
ok: checked.ok,
|
|
8182
|
+
ms: checked.ms,
|
|
8183
|
+
...checked.problems ? { problems: checked.problems } : {},
|
|
8184
|
+
...checked.damagedTables?.length ? { damagedTables: checked.damagedTables } : {},
|
|
8185
|
+
...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
|
|
8186
|
+
};
|
|
8187
|
+
const damage = command ? explainDamage(checked, command) : null;
|
|
8188
|
+
const healthOf = { health, ...damage ? { damage } : {} };
|
|
7717
8189
|
try {
|
|
7718
8190
|
return await reading(path, (database) => {
|
|
7719
8191
|
const { version, writable } = schemaOf(database);
|
|
@@ -7723,11 +8195,12 @@ var storeSummary = /* @__PURE__ */ __name(async (env) => {
|
|
|
7723
8195
|
schema: version,
|
|
7724
8196
|
speaks: SPEAKS,
|
|
7725
8197
|
writable,
|
|
7726
|
-
...version > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {}
|
|
8198
|
+
...version > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
|
|
8199
|
+
...healthOf
|
|
7727
8200
|
};
|
|
7728
8201
|
});
|
|
7729
8202
|
} catch (error) {
|
|
7730
|
-
return { path, exists: true, error: messageOf2(error) };
|
|
8203
|
+
return { path, exists: true, error: messageOf2(error), ...healthOf };
|
|
7731
8204
|
}
|
|
7732
8205
|
}, "storeSummary");
|
|
7733
8206
|
var result = /* @__PURE__ */ __name((command, value, next = []) => renderAnswer(command, outputFor(command), itemOf(snakeKeys(value), { next })), "result");
|
|
@@ -7742,7 +8215,8 @@ var storeMaintenanceCommands = /* @__PURE__ */ __name((messenger) => [
|
|
|
7742
8215
|
repairCommand(messenger),
|
|
7743
8216
|
resetCommand(messenger),
|
|
7744
8217
|
copiesCommand(),
|
|
7745
|
-
storeTablesCommand(messenger)
|
|
8218
|
+
storeTablesCommand(messenger),
|
|
8219
|
+
storeRecoverCommand({ command: messenger.app.command, version: messenger.app.version })
|
|
7746
8220
|
], "storeMaintenanceCommands");
|
|
7747
8221
|
var refuseWhileServing = /* @__PURE__ */ __name((command, messenger) => {
|
|
7748
8222
|
const serving = servingProfiles(messenger.app, environmentOf(command).env ?? process.env);
|
|
@@ -7754,7 +8228,7 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
|
|
|
7754
8228
|
const { renderer, format } = outputFor(this);
|
|
7755
8229
|
const { dryRun: dryRun2 } = this.opts();
|
|
7756
8230
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7757
|
-
if (!
|
|
8231
|
+
if (!existsSync9(path)) {
|
|
7758
8232
|
result(this, { path, exists: false });
|
|
7759
8233
|
return;
|
|
7760
8234
|
}
|
|
@@ -7794,7 +8268,7 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
|
|
|
7794
8268
|
}, "notesOf");
|
|
7795
8269
|
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) {
|
|
7796
8270
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7797
|
-
if (!
|
|
8271
|
+
if (!existsSync9(path))
|
|
7798
8272
|
throw new CliError("not_found", `no store at ${path}`);
|
|
7799
8273
|
const deleted = await reading(path, (database) => deleteCopy(database, name));
|
|
7800
8274
|
result(this, { path, deleted });
|
|
@@ -7802,7 +8276,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
|
|
|
7802
8276
|
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() {
|
|
7803
8277
|
const { renderer } = outputFor(this);
|
|
7804
8278
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7805
|
-
if (!
|
|
8279
|
+
if (!existsSync9(path)) {
|
|
7806
8280
|
result(this, { path, exists: false, ok: true });
|
|
7807
8281
|
return;
|
|
7808
8282
|
}
|
|
@@ -7865,7 +8339,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
|
|
|
7865
8339
|
...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
|
|
7866
8340
|
]);
|
|
7867
8341
|
const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
|
|
7868
|
-
const { bavail, bsize } =
|
|
8342
|
+
const { bavail, bsize } = statfsSync2(dirname2(path));
|
|
7869
8343
|
const free = Number(bavail) * Number(bsize);
|
|
7870
8344
|
const behind = schema.version > 0 ? chatsBehind(database) : [];
|
|
7871
8345
|
const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
|
|
@@ -7953,14 +8427,18 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
|
|
|
7953
8427
|
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() {
|
|
7954
8428
|
const { renderer } = outputFor(this);
|
|
7955
8429
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7956
|
-
if (!
|
|
8430
|
+
if (!existsSync9(path)) {
|
|
7957
8431
|
result(this, { path, exists: false });
|
|
7958
8432
|
renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
|
|
7959
8433
|
return;
|
|
7960
8434
|
}
|
|
7961
8435
|
const answer = await reading(path, (database) => {
|
|
7962
8436
|
const from = schemaOf(database).version;
|
|
7963
|
-
migrate(database, {
|
|
8437
|
+
migrate(database, {
|
|
8438
|
+
command: messenger.app.command,
|
|
8439
|
+
version: messenger.app.version,
|
|
8440
|
+
rollback: { store: path, warn: /* @__PURE__ */ __name((line) => renderer.warn(line), "warn") }
|
|
8441
|
+
});
|
|
7964
8442
|
const { normalized, indexed, terms } = buildWordIndex(database, (note) => renderer.note(note));
|
|
7965
8443
|
const stemmed = buildStems(database, (note) => renderer.note(note));
|
|
7966
8444
|
const notes = buildNoteIndex(database, (note) => renderer.note(note));
|
|
@@ -8013,7 +8491,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
|
|
|
8013
8491
|
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() {
|
|
8014
8492
|
const { renderer } = outputFor(this);
|
|
8015
8493
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8016
|
-
if (!
|
|
8494
|
+
if (!existsSync9(path)) {
|
|
8017
8495
|
result(this, { path, exists: false });
|
|
8018
8496
|
return;
|
|
8019
8497
|
}
|
|
@@ -8042,11 +8520,11 @@ var reindexCommand = /* @__PURE__ */ __name((messenger) => destroysNothing(annot
|
|
|
8042
8520
|
result(this, answer);
|
|
8043
8521
|
}), "reindexCommand");
|
|
8044
8522
|
var vacuumInto = /* @__PURE__ */ __name(async (path, target) => {
|
|
8045
|
-
|
|
8523
|
+
writeFileSync2(target, "", { flag: "wx", mode: 384 });
|
|
8046
8524
|
try {
|
|
8047
8525
|
await reading(path, (database) => database.prepare("VACUUM INTO ?").run(target));
|
|
8048
8526
|
} catch (error) {
|
|
8049
|
-
|
|
8527
|
+
rmSync3(target, { force: true });
|
|
8050
8528
|
throw error;
|
|
8051
8529
|
}
|
|
8052
8530
|
}, "vacuumInto");
|
|
@@ -8055,9 +8533,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
|
|
|
8055
8533
|
const { encrypt } = this.opts();
|
|
8056
8534
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8057
8535
|
const target = resolve(file2);
|
|
8058
|
-
if (!
|
|
8536
|
+
if (!existsSync9(path))
|
|
8059
8537
|
throw new CliError("not_found", `no store at ${path} to back up`);
|
|
8060
|
-
if (
|
|
8538
|
+
if (existsSync9(target))
|
|
8061
8539
|
throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
|
|
8062
8540
|
const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
|
|
8063
8541
|
const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
|
|
@@ -8079,67 +8557,69 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
|
|
|
8079
8557
|
});
|
|
8080
8558
|
} catch (error) {
|
|
8081
8559
|
if (password === void 0)
|
|
8082
|
-
|
|
8560
|
+
rmSync3(target, { force: true });
|
|
8083
8561
|
throw error;
|
|
8084
8562
|
} finally {
|
|
8085
8563
|
if (password !== void 0)
|
|
8086
|
-
|
|
8564
|
+
rmSync3(copyAt, { force: true });
|
|
8087
8565
|
}
|
|
8088
8566
|
}), "backupCommand");
|
|
8089
8567
|
var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"), { output: { entity: "store_decrypt" }, effects: LOCAL_WRITE }).description("open a file written with --encrypt into a new file; asks for its password").argument("<file>", "a file `store backup --encrypt` or `store export --encrypt` wrote").requiredOption("--output <file>", "the new file, readable only by you").action(async function(file2) {
|
|
8090
8568
|
const { output } = this.opts();
|
|
8091
8569
|
const from = resolve(file2);
|
|
8092
8570
|
const to = resolve(output);
|
|
8093
|
-
if (!
|
|
8571
|
+
if (!existsSync9(from))
|
|
8094
8572
|
throw new CliError("not_found", `no file at ${from}`);
|
|
8095
8573
|
if (!isSealed(from))
|
|
8096
8574
|
throw new CliError("validation_error", `${from} was not written with --encrypt`);
|
|
8097
|
-
if (
|
|
8575
|
+
if (existsSync9(to))
|
|
8098
8576
|
throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
|
|
8099
8577
|
await unsealFile(from, to, await passwordOf(this, { twice: false }));
|
|
8100
8578
|
result(this, { path: to, from, bytes: bytesOf2(to) });
|
|
8101
8579
|
}), "decryptCommand");
|
|
8102
|
-
var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup
|
|
8580
|
+
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) {
|
|
8103
8581
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8104
8582
|
const given = resolve(file2);
|
|
8105
|
-
if (!
|
|
8583
|
+
if (!existsSync9(given))
|
|
8106
8584
|
throw new CliError("not_found", `no file at ${given}`);
|
|
8107
8585
|
refuseWhileServing(this, messenger);
|
|
8108
8586
|
if (!isSealed(given))
|
|
8109
8587
|
return restoreFrom(this, messenger, given, given);
|
|
8110
8588
|
const opened = `${path}.unsealing-${process.pid}`;
|
|
8111
|
-
mkdirSync(
|
|
8589
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
8112
8590
|
try {
|
|
8113
8591
|
await unsealFile(given, opened, await passwordOf(this, { twice: false }));
|
|
8114
8592
|
await restoreFrom(this, messenger, opened, given);
|
|
8115
8593
|
} finally {
|
|
8116
|
-
|
|
8594
|
+
rmSync3(opened, { force: true });
|
|
8117
8595
|
}
|
|
8118
8596
|
}), "restoreCommand");
|
|
8119
8597
|
var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
|
|
8120
8598
|
const { renderer } = outputFor(command);
|
|
8121
8599
|
const path = storePath(environmentOf(command).env ?? process.env);
|
|
8122
|
-
if (
|
|
8600
|
+
if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
|
|
8123
8601
|
throw new CliError("validation_error", `${backup} is the store itself`);
|
|
8124
8602
|
}
|
|
8603
|
+
if (await isRollbackCopy(backup))
|
|
8604
|
+
return rollBackFrom(command, messenger, backup);
|
|
8125
8605
|
const schema = await backupSchema(backup);
|
|
8126
8606
|
const stamp = stampNow();
|
|
8127
|
-
const kept =
|
|
8607
|
+
const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
|
|
8128
8608
|
if (kept) {
|
|
8129
8609
|
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
8130
8610
|
await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
|
|
8131
8611
|
} else
|
|
8132
|
-
mkdirSync(
|
|
8612
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
8133
8613
|
const incoming = `${path}.restoring-${stamp}`;
|
|
8134
8614
|
copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
|
|
8135
8615
|
chmodSync(incoming, 384);
|
|
8136
8616
|
if (kept) {
|
|
8137
|
-
|
|
8617
|
+
renameSync3(path, kept);
|
|
8138
8618
|
for (const suffix of ["-wal", "-shm"])
|
|
8139
|
-
if (
|
|
8140
|
-
|
|
8619
|
+
if (existsSync9(`${path}${suffix}`))
|
|
8620
|
+
renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
|
|
8141
8621
|
}
|
|
8142
|
-
|
|
8622
|
+
renameSync3(incoming, path);
|
|
8143
8623
|
result(command, { path, restoredFrom: given, keptAt: kept, schema: schema.version });
|
|
8144
8624
|
if (kept)
|
|
8145
8625
|
renderer.note(`the store it replaced is kept at ${kept}`);
|
|
@@ -8148,6 +8628,43 @@ var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, give
|
|
|
8148
8628
|
renderer.note(`the backup is behind this build; the next command migrates it \u2014 \`${lineOf(command, "store migrate")}\` now`);
|
|
8149
8629
|
}
|
|
8150
8630
|
}, "restoreFrom");
|
|
8631
|
+
var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
|
|
8632
|
+
try {
|
|
8633
|
+
return await readingOnly(file2, (database) => database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'rollback_meta'").get() !== void 0);
|
|
8634
|
+
} catch {
|
|
8635
|
+
return false;
|
|
8636
|
+
}
|
|
8637
|
+
}, "isRollbackCopy");
|
|
8638
|
+
var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
|
|
8639
|
+
const { renderer } = outputFor(command);
|
|
8640
|
+
const path = storePath(environmentOf(command).env ?? process.env);
|
|
8641
|
+
if (!existsSync9(path))
|
|
8642
|
+
throw new CliError("not_found", `no store at ${path} to roll back`);
|
|
8643
|
+
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
8644
|
+
await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
|
|
8645
|
+
const { database } = await openSqlite(path);
|
|
8646
|
+
let rolled;
|
|
8647
|
+
try {
|
|
8648
|
+
rolled = rollBack(database, copy);
|
|
8649
|
+
} finally {
|
|
8650
|
+
database.close();
|
|
8651
|
+
}
|
|
8652
|
+
result(command, {
|
|
8653
|
+
path,
|
|
8654
|
+
restoredFrom: copy,
|
|
8655
|
+
rolledBack: true,
|
|
8656
|
+
schema: rolled.from,
|
|
8657
|
+
was: rolled.was,
|
|
8658
|
+
tables: rolled.restored,
|
|
8659
|
+
rebuilt: rolled.rebuilt,
|
|
8660
|
+
foreignKeyViolations: rolled.foreignKeyViolations
|
|
8661
|
+
});
|
|
8662
|
+
const taken = new Date(rolled.createdAt).toISOString();
|
|
8663
|
+
renderer.note(`the store is back at schema ${rolled.from}; ${rolled.tables.length > 0 ? rolled.tables.join(", ") : "no table"} hold what they held at ${taken}, and what was written to them since is not kept`);
|
|
8664
|
+
renderer.note("open it with the older tool and run its `store rebuild`: the search indexes are behind the tables");
|
|
8665
|
+
renderer.note(`a tool that speaks schema ${rolled.to} or later migrates it again on its next run`);
|
|
8666
|
+
renderer.note("restart every serve and mcp of either CLI that was running, so they read the restored store");
|
|
8667
|
+
}, "rollBackFrom");
|
|
8151
8668
|
var backupSchema = /* @__PURE__ */ __name(async (backup) => {
|
|
8152
8669
|
let read;
|
|
8153
8670
|
try {
|
|
@@ -8171,7 +8688,7 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
|
|
|
8171
8688
|
var STORE_LOCK_WAIT_MS = 1e3;
|
|
8172
8689
|
var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
|
|
8173
8690
|
const { command } = messenger.app;
|
|
8174
|
-
const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) =>
|
|
8691
|
+
const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
|
|
8175
8692
|
const holders = holdersOf(files);
|
|
8176
8693
|
if (holders === void 0) {
|
|
8177
8694
|
warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
|
|
@@ -8197,7 +8714,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
|
|
|
8197
8714
|
const { command } = messenger.app;
|
|
8198
8715
|
const env = environmentOf(this).env ?? process.env;
|
|
8199
8716
|
const path = storePath(env);
|
|
8200
|
-
if (!
|
|
8717
|
+
if (!existsSync9(path)) {
|
|
8201
8718
|
result(this, { path, exists: false, reset: false });
|
|
8202
8719
|
renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
|
|
8203
8720
|
return;
|
|
@@ -8233,17 +8750,17 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
|
|
|
8233
8750
|
});
|
|
8234
8751
|
renderer.note(`backed the store up to ${backup}`);
|
|
8235
8752
|
}
|
|
8236
|
-
for (const suffix of
|
|
8237
|
-
|
|
8753
|
+
for (const suffix of STORE_PARTS2)
|
|
8754
|
+
rmSync3(`${path}${suffix}`, { force: true });
|
|
8238
8755
|
await (await openStore({ path, command })).close();
|
|
8239
8756
|
const schema = await reading(path, (database) => schemaOf(database).version);
|
|
8240
8757
|
result(this, { path, exists: true, reset: true, backup, backedUp, schema });
|
|
8241
8758
|
renderer.note(backup ? `the store is empty at schema ${schema}; \`${command} store restore ${backup}\` puts the old one back once a build can read it` : `the store is empty at schema ${schema}; there is no backup`);
|
|
8242
8759
|
}), "resetCommand");
|
|
8243
|
-
var
|
|
8760
|
+
var STORE_PARTS2 = ["", "-wal", "-shm"];
|
|
8244
8761
|
var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
|
|
8245
|
-
const files =
|
|
8246
|
-
const holders = holdersOf(files.map((file2) =>
|
|
8762
|
+
const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync9(file2));
|
|
8763
|
+
const holders = holdersOf(files.map((file2) => realpathSync2(file2)));
|
|
8247
8764
|
const serving = servingProfiles(messenger.app, env).length > 0;
|
|
8248
8765
|
const read = await readingOnly(path, (database) => ({
|
|
8249
8766
|
schema: schemaOf(database).version,
|