Script for easily configuring, using, switching and comparing local offline coding models
1import { execSync } from "node:child_process";
2import { getChatModels, getAutocompleteModels } from "../registry/models.js";
3import { TUIS } from "../registry/tuis.js";
4import { getActiveChatModel, getActiveAutocompleteModel, getActiveTui } from "../runtime-config.js";
5import { commandExists } from "../util.js";
6
7const BOLD = "\x1b[1m";
8const GREEN = "\x1b[0;32m";
9const DIM = "\x1b[2m";
10const RESET = "\x1b[0m";
11
12function isPulled(ollamaTag: string): boolean {
13 try {
14 const output = execSync("ollama list", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
15 return output.includes(ollamaTag);
16 } catch {
17 return false;
18 }
19}
20
21export function listModels(): void {
22 const activeChatId = getActiveChatModel().id;
23 const activeAutoId = getActiveAutocompleteModel().id;
24
25 console.log(`\n${BOLD}Chat models:${RESET}`);
26 for (const m of getChatModels()) {
27 const active = m.id === activeChatId ? ` ${GREEN}<- active${RESET}` : "";
28 const pulled = isPulled(m.ollamaTag) ? "" : ` ${DIM}(not pulled)${RESET}`;
29 console.log(
30 ` ${BOLD}${m.id}${RESET} ${m.name} ${DIM}${m.ollamaTag}${RESET}${active}${pulled}`,
31 );
32 }
33
34 console.log(`\n${BOLD}Autocomplete models:${RESET}`);
35 for (const m of getAutocompleteModels()) {
36 const active = m.id === activeAutoId ? ` ${GREEN}<- active${RESET}` : "";
37 const pulled = isPulled(m.ollamaTag) ? "" : ` ${DIM}(not pulled)${RESET}`;
38 console.log(
39 ` ${BOLD}${m.id}${RESET} ${m.name} ${DIM}${m.ollamaTag}${RESET}${active}${pulled}`,
40 );
41 }
42 console.log("");
43}
44
45export function listTuis(): void {
46 const activeId = getActiveTui().id;
47
48 console.log(`\n${BOLD}Available TUIs:${RESET}`);
49 for (const t of TUIS) {
50 const active = t.id === activeId ? ` ${GREEN}<- active${RESET}` : "";
51 const installed = commandExists(t.checkCmd)
52 ? ""
53 : ` ${DIM}(not installed)${RESET}`;
54 console.log(` ${BOLD}${t.id}${RESET} ${t.name}${active}${installed}`);
55 }
56 console.log("");
57}