Elffuss BraidHub

kikocis/continue public

main · 1.1 KiBRawPermalink
1import { getUriDescription } from "../../util/uri";
2
3import { ToolImpl } from ".";
4import { throwIfFileIsSecurityConcern } from "../../indexing/ignore";
5import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
6
7export const readCurrentlyOpenFileImpl: ToolImpl = async (_, extras) => {
8 const result = await extras.ide.getCurrentFile();
9
10 if (result) {
11 throwIfFileIsSecurityConcern(result.path);
12 await throwIfFileExceedsHalfOfContext(
13 result.path,
14 result.contents,
15 extras.config.selectedModelByRole.chat,
16 );
17
18 const { relativePathOrBasename, last2Parts, baseName } = getUriDescription(
19 result.path,
20 await extras.ide.getWorkspaceDirs(),
21 );
22
23 return [
24 {
25 name: `Current file: ${baseName}`,
26 description: last2Parts,
27 content: `\`\`\`${relativePathOrBasename}\n${result.contents}\n\`\`\``,
28 uri: {
29 type: "file",
30 value: result.path,
31 },
32 },
33 ];
34 } else {
35 return [
36 {
37 name: `No Current File`,
38 description: "",
39 content: "There are no files currently open.",
40 },
41 ];
42 }
43};