mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 15:41:13 +00:00
* 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
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
/** Formats plugin source paths for user-facing status output. */
|
|
import path from "node:path";
|
|
import { isPathInside } from "../infra/path-guards.js";
|
|
import { shortenHomeInString } from "../utils.js";
|
|
import type { PluginRecord } from "./registry.js";
|
|
import type { PluginSourceRoots } from "./roots.js";
|
|
export { resolvePluginSourceRoots } from "./roots.js";
|
|
|
|
function tryRelative(root: string, filePath: string): string | null {
|
|
if (!isPathInside(root, filePath)) {
|
|
return null;
|
|
}
|
|
const rel = path.relative(root, filePath);
|
|
if (!rel || rel === ".") {
|
|
return null;
|
|
}
|
|
// Normalize to forward slashes for display (path.relative uses backslashes on Windows)
|
|
return rel.replaceAll("\\", "/");
|
|
}
|
|
|
|
/** Formats a plugin source path for status tables using known source roots. */
|
|
export function formatPluginSourceForTable(
|
|
plugin: Pick<PluginRecord, "source" | "origin">,
|
|
roots: PluginSourceRoots,
|
|
): { value: string; rootKey?: keyof PluginSourceRoots } {
|
|
const raw = plugin.source;
|
|
|
|
if (plugin.origin === "bundled" && roots.stock) {
|
|
const rel = tryRelative(roots.stock, raw);
|
|
if (rel) {
|
|
return { value: `stock:${rel}`, rootKey: "stock" };
|
|
}
|
|
}
|
|
if (plugin.origin === "workspace" && roots.workspace) {
|
|
const rel = tryRelative(roots.workspace, raw);
|
|
if (rel) {
|
|
return { value: `workspace:${rel}`, rootKey: "workspace" };
|
|
}
|
|
}
|
|
if (plugin.origin === "global" && roots.global) {
|
|
const rel = tryRelative(roots.global, raw);
|
|
if (rel) {
|
|
return { value: `global:${rel}`, rootKey: "global" };
|
|
}
|
|
}
|
|
|
|
// Keep this stable/pasteable; only ~-shorten.
|
|
return { value: shortenHomeInString(raw) };
|
|
}
|