1import { Type } from "@sinclair/typebox";
2import type { AgentTool } from "@mariozechner/pi-ai";
3import simpleGit from "simple-git";
4
5const RefsSchema = Type.Object({
6 type: Type.Union([
7 Type.Literal("branches"),
8 Type.Literal("tags"),
9 Type.Literal("remotes"),
10 ]),
11});
12
13export const createGitRefsTool = (workspacePath: string): AgentTool => ({
14 name: "git_refs",
15 label: "Git Refs",
16 description: "List branches or tags.",
17 parameters: RefsSchema as any,
18 execute: async (_toolCallId: string, params: any) => {
19 const git = simpleGit(workspacePath);
20
21 if (params.type === "tags") {
22 const tags = await git.tags();
23 return {
24 content: [{ type: "text", text: tags.all.join("\n") }],
25 details: { count: tags.all.length },
26 };
27 }
28
29 if (params.type === "remotes") {
30 const raw = await git.raw(["branch", "-r"]);
31 return {
32 content: [{ type: "text", text: raw }],
33 details: {},
34 };
35 }
36
37 const raw = await git.raw(["branch", "-a"]);
38 return {
39 content: [{ type: "text", text: raw }],
40 details: {},
41 };
42 },
43});