Files
openclaw/src/plugins/setup-registry.runtime.ts
T
Peter Steinberger 98e3f729bc refactor: remove dead plugin loader exports (#105937)
* refactor(plugins): trim activation and contract exports

* test(plugins): restore fixture cleanup

* refactor(plugins): trim install and loader exports

* test(plugins): fully reset loader caches

* refactor(plugins): trim metadata and catalog exports

* test(plugins): preserve catalog trust coverage

* refactor(plugins): trim provider and plugin exports

* refactor(plugins): trim runtime and tool exports

* test(plugins): update dead-export consumers

* test(plugins): remove empty dead-export suites

* refactor(plugins): align exports with split registry

* refactor(plugins): trim drifted loader exports

* style(plugins): format test fixtures

* refactor(scripts): use supported plugin APIs

* refactor(plugins): finish dead export cleanup

* chore(deadcode): refresh export baseline

* test(cli): mock production memory state

* chore(deadcode): sync latest export baseline

* fix(tests): keep plugin fixtures inside core

* chore(deadcode): refresh rebased export baseline

* chore(deadcode): sync current ratchets

* fix(plugins): retain reserved slot invariant

* fix(plugins): preserve dead-export invariants

* test(plugins): use neutral catalog query fixture

* test(plugins): satisfy catalog lint

* test(plugins): preserve integrity drift coverage

* fix(ci): register skill experience live proof
2026-07-13 01:29:33 -07:00

93 lines
2.8 KiB
TypeScript

/** Metadata lookup helpers for plugin setup CLI backend descriptors. */
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { isInstalledPluginEnabled } from "./installed-plugin-index.js";
import {
resolvePluginMetadataSnapshot,
type PluginMetadataSnapshot,
} from "./plugin-metadata-snapshot.js";
import { getActivePluginRegistryWorkspaceDirFromState } from "./runtime-state.js";
type SetupCliBackendDescriptorEntry = {
pluginId: string;
backend: {
id: string;
};
};
type SetupCliBackendDescriptorLookupParams = {
backend: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
};
type SetupCliBackendDescriptorCache = {
configFingerprint: string;
entries: SetupCliBackendDescriptorEntry[];
};
let cachedSetupCliBackendDescriptors: SetupCliBackendDescriptorCache | undefined;
function resolveMetadataSnapshotForSetupCliBackends(
params: Omit<SetupCliBackendDescriptorLookupParams, "backend"> = {},
): {
snapshot: PluginMetadataSnapshot;
cacheable: boolean;
} {
const env = params.env ?? process.env;
const workspaceDir = params.workspaceDir ?? getActivePluginRegistryWorkspaceDirFromState();
const snapshot = resolvePluginMetadataSnapshot({
config: params.config ?? {},
env,
...(workspaceDir !== undefined
? {
workspaceDir,
allowWorkspaceScopedCurrent: true,
}
: {}),
});
return {
snapshot,
cacheable: true,
};
}
function resolveSetupCliBackendDescriptors(
params: Omit<SetupCliBackendDescriptorLookupParams, "backend"> = {},
): SetupCliBackendDescriptorEntry[] {
const { snapshot, cacheable } = resolveMetadataSnapshotForSetupCliBackends(params);
const configFingerprint = snapshot.configFingerprint;
if (
cacheable &&
configFingerprint &&
cachedSetupCliBackendDescriptors?.configFingerprint === configFingerprint
) {
return cachedSetupCliBackendDescriptors.entries;
}
const entries = snapshot.plugins.flatMap((plugin) => {
if (!isInstalledPluginEnabled(snapshot.index, plugin.id)) {
return [];
}
return [...plugin.cliBackends, ...(plugin.setup?.cliBackends ?? [])].map(
(backendId) =>
({
pluginId: plugin.id,
backend: { id: backendId },
}) satisfies SetupCliBackendDescriptorEntry,
);
});
if (cacheable && configFingerprint) {
cachedSetupCliBackendDescriptors = { configFingerprint, entries };
}
return entries;
}
export function resolvePluginSetupCliBackendDescriptor(
params: SetupCliBackendDescriptorLookupParams,
) {
const normalized = normalizeProviderId(params.backend);
return resolveSetupCliBackendDescriptors(params).find(
(entry) => normalizeProviderId(entry.backend.id) === normalized,
);
}