Skip to content

fix: PreCompact hook degradation, model:inherit passthrough, AGENTS.md hook section formatting - #9

Merged
Disdjj merged 1 commit into
mainfrom
fix/hook-precompat-model-inherit
Aug 24, 2026
Merged

fix: PreCompact hook degradation, model:inherit passthrough, AGENTS.md hook section formatting#9
Disdjj merged 1 commit into
mainfrom
fix/hook-precompat-model-inherit

Conversation

@Disdjj

@Disdjj Disdjj commented Aug 24, 2026

Copy link
Copy Markdown
Member

Three conversion gaps found while converting the llmdoc V3 plugin surface to Codex (context: TokenRollAI/llmdoc#32).

1. PreCompact hooks were dropped entirely

PORTABLE_EVENTS didn't include PreCompact, so it was skipped with a warning — even for codex/opencode where hooks already degrade to AGENTS.md notes anyway. For llmdoc this silently discarded the compact-continuation hook.

Now PreCompact degrades like SessionStart/Stop. Degraded notes also use event-appropriate timing phrases: Right before context compaction, run: … instead of the semantically wrong Run after PreCompact: …. Cursor still warns (no preCompact in its event map) — unchanged.

2. model: inherit was hardcoded to a mapped model name

inherit (and an absent model) went through mapModel and came out as e.g. model = "gpt-5.6-sol" — freezing today's default into the generated agent, which rots as platform defaults move. All four platform branches now omit the model field for inherit/absent, letting the target platform apply its own session default. (effort/sandbox_mode mapping unchanged.)

3. Fresh AGENTS.md opened with a stray ---

When no AGENTS.md existed, the hook section was pushed as ---\n\n# Hooks….trim(), so the file started with --- — which renders as a frontmatter fence / dangling rule. The separator is now only inserted when appending to an existing AGENTS.md (with trimEnd before it).

Verification

  • vitest: 90 passed (3 new tests: PreCompact degradation, timing phrases, inherit omission across all 4 platforms)
  • End-to-end against the llmdoc plugin surface: all three hooks now present in AGENTS.md with correct phrasing and no leading ---; both agent TOMLs have no model = line.

Remaining (out of scope here, tracked in TokenRollAI/llmdoc#32): wiring codex hooks natively instead of AGENTS.md prose, if/when Codex exposes a stable hook config.

…erit, clean AGENTS.md hook section

Found while converting the llmdoc plugin surface:

- PreCompact hooks were dropped entirely with a skip warning; for platforms
  where hooks already degrade to AGENTS.md notes (codex/opencode) there is
  no reason to treat PreCompact worse than SessionStart/Stop. Degraded
  notes now also use event-appropriate timing phrases ('Right before
  context compaction, run …' instead of the semantically wrong 'Run after
  PreCompact').
- 'model: inherit' (and an absent model) was hardcoded to a mapped model
  name (e.g. gpt-5.6-sol), freezing today's default into the output. All
  four platform branches now omit the model field so the target platform's
  own session default applies.
- A freshly created AGENTS.md opened with a stray '---' (reads as a
  frontmatter fence); the hook section is now assembled without a leading
  separator, and appending to an existing AGENTS.md trims before adding
  the thematic break.
@Disdjj

Disdjj commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

Pushed a follow-up that supersedes the codex half of the original approach: Codex plugins support native hooks — default file hooks/hooks.json at the plugin root, Claude-compatible schema (same events incl. SessionStart/Stop/PreCompact/SubagentStart, matchers, type:command, additionalContextLimit). Sources: plugins guide ("The default plugin hook file is hooks/hooks.json … you don't need a hooks entry in .codex-plugin/plugin.json") and the hooks reference.

So for codex, convertHooks now passes hooks through losslessly to hooks/hooks.json (unknown fields survive; Codex itself skips non-command handler types) and emits a warning that plugin hooks are non-managed and need /hooks trust review. The AGENTS.md prose degradation stays for opencode only — where the PreCompact inclusion and timing-phrase fixes from the first commit still apply.

End-to-end on the llmdoc surface: all three hook events land in hooks/hooks.json with additionalContextLimit intact, no AGENTS.md fallback file. 92 tests pass.

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