Skip to content

[Phase 4] Codex/OpenAI Engine Adapter (App-Server Protocol) #412

Description

@frankbria

Summary

Implement an AgentAdapter for OpenAI's Codex using the app-server JSON-RPC protocol defined in the Symphony spec. This adapter speaks the same protocol Symphony uses.

Parent issue: #408

Motivation

OpenAI's Codex has a well-defined app-server protocol (JSON-RPC over stdio) that Symphony already documents in detail (spec Section 10). Implementing this adapter makes CodeFrame compatible with the Codex ecosystem and any future agent that speaks this protocol.

Scope

New module: core/engines/codex.py

  1. CodexAdapter implementing AgentAdapter:
class CodexAdapter:
    name = "codex"
    requires_api_key = {"OPENAI_API_KEY": "OpenAI API key"}
    
    def execute(self, task_prompt, workspace_path, context, timeout_ms):
        # 1. Launch codex app-server subprocess
        # 2. Send initialize → initialized → thread/start → turn/start
        # 3. Stream turn events
        # 4. Handle turn/completed, turn/failed, turn/cancelled
        # 5. Return AgentResult
        ...
  1. App-server protocol implementation (per Symphony spec Section 10):

    • JSON-RPC message framing over stdio
    • Startup handshake: initializeinitializedthread/startturn/start
    • Turn streaming: read line-delimited JSON events
    • Completion detection: turn/completed, turn/failed, turn/cancelled
    • Approval handling: auto-approve by default (configurable)
    • Timeout: turn_timeout_ms, read_timeout_ms, stall_timeout_ms
  2. Configuration:

    • codex_command: path to Codex binary (default: codex app-server)
    • approval_policy: auto-approve, require-approval
    • sandbox_mode: configurable per Symphony spec
    • turn_timeout_ms: default 3600000 (1 hour)
  3. Event mapping:

    • Codex session_startedAgentEvent(type="progress")
    • Codex turn_completedAgentEvent(type="completed")
    • Codex notificationAgentEvent(type="progress")
    • Token usage extraction from Codex events

Acceptance Criteria

  • CodexAdapter implements AgentAdapter protocol
  • Full app-server handshake (initialize → thread/start → turn/start)
  • Turn streaming with proper line-delimited JSON parsing
  • Auto-approval of command/file change requests (configurable)
  • Timeout enforcement (turn, read, stall)
  • Token usage tracked from Codex events
  • Works with cf work start <id> --execute --engine codex
  • Integration test with mock app-server

Dependencies

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestphase-4.2Phase 4.2: First Adapter Implementations (Claude Code, Codex)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions