mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:34:32 +00: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
|
* Format the hooks list output
|
||||||
*/
|
*/
|
||||||
@@ -565,24 +590,7 @@ export function registerHooksCli(program: Command): void {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const hookName of probe.hooks) {
|
next = enableInternalHookEntries(next, 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 = recordHookInstall(next, {
|
next = recordHookInstall(next, {
|
||||||
hookId: probe.hookPackId,
|
hookId: probe.hookPackId,
|
||||||
@@ -611,38 +619,7 @@ export function registerHooksCli(program: Command): void {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next: OpenClawConfig = {
|
let next = enableInternalHookEntries(cfg, result.hooks);
|
||||||
...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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path";
|
const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path";
|
||||||
|
|
||||||
@@ -691,38 +668,7 @@ export function registerHooksCli(program: Command): void {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next: OpenClawConfig = {
|
let next = enableInternalHookEntries(cfg, result.hooks);
|
||||||
...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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
next = recordHookInstall(next, {
|
next = recordHookInstall(next, {
|
||||||
hookId: result.hookPackId,
|
hookId: result.hookPackId,
|
||||||
|
|||||||
Reference in New Issue
Block a user