UNPKG

@gguf/claw

Version:

Multi-channel AI gateway with extensible messaging integrations

235 lines (230 loc) 10.3 kB
import { Dt as theme, Et as isRich, X as escapeRegExp, _ as defaultRuntime, cn as hasHelpOrVersion, ln as hasRootVersionAlias, n as isTruthyEnvValue, nn as getCommandPath, on as getVerboseFlag, sn as hasFlag, xt as setVerbose } from "./entry.js"; import "./auth-profiles-DFa1zzNy.js"; import { n as replaceCliName, r as resolveCliName } from "./command-format-D3syQOZg.js"; import "./exec-CBKBIMpA.js"; import "./agent-scope-RzK9Zcks.js"; import "./github-copilot-token-DuFIqfeC.js"; import "./model-DY9t1aT6.js"; import "./pi-model-discovery-Do3xMEtM.js"; import "./frontmatter-D-YR-Ghi.js"; import "./skills-DJmGZazd.js"; import "./manifest-registry-DS2iK5AZ.js"; import { V as VERSION } from "./config-B2kL1ciP.js"; import "./client-CDjZdZtI.js"; import "./call-DXhJGwEy.js"; import "./message-channel-CVHJDItx.js"; import "./pairing-token-Byh6drgn.js"; import "./subagent-registry-C7Edpn23.js"; import "./sessions-BD5dyLxb.js"; import "./tokens-D5RzuaYP.js"; import "./normalize-Db7Xtx2v.js"; import "./accounts-BpzwDfBB.js"; import "./bindings-KqaGKS1E.js"; import "./logging-CFvkxgcX.js"; import "./send-BFiRlO6V.js"; import "./plugins-RqhjLCb6.js"; import "./send-CWDtU8Gi.js"; import "./with-timeout-nVWy7PWz.js"; import "./deliver-CeVE1Jh-.js"; import "./diagnostic-774btyou.js"; import "./diagnostic-session-state-HO94DMou.js"; import "./accounts-B3D4iWUP.js"; import "./send-DCCBUsNn.js"; import "./image-ops-lDlFpoR2.js"; import "./pi-embedded-helpers-NVEtaJwl.js"; import "./sandbox-CO-R8v6J.js"; import "./common-DcSh1hZE.js"; import "./chrome-52ZF7gmE.js"; import "./tailscale-BzRVNhMW.js"; import "./auth-Dq2pFnjj.js"; import "./server-context-C1f7cijA.js"; import "./routes-BJmh1Ify.js"; import "./redact-C2s6sr73.js"; import "./errors-CFEPAPWc.js"; import "./fs-safe-3YwsxSr5.js"; import "./paths-CXKNzNjU.js"; import "./ssrf-Cv2DiHsm.js"; import "./store-e6fIrP17.js"; import "./ports-59j-bA53.js"; import "./trash-DVLJ0k6q.js"; import "./dock-BZuwgj1O.js"; import "./accounts-Jg3_1Y-r.js"; import "./paths-CXpciDEv.js"; import "./thinking-CJPPUYWd.js"; import "./models-config-5zJ39mUb.js"; import "./reply-prefix-DJOqzjBt.js"; import "./memory-cli-C3uas9sI.js"; import "./manager-D3ZmOwqt.js"; import "./gemini-auth-CdgAkz2K.js"; import "./sqlite-1-TCahE6.js"; import "./retry-BcjnIuo-.js"; import "./chunk-Z2NYDchs.js"; import "./markdown-tables-GCHx-nGT.js"; import "./fetch-guard-B5BAqVyD.js"; import "./local-roots-SkDT1Wv8.js"; import "./ir-DAwVi0a7.js"; import "./render-e7fENCYH.js"; import "./commands-registry-CRmMPJQ9.js"; import "./image-QGUQCdGh.js"; import "./tool-display-Cs1uRaRV.js"; import "./runner-D81xREgc.js"; import "./model-catalog-DLoDxnxL.js"; import "./session-utils-C3Oi9cXA.js"; import "./skill-commands-D2rmj6w8.js"; import "./workspace-dirs-BXftTDSV.js"; import "./pairing-store-CruPwgBw.js"; import "./fetch-vg2oFVIH.js"; import "./exec-approvals-BZA6z4HM.js"; import "./nodes-screen-x7YKy8Ay.js"; import "./session-cost-usage-CpxG9Mup.js"; import "./pi-tools.policy-DeRwGLEO.js"; import "./control-service-DGleRjGJ.js"; import "./stagger-CArN2YVJ.js"; import "./channel-selection-DoXlsBhe.js"; import "./send-C3RIrBTr.js"; import "./outbound-attachment-CdFWGHgJ.js"; import "./delivery-queue-DKdWlR61.js"; import "./send-0Nz3O9Jc.js"; import "./resolve-route-BONxzeyg.js"; import "./channel-activity-BYGpAtHP.js"; import "./tables-BrqD0SUa.js"; import "./proxy-DL3MD6-P.js"; import { t as formatDocsLink } from "./links-CW8Bx7rK.js"; import "./cli-utils-CCaEbxAz.js"; import "./help-format-B0pWGnZs.js"; import "./progress-BAHiAaDW.js"; import "./replies-CuUAAFF2.js"; import "./onboard-helpers-CEx2tGVB.js"; import "./prompt-style-DwCXob2h.js"; import "./pairing-labels-DtxjElSq.js"; import "./catalog-vmrRUSxJ.js"; import "./plugin-registry-CXQ59uvq.js"; import { n as resolveCliChannelOptions } from "./channel-options-RMlqt6L8.js"; import { t as getSubCliCommandsWithSubcommands } from "./register.subclis-CPEP_g__.js"; import { a as registerProgramCommands, r as getCoreCliCommandsWithSubcommands } from "./command-registry-D81FNA9E.js"; import { r as setProgramContext } from "./program-context--isQKnLs.js"; import { t as forceFreePort } from "./ports-B2UK3R3y.js"; import { n as formatCliBannerLine, r as hasEmittedCliBanner, t as emitCliBanner } from "./banner-CtyoWCcv.js"; import { Command } 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/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>)"); 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" ]); 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); if (!verbose) process.env.NODE_NO_WARNINGS ??= "1"; if (commandPath[0] === "doctor" || commandPath[0] === "completion") return; const { ensureConfigReady } = await import("./config-guard-BRSGlD76.js").then((n) => n.t); await ensureConfigReady({ runtime: defaultRuntime, commandPath }); if (PLUGIN_REQUIRED_COMMANDS.has(commandPath[0])) { const { ensurePluginRegistryLoaded } = await import("./plugin-registry-CXQ59uvq.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 };