Skip to content

feat(desktop): runnable Codex-on-agent-kit swap behind PWRAGENT_CODEX_KIT#695

Draft
huntharo wants to merge 3 commits into
mainfrom
claude/codex-kit-swap
Draft

feat(desktop): runnable Codex-on-agent-kit swap behind PWRAGENT_CODEX_KIT#695
huntharo wants to merge 3 commits into
mainfrom
claude/codex-kit-swap

Conversation

@huntharo

@huntharo huntharo commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Draft / WIP tracker — recreated after #679 was auto-closed by a history rewrite on main; rebased clean onto the new main (2 commits, no conflicts). The Phase-B Codex swap: PwrAgent's live Codex thread driven through the kit's CodexThreadClient (@pwrdrvr/agent-client) behind PWRAGENT_CODEX_KIT=1, instead of the in-tree CodexAppServerClient. Flag-off keeps the in-tree client byte-for-byte unchanged (A/B-able).

What runs through the kit now

CodexKitBackendClient (codex-kit-adapter.ts) implements the registry's BackendClient surface over CodexThreadClient; codexEventToNotifications maps the kit's neutral NormalizedThreadEvents → the AppServerNotification shapes the registry + renderer consume live. Gated at one seam (the codexClient construction in backend-registry.ts); downstream wiring untouched.

Depends on: pwrdrvr/agent-kit#7

The ported kit methods aren't published yet, so this branch uses a local bridge: a root pnpm override points @pwrdrvr/agent-client at a tarball built from the agent-kit feature-port branch. CI is red until agent-kit#7 lands, a version is published, the apps/desktop pin is bumped, and the override is dropped. Expected for the draft.

Run it (local bridge in place)

PWRAGENT_CODEX_KIT=1 pnpm --filter @pwragent/desktop dev

Status

Rebased onto new main, built green locally against the linked kit build: desktop typecheck · build · 6 adapter tests · 230 backend-registry tests (242 desktop-main total). Agent-kit side (#7): 46 tests (6 new), CI green.

Not yet validated end-to-end with a live GUI + real Codex — that's the launch test. Relationship to #672: independent; #672 is the parity gate (normalizer fidelity), this is the runtime wiring + feature port.

🤖 Generated with Claude Code

huntharo and others added 3 commits June 8, 2026 16:30
…_KIT

First launchable slice of the Phase-B Codex swap. When PWRAGENT_CODEX_KIT=1,
PwrAgent drives the live Codex thread through the kit's CodexThreadClient
(@pwrdrvr/agent-client) instead of the in-tree CodexAppServerClient.

- New CodexKitBackendClient (codex-kit-adapter.ts) implements the registry's
  BackendClient surface over CodexThreadClient: startThread, startTurn, stream,
  readThread (via the B1 reduceNormalizedThread + normalizedThreadToReplay
  adapter), interruptTurn, close.
- codexEventToNotifications maps the kit's neutral NormalizedThreadEvents to the
  AppServerNotification shapes the registry + renderer already consume live
  (turn lifecycle, agent-message deltas/completion, tool-call items, token
  usage, errors). Pure + unit-tested.
- Gated at one seam (backend-registry.ts construction); flag-off keeps the full
  in-tree client byte-for-byte unchanged. Rich Codex features (steer/compact/
  review/model+skill+account queries) are intentionally unavailable under the
  flag in v1 — they're optional on BackendClient, so omitting them is clean.

Scope is the core path you can actually launch and run a Codex turn on. The
feature port + full client deletion follow. Built green: typecheck, desktop
build, 6 new adapter tests, 230 backend-registry tests, boundary lint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Now that agent-client's CodexThreadClient has steer/compact/review/trust/
permissions (agent-kit branch claude/codex-feature-port), expose them through
CodexKitBackendClient so the PWRAGENT_CODEX_KIT path is no longer core-chat-only:

- steerTurn → kit turn/steer (maps AppServerTurnInputItem[] → UserInput[])
- compactThread → kit thread/compact/start
- startReview → kit review/start
- setThreadPermissions → kit thread/resume overlay
- trustProject → kit config/value/write

LOCAL BRIDGE (pending publish): the root pnpm override points @pwrdrvr/agent-client
at a local tarball built from the agent-kit feature-port branch
(file:/Users/huntharo/.../agent-kit/.worktrees/codex-port/.pack/...0.6.1.tgz),
because the ported methods aren't published yet. To run:
  PWRAGENT_CODEX_KIT=1 pnpm --filter @pwragent/desktop dev
Before merge: publish agent-client with these methods, bump the apps/desktop pin,
and drop the override — CI stays red until then (expected for this draft).

Built green locally against the linked build: desktop typecheck, build, 6 adapter
tests, 230 backend-registry tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rn end

Repro (PWRAGENT_CODEX_KIT=1, real Codex, after a steer): the thread LIST stuck
"thinking" while the transcript was idle — a state divergence that shouldn't be
possible.

Root cause: on every startTurn the registry emits a synthetic
`turn/started turnId=pending:<threadId>` placeholder, which adds to
`activeTurnKeys` (the thread-list "thinking" driver). That placeholder never
receives a per-turn terminal event — it is only swept by the wholesale
`thread/status/changed`→non-active handler. The in-tree Codex client emits
`thread/status/changed`; the kit's neutral event stream has NO thread-status
event, so `normalizeNotification` drops Codex's status notifications and the
adapter never re-synthesized them. The pending key leaked → list stuck thinking;
the transcript reads threadStatus=idle and self-heals, so it did not.

Fix: synthesize a `thread/status/changed` → idle in codexEventToNotifications at
turn end (turn_completed and error), triggering the registry sweep. Single-active-
turn is enforced by the registry, so idle-on-completion can't prematurely clear a
concurrent turn. +2 adapter tests. (Proper long-term fix: a neutral thread_status
event through agent-core so real Codex status is preserved — follow-up on the kit.)

Co-Authored-By: Claude Opus 4.8 (1M context) <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