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
37 changes: 8 additions & 29 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,11 @@ bare clone with no workspace, the full guide is at <https://docs.start9.com/pack

## This package

- **The base image is pinned in `./Dockerfile`, not in the manifest.** The manifest
sets `source: { dockerBuild: {} }` because the package builds a thin image on top of
upstream's; the `FROM` line is the pin. See `UPDATING.md` for the bump recipe.
- **The Dockerfile's added packages are load-bearing.** The upstream image is a slim
Alpine base with neither `git` nor `bash`; OpenCode shells out to both (repositories,
diffs, worktrees, its terminal tool). Removing `git`, `bash`, or `openssh-client`
silently breaks those features.
- **The interface port is defined once, in `startos/utils.ts`.** `startos/main.ts`
passes it to `opencode serve` and health-checks it, and `startos/interfaces.ts`
binds it. If the port ever changes, all three must change together.
- **The password is delivered only through the environment.** OpenCode reads
`OPENCODE_PASSWORD`, with the username fixed at `opencode`; it cannot be handed a
password hash in a config file. `startos/fileModels/store.json.ts` holds the value
on the `startos` volume, which no subcontainer mounts. Do not "improve" this by
writing OpenCode's own config file.
- **`startos/main.ts` mounts the `main` volume over the container's entire home**
(`/root`), which is where OpenCode keeps sessions, provider credentials, cloned
repositories, and projects. Narrowing the mountpoint drops user data from backups.

## Working here

```bash
npx tsc --noEmit # fast type check
make format # Prettier, using the SDK's shared config
make x86 # build opencode_x86_64.s9pk (and `make arm` for aarch64)
```

A green type-check proves nothing about the service; install the `.s9pk` on a StartOS
box and exercise it. See the packaging guide's Development Workflow page.
- **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.
- **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.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM ghcr.io/anomalyco/opencode:2.4.1
FROM ghcr.io/anomalyco/opencode:2.4.1@sha256:10e340e3e86d7b23e95cd9960f5a934beae8a87593d7398b5629b6112ed1fc63

# The upstream image is a slim Alpine base that ships neither git nor a POSIX
# shell beyond busybox. OpenCode shells out to git for repositories, diffs and
# worktrees, and uses a shell for its terminal tool, so both are required for
# the service to work as documented. openssh-client lets git reach ssh remotes.
# OpenCode shells out to git and bash, which the Alpine base omits.
RUN apk add --no-cache git bash openssh-client
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ network instead of a terminal on the same machine.
## Image and Container Runtime

The package builds a thin image on top of the upstream OpenCode image
(`ghcr.io/anomalyco/opencode`), pinned to a released tag in the package's
`Dockerfile`. The upstream image is a slim Alpine base that ships neither `git`
nor `bash`, and OpenCode shells out to `git` for repositories, diffs, and
(`ghcr.io/anomalyco/opencode`), pinned in the package's `Dockerfile` by release
tag and manifest-list digest. The upstream image is a slim Alpine base that ships
neither `git` nor `bash`, and OpenCode shells out to `git` for repositories, diffs, and
worktrees and to a shell for its terminal tool — so the package Dockerfile adds
`git`, `bash`, and `openssh-client` (for `ssh` git remotes). Architectures are
`x86_64` and `aarch64`, matching the architectures upstream publishes.
Expand Down Expand Up @@ -124,9 +124,8 @@ 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.

Model providers are not preconfigured; connecting one is part of using the app,
not part of install. Nothing upstream is disabled or skipped, and the package
adds no files OpenCode did not already expect.
The package writes no OpenCode configuration, so provider and model setup is
upstream's own, in the web app.

## Actions

Expand All @@ -144,8 +143,7 @@ status gating; what follows is what the metadata cannot express.
every existing web session out when its password changes, so anyone already
signed in must sign in again with the new password.
- **Repeat safety.** Repeatable. Each run mints a fresh password and replaces the
previous one; it never accumulates. A `warning` is shown before it runs once a
password already exists.
previous one; it never accumulates.
- **Outputs.** The username `opencode` (unmasked, copyable) and the new password
(masked, copyable).

Expand All @@ -160,10 +158,8 @@ One task, raised by `startos/init/watchCredentials.ts`.
Because it is `critical`, it blocks the service from starting and suspends the
ordinary controls until it is satisfied — this is what the user sees first, and
why nothing is reachable before a password exists. It is idempotent on its replay
key, so ordinary rebuilds do not re-raise it. It returns only if the stored
password is lost — most plausibly a restore that brought back `main` without the
`startos` volume, in which case a new password must be set (and existing sessions
are invalidated).
key, so ordinary rebuilds do not re-raise it. It returns only if `store.json`
loses the password, and running the action again clears it.

## Health Checks

Expand Down Expand Up @@ -207,13 +203,11 @@ required.
2. **The `opencode pair` pairing-link flow is not wired up.** Sign in with the
password from the **Set Admin Password** action instead of a one-time pairing
link or QR code.
3. **Model provider credentials are not preconfigured.** Connect a provider in
the web UI after install; the package ships no provider configuration.
4. **OpenCode's self-updater is disabled** in the container. The server is updated
3. **OpenCode's self-updater is disabled** in the container. The server is updated
by updating the StartOS package, not from inside the app.
5. **The container runs as `root`.** The upstream image does, and the package does
4. **The container runs as `root`.** The upstream image does, and the package does
not change its user.
6. **The service opens its own outbound connections** — to model providers and to
5. **The service opens its own outbound connections** — to model providers and to
git repositories it clones or fetches. Those are made from the server's
outbound route, independently of whichever address the web interface is
published on.
Expand Down
17 changes: 9 additions & 8 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

The package wraps a single upstream source: the published OpenCode container
image, `ghcr.io/anomalyco/opencode`. The package builds a thin image on top of it
(`./Dockerfile`), so the pin lives in that Dockerfile's `FROM` line rather than in
a `dockerTag` field in `startos/manifest/index.ts` — the manifest only says
`source: { dockerBuild: {} }`.
(`./Dockerfile`), so the pin — release tag plus manifest-list digest — lives in
that Dockerfile's `FROM` line rather than in a `dockerTag` field in
`startos/manifest/index.ts`, which only says `source: { dockerBuild: {} }`.

## Determining the upstream version

Expand All @@ -24,19 +24,20 @@ Do not use `.../releases/latest`: this repository marks the current `v2.x` line
newer than what that endpoint returns, so it still reports the `v1.19.x` series.
Upstream's `<https://opencode.ai>` site also names the current version.

The package targets `x86_64` and `aarch64`; confirm the new tag publishes both
before bumping:
The package targets `x86_64` and `aarch64`. Confirm the new tag publishes both,
and read its manifest-list digest (the top-level `Digest:` line, not a
per-platform one):

```bash
docker manifest inspect ghcr.io/anomalyco/opencode:<version> | jq '.manifests[].platform'
docker buildx imagetools inspect ghcr.io/anomalyco/opencode:<version>
```

## Applying the bump

1. Edit the `FROM` line in `./Dockerfile` to the new tag:
1. Edit the `FROM` line in `./Dockerfile` to the new tag and its digest:

```dockerfile
FROM ghcr.io/anomalyco/opencode:<version>
FROM ghcr.io/anomalyco/opencode:<version>@sha256:<manifest-list digest>
```

2. Bump the package version in `startos/versions/current.ts` to match, and add
Expand Down
10 changes: 5 additions & 5 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ StartOS server. You use it from a browser:
1. On install, the service shows a task: **Set the admin password before signing
in**. Run the **Set Admin Password** action and copy the password it returns.
The username is always `opencode`.
2. Open the **Web Interface** from the service's Interfaces tab (enable an
address there if none is enabled yet).
2. Open the **Web Interface** from the service's Interfaces tab.
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. In the web app, open **Settings → Providers** and connect a model provider
(an API key, or your OpenCode Console account). OpenCode can't do anything
until it has a model to use.
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).
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 Down
2 changes: 0 additions & 2 deletions startos/actions/setAdminPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const setAdminPassword = sdk.Action.withoutInput(
description: i18n(
'Generate a new random password for the OpenCode web interface. Replaces any existing password.',
),
// Confirm before overwriting an existing password; run straight through on
// first set.
warning: (await storeJson.read((s) => s.adminPassword).const(effects))
? i18n('Replaces the current admin password.')
: null,
Expand Down
3 changes: 0 additions & 3 deletions startos/backups.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { sdk } from './sdk'

export const { createBackup, restoreInit } = sdk.setupBackups(
// `main` (the container's home: sessions, credentials, repositories and
// projects) plus `startos` (the generated login password). Restoring the data
// without the password would leave the service locked behind a lost credential.
async ({ effects }) => sdk.Backups.ofVolumes('main', 'startos'),
)
4 changes: 0 additions & 4 deletions startos/fileModels/store.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { FileHelper, z } from '@start9labs/start-sdk'
import { sdk } from '../sdk'

const shape = z.looseObject({
// The password the OpenCode server requires for the web interface and HTTP
// API. Cleartext because the server reads it from the environment unchanged,
// so it cannot be stored as a hash. It lives on the `startos` volume, which no
// subcontainer mounts, so the service never sees the file itself.
adminPassword: z.string().optional().catch(undefined),
})

Expand Down
4 changes: 0 additions & 4 deletions startos/init/watchCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { storeJson } from '../fileModels/store.json'
import { i18n } from '../i18n'
import { sdk } from '../sdk'

// Reactive watcher: on a fresh install (or if the store is ever cleared) it
// raises a critical task that blocks the service until the user sets a password.
// The task is idempotent on its replay key, so a rebuild after the password is
// set is a no-op.
export const watchCredentials = sdk.setupOnInit(async (effects) => {
const adminPassword = await storeJson
.read((s) => s.adminPassword)
Expand Down
3 changes: 0 additions & 3 deletions startos/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { sdk } from './sdk'
import { uiPort } from './utils'

export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
// One HTTP origin serves both the browser web app (`/`) and the HTTP API
// (`/api/*`), so a single interface covers everything.
const uiMulti = sdk.MultiHost.of(effects, 'ui')
const uiOrigin = await uiMulti.bindPort(uiPort, {
protocol: 'http',
Expand All @@ -16,7 +14,6 @@ export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
id: 'ui',
description: i18n('The OpenCode web interface and HTTP API'),
type: 'ui',
// The URL itself carries no secret; the server gates it with its own login.
masked: false,
schemeOverride: null,
username: null,
Expand Down
14 changes: 0 additions & 14 deletions startos/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { sdk } from './sdk'
import { uiPort } from './utils'

export const main = sdk.setupMain(async ({ effects }) => {
// Reactive: when the password changes (set or rotated by the action), the
// daemon spec is rebuilt and the server restarts with the new value.
//
// A missing password is unreachable in normal operation: `watchCredentials`
// raises a critical task on a fresh install or a restore that brought back
// `main` without `startos`, and a critical task blocks the service from
// starting. Throwing rather than substituting a value keeps the failure
// visible and, unlike a generated fallback, produces no restart loop.
const adminPassword = await storeJson
.read((s) => s.adminPassword)
.const(effects)
Expand All @@ -27,17 +19,12 @@ export const main = sdk.setupMain(async ({ effects }) => {
sdk.Mounts.of().mountVolume({
volumeId: 'main',
subpath: null,
// The image's HOME is /root, and OpenCode keeps everything — sessions
// database, provider credentials, cloned repositories and the user's
// own projects — under it. Mounting the whole home persists it all.
mountpoint: '/root',
readonly: false,
}),
'opencode-sub',
),
exec: {
// The image's entrypoint is the `opencode` binary itself; override only
// the command so it runs the server rather than the interactive TUI.
command: sdk.useEntrypoint([
'serve',
'--hostname',
Expand All @@ -47,7 +34,6 @@ export const main = sdk.setupMain(async ({ effects }) => {
]),
env: {
OPENCODE_PASSWORD: adminPassword,
// Never let the container try to replace its own binary.
OPENCODE_DISABLE_AUTOUPDATE: '1',
},
},
Expand Down
8 changes: 2 additions & 6 deletions startos/manifest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ export const manifest = setupManifest({
id: 'opencode',
title: 'OpenCode',
license: 'MIT',
packageRepo: 'https://github.com/jonbotx/opencode-startos',
packageRepo: 'https://github.com/Start9-Community/opencode-startos',
upstreamRepo: 'https://github.com/anomalyco/opencode',
marketingUrl: 'https://opencode.ai',
donationUrl: null,
description: { short, long },
// `main` is the container's home directory (sessions, credentials,
// repositories and projects); `startos` holds the generated login password
// and is never mounted into the container.
// `startos` holds the login password and is never mounted into the container.
volumes: ['main', 'startos'],
images: {
// Built from ./Dockerfile: the upstream image plus the git and bash the
// Alpine base omits (see the Dockerfile for why).
opencode: {
source: { dockerBuild: {} },
arch: ['x86_64', 'aarch64'],
Expand Down
3 changes: 0 additions & 3 deletions startos/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
// The internal port the OpenCode server binds and that the `ui` interface is
// exported on. Kept in one place so startos/main.ts (which launches it and
// health-checks it) and startos/interfaces.ts (which exposes it) cannot drift.
export const uiPort = 4096