Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/plan-usage-percent-used.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Improve the usage information display in the TUI.
14 changes: 8 additions & 6 deletions apps/kimi-code/src/tui/components/messages/usage-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,19 @@ function buildManagedUsageSection(
const rows: ManagedUsageRow[] = [];
if (summary !== null) rows.push(summary);
rows.push(...limits);
const usedRatio = (r: ManagedUsageRow): number =>
r.limit > 0 ? Math.max(0, Math.min(r.used / r.limit, 1)) : 0;
const labelWidth = Math.max(10, ...rows.map((r) => r.label.length));
const pctWidth = Math.max(...rows.map((r) => `${Math.round(usedRatio(r) * 100)}% used`.length));
const out: string[] = [accent('Plan usage')];
for (const row of rows) {
const ratioUsed = row.limit > 0 ? row.used / row.limit : 0;
const leftRatio = 1 - Math.max(0, Math.min(ratioUsed, 1));
const bar = renderProgressBar(Math.max(0, Math.min(ratioUsed, 1)), 20);
const pct = `${Math.round(leftRatio * 100)}% left`;
const ratioUsed = usedRatio(row);
const bar = renderProgressBar(ratioUsed, 20);
const pct = `${Math.round(ratioUsed * 100)}% used`;
const barColoured = chalk.hex(severityHex(ratioSeverity(ratioUsed)))(bar);
const label = row.label.padEnd(labelWidth, ' ');
const resetStr = row.resetHint ? muted(` (${row.resetHint})`) : '';
out.push(` ${muted(label)} ${barColoured} ${value(pct)}${resetStr}`);
const resetStr = row.resetHint ? ` ${muted(row.resetHint)}` : '';
out.push(` ${muted(label)} ${barColoured} ${value(pct.padEnd(pctWidth, ' '))}${resetStr}`);
}
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('status panel report lines', () => {
expect(output).toContain('25.0%');
expect(output).toContain('(3.0k / 12.0k)');
expect(output).toContain('Plan usage');
expect(output).toContain('92% left');
expect(output).toContain('8% used');
expect(output).not.toContain('Account');
expect(output).not.toContain('AGENTS.md');
expect(output).not.toContain('Runtime');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('UsagePanelComponent', () => {
expect(lines).toContain('Context window');
expect(lines.join('\n')).toContain('25.0%');
expect(lines).toContain('Plan usage');
expect(lines.join('\n')).toContain('80% left');
expect(lines.join('\n')).toContain('(resets tomorrow)');
expect(lines.join('\n')).toContain('20% used');
expect(lines.join('\n')).toContain('resets tomorrow');
});

it('wraps preformatted usage lines in a bordered panel', () => {
Expand Down
Loading