File: //lib/node_modules/openclaw/dist/program-B5ooPX9T.js
import { Dt as theme, Et as isRich, Ft as tryParseLogLevel, Nt as ALLOWED_LOG_LEVELS, X as escapeRegExp, an as getCommandPath, dn as hasHelpOrVersion, fn as hasRootVersionAlias, ln as getVerboseFlag, r as isTruthyEnvValue, un as hasFlag, v as defaultRuntime, xt as setVerbose } from "./entry.js";
import "./auth-profiles-BLqWs5Ho.js";
import { n as replaceCliName, r as resolveCliName } from "./command-format-_PO7rvrJ.js";
import "./agent-scope-BUKPOSoo.js";
import "./exec-G9-WTRVN.js";
import "./github-copilot-token-RNgXBxZS.js";
import "./host-env-security-DyQuUnEd.js";
import "./model-COhFTjBU.js";
import "./pi-model-discovery-CwESh4K1.js";
import "./frontmatter-17nP3KZr.js";
import "./skills-CWeJXlIQ.js";
import "./manifest-registry-BPlNBgie.js";
import "./config-DWx3SXRc.js";
import { r as VERSION } from "./env-vars-iFkEK4MO.js";
import "./dock-DE75y38s.js";
import "./message-channel-CIQTys4Q.js";
import "./sessions-Dlc3fwqk.js";
import "./plugins-DZodvLr1.js";
import "./accounts-g8UOA9ZQ.js";
import "./accounts-iAP56FFD.js";
import "./accounts-B7WS3ElX.js";
import "./bindings-DieZWR44.js";
import "./logging-CFvkxgcX.js";
import "./send-COqvwcD8.js";
import "./send-Bsif7DOx.js";
import "./subagent-registry-DAeKcITJ.js";
import "./paths-Dvmk_rXi.js";
import "./chat-envelope-BG_U_muK.js";
import "./client-BtjXMOD6.js";
import "./call-DQYruQvM.js";
import "./pairing-token-qLzAsGdq.js";
import "./net-BEAjYacy.js";
import "./ip-m9Sjsn1o.js";
import "./tailnet-BOWO-AaH.js";
import "./tokens-D60Twogq.js";
import "./with-timeout-CEqF9gkI.js";
import "./deliver-DOwrkCH2.js";
import "./diagnostic-J4rp2SRl.js";
import "./diagnostic-session-state-CT36_PCE.js";
import "./send-T8zEpqSk.js";
import "./image-ops-CdtmwUCR.js";
import "./pi-embedded-helpers-CbXrZ-8i.js";
import "./sandbox-B6QqSqwe.js";
import "./tool-catalog-BS-Gk_Yg.js";
import "./chrome-Cw-tdii4.js";
import "./tailscale-B21pc9dr.js";
import "./auth-Dw00sIWu.js";
import "./server-context-B5puT4XF.js";
import "./redact-CjuqjXFe.js";
import "./errors-DjnYuRJy.js";
import "./fs-safe-Cwp1VOPx.js";
import "./trash-CX7nB-3e.js";
import "./ssrf-BjDQh-0k.js";
import "./store-CP7czNHW.js";
import "./ports-CCM0e3iq.js";
import "./server-middleware-ti_BzwRQ.js";
import "./tool-images-DfuwmJ1p.js";
import "./thinking-BF74hBT8.js";
import "./models-config-CSZqabpA.js";
import "./exec-approvals-allowlist-BhbPGoNp.js";
import "./exec-safe-bin-runtime-policy-CComo_OL.js";
import "./reply-prefix-DAmIy_Z5.js";
import "./memory-cli-cd4fgeOx.js";
import "./manager-CxJqMHgG.js";
import "./gemini-auth-B7e2y1yw.js";
import "./fetch-guard-D9xirO1r.js";
import "./query-expansion-BTx3AUZ-.js";
import "./retry-BLB59C0N.js";
import "./target-errors-BxFxCuxQ.js";
import "./chunk-BvqBAgzS.js";
import "./markdown-tables-ByuLnZsd.js";
import "./local-roots-CmtTCtgw.js";
import "./ir-Bem5E4cr.js";
import "./render-Bdn0My43.js";
import "./commands-CdC0wdcL.js";
import "./commands-registry-DSKAIGC_.js";
import "./image-DFsKde0k.js";
import "./tool-display-9_qVpbf1.js";
import "./runner-zte249sT.js";
import "./model-catalog-B5adpD0Z.js";
import "./pairing-store-BICHFkVx.js";
import "./fetch-Cg7F6jVj.js";
import "./exec-approvals-B-M763CP.js";
import "./nodes-screen-BPGhiVFW.js";
import "./session-utils-C_guar9P.js";
import "./session-cost-usage-CvGuEEE6.js";
import "./skill-commands-CwRTVk0N.js";
import "./workspace-dirs-BPGnREEO.js";
import "./channel-activity-Czj5FT0A.js";
import "./tables-CycdFBqL.js";
import "./server-lifecycle-QH6dow-t.js";
import "./stagger-wClkZ9EC.js";
import "./channel-selection-Dz2_TSrQ.js";
import "./send-DwUJxZD_.js";
import "./outbound-attachment-DgYeDKmI.js";
import "./delivery-queue-ChFqRLAV.js";
import "./send-MEoRs0eF.js";
import "./resolve-route-DveekqJh.js";
import "./proxy-WehDGK1u.js";
import { t as formatDocsLink } from "./links-DNSoSnpZ.js";
import "./cli-utils-DyGKoc5l.js";
import "./help-format-CSCL71i7.js";
import "./progress-NYYdD1uh.js";
import "./replies-BbUlxpbc.js";
import "./onboard-helpers-DOdss3HD.js";
import "./prompt-style-EoDyMHYF.js";
import "./pairing-labels-Bmmdqu3C.js";
import "./pi-tools.policy-CwTPF5VO.js";
import "./catalog-qxFkHr5X.js";
import "./plugin-registry-u1Kk8wSY.js";
import { n as resolveCliChannelOptions } from "./channel-options-DqZ1c24v.js";
import { t as getSubCliCommandsWithSubcommands } from "./register.subclis-CQD3-SyD.js";
import { a as registerProgramCommands, r as getCoreCliCommandsWithSubcommands } from "./command-registry-c6_yAaXT.js";
import { r as setProgramContext } from "./program-context-DMkrV4MF.js";
import { t as forceFreePort } from "./ports-BtBq1142.js";
import { n as formatCliBannerLine, r as hasEmittedCliBanner, t as emitCliBanner } from "./banner-CwOHoB31.js";
import { Command, InvalidArgumentError } from "commander";
//#region src/cli/program/context.ts
function createProgramContext() {
const channelOptions = resolveCliChannelOptions();
return {
programVersion: VERSION,
channelOptions,
messageChannelOptions: channelOptions.join("|"),
agentChannelOptions: ["last", ...channelOptions].join("|")
};
}
//#endregion
//#region src/cli/log-level-option.ts
const CLI_LOG_LEVEL_VALUES = ALLOWED_LOG_LEVELS.join("|");
function parseCliLogLevelOption(value) {
const parsed = tryParseLogLevel(value);
if (!parsed) throw new InvalidArgumentError(`Invalid --log-level (use ${CLI_LOG_LEVEL_VALUES})`);
return parsed;
}
//#endregion
//#region src/cli/program/help.ts
const CLI_NAME = resolveCliName();
const CLI_NAME_PATTERN = escapeRegExp(CLI_NAME);
const ROOT_COMMANDS_WITH_SUBCOMMANDS = new Set([...getCoreCliCommandsWithSubcommands(), ...getSubCliCommandsWithSubcommands()]);
const ROOT_COMMANDS_HINT = "Hint: commands suffixed with * have subcommands. Run <command> --help for details.";
const EXAMPLES = [
["openclaw models --help", "Show detailed help for the models command."],
["openclaw channels login --verbose", "Link personal WhatsApp Web and show QR + connection logs."],
["openclaw message send --target +15555550123 --message \"Hi\" --json", "Send via your web session and print JSON result."],
["openclaw gateway --port 18789", "Run the WebSocket Gateway locally."],
["openclaw --dev gateway", "Run a dev Gateway (isolated state/config) on ws://127.0.0.1:19001."],
["openclaw gateway --force", "Kill anything bound to the default gateway port, then start it."],
["openclaw gateway ...", "Gateway control via WebSocket."],
["openclaw agent --to +15555550123 --message \"Run summary\" --deliver", "Talk directly to the agent using the Gateway; optionally send the WhatsApp reply."],
["openclaw message send --channel telegram --target @mychat --message \"Hi\"", "Send via your Telegram bot."]
];
function configureProgramHelp(program, ctx) {
program.name(CLI_NAME).description("").version(ctx.programVersion).option("--dev", "Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)").option("--profile <name>", "Use a named profile (isolates OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH under ~/.openclaw-<name>)").option("--log-level <level>", `Global log level override for file + console (${CLI_LOG_LEVEL_VALUES})`, parseCliLogLevelOption);
program.option("--no-color", "Disable ANSI colors", false);
program.helpOption("-h, --help", "Display help for command");
program.helpCommand("help [command]", "Display help for command");
program.configureHelp({
sortSubcommands: true,
sortOptions: true,
optionTerm: (option) => theme.option(option.flags),
subcommandTerm: (cmd) => {
const hasSubcommands = cmd.parent === program && ROOT_COMMANDS_WITH_SUBCOMMANDS.has(cmd.name());
return theme.command(hasSubcommands ? `${cmd.name()} *` : cmd.name());
}
});
const formatHelpOutput = (str) => {
let output = str;
if (new RegExp(`^Usage:\\s+${CLI_NAME_PATTERN}\\s+\\[options\\]\\s+\\[command\\]\\s*$`, "m").test(output) && /^Commands:/m.test(output)) output = output.replace(/^Commands:/m, `Commands:\n ${theme.muted(ROOT_COMMANDS_HINT)}`);
return output.replace(/^Usage:/gm, theme.heading("Usage:")).replace(/^Options:/gm, theme.heading("Options:")).replace(/^Commands:/gm, theme.heading("Commands:"));
};
program.configureOutput({
writeOut: (str) => {
process.stdout.write(formatHelpOutput(str));
},
writeErr: (str) => {
process.stderr.write(formatHelpOutput(str));
},
outputError: (str, write) => write(theme.error(str))
});
if (hasFlag(process.argv, "-V") || hasFlag(process.argv, "--version") || hasRootVersionAlias(process.argv)) {
console.log(ctx.programVersion);
process.exit(0);
}
program.addHelpText("beforeAll", () => {
if (hasEmittedCliBanner()) return "";
const rich = isRich();
return `\n${formatCliBannerLine(ctx.programVersion, { richTty: rich })}\n`;
});
const fmtExamples = EXAMPLES.map(([cmd, desc]) => ` ${theme.command(replaceCliName(cmd, CLI_NAME))}\n ${theme.muted(desc)}`).join("\n");
program.addHelpText("afterAll", ({ command }) => {
if (command !== program) return "";
const docs = formatDocsLink("/cli", "docs.openclaw.ai/cli");
return `\n${theme.heading("Examples:")}\n${fmtExamples}\n\n${theme.muted("Docs:")} ${docs}\n`;
});
}
//#endregion
//#region src/cli/program/preaction.ts
function setProcessTitleForCommand(actionCommand) {
let current = actionCommand;
while (current.parent && current.parent.parent) current = current.parent;
const name = current.name();
const cliName = resolveCliName();
if (!name || name === cliName) return;
process.title = `${cliName}-${name}`;
}
const PLUGIN_REQUIRED_COMMANDS = new Set([
"message",
"channels",
"directory",
"configure",
"onboard"
]);
function getRootCommand(command) {
let current = command;
while (current.parent) current = current.parent;
return current;
}
function getCliLogLevel(actionCommand) {
const root = getRootCommand(actionCommand);
if (typeof root.getOptionValueSource !== "function") return;
if (root.getOptionValueSource("logLevel") !== "cli") return;
const logLevel = root.opts().logLevel;
return typeof logLevel === "string" ? logLevel : void 0;
}
function registerPreActionHooks(program, programVersion) {
program.hook("preAction", async (_thisCommand, actionCommand) => {
setProcessTitleForCommand(actionCommand);
const argv = process.argv;
if (hasHelpOrVersion(argv)) return;
const commandPath = getCommandPath(argv, 2);
if (!(isTruthyEnvValue(process.env.OPENCLAW_HIDE_BANNER) || commandPath[0] === "update" || commandPath[0] === "completion" || commandPath[0] === "plugins" && commandPath[1] === "update")) emitCliBanner(programVersion);
const verbose = getVerboseFlag(argv, { includeDebug: true });
setVerbose(verbose);
const cliLogLevel = getCliLogLevel(actionCommand);
if (cliLogLevel) process.env.OPENCLAW_LOG_LEVEL = cliLogLevel;
if (!verbose) process.env.NODE_NO_WARNINGS ??= "1";
if (commandPath[0] === "doctor" || commandPath[0] === "completion") return;
const { ensureConfigReady } = await import("./config-guard-D76MaHGD.js").then((n) => n.t);
await ensureConfigReady({
runtime: defaultRuntime,
commandPath
});
if (PLUGIN_REQUIRED_COMMANDS.has(commandPath[0])) {
const { ensurePluginRegistryLoaded } = await import("./plugin-registry-u1Kk8wSY.js").then((n) => n.n);
ensurePluginRegistryLoaded();
}
});
}
//#endregion
//#region src/cli/program/build-program.ts
function buildProgram() {
const program = new Command();
const ctx = createProgramContext();
const argv = process.argv;
setProgramContext(program, ctx);
configureProgramHelp(program, ctx);
registerPreActionHooks(program, ctx.programVersion);
registerProgramCommands(program, ctx, argv);
return program;
}
//#endregion
export { buildProgram };