UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

316 lines (315 loc) • 9.82 kB
import { E as getPrimaryCommand, k as hasHelpOrVersion, x as buildParseArgv } from "./logger-kwZIqwuw.js"; import { t as isTruthyEnvValue } from "./env-Dnra1IpT.js"; import { r as resolveActionArgs } from "./helpers-CvoyfQ8F.js"; import { n as getSubCliEntries$1 } from "./subcli-descriptors-CW8V25gW.js"; //#region src/cli/program/action-reparse.ts async function reparseProgramFromActionArgs(program, actionArgs) { const actionCommand = actionArgs.at(-1); const rawArgs = (actionCommand?.parent ?? program).rawArgs; const actionArgsList = resolveActionArgs(actionCommand); const fallbackArgv = actionCommand?.name() ? [actionCommand.name(), ...actionArgsList] : actionArgsList; const parseArgv = buildParseArgv({ programName: program.name(), rawArgs, fallbackArgv }); await program.parseAsync(parseArgv); } //#endregion //#region src/cli/program/command-tree.ts function removeCommand(program, command) { const commands = program.commands; const index = commands.indexOf(command); if (index < 0) return false; commands.splice(index, 1); return true; } function removeCommandByName(program, name) { const existing = program.commands.find((command) => command.name() === name); if (!existing) return false; return removeCommand(program, existing); } //#endregion //#region src/cli/program/register.subclis.ts const shouldRegisterPrimaryOnly = (argv) => { if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS)) return false; if (hasHelpOrVersion(argv)) return false; return true; }; const shouldEagerRegisterSubcommands = (_argv) => { return isTruthyEnvValue(process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS); }; const loadValidatedConfigForPluginRegistration = async () => { const mod = await import("./config-BaO3yYka.js"); if (!(await mod.readConfigFileSnapshot()).valid) return null; return mod.loadConfig(); }; const entries = [ { name: "acp", description: "Agent Control Protocol tools", hasSubcommands: true, register: async (program) => { (await import("./acp-cli-BQ740PFm.js")).registerAcpCli(program); } }, { name: "gateway", description: "Run, inspect, and query the WebSocket Gateway", hasSubcommands: true, register: async (program) => { (await import("./gateway-cli-Dsd9gHBa.js")).registerGatewayCli(program); } }, { name: "daemon", description: "Gateway service (legacy alias)", hasSubcommands: true, register: async (program) => { (await import("./cli/daemon-cli.js")).registerDaemonCli(program); } }, { name: "logs", description: "Tail gateway file logs via RPC", hasSubcommands: false, register: async (program) => { (await import("./logs-cli-Bgpikxqo.js")).registerLogsCli(program); } }, { name: "system", description: "System events, heartbeat, and presence", hasSubcommands: true, register: async (program) => { (await import("./system-cli-IL3AAQ9B.js")).registerSystemCli(program); } }, { name: "models", description: "Discover, scan, and configure models", hasSubcommands: true, register: async (program) => { (await import("./models-cli-49dTn2AZ.js")).registerModelsCli(program); } }, { name: "approvals", description: "Manage exec approvals (gateway or node host)", hasSubcommands: true, register: async (program) => { (await import("./exec-approvals-cli-C5PiR-h7.js")).registerExecApprovalsCli(program); } }, { name: "nodes", description: "Manage gateway-owned node pairing and node commands", hasSubcommands: true, register: async (program) => { (await import("./nodes-cli-WOx76l2Z.js")).registerNodesCli(program); } }, { name: "devices", description: "Device pairing + token management", hasSubcommands: true, register: async (program) => { (await import("./devices-cli-CFYweC1G.js")).registerDevicesCli(program); } }, { name: "node", description: "Run and manage the headless node host service", hasSubcommands: true, register: async (program) => { (await import("./node-cli-D-CVP1xo.js")).registerNodeCli(program); } }, { name: "sandbox", description: "Manage sandbox containers for agent isolation", hasSubcommands: true, register: async (program) => { (await import("./sandbox-cli-0PvmCTlp.js")).registerSandboxCli(program); } }, { name: "tui", description: "Open a terminal UI connected to the Gateway", hasSubcommands: false, register: async (program) => { (await import("./tui-cli-BYU1KpCi.js")).registerTuiCli(program); } }, { name: "cron", description: "Manage cron jobs via the Gateway scheduler", hasSubcommands: true, register: async (program) => { (await import("./cron-cli-BcTN5zbZ.js")).registerCronCli(program); } }, { name: "dns", description: "DNS helpers for wide-area discovery (Tailscale + CoreDNS)", hasSubcommands: true, register: async (program) => { (await import("./dns-cli-DMdqkOy_.js")).registerDnsCli(program); } }, { name: "docs", description: "Search the live OpenClaw docs", hasSubcommands: false, register: async (program) => { (await import("./docs-cli-DSvOkQHV.js")).registerDocsCli(program); } }, { name: "hooks", description: "Manage internal agent hooks", hasSubcommands: true, register: async (program) => { (await import("./hooks-cli-C88_5bww.js")).registerHooksCli(program); } }, { name: "webhooks", description: "Webhook helpers and integrations", hasSubcommands: true, register: async (program) => { (await import("./webhooks-cli-Ze0RGT_-.js")).registerWebhooksCli(program); } }, { name: "qr", description: "Generate iOS pairing QR/setup code", hasSubcommands: false, register: async (program) => { (await import("./qr-cli-DknoP9Un.js")).registerQrCli(program); } }, { name: "clawbot", description: "Legacy clawbot command aliases", hasSubcommands: true, register: async (program) => { (await import("./clawbot-cli-Dfec3Pzb.js")).registerClawbotCli(program); } }, { name: "pairing", description: "Secure DM pairing (approve inbound requests)", hasSubcommands: true, register: async (program) => { const { registerPluginCliCommands } = await import("./cli-CZyw_AGr.js"); const config = await loadValidatedConfigForPluginRegistration(); if (config) registerPluginCliCommands(program, config); (await import("./pairing-cli-Brj1DwQC.js")).registerPairingCli(program); } }, { name: "plugins", description: "Manage OpenClaw plugins and extensions", hasSubcommands: true, register: async (program) => { (await import("./plugins-cli-BpaoIqv3.js")).registerPluginsCli(program); const { registerPluginCliCommands } = await import("./cli-CZyw_AGr.js"); const config = await loadValidatedConfigForPluginRegistration(); if (config) registerPluginCliCommands(program, config); } }, { name: "channels", description: "Manage connected chat channels (Telegram, Discord, etc.)", hasSubcommands: true, register: async (program) => { (await import("./channels-cli-DFURdJqL.js")).registerChannelsCli(program); } }, { name: "directory", description: "Lookup contact and group IDs (self, peers, groups) for supported chat channels", hasSubcommands: true, register: async (program) => { (await import("./directory-cli-Car46LSi.js")).registerDirectoryCli(program); } }, { name: "security", description: "Security tools and local config audits", hasSubcommands: true, register: async (program) => { (await import("./security-cli-cFxOE_BC.js")).registerSecurityCli(program); } }, { name: "secrets", description: "Secrets runtime reload controls", hasSubcommands: true, register: async (program) => { (await import("./secrets-cli-COLCJYzb.js")).registerSecretsCli(program); } }, { name: "skills", description: "List and inspect available skills", hasSubcommands: true, register: async (program) => { (await import("./skills-cli-t-pkc5KW.js")).registerSkillsCli(program); } }, { name: "update", description: "Update OpenClaw and inspect update channel status", hasSubcommands: true, register: async (program) => { (await import("./update-cli-6OGXKQdy.js")).registerUpdateCli(program); } }, { name: "completion", description: "Generate shell completion script", hasSubcommands: false, register: async (program) => { (await import("./completion-cli-DxT2ILHj.js")).registerCompletionCli(program); } } ]; function getSubCliEntries() { return getSubCliEntries$1(); } async function registerSubCliByName(program, name) { const entry = entries.find((candidate) => candidate.name === name); if (!entry) return false; removeCommandByName(program, entry.name); await entry.register(program); return true; } function registerLazyCommand(program, entry) { const placeholder = program.command(entry.name).description(entry.description); placeholder.allowUnknownOption(true); placeholder.allowExcessArguments(true); placeholder.action(async (...actionArgs) => { removeCommand(program, placeholder); await entry.register(program); await reparseProgramFromActionArgs(program, actionArgs); }); } function registerSubCliCommands(program, argv = process.argv) { if (shouldEagerRegisterSubcommands(argv)) { for (const entry of entries) entry.register(program); return; } const primary = getPrimaryCommand(argv); if (primary && shouldRegisterPrimaryOnly(argv)) { const entry = entries.find((candidate) => candidate.name === primary); if (entry) { registerLazyCommand(program, entry); return; } } for (const candidate of entries) registerLazyCommand(program, candidate); } //#endregion export { removeCommandByName as a, registerSubCliCommands as i, loadValidatedConfigForPluginRegistration as n, reparseProgramFromActionArgs as o, registerSubCliByName as r, getSubCliEntries as t };