Skip to content

Commit e1d5d3d

Browse files
authored
refactor(channels): move single-account promotion keys to plugin declarations (#112293)
* refactor(channels): move single-account promotion keys to plugin declarations * fix(channels): keep legacy promotion tier for undeclared setup adapters * fix(channels): keep plugin discovery lazy in setup promotion helpers * fix(channels): resolve bundled promotion surfaces from setup-only artifacts * test(matrix): use vi.stubEnv in setup test env helper
1 parent c1cf439 commit e1d5d3d

43 files changed

Lines changed: 866 additions & 241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ b6b8edc50ecab8386c9acd8f374a207212b5a99c8f518538bbcf0c458dda3881 module/runtime
117117
596a315d426121c9620b314e3a9a7f523840b46e007d94d0d5e83cdedf789d15 module/security-runtime
118118
31b785e74f1f8f56241b7756ef6a5d86199c5ce177cbb1c234a261866972f270 module/session-discussion
119119
9d7d884330397701c7de9f5b6800b970b2b349027491704184cb1bd6cda1fd00 module/session-store-runtime
120-
695971d31b3e16f0bf9b643acc30df312fe94b3c0dfb27a2e6156c8a00b5e261 module/setup
121-
9129c17df1523903f34beffd348ce177fcaa2983e155a8c854a50cf1bd7e99c4 module/setup-runtime
120+
5a8eb44c7fdf351aa3b4cd53db5c5233770faa8a56551a2eb3a55bd9d57c75cf module/setup
121+
81a6e5696a540578df31e432e0894c9eb3734ba1f40d7a62943c2470f25ab12f module/setup-runtime
122122
cd431f6ba8327b81438b7a63b1963120f200f5abd145fb6aa7c5c561339cb0b1 module/setup-tools
123123
18e384ec43d9eaee52c8e286e127bda2048370e2337964a754d94b236724ca9e module/skill-commands-runtime
124124
ae469f32799380e6b045abaefefee6eb3f00d714ffbf36b6eeef5025dc529472 module/speech-settings

‎docs/plugins/sdk-setup.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,18 @@ The setup patch adapters stay hot-path safe on import. Their bundled single-acco
354354

355355
When a channel upgrades from a single-account top-level config to `channels.<id>.accounts.*`, the default shared behavior moves promoted account-scoped values into `accounts.default`.
356356

357-
Bundled channels can narrow or override that promotion through their setup contract surface:
357+
Every channel plugin can extend or narrow that promotion through its setup adapter:
358358

359359
- `singleAccountKeysToMove`: extra top-level keys that should move into the promoted account
360360
- `namedAccountPromotionKeys`: when named accounts already exist, only these keys move into the promoted account; shared policy/delivery keys stay at the channel root
361361
- `resolveSingleAccountPromotionTarget(...)`: choose which existing account receives promoted values
362362

363+
The presence of `singleAccountKeysToMove` marks the promotion contract complete. Declare the field even when it is an empty array to opt out of legacy key promotion. Adapters that omit the field retain the pre-declaration promotion tiers for compatibility with already-published plugins; this compatibility tier is scheduled for removal at the next Plugin SDK major after the migration documented in [#112238](https://github.com/openclaw/openclaw/issues/112238).
364+
365+
Declare `openclaw.setupFeatures.configPromotion: true` in the plugin package manifest when doctor must load these declarations from the lightweight bundled setup artifact. The setup-only plugin surface and the full channel plugin must expose the same declarations.
366+
367+
When calling `moveSingleAccountChannelSectionToDefaultAccount(...)` with an already resolved plugin, pass its setup adapter as `setupSurface`. Caller-supplied setup surfaces take precedence over loaded and bundled lookup, which keeps scoped or setup-only plugins independent of global registration.
368+
363369
<Note>
364370
Matrix is the current bundled example. If exactly one named Matrix account already exists, or if `defaultAccount` points at an existing non-canonical key such as `Ops`, promotion preserves that account instead of creating a new `accounts.default` entry.
365371
</Note>

‎extensions/clickclack/src/setup-core.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export function applyClickClackSetupConfigPatch(params: {
157157
: moveSingleAccountChannelSectionToDefaultAccount({
158158
cfg: params.cfg,
159159
channelKey: channel,
160+
setupSurface: clickClackSetupAdapter,
160161
});
161162
const namedConfig = applyAccountNameToChannelSection({
162163
cfg: scopedConfig,

‎extensions/imessage/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"setupEntry": "./setup-entry.ts",
1818
"setupFeatures": {
19+
"configPromotion": true,
1920
"legacyStateMigrations": true
2021
},
2122
"channel": {

‎extensions/imessage/src/setup-core.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ async function promptIMessageAllowFrom(params: {
135135
channel,
136136
accountId,
137137
allowFrom,
138+
setupSurface: imessageSetupAdapter,
138139
}),
139140
});
140141
}
@@ -180,6 +181,7 @@ export const imessageDmPolicy = {
180181
),
181182
}
182183
: { dmPolicy: policy },
184+
setupSurface: imessageSetupAdapter,
183185
});
184186
},
185187
promptAllowFrom: promptIMessageAllowFrom,
@@ -222,10 +224,13 @@ export const imessageCompletionNote = {
222224
],
223225
};
224226

225-
export const imessageSetupAdapter: ChannelSetupAdapter = createPatchedAccountSetupAdapter({
226-
channelKey: channel,
227-
buildPatch: (input) => buildIMessageSetupPatch(input),
228-
});
227+
export const imessageSetupAdapter: ChannelSetupAdapter = {
228+
...createPatchedAccountSetupAdapter({
229+
channelKey: channel,
230+
buildPatch: (input) => buildIMessageSetupPatch(input),
231+
}),
232+
singleAccountKeysToMove: ["cliPath", "dbPath", "service", "region"],
233+
};
229234

230235
export const imessageSetupStatusBase = {
231236
configuredLabel: t("wizard.channels.statusConfigured"),

‎extensions/irc/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"allowInvalidConfigRecovery": true
1919
},
2020
"setupEntry": "./setup-entry.ts",
21+
"setupFeatures": {
22+
"configPromotion": true
23+
},
2124
"channel": {
2225
"id": "irc",
2326
"configuredState": {

‎extensions/irc/src/setup-core.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function setIrcGroupAccess(
111111
}
112112

113113
export const ircSetupAdapter: ChannelSetupAdapter = {
114+
singleAccountKeysToMove: ["password"],
114115
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
115116
applyAccountName: ({ cfg, accountId, name }) =>
116117
applyAccountNameToChannelSection({

‎extensions/matrix/src/channel.setup.test.ts‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,13 @@ describe("matrix setup post-write bootstrap", () => {
100100
values: Record<string, string | undefined>,
101101
run: () => Promise<T> | T,
102102
) {
103-
const previousEnv = Object.fromEntries(
104-
Object.keys(values).map((key) => [key, process.env[key]]),
105-
) as Record<string, string | undefined>;
106103
for (const [key, value] of Object.entries(values)) {
107-
if (value === undefined) {
108-
delete process.env[key];
109-
} else {
110-
process.env[key] = value;
111-
}
104+
vi.stubEnv(key, value);
112105
}
113106
try {
114107
return await run();
115108
} finally {
116-
for (const [key, value] of Object.entries(previousEnv)) {
117-
if (value === undefined) {
118-
delete process.env[key];
119-
} else {
120-
process.env[key] = value;
121-
}
122-
}
109+
vi.unstubAllEnvs();
123110
}
124111
}
125112

@@ -131,6 +118,14 @@ describe("matrix setup post-write bootstrap", () => {
131118
installMatrixTestRuntime();
132119
});
133120

121+
it("exposes config-promotion declarations on the setup-only adapter", () => {
122+
expect(matrixSetupAdapter.singleAccountKeysToMove).toEqual(
123+
expect.arrayContaining(["homeserver", "accessToken", "deviceName", "rooms"]),
124+
);
125+
expect(matrixSetupAdapter.namedAccountPromotionKeys).toContain("homeserver");
126+
expect(matrixSetupAdapter.resolveSingleAccountPromotionTarget).toBeTypeOf("function");
127+
});
128+
134129
it("bootstraps verification for newly added encrypted accounts", async () => {
135130
const { previousCfg, nextCfg, accountId, input } = applyDefaultAccountConfig();
136131
mockBootstrapResult({ success: true, backupVersion: "7" });

‎extensions/matrix/src/setup-contract.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/routing";
33

44
export const matrixSingleAccountKeysToMove = [
5+
"homeserver",
6+
"userId",
7+
"accessToken",
8+
"password",
59
"deviceId",
10+
"deviceName",
611
"avatarUrl",
712
"initialSyncLimit",
813
"encryption",

‎extensions/matrix/src/setup-core.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
import { resolveDefaultMatrixAccountId, resolveMatrixAccountConfig } from "./matrix/accounts.js";
1212
import { resolveMatrixConfigFieldPath, updateMatrixAccountConfig } from "./matrix/config-update.js";
1313
import { applyMatrixSetupAccountConfig, validateMatrixSetupInput } from "./setup-config.js";
14+
import {
15+
namedAccountPromotionKeys,
16+
resolveSingleAccountPromotionTarget,
17+
singleAccountKeysToMove,
18+
} from "./setup-contract.js";
1419
import { resolveMatrixSetupDmAllowFrom } from "./setup-dm-policy.js";
1520
import type { CoreConfig } from "./types.js";
1621

@@ -111,6 +116,9 @@ export function createMatrixSetupWizardProxy(
111116
}
112117

113118
export const matrixSetupAdapter: ChannelSetupAdapter = {
119+
singleAccountKeysToMove,
120+
namedAccountPromotionKeys,
121+
resolveSingleAccountPromotionTarget,
114122
resolveAccountId: ({ accountId, input }) =>
115123
resolveMatrixSetupAccountId({
116124
accountId,

0 commit comments

Comments
 (0)