mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-04 18:31:36 -07:00
Re-submission: Make --allowed-tools work in non-interactive mode (#10289)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matt korwel <matt.korwel@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import { quote } from 'shell-quote';
|
||||
import { doesToolInvocationMatch } from './tool-utils.js';
|
||||
import { spawn, type SpawnOptionsWithoutStdio } from 'node:child_process';
|
||||
|
||||
const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
||||
export const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
||||
|
||||
/**
|
||||
* An identifier for the shell type.
|
||||
|
||||
@@ -36,6 +36,15 @@ describe('doesToolInvocationMatch', () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should match a command with an alias', () => {
|
||||
const invocation = {
|
||||
params: { command: 'wc -l' },
|
||||
} as AnyToolInvocation;
|
||||
const patterns = ['ShellTool(wc)'];
|
||||
const result = doesToolInvocationMatch('ShellTool', invocation, patterns);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should match a command that is a prefix', () => {
|
||||
const invocation = {
|
||||
params: { command: 'git status -v' },
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
import type { AnyDeclarativeTool, AnyToolInvocation } from '../index.js';
|
||||
import { isTool } from '../index.js';
|
||||
|
||||
const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
||||
import { SHELL_TOOL_NAMES } from './shell-utils.js';
|
||||
|
||||
/**
|
||||
* Checks if a tool invocation matches any of a list of patterns.
|
||||
@@ -61,7 +60,7 @@ export function doesToolInvocationMatch(
|
||||
|
||||
if (
|
||||
'command' in invocation.params &&
|
||||
toolNames.includes('run_shell_command')
|
||||
toolNames.some((name) => SHELL_TOOL_NAMES.includes(name))
|
||||
) {
|
||||
const argValue = String(
|
||||
(invocation.params as { command: string }).command,
|
||||
|
||||
Reference in New Issue
Block a user