import { execSync } from "node:child_process"; import { getChatModels, getAutocompleteModels } from "../registry/models.js"; import { TUIS } from "../registry/tuis.js"; import { getActiveChatModel, getActiveAutocompleteModel, getActiveTui } from "../runtime-config.js"; import { commandExists } from "../util.js"; const BOLD = "\x1b[1m"; const GREEN = "\x1b[0;32m"; const DIM = "\x1b[2m"; const RESET = "\x1b[0m"; function isPulled(ollamaTag: string): boolean { try { const output = execSync("ollama list", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }); return output.includes(ollamaTag); } catch { return false; } } export function listModels(): void { const activeChatId = getActiveChatModel().id; const activeAutoId = getActiveAutocompleteModel().id; console.log(`\n${BOLD}Chat models:${RESET}`); for (const m of getChatModels()) { const active = m.id === activeChatId ? ` ${GREEN}<- active${RESET}` : ""; const pulled = isPulled(m.ollamaTag) ? "" : ` ${DIM}(not pulled)${RESET}`; console.log( ` ${BOLD}${m.id}${RESET} ${m.name} ${DIM}${m.ollamaTag}${RESET}${active}${pulled}`, ); } console.log(`\n${BOLD}Autocomplete models:${RESET}`); for (const m of getAutocompleteModels()) { const active = m.id === activeAutoId ? ` ${GREEN}<- active${RESET}` : ""; const pulled = isPulled(m.ollamaTag) ? "" : ` ${DIM}(not pulled)${RESET}`; console.log( ` ${BOLD}${m.id}${RESET} ${m.name} ${DIM}${m.ollamaTag}${RESET}${active}${pulled}`, ); } console.log(""); } export function listTuis(): void { const activeId = getActiveTui().id; console.log(`\n${BOLD}Available TUIs:${RESET}`); for (const t of TUIS) { const active = t.id === activeId ? ` ${GREEN}<- active${RESET}` : ""; const installed = commandExists(t.checkCmd) ? "" : ` ${DIM}(not installed)${RESET}`; console.log(` ${BOLD}${t.id}${RESET} ${t.name}${active}${installed}`); } console.log(""); }