refactor(cli): dedupe hooks install config updates

This commit is contained in:
Peter Steinberger
2026-02-14 21:39:52 +00:00
parent aeb953bdf4
commit 29e84dc130

View File

@@ -118,6 +118,31 @@ async function readInstalledPackageVersion(dir: string): Promise<string | undefi
}
}
type HookInternalEntryLike = Record<string, unknown> & { enabled?: boolean };
function enableInternalHookEntries(config: OpenClawConfig, hookNames: string[]): OpenClawConfig {
const entries = { ...config.hooks?.internal?.entries } as Record<string, HookInternalEntryLike>;
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,