repo-tools: Strip ANSI codes and set NO_COLOR for CLI report extraction

Cleye outputs ANSI bold escape sequences around section headers
(e.g. Usage:, Flags:) unconditionally, which prevented the help
page parser from recognizing them. Strip ANSI SGR sequences from
captured output and set NO_COLOR=1 in the child environment.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-02-27 10:45:56 +01:00
parent f2a8299d7a
commit aac8cd4cc2
+5 -20
View File
@@ -15,17 +15,12 @@
*/
import { spawnSync } from 'node:child_process';
import {
openSync,
closeSync,
readFileSync,
unlinkSync,
statSync,
} from 'node:fs';
import { openSync, closeSync, readFileSync, unlinkSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
console.error('[util.ts] createBinRunner module loaded');
// Matches ANSI SGR escape sequences (e.g. bold, color, reset)
const ansiPattern = new RegExp(`${String.fromCharCode(0x1b)}\\[[0-9;]*m`, 'g');
/**
* Redirect stdout to a temp file so that Node.js creates a SyncWriteStream
@@ -45,22 +40,12 @@ export function createBinRunner(cwd: string, path: string) {
try {
const result = spawnSync('node', args, {
cwd,
env: { ...process.env, NO_COLOR: '1' },
stdio: ['ignore', outFd, 'pipe'],
maxBuffer: 10 * 1024 * 1024,
});
closeSync(outFd);
const fileSize = statSync(outPath).size;
const stdout = readFileSync(outPath, 'utf8');
// Temporary debug: log first 200 chars of every command
console.error(
`[debug] ${args
.slice(-2)
.join(' ')} size=${fileSize} out=${JSON.stringify(
stdout.slice(0, 200),
)}`,
);
const stdout = readFileSync(outPath, 'utf8').replace(ansiPattern, '');
if (result.error) {
throw new Error(`Process error: ${result.error.message}`);