From 465b4a0c3cfb79e945a349f2b3e743a8447f114d Mon Sep 17 00:00:00 2001 From: William Valentin Date: Thu, 5 Feb 2026 13:35:10 -0800 Subject: [PATCH] feat: add /backend command parsing Add support for /backend command to show or switch local backend providers. Follows the same pattern as /model command with optional argument support. Co-Authored-By: Claude Opus 4.5 --- src/frontends/tui/commands.test.ts | 9 +++++++++ src/frontends/tui/commands.ts | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/frontends/tui/commands.test.ts b/src/frontends/tui/commands.test.ts index 917b408..dea4267 100644 --- a/src/frontends/tui/commands.test.ts +++ b/src/frontends/tui/commands.test.ts @@ -35,6 +35,15 @@ describe('parseCommand', () => { expect(parseCommand('/model opus')).toEqual({ type: 'model', name: 'opus' }); }); + it('parses /backend command without argument', () => { + expect(parseCommand('/backend')).toEqual({ type: 'backend' }); + }); + + it('parses /backend command with argument', () => { + expect(parseCommand('/backend llamacpp')).toEqual({ type: 'backend', provider: 'llamacpp' }); + expect(parseCommand('/backend ollama')).toEqual({ type: 'backend', provider: 'ollama' }); + }); + it('parses /transfer command', () => { expect(parseCommand('/transfer telegram')).toEqual({ type: 'transfer', target: 'telegram' }); }); diff --git a/src/frontends/tui/commands.ts b/src/frontends/tui/commands.ts index 015f4e7..7602f4e 100644 --- a/src/frontends/tui/commands.ts +++ b/src/frontends/tui/commands.ts @@ -5,6 +5,7 @@ export type Command = | { type: 'status' } | { type: 'fullscreen' } | { type: 'model'; name?: string } + | { type: 'backend'; provider?: string } | { type: 'transfer'; target: string } | { type: 'message'; content: string }; @@ -46,6 +47,15 @@ export function parseCommand(input: string): Command | null { return { type: 'model', name }; } + // Backend (with optional argument) + if (trimmed === '/backend') { + return { type: 'backend' }; + } + if (trimmed.startsWith('/backend ')) { + const provider = trimmed.slice('/backend '.length).trim(); + return { type: 'backend', provider }; + } + // Transfer if (trimmed.startsWith('/transfer ')) { const target = trimmed.slice('/transfer '.length).trim(); @@ -61,6 +71,7 @@ export function getHelpText(): string { Commands: /help, /? Show this help /model [name] Show or switch model (local, default, fast, complex) + /backend [provider] Show or switch local backend (ollama, llamacpp) /reset, /clear Clear conversation history /status Show session info and token usage /fullscreen, /fs Switch to fullscreen mode