1import { Type } from "@sinclair/typebox";
2import type { AgentTool } from "@mariozechner/pi-ai";
3import simpleGit from "simple-git";
4import { ToolInputError } from "../../../util/errors.js";
5
6const ShowSchema = Type.Object({
7 ref: Type.String({ description: "Commit hash or ref" }),
8});
9
10export const createGitShowTool = (workspacePath: string): AgentTool => ({
11 name: "git_show",
12 label: "Git Show",
13 description: "Show details for a commit or object.",
14 parameters: ShowSchema as any,
15 execute: async (_toolCallId: string, params: any) => {
16 if (!String(params.ref ?? "").trim()) {
17 throw new ToolInputError("ref must be a non-empty string");
18 }
19 const git = simpleGit(workspacePath);
20 const text = await git.show([params.ref]);
21
22 return {
23 content: [{ type: "text", text }],
24 details: { ref: params.ref },
25 };
26 },
27});