Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

feat(cli): import Codex rollout text for autoindex

Jarvisea74d9987db9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2427cf3df..c74113faf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- `xerj sessions import --format codex` prepares one explicitly selected Codex
+ rollout JSONL using the same native PII redactor and no-clobber publication
+ as the Claude Code adapter. It exports user/assistant response text with
+ source locations, archive event IDs and explicit message phases; duplicate
+ events, system/developer messages, reasoning and tool payloads are skipped. Unsupported
+ shapes and external history references refuse publication. This extends
+ #1793 without automatic discovery or inferred file/commit associations. See
+ [the format contract](tools/session-import/README.md#codex-rollout-adapter).
+
- `xerj sessions import --format claude-code --input FILE --output NEW.jsonl`
prepares an explicit Claude Code JSONL transcript for ordinary `autoindex`.
It emits text-bearing user/assistant records through the existing native
diff --git a/engine/crates/xerj-autoindex/src/sessions.rs b/engine/crates/xerj-autoindex/src/sessions.rs
index 8767a7963..0c0fccb74 100644
--- a/engine/crates/xerj-autoindex/src/sessions.rs
+++ b/engine/crates/xerj-autoindex/src/sessions.rs
@@ -16,9 +16,9 @@ const MAX_RECORDS: usize = 100_000;
pub const HELP: &str = "xerj sessions import — offline session preparation for autoindex
-USAGE: xerj sessions import --format claude-code --input FILE --output NEW.jsonl
+USAGE: xerj sessions import --format <claude-code|codex> --input FILE --output NEW.jsonl
-Read one explicit Claude Code JSONL transcript; write user/assistant text
+Read one explicit Claude Code transcript or Codex rollout JSONL; write user/assistant text
records through the existing native PII redactor before any output is stored.
Preserve session/message UUIDs, parent UUIDs, source filename/line/byte offset,
branch metadata and file paths explicitly named by Read/Write/Edit/MultiEdit.
@@ -30,7 +30,10 @@ The output is a new, private JSONL snapshot. Existing output is never replaced;
parse failures publish nothing. No node is started or contacted. Review the
export, then run: xerj autoindex <export-folder> --prefix <your-prefix>
The redactor handles email/IP/card/SSN/phone patterns, not every secret or name.
-Input <=512 MiB; line <=1 MiB; turn text <=256 KiB; <=100000 message UUIDs.
+Codex reads response_item messages after session_meta, skips duplicate event_msg
+text and tools/reasoning; uses line-and-byte-digest event IDs, no inferred parents
+or files. exec --json and external history_base are unsupported.
+Input <=512 MiB; line <=1 MiB; turn text <=256 KiB; <=100000 messages.
Exit 0: exported, JSON summary on stdout; 2: usage; 1: import/publication error.
";
@@ -165,7 +168,115 @@ fn publish(file: tempfile::NamedTempFile, output: &Path) -> Result<()> {
Ok(())
}
+struct ParsedTurn {
+ text_fields: Value,
+ identity_fields: Value,
+}
+
+fn claude_turn(
+ entry: &Value,
+ line: u64,
+ offset: u64,
+ source_file: &str,
+ summary: &mut ImportSummary,
+ session: &mut Option<String>,
+ seen: &mut HashSet<String>,
+) -> Result<Option<ParsedTurn>> {
+ let kind = entry["type"]
+ .as_str()
+ .with_context(|| format!("line {line}: missing session record type"))?;
+ if !matches!(kind, "user" | "assistant") {
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let sid = uuid_field(entry, "sessionId", line)?;
+ if let Some(expected) = session.as_ref() {
+ ensure!(
+ expected == &sid,
+ "line {line}: mixed session IDs are unsupported"
+ );
+ } else {
+ *session = Some(sid.clone());
+ }
+ let mid = uuid_field(entry, "uuid", line)?;
+ ensure!(
+ seen.len() < MAX_RECORDS,
+ "session exceeds 100000 message UUIDs"
+ );
+ ensure!(
+ seen.insert(mid.clone()),
+ "line {line}: repeated message UUID; export a transcript without revisions"
+ );
+ if flag(entry, "isMeta", line)? {
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let message = entry["message"]
+ .as_object()
+ .with_context(|| format!("line {line}: missing message object"))?;
+ ensure!(
+ message.get("role").is_none_or(|r| r.as_str() == Some(kind)),
+ "line {line}: message role disagrees with record type"
+ );
+ let (body, files) = turn_text(
+ message.get("content").unwrap_or(&Value::Null),
+ line,
+ &mut summary.skipped_blocks,
+ )?;
+ if body.trim().is_empty() {
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let parent_id = if entry["parentUuid"].is_null() {
+ Value::Null
+ } else {
+ json!(uuid_field(entry, "parentUuid", line)?)
+ };
+ let timestamp = optional_text(entry, "timestamp", line)?;
+ if let Some(text) = timestamp.as_str() {
+ ensure!(
+ chrono::DateTime::parse_from_rfc3339(text).is_ok(),
+ "line {line}: invalid timestamp"
+ );
+ }
+ let text_fields = json!({"body":body, "files":files, "source_file":source_file,
+ "cwd":optional_text(entry,"cwd",line)?, "git_branch":optional_text(entry,"gitBranch",line)?});
+ let mut record = json!({});
+ record["id"] = json!(format!("{sid}/{mid}"));
+ record["session_schema_version"] = json!(1);
+ record["session_format"] = json!("claude-code");
+ record["session_id"] = json!(sid);
+ record["message_id"] = json!(mid);
+ record["parent_id"] = parent_id;
+ record["role"] = json!(kind);
+ record["timestamp"] = timestamp;
+ record["source_line"] = json!(line);
+ record["source_byte_offset"] = json!(offset);
+ record["is_sidechain"] = json!(flag(entry, "isSidechain", line)?);
+ record["is_summary"] = json!(flag(entry, "isCompactSummary", line)?);
+ Ok(Some(ParsedTurn {
+ text_fields,
+ identity_fields: record,
+ }))
+}
+
+mod codex;
+
+#[derive(Clone, Copy)]
+enum SessionFormat {
+ ClaudeCode,
+ Codex,
+}
+
pub fn import_claude_code(input: &Path, output: &Path) -> Result<ImportSummary> {
+ import_session(input, output, SessionFormat::ClaudeCode)
+}
+
+pub fn import_codex(input: &Path, output: &Path) -> Result<ImportSummary> {
+ import_session(input, output, SessionFormat::Codex)
+}
+
+fn import_session(input: &Path, output: &Path, format: SessionFormat) -> Result<ImportSummary> {
match fs::symlink_metadata(output) {
Ok(_) => bail!("session output already exists; choose a new output path"),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
@@ -217,6 +328,7 @@ pub fn import_claude_code(input: &Path, output: &Path) -> Result<ImportSummary>
let mut written = 0u64;
let mut session: Option<String> = None;
let mut seen = HashSet::new();
+ let mut codex = codex::CodexState::default();
loop {
bytes.clear();
let count = (&mut reader)
@@ -240,84 +352,38 @@ pub fn import_claude_code(input: &Path, output: &Path) -> Result<ImportSummary>
let entry: Value = serde_json::from_slice(&bytes).map_err(|_| {
anyhow::anyhow!("line {line}: invalid JSON; no session export published")
})?;
- let kind = entry["type"]
- .as_str()
- .with_context(|| format!("line {line}: missing session record type"))?;
- if !matches!(kind, "user" | "assistant") {
- summary.skipped_records += 1;
- continue;
- }
- let sid = uuid_field(&entry, "sessionId", line)?;
- if let Some(expected) = &session {
- ensure!(
- expected == &sid,
- "line {line}: mixed session IDs are unsupported"
- );
- } else {
- session = Some(sid.clone());
- }
- let mid = uuid_field(&entry, "uuid", line)?;
- ensure!(
- seen.len() < MAX_RECORDS,
- "session exceeds 100000 message UUIDs"
- );
- ensure!(
- seen.insert(mid.clone()),
- "line {line}: repeated message UUID; export a transcript without revisions"
- );
- if flag(&entry, "isMeta", line)? {
- summary.skipped_records += 1;
- continue;
- }
- let message = entry["message"]
- .as_object()
- .with_context(|| format!("line {line}: missing message object"))?;
- ensure!(
- message.get("role").is_none_or(|r| r.as_str() == Some(kind)),
- "line {line}: message role disagrees with record type"
- );
- let (body, files) = turn_text(
- message.get("content").unwrap_or(&Value::Null),
- line,
- &mut summary.skipped_blocks,
- )?;
- if body.trim().is_empty() {
- summary.skipped_records += 1;
+ let parsed = match format {
+ SessionFormat::ClaudeCode => claude_turn(
+ &entry,
+ line,
+ offset,
+ source_file,
+ &mut summary,
+ &mut session,
+ &mut seen,
+ )?,
+ SessionFormat::Codex => {
+ codex.turn(&entry, line, offset, source_file, &bytes, &mut summary)?
+ }
+ };
+ let Some(ParsedTurn {
+ text_fields: mut record,
+ identity_fields,
+ }) = parsed
+ else {
continue;
- }
- let parent_id = if entry["parentUuid"].is_null() {
- Value::Null
- } else {
- json!(uuid_field(&entry, "parentUuid", line)?)
};
- let timestamp = optional_text(&entry, "timestamp", line)?;
- if let Some(text) = timestamp.as_str() {
- ensure!(
- chrono::DateTime::parse_from_rfc3339(text).is_ok(),
- "line {line}: invalid timestamp"
- );
- }
- let mut record = json!({"body":body, "files":files, "source_file":source_file,
- "cwd":optional_text(&entry,"cwd",line)?, "git_branch":optional_text(&entry,"gitBranch",line)?});
ensure!(
redactor.process(&mut record) == ProcessAction::Pass,
"PII redaction refused session record"
);
- // Only validated opaque IDs/enums and provenance numbers bypass the
- // text redactor: a phone regex must not corrupt UUID relationships.
- record["id"] = json!(format!("{sid}/{mid}"));
- record["session_schema_version"] = json!(1);
- record["session_format"] = json!("claude-code");
- record["session_id"] = json!(sid);
- record["message_id"] = json!(mid);
- record["parent_id"] = parent_id;
- record["role"] = json!(kind);
- record["timestamp"] = timestamp;
- record["source_line"] = json!(line);
- record["source_byte_offset"] = json!(offset);
- record["is_sidechain"] = json!(flag(&entry, "isSidechain", line)?);
- record["is_summary"] = json!(flag(&entry, "isCompactSummary", line)?);
- let title = record["body"]
+ // Only validated enums/IDs and numeric provenance bypass text redaction.
+ record
+ .as_object_mut()
+ .unwrap()
+ .extend(identity_fields.as_object().unwrap().clone());
+ let kind = record["role"].as_str().unwrap();
+ let title: String = record["body"]
.as_str()
.unwrap()
.lines()
@@ -325,7 +391,7 @@ pub fn import_claude_code(input: &Path, output: &Path) -> Result<ImportSummary>
.unwrap_or("")
.chars()
.take(120)
- .collect::<String>();
+ .collect();
record["title"] = json!(format!("{kind}: {title}"));
let mut encoded = serde_json::to_vec(&record)?;
encoded.push(b'\n');
@@ -355,7 +421,7 @@ pub fn run_cli(args: &[String]) -> i32 {
print!("{HELP}");
return 0;
}
- let parsed = (|| -> Result<(PathBuf, PathBuf)> {
+ let parsed = (|| -> Result<(PathBuf, PathBuf, SessionFormat)> {
ensure!(args[0] == "import", "expected sessions import");
let mut input = None;
let mut output = None;
@@ -375,23 +441,25 @@ pub fn run_cli(args: &[String]) -> i32 {
.context("session import option requires a value")?;
*slot = Some(value.clone());
}
- ensure!(
- format.as_deref() == Some("claude-code"),
- "--format claude-code is required"
- );
+ let format = match format.as_deref() {
+ Some("claude-code") => SessionFormat::ClaudeCode,
+ Some("codex") => SessionFormat::Codex,
+ _ => bail!("--format claude-code or --format codex is required"),
+ };
Ok((
PathBuf::from(input.context("--input is required")?),
PathBuf::from(output.context("--output is required")?),
+ format,
))
})();
- let (input, output) = match parsed {
+ let (input, output, format) = match parsed {
Ok(paths) => paths,
Err(error) => {
eprintln!("error: {error}");
return 2;
}
};
- match import_claude_code(&input, &output) {
+ match import_session(&input, &output, format) {
Ok(summary) => {
let mut stdout = std::io::stdout().lock();
if serde_json::to_writer(&mut stdout, &summary).is_err() || writeln!(stdout).is_err() {
@@ -422,7 +490,7 @@ mod tests {
"message":{"role":role,"content":content}})
}
- fn write_input(path: &Path, entries: &[Value]) {
+ pub(super) fn write_input(path: &Path, entries: &[Value]) {
let mut text = entries
.iter()
.map(Value::to_string)
diff --git a/engine/crates/xerj-autoindex/src/sessions/codex.rs b/engine/crates/xerj-autoindex/src/sessions/codex.rs
new file mode 100644
index 000000000..31a0df3a8
--- /dev/null
+++ b/engine/crates/xerj-autoindex/src/sessions/codex.rs
@@ -0,0 +1,411 @@
+//! Explicit Codex rollout subset. Reference and licence are pinned in the import guide.
+use super::*;
+
+#[derive(Default)]
+pub(super) struct CodexState {
+ session: Option<String>,
+ cwd: Value,
+ branch: Value,
+ messages: usize,
+}
+
+fn timestamp(entry: &Value, line: u64) -> Result<Value> {
+ let timestamp = entry["timestamp"]
+ .as_str()
+ .with_context(|| format!("line {line}: missing rollout timestamp"))?;
+ ensure!(
+ chrono::DateTime::parse_from_rfc3339(timestamp).is_ok(),
+ "line {line}: invalid rollout timestamp"
+ );
+ Ok(json!(timestamp))
+}
+
+impl CodexState {
+ pub(super) fn turn(
+ &mut self,
+ entry: &Value,
+ line: u64,
+ offset: u64,
+ source_file: &str,
+ bytes: &[u8],
+ summary: &mut ImportSummary,
+ ) -> Result<Option<ParsedTurn>> {
+ let kind = entry["type"]
+ .as_str()
+ .with_context(|| format!("line {line}: missing rollout record type"))?;
+ let time = timestamp(entry, line)?;
+ let payload = &entry["payload"];
+ ensure!(
+ payload.is_object(),
+ "line {line}: expected rollout payload object"
+ );
+ if kind == "session_meta" {
+ ensure!(
+ self.session.is_none(),
+ "line {line}: repeated session metadata; select one rollout file"
+ );
+ self.session = Some(uuid_field(payload, "id", line)?);
+ // A single file cannot resolve a prefix inherited from another rollout.
+ ensure!(payload["history_base"].is_null(), "line {line}: external history_base is unsupported; select a self-contained archived rollout");
+ self.cwd = optional_text(payload, "cwd", line)?;
+ ensure!(
+ payload["git"].is_null() || payload["git"].is_object(),
+ "line {line}: invalid git metadata"
+ );
+ self.branch = optional_text(&payload["git"], "branch", line)?;
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let sid = self.session.as_ref().with_context(|| format!("line {line}: Codex rollout must start with session_meta; exec --json is unsupported"))?;
+ if kind == "turn_context" {
+ // This is the explicit per-turn working directory; instructions stay out.
+ self.cwd = optional_text(payload, "cwd", line)?;
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ if kind != "response_item" {
+ ensure!(
+ matches!(
+ kind,
+ "event_msg"
+ | "compacted"
+ | "token_usage_record"
+ | "world_state"
+ | "security_risk_score"
+ ),
+ "line {line}: unsupported rollout record type"
+ );
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let item = payload["type"]
+ .as_str()
+ .with_context(|| format!("line {line}: missing response item type"))?;
+ if item != "message" {
+ ensure!(
+ matches!(
+ item,
+ "reasoning"
+ | "function_call"
+ | "function_call_output"
+ | "custom_tool_call"
+ | "custom_tool_call_output"
+ | "local_shell_call"
+ | "web_search_call"
+ | "image_generation_call"
+ | "tool_search_call"
+ | "tool_search_output"
+ | "additional_tools"
+ | "agent_message"
+ | "compaction"
+ | "configuration_update"
+ | "compaction_trigger"
+ | "context_compaction"
+ ),
+ "line {line}: unsupported response item type"
+ );
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ let role = payload["role"]
+ .as_str()
+ .with_context(|| format!("line {line}: missing message role"))?;
+ if matches!(role, "system" | "developer") {
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ ensure!(
+ matches!(role, "user" | "assistant"),
+ "line {line}: unsupported message role"
+ );
+ ensure!(
+ payload["channel"].is_null(),
+ "line {line}: channel-bearing messages are unsupported"
+ );
+ self.messages += 1;
+ ensure!(
+ self.messages <= MAX_RECORDS,
+ "session exceeds 100000 response messages"
+ );
+ let phase = optional_text(payload, "phase", line)?;
+ ensure!(
+ phase.is_null()
+ || matches!(
+ phase.as_str(),
+ Some("commentary" | "partial_answer" | "final_answer")
+ ),
+ "line {line}: unsupported message phase"
+ );
+ let blocks = payload["content"]
+ .as_array()
+ .with_context(|| format!("line {line}: unsupported message content"))?;
+ let mut body = String::new();
+ for block in blocks {
+ match block["type"].as_str() {
+ Some("input_text" | "output_text") => {
+ let text = block["text"]
+ .as_str()
+ .with_context(|| format!("line {line}: malformed text block"))?;
+ let separator = usize::from(!body.is_empty());
+ ensure!(
+ body.len() + separator + text.len() <= MAX_TEXT_BYTES,
+ "line {line}: turn text exceeds 256 KiB"
+ );
+ if !body.is_empty() {
+ body.push('\n');
+ }
+ body.push_str(text);
+ }
+ Some("input_image" | "input_audio") => summary.skipped_blocks += 1,
+ _ => bail!("line {line}: unsupported content block type"),
+ }
+ }
+ if body.trim().is_empty() {
+ summary.skipped_records += 1;
+ return Ok(None);
+ }
+ // Rollout message IDs can be absent, arbitrary or repeated. This is an
+ // archive event identity, not an invented provider ID or parent chain.
+ let mid = format!("line-{line}-{:x}", Sha256::digest(bytes));
+ Ok(Some(ParsedTurn {
+ text_fields: json!({"body":body, "files":[], "source_file":source_file,
+ "cwd":self.cwd, "git_branch":self.branch}),
+ identity_fields: json!({"id":format!("codex/{sid}/{mid}"),
+ "session_schema_version":1, "session_format":"codex", "session_id":sid,
+ "message_id":mid, "parent_id":null, "role":role, "timestamp":time,
+ "source_line":line, "source_byte_offset":offset, "is_sidechain":null,
+ "is_summary":false, "message_phase":phase}),
+ }))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::sessions::tests::write_input;
+
+ fn meta() -> Value {
+ json!({"timestamp":"2026-10-25T00:00:00Z", "type":"session_meta",
+ "payload":{"id":"550e8400-e29b-41d4-a716-446655440000", "cwd":"/first", "git":{"branch":"main"}}})
+ }
+
+ fn message(text: &str) -> Value {
+ json!({"timestamp":"2026-10-25T00:00:01Z", "type":"response_item",
+ "payload":{"type":"message", "role":"assistant", "content":[{"type":"output_text", "text":text}]}})
+ }
+
+ #[test]
+ fn codex_archive_identity_provenance_and_redaction_are_reproducible() {
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("[email protected]");
+ let output = dir.path().join("safe.jsonl");
+ let original = include_bytes!("../../tests/fixtures/codex-session.jsonl");
+ fs::write(&input, original).unwrap();
+ let summary = import_codex(&input, &output).unwrap();
+ assert_eq!(
+ (
+ summary.records,
+ summary.source_lines,
+ summary.skipped_records,
+ summary.skipped_blocks
+ ),
+ (2, 10, 8, 1)
+ );
+ let safe = fs::read(&output).unwrap();
+ let text = std::str::from_utf8(&safe).unwrap();
+ assert!(!text.contains("DO_NOT_EXPORT"));
+ assert!(!text.contains("[email protected]"));
+ assert!(text.contains("[REDACTED_EMAIL]"));
+ let rows: Vec<Value> = text
+ .lines()
+ .map(|s| serde_json::from_str(s).unwrap())
+ .collect();
+ let offset: usize = original
+ .split_inclusive(|b| *b == b'\n')
+ .take(8)
+ .map(<[u8]>::len)
+ .sum();
+ assert_eq!(rows[1]["source_line"], 9);
+ assert_eq!(rows[1]["source_byte_offset"], offset);
+ assert_eq!(rows[1]["message_phase"], "final_answer");
+ assert_eq!(rows[1]["is_sidechain"], Value::Null);
+ assert_eq!(rows[1]["parent_id"], Value::Null);
+ assert_eq!(rows[1]["files"], json!([]));
+ assert_eq!(
+ summary.source_sha256,
+ format!("{:x}", Sha256::digest(original))
+ );
+ assert_eq!(
+ summary.output_sha256,
+ format!("{:x}", Sha256::digest(&safe))
+ );
+ assert_eq!(fs::read(&input).unwrap(), original);
+ assert_eq!(
+ rows[0].as_object().unwrap().keys().collect::<Vec<_>>(),
+ rows[1].as_object().unwrap().keys().collect::<Vec<_>>()
+ );
+ let again = dir.path().join("again.jsonl");
+ import_codex(&input, &again).unwrap();
+ assert_eq!(fs::read(&again).unwrap(), safe);
+ assert!(import_codex(&input, &output).is_err());
+ assert_eq!(fs::read(&output).unwrap(), safe);
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ assert_eq!(
+ fs::metadata(output).unwrap().permissions().mode() & 0o777,
+ 0o600
+ );
+ }
+ }
+
+ #[test]
+ fn codex_ignores_provider_ids_and_keeps_identical_messages_as_distinct_archive_events() {
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("input.jsonl");
+ let output = dir.path().join("safe.jsonl");
+ let mut turn = message("repeat");
+ turn["payload"]["id"] = json!("not-a-uuid [email protected]");
+ write_input(&input, &[meta(), turn.clone(), turn]);
+ import_codex(&input, &output).unwrap();
+ let rows: Vec<Value> = fs::read_to_string(output)
+ .unwrap()
+ .lines()
+ .map(|s| serde_json::from_str(s).unwrap())
+ .collect();
+ assert_ne!(rows[0]["id"], rows[1]["id"]);
+ assert!(rows[0]["message_id"]
+ .as_str()
+ .unwrap()
+ .starts_with("line-2-"));
+ assert!(!rows[0].to_string().contains("[email protected]"));
+ }
+
+ #[test]
+ fn codex_context_and_all_five_pii_types_use_the_shared_redactor() {
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("input.jsonl");
+ let output = dir.path().join("safe.jsonl");
+ let mut header = meta();
+ header["payload"]["git"]["branch"] = json!("[email protected]");
+ let context = json!({"timestamp":"2026-10-25T00:00:00Z", "type":"turn_context", "payload":{"cwd":"/[email protected]/new", "instructions":"DO_NOT_EXPORT"}});
+ write_input(
+ &input,
+ &[
+ header,
+ context,
+ message(
+ "Email: [email protected]. IP: 192.0.2.55. Card: 4111-1111-1111-1111. SSN: 123-45-6789. Phone: 202-555-0147.",
+ ),
+ ],
+ );
+ import_codex(&input, &output).unwrap();
+ let text = fs::read_to_string(output).unwrap();
+ for marker in ["EMAIL", "IP", "CC", "SSN", "PHONE"] {
+ assert!(text.contains(&format!("[REDACTED_{marker}]")), "{text}");
+ }
+ assert!(!text.contains("DO_NOT_EXPORT"));
+ assert!(!text.contains("[email protected]"));
+ let row: Value = serde_json::from_str(&text).unwrap();
+ assert_eq!(row["cwd"], "/[REDACTED_EMAIL]/new");
+ assert_eq!(row["git_branch"], "[REDACTED_EMAIL]");
+ }
+
+ #[test]
+ fn codex_unsupported_or_malformed_shapes_publish_nothing_and_can_recover() {
+ let mut missing_text = message("valid");
+ missing_text["payload"]["content"][0]["text"] = json!(7);
+ let mut role = message("valid");
+ role["payload"]["role"] = json!("future");
+ let mut block = message("valid");
+ block["payload"]["content"][0]["type"] = json!("future_text");
+ let mut phase = message("valid");
+ phase["payload"]["phase"] = json!("analysis");
+ let mut channel = message("DO_NOT_EXPORT_ANALYSIS");
+ channel["payload"]["channel"] = json!("analysis");
+ let mut time = message("valid");
+ time["timestamp"] = json!("invalid");
+ let mut cwd = meta();
+ cwd["type"] = json!("turn_context");
+ cwd["payload"]["cwd"] = json!(5);
+ let mut inherited = meta();
+ inherited["payload"]["history_base"] = json!({"rollout_id":"external"});
+ let mut bad_id = meta();
+ bad_id["payload"]["id"] = json!("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz");
+ for (entries, needle) in [
+ (vec![message("valid")], "start with session_meta"),
+ (
+ vec![meta(), message("valid"), meta()],
+ "repeated session metadata",
+ ),
+ (vec![inherited, message("valid")], "external history_base"),
+ (vec![bad_id], "invalid UUID"),
+ (
+ vec![meta(), message("valid"), missing_text],
+ "malformed text",
+ ),
+ (vec![meta(), role], "unsupported message role"),
+ (vec![meta(), block], "unsupported content block"),
+ (vec![meta(), phase], "unsupported message phase"),
+ (vec![meta(), channel], "channel-bearing"),
+ (vec![meta(), time], "invalid rollout timestamp"),
+ (vec![meta(), cwd], "expected text in cwd"),
+ (
+ vec![
+ meta(),
+ json!({"timestamp":"2026-10-25T00:00:00Z", "type":"future", "payload":{}}),
+ ],
+ "unsupported rollout",
+ ),
+ (vec![meta()], "no supported text-bearing"),
+ ] {
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("input.jsonl");
+ let output = dir.path().join("safe.jsonl");
+ write_input(&input, &entries);
+ let before = fs::read(&input).unwrap();
+ let error = import_codex(&input, &output).unwrap_err().to_string();
+ assert!(error.contains(needle), "{needle}: {error}");
+ assert!(!error.contains("DO_NOT_EXPORT"));
+ assert!(!output.exists());
+ assert_eq!(fs::read(&input).unwrap(), before);
+ assert_eq!(fs::read_dir(dir.path()).unwrap().count(), 1);
+ write_input(&input, &[meta(), message("fixed archive")]);
+ assert_eq!(import_codex(&input, &output).unwrap().records, 1);
+ }
+ }
+
+ #[test]
+ fn codex_truncated_tail_and_text_limits_are_atomic() {
+ for text_len in [MAX_TEXT_BYTES, MAX_TEXT_BYTES + 1] {
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("input.jsonl");
+ let output = dir.path().join("safe.jsonl");
+ write_input(&input, &[meta(), message(&"x".repeat(text_len))]);
+ if text_len == MAX_TEXT_BYTES {
+ assert_eq!(import_codex(&input, &output).unwrap().records, 1);
+ } else {
+ assert!(import_codex(&input, &output)
+ .unwrap_err()
+ .to_string()
+ .contains("exceeds 256 KiB"));
+ assert!(!output.exists());
+ }
+ }
+ let dir = tempfile::tempdir().unwrap();
+ let input = dir.path().join("input.jsonl");
+ let output = dir.path().join("safe.jsonl");
+ write_input(&input, &[meta(), message("valid")]);
+ fs::OpenOptions::new()
+ .append(true)
+ .open(&input)
+ .unwrap()
+ .write_all(b"{\"DO_NOT_EXPORT\":")
+ .unwrap();
+ let error = import_codex(&input, &output).unwrap_err().to_string();
+ assert!(error.contains("line 3: invalid JSON"), "{error}");
+ assert!(!error.contains("DO_NOT_EXPORT"));
+ assert!(!output.exists());
+ assert_eq!(fs::read_dir(dir.path()).unwrap().count(), 1);
+ }
+}
diff --git a/engine/crates/xerj-autoindex/tests/fixtures/codex-session.jsonl b/engine/crates/xerj-autoindex/tests/fixtures/codex-session.jsonl
new file mode 100644
index 000000000..63ace151c
--- /dev/null
+++ b/engine/crates/xerj-autoindex/tests/fixtures/codex-session.jsonl
@@ -0,0 +1,10 @@
+{"timestamp":"2026-10-25T00:00:00Z","type":"session_meta","payload":{"id":"550e8400-e29b-41d4-a716-446655440000","cwd":"/synthetic/project","git":{"branch":"main"},"base_instructions":{"text":"DO_NOT_EXPORT_INSTRUCTIONS"}}}
+{"timestamp":"2026-10-25T00:00:01Z","type":"response_item","payload":{"type":"message","role":"developer","content":[{"type":"input_text","text":"DO_NOT_EXPORT_DEVELOPER"}]}}
+{"timestamp":"2026-10-25T00:00:02Z","type":"turn_context","payload":{"cwd":"/synthetic/project","user_instructions":"DO_NOT_EXPORT_CONTEXT"}}
+{"timestamp":"2026-10-25T00:00:03Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"Why did we drop polling?"},{"type":"input_image","image_url":"DO_NOT_EXPORT_IMAGE"}]}}
+{"timestamp":"2026-10-25T00:00:04Z","type":"event_msg","payload":{"type":"user_message","message":"DO_NOT_EXPORT_DUPLICATE_USER"}}
+{"timestamp":"2026-10-25T00:00:05Z","type":"response_item","payload":{"type":"reasoning","summary":[{"type":"summary_text","text":"DO_NOT_EXPORT_REASONING"}],"encrypted_content":"DO_NOT_EXPORT_ENCRYPTED"}}
+{"timestamp":"2026-10-25T00:00:06Z","type":"response_item","payload":{"type":"function_call","name":"exec_command","arguments":"DO_NOT_EXPORT_TOOL"}}
+{"timestamp":"2026-10-25T00:00:07Z","type":"response_item","payload":{"type":"function_call_output","output":"DO_NOT_EXPORT_RESULT"}}
+{"timestamp":"2026-10-25T00:00:08Z","type":"response_item","payload":{"type":"message","id":"[email protected]","role":"assistant","phase":"final_answer","content":[{"type":"output_text","text":"We dropped polling because the durable journal recovers missed file events. Contact [email protected].","annotations":["DO_NOT_EXPORT_ANNOTATIONS"]}],"encrypted_content":"DO_NOT_EXPORT_ENCRYPTED_MESSAGE"}}
+{"timestamp":"2026-10-25T00:00:09Z","type":"event_msg","payload":{"type":"agent_message","message":"DO_NOT_EXPORT_DUPLICATE_ASSISTANT"}}
diff --git a/engine/crates/xerj-server/tests/sessions_cli.rs b/engine/crates/xerj-server/tests/sessions_cli.rs
index e75bcb59a..ea0023f32 100644
--- a/engine/crates/xerj-server/tests/sessions_cli.rs
+++ b/engine/crates/xerj-server/tests/sessions_cli.rs
@@ -61,6 +61,48 @@ fn sessions_cli_bad_format_is_usage_error_without_output() {
assert!(!output.exists());
}
+#[test]
+fn sessions_cli_codex_rollout_exports_decision_without_duplicate_events_or_private_payloads() {
+ let work = tempfile::tempdir().unwrap();
+ let input = work.path().join("rollout.jsonl");
+ let output = work.path().join("records.jsonl");
+ std::fs::write(
+ &input,
+ include_str!("../../xerj-autoindex/tests/fixtures/codex-session.jsonl"),
+ )
+ .unwrap();
+ let result = Command::new(env!("CARGO_BIN_EXE_xerj"))
+ .args(["sessions", "import", "--format", "codex", "--input"])
+ .arg(&input)
+ .arg("--output")
+ .arg(&output)
+ .output()
+ .unwrap();
+ assert!(
+ result.status.success(),
+ "{}",
+ String::from_utf8_lossy(&result.stderr)
+ );
+ let report: Value = serde_json::from_slice(&result.stdout).unwrap();
+ assert_eq!(report["records"], 2);
+ assert_eq!(report["source_lines"], 10);
+ assert_eq!(report["skipped_records"], 8);
+ assert_eq!(report["skipped_blocks"], 1);
+ let text = std::fs::read_to_string(output).unwrap();
+ assert!(!text.contains("DO_NOT_EXPORT"));
+ assert!(!text.contains("[email protected]"));
+ assert!(text.contains("[REDACTED_EMAIL]"));
+ let rows: Vec<Value> = text
+ .lines()
+ .map(|s| serde_json::from_str(s).unwrap())
+ .collect();
+ assert_eq!(rows[1]["session_format"], "codex");
+ assert_eq!(rows[1]["source_line"], 9);
+ assert_eq!(rows[1]["message_phase"], "final_answer");
+ assert_eq!(rows[1]["parent_id"], Value::Null);
+ assert_eq!(rows[1]["files"], serde_json::json!([]));
+}
+
#[test]
fn sessions_cli_malformed_tail_keeps_input_and_publishes_no_partial_export() {
let work = tempfile::tempdir().unwrap();
diff --git a/tools/session-import/CODEX_VERIFICATION.md b/tools/session-import/CODEX_VERIFICATION.md
new file mode 100644
index 000000000..6fdd4d2ab
--- /dev/null
+++ b/tools/session-import/CODEX_VERIFICATION.md
@@ -0,0 +1,145 @@
+# Codex rollout adapter verification — 2026-10-26
+
+Local runs span October 25–26, Asia/Shanghai.
+
+OpenAI Codex, operated by Jarvis636431. macOS arm64, Rust 1.97.1.
+Independent branch from upstream `23016aa6d41123956860309a5aae3d3526b4415e`,
+which includes merged #2406. No stacked commits or dependency on open #2384.
+The supported format and pinned Apache-2.0 reference are in
+[the import guide](README.md#codex-rollout-adapter).
+
+## Commands and results
+
+From `engine/`:
+
+```sh
+cargo +1.97.1 fmt --all
+cargo +1.97.1 fmt --all -- --check
+cargo +1.97.1 build --locked --offline --release -j 32 \
+ -p xerj-autoindex -p xerj-server -p es-yaml-runner
+
+TMPDIR=/private/tmp cargo +1.97.1 test --locked --offline -p xerj-autoindex -- \
+ --test-threads=1 \
+ --skip content::tests::lossy_display_collisions_keep_distinct_alias_identities \
+ --skip corpus_data_skip_tests::corpus_index_summary_splits_indexed_extensions_from_ignored_data \
+ --skip inventory_delta_tests::a_non_utf8_excluded_name_is_matched_on_disk_via_path_id
+
+cargo +1.97.1 test --locked --offline -p xerj-autoindex --lib sessions::
+TMPDIR=/private/tmp cargo +1.97.1 test --locked --offline \
+ -p xerj-server --test sessions_cli --bin xerj -- --test-threads=1
+
+cargo +1.97.1 clippy --locked --offline --no-deps \
+ -p xerj-autoindex --all-targets -- -D warnings -A dead_code
+cargo +1.97.1 clippy --locked --offline --no-deps \
+ -p xerj-server --bin xerj --test sessions_cli -- -D warnings
+```
+
+- Autoindex crate: **1,844 passed, 0 failed, 5 existing ignored, 3 filtered**
+ across unit/integration/doc-test invocations. Session module: **16 passed**
+ (11 existing Claude Code/shared-I/O tests, 5 Codex tests).
+- Main program: **119 passed**; CLI integration: **4 passed**.
+- Both listed Clippy invocations passed. The existing `resolve_reporting`
+ dead-code warning still needs the command-line allowance for autoindex; no
+ lint suppression was added to source. The server command is scoped to its
+ main binary and session integration target, not every server test target.
+- Formatting and whitespace checks passed. From the repository root,
+ `python3 .github/scripts/workflow-timeout-guard.py` passed (40 jobs across
+ 12 workflows); Python compilation of `tools/session-import/smoke.py` passed.
+
+The three filesystem filters and original baseline reproductions are documented
+in [the Claude Code verification](VERIFICATION.md#why-the-three-filters-exist).
+The affected `content.rs` is byte-identical to that baseline; `lib.rs` differs
+only by exporting the sessions module. No committed skip/assertion changed.
+Loopback tests ran with permission to bind local sockets and a canonical
+`TMPDIR`; sandbox-denied socket failures are not reported as product defects.
+An early PII fixture without separators made the native credit-card pattern
+consume adjacent numeric examples; labels/punctuation corrected the synthetic
+test input, without changing the plugin or weakening the five-type assertions.
+
+## Regression evidence
+
+Before adding format support, the new real CLI regression failed with
+`error: --format claude-code is required` (1 failed, 0 passed). It now passes
+and pins 2 exported records from 10 physical lines, 8 skipped records, 1 skipped
+attachment block, the decision on source line 9 and its explicit final phase.
+
+The unit fixtures check input/output digests, unchanged source, byte offset,
+private file permissions, deterministic archive event IDs, repeated provider IDs,
+identical messages on distinct lines, source/context metadata redaction,
+five native PII types, absent parent/file associations, malformed tails,
+inclusive text bounds, unsupported fields, no-clobber output and successful
+recovery after correcting an invalid synthetic source.
+
+Private copies of the module were compiled for targeted mutations; production
+source was not mutated:
+
+- Bypassing the shared redactor failed exactly the 2 Codex privacy tests;
+ the other 3 Codex tests passed.
+- Removing the external `history_base` guard caused a one-record export to
+ publish incorrectly; the refusal/recovery regression failed, and the other
+ 4 Codex tests passed.
+- Restoring the unmodified copy passed all 16 session tests.
+
+## Real index lifecycle
+
+From the repository root, using a source-built release binary reporting
+`xerj v1.0.0-rc.99`:
+
+```sh
+python3 tools/session-import/smoke.py --binary engine/target/release/xerj --format codex
+python3 tools/session-import/smoke.py --binary engine/target/release/xerj --format claude-code
+```
+
+Both private-node runs passed: 2 redacted records, existing-output refusal,
+dry-run **1 file (0 MB)**, successful first index and unchanged rerun with
+**2 live documents**, no refused datasets/files, decision retrieval, and
+graceful restart retaining 2 documents. Codex retained original source line 9
+and an empty file-reference array; Claude Code retained line 3 and
+`src/watch.rs`. Raw email and the fixture's private-payload sentinels were absent
+from stored source. Each node stopped normally (exit 0).
+
+Observed autoindex `done.wall_s`: Codex 0.8 / 0.3 seconds, Claude Code
+0.8 / 0.4 seconds. These tiny fixtures are lifecycle checks, not a speed
+benchmark. Both flows used default lexical retrieval and `--no-semantic`, with
+no model, personal transcript, existing node or existing index involved.
+
+## Compatibility gate
+
+Against a separate fresh private node using the same release candidate:
+
+```sh
+engine/target/release/es-yaml-runner --url "$PRIVATE_NODE_URL" \
+ --dir engine/tests/es-compat-yaml/yaml
+```
+
+Observed **229 files; 1,444 passed, 0 failed, 10 skipped, 1,454 total; exit 0**.
+The unchanged suite reported **75 catch-lenient cases**. No YAML, runner,
+catch-lenient policy or HTTP search implementation changed. The conformance
+node shut down normally with exit 0. This validates the candidate source build,
+not published release assets or hosted merge-ref CI.
+
+## Review and limits
+
+Audited against `docs/CONTRIBUTION_REVIEW.md`: the effective diff adds one
+format parser and synthetic fixture, shares the existing bounded I/O/redaction/
+no-clobber path, and extends the existing CLI/smoke documentation and tests.
+Claude Code keeps its field meanings and admission rules. No normal JSONL
+extractor, network endpoint, workflow, dependency, lockfile, model configuration
+or existing index is changed. Existing recovery and publication helpers remain
+in use. Text and metadata go through redaction before staging writes; only
+validated IDs, enums, timestamps and numeric provenance bypass it.
+
+Export schema 1 gains a separate `session_format=codex` record shape and
+Codex-only nullable `message_phase`. No previous export/index is rewritten;
+refresh uses a new export folder and index prefix/state directory. Message IDs
+locate archive events, not provider messages or active conversation branches.
+The parser preserves physical response-message order, including historical
+text before rollback/compaction, and does not infer file edits or commits.
+
+Legacy product migrations, distributed writes, optional accelerators, model
+execution and provider behavior are not applicable to this offline adapter.
+Real personal transcripts, live Codex client runs, Windows/Linux execution,
+automatic discovery, external history resolution, active-context reconstruction,
+incremental refresh, deep secret removal and generated-answer quality were not
+tested or claimed. Website gates were not run: no landing files change.
+Hosted merge-ref CI is separate from these local receipts.
diff --git a/tools/session-import/README.md b/tools/session-import/README.md
index 0049bc0aa..e5b14aa0e 100644
--- a/tools/session-import/README.md
+++ b/tools/session-import/README.md
@@ -1,11 +1,11 @@
-# Import one Claude Code transcript for decision retrieval
+# Import an archived agent transcript for decision retrieval
`xerj sessions import` is the explicit preparation step for a single Claude Code
-JSONL transcript. It runs locally, calls no model or node, and exports text
+transcript or Codex rollout JSONL file. It runs locally, calls no model or node, and exports text
turns through XERJ's existing native PII plugin. Review the export, then give its
-folder to ordinary `xerj autoindex`. This is the first scoped part of
+folder to ordinary `xerj autoindex`. This covers two explicit formats for
[#1793](https://github.com/xerj-org/xerj/issues/1793), not automatic transcript
-discovery, a multi-client adapter, a live conversation view or incremental sync.
+discovery, a live conversation view or incremental sync.
## Try the synthetic example
@@ -66,7 +66,7 @@ raw JSONL; pointing it at the original transcript folder does **not** activate
this preparation or redaction. Use a prefix you own; follow the normal
autoindex estimate/approval contract for large exports.
-## Record and source contract
+## Claude Code record and source contract
One output line is one text-bearing `user` or `assistant` event. `message.content`
may be a string or an array of `text`/recognized non-text blocks. Text blocks
@@ -131,7 +131,8 @@ file; it is not a complete export. Use a new destination after interruption.
Claude Code documents its on-disk JSONL as an internal format that can change:
[session storage](https://code.claude.com/docs/en/sessions#where-transcripts-are-stored).
This adapter supports the explicit shapes above, not every client version,
-`stream-json`, rendered `/export` text, Codex or Cursor logs.
+`stream-json`, rendered `/export` text or Cursor logs. Codex uses the separate
+explicit adapter below.
Reference retrieved before implementation: Anthropic's MIT-licensed SDK at
`0e89b298e771259378a6cd3734e00d323dff5703`,
@@ -146,3 +147,87 @@ All checked-in fixtures are synthetic. No real personal transcript or real
Claude client release is claimed validated by those fixtures. Unit and CLI
tests cover redaction, provenance, filtering, size limits, malformed tails,
unsupported shapes, no-clobber publication and recovery.
+
+## Codex rollout adapter
+
+Select an archived, uncompressed rollout JSONL file explicitly. The command
+does not scan `~/.codex`, read the history database, resolve other rollouts or
+run Codex. Use the same private-output and review-before-indexing steps above:
+
+```sh
+set -eu
+SESSION_EXPORT=$(mktemp -d)
+xerj sessions import --format codex \
+ --input /path/to/archived-rollout.jsonl \
+ --output "$SESSION_EXPORT/records.jsonl"
+```
+
+The file must start (ignoring blank lines) with one `session_meta` containing a
+UUID `payload.id`. Only `response_item` / `payload.type=message` with role `user`
+or `assistant` exports text. Ordered `input_text` and `output_text` blocks are
+joined with newlines; `input_image` and `input_audio` increment skipped blocks.
+Unknown message roles, phases, block types, response item types or top-level
+record types refuse the whole snapshot. Channel-bearing messages also refuse;
+reasoning is not admitted as message text. All envelopes need an RFC 3339
+timestamp and object payload. This is a deliberately bounded subset of an
+internal format, not a claim of support for every Codex version.
+
+`event_msg` records are skipped, including the duplicate user/assistant text
+they can contain. System/developer messages, reasoning, tool calls and results,
+agent-to-agent messages, compaction payloads, world-state and usage/security
+records are not exported. The summary uses the same definitions above: skipped
+blocks count non-text attachments in admitted user/assistant messages; skipped
+records count every nonblank record not exported. No raw metadata, encrypted
+content, provider message ID, annotations, tool argument, image or audio URL is
+included. A user-role text block can itself contain injected context or private
+facts; this adapter does not distinguish that text from a human prompt. Review
+the export; the native five-pattern PII redactor is not a general secret filter.
+
+Codex output keeps schema 1 and the shared text/source fields, with these
+format-specific meanings:
+
+| Field | Codex meaning |
+|---|---|
+| `session_format`, `session_id` | `codex`, canonical thread UUID from `session_meta.payload.id` (not a root-session or provider message ID) |
+| `message_id` | `line-<physical-line>-<SHA256 of original line bytes, including newline if present>`; an archive event locator, not a Codex message ID |
+| `id` | `codex/<session_id>/<message_id>`; identical archived input repeats identically, repeated equal messages at different lines remain distinct |
+| `parent_id`, `is_sidechain` | null: no parent chain or branch status inferred |
+| `files` | Empty array; shell commands, patches and prose are not parsed into file/commit associations |
+| `cwd`, `git_branch` | Redacted session `cwd` and `git.branch`; each `turn_context` replaces the cwd (missing/null becomes unknown). Branch is a session-creation snapshot, not a per-turn observation |
+| `message_phase` | Explicit `commentary`, `partial_answer`, `final_answer`, or null when absent; this additional field is Codex-only |
+| `is_summary` | false; compaction summaries and replacement histories are omitted |
+| `timestamp`, `source_*` | Envelope timestamp and original basename/physical line/byte offset |
+
+The exporter preserves physical message order, including text before a rollback
+or compaction; it does not reconstruct the current model context or active
+conversation. A non-null `history_base` refuses because a single file cannot
+resolve an external inherited prefix. Fork/subagent metadata is not followed,
+and no complete-conversation claim is made for an individual file. Newer
+`retained_context`, inter-agent and realtime record envelopes are unsupported.
+The `codex exec --json` event stream, `history.jsonl` prompt history, compressed
+rollouts and app-server JSON-RPC are separate formats and are unsupported.
+
+All original size limits, source-change detection, sanitized staging, no-clobber
+publication, exit codes and new-folder/prefix recovery rules apply. The 100,000
+message limit counts user/assistant response messages (including attachment-only
+messages); there is no invented UUID requirement or deduplication by provider ID.
+Existing Claude Code exports retain their previous field meanings and key set;
+no existing index or export is upgraded or rewritten.
+
+Reference retrieved before implementation: OpenAI Codex, Apache-2.0, pinned at
+`970111f6cb62cc02fe36a82ea7d71b37a2889c97`:
+
+- [`recorder.rs:2127–2160`](https://github.com/openai/codex/blob/970111f6cb62cc02fe36a82ea7d71b37a2889c97/codex-rs/rollout/src/recorder.rs#L2127-L2160): timestamped flattened rollout envelope.
+- [`rollout_payload.rs:30–73`](https://github.com/openai/codex/blob/970111f6cb62cc02fe36a82ea7d71b37a2889c97/codex-rs/history/src/rollout_payload.rs#L30-L73): tagged payloads distinguish responses, events, context and compaction.
+- [`protocol.rs:3279–3356`](https://github.com/openai/codex/blob/970111f6cb62cc02fe36a82ea7d71b37a2889c97/codex-rs/protocol/src/protocol.rs#L3279-L3356): thread identity, cwd, forks and inherited history.
+- [`models.rs:883–915`](https://github.com/openai/codex/blob/970111f6cb62cc02fe36a82ea7d71b37a2889c97/codex-rs/protocol/src/models.rs#L883-L915) and [`1052–1083`](https://github.com/openai/codex/blob/970111f6cb62cc02fe36a82ea7d71b37a2889c97/codex-rs/protocol/src/models.rs#L1052-L1083): text/attachment blocks and optional response IDs/phases.
+
+These are format evidence, not copied implementation. The official
+[non-interactive guide](https://developers.openai.com/codex/noninteractive)
+documents `exec --json` events; that stream is not the disk rollout adapter.
+Fixtures are synthetic, not personal transcripts or a live-client run.
+Run the Codex fixture through the same private-node lifecycle check:
+
+```sh
+python3 tools/session-import/smoke.py --binary engine/target/release/xerj --format codex
+```
diff --git a/tools/session-import/smoke.py b/tools/session-import/smoke.py
index 2a7b44e32..b5bdce844 100644
--- a/tools/session-import/smoke.py
+++ b/tools/session-import/smoke.py
@@ -24,6 +24,7 @@ def run(binary, arguments, env, work, expected=0):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--binary', type=Path, required=True)
+ parser.add_argument('--format', choices=('claude-code', 'codex'), default='claude-code')
args = parser.parse_args()
binary = args.binary.resolve(strict=True)
env = {k: v for k, v in os.environ.items() if not k.startswith('XERJ_')
@@ -32,11 +33,12 @@ def main():
with tempfile.TemporaryDirectory(prefix='xerj-sessions-smoke-') as temp:
work = Path(temp)
source = work / 'session.jsonl'
- source.write_bytes((ROOT / 'engine/crates/xerj-autoindex/tests/fixtures/claude-session.jsonl').read_bytes())
+ fixture = 'codex-session.jsonl' if args.format == 'codex' else 'claude-session.jsonl'
+ source.write_bytes((ROOT / 'engine/crates/xerj-autoindex/tests/fixtures' / fixture).read_bytes())
exports = work / 'export'
exports.mkdir()
output = exports / 'records.jsonl'
- command = ['sessions', 'import', '--format', 'claude-code', '--input', str(source), '--output', str(output)]
+ command = ['sessions', 'import', '--format', args.format, '--input', str(source), '--output', str(output)]
imported = json.loads(run(binary, command, env, work).stdout)
assert imported['records'] == 2, imported
safe = output.read_bytes()
@@ -134,12 +136,15 @@ def main():
assert '[email protected]' not in json.dumps(stored)
assert 'DO_NOT_EXPORT' not in json.dumps(stored)
decision = next(h['_source'] for h in stored if 'durable journal' in h['_source']['body'])
- assert decision['source_file'] == 'session.jsonl' and decision['source_line'] == 3, decision
- assert decision['files'] == ['src/watch.rs'], decision
+ expected_line = 9 if args.format == 'codex' else 3
+ expected_files = [] if args.format == 'codex' else ['src/watch.rs']
+ assert decision['source_file'] == 'session.jsonl' and decision['source_line'] == expected_line, decision
+ assert decision['files'] == expected_files, decision
+ assert decision['session_format'] == args.format, decision
search = run(binary, ['search', '--prefix', 'session-smoke', '--url', url,
'--json', 'why did we drop polling'], env, work)
assert 'durable journal' in search.stdout, search.stdout
- print('search: decision text found; original session.jsonl:3 and src/watch.rs retained', flush=True)
+ print(f'search: decision text found; original session.jsonl:{expected_line}; files={expected_files}', flush=True)
finally:
stop(child)
child = start(log)