-
Notifications
You must be signed in to change notification settings - Fork 701
feat(cli): add OpenCode agent support via ACP #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add full OpenCode CLI integration using the Agent Client Protocol (ACP), enabling Happy Coder to work with OpenCode as an alternative backend. New files: - cli/src/opencode/constants.ts - Environment variables and model constants - cli/src/opencode/runOpenCode.ts - Main entry point for OpenCode sessions - cli/src/agent/factories/opencode.ts - Backend factory for ACP - cli/src/agent/transport/handlers/OpenCodeTransport.ts - Transport handler - cli/src/ui/ink/OpenCodeDisplay.tsx - Terminal UI component Usage: happy opencode # Start OpenCode mode OPENCODE_API_KEY=... # Or ANTHROPIC_API_KEY OPENCODE_MODEL=... # Optional model override Supported models: - anthropic/claude-sonnet-4-20250514 (default) - anthropic/claude-opus-4-20250514 - openai/gpt-4o - openai/o1 - google/gemini-2.5-pro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a11884c075
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| session.sendAgentMessage('opencode', { | ||
| type: 'task_complete', | ||
| id: randomUUID(), | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset diff tracking after each turn
The OpenCode loop ends a turn by emitting task_complete, but it never clears the GeminiDiffProcessor state (it is only reset on abort). Because the diff processor caches per-path diffs to suppress duplicates, keeping that cache across turns can suppress legitimate diff updates when a later turn produces the same patch (e.g., retrying or undo/redo), and it can grow unbounded over long sessions. Consider resetting the diff processor at the same point you send task_complete so each turn starts with a clean diff state.
Useful? React with 👍 / 👎.
|
Ok, thank you for taking a shot at this and getting it working. I think you and @leeroybrun are doing the same thing with opencode. I don't know enough about the various opencode PRs tonight, but I will tomorrow. |
- Increase init timeout from 60s to 120s (OpenCode loads many plugins) - Filter OpenCode-specific log messages (service=, bun output, plugin loading) - Prevents JSON-RPC parsing failures from debug output
The cwd is already passed via spawn options, passing it again as an argument could cause issues with duplicate path handling.
Summary
Add full OpenCode CLI integration using the Agent Client Protocol (ACP), enabling Happy Coder to work with OpenCode as an alternative backend.
Changes
New Files
cli/src/opencode/constants.ts- Environment variables and model constantscli/src/opencode/runOpenCode.ts- Main entry point for OpenCode sessions (~730 lines)cli/src/agent/factories/opencode.ts- Backend factory for ACPcli/src/agent/transport/handlers/OpenCodeTransport.ts- Transport handlercli/src/ui/ink/OpenCodeDisplay.tsx- Terminal UI componentModified Files
cli/src/index.ts- Addhappy opencodesubcommandcli/src/agent/factories/index.ts- Export opencode factorycli/src/agent/transport/handlers/index.ts- Export opencode transportcli/src/agent/transport/index.ts- Export opencode transportcli/src/utils/createSessionMetadata.ts- Add 'opencode' flavor typeUsage
Supported Models
anthropic/claude-sonnet-4-20250514(default)anthropic/claude-opus-4-20250514openai/gpt-4oopenai/o1google/gemini-2.5-proImplementation Details
The implementation follows the same patterns established by the Gemini integration:
Testing
npm run build)happy opencodeoption