Compare commits

...

1 Commits

Author SHA1 Message Date
BarreiroT 5102fe6c77 Do not show costs in the summary for free models 2026-06-20 12:58:18 -03:00
4 changed files with 34 additions and 1 deletions
@@ -115,4 +115,28 @@ describe("interactive exit summary", () => {
expect(output).not.toContain(" Cost");
expect(output).not.toContain("$0.250000");
});
it("zeros persisted cost for free Cline models", () => {
const summary = createInteractiveExitSummary({
sessionId: "sess_123",
row: makeSessionRecord(),
messages: [
{ role: "user", content: "hello" },
{ role: "assistant", content: "hi" },
],
usage: {
inputTokens: 100,
outputTokens: 50,
cacheReadTokens: 0,
cacheWriteTokens: 0,
totalCost: 0.25,
},
shouldZeroCost: true,
});
expect(summary?.totalCost).toBe(0);
expect(formatInteractiveExitSummary(summary!)).toContain(
" Cost $0.00",
);
});
});
@@ -47,6 +47,7 @@ export function createInteractiveExitSummary(input: {
row?: SessionRecord;
messages?: Message[];
usage?: SessionAccumulatedUsage;
shouldZeroCost?: boolean;
}): InteractiveExitSummary | undefined {
const sessionId = trim(input.sessionId);
if (!sessionId) {
@@ -59,10 +60,13 @@ export function createInteractiveExitSummary(input: {
return undefined;
}
const totalCost =
let totalCost =
asFiniteNumber(input.usage?.totalCost) ??
asFiniteNumber(input.row?.metadata?.aggregatedAgentsCost) ??
asFiniteNumber(input.row?.metadata?.totalCost);
if (input.shouldZeroCost && totalCost !== undefined) {
totalCost = 0;
}
return {
sessionId,
@@ -93,6 +93,7 @@ export function createInteractiveSessionRuntime(input: {
onTeamEvent: (event: TeamEvent) => void;
onPendingPrompts: (event: PendingPromptSnapshot) => void;
onPendingPromptSubmitted: (event: PendingPromptSubmittedEvent) => void;
shouldZeroExitSummaryCost?: () => boolean;
}) {
let sessionManager: CliCore | undefined;
let runtimeHooks: RuntimeHooks | undefined;
@@ -344,6 +345,7 @@ export function createInteractiveSessionRuntime(input: {
row,
messages,
usage,
shouldZeroCost: input.shouldZeroExitSummaryCost?.() ?? false,
});
};
+3
View File
@@ -159,6 +159,7 @@ export async function runInteractive(
});
const providerSettingsManager = new ProviderSettingsManager();
let zeroCurrentTurnCost = false;
let zeroExitSummaryCost = false;
const sessionRuntime = createInteractiveSessionRuntime({
config,
@@ -183,6 +184,7 @@ export async function runInteractive(
onPendingPromptSubmitted: (event) => {
uiEvents.emit("pending-prompt-submitted", event);
},
shouldZeroExitSummaryCost: () => zeroExitSummaryCost,
});
let modeChangePromise: Promise<void> | undefined;
let modeChangeTarget: "plan" | "act" | undefined;
@@ -487,6 +489,7 @@ export async function runInteractive(
commandOutput = chatCommandResult.commandOutput;
zeroTurnCost = await shouldZeroClineFreeModelCost(config);
zeroCurrentTurnCost = zeroTurnCost;
zeroExitSummaryCost ||= zeroTurnCost;
const {
prompt: userInput,
userImages,