From 29e84dc130c06b1d06ba59bb1a0788361617c265 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 21:39:52 +0000 Subject: [PATCH] refactor(cli): dedupe hooks install config updates --- src/cli/hooks-cli.ts | 110 +++++++++++-------------------------------- 1 file changed, 28 insertions(+), 82 deletions(-) diff --git a/src/cli/hooks-cli.ts b/src/cli/hooks-cli.ts index 9b3ab010030..7f7b0e9eb0a 100644 --- a/src/cli/hooks-cli.ts +++ b/src/cli/hooks-cli.ts @@ -118,6 +118,31 @@ async function readInstalledPackageVersion(dir: string): Promise & { enabled?: boolean }; + +function enableInternalHookEntries(config: OpenClawConfig, hookNames: string[]): OpenClawConfig { + const entries = { ...config.hooks?.internal?.entries } as Record; + + for (const hookName of hookNames) { + entries[hookName] = { + ...entries[hookName], + enabled: true, + }; + } + + return { + ...config, + hooks: { + ...config.hooks, + internal: { + ...config.hooks?.internal, + enabled: true, + entries, + }, + }, + }; +} + /** * Format the hooks list output */ @@ -565,24 +590,7 @@ export function registerHooksCli(program: Command): void { }, }; - for (const hookName of probe.hooks) { - next = { - ...next, - hooks: { - ...next.hooks, - internal: { - ...next.hooks?.internal, - entries: { - ...next.hooks?.internal?.entries, - [hookName]: { - ...(next.hooks?.internal?.entries?.[hookName] as object | undefined), - enabled: true, - }, - }, - }, - }, - }; - } + next = enableInternalHookEntries(next, probe.hooks); next = recordHookInstall(next, { hookId: probe.hookPackId, @@ -611,38 +619,7 @@ export function registerHooksCli(program: Command): void { process.exit(1); } - let next: OpenClawConfig = { - ...cfg, - hooks: { - ...cfg.hooks, - internal: { - ...cfg.hooks?.internal, - enabled: true, - entries: { - ...cfg.hooks?.internal?.entries, - }, - }, - }, - }; - - for (const hookName of result.hooks) { - next = { - ...next, - hooks: { - ...next.hooks, - internal: { - ...next.hooks?.internal, - entries: { - ...next.hooks?.internal?.entries, - [hookName]: { - ...(next.hooks?.internal?.entries?.[hookName] as object | undefined), - enabled: true, - }, - }, - }, - }, - }; - } + let next = enableInternalHookEntries(cfg, result.hooks); const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path"; @@ -691,38 +668,7 @@ export function registerHooksCli(program: Command): void { process.exit(1); } - let next: OpenClawConfig = { - ...cfg, - hooks: { - ...cfg.hooks, - internal: { - ...cfg.hooks?.internal, - enabled: true, - entries: { - ...cfg.hooks?.internal?.entries, - }, - }, - }, - }; - - for (const hookName of result.hooks) { - next = { - ...next, - hooks: { - ...next.hooks, - internal: { - ...next.hooks?.internal, - entries: { - ...next.hooks?.internal?.entries, - [hookName]: { - ...(next.hooks?.internal?.entries?.[hookName] as object | undefined), - enabled: true, - }, - }, - }, - }, - }; - } + let next = enableInternalHookEntries(cfg, result.hooks); next = recordHookInstall(next, { hookId: result.hookPackId,