fix(cli): route logs to stderr in 'openclaw agent --json' to prevent plugin loading pollution

This commit is contained in:
ziy 2026-03-20 22:30:58 +08:00
parent dc86b6d72a
commit 7caf1239ad

View File

@ -1,4 +1,5 @@
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
import { routeLogsToStderr } from "../logging.js";
import { listAgentIds } from "../agents/agent-scope.js";
import { formatCliCommand } from "../cli/command-format.js";
import type { CliDeps } from "../cli/deps.js";
@ -179,6 +180,11 @@ export async function agentViaGatewayCommand(opts: AgentCliOpts, runtime: Runtim
}
export async function agentCliCommand(opts: AgentCliOpts, runtime: RuntimeEnv, deps?: CliDeps) {
// When --json is set, route all logs to stderr so only the JSON result appears on stdout.
if (opts.json) {
routeLogsToStderr();
}
const localOpts = {
...opts,
agentId: opts.agent,