Files
openclaw/src/cli/command-startup-policy.ts
Peter Steinberger 250376f885 fix: simplify bundled runtime dependency repair (#75183)
Summary:
- Merged fix: simplify bundled runtime dependency repair after ClawSweeper review.

ClawSweeper fixups:
- Included follow-up commit: fix: verify cached bundled runtime roots
- Included follow-up commit: refactor: simplify plugin runtime startup paths
- Included follow-up commit: refactor: trim plugin startup policy helpers
- Included follow-up commit: refactor: trust package manager runtime deps materialization
- Included follow-up commit: fix: narrow channel runtime deps skip policy
- Included follow-up commit: refactor: defer startup plugin runtime deps
- Ran the ClawSweeper repair loop before final review.

Validation:
- ClawSweeper review passed for head 04dc566534.
- Required merge gates passed before the squash merge.

Prepared head SHA: 04dc566534
Review: https://github.com/openclaw/openclaw/pull/75183#issuecomment-4358383786

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Shakker <shakkerdroid@gmail.com>
Co-authored-by: clawsweeper-repair <clawsweeper-repair@users.noreply.github.com>
2026-05-01 07:49:02 +00:00

90 lines
2.9 KiB
TypeScript

import { isTruthyEnvValue } from "../infra/env.js";
import type { CliCommandPluginLoadPolicy } from "./command-catalog.js";
import { resolveCliCommandPathPolicy } from "./command-path-policy.js";
export function shouldBypassConfigGuardForCommandPath(commandPath: string[]): boolean {
return resolveCliCommandPathPolicy(commandPath).bypassConfigGuard;
}
export function shouldSkipRouteConfigGuardForCommandPath(params: {
commandPath: string[];
suppressDoctorStdout: boolean;
}): boolean {
const routeConfigGuard = resolveCliCommandPathPolicy(params.commandPath).routeConfigGuard;
return (
routeConfigGuard === "always" ||
(routeConfigGuard === "when-suppressed" && params.suppressDoctorStdout)
);
}
export function shouldLoadPluginsForCommandPath(params: {
argv?: string[];
commandPath: string[];
jsonOutputMode: boolean;
}): boolean {
return shouldLoadPlugins({
loadPlugins: resolveCliCommandPathPolicy(params.commandPath).loadPlugins,
argv: params.argv,
commandPath: params.commandPath,
jsonOutputMode: params.jsonOutputMode,
});
}
function shouldLoadPlugins(params: {
argv?: string[];
commandPath: string[];
jsonOutputMode: boolean;
loadPlugins: CliCommandPluginLoadPolicy;
}): boolean {
const loadPlugins = params.loadPlugins;
if (typeof loadPlugins === "function") {
return loadPlugins({
argv: params.argv ?? [],
commandPath: params.commandPath,
jsonOutputMode: params.jsonOutputMode,
});
}
return loadPlugins === "always" || (loadPlugins === "text-only" && !params.jsonOutputMode);
}
export function shouldHideCliBannerForCommandPath(
commandPath: string[],
env: NodeJS.ProcessEnv = process.env,
): boolean {
return (
isTruthyEnvValue(env.OPENCLAW_HIDE_BANNER) ||
resolveCliCommandPathPolicy(commandPath).hideBanner
);
}
export function shouldEnsureCliPathForCommandPath(commandPath: string[]): boolean {
return commandPath.length === 0 || resolveCliCommandPathPolicy(commandPath).ensureCliPath;
}
export function resolveCliStartupPolicy(params: {
argv?: string[];
commandPath: string[];
jsonOutputMode: boolean;
env?: NodeJS.ProcessEnv;
routeMode?: boolean;
}) {
const suppressDoctorStdout = params.jsonOutputMode;
const commandPolicy = resolveCliCommandPathPolicy(params.commandPath);
const env = params.env ?? process.env;
return {
suppressDoctorStdout,
hideBanner: isTruthyEnvValue(env.OPENCLAW_HIDE_BANNER) || commandPolicy.hideBanner,
skipConfigGuard: params.routeMode
? commandPolicy.routeConfigGuard === "always" ||
(commandPolicy.routeConfigGuard === "when-suppressed" && suppressDoctorStdout)
: false,
loadPlugins: shouldLoadPlugins({
argv: params.argv,
commandPath: params.commandPath,
jsonOutputMode: params.jsonOutputMode,
loadPlugins: commandPolicy.loadPlugins,
}),
pluginRegistry: commandPolicy.pluginRegistry,
};
}