Repository navigation
Conversation
The OpenCode integration could not launch or talk to OpenCode v2.x servers,
so tapping OpenCode in the app always failed.
Three separate v2 incompatibilities are addressed:
1. Ready-line banner. `createOpencodeServer()` from the bundled
`@opencode-ai/sdk` waits for a line starting with
"opencode server listening". v2 prints "server listening on <url>",
so the match never fired and the SDK killed the server after the
15s timeout ("Timeout waiting for server to start after 15000ms").
We now discover and reuse an already-running server instead of
relying on that banner:
- `OPENCODE_SERVER_URL` (explicit override)
- probe the default port (4096)
- read `~/.config/opencode/service.json` written by
`opencode serve --service`, including its password
Servers discovered this way are marked external and are never
killed on `destroy()`; only servers we spawned are closed.
2. Authentication. v2 servers generate a per-server password. The CLI
built its client with a random Basic header that v2 rejects with 401.
The password read from `service.json` is now used for Basic auth.
3. Session list endpoint and payload shape. The SDK's
`experimental.session.list` requests `/experimental/session`, which
v2.1.4 serves as the web UI (text/html) rather than JSON, so the SDK
threw "Request is not supported by this version of OpenCode Server
(Server responded with text/html)". We now fall back to a direct
request against `/api/session`, and normalize the v2 payload into
the v1 shape the app expects: `directory` comes from
`location.directory`, `slug` is derived when absent, `version` comes
from `/api/info`, and `project` is reconstructed. v1-shaped
responses pass through unchanged.
Fixes shellular-org#117
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #117.
Problem
Tapping OpenCode in the app always failed against an OpenCode v2.x server. Three separate v2 incompatibilities were involved.
1. Ready-line banner (the 15s timeout)
createOpencodeServer()from the bundled@opencode-ai/sdk@1.18.18waits for a stdout line starting withopencode server listening:OpenCode v2 prints
server listening on http://127.0.0.1:40201instead, so the match never fires and the SDK kills the server aftertimeoutms, surfacing as:2. Per-server password
v2 generates a password per server. The CLI built its client with a random Basic header (
Basic base64(shellular:<random32>)) that v2 rejects with 401, and never read the printed password.3. Session list endpoint returns HTML
experimental.session.listrequests/experimental/session. On v2.1.4 that path serves the web UI:so the SDK's response interceptor throws:
The real JSON API is at
/api/session:The v2 payload also differs in shape from what the app expects:
directorylives underlocation.directory, andslug/version/projectare absent.Changes
All in
cli/src/agents/opencode.ts:OPENCODE_SERVER_URL→ default port 4096 probe →~/.config/opencode/service.json(written byopencode serve --service). Discovered servers are markedexternaland are never killed indestroy(); only servers we spawn are closed.service.jsonfor Basic auth instead of a random one./api/sessionwhen the SDK call fails, and normalize the v2 response into the v1 shape:directoryfromlocation.directory,slugderived from the title when missing,versionfrom/api/info,projectreconstructed fromprojectID+ directory. v1-shaped payloads pass through unchanged, so older servers keep working.Verification
Against OpenCode v2.1.4 on Linux, paired with the iOS app (0.0.43):
tsc --noEmitcleanbiome checkcleanpnpm run buildsucceedsNote the server was already running as a background service, so the spawn path (and therefore the banner fix itself) is not exercised here — it remains the fallback when no server is discoverable.