feat: OpenAI Codex as a codeoid backend (app-server JSON-RPC, first slice) - #142
Merged
Conversation
…lice)
Codex CLI becomes the third native harness backend, riding ChatGPT-
subscription auth that lives entirely in codex's own ~/.codex store.
Grounded against a live probe of @openai/codex@0.144.1 app-server
(newline JSON-RPC over stdio; see docs/provider-codex-design.md).
- codex/rpc.ts: JSON-RPC client — requests, notifications, and
SERVER→client requests (the native approval seam; unlike pi, no
injected bridge extension is needed).
- codex/index.ts: CodexProvider (SessionProvider) — warm process, one
codex thread per backing session (thread id = backingSessionId,
thread/resume on reconnect, fresh thread on rotation), turn/start
pinned to approvalPolicy 'untrusted' so codex ASKS before privileged
actions and codeoid's canUseTool is authoritative (fail-closed: no
gate wired → denied; unknown server requests → refused).
item/tool/requestUserInput maps to requestUserInput
(session.ui_request). Non-gated items (codex-trusted reads) are
recorded retrospectively as paired tool_start/tool_complete so
scrollback + canonical history stay honest. systemPromptAppend →
developerInstructions; seedFromHistory prepends the structured
transcript (warm-backend ceiling). model/list → live catalog.
- buildCodexEnv: hardened subprocess env (CODEX_/OPENAI_/LC_ prefixes,
*_API_KEY suffix; ~/.codex via HOME) — GHSA-38vh posture.
- Config providers.codex {enabled, command}; registry activation via
resolveCodexCommand (config → PATH; no bundled fallback yet — native
per-platform binary, needs a size audit) with the #141
supported-but-unavailable hint otherwise.
Tests: fake-codex fixture (newline JSON-RPC subprocess) driving C1-C9:
text/thinking streaming + usage, approval approve/deny round-trips,
retrospective non-gated items, structured history seed (one-shot),
user-input select round-trip, missing binary, model mapping, resolution
+ registry hints. No wire changes.
🤖 Gemini code reviewIntroduced OpenAI Codex as a codeoid backend utilizing JSON-RPC over stdio. Includes a robust client, custom sandboxed environment, config registry integration, and extensive offline test suites. Found and addressed a potential host crash due to unhandled stdin EPIPE errors. Findings: 🔴 0 · 🟠 1 · 🟡 0 · 🟢 1 Tokens spent · ⬆️ Input: 17,706 · ⬇️ Output: 388 · Σ Total: 26,349 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #142 +/- ##
==========================================
+ Coverage 82.11% 82.55% +0.44%
==========================================
Files 98 101 +3
Lines 16922 17404 +482
==========================================
+ Hits 13895 14368 +473
- Misses 3027 3036 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Patch coverage 89.4% → ~99%: C9 lifecycle (thread id round-trips as the backing id, reset/setHasQueried/dispose, onModels catalog), C10 interrupt → turn/interrupt → stopReason 'interrupted', C11 unknown server→client request refused with a JSON-RPC error (fail closed), C12 rpc edges (spawn failure rejects in-flight requests, request timeout, request/notify after exit), plus bare-name and system-PATH codex resolution. fake-codex grows hang-forever/unknown-request/noReply behaviors and surfaces error responses to turn scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Codex CLI becomes the third native harness backend (after claude and pi) — agentic GPT riding ChatGPT-subscription auth, which lives entirely in codex's own
~/.codexstore; codeoid never touches tokens. First slice ofdocs/provider-codex-design.md, grounded against a live probe of@openai/codex@0.144.1(codex app-server, newline JSON-RPC over stdio, self-describing protocol viagenerate-json-schema).Design
codex/rpc.ts— JSON-RPC client: requests, notifications, and server→client requests. That last category is the headline: codex natively asks its client for approvals, so unlike pi there is no injected bridge extension — the protocol itself provides the gate seam.codex/index.ts—CodexProvider(warm). One codex thread per backing session: thread id round-trips asbackingSessionId,thread/resumereattaches after daemon restart, rotation starts a fresh thread. Everyturn/startpinsapprovalPolicy: "untrusted"so codex asks before privileged actions and codeoid'scanUseToolis authoritative — fail-closed throughout (no gate wired → denied; unknown server request → refused, not guessed).item/tool/requestUserInputmaps onto the feat: provider extension surface — dialogs, dynamic commands, rich parts, provider registry #131 dialog surface (session.ui_request). Items codex runs under its own trusted policy (read-only commands) are recorded retrospectively as pairedtool_start/tool_complete— visible in scrollback and canonical history without pretending codeoid gated them.systemPromptAppend→developerInstructions;seedFromHistoryprepends the structured transcript from feat: Phase-2 canonical history — native tool_use/functionCall replay across backends #138 (one-shot);model/listfeeds the live model picker.buildCodexEnv— hardened subprocess env (GHSA-38vh posture):CODEX_/OPENAI_/LC_prefixes +*_API_KEYsuffix;~/.codexreachable via HOME in the shared basics.providers.codex {enabled, command}mirroring pi; activation viaresolveCodexCommand(config → PATH), otherwise the feat: bundle pi so the backend works with zero install #141 supported-but-unavailable hint (npm i -g @openai/codex). No bundled fallback yet:@openai/codexis a per-platform native binary — bundling needs a size/platform audit first (tracked in the design doc).Tests
fake-codexfixture (newline JSON-RPC subprocess, fake-pi pattern) driving nine cases: text+thinking streaming with usage mapping, approval approve and deny round-trips (the fixture only runs the item when it receivesapproved), retrospective non-gated items, structured-history seed (and its one-shot semantics), user-input select round-trip, missing-binary error, model catalog mapping, and resolution/registry hint states.Not yet covered (follow-up slices, listed in the design doc):
turn/steer→pushMidTurn, plan/diff notifications as rich parts, dynamic commands, live smoke against a real logged-in codex, bundling audit.bun run test(1252 pass),typecheck,lintgreen.🤖 Generated with Claude Code