Skip to content

feat(agent-adapter): probe and spawn opencode from the resolved binary (CODE-76)#244

Open
lucas77778 wants to merge 2 commits into
masterfrom
chenyu/code-76
Open

feat(agent-adapter): probe and spawn opencode from the resolved binary (CODE-76)#244
lucas77778 wants to merge 2 commits into
masterfrom
chenyu/code-76

Conversation

@lucas77778

Copy link
Copy Markdown
Member

Extracts the CODE-76 work from the code-248 branch as a standalone PR, rebased onto latest master (two cherry-picked commits).

Changes

  • OpencodeProbe (src/probe/opencode.ts): detects a user-installed opencode CLI — daemon PATH scan plus the official install location ~/.opencode/bin, each candidate verified via --version (bare semver, anchored whole-output match). opencode joins ProbeableKind and the default prober set, so it now appears in the agent-runtime.list wire resource.
  • opencode/serve.ts: all opencode serve spawns (per-session live server and the shared history server) now go through one owned spawn path — binary from agentRuntimeProber.resolveBinary('opencode') (managed → detected), bare-name PATH fallback for unprobed hosts. Replaces the SDK's createOpencodeServer, which hard-codes bare-name PATH resolution, cannot set cwd, and doesn't set windowsHide (Invariant 6).
  • history-server.ts slims down to the manager logic, delegating spawn/readiness/termination to serve.ts.
  • Docs and stale "opencode absent until CODE-76" markers updated across AGENTS.md, workbench hooks/onboarding, and the dev mock host.

Conflict resolution notes

The original commits were authored on the code-248 branch; cherry-picking onto master required resolving conflicts in AGENTS.md (root + agent-adapter) and history-server.ts imports. CODE-248 (pi adapter) context that leaked into the conflict hunks was deliberately excluded — this PR carries only the CODE-76 changes.

Verification

  • pnpm check:ci — 0 errors
  • pnpm test — 222 files / 1735 tests passed

Copilot AI review requested due to automatic review settings July 22, 2026 08:08
@linear-code

linear-code Bot commented Jul 22, 2026

Copy link
Copy Markdown

CODE-76

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds probe-based OpenCode binary resolution and centralizes its server lifecycle. The main changes are:

  • Detect OpenCode from PATH and its official install directory.
  • Resolve managed or detected binaries before spawning.
  • Share spawn, readiness, and shutdown logic across session and history servers.
  • Report OpenCode through the agent-runtime resource.
  • Update tests, mocks, and runtime documentation.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • Validated the pre-run state showed the bare-name spawn failed even though the opencode binary existed.
  • Validated the post-run state shows malformed version rejection, detection of server version 1.18.2, both server readiness paths, HTTP responses, and termination.
  • Examined the invocation evidence showing both child processes executed the exact opencode binary with proper PATH, serve arguments, working directory behavior, inherited session CWD, config marker, and two SIGTERM exits.
  • Assembled and uploaded runtime artifacts documenting the run, including the before-state, after-state, and invocation logs.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
packages/host/agent-adapter/src/native/opencode/serve.ts Adds shared binary resolution, process spawning, readiness detection, and shutdown handling.
packages/host/agent-adapter/src/native/opencode/adapter.ts Moves per-session OpenCode servers from the SDK spawn helper to the shared owned spawn path.
packages/host/agent-adapter/src/native/opencode/history-server.ts Delegates history-server process mechanics while preserving neutral cwd, retries, and idle reaping.
packages/host/agent-adapter/src/probe/opencode.ts Adds OpenCode executable discovery and bare-semver version validation.
packages/host/agent-adapter/src/probe/prober.ts Registers OpenCode in the default runtime probe set.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Probe[Probe OpenCode runtime] --> Managed{Managed binary?}
  Managed -->|Yes| Spawn[Spawn opencode serve]
  Managed -->|No| Detected{Detected binary?}
  Detected -->|Yes| Spawn
  Detected -->|No| Fallback[Bare PATH fallback]
  Fallback --> Spawn
  Spawn --> Session[Per-session server]
  Spawn --> History[Shared history server]
  Session --> Ready[Wait for listening URL]
  History --> Ready
  Ready --> Client[Create SDK client]
  Session --> Stop[SIGTERM then SIGKILL]
  History --> Reap[Idle reap]
  Reap --> Stop
Loading

Reviews (1): Last reviewed commit: "feat(agent-adapter): spawn opencode serv..." | Re-trigger Greptile

@lucas77778
lucas77778 requested a review from AprilNEA July 22, 2026 08:25
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.

2 participants