Elffuss BraidHub

kikocis/continue public

main · 1.1 KiBRawPermalink
1import { resolveRelativePathInDir } from "../../util/ideUtils";
2import { getUriPathBasename } from "../../util/uri";
3
4import { ToolImpl } from ".";
5import { throwIfFileIsSecurityConcern } from "../../indexing/ignore";
6import { getStringArg } from "../parseArgs";
7import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
8
9export const readFileImpl: ToolImpl = async (args, extras) => {
10 const filepath = getStringArg(args, "filepath");
11 throwIfFileIsSecurityConcern(filepath);
12
13 const firstUriMatch = await resolveRelativePathInDir(filepath, extras.ide);
14 if (!firstUriMatch) {
15 throw new Error(
16 `File "${filepath}" does not exist. You might want to check the path and try again.`,
17 );
18 }
19 const content = await extras.ide.readFile(firstUriMatch);
20
21 await throwIfFileExceedsHalfOfContext(
22 filepath,
23 content,
24 extras.config.selectedModelByRole.chat,
25 );
26
27 return [
28 {
29 name: getUriPathBasename(firstUriMatch),
30 description: filepath,
31 content,
32 uri: {
33 type: "file",
34 value: firstUriMatch,
35 },
36 },
37 ];
38};