Offer to install opencode and connect it to the local server

After setup, if opencode is missing, offer to install it with its
official installer; then add an `llmhost` provider pointing at
http://localhost:<api port>/v1 that reads llm-host's key file directly.
Other providers and the default model are kept, the original config is
backed up once, trailing commas are tolerated, and a config with
comments is left untouched (the block is printed instead). Re-runs and
`llmhost update` keep the provider's port and models in sync.
New: `llmhost opencode-setup`, and setup flags --opencode / --no-opencode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
This commit is contained in:
neil 2026-11-02 05:37:35 -08:00
parent 3da3d8ed45
commit 7ad0642d2e
3 changed files with 189 additions and 20 deletions

View file

@ -49,7 +49,8 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
| `llmhost logs -f` | follow the model server log |
| `llmhost start` / `stop` / `restart` | control the model server (stop frees the GPU) |
| `llmhost key` | print the API key |
| `llmhost opencode-config` | print what to add to opencode on your client machine |
| `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 update` | pull the latest llm-host and re-plan (`--backend` also upgrades vLLM/MLX) |
| `llmhost uninstall [--purge]` | remove services and backends (downloaded models are kept) |
@ -58,9 +59,16 @@ temperature and power with 10-minute charts, the server log, and buttons to swit
## Connecting opencode
Run `llmhost opencode-config` on the server. It prints a provider block for `~/.config/opencode/opencode.json`
and a one-liner that copies the API key to the client. Only one model is loaded at a time; pick the one
the server is currently running.
**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`.
`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.
## How models are chosen