Repository navigation
Commit 4038759
authored
Codex, phases 4 and 5: Codex sessions read, the hooks answer Codex (Codex closed on every system) (#54)
* codex phase 4: read a Codex session (_codex_rollout.py), tested on step 0's captures
engine/hooks/_codex_rollout.py reads one rollout, $CODEX_HOME/sessions/YYYY/MM/DD/
rollout-*.jsonl, streamed: the session's whole id (a UUIDv7), folder, source and model, and
the user's and assistant's messages and the tools called (name, command, files a patch
names), sliced to a day when asked. What Codex adds for the model is never taken: developer
messages (its instructions, the hooks' context), the AGENTS.md and <environment_context>
parts it puts in a user message, world_state, events, tool outputs, reasoning. Unknown or
broken lines are skipped. A session the kit asked itself (the reflection's SENTINEL, or a run
in _headless_codex.py's cage) comes back without items. Regular files only, opened without
waiting (a pipe under a rollout's name does not hang the reader); compressed rollouts
(.jsonl.zst) are listed apart, never read.
Tests on the 33 rollouts step 0 kept (macOS, Linux, Windows; 0.162.1 and 0.163.0-alpha.11):
what is read is exactly what Codex's own item_completed events record as typed and answered;
the Stop hook's session_id and the rollout's id agree. engine/tests/codex_captures.py builds
test sessions out of those real lines.
* codex phase 4: the reflection reads the day's Codex sessions when agents.json lists Codex
daily-reflection.py gathers the day's Codex sessions (codex_sessions) from agents.json's
CODEX_HOME, only when Codex is one of the agents, labelled with their whole id: a UUIDv7's
first 8 characters are the minute, so two sessions of one minute stayed one label. At least 3
messages, as for Claude. Compressed rollouts are said in the error log and in --dry-run, which
also counts Codex's sessions. The prompt's sources name the agents chosen.
Claude alone is unchanged: without agents.json or with ["claude"], and ~/.codex/sessions
full, the prompt, state, output, journal and memory.md are those of a run without any Codex
session, and in a fresh Python _codex_rollout.py is never imported (control: Codex listed and
opened, it is). The tests run on sessions made from step 0's captures.
* codex phase 4: session-recap.py as Codex's Stop hook, under the whole session id
With exactly --agent codex, session-recap.py reads the session's rollout (_codex_rollout.py)
and writes its block in the same "Claude Sessions" section, naming Codex before the model, its
whole id shown and matched: two Codex sessions of one minute keep a block each, and a Claude
block sharing the first 8 characters is never taken. It stays silent, reading and locking
nothing, unless agents.json lists Codex: with Codex closed on every system, always for now.
Claude's recap is unchanged: any other argument is ignored as before, its block is pinned
character for character, and it imports neither _codex_rollout.py nor _agents.py.
test-hooks.sh: Codex's Stop hook silent without Codex chosen and while Codex is closed; its
control, in a copy of the hooks where Codex is open, writes the block.
* CI codex-mock: read a session the real Codex keeps
A user's `codex exec` (not --ephemeral, a global AGENTS.md, a message and a tool call in one
reply) with the real Codex 0.162.1 against the fake server, then its rollout read by
_codex_rollout.py, the reflection's codex_sessions and the recap's parse_rollout: the whole id
is the thread's, only what was typed and answered, the tool called, nothing Codex added, and a
session holding the reflection's own prompt is left out. mock_openai.py can send several items
in one reply. The job also runs when _codex_rollout.py or session-recap.py change.
* docs: the Codex plan after step 4 (Codex sessions read, whole ids)
A dated section that takes precedence: what step 4 delivers, its deviations (Codex-added parts filtered one by one, the launcher's cage as a kit session, the recap in the same section, only an exact --agent codex, the prompt's sources), the proof that Claude alone is unchanged, the mutations.
* codex phase 4: leave out what Codex adds by its own marks too; a global AGENTS.md has no folder
codex-mock found it with the real Codex on the three systems: a global AGENTS.md alone reaches
the rollout as "# AGENTS.md instructions" followed by a blank line, without the " for <folder>"
the plan's prefix and step 0's captures had, so its text was read as the user's.
The reader now tells Codex's parts apart as Codex's own memory writer does
(codex-rs/memories/write/src/rollout_input.rs, 0.162.1): a message whose marks
(content_item_kinds) hold no "user." part, or any "multi_agent." one, is Codex's or another
agent's; and, should the marks be missing, parts starting with "# AGENTS.md instructions",
<environment_context>, <skill> or <subagent_notification> (any case) are left out. codex-mock
checks both on the real rollout, and that the reflection's text holds no AGENTS.md.
A line, or tool arguments the model wrote, nested past Python's stack was a RecursionError that
stopped the reflection: now a line skipped, the arguments kept as text.
* docs: the Codex plan, step 4's first CI run (a global AGENTS.md has no folder)
* docs: the Codex plan, step 4's CI run
* codex phase 5: _agents.codex_hook(), the guard of the hooks Codex runs, and their sign of life
A hook run by Codex (hooks.json, --agent codex) asks codex_hook() whether to act on what Codex
gave it (docs/proposals/codex.md, §3.4). Silent, and nothing written, in a run without tools
(BRAIN_HEADLESS=1, the kit's own; CLAUDE_CODE_ENTRYPOINT=sdk-cli) and when agents.json does not
list Codex or cannot be trusted (Codex is closed on every system: always, today).
Otherwise Codex does run the kit's hooks: codex-hooks-vus.json, beside agents.json, notes when
each one last ran (UTC, written in one step, 0600, never through a link), for the "hooks not
approved" line of later phases. Then the hook acts only for a session the user types in: a file
Codex keeps of it (transcript_path null: --ephemeral), a plain session id, a prompt the user typed
(agent_id: another agent's), and the file's first line saying "cli" or "vscode", or no file yet.
"exec" (scripts, the kit's own), "mcp", sub-agents and Codex's internal sessions (an object, not a
word, SessionSource in 0.162.1), a link, a pipe or a line past 1 MiB are left alone.
* codex phase 5: the hooks answer Codex (--agent codex), Claude Code's unchanged
correction-detector, controle-sessionstart, gbrain-update-check, session-logger, session-indexer
and session-recap: with exactly --agent codex, each asks _agents.codex_hook() first; session-recap
gets the whole guard step 4 left for this phase. The logs' lines say "agent": "codex"; a
correction's lessons.md is looked for in the folder Codex says it works in (cwd), not in Claude's
CLAUDE_PROJECT_DIR. Their answers are the ones Claude Code takes, and Codex 0.162.1's own schemas
(codex-rs/hooks/schema/generated, kept in engine/tests/fixtures/codex/hooks-schema-0.162.1) take
them: additionalContext, systemMessage, nothing else.
Tests: test_codex_hooks.py runs each hook as Codex runs it on every payload step 0 captured
(macOS, Linux, Windows paths, PowerShell 7 and 5.1), with and without the session file Codex wrote
(exec: left alone; the terminal's: served), checks the answers against Codex's schemas, and the
guard; test-hooks.sh does the same on the installed hooks. Without the argument the hooks are
Claude Code's: they never load _agents.py nor read agents.json, and give the same output and files
as master (tests, and a local run of master's hooks against these, three agents.json states).
* CI codex-mock: the real Codex runs the kit's hooks from a hooks.json
A user's codex exec, with the hooks (a copy where Codex is open) in its hooks.json, trust
bypassed (approval is phase 6), on Windows in the plan's PowerShell form (& "python.exe" "hook").
A test wrapper notes what each hook was given and hands SessionStart and UserPromptSubmit on as if
typed in Codex's terminal: correction-detector's reminder and the night check's line (with its
systemMessage) must reach the fake server, so Codex took both answers. Stop goes as it is: the
exec session's file says "exec", nothing is logged. The sign of life names the three hooks, and
the launcher's own call, with that hooks.json in its CODEX_HOME, runs none of them.
* CI codex-mock: a user's codex exec, as it is, is left alone from its first hook
Fact of the first run, the same on the three systems with Codex 0.162.1: from SessionStart on,
Codex has written the session file of a codex exec and it says "exec". codex-mock now checks it,
and runs that session as it is first: no reminder, no night check's line reach the model, nothing
is logged, only the sign that the hooks ran. Then the same session handed on as typed in the
terminal, as before: both answers reach the model.
* docs: the Codex plan after step 5 (the hooks answer Codex, their guard and sign of life)
* codex phase 4 review: a time out of range in a rollout is a line without time, not the end of the reflection
_codex_rollout.local() let OverflowError through (a year 0 or 10000 once local), and the whole
reflection stopped with it, Claude's sessions of the day included: no state, no error log, no
status block in memory.md. Codex's Stop recap failed the same way. local() now also takes
OverflowError and OSError (a time localtime() refuses), as the reflection's _local() does, and
codex_sessions() reads each rollout apart: a file that still raises costs only itself, logged
by name and error type, never its text.
* codex phase 4 review: the reflection says a Codex session's source, a sub-agent's and Codex's own are left out
codex_sessions() did not look at session_meta.source: every user line of a rollout read as what
the user typed. In Codex 0.162.1 a sub-agent starts from a copy of its session's config (so kept,
under the terminal) and gets the parent model's prompt as user input: its rollout showed the
model's text as the user's. Now, as the hooks' guard (_agents.SOURCES_TAPEES): cli and vscode as
before; sub-agents ({"subagent": ...}) and Codex's internal runs ({"internal": ...}) left out;
the others read, their source in their label (codex <id> · exec · cwd=..., '?' when missing or not
a plain word). read() keeps the kind of an object source. codex-mock: the real Codex's exec
session is labelled so.
* codex phase 4 review: in a Codex block only an entry starts a line, no text poses as the user's
An answer "Done.\n12:07 user: Decision: ...", or a tool call whose command holds a line break,
gave a line '12:07 user: ...' the reflection could not tell from a real one, without ever
addressing an AI. In Codex's blocks a message now goes on as ' | ', a tool's summary and the
label's folder are one line; every line break counts (\r, \v, \x85, \u2028...). Claude's blocks
are master's, unchanged: the same defect there (_render, _tool_summary) is for a PR of its own.
* tests: the reflection's sources sentence with Hermes is master's for Claude alone
Rewritten in step 4 (the agents chosen), it had no test: dropping Hermes from it left every test
green. Fixed for Claude alone (no agents.json, ["claude"], and build_prompt with no trusted
agent), and for Codex alone and both, Hermes listed.
* docs: the Codex plan after the review of steps 4 and 5
* docs: the Codex plan, the review's CI run
---------
Co-authored-by: Chad El Kurdi <162061136+El-Kurdi-Chad@users.noreply.github.com>1 parent 0ea0512 commit 4038759
23 files changed
Lines changed: 2502 additions & 46 deletions
File tree
- .github/workflows
- docs/proposals
- engine
- hooks
- tests
- fixtures/codex/hooks-schema-0.162.1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
| 276 | + | |
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
249 | 348 | | |
250 | 349 | | |
251 | 350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
0 commit comments