import { z } from "zod";
import { createToolFactory, PermissionLevel, ToolCategory } from "../types.js";
/**
 * Write tool - Writes files to the filesystem.
 */
export const writeToolFactory = createToolFactory("write", (services) => ({
    description: "Writes a file to the local filesystem.",
    category: ToolCategory.FILE,
    defaultPermission: PermissionLevel.PROMPT,
    inputSchema: z.object({
        file_path: z.string().describe("Relative path to file"),
        content: z.string().describe("Content to write"),
    }),
    execute: async ({ file_path, content }) => {
        try {
            await services.appShell.writeFile(file_path, content);
            return { success: true, message: `File written: ${file_path}` };
        }
        catch (error) {
            if (error instanceof Error) {
                throw new Error(`Failed to write file: ${error.message}`);
            }
            throw new Error("Failed to write file: Unknown error");
        }
    },
    getSummary: (input) => {
        const lineCount = input.content.split("\n").length;
        return {
            output: `Wrote ${lineCount} line${lineCount === 1 ? "" : "s"}`,
        };
    },
}));
//# sourceMappingURL=write.js.map