Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/core/brain/tools/definitions/system/bash.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@

import { spawn, ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import { platform } from 'os';
import {
createInternalToolName,
type InternalTool,
type InternalToolHandler,
} from '../../types.js';
import { logger } from '../../../../logger/index.js';

/**
* Get the appropriate shell command and args for the current OS
*/
function getShellCommand(): { shell: string; args: string[] } {
if (platform() === 'win32') {
return { shell: 'cmd.exe', args: ['/c'] };
}
return { shell: '/bin/bash', args: ['-c'] };
}

/**
* Command execution result structure
*/
Expand Down Expand Up @@ -66,7 +77,8 @@ class BashSession extends EventEmitter {

try {
// Start bash process with non-interactive mode to avoid prompt issues
this.process = spawn('/bin/bash', [], {
const { shell, args } = getShellCommand();
this.process = spawn(shell, args, {
cwd: this.currentWorkingDir,
Comment on lines 78 to 82

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Persistent sessions spawn non-interactive shell

The new getShellCommand always adds ['-c'] (or ['/c'] on Windows) and initialize() now uses those args when starting the persistent shell. Both bash -c and cmd.exe /c immediately exit after running a command, so launching them without a command ends the process at once and the BashSession never stays active. As a result, any call to the tool with persistent: true fails on all platforms because session.executeCommand will throw "Bash session is not running". Persistent sessions need an interactive shell (bash with no -c, cmd.exe without /c or with /K).

Useful? React with 👍 / 👎.

stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env },
Expand Down Expand Up @@ -240,7 +252,7 @@ class BashSessionManager {
* Execute a bash command with optional session persistence
*/
async function executeBashCommand(options: CommandOptions): Promise<CommandResult> {
const { command, timeout = 30000, workingDir, environment, shell = '/bin/bash' } = options;
const { command, timeout = 30000, workingDir, environment } = options;

logger.debug('Executing bash command', { command, timeout, workingDir });

Expand All @@ -254,7 +266,8 @@ async function executeBashCommand(options: CommandOptions): Promise<CommandResul
let output = '';
let error = '';

const childProcess = spawn(shell, ['-c', command], {
const { shell, args } = getShellCommand();
const childProcess = spawn(shell, [...args, command], {
cwd: workingDir || process.cwd(),
env: { ...process.env, ...environment },
stdio: ['pipe', 'pipe', 'pipe'],
Expand Down
Loading