mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
Smart Edit Strategy Logging (#10345)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -81,6 +81,12 @@ describe('SmartEditTool', () => {
|
||||
} as unknown as BaseLlmClient;
|
||||
|
||||
mockConfig = {
|
||||
getUsageStatisticsEnabled: vi.fn(() => true),
|
||||
getSessionId: vi.fn(() => 'mock-session-id'),
|
||||
getContentGeneratorConfig: vi.fn(() => ({ authType: 'mock' })),
|
||||
getUseSmartEdit: vi.fn(() => false),
|
||||
getUseModelRouter: vi.fn(() => false),
|
||||
getProxy: vi.fn(() => undefined),
|
||||
getGeminiClient: vi.fn().mockReturnValue(geminiClient),
|
||||
getBaseLlmClient: vi.fn().mockReturnValue(baseLlmClient),
|
||||
getTargetDir: () => rootDir,
|
||||
@@ -195,7 +201,7 @@ describe('SmartEditTool', () => {
|
||||
|
||||
it('should perform an exact replacement', async () => {
|
||||
const content = 'hello world';
|
||||
const result = await calculateReplacement({
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.txt',
|
||||
instruction: 'test',
|
||||
@@ -211,7 +217,7 @@ describe('SmartEditTool', () => {
|
||||
|
||||
it('should perform a flexible, whitespace-insensitive replacement', async () => {
|
||||
const content = ' hello\n world\n';
|
||||
const result = await calculateReplacement({
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.txt',
|
||||
instruction: 'test',
|
||||
@@ -227,7 +233,7 @@ describe('SmartEditTool', () => {
|
||||
|
||||
it('should return 0 occurrences if no match is found', async () => {
|
||||
const content = 'hello world';
|
||||
const result = await calculateReplacement({
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.txt',
|
||||
instruction: 'test',
|
||||
@@ -245,7 +251,7 @@ describe('SmartEditTool', () => {
|
||||
// This case would fail with the previous exact and line-trimming flexible logic
|
||||
// because the whitespace *within* the line is different.
|
||||
const content = ' function myFunc( a, b ) {\n return a + b;\n }';
|
||||
const result = await calculateReplacement({
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.js',
|
||||
instruction: 'test',
|
||||
|
||||
@@ -32,6 +32,8 @@ import { IdeClient } from '../ide/ide-client.js';
|
||||
import { FixLLMEditWithInstruction } from '../utils/llm-edit-fixer.js';
|
||||
import { applyReplacement } from './edit.js';
|
||||
import { safeLiteralReplace } from '../utils/textUtils.js';
|
||||
import { SmartEditStrategyEvent } from '../telemetry/types.js';
|
||||
import { logSmartEditStrategy } from '../telemetry/loggers.js';
|
||||
|
||||
interface ReplacementContext {
|
||||
params: EditToolParams;
|
||||
@@ -229,6 +231,7 @@ function detectLineEnding(content: string): '\r\n' | '\n' {
|
||||
}
|
||||
|
||||
export async function calculateReplacement(
|
||||
config: Config,
|
||||
context: ReplacementContext,
|
||||
): Promise<ReplacementResult> {
|
||||
const { currentContent, params } = context;
|
||||
@@ -247,16 +250,22 @@ export async function calculateReplacement(
|
||||
|
||||
const exactResult = await calculateExactReplacement(context);
|
||||
if (exactResult) {
|
||||
const event = new SmartEditStrategyEvent('exact');
|
||||
logSmartEditStrategy(config, event);
|
||||
return exactResult;
|
||||
}
|
||||
|
||||
const flexibleResult = await calculateFlexibleReplacement(context);
|
||||
if (flexibleResult) {
|
||||
const event = new SmartEditStrategyEvent('flexible');
|
||||
logSmartEditStrategy(config, event);
|
||||
return flexibleResult;
|
||||
}
|
||||
|
||||
const regexResult = await calculateRegexReplacement(context);
|
||||
if (regexResult) {
|
||||
const event = new SmartEditStrategyEvent('regex');
|
||||
logSmartEditStrategy(config, event);
|
||||
return regexResult;
|
||||
}
|
||||
|
||||
@@ -388,7 +397,7 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
};
|
||||
}
|
||||
|
||||
const secondAttemptResult = await calculateReplacement({
|
||||
const secondAttemptResult = await calculateReplacement(this.config, {
|
||||
params: {
|
||||
...params,
|
||||
old_string: fixedEdit.search,
|
||||
@@ -516,7 +525,7 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
};
|
||||
}
|
||||
|
||||
const replacementResult = await calculateReplacement({
|
||||
const replacementResult = await calculateReplacement(this.config, {
|
||||
params,
|
||||
currentContent,
|
||||
abortSignal,
|
||||
|
||||
Reference in New Issue
Block a user