Skip to content

feat(opencode): support native OpenCode v2 provider - #131

Merged
AllenReder merged 2 commits into
mainfrom
feat/opencode-v2-provider
Sep 26, 2026
Merged

AllenReder merged 2 commits into
mainfrom
feat/opencode-v2-provider

Conversation

@AllenReder

Copy link
Copy Markdown
Owner

Summary

Implements #125: Awen's OpenCode provider now speaks the native OpenCode v2 server contract instead of the v1 contract. OpenCode v1 is no longer supported (ADR-0021).

  • Replace the v1 @opencode-ai/sdk with the official @opencode/client, pinned to 2.0.12; MINIMUM_OPENCODE_VERSION is now 2.0.12.
  • Accept the v2 serve ready line (server listening on <url>, case-insensitive, matched anywhere on the line), and keep an unterminated readiness line pending instead of resolving a truncated URL.
  • Probe health via server.info; load providers, models, agents, skills, and commands through the v2 client per Workspace directory.
  • Managed servers get a generated password (injected as OPENCODE_PASSWORD) and authenticate with Basic auth; startup diagnostics redact it. OPENCODE_CONFIG_CONTENT no longer defaults to {}, so the managed server reads the user's own OpenCode config.
  • Wait for the v2 provider registry before reporting a "no upstream providers" warning, so the first status check does not cache a transient empty inventory.
  • Exclude disabled providers/models from the catalog and connected count.
  • Remove the v1 CLI-parser inventory fallback and its tests; add an opt-in real-binary integration test.

Verification

  • pnpm typecheck green for the workspace; lint and fmt:check clean.
  • OpenCode suite passes, including the opt-in real-binary integration test against OpenCode 2.0.18 on Windows (AWEN_TEST_OPENCODE_V2_BINARY): managed startup, auth rejection without a password, chat/approval/fork/compaction, and a real adapter turn over an external serverUrl.

Notes

  • ADR: docs/adr/0021-opencode-v2-only-support.md.
  • Machines on OpenCode 1.x must upgrade to 2.0.12 or newer.
  • Upstream merged only a two-line ready-line fix (pingdotgg/t3code#13651); this ports the full native v2 migration.

Closes #125

Awen's OpenCode provider still spoke the OpenCode 1 server contract: it
waited for the `opencode server listening` banner, called v1 root HTTP
routes, and assumed no server authentication. OpenCode 2 prints
`server listening on <url>`, serves its API under `/api/*`, and requires a
server password, so every managed server start ended in
`Timed out waiting for OpenCode server start after 30000ms` (issue #125).

Port the native v2 integration (adapting pingdotgg/t3code#13008 /
gidorah/t3code#3) and drop v1 (ADR-0021):

- Replace the v1 `@opencode-ai/sdk` with the official `@opencode/client`,
  pinned to 2.0.12, and raise MINIMUM_OPENCODE_VERSION to 2.0.12.
- Parse the v2 ready line with a tolerant `server listening on <url>`
  match instead of requiring the v1 prefix, and stop assuming the URL
  arrives newline-terminated.
- Probe health through `server.info`, and load providers, models, agents,
  skills, and commands through the v2 client with the Workspace directory.
- Generate a per-server password for managed servers, inject it as
  `OPENCODE_PASSWORD`, authenticate with Basic auth, and redact it from
  startup diagnostics.
- Delete the v1 CLI-parser inventory fallback and its tests; rewrite the
  runtime, provider, adapter, and text-generation tests against native v2
  execution/inbox events; add an opt-in real-binary integration test that
  also proves the managed server rejects unauthenticated requests.

Awen-specific provider presentation (`approvalRequestKinds`) and `@awen/*`
scopes are preserved. The upstream merged ready-line band-aid
(pingdotgg/t3code#13651) is superseded. Machines on OpenCode 1.x must
upgrade to 2.0.12 or newer.

Refs #125
OpenCode v2 prints its serve banner before its provider registry finishes
loading, so `/api/provider` and `/api/model` can briefly report nothing.
`checkOpenCodeProviderStatus` read that empty inventory once and cached a
false "did not report any connected upstream providers" warning with 0
models on the first check after startup, even though a later refresh
showed the providers.

Poll the inventory until providers and models are both present, or a
bounded wall-clock deadline passes, so the first status check reflects
the warm server instead of a transient empty registry. The client is
created once and reused across attempts, and the wait deliberately uses a
wall-clock timer so it does not freeze under a test clock.

Refs #125
@AllenReder
AllenReder merged commit 402572c into main Sep 26, 2026
13 checks passed
@AllenReder
AllenReder deleted the feat/opencode-v2-provider branch September 26, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: opencode provider 无法识别

1 participant