openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1,016 lines (1,015 loc) • 19.5 kB
JavaScript
import { a as resolveCliParentCommandPath } from "./config-output-mode-B_Eb6adL.mjs";
import { n as getCommandPathWithRootOptions, s as hasFlag } from "./argv-CbnKpH-r.mjs";
import { i as resolveGatewayCommandPath } from "./gateway-run-argv-CMDDyZ3j.mjs";
import "./src-H3RMXyFL.mjs";
import { t as expectDefined } from "./expect-DDakjvvQ.mjs";
//#region src/cli/command-catalog.ts
const PASSIVE_STARTUP_POLICY = {
configGuard: "skip",
loadPlugins: "never",
ensureCliPath: false,
networkProxy: "bypass"
};
function hasCliOption(e, t) {
for (const n of e.slice(2)) {
if (n === "--") return false;
if (n === t || n.startsWith(`${t}=`)) return true;
}
return false;
}
const modelRunStartupPolicy = { configGuard: ({ options: e }) => e?.gateway === true && e.local !== true ? "validate" : "run" };
const serviceInstallStartupPolicy = {
configGuard: ({ options: e }) => e?.expectedRuntimePin !== void 0 || e?.restoreServiceCli !== void 0 ? "defer" : "run",
networkProxy: "bypass"
};
/** Command path registry used before Commander registration has loaded all plugins. */
const cliCommandCatalog = [
{
commandPath: ["setup"],
policy: {
configGuard: ({ argv: e, options: t }) => t?.reset === true || hasFlag(e, "--reset") ? "defer" : "skip",
loadPlugins: "never",
ensureCliPath: false
}
},
{
commandPath: ["qa"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["database"],
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true
}
},
{
commandPath: ["crestodian"],
policy: {
configGuard: "skip",
loadPlugins: "never",
ensureCliPath: false
}
},
{
commandPath: ["agent"],
policy: {
configGuard: ({ argv: e }) => hasFlag(e, "--local") ? "run" : "skip",
loadPlugins: ({ argv: e }) => hasFlag(e, "--local"),
pluginRegistry: { scope: "all" },
networkProxy: ({ argv: e }) => hasFlag(e, "--local") ? "default" : "bypass"
}
},
{
commandPath: ["agent", "exec"],
policy: {
configGuard: "skip",
loadPlugins: "never",
ownsProtocolStdout: true,
hideBanner: true,
networkProxy: "default"
}
},
{
commandPath: [
"infer",
"model",
"run"
],
policy: modelRunStartupPolicy
},
{
commandPath: [
"capability",
"model",
"run"
],
policy: modelRunStartupPolicy
},
{
commandPath: ["transcripts"],
policy: {
ownsProtocolStdout: true,
hideBanner: true
}
},
{
commandPath: ["message"],
policy: {
configGuard: "defer",
loadPlugins: "never"
}
},
{
commandPath: ["docs"],
policy: { configGuard: "skip" }
},
{
commandPath: ["reset"],
policy: { configGuard: "skip" }
},
{
commandPath: ["uninstall"],
policy: { configGuard: "skip" }
},
{
commandPath: ["channels"],
policy: {
loadPlugins: "always",
pluginRegistry: { scope: "configured-channels" }
}
},
{
commandPath: ["directory"],
policy: { loadPlugins: "always" }
},
{
commandPath: ["sandbox"],
policy: {
loadPlugins: ({ argv: e, commandPath: t }) => !((t[1] === "list" || t[1] === "recreate") && hasFlag(e, "--browser")),
pluginRegistry: { scope: "sandbox-backends" }
}
},
...["list", "recreate"].map((e) => ({
commandPath: ["sandbox", e],
policy: { pluginRegistry: { scope: "sandbox-management" } }
})),
{
commandPath: ["agents"],
policy: {
loadPlugins: "always",
networkProxy: "bypass"
}
},
{
commandPath: ["agents"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
},
route: { id: "agents-list" }
},
{
commandPath: ["agents", "bind"],
exact: true,
policy: { loadPlugins: "never" }
},
{
commandPath: ["agents", "bindings"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never"
}
},
...[["agents", "add"], [
"agents",
"team",
"create"
]].map((e) => ({
commandPath: e,
exact: true,
policy: {
configGuard: "defer",
loadPlugins: "never"
}
})),
...[
"unbind",
"set-identity",
"delete"
].map((e) => ({
commandPath: ["agents", e],
exact: true,
policy: { loadPlugins: "never" }
})),
{
commandPath: ["configure"],
policy: {
configGuard: "skip",
stateStoreGuard: "run",
loadPlugins: "never"
}
},
{
commandPath: ["config"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
...[
"create",
"validate",
"build",
"dev"
].map((e) => ({
commandPath: ["templates", e],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["migrate"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
...["status", "health"].map((e) => ({
commandPath: [e],
policy: {
...PASSIVE_STARTUP_POLICY,
pluginRegistry: { scope: "channels" }
},
route: { id: e }
})),
{
commandPath: ["telemetry"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["audit"],
policy: PASSIVE_STARTUP_POLICY
},
{
commandPath: ["gateway"],
policy: { networkProxy: ({ commandPath: e }) => e.length === 1 || e[1] === "run" ? "default" : "bypass" }
},
{
commandPath: ["gateway", "status"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
},
route: { id: "gateway-status" }
},
{
commandPath: ["gateway", "recover-lock"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["gateway", "call"],
exact: true,
policy: PASSIVE_STARTUP_POLICY
},
...["suspend", "resume"].map((e) => ({
commandPath: ["gateway", e],
exact: true,
policy: {
configGuard: "validate",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["gateway", "diagnostics"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["gateway", "discover"],
exact: true,
policy: { networkProxy: "bypass" }
},
{
commandPath: ["gateway", "health"],
exact: true,
policy: {
configGuard: "skip",
networkProxy: "bypass"
},
route: { id: "gateway-health" }
},
{
commandPath: ["gateway", "install"],
exact: true,
policy: serviceInstallStartupPolicy
},
...["probe", "start"].map((e) => ({
commandPath: ["gateway", e],
exact: true,
policy: { networkProxy: "bypass" }
})),
...[
"stability",
"stop",
"restart",
"uninstall",
"usage-cost"
].map((e) => ({
commandPath: ["gateway", e],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["sessions"],
exact: true,
policy: {
configGuard: "skip",
ensureCliPath: false,
ownsProtocolStdout: true,
networkProxy: "bypass"
},
route: { id: "sessions" }
},
{
commandPath: ["agents", "list"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
},
route: { id: "agents-list" }
},
{
commandPath: ["config", "file"],
exact: true,
policy: {
...PASSIVE_STARTUP_POLICY,
ownsProtocolStdout: true
}
},
{
commandPath: ["config", "get"],
exact: true,
policy: {
configGuard: "skip",
ensureCliPath: false,
networkProxy: "bypass"
},
route: { id: "config-get" }
},
{
commandPath: ["config", "unset"],
exact: true,
policy: {
configGuard: "defer",
loadPlugins: "never",
ensureCliPath: false,
networkProxy: "bypass"
},
route: { id: "config-unset" }
},
...["set", "patch"].map((e) => ({
commandPath: ["config", e],
exact: true,
policy: {
configGuard: "defer",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["models"],
exact: true,
policy: PASSIVE_STARTUP_POLICY,
route: { id: "models-status" }
},
...[
"refresh",
"set",
"set-image",
"aliases",
"fallbacks",
"image-fallbacks",
"scan"
].map((e) => ({ commandPath: ["models", e] })),
{
commandPath: ["models", "auth"],
policy: { stateStoreGuard: "run" }
},
{
commandPath: ["models", "accounts"],
policy: PASSIVE_STARTUP_POLICY
},
{
commandPath: ["models", "list"],
exact: true,
policy: {
configGuard: "skip",
ensureCliPath: false,
networkProxy: "bypass"
},
route: { id: "models-list" }
},
{
commandPath: ["models", "status"],
exact: true,
policy: {
ensureCliPath: false,
configGuard: "skip",
loadPlugins: "never",
networkProxy: ({ argv: e }) => hasFlag(e, "--probe") ? "default" : "bypass"
},
route: { id: "models-status" }
},
...["tool", "tools"].map((e) => ({
commandPath: [e],
policy: {
loadPlugins: "never",
ensureCliPath: false,
networkProxy: "bypass"
}
})),
{
commandPath: ["acp"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["acp"],
exact: true,
policy: { ownsProtocolStdout: true }
},
{
commandPath: ["approvals"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["approvals", "pending"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["automations"],
policy: {
configGuard: "skip",
networkProxy: "bypass"
}
},
{
commandPath: ["backup"],
policy: {
configGuard: "skip",
networkProxy: "bypass"
}
},
{
commandPath: ["chat"],
policy: { networkProxy: "default" }
},
{
commandPath: ["config"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["cron"],
policy: {
configGuard: "skip",
networkProxy: "bypass"
}
},
{
commandPath: ["dashboard"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["daemon"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["daemon", "install"],
exact: true,
policy: serviceInstallStartupPolicy
},
...[
"status",
"stop",
"restart",
"uninstall"
].map((e) => ({
commandPath: ["daemon", e],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["devices"],
policy: {
configGuard: "validate",
networkProxy: "bypass"
}
},
{
commandPath: ["worktrees"],
policy: {
configGuard: "validate",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["doctor"],
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: ({ argv: e }) => hasCliOption(e, "--state-sqlite") || hasCliOption(e, "--client-credentials") ? "bypass" : "default"
}
},
{
commandPath: ["triage"],
policy: {
configGuard: "skip",
loadPlugins: "never"
}
},
{
commandPath: ["exec-approvals"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["exec-policy"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["hooks"],
policy: { networkProxy: "bypass" }
},
...[
["hooks"],
["hooks", "list"],
["hooks", "info"],
["hooks", "check"]
].map((e) => ({
commandPath: e,
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["logs"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["mcp"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["mcp", "serve"],
exact: true,
policy: { ownsProtocolStdout: true }
},
{
commandPath: ["browser", "extension"],
policy: {
configGuard: "validate",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: [
"browser",
"extension",
"native-host"
],
exact: true,
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true,
ownsProtocolStdout: true
}
},
{
commandPath: ["node"],
policy: { networkProxy: "bypass" }
},
...[
"install",
"uninstall",
"start",
"stop",
"restart"
].map((e) => ({
commandPath: ["node", e],
exact: true,
policy: {
configGuard: "validate",
loadPlugins: "never"
}
})),
{
commandPath: ["node", "identity"],
exact: true,
policy: PASSIVE_STARTUP_POLICY
},
{
commandPath: ["node", "status"],
exact: true,
policy: PASSIVE_STARTUP_POLICY
},
{
commandPath: ["node", "worker"],
exact: true,
policy: {
configGuard: "validate",
hideBanner: true,
loadPlugins: "never",
ownsProtocolStdout: true,
networkProxy: "bypass"
}
},
{
commandPath: ["node", "run"],
exact: true,
policy: { networkProxy: "default" }
},
{
commandPath: ["connect"],
exact: true,
policy: { networkProxy: "default" }
},
{
commandPath: ["worker"],
exact: true,
policy: {
configGuard: "skip",
hideBanner: true,
loadPlugins: "never",
ownsProtocolStdout: true,
networkProxy: "bypass"
}
},
{
commandPath: ["nodes"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["nodes", "status"],
exact: true,
policy: { configGuard: "skip" }
},
{
commandPath: ["nodes", "list"],
exact: true,
policy: { configGuard: "skip" }
},
...[
"describe",
"pending",
"approve",
"reject",
"remove",
"rename",
"invoke",
"notify",
"push",
"camera",
"screen",
"location"
].map((e) => ({
commandPath: ["nodes", e],
policy: { configGuard: "validate" }
})),
{
commandPath: ["pairing"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["proxy"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["qr"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["reset"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["completion"],
policy: {
configGuard: "skip",
hideBanner: true,
networkProxy: "bypass"
}
},
{
commandPath: ["secrets"],
policy: {
configGuard: "skip",
networkProxy: "bypass"
}
},
{
commandPath: ["security"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["system"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["resume"],
policy: { networkProxy: "bypass" }
},
{
commandPath: ["terminal"],
policy: { networkProxy: "default" }
},
{
commandPath: ["tui"],
policy: { networkProxy: ({ argv: e }) => hasFlag(e, "--local") ? "default" : "bypass" }
},
{
commandPath: ["uninstall"],
policy: { networkProxy: "bypass" }
},
...[
"migrate",
"restore",
"finish"
].map((e) => ({
commandPath: ["update", e],
exact: true,
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true,
ownsProtocolStdout: true
}
})),
{
commandPath: ["update", "adopt-immutable"],
exact: true,
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true
}
},
{
commandPath: ["update", "cleanup"],
exact: true,
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true
}
},
{
commandPath: ["update"],
policy: {
configGuard: "skip",
hideBanner: true
}
},
...["admit", "preflight"].map((e) => ({
commandPath: ["update", e],
policy: {
...PASSIVE_STARTUP_POLICY,
hideBanner: true,
ownsProtocolStdout: true
}
})),
{
commandPath: ["config", "validate"],
exact: true,
policy: {
configGuard: "skip",
networkProxy: "bypass"
}
},
{
commandPath: ["config", "schema"],
exact: true,
policy: {
configGuard: "skip",
ownsProtocolStdout: true,
networkProxy: "bypass"
}
},
{
commandPath: ["plugins", "update"],
exact: true,
policy: { hideBanner: true }
},
{
commandPath: ["plugins", "list"],
exact: true,
policy: PASSIVE_STARTUP_POLICY,
route: { id: "plugins-list" }
},
{
commandPath: ["plugins", "lint"],
exact: true,
policy: PASSIVE_STARTUP_POLICY
},
...[
"build",
"validate",
"init"
].map((e) => ({
commandPath: ["plugins", e],
exact: true,
policy: { configGuard: "skip" }
})),
{
commandPath: ["onboard"],
exact: true,
policy: {
loadPlugins: "never",
configGuard: ({ argv: e, options: t }) => t?.reset === true || hasFlag(e, "--reset") ? "defer" : "run"
}
},
...[
["recommendations"],
["recommendations", "acknowledge"],
["recommendations", "refresh"]
].map((e) => ({
commandPath: ["onboard", ...e],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["channels", "add"],
exact: true,
policy: {
stateStoreGuard: "run",
loadPlugins: "never",
networkProxy: "bypass"
}
},
{
commandPath: ["channels", "login"],
exact: true,
policy: { stateStoreGuard: "run" }
},
{
commandPath: ["channels", "logs"],
exact: true,
policy: {
configGuard: "validate",
loadPlugins: "never",
networkProxy: "bypass"
}
},
...["remove", "resolve"].map((e) => ({
commandPath: ["channels", e],
exact: true,
policy: {
pluginRegistry: { scope: "configured-channels" },
networkProxy: "bypass"
}
})),
{
commandPath: ["channels", "status"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: ({ argv: e }) => hasFlag(e, "--probe") ? "default" : "bypass"
},
route: { id: "channels-status" }
},
{
commandPath: ["channels", "list"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
},
route: { id: "channels-list" }
},
...[
["skills"],
["skills", "check"],
["skills", "info"],
["skills", "list"]
].map((e) => ({
commandPath: e,
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never",
networkProxy: "bypass"
}
})),
{
commandPath: ["skills", "install"],
exact: true
},
{
commandPath: ["skills", "search"],
exact: true,
policy: {
configGuard: "skip",
loadPlugins: "never"
}
},
{
commandPath: ["memory"],
policy: {
configGuard: "validate",
loadPlugins: "always",
pluginRegistry: { scope: "memory" }
}
},
{
commandPath: ["memory", "search"],
exact: true,
policy: { configGuard: "skip" }
},
{
commandPath: ["memory", "status"],
exact: true,
policy: { configGuard: ({ argv: e }) => hasFlag(e, "--index") || hasFlag(e, "--fix") ? "validate" : "skip" }
},
{
commandPath: ["skills", "update"],
exact: true
},
{
commandPath: ["skills", "verify"],
exact: true
}
];
//#endregion
//#region src/cli/command-path-matches.ts
function matchesCommandPath(e, t, n) {
if (t.some((t, n) => e[n] !== t)) return false;
return !n?.exact || e.length === t.length;
}
//#endregion
//#region src/cli/command-path-policy.ts
const DEFAULT_CLI_COMMAND_PATH_POLICY = {
configGuard: "run",
stateStoreGuard: "skip",
loadPlugins: "never",
pluginRegistry: { scope: "all" },
ownsProtocolStdout: false,
hideBanner: false,
ensureCliPath: true,
networkProxy: "default"
};
function resolveCliCommandPathPolicy(e) {
const t = { ...DEFAULT_CLI_COMMAND_PATH_POLICY };
for (const n of cliCommandCatalog) {
if (!n.policy) continue;
if (!matchesCommandPath(e, n.commandPath, { exact: n.exact })) continue;
Object.assign(t, n.policy);
}
return t;
}
function resolveCliNetworkProxyPolicy(e) {
const t = resolveGatewayCommandPath(e) ?? resolveCliParentCommandPath(e) ?? getCommandPathWithRootOptions(e, e.length);
let n = [];
if (t.length > 0) {
let e = null;
for (const n of cliCommandCatalog) {
if (!matchesCommandPath(t, n.commandPath)) continue;
if (!e || n.commandPath.length > e.length) e = n.commandPath;
}
n = e ? [...e] : [expectDefined(t[0], "tokens entry at 0")];
}
const r = resolveCliCommandPathPolicy(n).networkProxy;
return typeof r === "function" ? r({
argv: e,
commandPath: n
}) : r;
}
//#endregion
export { cliCommandCatalog as i, resolveCliNetworkProxyPolicy as n, matchesCommandPath as r, resolveCliCommandPathPolicy as t };