Add configurable timeout parameter to runTerminalCommand tool

This commit is contained in:
Nate
2025-12-05 18:07:50 -08:00
parent 0ed5285f6c
commit 2441b0fecc

View File

@@ -45,6 +45,11 @@ IMPORTANT: To edit files, use Edit/MultiEdit tools instead of bash commands (sed
type: "string",
description: "The command to execute in the terminal.",
},
timeout: {
type: "number",
description:
"Optional timeout in seconds (max 600). Only use this parameter when a command takes too long and times out with the default 120 second timeout.",
},
},
},
readonly: false,
@@ -75,7 +80,13 @@ IMPORTANT: To edit files, use Edit/MultiEdit tools instead of bash commands (sed
],
};
},
run: async ({ command }: { command: string }): Promise<string> => {
run: async ({
command,
timeout,
}: {
command: string;
timeout?: number;
}): Promise<string> => {
return new Promise((resolve, reject) => {
// Use same shell logic as core implementation
const { shell, args } = getShellCommand(command);
@@ -85,10 +96,18 @@ IMPORTANT: To edit files, use Edit/MultiEdit tools instead of bash commands (sed
let timeoutId: NodeJS.Timeout;
let isResolved = false;
const TIMEOUT_MS =
process.env.NODE_ENV === "test" && process.env.TEST_TERMINAL_TIMEOUT
? parseInt(process.env.TEST_TERMINAL_TIMEOUT, 10)
: 120000; // 120 seconds default, configurable for tests
// Determine timeout: use provided timeout (capped at 600s), test env variable, or default 120s
let TIMEOUT_MS = 180000; // 180 seconds default
if (timeout !== undefined) {
// Cap at 600 seconds (10 minutes)
const cappedTimeout = Math.min(timeout, 600);
TIMEOUT_MS = cappedTimeout * 1000;
} else if (
process.env.NODE_ENV === "test" &&
process.env.TEST_TERMINAL_TIMEOUT
) {
TIMEOUT_MS = parseInt(process.env.TEST_TERMINAL_TIMEOUT, 10);
}
const resetTimeout = () => {
if (timeoutId) {