Codex Event Dispatch Refactor Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Keep Codex app-server event normalization split by provider-edge responsibility by making events.py a smaller notification dispatcher.
Architecture: Keep src/codealmanac/integrations/harnesses/codex/events.py as the dispatcher named in the live agreement. Move notification-specific handler logic for text/plan deltas, plan updates, output deltas, warnings, and errors into notification_events.py. Do not move item, agent, usage, turn-completion, or result mapping back into events.py.
Tech Stack: Existing Codex app-server harness event model, focused Codex adapter tests, pytest, ruff.
Scope#
In scope:
- Keep
map_codex_notification(...)public behavior unchanged. - Extract private helper functions inside
events.py. - Add
notification_events.pywhen the architecture cap proves the helpers do not belong in the dispatcher file. - Keep
item_events.py,agent_events.py, andresult.pyas the owners of their existing responsibilities. - Update the refactor worklog.
Out of scope:
- No new provider event behavior.
- No changes to raw Codex JSON handling.
- No new files except
notification_events.pyif the dispatcher cap requires it.
Tasks#
Task 1: Extract Inline Event Handlers#
Files:
- Modify:
src/codealmanac/integrations/harnesses/codex/events.py
Steps:
- Add an
OUTPUT_DELTA_METHODSconstant. - Create
src/codealmanac/integrations/harnesses/codex/notification_events.py. - Move text delta, plan delta, plan update, output delta, warning, error, and
plan-summary helpers into
notification_events.py. - Update
events.pyto stay a dispatcher over notification methods. - Update the architecture test to include
notification_events.pyand forbid error/event-kind details inevents.py. - Keep event kinds, messages, actor assignment, raw payloads, and state mutation identical.
Task 2: Verify And Record#
Files:
- Modify:
docs/refactor-audit-2026-07-06/worklog.md
Run:
uv run pytest tests/test_codex_app_server_adapter.py tests/test_codex_adapter.py -q
uv run ruff check src/codealmanac/integrations/harnesses/codex/events.py tests/test_codex_app_server_adapter.py tests/test_codex_adapter.py
uv run pytest
uv run ruff check .
git diff --checkExpected: all pass.
Commit:
git add src/codealmanac/integrations/harnesses/codex/events.py src/codealmanac/integrations/harnesses/codex/notification_events.py tests/test_architecture.py docs/plans/2026-07-06-codex-event-dispatch-refactor.md docs/refactor-audit-2026-07-06/worklog.md
git commit -m "refactor: slim codex event dispatcher"