(args, extras)
| 5 | export const DEFAULT_GIT_DIFF_LINE_LIMIT = 5000; |
| 6 | |
| 7 | export 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 | |
| 13 | if (!combinedDiff.trim()) { |
| 14 | return [ |
| 15 | { |
| 16 | name: "Diff", |
| 17 | description: "current Git diff", |
| 18 | content: "The current diff is empty", |
| 19 | }, |
| 20 | ]; |
| 21 | } |
| 22 | |
| 23 | const diffLines = combinedDiff.split("\n"); |
| 24 | |
| 25 | let truncated = false; |
| 26 | let processedDiff = combinedDiff; |
| 27 | |
| 28 | if (diffLines.length > DEFAULT_GIT_DIFF_LINE_LIMIT) { |
| 29 | truncated = true; |
| 30 | processedDiff = diffLines.slice(0, DEFAULT_GIT_DIFF_LINE_LIMIT).join("\n"); |
| 31 | } |
| 32 | |
| 33 | const contextItems: ContextItem[] = [ |
| 34 | { |
| 35 | name: "Diff", |
| 36 | description: "The current git diff", |
| 37 | content: processedDiff, |
| 38 | }, |
| 39 | ]; |
| 40 | |
| 41 | if (truncated) { |
| 42 | contextItems.push({ |
| 43 | name: "Truncation warning", |
| 44 | description: "", |
| 45 | content: `The git diff was truncated because it exceeded ${DEFAULT_GIT_DIFF_LINE_LIMIT} lines. Consider viewing specific files or focusing on smaller changes.`, |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | return contextItems; |
| 50 | }; |
no test coverage detected