From 913dcd774e8af4ea0fc2e4fe863395ed11c070f4 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Mon, 9 Mar 2026 04:58:10 -0400 Subject: [PATCH] Matrix: show account-scoped onboarding paths --- extensions/matrix/src/onboarding.test.ts | 31 ++++++++++++++++++++++ extensions/matrix/src/onboarding.ts | 12 ++++++++- src/channels/plugins/setup-wizard-types.ts | 4 +++ src/commands/onboard-channels.ts | 8 ++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/extensions/matrix/src/onboarding.test.ts b/extensions/matrix/src/onboarding.test.ts index a4ce2e55f1a..d956558c72c 100644 --- a/extensions/matrix/src/onboarding.test.ts +++ b/extensions/matrix/src/onboarding.test.ts @@ -263,4 +263,35 @@ describe("matrix onboarding", () => { expect(result.cfg.channels?.["matrix"]?.dm).toBeUndefined(); expect(result.cfg.channels?.["matrix"]?.groups).toBeUndefined(); }); + + it("reports account-scoped DM config keys for named accounts", () => { + const resolveConfigKeys = matrixOnboardingAdapter.dmPolicy?.resolveConfigKeys; + expect(resolveConfigKeys).toBeDefined(); + if (!resolveConfigKeys) { + return; + } + + expect( + resolveConfigKeys( + { + channels: { + matrix: { + accounts: { + default: { + homeserver: "https://matrix.main.example.org", + }, + ops: { + homeserver: "https://matrix.ops.example.org", + }, + }, + }, + }, + } as CoreConfig, + "ops", + ), + ).toEqual({ + policyKey: "channels.matrix.accounts.ops.dm.policy", + allowFromKey: "channels.matrix.accounts.ops.dm.allowFrom", + }); + }); }); diff --git a/extensions/matrix/src/onboarding.ts b/extensions/matrix/src/onboarding.ts index b49b3be4973..b12ce7b9972 100644 --- a/extensions/matrix/src/onboarding.ts +++ b/extensions/matrix/src/onboarding.ts @@ -26,7 +26,7 @@ import { hasReadyMatrixEnvAuth, resolveScopedMatrixEnvConfig, } from "./matrix/client.js"; -import { updateMatrixAccountConfig } from "./matrix/config-update.js"; +import { resolveMatrixConfigPath, updateMatrixAccountConfig } from "./matrix/config-update.js"; import { ensureMatrixSdkInstalled, isMatrixSdkAvailable } from "./matrix/deps.js"; import { resolveMatrixTargets } from "./resolve-targets.js"; import type { CoreConfig } from "./types.js"; @@ -177,6 +177,16 @@ const dmPolicy: ChannelSetupDmPolicy = { channel, policyKey: "channels.matrix.dm.policy", allowFromKey: "channels.matrix.dm.allowFrom", + resolveConfigKeys: (cfg, accountId) => { + const basePath = resolveMatrixConfigPath( + cfg as CoreConfig, + resolveMatrixOnboardingAccountId(cfg as CoreConfig, accountId), + ); + return { + policyKey: `${basePath}.dm.policy`, + allowFromKey: `${basePath}.dm.allowFrom`, + }; + }, getCurrent: (cfg, accountId) => resolveMatrixAccountConfig({ cfg: cfg as CoreConfig, diff --git a/src/channels/plugins/setup-wizard-types.ts b/src/channels/plugins/setup-wizard-types.ts index 47e9fa3ecb2..6c47ffc3712 100644 --- a/src/channels/plugins/setup-wizard-types.ts +++ b/src/channels/plugins/setup-wizard-types.ts @@ -81,6 +81,10 @@ export type ChannelSetupDmPolicy = { channel: ChannelId; policyKey: string; allowFromKey: string; + resolveConfigKeys?: ( + cfg: OpenClawConfig, + accountId?: string, + ) => { policyKey: string; allowFromKey: string }; getCurrent: (cfg: OpenClawConfig, accountId?: string) => DmPolicy; setPolicy: (cfg: OpenClawConfig, policy: DmPolicy, accountId?: string) => OpenClawConfig; promptAllowFrom?: (params: { diff --git a/src/commands/onboard-channels.ts b/src/commands/onboard-channels.ts index 4b0349ac391..60c89e4b374 100644 --- a/src/commands/onboard-channels.ts +++ b/src/commands/onboard-channels.ts @@ -293,12 +293,16 @@ async function maybeConfigureDmPolicies(params: { let cfg = params.cfg; const selectPolicy = async (policy: ChannelSetupDmPolicy) => { const accountId = accountIdsByChannel?.get(policy.channel); + const { policyKey, allowFromKey } = policy.resolveConfigKeys?.(cfg, accountId) ?? { + policyKey: policy.policyKey, + allowFromKey: policy.allowFromKey, + }; await prompter.note( [ "Default: pairing (unknown DMs get a pairing code).", `Approve: ${formatCliCommand(`openclaw pairing approve ${policy.channel} `)}`, - `Allowlist DMs: ${policy.policyKey}="allowlist" + ${policy.allowFromKey} entries.`, - `Public DMs: ${policy.policyKey}="open" + ${policy.allowFromKey} includes "*".`, + `Allowlist DMs: ${policyKey}="allowlist" + ${allowFromKey} entries.`, + `Public DMs: ${policyKey}="open" + ${allowFromKey} includes "*".`, "Multi-user DMs: run: " + formatCliCommand('openclaw config set session.dmScope "per-channel-peer"') + ' (or "per-account-channel-peer" for multi-account channels) to isolate sessions.',