blob: 206267be2a6b0a9ba055c9401c0dc5fd7296d8ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/**
* @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);
}
}
|