Skip to content

[Phase 4] OpenCode Engine Adapter #416

Description

@frankbria

Summary

Implement an AgentAdapter for OpenCode, an open-source terminal-based AI coding assistant, allowing CodeFrame to delegate code writing to OpenCode as a subprocess.

Parent issue: #408

Motivation

OpenCode is a fast, terminal-native AI coding tool with multi-model support and strong file editing. It provides a different execution profile from Claude Code and can work with multiple LLM providers (OpenAI, Anthropic, etc.), giving CodeFrame users flexibility in which underlying model powers their coding agent.

Scope

New module: core/engines/opencode.py

  1. OpenCodeAdapter implementing AgentAdapter:
class OpenCodeAdapter:
    name = "opencode"
    requires_api_key = {}  # OpenCode manages its own API keys/config
    
    def execute(self, task_prompt, workspace_path, context, timeout_ms):
        # 1. Build task prompt from context packager
        # 2. Launch opencode in non-interactive/script mode
        #    with cwd=workspace_path
        # 3. Capture output
        # 4. Parse results into AgentResult
        ...
  1. OpenCode CLI invocation:

    • Research OpenCode's non-interactive/scripting mode
    • Pass task prompt via appropriate mechanism (stdin, flag, or file)
    • Set cwd to workspace path
    • Disable auto-commits (CodeFrame owns git workflow)
  2. Output parsing:

    • Detect modified files via git diff after execution
    • Parse success/failure from exit code and output
    • Extract summary from completion output
  3. Configuration:

    • opencode_path: path to opencode binary (default: opencode)
    • opencode_model: LLM model override (optional)
    • opencode_flags: additional CLI flags

Acceptance Criteria

  • OpenCodeAdapter implements AgentAdapter protocol
  • OpenCode launched as subprocess with correct cwd
  • Task prompt passed via appropriate mechanism
  • Timeout enforced
  • Modified files detected via git diff
  • Works with cf work start <id> --execute --engine opencode
  • Integration test with mock binary

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-4.5Phase 4.5: Context Engineering & Additional Adapters

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions