From f7cc87a4bb5b76651a2338ef9cd9a57adcf54ae9 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Fri, 6 Feb 2026 10:05:32 -0800 Subject: [PATCH] fix: sync agent tier when /model command switches model The /model command was only updating the router's currentTier but not the agent's currentTier. Since NativeAgent.chatWithRouter() passes its own tier to router.chat(), switching to 'local' still sent requests through the default (Anthropic) client first. --- src/frontends/tui/minimal.test.ts | 39 +++++++++++++++++++++++++++++++ src/frontends/tui/minimal.ts | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/src/frontends/tui/minimal.test.ts b/src/frontends/tui/minimal.test.ts index 1830536..579e908 100644 --- a/src/frontends/tui/minimal.test.ts +++ b/src/frontends/tui/minimal.test.ts @@ -77,4 +77,43 @@ describe('MinimalTui backend command', () => { expect(mockRouter.setLocalClient).toHaveBeenCalled(); }); + + it('syncs agent tier when /model command switches tier', () => { + const mockSession = { + id: 'test', + getHistory: () => [], + addMessage: vi.fn(), + clear: vi.fn(), + }; + + const mockRouter = { + getTier: () => 'default' as const, + getAvailableTiers: () => ['default', 'local'], + setTier: vi.fn(() => true), + getLocalProviderName: () => 'ollama', + setLocalClient: vi.fn(), + chat: vi.fn(), + getClient: vi.fn(), + }; + + const mockAgent = { + setModelTier: vi.fn(), + getModelTier: vi.fn(() => 'default'), + process: vi.fn(), + }; + + const tui = new MinimalTui({ + session: mockSession as any, + modelClient: mockRouter as any, + modelRouter: mockRouter as any, + agent: mockAgent as any, + systemPrompt: 'test', + }); + + // Call private handleModelCommand to switch to local + (tui as any).handleModelCommand('local'); + + expect(mockRouter.setTier).toHaveBeenCalledWith('local'); + expect(mockAgent.setModelTier).toHaveBeenCalledWith('local'); + }); }); diff --git a/src/frontends/tui/minimal.ts b/src/frontends/tui/minimal.ts index 57f58ce..1ea8344 100644 --- a/src/frontends/tui/minimal.ts +++ b/src/frontends/tui/minimal.ts @@ -213,6 +213,10 @@ export class MinimalTui { const tier = resolveModelAlias(name); if (router.setTier(tier)) { + // Also update the agent tier so chatWithRouter uses the correct client + if (this.config.agent) { + this.config.agent.setModelTier(tier); + } console.log(`${colors.gray}Switched to model:${colors.reset} ${tier}\n`); } else { console.log(`${colors.gray}Model not available:${colors.reset} ${name}\n`);