mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-21 10:01:37 -06:00
ba467fbd3e
* Install ClawHub packages for new Claw agents * test(claws): cover skill and plugin installation * docs(claws): document package artifacts * fix(claws): bind package trust preflight * fix(claws): bind package capability consent * fix(claws): satisfy package type guards * test(claws): update package installer fixtures * test(claws): complete package plan fixtures * test(claws): model complete ClawHub results * fix(claws): serialize plugin ownership changes * fix(claws): cover legacy plugin lifecycle updates * fix(claws): preserve legacy ClawHub update selectors * test(claws): type lifecycle lease mock * refactor(claws): isolate plugin update lifecycle * fix(claws): declare managed installer coordination * test(claws): preserve partial collision result * test(claws): clean installer temp dirs --------- Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { readClawPackageRefs, type PersistedClawPackageRef } from "../claws/provenance.js";
|
|
import type { PluginInstallRecord } from "../config/types.plugins.js";
|
|
import type { OpenClawStateDatabaseOptions } from "../state/openclaw-state-db.js";
|
|
|
|
function clawPackageRefMatchesPluginInstall(
|
|
ref: PersistedClawPackageRef,
|
|
pluginId: string,
|
|
record: PluginInstallRecord,
|
|
): boolean {
|
|
if (ref.kind !== "plugin" || ref.source !== "clawhub" || record.source !== "clawhub") {
|
|
return false;
|
|
}
|
|
const installedRef =
|
|
record.clawhubPackage ?? record.spec?.replace(/^clawhub:/i, "").replace(/@[^@]+$/, "");
|
|
return (installedRef ?? pluginId) === ref.ref;
|
|
}
|
|
|
|
/** Explain Claw dependents without blocking the operator-owned uninstall. */
|
|
export function collectClawPluginUninstallWarnings(params: {
|
|
pluginId: string;
|
|
installRecord?: PluginInstallRecord;
|
|
env?: OpenClawStateDatabaseOptions["env"];
|
|
}): string[] {
|
|
const installRecord = params.installRecord;
|
|
if (!installRecord || installRecord.source !== "clawhub") {
|
|
return [];
|
|
}
|
|
const refs = readClawPackageRefs({
|
|
kind: "plugin",
|
|
source: "clawhub",
|
|
...(params.env ? { env: params.env } : {}),
|
|
}).filter(
|
|
(ref) =>
|
|
ref.status !== "rolled_back" &&
|
|
clawPackageRefMatchesPluginInstall(ref, params.pluginId, installRecord),
|
|
);
|
|
const clawIds = [...new Set(refs.map((ref) => ref.clawName))].toSorted();
|
|
if (clawIds.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
const installedVersion = installRecord.resolvedVersion ?? installRecord.version;
|
|
const expectedVersions = [...new Set(refs.map((ref) => ref.version))].toSorted();
|
|
const drifted =
|
|
installedVersion !== undefined &&
|
|
expectedVersions.some((version) => version !== installedVersion);
|
|
|
|
const warnings = [
|
|
`Warning: plugin "${params.pluginId}" is referenced by Claw${clawIds.length === 1 ? "" : "s"}: ${clawIds.join(", ")}.`,
|
|
];
|
|
if (drifted) {
|
|
warnings.push(
|
|
`Installed version ${installedVersion} differs from the Claw reference${expectedVersions.length === 1 ? "" : "s"} ${expectedVersions.join(", ")}.`,
|
|
);
|
|
}
|
|
warnings.push(
|
|
"Uninstalling it may break those Claws until the plugin is reinstalled or the Claws are updated.",
|
|
);
|
|
return warnings;
|
|
}
|