feat(cli): show context compression count in status bar

Display the number of context compressions in the CLI status bar when
compressions > 0, helping users understand conversation compression
pressure during long sessions.

- Wide layout (>=76 cols): shows 'cmp N' between context percent and duration
- Medium layout (52-75 cols): shows 'cmp N' between percent and duration
- Narrow layout (<52 cols): omitted to save space
- Color-coded: dim for 1-4, warn for 5-9, bad for 10+
- Hidden when zero to keep the bar clean for new sessions

Closes #18564
This commit is contained in:
Sofia Yang 2026-05-01 18:24:06 -05:00 committed by Teknium
parent e38ea38079
commit 103e11926f
2 changed files with 141 additions and 2 deletions

View file

@ -207,6 +207,118 @@ class TestCLIStatusBar:
assert "" in text
assert "claude-sonnet-4-20250514" in text
def test_compression_count_shown_in_wide_status_bar(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_230,
completion_tokens=2_220,
total_tokens=12_450,
api_calls=7,
context_tokens=12_450,
context_length=200_000,
compressions=3,
)
text = cli_obj._build_status_bar_text(width=120)
assert "cmp 3" in text
def test_compression_count_hidden_when_zero(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_230,
completion_tokens=2_220,
total_tokens=12_450,
api_calls=7,
context_tokens=12_450,
context_length=200_000,
compressions=0,
)
text = cli_obj._build_status_bar_text(width=120)
assert "cmp" not in text
def test_compression_count_shown_in_medium_status_bar(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_000,
completion_tokens=2_400,
total_tokens=12_400,
api_calls=7,
context_tokens=12_400,
context_length=200_000,
compressions=2,
)
text = cli_obj._build_status_bar_text(width=60)
assert "cmp 2" in text
def test_compression_count_hidden_in_narrow_status_bar(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_000,
completion_tokens=2_400,
total_tokens=12_400,
api_calls=7,
context_tokens=12_400,
context_length=200_000,
compressions=5,
)
text = cli_obj._build_status_bar_text(width=50)
assert "cmp" not in text
def test_compression_count_style_thresholds(self):
cli_obj = _make_cli()
assert cli_obj._compression_count_style(1) == "class:status-bar-dim"
assert cli_obj._compression_count_style(4) == "class:status-bar-dim"
assert cli_obj._compression_count_style(5) == "class:status-bar-warn"
assert cli_obj._compression_count_style(9) == "class:status-bar-warn"
assert cli_obj._compression_count_style(10) == "class:status-bar-bad"
assert cli_obj._compression_count_style(25) == "class:status-bar-bad"
def test_compression_count_in_wide_fragments(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_230,
completion_tokens=2_220,
total_tokens=12_450,
api_calls=7,
context_tokens=12_450,
context_length=200_000,
compressions=7,
)
cli_obj._status_bar_visible = True
frags = cli_obj._get_status_bar_fragments()
frag_texts = [text for _, text in frags]
assert "cmp 7" in frag_texts
frag_styles = {text: style for style, text in frags}
assert frag_styles["cmp 7"] == "class:status-bar-warn"
def test_compression_count_absent_from_fragments_when_zero(self):
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_230,
completion_tokens=2_220,
total_tokens=12_450,
api_calls=7,
context_tokens=12_450,
context_length=200_000,
compressions=0,
)
cli_obj._status_bar_visible = True
frags = cli_obj._get_status_bar_fragments()
frag_texts = [text for _, text in frags]
assert not any("cmp" in t for t in frag_texts)
def test_minimal_tui_chrome_threshold(self):
cli_obj = _make_cli()