feat(#2160): collapse verbose '(1M context)' model suffix to compact (1M) badge (#2173)

* feat(#2160): collapse verbose '(1M context)' model suffix to compact (1M) badge

Claude Code appends " (1M context)" to the model display name in
long-context sessions, eating 12 characters of statusline width. Collapse
it to " (1M)" — the signal stays, the width doesn't. Any other display
name passes through unchanged.

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

* docs(#2160): changeset fragment for PR #2173

* fix(#2160): review fixes — ctx variant, boundary test, changeset format

- broaden the suffix match with a context|ctx alternation (approval-condition
  variant the regex missed)
- pin non-context parentheticals ((beta), (deprecated)) as untouched
- changeset body ends with the (#2160) citation per house convention

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

* test: regenerate golden-install-parity fixtures for the statusline hook change

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

---------

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
Cody Anderson
2026-07-14 18:37:43 -06:00
committed by GitHub
parent fc913b37a5
commit eec9efc351
14 changed files with 89 additions and 13 deletions

View File

@@ -1365,6 +1365,60 @@ test('config-set statusline.show_context_tokens yes → rejected', () => {
}
// ────────────────────────────────────────────────────────────────────────
// Compact 1M model badge
// ────────────────────────────────────────────────────────────────────────
{
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const statusline = require('../hooks/gsd-statusline.js');
const { compactModelName } = statusline;
describe('compactModelName', () => {
test('collapses "(1M context)" to "(1M)"', () => {
assert.equal(compactModelName('Sonnet 4.5 (1M context)'), 'Sonnet 4.5 (1M)');
});
test('is case-insensitive on "context" and preserves the token case', () => {
assert.equal(compactModelName('Opus 4.6 (1m CONTEXT)'), 'Opus 4.6 (1m)');
});
test('tolerates future window sizes (#2160 approval condition)', () => {
assert.equal(compactModelName('Sonnet 5 (500K context)'), 'Sonnet 5 (500K)');
assert.equal(compactModelName('Opus 5 (2M context)'), 'Opus 5 (2M)');
});
test('handles the abbreviated "ctx" variant (#2160 approval condition)', () => {
assert.equal(compactModelName('Sonnet 4.5 (1M ctx)'), 'Sonnet 4.5 (1M)');
assert.equal(compactModelName('Opus 5 (2M CTX)'), 'Opus 5 (2M)');
});
test('leaves non-context parentheticals untouched', () => {
assert.equal(compactModelName('Sonnet 5 (beta)'), 'Sonnet 5 (beta)');
assert.equal(compactModelName('Opus 4 (deprecated)'), 'Opus 4 (deprecated)');
});
test('leaves ordinary names unchanged', () => {
assert.equal(compactModelName('Claude'), 'Claude');
assert.equal(compactModelName('Sonnet 4.5'), 'Sonnet 4.5');
});
test('only matches the suffix position', () => {
assert.equal(
compactModelName('(1M context) Special'), '(1M context) Special');
});
test('passes non-strings through', () => {
assert.equal(compactModelName(undefined), undefined);
assert.equal(compactModelName(null), null);
});
});
describe('renderStatusline uses the compact badge', () => {
test('rendered output carries (1M), not (1M context)', () => {
const out = statusline.renderStatusline({
model: { display_name: 'Sonnet 4.5 (1M context)' },
workspace: { current_dir: require('node:os').tmpdir() },
});
assert.ok(out.includes('Sonnet 4.5 (1M)'), `expected compact badge; got: ${out}`);
assert.ok(!out.includes('(1M context)'), `expected no verbose suffix; got: ${out}`);
});
});
}
// ────────────────────────────────────────────────────────────────────────
// Git segment (statusline.show_git)
// ────────────────────────────────────────────────────────────────────────