Remove passthroughCommands (#252)
This commit is contained in:
parent
a0bed3e716
commit
415b757d4a
|
@ -88,7 +88,6 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
argv.debug_mode || false,
|
argv.debug_mode || false,
|
||||||
argv.question || '',
|
argv.question || '',
|
||||||
undefined, // TODO: load passthroughCommands from .env file
|
|
||||||
argv.full_context || false,
|
argv.full_context || false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<React.SetStateAction<HistoryItem[]>>,
|
|
||||||
itemData: Omit<HistoryItem, 'id'>,
|
|
||||||
id: number,
|
|
||||||
) => {
|
|
||||||
setHistory((prevHistory) => [
|
|
||||||
...prevHistory,
|
|
||||||
{ ...itemData, id } as HistoryItem,
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const usePassthroughProcessor = (
|
|
||||||
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
|
||||||
setStreamingState: React.Dispatch<React.SetStateAction<StreamingState>>,
|
|
||||||
setDebugMessage: React.Dispatch<React.SetStateAction<string>>,
|
|
||||||
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 };
|
|
||||||
};
|
|
|
@ -30,7 +30,6 @@ import {
|
||||||
import { isAtCommand } from '../utils/commandUtils.js';
|
import { isAtCommand } from '../utils/commandUtils.js';
|
||||||
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
|
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
|
||||||
import { useShellCommandProcessor } from './shellCommandProcessor.js';
|
import { useShellCommandProcessor } from './shellCommandProcessor.js';
|
||||||
import { usePassthroughProcessor } from './passthroughCommandProcessor.js';
|
|
||||||
import { handleAtCommand } from './atCommandProcessor.js';
|
import { handleAtCommand } from './atCommandProcessor.js';
|
||||||
import { findSafeSplitPoint } from '../utils/markdownUtilities.js';
|
import { findSafeSplitPoint } from '../utils/markdownUtilities.js';
|
||||||
|
|
||||||
|
@ -88,14 +87,6 @@ export const useGeminiStream = (
|
||||||
config,
|
config,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { handlePassthroughCommand } = usePassthroughProcessor(
|
|
||||||
setHistory,
|
|
||||||
setStreamingState,
|
|
||||||
setDebugMessage,
|
|
||||||
getNextMessageId,
|
|
||||||
config,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Initialize Client Effect - uses props now
|
// Initialize Client Effect - uses props now
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInitError(null);
|
setInitError(null);
|
||||||
|
@ -177,11 +168,6 @@ export const useGeminiStream = (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Check for Passthrough Commands
|
|
||||||
if (handlePassthroughCommand(trimmedQuery)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Check for @ Commands using the utility function
|
// 3. Check for @ Commands using the utility function
|
||||||
if (isAtCommand(trimmedQuery)) {
|
if (isAtCommand(trimmedQuery)) {
|
||||||
const atCommandResult = await handleAtCommand({
|
const atCommandResult = await handleAtCommand({
|
||||||
|
@ -542,7 +528,6 @@ export const useGeminiStream = (
|
||||||
getNextMessageId,
|
getNextMessageId,
|
||||||
updateGeminiMessage,
|
updateGeminiMessage,
|
||||||
handleSlashCommand,
|
handleSlashCommand,
|
||||||
handlePassthroughCommand,
|
|
||||||
// handleAtCommand is implicitly included via its direct call
|
// handleAtCommand is implicitly included via its direct call
|
||||||
setDebugMessage, // Added dependency for handleAtCommand & passthrough
|
setDebugMessage, // Added dependency for handleAtCommand & passthrough
|
||||||
setStreamingState, // Added dependency for handlePassthroughCommand
|
setStreamingState, // Added dependency for handlePassthroughCommand
|
||||||
|
|
|
@ -21,8 +21,6 @@ import { WebFetchTool } from '../tools/web-fetch.js';
|
||||||
import { ReadManyFilesTool } from '../tools/read-many-files.js';
|
import { ReadManyFilesTool } from '../tools/read-many-files.js';
|
||||||
import { BaseTool, ToolResult } from '../tools/tools.js';
|
import { BaseTool, ToolResult } from '../tools/tools.js';
|
||||||
|
|
||||||
const DEFAULT_PASSTHROUGH_COMMANDS = ['ls', 'git', 'npm'];
|
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
private toolRegistry: ToolRegistry;
|
private toolRegistry: ToolRegistry;
|
||||||
|
|
||||||
|
@ -33,7 +31,6 @@ export class Config {
|
||||||
private readonly targetDir: string,
|
private readonly targetDir: string,
|
||||||
private readonly debugMode: boolean,
|
private readonly debugMode: boolean,
|
||||||
private readonly question: string | undefined, // Keep undefined possibility
|
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
|
private readonly fullContext: boolean = false, // Default value here
|
||||||
) {
|
) {
|
||||||
// toolRegistry still needs initialization based on the instance
|
// toolRegistry still needs initialization based on the instance
|
||||||
|
@ -67,10 +64,6 @@ export class Config {
|
||||||
return this.question;
|
return this.question;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPassthroughCommands(): string[] {
|
|
||||||
return this.passthroughCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
getFullContext(): boolean {
|
getFullContext(): boolean {
|
||||||
return this.fullContext;
|
return this.fullContext;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +99,6 @@ export function createServerConfig(
|
||||||
targetDir: string,
|
targetDir: string,
|
||||||
debugMode: boolean,
|
debugMode: boolean,
|
||||||
question: string,
|
question: string,
|
||||||
passthroughCommands?: string[],
|
|
||||||
fullContext?: boolean,
|
fullContext?: boolean,
|
||||||
): Config {
|
): Config {
|
||||||
return new Config(
|
return new Config(
|
||||||
|
@ -116,7 +108,6 @@ export function createServerConfig(
|
||||||
path.resolve(targetDir),
|
path.resolve(targetDir),
|
||||||
debugMode,
|
debugMode,
|
||||||
question,
|
question,
|
||||||
passthroughCommands,
|
|
||||||
fullContext,
|
fullContext,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue