mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 04:54:25 -07:00
feat(cli): implement compact tool output (#20974)
This commit is contained in:
@@ -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,
|
||||
})),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user