commit acb96e8358e3160807982bea7afd57b774d19dd0 Author: umbra audio Date: Sun Oct 18 08:00:46 2026 -0700 Add opencode-lmstudio: sync LM Studio models into the OpenCode config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cc62ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +*.bak-* diff --git a/README.md b/README.md new file mode 100644 index 0000000..98be2ae --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +# opencode-lmstudio + +A single-file, dependency-free helper that discovers LM Studio (and other +OpenAI-compatible) servers and writes their models into your OpenCode config. + +- **Python 3.8+, standard library only** — no `pip install`, no `jq`, no setup. +- Detects this machine's LAN IP, probes `localhost` and the local IP, then + prompts for any additional servers (each gets a name). +- Reads rich metadata from LM Studio's `/api/v0/models`, falling back to + `/v1/models` for plain OpenAI-compatible servers. +- Merges providers/models into `~/.config/opencode/opencode.json`, skipping + duplicates. `--prune` removes models the server no longer advertises. +- Backs up the config and writes atomically. + +## Usage + +```bash +# interactive: detects local IP, offers localhost + the local LM Studio, +# then prompts for other servers and names +python3 opencode-lmstudio.py + +# non-interactive, name a server explicitly +python3 opencode-lmstudio.py --server 192.168.123.16=BigBox --yes + +# preview changes without writing / just list models +python3 opencode-lmstudio.py --server 192.168.123.16=BigBox --dry-run +python3 opencode-lmstudio.py --server 192.168.123.16=BigBox --list + +# drop models the server no longer advertises +python3 opencode-lmstudio.py --server 192.168.123.16=BigBox --prune --yes +``` + +## Options + +| Flag | Description | +|---|---| +| `--server HOST[=NAME]` | Server IP/host, optionally `=Name` (repeatable) | +| `--port PORT` | Server port (default `1234`) | +| `--config PATH` | Config file (default `~/.config/opencode/opencode.json`) | +| `--timeout SECS` | Per-request timeout (default `6.0`) | +| `--list` | Only list models; do not write the config | +| `--prune` | Remove configured models the server no longer advertises | +| `--dry-run` | Show changes without writing | +| `--yes` | Assume yes / accept default names | + +## How a server becomes a provider + +Each server is written as an OpenCode provider using +`@opencode/ai/providers/openai-compatible` with `settings.baseURL` set to +`http://HOST:PORT/v1`. Model capability flags (`tools`, `input`, `output`) and +`limit.context` come from the server's metadata; vision models advertise image +input, and embedding models are added but marked `"disabled": true`. + +Duplicate handling is by `baseURL` (an existing provider for the same server is +reused even if named differently) and by `modelID` (models already present are +kept, not re-added). + +## Safety + +- Backs up the previous config before every write (`opencode.json.bak-