-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.ts
More file actions
38 lines (29 loc) · 1017 Bytes
/
tools.ts
File metadata and controls
38 lines (29 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { tool } from "ai";
import { simpleGit } from "simple-git";
import { z } from "zod";
// === Schemas & Types ===
// File change schema
const excludeFiles = ["dist", "bun.lock"];
const fileChange = z.object({
rootDir: z.string().min(1).describe("The root directory"),
});
type FileChange = z.infer<typeof fileChange>;
// === Tool Implementations ===
// 1. Get file changes in directory
async function getFileChangesInDirectory({ rootDir }: FileChange) {
const git = simpleGit(rootDir);
const summary = await git.diffSummary();
const diffs: { file: string; diff: string }[] = [];
for (const file of summary.files) {
if (excludeFiles.includes(file.file)) continue;
const diff = await git.diff(["--", file.file]);
diffs.push({ file: file.file, diff });
}
return diffs;
}
// === Tool Exports ===
export const getFileChangesInDirectoryTool = tool({
description: "Gets the code changes made in given directory",
inputSchema: fileChange,
execute: getFileChangesInDirectory,
});