mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(cli): dedupe hooks install config updates
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user