openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
799 lines (798 loc) • 31.2 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { c as normalizeOptionalTrimmedStringList, v as normalizeUniqueTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs";
import { t as isBlockedObjectKey } from "./prototype-keys-CLGi5xDj.mjs";
import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs";
import "./utils-C8YECn2Q.mjs";
import { n as groupPluginRecords, t as PLUGIN_ORIGIN_PRIORITIES } from "./record-groups-DII71OvH.mjs";
import { g as isPluginCandidateInstallOwnerAmbiguous, h as createPluginInstallOwnerMetadata, n as discoverOpenClawPlugins, y as resolvePluginCandidateInstallOwner } from "./discovery-DvJYrQFY.mjs";
import { a as resolveCompatibilityHostVersion } from "./version-GlxUMdxI.mjs";
import { n as isPathInside } from "./path-safety-CTChYC4Z.mjs";
import { a as pluginCacheRealpathSync, c as readPluginCacheFile, i as pluginCacheLstatSync, o as pluginCacheStatSync, r as pluginCacheExistsSync, s as readPluginCacheDirectory } from "./plugin-cache-files-e1aGp2KM.mjs";
import { n as isCoreReservedPluginId, r as loadPluginManifest, s as normalizeManifestChannelCommandDefaults, t as PLUGIN_MANIFEST_FILENAME } from "./manifest-Y5vPZPOf.mjs";
import { r as isForeignBundledPluginRoot } from "./bundled-dir-BKvdAqkP.mjs";
import { t as normalizePluginPolicyId } from "./plugin-policy-id-CkilMowp.mjs";
import { C as normalizePluginsConfigWithResolverCore } from "./config-state-B1JlHgba.mjs";
import { t as dedupeByKey } from "./dedupe-by-key-Cpowmfct.mjs";
import { t as PLUGIN_MANIFEST_CONTRACT_KEYS } from "./manifest-contract-keys-BVB8HMAG.mjs";
import { r as normalizeManifestCatalog } from "./manifest-capability-normalizers-mW51WFYi.mjs";
import { a as isThemeId } from "./theme-ids-CP6Aodag.mjs";
import { n as MAX_THEME_DEFINITION_BYTES, y as normalizeThemeDefinition } from "./theme-DHNzyMXg.mjs";
import { i as loadBundleManifest } from "./bundle-manifest-js7o0H7U.mjs";
import { n as satisfiesPluginApiRange, t as resolvePackagePluginApiRange } from "./package-compat-BLExNVkv.mjs";
import { t as shouldRejectHardlinkedPluginFiles } from "./hardlink-policy-Kq1Lxk7_.mjs";
import { n as isBundledPluginInsideDevSourceRoot } from "./dev-source-root-HNpp2lb0.mjs";
import { i as getOfficialExternalPluginCatalogEntryForPackage } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { r as resolveInstalledPluginIndexStorePath } from "./installed-plugin-index-store-path-VYnur1Rc.mjs";
import { o as getOfficialExternalPluginCatalogManifest } from "./official-external-plugin-catalog-source-4o5oPhVN.mjs";
import { n as resolvePluginTrust, t as matchesInstalledPluginRecord } from "./installed-plugin-record-match-CL-dKCYg.mjs";
import { a as sniffInlineImageMime } from "./inline-image-data-url-DP3ia8a0.mjs";
import { t as isSelfContainedSvg } from "./svg-image-ClSksOzI.mjs";
import { a as PORTABLE_PLUGIN_ICON_PATH, i as PLUGIN_TOOL_ACTIVITY_ICON_DIR, n as PLUGIN_ACTIVITY_ICON_PATH, o as isPluginActivityToolName, r as PLUGIN_THEME_BACKGROUND_MAX_BYTES, t as PLUGIN_ACTIVITY_ICON_MAX_BYTES } from "./portable-icon-paths-DPJs05Pc.mjs";
import { t as checkMinHostVersion } from "./min-host-version-B_V6HMtQ.mjs";
import path from "node:path";
//#region src/plugins/manifest-install-owner.ts
const { record: recordPluginManifestInstallOwner, resolve: resolvePluginManifestInstallOwner, isAmbiguous: isPluginManifestInstallOwnerAmbiguous } = createPluginInstallOwnerMetadata("openclaw.pluginManifestInstallOwner", false);
//#endregion
//#region src/plugins/manifest-theme-definitions.ts
const BACKGROUND_MIME_TYPES = /* @__PURE__ */ new Set([
"image/png",
"image/jpeg",
"image/webp"
]);
/** Capture palettes and artwork so a published generation never reads changed files. */
function loadManifestThemeDefinitions(e) {
if (!e.themes?.length) return;
return e.themes.flatMap((t) => {
try {
if (e.pluginId === "user" || !isThemeId(`${e.pluginId}/${t.id}`)) throw new Error("qualified theme ID must be portable, outside user/, and at most 256 characters");
const n = readPluginCacheFile({
rootDir: e.rootDir,
relativePath: t.source,
rejectHardlinks: e.rejectHardlinks,
maxBytes: MAX_THEME_DEFINITION_BYTES * 4
});
if (!n.ok) throw new Error("source must be a readable JSON file inside the plugin root");
const r = normalizeThemeDefinition(JSON.parse(n.contents.toString("utf8")), {
iconIds: Object.keys(t.icons ?? {}),
hatIds: Object.keys(t.hats ?? {}),
critterIds: Object.keys(t.critters ?? {})
});
if (r.name !== t.name || r.description !== t.description) throw new Error("name and description must match the manifest declaration");
const readSvg = (t) => {
const n = readPluginCacheFile({
rootDir: e.rootDir,
relativePath: t,
rejectHardlinks: e.rejectHardlinks,
maxBytes: PLUGIN_ACTIVITY_ICON_MAX_BYTES
});
if (!n.ok) throw new Error(`artwork ${t} must be a readable SVG inside the plugin root, at most ${PLUGIN_ACTIVITY_ICON_MAX_BYTES} bytes`);
const r = n.contents.toString("utf8");
if (!isSelfContainedSvg(r)) throw new Error(`artwork ${t} must be a self-contained SVG`);
return r;
};
const readBackground = (t) => {
const n = readPluginCacheFile({
rootDir: e.rootDir,
relativePath: t,
rejectHardlinks: e.rejectHardlinks,
maxBytes: PLUGIN_THEME_BACKGROUND_MAX_BYTES
});
if (!n.ok || !BACKGROUND_MIME_TYPES.has(sniffInlineImageMime(n.contents) ?? "")) throw new Error(`background ${t} must be a readable PNG, JPEG, or WebP inside the plugin root, at most ${PLUGIN_THEME_BACKGROUND_MAX_BYTES} bytes`);
return n.contents.toString("base64");
};
const i = {
...t.icons ? { icons: Object.fromEntries(Object.entries(t.icons).map(([e, t]) => [e, { svg: readSvg(t) }])) } : {},
...t.hats ? { hats: Object.fromEntries(Object.entries(t.hats).map(([e, t]) => [e, { svg: readSvg(t) }])) } : {},
...t.critters ? { critters: Object.fromEntries(Object.entries(t.critters).map(([e, { source: t, ...n }]) => [e, {
svg: readSvg(t),
...n
}])) } : {},
...t.backgrounds ? { backgrounds: Object.fromEntries(Object.entries(t.backgrounds).map(([e, t]) => [e, { base64: readBackground(t) }])) } : {}
};
return [{
id: t.id,
definition: r,
...t.icons || t.hats || t.critters || t.backgrounds ? { artwork: i } : {}
}];
} catch (n) {
e.diagnostics.push({
level: "warn",
pluginId: e.pluginId,
message: `theme ${t.id} is unavailable: ${n instanceof Error ? n.message : "invalid definition"}`
});
return [];
}
});
}
//#endregion
//#region src/plugins/manifest-record.ts
function resolvePluginSourcePath(e) {
if (pluginCacheExistsSync(e)) return e;
if (e.endsWith(".ts")) {
const t = e.slice(0, -3) + ".js";
if (pluginCacheExistsSync(t)) return t;
}
return e;
}
function isPluginRootPath(e) {
const t = path.resolve(e.targetPath);
const n = path.resolve(e.rootPath);
if (!isPathInside(n, t)) return false;
const r = pluginCacheRealpathSync(t);
if (!r) return e.targetMustExist !== true;
if (!isPathInside(e.rootRealPath, r)) return false;
if (e.rejectHardlinks === true) {
const e = pluginCacheStatSync(t);
if (!e || e.nlink > 1) return false;
}
return true;
}
function resolvePortablePluginIcons(e) {
let t;
const resolveIcon = (n) => {
const r = path.resolve(e.rootDir, n);
const i = pluginCacheLstatSync(r);
if (!i?.isFile() || e.rejectHardlinks && i.nlink > 1) return;
if (!t) {
const n = path.resolve(e.rootDir);
t = {
path: n,
realPath: pluginCacheRealpathSync(n) ?? n
};
}
return isPluginRootPath({
rootPath: t.path,
targetPath: r,
rootRealPath: t.realPath,
rejectHardlinks: e.rejectHardlinks,
targetMustExist: true
}) ? r : void 0;
};
const n = resolveIcon(PORTABLE_PLUGIN_ICON_PATH);
const r = resolveIcon(PLUGIN_ACTIVITY_ICON_PATH);
const i = path.resolve(e.rootDir, PLUGIN_TOOL_ACTIVITY_ICON_DIR);
if (!isPluginRootPath({
rootPath: e.rootDir,
rootRealPath: e.rootDir === t?.path ? t.realPath : pluginCacheRealpathSync(e.rootDir) ?? e.rootDir,
targetPath: i,
targetMustExist: true
})) return {
iconPath: n,
activityIconPath: r
};
let a;
try {
a = readPluginCacheDirectory(i);
} catch {
return {
iconPath: n,
activityIconPath: r
};
}
if (a.length > 128) return {
iconPath: n,
activityIconPath: r
};
const o = [];
for (const e of a.map((e) => e.name).toSorted()) {
const t = e.endsWith(".svg") ? e.slice(0, -4) : "";
if (!isPluginActivityToolName(t)) continue;
const n = resolveIcon(`${PLUGIN_TOOL_ACTIVITY_ICON_DIR}/${e}`);
if (n) o.push([t, n]);
}
return {
iconPath: n,
activityIconPath: r,
...o.length ? { toolActivityIconPaths: Object.fromEntries(o) } : {}
};
}
function mergePackageChannelMetaIntoChannelConfigs(e) {
const t = e.packageChannel?.id?.trim();
if (!t || isBlockedObjectKey(t) || !e.channelConfigs || !Object.hasOwn(e.channelConfigs, t)) return e.channelConfigs;
const n = e.channelConfigs[t];
if (!n) return e.channelConfigs;
const r = n.label ?? normalizeOptionalString(e.packageChannel?.label) ?? "";
const i = n.description ?? normalizeOptionalString(e.packageChannel?.blurb) ?? "";
const a = n.preferOver ?? normalizeOptionalTrimmedStringList(e.packageChannel?.preferOver);
const o = n.commands ?? normalizeManifestChannelCommandDefaults(e.packageChannel?.commands);
const s = Object.create(null);
for (const [t, n] of Object.entries(e.channelConfigs)) if (!isBlockedObjectKey(t)) s[t] = n;
s[t] = {
...n,
...r ? { label: r } : {},
...i ? { description: i } : {},
...a?.length ? { preferOver: a } : {},
...o ? { commands: o } : {}
};
return s;
}
function mergeManifestContracts(e, t) {
if (!t) return e;
const n = {};
for (const r of PLUGIN_MANIFEST_CONTRACT_KEYS) {
const i = normalizeUniqueTrimmedStringList([...e?.[r] ?? [], ...t[r] ?? []]);
if (i.length > 0) n[r] = i;
}
return Object.keys(n).length > 0 ? n : void 0;
}
function mergeCatalogChannelConfigs(e) {
if (!e.catalogChannelConfigs) return e.manifestChannelConfigs;
const t = Object.create(null);
for (const [n, r] of Object.entries(e.catalogChannelConfigs)) if (!isBlockedObjectKey(n)) t[n] = r;
for (const [n, r] of Object.entries(e.manifestChannelConfigs ?? {})) if (!isBlockedObjectKey(n)) {
const e = t[n];
if (!e) {
t[n] = r;
continue;
}
const i = {
...e,
...r,
schema: r.schema ?? e.schema
};
if (e.uiHints || r.uiHints) i.uiHints = {
...e.uiHints,
...r.uiHints
};
for (const t of [
"runtime",
"label",
"description",
"preferOver",
"commands"
]) {
const n = r[t] ?? e[t];
if (n) Object.assign(i, { [t]: n });
}
t[n] = i;
}
return Object.keys(t).length > 0 ? t : void 0;
}
function buildPluginManifestRecord(e) {
const t = e.candidate.effectivePluginId ?? e.manifest.id;
const resolveCatalogEntry = (n) => {
const r = e.manifest[n];
if (r === void 0) return;
const i = e.candidate.rootDir;
const a = e.manifestPath;
const o = e.rejectHardlinks;
const s = e.diagnostics;
const pushDiagnostic = () => {
s.push({
level: "warn",
pluginId: sanitizeForLog(t),
source: sanitizeForLog(a),
message: `plugin manifest ${n} must resolve inside the plugin root; ignoring entry`
});
};
if (!r || path.isAbsolute(r)) {
pushDiagnostic();
return;
}
const c = path.resolve(i);
const l = pluginCacheRealpathSync(c) ?? c;
const u = path.resolve(c, r);
if (!isPluginRootPath({
rootPath: c,
targetPath: u,
rootRealPath: l,
rejectHardlinks: o,
targetMustExist: pluginCacheExistsSync(u)
})) {
pushDiagnostic();
return;
}
const d = resolvePluginSourcePath(u);
if (!isPluginRootPath({
rootPath: c,
targetPath: d,
rootRealPath: l,
rejectHardlinks: o,
targetMustExist: pluginCacheExistsSync(d)
})) {
pushDiagnostic();
return;
}
return d;
};
const n = e.candidate.origin === "bundled" && e.bundledChannelConfigCollector ? e.bundledChannelConfigCollector({
pluginDir: e.candidate.packageDir ?? e.candidate.rootDir,
manifest: e.manifest,
packageManifest: e.candidate.packageManifest
}) : e.manifest.channelConfigs;
const r = e.candidate.origin !== "bundled" ? getOfficialExternalPluginCatalogManifest(getOfficialExternalPluginCatalogEntryForPackage(e.candidate.packageName) ?? {}) : void 0;
const i = mergePackageChannelMetaIntoChannelConfigs({
channelConfigs: mergeCatalogChannelConfigs({
manifestChannelConfigs: n,
catalogChannelConfigs: r?.channelConfigs
}),
packageChannel: e.candidate.packageManifest?.channel
});
const a = normalizeManifestChannelCommandDefaults(e.candidate.packageManifest?.channel?.commands);
return {
id: t,
categories: e.manifest.categories,
backupResources: e.manifest.backupResources,
doctorContract: e.manifest.doctorContract,
doctorHealthChecks: e.manifest.doctorHealthChecks,
sessionRouteStateOwners: e.manifest.sessionRouteStateOwners,
name: normalizeOptionalString(e.manifest.name) ?? e.candidate.packageName,
description: normalizeOptionalString(e.manifest.description) ?? e.candidate.packageDescription,
catalog: normalizeManifestCatalog({
featured: e.manifest.catalog?.featured ?? r?.catalog?.featured,
order: e.manifest.catalog?.order ?? r?.catalog?.order
}),
...resolvePortablePluginIcons({
rootDir: e.candidate.rootDir,
rejectHardlinks: e.rejectHardlinks
}),
version: normalizeOptionalString(e.manifest.version) ?? e.candidate.packageVersion,
packageName: e.candidate.packageName,
packageVersion: e.candidate.packageVersion,
packageDescription: e.candidate.packageDescription,
enabledByDefault: e.manifest.enabledByDefault === true ? true : void 0,
enabledByDefaultOnPlatforms: e.manifest.enabledByDefaultOnPlatforms,
autoEnableWhenConfiguredProviders: e.manifest.autoEnableWhenConfiguredProviders,
legacyPluginIds: e.manifest.legacyPluginIds,
format: e.candidate.format ?? "openclaw",
bundleFormat: e.candidate.bundleFormat,
kind: e.manifest.kind,
contextEngineIds: e.manifest.contextEngineIds,
reload: e.manifest.reload,
channels: e.manifest.channels ?? [],
channelAccountKeyPolicies: e.manifest.channelAccountKeyPolicies,
providers: e.manifest.providers ?? [],
managesOwnAvailability: e.manifest.managesOwnAvailability,
providerDiscoverySource: resolveCatalogEntry("providerCatalogEntry"),
capabilityCatalogSource: e.manifest.capabilityCatalogEntry === void 0 ? void 0 : resolveCatalogEntry("capabilityCatalogEntry") ?? null,
modelSupport: e.manifest.modelSupport,
modelCatalog: e.manifest.modelCatalog,
modelPricing: e.manifest.modelPricing,
modelIdNormalization: e.manifest.modelIdNormalization,
providerEndpoints: e.manifest.providerEndpoints,
providerRequest: e.manifest.providerRequest,
secretProviderIntegrations: e.manifest.secretProviderIntegrations,
cliBackends: e.manifest.cliBackends ?? [],
syntheticAuthRefs: e.manifest.syntheticAuthRefs ?? [],
nonSecretAuthMarkers: e.manifest.nonSecretAuthMarkers ?? [],
commandAliases: e.manifest.commandAliases,
cliCommands: e.manifest.cliCommands,
providerUsageAuthEnvVars: e.manifest.providerUsageAuthEnvVars,
providerAuthAliases: e.manifest.providerAuthAliases,
providerAuthChoices: e.manifest.providerAuthChoices,
activation: e.manifest.activation,
setup: e.manifest.setup,
packageManifest: e.candidate.packageManifest,
packageDependencies: e.candidate.packageDependencies,
packageOptionalDependencies: e.candidate.packageOptionalDependencies,
packageChannel: e.candidate.packageManifest?.channel,
packageInstall: e.candidate.packageManifest?.install,
trustedOfficialInstall: e.trust.reason === "trusted-official" ? true : void 0,
trust: e.trust,
qaRunners: e.manifest.qaRunners,
dashboard: e.manifest.dashboard,
controlUi: e.manifest.controlUi,
uiCapabilities: e.manifest.uiCapabilities,
themes: e.manifest.themes,
themeDefinitions: loadManifestThemeDefinitions({
pluginId: t,
rootDir: e.candidate.rootDir,
themes: e.manifest.themes,
rejectHardlinks: e.rejectHardlinks,
diagnostics: e.diagnostics
}),
mcpServers: e.manifest.mcpServers,
skills: e.manifest.skills ?? [],
settingsFiles: [],
hooks: [],
origin: e.candidate.origin,
workspaceDir: e.candidate.workspaceDir,
rootDir: e.candidate.rootDir,
source: e.candidate.source,
setupSource: e.candidate.setupSource,
manifestPath: e.manifestPath,
schemaCacheKey: e.schemaCacheKey,
configSchema: e.configSchema,
configUiHints: e.manifest.uiHints,
configGroups: e.manifest.configGroups,
contracts: mergeManifestContracts(e.manifest.contracts, r?.contracts),
transcriptSources: e.manifest.transcriptSources,
decisionModels: e.manifest.decisionModels,
mediaUnderstandingProviderMetadata: e.manifest.mediaUnderstandingProviderMetadata,
imageGenerationProviderMetadata: e.manifest.imageGenerationProviderMetadata,
videoGenerationProviderMetadata: e.manifest.videoGenerationProviderMetadata,
musicGenerationProviderMetadata: e.manifest.musicGenerationProviderMetadata,
toolMetadata: e.manifest.toolMetadata,
configContracts: e.manifest.configContracts,
channelConfigs: i,
...e.candidate.packageManifest?.channel?.id ? { channelCatalogMeta: {
id: e.candidate.packageManifest.channel.id,
...typeof e.candidate.packageManifest.channel.label === "string" ? { label: e.candidate.packageManifest.channel.label } : {},
...typeof e.candidate.packageManifest.channel.blurb === "string" ? { blurb: e.candidate.packageManifest.channel.blurb } : {},
...e.candidate.packageManifest.channel.preferOver ? { preferOver: e.candidate.packageManifest.channel.preferOver } : {},
...a ? { commands: a } : {}
} } : {}
};
}
function buildBundleManifestRecord(e) {
return {
id: e.manifest.id,
name: normalizeOptionalString(e.manifest.name) ?? e.candidate.idHint,
description: normalizeOptionalString(e.manifest.description),
...resolvePortablePluginIcons({
rootDir: e.candidate.rootDir,
rejectHardlinks: e.rejectHardlinks
}),
version: normalizeOptionalString(e.manifest.version),
packageName: e.candidate.packageName,
packageVersion: e.candidate.packageVersion,
packageDescription: e.candidate.packageDescription,
packageManifest: e.candidate.packageManifest,
packageDependencies: e.candidate.packageDependencies,
packageOptionalDependencies: e.candidate.packageOptionalDependencies,
packageChannel: e.candidate.packageManifest?.channel,
packageInstall: e.candidate.packageManifest?.install,
format: "bundle",
bundleFormat: e.candidate.bundleFormat,
bundleCapabilities: e.manifest.capabilities,
...e.manifest.onboardingSkill ? { onboardingSkill: e.manifest.onboardingSkill } : {},
activation: e.manifest.activation,
channels: [],
providers: [],
cliBackends: [],
syntheticAuthRefs: [],
nonSecretAuthMarkers: [],
skills: e.manifest.skills ?? [],
settingsFiles: e.manifest.settingsFiles ?? [],
hooks: e.manifest.hooks ?? [],
origin: e.candidate.origin,
workspaceDir: e.candidate.workspaceDir,
rootDir: e.candidate.rootDir,
source: e.candidate.source,
manifestPath: e.manifestPath,
schemaCacheKey: void 0,
configSchema: void 0,
configUiHints: void 0,
configContracts: void 0,
channelConfigs: void 0
};
}
//#endregion
//#region src/plugins/manifest-registry-build.ts
function rejectCaseFoldedIdCollisions(e, t) {
const n = /* @__PURE__ */ new Set();
for (const [r, i] of groupPluginRecords(e, (e) => normalizePluginPolicyId(e.id))) {
const e = [...new Set(i.map((e) => e.id))].toSorted();
if (e.length < 2) continue;
const a = `plugin ids ${e.map((e) => JSON.stringify(e)).join(", ")} collide as normalized id ${JSON.stringify(r)}; refusing all colliding plugins`;
for (const e of i) {
n.add(e);
t.push({
level: "error",
pluginId: e.id,
source: e.source,
message: a
});
}
}
return e.filter((e) => !n.has(e));
}
function pushNonBundledChannelConfigDescriptorDiagnostic(e) {
if (e.record.origin === "bundled" || e.record.format === "bundle") return;
const t = normalizePluginPolicyId(e.record.id);
const n = e.normalized?.entries[t];
if (e.normalized?.enabled === false || n?.enabled === false || e.normalized?.deny.includes(t) || e.normalized?.allow.length && !e.normalized.allow.includes(t)) return;
const r = e.record.channels.map((e) => e.trim()).filter((e) => e.length > 0);
if (r.length === 0) return;
const i = e.record.channelConfigs ?? {};
const a = r.filter((e) => !Object.hasOwn(i, e));
if (a.length === 0) return;
const o = a.map(sanitizeForLog);
e.diagnostics.push({
level: "warn",
pluginId: sanitizeForLog(e.record.id),
source: sanitizeForLog(e.record.manifestPath),
message: `channel plugin manifest declares ${o.join(", ")} without channelConfigs metadata; add openclaw.plugin.json#channelConfigs so config schema and setup surfaces work before runtime loads. Channels without channelConfigs still appear in channel listings, but setup UI may be limited.`
});
}
function dedupePluginDiagnostics(e, t) {
return dedupeByKey(e, (e) => JSON.stringify([
e.level,
e.pluginId ?? "",
e.message,
e.level === "error" || t.has(e) ? e.source ?? "" : ""
]));
}
function isStaleForeignBundledPin(e) {
return isForeignBundledPluginRoot(e.candidate.rootDir, e.env) && !isBundledPluginInsideDevSourceRoot({
rootDir: e.candidate.rootDir,
env: e.env
});
}
function resolveDuplicatePrecedenceRank(e) {
if (e.candidate.origin === "config" || e.candidate.configSelected) return 0;
if (e.candidate.origin === "bundled" && isBundledPluginInsideDevSourceRoot({
rootDir: e.candidate.rootDir,
env: e.env
})) return 1;
if (e.candidate.origin === "global" && !isStaleForeignBundledPin({
candidate: e.candidate,
env: e.env
}) && matchesInstalledPluginRecord(e)) return 2;
if (e.candidate.origin === "bundled") return 3;
if (e.candidate.origin === "workspace") return 4;
return 5;
}
function isSameGlobalPackageDuplicate(e, t) {
if (e.origin !== "global" || t.origin !== "global") return false;
const n = normalizeOptionalString(e.packageName);
const r = normalizeOptionalString(t.packageName);
if (!n || n !== r) return false;
const i = normalizeOptionalString(e.packageVersion);
const a = normalizeOptionalString(t.packageVersion);
return Boolean(i && a && i === a);
}
function buildPluginManifestRegistry(e) {
const t = e.config ?? {};
const n = normalizePluginsConfigWithResolverCore(t.plugins);
const r = e.env ?? process.env;
const i = e.registryPath ?? resolveInstalledPluginIndexStorePath({ env: r });
const { getInstallRecords: a } = e;
const o = e.candidates ? {
candidates: e.candidates,
diagnostics: e.diagnostics ?? []
} : e.discovery ?? discoverOpenClawPlugins({
workspaceDir: e.workspaceDir,
extraPaths: n.loadPaths,
env: r,
installRecords: a()
});
const s = new Set(o.diagnostics);
const c = [...s];
const l = o.candidates.toSorted((e, t) => Number(t.origin === "config" || t.configSelected === true) - Number(e.origin === "config" || e.configSelected === true));
const u = /* @__PURE__ */ new Map();
const d = /* @__PURE__ */ new Map();
const f = /* @__PURE__ */ new Set();
const p = resolveCompatibilityHostVersion(r);
const m = new Set(n.loadPaths.map((e) => resolveUserPath(e, r)).filter((e) => pluginCacheStatSync(e)?.isFile() === true).map((e) => path.resolve(e)));
for (const t of l) {
const n = shouldRejectHardlinkedPluginFiles({
origin: t.origin,
rootDir: t.rootDir,
env: r
});
const o = (t.format ?? "openclaw") === "bundle";
const s = t.origin === "config" && m.has(path.resolve(t.source)) && !pluginCacheExistsSync(path.join(t.rootDir, "openclaw.plugin.json"));
if (s && isCoreReservedPluginId(t.idHint)) {
c.push({
level: "error",
pluginId: t.idHint,
source: t.source,
message: `plugin manifest id "${t.idHint}" is reserved by OpenClaw core`
});
continue;
}
const l = t.origin === "bundled" && t.bundledManifest && t.bundledManifestPath ? {
ok: true,
manifest: t.bundledManifest,
manifestPath: t.bundledManifestPath
} : o && t.bundleFormat ? loadBundleManifest({
rootDir: t.rootDir,
bundleFormat: t.bundleFormat,
rejectHardlinks: n
}) : s ? {
ok: true,
manifest: {
id: t.idHint,
configSchema: {
type: "object",
additionalProperties: false
},
activation: { onStartup: true }
},
manifestPath: t.source
} : loadPluginManifest(t.rootDir, n);
if (!l.ok) {
c.push({
level: "error",
pluginId: t.diagnosticIdHint ?? t.idHint,
message: l.error,
source: l.manifestPath,
..."diagnosticCode" in l && l.diagnosticCode ? { code: l.diagnosticCode } : {}
});
continue;
}
if ("warnings" in l && l.warnings) d.set(l.manifestPath, l.warnings);
const h = l.manifest;
const g = t.effectivePluginId ?? h.id;
if (t.origin !== "bundled") {
const e = path.join(t.packageDir ?? t.rootDir, "package.json");
const n = t.origin === "global" && matchesInstalledPluginRecord({
candidate: t,
env: r,
installRecords: a()
});
const i = checkMinHostVersion({
currentVersion: p,
minHostVersion: t.packageManifest?.install?.minHostVersion,
allowLegacyBareSemver: n
});
if (!i.ok) {
c.push({
level: i.kind === "invalid" ? "error" : "warn",
pluginId: g,
source: e,
message: i.kind === "invalid" ? `plugin manifest invalid | ${i.error}` : i.kind === "unknown_host_version" ? `plugin requires OpenClaw >=${i.requirement.minimumLabel}, but this host version could not be determined; skipping load` : `plugin requires OpenClaw >=${i.requirement.minimumLabel}, but this host is ${i.currentVersion}; skipping load`
});
continue;
}
const o = resolvePackagePluginApiRange(t.packageManifest);
if (!o.ok) {
c.push({
level: "error",
pluginId: g,
source: e,
message: `plugin manifest invalid | ${o.error}`
});
continue;
}
const s = o.range;
if (s && !satisfiesPluginApiRange(p, s)) {
c.push({
level: "warn",
configDisposition: "preserve",
pluginId: g,
source: e,
message: `plugin requires plugin API ${s}, but this host is ${p}; skipping load (check "openclaw --version", OPENCLAW_COMPATIBILITY_HOST_VERSION, or run "openclaw doctor")`
});
continue;
}
}
const _ = "configSchema" in h ? h.configSchema : void 0;
const v = (() => {
if (!_ || s) return;
const e = readPluginCacheFile({
rootDir: t.rootDir,
relativePath: path.relative(t.rootDir, l.manifestPath),
rejectHardlinks: n,
maxBytes: 262144
});
return e.ok ? `${l.manifestPath}:${e.hash}` : l.manifestPath;
})();
const y = o ? buildBundleManifestRecord({
manifest: h,
candidate: t,
manifestPath: l.manifestPath,
rejectHardlinks: n
}) : buildPluginManifestRecord({
manifest: h,
candidate: t,
manifestPath: l.manifestPath,
diagnostics: c,
rejectHardlinks: n,
schemaCacheKey: v,
configSchema: _,
trust: resolvePluginTrust({
registryPath: i,
candidate: t,
env: r,
installRecords: a()
}),
...e.bundledChannelConfigCollector ? { bundledChannelConfigCollector: e.bundledChannelConfigCollector } : {}
});
if (t.sourcePreferred || t.origin === "bundled" && t.configSelected) y.sourcePreferred = true;
recordPluginManifestInstallOwner(y, resolvePluginCandidateInstallOwner(t), isPluginCandidateInstallOwnerAmbiguous(t));
const b = u.get(g);
if (b) {
const e = b.candidate.rootDir === t.rootDir;
if ((() => {
if (e) return true;
const n = pluginCacheRealpathSync(b.candidate.rootDir);
const r = pluginCacheRealpathSync(t.rootDir);
return Boolean(n && r && n === r);
})()) {
if (y.sourcePreferred || b.record.sourcePreferred) {
y.sourcePreferred = true;
b.record.sourcePreferred = true;
}
if (PLUGIN_ORIGIN_PRIORITIES[t.origin]?.explicit < PLUGIN_ORIGIN_PRIORITIES[b.candidate.origin]?.explicit) u.set(g, {
candidate: t,
record: y
});
continue;
}
const n = resolveDuplicatePrecedenceRank({
candidate: t,
env: r,
installRecords: a()
});
const i = resolveDuplicatePrecedenceRank({
candidate: b.candidate,
env: r,
installRecords: a()
});
const o = n < i;
const s = o ? t : b.candidate;
const l = o ? b.candidate : t;
if (o) u.set(g, {
candidate: t,
record: y
});
const d = b.candidate;
const p = a();
if ([[t, d], [d, t]].some(([e, t]) => matchesInstalledPluginRecord({
candidate: e,
env: r,
installRecords: p
}) && !isStaleForeignBundledPin({
candidate: e,
env: r
}) && t.origin === "bundled" && !isBundledPluginInsideDevSourceRoot({
rootDir: t.rootDir,
env: r
}))) continue;
if (isSameGlobalPackageDuplicate(t, b.candidate)) continue;
const m = s.origin === "bundled" && isStaleForeignBundledPin({
candidate: l,
env: r
}) && matchesInstalledPluginRecord({
candidate: l,
env: r,
installRecords: a()
});
const h = !m && Math.min(n, i) === 0 && n !== i;
if (h) {
if (f.has(g)) continue;
f.add(g);
}
c.push({
level: h ? "info" : "warn",
...h ? { code: "explicit-config-plugin-selection" } : {},
pluginId: g,
source: l.source,
message: m ? `stale plugin install record: "${g}" is pinned to ${l.rootDir}, which belongs to a different OpenClaw installation. This installation's bundled plugin is being used instead. No uninstall is needed to use the bundled plugin. Uninstalling, even with \`--keep-files\`, removes plugin configuration; re-enabling does not restore it.` : h ? `duplicate plugin id resolved by explicit config-selected plugin; ${l.origin} plugin will be overridden by config plugin (${s.source})` : `duplicate plugin id detected; ${l.origin} plugin will be overridden by ${s.origin} plugin (${s.source}); ignored plugin source: ${l.source}`
});
continue;
}
u.set(g, {
candidate: t,
record: y
});
}
const h = rejectCaseFoldedIdCollisions([...u.values()].map(({ record: e }) => e), c);
for (const e of h) {
for (const t of d.get(e.manifestPath) ?? []) c.push({
level: "warn",
pluginId: sanitizeForLog(e.id),
source: sanitizeForLog(e.manifestPath),
message: sanitizeForLog(t)
});
pushNonBundledChannelConfigDescriptorDiagnostic({
record: e,
diagnostics: c,
normalized: n
});
}
return {
plugins: h,
diagnostics: dedupePluginDiagnostics(c, s)
};
}
/** Load manifest metadata from the bundled/source plugin tree without consulting operator state. */
function loadBundledPluginManifestRegistry(e = {}) {
const t = e.env ?? process.env;
const n = {};
return buildPluginManifestRegistry({
env: t,
getInstallRecords: () => n,
discovery: discoverOpenClawPlugins({
env: t,
installRecords: n,
rootScope: "bundled",
...e.bundledRoot ? { bundledRoot: e.bundledRoot } : {}
})
});
}
//#endregion
export { resolvePluginManifestInstallOwner as i, loadBundledPluginManifestRegistry as n, isPluginManifestInstallOwnerAmbiguous as r, buildPluginManifestRegistry as t };