feat(tui): use configured compaction threshold for /context output

This commit is contained in:
William Valentin
2026-02-16 18:10:54 -08:00
parent 409ab04ca1
commit fc6a79ed90
7 changed files with 53 additions and 4 deletions
+39
View File
@@ -29,6 +29,7 @@ function asAgent(value: unknown): NativeAgent {
function minimalTuiPrivates(value: MinimalTui): {
handleBackendCommand: (provider: string) => Promise<void>;
handleModelCommand: (tier: string, providerModel?: string) => void;
handleContextCommand: () => void;
handleEscapeAction: () => boolean;
prompt: (text: string) => Promise<string>;
rl: {
@@ -43,6 +44,7 @@ function minimalTuiPrivates(value: MinimalTui): {
return value as unknown as {
handleBackendCommand: (provider: string) => Promise<void>;
handleModelCommand: (tier: string, providerModel?: string) => void;
handleContextCommand: () => void;
handleEscapeAction: () => boolean;
prompt: (text: string) => Promise<string>;
rl: {
@@ -174,6 +176,43 @@ describe('MinimalTui backend command', () => {
expect(mockAgent.setModelTier).toHaveBeenCalledWith('local');
});
it('uses configured compaction threshold in /context output', () => {
const mockSession = {
id: 'test',
getHistory: () => [{ role: 'user', content: 'x'.repeat(400) }],
addMessage: vi.fn(),
clear: vi.fn(),
replaceHistory: vi.fn(),
};
const mockRouter: TuiRouterStub = {
getTier: () => 'default' as const,
getAvailableTiers: () => ['default'],
setTier: vi.fn(() => true),
getLabel: () => 'gpt-4o',
getLocalProviderName: () => 'ollama',
setLocalClient: vi.fn(),
chat: vi.fn(),
getClient: vi.fn(),
};
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
try {
const tui = new MinimalTui({
session: asSession(mockSession),
modelClient: asRouter(mockRouter),
modelRouter: asRouter(mockRouter),
systemPrompt: 'test',
contextThresholdPct: 67,
});
minimalTuiPrivates(tui).handleContextCommand();
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('compaction threshold: 67%'));
} finally {
logSpy.mockRestore();
}
});
it('reuses configured provider credentials for /model <tier> <provider/model>', () => {
const prevOpenRouterKey = process.env.OPENROUTER_API_KEY;
delete process.env.OPENROUTER_API_KEY;