strip ansi from shell output (#699)

This commit is contained in:
Olcan 2025-06-02 14:50:12 -07:00 committed by GitHub
parent 51949f3121
commit 1dcf0a4cbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import crypto from 'crypto';
import path from 'path';
import os from 'os';
import fs from 'fs';
import stripAnsi from 'strip-ansi';
const OUTPUT_UPDATE_INTERVAL_MS = 1000;
@ -126,12 +127,12 @@ export const useShellCommandProcessor = (
let exited = false;
let output = '';
let lastUpdateTime = Date.now();
const handleOutput = (data: string) => {
const handleOutput = (data: Buffer) => {
// continue to consume post-exit for background processes
// removing listeners can overflow OS buffer and block subprocesses
// destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE
if (!exited) {
output += data;
output += stripAnsi(data.toString());
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
setPendingHistoryItem({
type: 'info',

View File

@ -18,6 +18,8 @@ import {
} from './tools.js';
import { SchemaValidator } from '../utils/schemaValidator.js';
import { getErrorMessage } from '../utils/errors.js';
import stripAnsi from 'strip-ansi';
export interface ShellToolParams {
command: string;
description?: string;
@ -177,7 +179,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
// removing listeners can overflow OS buffer and block subprocesses
// destroying (e.g. shell.stdout.destroy()) can terminate subprocesses via SIGPIPE
if (!exited) {
const str = data.toString();
const str = stripAnsi(data.toString());
stdout += str;
appendOutput(str);
}
@ -186,7 +188,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
let stderr = '';
shell.stderr.on('data', (data: Buffer) => {
if (!exited) {
const str = data.toString();
const str = stripAnsi(data.toString());
stderr += str;
appendOutput(str);
}