From 415b757d4a7e654ebf6eae50b67498d0ae49f7f2 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Mon, 5 May 2025 17:57:06 +0000 Subject: [PATCH] Remove passthroughCommands (#252) --- packages/cli/src/config/config.ts | 1 - .../ui/hooks/passthroughCommandProcessor.ts | 108 ------------------ packages/cli/src/ui/hooks/useGeminiStream.ts | 15 --- packages/server/src/config/config.ts | 9 -- 4 files changed, 133 deletions(-) delete mode 100644 packages/cli/src/ui/hooks/passthroughCommandProcessor.ts diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 94390ec1..20ca7806 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -88,7 +88,6 @@ export async function loadCliConfig(settings: Settings): Promise { process.cwd(), argv.debug_mode || false, argv.question || '', - undefined, // TODO: load passthroughCommands from .env file argv.full_context || false, ); } diff --git a/packages/cli/src/ui/hooks/passthroughCommandProcessor.ts b/packages/cli/src/ui/hooks/passthroughCommandProcessor.ts deleted file mode 100644 index 97244e8c..00000000 --- a/packages/cli/src/ui/hooks/passthroughCommandProcessor.ts +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import { exec as _exec } from 'child_process'; -import { useCallback } from 'react'; -import { Config } from '@gemini-code/server'; -import { type PartListUnion } from '@google/genai'; -import { HistoryItem, StreamingState } from '../types.js'; -import { getCommandFromQuery } from '../utils/commandUtils.js'; - -// Helper function (consider moving to a shared util if used elsewhere) -const addHistoryItem = ( - setHistory: React.Dispatch>, - itemData: Omit, - id: number, -) => { - setHistory((prevHistory) => [ - ...prevHistory, - { ...itemData, id } as HistoryItem, - ]); -}; - -export const usePassthroughProcessor = ( - setHistory: React.Dispatch>, - setStreamingState: React.Dispatch>, - setDebugMessage: React.Dispatch>, - getNextMessageId: (baseTimestamp: number) => number, - config: Config, -) => { - const handlePassthroughCommand = useCallback( - (rawQuery: PartListUnion): boolean => { - if (typeof rawQuery !== 'string') { - return false; // Passthrough only works with string commands - } - - const trimmedQuery = rawQuery.trim(); - if (!trimmedQuery) { - return false; - } - - const [symbol, command] = getCommandFromQuery(trimmedQuery); - - // Passthrough commands don't start with symbol - if (symbol !== undefined) { - return false; - } - - if (config.getPassthroughCommands().includes(command)) { - // Add user message *before* execution starts - const userMessageTimestamp = Date.now(); - addHistoryItem( - setHistory, - { type: 'user', text: trimmedQuery }, - userMessageTimestamp, - ); - - // Execute and capture output - const targetDir = config.getTargetDir(); - setDebugMessage( - `Executing pass through command in ${targetDir}: ${trimmedQuery}`, - ); - const execOptions = { - cwd: targetDir, - }; - - // Set state to Responding while the command runs - setStreamingState(StreamingState.Responding); - - _exec(trimmedQuery, execOptions, (error, stdout, stderr) => { - const timestamp = getNextMessageId(userMessageTimestamp); // Use user message time as base - if (error) { - addHistoryItem( - setHistory, - { type: 'error', text: error.message }, - timestamp, - ); - } else if (stderr) { - // Treat stderr as info for passthrough, as some tools use it for non-error output - addHistoryItem( - setHistory, - { type: 'info', text: stderr }, - timestamp, - ); - } else { - // Add stdout as an info message - addHistoryItem( - setHistory, - { type: 'info', text: stdout || '(Command produced no output)' }, - timestamp, - ); - } - // Set state back to Idle *after* command finishes and output is added - setStreamingState(StreamingState.Idle); - }); - - return true; // Command was handled - } - - return false; // Not a passthrough command - }, - [config, setDebugMessage, setHistory, setStreamingState, getNextMessageId], - ); - - return { handlePassthroughCommand }; -}; diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 52675145..2931bbc3 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -30,7 +30,6 @@ import { import { isAtCommand } from '../utils/commandUtils.js'; import { useSlashCommandProcessor } from './slashCommandProcessor.js'; import { useShellCommandProcessor } from './shellCommandProcessor.js'; -import { usePassthroughProcessor } from './passthroughCommandProcessor.js'; import { handleAtCommand } from './atCommandProcessor.js'; import { findSafeSplitPoint } from '../utils/markdownUtilities.js'; @@ -88,14 +87,6 @@ export const useGeminiStream = ( config, ); - const { handlePassthroughCommand } = usePassthroughProcessor( - setHistory, - setStreamingState, - setDebugMessage, - getNextMessageId, - config, - ); - // Initialize Client Effect - uses props now useEffect(() => { setInitError(null); @@ -177,11 +168,6 @@ export const useGeminiStream = ( return; } - // 3. Check for Passthrough Commands - if (handlePassthroughCommand(trimmedQuery)) { - return; - } - // 3. Check for @ Commands using the utility function if (isAtCommand(trimmedQuery)) { const atCommandResult = await handleAtCommand({ @@ -542,7 +528,6 @@ export const useGeminiStream = ( getNextMessageId, updateGeminiMessage, handleSlashCommand, - handlePassthroughCommand, // handleAtCommand is implicitly included via its direct call setDebugMessage, // Added dependency for handleAtCommand & passthrough setStreamingState, // Added dependency for handlePassthroughCommand diff --git a/packages/server/src/config/config.ts b/packages/server/src/config/config.ts index 12e4f740..82b31902 100644 --- a/packages/server/src/config/config.ts +++ b/packages/server/src/config/config.ts @@ -21,8 +21,6 @@ import { WebFetchTool } from '../tools/web-fetch.js'; import { ReadManyFilesTool } from '../tools/read-many-files.js'; import { BaseTool, ToolResult } from '../tools/tools.js'; -const DEFAULT_PASSTHROUGH_COMMANDS = ['ls', 'git', 'npm']; - export class Config { private toolRegistry: ToolRegistry; @@ -33,7 +31,6 @@ export class Config { private readonly targetDir: string, private readonly debugMode: boolean, private readonly question: string | undefined, // Keep undefined possibility - private readonly passthroughCommands: string[] = DEFAULT_PASSTHROUGH_COMMANDS, // Default value here private readonly fullContext: boolean = false, // Default value here ) { // toolRegistry still needs initialization based on the instance @@ -67,10 +64,6 @@ export class Config { return this.question; } - getPassthroughCommands(): string[] { - return this.passthroughCommands; - } - getFullContext(): boolean { return this.fullContext; } @@ -106,7 +99,6 @@ export function createServerConfig( targetDir: string, debugMode: boolean, question: string, - passthroughCommands?: string[], fullContext?: boolean, ): Config { return new Config( @@ -116,7 +108,6 @@ export function createServerConfig( path.resolve(targetDir), debugMode, question, - passthroughCommands, fullContext, ); }