From ed0b098d759627647e1901bbd4a7850ea30d2fb1 Mon Sep 17 00:00:00 2001 From: Ayumi Server Date: Mon, 27 Apr 2026 15:44:49 +0000 Subject: [PATCH] fix: inject pluginConfig into hook handler event context When plugins register hooks via api.registerHook(), pluginConfig from openclaw.json was not available in the hook event context. Plugins that accessed ctx.pluginConfig or event.context.pluginConfig received undefined, causing silent failures or fallback to defaults. Changes: - Add pluginConfig parameter to registerHook() function - Wrap handler to inject pluginConfig into event.context before invocation - Pass params.pluginConfig through createApi() call site Fixes #72880 --- src/plugins/registry.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/plugins/registry.ts b/src/plugins/registry.ts index ac528582f9a..5b35259fed7 100644 --- a/src/plugins/registry.ts +++ b/src/plugins/registry.ts @@ -422,6 +422,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { handler: Parameters[1], opts: OpenClawPluginHookOptions | undefined, config: OpenClawPluginApi["config"], + pluginConfig: unknown, ) => { const eventList = Array.isArray(events) ? events : [events]; const normalizedEvents = eventList.map((event) => event.trim()).filter(Boolean); @@ -499,8 +500,16 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { handler: Parameters[1]; }> = []; for (const event of normalizedEvents) { - registerInternalHook(event, handler); - nextRegistrations.push({ event, handler }); + // Wrap handler to inject pluginConfig into event context + // so plugins can access their configured pluginConfig at invocation time + const wrappedHandler: typeof handler = async (evt) => { + if (evt.context && typeof evt.context === "object") { + (evt.context as Record).pluginConfig = pluginConfig; + } + return handler(evt); + }; + registerInternalHook(event, wrappedHandler); + nextRegistrations.push({ event, handler: wrappedHandler }); } activePluginHookRegistrations.set(hookName, nextRegistrations); const rollbackEntries = pluginHookRollback.get(record.id) ?? []; @@ -1466,7 +1475,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { ? { registerTool: (tool, opts) => registerTool(record, tool, opts), registerHook: (events, handler, opts) => - registerHook(record, events, handler, opts, params.config), + registerHook(record, events, handler, opts, params.config, params.pluginConfig), registerHttpRoute: (routeParams) => registerHttpRoute(record, routeParams), registerProvider: (provider) => registerProvider(record, provider), registerAgentHarness: (harness) => registerAgentHarness(record, harness),