ocruntime package + native tmux runtime (#376) #389

Closed
opened 2026-07-19 10:32:45 +02:00 by dries · 0 comments
Owner

Parent

#388 (spec), #376, epic #375. Spec: spec/runtime-neutral-lifecycle/requirements.md (AD-1, AD-3, AD-4, AD-10).

What to build

A new internal/ocruntime package that abstracts how a project's OpenCode instance is hosted, with a native-tmux implementation. This is the plug point #375's container runtime slots into. Built and unit-tested in isolation; not yet wired into the host (that is the next ticket).

Runtime interface: Launch(ctx, LaunchSpec) (*Instance, error), Probe(ctx, *Instance) bool, Stop(ctx, *Instance) error. LaunchSpec{RepoRoot, Host, Port, PermissionJSON} (secret field added by #377). Instance{Endpoint, Kind, ID, PID, secret(unexported)}.

Native runtime: Launch threads the given ocman-allocated port into the tmux launch (opencode --port N, replacing --port 0), seeds OPENCODE_PERMISSION, returns Endpoint (full base URL) + Kind="native-tmux" + tmux session name as ID. Probe = GET /config returns 200. Stop kills the tmux session. A free-loopback-port allocator (bind→close) lives here or in a small helper (host will call it — AD-3 says allocation is host policy, but the helper can live alongside).

Native tmux behavior stays compatible: same tmux.SessionNameForPath, same attachable window, same permission seeding.

Acceptance criteria

  • internal/ocruntime exposes the Runtime interface + LaunchSpec/Instance types; secret is unexported (with a ponytail: note for #377).
  • Native Launch launches opencode --port N (not --port 0) with the allocated port and seeds OPENCODE_PERMISSION.
  • Native Probe returns true only when GET /config answers 200; false on refused/500/other.
  • Native Stop tears down the tmux session.
  • Free-port allocator returns a port that then binds successfully (runnable self-check).
  • Tests cover Launch port-threading, Probe (200/500/refused via httptest), Stop, and allocation. Coverage ratchet: new code ships with tests.

Blocked by

None — can start immediately.

## Parent #388 (spec), #376, epic #375. Spec: `spec/runtime-neutral-lifecycle/requirements.md` (AD-1, AD-3, AD-4, AD-10). ## What to build A new `internal/ocruntime` package that abstracts how a project's OpenCode instance is hosted, with a native-tmux implementation. This is the plug point #375's container runtime slots into. Built and unit-tested in isolation; not yet wired into the host (that is the next ticket). `Runtime` interface: `Launch(ctx, LaunchSpec) (*Instance, error)`, `Probe(ctx, *Instance) bool`, `Stop(ctx, *Instance) error`. `LaunchSpec{RepoRoot, Host, Port, PermissionJSON}` (secret field added by #377). `Instance{Endpoint, Kind, ID, PID, secret(unexported)}`. Native runtime: `Launch` threads the given ocman-allocated port into the tmux launch (`opencode --port N`, replacing `--port 0`), seeds `OPENCODE_PERMISSION`, returns `Endpoint` (full base URL) + `Kind="native-tmux"` + tmux session name as `ID`. `Probe` = `GET /config` returns 200. `Stop` kills the tmux session. A free-loopback-port allocator (bind→close) lives here or in a small helper (host will call it — AD-3 says allocation is host policy, but the helper can live alongside). Native tmux behavior stays compatible: same `tmux.SessionNameForPath`, same attachable window, same permission seeding. ## Acceptance criteria - [ ] `internal/ocruntime` exposes the `Runtime` interface + `LaunchSpec`/`Instance` types; `secret` is unexported (with a `ponytail:` note for #377). - [ ] Native `Launch` launches `opencode --port N` (not `--port 0`) with the allocated port and seeds `OPENCODE_PERMISSION`. - [ ] Native `Probe` returns true only when `GET /config` answers 200; false on refused/500/other. - [ ] Native `Stop` tears down the tmux session. - [ ] Free-port allocator returns a port that then binds successfully (runnable self-check). - [ ] Tests cover Launch port-threading, Probe (200/500/refused via httptest), Stop, and allocation. Coverage ratchet: new code ships with tests. ## Blocked by None — can start immediately.
dries closed this issue 2026-07-19 18:10:58 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#389
No description provided.