/**
 * Git diff tool for Clawx.
 * Written fresh — not present in OpenClaw as a model tool.
 */
import { Type } from "@sinclair/typebox";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
const GitDiffSchema = Type.Object({
    path: Type.Optional(Type.String({ description: "Directory to diff in (default: working directory)" })),
    staged: Type.Optional(Type.Boolean({ description: "Show staged changes only (default: false)" })),
    file: Type.Optional(Type.String({ description: "Specific file to diff" })),
});
export function createGitDiffTool(defaultCwd) {
    return {
        name: "git_diff",
        label: "Git Diff",
        description: "Show file differences in a git repository",
        parameters: GitDiffSchema,
        async execute(_toolCallId, params) {
            const cwd = params.path || defaultCwd;
            const args = ["diff"];
            if (params.staged)
                args.push("--cached");
            args.push("--stat", "--patch");
            if (params.file)
                args.push("--", params.file);
            try {
                const { stdout } = await execFileAsync("git", args, {
                    cwd,
                    timeout: 10_000,
                    maxBuffer: 1024 * 1024,
                    encoding: "utf-8",
                });
                return {
                    content: [{ type: "text", text: stdout.trim() || "(no differences)" }],
                    details: {},
                };
            }
            catch (e) {
                const msg = e instanceof Error ? e.message : String(e);
                return {
                    content: [{ type: "text", text: `git diff error: ${msg}` }],
                    details: {},
                };
            }
        },
    };
}
//# sourceMappingURL=gitDiff.js.map