Script for easily configuring, using, switching and comparing local offline coding models
1import { TUIS, getTuiById } from "../registry/tuis.js";
2import { loadConfig, saveConfig, getActiveTui } from "../runtime-config.js";
3import { createLauncherScripts } from "../steps/scripts.js";
4import { writeTuiConfig } from "../steps/aider-config.js";
5import { commandExists, runPassthrough } from "../util.js";
6import { log, err } from "../log.js";
7
8const BOLD = "\x1b[1m";
9const GREEN = "\x1b[0;32m";
10const DIM = "\x1b[2m";
11const RESET = "\x1b[0m";
12
13export function listTuis(): void {
14 const activeId = getActiveTui().id;
15
16 console.log(`\n${BOLD}Available TUIs:${RESET}`);
17 for (const t of TUIS) {
18 const active = t.id === activeId ? ` ${GREEN}<- active${RESET}` : "";
19 const installed = commandExists(t.checkCmd)
20 ? ""
21 : ` ${DIM}(not installed)${RESET}`;
22 console.log(` ${BOLD}${t.id}${RESET} ${t.name}${active}${installed}`);
23 }
24 console.log("");
25}
26
27export async function setTui(id: string): Promise<void> {
28 const tui = getTuiById(id);
29 if (!tui) {
30 err(
31 `Unknown TUI: ${id}\nAvailable: ${TUIS.map((t) => t.id).join(", ")}`,
32 );
33 }
34
35 // Install if needed
36 if (!commandExists(tui.checkCmd)) {
37 log(`Installing ${tui.name}...`);
38 runPassthrough(tui.installCmd);
39 }
40
41 const config = loadConfig();
42 config.tui = id;
43 saveConfig(config);
44 log(`Active TUI set to ${tui.name}`);
45
46 // Regenerate scripts and configs
47 await createLauncherScripts();
48 await writeTuiConfig();
49 log("Launcher scripts and configs regenerated.");
50}