Skip to content

feat: add Codex CLI provider for subprocess integration#80

Merged
lxowalle merged 8 commits intosipeed:mainfrom
Leeaandrob:feat/codex-cli-provider
Feb 16, 2026
Merged

feat: add Codex CLI provider for subprocess integration#80
lxowalle merged 8 commits intosipeed:mainfrom
Leeaandrob:feat/codex-cli-provider

Conversation

@Leeaandrob
Copy link
Collaborator

Summary

  • Add CodexCliProvider that wraps codex exec --json as a subprocess, analogous to the existing ClaudeCliProvider pattern
  • Add credential reader for ~/.codex/auth.json with token expiry detection (based on file mtime + 1h)
  • Integrate into provider factory: provider: "codex-cli" for subprocess mode, auth_method: "codex-cli" for API mode with local CLI tokens
  • Fix tilde ~ expansion in workspace path for all CLI providers (cfg.WorkspacePath() instead of raw config value)

New Files

File Description
codex_cli_provider.go Subprocess wrapper: builds prompt, runs codex exec --json, parses JSONL events
codex_cli_credentials.go Reads ~/.codex/auth.json, estimates token expiry from file mtime
codex_cli_provider_test.go 29 tests: JSONL parsing, prompt building, mock CLI, context cancel
codex_cli_credentials_test.go 8 tests: valid/invalid/expired credentials, CODEX_HOME env

Configuration

{
  "agents": {
    "defaults": {
      "provider": "codex-cli",
      "model": "codex-cli"
    }
  }
}

Or use Codex CLI tokens with the HTTP API provider:

{
  "providers": {
    "openai": {
      "auth_method": "codex-cli"
    }
  }
}

Test plan

  • All 37 Codex-related unit tests passing
  • go vet ./... clean
  • Tested locally: picoclaw agent -m "test" returns valid response with provider: "codex-cli"
  • Verified no regression on existing providers

Add CodexCliProvider that wraps `codex exec --json` as a subprocess,
analogous to the existing ClaudeCliProvider pattern. This enables using
OpenAI's Codex CLI tool as a local LLM backend.

- CodexCliProvider: subprocess wrapper parsing JSONL event stream
- Credential reader for ~/.codex/auth.json with token expiry detection
- Factory integration: provider "codex-cli" and auth_method "codex-cli"
- Fix tilde expansion in workspace path for CLI providers
- 37 unit tests covering parsing, prompt building, credentials, and mocks
- Extract shared tool call parsing into tool_call_extract.go
  (extractToolCallsFromText, stripToolCallsFromText, findMatchingBrace)
- Both ClaudeCliProvider and CodexCliProvider now share the same
  tool call extraction logic for PicoClaw-specific tools
- Fix cache token accounting: include cached_input_tokens in total
- Add 2 new tests for tool call extraction from JSONL events
- Update existing tests for corrected token calculations
Dockerfile used golang:1.24-alpine but go.mod requires go >= 1.25.7.
This caused Docker builds to fail on all branches with:
  "go: go.mod requires go >= 1.25.7 (running go 1.24.13)"

Update to golang:1.25-alpine to match the project requirement.
@Leeaandrob
Copy link
Collaborator Author

Docker build fix included

The Docker build was failing on all branches (including main) because Dockerfile used golang:1.24-alpine while go.mod requires go >= 1.25.7:

go: go.mod requires go >= 1.25.7 (running go 1.24.13; GOTOOLCHAIN=local)

This PR includes a fix: updated FROM golang:1.24-alpineFROM golang:1.25-alpine to match the project requirement.

This is a pre-existing issue unrelated to the Codex CLI provider changes.

@spa5k
Copy link

spa5k commented Feb 12, 2026

I was thinking about doing this myself lol.

@Leeaandrob
Copy link
Collaborator Author

Superseded by upstream codex_provider.go (API-based via OpenAI SDK). The CLI subprocess approach is no longer needed.

@Leeaandrob
Copy link
Collaborator Author

Reopened: The Codex CLI provider (subprocess wrapper for the codex binary) is a different approach from the existing codex_provider.go (API SDK via HTTP). Both serve different use cases, similar to how claude_cli_provider.go coexists with the Anthropic HTTP provider. Closing this was a mistake.

@Leeaandrob Leeaandrob reopened this Feb 13, 2026
Resolve Dockerfile conflict (pin golang:1.25.7-alpine from upstream).
Codex writes diagnostic messages to stderr (e.g. rollout errors) which
cause non-zero exit codes even when valid JSONL output exists on stdout.
Parse stdout first before checking exit code to avoid false errors.
- Remove trailing whitespace in web.go and base_test.go
- Update config_test.go and web_test.go for WebSearchToolOptions API
Accept upstream deepseek provider, updated web tools tests, and
DuckDuckGo config test. Keep codex-cli provider case alongside
new upstream providers.
@lxowalle
Copy link
Collaborator

Thanks for the pr.

@lxowalle lxowalle merged commit e77b0a6 into sipeed:main Feb 16, 2026
3 checks passed
edgargomero pushed a commit to edgargomero/kntorclaw that referenced this pull request Feb 16, 2026
* feat: add Codex CLI provider for OpenAI subprocess integration

Add CodexCliProvider that wraps `codex exec --json` as a subprocess,
analogous to the existing ClaudeCliProvider pattern. This enables using
OpenAI's Codex CLI tool as a local LLM backend.

- CodexCliProvider: subprocess wrapper parsing JSONL event stream
- Credential reader for ~/.codex/auth.json with token expiry detection
- Factory integration: provider "codex-cli" and auth_method "codex-cli"
- Fix tilde expansion in workspace path for CLI providers
- 37 unit tests covering parsing, prompt building, credentials, and mocks

* fix: add tool call extraction to Codex CLI provider

- Extract shared tool call parsing into tool_call_extract.go
  (extractToolCallsFromText, stripToolCallsFromText, findMatchingBrace)
- Both ClaudeCliProvider and CodexCliProvider now share the same
  tool call extraction logic for PicoClaw-specific tools
- Fix cache token accounting: include cached_input_tokens in total
- Add 2 new tests for tool call extraction from JSONL events
- Update existing tests for corrected token calculations

* fix(docker): update Go version to match go.mod requirement

Dockerfile used golang:1.24-alpine but go.mod requires go >= 1.25.7.
This caused Docker builds to fail on all branches with:
  "go: go.mod requires go >= 1.25.7 (running go 1.24.13)"

Update to golang:1.25-alpine to match the project requirement.

* fix: handle codex CLI stderr noise without losing valid stdout

Codex writes diagnostic messages to stderr (e.g. rollout errors) which
cause non-zero exit codes even when valid JSONL output exists on stdout.
Parse stdout first before checking exit code to avoid false errors.

* style: fix gofmt formatting and update web search API in tests

- Remove trailing whitespace in web.go and base_test.go
- Update config_test.go and web_test.go for WebSearchToolOptions API
emadomedher pushed a commit to emadomedher/picoclaw that referenced this pull request Feb 17, 2026
* feat: add Codex CLI provider for OpenAI subprocess integration

Add CodexCliProvider that wraps `codex exec --json` as a subprocess,
analogous to the existing ClaudeCliProvider pattern. This enables using
OpenAI's Codex CLI tool as a local LLM backend.

- CodexCliProvider: subprocess wrapper parsing JSONL event stream
- Credential reader for ~/.codex/auth.json with token expiry detection
- Factory integration: provider "codex-cli" and auth_method "codex-cli"
- Fix tilde expansion in workspace path for CLI providers
- 37 unit tests covering parsing, prompt building, credentials, and mocks

* fix: add tool call extraction to Codex CLI provider

- Extract shared tool call parsing into tool_call_extract.go
  (extractToolCallsFromText, stripToolCallsFromText, findMatchingBrace)
- Both ClaudeCliProvider and CodexCliProvider now share the same
  tool call extraction logic for PicoClaw-specific tools
- Fix cache token accounting: include cached_input_tokens in total
- Add 2 new tests for tool call extraction from JSONL events
- Update existing tests for corrected token calculations

* fix(docker): update Go version to match go.mod requirement

Dockerfile used golang:1.24-alpine but go.mod requires go >= 1.25.7.
This caused Docker builds to fail on all branches with:
  "go: go.mod requires go >= 1.25.7 (running go 1.24.13)"

Update to golang:1.25-alpine to match the project requirement.

* fix: handle codex CLI stderr noise without losing valid stdout

Codex writes diagnostic messages to stderr (e.g. rollout errors) which
cause non-zero exit codes even when valid JSONL output exists on stdout.
Parse stdout first before checking exit code to avoid false errors.

* style: fix gofmt formatting and update web search API in tests

- Remove trailing whitespace in web.go and base_test.go
- Update config_test.go and web_test.go for WebSearchToolOptions API
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.

3 participants