Files
openclaw/src/cli/command-registration-policy.ts
2026-04-29 13:47:03 +01:00

42 lines
1.3 KiB
TypeScript

import { isTruthyEnvValue } from "../infra/env.js";
import { resolveCliArgvInvocation } from "./argv-invocation.js";
const RESERVED_NON_PLUGIN_COMMAND_ROOTS = new Set(["tools"]);
export function shouldRegisterPrimaryCommandOnly(argv: string[]): boolean {
const invocation = resolveCliArgvInvocation(argv);
return invocation.primary !== null || !invocation.hasHelpOrVersion;
}
export function shouldSkipPluginCommandRegistration(params: {
argv: string[];
primary: string | null;
hasBuiltinPrimary: boolean;
}): boolean {
if (params.hasBuiltinPrimary) {
return true;
}
const invocation = resolveCliArgvInvocation(params.argv);
if (params.primary === "help") {
return invocation.hasHelpOrVersion && invocation.commandPath.length <= 1;
}
if (!params.primary) {
return invocation.hasHelpOrVersion;
}
if (RESERVED_NON_PLUGIN_COMMAND_ROOTS.has(params.primary)) {
return true;
}
return false;
}
export function shouldEagerRegisterSubcommands(env: NodeJS.ProcessEnv = process.env): boolean {
return isTruthyEnvValue(env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS);
}
export function shouldRegisterPrimarySubcommandOnly(
argv: string[],
env: NodeJS.ProcessEnv = process.env,
): boolean {
return !shouldEagerRegisterSubcommands(env) && shouldRegisterPrimaryCommandOnly(argv);
}