diff --git a/extensions/cli/src/tools/runTerminalCommand.ts b/extensions/cli/src/tools/runTerminalCommand.ts index cfa096655..f6c2809c5 100644 --- a/extensions/cli/src/tools/runTerminalCommand.ts +++ b/extensions/cli/src/tools/runTerminalCommand.ts @@ -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 => { + run: async ({ + command, + timeout, + }: { + command: string; + timeout?: number; + }): Promise => { 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) {