continue-custom/core/tools/implementations/readCurrentlyOpenFile.ts
2025-08-21 13:40:03 -07:00

45 lines
1.1 KiB
TypeScript

import { getUriDescription } from "../../util/uri";
import { ToolImpl } from ".";
import {
throwIfFileExceedsHalfOfContext,
throwIfFileIsSecurityConcern,
} from "./readFileLimit";
export const readCurrentlyOpenFileImpl: ToolImpl = async (_, extras) => {
const result = await extras.ide.getCurrentFile();
if (result) {
await throwIfFileIsSecurityConcern(result.path);
await throwIfFileExceedsHalfOfContext(
result.path,
result.contents,
extras.config.selectedModelByRole.chat,
);
const { relativePathOrBasename, last2Parts, baseName } = getUriDescription(
result.path,
await extras.ide.getWorkspaceDirs(),
);
return [
{
name: `Current file: ${baseName}`,
description: last2Parts,
content: `\`\`\`${relativePathOrBasename}\n${result.contents}\n\`\`\``,
uri: {
type: "file",
value: result.path,
},
},
];
} else {
return [
{
name: `No Current File`,
description: "",
content: "There are no files currently open.",
},
];
}
};