From b0f6da8001e9a253326b2552ce8b679dca18880e Mon Sep 17 00:00:00 2001 From: David Gil - Klaus Date: Thu, 19 Feb 2026 23:43:04 +0100 Subject: [PATCH] fix(cli): suppress progress bars and indexing output when not TTY When stdout/stderr is not a terminal (e.g., captured by a parent process), OSC 9;4 progress sequences and carriage-return-based status lines produce massive output (247K chars for a typical update). This caused OpenClaw's qmd update to fail with 'too much output' errors, retrying ~24 times per 10 minutes. Gate all progress output on process.stderr.isTTY. Summary lines still print normally. --- src/qmd.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/qmd.ts b/src/qmd.ts index d57b7e8..ed70baf 100755 --- a/src/qmd.ts +++ b/src/qmd.ts @@ -165,19 +165,20 @@ const cursor = { process.on('SIGINT', () => { cursor.show(); process.exit(130); }); process.on('SIGTERM', () => { cursor.show(); process.exit(143); }); -// Terminal progress bar using OSC 9;4 escape sequence +// Terminal progress bar using OSC 9;4 escape sequence (TTY only) +const isTTY = process.stderr.isTTY; const progress = { set(percent: number) { - process.stderr.write(`\x1b]9;4;1;${Math.round(percent)}\x07`); + if (isTTY) process.stderr.write(`\x1b]9;4;1;${Math.round(percent)}\x07`); }, clear() { - process.stderr.write(`\x1b]9;4;0\x07`); + if (isTTY) process.stderr.write(`\x1b]9;4;0\x07`); }, indeterminate() { - process.stderr.write(`\x1b]9;4;3\x07`); + if (isTTY) process.stderr.write(`\x1b]9;4;3\x07`); }, error() { - process.stderr.write(`\x1b]9;4;2\x07`); + if (isTTY) process.stderr.write(`\x1b]9;4;2\x07`); }, }; @@ -1491,7 +1492,7 @@ async function indexFiles(pwd?: string, globPattern: string = DEFAULT_GLOB, coll const rate = processed / elapsed; const remaining = (total - processed) / rate; const eta = processed > 2 ? ` ETA: ${formatETA(remaining)}` : ""; - process.stderr.write(`\rIndexing: ${processed}/${total}${eta} `); + if (isTTY) process.stderr.write(`\rIndexing: ${processed}/${total}${eta} `); } // Deactivate documents in this collection that no longer exist @@ -1682,7 +1683,7 @@ async function vectorIndex(model: string = DEFAULT_EMBED_MODEL, force: boolean = const eta = elapsed > 2 ? formatETA(etaSec) : "..."; const errStr = errors > 0 ? ` ${c.yellow}${errors} err${c.reset}` : ""; - process.stderr.write(`\r${c.cyan}${bar}${c.reset} ${c.bold}${percentStr}%${c.reset} ${c.dim}${chunksEmbedded}/${totalChunks}${c.reset}${errStr} ${c.dim}${throughput} ETA ${eta}${c.reset} `); + if (isTTY) process.stderr.write(`\r${c.cyan}${bar}${c.reset} ${c.bold}${percentStr}%${c.reset} ${c.dim}${chunksEmbedded}/${totalChunks}${c.reset}${errStr} ${c.dim}${throughput} ETA ${eta}${c.reset} `); } progress.clear();