openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
872 lines (871 loc) • 36 kB
JavaScript
import "./redact-BDinS1q9.js";
import "./errors-BxyFnvP3.js";
import "./unhandled-rejections-CDJ8dOVP.js";
import "./logger-kwZIqwuw.js";
import { _ as resolveStateDir } from "./paths-ViKUYWUK.js";
import "./tmp-openclaw-dir-idKIOMmb.js";
import { r as theme } from "./theme-CdOoMzRk.js";
import "./globals-DBUMOBZ8.js";
import { m as defaultRuntime } from "./subsystem-DISldKSB.js";
import "./ansi-BEJF8NKS.js";
import "./boolean-C3GkJetE.js";
import "./env-Dnra1IpT.js";
import "./warning-filter-CBhOcgHd.js";
import { S as shortenHomePath, x as shortenHomeInString } from "./utils-CS0Ikux6.js";
import { t as formatDocsLink } from "./links-8xRhWBQL.js";
import "./paths-C4Oy7wjk.js";
import "./auth-profiles-DRuJBw5y.js";
import "./agent-scope-bjWqU22i.js";
import "./boundary-path-Dm0QJ7-y.js";
import "./boundary-file-read-DcZxlWD8.js";
import "./logger-BmpSCz93.js";
import "./exec-B5_AYfQG.js";
import "./workspace-D4K6QX9X.js";
import "./model-selection-BnFtDmP7.js";
import { g as writeConfigFile, s as loadConfig } from "./io-y3Az_Onx.js";
import "./shell-env-BOu7XeT_.js";
import "./safe-text-yavot2qw.js";
import "./version-CD3oP1-d.js";
import "./env-substitution-O6uabUmO.js";
import "./includes-Bj3eLUWH.js";
import "./zod-schema.providers-core-COy5nBQ0.js";
import "./legacy-web-search-BB-ZHEhz.js";
import "./registry-C5UkPpaO.js";
import { l as defaultSlotIdForKey } from "./config-state-Br0ucqMb.js";
import "./min-host-version-RMBWtIAR.js";
import { o as resolvePluginSourceRoots } from "./manifest-registry-B5JNQdOM.js";
import "./runtime-guard-PhQ6PwQa.js";
import "./avatar-policy-B5nOfso_.js";
import "./ip-Ce8EDTBZ.js";
import "./zod-schema.agent-runtime-Dtg4Jy6G.js";
import "./zod-schema.core-BuVz8Rk7.js";
import "./config-D4zN4BRl.js";
import "./file-lock-DEiVq2ow.js";
import "./audit-fs-DTQIjp2r.js";
import "./resolve-B7S4PlnO.js";
import "./profiles-COPO-hHI.js";
import { u as promptYesNo } from "./tailscale-CxY-91GZ.js";
import "./tailnet-DHiKSG7V.js";
import "./net-JAg9zL0G.js";
import "./auth-Buq0Niri.js";
import "./credentials-D8pfRimu.js";
import "./message-channel-BliByQBl.js";
import "./store-C5UK26Ce.js";
import "./runtime-Iz8uZ7EU.js";
import "./plugins-B09-vgme.js";
import "./sessions-D9ZgHCHb.js";
import "./paths-rhN9LKM_.js";
import "./session-write-lock-va3qZE6f.js";
import "./method-scopes-BiEi0X2g.js";
import "./call-CQbSO4Fr.js";
import "./prompt-style-C4CV4Y_p.js";
import "./ports-lsof-BLEgL_Gn.js";
import "./restart-stale-pids-BsPvlGJd.js";
import "./ports-FldL_Lhq.js";
import "./logging-CznuqaMu.js";
import "./commands-C6oAw_H-.js";
import "./issue-format-BtLIwOtN.js";
import "./identity-Dp-UIak4.js";
import "./heartbeat-Bdfr_onc.js";
import "./pi-embedded-CbCYZxIb.js";
import "./internal-hooks-CIUghoK4.js";
import "./multimodal-B8yEZcl5.js";
import "./memory-search-B_aq08y5.js";
import "./provider-catalog-rVN7ZbR5.js";
import "./secret-input-DXoOLNgb.js";
import "./bindings-CFudGB9Z.js";
import "./resolve-route-DwFWP4JW.js";
import "./routing-zOQ0wwtV.js";
import "./identity-file-DVLib087.js";
import "./outbound-runtime-m-y0nd6F.js";
import "./provider-env-vars-CpUJqT5v.js";
import "./provider-auth-input-Bus9W_qh.js";
import "./provider-model-minimax-DSmX4BNO.js";
import "./provider-models-BKjzpTsb.js";
import "./anthropic-vertex-provider-B2x4YywE.js";
import "./provider-catalog-BTgF8VyO.js";
import "./provider-catalog-D0IlX18O.js";
import "./provider-catalog-BTmUX0Mp.js";
import "./provider-catalog-sph_Rl63.js";
import "./provider-catalog-C7tUyBwV.js";
import "./provider-catalog-C8dPZpHW.js";
import "./provider-catalog-BJNff1VI.js";
import "./provider-catalog-IAdymoqT.js";
import "./provider-catalog-Bjc7evzh.js";
import "./models-config.providers.discovery-CjkO08q6.js";
import "./text-runtime-DVXt5xhi.js";
import "./tool-catalog-BjSY4C4F.js";
import "./docker-Bhjg8g2t.js";
import "./sandbox-DTlKNieF.js";
import "./common-zReYuoMM.js";
import "./image-ops-By4YfyWa.js";
import "./thinking-CJoSRIGR.js";
import "./path-alias-guards-CwRM04O1.js";
import "./sandbox-paths-Cn8i8Jxm.js";
import "./channel-actions-fV93bLjV.js";
import "./mime-CsUtzcn2.js";
import "./ssrf-0bPJMoZR.js";
import "./fetch-guard-CYl1q2XH.js";
import { n as enablePluginInConfig, r as setPluginEnabledInConfig } from "./provider-web-search-COZNygbd.js";
import "./manager-Bw8JrihM.js";
import "./config-schema-CPzP2Ds6.js";
import "./channel-plugin-common-ClptUZHU.js";
import "./status-helpers-Cflmo90d.js";
import "./conversation-runtime-nmWgJSXS.js";
import "./runtime-whatsapp-boundary-XjdkYMz_.js";
import "./pairing-store-BGKLrjo6.js";
import "./json-store--JDX3zNL.js";
import "./secret-file-Bif7RlZ-.js";
import "./channel-config-schema-CgpS17zB.js";
import "./setup-binary-C2MYZTCc.js";
import "./archive-pOxyr9r4.js";
import "./fs-safe-DZyOgpPN.js";
import "./signal-cli-install-fVOL9FvX.js";
import "./setup-wizard-proxy-DoOpOF8S.js";
import "./setup-BI3ohdrT.js";
import "./dm-policy-shared-DtcQProI.js";
import "./runtime-env-DQOYrXVl.js";
import "./temp-path-B91lt0LF.js";
import "./diagnostic-CDTtMQBT.js";
import "./logging-CCTKg_fh.js";
import "./config-runtime-BYNizC50.js";
import "./level-overrides-DzIzQ3ZY.js";
import "./exec-approvals-BF_Qfdq8.js";
import "./webhook-ingress-D-H5frou.js";
import "./system-events-BU_NYynX.js";
import "./ssrf-policy-DYINyIKC.js";
import "./hook-runtime-BUYmDbaA.js";
import "./templating-BDXRiJUh.js";
import "./channel-reply-pipeline-BxH4-AP2.js";
import "./reply-history-n7nOPLta.js";
import "./commands-registry.data-BFXJWoqi.js";
import "./commands-registry-Bh9pJ817.js";
import "./frontmatter-CP5371Rm.js";
import "./env-overrides-BNSo89u5.js";
import "./skills-M0AZJeXx.js";
import "./skills-remote-BHxDA4Jw.js";
import "./workspace-dirs-DqDLiRvZ.js";
import "./pairing-token-DAszGmwD.js";
import "./skill-commands-D73dGR_l.js";
import "./config-CLRQPUSt.js";
import "./routes-XT2JfvT-.js";
import "./ssh-tunnel-LM52qY6N.js";
import "./server-middleware-BP59C6FL.js";
import "./provider-auth-ref-CQEp9sp3.js";
import "./provider-auth-helpers-Do3RFvdi.js";
import "./provider-api-key-auth-BEeRW3dq.js";
import "./pairing-labels-D27Y4Vv6.js";
import "./directory-runtime-D9Y42mW-.js";
import "./read-only-account-inspect-CJPRBFj7.js";
import "./src-BoNU6eQs.js";
import "./web-media-PKy3RbRG.js";
import "./media-understanding-BDOSvuM9.js";
import "./web-media-CiSbdGPs.js";
import "./state-paths-Dvb3Mfl3.js";
import "./llm-task-Br6Ixjlh.js";
import "./pi-model-discovery-DO3tFksS.js";
import "./exec-inline-eval-CpmxWJsW.js";
import "./target-registry-9OUOvlxj.js";
import "./external-content-DZI9vlJn.js";
import "./brave-onFD06fq.js";
import "./duckduckgo-CZuAOfiQ.js";
import "./exa-5bwgY04k.js";
import "./security-runtime-xlw0Fxx2.js";
import "./provider-usage-ClxTGn5c.js";
import "./provider-models-Bjv0V4OP.js";
import "./media-understanding-provider-DllGbg-v.js";
import "./media-understanding-provider-BDq4rFL-.js";
import "./provider-onboard-CSnPvkMM.js";
import "./onboard-BU8aRvq7.js";
import "./perplexity-web-search-provider-CI38RNUU.js";
import "./perplexity-CMZbsreI.js";
import "./model-definitions-CLagLj0g.js";
import "./onboard-0P7GBI2D.js";
import "./provider-catalog-CKHo9CRM.js";
import "./provider-models-Dmjtw6kn.js";
import "./stream-C-KGzzT0.js";
import "./web-search-CO1hvu_l.js";
import "./stagger-CFqdtCYL.js";
import "./command-secret-targets-DLs8jC2H.js";
import "./delivery-queue-DHURMSqX.js";
import "./channel-summary-Ctrv7moa.js";
import "./follow-redirects-CVAaqIk4.js";
import "./tool-policy-match-DQWWRSN4.js";
import "./runtime-CAdCdG-M.js";
import "./channel-status-BfM90KqH.js";
import "./discord-core-DLbIyXWy.js";
import "./cli-runtime-Cx1v7N7v.js";
import "./config-presence-DA3j8Nmi.js";
import "./query-expansion-BOJBTXsp.js";
import "./search-manager-DNBHwaee.js";
import "./acp-runtime-BHZj-SLU.js";
import "./telegram-core-DD8gCuaX.js";
import "./audit-BI48Fi3j.js";
import "./gateway-runtime-Dn2qAGY7.js";
import "./connection-auth-Nl2a3tDb.js";
import "./mcp-config-CDIWSqVk.js";
import "./frontmatter-AzDGezO7.js";
import "./install-source-utils-C3NuFv6M.js";
import { f as logSlotWarnings, i as applySlotSelectionForPlugin, s as createPluginInstallLogger } from "./plugins-install-persist-BwIiVqib.js";
import { s as parseClawHubPluginSpec } from "./clawhub-CrF94Azs.js";
import { s as resolvePluginInstallDir } from "./installs-Qst5vOrV.js";
import "./clawhub-DS9sebNq.js";
import { a as buildPluginStatusReport, i as buildPluginInspectReport, n as buildPluginCompatibilityNotices, o as formatPluginCompatibilityNotice, t as buildAllPluginInspectReports } from "./status-DI5hmNdJ.js";
import "./plugin-install-plan-L6kxUjNd.js";
import "./bundled-sources-xtMJNHi6.js";
import { n as renderTable, t as getTerminalTableWidth } from "./table-7g_hocqO.js";
import { n as runPluginInstallCommand, t as runPluginUpdateCommand } from "./plugins-update-command-CwlygFKD.js";
import { o as listMarketplacePlugins } from "./update-DfP886uW.js";
import path from "node:path";
import os from "node:os";
import fs from "node:fs/promises";
//#region src/plugins/source-display.ts
function tryRelative(root, filePath) {
const rel = path.relative(root, filePath);
if (!rel || rel === ".") return null;
if (rel === "..") return null;
if (rel.startsWith(`..${path.sep}`) || rel.startsWith("../") || rel.startsWith("..\\")) return null;
if (path.isAbsolute(rel)) return null;
return rel.replaceAll("\\", "/");
}
function formatPluginSourceForTable(plugin, roots) {
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"
};
}
return { value: shortenHomeInString(raw) };
}
//#endregion
//#region src/plugins/uninstall.ts
function resolveUninstallDirectoryTarget(params) {
if (!params.hasInstall) return null;
if (params.installRecord?.source === "path") return null;
let defaultPath;
try {
defaultPath = resolvePluginInstallDir(params.pluginId, params.extensionsDir);
} catch {
return null;
}
const configuredPath = params.installRecord?.installPath;
if (!configuredPath) return defaultPath;
if (path.resolve(configuredPath) === path.resolve(defaultPath)) return configuredPath;
return defaultPath;
}
/**
* Remove plugin references from config (pure config mutation).
* Returns a new config with the plugin removed from entries, installs, allow, load.paths, and slots.
*/
function removePluginFromConfig(cfg, pluginId) {
const actions = {
entry: false,
install: false,
allowlist: false,
loadPath: false,
memorySlot: false
};
const pluginsConfig = cfg.plugins ?? {};
let entries = pluginsConfig.entries;
if (entries && pluginId in entries) {
const { [pluginId]: _, ...rest } = entries;
entries = Object.keys(rest).length > 0 ? rest : void 0;
actions.entry = true;
}
let installs = pluginsConfig.installs;
const installRecord = installs?.[pluginId];
if (installs && pluginId in installs) {
const { [pluginId]: _, ...rest } = installs;
installs = Object.keys(rest).length > 0 ? rest : void 0;
actions.install = true;
}
let allow = pluginsConfig.allow;
if (Array.isArray(allow) && allow.includes(pluginId)) {
allow = allow.filter((id) => id !== pluginId);
if (allow.length === 0) allow = void 0;
actions.allowlist = true;
}
let load = pluginsConfig.load;
if (installRecord?.source === "path" && installRecord.sourcePath) {
const sourcePath = installRecord.sourcePath;
const loadPaths = load?.paths;
if (Array.isArray(loadPaths) && loadPaths.includes(sourcePath)) {
const nextLoadPaths = loadPaths.filter((p) => p !== sourcePath);
load = nextLoadPaths.length > 0 ? {
...load,
paths: nextLoadPaths
} : void 0;
actions.loadPath = true;
}
}
let slots = pluginsConfig.slots;
if (slots?.memory === pluginId) {
slots = {
...slots,
memory: defaultSlotIdForKey("memory")
};
actions.memorySlot = true;
}
if (slots && Object.keys(slots).length === 0) slots = void 0;
const cleanedPlugins = {
...pluginsConfig,
entries,
installs,
allow,
load,
slots
};
if (cleanedPlugins.entries === void 0) delete cleanedPlugins.entries;
if (cleanedPlugins.installs === void 0) delete cleanedPlugins.installs;
if (cleanedPlugins.allow === void 0) delete cleanedPlugins.allow;
if (cleanedPlugins.load === void 0) delete cleanedPlugins.load;
if (cleanedPlugins.slots === void 0) delete cleanedPlugins.slots;
return {
config: {
...cfg,
plugins: Object.keys(cleanedPlugins).length > 0 ? cleanedPlugins : void 0
},
actions
};
}
/**
* Uninstall a plugin by removing it from config and optionally deleting installed files.
* Linked plugins (source === "path") never have their source directory deleted.
*/
async function uninstallPlugin(params) {
const { config, pluginId, deleteFiles = true, extensionsDir } = params;
const hasEntry = pluginId in (config.plugins?.entries ?? {});
const hasInstall = pluginId in (config.plugins?.installs ?? {});
if (!hasEntry && !hasInstall) return {
ok: false,
error: `Plugin not found: ${pluginId}`
};
const installRecord = config.plugins?.installs?.[pluginId];
const isLinked = installRecord?.source === "path";
const { config: newConfig, actions: configActions } = removePluginFromConfig(config, pluginId);
const actions = {
...configActions,
directory: false
};
const warnings = [];
const deleteTarget = deleteFiles && !isLinked ? resolveUninstallDirectoryTarget({
pluginId,
hasInstall,
installRecord,
extensionsDir
}) : null;
if (deleteTarget) {
const existed = await fs.access(deleteTarget).then(() => true).catch(() => false) ?? false;
try {
await fs.rm(deleteTarget, {
recursive: true,
force: true
});
actions.directory = existed;
} catch (error) {
warnings.push(`Failed to remove plugin directory ${deleteTarget}: ${error instanceof Error ? error.message : String(error)}`);
}
}
return {
ok: true,
config: newConfig,
pluginId,
actions,
warnings
};
}
//#endregion
//#region src/cli/plugins-cli.ts
function resolvePluginUninstallId(params) {
const rawId = params.rawId.trim();
const plugin = params.plugins.find((entry) => entry.id === rawId || entry.name === rawId);
if (plugin) return {
pluginId: plugin.id,
plugin
};
for (const [pluginId, install] of Object.entries(params.config.plugins?.installs ?? {})) if (install.spec === rawId || install.resolvedSpec === rawId || install.resolvedName === rawId || install.marketplacePlugin === rawId) return { pluginId };
const requestedClawHub = parseClawHubPluginSpec(rawId);
if (requestedClawHub) {
for (const [pluginId, install] of Object.entries(params.config.plugins?.installs ?? {})) if ((install.clawhubPackage ?? parseClawHubPluginSpec(install.spec ?? "")?.name ?? parseClawHubPluginSpec(install.resolvedSpec ?? "")?.name) === requestedClawHub.name) return { pluginId };
}
return { pluginId: rawId };
}
function formatPluginLine(plugin, verbose = false) {
const status = plugin.status === "loaded" ? theme.success("loaded") : plugin.status === "disabled" ? theme.warn("disabled") : theme.error("error");
const name = theme.command(plugin.name || plugin.id);
const idSuffix = plugin.name && plugin.name !== plugin.id ? theme.muted(` (${plugin.id})`) : "";
const desc = plugin.description ? theme.muted(plugin.description.length > 60 ? `${plugin.description.slice(0, 57)}...` : plugin.description) : theme.muted("(no description)");
const format = plugin.format ?? "openclaw";
if (!verbose) return `${name}${idSuffix} ${status} ${theme.muted(`[${format}]`)} - ${desc}`;
const parts = [
`${name}${idSuffix} ${status}`,
` format: ${format}`,
` source: ${theme.muted(shortenHomeInString(plugin.source))}`,
` origin: ${plugin.origin}`
];
if (plugin.bundleFormat) parts.push(` bundle format: ${plugin.bundleFormat}`);
if (plugin.version) parts.push(` version: ${plugin.version}`);
if (plugin.providerIds.length > 0) parts.push(` providers: ${plugin.providerIds.join(", ")}`);
if (plugin.error) parts.push(theme.error(` error: ${plugin.error}`));
return parts.join("\n");
}
function formatInspectSection(title, lines) {
if (lines.length === 0) return [];
return [
"",
theme.muted(`${title}:`),
...lines
];
}
function formatCapabilityKinds(capabilities) {
if (capabilities.length === 0) return "-";
return capabilities.map((entry) => entry.kind).join(", ");
}
function formatHookSummary(params) {
const parts = [];
if (params.usesLegacyBeforeAgentStart) parts.push("before_agent_start");
const nonLegacyTypedHookCount = params.typedHookCount - (params.usesLegacyBeforeAgentStart ? 1 : 0);
if (nonLegacyTypedHookCount > 0) parts.push(`${nonLegacyTypedHookCount} typed`);
if (params.customHookCount > 0) parts.push(`${params.customHookCount} custom`);
return parts.length > 0 ? parts.join(", ") : "-";
}
function formatInstallLines(install) {
if (!install) return [];
const lines = [`Source: ${install.source}`];
if (install.spec) lines.push(`Spec: ${install.spec}`);
if (install.sourcePath) lines.push(`Source path: ${shortenHomePath(install.sourcePath)}`);
if (install.installPath) lines.push(`Install path: ${shortenHomePath(install.installPath)}`);
if (install.version) lines.push(`Recorded version: ${install.version}`);
if (install.installedAt) lines.push(`Installed at: ${install.installedAt}`);
return lines;
}
function registerPluginsCli(program) {
const plugins = program.command("plugins").description("Manage OpenClaw plugins and extensions").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/plugins", "docs.openclaw.ai/cli/plugins")}\n`);
plugins.command("list").description("List discovered plugins").option("--json", "Print JSON").option("--enabled", "Only show enabled plugins", false).option("--verbose", "Show detailed entries", false).action((opts) => {
const report = buildPluginStatusReport();
const list = opts.enabled ? report.plugins.filter((p) => p.status === "loaded") : report.plugins;
if (opts.json) {
const payload = {
workspaceDir: report.workspaceDir,
plugins: list,
diagnostics: report.diagnostics
};
defaultRuntime.writeJson(payload);
return;
}
if (list.length === 0) {
defaultRuntime.log(theme.muted("No plugins found."));
return;
}
const loaded = list.filter((p) => p.status === "loaded").length;
defaultRuntime.log(`${theme.heading("Plugins")} ${theme.muted(`(${loaded}/${list.length} loaded)`)}`);
if (!opts.verbose) {
const tableWidth = getTerminalTableWidth();
const sourceRoots = resolvePluginSourceRoots({ workspaceDir: report.workspaceDir });
const usedRoots = /* @__PURE__ */ new Set();
const rows = list.map((plugin) => {
const desc = plugin.description ? theme.muted(plugin.description) : "";
const formattedSource = formatPluginSourceForTable(plugin, sourceRoots);
if (formattedSource.rootKey) usedRoots.add(formattedSource.rootKey);
const sourceLine = desc ? `${formattedSource.value}\n${desc}` : formattedSource.value;
return {
Name: plugin.name || plugin.id,
ID: plugin.name && plugin.name !== plugin.id ? plugin.id : "",
Format: plugin.format ?? "openclaw",
Status: plugin.status === "loaded" ? theme.success("loaded") : plugin.status === "disabled" ? theme.warn("disabled") : theme.error("error"),
Source: sourceLine,
Version: plugin.version ?? ""
};
});
if (usedRoots.size > 0) {
defaultRuntime.log(theme.muted("Source roots:"));
for (const key of [
"stock",
"workspace",
"global"
]) {
if (!usedRoots.has(key)) continue;
const dir = sourceRoots[key];
if (!dir) continue;
defaultRuntime.log(` ${theme.command(`${key}:`)} ${theme.muted(dir)}`);
}
defaultRuntime.log("");
}
defaultRuntime.log(renderTable({
width: tableWidth,
columns: [
{
key: "Name",
header: "Name",
minWidth: 14,
flex: true
},
{
key: "ID",
header: "ID",
minWidth: 10,
flex: true
},
{
key: "Format",
header: "Format",
minWidth: 9
},
{
key: "Status",
header: "Status",
minWidth: 10
},
{
key: "Source",
header: "Source",
minWidth: 26,
flex: true
},
{
key: "Version",
header: "Version",
minWidth: 8
}
],
rows
}).trimEnd());
return;
}
const lines = [];
for (const plugin of list) {
lines.push(formatPluginLine(plugin, true));
lines.push("");
}
defaultRuntime.log(lines.join("\n").trim());
});
plugins.command("inspect").alias("info").description("Inspect plugin details").argument("[id]", "Plugin id").option("--all", "Inspect all plugins").option("--json", "Print JSON").action((id, opts) => {
const cfg = loadConfig();
const report = buildPluginStatusReport({ config: cfg });
if (opts.all) {
if (id) {
defaultRuntime.error("Pass either a plugin id or --all, not both.");
return defaultRuntime.exit(1);
}
const inspectAll = buildAllPluginInspectReports({
config: cfg,
report
});
const inspectAllWithInstall = inspectAll.map((inspect) => ({
...inspect,
install: cfg.plugins?.installs?.[inspect.plugin.id]
}));
if (opts.json) {
defaultRuntime.writeJson(inspectAllWithInstall);
return;
}
const tableWidth = getTerminalTableWidth();
const rows = inspectAll.map((inspect) => ({
Name: inspect.plugin.name || inspect.plugin.id,
ID: inspect.plugin.name && inspect.plugin.name !== inspect.plugin.id ? inspect.plugin.id : "",
Status: inspect.plugin.status === "loaded" ? theme.success("loaded") : inspect.plugin.status === "disabled" ? theme.warn("disabled") : theme.error("error"),
Shape: inspect.shape,
Capabilities: formatCapabilityKinds(inspect.capabilities),
Compatibility: inspect.compatibility.length > 0 ? inspect.compatibility.map((entry) => entry.severity === "warn" ? `warn:${entry.code}` : entry.code).join(", ") : "none",
Bundle: inspect.bundleCapabilities.length > 0 ? inspect.bundleCapabilities.join(", ") : "-",
Hooks: formatHookSummary({
usesLegacyBeforeAgentStart: inspect.usesLegacyBeforeAgentStart,
typedHookCount: inspect.typedHooks.length,
customHookCount: inspect.customHooks.length
})
}));
defaultRuntime.log(renderTable({
width: tableWidth,
columns: [
{
key: "Name",
header: "Name",
minWidth: 14,
flex: true
},
{
key: "ID",
header: "ID",
minWidth: 10,
flex: true
},
{
key: "Status",
header: "Status",
minWidth: 10
},
{
key: "Shape",
header: "Shape",
minWidth: 18
},
{
key: "Capabilities",
header: "Capabilities",
minWidth: 28,
flex: true
},
{
key: "Compatibility",
header: "Compatibility",
minWidth: 24,
flex: true
},
{
key: "Bundle",
header: "Bundle",
minWidth: 14,
flex: true
},
{
key: "Hooks",
header: "Hooks",
minWidth: 20,
flex: true
}
],
rows
}).trimEnd());
return;
}
if (!id) {
defaultRuntime.error("Provide a plugin id or use --all.");
return defaultRuntime.exit(1);
}
const inspect = buildPluginInspectReport({
id,
config: cfg,
report
});
if (!inspect) {
defaultRuntime.error(`Plugin not found: ${id}`);
return defaultRuntime.exit(1);
}
const install = cfg.plugins?.installs?.[inspect.plugin.id];
if (opts.json) {
defaultRuntime.writeJson({
...inspect,
install
});
return;
}
const lines = [];
lines.push(theme.heading(inspect.plugin.name || inspect.plugin.id));
if (inspect.plugin.name && inspect.plugin.name !== inspect.plugin.id) lines.push(theme.muted(`id: ${inspect.plugin.id}`));
if (inspect.plugin.description) lines.push(inspect.plugin.description);
lines.push("");
lines.push(`${theme.muted("Status:")} ${inspect.plugin.status}`);
lines.push(`${theme.muted("Format:")} ${inspect.plugin.format ?? "openclaw"}`);
if (inspect.plugin.bundleFormat) lines.push(`${theme.muted("Bundle format:")} ${inspect.plugin.bundleFormat}`);
lines.push(`${theme.muted("Source:")} ${shortenHomeInString(inspect.plugin.source)}`);
lines.push(`${theme.muted("Origin:")} ${inspect.plugin.origin}`);
if (inspect.plugin.version) lines.push(`${theme.muted("Version:")} ${inspect.plugin.version}`);
lines.push(`${theme.muted("Shape:")} ${inspect.shape}`);
lines.push(`${theme.muted("Capability mode:")} ${inspect.capabilityMode}`);
lines.push(`${theme.muted("Legacy before_agent_start:")} ${inspect.usesLegacyBeforeAgentStart ? "yes" : "no"}`);
if (inspect.bundleCapabilities.length > 0) lines.push(`${theme.muted("Bundle capabilities:")} ${inspect.bundleCapabilities.join(", ")}`);
lines.push(...formatInspectSection("Capabilities", inspect.capabilities.map((entry) => `${entry.kind}: ${entry.ids.length > 0 ? entry.ids.join(", ") : "(registered)"}`)));
lines.push(...formatInspectSection("Typed hooks", inspect.typedHooks.map((entry) => entry.priority == null ? entry.name : `${entry.name} (priority ${entry.priority})`)));
lines.push(...formatInspectSection("Compatibility warnings", inspect.compatibility.map(formatPluginCompatibilityNotice)));
lines.push(...formatInspectSection("Custom hooks", inspect.customHooks.map((entry) => `${entry.name}: ${entry.events.join(", ")}`)));
lines.push(...formatInspectSection("Tools", inspect.tools.map((entry) => {
const names = entry.names.length > 0 ? entry.names.join(", ") : "(anonymous)";
return entry.optional ? `${names} [optional]` : names;
})));
lines.push(...formatInspectSection("Commands", inspect.commands));
lines.push(...formatInspectSection("CLI commands", inspect.cliCommands));
lines.push(...formatInspectSection("Services", inspect.services));
lines.push(...formatInspectSection("Gateway methods", inspect.gatewayMethods));
lines.push(...formatInspectSection("MCP servers", inspect.mcpServers.map((entry) => entry.hasStdioTransport ? entry.name : `${entry.name} (unsupported transport)`)));
lines.push(...formatInspectSection("LSP servers", inspect.lspServers.map((entry) => entry.hasStdioTransport ? entry.name : `${entry.name} (unsupported transport)`)));
if (inspect.httpRouteCount > 0) lines.push(...formatInspectSection("HTTP routes", [String(inspect.httpRouteCount)]));
const policyLines = [];
if (typeof inspect.policy.allowPromptInjection === "boolean") policyLines.push(`allowPromptInjection: ${inspect.policy.allowPromptInjection}`);
if (typeof inspect.policy.allowModelOverride === "boolean") policyLines.push(`allowModelOverride: ${inspect.policy.allowModelOverride}`);
if (inspect.policy.hasAllowedModelsConfig) policyLines.push(`allowedModels: ${inspect.policy.allowedModels.length > 0 ? inspect.policy.allowedModels.join(", ") : "(configured but empty)"}`);
lines.push(...formatInspectSection("Policy", policyLines));
lines.push(...formatInspectSection("Diagnostics", inspect.diagnostics.map((entry) => `${entry.level.toUpperCase()}: ${entry.message}`)));
lines.push(...formatInspectSection("Install", formatInstallLines(install)));
if (inspect.plugin.error) lines.push("", `${theme.error("Error:")} ${inspect.plugin.error}`);
defaultRuntime.log(lines.join("\n"));
});
plugins.command("enable").description("Enable a plugin in config").argument("<id>", "Plugin id").action(async (id) => {
const enableResult = enablePluginInConfig(loadConfig(), id);
let next = enableResult.config;
const slotResult = applySlotSelectionForPlugin(next, id);
next = slotResult.config;
await writeConfigFile(next);
logSlotWarnings(slotResult.warnings);
if (enableResult.enabled) {
defaultRuntime.log(`Enabled plugin "${id}". Restart the gateway to apply.`);
return;
}
defaultRuntime.log(theme.warn(`Plugin "${id}" could not be enabled (${enableResult.reason ?? "unknown reason"}).`));
});
plugins.command("disable").description("Disable a plugin in config").argument("<id>", "Plugin id").action(async (id) => {
await writeConfigFile(setPluginEnabledInConfig(loadConfig(), id, false));
defaultRuntime.log(`Disabled plugin "${id}". Restart the gateway to apply.`);
});
plugins.command("uninstall").description("Uninstall a plugin").argument("<id>", "Plugin id").option("--keep-files", "Keep installed files on disk", false).option("--keep-config", "Deprecated alias for --keep-files", false).option("--force", "Skip confirmation prompt", false).option("--dry-run", "Show what would be removed without making changes", false).action(async (id, opts) => {
const cfg = loadConfig();
const report = buildPluginStatusReport({ config: cfg });
const extensionsDir = path.join(resolveStateDir(process.env, os.homedir), "extensions");
const keepFiles = Boolean(opts.keepFiles || opts.keepConfig);
if (opts.keepConfig) defaultRuntime.log(theme.warn("`--keep-config` is deprecated, use `--keep-files`."));
const { plugin, pluginId } = resolvePluginUninstallId({
rawId: id,
config: cfg,
plugins: report.plugins
});
const hasEntry = pluginId in (cfg.plugins?.entries ?? {});
const hasInstall = pluginId in (cfg.plugins?.installs ?? {});
if (!hasEntry && !hasInstall) {
if (plugin) defaultRuntime.error(`Plugin "${pluginId}" is not managed by plugins config/install records and cannot be uninstalled.`);
else defaultRuntime.error(`Plugin not found: ${id}`);
return defaultRuntime.exit(1);
}
const install = cfg.plugins?.installs?.[pluginId];
const isLinked = install?.source === "path";
const preview = [];
if (hasEntry) preview.push("config entry");
if (hasInstall) preview.push("install record");
if (cfg.plugins?.allow?.includes(pluginId)) preview.push("allowlist entry");
if (isLinked && install?.sourcePath && cfg.plugins?.load?.paths?.includes(install.sourcePath)) preview.push("load path");
if (cfg.plugins?.slots?.memory === pluginId) preview.push(`memory slot (will reset to "memory-core")`);
const deleteTarget = !keepFiles ? resolveUninstallDirectoryTarget({
pluginId,
hasInstall,
installRecord: install,
extensionsDir
}) : null;
if (deleteTarget) preview.push(`directory: ${shortenHomePath(deleteTarget)}`);
const pluginName = plugin?.name || pluginId;
defaultRuntime.log(`Plugin: ${theme.command(pluginName)}${pluginName !== pluginId ? theme.muted(` (${pluginId})`) : ""}`);
defaultRuntime.log(`Will remove: ${preview.length > 0 ? preview.join(", ") : "(nothing)"}`);
if (opts.dryRun) {
defaultRuntime.log(theme.muted("Dry run, no changes made."));
return;
}
if (!opts.force) {
if (!await promptYesNo(`Uninstall plugin "${pluginId}"?`)) {
defaultRuntime.log("Cancelled.");
return;
}
}
const result = await uninstallPlugin({
config: cfg,
pluginId,
deleteFiles: !keepFiles,
extensionsDir
});
if (!result.ok) {
defaultRuntime.error(result.error);
return defaultRuntime.exit(1);
}
for (const warning of result.warnings) defaultRuntime.log(theme.warn(warning));
await writeConfigFile(result.config);
const removed = [];
if (result.actions.entry) removed.push("config entry");
if (result.actions.install) removed.push("install record");
if (result.actions.allowlist) removed.push("allowlist");
if (result.actions.loadPath) removed.push("load path");
if (result.actions.memorySlot) removed.push("memory slot");
if (result.actions.directory) removed.push("directory");
defaultRuntime.log(`Uninstalled plugin "${pluginId}". Removed: ${removed.length > 0 ? removed.join(", ") : "nothing"}.`);
defaultRuntime.log("Restart the gateway to apply changes.");
});
plugins.command("install").description("Install a plugin or hook pack (path, archive, npm spec, clawhub:package, or marketplace entry)").argument("<path-or-spec-or-plugin>", "Path (.ts/.js/.zip/.tgz/.tar.gz), npm package spec, or marketplace plugin name").option("-l, --link", "Link a local path instead of copying", false).option("--pin", "Record npm installs as exact resolved <name>@<version>", false).option("--marketplace <source>", "Install a Claude marketplace plugin from a local repo/path or git/GitHub source").action(async (raw, opts) => {
await runPluginInstallCommand({
raw,
opts
});
});
plugins.command("update").description("Update installed plugins and tracked hook packs").argument("[id]", "Plugin or hook-pack id (omit with --all)").option("--all", "Update all tracked plugins and hook packs", false).option("--dry-run", "Show what would change without writing", false).action(async (id, opts) => {
await runPluginUpdateCommand({
id,
opts
});
});
plugins.command("doctor").description("Report plugin load issues").action(() => {
const report = buildPluginStatusReport();
const errors = report.plugins.filter((p) => p.status === "error");
const diags = report.diagnostics.filter((d) => d.level === "error");
const compatibility = buildPluginCompatibilityNotices({ report });
if (errors.length === 0 && diags.length === 0 && compatibility.length === 0) {
defaultRuntime.log("No plugin issues detected.");
return;
}
const lines = [];
if (errors.length > 0) {
lines.push(theme.error("Plugin errors:"));
for (const entry of errors) lines.push(`- ${entry.id}: ${entry.error ?? "failed to load"} (${entry.source})`);
}
if (diags.length > 0) {
if (lines.length > 0) lines.push("");
lines.push(theme.warn("Diagnostics:"));
for (const diag of diags) {
const target = diag.pluginId ? `${diag.pluginId}: ` : "";
lines.push(`- ${target}${diag.message}`);
}
}
if (compatibility.length > 0) {
if (lines.length > 0) lines.push("");
lines.push(theme.warn("Compatibility:"));
for (const notice of compatibility) {
const marker = notice.severity === "warn" ? theme.warn("warn") : theme.muted("info");
lines.push(`- ${formatPluginCompatibilityNotice(notice)} [${marker}]`);
}
}
const docs = formatDocsLink("/plugin", "docs.openclaw.ai/plugin");
lines.push("");
lines.push(`${theme.muted("Docs:")} ${docs}`);
defaultRuntime.log(lines.join("\n"));
});
plugins.command("marketplace").description("Inspect Claude-compatible plugin marketplaces").command("list").description("List plugins published by a marketplace source").argument("<source>", "Local marketplace path/repo or git/GitHub source").option("--json", "Print JSON").action(async (source, opts) => {
const result = await listMarketplacePlugins({
marketplace: source,
logger: createPluginInstallLogger()
});
if (!result.ok) {
defaultRuntime.error(result.error);
return defaultRuntime.exit(1);
}
if (opts.json) {
defaultRuntime.writeJson({
source: result.sourceLabel,
name: result.manifest.name,
version: result.manifest.version,
plugins: result.manifest.plugins
});
return;
}
if (result.manifest.plugins.length === 0) {
defaultRuntime.log(`No plugins found in marketplace ${result.sourceLabel}.`);
return;
}
defaultRuntime.log(`${theme.heading("Marketplace")} ${theme.muted(result.manifest.name ?? result.sourceLabel)}`);
for (const plugin of result.manifest.plugins) {
const suffix = plugin.version ? theme.muted(` v${plugin.version}`) : "";
const desc = plugin.description ? ` - ${theme.muted(plugin.description)}` : "";
defaultRuntime.log(`${theme.command(plugin.name)}${suffix}${desc}`);
}
});
}
//#endregion
export { registerPluginsCli };