feat: in-process Lua core handler for codex (#47, phase 3)#67
Open
Cannon07 wants to merge 2 commits into
Open
Conversation
Flips Codex's PreToolUse / PostToolUse hooks from per-shim bash translation to a single RPC into the in-process Lua orchestrator, matching the pattern already shipped for claudecode (#63), opencode (#65), and copilot (#66). - backends/codex/code-{preview,close}-diff.sh: trimmed to the copilot shape — set -uo pipefail (no -e), fast-path filter for read/view/glob/grep/ls/ list_files plus mcp__*, socket discovery, then a single nvim_call into pre_tool / post_tool. Abstains (exit 0, no stdout) when nvim is unreachable so codex falls back to its native ask-before-write loop. - lua/code-preview/pre_tool/normalisers.lua: new codex entry. Codex's payload is almost canonical (top-level tool_name, cwd, tool_input), so the only real translation is apply_patch → ApplyPatch with tool_input.command moved to tool_input.patch_text. Edit / Write / Bash / ApplyPatch are passthrough; file_path is run through resolve_path for cross-backend key parity. Blank file_path / command / patch text drop tool_name to nil so the dispatcher no-ops (matches the old shim's defensive `[[ -z $FP ]] && exit 0` guards). - lua/code-preview/pre_tool/emitters.lua: explicit codex = none entry (mirrors copilot). Codex has no review-gate analogue to emit a permissionDecision for. - tests/plugin/pre_tool_normaliser_spec.lua: new describe block covering apply_patch translation, ApplyPatch/Edit/Write/Bash passthrough, blank-field defenses dropping tool_name, mcp__* and noise tools yielding nil. Refs #47 (phase 3). No behaviour change for codex users. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Mirrors PR #66's followup for copilot: - tests/backends/codex/test_{apply_patch,edit}.sh: docstrings still referenced the old bash adapter / bin/core-pre-tool.sh flow. Point them at the new in-process Lua normaliser. - lua/code-preview/pre_tool/normalisers.lua (codex block): add the path-normalisation note so the resolve_path call doesn't look magical to the next reader (parity with copilot's block). Also note that the canonical-ApplyPatch branch fixes a dormant bug in the old shim — its ApplyPatch|Edit|Write case blank-checked file_path, which canonical ApplyPatch doesn't carry, so any such payload would have been silently dropped. Nothing emits canonical ApplyPatch today, but the new branch checks patch_text correctly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Flips Codex's PreToolUse / PostToolUse hooks from per-shim bash translation to a single RPC into the in-process Lua orchestrator, matching the pattern already shipped for claudecode (#63), opencode (#65), and copilot (#66). Refs #47 (phase 3). No behaviour change for codex users.
Changes
backends/codex/code-{preview,close}-diff.sh— trimmed to the copilot shape:set -uo pipefail(no-e), fast-path filter forread/view/glob/grep/ls/list_filesplusmcp__*, socket discovery, then a singlenvim_callintopre_tool/post_tool. Abstains silently (exit 0, no stdout) when nvim is unreachable so codex falls back to its native ask-before-write loop.lua/code-preview/pre_tool/normalisers.lua— newcodexentry. Codex's payload is almost canonical (top-leveltool_name,cwd,tool_input); the only real translation isapply_patch→ApplyPatchwithtool_input.commandmoved totool_input.patch_text. Edit / Write / Bash / ApplyPatch are passthrough.file_pathruns throughresolve_pathso internal keys (active_diffs, changes registry) compare equal across backends. Blank file_path / command / patch text droptool_nametonil— matches the old shim's[[ -z "$FP" ]] && exit 0guards.lua/code-preview/pre_tool/emitters.lua— explicitcodex = noneentry (mirrors copilot). Codex has no review-gate analogue to emit a permissionDecision for.tests/plugin/pre_tool_normaliser_spec.lua— new describe block covering apply_patch translation, ApplyPatch/Edit/Write/Bash passthrough, blank-field defenses droppingtool_name,mcp__*and noise tools yielding nil.Notable: latent ApplyPatch bug fixed in passing
The old bash shim's
ApplyPatch|Edit|Write)case blank-checkedtool_input.file_path, which canonicalApplyPatchdoesn't carry (it carriespatch_text). So any payload using the canonical tool name would have been silently dropped on the empty-file_path guard. Dormant because nothing emits canonicalApplyPatchtoday (codex always uses lowercaseapply_patchwithtool_input.command), but the new normaliser checkspatch_textcorrectly on that branch.Followup commit (review nits)
dba4bee: refresh test docstrings to point at the in-process Lua normaliser instead of the oldbin/core-pre-tool.shadapter (parity with #66's followup for copilot), and add the path-normalisation note above the codex block so theresolve_pathcall doesn't look magical.Test plan
./tests/run_lua.sh— all green (12 codex normaliser cases + existing suites)./tests/run.sh— 68/68 including existing codex E2E (test_apply_patch.sh,test_edit.sh,test_install.sh)🤖 Generated with Claude Code