From e03db28ba73859942dbc19b91d3f5de57d4dcdfb Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 11 Apr 2026 17:45:39 +0100 Subject: [PATCH] fix(plugins): split hook runner registry types --- src/plugins/hook-registry.types.ts | 22 ++++++++++++++++++++++ src/plugins/hook-runner-global.ts | 8 ++++---- src/plugins/hooks.ts | 11 +++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/plugins/hook-registry.types.ts diff --git a/src/plugins/hook-registry.types.ts b/src/plugins/hook-registry.types.ts new file mode 100644 index 00000000000..c2e450dbdaf --- /dev/null +++ b/src/plugins/hook-registry.types.ts @@ -0,0 +1,22 @@ +import type { HookEntry } from "../hooks/types.js"; +import type { PluginHookRegistration as TypedPluginHookRegistration } from "./types.js"; + +export type PluginLegacyHookRegistration = { + pluginId: string; + entry: HookEntry; + events: string[]; + source: string; + rootDir?: string; +}; + +export type HookRunnerRegistry = { + hooks: PluginLegacyHookRegistration[]; + typedHooks: TypedPluginHookRegistration[]; +}; + +export type GlobalHookRunnerRegistry = HookRunnerRegistry & { + plugins: Array<{ + id: string; + status: "loaded" | "disabled" | "error"; + }>; +}; diff --git a/src/plugins/hook-runner-global.ts b/src/plugins/hook-runner-global.ts index 0c2dfdd8e08..991ee323cce 100644 --- a/src/plugins/hook-runner-global.ts +++ b/src/plugins/hook-runner-global.ts @@ -7,13 +7,13 @@ import { createSubsystemLogger } from "../logging/subsystem.js"; import { resolveGlobalSingleton } from "../shared/global-singleton.js"; +import type { GlobalHookRunnerRegistry } from "./hook-registry.types.js"; import { createHookRunner, type HookRunner } from "./hooks.js"; -import type { PluginRegistry } from "./registry-types.js"; import type { PluginHookGatewayContext, PluginHookGatewayStopEvent } from "./types.js"; type HookRunnerGlobalState = { hookRunner: HookRunner | null; - registry: PluginRegistry | null; + registry: GlobalHookRunnerRegistry | null; }; const hookRunnerGlobalStateKey = Symbol.for("openclaw.plugins.hook-runner-global-state"); @@ -29,7 +29,7 @@ const getLog = () => createSubsystemLogger("plugins"); * Initialize the global hook runner with a plugin registry. * Called once when plugins are loaded during gateway startup. */ -export function initializeGlobalHookRunner(registry: PluginRegistry): void { +export function initializeGlobalHookRunner(registry: GlobalHookRunnerRegistry): void { const state = getState(); const log = getLog(); state.registry = registry; @@ -63,7 +63,7 @@ export function getGlobalHookRunner(): HookRunner | null { * Get the global plugin registry. * Returns null if plugins haven't been loaded yet. */ -export function getGlobalPluginRegistry(): PluginRegistry | null { +export function getGlobalPluginRegistry(): GlobalHookRunnerRegistry | null { return getState().registry; } diff --git a/src/plugins/hooks.ts b/src/plugins/hooks.ts index 7b3ad7bd84b..eeef2362df7 100644 --- a/src/plugins/hooks.ts +++ b/src/plugins/hooks.ts @@ -7,7 +7,7 @@ import { formatErrorMessage } from "../infra/errors.js"; import { concatOptionalTextSegments } from "../shared/text/join-segments.js"; -import type { PluginRegistry } from "./registry.js"; +import type { GlobalHookRunnerRegistry, HookRunnerRegistry } from "./hook-registry.types.js"; import type { PluginHookAfterCompactionEvent, PluginHookAfterToolCallEvent, @@ -184,7 +184,7 @@ type SyncHookResult = ReturnType>; * Get hooks for a specific hook name, sorted by priority (higher first). */ function getHooksForName( - registry: PluginRegistry, + registry: HookRunnerRegistry, hookName: K, ): PluginHookRegistration[] { return (registry.typedHooks as PluginHookRegistration[]) @@ -193,7 +193,7 @@ function getHooksForName( } function getHooksForNameAndPlugin( - registry: PluginRegistry, + registry: HookRunnerRegistry, hookName: K, pluginId: string, ): PluginHookRegistration[] { @@ -203,7 +203,10 @@ function getHooksForNameAndPlugin( /** * Create a hook runner for a specific registry. */ -export function createHookRunner(registry: PluginRegistry, options: HookRunnerOptions = {}) { +export function createHookRunner( + registry: GlobalHookRunnerRegistry, + options: HookRunnerOptions = {}, +) { const logger = options.logger; const catchErrors = options.catchErrors ?? true; const failurePolicyByHook = options.failurePolicyByHook ?? {};