opencode: name providers LLMHost (Local) / LLMHost (<host>), identify by key file

The local and remote setup paths already used distinct provider ids, so one
opencode config can point at a local server and any number of remote ones.
Name them after the machine they reach so they're tellable apart in /models.

Decide which block is *this* machine's by the key-file reference it carries
rather than by its name, so:

  - a provider renamed by hand is still recognised and updated in place
    instead of a second one being added next to it;
  - a remote provider sitting under the `llmhost` id is no longer silently
    overwritten with a localhost baseURL (setup takes `llmhost-local` and
    says so) -- the one-shot .before-llmhost backup could not recover it;
  - uninstall removes only the local provider, never `llmhost-*` blocks for
    servers that are still running, and never providers it didn't create.

Add `llmhost opencode-remove` for the case the servers can't handle for each
other: uninstalling on a server can't reach the clients pointing at it. Wire
uninstall to it, repointing opencode's default model at a surviving llm-host
provider and dropping `model` only when none is left.

Also split config read/write out of configure() and report `unparsable`: a
syntactically broken opencode.json used to raise ValueError mid-setup.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-02 23:40:33 -08:00
parent a250812d42
commit 504ea3018a
3 changed files with 264 additions and 47 deletions

View file

@ -52,8 +52,9 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
| `llmhost key` | print the API key |
| `llmhost opencode-setup` | install opencode here if needed and connect it to this server |
| `llmhost opencode-config` | print what to add to opencode on another machine |
| `llmhost opencode-remove` | take llm-host back out of this machine's opencode config (`--host` for a retired remote server, `--all` for every one) |
| `llmhost update` | pull the latest llm-host and re-plan (`--backend` also upgrades vLLM/MLX) |
| `llmhost uninstall [--purge] [--models]` | remove services and backends; asks before deleting downloaded models (`--models` deletes without asking) |
| `llmhost uninstall [--purge] [--models]` | remove services, backends and this machine's opencode provider; asks before deleting downloaded models (`--models` deletes without asking) |
The dashboard (`http://<host>.local:11340`) shows the active model, throughput, KV cache, GPU utilization,
temperature and power with 10-minute charts, the server log, and buttons to switch models or stop the server.
@ -62,14 +63,37 @@ temperature and power with 10-minute charts, the server log, and buttons to swit
**On the server itself**, setup handles it: if opencode isn't installed it offers to install it (official
installer, into `~/.opencode/bin`), then adds an `llmhost` provider to `~/.config/opencode/opencode.json`
pointing at `http://localhost:<api port>/v1` and reading the key straight from llm-host's key file. Other
providers and your default model are left alone; the first change backs the file up as `opencode.json.before-llmhost`.
pointing at `http://localhost:<api port>/v1` and reading the key straight from llm-host's key file. It shows up
in opencode as **LLMHost (Local)**. Other providers and your default model are left alone; the first change backs
the file up as `opencode.json.before-llmhost`.
`llmhost update` keeps the provider's port and model list in sync. Run it on demand with `llmhost opencode-setup`
(`--yes` to install without asking); skip it during setup with `--no-opencode`, or install without asking with `--opencode`.
A config with comments (`.jsonc`) is never rewritten, since that would drop them; setup prints the block to paste instead.
**On another machine**, run `llmhost opencode-config` on the server. It prints a provider block and a one-liner
that copies the API key over. Only one model is loaded at a time; pick the one the server is currently running.
that copies the API key over. That block is named **LLMHost (<the server's hostname>)** — e.g. `LLMHost (popos.local)`
— under the provider id `llmhost-<shorthost>`. Only one model is loaded at a time; pick the one the server is
currently running.
### One opencode, several servers
The two paths use different provider ids, so a single opencode config can point at a local server and any number
of remote ones at once, each named after the machine it reaches:
| | provider id | shows up as | API key |
|---|---|---|---|
| local | `llmhost` | `LLMHost (Local)` | read straight from `~/.config/llm-host/api_key` |
| remote | `llmhost-<shorthost>` | `LLMHost (<host>)` | copied to `~/.config/opencode/llmhost-<shorthost>.key` |
Which block belongs to *this* machine is decided by the key-file reference it carries, not by its name. So the
provider is still recognised after you rename it, a remote provider that happens to sit under the `llmhost` id is
never overwritten (setup takes `llmhost-local` instead and says so), and `uninstall` removes only the local
provider — remote ones, and providers llm-host didn't create, are left in place. If a provider's default model
goes away with it, `model` is repointed at a surviving llm-host provider, and dropped only if there is none.
Retiring a server is the one thing the servers can't do for each other: uninstalling on `popos` can't reach the
clients pointing at it. On each client, run `llmhost opencode-remove --host popos.local` (or delete the block by
hand if llm-host isn't installed there).
## How models are chosen