@openclaw/matrix 2026.7.2-beta.4 → 2026.7.2-beta.5
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/README.md +1 -1
- package/dist/api.js +4 -4
- package/dist/{approval-handler.runtime-AsawryfP.js → approval-handler.runtime-D1ibJgSk.js} +4 -4
- package/dist/{approval-ids-XAMP8vN9.js → approval-ids-2OQj32-K.js} +1 -1
- package/dist/{approval-reaction-auth-DButmM13.js → approval-reaction-auth-CCAWWkbu.js} +2 -2
- package/dist/{channel-MBtrY36B.js → channel-Cmi248PA.js} +28 -32
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.runtime-Bi4Dgy2P.js → channel.runtime-BaPXFRgT.js} +34 -40
- package/dist/{cli-CcPuMyCk.js → cli-0CNHkps5.js} +863 -843
- package/dist/{cli-metadata-DAhDhbYX.js → cli-metadata-DnXxNCoj.js} +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{client-Dg8dk8NW.js → client-BFRg0kd4.js} +2 -2
- package/dist/{client-BwX6rURh.js → client-CitERujx.js} +2 -2
- package/dist/{client-bootstrap-ZAaO9fZ-.js → client-bootstrap-CkAnkzB6.js} +1 -1
- package/dist/{config-schema-CggnuwnJ.js → config-schema-BShrVROw.js} +16 -2
- package/dist/contract-api.js +2 -2
- package/dist/{create-client-Und1YmJ2.js → create-client-f-CkRllE.js} +3 -3
- package/dist/{crypto-runtime-_j7TpS7k.js → crypto-runtime-D9_6J5tZ.js} +2 -2
- package/dist/{device-health-D4LBxuPq.js → device-health-B4-YXtJR.js} +6 -1
- package/dist/{directory-live-B6fbX6jf.js → directory-live-YRgYDx2w.js} +3 -3
- package/dist/{doctor-C0LPJGTz.js → doctor-CM8ijNpW.js} +1 -1
- package/dist/{doctor-contract-CWVdlRQR.js → doctor-contract-BMSJkkAE.js} +21 -37
- package/dist/doctor-contract-api.js +4 -4
- package/dist/{draft-stream-BfibauH1.js → draft-stream-CIjafRr0.js} +1 -1
- package/dist/{file-sync-store-DUEWCEjb.js → file-sync-store-DiiFsayX.js} +1 -1
- package/dist/{http-client-DOyTG9l2.js → http-client-CycYxU9-.js} +1 -1
- package/dist/{idb-persistence-C6zQfW2w.js → idb-persistence-B6x7dMsF.js} +5 -11
- package/dist/index.js +1 -1
- package/dist/{logging-QH-48Gr6.js → logging-DV-p52N0.js} +8 -1
- package/dist/{media-text-Cv1VIHXW.js → media-text-DlQC_k_K.js} +1 -1
- package/dist/{messages-ClTgfFl6.js → messages-Bf_s--M9.js} +3 -3
- package/dist/{monitor-2BjKS9RV.js → monitor-s--XqoxF.js} +2037 -1803
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- package/dist/probe.runtime-BJOvCHnZ.js +3 -0
- package/dist/{profile-update-C2My3TML.js → profile-update-z3aM46KS.js} +2 -2
- package/dist/{reaction-events-Cj6thhmc.js → reaction-events-DrK9Zua7.js} +2 -2
- package/dist/{recovery-key-store-0O8ARdT_.js → recovery-key-store-BNnHvXdk.js} +1 -1
- package/dist/{resolve-targets-Dn11HT76.js → resolve-targets-nNMcrV3W.js} +1 -1
- package/dist/{resolver.runtime-Zguh0hH9.js → resolver.runtime-BvaFlVLg.js} +1 -1
- package/dist/{room-info-B6vKD5DF.js → room-info-CAFZ3Z9J.js} +13 -12
- package/dist/{sdk-DiRXiRRf.js → sdk-UzPd8tst.js} +227 -181
- package/dist/{send-CZCmDQu8.js → send-C9Ssx-iV.js} +623 -108
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/{setup-bootstrap-C9w01xQK.js → setup-bootstrap-BBGpPKgy.js} +2 -2
- package/dist/{setup-core-D6gyoyeg.js → setup-core-a542Ernq.js} +29 -27
- package/dist/setup-plugin-api.js +3 -3
- package/dist/{setup-surface-DZIEWtQC.js → setup-surface-BJrCI6KT.js} +32 -30
- package/dist/{shared-C7Vm9RxI.js → shared-CUH5otj8.js} +5 -12
- package/dist/{startup-verification-D1nscMh8.js → startup-verification-wm3_i88s.js} +1 -1
- package/dist/{storage-BrkTJZov.js → storage-BvAkgzvT.js} +20 -20
- package/dist/{thread-bindings-BcYBELC7.js → thread-bindings-D3RfVgAF.js} +4 -3
- package/dist/{tool-actions.runtime-Dbco_Vwn.js → tool-actions.runtime-Dh5ow2EK.js} +8 -8
- package/dist/{verification-DhMBWxOJ.js → verification-ZdAXdmuh.js} +1 -1
- package/package.json +4 -5
- package/dist/probe.runtime-BWkgfbiE.js +0 -3
- package/npm-shrinkwrap.json +0 -557
|
@@ -1,45 +1,23 @@
|
|
|
1
1
|
import { a as resolveMatrixAccountConfig } from "./account-config-BZWN9tGS.js";
|
|
2
2
|
import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
|
|
3
|
-
import { _ as resolveMatrixAccount, l as resolveMatrixConfigPath, n as matrixSetupAdapter, u as updateMatrixAccountConfig } from "./setup-core-
|
|
3
|
+
import { _ as resolveMatrixAccount, l as resolveMatrixConfigPath, n as matrixSetupAdapter, u as updateMatrixAccountConfig } from "./setup-core-a542Ernq.js";
|
|
4
4
|
import { t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
|
|
5
|
-
import { n as withResolvedActionClient } from "./client-
|
|
6
|
-
import { p as resolveMatrixAuthContext } from "./shared-
|
|
7
|
-
import "./client-
|
|
5
|
+
import { n as withResolvedActionClient } from "./client-CitERujx.js";
|
|
6
|
+
import { p as resolveMatrixAuthContext } from "./shared-CUH5otj8.js";
|
|
7
|
+
import "./client-BFRg0kd4.js";
|
|
8
8
|
import { a as formatZonedTimestamp } from "./runtime-api-D1xI_cvh.js";
|
|
9
|
-
import { isOpenClawManagedMatrixDevice, summarizeMatrixDeviceHealth } from "./device-health-D4LBxuPq.js";
|
|
10
|
-
import { n as updateMatrixOwnProfile, t as applyMatrixProfileUpdate } from "./profile-update-C2My3TML.js";
|
|
11
|
-
import { a as confirmMatrixVerificationSas, b as verifyMatrixRecoveryKey, c as getMatrixRoomKeyBackupStatus, d as listMatrixVerifications, f as mismatchMatrixVerificationSas, g as runMatrixSelfVerification, h as restoreMatrixRoomKeyBackup, l as getMatrixVerificationSas, m as resetMatrixRoomKeyBackup, n as bootstrapMatrixVerification, p as requestMatrixVerification, r as cancelMatrixVerification, t as acceptMatrixVerification, u as getMatrixVerificationStatus, v as startMatrixVerification } from "./verification-DhMBWxOJ.js";
|
|
12
9
|
import { t as resolveMatrixRoomKeyBackupIssue } from "./backup-health-Dm_YMVFT.js";
|
|
13
|
-
import {
|
|
10
|
+
import { i as setMatrixSdkLogMode, r as setMatrixSdkConsoleLogging } from "./logging-DV-p52N0.js";
|
|
11
|
+
import { n as isOpenClawManagedMatrixDevice, r as summarizeMatrixDeviceHealth } from "./device-health-B4-YXtJR.js";
|
|
12
|
+
import { n as updateMatrixOwnProfile, t as applyMatrixProfileUpdate } from "./profile-update-z3aM46KS.js";
|
|
13
|
+
import { a as confirmMatrixVerificationSas, b as verifyMatrixRecoveryKey, c as getMatrixRoomKeyBackupStatus, d as listMatrixVerifications, f as mismatchMatrixVerificationSas, g as runMatrixSelfVerification, h as restoreMatrixRoomKeyBackup, l as getMatrixVerificationSas, m as resetMatrixRoomKeyBackup, n as bootstrapMatrixVerification, p as requestMatrixVerification, r as cancelMatrixVerification, t as acceptMatrixVerification, u as getMatrixVerificationStatus, v as startMatrixVerification } from "./verification-ZdAXdmuh.js";
|
|
14
14
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
15
15
|
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
16
16
|
import { parseStrictInteger, timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
|
|
17
17
|
import { readByteStreamWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
|
|
18
|
-
//#region extensions/matrix/src/
|
|
19
|
-
async function listMatrixOwnDevices(opts = {}) {
|
|
20
|
-
return await withResolvedActionClient(opts, async (client) => await client.listOwnDevices());
|
|
21
|
-
}
|
|
22
|
-
async function pruneMatrixStaleGatewayDevices(opts = {}) {
|
|
23
|
-
return await withResolvedActionClient(opts, async (client) => {
|
|
24
|
-
const devices = await client.listOwnDevices();
|
|
25
|
-
const staleGatewayDeviceIds = summarizeMatrixDeviceHealth(devices).staleOpenClawDevices.map((device) => device.deviceId);
|
|
26
|
-
return {
|
|
27
|
-
before: devices,
|
|
28
|
-
staleGatewayDeviceIds,
|
|
29
|
-
...staleGatewayDeviceIds.length > 0 ? await client.deleteOwnDevices(staleGatewayDeviceIds) : {
|
|
30
|
-
currentDeviceId: devices.find((device) => device.current)?.deviceId ?? null,
|
|
31
|
-
deletedDeviceIds: [],
|
|
32
|
-
remainingDevices: devices
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region extensions/matrix/src/cli.ts
|
|
18
|
+
//#region extensions/matrix/src/cli-shared.ts
|
|
39
19
|
let matrixCliExitScheduled = false;
|
|
40
20
|
const MATRIX_CLI_RECOVERY_KEY_STDIN_MAX_BYTES = 1024 * 1024;
|
|
41
|
-
const loadMatrixActionClientModule = createLazyRuntimeModule(() => import("./client-BwX6rURh.js").then((n) => n.t));
|
|
42
|
-
const loadMatrixDirectManagementModule = createLazyRuntimeModule(() => import("./send-CZCmDQu8.js").then((n) => n.d));
|
|
43
21
|
function scheduleMatrixCliExit() {
|
|
44
22
|
if (matrixCliExitScheduled || process.env.VITEST) return;
|
|
45
23
|
matrixCliExitScheduled = true;
|
|
@@ -72,28 +50,18 @@ async function requireMatrixCliRecoveryKeyInput(options) {
|
|
|
72
50
|
if (!recoveryKey) throw new Error("Matrix recovery key is required. Pass --recovery-key-stdin to read it from stdin.");
|
|
73
51
|
return recoveryKey;
|
|
74
52
|
}
|
|
75
|
-
function toErrorMessage(err) {
|
|
76
|
-
return formatMatrixErrorMessage(err);
|
|
77
|
-
}
|
|
78
53
|
function printJson(payload) {
|
|
79
54
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
80
55
|
}
|
|
81
|
-
function formatLocalTimestamp(value) {
|
|
82
|
-
if (!value) return null;
|
|
83
|
-
const parsed = new Date(value);
|
|
84
|
-
if (!Number.isFinite(parsed.getTime())) return value;
|
|
85
|
-
return formatZonedTimestamp(parsed, { displaySeconds: true }) ?? value;
|
|
86
|
-
}
|
|
87
56
|
function printTimestamp(label, value) {
|
|
88
|
-
|
|
89
|
-
|
|
57
|
+
if (!value) return;
|
|
58
|
+
const parsed = new Date(value);
|
|
59
|
+
const formatted = Number.isFinite(parsed.getTime()) ? formatZonedTimestamp(parsed, { displaySeconds: true }) ?? value : value;
|
|
60
|
+
console.log(`${label}: ${formatMatrixCliText(formatted)}`);
|
|
90
61
|
}
|
|
91
62
|
function printAccountLabel(accountId) {
|
|
92
63
|
console.log(`Account: ${formatMatrixCliText(normalizeAccountId(accountId))}`);
|
|
93
64
|
}
|
|
94
|
-
function resolveMatrixCliAccountId(accountId) {
|
|
95
|
-
return resolveMatrixCliAccountContext(accountId).accountId;
|
|
96
|
-
}
|
|
97
65
|
function resolveMatrixCliAccountContext(accountId) {
|
|
98
66
|
const cfg = getMatrixRuntime().config.current();
|
|
99
67
|
return {
|
|
@@ -132,19 +100,6 @@ function formatMatrixCliShellArg(value) {
|
|
|
132
100
|
function formatMatrixCliText(value, fallback = "unknown") {
|
|
133
101
|
return sanitizeMatrixCliText(value ?? fallback);
|
|
134
102
|
}
|
|
135
|
-
function printMatrixOwnDevices(devices) {
|
|
136
|
-
if (devices.length === 0) {
|
|
137
|
-
console.log("Devices: none");
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
for (const device of devices) {
|
|
141
|
-
const labels = [device.current ? "current" : null, device.displayName].filter((label) => Boolean(label)).map((label) => formatMatrixCliText(label));
|
|
142
|
-
console.log(`- ${formatMatrixCliText(device.deviceId)}${labels.length ? ` (${labels.join(", ")})` : ""}`);
|
|
143
|
-
const lastSeenAt = timestampMsToIsoString(device.lastSeenTs);
|
|
144
|
-
if (lastSeenAt) printTimestamp(" Last seen", lastSeenAt);
|
|
145
|
-
if (device.lastSeenIp) console.log(` Last IP: ${formatMatrixCliText(device.lastSeenIp)}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
103
|
function configureCliLogMode(verbose) {
|
|
149
104
|
setMatrixSdkLogMode(verbose ? "default" : "quiet");
|
|
150
105
|
setMatrixSdkConsoleLogging(verbose);
|
|
@@ -158,209 +113,6 @@ function parseOptionalInt(value, fieldName, opts = {}) {
|
|
|
158
113
|
if (opts.min !== void 0 && parsed < opts.min) throw new Error(opts.min === 1 ? `${fieldName} must be a positive integer` : `${fieldName} must be a non-negative integer`);
|
|
159
114
|
return parsed;
|
|
160
115
|
}
|
|
161
|
-
async function addMatrixAccount(params) {
|
|
162
|
-
const initialSyncLimit = parseOptionalInt(params.initialSyncLimit, "--initial-sync-limit", { min: 0 });
|
|
163
|
-
const runtime = getMatrixRuntime();
|
|
164
|
-
const cfg = runtime.config.current();
|
|
165
|
-
if (!matrixSetupAdapter.applyAccountConfig) throw new Error("Matrix account setup is unavailable.");
|
|
166
|
-
const input = {
|
|
167
|
-
name: params.name,
|
|
168
|
-
avatarUrl: params.avatarUrl,
|
|
169
|
-
homeserver: params.homeserver,
|
|
170
|
-
dangerouslyAllowPrivateNetwork: params.allowPrivateNetwork,
|
|
171
|
-
proxy: params.proxy,
|
|
172
|
-
userId: params.userId,
|
|
173
|
-
accessToken: params.accessToken,
|
|
174
|
-
password: params.password,
|
|
175
|
-
deviceName: params.deviceName,
|
|
176
|
-
initialSyncLimit,
|
|
177
|
-
useEnv: params.useEnv === true
|
|
178
|
-
};
|
|
179
|
-
const accountId = matrixSetupAdapter.resolveAccountId?.({
|
|
180
|
-
cfg,
|
|
181
|
-
accountId: params.account,
|
|
182
|
-
input
|
|
183
|
-
}) ?? normalizeAccountId(params.account?.trim() || params.name?.trim());
|
|
184
|
-
const validationError = matrixSetupAdapter.validateInput?.({
|
|
185
|
-
cfg,
|
|
186
|
-
accountId,
|
|
187
|
-
input
|
|
188
|
-
});
|
|
189
|
-
if (validationError) throw new Error(validationError);
|
|
190
|
-
let updated = matrixSetupAdapter.applyAccountConfig({
|
|
191
|
-
cfg,
|
|
192
|
-
accountId,
|
|
193
|
-
input
|
|
194
|
-
});
|
|
195
|
-
if (params.enableEncryption === true) updated = updateMatrixAccountConfig(updated, accountId, { encryption: true });
|
|
196
|
-
await runtime.config.replaceConfigFile({
|
|
197
|
-
nextConfig: updated,
|
|
198
|
-
afterWrite: { mode: "auto" }
|
|
199
|
-
});
|
|
200
|
-
const accountConfig = resolveMatrixAccountConfig({
|
|
201
|
-
cfg: updated,
|
|
202
|
-
accountId
|
|
203
|
-
});
|
|
204
|
-
let verificationBootstrap = {
|
|
205
|
-
attempted: false,
|
|
206
|
-
success: false,
|
|
207
|
-
recoveryKeyCreatedAt: null,
|
|
208
|
-
backupVersion: null
|
|
209
|
-
};
|
|
210
|
-
if (accountConfig.encryption === true) {
|
|
211
|
-
const { maybeBootstrapNewEncryptedMatrixAccount } = await import("./setup-bootstrap-C9w01xQK.js");
|
|
212
|
-
verificationBootstrap = await maybeBootstrapNewEncryptedMatrixAccount({
|
|
213
|
-
previousCfg: cfg,
|
|
214
|
-
cfg: updated,
|
|
215
|
-
accountId
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
const desiredDisplayName = input.name?.trim();
|
|
219
|
-
const desiredAvatarUrl = input.avatarUrl?.trim();
|
|
220
|
-
let profile = {
|
|
221
|
-
attempted: false,
|
|
222
|
-
displayNameUpdated: false,
|
|
223
|
-
avatarUpdated: false,
|
|
224
|
-
resolvedAvatarUrl: null,
|
|
225
|
-
convertedAvatarFromHttp: false
|
|
226
|
-
};
|
|
227
|
-
if (desiredDisplayName || desiredAvatarUrl) try {
|
|
228
|
-
const synced = await updateMatrixOwnProfile({
|
|
229
|
-
cfg: updated,
|
|
230
|
-
accountId,
|
|
231
|
-
displayName: desiredDisplayName,
|
|
232
|
-
avatarUrl: desiredAvatarUrl
|
|
233
|
-
});
|
|
234
|
-
let resolvedAvatarUrl = synced.resolvedAvatarUrl;
|
|
235
|
-
if (synced.convertedAvatarFromHttp && synced.resolvedAvatarUrl) {
|
|
236
|
-
const withAvatar = updateMatrixAccountConfig(runtime.config.current(), accountId, { avatarUrl: synced.resolvedAvatarUrl });
|
|
237
|
-
await runtime.config.replaceConfigFile({
|
|
238
|
-
nextConfig: withAvatar,
|
|
239
|
-
afterWrite: { mode: "auto" }
|
|
240
|
-
});
|
|
241
|
-
resolvedAvatarUrl = synced.resolvedAvatarUrl;
|
|
242
|
-
}
|
|
243
|
-
profile = {
|
|
244
|
-
attempted: true,
|
|
245
|
-
displayNameUpdated: synced.displayNameUpdated,
|
|
246
|
-
avatarUpdated: synced.avatarUpdated,
|
|
247
|
-
resolvedAvatarUrl,
|
|
248
|
-
convertedAvatarFromHttp: synced.convertedAvatarFromHttp
|
|
249
|
-
};
|
|
250
|
-
} catch (err) {
|
|
251
|
-
profile = {
|
|
252
|
-
attempted: true,
|
|
253
|
-
displayNameUpdated: false,
|
|
254
|
-
avatarUpdated: false,
|
|
255
|
-
resolvedAvatarUrl: null,
|
|
256
|
-
convertedAvatarFromHttp: false,
|
|
257
|
-
error: toErrorMessage(err)
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
let deviceHealth;
|
|
261
|
-
try {
|
|
262
|
-
const addedDevices = await listMatrixOwnDevices({
|
|
263
|
-
accountId,
|
|
264
|
-
cfg: updated
|
|
265
|
-
});
|
|
266
|
-
deviceHealth = {
|
|
267
|
-
currentDeviceId: addedDevices.find((device) => device.current)?.deviceId ?? null,
|
|
268
|
-
staleOpenClawDeviceIds: addedDevices.filter((device) => !device.current && isOpenClawManagedMatrixDevice(device.displayName)).map((device) => device.deviceId)
|
|
269
|
-
};
|
|
270
|
-
} catch (err) {
|
|
271
|
-
deviceHealth = {
|
|
272
|
-
currentDeviceId: null,
|
|
273
|
-
staleOpenClawDeviceIds: [],
|
|
274
|
-
error: toErrorMessage(err)
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
return {
|
|
278
|
-
accountId,
|
|
279
|
-
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
280
|
-
useEnv: input.useEnv === true,
|
|
281
|
-
encryptionEnabled: accountConfig.encryption === true,
|
|
282
|
-
deviceHealth,
|
|
283
|
-
verificationBootstrap,
|
|
284
|
-
profile
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function printDirectRoomCandidate(room) {
|
|
288
|
-
const members = room.joinedMembers === null ? "unavailable" : room.joinedMembers.map((member) => formatMatrixCliText(member)).join(", ") || "none";
|
|
289
|
-
console.log(`- ${formatMatrixCliText(room.roomId)} [${room.source}] strict=${room.strict ? "yes" : "no"} joined=${members}`);
|
|
290
|
-
}
|
|
291
|
-
function printDirectRoomInspection(result) {
|
|
292
|
-
printAccountLabel(result.accountId);
|
|
293
|
-
console.log(`Peer: ${formatMatrixCliText(result.remoteUserId)}`);
|
|
294
|
-
console.log(`Self: ${formatMatrixCliText(result.selfUserId)}`);
|
|
295
|
-
console.log(`Active direct room: ${formatMatrixCliText(result.activeRoomId, "none")}`);
|
|
296
|
-
console.log(`Mapped rooms: ${result.mappedRoomIds.length ? result.mappedRoomIds.map((roomId) => formatMatrixCliText(roomId)).join(", ") : "none"}`);
|
|
297
|
-
console.log(`Discovered strict rooms: ${result.discoveredStrictRoomIds.length ? result.discoveredStrictRoomIds.map((roomId) => formatMatrixCliText(roomId)).join(", ") : "none"}`);
|
|
298
|
-
if (result.mappedRooms.length > 0) {
|
|
299
|
-
console.log("Mapped room details:");
|
|
300
|
-
for (const room of result.mappedRooms) printDirectRoomCandidate(room);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
async function inspectMatrixDirectRoom(params) {
|
|
304
|
-
const cfg = getMatrixRuntime().config.current();
|
|
305
|
-
const [{ withResolvedActionClient }, { inspectMatrixDirectRooms }] = await Promise.all([loadMatrixActionClientModule(), loadMatrixDirectManagementModule()]);
|
|
306
|
-
return await withResolvedActionClient({
|
|
307
|
-
accountId: params.accountId,
|
|
308
|
-
cfg
|
|
309
|
-
}, async (client) => {
|
|
310
|
-
const inspection = await inspectMatrixDirectRooms({
|
|
311
|
-
client,
|
|
312
|
-
remoteUserId: params.userId
|
|
313
|
-
});
|
|
314
|
-
return {
|
|
315
|
-
accountId: params.accountId,
|
|
316
|
-
remoteUserId: inspection.remoteUserId,
|
|
317
|
-
selfUserId: inspection.selfUserId,
|
|
318
|
-
mappedRoomIds: inspection.mappedRoomIds,
|
|
319
|
-
mappedRooms: inspection.mappedRooms.map(toCliDirectRoomCandidate),
|
|
320
|
-
discoveredStrictRoomIds: inspection.discoveredStrictRoomIds,
|
|
321
|
-
activeRoomId: inspection.activeRoomId
|
|
322
|
-
};
|
|
323
|
-
}, "persist");
|
|
324
|
-
}
|
|
325
|
-
async function repairMatrixDirectRoom(params) {
|
|
326
|
-
const cfg = getMatrixRuntime().config.current();
|
|
327
|
-
const account = resolveMatrixAccount({
|
|
328
|
-
cfg,
|
|
329
|
-
accountId: params.accountId
|
|
330
|
-
});
|
|
331
|
-
const [{ withStartedActionClient }, { repairMatrixDirectRooms }] = await Promise.all([loadMatrixActionClientModule(), loadMatrixDirectManagementModule()]);
|
|
332
|
-
return await withStartedActionClient({
|
|
333
|
-
accountId: params.accountId,
|
|
334
|
-
cfg
|
|
335
|
-
}, async (client) => {
|
|
336
|
-
const repaired = await repairMatrixDirectRooms({
|
|
337
|
-
client,
|
|
338
|
-
remoteUserId: params.userId,
|
|
339
|
-
encrypted: account.config.encryption === true
|
|
340
|
-
});
|
|
341
|
-
return {
|
|
342
|
-
accountId: params.accountId,
|
|
343
|
-
remoteUserId: repaired.remoteUserId,
|
|
344
|
-
selfUserId: repaired.selfUserId,
|
|
345
|
-
mappedRoomIds: repaired.mappedRoomIds,
|
|
346
|
-
mappedRooms: repaired.mappedRooms.map(toCliDirectRoomCandidate),
|
|
347
|
-
discoveredStrictRoomIds: repaired.discoveredStrictRoomIds,
|
|
348
|
-
activeRoomId: repaired.activeRoomId,
|
|
349
|
-
encrypted: account.config.encryption === true,
|
|
350
|
-
createdRoomId: repaired.createdRoomId,
|
|
351
|
-
changed: repaired.changed,
|
|
352
|
-
directContentBefore: repaired.directContentBefore,
|
|
353
|
-
directContentAfter: repaired.directContentAfter
|
|
354
|
-
};
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
async function setMatrixProfile(params) {
|
|
358
|
-
return await applyMatrixProfileUpdate({
|
|
359
|
-
account: params.account,
|
|
360
|
-
displayName: params.name,
|
|
361
|
-
avatarUrl: params.avatarUrl
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
116
|
async function runMatrixCliCommand(config) {
|
|
365
117
|
configureCliLogMode(config.verbose);
|
|
366
118
|
try {
|
|
@@ -369,7 +121,7 @@ async function runMatrixCliCommand(config) {
|
|
|
369
121
|
else config.onText(result, config.verbose);
|
|
370
122
|
if (config.shouldFail?.(result)) markCliFailure();
|
|
371
123
|
} catch (err) {
|
|
372
|
-
const message =
|
|
124
|
+
const message = formatMatrixErrorMessage(err);
|
|
373
125
|
if (config.json) printJson(config.onJsonError ? config.onJsonError(message) : { error: message });
|
|
374
126
|
else {
|
|
375
127
|
console.error(`${config.errorPrefix}: ${formatMatrixCliText(message)}`);
|
|
@@ -380,122 +132,6 @@ async function runMatrixCliCommand(config) {
|
|
|
380
132
|
scheduleMatrixCliExit();
|
|
381
133
|
}
|
|
382
134
|
}
|
|
383
|
-
function isMatrixVerificationSetupComplete(status) {
|
|
384
|
-
return status.encryptionEnabled && status.verified && status.crossSigningVerified && status.signedByOwner && status.serverDeviceKnown === true && resolveMatrixRoomKeyBackupIssue(resolveBackupStatus(status)).code === "ok";
|
|
385
|
-
}
|
|
386
|
-
function buildNoopMatrixVerificationBootstrap(status) {
|
|
387
|
-
return {
|
|
388
|
-
success: true,
|
|
389
|
-
verification: {
|
|
390
|
-
...status,
|
|
391
|
-
backup: resolveBackupStatus(status),
|
|
392
|
-
serverDeviceKnown: status.serverDeviceKnown ?? null
|
|
393
|
-
},
|
|
394
|
-
crossSigning: {
|
|
395
|
-
userId: status.userId,
|
|
396
|
-
masterKeyPublished: status.crossSigningVerified,
|
|
397
|
-
selfSigningKeyPublished: status.signedByOwner,
|
|
398
|
-
userSigningKeyPublished: status.signedByOwner,
|
|
399
|
-
published: status.crossSigningVerified && status.signedByOwner
|
|
400
|
-
},
|
|
401
|
-
pendingVerifications: status.pendingVerifications,
|
|
402
|
-
cryptoBootstrap: null
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
async function setupMatrixEncryption(params) {
|
|
406
|
-
const runtime = getMatrixRuntime();
|
|
407
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(params.account);
|
|
408
|
-
if (!resolveMatrixAccount({
|
|
409
|
-
cfg,
|
|
410
|
-
accountId
|
|
411
|
-
}).configured) throw new Error(`Matrix account "${accountId}" is not configured; run ${formatMatrixCliCommand("account add", accountId)} first.`);
|
|
412
|
-
const encryptionChanged = resolveMatrixAccountConfig({
|
|
413
|
-
cfg,
|
|
414
|
-
accountId
|
|
415
|
-
}).encryption !== true;
|
|
416
|
-
const updated = encryptionChanged ? updateMatrixAccountConfig(cfg, accountId, { encryption: true }) : cfg;
|
|
417
|
-
if (encryptionChanged) await runtime.config.replaceConfigFile({
|
|
418
|
-
nextConfig: updated,
|
|
419
|
-
afterWrite: { mode: "auto" }
|
|
420
|
-
});
|
|
421
|
-
const existingStatus = !encryptionChanged && !params.recoveryKey && params.forceResetCrossSigning !== true ? await getMatrixVerificationStatus({
|
|
422
|
-
accountId,
|
|
423
|
-
cfg: updated,
|
|
424
|
-
readiness: "none"
|
|
425
|
-
}) : null;
|
|
426
|
-
if (existingStatus && isMatrixVerificationSetupComplete(existingStatus)) return {
|
|
427
|
-
accountId,
|
|
428
|
-
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
429
|
-
encryptionChanged,
|
|
430
|
-
bootstrap: buildNoopMatrixVerificationBootstrap(existingStatus),
|
|
431
|
-
status: existingStatus
|
|
432
|
-
};
|
|
433
|
-
const bootstrap = await bootstrapMatrixVerification({
|
|
434
|
-
accountId,
|
|
435
|
-
cfg: updated,
|
|
436
|
-
recoveryKey: params.recoveryKey,
|
|
437
|
-
forceResetCrossSigning: params.forceResetCrossSigning === true
|
|
438
|
-
});
|
|
439
|
-
const status = await getMatrixVerificationStatus({
|
|
440
|
-
accountId,
|
|
441
|
-
cfg: updated
|
|
442
|
-
});
|
|
443
|
-
return {
|
|
444
|
-
accountId,
|
|
445
|
-
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
446
|
-
encryptionChanged,
|
|
447
|
-
bootstrap,
|
|
448
|
-
status
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
function toCliDirectRoomCandidate(room) {
|
|
452
|
-
return {
|
|
453
|
-
roomId: room.roomId,
|
|
454
|
-
source: room.source,
|
|
455
|
-
strict: room.strict,
|
|
456
|
-
joinedMembers: room.joinedMembers
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function resolveBackupStatus(status) {
|
|
460
|
-
return {
|
|
461
|
-
serverVersion: status.backup?.serverVersion ?? status.backupVersion ?? null,
|
|
462
|
-
activeVersion: status.backup?.activeVersion ?? null,
|
|
463
|
-
trusted: status.backup?.trusted ?? null,
|
|
464
|
-
matchesDecryptionKey: status.backup?.matchesDecryptionKey ?? null,
|
|
465
|
-
decryptionKeyCached: status.backup?.decryptionKeyCached ?? null,
|
|
466
|
-
keyLoadAttempted: status.backup?.keyLoadAttempted ?? false,
|
|
467
|
-
keyLoadError: status.backup?.keyLoadError ?? null
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function yesNoUnknown(value) {
|
|
471
|
-
if (value === true) return "yes";
|
|
472
|
-
if (value === false) return "no";
|
|
473
|
-
return "unknown";
|
|
474
|
-
}
|
|
475
|
-
function printBackupStatus(backup) {
|
|
476
|
-
console.log(`Backup server version: ${formatMatrixCliText(backup.serverVersion, "none")}`);
|
|
477
|
-
console.log(`Backup active on this device: ${formatMatrixCliText(backup.activeVersion, "no")}`);
|
|
478
|
-
console.log(`Backup trusted by this device: ${yesNoUnknown(backup.trusted)}`);
|
|
479
|
-
console.log(`Backup matches local decryption key: ${yesNoUnknown(backup.matchesDecryptionKey)}`);
|
|
480
|
-
console.log(`Backup key cached locally: ${yesNoUnknown(backup.decryptionKeyCached)}`);
|
|
481
|
-
console.log(`Backup key load attempted: ${yesNoUnknown(backup.keyLoadAttempted)}`);
|
|
482
|
-
if (backup.keyLoadError) console.log(`Backup key load error: ${formatMatrixCliText(backup.keyLoadError)}`);
|
|
483
|
-
}
|
|
484
|
-
function printVerificationIdentity(status) {
|
|
485
|
-
console.log(`User: ${formatMatrixCliText(status.userId)}`);
|
|
486
|
-
console.log(`Device: ${formatMatrixCliText(status.deviceId)}`);
|
|
487
|
-
}
|
|
488
|
-
function printVerificationBackupSummary(status) {
|
|
489
|
-
printBackupSummary(resolveBackupStatus(status));
|
|
490
|
-
}
|
|
491
|
-
function printVerificationBackupStatus(status) {
|
|
492
|
-
printBackupStatus(resolveBackupStatus(status));
|
|
493
|
-
}
|
|
494
|
-
function printVerificationTrustDiagnostics(status) {
|
|
495
|
-
console.log(`Locally trusted: ${status.localVerified ? "yes" : "no"}`);
|
|
496
|
-
console.log(`Cross-signing verified: ${status.crossSigningVerified ? "yes" : "no"}`);
|
|
497
|
-
console.log(`Signed by owner: ${status.signedByOwner ? "yes" : "no"}`);
|
|
498
|
-
}
|
|
499
135
|
function sanitizeMatrixCliText(value) {
|
|
500
136
|
let withoutAnsi = "";
|
|
501
137
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -566,6 +202,46 @@ function isUnsafeMatrixCliTerminalCode(code) {
|
|
|
566
202
|
function isAnsiFinalByte(code) {
|
|
567
203
|
return code >= 64 && code <= 126;
|
|
568
204
|
}
|
|
205
|
+
function resolveBackupStatus(status) {
|
|
206
|
+
return {
|
|
207
|
+
serverVersion: status.backup?.serverVersion ?? status.backupVersion ?? null,
|
|
208
|
+
activeVersion: status.backup?.activeVersion ?? null,
|
|
209
|
+
trusted: status.backup?.trusted ?? null,
|
|
210
|
+
matchesDecryptionKey: status.backup?.matchesDecryptionKey ?? null,
|
|
211
|
+
decryptionKeyCached: status.backup?.decryptionKeyCached ?? null,
|
|
212
|
+
keyLoadAttempted: status.backup?.keyLoadAttempted ?? false,
|
|
213
|
+
keyLoadError: status.backup?.keyLoadError ?? null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function yesNoUnknown(value) {
|
|
217
|
+
if (value === true) return "yes";
|
|
218
|
+
if (value === false) return "no";
|
|
219
|
+
return "unknown";
|
|
220
|
+
}
|
|
221
|
+
function printBackupStatus(backup) {
|
|
222
|
+
console.log(`Backup server version: ${formatMatrixCliText(backup.serverVersion, "none")}`);
|
|
223
|
+
console.log(`Backup active on this device: ${formatMatrixCliText(backup.activeVersion, "no")}`);
|
|
224
|
+
console.log(`Backup trusted by this device: ${yesNoUnknown(backup.trusted)}`);
|
|
225
|
+
console.log(`Backup matches local decryption key: ${yesNoUnknown(backup.matchesDecryptionKey)}`);
|
|
226
|
+
console.log(`Backup key cached locally: ${yesNoUnknown(backup.decryptionKeyCached)}`);
|
|
227
|
+
console.log(`Backup key load attempted: ${yesNoUnknown(backup.keyLoadAttempted)}`);
|
|
228
|
+
if (backup.keyLoadError) console.log(`Backup key load error: ${formatMatrixCliText(backup.keyLoadError)}`);
|
|
229
|
+
}
|
|
230
|
+
function printVerificationIdentity(status) {
|
|
231
|
+
console.log(`User: ${formatMatrixCliText(status.userId)}`);
|
|
232
|
+
console.log(`Device: ${formatMatrixCliText(status.deviceId)}`);
|
|
233
|
+
}
|
|
234
|
+
function printVerificationBackupSummary(status) {
|
|
235
|
+
printBackupSummary(resolveBackupStatus(status));
|
|
236
|
+
}
|
|
237
|
+
function printVerificationBackupStatus(status) {
|
|
238
|
+
printBackupStatus(resolveBackupStatus(status));
|
|
239
|
+
}
|
|
240
|
+
function printVerificationTrustDiagnostics(status) {
|
|
241
|
+
console.log(`Locally trusted: ${status.localVerified ? "yes" : "no"}`);
|
|
242
|
+
console.log(`Cross-signing verified: ${status.crossSigningVerified ? "yes" : "no"}`);
|
|
243
|
+
console.log(`Signed by owner: ${status.signedByOwner ? "yes" : "no"}`);
|
|
244
|
+
}
|
|
569
245
|
function formatMatrixCliSasEmoji(emoji) {
|
|
570
246
|
return emoji.map(([emojiValue, label]) => `${sanitizeMatrixCliText(emojiValue)} ${sanitizeMatrixCliText(label)}`).join(" | ");
|
|
571
247
|
}
|
|
@@ -596,11 +272,775 @@ function printMatrixVerificationSummaries(summaries) {
|
|
|
596
272
|
printMatrixVerificationSummary(summary);
|
|
597
273
|
});
|
|
598
274
|
}
|
|
599
|
-
function printMatrixVerificationSas(sas) {
|
|
600
|
-
if (sas.emoji?.length) console.log(`SAS emoji: ${formatMatrixCliSasEmoji(sas.emoji)}`);
|
|
601
|
-
else if (sas.decimal) console.log(`SAS decimals: ${sas.decimal.join(" ")}`);
|
|
602
|
-
else console.log("SAS: unavailable");
|
|
603
|
-
}
|
|
275
|
+
function printMatrixVerificationSas(sas) {
|
|
276
|
+
if (sas.emoji?.length) console.log(`SAS emoji: ${formatMatrixCliSasEmoji(sas.emoji)}`);
|
|
277
|
+
else if (sas.decimal) console.log(`SAS decimals: ${sas.decimal.join(" ")}`);
|
|
278
|
+
else console.log("SAS: unavailable");
|
|
279
|
+
}
|
|
280
|
+
function printVerificationGuidance(status, accountId) {
|
|
281
|
+
printGuidance(buildVerificationGuidance(status, accountId));
|
|
282
|
+
}
|
|
283
|
+
function printBackupGuidance(backup, accountId, options = {}) {
|
|
284
|
+
printGuidance(buildBackupGuidance(backup, accountId, options));
|
|
285
|
+
}
|
|
286
|
+
function printBackupSummary(backup) {
|
|
287
|
+
const issue = resolveMatrixRoomKeyBackupIssue(backup);
|
|
288
|
+
console.log(`Backup: ${issue.summary}`);
|
|
289
|
+
if (backup.serverVersion) console.log(`Backup version: ${formatMatrixCliText(backup.serverVersion)}`);
|
|
290
|
+
}
|
|
291
|
+
function buildVerificationGuidance(status, accountId) {
|
|
292
|
+
const backup = resolveBackupStatus(status);
|
|
293
|
+
const nextSteps = /* @__PURE__ */ new Set();
|
|
294
|
+
if (!status.verified) if (status.recoveryKeyAccepted === true && status.backupUsable === true) {
|
|
295
|
+
nextSteps.add(`Recovery key can unlock the room-key backup, but full Matrix identity trust is still incomplete. Run ${formatMatrixCliCommand("verify self", accountId)}, accept the request in another verified Matrix client, and confirm the SAS only if it matches.`);
|
|
296
|
+
nextSteps.add(`If you intend to replace the current cross-signing identity, run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify bootstrap --recovery-key-stdin --force-reset-cross-signing", accountId)}.`);
|
|
297
|
+
} else nextSteps.add(`Run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify device --recovery-key-stdin", accountId)}. If you do not have the recovery key but still have another verified Matrix client, run ${formatMatrixCliCommand("verify self", accountId)} instead.`);
|
|
298
|
+
if (status.serverDeviceKnown === false) nextSteps.add(`This Matrix device is no longer listed on the homeserver. Create a new OpenClaw Matrix device with ${formatMatrixCliCommand("account add --homeserver <url> --user-id <@user:server> --password <password> --device-name OpenClaw-Gateway", accountId)}. If you use token auth, create a fresh Matrix access token in your Matrix client or admin UI, then run ${formatMatrixCliCommand("account add --homeserver <url> --access-token <token>", accountId)}.`);
|
|
299
|
+
for (const step of buildBackupGuidance(backup, accountId, { recoveryKeyStored: status.recoveryKeyStored })) nextSteps.add(step);
|
|
300
|
+
if (status.pendingVerifications > 0) nextSteps.add(`Review pending verification requests with ${formatMatrixCliCommand("verify list", accountId)}. Complete each active request with ${formatMatrixCliCommand("verify sas <id>", accountId)} and ${formatMatrixCliCommand("verify confirm-sas <id>", accountId)}, or cancel stale requests with ${formatMatrixCliCommand("verify cancel <id>", accountId)}.`);
|
|
301
|
+
return Array.from(nextSteps);
|
|
302
|
+
}
|
|
303
|
+
function buildBackupGuidance(backup, accountId, options = {}) {
|
|
304
|
+
const backupIssue = resolveMatrixRoomKeyBackupIssue(backup);
|
|
305
|
+
const nextSteps = /* @__PURE__ */ new Set();
|
|
306
|
+
if (backupIssue.code === "missing-server-backup") nextSteps.add(`Run ${formatMatrixCliCommand("verify bootstrap", accountId)} to create a room key backup.`);
|
|
307
|
+
else if (backupIssue.code === "key-load-failed" || backupIssue.code === "key-not-loaded" || backupIssue.code === "inactive") if (options.recoveryKeyStored) nextSteps.add(`Backup key is not loaded on this device. Run ${formatMatrixCliCommand("verify backup restore", accountId)} to load it and restore old room keys. If restore still cannot load the key, run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)}.`);
|
|
308
|
+
else nextSteps.add(`Run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)} to load the server backup and store the key for future restores.`);
|
|
309
|
+
else if (backupIssue.code === "key-mismatch") {
|
|
310
|
+
nextSteps.add(`Backup key mismatch on this device. Run the shown printf pipeline with the active server backup recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)}.`);
|
|
311
|
+
nextSteps.add(`If you want a fresh backup baseline and accept losing unrecoverable history, run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}. Add --rotate-recovery-key only when the old recovery key should stop unlocking the fresh backup.`);
|
|
312
|
+
} else if (backupIssue.code === "untrusted-signature") {
|
|
313
|
+
nextSteps.add(`Backup trust chain is not verified on this device. Run the shown printf pipeline with the correct recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify device --recovery-key-stdin", accountId)}.`);
|
|
314
|
+
nextSteps.add(`If device identity trust remains incomplete after that, run ${formatMatrixCliCommand("verify self", accountId)} from another verified Matrix client.`);
|
|
315
|
+
nextSteps.add(`If you want a fresh backup baseline and accept losing unrecoverable history, run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}. Add --rotate-recovery-key only when the old recovery key should stop unlocking the fresh backup.`);
|
|
316
|
+
} else if (backupIssue.code === "indeterminate") nextSteps.add(`Run ${formatMatrixCliCommand("verify status --verbose", accountId)} to inspect backup trust diagnostics.`);
|
|
317
|
+
return Array.from(nextSteps);
|
|
318
|
+
}
|
|
319
|
+
function printGuidance(lines) {
|
|
320
|
+
if (lines.length === 0) return;
|
|
321
|
+
console.log("Next steps:");
|
|
322
|
+
for (const line of lines) console.log(`- ${line}`);
|
|
323
|
+
}
|
|
324
|
+
function printVerificationStatus(status, verbose = false, accountId) {
|
|
325
|
+
console.log(`Verified by owner: ${status.verified ? "yes" : "no"}`);
|
|
326
|
+
if (status.serverDeviceKnown === false) console.log("Device issue: current Matrix device is missing from the homeserver device list");
|
|
327
|
+
const backupIssue = resolveMatrixRoomKeyBackupIssue(resolveBackupStatus(status));
|
|
328
|
+
printVerificationBackupSummary(status);
|
|
329
|
+
if (backupIssue.message) console.log(`Backup issue: ${backupIssue.message}`);
|
|
330
|
+
if (verbose) {
|
|
331
|
+
console.log("Diagnostics:");
|
|
332
|
+
printVerificationIdentity(status);
|
|
333
|
+
if (status.serverDeviceKnown !== void 0) console.log(`Device present on server: ${yesNoUnknown(status.serverDeviceKnown ?? null)}`);
|
|
334
|
+
printVerificationTrustDiagnostics(status);
|
|
335
|
+
printVerificationBackupStatus(status);
|
|
336
|
+
console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
|
337
|
+
printTimestamp("Recovery key created at", status.recoveryKeyCreatedAt);
|
|
338
|
+
console.log(`Pending verifications: ${status.pendingVerifications}`);
|
|
339
|
+
} else console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
|
340
|
+
printVerificationGuidance(status, accountId);
|
|
341
|
+
}
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region extensions/matrix/src/matrix/actions/devices.ts
|
|
344
|
+
async function listMatrixOwnDevices(opts = {}) {
|
|
345
|
+
return await withResolvedActionClient(opts, async (client) => await client.listOwnDevices());
|
|
346
|
+
}
|
|
347
|
+
async function pruneMatrixStaleGatewayDevices(opts = {}) {
|
|
348
|
+
return await withResolvedActionClient(opts, async (client) => {
|
|
349
|
+
const devices = await client.listOwnDevices();
|
|
350
|
+
const staleGatewayDeviceIds = summarizeMatrixDeviceHealth(devices).staleOpenClawDevices.map((device) => device.deviceId);
|
|
351
|
+
return {
|
|
352
|
+
before: devices,
|
|
353
|
+
staleGatewayDeviceIds,
|
|
354
|
+
...staleGatewayDeviceIds.length > 0 ? await client.deleteOwnDevices(staleGatewayDeviceIds) : {
|
|
355
|
+
currentDeviceId: devices.find((device) => device.current)?.deviceId ?? null,
|
|
356
|
+
deletedDeviceIds: [],
|
|
357
|
+
remainingDevices: devices
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region extensions/matrix/src/cli-account.ts
|
|
364
|
+
async function addMatrixAccount(params) {
|
|
365
|
+
const initialSyncLimit = parseOptionalInt(params.initialSyncLimit, "--initial-sync-limit", { min: 0 });
|
|
366
|
+
const runtime = getMatrixRuntime();
|
|
367
|
+
const cfg = runtime.config.current();
|
|
368
|
+
if (!matrixSetupAdapter.applyAccountConfig) throw new Error("Matrix account setup is unavailable.");
|
|
369
|
+
const input = {
|
|
370
|
+
name: params.name,
|
|
371
|
+
avatarUrl: params.avatarUrl,
|
|
372
|
+
homeserver: params.homeserver,
|
|
373
|
+
dangerouslyAllowPrivateNetwork: params.allowPrivateNetwork,
|
|
374
|
+
proxy: params.proxy,
|
|
375
|
+
userId: params.userId,
|
|
376
|
+
accessToken: params.accessToken,
|
|
377
|
+
password: params.password,
|
|
378
|
+
deviceName: params.deviceName,
|
|
379
|
+
initialSyncLimit,
|
|
380
|
+
useEnv: params.useEnv === true
|
|
381
|
+
};
|
|
382
|
+
const accountId = matrixSetupAdapter.resolveAccountId?.({
|
|
383
|
+
cfg,
|
|
384
|
+
accountId: params.account,
|
|
385
|
+
input
|
|
386
|
+
}) ?? normalizeAccountId(params.account?.trim() || params.name?.trim());
|
|
387
|
+
const validationError = matrixSetupAdapter.validateInput?.({
|
|
388
|
+
cfg,
|
|
389
|
+
accountId,
|
|
390
|
+
input
|
|
391
|
+
});
|
|
392
|
+
if (validationError) throw new Error(validationError);
|
|
393
|
+
let updated = matrixSetupAdapter.applyAccountConfig({
|
|
394
|
+
cfg,
|
|
395
|
+
accountId,
|
|
396
|
+
input
|
|
397
|
+
});
|
|
398
|
+
if (params.enableEncryption === true) updated = updateMatrixAccountConfig(updated, accountId, { encryption: true });
|
|
399
|
+
await runtime.config.replaceConfigFile({
|
|
400
|
+
nextConfig: updated,
|
|
401
|
+
afterWrite: { mode: "auto" }
|
|
402
|
+
});
|
|
403
|
+
const accountConfig = resolveMatrixAccountConfig({
|
|
404
|
+
cfg: updated,
|
|
405
|
+
accountId
|
|
406
|
+
});
|
|
407
|
+
let verificationBootstrap = {
|
|
408
|
+
attempted: false,
|
|
409
|
+
success: false,
|
|
410
|
+
recoveryKeyCreatedAt: null,
|
|
411
|
+
backupVersion: null
|
|
412
|
+
};
|
|
413
|
+
if (accountConfig.encryption === true) {
|
|
414
|
+
const { maybeBootstrapNewEncryptedMatrixAccount } = await import("./setup-bootstrap-BBGpPKgy.js");
|
|
415
|
+
verificationBootstrap = await maybeBootstrapNewEncryptedMatrixAccount({
|
|
416
|
+
previousCfg: cfg,
|
|
417
|
+
cfg: updated,
|
|
418
|
+
accountId
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
const desiredDisplayName = input.name?.trim();
|
|
422
|
+
const desiredAvatarUrl = input.avatarUrl?.trim();
|
|
423
|
+
let profile = {
|
|
424
|
+
attempted: false,
|
|
425
|
+
displayNameUpdated: false,
|
|
426
|
+
avatarUpdated: false,
|
|
427
|
+
resolvedAvatarUrl: null,
|
|
428
|
+
convertedAvatarFromHttp: false
|
|
429
|
+
};
|
|
430
|
+
if (desiredDisplayName || desiredAvatarUrl) try {
|
|
431
|
+
const synced = await updateMatrixOwnProfile({
|
|
432
|
+
cfg: updated,
|
|
433
|
+
accountId,
|
|
434
|
+
displayName: desiredDisplayName,
|
|
435
|
+
avatarUrl: desiredAvatarUrl
|
|
436
|
+
});
|
|
437
|
+
let resolvedAvatarUrl = synced.resolvedAvatarUrl;
|
|
438
|
+
if (synced.convertedAvatarFromHttp && synced.resolvedAvatarUrl) {
|
|
439
|
+
const withAvatar = updateMatrixAccountConfig(runtime.config.current(), accountId, { avatarUrl: synced.resolvedAvatarUrl });
|
|
440
|
+
await runtime.config.replaceConfigFile({
|
|
441
|
+
nextConfig: withAvatar,
|
|
442
|
+
afterWrite: { mode: "auto" }
|
|
443
|
+
});
|
|
444
|
+
resolvedAvatarUrl = synced.resolvedAvatarUrl;
|
|
445
|
+
}
|
|
446
|
+
profile = {
|
|
447
|
+
attempted: true,
|
|
448
|
+
displayNameUpdated: synced.displayNameUpdated,
|
|
449
|
+
avatarUpdated: synced.avatarUpdated,
|
|
450
|
+
resolvedAvatarUrl,
|
|
451
|
+
convertedAvatarFromHttp: synced.convertedAvatarFromHttp
|
|
452
|
+
};
|
|
453
|
+
} catch (err) {
|
|
454
|
+
profile = {
|
|
455
|
+
attempted: true,
|
|
456
|
+
displayNameUpdated: false,
|
|
457
|
+
avatarUpdated: false,
|
|
458
|
+
resolvedAvatarUrl: null,
|
|
459
|
+
convertedAvatarFromHttp: false,
|
|
460
|
+
error: formatMatrixErrorMessage(err)
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
let deviceHealth;
|
|
464
|
+
try {
|
|
465
|
+
const addedDevices = await listMatrixOwnDevices({
|
|
466
|
+
accountId,
|
|
467
|
+
cfg: updated
|
|
468
|
+
});
|
|
469
|
+
deviceHealth = {
|
|
470
|
+
currentDeviceId: addedDevices.find((device) => device.current)?.deviceId ?? null,
|
|
471
|
+
staleOpenClawDeviceIds: addedDevices.filter((device) => !device.current && isOpenClawManagedMatrixDevice(device.displayName)).map((device) => device.deviceId)
|
|
472
|
+
};
|
|
473
|
+
} catch (err) {
|
|
474
|
+
deviceHealth = {
|
|
475
|
+
currentDeviceId: null,
|
|
476
|
+
staleOpenClawDeviceIds: [],
|
|
477
|
+
error: formatMatrixErrorMessage(err)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
accountId,
|
|
482
|
+
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
483
|
+
useEnv: input.useEnv === true,
|
|
484
|
+
encryptionEnabled: accountConfig.encryption === true,
|
|
485
|
+
deviceHealth,
|
|
486
|
+
verificationBootstrap,
|
|
487
|
+
profile
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function registerMatrixAccountCommands(root) {
|
|
491
|
+
root.command("account").description("Manage matrix channel accounts").command("add").description("Add or update a matrix account (wrapper around channel setup)").option("--account <id>", "Account ID (default: normalized --name, else default)").option("--name <name>", "Optional display name for this account").option("--avatar-url <url>", "Optional Matrix avatar URL (mxc:// or http(s) URL)").option("--homeserver <url>", "Matrix homeserver URL").option("--proxy <url>", "Optional HTTP(S) proxy URL for Matrix requests").option("--allow-private-network", "Allow Matrix homeserver traffic to private/internal hosts for this account").option("--user-id <id>", "Matrix user ID").option("--access-token <token>", "Matrix access token").option("--password <password>", "Matrix password").option("--device-name <name>", "Matrix device display name").option("--initial-sync-limit <n>", "Matrix initial sync limit").option("--enable-e2ee", "Enable Matrix end-to-end encryption and bootstrap verification").option("--encryption", "Alias for --enable-e2ee").option("--use-env", "Use MATRIX_* env vars (or MATRIX_<ACCOUNT_ID>_* for non-default accounts)").option("--verbose", "Show setup details").option("--json", "Output as JSON").action(async (options) => {
|
|
492
|
+
await runMatrixCliCommand({
|
|
493
|
+
verbose: options.verbose === true,
|
|
494
|
+
json: options.json === true,
|
|
495
|
+
run: async () => await addMatrixAccount({
|
|
496
|
+
account: options.account,
|
|
497
|
+
name: options.name,
|
|
498
|
+
avatarUrl: options.avatarUrl,
|
|
499
|
+
homeserver: options.homeserver,
|
|
500
|
+
proxy: options.proxy,
|
|
501
|
+
allowPrivateNetwork: options.allowPrivateNetwork === true,
|
|
502
|
+
userId: options.userId,
|
|
503
|
+
accessToken: options.accessToken,
|
|
504
|
+
password: options.password,
|
|
505
|
+
deviceName: options.deviceName,
|
|
506
|
+
initialSyncLimit: options.initialSyncLimit,
|
|
507
|
+
enableEncryption: options.enableE2ee === true || options.encryption === true,
|
|
508
|
+
useEnv: options.useEnv === true
|
|
509
|
+
}),
|
|
510
|
+
onText: (result) => {
|
|
511
|
+
console.log(`Saved matrix account: ${formatMatrixCliText(result.accountId)}`);
|
|
512
|
+
console.log(`Config path: ${formatMatrixCliText(result.configPath)}`);
|
|
513
|
+
console.log(`Credentials source: ${result.useEnv ? "MATRIX_* / MATRIX_<ACCOUNT_ID>_* env vars" : "inline config"}`);
|
|
514
|
+
console.log(`Encryption: ${result.encryptionEnabled ? "enabled" : "disabled"}`);
|
|
515
|
+
if (result.verificationBootstrap.attempted) if (result.verificationBootstrap.success) {
|
|
516
|
+
console.log("Matrix verification bootstrap: complete");
|
|
517
|
+
printTimestamp("Recovery key created at", result.verificationBootstrap.recoveryKeyCreatedAt);
|
|
518
|
+
if (result.verificationBootstrap.backupVersion) console.log(`Backup version: ${formatMatrixCliText(result.verificationBootstrap.backupVersion)}`);
|
|
519
|
+
} else console.error(`Matrix verification bootstrap warning: ${formatMatrixCliText(result.verificationBootstrap.error)}`);
|
|
520
|
+
if (result.deviceHealth.error) console.error(`Matrix device health warning: ${formatMatrixCliText(result.deviceHealth.error)}`);
|
|
521
|
+
else if (result.deviceHealth.staleOpenClawDeviceIds.length > 0) {
|
|
522
|
+
const staleDeviceIds = result.deviceHealth.staleOpenClawDeviceIds.map((deviceId) => formatMatrixCliText(deviceId)).join(", ");
|
|
523
|
+
console.log(`Matrix device hygiene warning: stale OpenClaw devices detected (${staleDeviceIds}). Run ${formatMatrixCliCommand("devices prune-stale", result.accountId)}.`);
|
|
524
|
+
}
|
|
525
|
+
if (result.profile.attempted) if (result.profile.error) console.error(`Profile sync warning: ${formatMatrixCliText(result.profile.error)}`);
|
|
526
|
+
else {
|
|
527
|
+
console.log(`Profile sync: name ${result.profile.displayNameUpdated ? "updated" : "unchanged"}, avatar ${result.profile.avatarUpdated ? "updated" : "unchanged"}`);
|
|
528
|
+
if (result.profile.convertedAvatarFromHttp && result.profile.resolvedAvatarUrl) console.log(`Avatar converted and saved as: ${formatMatrixCliText(result.profile.resolvedAvatarUrl)}`);
|
|
529
|
+
}
|
|
530
|
+
const bindHint = `openclaw agents bind --agent <id> --bind matrix:${result.accountId}`;
|
|
531
|
+
console.log(`Bind this account to an agent: ${bindHint}`);
|
|
532
|
+
},
|
|
533
|
+
errorPrefix: "Account setup failed"
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region extensions/matrix/src/cli-devices.ts
|
|
539
|
+
function printMatrixOwnDevices(devices) {
|
|
540
|
+
if (devices.length === 0) {
|
|
541
|
+
console.log("Devices: none");
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
for (const device of devices) {
|
|
545
|
+
const labels = [device.current ? "current" : null, device.displayName].filter((label) => Boolean(label)).map((label) => formatMatrixCliText(label));
|
|
546
|
+
console.log(`- ${formatMatrixCliText(device.deviceId)}${labels.length ? ` (${labels.join(", ")})` : ""}`);
|
|
547
|
+
const lastSeenAt = timestampMsToIsoString(device.lastSeenTs);
|
|
548
|
+
if (lastSeenAt) printTimestamp(" Last seen", lastSeenAt);
|
|
549
|
+
if (device.lastSeenIp) console.log(` Last IP: ${formatMatrixCliText(device.lastSeenIp)}`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function registerMatrixDeviceCommands(root) {
|
|
553
|
+
const devices = root.command("devices").description("Inspect and clean up Matrix devices");
|
|
554
|
+
devices.command("list").description("List server-side Matrix devices for this account").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
555
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
556
|
+
await runMatrixCliCommand({
|
|
557
|
+
verbose: options.verbose === true,
|
|
558
|
+
json: options.json === true,
|
|
559
|
+
run: async () => await listMatrixOwnDevices({
|
|
560
|
+
accountId,
|
|
561
|
+
cfg
|
|
562
|
+
}),
|
|
563
|
+
onText: (result) => {
|
|
564
|
+
printAccountLabel(accountId);
|
|
565
|
+
printMatrixOwnDevices(result);
|
|
566
|
+
},
|
|
567
|
+
errorPrefix: "Device listing failed"
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
devices.command("prune-stale").description("Delete stale OpenClaw-managed devices for this account").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
571
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
572
|
+
await runMatrixCliCommand({
|
|
573
|
+
verbose: options.verbose === true,
|
|
574
|
+
json: options.json === true,
|
|
575
|
+
run: async () => await pruneMatrixStaleGatewayDevices({
|
|
576
|
+
accountId,
|
|
577
|
+
cfg
|
|
578
|
+
}),
|
|
579
|
+
onText: (result, verbose) => {
|
|
580
|
+
printAccountLabel(accountId);
|
|
581
|
+
console.log(`Deleted stale OpenClaw devices: ${result.deletedDeviceIds.length ? result.deletedDeviceIds.map((deviceId) => formatMatrixCliText(deviceId)).join(", ") : "none"}`);
|
|
582
|
+
console.log(`Current device: ${formatMatrixCliText(result.currentDeviceId)}`);
|
|
583
|
+
console.log(`Remaining devices: ${result.remainingDevices.length}`);
|
|
584
|
+
if (verbose) {
|
|
585
|
+
console.log("Devices before cleanup:");
|
|
586
|
+
printMatrixOwnDevices(result.before);
|
|
587
|
+
console.log("Devices after cleanup:");
|
|
588
|
+
printMatrixOwnDevices(result.remainingDevices);
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
errorPrefix: "Device cleanup failed"
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region extensions/matrix/src/cli-direct.ts
|
|
597
|
+
const loadMatrixActionClientModule = createLazyRuntimeModule(() => import("./client-CitERujx.js").then((n) => n.t));
|
|
598
|
+
const loadMatrixDirectManagementModule = createLazyRuntimeModule(() => import("./send-C9Ssx-iV.js").then((n) => n.l));
|
|
599
|
+
function printDirectRoomCandidate(room) {
|
|
600
|
+
const members = room.joinedMembers === null ? "unavailable" : room.joinedMembers.map((member) => formatMatrixCliText(member)).join(", ") || "none";
|
|
601
|
+
console.log(`- ${formatMatrixCliText(room.roomId)} [${room.source}] strict=${room.strict ? "yes" : "no"} joined=${members}`);
|
|
602
|
+
}
|
|
603
|
+
function printDirectRoomInspection(result) {
|
|
604
|
+
printAccountLabel(result.accountId);
|
|
605
|
+
console.log(`Peer: ${formatMatrixCliText(result.remoteUserId)}`);
|
|
606
|
+
console.log(`Self: ${formatMatrixCliText(result.selfUserId)}`);
|
|
607
|
+
console.log(`Active direct room: ${formatMatrixCliText(result.activeRoomId, "none")}`);
|
|
608
|
+
console.log(`Mapped rooms: ${result.mappedRoomIds.length ? result.mappedRoomIds.map((roomId) => formatMatrixCliText(roomId)).join(", ") : "none"}`);
|
|
609
|
+
console.log(`Discovered strict rooms: ${result.discoveredStrictRoomIds.length ? result.discoveredStrictRoomIds.map((roomId) => formatMatrixCliText(roomId)).join(", ") : "none"}`);
|
|
610
|
+
if (result.mappedRooms.length > 0) {
|
|
611
|
+
console.log("Mapped room details:");
|
|
612
|
+
for (const room of result.mappedRooms) printDirectRoomCandidate(room);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
async function inspectMatrixDirectRoom(params) {
|
|
616
|
+
const cfg = getMatrixRuntime().config.current();
|
|
617
|
+
const [{ withResolvedActionClient }, { inspectMatrixDirectRooms }] = await Promise.all([loadMatrixActionClientModule(), loadMatrixDirectManagementModule()]);
|
|
618
|
+
return await withResolvedActionClient({
|
|
619
|
+
accountId: params.accountId,
|
|
620
|
+
cfg
|
|
621
|
+
}, async (client) => {
|
|
622
|
+
const inspection = await inspectMatrixDirectRooms({
|
|
623
|
+
client,
|
|
624
|
+
remoteUserId: params.userId
|
|
625
|
+
});
|
|
626
|
+
return {
|
|
627
|
+
accountId: params.accountId,
|
|
628
|
+
remoteUserId: inspection.remoteUserId,
|
|
629
|
+
selfUserId: inspection.selfUserId,
|
|
630
|
+
mappedRoomIds: inspection.mappedRoomIds,
|
|
631
|
+
mappedRooms: inspection.mappedRooms.map(toCliDirectRoomCandidate),
|
|
632
|
+
discoveredStrictRoomIds: inspection.discoveredStrictRoomIds,
|
|
633
|
+
activeRoomId: inspection.activeRoomId
|
|
634
|
+
};
|
|
635
|
+
}, "persist");
|
|
636
|
+
}
|
|
637
|
+
async function repairMatrixDirectRoom(params) {
|
|
638
|
+
const cfg = getMatrixRuntime().config.current();
|
|
639
|
+
const account = resolveMatrixAccount({
|
|
640
|
+
cfg,
|
|
641
|
+
accountId: params.accountId
|
|
642
|
+
});
|
|
643
|
+
const [{ withStartedActionClient }, { repairMatrixDirectRooms }] = await Promise.all([loadMatrixActionClientModule(), loadMatrixDirectManagementModule()]);
|
|
644
|
+
return await withStartedActionClient({
|
|
645
|
+
accountId: params.accountId,
|
|
646
|
+
cfg
|
|
647
|
+
}, async (client) => {
|
|
648
|
+
const repaired = await repairMatrixDirectRooms({
|
|
649
|
+
client,
|
|
650
|
+
remoteUserId: params.userId,
|
|
651
|
+
encrypted: account.config.encryption === true
|
|
652
|
+
});
|
|
653
|
+
return {
|
|
654
|
+
accountId: params.accountId,
|
|
655
|
+
remoteUserId: repaired.remoteUserId,
|
|
656
|
+
selfUserId: repaired.selfUserId,
|
|
657
|
+
mappedRoomIds: repaired.mappedRoomIds,
|
|
658
|
+
mappedRooms: repaired.mappedRooms.map(toCliDirectRoomCandidate),
|
|
659
|
+
discoveredStrictRoomIds: repaired.discoveredStrictRoomIds,
|
|
660
|
+
activeRoomId: repaired.activeRoomId,
|
|
661
|
+
encrypted: account.config.encryption === true,
|
|
662
|
+
createdRoomId: repaired.createdRoomId,
|
|
663
|
+
changed: repaired.changed,
|
|
664
|
+
directContentBefore: repaired.directContentBefore,
|
|
665
|
+
directContentAfter: repaired.directContentAfter
|
|
666
|
+
};
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
function toCliDirectRoomCandidate(room) {
|
|
670
|
+
return {
|
|
671
|
+
roomId: room.roomId,
|
|
672
|
+
source: room.source,
|
|
673
|
+
strict: room.strict,
|
|
674
|
+
joinedMembers: room.joinedMembers
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function registerMatrixDirectCommands(root) {
|
|
678
|
+
const direct = root.command("direct").description("Inspect and repair Matrix direct-room state");
|
|
679
|
+
direct.command("inspect").description("Inspect direct-room mappings for a Matrix user").requiredOption("--user-id <id>", "Peer Matrix user ID").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
680
|
+
const accountId = resolveMatrixCliAccountContext(options.account).accountId;
|
|
681
|
+
await runMatrixCliCommand({
|
|
682
|
+
verbose: options.verbose === true,
|
|
683
|
+
json: options.json === true,
|
|
684
|
+
run: async () => await inspectMatrixDirectRoom({
|
|
685
|
+
accountId,
|
|
686
|
+
userId: options.userId
|
|
687
|
+
}),
|
|
688
|
+
onText: (result) => {
|
|
689
|
+
printDirectRoomInspection(result);
|
|
690
|
+
},
|
|
691
|
+
errorPrefix: "Direct room inspection failed"
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
direct.command("repair").description("Repair Matrix direct-room mappings for a Matrix user").requiredOption("--user-id <id>", "Peer Matrix user ID").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
695
|
+
const accountId = resolveMatrixCliAccountContext(options.account).accountId;
|
|
696
|
+
await runMatrixCliCommand({
|
|
697
|
+
verbose: options.verbose === true,
|
|
698
|
+
json: options.json === true,
|
|
699
|
+
run: async () => await repairMatrixDirectRoom({
|
|
700
|
+
accountId,
|
|
701
|
+
userId: options.userId
|
|
702
|
+
}),
|
|
703
|
+
onText: (result, verbose) => {
|
|
704
|
+
printDirectRoomInspection(result);
|
|
705
|
+
console.log(`Encrypted room creation: ${result.encrypted ? "enabled" : "disabled"}`);
|
|
706
|
+
console.log(`Created room: ${formatMatrixCliText(result.createdRoomId, "none")}`);
|
|
707
|
+
console.log(`m.direct updated: ${result.changed ? "yes" : "no"}`);
|
|
708
|
+
if (verbose) {
|
|
709
|
+
console.log(`m.direct before: ${formatMatrixCliText(JSON.stringify(result.directContentBefore[result.remoteUserId] ?? []))}`);
|
|
710
|
+
console.log(`m.direct after: ${formatMatrixCliText(JSON.stringify(result.directContentAfter[result.remoteUserId] ?? []))}`);
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
errorPrefix: "Direct room repair failed"
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region extensions/matrix/src/cli-encryption.ts
|
|
719
|
+
function isMatrixVerificationSetupComplete(status) {
|
|
720
|
+
return status.encryptionEnabled && status.verified && status.crossSigningVerified && status.signedByOwner && status.serverDeviceKnown === true && resolveMatrixRoomKeyBackupIssue(resolveBackupStatus(status)).code === "ok";
|
|
721
|
+
}
|
|
722
|
+
function buildNoopMatrixVerificationBootstrap(status) {
|
|
723
|
+
return {
|
|
724
|
+
success: true,
|
|
725
|
+
verification: {
|
|
726
|
+
...status,
|
|
727
|
+
backup: resolveBackupStatus(status),
|
|
728
|
+
serverDeviceKnown: status.serverDeviceKnown ?? null
|
|
729
|
+
},
|
|
730
|
+
crossSigning: {
|
|
731
|
+
userId: status.userId,
|
|
732
|
+
masterKeyPublished: status.crossSigningVerified,
|
|
733
|
+
selfSigningKeyPublished: status.signedByOwner,
|
|
734
|
+
userSigningKeyPublished: status.signedByOwner,
|
|
735
|
+
published: status.crossSigningVerified && status.signedByOwner
|
|
736
|
+
},
|
|
737
|
+
pendingVerifications: status.pendingVerifications,
|
|
738
|
+
cryptoBootstrap: null
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
async function setupMatrixEncryption(params) {
|
|
742
|
+
const runtime = getMatrixRuntime();
|
|
743
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(params.account);
|
|
744
|
+
if (!resolveMatrixAccount({
|
|
745
|
+
cfg,
|
|
746
|
+
accountId
|
|
747
|
+
}).configured) throw new Error(`Matrix account "${accountId}" is not configured; run ${formatMatrixCliCommand("account add", accountId)} first.`);
|
|
748
|
+
const encryptionChanged = resolveMatrixAccountConfig({
|
|
749
|
+
cfg,
|
|
750
|
+
accountId
|
|
751
|
+
}).encryption !== true;
|
|
752
|
+
const updated = encryptionChanged ? updateMatrixAccountConfig(cfg, accountId, { encryption: true }) : cfg;
|
|
753
|
+
if (encryptionChanged) await runtime.config.replaceConfigFile({
|
|
754
|
+
nextConfig: updated,
|
|
755
|
+
afterWrite: { mode: "auto" }
|
|
756
|
+
});
|
|
757
|
+
const existingStatus = !encryptionChanged && !params.recoveryKey && params.forceResetCrossSigning !== true ? await getMatrixVerificationStatus({
|
|
758
|
+
accountId,
|
|
759
|
+
cfg: updated,
|
|
760
|
+
readiness: "none"
|
|
761
|
+
}) : null;
|
|
762
|
+
if (existingStatus && isMatrixVerificationSetupComplete(existingStatus)) return {
|
|
763
|
+
accountId,
|
|
764
|
+
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
765
|
+
encryptionChanged,
|
|
766
|
+
bootstrap: buildNoopMatrixVerificationBootstrap(existingStatus),
|
|
767
|
+
status: existingStatus
|
|
768
|
+
};
|
|
769
|
+
const bootstrap = await bootstrapMatrixVerification({
|
|
770
|
+
accountId,
|
|
771
|
+
cfg: updated,
|
|
772
|
+
recoveryKey: params.recoveryKey,
|
|
773
|
+
forceResetCrossSigning: params.forceResetCrossSigning === true
|
|
774
|
+
});
|
|
775
|
+
const status = await getMatrixVerificationStatus({
|
|
776
|
+
accountId,
|
|
777
|
+
cfg: updated
|
|
778
|
+
});
|
|
779
|
+
return {
|
|
780
|
+
accountId,
|
|
781
|
+
configPath: resolveMatrixConfigPath(updated, accountId),
|
|
782
|
+
encryptionChanged,
|
|
783
|
+
bootstrap,
|
|
784
|
+
status
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
function printMatrixEncryptionSetupResult(result, verbose = false) {
|
|
788
|
+
printAccountLabel(result.accountId);
|
|
789
|
+
console.log(`Encryption config: ${result.encryptionChanged ? "enabled" : "already enabled"} at ${formatMatrixCliText(result.configPath)}`);
|
|
790
|
+
console.log(`Bootstrap success: ${result.bootstrap.success ? "yes" : "no"}`);
|
|
791
|
+
if (result.bootstrap.error) console.log(`Bootstrap error: ${formatMatrixCliText(result.bootstrap.error)}`);
|
|
792
|
+
console.log(`Verified by owner: ${result.status.verified ? "yes" : "no"}`);
|
|
793
|
+
printVerificationBackupSummary(result.status);
|
|
794
|
+
if (verbose) {
|
|
795
|
+
printVerificationIdentity(result.status);
|
|
796
|
+
printVerificationTrustDiagnostics(result.status);
|
|
797
|
+
printVerificationBackupStatus(result.status);
|
|
798
|
+
console.log(`Recovery key stored: ${result.status.recoveryKeyStored ? "yes" : "no"}`);
|
|
799
|
+
printTimestamp("Recovery key created at", result.status.recoveryKeyCreatedAt);
|
|
800
|
+
console.log(`Pending verifications: ${result.status.pendingVerifications}`);
|
|
801
|
+
}
|
|
802
|
+
printVerificationGuidance(result.status, result.accountId);
|
|
803
|
+
}
|
|
804
|
+
function registerMatrixEncryptionCommands(root) {
|
|
805
|
+
root.command("encryption").description("Set up Matrix end-to-end encryption").command("setup").description("Enable Matrix E2EE, bootstrap verification, and print next steps").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Recovery key to apply before bootstrap (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--force-reset-cross-signing", "Force reset cross-signing identity before bootstrap (requires active recovery key)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
806
|
+
await runMatrixCliCommand({
|
|
807
|
+
verbose: options.verbose === true,
|
|
808
|
+
json: options.json === true,
|
|
809
|
+
run: async () => await setupMatrixEncryption({
|
|
810
|
+
account: options.account,
|
|
811
|
+
recoveryKey: await resolveMatrixCliRecoveryKeyInput({
|
|
812
|
+
recoveryKey: options.recoveryKey,
|
|
813
|
+
recoveryKeyStdin: options.recoveryKeyStdin
|
|
814
|
+
}),
|
|
815
|
+
forceResetCrossSigning: options.forceResetCrossSigning === true
|
|
816
|
+
}),
|
|
817
|
+
onText: (result, verbose) => {
|
|
818
|
+
printMatrixEncryptionSetupResult(result, verbose);
|
|
819
|
+
},
|
|
820
|
+
onJson: (result) => ({
|
|
821
|
+
success: result.bootstrap.success,
|
|
822
|
+
...result
|
|
823
|
+
}),
|
|
824
|
+
shouldFail: (result) => !result.bootstrap.success,
|
|
825
|
+
errorPrefix: "Encryption setup failed",
|
|
826
|
+
onJsonError: (message) => ({
|
|
827
|
+
success: false,
|
|
828
|
+
error: message
|
|
829
|
+
})
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region extensions/matrix/src/cli-profile.ts
|
|
835
|
+
function registerMatrixProfileCommands(root) {
|
|
836
|
+
root.command("profile").description("Manage Matrix bot profile").command("set").description("Update Matrix profile display name and/or avatar").option("--account <id>", "Account ID (for multi-account setups)").option("--name <name>", "Profile display name").option("--avatar-url <url>", "Profile avatar URL (mxc:// or http(s) URL)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
837
|
+
await runMatrixCliCommand({
|
|
838
|
+
verbose: options.verbose === true,
|
|
839
|
+
json: options.json === true,
|
|
840
|
+
run: async () => await applyMatrixProfileUpdate({
|
|
841
|
+
account: options.account,
|
|
842
|
+
displayName: options.name,
|
|
843
|
+
avatarUrl: options.avatarUrl
|
|
844
|
+
}),
|
|
845
|
+
onText: (result) => {
|
|
846
|
+
printAccountLabel(result.accountId);
|
|
847
|
+
console.log(`Config path: ${result.configPath}`);
|
|
848
|
+
console.log(`Profile update: name ${result.profile.displayNameUpdated ? "updated" : "unchanged"}, avatar ${result.profile.avatarUpdated ? "updated" : "unchanged"}`);
|
|
849
|
+
if (result.profile.convertedAvatarFromHttp && result.avatarUrl) console.log(`Avatar converted and saved as: ${formatMatrixCliText(result.avatarUrl)}`);
|
|
850
|
+
},
|
|
851
|
+
errorPrefix: "Profile update failed"
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
//#endregion
|
|
856
|
+
//#region extensions/matrix/src/cli-verification-backup.ts
|
|
857
|
+
function registerMatrixVerificationBackupCommands(verify) {
|
|
858
|
+
const backup = verify.command("backup").description("Matrix room-key backup health and restore");
|
|
859
|
+
backup.command("status").description("Show Matrix room-key backup status for this device").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
860
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
861
|
+
await runMatrixCliCommand({
|
|
862
|
+
verbose: options.verbose === true,
|
|
863
|
+
json: options.json === true,
|
|
864
|
+
run: async () => await getMatrixRoomKeyBackupStatus({
|
|
865
|
+
accountId,
|
|
866
|
+
cfg
|
|
867
|
+
}),
|
|
868
|
+
onText: (status, verbose) => {
|
|
869
|
+
printAccountLabel(accountId);
|
|
870
|
+
printBackupSummary(status);
|
|
871
|
+
if (verbose) printBackupStatus(status);
|
|
872
|
+
printBackupGuidance(status, accountId);
|
|
873
|
+
},
|
|
874
|
+
errorPrefix: "Backup status failed"
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
backup.command("reset").description("Delete the current server backup and create a fresh room-key backup baseline, repairing secret storage if needed for a durable reset").option("--account <id>", "Account ID (for multi-account setups)").option("--yes", "Confirm destructive backup reset", false).option("--rotate-recovery-key", "Create a new Matrix recovery key for the fresh backup").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
878
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
879
|
+
await runMatrixCliCommand({
|
|
880
|
+
verbose: options.verbose === true,
|
|
881
|
+
json: options.json === true,
|
|
882
|
+
run: async () => {
|
|
883
|
+
if (options.yes !== true) throw new Error(`Refusing to reset Matrix room-key backup without --yes. If you accept losing unrecoverable history, re-run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}.`);
|
|
884
|
+
return await resetMatrixRoomKeyBackup({
|
|
885
|
+
accountId,
|
|
886
|
+
cfg,
|
|
887
|
+
rotateRecoveryKey: options.rotateRecoveryKey === true
|
|
888
|
+
});
|
|
889
|
+
},
|
|
890
|
+
onText: (result, verbose) => {
|
|
891
|
+
printAccountLabel(accountId);
|
|
892
|
+
console.log(`Reset success: ${result.success ? "yes" : "no"}`);
|
|
893
|
+
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
894
|
+
console.log(`Previous backup version: ${formatMatrixCliText(result.previousVersion, "none")}`);
|
|
895
|
+
console.log(`Deleted backup version: ${formatMatrixCliText(result.deletedVersion, "none")}`);
|
|
896
|
+
console.log(`Current backup version: ${formatMatrixCliText(result.createdVersion, "none")}`);
|
|
897
|
+
printBackupSummary(result.backup);
|
|
898
|
+
if (verbose) {
|
|
899
|
+
printTimestamp("Reset at", result.resetAt);
|
|
900
|
+
printBackupStatus(result.backup);
|
|
901
|
+
}
|
|
902
|
+
printBackupGuidance(result.backup, accountId);
|
|
903
|
+
},
|
|
904
|
+
shouldFail: (result) => !result.success,
|
|
905
|
+
errorPrefix: "Backup reset failed",
|
|
906
|
+
onJsonError: (message) => ({
|
|
907
|
+
success: false,
|
|
908
|
+
error: message
|
|
909
|
+
})
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
backup.command("restore").description("Restore encrypted room keys from server backup").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Optional recovery key to load before restoring (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
913
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
914
|
+
await runMatrixCliCommand({
|
|
915
|
+
verbose: options.verbose === true,
|
|
916
|
+
json: options.json === true,
|
|
917
|
+
run: async () => await restoreMatrixRoomKeyBackup({
|
|
918
|
+
accountId,
|
|
919
|
+
cfg,
|
|
920
|
+
recoveryKey: await resolveMatrixCliRecoveryKeyInput(options)
|
|
921
|
+
}),
|
|
922
|
+
onText: (result, verbose) => {
|
|
923
|
+
printAccountLabel(accountId);
|
|
924
|
+
console.log(`Restore success: ${result.success ? "yes" : "no"}`);
|
|
925
|
+
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
926
|
+
console.log(`Backup version: ${formatMatrixCliText(result.backupVersion, "none")}`);
|
|
927
|
+
console.log(`Imported keys: ${result.imported}/${result.total}`);
|
|
928
|
+
printBackupSummary(result.backup);
|
|
929
|
+
if (verbose) {
|
|
930
|
+
console.log(`Loaded key from secret storage: ${result.loadedFromSecretStorage ? "yes" : "no"}`);
|
|
931
|
+
printTimestamp("Restored at", result.restoredAt);
|
|
932
|
+
printBackupStatus(result.backup);
|
|
933
|
+
}
|
|
934
|
+
printBackupGuidance(result.backup, accountId, { recoveryKeyStored: result.loadedFromSecretStorage });
|
|
935
|
+
},
|
|
936
|
+
shouldFail: (result) => !result.success,
|
|
937
|
+
errorPrefix: "Backup restore failed",
|
|
938
|
+
onJsonError: (message) => ({
|
|
939
|
+
success: false,
|
|
940
|
+
error: message
|
|
941
|
+
})
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
verify.command("bootstrap").description("Bootstrap Matrix cross-signing and device verification state").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Recovery key to apply before bootstrap (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--force-reset-cross-signing", "Force reset cross-signing identity before bootstrap (requires active recovery key)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
945
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
946
|
+
await runMatrixCliCommand({
|
|
947
|
+
verbose: options.verbose === true,
|
|
948
|
+
json: options.json === true,
|
|
949
|
+
run: async () => await bootstrapMatrixVerification({
|
|
950
|
+
accountId,
|
|
951
|
+
cfg,
|
|
952
|
+
recoveryKey: await resolveMatrixCliRecoveryKeyInput(options),
|
|
953
|
+
forceResetCrossSigning: options.forceResetCrossSigning === true
|
|
954
|
+
}),
|
|
955
|
+
onText: (result, verbose) => {
|
|
956
|
+
printAccountLabel(accountId);
|
|
957
|
+
console.log(`Bootstrap success: ${result.success ? "yes" : "no"}`);
|
|
958
|
+
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
959
|
+
console.log(`Verified by owner: ${result.verification.verified ? "yes" : "no"}`);
|
|
960
|
+
printVerificationIdentity(result.verification);
|
|
961
|
+
if (verbose) {
|
|
962
|
+
printVerificationTrustDiagnostics(result.verification);
|
|
963
|
+
console.log(`Cross-signing published: ${result.crossSigning.published ? "yes" : "no"} (master=${result.crossSigning.masterKeyPublished ? "yes" : "no"}, self=${result.crossSigning.selfSigningKeyPublished ? "yes" : "no"}, user=${result.crossSigning.userSigningKeyPublished ? "yes" : "no"})`);
|
|
964
|
+
printVerificationBackupStatus(result.verification);
|
|
965
|
+
printTimestamp("Recovery key created at", result.verification.recoveryKeyCreatedAt);
|
|
966
|
+
console.log(`Pending verifications: ${result.pendingVerifications}`);
|
|
967
|
+
} else {
|
|
968
|
+
console.log(`Cross-signing published: ${result.crossSigning.published ? "yes" : "no"}`);
|
|
969
|
+
printVerificationBackupSummary(result.verification);
|
|
970
|
+
}
|
|
971
|
+
printVerificationGuidance({
|
|
972
|
+
...result.verification,
|
|
973
|
+
pendingVerifications: result.pendingVerifications
|
|
974
|
+
}, accountId);
|
|
975
|
+
},
|
|
976
|
+
shouldFail: (result) => !result.success,
|
|
977
|
+
errorPrefix: "Verification bootstrap failed",
|
|
978
|
+
onJsonError: (message) => ({
|
|
979
|
+
success: false,
|
|
980
|
+
error: message
|
|
981
|
+
})
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
verify.command("device [key]").description("Verify device using a Matrix recovery key").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (key, options) => {
|
|
985
|
+
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
986
|
+
await runMatrixCliCommand({
|
|
987
|
+
verbose: options.verbose === true,
|
|
988
|
+
json: options.json === true,
|
|
989
|
+
run: async () => await verifyMatrixRecoveryKey(await requireMatrixCliRecoveryKeyInput({
|
|
990
|
+
recoveryKey: key,
|
|
991
|
+
recoveryKeyStdin: options.recoveryKeyStdin
|
|
992
|
+
}), {
|
|
993
|
+
accountId,
|
|
994
|
+
cfg
|
|
995
|
+
}),
|
|
996
|
+
onText: (result, verbose) => {
|
|
997
|
+
printAccountLabel(accountId);
|
|
998
|
+
if (!result.success) {
|
|
999
|
+
console.error(`Verification failed: ${formatMatrixCliText(result.error)}`);
|
|
1000
|
+
printVerificationIdentity(result);
|
|
1001
|
+
console.log(`Recovery key accepted: ${result.recoveryKeyAccepted ? "yes" : "no"}`);
|
|
1002
|
+
console.log(`Backup usable: ${result.backupUsable ? "yes" : "no"}`);
|
|
1003
|
+
console.log(`Device verified by owner: ${result.deviceOwnerVerified ? "yes" : "no"}`);
|
|
1004
|
+
printVerificationBackupSummary(result);
|
|
1005
|
+
if (verbose) {
|
|
1006
|
+
printVerificationTrustDiagnostics(result);
|
|
1007
|
+
printVerificationBackupStatus(result);
|
|
1008
|
+
printTimestamp("Recovery key created at", result.recoveryKeyCreatedAt);
|
|
1009
|
+
}
|
|
1010
|
+
printVerificationGuidance({
|
|
1011
|
+
...result,
|
|
1012
|
+
pendingVerifications: 0
|
|
1013
|
+
}, accountId);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
console.log("Device verification completed successfully.");
|
|
1017
|
+
printVerificationIdentity(result);
|
|
1018
|
+
console.log(`Recovery key accepted: ${result.recoveryKeyAccepted ? "yes" : "no"}`);
|
|
1019
|
+
console.log(`Backup usable: ${result.backupUsable ? "yes" : "no"}`);
|
|
1020
|
+
console.log(`Device verified by owner: ${result.deviceOwnerVerified ? "yes" : "no"}`);
|
|
1021
|
+
printVerificationBackupSummary(result);
|
|
1022
|
+
if (verbose) {
|
|
1023
|
+
printVerificationTrustDiagnostics(result);
|
|
1024
|
+
printVerificationBackupStatus(result);
|
|
1025
|
+
printTimestamp("Recovery key created at", result.recoveryKeyCreatedAt);
|
|
1026
|
+
printTimestamp("Verified at", result.verifiedAt);
|
|
1027
|
+
}
|
|
1028
|
+
printVerificationGuidance({
|
|
1029
|
+
...result,
|
|
1030
|
+
pendingVerifications: 0
|
|
1031
|
+
}, accountId);
|
|
1032
|
+
},
|
|
1033
|
+
shouldFail: (result) => !result.success,
|
|
1034
|
+
errorPrefix: "Verification failed",
|
|
1035
|
+
onJsonError: (message) => ({
|
|
1036
|
+
success: false,
|
|
1037
|
+
error: message
|
|
1038
|
+
})
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
//#endregion
|
|
1043
|
+
//#region extensions/matrix/src/cli-verification.ts
|
|
604
1044
|
function matrixCliVerificationDmLookupOptions(options) {
|
|
605
1045
|
const lookup = {};
|
|
606
1046
|
if (options.roomId !== void 0) lookup.verificationDmRoomId = options.roomId;
|
|
@@ -729,243 +1169,35 @@ async function runMatrixCliSelfVerificationCommand(options) {
|
|
|
729
1169
|
onRequested: (summary) => {
|
|
730
1170
|
printAccountLabel(accountId);
|
|
731
1171
|
printMatrixVerificationSummary(summary);
|
|
732
|
-
console.log("Accept this verification request in another Matrix client.");
|
|
733
|
-
},
|
|
734
|
-
onReady: (summary) => {
|
|
735
|
-
console.log("Verification request accepted.");
|
|
736
|
-
if (!summary.hasSas) console.log("Starting SAS verification...");
|
|
737
|
-
},
|
|
738
|
-
onSas: (summary) => {
|
|
739
|
-
printMatrixVerificationSas(summary.sas ?? {});
|
|
740
|
-
console.log("Compare this SAS with the other Matrix client.");
|
|
741
|
-
},
|
|
742
|
-
confirmSas: async () => await promptMatrixVerificationSasMatch()
|
|
743
|
-
});
|
|
744
|
-
},
|
|
745
|
-
onText: (summary, verbose) => {
|
|
746
|
-
printMatrixVerificationSummary(summary);
|
|
747
|
-
console.log(`Device verified by owner: ${summary.deviceOwnerVerified ? "yes" : "no"}`);
|
|
748
|
-
printVerificationTrustDiagnostics(summary.ownerVerification);
|
|
749
|
-
printVerificationBackupSummary(summary.ownerVerification);
|
|
750
|
-
if (verbose) printVerificationBackupStatus(summary.ownerVerification);
|
|
751
|
-
console.log("Self-verification complete.");
|
|
752
|
-
},
|
|
753
|
-
onTextError: () => {
|
|
754
|
-
const accountId = resolvedAccountId ?? options.account;
|
|
755
|
-
printGuidance([`Run ${formatMatrixCliCommand("verify self", accountId)} again and accept the request in another verified Matrix client for this account.`, `Then run ${formatMatrixCliCommand("verify status --verbose", accountId)} to confirm Cross-signing verified: yes and Signed by owner: yes.`]);
|
|
756
|
-
},
|
|
757
|
-
errorPrefix: "Self-verification failed"
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
function printVerificationGuidance(status, accountId) {
|
|
761
|
-
printGuidance(buildVerificationGuidance(status, accountId));
|
|
762
|
-
}
|
|
763
|
-
function printBackupGuidance(backup, accountId, options = {}) {
|
|
764
|
-
printGuidance(buildBackupGuidance(backup, accountId, options));
|
|
765
|
-
}
|
|
766
|
-
function printBackupSummary(backup) {
|
|
767
|
-
const issue = resolveMatrixRoomKeyBackupIssue(backup);
|
|
768
|
-
console.log(`Backup: ${issue.summary}`);
|
|
769
|
-
if (backup.serverVersion) console.log(`Backup version: ${formatMatrixCliText(backup.serverVersion)}`);
|
|
770
|
-
}
|
|
771
|
-
function buildVerificationGuidance(status, accountId) {
|
|
772
|
-
const backup = resolveBackupStatus(status);
|
|
773
|
-
const nextSteps = /* @__PURE__ */ new Set();
|
|
774
|
-
if (!status.verified) if (status.recoveryKeyAccepted === true && status.backupUsable === true) {
|
|
775
|
-
nextSteps.add(`Recovery key can unlock the room-key backup, but full Matrix identity trust is still incomplete. Run ${formatMatrixCliCommand("verify self", accountId)}, accept the request in another verified Matrix client, and confirm the SAS only if it matches.`);
|
|
776
|
-
nextSteps.add(`If you intend to replace the current cross-signing identity, run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify bootstrap --recovery-key-stdin --force-reset-cross-signing", accountId)}.`);
|
|
777
|
-
} else nextSteps.add(`Run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify device --recovery-key-stdin", accountId)}. If you do not have the recovery key but still have another verified Matrix client, run ${formatMatrixCliCommand("verify self", accountId)} instead.`);
|
|
778
|
-
if (status.serverDeviceKnown === false) nextSteps.add(`This Matrix device is no longer listed on the homeserver. Create a new OpenClaw Matrix device with ${formatMatrixCliCommand("account add --homeserver <url> --user-id <@user:server> --password <password> --device-name OpenClaw-Gateway", accountId)}. If you use token auth, create a fresh Matrix access token in your Matrix client or admin UI, then run ${formatMatrixCliCommand("account add --homeserver <url> --access-token <token>", accountId)}.`);
|
|
779
|
-
for (const step of buildBackupGuidance(backup, accountId, { recoveryKeyStored: status.recoveryKeyStored })) nextSteps.add(step);
|
|
780
|
-
if (status.pendingVerifications > 0) nextSteps.add(`Review pending verification requests with ${formatMatrixCliCommand("verify list", accountId)}. Complete each active request with ${formatMatrixCliCommand("verify sas <id>", accountId)} and ${formatMatrixCliCommand("verify confirm-sas <id>", accountId)}, or cancel stale requests with ${formatMatrixCliCommand("verify cancel <id>", accountId)}.`);
|
|
781
|
-
return Array.from(nextSteps);
|
|
782
|
-
}
|
|
783
|
-
function buildBackupGuidance(backup, accountId, options = {}) {
|
|
784
|
-
const backupIssue = resolveMatrixRoomKeyBackupIssue(backup);
|
|
785
|
-
const nextSteps = /* @__PURE__ */ new Set();
|
|
786
|
-
if (backupIssue.code === "missing-server-backup") nextSteps.add(`Run ${formatMatrixCliCommand("verify bootstrap", accountId)} to create a room key backup.`);
|
|
787
|
-
else if (backupIssue.code === "key-load-failed" || backupIssue.code === "key-not-loaded" || backupIssue.code === "inactive") if (options.recoveryKeyStored) nextSteps.add(`Backup key is not loaded on this device. Run ${formatMatrixCliCommand("verify backup restore", accountId)} to load it and restore old room keys. If restore still cannot load the key, run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)}.`);
|
|
788
|
-
else nextSteps.add(`Run the shown printf pipeline with the Matrix recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)} to load the server backup and store the key for future restores.`);
|
|
789
|
-
else if (backupIssue.code === "key-mismatch") {
|
|
790
|
-
nextSteps.add(`Backup key mismatch on this device. Run the shown printf pipeline with the active server backup recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify backup restore --recovery-key-stdin", accountId)}.`);
|
|
791
|
-
nextSteps.add(`If you want a fresh backup baseline and accept losing unrecoverable history, run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}. Add --rotate-recovery-key only when the old recovery key should stop unlocking the fresh backup.`);
|
|
792
|
-
} else if (backupIssue.code === "untrusted-signature") {
|
|
793
|
-
nextSteps.add(`Backup trust chain is not verified on this device. Run the shown printf pipeline with the correct recovery key env var for this account: ${formatMatrixCliRecoveryKeyStdinCommand("verify device --recovery-key-stdin", accountId)}.`);
|
|
794
|
-
nextSteps.add(`If device identity trust remains incomplete after that, run ${formatMatrixCliCommand("verify self", accountId)} from another verified Matrix client.`);
|
|
795
|
-
nextSteps.add(`If you want a fresh backup baseline and accept losing unrecoverable history, run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}. Add --rotate-recovery-key only when the old recovery key should stop unlocking the fresh backup.`);
|
|
796
|
-
} else if (backupIssue.code === "indeterminate") nextSteps.add(`Run ${formatMatrixCliCommand("verify status --verbose", accountId)} to inspect backup trust diagnostics.`);
|
|
797
|
-
return Array.from(nextSteps);
|
|
798
|
-
}
|
|
799
|
-
function printGuidance(lines) {
|
|
800
|
-
if (lines.length === 0) return;
|
|
801
|
-
console.log("Next steps:");
|
|
802
|
-
for (const line of lines) console.log(`- ${line}`);
|
|
803
|
-
}
|
|
804
|
-
function printVerificationStatus(status, verbose = false, accountId) {
|
|
805
|
-
console.log(`Verified by owner: ${status.verified ? "yes" : "no"}`);
|
|
806
|
-
if (status.serverDeviceKnown === false) console.log("Device issue: current Matrix device is missing from the homeserver device list");
|
|
807
|
-
const backupIssue = resolveMatrixRoomKeyBackupIssue(resolveBackupStatus(status));
|
|
808
|
-
printVerificationBackupSummary(status);
|
|
809
|
-
if (backupIssue.message) console.log(`Backup issue: ${backupIssue.message}`);
|
|
810
|
-
if (verbose) {
|
|
811
|
-
console.log("Diagnostics:");
|
|
812
|
-
printVerificationIdentity(status);
|
|
813
|
-
if (status.serverDeviceKnown !== void 0) console.log(`Device present on server: ${yesNoUnknown(status.serverDeviceKnown ?? null)}`);
|
|
814
|
-
printVerificationTrustDiagnostics(status);
|
|
815
|
-
printVerificationBackupStatus(status);
|
|
816
|
-
console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
|
817
|
-
printTimestamp("Recovery key created at", status.recoveryKeyCreatedAt);
|
|
818
|
-
console.log(`Pending verifications: ${status.pendingVerifications}`);
|
|
819
|
-
} else console.log(`Recovery key stored: ${status.recoveryKeyStored ? "yes" : "no"}`);
|
|
820
|
-
printVerificationGuidance(status, accountId);
|
|
821
|
-
}
|
|
822
|
-
function printMatrixEncryptionSetupResult(result, verbose = false) {
|
|
823
|
-
printAccountLabel(result.accountId);
|
|
824
|
-
console.log(`Encryption config: ${result.encryptionChanged ? "enabled" : "already enabled"} at ${formatMatrixCliText(result.configPath)}`);
|
|
825
|
-
console.log(`Bootstrap success: ${result.bootstrap.success ? "yes" : "no"}`);
|
|
826
|
-
if (result.bootstrap.error) console.log(`Bootstrap error: ${formatMatrixCliText(result.bootstrap.error)}`);
|
|
827
|
-
console.log(`Verified by owner: ${result.status.verified ? "yes" : "no"}`);
|
|
828
|
-
printVerificationBackupSummary(result.status);
|
|
829
|
-
if (verbose) {
|
|
830
|
-
printVerificationIdentity(result.status);
|
|
831
|
-
printVerificationTrustDiagnostics(result.status);
|
|
832
|
-
printVerificationBackupStatus(result.status);
|
|
833
|
-
console.log(`Recovery key stored: ${result.status.recoveryKeyStored ? "yes" : "no"}`);
|
|
834
|
-
printTimestamp("Recovery key created at", result.status.recoveryKeyCreatedAt);
|
|
835
|
-
console.log(`Pending verifications: ${result.status.pendingVerifications}`);
|
|
836
|
-
}
|
|
837
|
-
printVerificationGuidance(result.status, result.accountId);
|
|
838
|
-
}
|
|
839
|
-
function registerMatrixCli(params) {
|
|
840
|
-
const root = params.program.command("matrix").description("Matrix channel utilities").addHelpText("after", () => "\nDocs: https://docs.openclaw.ai/channels/matrix\n");
|
|
841
|
-
root.command("account").description("Manage matrix channel accounts").command("add").description("Add or update a matrix account (wrapper around channel setup)").option("--account <id>", "Account ID (default: normalized --name, else default)").option("--name <name>", "Optional display name for this account").option("--avatar-url <url>", "Optional Matrix avatar URL (mxc:// or http(s) URL)").option("--homeserver <url>", "Matrix homeserver URL").option("--proxy <url>", "Optional HTTP(S) proxy URL for Matrix requests").option("--allow-private-network", "Allow Matrix homeserver traffic to private/internal hosts for this account").option("--user-id <id>", "Matrix user ID").option("--access-token <token>", "Matrix access token").option("--password <password>", "Matrix password").option("--device-name <name>", "Matrix device display name").option("--initial-sync-limit <n>", "Matrix initial sync limit").option("--enable-e2ee", "Enable Matrix end-to-end encryption and bootstrap verification").option("--encryption", "Alias for --enable-e2ee").option("--use-env", "Use MATRIX_* env vars (or MATRIX_<ACCOUNT_ID>_* for non-default accounts)").option("--verbose", "Show setup details").option("--json", "Output as JSON").action(async (options) => {
|
|
842
|
-
await runMatrixCliCommand({
|
|
843
|
-
verbose: options.verbose === true,
|
|
844
|
-
json: options.json === true,
|
|
845
|
-
run: async () => await addMatrixAccount({
|
|
846
|
-
account: options.account,
|
|
847
|
-
name: options.name,
|
|
848
|
-
avatarUrl: options.avatarUrl,
|
|
849
|
-
homeserver: options.homeserver,
|
|
850
|
-
proxy: options.proxy,
|
|
851
|
-
allowPrivateNetwork: options.allowPrivateNetwork === true,
|
|
852
|
-
userId: options.userId,
|
|
853
|
-
accessToken: options.accessToken,
|
|
854
|
-
password: options.password,
|
|
855
|
-
deviceName: options.deviceName,
|
|
856
|
-
initialSyncLimit: options.initialSyncLimit,
|
|
857
|
-
enableEncryption: options.enableE2ee === true || options.encryption === true,
|
|
858
|
-
useEnv: options.useEnv === true
|
|
859
|
-
}),
|
|
860
|
-
onText: (result) => {
|
|
861
|
-
console.log(`Saved matrix account: ${formatMatrixCliText(result.accountId)}`);
|
|
862
|
-
console.log(`Config path: ${formatMatrixCliText(result.configPath)}`);
|
|
863
|
-
console.log(`Credentials source: ${result.useEnv ? "MATRIX_* / MATRIX_<ACCOUNT_ID>_* env vars" : "inline config"}`);
|
|
864
|
-
console.log(`Encryption: ${result.encryptionEnabled ? "enabled" : "disabled"}`);
|
|
865
|
-
if (result.verificationBootstrap.attempted) if (result.verificationBootstrap.success) {
|
|
866
|
-
console.log("Matrix verification bootstrap: complete");
|
|
867
|
-
printTimestamp("Recovery key created at", result.verificationBootstrap.recoveryKeyCreatedAt);
|
|
868
|
-
if (result.verificationBootstrap.backupVersion) console.log(`Backup version: ${formatMatrixCliText(result.verificationBootstrap.backupVersion)}`);
|
|
869
|
-
} else console.error(`Matrix verification bootstrap warning: ${formatMatrixCliText(result.verificationBootstrap.error)}`);
|
|
870
|
-
if (result.deviceHealth.error) console.error(`Matrix device health warning: ${formatMatrixCliText(result.deviceHealth.error)}`);
|
|
871
|
-
else if (result.deviceHealth.staleOpenClawDeviceIds.length > 0) {
|
|
872
|
-
const staleDeviceIds = result.deviceHealth.staleOpenClawDeviceIds.map((deviceId) => formatMatrixCliText(deviceId)).join(", ");
|
|
873
|
-
console.log(`Matrix device hygiene warning: stale OpenClaw devices detected (${staleDeviceIds}). Run ${formatMatrixCliCommand("devices prune-stale", result.accountId)}.`);
|
|
874
|
-
}
|
|
875
|
-
if (result.profile.attempted) if (result.profile.error) console.error(`Profile sync warning: ${formatMatrixCliText(result.profile.error)}`);
|
|
876
|
-
else {
|
|
877
|
-
console.log(`Profile sync: name ${result.profile.displayNameUpdated ? "updated" : "unchanged"}, avatar ${result.profile.avatarUpdated ? "updated" : "unchanged"}`);
|
|
878
|
-
if (result.profile.convertedAvatarFromHttp && result.profile.resolvedAvatarUrl) console.log(`Avatar converted and saved as: ${formatMatrixCliText(result.profile.resolvedAvatarUrl)}`);
|
|
879
|
-
}
|
|
880
|
-
const bindHint = `openclaw agents bind --agent <id> --bind matrix:${result.accountId}`;
|
|
881
|
-
console.log(`Bind this account to an agent: ${bindHint}`);
|
|
882
|
-
},
|
|
883
|
-
errorPrefix: "Account setup failed"
|
|
884
|
-
});
|
|
885
|
-
});
|
|
886
|
-
root.command("profile").description("Manage Matrix bot profile").command("set").description("Update Matrix profile display name and/or avatar").option("--account <id>", "Account ID (for multi-account setups)").option("--name <name>", "Profile display name").option("--avatar-url <url>", "Profile avatar URL (mxc:// or http(s) URL)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
887
|
-
await runMatrixCliCommand({
|
|
888
|
-
verbose: options.verbose === true,
|
|
889
|
-
json: options.json === true,
|
|
890
|
-
run: async () => await setMatrixProfile({
|
|
891
|
-
account: options.account,
|
|
892
|
-
name: options.name,
|
|
893
|
-
avatarUrl: options.avatarUrl
|
|
894
|
-
}),
|
|
895
|
-
onText: (result) => {
|
|
896
|
-
printAccountLabel(result.accountId);
|
|
897
|
-
console.log(`Config path: ${result.configPath}`);
|
|
898
|
-
console.log(`Profile update: name ${result.profile.displayNameUpdated ? "updated" : "unchanged"}, avatar ${result.profile.avatarUpdated ? "updated" : "unchanged"}`);
|
|
899
|
-
if (result.profile.convertedAvatarFromHttp && result.avatarUrl) console.log(`Avatar converted and saved as: ${formatMatrixCliText(result.avatarUrl)}`);
|
|
900
|
-
},
|
|
901
|
-
errorPrefix: "Profile update failed"
|
|
902
|
-
});
|
|
903
|
-
});
|
|
904
|
-
const direct = root.command("direct").description("Inspect and repair Matrix direct-room state");
|
|
905
|
-
direct.command("inspect").description("Inspect direct-room mappings for a Matrix user").requiredOption("--user-id <id>", "Peer Matrix user ID").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
906
|
-
const accountId = resolveMatrixCliAccountId(options.account);
|
|
907
|
-
await runMatrixCliCommand({
|
|
908
|
-
verbose: options.verbose === true,
|
|
909
|
-
json: options.json === true,
|
|
910
|
-
run: async () => await inspectMatrixDirectRoom({
|
|
911
|
-
accountId,
|
|
912
|
-
userId: options.userId
|
|
913
|
-
}),
|
|
914
|
-
onText: (result) => {
|
|
915
|
-
printDirectRoomInspection(result);
|
|
916
|
-
},
|
|
917
|
-
errorPrefix: "Direct room inspection failed"
|
|
918
|
-
});
|
|
919
|
-
});
|
|
920
|
-
direct.command("repair").description("Repair Matrix direct-room mappings for a Matrix user").requiredOption("--user-id <id>", "Peer Matrix user ID").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
921
|
-
const accountId = resolveMatrixCliAccountId(options.account);
|
|
922
|
-
await runMatrixCliCommand({
|
|
923
|
-
verbose: options.verbose === true,
|
|
924
|
-
json: options.json === true,
|
|
925
|
-
run: async () => await repairMatrixDirectRoom({
|
|
926
|
-
accountId,
|
|
927
|
-
userId: options.userId
|
|
928
|
-
}),
|
|
929
|
-
onText: (result, verbose) => {
|
|
930
|
-
printDirectRoomInspection(result);
|
|
931
|
-
console.log(`Encrypted room creation: ${result.encrypted ? "enabled" : "disabled"}`);
|
|
932
|
-
console.log(`Created room: ${formatMatrixCliText(result.createdRoomId, "none")}`);
|
|
933
|
-
console.log(`m.direct updated: ${result.changed ? "yes" : "no"}`);
|
|
934
|
-
if (verbose) {
|
|
935
|
-
console.log(`m.direct before: ${formatMatrixCliText(JSON.stringify(result.directContentBefore[result.remoteUserId] ?? []))}`);
|
|
936
|
-
console.log(`m.direct after: ${formatMatrixCliText(JSON.stringify(result.directContentAfter[result.remoteUserId] ?? []))}`);
|
|
937
|
-
}
|
|
938
|
-
},
|
|
939
|
-
errorPrefix: "Direct room repair failed"
|
|
940
|
-
});
|
|
941
|
-
});
|
|
942
|
-
root.command("encryption").description("Set up Matrix end-to-end encryption").command("setup").description("Enable Matrix E2EE, bootstrap verification, and print next steps").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Recovery key to apply before bootstrap (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--force-reset-cross-signing", "Force reset cross-signing identity before bootstrap (requires active recovery key)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
943
|
-
await runMatrixCliCommand({
|
|
944
|
-
verbose: options.verbose === true,
|
|
945
|
-
json: options.json === true,
|
|
946
|
-
run: async () => await setupMatrixEncryption({
|
|
947
|
-
account: options.account,
|
|
948
|
-
recoveryKey: await resolveMatrixCliRecoveryKeyInput({
|
|
949
|
-
recoveryKey: options.recoveryKey,
|
|
950
|
-
recoveryKeyStdin: options.recoveryKeyStdin
|
|
951
|
-
}),
|
|
952
|
-
forceResetCrossSigning: options.forceResetCrossSigning === true
|
|
953
|
-
}),
|
|
954
|
-
onText: (result, verbose) => {
|
|
955
|
-
printMatrixEncryptionSetupResult(result, verbose);
|
|
956
|
-
},
|
|
957
|
-
onJson: (result) => ({
|
|
958
|
-
success: result.bootstrap.success,
|
|
959
|
-
...result
|
|
960
|
-
}),
|
|
961
|
-
shouldFail: (result) => !result.bootstrap.success,
|
|
962
|
-
errorPrefix: "Encryption setup failed",
|
|
963
|
-
onJsonError: (message) => ({
|
|
964
|
-
success: false,
|
|
965
|
-
error: message
|
|
966
|
-
})
|
|
967
|
-
});
|
|
1172
|
+
console.log("Accept this verification request in another Matrix client.");
|
|
1173
|
+
},
|
|
1174
|
+
onReady: (summary) => {
|
|
1175
|
+
console.log("Verification request accepted.");
|
|
1176
|
+
if (!summary.hasSas) console.log("Starting SAS verification...");
|
|
1177
|
+
},
|
|
1178
|
+
onSas: (summary) => {
|
|
1179
|
+
printMatrixVerificationSas(summary.sas ?? {});
|
|
1180
|
+
console.log("Compare this SAS with the other Matrix client.");
|
|
1181
|
+
},
|
|
1182
|
+
confirmSas: async () => await promptMatrixVerificationSasMatch()
|
|
1183
|
+
});
|
|
1184
|
+
},
|
|
1185
|
+
onText: (summary, verbose) => {
|
|
1186
|
+
printMatrixVerificationSummary(summary);
|
|
1187
|
+
console.log(`Device verified by owner: ${summary.deviceOwnerVerified ? "yes" : "no"}`);
|
|
1188
|
+
printVerificationTrustDiagnostics(summary.ownerVerification);
|
|
1189
|
+
printVerificationBackupSummary(summary.ownerVerification);
|
|
1190
|
+
if (verbose) printVerificationBackupStatus(summary.ownerVerification);
|
|
1191
|
+
console.log("Self-verification complete.");
|
|
1192
|
+
},
|
|
1193
|
+
onTextError: () => {
|
|
1194
|
+
const accountId = resolvedAccountId ?? options.account;
|
|
1195
|
+
printGuidance([`Run ${formatMatrixCliCommand("verify self", accountId)} again and accept the request in another verified Matrix client for this account.`, `Then run ${formatMatrixCliCommand("verify status --verbose", accountId)} to confirm Cross-signing verified: yes and Signed by owner: yes.`]);
|
|
1196
|
+
},
|
|
1197
|
+
errorPrefix: "Self-verification failed"
|
|
968
1198
|
});
|
|
1199
|
+
}
|
|
1200
|
+
function registerMatrixVerificationCommands(root) {
|
|
969
1201
|
const verify = root.command("verify").description("Device verification for Matrix E2EE");
|
|
970
1202
|
verify.command("list").description("List pending Matrix verification requests").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
971
1203
|
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
@@ -1116,230 +1348,18 @@ function registerMatrixCli(params) {
|
|
|
1116
1348
|
errorPrefix: "Error"
|
|
1117
1349
|
});
|
|
1118
1350
|
});
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
printBackupSummary(status);
|
|
1132
|
-
if (verbose) printBackupStatus(status);
|
|
1133
|
-
printBackupGuidance(status, accountId);
|
|
1134
|
-
},
|
|
1135
|
-
errorPrefix: "Backup status failed"
|
|
1136
|
-
});
|
|
1137
|
-
});
|
|
1138
|
-
backup.command("reset").description("Delete the current server backup and create a fresh room-key backup baseline, repairing secret storage if needed for a durable reset").option("--account <id>", "Account ID (for multi-account setups)").option("--yes", "Confirm destructive backup reset", false).option("--rotate-recovery-key", "Create a new Matrix recovery key for the fresh backup").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
1139
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1140
|
-
await runMatrixCliCommand({
|
|
1141
|
-
verbose: options.verbose === true,
|
|
1142
|
-
json: options.json === true,
|
|
1143
|
-
run: async () => {
|
|
1144
|
-
if (options.yes !== true) throw new Error(`Refusing to reset Matrix room-key backup without --yes. If you accept losing unrecoverable history, re-run ${formatMatrixCliCommand("verify backup reset --yes", accountId)}.`);
|
|
1145
|
-
return await resetMatrixRoomKeyBackup({
|
|
1146
|
-
accountId,
|
|
1147
|
-
cfg,
|
|
1148
|
-
rotateRecoveryKey: options.rotateRecoveryKey === true
|
|
1149
|
-
});
|
|
1150
|
-
},
|
|
1151
|
-
onText: (result, verbose) => {
|
|
1152
|
-
printAccountLabel(accountId);
|
|
1153
|
-
console.log(`Reset success: ${result.success ? "yes" : "no"}`);
|
|
1154
|
-
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
1155
|
-
console.log(`Previous backup version: ${formatMatrixCliText(result.previousVersion, "none")}`);
|
|
1156
|
-
console.log(`Deleted backup version: ${formatMatrixCliText(result.deletedVersion, "none")}`);
|
|
1157
|
-
console.log(`Current backup version: ${formatMatrixCliText(result.createdVersion, "none")}`);
|
|
1158
|
-
printBackupSummary(result.backup);
|
|
1159
|
-
if (verbose) {
|
|
1160
|
-
printTimestamp("Reset at", result.resetAt);
|
|
1161
|
-
printBackupStatus(result.backup);
|
|
1162
|
-
}
|
|
1163
|
-
printBackupGuidance(result.backup, accountId);
|
|
1164
|
-
},
|
|
1165
|
-
shouldFail: (result) => !result.success,
|
|
1166
|
-
errorPrefix: "Backup reset failed",
|
|
1167
|
-
onJsonError: (message) => ({
|
|
1168
|
-
success: false,
|
|
1169
|
-
error: message
|
|
1170
|
-
})
|
|
1171
|
-
});
|
|
1172
|
-
});
|
|
1173
|
-
backup.command("restore").description("Restore encrypted room keys from server backup").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Optional recovery key to load before restoring (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
1174
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1175
|
-
await runMatrixCliCommand({
|
|
1176
|
-
verbose: options.verbose === true,
|
|
1177
|
-
json: options.json === true,
|
|
1178
|
-
run: async () => await restoreMatrixRoomKeyBackup({
|
|
1179
|
-
accountId,
|
|
1180
|
-
cfg,
|
|
1181
|
-
recoveryKey: await resolveMatrixCliRecoveryKeyInput(options)
|
|
1182
|
-
}),
|
|
1183
|
-
onText: (result, verbose) => {
|
|
1184
|
-
printAccountLabel(accountId);
|
|
1185
|
-
console.log(`Restore success: ${result.success ? "yes" : "no"}`);
|
|
1186
|
-
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
1187
|
-
console.log(`Backup version: ${formatMatrixCliText(result.backupVersion, "none")}`);
|
|
1188
|
-
console.log(`Imported keys: ${result.imported}/${result.total}`);
|
|
1189
|
-
printBackupSummary(result.backup);
|
|
1190
|
-
if (verbose) {
|
|
1191
|
-
console.log(`Loaded key from secret storage: ${result.loadedFromSecretStorage ? "yes" : "no"}`);
|
|
1192
|
-
printTimestamp("Restored at", result.restoredAt);
|
|
1193
|
-
printBackupStatus(result.backup);
|
|
1194
|
-
}
|
|
1195
|
-
printBackupGuidance(result.backup, accountId, { recoveryKeyStored: result.loadedFromSecretStorage });
|
|
1196
|
-
},
|
|
1197
|
-
shouldFail: (result) => !result.success,
|
|
1198
|
-
errorPrefix: "Backup restore failed",
|
|
1199
|
-
onJsonError: (message) => ({
|
|
1200
|
-
success: false,
|
|
1201
|
-
error: message
|
|
1202
|
-
})
|
|
1203
|
-
});
|
|
1204
|
-
});
|
|
1205
|
-
verify.command("bootstrap").description("Bootstrap Matrix cross-signing and device verification state").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key <key>", "Recovery key to apply before bootstrap (prefer --recovery-key-stdin)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--force-reset-cross-signing", "Force reset cross-signing identity before bootstrap (requires active recovery key)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
1206
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1207
|
-
await runMatrixCliCommand({
|
|
1208
|
-
verbose: options.verbose === true,
|
|
1209
|
-
json: options.json === true,
|
|
1210
|
-
run: async () => await bootstrapMatrixVerification({
|
|
1211
|
-
accountId,
|
|
1212
|
-
cfg,
|
|
1213
|
-
recoveryKey: await resolveMatrixCliRecoveryKeyInput(options),
|
|
1214
|
-
forceResetCrossSigning: options.forceResetCrossSigning === true
|
|
1215
|
-
}),
|
|
1216
|
-
onText: (result, verbose) => {
|
|
1217
|
-
printAccountLabel(accountId);
|
|
1218
|
-
console.log(`Bootstrap success: ${result.success ? "yes" : "no"}`);
|
|
1219
|
-
if (result.error) console.log(`Error: ${formatMatrixCliText(result.error)}`);
|
|
1220
|
-
console.log(`Verified by owner: ${result.verification.verified ? "yes" : "no"}`);
|
|
1221
|
-
printVerificationIdentity(result.verification);
|
|
1222
|
-
if (verbose) {
|
|
1223
|
-
printVerificationTrustDiagnostics(result.verification);
|
|
1224
|
-
console.log(`Cross-signing published: ${result.crossSigning.published ? "yes" : "no"} (master=${result.crossSigning.masterKeyPublished ? "yes" : "no"}, self=${result.crossSigning.selfSigningKeyPublished ? "yes" : "no"}, user=${result.crossSigning.userSigningKeyPublished ? "yes" : "no"})`);
|
|
1225
|
-
printVerificationBackupStatus(result.verification);
|
|
1226
|
-
printTimestamp("Recovery key created at", result.verification.recoveryKeyCreatedAt);
|
|
1227
|
-
console.log(`Pending verifications: ${result.pendingVerifications}`);
|
|
1228
|
-
} else {
|
|
1229
|
-
console.log(`Cross-signing published: ${result.crossSigning.published ? "yes" : "no"}`);
|
|
1230
|
-
printVerificationBackupSummary(result.verification);
|
|
1231
|
-
}
|
|
1232
|
-
printVerificationGuidance({
|
|
1233
|
-
...result.verification,
|
|
1234
|
-
pendingVerifications: result.pendingVerifications
|
|
1235
|
-
}, accountId);
|
|
1236
|
-
},
|
|
1237
|
-
shouldFail: (result) => !result.success,
|
|
1238
|
-
errorPrefix: "Verification bootstrap failed",
|
|
1239
|
-
onJsonError: (message) => ({
|
|
1240
|
-
success: false,
|
|
1241
|
-
error: message
|
|
1242
|
-
})
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
verify.command("device [key]").description("Verify device using a Matrix recovery key").option("--account <id>", "Account ID (for multi-account setups)").option("--recovery-key-stdin", "Read the Matrix recovery key from stdin").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (key, options) => {
|
|
1246
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1247
|
-
await runMatrixCliCommand({
|
|
1248
|
-
verbose: options.verbose === true,
|
|
1249
|
-
json: options.json === true,
|
|
1250
|
-
run: async () => await verifyMatrixRecoveryKey(await requireMatrixCliRecoveryKeyInput({
|
|
1251
|
-
recoveryKey: key,
|
|
1252
|
-
recoveryKeyStdin: options.recoveryKeyStdin
|
|
1253
|
-
}), {
|
|
1254
|
-
accountId,
|
|
1255
|
-
cfg
|
|
1256
|
-
}),
|
|
1257
|
-
onText: (result, verbose) => {
|
|
1258
|
-
printAccountLabel(accountId);
|
|
1259
|
-
if (!result.success) {
|
|
1260
|
-
console.error(`Verification failed: ${formatMatrixCliText(result.error)}`);
|
|
1261
|
-
printVerificationIdentity(result);
|
|
1262
|
-
console.log(`Recovery key accepted: ${result.recoveryKeyAccepted ? "yes" : "no"}`);
|
|
1263
|
-
console.log(`Backup usable: ${result.backupUsable ? "yes" : "no"}`);
|
|
1264
|
-
console.log(`Device verified by owner: ${result.deviceOwnerVerified ? "yes" : "no"}`);
|
|
1265
|
-
printVerificationBackupSummary(result);
|
|
1266
|
-
if (verbose) {
|
|
1267
|
-
printVerificationTrustDiagnostics(result);
|
|
1268
|
-
printVerificationBackupStatus(result);
|
|
1269
|
-
printTimestamp("Recovery key created at", result.recoveryKeyCreatedAt);
|
|
1270
|
-
}
|
|
1271
|
-
printVerificationGuidance({
|
|
1272
|
-
...result,
|
|
1273
|
-
pendingVerifications: 0
|
|
1274
|
-
}, accountId);
|
|
1275
|
-
return;
|
|
1276
|
-
}
|
|
1277
|
-
console.log("Device verification completed successfully.");
|
|
1278
|
-
printVerificationIdentity(result);
|
|
1279
|
-
console.log(`Recovery key accepted: ${result.recoveryKeyAccepted ? "yes" : "no"}`);
|
|
1280
|
-
console.log(`Backup usable: ${result.backupUsable ? "yes" : "no"}`);
|
|
1281
|
-
console.log(`Device verified by owner: ${result.deviceOwnerVerified ? "yes" : "no"}`);
|
|
1282
|
-
printVerificationBackupSummary(result);
|
|
1283
|
-
if (verbose) {
|
|
1284
|
-
printVerificationTrustDiagnostics(result);
|
|
1285
|
-
printVerificationBackupStatus(result);
|
|
1286
|
-
printTimestamp("Recovery key created at", result.recoveryKeyCreatedAt);
|
|
1287
|
-
printTimestamp("Verified at", result.verifiedAt);
|
|
1288
|
-
}
|
|
1289
|
-
printVerificationGuidance({
|
|
1290
|
-
...result,
|
|
1291
|
-
pendingVerifications: 0
|
|
1292
|
-
}, accountId);
|
|
1293
|
-
},
|
|
1294
|
-
shouldFail: (result) => !result.success,
|
|
1295
|
-
errorPrefix: "Verification failed",
|
|
1296
|
-
onJsonError: (message) => ({
|
|
1297
|
-
success: false,
|
|
1298
|
-
error: message
|
|
1299
|
-
})
|
|
1300
|
-
});
|
|
1301
|
-
});
|
|
1302
|
-
const devices = root.command("devices").description("Inspect and clean up Matrix devices");
|
|
1303
|
-
devices.command("list").description("List server-side Matrix devices for this account").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
1304
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1305
|
-
await runMatrixCliCommand({
|
|
1306
|
-
verbose: options.verbose === true,
|
|
1307
|
-
json: options.json === true,
|
|
1308
|
-
run: async () => await listMatrixOwnDevices({
|
|
1309
|
-
accountId,
|
|
1310
|
-
cfg
|
|
1311
|
-
}),
|
|
1312
|
-
onText: (result) => {
|
|
1313
|
-
printAccountLabel(accountId);
|
|
1314
|
-
printMatrixOwnDevices(result);
|
|
1315
|
-
},
|
|
1316
|
-
errorPrefix: "Device listing failed"
|
|
1317
|
-
});
|
|
1318
|
-
});
|
|
1319
|
-
devices.command("prune-stale").description("Delete stale OpenClaw-managed devices for this account").option("--account <id>", "Account ID (for multi-account setups)").option("--verbose", "Show detailed diagnostics").option("--json", "Output as JSON").action(async (options) => {
|
|
1320
|
-
const { accountId, cfg } = resolveMatrixCliAccountContext(options.account);
|
|
1321
|
-
await runMatrixCliCommand({
|
|
1322
|
-
verbose: options.verbose === true,
|
|
1323
|
-
json: options.json === true,
|
|
1324
|
-
run: async () => await pruneMatrixStaleGatewayDevices({
|
|
1325
|
-
accountId,
|
|
1326
|
-
cfg
|
|
1327
|
-
}),
|
|
1328
|
-
onText: (result, verbose) => {
|
|
1329
|
-
printAccountLabel(accountId);
|
|
1330
|
-
console.log(`Deleted stale OpenClaw devices: ${result.deletedDeviceIds.length ? result.deletedDeviceIds.map((deviceId) => formatMatrixCliText(deviceId)).join(", ") : "none"}`);
|
|
1331
|
-
console.log(`Current device: ${formatMatrixCliText(result.currentDeviceId)}`);
|
|
1332
|
-
console.log(`Remaining devices: ${result.remainingDevices.length}`);
|
|
1333
|
-
if (verbose) {
|
|
1334
|
-
console.log("Devices before cleanup:");
|
|
1335
|
-
printMatrixOwnDevices(result.before);
|
|
1336
|
-
console.log("Devices after cleanup:");
|
|
1337
|
-
printMatrixOwnDevices(result.remainingDevices);
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
errorPrefix: "Device cleanup failed"
|
|
1341
|
-
});
|
|
1342
|
-
});
|
|
1351
|
+
registerMatrixVerificationBackupCommands(verify);
|
|
1352
|
+
}
|
|
1353
|
+
//#endregion
|
|
1354
|
+
//#region extensions/matrix/src/cli.ts
|
|
1355
|
+
function registerMatrixCli(params) {
|
|
1356
|
+
const root = params.program.command("matrix").description("Matrix channel utilities").addHelpText("after", () => "\nDocs: https://docs.openclaw.ai/channels/matrix\n");
|
|
1357
|
+
registerMatrixAccountCommands(root);
|
|
1358
|
+
registerMatrixProfileCommands(root);
|
|
1359
|
+
registerMatrixDirectCommands(root);
|
|
1360
|
+
registerMatrixEncryptionCommands(root);
|
|
1361
|
+
registerMatrixVerificationCommands(root);
|
|
1362
|
+
registerMatrixDeviceCommands(root);
|
|
1343
1363
|
}
|
|
1344
1364
|
//#endregion
|
|
1345
1365
|
export { registerMatrixCli };
|