feat: Introduce an AI-driven interactive shell mode with new

`read-shell` and `write-to-shell` tools and a configurable mode setting.
This commit is contained in:
Gaurav Ghosh
2026-03-20 13:39:10 -07:00
parent cbacdc67d0
commit 651ad63ed6
22 changed files with 906 additions and 83 deletions
+26 -1
View File
@@ -36,6 +36,8 @@ import { GlobTool } from '../tools/glob.js';
import { ActivateSkillTool } from '../tools/activate-skill.js';
import { EditTool } from '../tools/edit.js';
import { ShellTool } from '../tools/shell.js';
import { WriteToShellTool } from '../tools/write-to-shell.js';
import { ReadShellTool } from '../tools/read-shell.js';
import { WriteFileTool } from '../tools/write-file.js';
import { WebFetchTool } from '../tools/web-fetch.js';
import { MemoryTool, setGeminiMdFilename } from '../tools/memoryTool.js';
@@ -656,6 +658,7 @@ export interface ConfigParameters {
useRipgrep?: boolean;
enableInteractiveShell?: boolean;
shellBackgroundCompletionBehavior?: string;
interactiveShellMode?: 'human' | 'ai' | 'off';
skipNextSpeakerCheck?: boolean;
shellExecutionConfig?: ShellExecutionConfig;
extensionManagement?: boolean;
@@ -868,6 +871,7 @@ export class Config implements McpContext, AgentLoopContext {
| 'inject'
| 'notify'
| 'silent';
private readonly interactiveShellMode: 'human' | 'ai' | 'off';
private readonly skipNextSpeakerCheck: boolean;
private readonly useBackgroundColor: boolean;
private readonly useAlternateBuffer: boolean;
@@ -1235,6 +1239,14 @@ export class Config implements McpContext, AgentLoopContext {
this.shellBackgroundCompletionBehavior = 'silent';
}
// interactiveShellMode takes precedence over enableInteractiveShell.
// If not set, derive from enableInteractiveShell for backward compat.
if (params.interactiveShellMode) {
this.interactiveShellMode = params.interactiveShellMode;
} else {
this.interactiveShellMode = this.enableInteractiveShell ? 'human' : 'off';
}
this.skipNextSpeakerCheck = params.skipNextSpeakerCheck ?? true;
this.shellExecutionConfig = {
terminalWidth: params.shellExecutionConfig?.terminalWidth ?? 80,
@@ -3211,10 +3223,14 @@ export class Config implements McpContext, AgentLoopContext {
return (
this.interactive &&
this.ptyInfo !== 'child_process' &&
this.enableInteractiveShell
this.interactiveShellMode !== 'off'
);
}
getInteractiveShellMode(): 'human' | 'ai' | 'off' {
return this.interactiveShellMode;
}
isSkillsSupportEnabled(): boolean {
return this.skillsSupport;
}
@@ -3575,6 +3591,15 @@ export class Config implements McpContext, AgentLoopContext {
new ReadBackgroundOutputTool(this, this.messageBus),
),
);
// Register AI-driven interactive shell tools when mode is 'ai'
if (this.getInteractiveShellMode() === 'ai') {
maybeRegister(WriteToShellTool, () =>
registry.registerTool(new WriteToShellTool(this.messageBus)),
);
maybeRegister(ReadShellTool, () =>
registry.registerTool(new ReadShellTool(this.messageBus)),
);
}
if (!this.isMemoryManagerEnabled()) {
maybeRegister(MemoryTool, () =>
registry.registerTool(new MemoryTool(this.messageBus, this.storage)),