Fall back to Homebrew and local install locations when opencode is not on the
service's minimal PATH, so a launchd/systemd restart cannot fail a run with
exec: opencode not found.
Brokered chat accepted an operator-supplied endpoint (-opencode-endpoint /
PIPELINES_OPENCODE_ENDPOINT) but failed closed against the operator's running
V2 service: that API authenticates every request with HTTP Basic auth (fixed
user "opencode" plus a password), the broker had no credential, so the health
probe answered 401 and startup logged "OpenCode endpoint ... is unreachable or
is not an OpenCode service", disabling chat entirely.
Established from the installed binary (opencode v2.0.20), not from docs:
`opencode --help` advertises `api`, `pair`, `serve`, `service` and `auth`;
`GET /api/info` is unauthenticated-401 with www-authenticate Basic realm
"Secure Area"; Basic auth user `opencode` with the password from
~/.local/state/opencode/service.json answers 200; `POST /api/pair` returns a
code and `GET /auth/connect/{code}` returns a token that is then accepted as
the Basic password.
- internal/opencode/pair.go (new): PairEndpoint does the pair exchange over the
shared nativeRequest transport (same auth, bounds and JSON checks);
ReadServiceCredential reads the operator's local service password under the
private-file rule; OpenEndpointAttached resolves the credential in precedence
order - explicit password file, a paired token stored by an earlier run, then
a fresh pairing bootstrapped by the local service credential - stores the
token owner-only and re-pairs once when a stored token is refused (401).
- internal/opencode/endpoint.go: OpenEndpoint wraps probeEndpoint, which returns
the connection even on failure; Connection.unauthorized (set on HTTP 401 by
the request paths, cleared per probe) distinguishes an authentication refusal
from any other refusal.
- cmd/pipelines-server/main.go: the endpoint attach uses OpenEndpointAttached
with the paired-credential file beside the pipeline database. An endpoint that
cannot be attached logs a line naming it and falls back to the server's own
OpenCode instance instead of leaving chat refused.
- internal/protocol/status.go, internal/server/websocket.go: get_status gains an
opencode object (health = endpoint | fallback | spawned | unavailable, plus
the endpoint url), the honest status evidence for the fallback. No credential
is ever placed there.
- Tests: internal/opencode/pair_test.go, internal/protocol/status_test.go and a
TestStatusReportsOpenCodeAttachment case in internal/server/status_test.go.
Repository checks: go build ./..., go vet ./... and gofmt -l . clean;
go test ./internal/... ./cmd/... green.
Packaged templates and skill references: the repository has no template tree
that mentions the OpenCode endpoint, and no packaged reference file is added, so
internal/author/install.go's managed inventory is unchanged. The packaged
authoring reference internal/author/skill/references/operations.md (the endpoint
paragraph around line 289, the "clear refusal and no fallback" wording and the
password-file/username-only credential story, and the missing opencode status
field) is now stale; per the maintenance convention the item does not edit the
shared document and instead records the stale points, with the exact wording
they should take, in docs/notes/chat-persistence.md for the docs-fold writer.
Add an opt-in way to broker chat from an operator-supplied OpenCode service
instead of the instance the server spawns for itself, and a way to adopt a
session that already exists on that endpoint so it appears in chat_sessions and
can be continued from the app.
- Endpoint selection: the `-opencode-endpoint` server flag (defaulting to
`PIPELINES_OPENCODE_ENDPOINT`) opts in; precedence is explicit flag >
explicit environment > the endpoint recorded on a previous run, with the
spawned instance as the default. opencode.OpenEndpoint validates the
reference once (http(s), host, no userinfo/query/fragment/path), detects the
backend from its own /api/info (v2) or /global/health (v1) contract, and
requires a streamable text/event-stream event path. It owns no process
(Close is a no-op) and never calls startServe; every failure names the
endpoint and disables chat rather than silently falling back. An
authenticated endpoint takes an optional password only through the private
file PIPELINES_OPENCODE_ENDPOINT_PASSWORD_FILE, with
PIPELINES_OPENCODE_ENDPOINT_USERNAME overriding the detected default.
- Persistence: the validated choice is recorded in an additive single-row
server_settings table so a restart with no flag/environment reuses it; an
unreachable recorded endpoint disables chat with a clear message and no
fallback.
- chat_adopt: a new protocol request (ChatAdoptRequest) with handleChatAdopt in
internal/server/chat.go. It refuses a nil broker/registry/payload and a
blank or foreign-shaped id before any endpoint call, reads the endpoint via
the shared Chat.Session (which reuses Sessions/decodeChatSessions), records
through the existing RecordOperatorSession with the endpoint's directory and
title verbatim, and echoes the adopted session plus its registry row like
chat_create. A missing id is refused naming the id and records nothing; an
endpoint record with an empty directory is refused rather than substituting
the server's working directory or home.
- CLI: `pipelines chat-adopt <session-id> [--json]` (usage, notes, help
inventory, dispatch) with docs/cli.md updated under Chat sessions.
- Autostart preserves the endpoint variables (and the password-file reference,
never an inline secret) via serviceEnvironmentKeys.
Checks before committing:
- Package location: the change is user-facing chat behaviour, so the packaged
authoring skill reference internal/author/skill/references/operations.md is
updated in the same change (Brokered OpenCode chat section) with a dated
verification-evidence entry and the not-deployed state. No new reference file
is added, so internal/author/install.go's managed inventory is unchanged.
- Packaged templates: this repository packages no template set for this
behaviour and none references the chat endpoint, so no template needs
updating.
- Verification: `go build ./...`, `go vet` on the touched packages, `gofmt -l`
clean and `go test ./...` all pass. The unit tests cover the endpoint
validation/precedence, the adopt happy path and refusals, the recorded
endpoint round-trip, the protocol round-trip and the CLI dispatch. The live
scratch-server check against the operator's real endpoint was not run in this
change.
Nothing unrelated is staged; docs left stale (README and other shared documents)
are not edited here and are for a single folding writer.
chat_sessions used to list exactly the OpenCode sessions the pipelines own,
filtered through pipeline.SessionOwner (run_steps/run_session_owners), so an
operator-created chat was an accident of the run-ownership table and the
operator's working sessions were mixed with the internals of running pipelines.
Add a first-class operator session:
- internal/pipeline/operator_sessions.go: a dedicated operator_sessions table
(session_id PK, directory, title, tag, created_at, last_used_at) with
RecordOperatorSession (upsert preserving created_at), a one-statement
TouchOperatorSession (no-op for a non-operator id), OperatorSessions bounded to
128 rows most-recently-used first, and OperatorDirectories (bounded MRU,
deduped). run_steps/run_session_owners and SessionOwner/OwnedSessions are
untouched.
- internal/server/chat.go: chat_sessions returns operator sessions only - it
reads the registry once, intersects it with one broker session-list call, fills
directory/tag/created/updated from the registry, sets busy for a session held
by another connection, keeps MRU order, and stays fail-closed (empty list, never
the endpoint's whole list). A pipeline stage session and an untagged row can
never be listed. chat_create resolves the directory (empty/'~'/'~/...' ->
operator home; relative or missing rejected before any OpenCode call), calls
broker.Create(title, resolved) and records the row with the operator tag.
chat_directories returns home first then bounded (8) deduped recents. A
successful prompt touches the operator session without affecting pipeline
prompts.
- internal/opencode, internal/protocol, internal/server/websocket.go and
message.go: unscoped session list, Create posts {"title":...,
"location":{"directory":...}} to POST /api/session, additive protocol fields
(omitempty) and the ChatDirectories request/response, plus the OperatorRegistry
option defaulting to the first store. One OpenCode transport per server is
unchanged.
Docs and references: docs/cli.md gains a "Chat sessions" section documenting the
operator-only fail-closed list, directory defaulting/rejection, chat_directories
(home first, deduped, bounded 8) and why a dedicated request was chosen.
internal/author/skill/references/operations.md's stale "Brokered OpenCode chat"
text (chat_create unbrokered, run_steps filtering, "listed the owned scratch
session" evidence) is rewritten to the operator-session registry, the fail-closed
filter, directory defaulting and the corrected live-test wording. No new
reference file, so internal/author/install.go's inventory is unchanged.
Checked for staleness elsewhere: README.md, the docs/ topic pages and the
packaged server/TUI templates carry no chat-session ownership claims, so none
needed updating.
Verified: gofmt -l clean; go vet and go build ./... clean; go test -count=1
./internal/pipeline/... ./internal/protocol/... ./internal/opencode/...
./internal/server/... and the full go test -count=1 ./... pass.
The installed OpenCode 2.0.20 exposes the authenticated SSE event firehose at
/api/event and the /api HTTP surface, but Detect selects backend "v2" and Open
returned no owned process/URL, so chat stayed disabled and every chat_* request
was answered with "chat is not configured on this server".
Add opencode.OpenStream/OpenChat: for either backend they start the single owned
opencode serve process, discover the loopback URL and verify the backend health
contract (/api/info for v2, /global/health for v1). main and the live test share
OpenChat so the selection cannot drift. Chat now streams real incremental
session.text.delta/session.reasoning.delta frames via the existing
Connection.EventStream + NormalizeChatEvent, with no polling and no fake
streaming.
- Authenticate the owned endpoint with the per-backend user (opencode for v2,
pipelines for v1); the v2 server ignores OPENCODE_SERVER_USERNAME.
- Send the V2 prompt shape {"text":...}, which the v1 translation also accepts.
- Skip firehose event types the adapter does not surface before decoding their
data, so session.instructions.updated (delta is an object) no longer fails the
stream.
Unit tests cover the per-backend user, the prompt shape/auth, the captured real
V2 event shapes and the selection guards. An opt-in live test drives
chat_sessions/chat_messages/a completed chat_prompt/an interrupted chat_prompt
against the installed OpenCode. Update the packaged operations reference with the
realized capability, dated evidence and deployment state.
Checks before commit: the packaged authoring reference
internal/author/skill/references/operations.md is updated in this change; no new
reference file was added, so internal/author/install.go's managed inventory is
unchanged and the internal/author tests pass. No packaged template describes the
brokered chat surface, and neither README.md nor the topic docs under docs/ (nor
web/) document it, so none of them needed updating.
Add the server-side half of the brokered chat path (route B): the
opencode.Chat adapter forwards chat_prompt to POST
/api/session/{id}/prompt through the owned Connection.Call translation
and derives chat_event frames from the authenticated /api/event SSE
firehose (text and reasoning deltas, tool parts with their status
transitions, step and usage). Every pushed frame carries a stable
session and message id, with a last-message-id fallback so step/tool
events that omit the assistant message id stay attributable.
The /connect handler keeps per-session retained state (chatHub) capped at
1 MiB with least-recently-updated eviction at 128 turns, so a
reconnecting client re-syncs through chat_messages instead of replaying
deltas the OpenCode per-session log never resends. Prompt dispatch
subscribes before posting and buffers pre-ack frames to preserve order,
and cancels the stream on disconnect so no goroutine leaks. chat_sessions
and chat_create are declared but not yet brokered: they answer with an
explicit protocol error rather than the generic Pong.
Reuse the existing transport, validation and normalization; no second
OpenCode transport or credential path is introduced.
Tests: protocol golden round-trip, adapter normalization + v1/v2 Call
translation, and handler ack/stream/validation/resume/disconnect, plus a
real-adapter no-tool evidence harness.
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers.
Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent.
Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.