From 8246e8dace5f1687c65f269f7de4dc2bb9cecc15 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 22 Jun 2026 14:10:40 +0800 Subject: [PATCH] refactor(plugins): share channel command normalization --- src/plugins/manifest-registry-installed.ts | 25 ++----------------- src/plugins/manifest-registry.ts | 28 +++------------------- src/plugins/manifest.ts | 2 +- 3 files changed, 6 insertions(+), 49 deletions(-) diff --git a/src/plugins/manifest-registry-installed.ts b/src/plugins/manifest-registry-installed.ts index 39b0c46b23e3..226280d7daf0 100644 --- a/src/plugins/manifest-registry-installed.ts +++ b/src/plugins/manifest-registry-installed.ts @@ -16,6 +16,7 @@ import type { BundledChannelConfigCollector } from "./manifest-registry.js"; import { DEFAULT_PLUGIN_ENTRY_CANDIDATES, getPackageManifestMetadata, + normalizeManifestChannelCommandDefaults, type OpenClawPackageManifest, type PackageManifest, type PluginPackageChannel, @@ -274,28 +275,6 @@ function resolveFallbackPluginSource(record: InstalledPluginIndexRecord): string return path.join(rootDir, DEFAULT_PLUGIN_ENTRY_CANDIDATES[0]); } -function normalizePackageChannelCommands( - commands: unknown, -): PluginPackageChannel["commands"] | undefined { - if (!isRecord(commands)) { - return undefined; - } - const nativeCommandsAutoEnabled = - typeof commands.nativeCommandsAutoEnabled === "boolean" - ? commands.nativeCommandsAutoEnabled - : undefined; - const nativeSkillsAutoEnabled = - typeof commands.nativeSkillsAutoEnabled === "boolean" - ? commands.nativeSkillsAutoEnabled - : undefined; - return nativeCommandsAutoEnabled !== undefined || nativeSkillsAutoEnabled !== undefined - ? { - ...(nativeCommandsAutoEnabled !== undefined ? { nativeCommandsAutoEnabled } : {}), - ...(nativeSkillsAutoEnabled !== undefined ? { nativeSkillsAutoEnabled } : {}), - } - : undefined; -} - function normalizePackageChannelExposure( exposure: unknown, ): PluginPackageChannel["exposure"] | undefined { @@ -480,7 +459,7 @@ function normalizePersistedPackageChannel(value: unknown): PluginPackageChannel if (exposure) { channel.exposure = exposure; } - const commands = normalizePackageChannelCommands(value.commands); + const commands = normalizeManifestChannelCommandDefaults(value.commands); if (commands) { channel.commands = commands; } diff --git a/src/plugins/manifest-registry.ts b/src/plugins/manifest-registry.ts index ecbd8c1945af..4bb054b1a3f7 100644 --- a/src/plugins/manifest-registry.ts +++ b/src/plugins/manifest-registry.ts @@ -53,6 +53,7 @@ import { type PluginManifestToolMetadata, type PluginPackageChannel, type PluginPackageInstall, + normalizeManifestChannelCommandDefaults, } from "./manifest.js"; import { checkMinHostVersion } from "./min-host-version.js"; import { @@ -295,29 +296,6 @@ function normalizePreferredPluginIds(raw: unknown): string[] | undefined { return normalizeOptionalTrimmedStringList(raw); } -function normalizePackageChannelCommands( - commands: unknown, -): PluginManifestChannelCommandDefaults | undefined { - if (!commands || typeof commands !== "object" || Array.isArray(commands)) { - return undefined; - } - const record = commands as Record; - const nativeCommandsAutoEnabled = - typeof record.nativeCommandsAutoEnabled === "boolean" - ? record.nativeCommandsAutoEnabled - : undefined; - const nativeSkillsAutoEnabled = - typeof record.nativeSkillsAutoEnabled === "boolean" - ? record.nativeSkillsAutoEnabled - : undefined; - return nativeCommandsAutoEnabled !== undefined || nativeSkillsAutoEnabled !== undefined - ? { - ...(nativeCommandsAutoEnabled !== undefined ? { nativeCommandsAutoEnabled } : {}), - ...(nativeSkillsAutoEnabled !== undefined ? { nativeSkillsAutoEnabled } : {}), - } - : undefined; -} - function mergePackageChannelMetaIntoChannelConfigs(params: { channelConfigs?: Record; packageChannel?: OpenClawPackageManifest["channel"]; @@ -342,7 +320,7 @@ function mergePackageChannelMetaIntoChannelConfigs(params: { const preferOver = existing.preferOver ?? normalizePreferredPluginIds(params.packageChannel?.preferOver); const commands = - existing.commands ?? normalizePackageChannelCommands(params.packageChannel?.commands); + existing.commands ?? normalizeManifestChannelCommandDefaults(params.packageChannel?.commands); const merged: Record = Object.create(null); for (const [key, value] of Object.entries(params.channelConfigs)) { @@ -501,7 +479,7 @@ function buildRecord(params: { }), packageChannel: params.candidate.packageManifest?.channel, }); - const packageChannelCommands = normalizePackageChannelCommands( + const packageChannelCommands = normalizeManifestChannelCommandDefaults( params.candidate.packageManifest?.channel?.commands, ); return { diff --git a/src/plugins/manifest.ts b/src/plugins/manifest.ts index ebec5fbbdd60..455c6a83bcb7 100644 --- a/src/plugins/manifest.ts +++ b/src/plugins/manifest.ts @@ -1615,7 +1615,7 @@ function normalizeChannelConfigs( return Object.keys(normalized).length > 0 ? normalized : undefined; } -function normalizeManifestChannelCommandDefaults( +export function normalizeManifestChannelCommandDefaults( value: unknown, ): PluginManifestChannelCommandDefaults | undefined { if (!isRecord(value)) {