Skip to content

About

Automatically surface new models added to lemonade-server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

lemonade-sync

Make Lemonade Server (local GGUF models served via an OpenAI-compatible API on port 13305) available to opencode.

This repository contains two independent tools that solve the same problem in different ways. They are mutually exclusive — pick one:

1. opencode plugin 2. live sync tool
What it does Registers Lemonade models with opencode at startup Watches the model cache dir and rewrites opencode.json whenever a model changes
Run-time Inside opencode (loaded as a plugin) Standalone container daemon
Refresh On every opencode restart On every cache-dir change (debounced)
Config written In-memory (no files touched) Directly into opencode.json

The plugin is the current, preferred approach and is what the author uses. The Docker sync tool is preserved for anyone who wants the live-watcher behavior.

Both tools assume Lemonade's model cache lives at ~/.cache/lemonade and its API is at http://<host>:13305.


1. The opencode plugin

What it does

On every opencode startup, the plugin:

  1. Fetches the model list from GET {baseURL}/v1/models.
  2. Registers the lemonade provider (via the @ai-sdk/openai-compatible SDK) with each returned model in opencode's in-memory config.

Models then appear in opencode as lemonade/<model-id> (e.g. lemonade/gpt-oss-20b-GGUF-Q4_K_M). Because registration happens in-memory, no configuration files are modified.

Requirements

  • opencode 1.18.x (the plugin uses the classic { id, server() } plugin contract).
  • Lemonade reachable from wherever opencode runs.

Installation

Reference the repo directly from GitHub in opencode.json:

{
  "plugin": ["git+https://github.com/stein3/lemonade-watcher.git"]
}

or with opencode plugin add git+https://github.com/stein3/lemonade-watcher.git.

You can pin a version with a ref fragment (...#v0.1.0, #main, or a commit SHA) and override the base URL with the options tuple:

"plugin": [["git+https://github.com/stein3/lemonade-watcher.git", { "baseURL": "http://host:13305" }]]

Then quit and restart opencode. The plugin loads once at startup; running sessions keep their already-loaded config.

Configuration

The base URL is resolved in this order:

  1. baseURL from the plugin options tuple
  2. LEMONADE_BASE_URL environment variable
  3. http://host.docker.internal:13305 (default)

If the model fetch fails (server down, wrong URL), opencode still starts; the lemonade provider is simply registered without models and an error is logged.

Uninstalling

Remove the entry from the plugin array in opencode.json, then restart opencode.


2. The live sync tool

What it does

Keeps provider.lemonade in your opencode.json up to date:

  1. On startup, it performs an initial sync.
  2. It watches the Lemonade model cache directory (via a polling observer, which is reliable inside Docker bind mounts) for file creation/move events.

Requirements

  • Docker (for the containerized daemon) or Python 3.12+ for a bare-metal run.
  • httpx and watchdog (pip install -r requirements.txt).
  • A running Lemonade instance and write access to the opencode.json you want updated.

Usage (Docker)

docker compose up --build

compose.yaml expects two host paths; both are parameterized with sensible defaults:

Variable Default Purpose
LEMONADE_CACHE_DIR ~/.cache/lemonade Host dir mounted into the container and watched
OPENCODE_WORKSPACE_DIR /workspace Host dir containing opencode.json, mounted at /workspace

The compose file itself sets the Lemonade API host to http://host.docker.internal:13305 via the host.docker.internal gateway.

Example overriding them:

LEMONADE_CACHE_DIR=/home/you/.cache/lemonade \
OPENCODE_WORKSPACE_DIR=/home/you/code/opencode \
docker compose up --build

Environment variables inside the container:

Variable Default Purpose
LEMONADE_BASE_URL http://localhost:13305 Lemonade API base URL
LEMONADE_CACHE_DIR ~/.cache/lemonade Cache dir to watch
OPENCODE_CONFIG_PATH /workspace/opencode.json opencode.json to rewrite

Usage (bare metal)

LEMONADE_BASE_URL=http://localhost:13305 \
LEMONADE_CACHE_DIR=~/.cache/lemonade \
OPENCODE_CONFIG_PATH=/path/to/opencode.json \
python3 lemonade_event_sync.py

The daemon logs what it fetches, writes, and detects; stop it with SIGTERM/Ctrl-C.


Notes

  • The opencode plugin fetches models only at startup, so a model downloaded while opencode is running appears after the next restart. The Docker tool reacts to downloads immediately but requires a file rewrite.
  • Both tools register the same lemonade provider shape, so switching between them requires no change to your model setting.

About

Automatically surface new models added to lemonade-server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages