Skip to content

Add Codex CLI support behind an agent adapter boundary - #5

Merged
frenchie4111 merged 5 commits into
mainfrom
feat/codex-adapter
Nov 20, 2026
Merged

frenchie4111 merged 5 commits into
mainfrom
feat/codex-adapter

Conversation

@frenchie4111

Copy link
Copy Markdown
Contributor

Adds Codex CLI as loch's second harness. Three commits, meant to be read in order:

  1. Extract an agent adapter boundary, and pin the bundle format. Everything loch needs from a harness now lives behind agent::Agent (src/agent.rs), in three tiers: attribution, transport and conversation. Later tiers default to declining. Claude Code moves onto it with no behaviour change. tests/bundle.rs now pins the packed bytes and ref of a bundle. On 100 real sessions, save and list gave identical refs and output before and after.
  2. Add the Codex CLI adapter (src/codex.rs, tests/codex.rs). install, blame, log, save, list, restore and ask all work for Codex. Bundles of a single agent's sessions keep their bytes, so existing Claude refs are unchanged.
  3. Stop install's payload overwriting the envelope's command. This was a pre-existing bug: install --json reported "command": "loch". The hook path is now hookCommand, and output::document drops any payload key that collides with an envelope key.

Verified end to end on real codex-cli 0.166 sessions

  • Hooks and blame: each turn owns the lines it wrote through the shell, with "agent": "codex" and Codex's thread title.
  • Cancelled turn: a turn cancelled in the TUI gets no Stop. The next prompt closes it as interrupted and keeps its edits.
  • ask: ask --at-turn forks at the end of that turn. Resumed, the fork knows that turn and nothing after it.
  • Cross-machine restore: the bundle was rewritten to another home, restored with --new-id into another directory, and resumed. It came back clean and recalled the conversation.
  • Discovery: all 70 local rollouts, across four CLI versions, are found under their live cwd.

Full findings are in CLAUDE.md: Codex storage, and what a third harness costs.

Needs a decision or a heads-up

  • Hook trust is manual. Codex skips new hooks until a person approves them in /hooks. loch reports needsReview and never writes trust itself. Trusting through the TUI is untested; test runs used --dangerously-bypass-hook-trust on scratch repos.
  • install --local for Codex writes ~/.codex/hooks.json, which applies to every Codex project on the machine. Codex has no uncommitted per-project file.
  • JSON changes:
    • install's hook path moved from command to hookCommand.
    • New error codes: unknown-agent and unsupported-agent.
    • New fields: agent/agentVersion on sessions, and agents[] on install.
    • schema stays 2.
  • Ness blame gutter: blame's payload is unchanged except that agent can now be codex, with turn/conversation null for those turns.
  • Ness's own hooks: if Ness rewrites ~/.codex/hooks.json wholesale, it will drop loch's hooks.

Gaps

ingest and backfill stay Claude-only. A Codex session that moved directories reports no branch. Forks have no title. archived_sessions isn't searched.

🤖 Generated with Claude Code

frenchie4111 and others added 5 commits November 19, 2026 15:08
Everything loch needs from one agent harness — hook events and hooks file,
reading a turn from the transcript, the store key for a transcript, session
discovery and metadata, a transcript's cwds, where a restore goes and how it
resumes, finding a transcript and forking it — is now behind agent::Agent,
in three tiers (attribution, transport, conversation) whose later tiers have
declining defaults. Claude Code moves onto it with no change in behaviour.

tests/bundle.rs now pins the packed JSON and ref of a bundle, and that
repacking reproduces the bytes. save and list on 100 real sessions gave
identical refs and output before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codex.rs implements every tier of agent::Agent for codex-cli: rollout
discovery under $CODEX_HOME/sessions, the live cwd from the last
turn_context (compared symlink-resolved, since Codex stores -C as given),
session_meta's branch only where the session hasn't moved, turns bounded by
the records naming their turn_id, restore filed by start date, and ask's
fork as a byte-for-byte prefix of the rollout resumed with codex resume.

install writes .codex/hooks.json (or with --local the user's) beside
whatever is there, appending groups so the trust Codex keys by position
stays valid, and reports needsReview: loch never writes Codex's hook trust.
list, save and install take --agent; sessions, bundles and restores carry
agent and agentVersion. A bundle's sessions name their agent only where it
differs from the bundle's, so every Claude-only bundle keeps its ref.

Verified end to end on real Codex sessions (CLAUDE.md, State): hooks and
blame, a cancelled TUI turn, ask at a turn and to the end, and a
cross-machine restore that resumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
install's payload field `command` (the hooks' loch path) replaced the
envelope's `command`, so `install --json` reported "command": "loch"
instead of "install". The field is now `hookCommand`, and output::document
drops any payload key that reuses an envelope key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e cases

- A bundle holding any non-Claude session is version 2, which v0.2.0 refuses
  as bundle-unreadable instead of restoring a Codex session as a Claude
  transcript with ok: true (checked against a v0.2.0 build). Claude-only
  bundles stay version 1, byte for byte; both are pinned.
- install with no --agent sets up Claude Code alone again; --agent codex or
  all opts in, so install --local never widens to the user-wide Codex file.
- ask on a turn of an agent this build lacks is unsupported-agent.
- A non-ASCII session_meta timestamp from a bundle no longer panics restore.
- Agent::can_restore replaces probing restore_path with an empty transcript.
- CLAUDE.md: the version rule, the install default and Ness note, and the
  cost of scanning every Codex rollout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frenchie4111
frenchie4111 merged commit 40ab80b into main Nov 20, 2026
2 checks passed
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