Skip to content

feat(hooks): SessionEnd lifecycle + PreCompact context injection - #172

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/hooks-sessionend-precompact
Open

feat(hooks): SessionEnd lifecycle + PreCompact context injection#172
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/hooks-sessionend-precompact

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary\n\nThis PR enhances the hooks subsystem with two lifecycle improvements:\n\n1. SessionEnd hook — a notification-only hook fired on every terminal turn path (complete / interrupted / error), so session summaries can be persisted even when history compaction never ran.\n2. PreCompact checkpoint reinjection — the PreCompact hook's additionalContexts are appended as a [PreCompact checkpoint] user message after compaction, so the checkpoint survives history compression and the model can recover context.\n3. Hooks config — accepts the deepcode-hooks MCP hooks_config.json list shape with camelCase event aliases.\n\n## Changes\n\n- core/events/session.py: add _run_end_hook invoked from the turn finally block (reason mapped from stop_reason)\n- core/agent_runtime/runner.py: capture PreCompact additional_contexts and reinject into compacted history\n- core/harness/hooks/events.py: register SessionEnd event, add to matcher-less set\n- core/harness/hooks/engine.py: add run_session_end; pass additional_contexts through run_pre_compact\n- core/harness/hooks/discovery.py: support deepcode-hooks MCP hooks_config.json list shape with camelCase aliases\n- core/harness/hooks/execution.py: register SessionEnd / PreCompact decoders\n\n## Notes\n\n- SessionEnd is notification-only: a hook failure is logged and never crashes a turn.\n- All 6 files pass py_compile; total diff +150/-12.

- SessionEnd: notification-only hook fired on every terminal path (complete / interrupted / error), so summaries can be persisted even when compaction never ran
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.

2 participants