Skip to content

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.

feat(cli): jarvis local-models — roles, models, options, catalogue, Hugging Face and server from the terminal

rubenluetke10-beep4ce1012e02d1
diff --git a/docs/jarvis-cli-reference.md b/docs/jarvis-cli-reference.md
index fdd9af1468..a14b39b3e7 100644
--- a/docs/jarvis-cli-reference.md
+++ b/docs/jarvis-cli-reference.md
@@ -111,6 +111,32 @@ _Generated from the curated command tree by `scripts/ci/gen_cli_reference.py`
- `jarvis ide close-terminals <names> --yes --dry-run` — Stop several coding agents and close their terminal panes.
- `jarvis ide rename-terminal <name> <new_name> --dry-run` — Rename a running terminal pane without restarting its agent.
+## local-models
+
+- `jarvis local-models catalog recommended --provider` — The curated shortlist ranked for this machine, with its review date.
+- `jarvis local-models catalog search <query> --sort --capability --limit --provider` — Browse the library; offline is reported as a sentence, not a failure.
+- `jarvis local-models catalog tags <name> --provider` — Every tag of one library model with size, quantization, context and fit.
+- `jarvis local-models hf enable <state> --provider --dry-run` — Show or flip the Hugging Face browsing switch.
+- `jarvis local-models hf files <user> <repo> --provider` — The .gguf files of one repository with quantization, size and fit.
+- `jarvis local-models hf pull <user> <repo> --quant --provider --dry-run` — Start pulling hf.co/<user>/<repo>[:<quant>] through the normal pull path.
+- `jarvis local-models hf search <query> --sort --limit --provider` — GGUF repositories on Hugging Face.
+- `jarvis local-models models delete <name> --reassign --provider --yes --dry-run` — Remove a download from the server (refused while a role still uses it).
+- `jarvis local-models models list --provider` — Every download with its facts, what is loaded, and the disk total.
+- `jarvis local-models models show <name> --provider` — One download with the long facts (license, parameters, template).
+- `jarvis local-models models unload <name> --provider --yes --dry-run` — Free the memory a loaded model holds; the next turn pays the load again.
+- `jarvis local-models options clear <name> --provider --dry-run` — Drop the profile so the server's defaults apply again.
+- `jarvis local-models options get <name> --provider` — The profile of one model as configured (empty when none).
+- `jarvis local-models options set <name> <values> --provider --dry-run` — Replace the profile of a model with the given knobs (whole set).
+- `jarvis local-models options suggest <name> --provider` — An advisory profile for this machine, with one reason per knob.
+- `jarvis local-models roles list --provider` — Every role with its pick, what qualifies, and the recommendation.
+- `jarvis local-models roles set <role> <model> --provider --dry-run` — Assign a model to a role (written through the config writers).
+- `jarvis local-models server env-guide --os --provider` — Copyable per-OS commands for the server's environment variables.
+- `jarvis local-models server log --lines --provider` — The last lines of the server log Jarvis writes when it starts the server.
+- `jarvis local-models server status --provider` — Runtime picture plus what is loaded and how much disk the downloads take.
+- `jarvis local-models server stop --provider --yes --dry-run` — Stop the server Jarvis itself started (never one started elsewhere).
+- `jarvis local-models server test <base_url> --provider` — Probe a host before saving it: version and latency, or why it failed.
+
+
## marketplace
- `jarvis marketplace browse` — Show everything the community marketplace offers, and what you already have.
diff --git a/docs/jarvis-cli.md b/docs/jarvis-cli.md
index 363803660b..3340cc3f50 100644
--- a/docs/jarvis-cli.md
+++ b/docs/jarvis-cli.md
@@ -23,8 +23,8 @@ The CLI is a **thin HTTP client over the REST API**, in two layers:
2. **Curated layer (`jarvis <group> <command>`)** — hand-written, ergonomic
commands for the common domains: `brain`, `config`, `missions`, `wiki`,
`sessions`, `skills`, `outputs`, `board`, `costs`, `workflows`, `conductor`,
- `contacts`, `telephony`, `marketplace`, `mcps`, `docs`, `frontier`, plus
- `auth`, `system`, `tasks`.
+ `contacts`, `telephony`, `marketplace`, `mcps`, `docs`, `frontier`,
+ `local-models`, plus `auth`, `system`, `tasks`.
Because the CLI only ever calls the same routes the WebUI calls, it inherits all
of Jarvis's safety machinery (risk tiers, the atomic config-write pipeline, the
@@ -112,6 +112,45 @@ entries (`marketplace-browse`, `marketplace-install`), so the assistant can look
the name up and then install it. Installing pulls somebody else's published
content onto your machine, so that path asks you to confirm out loud first.
+## Local models from the terminal
+
+The "Local models" section — what is installed on the pull-capable local server
+(Ollama today), which download fills each role, per-model option profiles, the
+public catalogue, Hugging Face GGUF browsing and the server itself — is one
+curated group. The provider defaults to `ollama`; `--provider <id>` names
+another pull-capable card (a cloud card answers with a sentence, never an empty
+table):
+
+```bash
+jarvis local-models roles # chat / tools_screen / deep / embedding
+jarvis local-models roles set deep qwen3:32b
+jarvis local-models models # every download, what is loaded, disk total
+jarvis local-models models show qwen3:32b
+jarvis local-models models unload qwen3:32b --yes # frees memory; the next turn reloads
+jarvis local-models models delete old:7b --reassign qwen3:32b --yes
+jarvis local-models options set qwen3:32b num_ctx=16384 temperature=0.2 think=false
+jarvis local-models options suggest qwen3:32b # an advisory profile for this machine
+jarvis local-models catalog search "vision" --capability vision
+jarvis local-models catalog tags qwen3
+jarvis local-models catalog recommended
+jarvis local-models hf enable on # off by default; nothing calls huggingface.co until then
+jarvis local-models hf search "llama 3.1 gguf"
+jarvis local-models hf files bartowski Llama-3.1-8B-Instruct-GGUF
+jarvis local-models hf pull bartowski Llama-3.1-8B-Instruct-GGUF --quant Q4_K_M
+jarvis local-models server status
+jarvis local-models server test http://127.0.0.1:11434
+jarvis local-models server log --lines 80
+jarvis local-models server env-guide --os linux
+jarvis local-models server stop --yes # only a server Jarvis itself started
+```
+
+`options set` replaces the whole profile: `KEY=VALUE` pairs are typed (numbers,
+`true`/`false`, JSON lists such as `stop='["</s>"]'`), and the writer clamps the
+values rather than rejecting them. Deleting a download is refused with a 409
+while a configured role still points at it, unless `--reassign` names another
+installed model — then the roles are rewritten first, and the delete runs only
+on a valid config. `--json` before the group prints the untouched API payload.
+
## Safety model
The CLI is agent-first, so it stays out of your way for safe work and only gates
@@ -120,7 +159,8 @@ the genuinely consequential:
- **Reads** (`GET`) and **reversible mutations** (switch provider, set language,
enable a skill) just run.
- **Destructive** actions — every `DELETE`, plus `config set`, `missions dispatch`,
- and `telephony outbound` — refuse unless you pass `--yes` (or set
+ `telephony outbound`, `local-models models unload` and `local-models server
+ stop` — refuse unless you pass `--yes` (or set
`JARVIS_CLI_ASSUME_YES=1`). A prompt is not an accepted substitute.
- **Desktop restart is UI-only.** Control/API clients, including
`jarvis system restart`, cannot restart the app even with `--yes --force`;
diff --git a/jarvis/cli_ctl/__main__.py b/jarvis/cli_ctl/__main__.py
index 1c7415e740..09c8aa1e3b 100644
--- a/jarvis/cli_ctl/__main__.py
+++ b/jarvis/cli_ctl/__main__.py
@@ -32,6 +32,7 @@ from jarvis.cli_ctl.commands import docs as docs_cmd
from jarvis.cli_ctl.commands import friends as friends_cmd
from jarvis.cli_ctl.commands import frontier as frontier_cmd
from jarvis.cli_ctl.commands import ide as ide_cmd
+from jarvis.cli_ctl.commands import local_models as local_models_cmd
from jarvis.cli_ctl.commands import marketplace as marketplace_cmd
from jarvis.cli_ctl.commands import mcps as mcps_cmd
from jarvis.cli_ctl.commands import missions as missions_cmd
@@ -134,6 +135,7 @@ app.add_typer(costs_cmd.app, name="costs")
app.add_typer(docs_cmd.app, name="docs")
app.add_typer(frontier_cmd.app, name="frontier")
app.add_typer(ide_cmd.app, name="ide")
+app.add_typer(local_models_cmd.app, name="local-models")
def _in_completion() -> bool:
diff --git a/jarvis/cli_ctl/command_index.py b/jarvis/cli_ctl/command_index.py
index 896db94eba..48893a5d6b 100644
--- a/jarvis/cli_ctl/command_index.py
+++ b/jarvis/cli_ctl/command_index.py
@@ -132,6 +132,30 @@ COMMAND_INDEX: dict[str, tuple[str, ...]] = {
),
"frontier": ("pending", "ack"),
"ide": ("rename-terminal", "close-terminals"),
+ "local-models": (
+ "roles list",
+ "roles set <chat|tools_screen|deep|embedding> <model>",
+ "models list",
+ "models show <model>",
+ "models unload <model> --yes",
+ "models delete <model> [--reassign <model>] --yes",
+ "options get <model>",
+ "options set <model> <key=value ...>",
+ "options clear <model>",
+ "options suggest <model>",
+ 'catalog search "<query>" [--capability --sort]',
+ "catalog tags <model>",
+ "catalog recommended",
+ 'hf search "<query>"',
+ "hf files <user> <repo>",
+ "hf pull <user> <repo> [--quant]",
+ "hf enable [on|off]",
+ "server status",
+ "server stop --yes",
+ "server test <url>",
+ "server log [--lines]",
+ "server env-guide [--os]",
+ ),
"marketplace": (
"install <id>",
"browse",
diff --git a/jarvis/cli_ctl/commands/local_models.py b/jarvis/cli_ctl/commands/local_models.py
new file mode 100644
index 0000000000..8e290e71a2
--- /dev/null
+++ b/jarvis/cli_ctl/commands/local_models.py
@@ -0,0 +1,404 @@
+"""local-models: the "Local models" section from a terminal.
+
+What is installed on the pull-capable local server (Ollama today), which model
+fills each role, the per-model option profile, the public catalogue, Hugging
+Face GGUF browsing, and the server itself. Every command calls the same
+``/api/providers/{provider}/local-models/...`` routes the section renders, so
+the capability gate (a cloud card answers 400 with a sentence) and the config
+writers are inherited, never re-implemented.
+
+The provider defaults to ``ollama``; ``--provider`` names another pull-capable
+card. Deleting a download, unloading it from memory, and stopping the server
+are the destructive actions and need ``--yes``.
+"""
+
+from __future__ import annotations
+
+import json
+from typing import Any
+
+import typer
+
+from jarvis.cli_ctl import invoke, options
+
+app = typer.Typer(
+ no_args_is_help=True,
+ help="Local models: roles, downloads, options, catalogue, Hugging Face, server.",
+)
+
+_PROVIDER = typer.Option("ollama", "--provider", help="Pull-capable provider id (default: ollama).")
+_VALUES = typer.Argument(
+ ..., help="KEY=VALUE pairs, e.g. num_ctx=8192 temperature=0.2 think=false."
+)
+
+
+def _base(provider: str) -> str:
+ return f"/api/providers/{provider.strip() or 'ollama'}/local-models"
+
+
+def _parse_value(raw: str) -> Any:
+ """``KEY=VALUE`` values arrive as text; numbers, booleans and JSON lists
+ become their typed form so the route's clamps see the real value."""
+ text = raw.strip()
+ if text.lower() in {"true", "false"}:
+ return text.lower() == "true"
+ try:
+ return json.loads(text)
+ except ValueError:
+ return text
+
+
+def _pairs(items: list[str]) -> dict[str, Any]:
+ out: dict[str, Any] = {}
+ for item in items:
+ key, sep, value = item.partition("=")
+ if not sep or not key.strip():
+ raise typer.BadParameter(f"expected KEY=VALUE, got {item!r}")
+ out[key.strip()] = _parse_value(value)
+ return out
+
+
+# ----------------------------------------------------------------------
+# roles
+# ----------------------------------------------------------------------
+
+roles_app = typer.Typer(
+ invoke_without_command=True,
+ help="Which download fills each role (chat, tools & screen, deep, embedding).",
+)
+app.add_typer(roles_app, name="roles")
+
+
+@roles_app.callback()
+def roles_root(ctx: typer.Context, provider: str = _PROVIDER) -> None:
+ """Bare ``roles`` lists, same as ``roles list``."""
+ if ctx.invoked_subcommand is None:
+ invoke.run("GET", f"{_base(provider)}/roles")
+
+
+@roles_app.command("list")
+def roles_list(provider: str = _PROVIDER) -> None:
+ """Every role with its pick, what qualifies, and the recommendation."""
+ invoke.run("GET", f"{_base(provider)}/roles")
+
+
+@roles_app.command("set")
+def roles_set(
+ role: str = typer.Argument(..., help="chat | tools_screen | deep | embedding."),
+ model: str = typer.Argument(
+ "", help='Installed model tag; "" hands the role back to discovery.'
+ ),
+ provider: str = _PROVIDER,
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Assign a model to a role (written through the config writers)."""
+ invoke.run(
+ "PUT",
+ f"{_base(provider)}/roles/{role}",
+ body={"model": model},
+ dangerous=False,
+ dry_run=dry_run,
+ )
+
+
+# ----------------------------------------------------------------------
+# models
+# ----------------------------------------------------------------------
+
+models_app = typer.Typer(
+ invoke_without_command=True,
+ help="The downloads on the server: list, show, unload, delete.",
+)
+app.add_typer(models_app, name="models")
+
+
+@models_app.callback()
+def models_root(ctx: typer.Context, provider: str = _PROVIDER) -> None:
+ """Bare ``models`` lists, same as ``models list``."""
+ if ctx.invoked_subcommand is None:
+ invoke.run("GET", f"{_base(provider)}/inventory")
+
+
+@models_app.command("list")
+def models_list(provider: str = _PROVIDER) -> None:
+ """Every download with its facts, what is loaded, and the disk total."""
+ invoke.run("GET", f"{_base(provider)}/inventory")
+
+
+@models_app.command("show")
+def models_show(name: str, provider: str = _PROVIDER) -> None:
+ """One download with the long facts (license, parameters, template)."""
+ invoke.run("GET", f"{_base(provider)}/inventory/{name}")
+
+
+@models_app.command("unload")
+def models_unload(
+ name: str,
+ provider: str = _PROVIDER,
+ yes: bool = options.yes_opt(),
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Free the memory a loaded model holds; the next turn pays the load again."""
+ invoke.run(
+ "POST",
+ f"{_base(provider)}/inventory/{name}/unload",
+ dangerous=True,
+ assume_yes=yes,
+ dry_run=dry_run,
+ )
+
+
+@models_app.command("delete")
+def models_delete(
+ name: str,
+ reassign: str = typer.Option(
+ "",
+ "--reassign",
+ help="Installed model that takes over every role still pointing at NAME.",
+ ),
+ provider: str = _PROVIDER,
+ yes: bool = options.yes_opt(),
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Remove a download from the server (refused while a role still uses it)."""
+ params = {"reassign": reassign.strip()} if reassign.strip() else None
+ invoke.run(
+ "DELETE",
+ f"{_base(provider)}/inventory/{name}",
+ params=params,
+ dangerous=True,
+ assume_yes=yes,
+ dry_run=dry_run,
+ )
+
+
+# ----------------------------------------------------------------------
+# options
+# ----------------------------------------------------------------------
+
+options_app = typer.Typer(
+ no_args_is_help=True,
+ help="Per-model option profiles (num_ctx, temperature, keep_alive, ...).",
+)
+app.add_typer(options_app, name="options")
+
+
+@options_app.command("get")
+def options_get(name: str, provider: str = _PROVIDER) -> None:
+ """The profile of one model as configured (empty when none)."""
+ invoke.run("GET", f"{_base(provider)}/models/{name}/options")
+
+
+@options_app.command("set")
+def options_set(
+ name: str,
+ values: list[str] = _VALUES,
+ provider: str = _PROVIDER,
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Replace the profile of a model with the given knobs (whole set)."""
+ invoke.run(
+ "PUT",
+ f"{_base(provider)}/models/{name}/options",
+ body=_pairs(values),
+ dangerous=False,
+ dry_run=dry_run,
+ )
+
+
+@options_app.command("clear")
+def options_clear(name: str, provider: str = _PROVIDER, dry_run: bool = options.dry_opt()) -> None:
+ """Drop the profile so the server's defaults apply again."""
+ invoke.run(
+ "DELETE",
+ f"{_base(provider)}/models/{name}/options",
+ dangerous=False,
+ dry_run=dry_run,
+ )
+
+
+@options_app.command("suggest")
+def options_suggest(name: str, provider: str = _PROVIDER) -> None:
+ """An advisory profile for this machine, with one reason per knob."""
+ invoke.run("GET", f"{_base(provider)}/models/{name}/suggested-options")
+
+
+# ----------------------------------------------------------------------
+# catalog
+# ----------------------------------------------------------------------
+
+catalog_app = typer.Typer(
+ no_args_is_help=True,
+ help="The public model library: search, tags, the recommended shortlist.",
+)
+app.add_typer(catalog_app, name="catalog")
+
+
+@catalog_app.command("search")
+def catalog_search(
+ query: str = typer.Argument("", help="Free text; empty lists the most popular."),
+ sort: str = typer.Option("popular", "--sort", help="popular | newest."),
+ capability: str = typer.Option(
+ "", "--capability", help="tools | vision | embedding | thinking."
+ ),
+ limit: int = typer.Option(50, "--limit", min=1, max=50),
+ provider: str = _PROVIDER,
+) -> None:
+ """Browse the library; offline is reported as a sentence, not a failure."""
+ params: dict[str, Any] = {"q": query, "sort": sort, "limit": limit}
+ if capability.strip():
+ params["capability"] = capability.strip()
+ invoke.run("GET", f"{_base(provider)}/catalog", params=params)
+
+
+@catalog_app.command("tags")
+def catalog_tags(name: str, provider: str = _PROVIDER) -> None:
+ """Every tag of one library model with size, quantization, context and fit."""
+ invoke.run("GET", f"{_base(provider)}/catalog/{name}/tags")
+
+
+@catalog_app.command("recommended")
+def catalog_recommended(provider: str = _PROVIDER) -> None:
+ """The curated shortlist ranked for this machine, with its review date."""
+ invoke.run("GET", f"{_base(provider)}/catalog/recommended")
+
+
+# ----------------------------------------------------------------------
+# hf
+# ----------------------------------------------------------------------
+
+hf_app = typer.Typer(
+ no_args_is_help=True,
+ help="Hugging Face GGUF browsing (off until switched on).",
+)
+app.add_typer(hf_app, name="hf")
+
+
+@hf_app.command("search")
+def hf_search(
+ query: str = typer.Argument("", help="Free text over GGUF repositories."),
+ sort: str = typer.Option(
+ "downloads", "--sort", help="downloads | lastModified | trendingScore."
+ ),
+ limit: int = typer.Option(30, "--limit", min=1, max=100),
+ provider: str = _PROVIDER,
+) -> None:
+ """GGUF repositories on Hugging Face."""
+ invoke.run(
+ "GET",
+ f"{_base(provider)}/hf/search",
+ params={"q": query, "sort": sort, "limit": limit},
+ )
+
+
+@hf_app.command("files")
+def hf_files(
+ user: str = typer.Argument(..., help="Repository owner."),
+ repo: str = typer.Argument(..., help="Repository name."),
+ provider: str = _PROVIDER,
+) -> None:
+ """The .gguf files of one repository with quantization, size and fit."""
+ invoke.run("GET", f"{_base(provider)}/hf/{user}/{repo}/files")
+
+
+@hf_app.command("pull")
+def hf_pull(
+ user: str = typer.Argument(..., help="Repository owner."),
+ repo: str = typer.Argument(..., help="Repository name."),
+ quant: str = typer.Option("", "--quant", help="Quantization tag, e.g. Q4_K_M."),
+ provider: str = _PROVIDER,
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Start pulling hf.co/<user>/<repo>[:<quant>] through the normal pull path."""
+ body: dict[str, Any] = {"user": user, "repo": repo}
+ if quant.strip():
+ body["quant"] = quant.strip()
+ invoke.run("POST", f"{_base(provider)}/hf/pull", body=body, dangerous=False, dry_run=dry_run)
+
+
+@hf_app.command("enable")
+def hf_enable(
+ state: str = typer.Argument("", help="on | off; empty shows the current switch."),
+ provider: str = _PROVIDER,
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Show or flip the Hugging Face browsing switch."""
+ choice = state.strip().lower()
+ if not choice:
+ invoke.run("GET", f"{_base(provider)}/hf/enabled")
+ return
+ if choice not in {"on", "off"}:
+ raise typer.BadParameter("expected 'on' or 'off'")
+ invoke.run(
+ "PUT",
+ f"{_base(provider)}/hf/enabled",
+ body={"enabled": choice == "on"},
+ dangerous=False,
+ dry_run=dry_run,
+ )
+
+
+# ----------------------------------------------------------------------
+# server
+# ----------------------------------------------------------------------
+
+server_app = typer.Typer(
+ no_args_is_help=True,
+ help="The local server: status, stop, probe a host, log, environment guide.",
+)
+app.add_typer(server_app, name="server")
+
+
+@server_app.command("status")
+def server_status(provider: str = _PROVIDER) -> None:
+ """Runtime picture plus what is loaded and how much disk the downloads take."""
+ invoke.run("GET", f"{_base(provider)}/server")
+
+
+@server_app.command("stop")
+def server_stop(
+ provider: str = _PROVIDER,
+ yes: bool = options.yes_opt(),
+ dry_run: bool = options.dry_opt(),
+) -> None:
+ """Stop the server Jarvis itself started (never one started elsewhere)."""
+ invoke.run(
+ "POST",
+ f"{_base(provider)}/server/stop",
+ dangerous=True,
+ assume_yes=yes,
+ dry_run=dry_run,
+ )
+
+
+@server_app.command("test")
+def server_test(
+ base_url: str = typer.Argument(..., help="Host to probe, e.g. http://127.0.0.1:11434."),
+ provider: str = _PROVIDER,
+) -> None:
+ """Probe a host before saving it: version and latency, or why it failed."""
+ invoke.run(
+ "POST",
+ f"{_base(provider)}/server/test",
+ body={"base_url": base_url},
+ dangerous=False,
+ )
+
+
+@server_app.command("log")
+def server_log(
+ lines: int = typer.Option(40, "--lines", min=1, max=500),
+ provider: str = _PROVIDER,
+) -> None:
+ """The last lines of the server log Jarvis writes when it starts the server."""
+ invoke.run("GET", f"{_base(provider)}/server/log", params={"lines": lines})
+
+
+@server_app.command("env-guide")
+def server_env_guide(
+ os_name: str = typer.Option("", "--os", help="windows | macos | linux; empty = this OS."),
+ provider: str = _PROVIDER,
+) -> None:
+ """Copyable per-OS commands for the server's environment variables."""
+ params = {"os": os_name.strip()} if os_name.strip() else None
+ invoke.run("GET", f"{_base(provider)}/server/env-guide", params=params)
diff --git a/tests/unit/cli_ctl/test_commands_local_models.py b/tests/unit/cli_ctl/test_commands_local_models.py
new file mode 100644
index 0000000000..ae5499bf11
--- /dev/null
+++ b/tests/unit/cli_ctl/test_commands_local_models.py
@@ -0,0 +1,291 @@
+"""`jarvis local-models ...` — the "Local models" section from a terminal.
+
+Every command must hit the exact mounted route with the exact body, the
+provider must default to ``ollama`` and follow ``--provider``, and the three
+destructive commands (unload, delete, server stop) must refuse without
+``--yes`` while the reversible writes (roles, options, HF switch) just run.
+"""
+
+from __future__ import annotations
+
+import pytest
+from typer.testing import CliRunner
+
+from jarvis.cli_ctl.__main__ import app
+
+runner = CliRunner()
+_BASE = "/api/providers/ollama/local-models"
+
+
+def _one(capture_api) -> dict:
+ assert len(capture_api["calls"]) == 1, capture_api["calls"]
+ return capture_api["calls"][0]
+
+
+# ----------------------------------------------------------------------
+# roles
+# ----------------------------------------------------------------------
+
+
[email protected]("argv", [["roles"], ["roles", "list"]])
+def test_roles_lists_bare_and_explicit(capture_api, argv) -> None:
+ res = runner.invoke(app, ["local-models", *argv])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("GET", f"{_BASE}/roles")
+
+
+def test_roles_set_puts_model_without_yes(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "roles", "set", "deep", "qwen3:32b"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("PUT", f"{_BASE}/roles/deep")
+ assert call["body"] == {"model": "qwen3:32b"}
+
+
+def test_roles_set_empty_model_hands_back_to_discovery(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "roles", "set", "chat"])
+ assert res.exit_code == 0, res.output
+ assert _one(capture_api)["body"] == {"model": ""}
+
+
+def test_provider_option_changes_the_prefix(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "roles", "--provider", "llamacpp"])
+ assert res.exit_code == 0, res.output
+ assert _one(capture_api)["path"] == "/api/providers/llamacpp/local-models/roles"
+
+
+# ----------------------------------------------------------------------
+# models
+# ----------------------------------------------------------------------
+
+
[email protected]("argv", [["models"], ["models", "list"]])
+def test_models_lists_inventory(capture_api, argv) -> None:
+ res = runner.invoke(app, ["local-models", *argv])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("GET", f"{_BASE}/inventory")
+
+
+def test_models_show_keeps_the_tag_colon(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "models", "show", "qwen3:32b"])
+ assert res.exit_code == 0, res.output
+ assert _one(capture_api)["path"] == f"{_BASE}/inventory/qwen3:32b"
+
+
+def test_models_unload_requires_yes(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "models", "unload", "qwen3:32b"])
+ assert res.exit_code == 1
+ assert capture_api["calls"] == []
+
+
+def test_models_unload_with_yes(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "models", "unload", "qwen3:32b", "--yes"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("POST", f"{_BASE}/inventory/qwen3:32b/unload")
+
+
+def test_models_delete_requires_yes(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "models", "delete", "old:7b"])
+ assert res.exit_code == 1
+ assert capture_api["calls"] == []
+
+
+def test_models_delete_with_reassign_and_yes(capture_api) -> None:
+ res = runner.invoke(
+ app,
+ ["local-models", "models", "delete", "old:7b", "--reassign", "qwen3:32b", "--yes"],
+ )
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("DELETE", f"{_BASE}/inventory/old:7b")
+ assert call["query"] == {"reassign": "qwen3:32b"}
+
+
+def test_models_delete_without_reassign_sends_no_query(capture_api) -> None:
+ runner.invoke(app, ["local-models", "models", "delete", "old:7b", "--yes"])
+ assert _one(capture_api)["query"] == {}
+
+
+def test_models_delete_conflict_exits_nonzero(capture_api) -> None:
+ capture_api["routes"][("DELETE", f"{_BASE}/inventory/old:7b")] = (
+ 409,
+ {"detail": "old:7b is still the pick for chat."},
+ )
+ res = runner.invoke(app, ["local-models", "models", "delete", "old:7b", "--yes"])
+ assert res.exit_code == 1
+
+
+# ----------------------------------------------------------------------
+# options
+# ----------------------------------------------------------------------
+
+
+def test_options_get(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "options", "get", "qwen3:32b"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("GET", f"{_BASE}/models/qwen3:32b/options")
+
+
+def test_options_set_types_the_pairs(capture_api) -> None:
+ res = runner.invoke(
+ app,
+ [
+ "local-models",
+ "options",
+ "set",
+ "qwen3:32b",
+ "num_ctx=16384",
+ "temperature=0.2",
+ "think=false",
+ "keep_alive=10m",
+ 'stop=["</s>"]',
+ ],
+ )
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("PUT", f"{_BASE}/models/qwen3:32b/options")
+ assert call["body"] == {
+ "num_ctx": 16384,
+ "temperature": 0.2,
+ "think": False,
+ "keep_alive": "10m",
+ "stop": ["</s>"],
+ }
+
+
+def test_options_set_rejects_a_bare_word(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "options", "set", "qwen3:32b", "num_ctx"])
+ assert res.exit_code != 0
+ assert capture_api["calls"] == []
+
+
+def test_options_clear_is_reversible(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "options", "clear", "qwen3:32b"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("DELETE", f"{_BASE}/models/qwen3:32b/options")
+
+
+def test_options_suggest(capture_api) -> None:
+ runner.invoke(app, ["local-models", "options", "suggest", "qwen3:32b"])
+ assert _one(capture_api)["path"] == f"{_BASE}/models/qwen3:32b/suggested-options"
+
+
+# ----------------------------------------------------------------------
+# catalog
+# ----------------------------------------------------------------------
+
+
+def test_catalog_search_params(capture_api) -> None:
+ res = runner.invoke(
+ app,
+ ["local-models", "catalog", "search", "vision", "--capability", "vision", "--limit", "5"],
+ )
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("GET", f"{_BASE}/catalog")
+ assert call["query"] == {"q": "vision", "sort": "popular", "capability": "vision", "limit": "5"}
+
+
+def test_catalog_tags_and_recommended(capture_api) -> None:
+ runner.invoke(app, ["local-models", "catalog", "tags", "qwen3"])
+ runner.invoke(app, ["local-models", "catalog", "recommended"])
+ paths = [c["path"] for c in capture_api["calls"]]
+ assert paths == [f"{_BASE}/catalog/qwen3/tags", f"{_BASE}/catalog/recommended"]
+
+
+# ----------------------------------------------------------------------
+# hf
+# ----------------------------------------------------------------------
+
+
+def test_hf_search(capture_api) -> None:
+ res = runner.invoke(
+ app, ["local-models", "hf", "search", "llama gguf", "--sort", "lastModified"]
+ )
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert call["path"] == f"{_BASE}/hf/search"
+ assert call["query"] == {"q": "llama gguf", "sort": "lastModified", "limit": "30"}
+
+
+def test_hf_files(capture_api) -> None:
+ runner.invoke(app, ["local-models", "hf", "files", "bartowski", "Llama-3.1-8B-GGUF"])
+ assert _one(capture_api)["path"] == f"{_BASE}/hf/bartowski/Llama-3.1-8B-GGUF/files"
+
+
+def test_hf_pull_body(capture_api) -> None:
+ res = runner.invoke(
+ app,
+ ["local-models", "hf", "pull", "bartowski", "Llama-3.1-8B-GGUF", "--quant", "Q4_K_M"],
+ )
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("POST", f"{_BASE}/hf/pull")
+ assert call["body"] == {"user": "bartowski", "repo": "Llama-3.1-8B-GGUF", "quant": "Q4_K_M"}
+
+
+def test_hf_enable_shows_then_flips(capture_api) -> None:
+ runner.invoke(app, ["local-models", "hf", "enable"])
+ runner.invoke(app, ["local-models", "hf", "enable", "on"])
+ runner.invoke(app, ["local-models", "hf", "enable", "off"])
+ calls = capture_api["calls"]
+ assert [(c["method"], c["body"]) for c in calls] == [
+ ("GET", None),
+ ("PUT", {"enabled": True}),
+ ("PUT", {"enabled": False}),
+ ]
+ assert all(c["path"] == f"{_BASE}/hf/enabled" for c in calls)
+
+
+def test_hf_enable_rejects_other_words(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "hf", "enable", "maybe"])
+ assert res.exit_code != 0
+ assert capture_api["calls"] == []
+
+
+# ----------------------------------------------------------------------
+# server
+# ----------------------------------------------------------------------
+
+
+def test_server_status(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "server", "status"])
+ assert res.exit_code == 0, res.output
+ assert _one(capture_api)["path"] == f"{_BASE}/server"
+
+
[email protected]("extra", [[], ["--dry-run"]])
+def test_server_stop_requires_yes_or_dry_run(capture_api, extra) -> None:
+ res = runner.invoke(app, ["local-models", "server", "stop", *extra])
+ assert capture_api["calls"] == []
+ assert res.exit_code == (0 if extra else 1)
+
+
+def test_server_stop_with_yes(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "server", "stop", "--yes"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("POST", f"{_BASE}/server/stop")
+
+
+def test_server_test_body(capture_api) -> None:
+ res = runner.invoke(app, ["local-models", "server", "test", "http://127.0.0.1:11434"])
+ assert res.exit_code == 0, res.output
+ call = _one(capture_api)
+ assert (call["method"], call["path"]) == ("POST", f"{_BASE}/server/test")
+ assert call["body"] == {"base_url": "http://127.0.0.1:11434"}
+
+
+def test_server_log_and_env_guide(capture_api) -> None:
+ runner.invoke(app, ["local-models", "server", "log", "--lines", "80"])
+ runner.invoke(app, ["local-models", "server", "env-guide", "--os", "linux"])
+ runner.invoke(app, ["local-models", "server", "env-guide"])
+ calls = capture_api["calls"]
+ assert calls[0]["path"] == f"{_BASE}/server/log" and calls[0]["query"] == {"lines": "80"}
+ assert calls[1]["path"] == f"{_BASE}/server/env-guide" and calls[1]["query"] == {"os": "linux"}
+ assert calls[2]["query"] == {}