This commit is contained in:
Bestom927 2026-01-29 19:00:16 +00:00 committed by GitHub
commit 34698dd61a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,11 +76,14 @@ const DEFAULT_APPROVAL_TIMEOUT_MS = 120_000;
const DEFAULT_APPROVAL_REQUEST_TIMEOUT_MS = 130_000; const DEFAULT_APPROVAL_REQUEST_TIMEOUT_MS = 130_000;
const DEFAULT_APPROVAL_RUNNING_NOTICE_MS = 10_000; const DEFAULT_APPROVAL_RUNNING_NOTICE_MS = 10_000;
const APPROVAL_SLUG_LENGTH = 8; const APPROVAL_SLUG_LENGTH = 8;
const TIMEOUT_FINALIZE_MS = 1000;
const PTY_DEFAULT_COLS = 120;
const PTY_DEFAULT_ROWS = 30;
type PtyExitEvent = { exitCode: number; signal?: number }; type PtyExitEvent = { exitCode: number; signal?: number };
type PtyListener<T> = (event: T) => void; type PtyListener<T> = (event: T) => void;
type PtyHandle = { type PtyHandle = {
pid: number; readonly pid: number;
write: (data: string | Buffer) => void; write: (data: string | Buffer) => void;
onData: (listener: PtyListener<string>) => void; onData: (listener: PtyListener<string>) => void;
onExit: (listener: PtyListener<PtyExitEvent>) => void; onExit: (listener: PtyListener<PtyExitEvent>) => void;
@ -405,14 +408,14 @@ async function runExecProcess(opts: {
}; };
const spawnPty = ptyModule.spawn ?? ptyModule.default?.spawn; const spawnPty = ptyModule.spawn ?? ptyModule.default?.spawn;
if (!spawnPty) { if (!spawnPty) {
throw new Error("PTY support is unavailable (node-pty spawn not found)."); throw new Error("PTY support is unavailable. Please install @lydell/node-pty or run without pty=true.");
} }
pty = spawnPty(shell, [...shellArgs, opts.command], { pty = spawnPty(shell, [...shellArgs, opts.command], {
cwd: opts.workdir, cwd: opts.workdir,
env: opts.env, env: opts.env,
name: process.env.TERM ?? "xterm-256color", name: process.env.TERM ?? "xterm-256color",
cols: 120, cols: PTY_DEFAULT_COLS,
rows: 30, rows: PTY_DEFAULT_ROWS,
}); });
stdin = { stdin = {
destroyed: false, destroyed: false,
@ -524,7 +527,7 @@ async function runExecProcess(opts: {
let timeoutTimer: NodeJS.Timeout | null = null; let timeoutTimer: NodeJS.Timeout | null = null;
let timeoutFinalizeTimer: NodeJS.Timeout | null = null; let timeoutFinalizeTimer: NodeJS.Timeout | null = null;
let timedOut = false; let timedOut = false;
const timeoutFinalizeMs = 1000; const timeoutFinalizeMs = TIMEOUT_FINALIZE_MS;
let resolveFn: ((outcome: ExecProcessOutcome) => void) | null = null; let resolveFn: ((outcome: ExecProcessOutcome) => void) | null = null;
const settle = (outcome: ExecProcessOutcome) => { const settle = (outcome: ExecProcessOutcome) => {
@ -751,8 +754,8 @@ export function createExecTool(
node?: string; node?: string;
}; };
if (!params.command) { if (!params.command?.trim()) {
throw new Error("Provide a command to start."); throw new Error("Command is required. Please provide a valid shell command to execute.");
} }
const maxOutput = DEFAULT_MAX_OUTPUT; const maxOutput = DEFAULT_MAX_OUTPUT;