mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Remove passthroughCommands (#252)
This commit is contained in:
@@ -88,7 +88,6 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
process.cwd(),
|
||||
argv.debug_mode || false,
|
||||
argv.question || '',
|
||||
undefined, // TODO: load passthroughCommands from .env file
|
||||
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 { 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
|
||||
|
||||
Reference in New Issue
Block a user