strip ansi from shell output (#699)
This commit is contained in:
parent
51949f3121
commit
1dcf0a4cbd
|
@ -15,6 +15,7 @@ import crypto from 'crypto';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import stripAnsi from 'strip-ansi';
|
||||||
|
|
||||||
const OUTPUT_UPDATE_INTERVAL_MS = 1000;
|
const OUTPUT_UPDATE_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
|
@ -126,12 +127,12 @@ export const useShellCommandProcessor = (
|
||||||
let exited = false;
|
let exited = false;
|
||||||
let output = '';
|
let output = '';
|
||||||
let lastUpdateTime = Date.now();
|
let lastUpdateTime = Date.now();
|
||||||
const handleOutput = (data: string) => {
|
const handleOutput = (data: Buffer) => {
|
||||||
// continue to consume post-exit for background processes
|
// continue to consume post-exit for background processes
|
||||||
// removing listeners can overflow OS buffer and block subprocesses
|
// removing listeners can overflow OS buffer and block subprocesses
|
||||||
// destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE
|
// destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE
|
||||||
if (!exited) {
|
if (!exited) {
|
||||||
output += data;
|
output += stripAnsi(data.toString());
|
||||||
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
|
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
|
||||||
setPendingHistoryItem({
|
setPendingHistoryItem({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
|
|
|
@ -18,6 +18,8 @@ import {
|
||||||
} from './tools.js';
|
} from './tools.js';
|
||||||
import { SchemaValidator } from '../utils/schemaValidator.js';
|
import { SchemaValidator } from '../utils/schemaValidator.js';
|
||||||
import { getErrorMessage } from '../utils/errors.js';
|
import { getErrorMessage } from '../utils/errors.js';
|
||||||
|
import stripAnsi from 'strip-ansi';
|
||||||
|
|
||||||
export interface ShellToolParams {
|
export interface ShellToolParams {
|
||||||
command: string;
|
command: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
@ -177,7 +179,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
// removing listeners can overflow OS buffer and block subprocesses
|
// removing listeners can overflow OS buffer and block subprocesses
|
||||||
// destroying (e.g. shell.stdout.destroy()) can terminate subprocesses via SIGPIPE
|
// destroying (e.g. shell.stdout.destroy()) can terminate subprocesses via SIGPIPE
|
||||||
if (!exited) {
|
if (!exited) {
|
||||||
const str = data.toString();
|
const str = stripAnsi(data.toString());
|
||||||
stdout += str;
|
stdout += str;
|
||||||
appendOutput(str);
|
appendOutput(str);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +188,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
shell.stderr.on('data', (data: Buffer) => {
|
shell.stderr.on('data', (data: Buffer) => {
|
||||||
if (!exited) {
|
if (!exited) {
|
||||||
const str = data.toString();
|
const str = stripAnsi(data.toString());
|
||||||
stderr += str;
|
stderr += str;
|
||||||
appendOutput(str);
|
appendOutput(str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue