import { z } from "zod";
import { buildTool } from "../Tool.js";
/**
 * read_file - Read file contents from the virtual filesystem.
 *
 * Reads the content of a file at the specified absolute path and
 * updates the internal file state cache for staleness detection.
 */
export const ReadFileTool = buildTool({
    name: "read_file",
    description: "Read the contents of a file from the virtual filesystem.",
    parameters: z.object({
        path: z.string().describe("Absolute path to the file to read."),
    }),
    isReadOnly: true,
    isConcurrencySafe: true,
    execute: async (bash, { path }) => {
        try {
            const content = await bash.fs.readFile(path, "utf-8");
            bash.updateFileState(path, { content });
            return content;
        }
        catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            return `Error reading file: ${message}`;
        }
    },
});
