Repository navigation
feat(integrations): add suv init codex for first-class Codex integration - #31
Conversation
706136b to
57c62ed
Compare
MadhuAppachi
left a comment
There was a problem hiding this comment.
Thanks for this — nice test coverage, especially around hook-merge idempotency and exit-code parsing.
Requesting one change: handle_init_codex propagates try_merge_codex_hooks(...) failures via ?, aborting the whole command on a malformed ~/.codex/hooks.json (and skipping MCP config too, since that step runs after). Both handle_init_claude_code and handle_init_cursor treat this as a soft failure instead — falling back to printing manual setup instructions. Worth matching that here, especially since this integration's whole point is coexisting with third-party hook files (synapse, plannotator) whose shape we don't control.
Non-blocking notes:
try_configure_codex_mcpalways overwrites thecommand/argson rerun, unlike Claude/Cursor which skip ifsuvaduis already present — looks intentional (refreshes stale binary paths) but a comment would help.- The
type -P suvPATH fallback in the hook script is a nice addition Claude/Cursor's scripts lack — worth backporting separately.
| /// Codex runs `PostToolUse` after both successful and failed Bash calls, so a | ||
| /// single handler captures both. The payload shares Claude Code's shape | ||
| /// (`tool_name`, `tool_input.command`, `cwd`, `session_id`). | ||
| pub fn handle_hook_codex() -> Result<(), Box<dyn std::error::Error>> { |
There was a problem hiding this comment.
handle_hook_codex() re-implements the same stdin-read/parse/session-id/prompt-context/entry-building logic already duplicated between handle_hook_claude_code() and handle_hook_claude_code_failure(), now tripling it instead of factoring it into a shared helper.
The risk is already visible in this PR: this function falls back to a random UUID when session_id is invalid, while the sibling handle_hook_codex_prompt silently drops the event instead — an inconsistency inherited from copying rather than sharing code. Worth deciding which behavior is intended and consolidating into one helper both hooks call.
There was a problem hiding this comment.
Consolidated in 1b8be3f — record_agent_bash_hook now backs all three Bash-tool handlers and cache_agent_prompt both prompt handlers (153+/238−). Cursor keeps its own: different payload keys and a {"continue":true} protocol response.
On which behaviour is intended — the asymmetry is deliberate and predates this PR, so I documented it rather than changing it. handle_hook_claude_code also falls back to a synthetic UUID while handle_hook_claude_prompt drops the event: losing a command from history is worse than losing prompt grouping, and a prompt cached under an id no command will ever look up is dead weight. Codex copied the convention correctly.
You were right not to fix it blind, so I validated against a live codex-cli 0.148 harness instead. That turned up something affecting 9c5054e: Codex reports no exit code at all, and success is indistinguishable from failure. tool_response is a plain string, and the key set is identical either way.
{
"session_id": "01a01ade-c43e-76f1-963f-1202e7c394a0",
"turn_id": "01a01ade-c524-7fe0-b7c6-41b998616b9e",
"transcript_path": "/Users/…/.codex/sessions/2026/08/19/rollout-….jsonl",
"cwd": "/Users/…/code/suvadu",
"hook_event_name": "PostToolUse",
"model": "gpt-5.6-sol",
"permission_mode": "default",
"tool_name": "Bash",
"tool_input": { "command": "echo suvadu-hook-probe-42" },
"tool_response": "suvadu-hook-probe-42\n",
"tool_use_id": "exec-837af453-534c-47b5-9a47-fb3d9f65b912"
}{
"…": "same key set, `ls /nonexistent-suvadu-probe`",
"tool_response": "ls: /nonexistent-suvadu-probe: No such file or directory\n"
}So the structured reads in codex_exit_code — including the "error": null case you guarded — are unreachable against 0.148, and every Codex entry records exit_code = NULL. I kept them as forward-compat but labelled them as unexercised, and added a regression test pinning the real shape so the assumption fails loudly if Codex changes it. Say the word if you'd rather delete the speculative branch than carry it.
tool_name, tool_input.command, cwd and session_id are all confirmed present and usable, and prompt grouping works end to end — replaying the captured payloads through the built binary:
session_id = codex-01a01ae8-1360-77a1-b916-5f75d25049b4
command = cargo build --release
exit_code =
executor = openai-codex
context = {"agent_prompt":"Reply OK. Run no commands."}
One thing for a separate issue, not this PR: the executor rename from codex to openai-codex orphans entries written by the older shell hook from any --executor filter — 18940 codex rows vs 49 openai-codex in my local history. Needs a migration or an alias.
There was a problem hiding this comment.
Correcting my last paragraph above — it was wrong, and no migration is needed.
I claimed this PR renames the executor from codex to openai-codex. It doesn't. openai-codex has been the canonical label since the initial release: src/hooks.rs has written it for CODEX_THREAD_ID-detected shells all along, and git log -S'--executor codex' --all and git log -S'suvadu-post-tool' --all both come back empty — suvadu has never emitted the bare codex label or generated that script.
The codex rows in my local history came from a hook I hand-wrote in July that calls suv add --executor codex directly. Entirely local, nothing to do with this repo. Sorry for the noise.
|
Thanks for this @benediktms — great work on the Codex integration. Reviewed and pushed a few small fixes directly to this branch (9c5054e), since "Allow edits from maintainers" was enabled:
Ran Left one as a review comment rather than fixing blind: |
|
254a953 fixes a destructive write in The function parsed Before, running init against a real config produced a 100+ line diff with all comments gone. After:
Verified across five cases (refresh with stale path, Same class of issue, deliberately left alone as out of scope for this PR: |
Ports the still-unclaimed piece of PR AppachiTech#31 (feat/codex-init) onto dev's own Codex integration (732dd34), which already covers hook-based command/prompt capture. Ties `suv init codex` to `suv mcp-serve` in ~/.codex/config.toml the same way Claude Code and Cursor already are, closing the remaining gap in AppachiTech#30. Uses toml_edit rather than a parse/reserialize round trip through toml::Value, since config.toml is hand-maintained and a round trip would silently strip every comment and reorder tables. Ported from github.com/benediktms/suvadu#31 (254a953), adapted to dev's src/integrations/codex.rs module split and CODEX_HOME-aware path resolution. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016kVHAmojKCWepQBxe9k1bN
|
Hey Benedikt — thanks for this, and sorry for the slow turnaround. While this was in review, we ended up independently shipping most of the same functionality on The piece that's not duplicated, and that we still want, is the MCP auto-registration in So we're going to rebase this PR down to just that piece on top of current |
254a953 to
47f0c07
Compare
Summary
suv init codex— a first-class Codex CLI integration on par with the Claude Code and OpenCode integrations. It installsPostToolUse+UserPromptSubmithooks into~/.codex/hooks.json(merging into any existing hooks such as synapse/plannotator rather than overwriting) and auto-registers the suvadu MCP server in~/.codex/config.toml.suv hook-codex/suv hook-codex-promptrecord Codex-run bash commands asexecutor=openai-codex(session prefixcodex-) and capture prompts for prompt-grouped sessions on the agent dashboard. Exit code is recorded only when Codex exposes it (it does not reliably), so it is left unknown rather than mislabeled.Linked Issue
Closes #30
Changes
src/cli.rs—InitTarget::Codex,init codexhelp text,hook-codex/hook-codex-promptsubcommandssrc/integrations.rs—handle_init_codex,handle_hook_codex,handle_hook_codex_prompt,try_configure_codex_mcp,try_merge_codex_hookssrc/main.rs— dispatch wiringTest Plan
cargo build,cargo test(1098 pass),cargo clippycleanexecutor=openai-codexwithagent_promptcontext grouped on the agent dashboard[mcp_servers.suvadu], re-ransuv init codex, and completed the Codex handshake (initialize→tools/listreturns 15 tools)