Remove conflicting shell Directory checks (#7845)

Co-authored-by: gemini-cli-robot <gemini-cli-robot@google.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
This commit is contained in:
Hadi Minooei
2025-09-13 10:33:12 -07:00
committed by GitHub
parent 2135dbb6a4
commit 35aeb3f420
2 changed files with 61 additions and 61 deletions
+8 -15
View File
@@ -130,10 +130,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
return `{ ${command} }; __code=$?; pgrep -g 0 >${tempFilePath} 2>&1; exit $__code;`;
})();
const cwd = path.resolve(
this.config.getTargetDir(),
this.params.directory || '',
);
const cwd = this.params.directory || this.config.getTargetDir();
let cumulativeOutput: string | AnsiOutput = '';
let lastUpdateTime = Date.now();
@@ -361,7 +358,7 @@ export class ShellTool extends BaseDeclarativeTool<
directory: {
type: 'string',
description:
'(OPTIONAL) Directory to run the command in, if not the project root directory. Must be relative to the project root directory and must already exist.',
'(OPTIONAL) The absolute path of the directory to run the command in. If not provided, the project root directory is used. Must be a directory within the workspace and must already exist.',
},
},
required: ['command'],
@@ -391,20 +388,16 @@ export class ShellTool extends BaseDeclarativeTool<
return 'Could not identify command root to obtain permission from user.';
}
if (params.directory) {
if (path.isAbsolute(params.directory)) {
return 'Directory cannot be absolute. Please refer to workspace directories by their name.';
if (!path.isAbsolute(params.directory)) {
return 'Directory must be an absolute path.';
}
const workspaceDirs = this.config.getWorkspaceContext().getDirectories();
const matchingDirs = workspaceDirs.filter(
(dir) => path.basename(dir) === params.directory,
const isWithinWorkspace = workspaceDirs.some((wsDir) =>
params.directory!.startsWith(wsDir),
);
if (matchingDirs.length === 0) {
return `Directory '${params.directory}' is not a registered workspace directory.`;
}
if (matchingDirs.length > 1) {
return `Directory name '${params.directory}' is ambiguous as it matches multiple workspace directories.`;
if (!isWithinWorkspace) {
return `Directory '${params.directory}' is not within any of the registered workspace directories.`;
}
}
return null;