195 lines
7.1 KiB
JavaScript
195 lines
7.1 KiB
JavaScript
import { c as enableConsoleCapture, i as normalizeEnv, n as isTruthyEnvValue, p as defaultRuntime } from "./entry.js";
|
|
import "./auth-profiles-CfFGCDJa.js";
|
|
import "./agent-scope-jm0ZdXwM.js";
|
|
import { d as resolveConfigDir } from "./utils-PmTbZoD1.js";
|
|
import "./exec-BIMFe4XS.js";
|
|
import "./github-copilot-token-rP-6QdKv.js";
|
|
import "./pi-model-discovery-CsRo-xMp.js";
|
|
import { M as VERSION } from "./config-DxJyvt4o.js";
|
|
import "./manifest-registry-tuAcHxrV.js";
|
|
import "./server-context-CM_E6wD5.js";
|
|
import { r as formatUncaughtError } from "./errors-DdT2Dtkb.js";
|
|
import "./control-service-BSfjo9v7.js";
|
|
import { t as ensureOpenClawCliOnPath } from "./path-env-CUhrC5DA.js";
|
|
import "./tailscale-BUcKO8Rr.js";
|
|
import "./auth-viF_w60n.js";
|
|
import "./client-BYx0ZoAv.js";
|
|
import "./call-BDMBg5WA.js";
|
|
import "./message-channel-Csfn34Sf.js";
|
|
import "./links-jGisPfXW.js";
|
|
import "./plugin-auto-enable-CIVp3SAp.js";
|
|
import "./plugins-TrKFfrLt.js";
|
|
import "./logging-fywhKCmE.js";
|
|
import "./accounts-B5QZU96b.js";
|
|
import { jt as installUnhandledRejectionHandler } from "./loader-DpqWKh1q.js";
|
|
import "./progress-Dn3kWpaL.js";
|
|
import "./prompt-style-D5D7b3cX.js";
|
|
import "./note-CBiVaqG7.js";
|
|
import "./clack-prompter-BJuVh97L.js";
|
|
import "./onboard-channels-B_dwrYOf.js";
|
|
import "./archive-mFgwsll-.js";
|
|
import "./installs-C5cjVarj.js";
|
|
import "./manager-rDmdE7O9.js";
|
|
import "./paths-RvF0P6tQ.js";
|
|
import "./sqlite-B_L84oiu.js";
|
|
import "./routes-XDcV8NF0.js";
|
|
import "./pi-embedded-helpers-wpP9rGyv.js";
|
|
import "./deliver-GshcYxn_.js";
|
|
import "./sandbox-DO8gYgPg.js";
|
|
import "./channel-summary-CgnCeeeN.js";
|
|
import "./wsl-CuoepaB0.js";
|
|
import "./skills-DtwGIkTI.js";
|
|
import "./image-FBFXvDnM.js";
|
|
import "./redact-CDPAzwi8.js";
|
|
import "./tool-display-BMYWrp0L.js";
|
|
import "./restart-sentinel-DywisDen.js";
|
|
import "./channel-selection-BM0IKqqi.js";
|
|
import "./commands-DSjmdo4s.js";
|
|
import "./pairing-store-DMex6WWe.js";
|
|
import "./login-qr-C-zwYd95.js";
|
|
import "./pairing-labels-C6I3dD-m.js";
|
|
import "./channels-status-issues-DRXQXvhY.js";
|
|
import { n as ensurePluginRegistryLoaded } from "./command-options-D-7lJZEz.js";
|
|
import { i as getCommandPath, s as getPrimaryCommand, u as hasHelpOrVersion } from "./register.subclis-jPRJc4B8.js";
|
|
import "./completion-cli-BK8NKINf.js";
|
|
import "./gateway-rpc-DNKo4-h7.js";
|
|
import "./deps-IViLD7E4.js";
|
|
import "./daemon-runtime-B_I7gTzc.js";
|
|
import { t as assertSupportedRuntime } from "./runtime-guard-DkjmhnBD.js";
|
|
import "./service-DDLmNXs9.js";
|
|
import "./systemd-BatTMuQk.js";
|
|
import "./service-audit-awAeeSHD.js";
|
|
import "./table-CIkhZk5W.js";
|
|
import "./widearea-dns-CwnGNpiS.js";
|
|
import "./audit-DZnIqsqD.js";
|
|
import "./onboard-skills-BU79xI4E.js";
|
|
import "./health-format-DDKHUGhA.js";
|
|
import "./update-runner-BfDdZ4iY.js";
|
|
import "./github-copilot-auth-C4Wf7BJq.js";
|
|
import "./logging-56YfW4V5.js";
|
|
import "./hooks-status-Dyz0pY0O.js";
|
|
import "./status-_uaxR-iL.js";
|
|
import "./skills-status-zh2LneT8.js";
|
|
import "./tui-Bg1fpDyw.js";
|
|
import "./agent-D69tT_Dc.js";
|
|
import "./node-service-3V4T3lmf.js";
|
|
import "./status.update-MBIVdU7c.js";
|
|
import "./auth-health-B3zeXSBU.js";
|
|
import { a as findRoutedCommand, n as emitCliBanner, t as ensureConfigReady } from "./config-guard-Cnesf00L.js";
|
|
import "./help-format-GuCWws6r.js";
|
|
import "./configure-SBTKEFIw.js";
|
|
import "./systemd-linger-C0UIEsx9.js";
|
|
import "./doctor-BA7KAp19.js";
|
|
import path from "node:path";
|
|
import process$1 from "node:process";
|
|
import fs from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import dotenv from "dotenv";
|
|
|
|
//#region src/infra/dotenv.ts
|
|
function loadDotEnv(opts) {
|
|
const quiet = opts?.quiet ?? true;
|
|
dotenv.config({ quiet });
|
|
const globalEnvPath = path.join(resolveConfigDir(process.env), ".env");
|
|
if (!fs.existsSync(globalEnvPath)) return;
|
|
dotenv.config({
|
|
quiet,
|
|
path: globalEnvPath,
|
|
override: false
|
|
});
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/cli/route.ts
|
|
async function prepareRoutedCommand(params) {
|
|
emitCliBanner(VERSION, { argv: params.argv });
|
|
await ensureConfigReady({
|
|
runtime: defaultRuntime,
|
|
commandPath: params.commandPath
|
|
});
|
|
if (params.loadPlugins) ensurePluginRegistryLoaded();
|
|
}
|
|
async function tryRouteCli(argv) {
|
|
if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_ROUTE_FIRST)) return false;
|
|
if (hasHelpOrVersion(argv)) return false;
|
|
const path = getCommandPath(argv, 2);
|
|
if (!path[0]) return false;
|
|
const route = findRoutedCommand(path);
|
|
if (!route) return false;
|
|
await prepareRoutedCommand({
|
|
argv,
|
|
commandPath: path,
|
|
loadPlugins: route.loadPlugins
|
|
});
|
|
return route.run(argv);
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/cli/run-main.ts
|
|
function rewriteUpdateFlagArgv(argv) {
|
|
const index = argv.indexOf("--update");
|
|
if (index === -1) return argv;
|
|
const next = [...argv];
|
|
next.splice(index, 1, "update");
|
|
return next;
|
|
}
|
|
async function runCli(argv = process$1.argv) {
|
|
const normalizedArgv = stripWindowsNodeExec(argv);
|
|
loadDotEnv({ quiet: true });
|
|
normalizeEnv();
|
|
ensureOpenClawCliOnPath();
|
|
assertSupportedRuntime();
|
|
if (await tryRouteCli(normalizedArgv)) return;
|
|
enableConsoleCapture();
|
|
const { buildProgram } = await import("./program-BCF0Arom.js");
|
|
const program = buildProgram();
|
|
installUnhandledRejectionHandler();
|
|
process$1.on("uncaughtException", (error) => {
|
|
console.error("[openclaw] Uncaught exception:", formatUncaughtError(error));
|
|
process$1.exit(1);
|
|
});
|
|
const parseArgv = rewriteUpdateFlagArgv(normalizedArgv);
|
|
const primary = getPrimaryCommand(parseArgv);
|
|
if (primary) {
|
|
const { registerSubCliByName } = await import("./register.subclis-vcrz--DC.js");
|
|
await registerSubCliByName(program, primary);
|
|
}
|
|
if (!(!primary && hasHelpOrVersion(parseArgv))) {
|
|
const { registerPluginCliCommands } = await import("./cli-Ck74a9PE.js");
|
|
const { loadConfig } = await import("./config-s8j0aiMc.js");
|
|
registerPluginCliCommands(program, loadConfig());
|
|
}
|
|
await program.parseAsync(parseArgv);
|
|
}
|
|
function stripWindowsNodeExec(argv) {
|
|
if (process$1.platform !== "win32") return argv;
|
|
const stripControlChars = (value) => {
|
|
let out = "";
|
|
for (let i = 0; i < value.length; i += 1) {
|
|
const code = value.charCodeAt(i);
|
|
if (code >= 32 && code !== 127) out += value[i];
|
|
}
|
|
return out;
|
|
};
|
|
const normalizeArg = (value) => stripControlChars(value).replace(/^['"]+|['"]+$/g, "").trim();
|
|
const normalizeCandidate = (value) => normalizeArg(value).replace(/^\\\\\\?\\/, "");
|
|
const execPath = normalizeCandidate(process$1.execPath);
|
|
const execPathLower = execPath.toLowerCase();
|
|
const execBase = path.basename(execPath).toLowerCase();
|
|
const isExecPath = (value) => {
|
|
if (!value) return false;
|
|
const normalized = normalizeCandidate(value);
|
|
if (!normalized) return false;
|
|
const lower = normalized.toLowerCase();
|
|
return lower === execPathLower || path.basename(lower) === execBase || lower.endsWith("\\node.exe") || lower.endsWith("/node.exe") || lower.includes("node.exe") || path.basename(lower) === "node.exe" && fs.existsSync(normalized);
|
|
};
|
|
const filtered = argv.filter((arg, index) => index === 0 || !isExecPath(arg));
|
|
if (filtered.length < 3) return filtered;
|
|
const cleaned = [...filtered];
|
|
if (isExecPath(cleaned[1])) cleaned.splice(1, 1);
|
|
if (isExecPath(cleaned[2])) cleaned.splice(2, 1);
|
|
return cleaned;
|
|
}
|
|
|
|
//#endregion
|
|
export { runCli }; |