feat: in-process Lua core handler for codex (#47, phase 3)#67
Open
Cannon07 wants to merge 1 commit 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>
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.Test plan
./tests/run_lua.sh— all green (14 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