feat(cli): invert context window display to show usage (#20071)

Co-authored-by: jacob314 <jacob314@gmail.com>
This commit is contained in:
Keith Guerin
2026-03-03 01:22:29 -08:00
committed by GitHub
parent 208291f391
commit 1e2afbb514
19 changed files with 235 additions and 68 deletions

View File

@@ -735,5 +735,59 @@ describe('SettingsUtils', () => {
expect(result).toBe('false');
});
});
describe('getDisplayValue with units', () => {
it('should format percentage correctly when unit is %', () => {
vi.mocked(getSettingsSchema).mockReturnValue({
model: {
properties: {
compressionThreshold: {
type: 'number',
label: 'Context Compression Threshold',
category: 'Model',
requiresRestart: true,
default: 0.5,
unit: '%',
},
},
},
} as unknown as SettingsSchemaType);
const settings = makeMockSettings({
model: { compressionThreshold: 0.8 },
});
const result = getDisplayValue(
'model.compressionThreshold',
settings,
makeMockSettings({}),
);
expect(result).toBe('0.8 (80%)*');
});
it('should append unit for non-% units', () => {
vi.mocked(getSettingsSchema).mockReturnValue({
ui: {
properties: {
pollingInterval: {
type: 'number',
label: 'Polling Interval',
category: 'UI',
requiresRestart: false,
default: 60,
unit: 's',
},
},
},
} as unknown as SettingsSchemaType);
const settings = makeMockSettings({ ui: { pollingInterval: 30 } });
const result = getDisplayValue(
'ui.pollingInterval',
settings,
makeMockSettings({}),
);
expect(result).toBe('30s*');
});
});
});
});

View File

@@ -84,7 +84,7 @@ export function getDefaultValue(key: string): SettingsValue {
/**
* Get the effective default value for a setting, checking experiment values when available.
* For settings like compressionThreshold, this will return the experiment value if set,
* For settings like Context Compression Threshold, this will return the experiment value if set,
* otherwise falls back to the schema default.
*/
export function getEffectiveDefaultValue(
@@ -289,6 +289,11 @@ export function getDisplayValue(
valueString = option?.label ?? `${value}`;
}
if (definition?.unit === '%' && typeof value === 'number') {
valueString = `${value} (${Math.round(value * 100)}%)`;
} else if (definition?.unit) {
valueString = `${valueString}${definition.unit}`;
}
if (existsInScope) {
return `${valueString}*`;
}