fix(cli): route logs to stderr during shell completion output (openclaw#15496) thanks @arosstale

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test

Co-authored-by: arosstale <117890364+arosstale@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
Artale
2026-02-14 02:14:53 +01:00
committed by GitHub
parent 87b31acbb5
commit 643288fda8
2 changed files with 6 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { resolveStateDir } from "../config/paths.js";
import { routeLogsToStderr } from "../logging/console.js";
import { pathExists } from "../utils.js";
import { getSubCliEntries, registerSubCliByName } from "./program/register.subclis.js";
@@ -235,6 +236,9 @@ export function registerCompletionCli(program: Command) {
)
.option("-y, --yes", "Skip confirmation (non-interactive)", false)
.action(async (options) => {
// Route logs to stderr so plugin loading messages do not corrupt
// the completion script written to stdout.
routeLogsToStderr();
const shell = options.shell ?? "zsh";
// Eagerly register all subcommands to build the full tree
const entries = getSubCliEntries();
@@ -269,7 +273,7 @@ export function registerCompletionCli(program: Command) {
throw new Error(`Unsupported shell: ${shell}`);
}
const script = getCompletionScript(shell, program);
console.log(script);
process.stdout.write(script + "\n");
});
}