From a1e3b73bc3f3564d5a5b2667e62ef2fcfa371f5c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 22:34:32 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m1/codex-146-messages.md Quest-Claim: b4bc78fa3a1e283d From fb0ce6801f00e0e3659cf25725eafeb8f1426f6e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 23:08:30 -0800 Subject: [PATCH 2/4] feat(messages): read Codex 0.146's interactive sessions Codex before 0.162 marks no part of a user turn, so a part opening with its environment or AGENTS.md wrapper is set aside and the rest read as typed. Turns without provenance from a version that writes it still fail, and shell.user_command parts, a command the person ran, are no longer unknown. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 5 ++-- quest/m1/codex-146-messages.md | 30 ------------------------ src/cli/main.ts | 3 ++- src/cli/messages.ts | 18 +++++++++++++- test/messages.test.ts | 43 ++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 34 deletions(-) delete mode 100644 quest/m1/codex-146-messages.md diff --git a/README.md b/README.md index cef4502f..07def69c 100644 --- a/README.md +++ b/README.md @@ -2105,8 +2105,9 @@ wording. T3 Code records whether a person or an agent created each message, so the sessions it drives are read from its state (`$T3CODE_HOME`, or `~/.t3`) and nowhere else. Other Claude Code sessions count the turns Claude Code marks as a human's, with its reminders dropped and a slash command spelled as typed; -other Codex sessions count the content Codex marks as the user's, outside -headless (`codex exec`) and sub-agent sessions. A log or record in a shape it +other Codex sessions count the content Codex marks as the user's (before 0.162, +which marks none, the parts but its environment and AGENTS.md instructions), +outside headless (`codex exec`) and sub-agent sessions. A log or record in a shape it does not know fails the command rather than being skipped. Output goes to stdout only; nothing is stored or posted. diff --git a/quest/m1/codex-146-messages.md b/quest/m1/codex-146-messages.md deleted file mode 100644 index fb5fc622..00000000 --- a/quest/m1/codex-146-messages.md +++ /dev/null @@ -1,30 +0,0 @@ -# [XS] quest messages reads Codex 0.146 sessions - -## Goal - -`quest messages` reads interactive Codex 0.146 sessions, so -`quest messages --since 2026-10-01` succeeds on a host that ran 0.146 rather -than failing with "user turn without Codex's provenance". Turns of an -unknown shape from other versions still fail. - -## Plan - -Decided 2026-11-17 (maintainer, `/quest-plan` after `/quest-run`): ✅ read -0.146's turns (rejected: skipping any rollout quest cannot read with a -warning, which would let a future format change drop a host's data silently -and reverses [#719](https://github.com/moq-dev/quest/pull/719)'s choice to -fail on unknown shapes; both; dropping it); ✅ m1 (rejected: m0), since the -gap is two days on one host and does not recur. - -- Codex 0.146 writes no `content_item_metadata` or `content_item_kinds` on - user turns, only `turn_id`. On one of the maintainer's hosts, 6 - interactive sessions (2026-10-15 and 16) hold 33 such turns in the window, - and one aborts the whole run; that kept the host out of the transcript audit - behind [#764](https://github.com/moq-dev/quest/pull/764). Sub-agent - sessions of that version are already skipped by their object `source`. -- In those sessions, injected parts open with `` or - `# AGENTS.md instructions for`, and typed text is a plain part. -- Recommended: for a session whose `session_meta.cli_version` predates - provenance, treat a part opening with a known 0.146 wrapper as - harness or `agents_md` and the rest as typed, and keep throwing for a - turn without metadata from a version that writes it. diff --git a/src/cli/main.ts b/src/cli/main.ts index 98ea3b2c..4779e3a1 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1577,7 +1577,8 @@ export function main(argv: string[], out: Output): number | Promise { "its state ($T3CODE_HOME, or ~/.t3), which records whether a person or an agent sent each message. " + "Other Claude Code sessions, from $CLAUDE_CONFIG_DIR (or ~/.config/claude and ~/.claude), count a turn " + "Claude Code marks as a human's; other Codex sessions, from $CODEX_HOME (or ~/.codex), count the " + - "content Codex marks as the user's, outside headless and sub-agent sessions. The repository is the " + + "content Codex marks as the user's (before 0.162, which marks none, the parts but its environment and " + + "AGENTS.md instructions), outside headless and sub-agent sessions. The repository is the " + "checkout's GitHub origin, else the directory. Output goes to stdout only, except a note on stderr " + "naming each Claude Code session whose malformed lines, such as a partial record a crashed write left, " + "were skipped and how many; nothing is stored or posted. Each answer a person gave an agent's blocking question (Claude Code's AskUserQuestion, " + diff --git a/src/cli/messages.ts b/src/cli/messages.ts index 8e76e5d0..5dfd727b 100644 --- a/src/cli/messages.ts +++ b/src/cli/messages.ts @@ -333,6 +333,7 @@ export function readCodexMessages(path: string, since: number, repository: (dir: const entries: Entry[] = []; let session: string | undefined; let typed = false; + let unmarked = false; let where = ""; let skill: string | null = null; const asked = new Map(); @@ -346,6 +347,7 @@ export function readCodexMessages(path: string, since: number, repository: (dir: throw new Error(`${path} does not start with a Codex session_meta record`); if (typeof payload.source !== "string" || payload.source === "exec") return false; typed = payload.originator !== T3_CODEX; + unmarked = writesNoProvenance(payload.cli_version); session = payload.id; const url = (payload.git as Record | undefined)?.repository_url; const repo = typeof url === "string" ? githubRepository(url) : null; @@ -448,6 +450,9 @@ export function readCodexMessages(path: string, since: number, repository: (dir: let sources: unknown[]; if (Array.isArray(provenance)) { sources = provenance.map((each) => (each as { provenance?: { type?: unknown } } | null)?.provenance?.type); + } else if (unmarked && meta?.content_item_kinds === undefined) { + // Codex before 0.162 marks no part, so the parts it adds are told apart by how they open, and the rest is typed. + sources = content.map((part) => (CODEX_WRAPPER.test(part?.text as string) ? "harness" : "user")); } else { // Codex 0.162's TUI marks each part with a kind instead. A compaction replays earlier turns, already read // where they were typed, with every kind unknown; a part whose kind says nothing otherwise cannot be told @@ -487,10 +492,19 @@ export function codexSkill(text: string): string | null { return /\s*([^<]+?)\s*<\/name>/.exec(text)?.[1] ?? null; } +/** Whether a Codex version predates 0.162, the first seen to mark who wrote each part of a user turn. */ +function writesNoProvenance(version: unknown): boolean { + const [major, minor] = /^(\d+)\.(\d+)\./.exec(String(version))?.slice(1).map(Number) ?? []; + return major === 0 && minor !== undefined && minor < 162; +} + +/** How the parts Codex before 0.162 adds to a user turn open: the environment and the AGENTS.md instructions. */ +const CODEX_WRAPPER = /^\s*(?:|# AGENTS\.md instructions\b)/; + /** Who Codex says wrote a part of a user turn: the person, or the instructions, harness, or skill it added. */ const CODEX_SOURCES = new Set(["user", "agents_md", "harness", "skills"]); -/** The content kinds Codex 0.162 gives the parts it adds to a user turn, never typed by the person. */ +/** The content kinds Codex 0.162 gives the parts of a user turn that are not text the person typed to the agent. */ const CODEX_INJECTED = new Set([ "agents_md.instructions", "environments.environment_context", @@ -503,6 +517,8 @@ const CODEX_INJECTED = new Set([ "tools.deferred_namespaces", "plugins.recommendations", "model.base_instructions", + // A command the person ran with `!`, which Codex shows its agent with the output: a command, not a message. + "shell.user_command", ]); /** T3 Code's agent names, as the harness names `quest usage` reports. */ diff --git a/test/messages.test.ts b/test/messages.test.ts index 7cf5c601..4231df8f 100644 --- a/test/messages.test.ts +++ b/test/messages.test.ts @@ -204,6 +204,9 @@ describe("readCodexMessages from Codex 0.162's TUI", () => { ]), kindTurn("2026-11-06T10:01:00Z", [["fix it", "user.text"]]), kindTurn("2026-11-06T10:02:00Z", [["replayed", "unknown"]]), + kindTurn("2026-11-06T10:03:00Z", [ + ["ls", "shell.user_command"], + ]), ), ); expect(readCodexMessages(path, SINCE, plain).map((m) => m.kind === "message" && m.text)).toEqual(["fix it"]); @@ -216,6 +219,46 @@ describe("readCodexMessages from Codex 0.162's TUI", () => { }); }); +describe("readCodexMessages from Codex 0.146's TUI", () => { + /** A user turn that marks nothing but its turn, as codex-tui 0.146 writes. */ + const bareTurn = (timestamp: string, parts: string[]) => ({ + type: "response_item", + timestamp, + payload: { + type: "message", + role: "user", + content: parts.map((text) => ({ type: "input_text", text })), + internal_chat_message_metadata_passthrough: { turn_id: "t" }, + }, + }); + const meta = (version: string) => codexMeta({ source: "cli", originator: "codex-tui", cli_version: version }); + + test("reads typed text and sets the parts Codex adds aside", () => { + const path = join(tempDir(), "rollout.jsonl"); + writeFileSync( + path, + lines( + meta("0.146.0"), + bareTurn("2026-11-06T10:00:00Z", [ + "# AGENTS.md instructions for /work/proj\n\n", + "\n /work/proj", + ]), + bareTurn("2026-11-06T10:00:30Z", ["\n 2026-11-06"]), + bareTurn("2026-11-06T10:01:00Z", ["fix it"]), + ), + ); + expect(readCodexMessages(path, SINCE, plain).map((m) => m.kind === "message" && m.text)).toEqual(["fix it"]); + }); + + test("fails on a turn without provenance from a version that writes it, or one with no version", () => { + for (const head of [meta("0.162.1"), meta("0.167.0-alpha.6"), meta("1.0.0"), meta("unknown"), codexMeta({})]) { + const path = join(tempDir(), "rollout.jsonl"); + writeFileSync(path, lines(head, bareTurn("2026-11-06T10:01:00Z", ["fix it"]))); + expect(() => readCodexMessages(path, SINCE, plain)).toThrow(/provenance/); + } + }); +}); + /** A Claude Code answer to `AskUserQuestion`, as the tool result's record holds it. */ const claudeAnswer = (timestamp: string, answers: object, extra: object = {}) => ({ type: "user", From a3b6e44fa7f3528311d8a6f0fa70cbf37e8f1bd6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 23:22:32 -0800 Subject: [PATCH 3/4] fix(messages): set aside `!` commands in Codex sessions before 0.162 Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- src/cli/main.ts | 2 +- src/cli/messages.ts | 4 ++-- test/messages.test.ts | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 07def69c..46d1b473 100644 --- a/README.md +++ b/README.md @@ -2106,7 +2106,7 @@ the sessions it drives are read from its state (`$T3CODE_HOME`, or `~/.t3`) and nowhere else. Other Claude Code sessions count the turns Claude Code marks as a human's, with its reminders dropped and a slash command spelled as typed; other Codex sessions count the content Codex marks as the user's (before 0.162, -which marks none, the parts but its environment and AGENTS.md instructions), +which marks none, the parts but its environment, shell commands, and AGENTS.md instructions), outside headless (`codex exec`) and sub-agent sessions. A log or record in a shape it does not know fails the command rather than being skipped. Output goes to stdout only; nothing is stored or posted. diff --git a/src/cli/main.ts b/src/cli/main.ts index 4779e3a1..afe8d1a5 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1577,7 +1577,7 @@ export function main(argv: string[], out: Output): number | Promise { "its state ($T3CODE_HOME, or ~/.t3), which records whether a person or an agent sent each message. " + "Other Claude Code sessions, from $CLAUDE_CONFIG_DIR (or ~/.config/claude and ~/.claude), count a turn " + "Claude Code marks as a human's; other Codex sessions, from $CODEX_HOME (or ~/.codex), count the " + - "content Codex marks as the user's (before 0.162, which marks none, the parts but its environment and " + + "content Codex marks as the user's (before 0.162, which marks none, the parts but its environment, shell commands, and " + "AGENTS.md instructions), outside headless and sub-agent sessions. The repository is the " + "checkout's GitHub origin, else the directory. Output goes to stdout only, except a note on stderr " + "naming each Claude Code session whose malformed lines, such as a partial record a crashed write left, " + diff --git a/src/cli/messages.ts b/src/cli/messages.ts index 5dfd727b..98c4a179 100644 --- a/src/cli/messages.ts +++ b/src/cli/messages.ts @@ -498,8 +498,8 @@ function writesNoProvenance(version: unknown): boolean { return major === 0 && minor !== undefined && minor < 162; } -/** How the parts Codex before 0.162 adds to a user turn open: the environment and the AGENTS.md instructions. */ -const CODEX_WRAPPER = /^\s*(?:|# AGENTS\.md instructions\b)/; +/** How the parts Codex before 0.162 adds to a user turn open: the environment, the AGENTS.md instructions, and a `!` command. */ +const CODEX_WRAPPER = /^\s*(?:|# AGENTS\.md instructions\b|)/; /** Who Codex says wrote a part of a user turn: the person, or the instructions, harness, or skill it added. */ const CODEX_SOURCES = new Set(["user", "agents_md", "harness", "skills"]); diff --git a/test/messages.test.ts b/test/messages.test.ts index 4231df8f..1591d7b1 100644 --- a/test/messages.test.ts +++ b/test/messages.test.ts @@ -244,6 +244,9 @@ describe("readCodexMessages from Codex 0.146's TUI", () => { "\n /work/proj", ]), bareTurn("2026-11-06T10:00:30Z", ["\n 2026-11-06"]), + bareTurn("2026-11-06T10:00:40Z", [ + "\nls\n", + ]), bareTurn("2026-11-06T10:01:00Z", ["fix it"]), ), ); From 2d2a27f0aebf84352759a14d829423bc6be718cd Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 12:15:52 -0800 Subject: [PATCH 4/4] fix(messages): require a complete Codex version before reading it as pre-0.162 Co-Authored-By: Claude Sonnet 5.5 --- src/cli/messages.ts | 4 +++- test/messages.test.ts | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cli/messages.ts b/src/cli/messages.ts index 98c4a179..cab6ab99 100644 --- a/src/cli/messages.ts +++ b/src/cli/messages.ts @@ -494,7 +494,9 @@ export function codexSkill(text: string): string | null { /** Whether a Codex version predates 0.162, the first seen to mark who wrote each part of a user turn. */ function writesNoProvenance(version: unknown): boolean { - const [major, minor] = /^(\d+)\.(\d+)\./.exec(String(version))?.slice(1).map(Number) ?? []; + const [major, minor] = + /^(\d+)\.(\d+)\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.exec(String(version))?.slice(1, 3).map(Number) ?? + []; return major === 0 && minor !== undefined && minor < 162; } diff --git a/test/messages.test.ts b/test/messages.test.ts index 1591d7b1..82394a3b 100644 --- a/test/messages.test.ts +++ b/test/messages.test.ts @@ -253,8 +253,26 @@ describe("readCodexMessages from Codex 0.146's TUI", () => { expect(readCodexMessages(path, SINCE, plain).map((m) => m.kind === "message" && m.text)).toEqual(["fix it"]); }); + test("reads a prerelease or build version before 0.162", () => { + for (const head of [meta("0.146.0-alpha.1"), meta("0.146.0+build.5")]) { + const path = join(tempDir(), "rollout.jsonl"); + writeFileSync(path, lines(head, bareTurn("2026-11-06T10:01:00Z", ["fix it"]))); + expect(readCodexMessages(path, SINCE, plain).map((m) => m.kind === "message" && m.text)).toEqual([ + "fix it", + ]); + } + }); + test("fails on a turn without provenance from a version that writes it, or one with no version", () => { - for (const head of [meta("0.162.1"), meta("0.167.0-alpha.6"), meta("1.0.0"), meta("unknown"), codexMeta({})]) { + for (const head of [ + meta("0.162.1"), + meta("0.167.0-alpha.6"), + meta("1.0.0"), + meta("unknown"), + meta("0.146.not-a-version"), + meta("0.146.0 "), + codexMeta({}), + ]) { const path = join(tempDir(), "rollout.jsonl"); writeFileSync(path, lines(head, bareTurn("2026-11-06T10:01:00Z", ["fix it"]))); expect(() => readCodexMessages(path, SINCE, plain)).toThrow(/provenance/);