mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 04:54:25 -07:00
Merge branch 'main' into adibakm/clear-context-conversation-approval
This commit is contained in:
@@ -413,6 +413,20 @@ export interface EditToolParams {
|
||||
ai_proposed_content?: string;
|
||||
}
|
||||
|
||||
export function isEditToolParams(args: unknown): args is EditToolParams {
|
||||
if (typeof args !== 'object' || args === null) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
'file_path' in args &&
|
||||
typeof args.file_path === 'string' &&
|
||||
'old_string' in args &&
|
||||
typeof args.old_string === 'string' &&
|
||||
'new_string' in args &&
|
||||
typeof args.new_string === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
interface CalculatedEdit {
|
||||
currentContent: string | null;
|
||||
newContent: string;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import fsPromises from 'node:fs/promises';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
import { MAX_LINE_LENGTH_TEXT_FILE } from '../utils/constants.js';
|
||||
|
||||
/**
|
||||
* Result object for a single grep match
|
||||
@@ -198,7 +199,14 @@ export async function formatGrepResults(
|
||||
// If isContext is undefined, assume it's a match (false)
|
||||
const separator = match.isContext ? '-' : ':';
|
||||
// trimEnd to avoid double newlines if line has them, but we want to preserve indentation
|
||||
llmContent += `L${match.lineNumber}${separator} ${match.line.trimEnd()}\n`;
|
||||
let lineContent = match.line.trimEnd();
|
||||
const graphemes = Array.from(lineContent);
|
||||
if (graphemes.length > MAX_LINE_LENGTH_TEXT_FILE) {
|
||||
lineContent =
|
||||
graphemes.slice(0, MAX_LINE_LENGTH_TEXT_FILE).join('') +
|
||||
'... [truncated]';
|
||||
}
|
||||
llmContent += `L${match.lineNumber}${separator} ${lineContent}\n`;
|
||||
});
|
||||
llmContent += '---\n';
|
||||
}
|
||||
|
||||
@@ -562,6 +562,22 @@ describe('GrepTool', () => {
|
||||
// Verify context after
|
||||
expect(result.llmContent).toContain('L60- Line 60');
|
||||
});
|
||||
|
||||
it('should truncate excessively long lines', async () => {
|
||||
const longString = 'a'.repeat(3000);
|
||||
await fs.writeFile(
|
||||
path.join(tempRootDir, 'longline.txt'),
|
||||
`Target match ${longString}`,
|
||||
);
|
||||
|
||||
const params: GrepToolParams = { pattern: 'Target match' };
|
||||
const invocation = grepTool.build(params);
|
||||
const result = await invocation.execute(abortSignal);
|
||||
|
||||
// MAX_LINE_LENGTH_TEXT_FILE is 2000. It should be truncated.
|
||||
expect(result.llmContent).toContain('... [truncated]');
|
||||
expect(result.llmContent).not.toContain(longString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDescription', () => {
|
||||
|
||||
@@ -2028,6 +2028,32 @@ describe('RipGrepTool', () => {
|
||||
expect(result.llmContent).not.toContain('fileB.txt');
|
||||
expect(result.llmContent).toContain('Copyright 2025 Google LLC');
|
||||
});
|
||||
|
||||
it('should truncate excessively long lines', async () => {
|
||||
const longString = 'a'.repeat(3000);
|
||||
mockSpawn.mockImplementation(
|
||||
createMockSpawn({
|
||||
outputData:
|
||||
JSON.stringify({
|
||||
type: 'match',
|
||||
data: {
|
||||
path: { text: 'longline.txt' },
|
||||
line_number: 1,
|
||||
lines: { text: `Target match ${longString}\n` },
|
||||
},
|
||||
}) + '\n',
|
||||
exitCode: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
const params: RipGrepToolParams = { pattern: 'Target match', context: 0 };
|
||||
const invocation = grepTool.build(params);
|
||||
const result = await invocation.execute(abortSignal);
|
||||
|
||||
// MAX_LINE_LENGTH_TEXT_FILE is 2000. It should be truncated.
|
||||
expect(result.llmContent).toContain('... [truncated]');
|
||||
expect(result.llmContent).not.toContain(longString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -74,6 +74,20 @@ export interface WriteFileToolParams {
|
||||
ai_proposed_content?: string;
|
||||
}
|
||||
|
||||
export function isWriteFileToolParams(
|
||||
args: unknown,
|
||||
): args is WriteFileToolParams {
|
||||
if (typeof args !== 'object' || args === null) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
'file_path' in args &&
|
||||
typeof args.file_path === 'string' &&
|
||||
'content' in args &&
|
||||
typeof args.content === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
interface GetCorrectedFileContentResult {
|
||||
originalContent: string;
|
||||
correctedContent: string;
|
||||
|
||||
Reference in New Issue
Block a user