From 6020c760b5805b3e12ba30ce98cf9eb2dc76bd60 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 2 Jun 2025 15:35:03 -0700 Subject: [PATCH] Feat: Enable YOLO mode for non-interactive execution (#702) --- packages/cli/src/gemini.tsx | 74 ++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index f8cc77b6..8caec007 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -13,11 +13,13 @@ import { readPackageUp } from 'read-package-up'; import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; import { sandbox_command, start_sandbox } from './utils/sandbox.js'; -import { loadSettings } from './config/settings.js'; +import { LoadedSettings, loadSettings } from './config/settings.js'; import { themeManager } from './ui/themes/theme-manager.js'; import { getStartupWarnings } from './utils/startupWarnings.js'; import { runNonInteractive } from './nonInteractiveCli.js'; import { + ApprovalMode, + Config, EditTool, GlobTool, GrepTool, @@ -114,32 +116,14 @@ async function main() { } // Non-interactive mode handled by runNonInteractive - let existingCoreTools = config.getCoreTools(); - existingCoreTools = existingCoreTools || [ - ReadFileTool.Name, - LSTool.Name, - GrepTool.Name, - GlobTool.Name, - EditTool.Name, - WriteFileTool.Name, - WebFetchTool.Name, - WebSearchTool.Name, - ReadManyFilesTool.Name, - ShellTool.Name, - MemoryTool.Name, - ]; - const interactiveTools = [ShellTool.Name, EditTool.Name, WriteFileTool.Name]; - const nonInteractiveTools = existingCoreTools.filter( - (tool) => !interactiveTools.includes(tool), + const nonInteractiveConfigResult = await loadNonInteractiveConfig( + config, + settings, ); - const nonInteractiveSettings = { - ...settings.merged, - coreTools: nonInteractiveTools, - }; - const nonInteractiveConfigResult = await loadCliConfig( - nonInteractiveSettings, - ); // Ensure config is reloaded with non-interactive tools - await runNonInteractive(nonInteractiveConfigResult.config, input); + + const nonInteractiveConfig = nonInteractiveConfigResult; + await runNonInteractive(nonInteractiveConfig, input); + process.exit(0); } // --- Global Unhandled Rejection Handler --- @@ -167,3 +151,41 @@ main().catch((error) => { } process.exit(1); }); +async function loadNonInteractiveConfig( + config: Config, + settings: LoadedSettings, +) { + if (config.getApprovalMode() === ApprovalMode.YOLO) { + // Since everything is being allowed we can use normal yolo behavior. + return config; + } + + // Everything is not allowed, ensure that only read-only tools are configured. + + let existingCoreTools = config.getCoreTools(); + existingCoreTools = existingCoreTools || [ + ReadFileTool.Name, + LSTool.Name, + GrepTool.Name, + GlobTool.Name, + EditTool.Name, + WriteFileTool.Name, + WebFetchTool.Name, + WebSearchTool.Name, + ReadManyFilesTool.Name, + ShellTool.Name, + MemoryTool.Name, + ]; + const interactiveTools = [ShellTool.Name, EditTool.Name, WriteFileTool.Name]; + const nonInteractiveTools = existingCoreTools.filter( + (tool) => !interactiveTools.includes(tool), + ); + const nonInteractiveSettings = { + ...settings.merged, + coreTools: nonInteractiveTools, + }; + const nonInteractiveConfigResult = await loadCliConfig( + nonInteractiveSettings, + ); + return nonInteractiveConfigResult.config; +}