Send accepted/removed lines with ACCEPT_FILE telemetry. (#19670)

This commit is contained in:
Christian Gunderman
2026-02-20 19:07:43 +00:00
committed by GitHub
parent ce03156c9f
commit 788a40c445
4 changed files with 38 additions and 8 deletions

View File

@@ -316,6 +316,14 @@ describe('telemetry', () => {
prompt_id: 'p1',
traceId: 'trace-1',
},
response: {
resultDisplay: {
diffStat: {
model_added_lines: 5,
model_removed_lines: 3,
},
},
},
outcome: ToolConfirmationOutcome.ProceedOnce,
status: 'success',
} as unknown as CompletedToolCall,
@@ -327,6 +335,8 @@ describe('telemetry', () => {
traceId: 'trace-1',
status: ActionStatus.ACTION_STATUS_NO_ERROR,
interaction: ConversationInteractionInteraction.ACCEPT_FILE,
acceptedLines: '5',
removedLines: '3',
isAgentic: true,
});
});

View File

@@ -22,6 +22,10 @@ import { EDIT_TOOL_NAMES } from '../tools/tool-names.js';
import { getErrorMessage } from '../utils/errors.js';
import type { CodeAssistServer } from './server.js';
import { ToolConfirmationOutcome } from '../tools/tools.js';
import {
computeModelAddedAndRemovedLines,
getFileDiffFromResultDisplay,
} from '../utils/fileDiffUtils.js';
export async function recordConversationOffered(
server: CodeAssistServer,
@@ -110,6 +114,8 @@ function summarizeToolCalls(
// Treat file edits as ACCEPT_FILE and everything else as unknown.
let isEdit = false;
let acceptedLines = 0;
let removedLines = 0;
// Iterate the tool calls and summarize them into a single conversation
// interaction so that the ConversationOffered and ConversationInteraction
@@ -136,7 +142,18 @@ function summarizeToolCalls(
// Edits are ACCEPT_FILE, everything else is UNKNOWN.
if (EDIT_TOOL_NAMES.has(toolCall.request.name)) {
isEdit ||= true;
isEdit = true;
if (toolCall.status === 'success') {
const fileDiff = getFileDiffFromResultDisplay(
toolCall.response.resultDisplay,
);
if (fileDiff?.diffStat) {
const lines = computeModelAddedAndRemovedLines(fileDiff.diffStat);
acceptedLines += lines.addedLines;
removedLines += lines.removedLines;
}
}
}
}
}
@@ -149,6 +166,8 @@ function summarizeToolCalls(
isEdit
? ConversationInteractionInteraction.ACCEPT_FILE
: ConversationInteractionInteraction.UNKNOWN,
isEdit ? String(acceptedLines) : undefined,
isEdit ? String(removedLines) : undefined,
)
: undefined;
}
@@ -157,15 +176,18 @@ function createConversationInteraction(
traceId: string,
status: ActionStatus,
interaction: ConversationInteractionInteraction,
acceptedLines?: string,
removedLines?: string,
): ConversationInteraction {
return {
traceId,
status,
interaction,
acceptedLines,
removedLines,
isAgentic: true,
};
}
function includesCode(resp: GenerateContentResponse): boolean {
if (!resp.candidates) {
return false;

View File

@@ -295,6 +295,7 @@ export interface ConversationInteraction {
status?: ActionStatus;
interaction?: ConversationInteractionInteraction;
acceptedLines?: string;
removedLines?: string;
language?: string;
isAgentic?: boolean;
}

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import type { FileDiff } from '../tools/tools.js';
import type { DiffStat, FileDiff } from '../tools/tools.js';
import type { ToolCallRecord } from '../services/chatRecordingService.js';
/**
@@ -23,17 +23,14 @@ export function getFileDiffFromResultDisplay(
typeof resultDisplay.diffStat === 'object' &&
resultDisplay.diffStat !== null
) {
const diffStat = resultDisplay.diffStat as FileDiff['diffStat'];
if (diffStat) {
if (resultDisplay.diffStat) {
return resultDisplay;
}
}
return undefined;
}
export function computeModelAddedAndRemovedLines(
stats: FileDiff['diffStat'] | undefined,
): {
export function computeModelAddedAndRemovedLines(stats: DiffStat | undefined): {
addedLines: number;
removedLines: number;
} {