mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-29 15:40:10 +00:00
- There were a few hiccups here. Somehow 2.5-flash wasn't actually abiding by our tool schema. Instead it was inferring `path`. To semi-combat this I've renamed `file_path` -> `path`. - We weren't elevating errors that were created via schema validation. Instead both the `glob` and `read-file.ts` now surface this. - In error scenarios (like failing schema) we were improperly surfacing these as success cases because we were overriding tool status.
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {
|
|
ReadFileLogic,
|
|
ReadFileToolParams,
|
|
ToolResult,
|
|
} from '@gemini-code/server';
|
|
import { BaseTool } from './tools.js';
|
|
import { ToolCallConfirmationDetails } from '../ui/types.js';
|
|
|
|
/**
|
|
* CLI wrapper for the ReadFile tool
|
|
*/
|
|
export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
|
|
static readonly Name: string = ReadFileLogic.Name;
|
|
private coreLogic: ReadFileLogic;
|
|
|
|
/**
|
|
* Creates a new instance of the ReadFileTool CLI wrapper
|
|
* @param rootDirectory Root directory to ground this tool in.
|
|
*/
|
|
constructor(rootDirectory: string) {
|
|
const coreLogicInstance = new ReadFileLogic(rootDirectory);
|
|
super(
|
|
ReadFileTool.Name,
|
|
'ReadFile',
|
|
'Reads and returns the content of a specified file from the local filesystem. Handles large files by allowing reading specific line ranges.',
|
|
(coreLogicInstance.schema.parameters as Record<string, unknown>) ?? {},
|
|
);
|
|
this.coreLogic = coreLogicInstance;
|
|
}
|
|
|
|
/**
|
|
* Delegates validation to the core logic
|
|
*/
|
|
validateToolParams(_params: ReadFileToolParams): string | null {
|
|
return this.coreLogic.validateToolParams(_params);
|
|
}
|
|
|
|
/**
|
|
* Delegates getting description to the core logic
|
|
*/
|
|
getDescription(_params: ReadFileToolParams): string {
|
|
return this.coreLogic.getDescription(_params);
|
|
}
|
|
|
|
/**
|
|
* Define confirmation behavior here in the CLI wrapper if needed
|
|
* For ReadFile, we likely don't need confirmation.
|
|
*/
|
|
shouldConfirmExecute(
|
|
_params: ReadFileToolParams,
|
|
): Promise<ToolCallConfirmationDetails | false> {
|
|
return Promise.resolve(false);
|
|
}
|
|
|
|
/**
|
|
* Delegates execution to the core logic
|
|
*/
|
|
execute(params: ReadFileToolParams): Promise<ToolResult> {
|
|
return this.coreLogic.execute(params);
|
|
}
|
|
}
|