import { tool } from "ai";
import z from "zod";
import { debugCache, createTypeScriptCheckFunction } from "./debug-cache.js";
export default function createBuildRenameFileTool(clark, services) {
    return tool({
        description: `
      Rename or move a file in the application.

      Use this tool to rename files or move them to different directories.
      This tool handles the file system operations and maintains draft state.

      Before using this tool:
      - Ensure the source file exists
      - Check that the destination doesn't already exist
      - Verify you have read the source file first

      Usage requirements:
      - Always use relative file paths from the project root
      - The destination path should include the new filename
      - Parent directory of destination must exist

      DO NOT USE FOR:
      - API files (api.yaml) - Use the API sub-agent instead
      - scope.ts files - Use the appropriate specialized tools instead
      - Files that should be renamed via specialized tools
    `,
        inputSchema: z.object({
            oldPath: z
                .string()
                .describe("Current relative path to the file (e.g., 'src/components/OldButton.tsx')"),
            newPath: z
                .string()
                .describe("New relative path for the file (e.g., 'src/components/Button.tsx')"),
        }),
        execute: async ({ oldPath, newPath }) => {
            if (!oldPath || !newPath) {
                throw new Error("Both oldPath and newPath are required");
            }
            if (oldPath === newPath) {
                throw new Error("oldPath and newPath must be different");
            }
            // AppShell.renameFile handles read-before-write validation and
            // marks the new path as requiring read before further edits
            await services.appShell.renameFile(oldPath, newPath);
            // Trigger eager TypeScript check after file rename
            const typeCheckFunction = createTypeScriptCheckFunction(services.appShell, clark.context.abortController?.signal);
            debugCache.startEagerTypeScriptCheck(typeCheckFunction);
            return {
                oldPath,
                newPath,
                message: `Successfully renamed ${oldPath} to ${newPath}`,
            };
        },
    });
}
//# sourceMappingURL=build-rename-file.js.map