Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(local-models): the overview lists what is installed, recommends installed-first, and sets everything up in one click
rubenluetke10-beep352ccd1f1bc5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ab6a2c601a..726a8e3585 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,40 @@ versioning per [SemVer](https://semver.org/).## [Unreleased]+### Added++- **Local models: one click sets everything up.** "Set up everything" on the+ overview starts the local server when it is stopped (and names the install+ on the button when it is not installed), then fills every role — chat,+ voice, tools & screen, deep & coding, embeddings — with the best download+ already on the server, fetches only what is missing, writes the suggested+ settings and reads back what it did, role by role. A slot served elsewhere+ is left alone and named; a refused slot does not stop the others. When+ another brain answers, the one decision left — making the local server+ the active brain — is offered right under the summary.+- **Local models: the installed models are on the overview.** Every download+ as one line — name, size, the capabilities a role cares about, which roles+ use it, which role it is the pick for, whether it sits in memory — with+ "Manage" opening the full ledger. Nothing hides behind the Advanced switch+ any more.++### Changed++- **Local models: recommendations are installed-first.** A role's pick is the+ best qualifying download already on the server — the largest one that fits+ this machine's graphics memory, preferring the role's capability (tools for+ a chat, thinking for deep work; voice stays in the fast class under 6 GB) —+ and the curated catalogue only stands in when nothing installed qualifies.+ Each row says why in one sentence. Eleven models on disk no longer end in+ "download qwen3.8:27b".++### Fixed++- **Local models: a changed role showed its old pick for up to 15 s.** The+ overview's in-memory memo was not dropped on a write, and the section never+ asked for a live rebuild after its own change. Every write now forgets the+ memo, and the section re-reads the overview live right after.+### Removed- **The Local models setup helper.** The "Setup helper" tab — a chat thatdiff --git a/jarvis/brain/ollama_overview.py b/jarvis/brain/ollama_overview.pyindex 738d129624..7bc5f443f1 100644--- a/jarvis/brain/ollama_overview.py+++ b/jarvis/brain/ollama_overview.py@@ -50,6 +50,7 @@ __all__ = ["DEFAULT_MAX_AGE_S","STALE_AFTER_S","build_overview",+ "forget","get_overview","inventory_payload","load_snapshot",@@ -116,6 +117,7 @@ def role_row(state: ollama_roles.RoleState) -> dict[str, Any]:"recommended_capabilities": list(spec.recommended),"qualifying": list(state.qualifying),"recommended": state.recommended,+ "recommended_reason": state.recommended_reason,"writable": spec.writable,"advanced": spec.advanced,"note": state.note,@@ -181,9 +183,12 @@ async def _roles_from(snapshot: inventory.InventorySnapshot | None,error: str | None,shortlist: list[dict[str, Any]] | None,+ machine: ollama_roles.Machine | None = None,) -> dict[str, Any]:models = list(snapshot.models) if snapshot is not None else []- states, _unused = await ollama_roles.list_roles(root, cfg, models=models, shortlist=shortlist)+ states, _unused = await ollama_roles.list_roles(+ root, cfg, models=models, shortlist=shortlist, machine=machine+ )return {"provider": provider_id,"server": root,@@ -257,7 +262,13 @@ async def build_overview(root: str, cfg: Any, *, provider_id: str = "ollama") ->)shortlist = recommended.get("models") if isinstance(recommended, dict) else Noneroles = await _roles_from(- provider_id, root, cfg, snapshot, error, shortlist if isinstance(shortlist, list) else []+ provider_id,+ root,+ cfg,+ snapshot,+ error,+ shortlist if isinstance(shortlist, list) else [],+ machine=ollama_roles.machine_from(recommended),)server = await _server_from(status, root)return {@@ -351,6 +362,18 @@ def _reset_for_tests() -> None:_refresh_tasks.clear()+def forget(root: str) -> None:+ """Drop the memoised overview for ``root`` after a write.++ A role pick, a tune, an unload or a delete changes what the next open+ must show; without this the memo answered the OLD payload for up to+ :data:`DEFAULT_MAX_AGE_S` after the write and the row the user had just+ changed stayed where it was. The disk snapshot is left alone — the next+ live build overwrites it.+ """+ _memo.pop(normalize_server_root(root), None)++def _fresh(root: str, max_age_s: float) -> dict[str, Any] | None:hit = _memo.get(root)if hit is not None and time.monotonic() - hit[0] < max_age_s:diff --git a/jarvis/brain/ollama_roles.py b/jarvis/brain/ollama_roles.pyindex 485dfe125b..3f321fd62c 100644--- a/jarvis/brain/ollama_roles.py+++ b/jarvis/brain/ollama_roles.py@@ -7,9 +7,15 @@ and the wiki's embedding model — plus two read-only consumers (the quick ack,dictation polish) that pin their own tag.This module names every slot as a :class:`RoleSpec`, reads its current pickfrom a loaded config, judges which INSTALLED downloads qualify for it (by the-capabilities ``/api/show`` declares) and points at the shortlist's pick for-this machine, so the "Local models" section can show the four rows with one-button each instead of four different pickers in four different views.+capabilities ``/api/show`` declares) and recommends one, so the "Local+models" section can show the four rows with one button each instead of four+different pickers in four different views.++The recommendation is INSTALLED FIRST: the best qualifying download already+on the server — the largest one that fits this machine's memory, with the+role's preferred capabilities — and only when nothing installed qualifies+does the curated shortlist's pick (a download) stand in. A user with eleven+models on disk is told which of them to use, not sent to the catalogue.Writing goes through the existing config writers only(``config_writer.set_brain_provider_model`` / ``set_ultrawiki_slot``), so a@@ -34,16 +40,21 @@ log = logging.getLogger(__name__)__all__ = ["ROLES","WRITABLE_ROLE_IDS",+ "Machine","RoleSpec","RoleState","current_pick","list_roles",+ "machine_from",+ "pick_installed","qualifying_models","role_spec","roles_using","set_role",]+_GIB = 1024**3+@dataclass(frozen=True, slots=True)class RoleSpec:@@ -66,6 +77,10 @@ class RoleSpec:writable: bool = True#: Hidden in the Simple view.advanced: bool = False+ #: Installed picks at or under this size (GiB) are preferred — the roles+ #: where speed beats depth (a call must answer within a breath). ``None``+ #: = the largest model that fits wins.+ max_size_gb: float | None = NoneROLES: tuple[RoleSpec, ...] = (@@ -84,6 +99,10 @@ ROLES: tuple[RoleSpec, ...] = (required=("completion",),recommended=("tools",),pull_role="chat",+ # A call is judged by its first word, not its best one: the pick stays+ # in the class that answers within a breath, the chat slot takes the+ # depth.+ max_size_gb=6.0,),RoleSpec(id="tools_screen",@@ -147,8 +166,12 @@ class RoleState:installed: bool#: Installed tags that declare every required capability.qualifying: tuple[str, ...]- #: The shortlist's pick for this machine (``""`` when it has none).+ #: The pick for this machine: the best qualifying INSTALLED download, or+ #: the shortlist's download when nothing installed qualifies (``""`` when+ #: neither has one).recommended: str+ #: One sentence saying why ``recommended`` is the pick (``""`` when none).+ recommended_reason: str = ""#: One sentence when the slot is not Ollama-backed right now.note: str = ""#: The voice brain's effective ``num_ctx`` on this machine (voice role only).@@ -263,8 +286,97 @@ def qualifying_models(spec: RoleSpec, models: list[OllamaModelInfo]) -> tuple[streturn tuple(out)+@dataclass(frozen=True, slots=True)+class Machine:+ """The memory an installed pick is judged against.++ ``memory_gb`` is ``None`` when the host would not say; ``accelerator_gb``+ is ``0.0`` for "no graphics memory I can vouch for" — the same two+ answers :func:`ollama_pull.fit_verdict` already reads.+ """++ memory_gb: float | None = None+ accelerator_gb: float = 0.0+++def _size_gb(info: OllamaModelInfo) -> float:+ return info.size_bytes / _GIB+++def _has_preferred(spec: RoleSpec, info: OllamaModelInfo) -> bool:+ return all(cap in info.capabilities for cap in spec.recommended)+++def _preferred_clause(spec: RoleSpec) -> str:+ return f" with {' and '.join(spec.recommended)}" if spec.recommended else ""+++def pick_installed(+ spec: RoleSpec, models: list[OllamaModelInfo], machine: Machine+) -> tuple[str, str]:+ """``(tag, reason)`` — the best INSTALLED download for ``spec``, or ``("", "")``.++ Bigger is better right up to the point where it stops fitting, so the+ pick is the largest qualifying model this machine runs comfortably; a+ model that also declares the role's preferred capabilities (tools for a+ chat, thinking for deep work) beats a larger one without them, because+ a chat model that cannot call tools is the wrong model however smart.+ When nothing fits comfortably the SMALLEST one is named (a starting+ point rather than four rows flagged "tight"); when the memory could not+ be read at all the largest is — the user installed it, the box presumably+ runs it. A role with ``max_size_gb`` prefers the class under that size.+ The reason is one English sentence the row shows beside the button.+ """+ candidates = [+ info+ for info in models+ if info.probed and all(c in info.capabilities for c in spec.required)+ ]+ if not candidates:+ return "", ""+ preferred = _preferred_clause(spec)++ if spec.max_size_gb is not None:+ fast = [m for m in candidates if _size_gb(m) <= spec.max_size_gb]+ if fast:+ best = max(fast, key=lambda m: (_has_preferred(spec, m), _size_gb(m)))+ return best.name, (+ f"Largest installed model{preferred} under {spec.max_size_gb:g} GB — "+ "this job needs fast answers more than depth."+ )+ best = min(candidates, key=lambda m: (not _has_preferred(spec, m), _size_gb(m)))+ return best.name, (+ f"Smallest installed model{preferred}; nothing under {spec.max_size_gb:g} GB "+ "is installed, and this job needs fast answers."+ )++ verdicts = {+ m.name: ollama_pull.fit_verdict(_size_gb(m), machine.memory_gb, machine.accelerator_gb)[0]+ for m in candidates+ }+ comfortable = [m for m in candidates if verdicts[m.name] == "comfortable"]+ if comfortable:+ best = max(comfortable, key=lambda m: (_has_preferred(spec, m), _size_gb(m)))+ where = (+ f"the {machine.accelerator_gb:.0f} GB of graphics memory"+ if machine.accelerator_gb > 0 and _size_gb(best) + 2.0 <= machine.accelerator_gb+ else f"{machine.memory_gb:g} GB of memory"+ )+ return best.name, f"Largest installed model{preferred} that fits in {where}."+ if all(v == "unknown" for v in verdicts.values()):+ best = max(candidates, key=lambda m: (_has_preferred(spec, m), _size_gb(m)))+ return best.name, (+ f"Largest installed model{preferred}; this machine's memory could not be read."+ )+ best = min(candidates, key=lambda m: (not _has_preferred(spec, m), _size_gb(m)))+ return best.name, (+ f"Smallest installed model{preferred} — every option is tight on this machine."+ )++def _recommended_for(spec: RoleSpec, rows: list[dict[str, Any]]) -> str:- """The shortlist's pick for ``spec`` on this machine.+ """The shortlist's pick for ``spec`` on this machine — the fallback when+ :func:`pick_installed` found nothing installed that qualifies.:func:`ollama_pull._pick_recommended` marks nothing for a role that hasa curated model installed already — the user has chosen. Then the@@ -285,6 +397,18 @@ def _recommended_for(spec: RoleSpec, rows: list[dict[str, Any]]) -> str:return ""+def machine_from(recommended: dict[str, Any] | None) -> Machine:+ """The :class:`Machine` a shortlist payload was judged against."""+ if not isinstance(recommended, dict):+ return Machine()+ memory = recommended.get("memory_gb")+ accel = recommended.get("accelerator_gb")+ return Machine(+ memory_gb=float(memory) if isinstance(memory, (int, float)) else None,+ accelerator_gb=float(accel) if isinstance(accel, (int, float)) else 0.0,+ )++async def list_roles(root: str,cfg: Any,@@ -292,6 +416,7 @@ async def list_roles(transport: Any = None,models: list[OllamaModelInfo] | None = None,shortlist: list[dict[str, Any]] | None = None,+ machine: Machine | None = None,) -> tuple[list[RoleState], str | None]:"""Every role with its pick, what qualifies, and the recommendation.@@ -299,10 +424,10 @@ async def list_roles(when ``/api/tags`` did not answer — the states are still complete (withempty ``qualifying`` and ``installed=False``) so the rows render.- ``models`` and ``shortlist`` let a caller that already holds the shared- inventory snapshot and the recommendations pass them in; either one left- ``None`` is fetched here (the snapshot is shared, so this costs no extra- sweep within its window).+ ``models``, ``shortlist`` and ``machine`` let a caller that already holds+ the shared inventory snapshot and the recommendations pass them in; any+ left ``None`` is fetched here (the snapshot is shared, so this costs no+ extra sweep within its window; the shortlist answers the machine too)."""error: str | None = Noneif models is None:@@ -315,10 +440,15 @@ async def list_roles(error = str(exc)if shortlist is None:try:- shortlist = (await ollama_pull.recommendations()).get("models") or []+ recommended = await ollama_pull.recommendations()+ shortlist = recommended.get("models") or []+ if machine is None:+ machine = machine_from(recommended)except Exception as exc: # noqa: BLE001 — the shortlist is advisory, the rows are notlog.warning("ollama-roles: shortlist unavailable: %s", exc)shortlist = []+ if machine is None:+ machine = Machine()states: list[RoleState] = []for spec in ROLES:@@ -328,13 +458,19 @@ async def list_roles(context_source = ""if spec.id == "voice" and current and error is None:context_tokens, context_source = await voice_context(cfg, current)+ recommended_tag, reason = pick_installed(spec, models, machine)+ if not recommended_tag:+ recommended_tag = _recommended_for(spec, shortlist)+ if recommended_tag:+ reason = "Nothing installed fits this job yet; this download is the pick."states.append(RoleState(spec=spec,current=current,installed=bool(current) and any(same_model(m.name, current) for m in models),qualifying=qualifying,- recommended=_recommended_for(spec, shortlist),+ recommended=recommended_tag,+ recommended_reason=reason,note=note,context_tokens=context_tokens,context_source=context_source,diff --git a/jarvis/ui/web/frontend/src/hooks/useLocalModels.ts b/jarvis/ui/web/frontend/src/hooks/useLocalModels.tsindex f06592bf14..60ae1228b6 100644--- a/jarvis/ui/web/frontend/src/hooks/useLocalModels.ts+++ b/jarvis/ui/web/frontend/src/hooks/useLocalModels.ts@@ -11,6 +11,7 @@*/import {keepPreviousData,+ type QueryClient,useMutation,useQuery,useQueryClient,@@ -126,8 +127,14 @@ export interface RoleRow {recommended_capabilities: string[];/** Installed tags declaring every required capability. */qualifying: string[];- /** The shortlist's pick for this machine; "" when it has none. */+ /**+ * The pick for this machine: the best qualifying INSTALLED download, or+ * the shortlist's download when nothing installed qualifies; "" when+ * neither has one.+ */recommended: string;+ /** One backend sentence saying why `recommended` is the pick; "" when none. */+ recommended_reason?: string;writable: boolean;advanced: boolean;/** Sentence when the slot is served by something other than Ollama. */@@ -1009,10 +1016,46 @@ export function useEnvGuide(providerId: string | undefined, os?: EnvGuideOs) {// ---------------------------------------------------------------------------/** Invalidate every query of the section for one provider. */+/**+ * Refetch the overview LIVE after a change this section made itself.+ *+ * A plain invalidation would re-read `GET …/overview`, which answers the+ * disk snapshot first (`source: "cache"`) and refreshes in the background —+ * so the row the user just changed would sit on its old value until the+ * next poll. `?fresh=1` skips the cache; the answer replaces the cached+ * payload under the same key, so every panel repaints from it.+ */+export function refetchOverviewFresh(+ qc: QueryClient,+ providerId: string,+): Promise<OverviewResponse | undefined> {+ return qc+ .fetchQuery({+ queryKey: localModelsKeys.overview(providerId),+ queryFn: () => getOverview(providerId, true),+ staleTime: 0,+ })+ .catch((err: unknown) => {+ // The write already landed; a failed re-read only delays the repaint+ // until the next poll, so it is logged rather than surfaced.+ console.warn("[local-models] fresh overview failed", err);+ return undefined;+ });+}+export function useInvalidateLocalModels(providerId: string | undefined) {const qc = useQueryClient();- return () =>- qc.invalidateQueries({ queryKey: ["local-models", providerId ?? ""] });+ return () => {+ const id = providerId ?? "";+ void refetchOverviewFresh(qc, id);+ return qc.invalidateQueries({+ queryKey: ["local-models", id],+ // The overview is being fetched fresh above; refetching it again+ // here would race that answer with a cache-first one.+ predicate: (q) =>+ !(q.queryKey.length === 3 && q.queryKey[2] === "overview"),+ });+ };}export function useSetRole(providerId: string | undefined) {@@ -1021,15 +1064,10 @@ export function useSetRole(providerId: string | undefined) {mutationFn: ({ role, model }: { role: LocalModelRole; model: string }) =>setRole(providerId as string, role, model),onSuccess: () => {- void qc.invalidateQueries({- queryKey: localModelsKeys.roles(providerId ?? ""),- });- void qc.invalidateQueries({- queryKey: localModelsKeys.inventory(providerId ?? ""),- });- void qc.invalidateQueries({- queryKey: localModelsKeys.overview(providerId ?? ""),- });+ const id = providerId ?? "";+ void qc.invalidateQueries({ queryKey: localModelsKeys.roles(id) });+ void qc.invalidateQueries({ queryKey: localModelsKeys.inventory(id) });+ void refetchOverviewFresh(qc, id);},});}diff --git a/jarvis/ui/web/frontend/src/i18n/locales/local_models/de.json b/jarvis/ui/web/frontend/src/i18n/locales/local_models/de.jsonindex 86fb5b8383..ffc8274073 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/local_models/de.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/local_models/de.json@@ -204,7 +204,41 @@"gpu_in_use": "{gb} belegt","gpu_in_use_none": "nichts belegt","loaded_expires": "läuft in {when} ab",- "checking": "Wird geprüft…"+ "checking": "Wird geprüft…",+ "action_setup": "Alles einrichten",+ "action_setup_hint": "Besetzt jede Rolle mit dem besten installierten Modell; lädt nur, was fehlt.",+ "action_setup_install": "{server} installieren und alles einrichten",+ "action_setup_install_hint": "Installiert den Server aus dem offiziellen Download und besetzt dann jede Rolle.",+ "setup_planning": "Liest, was installiert ist…",+ "setup_server_starting": "{server} wird gestartet…",+ "setup_server_installing": "{server} wird installiert…",+ "setup_pulling": "{model} wird heruntergeladen",+ "setup_assigning": "{role} wird zugewiesen: {model}…",+ "setup_tuning": "Einstellungen für {model} werden gewählt…",+ "setup_done": "Alles ist eingerichtet.",+ "setup_done_nothing": "Alles war schon eingerichtet; nichts geändert.",+ "setup_assigned": "{role} → {model}",+ "setup_kept_one": "1 Rolle behält ihre Wahl.",+ "setup_kept": "{count} Rollen behalten ihre Wahl.",+ "setup_skipped": "{role} übersprungen: {reason}",+ "setup_skipped_no_pick": "kein installiertes Modell passt und der Katalog hat keine Empfehlung",+ "setup_error": "Einrichtung abgebrochen: {message}",+ "setup_brain_hint": "{server} ist eingerichtet, aber {brain} antwortet weiterhin.",+ "setup_brain_button": "{server} zum aktiven Gehirn machen",+ "setup_brain_switched": "{server} ist jetzt das aktive Gehirn.",+ "setup_brain_failed": "Das Gehirn konnte nicht umgestellt werden: {message}"+ },+ "installed": {+ "title": "Installierte Modelle",+ "subtitle": "{count} Downloads · {size} auf der Platte",+ "subtitle_one": "1 Download · {size} auf der Platte",+ "manage": "Verwalten",+ "list_label": "Installierte Modelle",+ "empty": "Noch ist nichts installiert.",+ "loading": "Liest die Downloads…",+ "loaded": "im Speicher",+ "unknown_caps": "Fähigkeiten unbekannt",+ "recommended_for": "Empfohlen für {role}"},"roles": {"title": "Rollen",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/local_models/en.json b/jarvis/ui/web/frontend/src/i18n/locales/local_models/en.jsonindex ec54917303..335b6f9f1c 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/local_models/en.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/local_models/en.json@@ -204,7 +204,41 @@"gpu_in_use": "{gb} in use","gpu_in_use_none": "nothing in use","loaded_expires": "expires in {when}",- "checking": "Checking…"+ "checking": "Checking…",+ "action_setup": "Set up everything",+ "action_setup_hint": "Fills every role with the best installed model; downloads only what is missing.",+ "action_setup_install": "Install {server} and set everything up",+ "action_setup_install_hint": "Installs the server from its official download, then fills every role.",+ "setup_planning": "Reading what is installed…",+ "setup_server_starting": "Starting {server}…",+ "setup_server_installing": "Installing {server}…",+ "setup_pulling": "Downloading {model}",+ "setup_assigning": "Assigning {role}: {model}…",+ "setup_tuning": "Choosing the settings for {model}…",+ "setup_done": "Everything is set up.",+ "setup_done_nothing": "Everything was already set up; nothing changed.",+ "setup_assigned": "{role} → {model}",+ "setup_kept_one": "1 role kept its pick.",+ "setup_kept": "{count} roles kept their pick.",+ "setup_skipped": "{role} skipped: {reason}",+ "setup_skipped_no_pick": "no installed model fits and the catalogue has no pick",+ "setup_error": "Setup stopped: {message}",+ "setup_brain_hint": "{server} is set up, but {brain} still answers.",+ "setup_brain_button": "Make {server} the active brain",+ "setup_brain_switched": "{server} is now the active brain.",+ "setup_brain_failed": "Could not switch the brain: {message}"+ },+ "installed": {+ "title": "Installed models",+ "subtitle": "{count} downloads · {size} on disk",+ "subtitle_one": "1 download · {size} on disk",+ "manage": "Manage",+ "list_label": "Installed models",+ "empty": "Nothing is installed yet.",+ "loading": "Reading the downloads…",+ "loaded": "in memory",+ "unknown_caps": "capabilities unknown",+ "recommended_for": "Recommended for {role}"},"roles": {"title": "Roles",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/local_models/es.json b/jarvis/ui/web/frontend/src/i18n/locales/local_models/es.jsonindex d6ad82c5d9..de3dbbe6f3 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/local_models/es.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/local_models/es.json@@ -204,7 +204,41 @@"gpu_in_use": "{gb} en uso","gpu_in_use_none": "nada en uso","loaded_expires": "caduca en {when}",- "checking": "Comprobando…"+ "checking": "Comprobando…",+ "action_setup": "Configurar todo",+ "action_setup_hint": "Llena cada rol con el mejor modelo instalado; descarga solo lo que falta.",+ "action_setup_install": "Instalar {server} y configurar todo",+ "action_setup_install_hint": "Instala el servidor desde su descarga oficial y luego llena cada rol.",+ "setup_planning": "Leyendo lo que está instalado…",+ "setup_server_starting": "Iniciando {server}…",+ "setup_server_installing": "Instalando {server}…",+ "setup_pulling": "Descargando {model}",+ "setup_assigning": "Asignando {role}: {model}…",+ "setup_tuning": "Eligiendo los ajustes para {model}…",+ "setup_done": "Todo está configurado.",+ "setup_done_nothing": "Todo ya estaba configurado; nada cambió.",+ "setup_assigned": "{role} → {model}",+ "setup_kept_one": "1 rol mantiene su elección.",+ "setup_kept": "{count} roles mantienen su elección.",+ "setup_skipped": "{role} omitido: {reason}",+ "setup_skipped_no_pick": "ningún modelo instalado encaja y el catálogo no tiene recomendación",+ "setup_error": "La configuración se detuvo: {message}",+ "setup_brain_hint": "{server} está configurado, pero {brain} sigue respondiendo.",+ "setup_brain_button": "Hacer de {server} el cerebro activo",+ "setup_brain_switched": "{server} es ahora el cerebro activo.",+ "setup_brain_failed": "No se pudo cambiar el cerebro: {message}"+ },+ "installed": {+ "title": "Modelos instalados",+ "subtitle": "{count} descargas · {size} en disco",+ "subtitle_one": "1 descarga · {size} en disco",+ "manage": "Gestionar",+ "list_label": "Modelos instalados",+ "empty": "Todavía no hay nada instalado.",+ "loading": "Leyendo las descargas…",+ "loaded": "en memoria",+ "unknown_caps": "capacidades desconocidas",+ "recommended_for": "Recomendado para {role}"},"roles": {"title": "Roles",diff --git a/jarvis/ui/web/frontend/src/views/LocalModelsView.tsx b/jarvis/ui/web/frontend/src/views/LocalModelsView.tsxindex e75b0c79cd..a49e87b99a 100644--- a/jarvis/ui/web/frontend/src/views/LocalModelsView.tsx+++ b/jarvis/ui/web/frontend/src/views/LocalModelsView.tsx@@ -153,6 +153,12 @@ export function LocalModelsView() {setMode(next);storeMode(next);}, []);+ // "Manage" on the overview's installed list: the full ledger lives on the+ // Advanced-only Models tab, so the switch flips along with the tab.+ const openManage = useCallback(() => {+ changeMode("advanced");+ setTab("models");+ }, [changeMode]);// Leaving Advanced while on an Advanced-only tab must not strand the user on// a tab the rail no longer shows.@@ -235,6 +241,7 @@ export function LocalModelsView() {onTune={setTuneModel}onOpenApiKeys={openApiKeys}onBrowse={openBrowse}+ onManage={openManage}advanced={mode === "advanced"}/>{tuneModel && (diff --git a/jarvis/ui/web/frontend/src/views/local-models/InstalledPanel.tsx b/jarvis/ui/web/frontend/src/views/local-models/InstalledPanel.tsxnew file mode 100644index 0000000000..6b88135532--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/local-models/InstalledPanel.tsx@@ -0,0 +1,212 @@+/**+ * Installed models — the compact ledger on the Simple overview: every+ * download on the server as one line, so "what do I have?" is answered on+ * the page the user lands on, not behind the Advanced switch.+ *+ * One line per model: name, parameters and size, the capabilities a role+ * cares about (tools / vision / thinking / embedding / audio — "completion"+ * is every model's and is not shown), which roles use it, which role it is+ * the recommendation for, and whether it sits in memory right now. Nothing+ * here writes; "Manage" opens the full ledger (Advanced → Models) with its+ * Tune, Use-for, Unload and Delete.+ */+import { useMemo, type ReactNode } from "react";+import { Database } from "lucide-react";++import {+ Panel,+ PanelHeader,+ SoftButton,+ StatusDot,+} from "@/components/extensions/primitives";+import type { LocalModelRow, RoleRow } from "@/hooks/useLocalModels";+import { fill, useT } from "@/i18n";+import { cn } from "@/lib/utils";++import { formatGb } from "./localModelsFormat";+import { canonical } from "./localSetup";++export interface InstalledPanelProps {+ models: LocalModelRow[];+ roles: RoleRow[];+ diskBytes: number;+ loading?: boolean;+ /** The server's sentence when it did not answer; the list is empty then. */+ error?: string | null;+ /** Opens the full ledger (Advanced → Models); the button hides without it. */+ onManage?: () => void;+}++/** The capabilities a role is gated on; the rest is noise on a one-liner. */+const ROLE_CAPABILITIES: ReadonlySet<string> = new Set([+ "tools",+ "vision",+ "thinking",+ "embedding",+ "audio",+]);++function Chip({+ children,+ tone = "muted",+}: {+ children: ReactNode;+ tone?: "muted" | "primary";+}) {+ return (+ <span+ className={cn(+ "inline-flex shrink-0 items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium",+ tone === "primary"+ ? "bg-primary/10 text-primary"+ : "bg-sheen/[0.08] text-muted-foreground",+ )}+ >+ {children}+ </span>+ );+}++export function InstalledPanel({+ models,+ roles,+ diskBytes,+ loading = false,+ error = null,+ onManage,+}: InstalledPanelProps) {+ const t = useT();+ const k = (key: string) => t(`local_models.installed.${key}`);++ const roleLabel = (roleId: string) => {+ const row = roles.find((r) => r.id === roleId);+ return t(row?.label_key ?? `local_models.role_${roleId}`);+ };++ // Which writable role recommends which download (the same pick the roles+ // ledger's "Use recommended" would assign).+ const recommendedFor = useMemo(() => {+ const out = new Map<string, string[]>();+ for (const row of roles) {+ if (!row.writable || row.advanced || !row.recommended) continue;+ const key = canonical(row.recommended);+ out.set(key, [...(out.get(key) ?? []), row.id]);+ }+ return out;+ }, [roles]);++ // The models in use first, then the biggest — the order a user scans in.+ const sorted = useMemo(+ () =>+ [...models].sort(+ (a, b) =>+ b.used_by.length - a.used_by.length || b.size_bytes - a.size_bytes,+ ),+ [models],+ );++ const subtitle =+ models.length === 1+ ? fill(k("subtitle_one"), { size: formatGb(diskBytes) })+ : fill(k("subtitle"), {+ count: models.length,+ size: formatGb(diskBytes),+ });++ return (+ <Panel className="p-4">+ <div className="space-y-3" data-testid="local-models-installed">+ <div className="flex flex-wrap items-start justify-between gap-3">+ <PanelHeader title={k("title")} subtitle={subtitle} />+ {onManage && models.length > 0 && (+ <SoftButton onClick={onManage} ariaLabel={k("manage")}>+ <Database className="h-3.5 w-3.5" />+ {k("manage")}+ </SoftButton>+ )}+ </div>++ {error && (+ <p+ className="text-sm text-amber-700 dark:text-amber-400"+ data-testid="installed-error"+ >+ {error}+ </p>+ )}+ {loading && models.length === 0 && !error && (+ <p className="text-sm text-muted-foreground">{k("loading")}</p>+ )}+ {!loading && models.length === 0 && !error && (+ <p className="text-sm text-muted-foreground" data-testid="installed-empty">+ {k("empty")}+ </p>+ )}++ {sorted.length > 0 && (+ <ul+ aria-label={k("list_label")}+ className="divide-y divide-border/70 overflow-hidden rounded-xl border border-border bg-card/60"+ >+ {sorted.map((row) => {+ const caps = row.probed+ ? row.capabilities.filter((c) => ROLE_CAPABILITIES.has(c))+ : [];+ const picks = (recommendedFor.get(canonical(row.name)) ?? []).filter(+ (roleId) => !row.used_by.includes(roleId as LocalModelRow["used_by"][number]),+ );+ return (+ <li+ key={row.name}+ className="grid gap-2 px-3.5 py-2.5 sm:grid-cols-[minmax(0,1.6fr)_minmax(0,1fr)_minmax(0,1.4fr)] sm:items-center"+ data-testid={`installed-${row.name}`}+ >+ <div className="min-w-0">+ <StatusDot+ tone={row.loaded ? "ok" : "off"}+ label={+ <span className="font-mono text-xs text-foreground/85">+ {row.name}+ </span>+ }+ />+ <div className="ml-4 mt-0.5 text-[11px] text-muted-foreground">+ {[row.parameter_size, formatGb(row.size_bytes)]+ .filter(Boolean)+ .join(" · ")}+ {row.loaded ? ` · ${k("loaded")}` : ""}+ </div>+ </div>+ <div className="flex flex-wrap gap-1">+ {row.probed ? (+ caps.map((cap) => <Chip key={cap}>{cap}</Chip>)+ ) : (+ <Chip>{k("unknown_caps")}</Chip>+ )}+ </div>+ <div className="flex flex-wrap items-center gap-1 sm:justify-end">+ {row.used_by.map((roleId) => (+ <Chip key={roleId} tone="primary">+ {roleLabel(roleId)}+ </Chip>+ ))}+ {picks.length > 0 && (+ <span+ className="text-[11px] text-muted-foreground"+ data-testid={`installed-recommended-${row.name}`}+ >+ {fill(k("recommended_for"), {+ role: picks.map(roleLabel).join(", "),+ })}+ </span>+ )}+ </div>+ </li>+ );+ })}+ </ul>+ )}+ </div>+ </Panel>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.test.tsx b/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.test.tsxindex a666f0554e..ca977bcc8b 100644--- a/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.test.tsx+++ b/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.test.tsx@@ -5,6 +5,7 @@ import {render,screen,waitFor,+ within,} from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -212,6 +213,8 @@ function installFetchMock(fx: Fixture = {}) {config_key: "",message: "",});+ if (url === "/api/brain/switch" && method === "POST")+ return ok({ ok: true, active: "ollama" });if (url === "/api/providers/ollama/pull" && method === "POST")return ok({state: "running",@@ -428,11 +431,29 @@ describe("OverviewPanel", () => {expect(advanced.getAttribute("data-variant")).not.toBe("checklist");});- it("hides the action row when no handler is wired", async () => {+ it("keeps 'Set up everything' even when no browse handler is wired", async () => {installFetchMock();renderPanel();await screen.findByTestId("overview-status");- expect(screen.queryByTestId("overview-actions")).toBeNull();+ expect(+ screen.queryByRole("button", {+ name: "local_models.overview.action_browse",+ }),+ ).toBeNull();+ expect(+ screen.getByRole("button", { name: "local_models.overview.action_setup" }),+ ).toBeDefined();+ });++ it("names the install on the setup button when the server is not installed", async () => {+ installFetchMock({ server: { ...SERVER, installed: false, running: false } });+ renderPanel();+ // The label follows the server facts, so it settles with the data.+ expect(+ await screen.findByRole("button", {+ name: "local_models.overview.action_setup_installOllama",+ }),+ ).toBeDefined();});it("shows the three tiles: downloads on disk, graphics memory in use, loaded now", async () => {@@ -488,7 +509,12 @@ describe("OverviewPanel", () => {expect(screen.getByTestId("role-row-embedding")).toBeDefined();expect(screen.queryByText("local_models.role_voice")).toBeNull();// Compact rows: the model, "not set", no badges, no picker, no Tune.- expect(screen.getByText("qwen3.5:4b", { selector: "span" })).toBeDefined();+ // (Scoped to the ledger: the installed list below names the model too.)+ expect(+ within(screen.getByTestId("roles-ledger")).getByText("qwen3.5:4b", {+ selector: "span",+ }),+ ).toBeDefined();expect(screen.getAllByText("local_models.roles.checklist_not_set").length,).toBe(3);@@ -598,7 +624,97 @@ describe("OverviewPanel", () => {(i as RequestInit)?.method === "POST",).map(([, i]) => JSON.parse(String((i as RequestInit).body)).model);- expect(pulls.sort()).toEqual(["qwen3-embedding:4b", "qwen3.8:27b"]);+ // Every role's own pick is fetched — nothing falls back to the chat pick.+ expect(pulls.sort()).toEqual([+ "qwen3-embedding:4b",+ "qwen3.5:4b",+ "qwen3.8:27b",+ ]);+ await screen.findByText("local_models.overview.setup_done");+ });++ it("'Set up everything' keeps a role on its pick, writes the rest, then offers the brain switch", async () => {+ const fetchMock = installFetchMock({+ roles: ROLES.map((r) =>+ r.id === "tools_screen"+ ? { ...r, current: "qwen3.5:4b", installed: true }+ : r,+ ),+ });+ mockProviders.providers = [+ { id: "ollama", label: "Ollama", tier: "brain", active: false },+ { id: "openrouter", label: "OpenRouter", tier: "brain", active: true },+ ];+ renderPanel();++ await screen.findByTestId("overview-actions");+ fireEvent.click(+ screen.getByRole("button", { name: "local_models.overview.action_setup" }),+ );++ const progress = await screen.findByTestId("setup-progress");+ await screen.findByText("local_models.overview.setup_done");+ // Chat moved to the recommended download, tools & screen kept its pick.+ expect(progress.textContent).toContain(+ "local_models.overview.setup_assignedlocal_models.role_chat|qwen3.8:27b",+ );+ expect(progress.textContent).toContain(+ "local_models.overview.setup_kept_one",+ );+ const puts = fetchMock.mock.calls+ .filter(+ ([u, i]) =>+ String(u).startsWith(`${BASE}/roles/`) &&+ (i as RequestInit)?.method === "PUT",+ )+ .map(([u]) => String(u).split("/").pop());+ expect(puts.sort()).toEqual(["chat", "deep", "embedding"]);++ // Another brain answers: the one decision left is offered in place.+ fireEvent.click(+ screen.getByRole("button", {+ name: "local_models.overview.setup_brain_buttonOllama",+ }),+ );+ await screen.findByTestId("setup-brain-done");+ expect(+ fetchMock.mock.calls.some(+ ([u, i]) =>+ String(u) === "/api/brain/switch" &&+ (i as RequestInit)?.method === "POST",+ ),+ ).toBe(true);+ expect(mockProviders.refetch).toHaveBeenCalled();+ });++ it("lists every installed model with what uses it and what it is recommended for", async () => {+ installFetchMock({+ models: [{ name: "qwen3.5:4b" }, { name: "qwen3-embedding:4b" }],+ roles: ROLES.map((r) =>+ r.id === "embedding"+ ? { ...r, recommended: "qwen3-embedding:4b" }+ : r,+ ),+ });+ const onManage = vi.fn();+ renderPanel({ onManage });++ const list = await screen.findByTestId("local-models-installed");+ await screen.findByTestId("installed-qwen3.5:4b");+ expect(list.textContent).toContain("local_models.installed.subtitle2|");+ // Each line says which roles it is the pick for (the fixture's rows+ // carry no used_by, so the markers are the recommendations).+ expect(+ screen.getByTestId("installed-recommended-qwen3.5:4b").textContent,+ ).toContain("local_models.role_tools_screen, local_models.role_deep");+ expect(+ screen.getByTestId("installed-recommended-qwen3-embedding:4b").textContent,+ ).toContain("local_models.role_embedding");++ fireEvent.click(+ screen.getByRole("button", { name: "local_models.installed.manage" }),+ );+ expect(onManage).toHaveBeenCalledTimes(1);});it("names the active brain when it is not the local server", async () => {diff --git a/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.tsx b/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.tsxindex 8d55eb4071..8181b01f3a 100644--- a/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.tsx+++ b/jarvis/ui/web/frontend/src/views/local-models/OverviewPanel.tsx@@ -4,24 +4,27 @@** Top to bottom: one status sentence ("Ollama 0.32 running · 16 GB graphics* memory · Ollama is not your active brain (OpenRouter answers)"), the- * primary action (Browse models), the headline tiles (downloads on disk,- * graphics memory, loaded now), and the roles as a checklist. Nothing here- * writes; the roles part is `RolesPanel`, mounted underneath so the- * integration wires one component.+ * actions — "Set up everything" first (the one click that starts the server,+ * fills every role with the best installed download and fetches only what+ * is missing; `useLocalSetup`), then "Browse models" — with the flow's+ * progress line underneath, the headline tiles (downloads on disk, graphics+ * memory, loaded now), the roles as a checklist, and every installed model+ * as one line (`InstalledPanel`), so "what do I have?" never needs the+ * Advanced switch.** Props take `providerId` — the id of the card that declares* `supports_model_pull` — never a provider name.*/-import { useEffect, useRef, type ReactNode } from "react";-import { Cpu, HardDrive, Layers, Search } from "lucide-react";+import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";+import { Cpu, HardDrive, Layers, Loader2, Search, Sparkles } from "lucide-react";import {SoftButton,StatTile,StatusDot,} from "@/components/extensions/primitives";-import { useOverview } from "@/hooks/useLocalModels";-import { useProviders } from "@/hooks/useProviders";+import { useOverview, type LocalModelRole } from "@/hooks/useLocalModels";+import { switchBrainProvider, useProviders } from "@/hooks/useProviders";import { fill, useT } from "@/i18n";import {LOCAL_MODELS_MARK_FIRST_DATA,@@ -29,12 +32,17 @@ import {} from "@/lib/localModelsPerf";import { cn } from "@/lib/utils";+import { InstalledPanel } from "./InstalledPanel";import { formatExpiry } from "./localModelsFormat";+import type { SetupStep, SetupSummary } from "./localSetup";import { RolesPanel, type RolesPanelProps } from "./RolesPanel";+import { useLocalSetup } from "./useLocalSetup";export interface OverviewPanelProps extends RolesPanelProps {/** Opens the catalogue ("Browse models"); the button hides without it. */onBrowse?: () => void;+ /** Opens the full installed ledger (Advanced → Models). */+ onManage?: () => void;/*** Detail level. The switch beside the rail must change what is on screen* HERE too, or it reads as a dead control: Simple keeps the roles a@@ -56,11 +64,13 @@ export function OverviewPanel({onTune,onOpenApiKeys,onBrowse,+ onManage,advanced = false,}: OverviewPanelProps) {const t = useT();const overview = useOverview(providerId);- const { providers } = useProviders();+ const { providers, refetch: refetchProviders } = useProviders();+ const setup = useLocalSetup(providerId);// One round-trip (or the painted snapshot) feeds every tile.const s = overview.data?.server;@@ -136,6 +146,8 @@ export function OverviewPanel({// The third clause only renders once the provider list is here — no gate.const activeBrain =providers.find((p) => p.tier === "brain" && p.active) ?? null;+ const otherBrainActive =+ activeBrain !== null && activeBrain.id !== providerId;const brainClause = activeBrain? activeBrain.id === providerId? fill(t("local_models.overview.status_brain_active"), {@@ -201,6 +213,28 @@ export function OverviewPanel({busy: "bg-primary animate-pulse",}[serverTone];+ // --- actions ----------------------------------------------------------+ // A server that is not installed gets a button that NAMES the install:+ // the click is the consent the dangerous-flagged install route asks for.+ const needsInstall = Boolean(s && !s.installed && !remote);+ const setupLabel = needsInstall+ ? fill(t("local_models.overview.action_setup_install"), {+ server: serverLabel,+ })+ : t("local_models.overview.action_setup");+ const setupHint = needsInstall+ ? t("local_models.overview.action_setup_install_hint")+ : t("local_models.overview.action_setup_hint");++ const roleRows = overview.data?.roles.roles ?? [];+ const roleLabel = useCallback(+ (role: LocalModelRole) => {+ const row = roleRows.find((r) => r.id === role);+ return t(row?.label_key ?? `local_models.role_${role}`);+ },+ [roleRows, t],+ );+return (<div className="space-y-4" data-testid="local-models-overview-panel"><p@@ -241,22 +275,48 @@ export function OverviewPanel({)}</p>- {onBrowse && (- <div- className="flex flex-wrap gap-2"- role="group"- aria-label={t("local_models.overview.actions_label")}- data-testid="overview-actions"- >+ <div+ className="flex flex-wrap gap-2"+ role="group"+ aria-label={t("local_models.overview.actions_label")}+ data-testid="overview-actions"+ >+ <ActionButton+ primary+ icon={+ setup.busy ? (+ <Loader2 className="h-4 w-4 animate-spin" />+ ) : (+ <Sparkles className="h-4 w-4" />+ )+ }+ label={setupLabel}+ hint={setupHint}+ onClick={setup.run}+ disabled={setup.busy}+ testId="overview-setup"+ />+ {onBrowse && (<ActionButton- primaryicon={<Search className="h-4 w-4" />}label={t("local_models.overview.action_browse")}hint={t("local_models.overview.action_browse_hint")}onClick={onBrowse}/>- </div>- )}+ )}+ </div>++ <SetupProgress+ step={setup.step}+ serverLabel={serverLabel}+ roleLabel={roleLabel}+ otherBrain={otherBrainActive ? (activeBrain?.label ?? "") : ""}+ onSwitchBrain={async () => {+ await switchBrainProvider(providerId);+ await refetchProviders();+ }}+ t={t}+ /><div className="grid grid-cols-1 gap-3 sm:grid-cols-3"><StatTile@@ -290,7 +350,189 @@ export function OverviewPanel({onTune={onTune}onOpenApiKeys={onOpenApiKeys}variant={advanced ? "ledger" : "checklist"}+ onSetup={setup.run}+ setupBusy={setup.busy}/>++ <InstalledPanel+ models={inventory.data?.models ?? []}+ roles={roleRows}+ diskBytes={inventory.data?.disk_bytes ?? s?.disk_bytes ?? 0}+ loading={overview.isLoading}+ error={inventory.data?.error ?? null}+ onManage={onManage}+ />+ </div>+ );+}++/**+ * The set-up flow's one line under the actions: what is happening now, or+ * — once it ended — what was done, in the user's words (role → model), plus+ * the one decision the flow leaves to the user: making this server the+ * active brain when another one answers right now.+ */+function SetupProgress({+ step,+ serverLabel,+ roleLabel,+ otherBrain,+ onSwitchBrain,+ t,+}: {+ step: SetupStep | null;+ serverLabel: string;+ roleLabel: (role: LocalModelRole) => string;+ /** The label of the brain that answers instead of this server; "" = none. */+ otherBrain: string;+ onSwitchBrain: () => Promise<void>;+ t: (key: string) => string;+}) {+ const [brain, setBrain] = useState<+ { state: "idle" } | { state: "switching" } | { state: "done" } | { state: "error"; message: string }+ >({ state: "idle" });+ // A new run resets the brain line.+ useEffect(() => {+ if (step && step.phase !== "done") setBrain({ state: "idle" });+ }, [step]);+ if (!step) return null;+ const k = (key: string) => t(`local_models.overview.${key}`);++ let tone: "busy" | "ok" | "error" = "busy";+ let text = "";+ let summary: SetupSummary | undefined;+ switch (step.phase) {+ case "planning":+ text = k("setup_planning");+ break;+ case "server": {+ const pct =+ typeof step.percent === "number" && step.action === "installing"+ ? ` ${Math.round(step.percent)} %`+ : "";+ text =+ `${fill(+ k(+ step.action === "starting"+ ? "setup_server_starting"+ : "setup_server_installing",+ ),+ { server: serverLabel },+ )}${pct} ${step.detail ?? ""}`.trim();+ break;+ }+ case "pulling": {+ const pct =+ typeof step.percent === "number" ? `${Math.round(step.percent)} %` : "";+ text = `${fill(k("setup_pulling"), { model: step.model })} ${pct} ${+ step.message ?? ""+ }`.trim();+ break;+ }+ case "assigning":+ text = fill(k("setup_assigning"), {+ role: roleLabel(step.role),+ model: step.model,+ });+ break;+ case "tuning":+ text = fill(k("setup_tuning"), { model: step.model });+ break;+ case "error":+ tone = "error";+ text = fill(k("setup_error"), { message: step.message });+ summary = step.summary;+ break;+ case "done":+ tone = "ok";+ summary = step.summary;+ text =+ summary.assigned.length === 0 &&+ summary.pulled.length === 0 &&+ !summary.serverStarted+ ? k("setup_done_nothing")+ : k("setup_done");+ break;+ }++ const lines: string[] = [];+ if (summary) {+ if (summary.assigned.length > 0)+ lines.push(+ summary.assigned+ .map((a) =>+ fill(k("setup_assigned"), {+ role: roleLabel(a.role),+ model: a.model,+ }),+ )+ .join(" · "),+ );+ if (summary.kept.length === 1) lines.push(k("setup_kept_one"));+ else if (summary.kept.length > 1)+ lines.push(fill(k("setup_kept"), { count: summary.kept.length }));+ for (const skip of summary.skipped)+ lines.push(+ fill(k("setup_skipped"), {+ role: roleLabel(skip.role),+ reason: skip.note || k("setup_skipped_no_pick"),+ }),+ );+ for (const [model, readback] of Object.entries(summary.readbacks))+ lines.push(`${model}: ${readback}`);+ }++ return (+ <div className="space-y-1 text-xs" data-testid="setup-progress">+ <StatusDot tone={tone} pulse={tone === "busy"} label={text} />+ {lines.map((line, i) => (+ <p key={i} className="ml-4 text-muted-foreground">+ {line}+ </p>+ ))}+ {step.phase === "done" && otherBrain && brain.state !== "done" && (+ <div+ className="ml-4 flex flex-wrap items-center gap-2 text-amber-700 dark:text-amber-400"+ data-testid="setup-brain"+ >+ <span>+ {fill(k("setup_brain_hint"), {+ server: serverLabel,+ brain: otherBrain,+ })}+ </span>+ <SoftButton+ primary+ disabled={brain.state === "switching"}+ onClick={() => {+ setBrain({ state: "switching" });+ onSwitchBrain().then(+ () => setBrain({ state: "done" }),+ (err: unknown) =>+ setBrain({+ state: "error",+ message: err instanceof Error ? err.message : String(err),+ }),+ );+ }}+ >+ {brain.state === "switching" ? (+ <Loader2 className="h-3.5 w-3.5 animate-spin" />+ ) : null}+ {fill(k("setup_brain_button"), { server: serverLabel })}+ </SoftButton>+ {brain.state === "error" && (+ <span className="text-destructive">+ {fill(k("setup_brain_failed"), { message: brain.message })}+ </span>+ )}+ </div>+ )}+ {step.phase === "done" && brain.state === "done" && (+ <p className="ml-4 text-emerald-600 dark:text-emerald-400" data-testid="setup-brain-done">+ {fill(k("setup_brain_switched"), { server: serverLabel })}+ </p>+ )}</div>);}@@ -302,32 +544,39 @@ function ActionButton({hint,onClick,primary,+ disabled,+ testId,}: {icon: ReactNode;label: string;hint: string;onClick: () => void;primary?: boolean;+ disabled?: boolean;+ testId?: string;}) {return (- <SoftButton- primary={primary}- onClick={onClick}- ariaLabel={label}- className="h-11 px-3.5 text-left"- >- <span className="shrink-0">{icon}</span>- <span className="flex min-w-0 flex-col leading-tight">- <span className="text-xs font-medium">{label}</span>- <span- className={cn(- "truncate text-[11px] font-normal",- primary ? "text-primary-foreground/80" : "text-muted-foreground",- )}- >- {hint}+ <span data-testid={testId}>+ <SoftButton+ primary={primary}+ onClick={onClick}+ disabled={disabled}+ ariaLabel={label}+ className="h-11 px-3.5 text-left"+ >+ <span className="shrink-0">{icon}</span>+ <span className="flex min-w-0 flex-col leading-tight">+ <span className="text-xs font-medium">{label}</span>+ <span+ className={cn(+ "truncate text-[11px] font-normal",+ primary ? "text-primary-foreground/80" : "text-muted-foreground",+ )}+ >+ {hint}+ </span></span>- </span>- </SoftButton>+ </SoftButton>+ </span>);}diff --git a/jarvis/ui/web/frontend/src/views/local-models/RolesPanel.tsx b/jarvis/ui/web/frontend/src/views/local-models/RolesPanel.tsxindex c3cf9d3481..668f2fd62a 100644--- a/jarvis/ui/web/frontend/src/views/local-models/RolesPanel.tsx+++ b/jarvis/ui/web/frontend/src/views/local-models/RolesPanel.tsx@@ -8,8 +8,9 @@* models that qualify, and "Use recommended" — which downloads the pick when* it is missing, assigns it, then writes the suggested options silently and* reads back one sentence. The read-only advanced roles hide under- * "More roles". When nothing is installed at all, the ledger collapses into a- * single "Set up the recommended models" button.+ * "More roles". When nothing is installed at all, the ledger shows one+ * "Set up the recommended models" button that runs the overview's set-up+ * flow (`useLocalSetup`).** Two variants: `ledger` (the full rows: picker, badges, Tune) and* `checklist` — one compact line per writable role (dot, label, model or@@ -37,22 +38,20 @@ import {StatusDot,} from "@/components/extensions/primitives";import {- getSuggestedOptions,- modelPullStatus,- saveModelOptions,setRole,- startModelPull,useInvalidateLocalModels,useOverview,useSetRole,type LocalModelRole,type RoleRow,- type SuggestedOptionsResponse,} from "@/hooks/useLocalModels";import { useProviders } from "@/hooks/useProviders";import { fill, useT } from "@/i18n";import { cn } from "@/lib/utils";+import { canonical, waitForPull } from "./localSetup";+import { useSilentTune } from "./useLocalSetup";+export interface RolesPanelProps {/** Id of the pull-capable provider card (found via `supports_model_pull`). */providerId: string;@@ -62,6 +61,10 @@ export interface RolesPanelProps {onOpenApiKeys?: () => void;/** `ledger` = full rows (default); `checklist` = compact rows that expand. */variant?: "ledger" | "checklist";+ /** Runs the overview's "Set up everything" flow (the empty state's button). */+ onSetup?: () => void;+ /** That flow is underway: the empty state's button waits. */+ setupBusy?: boolean;}type Phase = "idle" | "pulling" | "assigning" | "tuning" | "done" | "error";@@ -81,31 +84,6 @@ const WRITABLE: readonly LocalModelRole[] = ["deep","embedding",];-const POLL_MS = 2000;--/** "qwen3.5" and "qwen3.5:latest" are the same download. */-function canonical(name: string): string {- return name.endsWith(":latest") ? name.slice(0, -":latest".length) : name;-}--/** Poll one download until the server reports it done; throws on error. */-async function waitForPull(- providerId: string,- model: string,- onProgress: (p: { percent?: number; message: string }) => void,- alive: () => boolean,-): Promise<void> {- await startModelPull(providerId, model);- for (;;) {- if (!alive()) return;- const pull = await modelPullStatus(providerId, model);- if (pull.state === "done") return;- if (pull.state === "error")- throw new Error(pull.message || "download failed");- onProgress({ percent: pull.percent, message: pull.message });- await new Promise((resolve) => window.setTimeout(resolve, POLL_MS));- }-}/** Human window size: 16384 -> "16k". */function contextLabel(numCtx: number): string {@@ -117,6 +95,8 @@ export function RolesPanel({onTune,onOpenApiKeys,variant = "ledger",+ onSetup,+ setupBusy = false,}: RolesPanelProps) {const t = useT();// Roles and inventory come from the one overview round-trip (painted@@ -135,7 +115,6 @@ export function RolesPanel({const invalidate = useInvalidateLocalModels(providerId);const [progress, setProgress] = useState<Record<string, Progress>>({});- const [setup, setSetup] = useState<Progress>({ phase: "idle" });const [moreOpen, setMoreOpen] = useState(false);// Checklist rows the user expanded into the full ledger row.const [expanded, setExpanded] = useState<Set<string>>(() => new Set());@@ -178,45 +157,13 @@ export function RolesPanel({const otherBrainActive =activeBrain !== null && activeBrain.id !== providerId;- const readbackFor = useCallback(- (s: SuggestedOptionsResponse): string => {- const ctx = s.options.num_ctx;- if (typeof ctx === "number") {- const key =- s.options.num_gpu != null- ? "local_models.roles.readback_gpu"- : "local_models.roles.readback_ctx";- return fill(t(key), { ctx: contextLabel(ctx) });- }- return s.reasons[0] ?? t("local_models.roles.readback_defaults");- },- [t],- );-const patch = useCallback((roleId: string, next: Progress) => {if (!mounted.current) return;setProgress((prev) => ({ ...prev, [roleId]: next }));}, []);/** Suggested options in, one sentence out. Never fails the flow. */- const tuneSilently = useCallback(- async (model: string): Promise<string> => {- try {- const suggested = await getSuggestedOptions(providerId, model);- await saveModelOptions(providerId, model, suggested.options);- return readbackFor(suggested);- } catch (err) {- // The slot is already assigned; a failed tune only loses the readback.- console.warn(- "[local-models] suggested options not applied",- model,- err,- );- return t("local_models.roles.tune_skipped");- }- },- [providerId, readbackFor, t],- );+ const tuneSilently = useSilentTune(providerId);const useRecommended = useCallback(async (row: RoleRow) => {@@ -250,68 +197,10 @@ export function RolesPanel({[alive, invalidate, isInstalled, patch, providerId, tuneSilently],);- /** Empty state: the chat pick and the embedding pick, then all four rows. */- const setupRecommended = useCallback(async () => {- const byId = new Map(primary.map((r) => [r.id, r]));- const chatPick = byId.get("chat")?.recommended ?? "";- const embedPick = byId.get("embedding")?.recommended ?? "";- const pulls = Array.from(new Set([chatPick, embedPick].filter(Boolean)));- if (pulls.length === 0) return;- const setSafe = (next: Progress) => {- if (mounted.current) setSetup(next);- };- try {- for (const model of pulls) {- if (isInstalled(model)) continue;- setSafe({ phase: "pulling", percent: 0, message: model });- await waitForPull(- providerId,- model,- (p) =>- setSafe({- phase: "pulling",- percent: p.percent,- message: `${model} ${p.message}`.trim(),- }),- alive,- );- if (!alive()) return;- }- setSafe({ phase: "assigning" });- const readbacks: string[] = [];- for (const roleId of WRITABLE) {- const row = byId.get(roleId);- if (!row) continue;- const fallback = roleId === "embedding" ? embedPick : chatPick;- const model =- row.recommended && pulls.includes(row.recommended)- ? row.recommended- : fallback;- if (!model) continue;- await setRole(providerId, roleId, model);- }- setSafe({ phase: "tuning" });- for (const model of pulls)- readbacks.push(`${model}: ${await tuneSilently(model)}`);- setSafe({ phase: "done", readback: readbacks.join(" ") });- } catch (err) {- setSafe({- phase: "error",- message: err instanceof Error ? err.message : String(err),- });- } finally {- invalidate();- }- }, [alive, invalidate, isInstalled, primary, providerId, tuneSilently]);-const nothingInstalled =inventory.data !== undefined &&!inventory.data.error &&inventory.data.models.length === 0;- const busy =- setup.phase === "pulling" ||- setup.phase === "assigning" ||- setup.phase === "tuning";return (<Panel className="p-4">@@ -359,7 +248,7 @@ export function RolesPanel({</p>)}- {nothingInstalled && rows.length > 0 && (+ {nothingInstalled && rows.length > 0 && onSetup && (<divclassName="rounded-lg border border-dashed border-border px-6 py-8 text-center"data-testid="roles-empty"@@ -368,12 +257,8 @@ export function RolesPanel({{t("local_models.roles.empty_body")}</p><div className="mt-4 flex justify-center">- <SoftButton- primary- onClick={() => void setupRecommended()}- disabled={busy}- >- {busy ? (+ <SoftButton primary onClick={onSetup} disabled={setupBusy}>+ {setupBusy ? (<Loader2 className="h-3.5 w-3.5 animate-spin" />) : (<Sparkles className="h-3.5 w-3.5" />@@ -381,11 +266,6 @@ export function RolesPanel({{t("local_models.roles.setup_button")}</SoftButton></div>- <ProgressLine- progress={setup}- t={t}- className="mt-3 justify-center"- /></div>)}@@ -623,6 +503,18 @@ function RoleLedgerRow({{t("local_models.roles.read_only")}</span>)}+ {canUseRecommended && row.recommended_reason && (+ <p+ className="mt-1 text-xs text-muted-foreground"+ data-testid="role-recommended-reason"+ >+ <span className="font-mono text-foreground/85">+ {row.recommended}+ </span>+ {" — "}+ {row.recommended_reason}+ </p>+ )}</div><div className="flex items-center gap-1.5 lg:justify-end">diff --git a/jarvis/ui/web/frontend/src/views/local-models/localSetup.test.ts b/jarvis/ui/web/frontend/src/views/local-models/localSetup.test.tsnew file mode 100644index 0000000000..7cecbe97b3--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/local-models/localSetup.test.ts@@ -0,0 +1,301 @@+/**+ * The "Set up everything" flow against a faked fetch: the plan (installed+ * first, kept picks, skipped slots, one download per missing model), the+ * server step (a stopped local server is started before the plan is read),+ * and the writes (one PUT per role, one tune per model, a refused slot does+ * not stop the rest).+ */+import { afterEach, describe, expect, it, vi } from "vitest";++import type { OverviewResponse, RoleRow } from "@/hooks/useLocalModels";++import { planRoles, runLocalSetup, type SetupStep } from "./localSetup";++const BASE = "/api/providers/ollama/local-models";++function role(overrides: Partial<RoleRow> & { id: RoleRow["id"] }): RoleRow {+ return {+ label_key: `local_models.role_${overrides.id}`,+ config_key: "",+ current: "",+ installed: false,+ required: [],+ recommended_capabilities: [],+ qualifying: [],+ recommended: "",+ recommended_reason: "",+ writable: true,+ advanced: false,+ note: "",+ ...overrides,+ };+}++function overview(+ roles: RoleRow[],+ models: string[],+ server: Partial<OverviewResponse["server"]> = {},+): OverviewResponse {+ return {+ server: {+ installed: true,+ binary: "ollama",+ running: true,+ version: "0.32.15",+ detail: "",+ base_url: "http://127.0.0.1:11434",+ host_kind: "local",+ models_dir: "",+ running_models: [],+ disk_bytes: 0,+ loaded_vram_bytes: 0,+ error: null,+ ...server,+ },+ roles: { provider: "ollama", server: "", roles, error: null },+ inventory: {+ provider: "ollama",+ server: "",+ models: models.map((name) => ({+ name,+ size_bytes: 1,+ digest: "",+ modified_at: "",+ family: "",+ parameter_size: "",+ quantization_level: "",+ context_length: null,+ capabilities: ["completion"],+ license: "",+ probed: true,+ used_by: [],+ loaded: false,+ size_vram_bytes: 0,+ expires_at: "",+ running_context_length: null,+ })),+ running: [],+ disk_bytes: 0,+ loaded_vram_bytes: 0,+ error: null,+ },+ recommended: {+ server: "",+ server_reachable: true,+ message: "",+ memory_gb: 32,+ accelerator_gb: 16,+ accelerator_source: "nvidia-smi",+ roles: ["chat", "vision", "coder", "embedding"],+ curated_reviewed_on: "2026-08-24",+ models: [],+ installed: [],+ },+ source: "live",+ fetched_at: 1_700_000_000,+ };+}++const ROLES: RoleRow[] = [+ role({+ id: "chat",+ current: "gemma4:12b-it-qat",+ installed: true,+ recommended: "gemma4:12b-it-qat",+ }),+ role({ id: "voice", current: "qwen3.5:4b", installed: true, recommended: "ornith:9b" }),+ role({ id: "tools_screen", recommended: "qwen3.5:4b" }),+ role({ id: "deep", recommended: "ornith:9b" }),+ role({+ id: "embedding",+ note: "The wiki embeds with openai, not with Ollama.",+ }),+ role({ id: "ack", writable: false, advanced: true, recommended: "qwen3.5:4b" }),+];++describe("planRoles", () => {+ it("keeps a role on its pick, assigns the rest, skips what is served elsewhere, downloads once", () => {+ const plan = planRoles(overview(ROLES, ["gemma4:12b-it-qat", "qwen3.5:4b"]));+ expect(plan.kept).toEqual([{ role: "chat", model: "gemma4:12b-it-qat" }]);+ expect(plan.assign).toEqual([+ { role: "voice", model: "ornith:9b" },+ { role: "tools_screen", model: "qwen3.5:4b" },+ { role: "deep", model: "ornith:9b" },+ ]);+ expect(plan.skipped).toEqual([+ { role: "embedding", note: "The wiki embeds with openai, not with Ollama." },+ ]);+ // ornith:9b is wanted twice and missing once; qwen3.5:4b is on disk.+ expect(plan.pulls).toEqual(["ornith:9b"]);+ });++ it("treats ':latest' as the same download and a missing pick as a skip", () => {+ const plan = planRoles(+ overview(+ [+ role({ id: "chat", current: "qwen3.5", installed: true, recommended: "qwen3.5:latest" }),+ role({ id: "deep" }),+ ],+ ["qwen3.5:latest"],+ ),+ );+ expect(plan.kept).toEqual([{ role: "chat", model: "qwen3.5:latest" }]);+ expect(plan.assign).toEqual([]);+ expect(plan.skipped).toEqual([{ role: "deep", note: "" }]);+ });+});++interface Script {+ overviews: OverviewResponse[];+ refuse?: string;+}++function installFetch(script: Script) {+ let reads = 0;+ const calls: string[] = [];+ const ok = (body: unknown) =>+ ({ ok: true, status: 200, json: async () => body }) as Response;+ const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {+ const url = String(input);+ const method = init?.method ?? "GET";+ calls.push(`${method} ${url}`);+ if (url === `${BASE}/overview?fresh=1`) {+ const body = script.overviews[Math.min(reads, script.overviews.length - 1)];+ reads += 1;+ return ok(body);+ }+ if (url === "/api/providers/ollama/ollama-runtime/start" && method === "POST")+ return ok({ ok: true, detail: "started", status: { running: true } });+ if (url.startsWith(`${BASE}/roles/`) && method === "PUT") {+ const roleId = url.split("/").pop();+ if (roleId === script.refuse)+ return {+ ok: false,+ status: 422,+ json: async () => ({ detail: "Install the managed voice server first." }),+ } as Response;+ return ok({ ok: true, role: roleId, model: "", config_key: "", message: "" });+ }+ if (url === "/api/providers/ollama/pull" && method === "POST")+ return ok({ state: "running", model: "", message: "" });+ if (url.startsWith("/api/providers/ollama/pull/status"))+ return ok({ state: "done", model: "", message: "", percent: 100 });+ throw new Error(`unexpected fetch: ${method} ${url}`);+ });+ vi.stubGlobal("fetch", fetchMock);+ return { calls };+}++afterEach(() => {+ vi.unstubAllGlobals();+});++describe("runLocalSetup", () => {+ it("downloads what is missing, writes each role once, tunes each model once", async () => {+ const { calls } = installFetch({+ overviews: [overview(ROLES, ["gemma4:12b-it-qat", "qwen3.5:4b"])],+ });+ const steps: SetupStep[] = [];+ const tuned: string[] = [];+ const summary = await runLocalSetup({+ providerId: "ollama",+ report: (s) => steps.push(s),+ alive: () => true,+ tune: async (model) => {+ tuned.push(model);+ return `${model} tuned`;+ },+ pollMs: 0,+ });+ expect(summary.serverStarted).toBe(false);+ expect(summary.pulled).toEqual(["ornith:9b"]);+ expect(summary.assigned.map((a) => a.role)).toEqual(["voice", "tools_screen", "deep"]);+ expect(summary.kept).toEqual([{ role: "chat", model: "gemma4:12b-it-qat" }]);+ expect(summary.skipped).toHaveLength(1);+ // ornith:9b serves two roles and is tuned once.+ expect(tuned).toEqual(["ornith:9b", "qwen3.5:4b"]);+ expect(summary.readbacks).toEqual({+ "ornith:9b": "ornith:9b tuned",+ "qwen3.5:4b": "qwen3.5:4b tuned",+ });+ expect(calls.filter((c) => c.startsWith("PUT"))).toEqual([+ `PUT ${BASE}/roles/voice`,+ `PUT ${BASE}/roles/tools_screen`,+ `PUT ${BASE}/roles/deep`,+ ]);+ expect(calls).not.toContain("POST /api/providers/ollama/ollama-runtime/start");+ expect(steps.at(-1)?.phase).toBe("done");+ // One download, three writes, two tunes (ornith:9b serves two roles).+ expect(steps.map((s) => s.phase)).toEqual([+ "planning",+ "pulling",+ "assigning",+ "tuning",+ "assigning",+ "tuning",+ "assigning",+ "done",+ ]);+ });++ it("starts a stopped local server first and reads the plan from the server that answers", async () => {+ const stopped = overview([], [], { running: false, installed: true });+ const running = overview(+ [role({ id: "chat", recommended: "qwen3.5:4b" })],+ ["qwen3.5:4b"],+ );+ const { calls } = installFetch({ overviews: [stopped, running] });+ const summary = await runLocalSetup({+ providerId: "ollama",+ report: () => undefined,+ alive: () => true,+ tune: async () => "",+ pollMs: 0,+ });+ expect(summary.serverStarted).toBe(true);+ expect(calls.indexOf("POST /api/providers/ollama/ollama-runtime/start")).toBeLessThan(+ calls.lastIndexOf(`GET ${BASE}/overview?fresh=1`),+ );+ expect(summary.assigned).toEqual([{ role: "chat", model: "qwen3.5:4b" }]);+ });++ it("stops with the backend's sentence when a remote server does not answer", async () => {+ installFetch({+ overviews: [+ overview([], [], {+ running: false,+ host_kind: "remote",+ error: "The server at http://box:11434 did not answer.",+ }),+ ],+ });+ await expect(+ runLocalSetup({+ providerId: "ollama",+ report: () => undefined,+ alive: () => true,+ tune: async () => "",+ pollMs: 0,+ }),+ ).rejects.toThrow("did not answer");+ });++ it("a refused slot is skipped with its reason and the other roles still land", async () => {+ installFetch({+ overviews: [overview(ROLES, ["gemma4:12b-it-qat", "qwen3.5:4b", "ornith:9b"])],+ refuse: "voice",+ });+ const summary = await runLocalSetup({+ providerId: "ollama",+ report: () => undefined,+ alive: () => true,+ tune: async () => "",+ pollMs: 0,+ });+ expect(summary.assigned.map((a) => a.role)).toEqual(["tools_screen", "deep"]);+ expect(summary.skipped).toContainEqual({+ role: "voice",+ note: "Install the managed voice server first.",+ });+ });+});diff --git a/jarvis/ui/web/frontend/src/views/local-models/localSetup.ts b/jarvis/ui/web/frontend/src/views/local-models/localSetup.tsnew file mode 100644index 0000000000..25ed6e3bb5--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/local-models/localSetup.ts@@ -0,0 +1,301 @@+/**+ * "Set up everything" — the one-click flow behind the Local models overview,+ * written as a pure async function so it can be tested against a faked+ * `fetch` and driven from a hook (`useLocalSetup`).+ *+ * The steps, in order, each reported through `report`:+ *+ * 1. server — the overview is read LIVE. A local server that is installed+ * but stopped is started; one that is not installed is+ * installed (the button that starts this flow names the+ * install, so the click is the consent) and then started; a+ * remote server that does not answer stops the flow with the+ * backend's sentence.+ * 2. plan — the roles' recommendations are read from that live overview,+ * so they come from what is on the server NOW: the best+ * installed download per role, a download only where nothing+ * installed qualifies.+ * 3. pull — every recommended model that is missing is downloaded once.+ * 4. assign — each writable role that is not already on its pick is set.+ * 5. tune — the suggested options are written for every model assigned.+ *+ * A role that is served elsewhere (the wiki embedding on a cloud provider,+ * the voice server not installed) or has no pick is skipped and named in+ * the summary; a role whose write fails is skipped with the reason and the+ * flow goes on — one refused slot must not undo the other four.+ *+ * Nothing here touches react-query or i18n: the caller repaints and renders+ * the sentences.+ */+import {+ ollamaRuntime,+ ollamaRuntimeInstall,+ ollamaRuntimeStart,+} from "@/hooks/useProviders";+import {+ getOverview,+ modelPullStatus,+ setRole,+ startModelPull,+ type LocalModelRole,+ type OverviewResponse,+ type RoleRow,+} from "@/hooks/useLocalModels";++/** The five slots the flow writes, in the order the rows show them. */+export const SETUP_ROLES: readonly LocalModelRole[] = [+ "chat",+ "voice",+ "tools_screen",+ "deep",+ "embedding",+];++export type SetupStep =+ | {+ phase: "server";+ action: "starting" | "installing";+ percent?: number;+ detail?: string;+ }+ | { phase: "planning" }+ | { phase: "pulling"; model: string; percent?: number; message?: string }+ | { phase: "assigning"; role: LocalModelRole; model: string }+ | { phase: "tuning"; model: string }+ | { phase: "done"; summary: SetupSummary }+ | { phase: "error"; message: string; summary?: SetupSummary };++export interface SetupSummary {+ /** Roles written in this run, in order. */+ assigned: Array<{ role: LocalModelRole; model: string }>;+ /** Roles that were already on their pick. */+ kept: Array<{ role: LocalModelRole; model: string }>;+ /** Roles left alone; `note` is the backend's sentence, "" = no pick. */+ skipped: Array<{ role: LocalModelRole; note: string }>;+ /** Models downloaded in this run. */+ pulled: string[];+ /** One readback sentence per model tuned. */+ readbacks: Record<string, string>;+ /** The server was started (or installed and started) by this run. */+ serverStarted: boolean;+}++export interface RunLocalSetupOptions {+ providerId: string;+ report: (step: SetupStep) => void;+ /** False once the caller unmounted; the flow then stops writing. */+ alive: () => boolean;+ /** Writes the suggested options for one model; answers the readback. */+ tune: (model: string) => Promise<string>;+ /** Milliseconds between polls of a download or an install (tests: 0). */+ pollMs?: number;+}++/** "qwen3.5" and "qwen3.5:latest" are the same download. */+export function canonical(name: string): string {+ return name.endsWith(":latest") ? name.slice(0, -":latest".length) : name;+}++function sleep(ms: number): Promise<void> {+ return new Promise((resolve) => window.setTimeout(resolve, ms));+}++/** Poll one download until the server reports it done; throws on error. */+export async function waitForPull(+ providerId: string,+ model: string,+ onProgress: (p: { percent?: number; message: string }) => void,+ alive: () => boolean,+ pollMs = 2000,+): Promise<void> {+ await startModelPull(providerId, model);+ for (;;) {+ if (!alive()) return;+ const pull = await modelPullStatus(providerId, model);+ if (pull.state === "done") return;+ if (pull.state === "error")+ throw new Error(pull.message || "download failed");+ onProgress({ percent: pull.percent, message: pull.message });+ await sleep(pollMs);+ }+}++/** Install the runtime and wait for the installer to finish; throws on error. */+async function installRuntime(+ providerId: string,+ report: (step: SetupStep) => void,+ alive: () => boolean,+ pollMs: number,+): Promise<void> {+ const first = await ollamaRuntimeInstall(providerId);+ if (first.phase === "error" || (first.started === false && first.error))+ throw new Error(first.error || first.message || "install failed");+ report({+ phase: "server",+ action: "installing",+ percent: first.percent,+ detail: first.detail,+ });+ for (;;) {+ if (!alive()) return;+ const { install } = await ollamaRuntime(providerId);+ if (!install.running) {+ if (install.phase === "error")+ throw new Error(install.error || "install failed");+ return;+ }+ report({+ phase: "server",+ action: "installing",+ percent: install.percent,+ detail: install.detail,+ });+ await sleep(pollMs);+ }+}++/**+ * Make sure the server answers; returns true when this run started it.+ * A remote server is only checked — nothing can be started there.+ */+async function ensureServer(+ overview: OverviewResponse,+ providerId: string,+ report: (step: SetupStep) => void,+ alive: () => boolean,+ pollMs: number,+): Promise<boolean> {+ const s = overview.server;+ if (s.running) return false;+ if (s.host_kind === "remote")+ throw new Error(+ s.error || s.detail || `The server at ${s.base_url} does not answer.`,+ );+ if (!s.installed) {+ await installRuntime(providerId, report, alive, pollMs);+ if (!alive()) return false;+ }+ report({ phase: "server", action: "starting" });+ await ollamaRuntimeStart(providerId);+ return true;+}++/** The plan: which role gets which model, what is missing, what is kept. */+export function planRoles(overview: OverviewResponse): {+ assign: Array<{ role: LocalModelRole; model: string }>;+ kept: SetupSummary["kept"];+ skipped: SetupSummary["skipped"];+ pulls: string[];+} {+ const installed = new Set(+ overview.inventory.models.map((m) => canonical(m.name)),+ );+ const byId = new Map<string, RoleRow>(+ overview.roles.roles.map((r) => [r.id, r]),+ );+ const assign: Array<{ role: LocalModelRole; model: string }> = [];+ const kept: SetupSummary["kept"] = [];+ const skipped: SetupSummary["skipped"] = [];+ const pulls: string[] = [];+ for (const role of SETUP_ROLES) {+ const row = byId.get(role);+ if (!row || !row.writable) continue;+ // Served by something other than this server (the note says what):+ // that is a choice the user made elsewhere, not a gap to fill.+ if (row.note && !row.current) {+ skipped.push({ role, note: row.note });+ continue;+ }+ const model = row.recommended;+ if (!model) {+ skipped.push({ role, note: "" });+ continue;+ }+ if (row.current && canonical(row.current) === canonical(model) && row.installed) {+ kept.push({ role, model });+ continue;+ }+ assign.push({ role, model });+ if (!installed.has(canonical(model)) && !pulls.includes(model))+ pulls.push(model);+ }+ return { assign, kept, skipped, pulls };+}++export async function runLocalSetup({+ providerId,+ report,+ alive,+ tune,+ pollMs = 2000,+}: RunLocalSetupOptions): Promise<SetupSummary> {+ const summary: SetupSummary = {+ assigned: [],+ kept: [],+ skipped: [],+ pulled: [],+ readbacks: {},+ serverStarted: false,+ };+ report({ phase: "planning" });+ let overview = await getOverview(providerId, true);+ if (!alive()) return summary;+ summary.serverStarted = await ensureServer(+ overview,+ providerId,+ report,+ alive,+ pollMs,+ );+ if (!alive()) return summary;+ if (summary.serverStarted) {+ // The recommendations must come from the server that now answers.+ report({ phase: "planning" });+ overview = await getOverview(providerId, true);+ if (!alive()) return summary;+ }+ if (overview.inventory.error)+ throw new Error(overview.inventory.error);++ const plan = planRoles(overview);+ summary.kept = plan.kept;+ summary.skipped = plan.skipped;++ for (const model of plan.pulls) {+ report({ phase: "pulling", model, percent: 0, message: "" });+ await waitForPull(+ providerId,+ model,+ (p) => report({ phase: "pulling", model, ...p }),+ alive,+ pollMs,+ );+ if (!alive()) return summary;+ summary.pulled.push(model);+ }++ const tuned = new Set<string>();+ for (const { role, model } of plan.assign) {+ report({ phase: "assigning", role, model });+ try {+ await setRole(providerId, role, model);+ } catch (err) {+ // One refused slot (a voice server that is not installed, a write the+ // config guard turned down) must not undo the other four.+ summary.skipped.push({+ role,+ note: err instanceof Error ? err.message : String(err),+ });+ continue;+ }+ if (!alive()) return summary;+ summary.assigned.push({ role, model });+ if (tuned.has(model)) continue;+ tuned.add(model);+ report({ phase: "tuning", model });+ summary.readbacks[model] = await tune(model);+ if (!alive()) return summary;+ }+ report({ phase: "done", summary });+ return summary;+}diff --git a/jarvis/ui/web/frontend/src/views/local-models/useLocalSetup.ts b/jarvis/ui/web/frontend/src/views/local-models/useLocalSetup.tsnew file mode 100644index 0000000000..c8d8fcc444--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/local-models/useLocalSetup.ts@@ -0,0 +1,117 @@+/**+ * The React side of "Set up everything": one hook that runs `runLocalSetup`+ * once at a time, keeps the current step in state for the progress line,+ * survives a tab switch (nothing is written to state after unmount) and+ * repaints the section when the run ends — however it ends.+ *+ * `useSilentTune` is the tune step on its own, shared with the per-row+ * "Use recommended" button: the suggested options go in, one readback+ * sentence comes out, and a failed tune never fails the flow — the role is+ * already assigned, only the sentence is lost.+ */+import { useCallback, useEffect, useRef, useState } from "react";++import {+ getSuggestedOptions,+ saveModelOptions,+ useInvalidateLocalModels,+ type SuggestedOptionsResponse,+} from "@/hooks/useLocalModels";+import { fill, useT } from "@/i18n";++import { formatContext } from "./localModelsFormat";+import { runLocalSetup, type SetupStep } from "./localSetup";++/** The one-sentence readback after a silent tune. */+export function readbackFor(+ s: SuggestedOptionsResponse,+ t: (key: string) => string,+): string {+ const ctx = s.options.num_ctx;+ if (typeof ctx === "number") {+ const key =+ s.options.num_gpu != null+ ? "local_models.roles.readback_gpu"+ : "local_models.roles.readback_ctx";+ return fill(t(key), { ctx: formatContext(ctx) });+ }+ return s.reasons[0] ?? t("local_models.roles.readback_defaults");+}++/** Suggested options in, one sentence out. Never throws. */+export function useSilentTune(providerId: string) {+ const t = useT();+ return useCallback(+ async (model: string): Promise<string> => {+ try {+ const suggested = await getSuggestedOptions(providerId, model);+ await saveModelOptions(providerId, model, suggested.options);+ return readbackFor(suggested, t);+ } catch (err) {+ console.warn(+ "[local-models] suggested options not applied",+ model,+ err,+ );+ return t("local_models.roles.tune_skipped");+ }+ },+ [providerId, t],+ );+}++export interface LocalSetupState {+ /** Starts a run; a second call while one runs is ignored. */+ run: () => void;+ /** The current step, `null` before the first run. */+ step: SetupStep | null;+ /** A run is underway. */+ busy: boolean;+ /** Clears a finished run's line. */+ reset: () => void;+}++export function useLocalSetup(providerId: string): LocalSetupState {+ const [step, setStep] = useState<SetupStep | null>(null);+ const running = useRef(false);+ const mounted = useRef(true);+ useEffect(() => {+ mounted.current = true;+ return () => {+ mounted.current = false;+ };+ }, []);+ const alive = useCallback(() => mounted.current, []);+ const invalidate = useInvalidateLocalModels(providerId);+ const tune = useSilentTune(providerId);++ const run = useCallback(() => {+ if (running.current) return;+ running.current = true;+ const report = (next: SetupStep) => {+ if (mounted.current) setStep(next);+ };+ report({ phase: "planning" });+ void (async () => {+ try {+ await runLocalSetup({ providerId, report, alive, tune });+ } catch (err) {+ report({+ phase: "error",+ message: err instanceof Error ? err.message : String(err),+ });+ } finally {+ running.current = false;+ invalidate();+ }+ })();+ }, [alive, invalidate, providerId, tune]);++ const reset = useCallback(() => {+ if (!running.current) setStep(null);+ }, []);++ const busy =+ step !== null && step.phase !== "done" && step.phase !== "error";+ return { run, step, busy, reset };+}diff --git a/jarvis/ui/web/local_models_routes.py b/jarvis/ui/web/local_models_routes.pyindex 478a72be08..dd07fd29ce 100644--- a/jarvis/ui/web/local_models_routes.py+++ b/jarvis/ui/web/local_models_routes.py@@ -125,6 +125,11 @@ class DeleteResponse(BaseModel):# ── Helpers ──────────────────────────────────────────────────────────────+def _forget_overview() -> None:+ """Drop the memoised overview after a write, so the next paint is honest."""+ ollama_overview.forget(_server_root())++def _server_root() -> str:from jarvis.brain.ollama_pull import server_root@@ -221,6 +226,7 @@ async def unload_inventory_model(provider_id: str, name: str) -> UnloadResponse:await inventory.unload_model(root, name)except OllamaServerError as exc:raise _http_error(exc) from exc+ _forget_overview()return UnloadResponse(ok=True,model=name,@@ -285,6 +291,7 @@ async def delete_inventory_model(await inventory.delete_model(root, name)except OllamaServerError as exc:raise _http_error(exc) from exc+ _forget_overview()message = f"{name} was deleted from the server."if reassigned:message += f" {', '.join(reassigned)} now use {target}."@@ -336,8 +343,12 @@ class RoleRow(BaseModel):recommended_capabilities: list[str]#: Installed tags declaring every required capability.qualifying: list[str]- #: The shortlist's pick for this machine (``""`` when it has none).+ #: The pick for this machine — the best qualifying INSTALLED download,+ #: or the shortlist's download when nothing installed qualifies (``""``+ #: when neither has one).recommended: str+ #: One sentence saying why ``recommended`` is the pick (``""`` when none).+ recommended_reason: str = ""writable: booladvanced: bool#: One sentence when the slot is served by something other than Ollama.@@ -393,6 +404,7 @@ async def set_role(except Exception as exc: # noqa: BLE001 — a failed TOML write is a 500 with the reasonlog.warning("local-models: role %s -> %s failed: %s", role, body.model, exc)raise HTTPException(status_code=500, detail=f"Could not save the role: {exc}") from exc+ _forget_overview()tag = written["model"]message = (f"{role} now uses {tag}."@@ -518,6 +530,7 @@ async def put_model_options(provider.models.pop(stored_key, None)if opts is not None:provider.models[tag] = opts+ _forget_overview()return _options_response(tag, opts)@@ -539,6 +552,7 @@ async def delete_model_options(provider = _ollama_provider_cfg(cfg)if stored_key is not None and provider is not None:provider.models.pop(stored_key, None)+ _forget_overview()return _options_response(name, None)diff --git a/tests/unit/brain/test_ollama_roles.py b/tests/unit/brain/test_ollama_roles.pyindex 186903a5de..2caa1c19c8 100644--- a/tests/unit/brain/test_ollama_roles.py+++ b/tests/unit/brain/test_ollama_roles.py@@ -1,6 +1,7 @@"""Roles: the four Ollama slots read from the config, judged against the-installed downloads, pointed at the shortlist's pick, and written through-the existing config writers only.+installed downloads, recommended installed-first (the shortlist only when+nothing installed qualifies), and written through the existing config+writers only."""from __future__ import annotations@@ -35,13 +36,35 @@ def _cfg() -> JarvisConfig:def fake() -> FakeOllamaServer:ollama_inventory._reset_for_tests()server = FakeOllamaServer()- server.add("qwen3.5:4b", capabilities=("completion", "tools", "vision"))- server.add("gemma4:12b-it-qat", capabilities=("completion", "tools", "thinking"))- server.add("qwen3-embedding:4b", capabilities=("embedding",))+ server.add("qwen3.5:4b", size=3_400_000_000, capabilities=("completion", "tools", "vision"))+ server.add(+ "gemma4:12b-it-qat",+ size=7_200_000_000,+ capabilities=("completion", "tools", "thinking"),+ )+ server.add("qwen3-embedding:4b", size=2_500_000_000, capabilities=("embedding",))server.add("broken:1b", show_fails=True)return server+def _info(+ name: str, size_gb: float, *caps: str, probed: bool = True+) -> ollama_inventory.OllamaModelInfo:+ return ollama_inventory.OllamaModelInfo(+ name=name,+ size_bytes=int(size_gb * 1024**3),+ digest="",+ modified_at="",+ family="",+ parameter_size="",+ quantization_level="",+ context_length=None,+ capabilities=tuple(caps),+ license="",+ probed=probed,+ )++@pytest.fixturedef shortlist(monkeypatch: pytest.MonkeyPatch) -> list[dict]:rows = [@@ -160,20 +183,111 @@ async def test_list_roles_judges_qualifying_models_by_capability(fake, shortlist@pytest.mark.asyncio-async def test_list_roles_points_at_the_shortlists_pick_or_the_largest_installed_one(+async def test_list_roles_recommends_installed_models_before_the_shortlist(fake, shortlist) -> None:+ """Eleven models on disk must not end in "download qwen3.8:27b"."""states, _ = await ollama_roles.list_roles(ROOT, _cfg(), transport=fake.transport())by_id = {s.spec.id: s for s in states}+ # The shortlist answered no memory figures, so every fit is "unknown"+ # and the largest installed model with the preferred capability wins.+ assert by_id["chat"].recommended == "gemma4:12b-it-qat"+ assert "installed" in by_id["chat"].recommended_reason+ # Screen reading needs vision: only the 4B declares it.+ assert by_id["tools_screen"].recommended == "qwen3.5:4b"+ # Deep work prefers thinking; the 12B declares it.+ assert by_id["deep"].recommended == "gemma4:12b-it-qat"+ assert by_id["embedding"].recommended == "qwen3-embedding:4b"+ # A call wants the fast class: the 12B is over the voice size cap.+ assert by_id["voice"].recommended == "qwen3.5:4b"+ assert "fast" in by_id["voice"].recommended_reason+ # The shortlist's downloads are never named while something installed qualifies.+ assert all(s.recommended != "qwen3.8:27b" for s in states)+++async def test_list_roles_judges_installed_picks_against_this_machines_memory(+ fake, shortlist+) -> None:+ machine = ollama_roles.Machine(memory_gb=32.0, accelerator_gb=8.0)+ states, _ = await ollama_roles.list_roles(+ ROOT, _cfg(), transport=fake.transport(), machine=machine+ )+ by_id = {s.spec.id: s for s in states}+ # 7.2 GB + overhead is over the 8 GB card (tight); 3.4 GB fits — it wins+ # although the 12B is bigger and thinks.+ assert by_id["chat"].recommended == "qwen3.5:4b"+ assert "8 GB of graphics memory" in by_id["chat"].recommended_reason+ assert by_id["deep"].recommended == "qwen3.5:4b"+++async def test_list_roles_falls_back_to_the_shortlist_when_nothing_installed_qualifies(+ shortlist,+) -> None:+ ollama_inventory._reset_for_tests()+ server = FakeOllamaServer()+ server.add("qwen3-embedding:4b", capabilities=("embedding",))+ states, _ = await ollama_roles.list_roles(ROOT, _cfg(), transport=server.transport())+ by_id = {s.spec.id: s for s in states}assert by_id["chat"].recommended == "qwen3.8:27b"- # The multimodal chat pick serves the screen role too.- assert by_id["tools_screen"].recommended == "qwen3.8:27b"+ assert "download" in by_id["chat"].recommended_reasonassert by_id["deep"].recommended == "ornith:9b"- # The picker marks nothing once the role has a curated model installed;- # the largest installed one is named so the button still has an answer.+ # The embedder is installed and qualifies: no download named there.assert by_id["embedding"].recommended == "qwen3-embedding:4b"+def test_pick_installed_prefers_the_roles_capability_over_raw_size() -> None:+ chat = ollama_roles.role_spec("chat")+ machine = ollama_roles.Machine(memory_gb=64.0, accelerator_gb=24.0)+ models = [+ _info("big-no-tools:14b", 9.0, "completion"),+ _info("mid-tools:12b", 7.2, "completion", "tools"),+ _info("small-tools:4b", 3.4, "completion", "tools"),+ _info("unprobed:30b", 18.0, probed=False),+ ]+ tag, reason = ollama_roles.pick_installed(chat, models, machine)+ assert tag == "mid-tools:12b"+ assert reason == "Largest installed model with tools that fits in the 24 GB of graphics memory."+++def test_pick_installed_names_the_smallest_when_everything_is_tight() -> None:+ chat = ollama_roles.role_spec("chat")+ machine = ollama_roles.Machine(memory_gb=16.0, accelerator_gb=4.0)+ models = [+ _info("a:14b", 9.0, "completion", "tools"),+ _info("b:8b", 5.0, "completion", "tools"),+ ]+ tag, reason = ollama_roles.pick_installed(chat, models, machine)+ assert tag == "b:8b"+ assert "tight" in reason+++def test_pick_installed_keeps_the_voice_pick_in_the_fast_class() -> None:+ voice = ollama_roles.role_spec("voice")+ machine = ollama_roles.Machine(memory_gb=64.0, accelerator_gb=24.0)+ models = [+ _info("deep:27b", 17.0, "completion", "tools"),+ _info("mid:9b", 5.6, "completion", "tools"),+ _info("tiny:1b", 0.8, "completion"),+ ]+ tag, reason = ollama_roles.pick_installed(voice, models, machine)+ assert tag == "mid:9b"+ assert "under 6 GB" in reason+ # Nothing under the cap: the smallest one, with the reason saying so.+ tag, reason = ollama_roles.pick_installed(voice, [models[0]], machine)+ assert tag == "deep:27b" and "nothing under 6 GB" in reason+ assert ollama_roles.pick_installed(voice, [], machine) == ("", "")+++def test_machine_from_reads_the_shortlists_figures() -> None:+ assert ollama_roles.machine_from({"memory_gb": 32, "accelerator_gb": 15.9}) == (+ ollama_roles.Machine(memory_gb=32.0, accelerator_gb=15.9)+ )+ assert ollama_roles.machine_from({"models": []}) == ollama_roles.Machine()+ assert ollama_roles.machine_from(None) == ollama_roles.Machine()++@pytest.mark.asyncioasync def test_list_roles_keeps_the_rows_when_the_server_is_offline(fake, shortlist) -> None:fake.offline = True@@ -192,7 +306,11 @@ async def test_list_roles_survives_a_failing_shortlist(fake, monkeypatch) -> Nonmonkeypatch.setattr(ollama_pull, "recommendations", _boom)states, error = await ollama_roles.list_roles(ROOT, _cfg(), transport=fake.transport())assert error is None- assert all(s.recommended == "" for s in states)+ # The installed picks do not need the registry; only a download would.+ by_id = {s.spec.id: s for s in states}+ assert by_id["chat"].recommended == "gemma4:12b-it-qat"+ assert by_id["embedding"].recommended == "qwen3-embedding:4b"+ assert all("download" not in s.recommended_reason for s in states)def test_set_role_writes_through_the_provider_card_writers(writes) -> None:diff --git a/tests/unit/ui/web/test_local_models_routes.py b/tests/unit/ui/web/test_local_models_routes.pyindex 04566a51cd..b41e365798 100644--- a/tests/unit/ui/web/test_local_models_routes.py+++ b/tests/unit/ui/web/test_local_models_routes.py@@ -260,11 +260,15 @@ def test_roles_list_every_slot_with_pick_qualifying_and_recommendation(assert list(roles) == ["chat", "voice", "tools_screen", "deep", "embedding", "ack", "polish"]assert roles["chat"]["current"] == "qwen3.5:4b"assert roles["chat"]["installed"] is True- assert roles["chat"]["recommended"] == "qwen3.8:27b"+ # Installed first: the largest download with tools, not the shortlist's.+ assert roles["chat"]["recommended"] == "gemma4:12b-it-qat"+ assert roles["chat"]["recommended_reason"].startswith("Largest installed model with tools")assert roles["chat"]["qualifying"] == ["qwen3.5:4b", "gemma4:12b-it-qat"]assert roles["tools_screen"]["required"] == ["tools", "vision"]assert roles["tools_screen"]["qualifying"] == ["qwen3.5:4b"]- assert roles["deep"]["recommended"] == "ornith:9b"+ assert roles["tools_screen"]["recommended"] == "qwen3.5:4b"+ assert roles["deep"]["recommended"] == "gemma4:12b-it-qat"+ assert roles["voice"]["recommended"] == "qwen3.5:4b"assert roles["embedding"]["qualifying"] == ["qwen3-embedding:4b"]assert roles["voice"]["writable"] is True and roles["voice"]["advanced"] is Falseassert roles["ack"]["writable"] is False and roles["ack"]["advanced"] is True@@ -297,6 +301,39 @@ def test_put_role_writes_through_the_config_writer(server, fake, writes) -> Noneassert provider.deep_model == ""+def test_put_role_drops_the_memoised_overview(server, fake, writes, monkeypatch) -> None:+ """The row the user just changed must not sit on its old pick for 15 s."""+ from jarvis.brain import ollama_overview, ollama_runtime++ ollama_overview._reset_for_tests()+ monkeypatch.setattr(+ ollama_runtime,+ "runtime_status",+ lambda: {+ "installed": True,+ "binary": "ollama",+ "running": True,+ "version": "0.32.15",+ "detail": "",+ "base_url": ROOT,+ "host_kind": "local",+ "models_dir": "",+ },+ )+ with TestClient(server.app) as client:+ first = client.get(f"{BASE}/overview").json()+ assert first["source"] == "live"+ assert client.put(f"{BASE}/roles/deep", json={"model": "qwen3.5:4b"}).status_code == 200+ # The memo is gone: a plain read is no longer a stale "live" answer,+ # and a fresh read carries the new pick.+ after = client.get(f"{BASE}/overview").json()+ assert after["source"] == "cache"+ fresh = client.get(f"{BASE}/overview", params={"fresh": 1}).json()+ deep = next(r for r in fresh["roles"]["roles"] if r["id"] == "deep")+ assert deep["current"] == "qwen3.5:4b"+ ollama_overview._reset_for_tests()++def test_put_role_refuses_read_only_and_unknown_roles(server, fake, writes) -> None:with TestClient(server.app) as client:ro = client.put(f"{BASE}/roles/ack", json={"model": "x"})