Skip to content

Commit eef23d9

Browse files
committed
fix(plugins): retain channel capabilities during discovery
1 parent 84e0890 commit eef23d9

9 files changed

Lines changed: 111 additions & 26 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ ad60ccc4fe9084d47f0477e02d9296bacad32f26d7456e2a84be8d25a53a25c2 module/boolean
2525
16dc9d32e8ca3ef78fc63e0fc4b20e6b943633e9572de1a49d24a880b6ffc66c module/channel-config-primitives
2626
c0f910ebfa3dbf283145fb1e3b9c016d03e853ef13e70402b09f3b9d9c2f4ab0 module/channel-config-schema
2727
2dd98659d9600e755f09ef00dd91c36692b8562ed3700461937e94f6cd1e640a module/channel-contract
28-
23fba2ab304d27b33fb8923e542741a03dd93b5b60cffc0337d89c46090ace95 module/channel-core
28+
6e7bb72d2fe65cd2541af6c057dba4faa5079f410f34e08fcb5348ab38e7a666 module/channel-core
2929
9a5aaf650f9242523bb57bdc2556c323ab64e55aa11e25e2685b73b23ee12534 module/channel-dm-policy
30-
fbf353eb38ae68d8ded3f2a60b432c7bb2c245d2ec7e7c9f53c6da19a0db0938 module/channel-entry-contract
30+
ba41c40956d6b4565605fa38c2d12f4b8471a0f8afe842798716b9032ee4d74a module/channel-entry-contract
3131
982f29a18e07228e3da82cae67d06ff38249592a29c2fd28f01f0d2016ff80d9 module/channel-feedback
3232
d645d24bcb7a5f68cc46c692ad0d1fbd19be0a99996f31e9479ce9cffce301c1 module/channel-inbound
3333
76bb7f531f3702c801e8fe7479e9e499f601fb361a4303afdcb45fc0da440e4b module/channel-inbound-debounce
@@ -58,7 +58,7 @@ eb4c757fe0086c1dbfa4c3f3caf3dcff0d3cab3924c608237f08f740a6ee5f59 module/command
5858
20f3f8042de53e4eee61b64de9102c8c202b9299e6a29235647a4729f70145f2 module/config-mutation
5959
189fa5a240cad0404cd281ad0a14a105a8f3231278d87b71cfbc4f96fb8e48ef module/config-runtime
6060
c1ea9510dfda047609a99d5d2cd1f1560f5d469a36e6b695766213d695c25b0f module/conversation-runtime
61-
8994adeb5aec2799c1a6d492f4f69db38ab15381038525666463580f520c5cfc module/core
61+
dea96213010cbc816345b1229534f1acb8b0bcfdbd7814c62eefc77030fa9cd8 module/core
6262
4af19d59c2f18674e7d7f7dc1b358b644dc707e6bd601dc47168bd9e4a669940 module/dedupe-runtime
6363
f70c93d28053ca2e8353e45e6515ce7acef188097c6117d1545965d0699c8004 module/device-bootstrap
6464
6215d3af5923bf5a616d73062534968b69f448e3e30adc64ae9caebdd1a46d71 module/diagnostic-runtime

‎docs/plugins/sdk-entrypoints.md‎

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ export default definePluginEntry({
170170

171171
Wraps `definePluginEntry` with channel-specific wiring: it automatically
172172
calls `api.registerChannel({ plugin })`, exposes an optional root-help CLI
173-
metadata seam, and gates `registerFull` on registration mode.
173+
metadata seam, and gates capability and full-runtime callbacks on registration
174+
mode.
174175

175176
```typescript
176177
import { defineChannelPluginEntry } from "openclaw/plugin-sdk/channel-core";
@@ -187,19 +188,23 @@ export default defineChannelPluginEntry({
187188
registerFull(api) {
188189
api.registerGatewayMethod(/* ... */);
189190
},
191+
registerCapabilities(api) {
192+
api.registerTranscriptSourceProvider(/* ... */);
193+
},
190194
});
191195
```
192196

193-
| Field | Type | Required | Default |
194-
| --------------------- | ---------------------------------------------------------------- | -------- | ------------------- |
195-
| `id` | `string` | Yes | - |
196-
| `name` | `string` | Yes | - |
197-
| `description` | `string` | Yes | - |
198-
| `plugin` | `ChannelPlugin` | Yes | - |
199-
| `configSchema` | `OpenClawPluginConfigSchema \| () => OpenClawPluginConfigSchema` | No | Empty object schema |
200-
| `setRuntime` | `(runtime: PluginRuntime) => void` | No | - |
201-
| `registerCliMetadata` | `(api: OpenClawPluginApi) => void` | No | - |
202-
| `registerFull` | `(api: OpenClawPluginApi) => void` | No | - |
197+
| Field | Type | Required | Default |
198+
| ---------------------- | ---------------------------------------------------------------- | -------- | ------------------- |
199+
| `id` | `string` | Yes | - |
200+
| `name` | `string` | Yes | - |
201+
| `description` | `string` | Yes | - |
202+
| `plugin` | `ChannelPlugin` | Yes | - |
203+
| `configSchema` | `OpenClawPluginConfigSchema \| () => OpenClawPluginConfigSchema` | No | Empty object schema |
204+
| `setRuntime` | `(runtime: PluginRuntime) => void` | No | - |
205+
| `registerCliMetadata` | `(api: OpenClawPluginApi) => void` | No | - |
206+
| `registerFull` | `(api: OpenClawPluginApi) => void` | No | - |
207+
| `registerCapabilities` | `(api: OpenClawPluginApi) => void` | No | - |
203208

204209
Callbacks run per registration mode (full table under
205210
[Registration mode](#registration-mode)):
@@ -214,10 +219,13 @@ Callbacks run per registration mode (full table under
214219
plugin loads.
215220
- `registerFull` runs only for `"full"` and `"tool-discovery"`. For
216221
`"tool-discovery"` it runs _instead of_ channel registration: OpenClaw
217-
skips `registerChannel`/`setRuntime` entirely and calls only
218-
`registerFull`, so any provider/tool registration your channel needs for
219-
standalone tool discovery or execution must live there, not behind normal
220-
channel setup.
222+
skips `registerChannel`/`setRuntime` entirely and calls the full-runtime
223+
callback followed by the capability callback. Keep tool registration in
224+
`registerFull` and capability providers in `registerCapabilities`.
225+
- `registerCapabilities` runs for `"discovery"`, `"full"`, and
226+
`"tool-discovery"`. Register inert advertised providers here so read-only
227+
capability discovery can find them without starting sockets, clients,
228+
workers, or services.
221229
- Discovery registration is non-activating, not import-free: OpenClaw may
222230
evaluate the trusted plugin entry and channel plugin module to build the
223231
snapshot. Keep top-level imports side-effect-free and put sockets,
@@ -327,14 +335,14 @@ full activation.
327335

328336
`api.registrationMode` tells your plugin how it was loaded:
329337

330-
| Mode | When | What to register |
331-
| ------------------ | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
332-
| `"full"` | Normal gateway startup | Everything |
333-
| `"discovery"` | Read-only capability discovery | Channel registration plus static CLI descriptors; entry code may load, but skip sockets, workers, clients, and services |
334-
| `"tool-discovery"` | Scoped load to list or run specific plugins' tools | Capability/tool registration only; no channel activation |
335-
| `"setup-only"` | Disabled/unconfigured channel | Channel registration only |
336-
| `"setup-runtime"` | Setup flow with runtime available | Channel registration plus only the lightweight runtime needed before the full entry loads |
337-
| `"cli-metadata"` | Root help / CLI metadata capture | CLI descriptors only |
338+
| Mode | When | What to register |
339+
| ------------------ | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
340+
| `"full"` | Normal gateway startup | Everything |
341+
| `"discovery"` | Read-only capability discovery | Channel registration, static CLI descriptors, and inert providers; skip sockets, workers, clients, and services |
342+
| `"tool-discovery"` | Scoped load to list or run specific plugins' tools | Capability/tool registration only; no channel activation |
343+
| `"setup-only"` | Disabled/unconfigured channel | Channel registration only |
344+
| `"setup-runtime"` | Setup flow with runtime available | Channel registration plus only the lightweight runtime needed before the full entry loads |
345+
| `"cli-metadata"` | Root help / CLI metadata capture | CLI descriptors only |
338346

339347
`defineChannelPluginEntry` handles this split automatically. If you use
340348
`definePluginEntry` directly for a channel, check mode yourself and remember

‎extensions/discord/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default defineBundledChannelEntry({
2424
registerFull(api) {
2525
registerDiscordActivities(api);
2626
registerDiscordSubagentHooks(api);
27+
},
28+
registerCapabilities(api) {
2729
api.registerTranscriptSourceProvider(discordVoiceTranscriptsSourceProvider);
2830
},
2931
});

‎src/plugin-sdk/channel-entry-contract.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function createBundledChannelEntry(params: {
104104
pluginId: string;
105105
registerCliMetadata?: (api: OpenClawPluginApi) => void;
106106
registerFull?: (api: OpenClawPluginApi) => void;
107+
registerCapabilities?: (api: OpenClawPluginApi) => void;
107108
}) {
108109
return defineBundledChannelEntry({
109110
id: params.pluginId,
@@ -114,6 +115,7 @@ function createBundledChannelEntry(params: {
114115
runtime: { specifier: "./runtime.cjs", exportName: "setRuntime" },
115116
registerCliMetadata: params.registerCliMetadata,
116117
registerFull: params.registerFull,
118+
registerCapabilities: params.registerCapabilities,
117119
});
118120
}
119121

@@ -128,6 +130,7 @@ describe("defineBundledChannelEntry", () => {
128130
runtimeMarker,
129131
});
130132
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
133+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
131134
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>((api) => {
132135
api.registerTool(
133136
{
@@ -145,6 +148,7 @@ describe("defineBundledChannelEntry", () => {
145148
pluginId,
146149
registerCliMetadata,
147150
registerFull,
151+
registerCapabilities,
148152
});
149153

150154
const api = createApi("tool-discovery");
@@ -153,6 +157,7 @@ describe("defineBundledChannelEntry", () => {
153157
expect(api.registerChannel).not.toHaveBeenCalled();
154158
expect(registerCliMetadata).not.toHaveBeenCalled();
155159
expect(registerFull).toHaveBeenCalledWith(api);
160+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(api);
156161
expect(api.registerTool).toHaveBeenCalledTimes(1);
157162
expect(fs.existsSync(runtimeMarker)).toBe(false);
158163
});
@@ -168,11 +173,13 @@ describe("defineBundledChannelEntry", () => {
168173
});
169174
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
170175
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>();
176+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
171177
const entry = createBundledChannelEntry({
172178
importerPath,
173179
pluginId,
174180
registerCliMetadata,
175181
registerFull,
182+
registerCapabilities,
176183
});
177184

178185
const api = createApi("discovery");
@@ -181,6 +188,7 @@ describe("defineBundledChannelEntry", () => {
181188
expect(api.registerChannel).toHaveBeenCalledTimes(1);
182189
expect(registerCliMetadata).toHaveBeenCalledWith(api);
183190
expect(registerFull).not.toHaveBeenCalled();
191+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(api);
184192
expect(fs.existsSync(runtimeMarker)).toBe(true);
185193
});
186194

@@ -195,24 +203,39 @@ describe("defineBundledChannelEntry", () => {
195203
});
196204
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
197205
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>();
206+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
198207
const entry = createBundledChannelEntry({
199208
importerPath,
200209
pluginId,
201210
registerCliMetadata,
202211
registerFull,
212+
registerCapabilities,
203213
});
204214

215+
const cliApi = createApi("cli-metadata");
216+
entry.register(cliApi);
217+
expect(registerCliMetadata).toHaveBeenCalledWith(cliApi);
218+
expect(registerCapabilities).not.toHaveBeenCalled();
219+
expect(fs.existsSync(runtimeMarker)).toBe(false);
220+
registerCliMetadata.mockClear();
221+
222+
entry.register(createApi("setup-only"));
223+
expect(registerCapabilities).not.toHaveBeenCalled();
224+
fs.rmSync(runtimeMarker, { force: true });
225+
205226
entry.register(createApi("setup-runtime"));
206227
expect(fs.existsSync(runtimeMarker)).toBe(true);
207228
expect(registerCliMetadata).not.toHaveBeenCalled();
208229
expect(registerFull).not.toHaveBeenCalled();
230+
expect(registerCapabilities).not.toHaveBeenCalled();
209231

210232
fs.rmSync(runtimeMarker, { force: true });
211233
const fullApi = createApi("full");
212234
entry.register(fullApi);
213235
expect(fs.existsSync(runtimeMarker)).toBe(true);
214236
expect(registerCliMetadata).toHaveBeenCalledWith(fullApi);
215237
expect(registerFull).toHaveBeenCalledWith(fullApi);
238+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(fullApi);
216239
});
217240
});
218241

‎src/plugin-sdk/channel-entry-contract.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type DefineBundledChannelEntryOptions<TPlugin = ChannelPlugin> = {
6363
features?: BundledChannelEntryFeatures;
6464
registerCliMetadata?: (api: OpenClawPluginApi) => void;
6565
registerFull?: (api: OpenClawPluginApi) => void;
66+
registerCapabilities?: (api: OpenClawPluginApi) => void;
6667
};
6768

6869
type DefineBundledChannelSetupEntryOptions = {
@@ -482,6 +483,7 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
482483
features,
483484
registerCliMetadata,
484485
registerFull,
486+
registerCapabilities,
485487
}: DefineBundledChannelEntryOptions<TPlugin>): BundledChannelEntryContract<TPlugin> {
486488
const resolvedConfigSchema: ChannelEntryConfigSchema<TPlugin> =
487489
typeof configSchema === "function"
@@ -540,6 +542,7 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
540542
if (api.registrationMode === "tool-discovery") {
541543
const profile = createProfiler({ pluginId: id, source: importMetaUrl });
542544
profile("bundled-register:registerFull", () => registerFull?.(api));
545+
profile("bundled-register:registerCapabilities", () => registerCapabilities?.(api));
543546
return;
544547
}
545548
const profile = createProfiler({ pluginId: id, source: importMetaUrl });
@@ -550,13 +553,15 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
550553
profile("bundled-register:setChannelRuntime", () => setChannelRuntime?.(api.runtime));
551554
if (api.registrationMode === "discovery") {
552555
profile("bundled-register:registerCliMetadata", () => registerCliMetadata?.(api));
556+
profile("bundled-register:registerCapabilities", () => registerCapabilities?.(api));
553557
return;
554558
}
555559
if (api.registrationMode !== "full") {
556560
return;
557561
}
558562
profile("bundled-register:registerCliMetadata", () => registerCliMetadata?.(api));
559563
profile("bundled-register:registerFull", () => registerFull?.(api));
564+
profile("bundled-register:registerCapabilities", () => registerCapabilities?.(api));
560565
},
561566
loadChannelPlugin,
562567
...(loadChannelOutbound ? { loadChannelOutbound } : {}),

‎src/plugin-sdk/core.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe("defineChannelPluginEntry", () => {
4343
it("runs tool registrations without channel runtime wiring during tool discovery", () => {
4444
const setRuntime = vi.fn<(runtime: PluginRuntime) => void>();
4545
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
46+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
4647
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>((api) => {
4748
api.registerTool(
4849
{
@@ -63,6 +64,7 @@ describe("defineChannelPluginEntry", () => {
6364
setRuntime,
6465
registerCliMetadata,
6566
registerFull,
67+
registerCapabilities,
6668
});
6769

6870
const api = createApi("tool-discovery");
@@ -72,13 +74,15 @@ describe("defineChannelPluginEntry", () => {
7274
expect(setRuntime).not.toHaveBeenCalled();
7375
expect(registerCliMetadata).not.toHaveBeenCalled();
7476
expect(registerFull).toHaveBeenCalledWith(api);
77+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(api);
7578
expect(api.registerTool).toHaveBeenCalledTimes(1);
7679
});
7780

7881
it("wires runtime helpers during discovery registration", () => {
7982
const setRuntime = vi.fn<(runtime: PluginRuntime) => void>();
8083
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
8184
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>();
85+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
8286
const entry = defineChannelPluginEntry({
8387
id: "runtime-discovery",
8488
name: "Runtime Discovery",
@@ -87,6 +91,7 @@ describe("defineChannelPluginEntry", () => {
8791
setRuntime,
8892
registerCliMetadata,
8993
registerFull,
94+
registerCapabilities,
9095
});
9196

9297
const api = createApi("discovery");
@@ -96,12 +101,14 @@ describe("defineChannelPluginEntry", () => {
96101
expect(registerCliMetadata).toHaveBeenCalledTimes(1);
97102
expect(setRuntime).toHaveBeenCalledWith(api.runtime);
98103
expect(registerFull).not.toHaveBeenCalled();
104+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(api);
99105
});
100106

101107
it("keeps setup-runtime and full registration wired to runtime helpers", () => {
102108
const setRuntime = vi.fn<(runtime: PluginRuntime) => void>();
103109
const registerCliMetadata = vi.fn<(api: OpenClawPluginApi) => void>();
104110
const registerFull = vi.fn<(api: OpenClawPluginApi) => void>();
111+
const registerCapabilities = vi.fn<(api: OpenClawPluginApi) => void>();
105112
const entry = defineChannelPluginEntry({
106113
id: "runtime-activation",
107114
name: "Runtime Activation",
@@ -110,20 +117,32 @@ describe("defineChannelPluginEntry", () => {
110117
setRuntime,
111118
registerCliMetadata,
112119
registerFull,
120+
registerCapabilities,
113121
});
114122

123+
const cliApi = createApi("cli-metadata");
124+
entry.register(cliApi);
125+
expect(registerCliMetadata).toHaveBeenCalledWith(cliApi);
126+
expect(registerCapabilities).not.toHaveBeenCalled();
127+
registerCliMetadata.mockClear();
128+
129+
entry.register(createApi("setup-only"));
130+
expect(registerCapabilities).not.toHaveBeenCalled();
131+
115132
const setupApi = createApi("setup-runtime");
116133
entry.register(setupApi);
117134
expect(setRuntime).toHaveBeenCalledWith(setupApi.runtime);
118135
expect(registerCliMetadata).not.toHaveBeenCalled();
119136
expect(registerFull).not.toHaveBeenCalled();
137+
expect(registerCapabilities).not.toHaveBeenCalled();
120138

121139
setRuntime.mockClear();
122140
const fullApi = createApi("full");
123141
entry.register(fullApi);
124142
expect(setRuntime).toHaveBeenCalledWith(fullApi.runtime);
125143
expect(registerCliMetadata).toHaveBeenCalledWith(fullApi);
126144
expect(registerFull).toHaveBeenCalledWith(fullApi);
145+
expect(registerCapabilities).toHaveBeenCalledExactlyOnceWith(fullApi);
127146
});
128147
});
129148

0 commit comments

Comments
 (0)