Skip to content

feat: in-process Lua core handler for codex (#47, phase 3)#67

Open
Cannon07 wants to merge 1 commit into
mainfrom
feat/codex-in-process-handler
Open

feat: in-process Lua core handler for codex (#47, phase 3)#67
Cannon07 wants to merge 1 commit into
mainfrom
feat/codex-in-process-handler

Conversation

@Cannon07
Copy link
Copy Markdown
Owner

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 for read/view/glob/grep/ls/list_files plus mcp__*, socket discovery, then a single nvim_call into pre_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 — new codex entry. Codex's payload is almost canonical (top-level tool_name, cwd, tool_input); the only real translation is apply_patchApplyPatch with tool_input.command moved to tool_input.patch_text. Edit / Write / Bash / ApplyPatch are passthrough. file_path runs through resolve_path so internal keys (active_diffs, changes registry) compare equal across backends. Blank file_path / command / patch text drop tool_name to nil — matches the old shim's [[ -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.

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)
  • Real Codex CLI session locally: apply_patch (Update/Add/Delete) opens diff, accept/reject clears registry, view/glob/mcp__ tools stay quiet, nvim-not-running case falls back to codex's native flow.

🤖 Generated with Claude Code

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>
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.

1 participant