@gguf/claw
Version:
WhatsApp gateway CLI (Baileys web) with Pi RPC agent
348 lines (345 loc) • 10.6 kB
JavaScript
import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js";
import { n as isTruthyEnvValue } from "./entry.js";
import { r as resolveActionArgs } from "./helpers-EKm3X92T.js";
//#region src/cli/argv.ts
const HELP_FLAGS = new Set(["-h", "--help"]);
const VERSION_FLAGS = new Set([
"-v",
"-V",
"--version"
]);
const FLAG_TERMINATOR = "--";
function hasHelpOrVersion(argv) {
return argv.some((arg) => HELP_FLAGS.has(arg) || VERSION_FLAGS.has(arg));
}
function isValueToken(arg) {
if (!arg) return false;
if (arg === FLAG_TERMINATOR) return false;
if (!arg.startsWith("-")) return true;
return /^-\d+(?:\.\d+)?$/.test(arg);
}
function parsePositiveInt(value) {
const parsed = Number.parseInt(value, 10);
if (Number.isNaN(parsed) || parsed <= 0) return;
return parsed;
}
function hasFlag(argv, name) {
const args = argv.slice(2);
for (const arg of args) {
if (arg === FLAG_TERMINATOR) break;
if (arg === name) return true;
}
return false;
}
function getFlagValue(argv, name) {
const args = argv.slice(2);
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (arg === FLAG_TERMINATOR) break;
if (arg === name) {
const next = args[i + 1];
return isValueToken(next) ? next : null;
}
if (arg.startsWith(`${name}=`)) {
const value = arg.slice(name.length + 1);
return value ? value : null;
}
}
}
function getVerboseFlag(argv, options) {
if (hasFlag(argv, "--verbose")) return true;
if (options?.includeDebug && hasFlag(argv, "--debug")) return true;
return false;
}
function getPositiveIntFlagValue(argv, name) {
const raw = getFlagValue(argv, name);
if (raw === null || raw === void 0) return raw;
return parsePositiveInt(raw);
}
function getCommandPath(argv, depth = 2) {
const args = argv.slice(2);
const path = [];
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (!arg) continue;
if (arg === "--") break;
if (arg.startsWith("-")) continue;
path.push(arg);
if (path.length >= depth) break;
}
return path;
}
function getPrimaryCommand(argv) {
const [primary] = getCommandPath(argv, 1);
return primary ?? null;
}
function buildParseArgv(params) {
const baseArgv = params.rawArgs && params.rawArgs.length > 0 ? params.rawArgs : params.fallbackArgv && params.fallbackArgv.length > 0 ? params.fallbackArgv : process.argv;
const programName = params.programName ?? "";
const normalizedArgv = programName && baseArgv[0] === programName ? baseArgv.slice(1) : baseArgv[0]?.endsWith("openclaw") ? baseArgv.slice(1) : baseArgv;
const executable = (normalizedArgv[0]?.split(/[/\\]/).pop() ?? "").toLowerCase();
if (normalizedArgv.length >= 2 && (isNodeExecutable(executable) || isBunExecutable(executable))) return normalizedArgv;
return [
"node",
programName || "openclaw",
...normalizedArgv
];
}
const nodeExecutablePattern = /^node-\d+(?:\.\d+)*(?:\.exe)?$/;
function isNodeExecutable(executable) {
return executable === "node" || executable === "node.exe" || executable === "nodejs" || executable === "nodejs.exe" || nodeExecutablePattern.test(executable);
}
function isBunExecutable(executable) {
return executable === "bun" || executable === "bun.exe";
}
//#endregion
//#region src/cli/program/register.subclis.ts
var register_subclis_exports = /* @__PURE__ */ __exportAll({
getSubCliEntries: () => getSubCliEntries,
registerSubCliByName: () => registerSubCliByName,
registerSubCliCommands: () => registerSubCliCommands
});
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 loadConfig = async () => {
return (await import("./config-CKLedg5Y.js").then((n) => n.t)).loadConfig();
};
const entries = [
{
name: "acp",
description: "Agent Control Protocol tools",
register: async (program) => {
(await import("./acp-cli-BOKabdeW.js")).registerAcpCli(program);
}
},
{
name: "gateway",
description: "Gateway control",
register: async (program) => {
(await import("./gateway-cli-DHP5DRUH.js")).registerGatewayCli(program);
}
},
{
name: "daemon",
description: "Gateway service (legacy alias)",
register: async (program) => {
(await import("./daemon-cli-CMKd_D6h.js").then((n) => n.t)).registerDaemonCli(program);
}
},
{
name: "logs",
description: "Gateway logs",
register: async (program) => {
(await import("./logs-cli-DtiFFkZL.js")).registerLogsCli(program);
}
},
{
name: "system",
description: "System events, heartbeat, and presence",
register: async (program) => {
(await import("./system-cli-Dqnt-b0D.js")).registerSystemCli(program);
}
},
{
name: "models",
description: "Model configuration",
register: async (program) => {
(await import("./models-cli-DHzyyLvp.js")).registerModelsCli(program);
}
},
{
name: "approvals",
description: "Exec approvals",
register: async (program) => {
(await import("./exec-approvals-cli-D7aVv5hN.js")).registerExecApprovalsCli(program);
}
},
{
name: "nodes",
description: "Node commands",
register: async (program) => {
(await import("./nodes-cli-hT8yYD7S.js")).registerNodesCli(program);
}
},
{
name: "devices",
description: "Device pairing + token management",
register: async (program) => {
(await import("./devices-cli-D_rnGkqO.js")).registerDevicesCli(program);
}
},
{
name: "node",
description: "Node control",
register: async (program) => {
(await import("./node-cli-DH7Ykym5.js")).registerNodeCli(program);
}
},
{
name: "sandbox",
description: "Sandbox tools",
register: async (program) => {
(await import("./sandbox-cli-Ces6i3n2.js")).registerSandboxCli(program);
}
},
{
name: "tui",
description: "Terminal UI",
register: async (program) => {
(await import("./tui-cli-DV_JAtnq.js")).registerTuiCli(program);
}
},
{
name: "cron",
description: "Cron scheduler",
register: async (program) => {
(await import("./cron-cli-CssI71-c.js")).registerCronCli(program);
}
},
{
name: "dns",
description: "DNS helpers",
register: async (program) => {
(await import("./dns-cli-CoeI4817.js")).registerDnsCli(program);
}
},
{
name: "docs",
description: "Docs helpers",
register: async (program) => {
(await import("./docs-cli-BH9bMx3a.js")).registerDocsCli(program);
}
},
{
name: "hooks",
description: "Hooks tooling",
register: async (program) => {
(await import("./hooks-cli-CmeQxEOM.js")).registerHooksCli(program);
}
},
{
name: "webhooks",
description: "Webhook helpers",
register: async (program) => {
(await import("./webhooks-cli-BztQHEco.js")).registerWebhooksCli(program);
}
},
{
name: "pairing",
description: "Pairing helpers",
register: async (program) => {
const { registerPluginCliCommands } = await import("./cli-DBAccB3n.js");
registerPluginCliCommands(program, await loadConfig());
(await import("./pairing-cli-C8KHRjaU.js")).registerPairingCli(program);
}
},
{
name: "plugins",
description: "Plugin management",
register: async (program) => {
(await import("./plugins-cli-Dr_R2-FY.js")).registerPluginsCli(program);
const { registerPluginCliCommands } = await import("./cli-DBAccB3n.js");
registerPluginCliCommands(program, await loadConfig());
}
},
{
name: "channels",
description: "Channel management",
register: async (program) => {
(await import("./channels-cli-PAlqhOZ7.js")).registerChannelsCli(program);
}
},
{
name: "directory",
description: "Directory commands",
register: async (program) => {
(await import("./directory-cli-CGLolzJC.js")).registerDirectoryCli(program);
}
},
{
name: "security",
description: "Security helpers",
register: async (program) => {
(await import("./security-cli-T7yrd3lb.js")).registerSecurityCli(program);
}
},
{
name: "skills",
description: "Skills management",
register: async (program) => {
(await import("./skills-cli-DBC5zFat.js")).registerSkillsCli(program);
}
},
{
name: "update",
description: "CLI update helpers",
register: async (program) => {
(await import("./update-cli-tQcy8mkI.js")).registerUpdateCli(program);
}
},
{
name: "completion",
description: "Generate shell completion script",
register: async (program) => {
(await import("./completion-cli-BbhA_JbG.js").then((n) => n.n)).registerCompletionCli(program);
}
}
];
function getSubCliEntries() {
return entries;
}
function removeCommand(program, command) {
const commands = program.commands;
const index = commands.indexOf(command);
if (index >= 0) commands.splice(index, 1);
}
async function registerSubCliByName(program, name) {
const entry = entries.find((candidate) => candidate.name === name);
if (!entry) return false;
const existing = program.commands.find((cmd) => cmd.name() === entry.name);
if (existing) removeCommand(program, existing);
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);
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);
});
}
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 { getCommandPath as a, getPrimaryCommand as c, hasHelpOrVersion as d, register_subclis_exports as i, getVerboseFlag as l, registerSubCliByName as n, getFlagValue as o, registerSubCliCommands as r, getPositiveIntFlagValue as s, getSubCliEntries as t, hasFlag as u };