import fs from "node:fs/promises";
import path from "node:path";
export const lsTool = {
    name: "ls",
    description: "List the immediate contents of a directory with type and size. " +
        "`path` defaults to the current working directory. Hidden entries are skipped.",
    inputSchema: {
        type: "object",
        properties: {
            path: { type: "string" },
        },
    },
    async execute(input, ctx) {
        const target = path.resolve(ctx.cwd, input.path ?? ".");
        const entries = await fs.readdir(target, { withFileTypes: true });
        const rows = [];
        for (const entry of entries) {
            if (entry.name.startsWith("."))
                continue;
            const abs = path.join(target, entry.name);
            if (entry.isDirectory()) {
                rows.push(`d  -          ${entry.name}/`);
            }
            else if (entry.isFile()) {
                const stat = await fs.stat(abs);
                rows.push(`f  ${String(stat.size).padStart(9, " ")}  ${entry.name}`);
            }
            else {
                rows.push(`?  -          ${entry.name}`);
            }
        }
        rows.sort();
        return `${target}\n${rows.join("\n") || "(empty)"}`;
    },
};
//# sourceMappingURL=ls.js.map