@@ -22,6 +22,8 @@ import type { SendMessageError } from "@/types/errors";
2222import type { StreamErrorMessage , SendMessageOptions , DeleteMessage } from "@/types/ipc" ;
2323import { Ok , Err } from "@/types/result" ;
2424import { validateWorkspaceName } from "@/utils/validation/workspaceValidation" ;
25+ import { createBashTool } from "@/services/tools/bash" ;
26+ import type { BashToolResult } from "@/types/tools" ;
2527
2628const createUnknownSendMessageError = ( raw : string ) : SendMessageError => ( {
2729 type : "unknown" ,
@@ -536,6 +538,48 @@ export class IpcMain {
536538 return { success : true , data : undefined } ;
537539 }
538540 ) ;
541+
542+ ipcMain . handle (
543+ IPC_CHANNELS . WORKSPACE_EXECUTE_BASH ,
544+ async (
545+ _event ,
546+ workspaceId : string ,
547+ script : string ,
548+ options ?: { timeout_secs ?: number ; max_lines ?: number ; stdin ?: string }
549+ ) => {
550+ try {
551+ // Get workspace metadata to find workspacePath
552+ const metadataResult = await this . aiService . getWorkspaceMetadata ( workspaceId ) ;
553+ if ( ! metadataResult . success ) {
554+ return Err ( `Failed to get workspace metadata: ${ metadataResult . error } ` ) ;
555+ }
556+
557+ const workspacePath = metadataResult . data . workspacePath ;
558+
559+ // Create bash tool with workspace's cwd
560+ const bashTool = createBashTool ( { cwd : workspacePath } ) ;
561+
562+ // Execute the script with provided options
563+ const result = ( await bashTool . execute ! (
564+ {
565+ script,
566+ timeout_secs : options ?. timeout_secs ?? 120 ,
567+ max_lines : options ?. max_lines ?? 1000 ,
568+ stdin : options ?. stdin ,
569+ } ,
570+ {
571+ toolCallId : `bash-${ Date . now ( ) } ` ,
572+ messages : [ ] ,
573+ }
574+ ) ) as BashToolResult ;
575+
576+ return Ok ( result ) ;
577+ } catch ( error ) {
578+ const message = error instanceof Error ? error . message : String ( error ) ;
579+ return Err ( `Failed to execute bash command: ${ message } ` ) ;
580+ }
581+ }
582+ ) ;
539583 }
540584
541585 private registerProviderHandlers ( ipcMain : ElectronIpcMain ) : void {
0 commit comments