Elffuss BraidHub

kikocis/continue public

85f086de04b1 · 1.2 KiBRawPermalink
1import { ToolImpl } from ".";
2import { ContextItem } from "../..";
3import { getDiffsFromCache } from "../../autocomplete/snippets/gitDiffCache";
4
5export const DEFAULT_GIT_DIFF_LINE_LIMIT = 5000;
6
7export const viewDiffImpl: ToolImpl = async (args, extras) => {
8 const diffs = await getDiffsFromCache(extras.ide); // const diffs = await extras.ide.getDiff(true);
9 // TODO includeUnstaged should be an option
10
11 const combinedDiff = diffs.join("\n");
12 const diffLines = combinedDiff.split("\n");
13
14 let truncated = false;
15 let processedDiff = combinedDiff;
16
17 if (diffLines.length > DEFAULT_GIT_DIFF_LINE_LIMIT) {
18 truncated = true;
19 processedDiff = diffLines.slice(0, DEFAULT_GIT_DIFF_LINE_LIMIT).join("\n");
20 }
21
22 const contextItems: ContextItem[] = [
23 {
24 name: "Diff",
25 description: "The current git diff",
26 content: processedDiff,
27 },
28 ];
29
30 if (truncated) {
31 contextItems.push({
32 name: "Truncation warning",
33 description: "",
34 content: `The git diff was truncated because it exceeded ${DEFAULT_GIT_DIFF_LINE_LIMIT} lines. Consider viewing specific files or focusing on smaller changes.`,
35 });
36 }
37
38 return contextItems;
39};