read current file tool
This commit is contained in:
parent
98582d00e4
commit
aee7e21bce
5 changed files with 45 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
export enum BuiltInToolNames {
|
||||
ReadFile = "read_file",
|
||||
ReadCurrentlyOpenFile = "read_currently_open_file",
|
||||
CreateNewFile = "create_new_file",
|
||||
RunTerminalCommand = "run_terminal_command",
|
||||
ViewSubdirectory = "view_subdirectory",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { ContextItem, ToolExtras } from "..";
|
||||
import MCPConnectionSingleton from "../context/mcp";
|
||||
import { BuiltInToolNames } from "./builtIn";
|
||||
|
||||
import { createNewFileImpl } from "./implementations/createNewFile";
|
||||
import { exactSearchImpl } from "./implementations/exactSearch";
|
||||
import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFile";
|
||||
import { readFileImpl } from "./implementations/readFile";
|
||||
import { runTerminalCommandImpl } from "./implementations/runTerminalCommand";
|
||||
import { searchWebImpl } from "./implementations/searchWeb";
|
||||
|
|
@ -99,6 +101,8 @@ export async function callTool(
|
|||
return await viewRepoMapImpl(args, extras);
|
||||
case BuiltInToolNames.ViewSubdirectory:
|
||||
return await viewSubdirectoryImpl(args, extras);
|
||||
case BuiltInToolNames.ReadCurrentlyOpenFile:
|
||||
return await readCurrentlyOpenFileImpl(args, extras);
|
||||
default:
|
||||
return await callToolFromUri(uri, args, extras);
|
||||
}
|
||||
|
|
|
|||
18
core/tools/definitions/readCurrentlyOpenFile.ts
Normal file
18
core/tools/definitions/readCurrentlyOpenFile.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Tool } from "../..";
|
||||
import { BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export const readCurrentlyOpenFileTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Read Currently Open File",
|
||||
wouldLikeTo: "read the current file",
|
||||
readonly: true,
|
||||
function: {
|
||||
name: BuiltInToolNames.ReadCurrentlyOpenFile,
|
||||
description:
|
||||
"Read the currently open file in the IDE. If the user seems to be referring to a file that you can't see, this is probably it.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
20
core/tools/implementations/readCurrentlyOpenFile.ts
Normal file
20
core/tools/implementations/readCurrentlyOpenFile.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { getBasename } from "../../util";
|
||||
|
||||
export const readCurrentlyOpenFileImpl: ToolImpl = async (args, extras) => {
|
||||
const result = await extras.ide.getCurrentFile();
|
||||
|
||||
if (!result) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const basename = getBasename(result.path);
|
||||
|
||||
return [
|
||||
{
|
||||
name: "Current file",
|
||||
description: basename,
|
||||
content: `\`\`\`${basename}\n${result.contents}\n\`\`\``,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { createNewFileTool } from "./definitions/createNewFile";
|
||||
import { exactSearchTool } from "./definitions/exactSearch";
|
||||
import { readCurrentlyOpenFileTool } from "./definitions/readCurrentlyOpenFile";
|
||||
import { readFileTool } from "./definitions/readFile";
|
||||
import { runTerminalCommandTool } from "./definitions/runTerminalCommand";
|
||||
import { searchWebTool } from "./definitions/searchWeb";
|
||||
|
|
@ -16,4 +17,5 @@ export const allTools = [
|
|||
exactSearchTool,
|
||||
searchWebTool,
|
||||
viewDiffTool,
|
||||
readCurrentlyOpenFileTool,
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue