Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- **Token breakdown: decompose the "in" headline into fresh vs cached.** The headline
"NN in" is dominated by cheap `cache_read` tokens; a new `Input X new · Y cached`
line separates freshly-billed input (`input + cache_creation`) from cache reads, so the
cost line is interpretable (a big "in" at 97% cache is mostly $1.50/M reads, not $15/M
fresh input). Applied to the single-session and live views.

## [1.0.0] - 2026-02-18

### Added
Expand Down
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,19 @@ describe('formatter: insights', () => {
expect(output).toContain('Warmup overhead');
});
});

describe('formatSession: input decomposed into fresh vs cached', () => {
it('shows freshly-billed input (input + cache writes) and cache reads separately', () => {
// input 5K + cacheCreation 10K = 15K fresh; cacheRead 50K cached.
const output = strip(formatSession(makeAnalysis()));
expect(output).toContain('Input');
expect(output).toContain('15.0K new');
expect(output).toContain('50.0K cached');
});

it('the headline "in" remains the full context total (fresh + cached)', () => {
// input+cacheRead+cacheCreation = 65K — the line a user sees as scale.
const output = strip(formatSession(makeAnalysis()));
expect(output).toContain('65.0K in');
});
});
8 changes: 8 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export function formatSession(analysis: SessionAnalysis): string {
const inBar = Math.round(inFrac * BAR_WIDTH);
const outBar = BAR_WIDTH - inBar;
lines.push(` Tokens ${chalk.cyan('\u2588'.repeat(inBar))}${chalk.green('\u2588'.repeat(outBar))} ${chalk.cyan(formatTokens(tokens.input + tokens.cacheRead + tokens.cacheCreation) + ' in')} ${chalk.green(formatTokens(tokens.output) + ' out')}`);
// Decompose "in": the headline is dominated by cheap cache reads. Show the
// freshly-billed input (input + cache writes) separately so the cost line
// is interpretable (a huge "in" at 97% cache is mostly $1.50/M reads, not
// $15/M fresh input).
const freshIn = tokens.input + tokens.cacheCreation;
lines.push(` Input ${chalk.gray(formatTokens(freshIn) + ' new')} ${chalk.gray('\u00b7')} ${chalk.gray(formatTokens(tokens.cacheRead) + ' cached')}`);
}
const cachePct = Math.round(analysis.cacheHitRate * 100);
lines.push(` Cache ${renderCacheBar(analysis.cacheHitRate)} ${cachePct}% hit`);
Expand Down Expand Up @@ -263,6 +269,8 @@ export function formatSessionLive(analysis: SessionAnalysis): string {
const inBar = Math.round(inFrac * BAR_WIDTH);
const outBar = BAR_WIDTH - inBar;
lines.push(` Tokens ${chalk.cyan('\u2588'.repeat(inBar))}${chalk.green('\u2588'.repeat(outBar))} ${chalk.cyan(formatTokens(liveTok.input + liveTok.cacheRead + liveTok.cacheCreation) + ' in')} ${chalk.green(formatTokens(liveTok.output) + ' out')}`);
const liveFreshIn = liveTok.input + liveTok.cacheCreation;
lines.push(` Input ${chalk.gray(formatTokens(liveFreshIn) + ' new')} ${chalk.gray('\u00b7')} ${chalk.gray(formatTokens(liveTok.cacheRead) + ' cached')}`);
}
const liveCachePct = Math.round(analysis.cacheHitRate * 100);
lines.push(` Cache ${renderCacheBar(analysis.cacheHitRate)} ${liveCachePct}% hit`);
Expand Down