Skip to content

Conversation

@shinpr
Copy link
Owner

@shinpr shinpr commented Dec 12, 2025

Summary

This PR adds support for OpenAI Codex CLI as a fourth execution engine alongside Cursor, Claude, and Gemini.

Changes

  • ServerConfig.ts: Add codex to AGENT_TYPE options
  • AgentExecutor.ts: Implement Codex command execution using codex exec --json format
  • StreamProcessor.ts: Add parser for Codex's streaming JSON output format
    • Detects Codex format via thread.started event
    • Accumulates agent_message items
    • Completes on turn.completed event
  • StreamProcessor.test.ts: Add behavior-focused tests for Codex parsing
  • README.md: Document Codex support in configuration section
  • RunAgentTool.ts: Make cwd parameter required (see Breaking Change below)

Codex Output Format

Codex uses a different output structure than other CLIs:

{"type":"thread.started","thread_id":"..."}
{"type":"turn.started"}
{"type":"item.completed","item":{"type":"reasoning","text":"..."}}
{"type":"item.completed","item":{"type":"agent_message","text":"..."}}
{"type":"turn.completed","usage":{...}}

Usage

{
  "env": {
    "AGENTS_DIR": "/path/to/agents",
    "AGENT_TYPE": "codex"
  }
}

⚠️ Breaking Change

cwd parameter is now required when calling the run_agent tool.

This change ensures consistent behavior across all CLI backends. Codex CLI requires execution within a trusted directory (git repository), and relying on process.cwd() was unreliable as it depends on where the MCP server was started.

MCP clients must now explicitly pass the cwd parameter:

{
  "agent": "my-agent",
  "prompt": "Do something",
  "cwd": "/path/to/working/directory"
}

Test Plan

  • All 257 existing tests pass
  • New Codex parser tests added and passing
  • Lint, type check, and build all pass
  • Manual testing with actual Codex CLI confirmed working

🤖 Generated with Claude Code

shinpr and others added 3 commits December 12, 2025 21:54
- Add 'codex' to AGENT_TYPE options in ServerConfig.ts
- Implement Codex command execution in AgentExecutor.ts
  - Uses `codex exec --json` command format
- Add Codex output parser in StreamProcessor.ts
  - Detects Codex format via thread.started event
  - Accumulates agent_message items
  - Completes on turn.completed event
- Add behavior-focused tests for Codex output parsing
- Update README.md with Codex documentation
- Bump version to 0.4.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The cwd parameter is now required to ensure consistent behavior across
all CLI backends. This prevents issues with Codex CLI which requires
execution within a trusted directory (git repository).

Changes:
- Update inputSchema to include cwd in required array
- Add validation for cwd parameter (non-empty, max length, no path traversal)
- Update RunAgentParams interface to make cwd non-optional
- Fix all tests to provide cwd parameter

BREAKING CHANGE: cwd parameter is now required when calling run_agent tool

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
… injection

Update prompt description to clarify that only the user's direct request
content should be passed, not meta-instructions like "call the agent".
This helps MCP clients generate cleaner prompts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@shinpr shinpr self-assigned this Dec 12, 2025
shinpr and others added 2 commits December 12, 2025 23:13
Help users understand that agent requests should include what they want
done, not just which agent to use. Vague requests like "use the agent"
without a task lead to poor results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Replace Japanese strings in StreamProcessor tests with English equivalents
for consistency and international readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@shinpr shinpr marked this pull request as ready for review December 12, 2025 14:17
@shinpr shinpr merged commit be3ceaf into main Dec 12, 2025
4 checks passed
@shinpr shinpr deleted the feature/codex-support branch December 12, 2025 14:17
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