feat(cli): implement compact tool output (#20974)

This commit is contained in:
Jarrod Whelan
2026-03-30 16:43:29 -07:00
committed by GitHub
parent 3e95b8ec59
commit 1df5c98b33
45 changed files with 2670 additions and 386 deletions
+24 -6
View File
@@ -7,6 +7,7 @@
import fsPromises from 'node:fs/promises';
import { debugLogger } from '../utils/debugLogger.js';
import { MAX_LINE_LENGTH_TEXT_FILE } from '../utils/constants.js';
import type { GrepResult } from './tools.js';
/**
* Result object for a single grep match
@@ -148,12 +149,18 @@ export async function formatGrepResults(
},
searchLocationDescription: string,
totalMaxMatches: number,
): Promise<{ llmContent: string; returnDisplay: string }> {
): Promise<{ llmContent: string; returnDisplay: GrepResult }> {
const { pattern, names_only, include_pattern } = params;
if (allMatches.length === 0) {
const noMatchMsg = `No matches found for pattern "${pattern}" ${searchLocationDescription}${include_pattern ? ` (filter: "${include_pattern}")` : ''}.`;
return { llmContent: noMatchMsg, returnDisplay: `No matches found` };
return {
llmContent: noMatchMsg,
returnDisplay: {
summary: 'No matches found',
matches: [],
},
};
}
const matchesByFile = groupMatchesByFile(allMatches);
@@ -181,7 +188,10 @@ export async function formatGrepResults(
llmContent += filePaths.join('\n');
return {
llmContent: llmContent.trim(),
returnDisplay: `Found ${filePaths.length} files${wasTruncated ? ' (limited)' : ''}`,
returnDisplay: {
summary: `Found ${filePaths.length} files${wasTruncated ? ' (limited)' : ''}`,
matches: [],
},
};
}
@@ -213,8 +223,16 @@ export async function formatGrepResults(
return {
llmContent: llmContent.trim(),
returnDisplay: `Found ${matchCount} ${matchTerm}${
wasTruncated ? ' (limited)' : ''
}`,
returnDisplay: {
summary: `Found ${matchCount} ${matchTerm}${wasTruncated ? ' (limited)' : ''}`,
matches: allMatches
.filter((m) => !m.isContext)
.map((m) => ({
filePath: m.filePath,
absolutePath: m.absolutePath,
lineNumber: m.lineNumber,
line: m.line,
})),
},
};
}