mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:20:43 +00:00
fix(cli): skip plugin bootstrap for json gateway agents
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { hasFlag } from "./argv.js";
|
||||
|
||||
export type CliCommandPluginLoadPolicy = "never" | "always" | "text-only";
|
||||
export type CliCommandPluginLoadPolicy =
|
||||
| "never"
|
||||
| "always"
|
||||
| "text-only"
|
||||
| ((ctx: { argv: string[]; commandPath: string[]; jsonOutputMode: boolean }) => boolean);
|
||||
export type CliRouteConfigGuardPolicy = "never" | "always" | "when-suppressed";
|
||||
export type CliNetworkProxyPolicy = "default" | "bypass";
|
||||
export type CliNetworkProxyPolicyResolver =
|
||||
@@ -48,7 +52,7 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
|
||||
{
|
||||
commandPath: ["agent"],
|
||||
policy: {
|
||||
loadPlugins: "always",
|
||||
loadPlugins: ({ argv, jsonOutputMode }) => hasFlag(argv, "--local") || !jsonOutputMode,
|
||||
networkProxy: ({ argv }) => (hasFlag(argv, "--local") ? "default" : "bypass"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -50,6 +50,37 @@ describe("command-execution-startup", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("skips local plugin bootstrap for JSON gateway agent calls", () => {
|
||||
expect(
|
||||
mod.resolveCliExecutionStartupContext({
|
||||
argv: ["node", "openclaw", "agent", "--agent", "main", "--message", "hi", "--json"],
|
||||
jsonOutputMode: true,
|
||||
}).startupPolicy.loadPlugins,
|
||||
).toBe(false);
|
||||
expect(
|
||||
mod.resolveCliExecutionStartupContext({
|
||||
argv: [
|
||||
"node",
|
||||
"openclaw",
|
||||
"agent",
|
||||
"--agent",
|
||||
"main",
|
||||
"--message",
|
||||
"hi",
|
||||
"--json",
|
||||
"--local",
|
||||
],
|
||||
jsonOutputMode: true,
|
||||
}).startupPolicy.loadPlugins,
|
||||
).toBe(true);
|
||||
expect(
|
||||
mod.resolveCliExecutionStartupContext({
|
||||
argv: ["node", "openclaw", "agent", "--agent", "main", "--message", "hi"],
|
||||
jsonOutputMode: false,
|
||||
}).startupPolicy.loadPlugins,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("routes logs to stderr and emits banner only when allowed", async () => {
|
||||
await mod.applyCliExecutionStartupPresentation({
|
||||
startupPolicy: {
|
||||
|
||||
@@ -18,6 +18,7 @@ export function resolveCliExecutionStartupContext(params: {
|
||||
invocation,
|
||||
commandPath,
|
||||
startupPolicy: resolveCliStartupPolicy({
|
||||
argv: params.argv,
|
||||
commandPath,
|
||||
jsonOutputMode: params.jsonOutputMode,
|
||||
env: params.env,
|
||||
|
||||
@@ -17,10 +17,18 @@ export function shouldSkipRouteConfigGuardForCommandPath(params: {
|
||||
}
|
||||
|
||||
export function shouldLoadPluginsForCommandPath(params: {
|
||||
argv?: string[];
|
||||
commandPath: string[];
|
||||
jsonOutputMode: boolean;
|
||||
}): boolean {
|
||||
const loadPlugins = resolveCliCommandPathPolicy(params.commandPath).loadPlugins;
|
||||
if (typeof loadPlugins === "function") {
|
||||
return loadPlugins({
|
||||
argv: params.argv ?? [],
|
||||
commandPath: params.commandPath,
|
||||
jsonOutputMode: params.jsonOutputMode,
|
||||
});
|
||||
}
|
||||
return loadPlugins === "always" || (loadPlugins === "text-only" && !params.jsonOutputMode);
|
||||
}
|
||||
|
||||
@@ -39,6 +47,7 @@ export function shouldEnsureCliPathForCommandPath(commandPath: string[]): boolea
|
||||
}
|
||||
|
||||
export function resolveCliStartupPolicy(params: {
|
||||
argv?: string[];
|
||||
commandPath: string[];
|
||||
jsonOutputMode: boolean;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
@@ -55,6 +64,7 @@ export function resolveCliStartupPolicy(params: {
|
||||
})
|
||||
: false,
|
||||
loadPlugins: shouldLoadPluginsForCommandPath({
|
||||
argv: params.argv,
|
||||
commandPath: params.commandPath,
|
||||
jsonOutputMode: params.jsonOutputMode,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user