Skip to content

feat(codex): SubagentStart + Pre/PostCompact context surfaces (hook parity)#14

Merged
VDP89 merged 1 commit into
mainfrom
feat/codex-context-hooks
Jun 5, 2026
Merged

feat(codex): SubagentStart + Pre/PostCompact context surfaces (hook parity)#14
VDP89 merged 1 commit into
mainfrom
feat/codex-context-hooks

Conversation

@VDP89

@VDP89 VDP89 commented Jun 5, 2026

Copy link
Copy Markdown
Owner

What

Final increment of the Codex hook deepening: the three context-injection surfaces — SubagentStart, PreCompact, PostCompact. With these, fscar init --adapter codex registers every documented Codex hook (the three blocking surfaces — PreToolUse, PermissionRequest, SubagentStop — plus these three context surfaces).

Schema-driven (the lesson from #13)

None of these has a decision in its output schema, so they are context-only — a scar cannot block them. I fetched each generated output schema and matched the emit path exactly:

  • SubagentStartsubagent-start.command.output.schema.json: additionalProperties:false, allows hookSpecificOutput.{hookEventName, additionalContext} + systemMessage, no decision. → inject via hookSpecificOutput.additionalContext.
  • PreCompact / PostCompact — allow only continue / stopReason / suppressOutput / systemMessage; no hookSpecificOutput, no additionalContext, no decision. → context via top-level systemMessage only.

A block=True on any of these never leaks a decision/hookSpecificOutput it isn't allowed (covered by tests).

How

  • payload: add HookEventType.SUBAGENT_START / PRE_COMPACT / POST_COMPACT.
  • codex adapter: map each (+ lowercase aliases), add to WANTED_EVENTS (install/doctor/manifest follow), dedicated emit_output branches per schema.
  • run_hook: these join PermissionRequest in _EXIT_ZERO_EVENTS (exit 0 — no exit-2 decision path).
  • docs/codex_integration_plan + README + CHANGELOG.

Verification

  • Each emit shape unit-tested against its schema (SubagentStart context + no-decision; PreCompact systemMessage-only; PostCompact block does not leak decision/hookSpecificOutput).
  • Gate: 193 passed (+3), ruff check fscars cookbook tests clean, mypy fscars strict clean.

Review focus

  1. Confirm the three emit shapes match the generated output schemas (esp. SubagentStart allowing hookSpecificOutput.additionalContext while compaction forbids hookSpecificOutput entirely).
  2. Confirm context surfaces correctly cannot block (no decision ever emitted) and run_hook returning exit 0 for them is right.
  3. Anything the 193-test suite + mypy strict would miss.

Intended to be cut as v0.8.0 together with SubagentStop (#13, already on main) = complete Codex native hook coverage. Version not bumped in this PR.

🤖 Generated with Claude Code

Completes native Codex hook parity. fscar init --adapter codex now registers
all documented events. These three are context-injection surfaces (no decision
in their output schemas, so a scar cannot block them); each emit path matches
the surface's generated schema exactly:

- SubagentStart: hookSpecificOutput.additionalContext + systemMessage (no decision).
- PreCompact/PostCompact: top-level systemMessage only (no hookSpecificOutput,
  no additionalContext, no decision).

run_hook returns exit 0 for all three (no exit-2 decision path), grouped with
PermissionRequest in _EXIT_ZERO_EVENTS. Adds HookEventType.SUBAGENT_START /
PRE_COMPACT / POST_COMPACT + mappings + WANTED_EVENTS. Output shapes verified
against the generated schemas (subagent-start / pre-compact / post-compact
.command.output.schema.json). Docs + CHANGELOG.

Gate: 193 passed, ruff clean, mypy strict clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ef7e3755e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +250 to +257
if event_type in (HookEventType.PRE_COMPACT, HookEventType.POST_COMPACT):
# Strictest schema: only continue/stopReason/suppressOutput/
# systemMessage — NO hookSpecificOutput, NO additionalContext, NO
# decision. systemMessage is the only context channel; a scar here
# cannot block. See pre-compact/post-compact output schemas.
message = output.system_message or output.additional_context
return (
json.dumps({"systemMessage": message}, ensure_ascii=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve compaction blocks with continue:false

For PreCompact/PostCompact scars that set block=True (for example, a project scar that wants to stop an auto-compaction until state is saved), this branch drops the block entirely and only emits systemMessage, so Codex proceeds. The Codex hook docs' common output fields include continue, and the PreCompact/PostCompact sections state that returning continue: false stops before/after compaction, so blocking compaction scars need to emit that schema-supported field (with stopReason) rather than being treated as context-only.

Useful? React with 👍 / 👎.

@VDP89
VDP89 merged commit db1cece into main Jun 5, 2026
9 checks passed
@VDP89
VDP89 deleted the feat/codex-context-hooks branch June 5, 2026 14:45
VDP89 added a commit that referenced this pull request Jun 5, 2026
fscar init --adapter codex now registers every documented Codex hook event:
the three blocking surfaces (PreToolUse, PermissionRequest, SubagentStop) plus
the three context surfaces (SubagentStart, PreCompact, PostCompact), each
matched to its generated output schema. Bundles PRs #13 + #14.

Co-Authored-By: Claude Opus 4.8 (1M context) <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.

1 participant