| |
| |
| |
| |
| |
|
|
| import { |
| type AgentLoopContext, |
| ShellExecutionService, |
| ShellTool, |
| type Config as CoreConfig, |
| } from '@google/gemini-cli-core'; |
| import type { |
| AgentShell, |
| AgentShellResult, |
| AgentShellOptions, |
| } from './types.js'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class SdkAgentShell implements AgentShell { |
| constructor(private readonly config: CoreConfig) {} |
|
|
| async exec( |
| command: string, |
| options?: AgentShellOptions, |
| ): Promise<AgentShellResult> { |
| const cwd = options?.cwd || this.config.getWorkingDir(); |
| const abortController = new AbortController(); |
|
|
| |
| const loopContext: AgentLoopContext = this.config; |
| const shellTool = new ShellTool(this.config, loopContext.messageBus); |
| try { |
| const invocation = shellTool.build({ |
| command, |
| dir_path: cwd, |
| }); |
|
|
| const confirmation = await invocation.shouldConfirmExecute( |
| abortController.signal, |
| ); |
| if (confirmation) { |
| throw new Error( |
| 'Command execution requires confirmation but no interactive session is available.', |
| ); |
| } |
| } catch (error) { |
| return { |
| output: '', |
| stdout: '', |
| stderr: '', |
| exitCode: 1, |
| error: error instanceof Error ? error : new Error(String(error)), |
| }; |
| } |
|
|
| const handle = await ShellExecutionService.execute( |
| command, |
| cwd, |
| () => {}, |
| abortController.signal, |
| false, |
| this.config.getShellExecutionConfig(), |
| ); |
|
|
| const result = await handle.result; |
|
|
| return { |
| output: result.output, |
| stdout: result.output, |
| stderr: '', |
| exitCode: result.exitCode, |
| }; |
| } |
| } |
|
|