- Combined resolveInputPath approach with new ContinueError system - Updated error handling to use ContinueError with appropriate error reasons - Maintained improved error messages from pe/read-file-errs branch
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { resolveInputPath } from "../../util/pathResolver";
|
|
import { getUriPathBasename } from "../../util/uri";
|
|
|
|
import { ToolImpl } from ".";
|
|
import { throwIfFileIsSecurityConcern } from "../../indexing/ignore";
|
|
import { getStringArg } from "../parseArgs";
|
|
import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
|
|
import { ContinueError, ContinueErrorReason } from "../../util/errors";
|
|
|
|
export const readFileImpl: ToolImpl = async (args, extras) => {
|
|
const filepath = getStringArg(args, "filepath");
|
|
|
|
// Resolve the path first to get the actual path for security check
|
|
const resolvedPath = await resolveInputPath(extras.ide, filepath);
|
|
if (!resolvedPath) {
|
|
throw new ContinueError(
|
|
ContinueErrorReason.FileNotFound,
|
|
`File "${filepath}" does not exist or is not accessible. You might want to check the path and try again.`,
|
|
);
|
|
}
|
|
|
|
// Security check on the resolved display path
|
|
throwIfFileIsSecurityConcern(resolvedPath.displayPath);
|
|
|
|
const content = await extras.ide.readFile(resolvedPath.uri);
|
|
|
|
await throwIfFileExceedsHalfOfContext(
|
|
resolvedPath.displayPath,
|
|
content,
|
|
extras.config.selectedModelByRole.chat,
|
|
);
|
|
|
|
return [
|
|
{
|
|
name: getUriPathBasename(resolvedPath.uri),
|
|
description: resolvedPath.displayPath,
|
|
content,
|
|
uri: {
|
|
type: "file",
|
|
value: resolvedPath.uri,
|
|
},
|
|
},
|
|
];
|
|
};
|