import { z } from "zod";
import { buildTool } from "../Tool.js";
/**
 * list_dir - List contents of a directory.
 *
 * Returns a newline-separated list of file and directory names
 * within the specified path.
 */
export const ListDirTool = buildTool({
    name: "list_dir",
    description: "List contents of a directory.",
    parameters: z.object({
        path: z.string().describe("Absolute path to the directory to list."),
    }),
    isReadOnly: true,
    isConcurrencySafe: true,
    execute: async (bash, { path }) => {
        try {
            const files = await bash.listDirDirect(path);
            return files.join("\n");
        }
        catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            return `Error listing directory ${path}: ${message}`;
        }
    },
});
