Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

57.8 KB
Raw Blame
// Curated cross-backend catalog of popular local LLMs.
//
// PortOS supports two local-LLM backends — Ollama (content-addressed blob
// store) and LM Studio (plain GGUF files). Their model identifiers differ
// (`llama3.2` vs `lmstudio-community/Llama-3.2-3B-Instruct-GGUF`). The GGUF
// weights themselves ARE portable; only the on-disk layout differs, so the
// migrate flow copies the weights across locally when it can (see
// `localLlmDisk.js`) and re-pulls the equivalent only when it can't. This
// catalog is the mapping table that makes both the in-UI install picker and
// the migrate re-pull fallback work without guessing: each entry carries the
// canonical id for whichever backend(s) ship a well-known build of that model.
//
// This module is pure (no I/O, no network) so it can be unit-tested and
// imported anywhere. The installed-state overlay is applied by the caller
// (server/services/localLlm.js) which knows what's actually on disk.

import { localModelSafety } from './localModelSafety.js';
import { hardwareRequirementsForLocalLlm } from './systemCapabilities.js';

export const BACKENDS = ['ollama', 'lmstudio'];

export const isBackend = (b) => BACKENDS.includes(b);

export const LOCAL_LLM_CATEGORIES = [
  { id: 'general', label: 'General purpose' },
  { id: 'coding', label: 'Coding & agents' },
  { id: 'security', label: 'Security specialists' },
  { id: 'security-uncensored', label: 'Security · Uncensored / abliterated' },
  { id: 'reasoning', label: 'Reasoning & analysis' },
  { id: 'vision', label: 'Image Analysis' },
  { id: 'chat', label: 'Chat & voice' },
  { id: 'writing', label: 'Fiction & writing' },
  // Audio/music GENERATION models (ACE-Step, MusicGen, AudioLDM2, Stable Audio,
  // Magenta…). These are NOT GGUF chat models and don't run on Ollama/LM Studio
  // — the Hugging Face search relaxes its GGUF filter for this category and the
  // installer routes audio installs into the shared audio-model registry
  // (server/services/audioModels.js) so the Music studio picks them up. The
  // curated `LOCAL_LLM_CATALOG` below never tags entries 'audio'; this category
  // is populated live from the Hub.
  { id: 'audio', label: 'Audio & Music' },
  { id: 'embedding', label: 'Text Embeddings' },
  { id: 'lightweight', label: 'Small & Fast' },
  { id: 'multilingual', label: 'Multilingual' }
];

// Each entry: { key, name, category, recommendedFor?, featured?, params, size,
//               family, description, note?, repository?, gated?, capabilities, context?, format?,
//               appleSiliconOnly?, ollama?, lmstudio?, ollamaImport?, ollamaAliases?,
//               lmstudioAliases?, benchmarkModel? }
//
// `category` is the one primary lane that groups a model in the unfiltered
// picker. `recommendedFor` is its intentionally broader set of use-case lanes:
// a general model can surface in Coding or Vision without being mislabeled as a
// specialist, while `capabilities` remains the factual modality/tool badge set.
// It must include the primary category. `featured` is reserved for a deliberate
// first-choice recommendation, not a measure of raw benchmark scores.
// `ollama` / `lmstudio` are the exact pull/download ids for that backend.
// `ollamaImport` marks a curated Hugging Face Safetensors directory that PortOS
// imports with `ollama create` instead of trying to pull from Ollama's registry.
// A missing id means there is no well-known build of that model for that
// backend (the user can still free-text install one).
// `ollamaAliases` / `lmstudioAliases` preserve recognized ids retired by an
// upstream publisher without making them available as fresh install targets.
// `benchmarkModel` is this entry's name in the public benchmark index behind
// Models > Comparison, and it is the ONLY thing that puts a locally installed
// model on that chart. Set it only where the evaluated configuration has been
// checked against the entry — never because the names look alike. The textual
// normalization in `comparisonModelScope.js` deliberately cannot derive it:
// `ornith:35b` and `Ornith-1.0-35B-GGUF` are one model with two spellings PortOS
// owns, and guessing from the id alone folds `Foundation-Sec-8B-Reasoning` onto
// the different `foundation-sec-8b` and a 4-bit local build onto the hosted
// API's price and throughput rows. Omit it when no equivalence is established;
// the model simply carries no benchmark evidence, which is the honest state.
// `context` is the model's native context window in tokens — set it only when
// it's a documented spec for that build (the install-card badge shows it; live
// Hugging Face results read the true value from GGUF metadata instead).
// `format` identifies a backend-native format such as `mlx` when the install id
// is not a GGUF build. `appleSiliconOnly` keeps native MLX recommendations out
// of catalogs where the selected host cannot run them.
//
// Ollama ids must name a build that runs LOCALLY. Several headline 2026 models
// (mistral-large-3, glm-5.2, deepseek-v4-*, minimax-m3, kimi-k3) are published
// to the Ollama library as `:cloud`-only tags whose manifests carry no weights —
// pulling one gets you an API passthrough, not a local model. Verify a tag has a
// non-zero manifest size before adding it here.
//
// Nor may an entry name weights whose KERNELS the backend lacks. Ollama and LM
// Studio both embed a stock llama.cpp, so a build carrying a vendor's private
// quantization type belongs in `specDecodePresets.js` (the llama-server launcher,
// where the operator chooses the binary) and NOT here. Ternary Bonsai 2 27B is
// the worked example: stock llama.cpp rejects its `PQ2_0`/`PTQ1_0` packs as
// unknown types, and — the reason this is a hard rule rather than a preference —
// it loads a plain ternary `Q2_0` with no warning and generates garbage, so the
// install would look like it worked. The same applies on the MLX side: that
// model's `mlx-2bit` pack declares a `prism_hadamard_qwen35` model type and ships
// its own loader, and a stock MLX loader skips the activation transform and
// returns wrong output rather than an error. See
// docs/research/2026-09-18-ternary-bonsai-2-27b.md.
export const LOCAL_LLM_CATALOG = [
  {
    key: 'vulnllm-r-7b-gguf', name: 'VulnLLM-R 7B (GGUF)',
    category: 'security', recommendedFor: ['security'],
    featured: { label: 'Vulnerability specialist', description: 'First specialist to evaluate for source vulnerability detection. Published results use different prompts and agent scaffolding; validate findings on your app.' },
    params: '7B', size: '8.1 GB', family: 'qwen',
    description: 'Specialized vulnerability reasoning from the original UCSB/VirtueAI project, converted by mradermacher. Published evaluations cover C/C++, Python and Java; JavaScript, TypeScript and Swift quality remains unverified.',
    note: 'Use the sandboxed Private security assessment task. No verified CyberGym, ExploitBench or ExploitGym scores; quantized quality and remediation require validation.',
    repository: 'mradermacher/VulnLLM-R-7B-GGUF',
    capabilities: ['chat', 'code', 'reasoning'],
    ollama: 'hf.co/mradermacher/VulnLLM-R-7B-GGUF:Q8_0',
    lmstudio: 'mradermacher/VulnLLM-R-7B-GGUF@Q8_0',
  },
  {
    key: 'foundation-sec-8b-reasoning', name: 'Foundation-Sec 8B Reasoning',
    category: 'security', recommendedFor: ['security'],
    params: '8B', size: '8.5 GB', family: 'llama', context: 32768,
    description: 'Cisco Foundation AI security reasoning model, using Cisco’s own Q8 GGUF. A baseline for threat modeling, vulnerability interpretation and remediation guidance; CTI benchmarks do not establish code-audit or patch correctness.',
    note: 'Safety-aligned, not an abliterated model. Run in the private assessment sandbox and independently validate guidance.',
    repository: 'fdtn-ai/Foundation-Sec-8B-Reasoning-Q8_0-GGUF',
    capabilities: ['chat', 'reasoning'],
    ollama: 'hf.co/fdtn-ai/Foundation-Sec-8B-Reasoning-Q8_0-GGUF:Q8_0',
    lmstudio: 'fdtn-ai/Foundation-Sec-8B-Reasoning-Q8_0-GGUF@Q8_0',
  },
  // Security candidates stay in a separate lane; refusal removal is not a
  // measured security capability. Exact-build evidence lives in localModelSafety.
  {
    key: 'qwen38-27b-uncensored-gguf',
    name: 'Qwen3.8 27B Uncensored (GGUF)',
    category: 'security-uncensored', recommendedFor: ['security-uncensored'],
    params: '27B', size: '16.8 GB', family: 'qwen',
    description: 'Portable sibling of the MLX security candidate. Prefer Q6_K or Q8_0 when memory permits. Security benchmark results for this exact build remain unverified.',
    note: 'Sandbox required for assessment. A popular publisher and a GGUF file are not a malware-free guarantee.',
    capabilities: ['chat', 'code', 'reasoning', 'tools'], context: 262144,
    ollama: 'hf.co/orcarouter/Qwen3.8-27B-Uncensored-GGUF:Q4_K_M',
    lmstudio: 'orcarouter/Qwen3.8-27B-Uncensored-GGUF@Q4_K_M',
  },

  // ── Small & fast tier ──
  // Sub-4B models for classification, routing, and the voice agent's tool turns,
  // where round-trip latency matters more than prose quality.
  {
    key: 'functiongemma-270m',
    name: 'FunctionGemma 270M',
    category: 'lightweight',
    recommendedFor: ['lightweight'],
    params: '270M',
    size: '301 MB',
    family: 'gemma',
    description: "Google's Gemma 3 270M fine-tuned purely for function calling — the smallest model here that still drives tools reliably.",
    capabilities: ['chat', 'tools'],
    context: 32768,
    ollama: 'functiongemma:270m',
    lmstudio: 'lmstudio-community/functiongemma-270m-it-GGUF'
  },
  {
    key: 'gemma-3-270m-it',
    name: 'Gemma 3 270M IT',
    category: 'lightweight',
    recommendedFor: ['lightweight'],
    params: '270M',
    size: '253 MB',
    family: 'gemma',
    description: 'Tiny instruction model for cheap classification, routing, and quick local utilities.',
    capabilities: ['chat', 'classification'],
    ollama: 'hf.co/lmstudio-community/gemma-3-270m-it-GGUF:Q4_K_M',
    lmstudio: 'lmstudio-community/gemma-3-270m-it-GGUF'
  },
  {
    key: 'lfm2.5-thinking-1.2b',
    name: 'LFM2.5 Thinking 1.2B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'reasoning'],
    params: '1.2B',
    size: '731 MB',
    family: 'lfm2',
    description: "Liquid AI's on-device hybrid model — reasoning and tool calling in well under a gigabyte, with a ~125K context.",
    capabilities: ['chat', 'reasoning', 'tools'],
    ollama: 'lfm2.5-thinking:1.2b',
    lmstudio: 'lmstudio-community/LFM2.5-1.2B-Thinking-GGUF'
  },
  {
    key: 'qwen2.5-7b-instruct',
    name: 'Qwen2.5 7B Instruct',
    category: 'general',
    recommendedFor: ['chat', 'general', 'lightweight'],
    featured: {
      label: 'Grok-box Persistent Mind',
      description: 'Default free local mind on CPU-only / ~16 GB hosts: tool-capable instruct build via Ollama. Keep Cursor / OpenCode Zen for coding.'
    },
    params: '7B',
    size: '4.7 GB',
    family: 'qwen',
    description: 'Qwen2.5 7B Instruct (Q4) — the default free Persistent Mind on Grok Bot boxes and other CPU-only / no-GPU hosts. Tool-capable; pair with cloud CLIs for coding tasks.',
    capabilities: ['chat', 'tools', 'multilingual'],
    context: 131072,
    ollama: 'qwen2.5:7b-instruct',
    lmstudio: 'lmstudio-community/Qwen2.5-7B-Instruct-GGUF'
  },
  {
    key: 'qwen2.5-3b',
    name: 'Qwen2.5 3B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'chat', 'multilingual'],
    params: '3B',
    size: '2.0 GB',
    family: 'qwen',
    description: 'Compact Qwen2.5 instruct model with solid tool use and no "thinking" delay — a fast, low-memory tool-calling brain for the voice agent.',
    capabilities: ['chat', 'tools', 'multilingual'],
    // hf.co/…-Instruct id (like the other 2507/instruct cards) so the model id
    // reported by the backend carries the "instruct" token the voice
    // tool-capability detector keys on — a bare `qwen2.5:3b` tag would not.
    ollama: 'hf.co/lmstudio-community/Qwen2.5-3B-Instruct-GGUF:Q4_K_M',
    lmstudio: 'lmstudio-community/Qwen2.5-3B-Instruct-GGUF'
  },
  {
    key: 'granite4.2-3b',
    name: 'Granite 4.2 3B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'reasoning'],
    params: '3B',
    size: '2.2 GB',
    family: 'granite',
    description: "Apache-licensed IBM Granite 4.2 — small, tool-capable, with thinking mode, tuned for tight instruction-following rather than chat flourish.",
    capabilities: ['chat', 'tools', 'reasoning'],
    context: 131072,
    ollama: 'granite4.2:3b',
    lmstudio: 'lmstudio-community/granite-4.2-3b-GGUF'
  },
  {
    key: 'nemotron-3-nano-4b',
    name: 'Nemotron 3 Nano 4B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'reasoning'],
    params: '4B',
    size: '2.8 GB',
    family: 'nemotron',
    description: "NVIDIA's efficient agentic model — reasoning and tool calling at 4B with a 256K context.",
    capabilities: ['chat', 'reasoning', 'tools'],
    context: 262144,
    ollama: 'nemotron-3-nano:4b',
    lmstudio: 'lmstudio-community/NVIDIA-Nemotron-3-Nano-4B-GGUF'
  },
  {
    key: 'qwen3.5-4b',
    name: 'Qwen3.5 4B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'general', 'vision', 'multilingual'],
    params: '4B',
    size: '3.4 GB',
    family: 'qwen',
    description: 'Compact current-generation Qwen with vision, tools, and a 256K context — a lot of capability per gigabyte.',
    capabilities: ['chat', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'qwen3.5:4b',
    lmstudio: 'lmstudio-community/Qwen3.5-4B-GGUF'
  },
  {
    key: 'phi-4-mini',
    name: 'Phi-4 Mini 3.8B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'reasoning', 'chat'],
    params: '3.8B',
    size: '2.4 GB',
    family: 'phi',
    description: "Microsoft's lightweight 3.8B model with 128K context, strong reasoning, multilingual support, and function calling.",
    capabilities: ['chat', 'reasoning', 'tools', 'multilingual'],
    context: 131072,
    ollama: 'phi4-mini',
    lmstudio: 'lmstudio-community/Phi-4-mini-instruct-GGUF'
  },
  {
    key: 'gemma3-4b-it',
    name: 'Gemma 3 4B IT',
    category: 'general',
    recommendedFor: ['general', 'vision', 'lightweight'],
    params: '4B',
    size: '3.3 GB',
    family: 'gemma',
    description: "Google's lightweight multimodal Gemma 3 4B instruction model with vision capabilities and a 128K context window.",
    repository: 'google/gemma-3-4b-it',
    gated: true,
    capabilities: ['chat', 'vision'],
    context: 131072,
    ollama: 'gemma3:4b',
    lmstudio: 'lmstudio-community/gemma-3-4b-it-GGUF'
  },
  {
    key: 'gemma4-e4b',
    name: 'Gemma 4 E4B',
    category: 'lightweight',
    recommendedFor: ['lightweight', 'general', 'vision', 'reasoning'],
    params: 'E4B',
    size: '6.6 GB',
    family: 'gemma',
    description: "Google's edge multimodal Gemma 4 (4.5B effective params) — on-device reasoning with thinking mode, tools, vision, and a 128K context window.",
    capabilities: ['chat', 'reasoning', 'tools', 'vision'],
    context: 131072,
    ollama: 'gemma4:e4b',
    lmstudio: 'lmstudio-community/gemma-4-E4B-it-GGUF'
  },
  // ── General-purpose laptop tier (16–32GB) ──
  {
    key: 'lfm2.5-8b-a1b',
    name: 'LFM2.5 8B-A1B',
    category: 'general',
    recommendedFor: ['general', 'chat', 'reasoning'],
    params: '8B / 1B active',
    size: '5.2 GB',
    family: 'lfm2',
    description: "Liquid AI's edge MoE (1B active) built for fast, reliable tool calling on consumer hardware — 8B quality at roughly 1B speed.",
    capabilities: ['chat', 'reasoning', 'tools'],
    ollama: 'lfm2.5:8b',
    lmstudio: 'LiquidAI/LFM2.5-8B-A1B-GGUF'
  },
  {
    key: 'hermes-3-llama-3.1-8b',
    name: 'Hermes 3 8B',
    category: 'chat',
    recommendedFor: ['chat'],
    params: '8B',
    size: '4.9 GB',
    family: 'hermes',
    description: 'NousResearch Hermes 3 (Llama 3.1 8B) — tuned for reliable function-calling and structured tool use, with no "thinking" delay. A robust pick for the voice agent\'s tool turns.',
    capabilities: ['chat', 'tools'],
    ollama: 'hermes3',
    lmstudio: 'NousResearch/Hermes-3-Llama-3.1-8B-GGUF'
  },
  {
    key: 'granite4.2-8b',
    name: 'Granite 4.2 8B',
    category: 'general',
    recommendedFor: ['general', 'reasoning', 'multilingual'],
    params: '8B',
    size: '5.3 GB',
    family: 'granite',
    description: 'Apache-licensed IBM Granite 4.2 instruct model with a 128K context, thinking mode, RAG, and tool use — clean, constrained output for structured and editorial work.',
    capabilities: ['chat', 'tools', 'reasoning', 'multilingual'],
    context: 131072,
    ollama: 'granite4.2:8b',
    lmstudio: 'lmstudio-community/granite-4.2-8b-GGUF'
  },
  {
    key: 'ministral-3-8b',
    name: 'Ministral 3 8B Instruct',
    category: 'general',
    recommendedFor: ['general', 'vision', 'multilingual'],
    params: '8B',
    size: '6.0 GB',
    family: 'ministral',
    description: "Mistral's edge instruct model — vision, tools, and a 256K context, with no thinking phase to wait through. (A separate Ministral 3 Reasoning build exists if you want one.)",
    capabilities: ['chat', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'ministral-3:8b',
    lmstudio: 'lmstudio-community/Ministral-3-8B-Instruct-2512-GGUF'
  },
  {
    key: 'qwen3.5-9b',
    name: 'Qwen3.5 9B',
    category: 'general',
    recommendedFor: ['general', 'vision', 'multilingual'],
    params: '9B',
    size: '6.6 GB',
    family: 'qwen',
    description: "Alibaba's current multimodal all-rounder — strong multilingual coverage, vision, tools, and a 256K context. A solid general default.",
    capabilities: ['chat', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'qwen3.5:9b',
    lmstudio: 'lmstudio-community/Qwen3.5-9B-GGUF'
  },
  {
    key: 'gemma4-12b',
    name: 'Gemma 4 12B',
    category: 'general',
    recommendedFor: ['general', 'vision'],
    params: '12B',
    size: '7.6 GB',
    family: 'gemma',
    description: "Google's mid-size Gemma 4 with vision, tools, and a 256K context — frontier-ish quality that still fits a 16GB machine.",
    capabilities: ['chat', 'tools', 'vision'],
    context: 262144,
    ollama: 'gemma4:12b',
    lmstudio: 'lmstudio-community/gemma-4-12B-it-GGUF'
  },
  {
    key: 'ministral-3-14b',
    name: 'Ministral 3 14B Instruct',
    category: 'general',
    recommendedFor: ['general', 'reasoning', 'vision'],
    params: '14B',
    size: '9.1 GB',
    family: 'ministral',
    description: 'The largest Ministral 3 — more headroom for reasoning and general work while staying laptop-friendly.',
    capabilities: ['chat', 'reasoning', 'tools', 'vision'],
    context: 262144,
    ollama: 'ministral-3:14b',
    lmstudio: 'lmstudio-community/Ministral-3-14B-Instruct-2512-GGUF'
  },
  {
    key: 'mistral-small-24b',
    name: 'Mistral Small 3.2 24B',
    category: 'general',
    recommendedFor: ['general', 'coding', 'vision', 'multilingual'],
    params: '24B',
    size: '15 GB',
    family: 'mistral',
    description: 'Mistral AI\'s 24B instruct model with vision support, tools, and a 128K context window — strong for local agents, coding, and multi-file tasks.',
    capabilities: ['chat', 'code', 'tools', 'vision', 'multilingual'],
    context: 131072,
    ollama: 'mistral-small:24b',
    lmstudio: 'lmstudio-community/Mistral-Small-3.2-24B-Instruct-2506-GGUF'
  },
  {
    key: 'gpt-oss-20b',
    benchmarkModel: 'gpt-oss-20b',
    name: 'GPT-OSS 20B',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '20B',
    size: '12 GB',
    family: 'gpt-oss',
    description: 'Open-weights 20B model — the default local thinking model.',
    capabilities: ['chat', 'reasoning', 'tools'],
    ollama: 'gpt-oss:20b',
    lmstudio: 'lmstudio-community/gpt-oss-20b-GGUF'
  },
  {
    key: 'magistral-small-24b',
    name: 'Magistral Small 24B',
    category: 'reasoning',
    recommendedFor: ['reasoning', 'multilingual'],
    params: '24B',
    size: '14 GB',
    family: 'magistral',
    description: "Mistral AI's open-weights reasoning model with explicit thinking mode, tools, and strong multilingual capabilities for complex multi-step reasoning.",
    repository: 'mistralai/Magistral-Small-2509',
    capabilities: ['chat', 'reasoning', 'tools', 'multilingual'],
    context: 40960,
    ollama: 'magistral:24b',
    lmstudio: 'lmstudio-community/Magistral-Small-2509-GGUF'
  },
  {
    key: 'gemma3-27b-it',
    name: 'Gemma 3 27B IT',
    category: 'general',
    recommendedFor: ['general', 'reasoning'],
    params: '27B',
    size: '17 GB',
    family: 'gemma',
    description: "Google's Gemma 3 27B instruction model — long-context local analysis for code-review findings without native tool calling.",
    note: 'Long-context local analysis option; Hugging Face’s official Gemma repository requires accepting its terms.',
    repository: 'google/gemma-3-27b-it',
    gated: true,
    capabilities: ['chat', 'vision'],
    context: 131072,
    ollama: 'gemma3:27b',
    lmstudio: 'lmstudio-community/gemma-3-27b-it-GGUF'
  },
  // ── Large general-purpose / long-context tier (32–128GB unified memory) ──
  // Best suited for whole-manuscript editorial review, where prose quality and a
  // long context window matter most. To actually fit the manuscript, raise Ollama's
  // context window (OLLAMA_CONTEXT_LENGTH) — the default 4K window silently truncates.
  {
    key: 'qwen3.8-27b-mlx-4bit',
    name: 'Qwen3.8 27B MLX 4-bit',
    category: 'general',
    recommendedFor: ['general', 'coding', 'reasoning', 'vision', 'multilingual'],
    featured: {
      label: 'Fast on Apple Silicon',
      description: 'Full image-analysis score in the local audit and the faster direct Qwen3.8 decoder fallback; MTPLX completed the end-to-end TUI task sooner.'
    },
    params: '27B',
    size: '15.0 GB',
    family: 'qwen',
    description: 'MLX Community’s current 4-bit Qwen3.8 27B build — a native Apple-Silicon format with long context, coding, reasoning, tools, vision, thinking, and multilingual support.',
    capabilities: ['chat', 'code', 'reasoning', 'tools', 'vision', 'multilingual'],
    context: 262144,
    format: 'mlx',
    appleSiliconOnly: true,
    ollama: 'qwen3.8:27b-mlx',
    lmstudio: 'mlx-community/Qwen3.8-27B-4bit',
    lmstudioAliases: ['lmstudio-community/Qwen3.8-27B-MLX-4bit']
  },
  {
    key: 'qwen3.8-27b-uncensored-mlx',
    name: 'Qwen3.8 27B Uncensored MLX',
    category: 'security-uncensored',
    recommendedFor: ['security-uncensored'],
    featured: { label: 'Security candidate', description: 'Practical local candidate for private assessment and remediation planning. CyberGym, ExploitBench and ExploitGym: no verified results for this exact abliterated build.' },
    params: '27B',
    size: '16.1 GB',
    family: 'qwen',
    description: 'OrcaRouter’s abliterated Qwen3.8 variant for red-team and unrestricted local evaluation, with 2-, 4-, 6-, and 8-bit MLX builds plus vision, tools, reasoning, and multilingual support.',
    note: 'Ollama imports 4-bit; LM Studio loads the root 4-bit build. Prefer 4-bit or higher; 2-bit is unsuitable for assessment. Sandbox required; benchmark quality remains unverified.',
    repository: 'orcarouter/Qwen3.8-27B-Uncensored-MLX',
    gated: false,
    capabilities: ['chat', 'code', 'reasoning', 'tools', 'vision', 'multilingual'],
    context: 262144,
    format: 'mlx',
    appleSiliconOnly: true,
    ollama: 'orcarouter/qwen3.8-27b-uncensored-mlx:4bit',
    ollamaImport: {
      repo: 'orcarouter/Qwen3.8-27B-Uncensored-MLX',
      subdir: '4-bit',
      minVersion: '0.19.0'
    },
    lmstudio: 'https://huggingface.co/orcarouter/Qwen3.8-27B-Uncensored-MLX',
    lmstudioAliases: ['orcarouter/Qwen3.8-27B-Uncensored-MLX']
  },
  {
    key: 'qwen3.8-27b',
    name: 'Qwen3.8 27B',
    category: 'general',
    recommendedFor: ['general', 'coding', 'reasoning', 'vision', 'multilingual'],
    featured: {
      label: 'Best Qwen3.8 path',
      description: 'For Qwen3.8 CoS tasks, use MTPLX + OpenCode MTPLX TUI; use native MLX when isolated decoder throughput or vision is the priority.'
    },
    params: '27B',
    size: '16.5 GB',
    family: 'qwen',
    description: 'Dense current-generation Qwen with a 256K context, strong coding and agent work, vision, tools, multilingual support, and a thinking mode — the strongest all-round local model that still fits 32GB. Unsloth Dynamic 3.0 GGUF: higher fidelity at the same size than earlier Unsloth quants.',
    note: 'Dynamic 3.0 is baked into the GGUF files — re-download if you already have an older Unsloth Qwen3.8 build. Native MLX Dynamic 3.0 is not available yet.',
    repository: 'unsloth/Qwen3.8-27B-GGUF',
    capabilities: ['chat', 'code', 'reasoning', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'hf.co/unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_M',
    ollamaAliases: ['hf.co/unsloth/Qwen3.8-27B-GGUF:Q4_K_M'],
    lmstudio: 'unsloth/Qwen3.8-27B-GGUF'
  },
  {
    key: 'qwen3.6-27b',
    name: 'Qwen3.6 27B',
    category: 'general',
    recommendedFor: ['general', 'coding', 'reasoning', 'vision', 'multilingual'],
    params: '27B',
    size: '18 GB',
    family: 'qwen',
    description: "Alibaba's dense 27B multimodal model with native vision, tools, thinking preservation, and a 262K context window — strong general, coding, and reasoning capability.",
    repository: 'Qwen/Qwen3.6-27B',
    capabilities: ['chat', 'code', 'reasoning', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'qwen3.6:27b',
    lmstudio: 'lmstudio-community/Qwen3.6-27B-GGUF'
  },
  {
    key: 'gemma4-26b-a4b',
    name: 'Gemma 4 26B-A4B',
    category: 'general',
    recommendedFor: ['general', 'vision'],
    params: '26B / 4B active',
    size: '18 GB',
    family: 'gemma',
    description: "Google's MoE (4B active) with a 256K context window and vision — a fast long-context option for one-shot whole-manuscript review. MLX build on Apple Silicon: gemma4:26b-mlx.",
    capabilities: ['chat', 'tools', 'vision'],
    context: 262144,
    ollama: 'gemma4:26b',
    lmstudio: 'lmstudio-community/gemma-4-26B-A4B-it-GGUF'
  },
  {
    key: 'muse-glimmer-30b',
    name: 'Muse Glimmer 30B',
    category: 'general',
    recommendedFor: ['general', 'reasoning', 'vision'],
    params: '30B',
    size: '18 GB',
    family: 'muse-glimmer',
    description: "Meta's Apache-2.0 open model for always-on local agents — vision, tools, and thinking, tuned for long tasks and failure recovery. Runs on a single GPU.",
    capabilities: ['chat', 'reasoning', 'tools', 'vision'],
    context: 131072,
    ollama: 'muse-glimmer:30b',
    lmstudio: 'lmstudio-community/Muse-Glimmer-30B-GGUF'
  },
  {
    key: 'glm-4.7-flash',
    name: 'GLM-4.7 Flash',
    category: 'general',
    recommendedFor: ['general', 'reasoning'],
    params: '30B class',
    size: '19 GB',
    family: 'glm',
    description: 'Z.ai\'s strongest model in the 30B class — reasoning plus tools with a ~198K context, balanced for lightweight local deployment.',
    capabilities: ['chat', 'reasoning', 'tools'],
    ollama: 'glm-4.7-flash',
    lmstudio: 'lmstudio-community/GLM-4.7-Flash-GGUF'
  },
  {
    key: 'olmo-3.1-32b',
    name: 'Olmo 3.1 32B Instruct',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '32B',
    size: '20 GB',
    family: 'olmo',
    description: "AI2's fully-open model — weights, data, and training recipe all published. Reasoning and tools with a 64K context; the sibling `olmo-3.1:32b-think` trades latency for depth.",
    capabilities: ['chat', 'reasoning', 'tools'],
    context: 65536,
    ollama: 'olmo-3.1:32b-instruct',
    lmstudio: 'lmstudio-community/Olmo-3.1-32B-Instruct-GGUF'
  },
  {
    key: 'deepseek-r1-8b',
    name: 'DeepSeek-R1 8B',
    category: 'reasoning',
    recommendedFor: ['reasoning', 'lightweight'],
    params: '8B',
    size: '4.9 GB',
    family: 'deepseek',
    description: "DeepSeek's open reasoning model distilled into an 8B Llama architecture — explicit chain-of-thought thinking for math, logic, and complex reasoning.",
    capabilities: ['chat', 'reasoning'],
    ollama: 'deepseek-r1:8b',
    lmstudio: 'lmstudio-community/DeepSeek-R1-Distill-Llama-8B-GGUF'
  },
  {
    key: 'deepseek-r1-14b',
    name: 'DeepSeek-R1 14B',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '14B',
    size: '9.0 GB',
    family: 'deepseek',
    description: "DeepSeek's open reasoning model distilled into a 14B Qwen architecture — deeper chain-of-thought thinking for math, logic, and complex problem-solving.",
    capabilities: ['chat', 'reasoning'],
    context: 131072,
    ollama: 'deepseek-r1:14b',
    lmstudio: 'lmstudio-community/DeepSeek-R1-Distill-Qwen-14B-GGUF'
  },
  {
    key: 'deepseek-r1-32b',
    name: 'DeepSeek-R1 32B',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '32B',
    size: '20 GB',
    family: 'deepseek',
    description: "DeepSeek's open reasoning model distilled into a 32B Qwen architecture — advanced chain-of-thought thinking for math, logic, and complex problem-solving.",
    capabilities: ['chat', 'reasoning'],
    context: 131072,
    ollama: 'deepseek-r1:32b',
    lmstudio: 'lmstudio-community/DeepSeek-R1-Distill-Qwen-32B-GGUF'
  },
  {
    key: 'deepseek-r1-70b',
    name: 'DeepSeek-R1 70B',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '70B',
    size: '43 GB',
    family: 'deepseek',
    description: "DeepSeek's open reasoning model distilled into a 70B Llama architecture — flagship chain-of-thought reasoning for high-memory workstations.",
    capabilities: ['chat', 'reasoning'],
    context: 131072,
    ollama: 'deepseek-r1:70b',
    lmstudio: 'lmstudio-community/DeepSeek-R1-Distill-Llama-70B-GGUF'
  },
  {
    key: 'phi-4-14b',
    name: 'Phi-4 14B',
    category: 'reasoning',
    recommendedFor: ['reasoning', 'general'],
    params: '14B',
    size: '9.1 GB',
    family: 'phi',
    description: "Microsoft's 14B open model with strong reasoning, math, and synthetic data quality — fits easily on 16GB machines.",
    capabilities: ['chat', 'reasoning', 'tools'],
    context: 16384,
    ollama: 'phi4',
    lmstudio: 'lmstudio-community/phi-4-GGUF'
  },
  {
    key: 'phi-4-reasoning-14b',
    name: 'Phi-4 Reasoning 14B',
    category: 'reasoning',
    recommendedFor: ['reasoning'],
    params: '14B',
    size: '11 GB',
    family: 'phi',
    description: "Microsoft's 14B open-weight reasoning model — specialized chain-of-thought thinking for complex math, logic, and multi-step reasoning.",
    capabilities: ['chat', 'reasoning'],
    context: 32768,
    ollama: 'phi4-reasoning:14b',
    lmstudio: 'lmstudio-community/Phi-4-reasoning-GGUF'
  },
  {
    key: 'gemma4-31b',
    name: 'Gemma 4 31B',
    category: 'general',
    recommendedFor: ['general', 'vision'],
    params: '31B',
    size: '20 GB',
    family: 'gemma',
    description: "Google's dense 31B with a 256K context window and vision — a strong long-context narrative editor that fits comfortably on 64GB+. MLX build on Apple Silicon: gemma4:31b-mlx.",
    capabilities: ['chat', 'tools', 'vision'],
    context: 262144,
    ollama: 'gemma4:31b',
    lmstudio: 'lmstudio-community/gemma-4-31B-it-GGUF'
  },
  {
    key: 'nemotron-3.5-lightning',
    name: 'Nemotron 3.5 Lightning 30B-A3B',
    category: 'reasoning',
    recommendedFor: ['reasoning', 'coding'],
    params: '30B / 3B active',
    size: '25 GB',
    family: 'nemotron',
    description: "NVIDIA's hybrid Mamba-Transformer agentic MoE with a 1M-token context — ultra-fast long-context reasoning, coding, and tool calling with only 3B active parameters.",
    repository: 'nvidia/Nemotron-3.5-Lightning-30B-A3B',
    capabilities: ['chat', 'reasoning', 'code', 'tools'],
    context: 1048576,
    ollama: 'nemotron-3.5-lightning:30b',
    lmstudio: 'lmstudio-community/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-GGUF'
  },
  {
    key: 'llama3.3-70b',
    name: 'Llama 3.3 70B',
    category: 'general',
    recommendedFor: ['general', 'reasoning', 'multilingual'],
    params: '70B',
    size: '43 GB',
    family: 'llama',
    description: "Meta's flagship 70B model with a 128K context window — offers performance comparable to Llama 3.1 405B for high-memory machines.",
    capabilities: ['chat', 'tools', 'multilingual'],
    context: 131072,
    ollama: 'llama3.3',
    ollamaAliases: ['llama3.3:70b'],
    lmstudio: 'lmstudio-community/Llama-3.3-70B-Instruct-GGUF'
  },
  {
    key: 'llama4-scout-17b',
    name: 'Llama 4 Scout 17B',
    category: 'general',
    recommendedFor: ['general', 'vision', 'multilingual'],
    params: '17B / MoE 16E',
    size: '11.2 GB',
    family: 'llama',
    description: "Meta's natively multimodal Llama 4 Scout — 17B active MoE architecture with vision, tools, multilingual support, and long-context capabilities.",
    capabilities: ['chat', 'tools', 'vision', 'multilingual'],
    context: 131072,
    ollama: 'llama4:scout',
    lmstudio: 'lmstudio-community/Llama-4-Scout-17B-16E-Instruct-GGUF'
  },
  {
    key: 'qwen3.5-122b-a10b',
    name: 'Qwen3.5 122B-A10B',
    category: 'general',
    recommendedFor: ['general', 'reasoning', 'vision', 'multilingual'],
    params: '122B / 10B active',
    size: '81 GB',
    family: 'qwen',
    description: 'The largest locally-runnable Qwen3.5 — frontier-class prose with a 256K context and only 10B active parameters. Needs ~96GB+ unified memory.',
    capabilities: ['chat', 'reasoning', 'tools', 'vision', 'multilingual'],
    context: 262144,
    ollama: 'qwen3.5:122b',
    lmstudio: 'lmstudio-community/Qwen3.5-122B-A10B-GGUF'
  },
  // ── Coding / agentic tier ──
  {
    key: 'qwen3-coder-30b',
    benchmarkModel: 'qwen3-coder-30b-a3b-instruct',
    name: 'Qwen3-Coder 30B',
    category: 'coding',
    recommendedFor: ['coding', 'general'],
    featured: {
      label: 'Best coding agent',
      description: 'Measured local CoS pick: Ollama + OpenCode TUI. Confirm the local performance record before changing the default on another machine.'
    },
    params: '30B / 3.3B active',
    size: '19 GB',
    family: 'qwen',
    description: 'Qwen\'s agentic coding model for repository work, tool calling, and multi-step software-engineering tasks. The audit made this the primary coding/TUI recommendation on the current Apple Silicon profile.',
    capabilities: ['chat', 'code', 'tools'],
    context: 262144,
    repository: 'Qwen/Qwen3-Coder-30B-A3B-Instruct',
    ollama: 'qwen3-coder:30b',
    lmstudio: 'lmstudio-community/Qwen3-Coder-30B-A3B-Instruct-GGUF'
  },
  {
    key: 'qwen2.5-coder-7b',
    benchmarkModel: 'qwen2.5-coder-instruct-7b',
    name: 'Qwen2.5-Coder 7B',
    category: 'coding',
    recommendedFor: ['coding'],
    params: '7B',
    size: '4.7 GB',
    family: 'qwen',
    description: "Alibaba's 7B open coding model — excellent code generation, multi-file editing, and tool use for 8–16GB laptops.",
    capabilities: ['chat', 'code', 'tools'],
    context: 131072,
    ollama: 'qwen2.5-coder:7b',
    lmstudio: 'lmstudio-community/Qwen2.5-Coder-7B-Instruct-GGUF'
  },
  {
    key: 'qwen2.5-coder-14b',
    name: 'Qwen2.5-Coder 14B',
    category: 'coding',
    recommendedFor: ['coding', 'reasoning'],
    params: '14B',
    size: '9.0 GB',
    family: 'qwen',
    description: "Alibaba's 14B open coding model — high-quality code generation, debugging, and multi-file context handling for 16GB+ hardware.",
    capabilities: ['chat', 'code', 'tools'],
    context: 131072,
    ollama: 'qwen2.5-coder:14b',
    lmstudio: 'lmstudio-community/Qwen2.5-Coder-14B-Instruct-GGUF'
  },
  {
    key: 'qwen2.5-coder-32b',
    benchmarkModel: 'qwen2.5-coder-instruct-32b',
    name: 'Qwen2.5-Coder 32B',
    category: 'coding',
    recommendedFor: ['coding', 'reasoning'],
    params: '32B',
    size: '20 GB',
    family: 'qwen',
    description: "Alibaba's 32B open coding model — state-of-the-art code generation, repository-level editing, and agentic tool use for 32GB+ hardware.",
    capabilities: ['chat', 'code', 'tools'],
    context: 131072,
    ollama: 'qwen2.5-coder:32b',
    lmstudio: 'lmstudio-community/Qwen2.5-Coder-32B-Instruct-GGUF'
  },
  {
    key: 'codestral-22b',
    name: 'Codestral 22B',
    category: 'coding',
    recommendedFor: ['coding'],
    params: '22B',
    size: '13 GB',
    family: 'codestral',
    description: "Mistral AI's 22B code model supporting over 80 programming languages, tuned for code completion and generation.",
    capabilities: ['chat', 'code', 'tools'],
    context: 32768,
    ollama: 'codestral',
    lmstudio: 'lmstudio-community/Codestral-22B-v0.1-GGUF'
  },
  {
    key: 'ornith-9b',
    benchmarkModel: 'ornith-1.0-9b',
    name: 'Ornith 1.0 9B',
    category: 'coding',
    recommendedFor: ['coding'],
    params: '9B',
    size: '5.6 GB',
    family: 'ornith',
    description: 'Self-improving open model family for agentic coding — the 9B fits a laptop while still driving tools over a 256K context.',
    capabilities: ['chat', 'code', 'tools'],
    context: 262144,
    ollama: 'ornith:9b',
    lmstudio: 'lmstudio-community/Ornith-1.0-9B-GGUF'
  },
  {
    key: 'devstral-small-2-24b',
    benchmarkModel: 'devstral-small-2-24b',
    name: 'Devstral Small 2 24B',
    category: 'coding',
    recommendedFor: ['coding', 'vision'],
    params: '24B',
    size: '15 GB',
    family: 'devstral',
    description: 'Mistral\'s agentic coding model for repo navigation, multi-file edits, and software-engineering agents — vision and a ~384K context.',
    capabilities: ['chat', 'code', 'tools', 'vision'],
    ollama: 'devstral-small-2:24b',
    lmstudio: 'unsloth/Devstral-Small-2-24B-Instruct-2512-GGUF'
  },
  {
    key: 'north-mini-code-1.0',
    benchmarkModel: 'north-mini-code-1.0',
    name: 'North Mini Code 1.0 30B-A3B',
    category: 'coding',
    recommendedFor: ['coding', 'reasoning'],
    params: '30B / 3B active',
    size: '19 GB',
    family: 'north-mini-code',
    description: "Cohere's first developer model — a 30B MoE (3B active) for agentic software engineering, with a ~488K context for whole-repo work.",
    capabilities: ['chat', 'code', 'reasoning', 'tools'],
    ollama: 'north-mini-code-1.0',
    lmstudio: 'unsloth/North-Mini-Code-1.0-GGUF'
  },
  {
    key: 'ornith-35b',
    benchmarkModel: 'ornith-1.0-35b',
    name: 'Ornith 1.0 35B',
    category: 'coding',
    recommendedFor: ['coding'],
    params: '35B',
    size: '21 GB',
    family: 'ornith',
    description: 'The larger Ornith for agentic coding — more headroom on long-horizon repo tasks, still a 256K context.',
    capabilities: ['chat', 'code', 'tools'],
    context: 262144,
    ollama: 'ornith:35b',
    lmstudio: 'lmstudio-community/Ornith-1.0-35B-GGUF'
  },
  {
    key: 'qwen3.6-35b-a3b',
    benchmarkModel: 'qwen3.6-35b-a3b',
    name: 'Qwen3.6 35B-A3B',
    category: 'coding',
    recommendedFor: ['coding', 'vision'],
    params: '35B / 3B active',
    size: '24 GB',
    family: 'qwen',
    description: 'Current Qwen coding MoE with agentic coding, repository reasoning, vision, and tool-use upgrades over Qwen3.5.',
    capabilities: ['chat', 'code', 'tools', 'vision'],
    context: 262144,
    ollama: 'qwen3.6:35b',
    lmstudio: 'unsloth/Qwen3.6-35B-A3B-GGUF'
  },
  // ── Fiction / writing tier ──
  {
    key: 'qwen3.6-fable-fusion',
    name: 'Qwen3.6 Fable Fusion 27B',
    category: 'writing',
    recommendedFor: ['writing', 'general'],
    featured: {
      label: 'Best fiction candidate',
      description: 'Best fiction-specialist result in the local audit. The screen is structural, not an aesthetic judgment—read the saved prose.'
    },
    params: '27B',
    size: '31 GB',
    family: 'qwen',
    description: 'A Qwen3.6 Fable Fusion checkpoint for fiction drafting and narrative voice experiments. Keep a general or coding model selected for agentic repository work.',
    capabilities: ['chat', 'reasoning'],
    context: 262144,
    repository: 'DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF',
    ollama: 'hf.co/DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF:Q8_0'
  },
  // ── Vision / image analysis tier ──
  {
    key: 'minicpm-v4.6',
    name: 'MiniCPM-V 4.6 (vision)',
    category: 'vision',
    recommendedFor: ['vision'],
    params: '1B',
    size: '1.6 GB',
    family: 'minicpm',
    description: 'Pocket-sized multimodal model for image and video understanding — the cheapest way to caption a large dataset locally.',
    capabilities: ['chat', 'vision'],
    context: 262144,
    ollama: 'minicpm-v4.6:1b',
    lmstudio: 'openbmb/MiniCPM-V-4_6-gguf'
  },
  {
    key: 'qwen3-vl-2b',
    name: 'Qwen3-VL 2B (vision)',
    category: 'vision',
    recommendedFor: ['vision'],
    params: '2B',
    size: '1.9 GB',
    family: 'qwen',
    description: 'Tiny Qwen3-VL for quick captions on modest hardware, with the same 256K context as its larger siblings.',
    capabilities: ['chat', 'vision'],
    context: 262144,
    ollama: 'qwen3-vl:2b',
    lmstudio: 'lmstudio-community/Qwen3-VL-2B-Instruct-GGUF'
  },
  {
    key: 'qwen3-vl-8b',
    name: 'Qwen3-VL 8B (vision)',
    category: 'vision',
    recommendedFor: ['vision'],
    params: '8B',
    size: '6.1 GB',
    family: 'qwen',
    description: 'The most capable vision-language model in the Qwen family at a laptop-friendly size — the recommended default for LoRA dataset captioning.',
    capabilities: ['chat', 'tools', 'vision'],
    context: 262144,
    ollama: 'qwen3-vl:8b',
    lmstudio: 'lmstudio-community/Qwen3-VL-8B-Instruct-GGUF'
  },
  {
    key: 'glm-4.6v-flash',
    name: 'GLM-4.6V Flash',
    category: 'vision',
    recommendedFor: ['vision'],
    params: 'Vision',
    size: '7.1 GB',
    family: 'glm',
    description: 'MLX vision-language model for image analysis on Apple Silicon.',
    capabilities: ['chat', 'vision'],
    lmstudio: 'lmstudio-community/GLM-4.6V-Flash-MLX-4bit'
  },
  {
    key: 'qwen3-vl-30b-a3b',
    name: 'Qwen3-VL 30B-A3B (vision)',
    category: 'vision',
    recommendedFor: ['vision'],
    params: '30B / 3B active',
    size: '20 GB',
    family: 'qwen',
    description: 'Larger Qwen3-VL MoE for the most detailed image captions — best on high-memory machines, and only 3B active so it stays responsive.',
    capabilities: ['chat', 'tools', 'vision'],
    context: 262144,
    ollama: 'qwen3-vl:30b',
    lmstudio: 'lmstudio-community/Qwen3-VL-30B-A3B-Instruct-GGUF'
  },
  {
    key: 'nemotron-3.5-bolt',
    name: 'Nemotron 3.5 Bolt 74B-A9B',
    category: 'vision',
    recommendedFor: ['vision', 'reasoning', 'coding'],
    params: '74B / 9B active',
    size: '24 GB',
    family: 'nemotron',
    description: "NVIDIA's hybrid Mamba-2/Transformer vision-language MoE — multimodal reasoning, coding, and tool calling with 9B active parameters, compressed into a 24GB footprint for local execution.",
    repository: 'nvidia/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-24GB-GGUF',
    capabilities: ['chat', 'reasoning', 'code', 'tools', 'vision'],
    context: 262144,
    ollama: 'nemotron-3.5-bolt',
    lmstudio: 'lmstudio-community/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-GGUF',
    lmstudioAliases: ['nvidia/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-24GB-GGUF']
  },
  {
    key: 'llama3.2-vision-11b',
    name: 'Llama 3.2 Vision 11B',
    category: 'vision',
    recommendedFor: ['vision', 'general'],
    params: '11B',
    size: '7.9 GB',
    family: 'llama',
    description: "Meta's instruction-tuned multimodal model with vision capabilities for image reasoning and captioning.",
    capabilities: ['chat', 'tools', 'vision'],
    context: 128000,
    ollama: 'llama3.2-vision:11b',
    lmstudio: 'lmstudio-community/Llama-3.2-11B-Vision-Instruct-GGUF'
  },
  // ── Multilingual tier ──
  {
    key: 'aya-expanse-8b',
    name: 'Aya Expanse 8B',
    category: 'multilingual',
    recommendedFor: ['multilingual', 'chat'],
    params: '8B',
    size: '5.1 GB',
    family: 'aya',
    description: "Cohere For AI's flagship open multilingual model covering 23 languages with high-fidelity translation and localized dialogue.",
    capabilities: ['chat', 'multilingual'],
    ollama: 'aya-expanse:8b',
    lmstudio: 'lmstudio-community/Aya-Expanse-8B-GGUF'
  },
  {
    key: 'aya-expanse-32b',
    name: 'Aya Expanse 32B',
    category: 'multilingual',
    recommendedFor: ['multilingual', 'chat', 'general'],
    params: '32B',
    size: '19.5 GB',
    family: 'aya',
    description: "Cohere For AI's high-capacity 32B multilingual model covering 23 languages with advanced translation and localized dialogue.",
    capabilities: ['chat', 'multilingual'],
    context: 128000,
    ollama: 'aya-expanse:32b',
    lmstudio: 'lmstudio-community/Aya-Expanse-32B-GGUF'
  },
  {
    key: 'translategemma-12b',
    name: 'TranslateGemma 12B',
    category: 'multilingual',
    recommendedFor: ['multilingual', 'chat'],
    params: '12B',
    size: '8.1 GB',
    family: 'gemma',
    description: "Google's open translation model built on Gemma 3 — high-fidelity translation across 55 languages with vision and a 128K context window.",
    capabilities: ['chat', 'multilingual', 'vision'],
    context: 131072,
    ollama: 'translategemma:12b',
    lmstudio: 'lmstudio-community/TranslateGemma-12B-IT-GGUF'
  },
  // ── Text embeddings ──
  // PortOS's memory/recall pipeline expects 768-dimension vectors
  // (EMBEDDING_DIM in server/services/embeddings.js) — every entry below
  // produces them. Larger embedders (e.g. qwen3-embedding at 1024 dims) are
  // deliberately absent: they fail the dimension check on ingest.
  {
    key: 'embeddinggemma-300m',
    name: 'EmbeddingGemma 300M',
    category: 'embedding',
    recommendedFor: ['embedding'],
    params: '300M',
    size: '622 MB',
    family: 'embedding',
    description: "Google's 300M embedding model — 768-dimension vectors for semantic search and memory recall.",
    capabilities: ['embeddings', 'multilingual'],
    ollama: 'embeddinggemma:300m',
    lmstudio: 'lmstudio-community/embeddinggemma-300m-qat-GGUF'
  },
  {
    key: 'nomic-embed-text',
    name: 'Nomic Embed Text',
    category: 'embedding',
    recommendedFor: ['embedding'],
    params: '137M',
    size: '274 MB',
    family: 'embedding',
    description: 'Text embedding model for semantic search / memory recall.',
    capabilities: ['embeddings'],
    ollama: 'nomic-embed-text',
    lmstudio: 'nomic-ai/nomic-embed-text-v1.5-GGUF'
  },
  {
    key: 'nomic-embed-text-v2-moe',
    name: 'Nomic Embed Text v2 MoE',
    category: 'embedding',
    recommendedFor: ['embedding'],
    params: '0.5B',
    size: '344 MB',
    family: 'embedding',
    description: 'Newer multilingual text-embedding MoE for semantic search and recall.',
    capabilities: ['embeddings', 'multilingual'],
    ollama: 'hf.co/nomic-ai/nomic-embed-text-v2-moe-GGUF:Q4_K_M',
    lmstudio: 'nomic-ai/nomic-embed-text-v2-moe-GGUF'
  }
];

// Models that have aged out of the suggested-install picker but that installs
// upgraded from an older PortOS may still have on disk. `mapModelToBackend`
// consults these AFTER `LOCAL_LLM_CATALOG` so a migrate of an older library
// still resolves exactly instead of falling back to a guessed stem — dropping an
// entry from the catalog above must not silently downgrade the migrate flow.
//
// Entries need BOTH ids: a one-sided pair maps to nothing and would only add a
// dead HuggingFace repo to the mapping table (both `lmstudio-community/llava-v1.5-7b-GGUF`
// and `lmstudio-community/CodeLlama-7b-Instruct-GGUF` 404 as of this refresh,
// so LLaVA 1.5 and Code Llama are omitted rather than mapped to a broken repo).
const RETIRED_MODEL_MAPPINGS = [
  // Preserve installed-model migration without recommending an unreviewed publisher.
  {
    key: 'nex-n2-mini',
    name: 'Nex-N2-mini 35B-A3B',
    category: 'coding',
    recommendedFor: ['coding', 'reasoning', 'vision'],
    params: '35B / 3B active',
    size: '22 GB',
    family: 'nex-n2',
    description: "Nex AGI's agentic MoE (3B active) on a Qwen3.5 base — strong at coding, tool calling, long-horizon agent tasks, and vision (75.3 Terminal-Bench 2.1). Apache-2.0; the Q4 build fits comfortably on 32GB+ and is easy on a 128GB Mac. Vision needs the repo's mmproj file. The 397B Nex-N2-Pro is the big sibling — it won't fit a 128GB Mac even at Q4.",
    capabilities: ['chat', 'code', 'tools', 'reasoning', 'vision'],
    ollama: 'hf.co/sjakek/Nex-N2-mini-GGUF:UD-Q4_K_M',
    lmstudio: 'sjakek/Nex-N2-mini-GGUF'
  },

  { ollama: 'llama3.2', lmstudio: 'lmstudio-community/Llama-3.2-3B-Instruct-GGUF' },
  { ollama: 'llama3.1', lmstudio: 'lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF' },
  { ollama: 'qwen2.5', lmstudio: 'lmstudio-community/Qwen2.5-7B-Instruct-GGUF' },
  { ollama: 'qwen3:30b', lmstudio: 'lmstudio-community/Qwen3-30B-A3B-GGUF' },
  { ollama: 'qwen2.5vl', lmstudio: 'lmstudio-community/Qwen2.5-VL-7B-Instruct-GGUF' },
  { ollama: 'qwen2.5vl:32b', lmstudio: 'lmstudio-community/Qwen2.5-VL-32B-Instruct-GGUF' },
  {
    ollama: 'hf.co/lmstudio-community/Qwen3-4B-Instruct-2507-GGUF:Q4_K_M',
    lmstudio: 'lmstudio-community/Qwen3-4B-Instruct-2507-GGUF'
  },
  { ollama: 'mistral', lmstudio: 'lmstudio-community/Mistral-7B-Instruct-v0.3-GGUF' },
  {
    ollama: 'hf.co/unsloth/Devstral-Small-2-24B-Instruct-2512-GGUF:UD-Q4_K_XL',
    lmstudio: 'unsloth/Devstral-Small-2-24B-Instruct-2512-GGUF'
  },
  {
    ollama: 'hf.co/lmstudio-community/Ministral-3-14B-Instruct-2512-GGUF:Q4_K_M',
    lmstudio: 'lmstudio-community/Ministral-3-14B-Instruct-2512-GGUF'
  },
  {
    ollama: 'hf.co/lmstudio-community/granite-3.2-8b-instruct-GGUF:Q4_K_M',
    lmstudio: 'lmstudio-community/granite-3.2-8b-instruct-GGUF'
  },
  { ollama: 'granite4.1:3b', lmstudio: 'lmstudio-community/granite-4.1-3b-GGUF' },
  { ollama: 'granite4.1:8b', lmstudio: 'lmstudio-community/granite-4.1-8b-GGUF' },
  { ollama: 'gemma2', lmstudio: 'lmstudio-community/gemma-2-9b-it-GGUF' },
  { ollama: 'phi3', lmstudio: 'lmstudio-community/Phi-3.1-mini-128k-instruct-GGUF' },
  { ollama: 'deepseek-r1', lmstudio: 'lmstudio-community/DeepSeek-R1-Distill-Qwen-7B-GGUF' },
  { ollama: 'minicpm-v', lmstudio: 'openbmb/MiniCPM-V-2_6-gguf' },
  { ollama: 'smollm2', lmstudio: 'lmstudio-community/SmolLM2-1.7B-Instruct-GGUF' },
  {
    ollama: 'nemotron-3-nano:30b',
    lmstudio: 'lmstudio-community/NVIDIA-Nemotron-3-Nano-30B-A3B-GGUF'
  }
];

// Strip only the implicit `:latest` tag (`llama3.2:latest` → `llama3.2`) and
// lowercase. Meaningful tags (`gpt-oss:20b`, `qwen2.5:7b`) are preserved so a
// `7b` build can't normalize onto — and be mistaken for — a `20b` catalog entry.
const normalizeOllamaId = (id) =>
  String(id || '').trim().toLowerCase().replace(/:latest$/, '');

// Reduce an LM Studio / HuggingFace id to a comparable stem:
// `lmstudio-community/Llama-3.2-3B-Instruct-GGUF` → `llama-3.2-3b-instruct`.
const normalizeLmStudioId = (id) => String(id || '')
  .split('/').pop()
  .trim()
  .toLowerCase()
  .replace(/[-.]gguf$/i, '');

/**
 * Reduce an install id to the stem this backend compares by. Exported because
 * matching "is this pulled model that catalog entry?" must use the SAME
 * normalization the catalog itself does; a second, looser copy is how a 7b
 * build gets mistaken for a 20b entry.
 */
export const normalizeBackendModelId = (backend, id) =>
  backend === 'ollama' ? normalizeOllamaId(id) : normalizeLmStudioId(id);

const normalizeFor = normalizeBackendModelId;

/**
 * Every install id one catalog entry is recognized by on `backend` — the
 * current one plus the aliases a publisher retired. Callers that need to know
 * "which ids name this model" (scope mapping, installed-state matching) must
 * use this rather than reading `entry[backend]`, or an install that pulled the
 * model under its old id goes unrecognized.
 */
export const entryIdsForBackend = (entry, backend) => [
  entry[backend],
  ...(Array.isArray(entry[`${backend}Aliases`]) ? entry[`${backend}Aliases`] : [])
].filter(Boolean);

const entryMatchesBackendId = (entry, backend, normalizedId) =>
  entryIdsForBackend(entry, backend).some((id) => normalizeFor(backend, id) === normalizedId);

const SIZE_UNIT_BYTES = { KB: 1024, MB: 1024 ** 2, GB: 1024 ** 3, TB: 1024 ** 4 };

/** Parse a catalog `size` string ('4.9 GB', '301 MB') to bytes; 0 if unparseable. */
const parseCatalogSizeBytes = (size) => {
  const match = /^([\d.]+)\s*(KB|MB|GB|TB)$/i.exec(String(size || '').trim());
  if (!match) return 0;
  return Math.round(Number(match[1]) * SIZE_UNIT_BYTES[match[2].toUpperCase()]);
};

/**
 * Bytes for a curated catalog entry's advertised download size, resolved by
 * the backend-specific install id (matched the same alias-aware way
 * `getOllamaImportSpec`/`getCatalog` match ids). 0 for an unrecognized id or
 * an entry whose `size` string doesn't parse — the disk preflight already
 * treats 0 as "unknown, never refuse," so a miss here fails open rather than
 * blocking an install PortOS just can't size.
 */
export function catalogSizeBytes(backend, modelId) {
  if (!isBackend(backend)) return 0;
  const normalizedId = normalizeFor(backend, modelId);
  const entry = LOCAL_LLM_CATALOG.find((candidate) => (
    candidate[backend] && entryMatchesBackendId(candidate, backend, normalizedId)
  ));
  return entry ? parseCatalogSizeBytes(entry.size) : 0;
}

/**
 * Return the trusted local-Safetensors import recipe for a curated Ollama id.
 * Unknown/free-text ids return null and continue through the normal pull path.
 */
export function getOllamaImportSpec(modelId) {
  const normalizedId = normalizeOllamaId(modelId);
  const entry = LOCAL_LLM_CATALOG.find((candidate) => (
    candidate.ollamaImport && entryMatchesBackendId(candidate, 'ollama', normalizedId)
  ));
  return entry ? { modelId: entry.ollama, ...entry.ollamaImport } : null;
}

/**
 * Return the catalog projected onto a single backend: only entries that ship
 * a known build for `backend`, each with the backend-specific install id
 * surfaced as `id`. Pure — pass installed ids to overlay an `installed` flag.
 *
 * @param {string} backend - 'ollama' | 'lmstudio'
 * @param {string[]} [installedIds] - ids currently installed on that backend
 * @param {{ appleSilicon?: boolean }} [options] - host capabilities used for platform-gated entries
 * @returns {Array<{ id, key, name, category, recommendedFor, featured, params, size, family, description, note, repository, gated, capabilities, format, hardwareRequirements, contextLength, installed }>}
 */
export function getCatalog(backend, installedIds = [], { appleSilicon } = {}) {
  if (!isBackend(backend)) return [];
  const installedNorm = new Set(installedIds.map((id) => normalizeFor(backend, id)));
  return LOCAL_LLM_CATALOG
    .filter((entry) => entry[backend] && (!entry.appleSiliconOnly || appleSilicon !== false))
    .map((entry) => {
      const recommendedFor = Array.isArray(entry.recommendedFor) && entry.recommendedFor.length
        ? [...entry.recommendedFor]
        : [entry.category];
      return {
        ...localModelSafety(entry.repository || entry.lmstudio || entry[backend]),
        id: entry[backend],
        key: entry.key,
        name: entry.name,
        category: entry.category,
        recommendedFor,
        featured: entry.featured ? { ...entry.featured } : null,
        params: entry.params,
        size: entry.size,
        family: entry.family,
        description: entry.description,
        note: entry.note || null,
        repository: entry.repository || null,
        gated: entry.gated === true,
        capabilities: entry.capabilities,
        format: entry.format || null,
        hardwareRequirements: hardwareRequirementsForLocalLlm(entry),
        // Native context window (tokens), when it's a documented spec; null otherwise.
        contextLength: Number.isFinite(entry.context) ? entry.context : null,
        installed: entryIdsForBackend(entry, backend)
          .some((id) => installedNorm.has(normalizeFor(backend, id)))
      };
    });
}

/**
 * Filter the per-backend catalog by a free-text query against name, id,
 * family, category, and description. Empty query returns the full catalog.
 */
export function searchCatalog(backend, query, installedIds = [], options = {}) {
  const all = getCatalog(backend, installedIds, options);
  const q = String(query || '').trim().toLowerCase();
  if (!q) return all;
  return all.filter((m) =>
    m.name.toLowerCase().includes(q) ||
    m.id.toLowerCase().includes(q) ||
    m.category.toLowerCase().includes(q) ||
    m.recommendedFor.some((category) => category.toLowerCase().includes(q)) ||
    m.family.toLowerCase().includes(q) ||
    m.capabilities.some((capability) => capability.toLowerCase().includes(q)) ||
    m.description.toLowerCase().includes(q));
}

/**
 * Map an installed model id on `fromBackend` to the equivalent install id on
 * `toBackend`, used by the migrate flow.
 *
 * Returns `{ targetId, exact }`:
 * - `exact: true`  — a curated (or retired-but-still-mapped) catalog entry
 *   matched and the target build is known.
 * - `exact: false` — best-effort derived name (only when the target is Ollama,
 *   which can pull bare model names); `targetId` is null when no reasonable
 *   guess exists (e.g. mapping an unknown model TO LM Studio needs a HF repo).
 */
export function mapModelToBackend(fromBackend, modelId, toBackend) {
  if (!isBackend(fromBackend) || !isBackend(toBackend) || fromBackend === toBackend) {
    return { targetId: null, exact: false };
  }
  const fromNorm = normalizeFor(fromBackend, modelId);
  // Suggested models first, then models retired from the picker — an install
  // that predates a catalog refresh still migrates exactly.
  const entry = [...LOCAL_LLM_CATALOG, ...RETIRED_MODEL_MAPPINGS].find(
    (e) => entryMatchesBackendId(e, fromBackend, fromNorm)
  );
  if (entry && entry[toBackend]) {
    return { targetId: entry[toBackend], exact: true };
  }
  // A known catalog entry without a build on the target backend is not an
  // unknown model: do not turn a native-format id (for example an MLX repo)
  // into a misleading best-effort Ollama stem.
  if (entry) return { targetId: null, exact: false };

  // No catalog match. Ollama can pull bare model names, so derive a stem and
  // try it best-effort. There's no safe way to guess a HuggingFace repo for
  // LM Studio, so bail with null and let the caller report the skip.
  if (toBackend === 'ollama') {
    const stem = fromBackend === 'lmstudio'
      ? normalizeLmStudioId(modelId).replace(/-instruct.*$/i, '').replace(/-\d+b.*$/i, '')
      : normalizeOllamaId(modelId);
    return { targetId: stem || null, exact: false };
  }
  return { targetId: null, exact: false };
}