Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ bare clone with no workspace, the full guide is at <https://docs.start9.com/pack
- **Keep `git`, `bash`, and `openssh-client` in the Dockerfile.** The upstream Alpine
image ships none of them, and OpenCode's repository and terminal features break
silently without them.
- **Deliver the password only through `OPENCODE_PASSWORD`.** Don't write it into
OpenCode's own config file; the server reads it from the environment alone.
- **Deliver the password and provider API keys only through the environment.** OpenCode
reads the password from `OPENCODE_PASSWORD` and each provider key from
`OPENCODE_KEY_<ID>`; don't write either into a config file.
- **Keep `main` mounted over the whole of `/root`.** OpenCode spreads its state across
`~/.local`, `~/.config` and `~/.cache`, and users keep projects under `~`; a narrower
mount drops data from restarts and backups.
- **The Configure Model Providers action owns only the providers it writes.** They are
the `opencode.json` entries carrying `package: @opencode/ai/providers/openai-compatible`;
rebuild those from the form, and leave every other entry — and a `model` that names
none of them — as you found it.
81 changes: 61 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The package declares two volumes.
| Volume | Mount point | Contents |
| --------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `main` | `/root` (read-write) | The container's entire home: sessions, credentials, repositories, projects, and OpenCode's own config, state, and cache. |
| `startos` | not mounted | StartOS-side state: `store.json`, holding the generated login password. |
| `startos` | not mounted | StartOS-side state: `store.json`, holding the generated login password and the configured providers' API keys. |

`main` is mounted over the image's home directory, so everything OpenCode writes
under `/root` persists across restarts and updates:
Expand All @@ -68,31 +68,40 @@ under `/root` persists across restarts and updates:
lost on restart; treat anything only in there as scratch.

The `startos` volume is deliberately not mounted into `opencode-sub`, so the
running server never sees the password file — it receives the password through
the `OPENCODE_PASSWORD` environment variable instead.
running server never sees the file itself — it receives the login password as
`OPENCODE_PASSWORD` and each configured provider's API key as an
`OPENCODE_KEY_<ID>` variable instead.

## File Models

The package owns exactly one file model: `store.json` on the `startos` volume.
The package owns two file models.

| File | Format | Key | Seeded by | Rewritten by |
| -------------------- | ------ | --------------- | --------------------------------- | ---------------------------- |
| `startos/store.json` | JSON | `adminPassword` | the **Set Admin Password** action | the same action, on each run |
| File | Format | Keys | Seeded by | Rewritten by |
| ------------------------------------- | ------ | ------------------------------- | ---------------------------------------- | ---------------------------- |
| `startos/store.json` | JSON | `adminPassword`, `providerKeys` | the **Set Admin Password** action | the two actions, on each run |
| `main/.config/opencode/opencode.json` | JSONC | `$schema`, `providers`, `model` | the **Configure Model Providers** action | the same action, on each run |

`adminPassword` is stored in clear text because the server reads it verbatim
from `OPENCODE_PASSWORD` and cannot be given a hash. There is no default: it is
absent until the user runs the action, which is what the [task](#tasks) waits
for.
for. `providerKeys` maps a configured provider's id to its API key, and has no
default either.

The schema is permissive (`z.looseObject`, every key optional), so the file is
never rewritten by the package on its own — only the action writes it, and it
only ever merges the one key. A hand edit to `adminPassword` therefore survives:
the running server watches the file and restarts with the new value. Nothing
else re-asserts or normalizes the file.
Both schemas are permissive (`z.looseObject`, every key optional), and the
package writes each file only from an action — never at startup, and never to
normalize or repair it. A hand edit therefore survives:

OpenCode's **own** configuration file (`~/.config/opencode/opencode.json`, or
`opencode.jsonc`, on the `main` volume) is not modeled by this package. OpenCode
writes and reads it, and the package neither seeds nor rewrites it.
- In `store.json`, the running server watches the file and restarts with the new
value.
- In `opencode.json`, OpenCode watches the file and reloads it without a restart.
The package leaves every key it does not own — including whatever OpenCode
writes there itself — as it found it.

`opencode.json` is OpenCode's own global configuration, at the path OpenCode
reads it from. The package models it so the Configure Model Providers action can
write provider entries; it is not generated, replaced, or seeded otherwise.
Comments and trailing commas are accepted, but saving reserializes the file as
JSON without its comments or formatting.

## Dependencies

Expand Down Expand Up @@ -124,13 +133,15 @@ complete and nothing to configure on disk.
3. The user opens the `ui` interface, signs in on the web page with the username
`opencode` and that password.

The package writes no OpenCode configuration, so provider and model setup is
upstream's own, in the web app.
Model providers are not preconfigured. Hosted providers connect in the web app
itself, under **Settings → Providers**; the **Configure Model Providers** action
adds an OpenAI-compatible endpoint the web app's own catalog has no entry for. The
package adds no files OpenCode did not already expect of it.

## Actions

One user-facing action. The OS carries its id, name, description, warning, and
status gating; what follows is what the metadata cannot express.
Two user-facing actions. The OS carries each one's id, name, description,
warning, and status gating; what follows is what the metadata cannot express.

### `set-admin-password` — Set Admin Password

Expand All @@ -147,6 +158,33 @@ status gating; what follows is what the metadata cannot express.
- **Outputs.** The username `opencode` (unmasked, copyable) and the new password
(masked, copyable).

### `configure-providers` — Configure Model Providers

- **When to run it.** When OpenCode should use an OpenAI-compatible endpoint the
web app's own catalog has no entry for — a vLLM, LM Studio, or Ollama server on
your network. Hosted providers connect in the web app itself, under
**Settings → Providers**.
- **What it changes.** For each provider in the form, an entry in the `providers`
map of `main/.config/opencode/opencode.json`, and its API key under
`providerKeys` in `startos/store.json`. Entries carrying
`package: @opencode/ai/providers/openai-compatible` are rebuilt; an ID collision
with any other entry is rejected before either file changes. Every other entry,
and a `model` that names none of the managed entries, is left as it was. The
`model` key is set when a provider's **Default** toggle is on, or dropped when it
names a provider this save removes. A new or changed API key
restarts the service, because the server receives it as an `OPENCODE_KEY_<ID>`
environment variable; a change that touches no key is picked up by the running
server without a restart.
- **Cost.** Seconds. Nothing outside the two files above is touched, and no
session, repository, or project is affected.
- **Repeat safety.** The form is prefilled with the OpenAI-compatible entries and
is the authority for them: leaving one out disconnects it, and an empty form
disconnects them all. A literal API key on an existing entry is prefilled and
moved into `providerKeys` on save. Providers using another package are not
listed and are not touched.
- **Outputs.** Each provider with the model IDs it serves, and the default model
when one is set.

## Tasks

One task, raised by `startos/init/watchCredentials.ts`.
Expand Down Expand Up @@ -226,14 +264,17 @@ volumes:
startos: unmounted
file_models:
- startos/store.json
- main/.config/opencode/opencode.json
startos_managed_env_vars:
- OPENCODE_PASSWORD
- OPENCODE_DISABLE_AUTOUPDATE
- OPENCODE_KEY_<PROVIDER_ID>
dependencies: none
interfaces:
ui: { type: ui, port: 4096 }
actions:
- set-admin-password
- configure-providers
tasks:
- { action: set-admin-password, severity: critical }
health_checks:
Expand Down
43 changes: 39 additions & 4 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ StartOS server. You use it from a browser:
3. On the **Connect to a server** screen, click **Use password**. The server
address is already filled in — leave it as it is — paste the password, and
click **Connect**.
4. Choose a model. Out of the box OpenCode uses a free model hosted by
OpenCode, so your prompts and code are sent to OpenCode's servers. To use
your own provider instead, open **Settings → Providers** and connect it (an
API key, or your OpenCode Console account).
4. Choose a model. Out of the box OpenCode uses a free model hosted by OpenCode,
so your prompts and code are sent to OpenCode's servers. To use a hosted
provider instead, open **Settings → Providers** in the web app and connect it
(an API key, or your OpenCode Console account). For an OpenAI-compatible
endpoint the app's catalog cannot reach — your own vLLM, LM Studio, or Ollama
server — run the **Configure Model Providers** action from StartOS; see
[Connecting a model provider](#connecting-a-model-provider).
5. Back on the home screen, click **Add project** and choose a folder to work in.
Pick a folder inside your home directory (`~/…`, shown as `root` when you
browse from `/`) — that is where your server keeps data across restarts.
Expand All @@ -52,6 +55,38 @@ open past sessions, and change settings from the sidebar. The same address also
serves the HTTP API under `/api/*`, if you want to drive the server from your own
scripts.

### Connecting a model provider

Hosted providers connect inside the web app, under **Settings → Providers**. The
**Configure Model Providers** action is for an OpenAI-compatible endpoint the
app's catalog has no entry for — a vLLM, LM Studio, or Ollama server on your
network. Run it from StartOS; each entry asks for:

- **ID** — a short name used to identify the provider (`vllm`). Lowercase
letters, digits, and dashes.
- **Name** — how the provider appears in OpenCode's model list (`Lab vLLM`).
- **Base URL** — the endpoint's API root, including `/v1`, for example
`http://192.168.1.50:8000/v1`.
- **API Key** — only if the endpoint checks one. Leave it blank for a local
server that accepts any request. It is kept on the StartOS side and is never
written into the configuration file.
- **Models** — one entry per model ID the endpoint serves, for example
`glm-5.3`. If you are not sure of the exact IDs, the endpoint lists them under
`/v1/models`.
- **Default** — turn this on to make the first model in the list the one new
sessions start on.

Save, and the models are available in the web app right away — refresh the page
if the picker still looks empty.

Run the action again to change an endpoint or add another provider, and delete a
provider by removing its entry from the list. The API key of a provider you have
already configured is filled in when the form opens, so leave it as it is unless
you are replacing it. OpenAI-compatible endpoints you configured by hand are
also listed, with any literal API key filled in. Providers connected in the web
app are not affected. If an ID is already in use outside this list, choose a
different ID.

### Changing the password

Run **Set Admin Password** again at any time to generate a new password. The
Expand Down
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "opencode-startos",
"dependencies": {
"@start9labs/start-sdk": "4.1.0"
"@start9labs/start-sdk": "4.1.0",
"jsonc-parser": "3.3.1"
},
"overrides": {
"@start9labs/start-sdk": "$@start9labs/start-sdk"
Expand Down
Loading