@wirecat/drive-cli 0.61.0 → 0.63.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/dist/bin/drive.js +2 -2
- package/dist/browse.d.ts +20 -0
- package/dist/browse.d.ts.map +1 -0
- package/dist/browse.js +146 -0
- package/dist/browse.js.map +1 -0
- package/dist/bundle/{all-profiles-H4L3Z5UM.js → all-profiles-GZJS3UKC.js} +13 -14
- package/dist/bundle/{anthropic-PPGFISVP.js → anthropic-RGV3WXX5.js} +9 -9
- package/dist/bundle/{app-server-YXVK2FUZ.js → app-server-AA2PJ7PV.js} +57 -55
- package/dist/bundle/{bun-DKZAL6ML.js → bun-OXZYIA3R.js} +2 -2
- package/dist/bundle/{bun-sqlite-MTZY36QK.js → bun-sqlite-D45NSDM3.js} +8 -8
- package/dist/bundle/{chunk-KV4267S4.js → chunk-27YUUGXQ.js} +1 -1
- package/dist/bundle/{chunk-6IBM4Z3V.js → chunk-2HF2MRXI.js} +1 -1
- package/dist/bundle/{chunk-HGOYQUT7.js → chunk-2NIC72HH.js} +4 -2
- package/dist/bundle/{chunk-XZBR2O63.js → chunk-2TDUGC5D.js} +1501 -781
- package/dist/bundle/{chunk-DEPMQHXQ.js → chunk-2TFXK3R4.js} +4 -4
- package/dist/bundle/{chunk-JVBLXSAA.js → chunk-33MGFUED.js} +652 -249
- package/dist/bundle/{chunk-S4YK6TTG.js → chunk-3BZRKLJ6.js} +13 -13
- package/dist/bundle/{chunk-6SUGANRJ.js → chunk-3HK5WMI5.js} +6 -6
- package/dist/bundle/{chunk-YWIU4HOT.js → chunk-3QINVLZI.js} +1 -1
- package/dist/bundle/{chunk-XYCCGGKN.js → chunk-44SBK6KB.js} +1207 -643
- package/dist/bundle/{chunk-LARQTWIL.js → chunk-4CIZWCXV.js} +1 -1
- package/dist/bundle/{chunk-WZ5XK74U.js → chunk-4OSSOWDM.js} +1 -1
- package/dist/bundle/{chunk-XGNC5OJG.js → chunk-4S4JMW6I.js} +1 -1
- package/dist/bundle/{chunk-WIU733D2.js → chunk-534OBX5Y.js} +1 -1
- package/dist/bundle/{chunk-UO2IUDVK.js → chunk-5PPL7JDM.js} +2 -2
- package/dist/bundle/{chunk-OFFA54TW.js → chunk-6EY46GAN.js} +2 -2
- package/dist/bundle/{chunk-RFRCOAWS.js → chunk-6KQJSFYF.js} +22 -22
- package/dist/bundle/{chunk-6DN4VPA7.js → chunk-6MQSQ4LX.js} +33 -31
- package/dist/bundle/{chunk-NIX2MWHZ.js → chunk-7EMQ26BA.js} +39 -25
- package/dist/bundle/{chunk-X2CXW4HM.js → chunk-ABYGSJZ4.js} +7 -7
- package/dist/bundle/{chunk-I26VL4W7.js → chunk-AEX37ETW.js} +2 -2
- package/dist/bundle/{chunk-36CWGEVX.js → chunk-BKYMKVHT.js} +2 -2
- package/dist/bundle/{chunk-3WZH3WV3.js → chunk-CE2TJBLP.js} +3 -3
- package/dist/bundle/{chunk-YMBFZA3H.js → chunk-DJ3SDJZY.js} +8 -8
- package/dist/bundle/{chunk-DXPOVLQC.js → chunk-DJHLVUL6.js} +227 -90
- package/dist/bundle/{chunk-VPDAH7PJ.js → chunk-E4SDKMBJ.js} +59 -1
- package/dist/bundle/{chunk-NZ2EIZLX.js → chunk-EOOGWUTP.js} +10 -10
- package/dist/bundle/{chunk-VYXVPYA3.js → chunk-FEZF3TII.js} +6 -6
- package/dist/bundle/{chunk-Q4XVBKX4.js → chunk-FRIJUILO.js} +3 -3
- package/dist/bundle/{chunk-OLPJRD4S.js → chunk-FUITWY7O.js} +1 -1
- package/dist/bundle/{chunk-AM4RIWOZ.js → chunk-HZZCEQTH.js} +18 -4
- package/dist/bundle/{chunk-2RJA4BQB.js → chunk-J24ZFCWM.js} +39 -26
- package/dist/bundle/{chunk-QSGT4ZH4.js → chunk-J4DIHPZ6.js} +1 -1
- package/dist/bundle/{chunk-ZHYRHERD.js → chunk-L37LMMRJ.js} +2 -2
- package/dist/bundle/{chunk-XLFJLZJL.js → chunk-LMAVCYLQ.js} +22 -14
- package/dist/bundle/{chunk-E6J5YH2N.js → chunk-LZEOQW7S.js} +36 -36
- package/dist/bundle/{chunk-FE5JJXKA.js → chunk-MOTRI3SY.js} +2 -2
- package/dist/bundle/{chunk-PJTX2MOI.js → chunk-ND6LLYGF.js} +98 -81
- package/dist/bundle/{chunk-3I2D5TK2.js → chunk-NEFSGCVA.js} +10 -10
- package/dist/bundle/{chunk-OGNOQDWB.js → chunk-O2XOX4HB.js} +34 -10
- package/dist/bundle/{chunk-DCBFNBEB.js → chunk-OD4U7GUY.js} +20 -20
- package/dist/bundle/{chunk-BXR7BKM3.js → chunk-OTROVC4E.js} +1 -1
- package/dist/bundle/{chunk-UKOYQC5O.js → chunk-OXY6SSZG.js} +184 -29
- package/dist/bundle/{chunk-ZMNYK3FC.js → chunk-PDCCYHCH.js} +5 -5
- package/dist/bundle/{chunk-J5UDQD5S.js → chunk-PO5RQQIG.js} +5 -5
- package/dist/bundle/{chunk-PY7LKNOS.js → chunk-Q5DJTRKV.js} +2 -2
- package/dist/bundle/{chunk-E5EXJ2XS.js → chunk-QCKZ3GAA.js} +4 -4
- package/dist/bundle/{chunk-3SJQNS72.js → chunk-RKELRWH7.js} +5 -5
- package/dist/bundle/{chunk-6Y2FWJZ4.js → chunk-S4RXABDR.js} +3 -3
- package/dist/bundle/{chunk-BQMIDYBA.js → chunk-SXM6MHRR.js} +12 -12
- package/dist/bundle/chunk-TF23BZW5.js +64 -0
- package/dist/bundle/{chunk-N2RLJTIW.js → chunk-TWUH22Z5.js} +4 -4
- package/dist/bundle/chunk-UPOSDTPT.js +87 -0
- package/dist/bundle/{chunk-J4HQVHMN.js → chunk-UQLWMGSD.js} +5 -5
- package/dist/bundle/{chunk-K7LS3NGM.js → chunk-V3NVXIQR.js} +736 -230
- package/dist/bundle/{chunk-TKGAYKXW.js → chunk-VAUMOZU5.js} +228 -66
- package/dist/bundle/{chunk-BF6TQMNB.js → chunk-VJEOGKAN.js} +8 -10
- package/dist/bundle/{chunk-XGMDWIUP.js → chunk-VKPCONDQ.js} +4 -4
- package/dist/bundle/{chunk-73WSULMI.js → chunk-WYGWWHZP.js} +2 -2
- package/dist/bundle/{chunk-5W56YMQS.js → chunk-XDC3TWTL.js} +60 -51
- package/dist/bundle/{chunk-5W7D5H2R.js → chunk-XIUDS3OK.js} +1 -1
- package/dist/bundle/{chunk-3UPIJ7DW.js → chunk-XNVFKMVR.js} +21868 -4533
- package/dist/bundle/{chunk-O5CUFS7T.js → chunk-XR6ESRU6.js} +2 -2
- package/dist/bundle/{chunk-EPCJUL6M.js → chunk-Y6GNA7HE.js} +3 -3
- package/dist/bundle/{chunk-67HS46KM.js → chunk-YGU6ULU5.js} +12 -12
- package/dist/bundle/{chunk-HFM653T3.js → chunk-YIP7ELON.js} +768 -131
- package/dist/bundle/{chunk-3252WXOL.js → chunk-YUWPNG7B.js} +1 -1
- package/dist/bundle/{chunk-QR5VQXQ5.js → chunk-Z42YYLTS.js} +59 -37
- package/dist/bundle/{chunk-AWN22PJK.js → chunk-Z5KC7XBR.js} +3 -3
- package/dist/bundle/{chunk-ECEYAQGN.js → chunk-ZM5J6ZMB.js} +4 -2
- package/dist/bundle/{chunk-YPF6OS37.js → chunk-ZMOUUOT2.js} +1 -1
- package/dist/bundle/{chunk-CACYL36O.js → chunk-ZOJU7ZFI.js} +8 -8
- package/dist/bundle/command-contract-BRW3AP44.js +38 -0
- package/dist/bundle/{decode-62A3HGPW.js → decode-G5YEIPNC.js} +8 -8
- package/dist/bundle/{dispatch-IE7PBEQC.js → dispatch-GEFIXA6X.js} +9 -9
- package/dist/bundle/drive.js +11 -11
- package/dist/bundle/{echarts-BGBPRGR5.js → echarts-W2CWHNXR.js} +2 -2
- package/dist/bundle/{embed-J3IBVV2V.js → embed-OBFFPVF4.js} +9 -9
- package/dist/bundle/{embedder-QFPMDRT2.js → embedder-NGCBQHIG.js} +12 -12
- package/dist/bundle/entry-ET6HGM7A.js +22 -0
- package/dist/bundle/{failure-BKOGBMIC.js → failure-GV77W3CD.js} +4 -4
- package/dist/bundle/first-run-JG52UZVO.js +30 -0
- package/dist/bundle/first-screen-CIL3GFAA.js +36 -0
- package/dist/bundle/{google-RXM2XEPD.js → google-CIWUVJ5C.js} +13 -13
- package/dist/bundle/{google-api-NC65BZO4.js → google-api-Z3NSTBBR.js} +56 -57
- package/dist/bundle/grants-3S4RL3WB.js +104 -0
- package/dist/bundle/{identity-PI6F2GWA.js → identity-OM6GFZ7T.js} +6 -6
- package/dist/bundle/{instructions-6LPDSKAD.js → instructions-YQBQSYSS.js} +1 -1
- package/dist/bundle/{login-HTY7GT2S.js → login-7RYSDVN3.js} +62 -63
- package/dist/bundle/{mcp-PPVOM4SE.js → mcp-GWDA3HOA.js} +2 -2
- package/dist/bundle/{node-IB246NCQ.js → node-IVU33RL7.js} +2 -2
- package/dist/bundle/{node-sqlite-G2Y5SFJM.js → node-sqlite-SIH5BEW2.js} +9 -9
- package/dist/bundle/oauth-PT4JEHLL.js +22 -0
- package/dist/bundle/{open-WD4GFSJD.js → open-IAO2SNII.js} +8 -8
- package/dist/bundle/{openai-QVM4PMY7.js → openai-SGOUBHXP.js} +17 -17
- package/dist/bundle/{process-SWPJGPQC.js → process-BPBMV3AT.js} +1 -1
- package/dist/bundle/{program-WHYFAMXR.js → program-MYKKJ4F6.js} +231 -87
- package/dist/bundle/prompt-3ZM64DCB.js +17 -0
- package/dist/bundle/{reasons-Q34DQWB6.js → reasons-57J2D77K.js} +5 -5
- package/dist/bundle/{recognize-DM3YWHSE.js → recognize-A5C5RPB3.js} +7 -7
- package/dist/bundle/{remote-KXVWRK7J.js → remote-VWYFLRGO.js} +10 -10
- package/dist/bundle/{rerank-TINXM3MY.js → rerank-4NGQWREA.js} +10 -10
- package/dist/bundle/{serve-IY2WL656.js → serve-Y6LQTFH5.js} +12 -12
- package/dist/bundle/{server-VPY3OWPC.js → server-6AUHIIUA.js} +43 -44
- package/dist/bundle/server-PFHI35HA.js +69 -0
- package/dist/bundle/{services-PXNBOCOC.js → services-2W4J7EMW.js} +47 -32
- package/dist/bundle/{sqlite-runtime-5ZK2CV7Y.js → sqlite-runtime-P6BBDX2H.js} +9 -9
- package/dist/bundle/{start-LDVCN3DK.js → start-AFFA3LKM.js} +9 -7
- package/dist/bundle/{state-3MKTT3VS.js → state-PXKKXR3R.js} +9 -9
- package/dist/bundle/{store-4VQOT5IJ.js → store-CN6JEUC4.js} +28 -18
- package/dist/bundle/{store-7M4MSUJV.js → store-IVV2BAGZ.js} +78 -28
- package/dist/bundle/store-maintenance-command-MSY2QNEH.js +59 -0
- package/dist/bundle/tokens-P4LPNUFW.js +102 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +5 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/folders.d.ts +2 -1
- package/dist/commands/folders.d.ts.map +1 -1
- package/dist/commands/folders.js +16 -3
- package/dist/commands/folders.js.map +1 -1
- package/dist/program.js +1 -1
- package/dist/program.js.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +15 -6
- package/dist/tokens.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/chunk-BCWUDTYQ.js +0 -22
- package/dist/bundle/chunk-W767AUNR.js +0 -132
- package/dist/bundle/chunk-WUP2MJDN.js +0 -42
- package/dist/bundle/command-contract-T3EO5AYD.js +0 -39
- package/dist/bundle/entry-YQSYER66.js +0 -22
- package/dist/bundle/first-run-ZIFPVZAI.js +0 -30
- package/dist/bundle/first-screen-L5U26EY7.js +0 -37
- package/dist/bundle/grants-SEWUYYH3.js +0 -105
- package/dist/bundle/oauth-MWBKBI4T.js +0 -22
- package/dist/bundle/prompt-OVYCGZB7.js +0 -17
- package/dist/bundle/server-EMWVVT2C.js +0 -70
- package/dist/bundle/store-maintenance-command-NRATYBWD.js +0 -60
- package/dist/bundle/tokens-XUKLM3SL.js +0 -103
- /package/dist/bundle/{chunk-LU3WKZBA.js → chunk-ZQ3GWKDQ.js} +0 -0
|
@@ -3,7 +3,7 @@ const require = __bundleRequire(import.meta.url);
|
|
|
3
3
|
import {
|
|
4
4
|
answerOf,
|
|
5
5
|
messengerContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XDC3TWTL.js";
|
|
7
7
|
import {
|
|
8
8
|
chatEventAnswer,
|
|
9
9
|
memberAnswer,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
serveRelay,
|
|
13
13
|
typedQuery,
|
|
14
14
|
withQuery
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-J24ZFCWM.js";
|
|
16
16
|
import {
|
|
17
17
|
stringWidth,
|
|
18
18
|
wrapAnsi
|
|
@@ -40,24 +40,24 @@ import {
|
|
|
40
40
|
snakeKeys,
|
|
41
41
|
storeTable,
|
|
42
42
|
withoutProviderRefs
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-33MGFUED.js";
|
|
44
44
|
import {
|
|
45
45
|
envName
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-ZM5J6ZMB.js";
|
|
47
47
|
import {
|
|
48
48
|
holdLock,
|
|
49
49
|
lockPath,
|
|
50
50
|
releaseLock,
|
|
51
51
|
servingProfiles,
|
|
52
52
|
takeLock
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-FRIJUILO.js";
|
|
54
54
|
import {
|
|
55
55
|
holdersOf
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-534OBX5Y.js";
|
|
57
57
|
import {
|
|
58
58
|
checkedOptions,
|
|
59
59
|
range
|
|
60
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-Z5KC7XBR.js";
|
|
61
61
|
import {
|
|
62
62
|
FETCHING,
|
|
63
63
|
RULES_VERSION,
|
|
@@ -70,28 +70,40 @@ import {
|
|
|
70
70
|
senderIsMe,
|
|
71
71
|
servicesFor,
|
|
72
72
|
syncsOneChat
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-44SBK6KB.js";
|
|
74
|
+
import {
|
|
75
|
+
withTimeLimit
|
|
76
|
+
} from "./chunk-ND6LLYGF.js";
|
|
74
77
|
import {
|
|
75
78
|
codeOf,
|
|
76
79
|
currentRun,
|
|
77
80
|
levelFor,
|
|
78
81
|
parseDuration
|
|
79
|
-
} from "./chunk-
|
|
80
|
-
import {
|
|
81
|
-
failureKey
|
|
82
|
-
} from "./chunk-BCWUDTYQ.js";
|
|
82
|
+
} from "./chunk-6MQSQ4LX.js";
|
|
83
83
|
import {
|
|
84
84
|
messagesFor,
|
|
85
85
|
systemFor,
|
|
86
86
|
validateImages
|
|
87
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-MOTRI3SY.js";
|
|
88
|
+
import {
|
|
89
|
+
QUICK_HEALTH_CHECKS,
|
|
90
|
+
explainDamage,
|
|
91
|
+
fts5Tables,
|
|
92
|
+
invalidJson,
|
|
93
|
+
storeHealth
|
|
94
|
+
} from "./chunk-VAUMOZU5.js";
|
|
88
95
|
import {
|
|
96
|
+
CORPORA,
|
|
89
97
|
MIGRATIONS,
|
|
98
|
+
drainCorpus,
|
|
99
|
+
drainMeetingIndex,
|
|
90
100
|
drainNoteIndex,
|
|
91
101
|
dropAllUnusedVectors,
|
|
92
102
|
fileFacts,
|
|
93
103
|
fillSearchIndex,
|
|
94
104
|
fillStems,
|
|
105
|
+
fillTrigrams,
|
|
106
|
+
fillVectorIndexes,
|
|
95
107
|
formatLocator,
|
|
96
108
|
involvementStoreOver,
|
|
97
109
|
migrate,
|
|
@@ -102,10 +114,12 @@ import {
|
|
|
102
114
|
parseLocator,
|
|
103
115
|
pendingNormalization,
|
|
104
116
|
readStoreTables,
|
|
117
|
+
rebuildMentions,
|
|
105
118
|
resetAttachmentWords,
|
|
106
119
|
resetNoteIndex,
|
|
107
120
|
resetSearchIndex,
|
|
108
121
|
resetStems,
|
|
122
|
+
rollBack,
|
|
109
123
|
rowCounts,
|
|
110
124
|
searchIndexState,
|
|
111
125
|
stemmerCache,
|
|
@@ -113,29 +127,38 @@ import {
|
|
|
113
127
|
storeClients,
|
|
114
128
|
storeContents,
|
|
115
129
|
vectorIndexCounts
|
|
116
|
-
} from "./chunk-
|
|
130
|
+
} from "./chunk-XNVFKMVR.js";
|
|
131
|
+
import {
|
|
132
|
+
readDamageMark,
|
|
133
|
+
readHealthMark,
|
|
134
|
+
recordDeepCheck
|
|
135
|
+
} from "./chunk-V3NVXIQR.js";
|
|
117
136
|
import {
|
|
118
137
|
queryFieldsOf
|
|
119
|
-
} from "./chunk-
|
|
138
|
+
} from "./chunk-EOOGWUTP.js";
|
|
139
|
+
import {
|
|
140
|
+
failureKey,
|
|
141
|
+
isStoreDamage
|
|
142
|
+
} from "./chunk-E4SDKMBJ.js";
|
|
120
143
|
import {
|
|
121
144
|
storePath
|
|
122
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-AEX37ETW.js";
|
|
123
146
|
import {
|
|
124
147
|
openCache
|
|
125
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-3HK5WMI5.js";
|
|
126
149
|
import {
|
|
127
150
|
readSecret
|
|
128
|
-
} from "./chunk-
|
|
151
|
+
} from "./chunk-Y6GNA7HE.js";
|
|
129
152
|
import {
|
|
130
153
|
Credentials,
|
|
131
154
|
pathsAreOverridden,
|
|
132
155
|
resolvePaths,
|
|
133
156
|
writeSecurely
|
|
134
|
-
} from "./chunk-
|
|
157
|
+
} from "./chunk-OD4U7GUY.js";
|
|
135
158
|
import {
|
|
136
159
|
singleLine,
|
|
137
160
|
visibleControls
|
|
138
|
-
} from "./chunk-
|
|
161
|
+
} from "./chunk-2HF2MRXI.js";
|
|
139
162
|
import {
|
|
140
163
|
array,
|
|
141
164
|
boolean,
|
|
@@ -159,10 +182,10 @@ import {
|
|
|
159
182
|
transform,
|
|
160
183
|
trim,
|
|
161
184
|
union
|
|
162
|
-
} from "./chunk-
|
|
185
|
+
} from "./chunk-FEZF3TII.js";
|
|
163
186
|
import {
|
|
164
187
|
CliError
|
|
165
|
-
} from "./chunk-
|
|
188
|
+
} from "./chunk-4OSSOWDM.js";
|
|
166
189
|
import {
|
|
167
190
|
__commonJS,
|
|
168
191
|
__name,
|
|
@@ -1816,7 +1839,7 @@ var require_liquid_node = __commonJS({
|
|
|
1816
1839
|
return readFileAsync(filepath, "utf8");
|
|
1817
1840
|
}
|
|
1818
1841
|
__name(readFile, "readFile");
|
|
1819
|
-
function
|
|
1842
|
+
function existsSync10(filepath) {
|
|
1820
1843
|
try {
|
|
1821
1844
|
fs$1.statSync(filepath);
|
|
1822
1845
|
return true;
|
|
@@ -1824,11 +1847,11 @@ var require_liquid_node = __commonJS({
|
|
|
1824
1847
|
return false;
|
|
1825
1848
|
}
|
|
1826
1849
|
}
|
|
1827
|
-
__name(
|
|
1828
|
-
function
|
|
1850
|
+
__name(existsSync10, "existsSync");
|
|
1851
|
+
function readFileSync5(filepath) {
|
|
1829
1852
|
return fs$1.readFileSync(filepath, "utf8");
|
|
1830
1853
|
}
|
|
1831
|
-
__name(
|
|
1854
|
+
__name(readFileSync5, "readFileSync");
|
|
1832
1855
|
function resolve2(root, file2, ext) {
|
|
1833
1856
|
if (!path.extname(file2))
|
|
1834
1857
|
file2 += ext;
|
|
@@ -1842,10 +1865,10 @@ var require_liquid_node = __commonJS({
|
|
|
1842
1865
|
}
|
|
1843
1866
|
}
|
|
1844
1867
|
__name(fallback, "fallback");
|
|
1845
|
-
function
|
|
1868
|
+
function dirname3(filepath) {
|
|
1846
1869
|
return path.dirname(filepath);
|
|
1847
1870
|
}
|
|
1848
|
-
__name(
|
|
1871
|
+
__name(dirname3, "dirname");
|
|
1849
1872
|
var realpathAsync = promisify(fs$1.realpath);
|
|
1850
1873
|
async function contains(root, file2) {
|
|
1851
1874
|
try {
|
|
@@ -1873,11 +1896,11 @@ var require_liquid_node = __commonJS({
|
|
|
1873
1896
|
__proto__: null,
|
|
1874
1897
|
exists,
|
|
1875
1898
|
readFile,
|
|
1876
|
-
existsSync:
|
|
1877
|
-
readFileSync:
|
|
1899
|
+
existsSync: existsSync10,
|
|
1900
|
+
readFileSync: readFileSync5,
|
|
1878
1901
|
resolve: resolve2,
|
|
1879
1902
|
fallback,
|
|
1880
|
-
dirname:
|
|
1903
|
+
dirname: dirname3,
|
|
1881
1904
|
contains,
|
|
1882
1905
|
containsSync,
|
|
1883
1906
|
sep: path.sep
|
|
@@ -3602,7 +3625,7 @@ var require_liquid_node = __commonJS({
|
|
|
3602
3625
|
uri_escape,
|
|
3603
3626
|
slugify
|
|
3604
3627
|
});
|
|
3605
|
-
var
|
|
3628
|
+
var join5 = argumentsToValue(function(v, arg) {
|
|
3606
3629
|
const array2 = toArray(v);
|
|
3607
3630
|
const sep = isNil(arg) ? " " : stringify(arg);
|
|
3608
3631
|
let outputSize = sep.length * Math.max(array2.length - 1, 0);
|
|
@@ -3878,7 +3901,7 @@ var require_liquid_node = __commonJS({
|
|
|
3878
3901
|
__name(sample, "sample");
|
|
3879
3902
|
var arrayFilters = /* @__PURE__ */ Object.freeze({
|
|
3880
3903
|
__proto__: null,
|
|
3881
|
-
join:
|
|
3904
|
+
join: join5,
|
|
3882
3905
|
last,
|
|
3883
3906
|
first,
|
|
3884
3907
|
reverse,
|
|
@@ -5502,11 +5525,11 @@ var require_liquid_node = __commonJS({
|
|
|
5502
5525
|
}
|
|
5503
5526
|
});
|
|
5504
5527
|
|
|
5505
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5506
|
-
import { chmodSync, constants, copyFileSync, existsSync as
|
|
5507
|
-
import { dirname, resolve } from "node:path";
|
|
5528
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
|
|
5529
|
+
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";
|
|
5530
|
+
import { dirname as dirname2, resolve } from "node:path";
|
|
5508
5531
|
|
|
5509
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5532
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/sealed.js
|
|
5510
5533
|
import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
5511
5534
|
import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
|
|
5512
5535
|
import { Transform } from "node:stream";
|
|
@@ -5613,7 +5636,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
|
|
|
5613
5636
|
renameSync(pending, to);
|
|
5614
5637
|
}, "unsealFile");
|
|
5615
5638
|
|
|
5616
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5639
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/store/compatibility.js
|
|
5617
5640
|
var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
|
|
5618
5641
|
var fileSchemaOf = /* @__PURE__ */ __name((database) => {
|
|
5619
5642
|
const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
|
|
@@ -5637,7 +5660,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
|
|
|
5637
5660
|
};
|
|
5638
5661
|
}, "compatibilityOf");
|
|
5639
5662
|
|
|
5640
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5663
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/store/repair.js
|
|
5641
5664
|
import { createHash as createHash2 } from "node:crypto";
|
|
5642
5665
|
var COPY_MARK = "__repair_";
|
|
5643
5666
|
var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
|
|
@@ -5891,10 +5914,545 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
|
|
|
5891
5914
|
return found;
|
|
5892
5915
|
}, "deleteCopy");
|
|
5893
5916
|
|
|
5894
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5895
|
-
import { existsSync as
|
|
5917
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/store-info.js
|
|
5918
|
+
import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
|
|
5919
|
+
|
|
5920
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
|
|
5921
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
5922
|
+
|
|
5923
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/store/recover.js
|
|
5924
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
5925
|
+
import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
|
|
5926
|
+
import { basename, dirname, join } from "node:path";
|
|
5927
|
+
import { Transform as Transform2 } from "node:stream";
|
|
5928
|
+
var SQLITE3_MINIMUM = [3, 43, 0];
|
|
5929
|
+
var STORE_PARTS = ["", "-wal", "-shm"];
|
|
5930
|
+
var RECOVER_LOCK = ".recover-lock";
|
|
5931
|
+
var INSERTED = /^INSERT OR IGNORE INTO '([^']+)'/;
|
|
5932
|
+
var LOST_AND_FOUND = "recover_lost_and_found";
|
|
5933
|
+
var recovers = /* @__PURE__ */ __name((program) => {
|
|
5934
|
+
try {
|
|
5935
|
+
execFileSync(program, [":memory:", ".recover"], { stdio: ["ignore", "ignore", "pipe"] });
|
|
5936
|
+
return true;
|
|
5937
|
+
} catch {
|
|
5938
|
+
return false;
|
|
5939
|
+
}
|
|
5940
|
+
}, "recovers");
|
|
5941
|
+
var sqlite3Program = /* @__PURE__ */ __name((program = "sqlite3") => {
|
|
5942
|
+
let version = null;
|
|
5943
|
+
try {
|
|
5944
|
+
version = execFileSync(program, ["--version"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).split(" ")[0] ?? null;
|
|
5945
|
+
} catch {
|
|
5946
|
+
return { program, version: null, usable: false };
|
|
5947
|
+
}
|
|
5948
|
+
const parts2 = (version ?? "").split(".").map(Number);
|
|
5949
|
+
const at = SQLITE3_MINIMUM.findIndex((wanted, i) => (parts2[i] ?? 0) !== wanted);
|
|
5950
|
+
const recent = at === -1 || (parts2[at] ?? 0) > (SQLITE3_MINIMUM[at] ?? 0);
|
|
5951
|
+
return { program, version, usable: recent && recovers(program) };
|
|
5952
|
+
}, "sqlite3Program");
|
|
5953
|
+
var activeTimers = /* @__PURE__ */ __name(() => {
|
|
5954
|
+
if (process.platform !== "linux")
|
|
5955
|
+
return void 0;
|
|
5956
|
+
try {
|
|
5957
|
+
return execFileSync("systemctl", ["--user", "list-timers", "--plain", "--no-legend"], {
|
|
5958
|
+
encoding: "utf8",
|
|
5959
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
5960
|
+
}).split("\n").map((line) => line.trim().split(/\s+/).at(-2) ?? "").filter((unit) => /^(memo|mail|tg|max|whatsapp|zoom|drive|gcal|wirecat)-.*\.timer$/.test(unit));
|
|
5961
|
+
} catch {
|
|
5962
|
+
return void 0;
|
|
5963
|
+
}
|
|
5964
|
+
}, "activeTimers");
|
|
5965
|
+
var alive = /* @__PURE__ */ __name((pid) => {
|
|
5966
|
+
try {
|
|
5967
|
+
process.kill(pid, 0);
|
|
5968
|
+
return true;
|
|
5969
|
+
} catch (error) {
|
|
5970
|
+
return error.code === "EPERM";
|
|
5971
|
+
}
|
|
5972
|
+
}, "alive");
|
|
5973
|
+
var runningRecovery = /* @__PURE__ */ __name((path) => {
|
|
5974
|
+
let pid;
|
|
5975
|
+
try {
|
|
5976
|
+
pid = Number(readFileSync(`${path}${RECOVER_LOCK}`, "utf8").trim());
|
|
5977
|
+
} catch {
|
|
5978
|
+
return null;
|
|
5979
|
+
}
|
|
5980
|
+
return Number.isInteger(pid) && pid > 0 && alive(pid) ? pid : null;
|
|
5981
|
+
}, "runningRecovery");
|
|
5982
|
+
var takeRecoverLock = /* @__PURE__ */ __name((path) => {
|
|
5983
|
+
const lock = `${path}${RECOVER_LOCK}`;
|
|
5984
|
+
const take = /* @__PURE__ */ __name(() => writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 }), "take");
|
|
5985
|
+
try {
|
|
5986
|
+
take();
|
|
5987
|
+
} catch (error) {
|
|
5988
|
+
if (error.code !== "EEXIST")
|
|
5989
|
+
throw error;
|
|
5990
|
+
const pid = runningRecovery(path);
|
|
5991
|
+
if (pid === null) {
|
|
5992
|
+
rmSync2(lock, { force: true });
|
|
5993
|
+
take();
|
|
5994
|
+
} else {
|
|
5995
|
+
throw new CliError("validation_error", `the store is being recovered by process ${pid} \u2014 wait for it to finish`, {
|
|
5996
|
+
reason: "store.recovering"
|
|
5997
|
+
});
|
|
5998
|
+
}
|
|
5999
|
+
}
|
|
6000
|
+
return () => rmSync2(lock, { force: true });
|
|
6001
|
+
}, "takeRecoverLock");
|
|
6002
|
+
var storeHolders = /* @__PURE__ */ __name((path) => {
|
|
6003
|
+
const folder = realpathSync(dirname(path));
|
|
6004
|
+
const files = STORE_PARTS.map((suffix) => join(folder, `${basename(path)}${suffix}`));
|
|
6005
|
+
const wanted = process.platform === "linux" ? files.flatMap((file2) => [file2, `${file2} (deleted)`]) : files.filter(existsSync2);
|
|
6006
|
+
const recovering = runningRecovery(path);
|
|
6007
|
+
const pids = holdersOf(wanted);
|
|
6008
|
+
if (pids === void 0 && recovering === null)
|
|
6009
|
+
return void 0;
|
|
6010
|
+
const all = [
|
|
6011
|
+
.../* @__PURE__ */ new Set([...pids ?? [], ...recovering !== null && recovering !== process.pid ? [recovering] : []])
|
|
6012
|
+
];
|
|
6013
|
+
return all.map((pid) => {
|
|
6014
|
+
let name = "?";
|
|
6015
|
+
try {
|
|
6016
|
+
name = readFileSync(`/proc/${pid}/comm`, "utf8").trim();
|
|
6017
|
+
} catch {
|
|
6018
|
+
}
|
|
6019
|
+
return { pid, name };
|
|
6020
|
+
});
|
|
6021
|
+
}, "storeHolders");
|
|
6022
|
+
var tableRows = /* @__PURE__ */ __name((database) => {
|
|
6023
|
+
const indexes = fts5Tables(database).map((index) => index.name);
|
|
6024
|
+
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}_`)));
|
|
6025
|
+
return Object.fromEntries(tables.map((table) => {
|
|
6026
|
+
try {
|
|
6027
|
+
return [table, Number(database.prepare(`SELECT count(*) AS n FROM "${table}"`).get()?.n)];
|
|
6028
|
+
} catch {
|
|
6029
|
+
return [table, null];
|
|
6030
|
+
}
|
|
6031
|
+
}));
|
|
6032
|
+
}, "tableRows");
|
|
6033
|
+
var copyReadableRows = /* @__PURE__ */ __name((path, target, program = "sqlite3") => new Promise((resolve2, reject) => {
|
|
6034
|
+
const reader = spawn(program, ["-readonly", path, `.recover --ignore-freelist --lost-and-found ${LOST_AND_FOUND}`], {
|
|
6035
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
6036
|
+
});
|
|
6037
|
+
const writer = spawn(program, ["-cmd", ".dbconfig defensive off", target], { stdio: ["pipe", "ignore", "pipe"] });
|
|
6038
|
+
const errors = [];
|
|
6039
|
+
const collect = /* @__PURE__ */ __name((chunk) => {
|
|
6040
|
+
for (const line of chunk.toString("utf8").split("\n"))
|
|
6041
|
+
if (line && errors.length < 50)
|
|
6042
|
+
errors.push(line.slice(0, 300));
|
|
6043
|
+
}, "collect");
|
|
6044
|
+
reader.stderr.on("data", collect);
|
|
6045
|
+
writer.stderr.on("data", collect);
|
|
6046
|
+
const read = {};
|
|
6047
|
+
let rest = "";
|
|
6048
|
+
const counter = new Transform2({
|
|
6049
|
+
transform(chunk, _encoding, done) {
|
|
6050
|
+
const lines = (rest + chunk.toString("latin1")).split("\n");
|
|
6051
|
+
rest = lines.pop() ?? "";
|
|
6052
|
+
for (const line of lines) {
|
|
6053
|
+
const table = INSERTED.exec(line)?.[1];
|
|
6054
|
+
if (table)
|
|
6055
|
+
read[table] = (read[table] ?? 0) + 1;
|
|
6056
|
+
}
|
|
6057
|
+
done(null, chunk);
|
|
6058
|
+
}
|
|
6059
|
+
});
|
|
6060
|
+
reader.stdout.pipe(counter).pipe(writer.stdin);
|
|
6061
|
+
let exits = 0;
|
|
6062
|
+
let readerCode = null;
|
|
6063
|
+
const exited = /* @__PURE__ */ __name(() => {
|
|
6064
|
+
exits += 1;
|
|
6065
|
+
if (exits < 2)
|
|
6066
|
+
return;
|
|
6067
|
+
if (readerCode !== 0)
|
|
6068
|
+
reject(new CliError("validation_error", `sqlite3 could not read the store: ${errors.join("; ")}`));
|
|
6069
|
+
else
|
|
6070
|
+
resolve2({ errors, read });
|
|
6071
|
+
}, "exited");
|
|
6072
|
+
reader.on("error", reject);
|
|
6073
|
+
writer.on("error", reject);
|
|
6074
|
+
reader.on("close", (code) => {
|
|
6075
|
+
readerCode = code;
|
|
6076
|
+
exited();
|
|
6077
|
+
});
|
|
6078
|
+
writer.on("close", exited);
|
|
6079
|
+
}), "copyReadableRows");
|
|
6080
|
+
var FILLERS = {
|
|
6081
|
+
message_words: /* @__PURE__ */ __name((database, now) => {
|
|
6082
|
+
resetSearchIndex(database);
|
|
6083
|
+
fillSearchIndex(database, { now });
|
|
6084
|
+
}, "message_words"),
|
|
6085
|
+
message_stems: /* @__PURE__ */ __name((database, now) => {
|
|
6086
|
+
resetStems(database, { force: true, now });
|
|
6087
|
+
fillStems(database, { now });
|
|
6088
|
+
}, "message_stems"),
|
|
6089
|
+
attachment_words: /* @__PURE__ */ __name((database) => void resetAttachmentWords(database), "attachment_words"),
|
|
6090
|
+
attachment_name_words: /* @__PURE__ */ __name((database) => (
|
|
6091
|
+
// As migration 20 filled it: й and ё fold as the triggers fold them.
|
|
6092
|
+
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")
|
|
6093
|
+
), "attachment_name_words"),
|
|
6094
|
+
meeting_words: /* @__PURE__ */ __name((database) => {
|
|
6095
|
+
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");
|
|
6096
|
+
drainMeetingIndex(database);
|
|
6097
|
+
}, "meeting_words"),
|
|
6098
|
+
// Built per account by the first search that needs them.
|
|
6099
|
+
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")
|
|
6100
|
+
};
|
|
6101
|
+
var CORPUS_TABLES = new Set(Object.values(CORPORA).flatMap((corpus) => [`${corpus.type}_words`, `${corpus.type}_stems`]));
|
|
6102
|
+
var TRIGRAMS = ["note_trigrams", "document_trigrams"];
|
|
6103
|
+
var rebuildDerived = /* @__PURE__ */ __name((database, { now = Date.now, note = /* @__PURE__ */ __name(() => {
|
|
6104
|
+
}, "note") } = {}) => {
|
|
6105
|
+
const lost = database.prepare("SELECT 1 FROM sqlite_master WHERE name = ?").get(LOST_AND_FOUND);
|
|
6106
|
+
const lostAndFound = lost ? Number(database.prepare(`SELECT count(*) AS n FROM ${LOST_AND_FOUND}`).get()?.n) : 0;
|
|
6107
|
+
if (lost)
|
|
6108
|
+
database.exec(`DROP TABLE ${LOST_AND_FOUND}`);
|
|
6109
|
+
const indexes = fts5Tables(database);
|
|
6110
|
+
for (const { name, sql } of indexes) {
|
|
6111
|
+
database.exec(`DROP TABLE "${name}"`);
|
|
6112
|
+
database.exec(sql);
|
|
6113
|
+
}
|
|
6114
|
+
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));
|
|
6115
|
+
for (const table of vectors) {
|
|
6116
|
+
database.exec(`DROP TRIGGER IF EXISTS "${table}_redo"`);
|
|
6117
|
+
database.exec(`DROP TABLE "${table}"`);
|
|
6118
|
+
database.prepare("DELETE FROM vector_indexes WHERE id = ?").run(Number(table.replace("vector_index_", "")));
|
|
6119
|
+
}
|
|
6120
|
+
const unfilled = [];
|
|
6121
|
+
const stemmerFor = stemmerCache();
|
|
6122
|
+
for (const { name, external } of indexes) {
|
|
6123
|
+
note(`rebuilding ${name}`);
|
|
6124
|
+
if (external)
|
|
6125
|
+
database.exec(`INSERT INTO "${name}" ("${name}") VALUES ('rebuild')`);
|
|
6126
|
+
else if (FILLERS[name])
|
|
6127
|
+
FILLERS[name](database, now);
|
|
6128
|
+
else if (!CORPUS_TABLES.has(name) && !TRIGRAMS.includes(name))
|
|
6129
|
+
unfilled.push(name);
|
|
6130
|
+
}
|
|
6131
|
+
note("rebuilding the words of notes, documents, memories, mail, tasks, transcripts and events");
|
|
6132
|
+
resetNoteIndex(database);
|
|
6133
|
+
for (const corpus of Object.values(CORPORA))
|
|
6134
|
+
drainCorpus(database, corpus, stemmerFor);
|
|
6135
|
+
for (const name of TRIGRAMS) {
|
|
6136
|
+
const type = name.replace("_trigrams", "");
|
|
6137
|
+
database.prepare(`UPDATE search_index_state SET filled_through = 0, watermark = (SELECT coalesce(max(id), 0) FROM ${type}s) WHERE name = ?`).run(name);
|
|
6138
|
+
}
|
|
6139
|
+
fillTrigrams(database);
|
|
6140
|
+
note("finding mentions again");
|
|
6141
|
+
const mentions = rebuildMentions(database, { now: now() }).mentions;
|
|
6142
|
+
involvementStoreOver({ database, now }).rebuild();
|
|
6143
|
+
note("indexing the stored vectors");
|
|
6144
|
+
const vectorModels = fillVectorIndexes(database);
|
|
6145
|
+
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)");
|
|
6146
|
+
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)]));
|
|
6147
|
+
return {
|
|
6148
|
+
lostAndFound,
|
|
6149
|
+
searchIndexes: indexes.map((index) => index.name),
|
|
6150
|
+
unfilled,
|
|
6151
|
+
mentions,
|
|
6152
|
+
vectorModels,
|
|
6153
|
+
chunksWithoutVector
|
|
6154
|
+
};
|
|
6155
|
+
}, "rebuildDerived");
|
|
6156
|
+
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) => {
|
|
6157
|
+
const child = String(group.child);
|
|
6158
|
+
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;
|
|
6159
|
+
let missing = [];
|
|
6160
|
+
try {
|
|
6161
|
+
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));
|
|
6162
|
+
} catch {
|
|
6163
|
+
}
|
|
6164
|
+
return { table: child, parent: String(group.parent), rows: Number(group.n), missing };
|
|
6165
|
+
}), "danglingRows");
|
|
6166
|
+
var mailToFetch = /* @__PURE__ */ __name((database) => {
|
|
6167
|
+
try {
|
|
6168
|
+
return database.prepare(`SELECT a.external_id AS account, count(DISTINCT l.email_id) AS n FROM email_locations l
|
|
6169
|
+
JOIN mailboxes b ON b.id = l.mailbox_id JOIN accounts a ON a.id = b.account_id
|
|
6170
|
+
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) }));
|
|
6171
|
+
} catch {
|
|
6172
|
+
return [];
|
|
6173
|
+
}
|
|
6174
|
+
}, "mailToFetch");
|
|
6175
|
+
var clearInvalidJson = /* @__PURE__ */ __name((database) => {
|
|
6176
|
+
const found = invalidJson(database);
|
|
6177
|
+
for (const { table, column, required } of found) {
|
|
6178
|
+
const invalid = `"${column}" IS NOT NULL AND NOT json_valid("${column}")`;
|
|
6179
|
+
database.exec(required ? `DELETE FROM "${table}" WHERE ${invalid}` : `UPDATE "${table}" SET "${column}" = NULL WHERE ${invalid}`);
|
|
6180
|
+
}
|
|
6181
|
+
return found;
|
|
6182
|
+
}, "clearInvalidJson");
|
|
6183
|
+
var refuseInUse = /* @__PURE__ */ __name((path) => {
|
|
6184
|
+
const holders = storeHolders(path);
|
|
6185
|
+
if (holders && holders.length > 0) {
|
|
6186
|
+
const timers = activeTimers() ?? [];
|
|
6187
|
+
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" });
|
|
6188
|
+
}
|
|
6189
|
+
}, "refuseInUse");
|
|
6190
|
+
var recoverStore = /* @__PURE__ */ __name(async ({ path, command, version, sqlite3 = "sqlite3", now = Date.now, note = /* @__PURE__ */ __name(() => {
|
|
6191
|
+
}, "note"), copy }) => {
|
|
6192
|
+
const started = Date.now();
|
|
6193
|
+
if (!existsSync2(path))
|
|
6194
|
+
throw new CliError("not_found", `no store at ${path}`);
|
|
6195
|
+
const program = copy ? { program: sqlite3, version: "given", usable: true } : sqlite3Program(sqlite3);
|
|
6196
|
+
if (!program.usable) {
|
|
6197
|
+
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" });
|
|
6198
|
+
}
|
|
6199
|
+
const releaseLock2 = takeRecoverLock(path);
|
|
6200
|
+
try {
|
|
6201
|
+
refuseInUse(path);
|
|
6202
|
+
const bytes = STORE_PARTS.reduce((sum, suffix) => sum + (statSync2(`${path}${suffix}`, { throwIfNoEntry: false })?.size ?? 0), 0);
|
|
6203
|
+
const { bavail, bsize } = statfsSync(dirname(path));
|
|
6204
|
+
if (Number(bavail) * Number(bsize) < bytes * 1.2)
|
|
6205
|
+
throw new CliError("validation_error", `the recovery needs about ${Math.ceil(bytes * 1.2 / 1e9)} GB free beside the store`);
|
|
6206
|
+
return await recoverLocked({ path, command, version, sqlite3, now, note, copy, started, program });
|
|
6207
|
+
} finally {
|
|
6208
|
+
releaseLock2();
|
|
6209
|
+
}
|
|
6210
|
+
}, "recoverStore");
|
|
6211
|
+
var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqlite3, now, note, copy, started, program }) => {
|
|
6212
|
+
const watch = (await openSqlite(path, { readOnly: true })).database;
|
|
6213
|
+
let watching = true;
|
|
6214
|
+
const stopWatching = /* @__PURE__ */ __name(() => {
|
|
6215
|
+
if (watching)
|
|
6216
|
+
watch.close();
|
|
6217
|
+
watching = false;
|
|
6218
|
+
}, "stopWatching");
|
|
6219
|
+
try {
|
|
6220
|
+
const dataVersion = /* @__PURE__ */ __name(() => Number(watch.prepare("PRAGMA data_version").get()?.data_version), "dataVersion");
|
|
6221
|
+
let rowsBefore;
|
|
6222
|
+
try {
|
|
6223
|
+
rowsBefore = tableRows(watch);
|
|
6224
|
+
} catch (error) {
|
|
6225
|
+
if (!isStoreDamage(error))
|
|
6226
|
+
throw error;
|
|
6227
|
+
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" });
|
|
6228
|
+
}
|
|
6229
|
+
const before = { data: dataVersion(), inode: statSync2(path).ino };
|
|
6230
|
+
const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
|
|
6231
|
+
const target = `${path}.recovering-${stamp}`;
|
|
6232
|
+
writeFileSync(target, "", { flag: "wx", mode: 384 });
|
|
6233
|
+
const dropTarget = /* @__PURE__ */ __name(() => {
|
|
6234
|
+
for (const suffix of [...STORE_PARTS, "-journal"])
|
|
6235
|
+
rmSync2(`${target}${suffix}`, { force: true });
|
|
6236
|
+
}, "dropTarget");
|
|
6237
|
+
note(`copying the readable rows into ${target}`);
|
|
6238
|
+
let copied;
|
|
6239
|
+
let copyErrors;
|
|
6240
|
+
let read;
|
|
6241
|
+
let opened;
|
|
6242
|
+
try {
|
|
6243
|
+
;
|
|
6244
|
+
({ errors: copyErrors, read } = await (copy ?? ((from, to) => copyReadableRows(from, to, sqlite3)))(path, target));
|
|
6245
|
+
copied = Date.now();
|
|
6246
|
+
opened = await openSqlite(target);
|
|
6247
|
+
} catch (error) {
|
|
6248
|
+
dropTarget();
|
|
6249
|
+
throw error;
|
|
6250
|
+
}
|
|
6251
|
+
let rebuilt;
|
|
6252
|
+
let kept;
|
|
6253
|
+
let dangling;
|
|
6254
|
+
let json;
|
|
6255
|
+
let fetch2;
|
|
6256
|
+
let schema;
|
|
6257
|
+
try {
|
|
6258
|
+
kept = tableRows(opened.database);
|
|
6259
|
+
migrate(opened.database, { command, ...version ? { version } : {} });
|
|
6260
|
+
note("clearing values that are not valid JSON");
|
|
6261
|
+
json = clearInvalidJson(opened.database);
|
|
6262
|
+
rebuilt = rebuildDerived(opened.database, { now, note });
|
|
6263
|
+
note("looking for rows that point at rows that were lost");
|
|
6264
|
+
dangling = danglingRows(opened.database);
|
|
6265
|
+
fetch2 = mailToFetch(opened.database);
|
|
6266
|
+
schema = fileSchemaOf(opened.database).version;
|
|
6267
|
+
opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
6268
|
+
} catch (error) {
|
|
6269
|
+
opened.database.close();
|
|
6270
|
+
dropTarget();
|
|
6271
|
+
throw error;
|
|
6272
|
+
}
|
|
6273
|
+
opened.database.close();
|
|
6274
|
+
const rebuiltAt = Date.now();
|
|
6275
|
+
note("checking the recovered file");
|
|
6276
|
+
const health = await storeHealth(target, { deep: true });
|
|
6277
|
+
const checkedAt = Date.now();
|
|
6278
|
+
if (!health.ok) {
|
|
6279
|
+
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" });
|
|
6280
|
+
}
|
|
6281
|
+
refuseInUse(path);
|
|
6282
|
+
const changed = dataVersion() !== before.data || statSync2(path, { throwIfNoEntry: false })?.ino !== before.inode;
|
|
6283
|
+
stopWatching();
|
|
6284
|
+
if (changed) {
|
|
6285
|
+
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" });
|
|
6286
|
+
}
|
|
6287
|
+
const keptAt = `${path}.before-recover-${stamp}`;
|
|
6288
|
+
for (const suffix of STORE_PARTS)
|
|
6289
|
+
if (existsSync2(`${path}${suffix}`))
|
|
6290
|
+
renameSync2(`${path}${suffix}`, `${keptAt}${suffix}`);
|
|
6291
|
+
for (const suffix of STORE_PARTS)
|
|
6292
|
+
if (existsSync2(`${target}${suffix}`))
|
|
6293
|
+
renameSync2(`${target}${suffix}`, `${path}${suffix}`);
|
|
6294
|
+
recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema, now });
|
|
6295
|
+
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);
|
|
6296
|
+
const seconds = /* @__PURE__ */ __name((from, to) => Math.round((to - from) / 100) / 10, "seconds");
|
|
6297
|
+
return {
|
|
6298
|
+
path,
|
|
6299
|
+
keptAt,
|
|
6300
|
+
sqlite3: program.version,
|
|
6301
|
+
lost,
|
|
6302
|
+
dangling,
|
|
6303
|
+
invalidJson: json,
|
|
6304
|
+
mailToFetch: fetch2,
|
|
6305
|
+
rebuilt,
|
|
6306
|
+
copyErrors,
|
|
6307
|
+
health,
|
|
6308
|
+
seconds: {
|
|
6309
|
+
copy: seconds(started, copied),
|
|
6310
|
+
rebuild: seconds(copied, rebuiltAt),
|
|
6311
|
+
check: seconds(rebuiltAt, checkedAt),
|
|
6312
|
+
total: seconds(started, Date.now())
|
|
6313
|
+
}
|
|
6314
|
+
};
|
|
6315
|
+
} finally {
|
|
6316
|
+
stopWatching();
|
|
6317
|
+
}
|
|
6318
|
+
}, "recoverLocked");
|
|
6319
|
+
|
|
6320
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
|
|
6321
|
+
var COUNTED = [
|
|
6322
|
+
"accounts",
|
|
6323
|
+
"chats",
|
|
6324
|
+
"messages",
|
|
6325
|
+
"attachments",
|
|
6326
|
+
"emails",
|
|
6327
|
+
"documents",
|
|
6328
|
+
"notes",
|
|
6329
|
+
"meetings",
|
|
6330
|
+
"chunks",
|
|
6331
|
+
"embeddings",
|
|
6332
|
+
"mentions"
|
|
6333
|
+
];
|
|
6334
|
+
var stopTimers = /* @__PURE__ */ __name((timers) => `systemctl --user stop ${timers.join(" ")}`, "stopTimers");
|
|
6335
|
+
var storeRecoveryCheck = /* @__PURE__ */ __name(async (env, command, version) => {
|
|
6336
|
+
const path = storePath(env);
|
|
6337
|
+
if (!existsSync3(path))
|
|
6338
|
+
return { path, exists: false, ok: true, next: [] };
|
|
6339
|
+
const health = await storeHealth(path, { deep: true });
|
|
6340
|
+
let rows = {};
|
|
6341
|
+
let schema = null;
|
|
6342
|
+
try {
|
|
6343
|
+
const { database } = await openSqlite(path, { readOnly: true });
|
|
6344
|
+
try {
|
|
6345
|
+
schema = fileSchemaOf(database).version;
|
|
6346
|
+
const all = tableRows(database);
|
|
6347
|
+
rows = Object.fromEntries(COUNTED.filter((table) => table in all).map((table) => [table, all[table] ?? null]));
|
|
6348
|
+
} finally {
|
|
6349
|
+
database.close();
|
|
6350
|
+
}
|
|
6351
|
+
} catch {
|
|
6352
|
+
}
|
|
6353
|
+
recordDeepCheck(path, health, { cli: command, ...version ? { version } : {}, schema });
|
|
6354
|
+
const mark = readDamageMark(path);
|
|
6355
|
+
const explanation = explainDamage(health, command, mark);
|
|
6356
|
+
const inUse = storeHolders(path) ?? null;
|
|
6357
|
+
const timers = activeTimers() ?? null;
|
|
6358
|
+
const sqlite3 = sqlite3Program();
|
|
6359
|
+
const next = health.ok ? [] : [
|
|
6360
|
+
...timers?.length ? [stopTimers(timers)] : [],
|
|
6361
|
+
...(inUse ?? []).map(({ pid, name }) => `stop ${name} (process ${pid}): it has the store open`),
|
|
6362
|
+
...sqlite3.usable ? [] : ["install sqlite3 3.43 or newer (apt install sqlite3, brew install sqlite)"],
|
|
6363
|
+
`${command} store recover run`
|
|
6364
|
+
];
|
|
6365
|
+
return {
|
|
6366
|
+
path,
|
|
6367
|
+
exists: true,
|
|
6368
|
+
ok: health.ok,
|
|
6369
|
+
seconds: Math.round(health.ms / 100) / 10,
|
|
6370
|
+
problems: health.problems ?? 0,
|
|
6371
|
+
damagedTables: health.damagedTables ?? [],
|
|
6372
|
+
damagedSearchIndexes: (health.searchIndexes ?? []).filter((index) => !index.ok).map(({ name, error }) => ({ name, ...error ? { error } : {} })),
|
|
6373
|
+
invalidJson: health.invalidJson ?? [],
|
|
6374
|
+
rows,
|
|
6375
|
+
explanation,
|
|
6376
|
+
damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
|
|
6377
|
+
lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
|
|
6378
|
+
inUse,
|
|
6379
|
+
timers,
|
|
6380
|
+
sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
|
|
6381
|
+
next
|
|
6382
|
+
};
|
|
6383
|
+
}, "storeRecoveryCheck");
|
|
6384
|
+
var storeRecoveryRun = /* @__PURE__ */ __name(async (env, { command, version, note, timers: scheduled = activeTimers, copy }) => {
|
|
6385
|
+
const timers = scheduled() ?? [];
|
|
6386
|
+
if (timers.length > 0)
|
|
6387
|
+
throw new CliError("validation_error", `stop the timers first, they open the store: ${stopTimers(timers)}`, {
|
|
6388
|
+
reason: "store.in-use"
|
|
6389
|
+
});
|
|
6390
|
+
const recovery = await recoverStore({
|
|
6391
|
+
path: storePath(env),
|
|
6392
|
+
command,
|
|
6393
|
+
...version ? { version } : {},
|
|
6394
|
+
...note ? { note } : {},
|
|
6395
|
+
...copy ? { copy } : {}
|
|
6396
|
+
});
|
|
6397
|
+
const mail = recovery.mailToFetch.map(({ account, emails }) => `mail <profile of ${account}> sync --rescan # ${emails} emails`);
|
|
6398
|
+
const lostMail = recovery.lost.some(({ table }) => table === "emails") && mail.length === 0 ? ["mail <profile> sync --rescan # each mail profile"] : [];
|
|
6399
|
+
const { health, copyErrors, ...kept } = recovery;
|
|
6400
|
+
return {
|
|
6401
|
+
...kept,
|
|
6402
|
+
copyErrors: copyErrors.length,
|
|
6403
|
+
checkedOk: health.ok,
|
|
6404
|
+
next: [...mail, ...lostMail, "systemctl --user start <the timers stopped before>"]
|
|
6405
|
+
};
|
|
6406
|
+
}, "storeRecoveryRun");
|
|
6407
|
+
var recoveryNotes = /* @__PURE__ */ __name((answer) => {
|
|
6408
|
+
if ("keptAt" in answer) {
|
|
6409
|
+
const lost = answer.lost.map(({ table, before, read, kept }) => `${table}: ${kept} kept of ${before ?? "an uncountable number"}${read > kept ? `, ${read - kept} read but unusable` : ""}`);
|
|
6410
|
+
return [
|
|
6411
|
+
`recovered in ${answer.seconds.total} s; the damaged file is kept at ${answer.keptAt}`,
|
|
6412
|
+
...lost.length ? lost : ["no table lost a row"],
|
|
6413
|
+
...answer.dangling.map(({ table, parent, rows }) => `${rows} rows of ${table} point at ${parent} rows the store does not hold`),
|
|
6414
|
+
...answer.invalidJson.map(({ table, column, rows, required }) => `${table}.${column}: ${rows} values were not valid JSON \u2014 ${required ? "those rows were dropped" : "set to empty"}`),
|
|
6415
|
+
...answer.next.map((line) => `next: ${line}`)
|
|
6416
|
+
];
|
|
6417
|
+
}
|
|
6418
|
+
if (!answer.exists)
|
|
6419
|
+
return ["no store yet"];
|
|
6420
|
+
if (answer.ok)
|
|
6421
|
+
return [`the store is healthy (checked every page and search index in ${answer.seconds} s)`];
|
|
6422
|
+
const why = answer.explanation;
|
|
6423
|
+
return [
|
|
6424
|
+
...why ? [why.what, ...why.impact, why.externalUnaffected] : [],
|
|
6425
|
+
answer.lastKnownGood ? `the store last passed a deep check at ${answer.lastKnownGood}` : "no deep check that passed is on record for this store",
|
|
6426
|
+
...answer.next.map((line) => `next: ${line}`)
|
|
6427
|
+
];
|
|
6428
|
+
}, "recoveryNotes");
|
|
6429
|
+
var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
|
|
6430
|
+
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() {
|
|
6431
|
+
const output = outputFor(this);
|
|
6432
|
+
const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command, version);
|
|
6433
|
+
renderAnswer(this, output, itemOf(snakeKeys(answer)));
|
|
6434
|
+
if (output.format === "pretty")
|
|
6435
|
+
for (const line of recoveryNotes(answer))
|
|
6436
|
+
output.renderer.note(line);
|
|
6437
|
+
});
|
|
6438
|
+
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() {
|
|
6439
|
+
const output = outputFor(this);
|
|
6440
|
+
const answer = await storeRecoveryRun(environmentOf(this).env ?? process.env, {
|
|
6441
|
+
command,
|
|
6442
|
+
...version ? { version } : {},
|
|
6443
|
+
note: /* @__PURE__ */ __name((text) => output.renderer.note(text), "note")
|
|
6444
|
+
});
|
|
6445
|
+
renderAnswer(this, output, itemOf(snakeKeys(answer)));
|
|
6446
|
+
if (output.format === "pretty")
|
|
6447
|
+
for (const line of recoveryNotes(answer))
|
|
6448
|
+
output.renderer.note(line);
|
|
6449
|
+
}));
|
|
6450
|
+
return recover;
|
|
6451
|
+
}, "storeRecoverCommand");
|
|
6452
|
+
|
|
6453
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/store-info.js
|
|
5896
6454
|
var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
|
|
5897
|
-
var bytesOf = /* @__PURE__ */ __name((path) =>
|
|
6455
|
+
var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
|
|
5898
6456
|
var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
|
|
5899
6457
|
var contentsOf = /* @__PURE__ */ __name((database, version, writable) => version > 0 && writable ? {
|
|
5900
6458
|
rows: rowCounts(database),
|
|
@@ -5905,7 +6463,7 @@ var contentsOf = /* @__PURE__ */ __name((database, version, writable) => version
|
|
|
5905
6463
|
} : { rows: {}, pendingNormalization: null, wordIndex: null, stemIndex: null }, "contentsOf");
|
|
5906
6464
|
var storeInfo = /* @__PURE__ */ __name(async (env) => {
|
|
5907
6465
|
const path = storePath(env);
|
|
5908
|
-
if (!
|
|
6466
|
+
if (!existsSync4(path))
|
|
5909
6467
|
return snakeKeys({ path, exists: false, schema: compatibilityOf(void 0) });
|
|
5910
6468
|
let schema = compatibilityOf(void 0);
|
|
5911
6469
|
try {
|
|
@@ -5938,7 +6496,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
|
|
|
5938
6496
|
renderAnswer(this, outputFor(this), itemOf(answer));
|
|
5939
6497
|
}), "storeInfoCommand");
|
|
5940
6498
|
|
|
5941
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6499
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
|
|
5942
6500
|
var ENCRYPT_OPTION = [
|
|
5943
6501
|
"--encrypt",
|
|
5944
6502
|
"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"
|
|
@@ -5957,9 +6515,9 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
|
|
|
5957
6515
|
return password;
|
|
5958
6516
|
}, "passwordOf");
|
|
5959
6517
|
|
|
5960
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
5961
|
-
import { existsSync as
|
|
5962
|
-
import { join } from "node:path";
|
|
6518
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/rules.js
|
|
6519
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
6520
|
+
import { join as join2 } from "node:path";
|
|
5963
6521
|
var REPLY_ACTIONS = ["reply", "task"];
|
|
5964
6522
|
var REPLY_MODELS = ["fill-only", "may-reword"];
|
|
5965
6523
|
var REPLY_KINDS = ["dialog", "group"];
|
|
@@ -6045,7 +6603,7 @@ var defaultRule = /* @__PURE__ */ __name((id) => ({
|
|
|
6045
6603
|
reply: { template: "", asReply: true },
|
|
6046
6604
|
limits: { perChat: "1/1d", perPerson: "1/1d" }
|
|
6047
6605
|
}), "defaultRule");
|
|
6048
|
-
var repliesPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
6606
|
+
var repliesPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).config, `${profile}.replies.json`), "repliesPathFor");
|
|
6049
6607
|
var EVERYONE = { reply: "all", allow: { people: [], chats: [] }, deny: { people: [], chats: [] } };
|
|
6050
6608
|
var outsideAudience = /* @__PURE__ */ __name((audience, person, chat) => {
|
|
6051
6609
|
if (person !== null && audience.deny.people.includes(person))
|
|
@@ -6075,11 +6633,11 @@ var readReplies = /* @__PURE__ */ __name((path, provider) => {
|
|
|
6075
6633
|
return parseReplies(readRepliesFile(path, provider), path, provider);
|
|
6076
6634
|
}, "readReplies");
|
|
6077
6635
|
var readRepliesFile = /* @__PURE__ */ __name((path, provider) => {
|
|
6078
|
-
if (!
|
|
6636
|
+
if (!existsSync5(path))
|
|
6079
6637
|
return { audience: structuredClone(EVERYONE), rules: [] };
|
|
6080
6638
|
let parsed;
|
|
6081
6639
|
try {
|
|
6082
|
-
parsed = JSON.parse(
|
|
6640
|
+
parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
6083
6641
|
} catch (error) {
|
|
6084
6642
|
throw broken(path, error instanceof Error ? error.message : String(error));
|
|
6085
6643
|
}
|
|
@@ -6128,9 +6686,9 @@ var problem = /* @__PURE__ */ __name((issue) => {
|
|
|
6128
6686
|
}, "problem");
|
|
6129
6687
|
var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
|
|
6130
6688
|
|
|
6131
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6132
|
-
import { existsSync as
|
|
6133
|
-
import { join as
|
|
6689
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/state.js
|
|
6690
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
6691
|
+
import { join as join3 } from "node:path";
|
|
6134
6692
|
var ANSWERED_KEPT = 1e3;
|
|
6135
6693
|
var times = record(string(), array(string()));
|
|
6136
6694
|
var stateFile = object({
|
|
@@ -6142,13 +6700,13 @@ var stateFile = object({
|
|
|
6142
6700
|
});
|
|
6143
6701
|
var emptyState = /* @__PURE__ */ __name(() => ({ paused: false, answered: [], sent: {} }), "emptyState");
|
|
6144
6702
|
var answeredKey = /* @__PURE__ */ __name((message) => `${message.chatId}:${message.id}`, "answeredKey");
|
|
6145
|
-
var repliesStatePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
6703
|
+
var repliesStatePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, `${profile}.replies-state.json`), "repliesStatePathFor");
|
|
6146
6704
|
var readRepliesState = /* @__PURE__ */ __name((path) => {
|
|
6147
|
-
if (!
|
|
6705
|
+
if (!existsSync6(path))
|
|
6148
6706
|
return emptyState();
|
|
6149
6707
|
let parsed;
|
|
6150
6708
|
try {
|
|
6151
|
-
parsed = JSON.parse(
|
|
6709
|
+
parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
6152
6710
|
} catch (error) {
|
|
6153
6711
|
throw broken2(path, error instanceof Error ? error.message : String(error));
|
|
6154
6712
|
}
|
|
@@ -6181,7 +6739,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
|
|
|
6181
6739
|
}, "recordReply");
|
|
6182
6740
|
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");
|
|
6183
6741
|
|
|
6184
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6742
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/decide.js
|
|
6185
6743
|
var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
|
|
6186
6744
|
var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
|
|
6187
6745
|
const { message, chat, owner, sender } = incoming;
|
|
@@ -6287,7 +6845,7 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
|
|
|
6287
6845
|
return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
|
|
6288
6846
|
}, "filled");
|
|
6289
6847
|
|
|
6290
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6848
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/template.js
|
|
6291
6849
|
var import_liquidjs = __toESM(require_liquid_node(), 1);
|
|
6292
6850
|
var TEMPLATE_LIMITS = {
|
|
6293
6851
|
parse: 32768,
|
|
@@ -6447,7 +7005,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
|
|
|
6447
7005
|
}
|
|
6448
7006
|
}, "renderReplyTemplate");
|
|
6449
7007
|
|
|
6450
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7008
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
|
|
6451
7009
|
var DRY_RUN_DAYS = 7;
|
|
6452
7010
|
var PAGE = 500;
|
|
6453
7011
|
var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
|
|
@@ -6561,7 +7119,7 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
|
|
|
6561
7119
|
}
|
|
6562
7120
|
}, "storedSince");
|
|
6563
7121
|
|
|
6564
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7122
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/embeddings/keys.js
|
|
6565
7123
|
var endpointKeyName = /* @__PURE__ */ __name((baseUrl) => {
|
|
6566
7124
|
const host = new URL(baseUrl).host;
|
|
6567
7125
|
return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
|
|
@@ -6592,7 +7150,7 @@ var embeddingKeys = /* @__PURE__ */ __name((app, env = process.env, keyring) =>
|
|
|
6592
7150
|
};
|
|
6593
7151
|
}, "embeddingKeys");
|
|
6594
7152
|
|
|
6595
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7153
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/models/openai.js
|
|
6596
7154
|
var options = strictObject({
|
|
6597
7155
|
temperature: range(0, 2),
|
|
6598
7156
|
top_p: range(0, 1),
|
|
@@ -6606,7 +7164,7 @@ var openai = {
|
|
|
6606
7164
|
images: true,
|
|
6607
7165
|
baseUrl: "https://api.openai.com/v1",
|
|
6608
7166
|
validate: /* @__PURE__ */ __name((given) => checkedOptions("openai", options, given), "validate"),
|
|
6609
|
-
complete: /* @__PURE__ */ __name(
|
|
7167
|
+
complete: /* @__PURE__ */ __name((target, request, checked, apiKey, fetcher) => withTimeLimit(12e4, async (deadline) => {
|
|
6610
7168
|
const response = await fetcher(`${target.baseUrl.replace(/\/+$/, "")}/chat/completions`, {
|
|
6611
7169
|
method: "POST",
|
|
6612
7170
|
headers: { "Content-Type": "application/json", ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {} },
|
|
@@ -6628,7 +7186,7 @@ var openai = {
|
|
|
6628
7186
|
],
|
|
6629
7187
|
...new URL(target.baseUrl).hostname === "api.openai.com" ? { max_completion_tokens: request.maxTokens } : { max_tokens: request.maxTokens }
|
|
6630
7188
|
}),
|
|
6631
|
-
signal:
|
|
7189
|
+
signal: deadline,
|
|
6632
7190
|
redirect: "error"
|
|
6633
7191
|
});
|
|
6634
7192
|
if (!response.ok)
|
|
@@ -6638,10 +7196,10 @@ var openai = {
|
|
|
6638
7196
|
if (choice?.finish_reason !== "stop" || typeof choice.message?.content !== "string" || !Number.isInteger(body.usage?.total_tokens) || (body.usage?.total_tokens ?? 0) < 1)
|
|
6639
7197
|
throw new Error("incomplete response");
|
|
6640
7198
|
return { text: choice.message.content, tokens: body.usage?.total_tokens };
|
|
6641
|
-
}, "complete")
|
|
7199
|
+
}), "complete")
|
|
6642
7200
|
};
|
|
6643
7201
|
|
|
6644
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7202
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/models/index.js
|
|
6645
7203
|
var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
6646
7204
|
complete: /* @__PURE__ */ __name(async (request) => {
|
|
6647
7205
|
if (deps.signal?.aborted)
|
|
@@ -6656,7 +7214,7 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
|
6656
7214
|
if (!adapter && target.provider === "openai")
|
|
6657
7215
|
adapter = openai;
|
|
6658
7216
|
if (!adapter && target.provider === "anthropic")
|
|
6659
|
-
adapter = (await import("./anthropic-
|
|
7217
|
+
adapter = (await import("./anthropic-RGV3WXX5.js")).anthropic;
|
|
6660
7218
|
if (!adapter)
|
|
6661
7219
|
throw new CliError("validation_error", `no model adapter for ${target.provider}`);
|
|
6662
7220
|
if (request.images !== void 0 && adapter.images !== true)
|
|
@@ -6697,19 +7255,19 @@ var modelGateway = /* @__PURE__ */ __name((deps) => ({
|
|
|
6697
7255
|
}, "complete")
|
|
6698
7256
|
}), "modelGateway");
|
|
6699
7257
|
|
|
6700
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
6701
|
-
import { existsSync as
|
|
6702
|
-
import { join as
|
|
7258
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/consents.js
|
|
7259
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
|
|
7260
|
+
import { join as join4 } from "node:path";
|
|
6703
7261
|
var shape = strictObject({
|
|
6704
7262
|
provider: nullable(pipe(string(), minLength(1))),
|
|
6705
7263
|
deniedChats: array(pipe(string(), minLength(1)))
|
|
6706
7264
|
});
|
|
6707
|
-
var replyConsentPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) =>
|
|
7265
|
+
var replyConsentPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).config, `${profile}.replies-consents.json`), "replyConsentPathFor");
|
|
6708
7266
|
var readReplyConsent = /* @__PURE__ */ __name((path) => {
|
|
6709
|
-
if (!
|
|
7267
|
+
if (!existsSync7(path))
|
|
6710
7268
|
return { provider: null, deniedChats: [] };
|
|
6711
7269
|
try {
|
|
6712
|
-
return parse(shape, JSON.parse(
|
|
7270
|
+
return parse(shape, JSON.parse(readFileSync4(path, "utf8")));
|
|
6713
7271
|
} catch {
|
|
6714
7272
|
throw new CliError("configuration_error", "reply model consent is invalid; fix its file before granting consent");
|
|
6715
7273
|
}
|
|
@@ -6722,7 +7280,7 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
|
|
|
6722
7280
|
return consent.provider === provider && !consent.deniedChats.includes(chat);
|
|
6723
7281
|
}, "mayModelReply");
|
|
6724
7282
|
|
|
6725
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7283
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/rendering.js
|
|
6726
7284
|
var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options2 = {
|
|
6727
7285
|
ai: true
|
|
6728
7286
|
}) => async (rule2, message, chat, now) => {
|
|
@@ -6769,7 +7327,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
|
|
|
6769
7327
|
return result2;
|
|
6770
7328
|
}, "replyRenderer");
|
|
6771
7329
|
|
|
6772
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7330
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/replies/serve.js
|
|
6773
7331
|
var NOT_ALLOWED = "replies.send is not allow";
|
|
6774
7332
|
var NO_RULES = "no rules";
|
|
6775
7333
|
var ONLY_TASK = "opened a task, sent nothing";
|
|
@@ -6862,7 +7420,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
|
|
|
6862
7420
|
return { skip: why };
|
|
6863
7421
|
}, "replyTo");
|
|
6864
7422
|
|
|
6865
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7423
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
|
|
6866
7424
|
var START_SYNC_DELAY_MS = 3e4;
|
|
6867
7425
|
var START_SYNC_BUDGET_MS = 5 * 6e4;
|
|
6868
7426
|
var START_SYNC_WINDOW_MS = 7 * 864e5;
|
|
@@ -6873,8 +7431,8 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
|
|
|
6873
7431
|
let pass = Promise.resolve();
|
|
6874
7432
|
let started = false;
|
|
6875
7433
|
let done;
|
|
6876
|
-
const run = /* @__PURE__ */ __name(
|
|
6877
|
-
|
|
7434
|
+
const run = /* @__PURE__ */ __name(() => withTimeLimit(budgetMs, (deadline) => catchUp(AbortSignal.any([controller.signal, deadline]))), "run");
|
|
7435
|
+
const catchUp = /* @__PURE__ */ __name(async (stop) => {
|
|
6878
7436
|
const floor = now() - windowMs;
|
|
6879
7437
|
const moved = [];
|
|
6880
7438
|
for (const chat of await chats(stop)) {
|
|
@@ -6915,7 +7473,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
|
|
|
6915
7473
|
code: "start_sync",
|
|
6916
7474
|
text: `caught up ${summary.fetched} message(s) in ${summary.chats} chat(s) that moved while serve was down` + (summary.stopped ? ` \u2014 stopped at the time limit, ${behind.length - summary.chats - summary.failed} left` : "")
|
|
6917
7475
|
});
|
|
6918
|
-
}, "
|
|
7476
|
+
}, "catchUp");
|
|
6919
7477
|
return {
|
|
6920
7478
|
start: /* @__PURE__ */ __name(() => {
|
|
6921
7479
|
if (started || controller.signal.aborted)
|
|
@@ -6939,7 +7497,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch: fetch2, note
|
|
|
6939
7497
|
};
|
|
6940
7498
|
}, "startSync");
|
|
6941
7499
|
|
|
6942
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7500
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
|
|
6943
7501
|
var FIRST_FETCH_MS = 6e4;
|
|
6944
7502
|
var DAY_MS = 864e5;
|
|
6945
7503
|
var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
|
|
@@ -6993,7 +7551,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch: fetch2, warn, fi
|
|
|
6993
7551
|
};
|
|
6994
7552
|
}, "memberFetches");
|
|
6995
7553
|
|
|
6996
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7554
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
|
|
6997
7555
|
var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
|
|
6998
7556
|
var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
|
|
6999
7557
|
if (context.format === "pretty") {
|
|
@@ -7026,7 +7584,7 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
|
|
|
7026
7584
|
return context;
|
|
7027
7585
|
}, "recordDiagnostics");
|
|
7028
7586
|
|
|
7029
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7587
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
|
|
7030
7588
|
var STEMS_EVERY_MS = 3e4;
|
|
7031
7589
|
var STEMS_SLICE_MS = 2e3;
|
|
7032
7590
|
var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
|
|
@@ -7066,7 +7624,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
|
|
|
7066
7624
|
};
|
|
7067
7625
|
}, "stemFills");
|
|
7068
7626
|
|
|
7069
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7627
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/render/messages.js
|
|
7070
7628
|
import { styleText } from "node:util";
|
|
7071
7629
|
var TIME_WIDTH = 8;
|
|
7072
7630
|
var INDENT = " ".repeat(TIME_WIDTH + 2);
|
|
@@ -7242,7 +7800,7 @@ var editedAt = /* @__PURE__ */ __name((message, options2) => {
|
|
|
7242
7800
|
return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
|
|
7243
7801
|
}, "editedAt");
|
|
7244
7802
|
|
|
7245
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7803
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
|
|
7246
7804
|
var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
|
|
7247
7805
|
var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
|
|
7248
7806
|
kind: attachment.kind,
|
|
@@ -7337,7 +7895,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
|
|
|
7337
7895
|
locale: messenger.app.locale
|
|
7338
7896
|
}), "viewOf");
|
|
7339
7897
|
|
|
7340
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7898
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
|
|
7341
7899
|
var observed = /* @__PURE__ */ __name((value) => ({
|
|
7342
7900
|
value: value.value,
|
|
7343
7901
|
observed_at: value.observedAt,
|
|
@@ -7404,7 +7962,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
|
|
|
7404
7962
|
}
|
|
7405
7963
|
}, "watchEventItem");
|
|
7406
7964
|
|
|
7407
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7965
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
|
|
7408
7966
|
var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
|
|
7409
7967
|
output: { entity: "watch_item" },
|
|
7410
7968
|
effects: REMOTE_READ,
|
|
@@ -7559,7 +8117,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
|
|
|
7559
8117
|
}
|
|
7560
8118
|
}, "describe");
|
|
7561
8119
|
|
|
7562
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
8120
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
|
|
7563
8121
|
var serveCommand = /* @__PURE__ */ __name((messenger) => {
|
|
7564
8122
|
const command = annotate(new Command("serve"), {
|
|
7565
8123
|
output: { entity: "serve_summary" },
|
|
@@ -7823,8 +8381,8 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
|
|
|
7823
8381
|
};
|
|
7824
8382
|
}, "tasking");
|
|
7825
8383
|
|
|
7826
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
7827
|
-
import { existsSync as
|
|
8384
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
|
|
8385
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
7828
8386
|
var PATH = "store tables list";
|
|
7829
8387
|
var STORE_TABLES_QUERY = {
|
|
7830
8388
|
entity: "store_table",
|
|
@@ -7853,7 +8411,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
|
|
|
7853
8411
|
const filter = filterOf(words);
|
|
7854
8412
|
const { full } = this.optsWithGlobals();
|
|
7855
8413
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7856
|
-
if (!
|
|
8414
|
+
if (!existsSync8(path))
|
|
7857
8415
|
throw new CliError("not_found", `no store at ${path}`);
|
|
7858
8416
|
const items = await readStoreTables(path, { filter, sizes: full === true });
|
|
7859
8417
|
renderAnswer(this, outputFor(this), listOf(PATH, {
|
|
@@ -7866,7 +8424,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
|
|
|
7866
8424
|
return tables;
|
|
7867
8425
|
}, "storeTablesCommand");
|
|
7868
8426
|
|
|
7869
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
8427
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.608.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_835308f42ae01aacd71fad942c0d0dc0/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
|
|
7870
8428
|
var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
|
|
7871
8429
|
var WORD_INDEX = "message_words";
|
|
7872
8430
|
var schemaOf = /* @__PURE__ */ __name((database) => {
|
|
@@ -7875,7 +8433,7 @@ var schemaOf = /* @__PURE__ */ __name((database) => {
|
|
|
7875
8433
|
}, "schemaOf");
|
|
7876
8434
|
var count2 = /* @__PURE__ */ __name((database, table) => Number(database.prepare(`SELECT count(*) AS n FROM ${table}`).get()?.n ?? 0), "count");
|
|
7877
8435
|
var pendingIfKnown2 = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
|
|
7878
|
-
var bytesOf2 = /* @__PURE__ */ __name((path) =>
|
|
8436
|
+
var bytesOf2 = /* @__PURE__ */ __name((path) => existsSync9(path) ? statSync4(path).size : 0, "bytesOf");
|
|
7879
8437
|
var reading = /* @__PURE__ */ __name(async (path, read) => {
|
|
7880
8438
|
const database = await openCache(path);
|
|
7881
8439
|
try {
|
|
@@ -7892,24 +8450,59 @@ var readingOnly = /* @__PURE__ */ __name(async (path, read) => {
|
|
|
7892
8450
|
database.close();
|
|
7893
8451
|
}
|
|
7894
8452
|
}, "readingOnly");
|
|
7895
|
-
var
|
|
8453
|
+
var withoutInode = /* @__PURE__ */ __name(({ inode: _, ...mark }) => mark, "withoutInode");
|
|
8454
|
+
var fileSchema = /* @__PURE__ */ __name(async (path) => {
|
|
8455
|
+
try {
|
|
8456
|
+
return await readingOnly(path, (database) => fileSchemaOf(database).version);
|
|
8457
|
+
} catch {
|
|
8458
|
+
return null;
|
|
8459
|
+
}
|
|
8460
|
+
}, "fileSchema");
|
|
8461
|
+
var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, version } = {}) => {
|
|
7896
8462
|
const path = storePath(env);
|
|
7897
|
-
if (!
|
|
8463
|
+
if (!existsSync9(path))
|
|
7898
8464
|
return { path, exists: false };
|
|
8465
|
+
const checked = await storeHealth(path, { deep });
|
|
8466
|
+
const recorded = deep ? recordDeepCheck(path, checked, {
|
|
8467
|
+
cli: command ?? "unknown",
|
|
8468
|
+
...version ? { version } : {},
|
|
8469
|
+
schema: await fileSchema(path)
|
|
8470
|
+
}) : null;
|
|
8471
|
+
const mark = readDamageMark(path);
|
|
8472
|
+
const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
|
|
8473
|
+
const health = {
|
|
8474
|
+
checked: checked.checked,
|
|
8475
|
+
covers: deep ? "every page and every search index" : QUICK_HEALTH_CHECKS,
|
|
8476
|
+
ok: checked.ok,
|
|
8477
|
+
ms: checked.ms,
|
|
8478
|
+
...checked.problems ? { problems: checked.problems } : {},
|
|
8479
|
+
...checked.damagedTables?.length ? { damagedTables: checked.damagedTables } : {},
|
|
8480
|
+
...checked.invalidJson?.length ? { invalidJson: checked.invalidJson } : {},
|
|
8481
|
+
...checked.searchIndexes?.some((index) => !index.ok) ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) } : {}
|
|
8482
|
+
};
|
|
8483
|
+
const damage = command ? explainDamage(checked, command, mark) : null;
|
|
8484
|
+
const healthOf = {
|
|
8485
|
+
health,
|
|
8486
|
+
lastKnownGood,
|
|
8487
|
+
...mark ? { damageMark: withoutInode(mark) } : {},
|
|
8488
|
+
...recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {},
|
|
8489
|
+
...damage ? { damage } : {}
|
|
8490
|
+
};
|
|
7899
8491
|
try {
|
|
7900
8492
|
return await reading(path, (database) => {
|
|
7901
|
-
const { version, writable } = schemaOf(database);
|
|
8493
|
+
const { version: version2, writable } = schemaOf(database);
|
|
7902
8494
|
return {
|
|
7903
8495
|
path,
|
|
7904
8496
|
exists: true,
|
|
7905
|
-
schema:
|
|
8497
|
+
schema: version2,
|
|
7906
8498
|
speaks: SPEAKS,
|
|
7907
8499
|
writable,
|
|
7908
|
-
...
|
|
8500
|
+
...version2 > 0 ? { chats: count2(database, "chats"), messages: count2(database, "messages") } : {},
|
|
8501
|
+
...healthOf
|
|
7909
8502
|
};
|
|
7910
8503
|
});
|
|
7911
8504
|
} catch (error) {
|
|
7912
|
-
return { path, exists: true, error: messageOf2(error) };
|
|
8505
|
+
return { path, exists: true, error: messageOf2(error), ...healthOf };
|
|
7913
8506
|
}
|
|
7914
8507
|
}, "storeSummary");
|
|
7915
8508
|
var result = /* @__PURE__ */ __name((command, value, next = []) => renderAnswer(command, outputFor(command), itemOf(snakeKeys(value), { next })), "result");
|
|
@@ -7924,7 +8517,8 @@ var storeMaintenanceCommands = /* @__PURE__ */ __name((messenger) => [
|
|
|
7924
8517
|
repairCommand(messenger),
|
|
7925
8518
|
resetCommand(messenger),
|
|
7926
8519
|
copiesCommand(),
|
|
7927
|
-
storeTablesCommand(messenger)
|
|
8520
|
+
storeTablesCommand(messenger),
|
|
8521
|
+
storeRecoverCommand({ command: messenger.app.command, version: messenger.app.version })
|
|
7928
8522
|
], "storeMaintenanceCommands");
|
|
7929
8523
|
var refuseWhileServing = /* @__PURE__ */ __name((command, messenger) => {
|
|
7930
8524
|
const serving = servingProfiles(messenger.app, environmentOf(command).env ?? process.env);
|
|
@@ -7936,7 +8530,7 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
|
|
|
7936
8530
|
const { renderer, format } = outputFor(this);
|
|
7937
8531
|
const { dryRun: dryRun2 } = this.opts();
|
|
7938
8532
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7939
|
-
if (!
|
|
8533
|
+
if (!existsSync9(path)) {
|
|
7940
8534
|
result(this, { path, exists: false });
|
|
7941
8535
|
return;
|
|
7942
8536
|
}
|
|
@@ -7976,7 +8570,7 @@ var notesOf = /* @__PURE__ */ __name((report, command) => {
|
|
|
7976
8570
|
}, "notesOf");
|
|
7977
8571
|
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) {
|
|
7978
8572
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7979
|
-
if (!
|
|
8573
|
+
if (!existsSync9(path))
|
|
7980
8574
|
throw new CliError("not_found", `no store at ${path}`);
|
|
7981
8575
|
const deleted = await reading(path, (database) => deleteCopy(database, name));
|
|
7982
8576
|
result(this, { path, deleted });
|
|
@@ -7984,7 +8578,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
|
|
|
7984
8578
|
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() {
|
|
7985
8579
|
const { renderer } = outputFor(this);
|
|
7986
8580
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
7987
|
-
if (!
|
|
8581
|
+
if (!existsSync9(path)) {
|
|
7988
8582
|
result(this, { path, exists: false, ok: true });
|
|
7989
8583
|
return;
|
|
7990
8584
|
}
|
|
@@ -8047,7 +8641,7 @@ var inspect = /* @__PURE__ */ __name((path) => reading(path, (database) => {
|
|
|
8047
8641
|
...schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []
|
|
8048
8642
|
]);
|
|
8049
8643
|
const size = bytesOf2(path) + bytesOf2(`${path}-wal`);
|
|
8050
|
-
const { bavail, bsize } =
|
|
8644
|
+
const { bavail, bsize } = statfsSync2(dirname2(path));
|
|
8051
8645
|
const free = Number(bavail) * Number(bsize);
|
|
8052
8646
|
const behind = schema.version > 0 ? chatsBehind(database) : [];
|
|
8053
8647
|
const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
|
|
@@ -8135,14 +8729,18 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
|
|
|
8135
8729
|
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() {
|
|
8136
8730
|
const { renderer } = outputFor(this);
|
|
8137
8731
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8138
|
-
if (!
|
|
8732
|
+
if (!existsSync9(path)) {
|
|
8139
8733
|
result(this, { path, exists: false });
|
|
8140
8734
|
renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
|
|
8141
8735
|
return;
|
|
8142
8736
|
}
|
|
8143
8737
|
const answer = await reading(path, (database) => {
|
|
8144
8738
|
const from = schemaOf(database).version;
|
|
8145
|
-
migrate(database, {
|
|
8739
|
+
migrate(database, {
|
|
8740
|
+
command: messenger.app.command,
|
|
8741
|
+
version: messenger.app.version,
|
|
8742
|
+
rollback: { store: path, warn: /* @__PURE__ */ __name((line) => renderer.warn(line), "warn") }
|
|
8743
|
+
});
|
|
8146
8744
|
const { normalized, indexed, terms } = buildWordIndex(database, (note) => renderer.note(note));
|
|
8147
8745
|
const stemmed = buildStems(database, (note) => renderer.note(note));
|
|
8148
8746
|
const notes = buildNoteIndex(database, (note) => renderer.note(note));
|
|
@@ -8195,7 +8793,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
|
|
|
8195
8793
|
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() {
|
|
8196
8794
|
const { renderer } = outputFor(this);
|
|
8197
8795
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8198
|
-
if (!
|
|
8796
|
+
if (!existsSync9(path)) {
|
|
8199
8797
|
result(this, { path, exists: false });
|
|
8200
8798
|
return;
|
|
8201
8799
|
}
|
|
@@ -8224,11 +8822,11 @@ var reindexCommand = /* @__PURE__ */ __name((messenger) => destroysNothing(annot
|
|
|
8224
8822
|
result(this, answer);
|
|
8225
8823
|
}), "reindexCommand");
|
|
8226
8824
|
var vacuumInto = /* @__PURE__ */ __name(async (path, target) => {
|
|
8227
|
-
|
|
8825
|
+
writeFileSync2(target, "", { flag: "wx", mode: 384 });
|
|
8228
8826
|
try {
|
|
8229
8827
|
await reading(path, (database) => database.prepare("VACUUM INTO ?").run(target));
|
|
8230
8828
|
} catch (error) {
|
|
8231
|
-
|
|
8829
|
+
rmSync3(target, { force: true });
|
|
8232
8830
|
throw error;
|
|
8233
8831
|
}
|
|
8234
8832
|
}, "vacuumInto");
|
|
@@ -8237,9 +8835,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
|
|
|
8237
8835
|
const { encrypt } = this.opts();
|
|
8238
8836
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8239
8837
|
const target = resolve(file2);
|
|
8240
|
-
if (!
|
|
8838
|
+
if (!existsSync9(path))
|
|
8241
8839
|
throw new CliError("not_found", `no store at ${path} to back up`);
|
|
8242
|
-
if (
|
|
8840
|
+
if (existsSync9(target))
|
|
8243
8841
|
throw new CliError("validation_error", `${target} exists \u2014 a backup never overwrites a file`);
|
|
8244
8842
|
const password = encrypt ? await passwordOf(this, { twice: true }) : void 0;
|
|
8245
8843
|
const copyAt = password === void 0 ? target : `${path}.backup-${process.pid}`;
|
|
@@ -8261,67 +8859,69 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
|
|
|
8261
8859
|
});
|
|
8262
8860
|
} catch (error) {
|
|
8263
8861
|
if (password === void 0)
|
|
8264
|
-
|
|
8862
|
+
rmSync3(target, { force: true });
|
|
8265
8863
|
throw error;
|
|
8266
8864
|
} finally {
|
|
8267
8865
|
if (password !== void 0)
|
|
8268
|
-
|
|
8866
|
+
rmSync3(copyAt, { force: true });
|
|
8269
8867
|
}
|
|
8270
8868
|
}), "backupCommand");
|
|
8271
8869
|
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) {
|
|
8272
8870
|
const { output } = this.opts();
|
|
8273
8871
|
const from = resolve(file2);
|
|
8274
8872
|
const to = resolve(output);
|
|
8275
|
-
if (!
|
|
8873
|
+
if (!existsSync9(from))
|
|
8276
8874
|
throw new CliError("not_found", `no file at ${from}`);
|
|
8277
8875
|
if (!isSealed(from))
|
|
8278
8876
|
throw new CliError("validation_error", `${from} was not written with --encrypt`);
|
|
8279
|
-
if (
|
|
8877
|
+
if (existsSync9(to))
|
|
8280
8878
|
throw new CliError("validation_error", `${to} exists \u2014 never overwritten`);
|
|
8281
8879
|
await unsealFile(from, to, await passwordOf(this, { twice: false }));
|
|
8282
8880
|
result(this, { path: to, from, bytes: bytesOf2(to) });
|
|
8283
8881
|
}), "decryptCommand");
|
|
8284
|
-
var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup
|
|
8882
|
+
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) {
|
|
8285
8883
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
8286
8884
|
const given = resolve(file2);
|
|
8287
|
-
if (!
|
|
8885
|
+
if (!existsSync9(given))
|
|
8288
8886
|
throw new CliError("not_found", `no file at ${given}`);
|
|
8289
8887
|
refuseWhileServing(this, messenger);
|
|
8290
8888
|
if (!isSealed(given))
|
|
8291
8889
|
return restoreFrom(this, messenger, given, given);
|
|
8292
8890
|
const opened = `${path}.unsealing-${process.pid}`;
|
|
8293
|
-
mkdirSync(
|
|
8891
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
8294
8892
|
try {
|
|
8295
8893
|
await unsealFile(given, opened, await passwordOf(this, { twice: false }));
|
|
8296
8894
|
await restoreFrom(this, messenger, opened, given);
|
|
8297
8895
|
} finally {
|
|
8298
|
-
|
|
8896
|
+
rmSync3(opened, { force: true });
|
|
8299
8897
|
}
|
|
8300
8898
|
}), "restoreCommand");
|
|
8301
8899
|
var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
|
|
8302
8900
|
const { renderer } = outputFor(command);
|
|
8303
8901
|
const path = storePath(environmentOf(command).env ?? process.env);
|
|
8304
|
-
if (
|
|
8902
|
+
if (existsSync9(path) && realpathSync2(backup) === realpathSync2(path)) {
|
|
8305
8903
|
throw new CliError("validation_error", `${backup} is the store itself`);
|
|
8306
8904
|
}
|
|
8905
|
+
if (await isRollbackCopy(backup))
|
|
8906
|
+
return rollBackFrom(command, messenger, backup);
|
|
8307
8907
|
const schema = await backupSchema(backup);
|
|
8308
8908
|
const stamp = stampNow();
|
|
8309
|
-
const kept =
|
|
8909
|
+
const kept = existsSync9(path) ? `${path}.before-restore-${stamp}` : null;
|
|
8310
8910
|
if (kept) {
|
|
8311
8911
|
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
8312
8912
|
await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
|
|
8313
8913
|
} else
|
|
8314
|
-
mkdirSync(
|
|
8914
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
8315
8915
|
const incoming = `${path}.restoring-${stamp}`;
|
|
8316
8916
|
copyFileSync(backup, incoming, constants.COPYFILE_EXCL);
|
|
8317
8917
|
chmodSync(incoming, 384);
|
|
8318
8918
|
if (kept) {
|
|
8319
|
-
|
|
8919
|
+
renameSync3(path, kept);
|
|
8320
8920
|
for (const suffix of ["-wal", "-shm"])
|
|
8321
|
-
if (
|
|
8322
|
-
|
|
8921
|
+
if (existsSync9(`${path}${suffix}`))
|
|
8922
|
+
renameSync3(`${path}${suffix}`, `${kept}${suffix}`);
|
|
8323
8923
|
}
|
|
8324
|
-
|
|
8924
|
+
renameSync3(incoming, path);
|
|
8325
8925
|
result(command, { path, restoredFrom: given, keptAt: kept, schema: schema.version });
|
|
8326
8926
|
if (kept)
|
|
8327
8927
|
renderer.note(`the store it replaced is kept at ${kept}`);
|
|
@@ -8330,6 +8930,43 @@ var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, give
|
|
|
8330
8930
|
renderer.note(`the backup is behind this build; the next command migrates it \u2014 \`${lineOf(command, "store migrate")}\` now`);
|
|
8331
8931
|
}
|
|
8332
8932
|
}, "restoreFrom");
|
|
8933
|
+
var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
|
|
8934
|
+
try {
|
|
8935
|
+
return await readingOnly(file2, (database) => database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'rollback_meta'").get() !== void 0);
|
|
8936
|
+
} catch {
|
|
8937
|
+
return false;
|
|
8938
|
+
}
|
|
8939
|
+
}, "isRollbackCopy");
|
|
8940
|
+
var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
|
|
8941
|
+
const { renderer } = outputFor(command);
|
|
8942
|
+
const path = storePath(environmentOf(command).env ?? process.env);
|
|
8943
|
+
if (!existsSync9(path))
|
|
8944
|
+
throw new CliError("not_found", `no store at ${path} to roll back`);
|
|
8945
|
+
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
8946
|
+
await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
|
|
8947
|
+
const { database } = await openSqlite(path);
|
|
8948
|
+
let rolled;
|
|
8949
|
+
try {
|
|
8950
|
+
rolled = rollBack(database, copy);
|
|
8951
|
+
} finally {
|
|
8952
|
+
database.close();
|
|
8953
|
+
}
|
|
8954
|
+
result(command, {
|
|
8955
|
+
path,
|
|
8956
|
+
restoredFrom: copy,
|
|
8957
|
+
rolledBack: true,
|
|
8958
|
+
schema: rolled.from,
|
|
8959
|
+
was: rolled.was,
|
|
8960
|
+
tables: rolled.restored,
|
|
8961
|
+
rebuilt: rolled.rebuilt,
|
|
8962
|
+
foreignKeyViolations: rolled.foreignKeyViolations
|
|
8963
|
+
});
|
|
8964
|
+
const taken = new Date(rolled.createdAt).toISOString();
|
|
8965
|
+
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`);
|
|
8966
|
+
renderer.note("open it with the older tool and run its `store rebuild`: the search indexes are behind the tables");
|
|
8967
|
+
renderer.note(`a tool that speaks schema ${rolled.to} or later migrates it again on its next run`);
|
|
8968
|
+
renderer.note("restart every serve and mcp of either CLI that was running, so they read the restored store");
|
|
8969
|
+
}, "rollBackFrom");
|
|
8333
8970
|
var backupSchema = /* @__PURE__ */ __name(async (backup) => {
|
|
8334
8971
|
let read;
|
|
8335
8972
|
try {
|
|
@@ -8353,7 +8990,7 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
|
|
|
8353
8990
|
var STORE_LOCK_WAIT_MS = 1e3;
|
|
8354
8991
|
var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
|
|
8355
8992
|
const { command } = messenger.app;
|
|
8356
|
-
const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) =>
|
|
8993
|
+
const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync9(file2)).map((file2) => realpathSync2(file2));
|
|
8357
8994
|
const holders = holdersOf(files);
|
|
8358
8995
|
if (holders === void 0) {
|
|
8359
8996
|
warn(`this system cannot say which processes have the store open \u2014 restart every running serve and mcp after this`);
|
|
@@ -8379,7 +9016,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
|
|
|
8379
9016
|
const { command } = messenger.app;
|
|
8380
9017
|
const env = environmentOf(this).env ?? process.env;
|
|
8381
9018
|
const path = storePath(env);
|
|
8382
|
-
if (!
|
|
9019
|
+
if (!existsSync9(path)) {
|
|
8383
9020
|
result(this, { path, exists: false, reset: false });
|
|
8384
9021
|
renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
|
|
8385
9022
|
return;
|
|
@@ -8415,17 +9052,17 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
|
|
|
8415
9052
|
});
|
|
8416
9053
|
renderer.note(`backed the store up to ${backup}`);
|
|
8417
9054
|
}
|
|
8418
|
-
for (const suffix of
|
|
8419
|
-
|
|
9055
|
+
for (const suffix of STORE_PARTS2)
|
|
9056
|
+
rmSync3(`${path}${suffix}`, { force: true });
|
|
8420
9057
|
await (await openStore({ path, command })).close();
|
|
8421
9058
|
const schema = await reading(path, (database) => schemaOf(database).version);
|
|
8422
9059
|
result(this, { path, exists: true, reset: true, backup, backedUp, schema });
|
|
8423
9060
|
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`);
|
|
8424
9061
|
}), "resetCommand");
|
|
8425
|
-
var
|
|
9062
|
+
var STORE_PARTS2 = ["", "-wal", "-shm"];
|
|
8426
9063
|
var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
|
|
8427
|
-
const files =
|
|
8428
|
-
const holders = holdersOf(files.map((file2) =>
|
|
9064
|
+
const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync9(file2));
|
|
9065
|
+
const holders = holdersOf(files.map((file2) => realpathSync2(file2)));
|
|
8429
9066
|
const serving = servingProfiles(messenger.app, env).length > 0;
|
|
8430
9067
|
const read = await readingOnly(path, (database) => ({
|
|
8431
9068
|
schema: schemaOf(database).version,
|