Skip to content

feat: support Codex CLI session transcripts alongside Claude Code - #1

Open
qwqwd65-ui wants to merge 1 commit into
mainfrom
feat/codex-support
Open

qwqwd65-ui wants to merge 1 commit into
mainfrom
feat/codex-support

Conversation

@qwqwd65-ui

Copy link
Copy Markdown
Collaborator

What

Adds first-class support for Codex CLI session transcripts alongside Claude Code, in one merged index per project.

Codex differs from Claude Code in two structural ways, both absorbed by a new source adapter:

  1. Directory layout — ~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<uuid>.jsonl, sharded by date, unrelated to cwd. Project membership is read back from each file's first line session_meta.payload.cwd (verified stable across 405 real rollouts).
  2. Record schema — each line is {timestamp, type, payload}, with event_msg and response_item double-writing the same content. Index stream reads event_msg (naturally deduped); scan/expand stream reads response_item (full tool-call input).

How

  • New scripts/codex.mjs — read-only Codex adapter: discovery (first-line meta), dual-stream normalization, scan/expand/list.
  • scripts/lib.mjs — source auto-detected from a file's first line; Claude + Codex sessions of the same real cwd merge into the same index/<enc>/ namespace. Read paths, index path, and search hits all cover both sources. Codex state keys are prefixed codex: so existing Claude incremental cursors are untouched — zero migration for existing indexes.
  • scripts/scan-transcript.ps1 — Windows fallback gains a Codex branch (source detection + Codex schema parsing).
  • Cross-platform hardening — removed a 3-platform silent-drop bug in readMeta (64KB first-line truncation) and a chunk-boundary UTF-8 split bug (bit CJK paths/content specifically).
  • Docs (README ×2, SKILL.md) + MCP tool descriptions updated for Codex coverage.

Testing

  • npm test — 16 pass (11 existing + 5 new in test/codex.test.mjs pinning dual-stream dedup and the short-message no-over-filter invariant).
  • Smoke test green (Claude path — zero regression).
  • End-to-end on real data: indexed 1440 chunks across 225 Codex sessions, exact search hit correctly tagged [codex]; ps1 scan/list/-Detail verified on a real rollout.

Notes / caveats

  • I only have Windows locally — the code has no Windows-only assumptions (all os.homedir() + path.join), but macOS/Linux were not run live. A npm test + a discovery pass over a real ~/.codex/sessions on either platform would fully confirm.
  • Not included in this PR: an unrelated prompt-hint.mjs wording tweak (left in the working tree, untouched).

Add a source adapter so trans reads Codex CLI rollout logs
(~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl) in addition to Claude
Code transcripts. Same-project sessions from both tools merge into one
index namespace, keyed by real cwd.

Two structural differences are normalized in scripts/codex.mjs:
- Directory layout: Codex shards by date, not cwd. Project membership
  is read from each file's first-line session_meta payload cwd
  (verified stable across 405 real rollouts).
- Record schema / double-write: each line is {timestamp,type,payload};
  event_msg and response_item duplicate the same content. Index stream
  reads event_msg (naturally deduped); scan/expand read response_item
  (full tool-call input).

lib.mjs dispatches by source, auto-detected from the file's first line
(Codex rollouts always start with session_meta; Claude never does).
Index state keys Codex sessions with a codex: prefix so existing Claude
cursors are untouched; chunk meta carries a source tag (absent = claude
for existing indexes, no migration needed).

Also hardens readMeta: reads to a real newline (4MB cap) instead of a
fixed 64KB buffer, and decodes UTF-8 once after concatenating -- a
truncated first line would otherwise silently drop a session, and a
chunk-boundary split would corrupt CJK paths/content (all platforms).

scan-transcript.ps1 (Windows-only fallback) gains a matching Codex
branch. New unit tests pin the two regressions hit during development:
event_msg-only dedup, and not over-filtering short human messages
("123" / "who are you") the way the Claude <=5-char filter would.

Co-Authored-By: Claude Opus 4.8 <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.

2 participants