Skip to content

feat: adapt tools for Codex clients - #177

Open
Gan332 wants to merge 1 commit into
jasonxu114514:mainfrom
Gan332:fix/codex-tool-adapters
Open

Gan332 wants to merge 1 commit into
jasonxu114514:mainfrom
Gan332:fix/codex-tool-adapters

Conversation

@Gan332

@Gan332 Gan332 commented Nov 15, 2026

Copy link
Copy Markdown

Summary

Codex declares a single exec_command tool plus a freeform apply_patch, while the gateway advertises the official OpenCode toolset. Models therefore called shell/read/edit/… and Codex rejected them as unsupported call, retrying until the turn aborted.

This change binds the official tools to Codex's tools when the client declares exec_command, translates their arguments, and keeps apply_patch as a freeform custom tool in Responses and streamed output. It also normalizes content: null to "" for strict Chat providers.

Changes

  • internal/gateway/tooladapt.go: argument adapters for shell/bash → exec_command, todowrite → update_plan, and (on Windows) read/write/edit/glob/grep/webfetch/websearch/skill → PowerShell commands. The scripts avoid .NET calls so they run in Codex's ConstrainedLanguage sandbox.
  • internal/gateway/toolshape.go: Codex aliases and custom-tool detection; adapters are only registered when exec_command is declared, so Claude Code and OpenCode clients are unaffected.
  • internal/protocol/{tools,response,stream,stream_emitter}.go: argument transforms, custom tool call plumbing, and conversion of apply_patch in response.completed.
  • internal/protocol/request.go: bridge custom tool calls and history, and normalize null or missing Chat message content to an empty string (fixes strict providers such as Alibaba DashScope and Cloudflare Workers AI returning The content field is a required field).

Testing

  • go test ./...
  • go vet ./...
  • Manual end-to-end requests through the gateway with codex-cli 0.169.0, including a freeform apply_patch, plus Chat and Responses upstream requests.

Codex declares one exec_command tool and a freeform apply_patch, while the gateway advertises the official OpenCode toolset. Map those official tools onto Codex's tools whenever the client declares exec_command, translate their arguments, and keep freeform custom calls intact through Responses and streamed output.

Also normalize null or missing Chat message content to an empty string: strict providers such as Alibaba DashScope and Cloudflare Workers AI reject the null that OpenAI-shaped clients send on tool-call-only assistant turns.
Gan332

This comment was marked as spam.

@jasonxu114514

Copy link
Copy Markdown
Owner

Thanks for the Codex compatibility work. Keeping this open pending blockers from static review of the current PR head: (1) tooladapt.go returns on non-Windows before registering the platform-independent patch transform, conflicting with the unconditional adapter test; (2) v1 read/write/edit use filePath but adapters only read path, and the PowerShell edit script emits true/false instead of the required dollar-prefixed booleans; (3) non-streaming Responses custom calls and Anthropic/Responses argument-delta adaptation are incomplete. Please validate protocol x streaming x platform coverage before merging. Main 14faec7 separately fixes Responses assistant-turn grouping and changes shaping helpers for optional prompt environments, so rebase against it and resolve overlapping request/tool files. No live upstream adapter verification was performed in this review.

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