Repository navigation
hooks: pre_compact and stop, told and never asked (#26 item 5, second slice) - #34
Merged
Merged
Conversation
#26 item 5, second slice. Two more events for the operator's hooks (admin.json `hooks`, and approved plugins): - pre_compact: run before /compact compacts the conversation. The event carries trigger (`manual`) and custom_instructions. What the commands print is shown with the compaction's result. - stop: run once a person's turn has ended, after any continuation the memory engine asked for. The event carries last_assistant_message. What the commands print joins the turn's notices. Neither can refuse anything: exit 2 is an ordinary exit for them. The three non-tool events now share one runner, hooks::run_event (the event as JSON on stdin with hook_event_name, session_id and cwd, bounded at 10 s), where only user_prompt_submit may refuse. Known limit, in the README: pre_compact runs when /compact is asked even on a route whose agent compacts its own conversation, where incode compacts nothing. Automatic compaction inside the API backend does not fire it yet (the agreed follow-up). Tests: the events carry their fields and exit 2 refuses nothing; a real turn with a stop hook shows its output among the notices, and none without one. Controls: with the stop firing removed, or exit 2 refusing for every event, the tests fail.
From a security review of 3d674a5. hooks_of dropped only a project plugin's user_prompt_submit, so the new stop and pre_compact commands of a cloned repository's (approved) plugin still ran, and every hook event added later would have too. A project's plugin now gives only pre_tool_use and post_tool_use, by allowlist; the rest are left out and traced. The operator's own plugins give every event. And what an approval is shown counted only the two tool lists: plugins::contents now uses HookConfig::count, over every event. Test: a project plugin's prompt, stop and pre_compact hooks are left out while the user plugin's are kept, and its summary counts all four. Control: with the allowlist replaced by the whole config, it fails.
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two more operator hook events (admin.json
hooksand approved plugins):pre_compact: before/compact; event hastrigger(manual) andcustom_instructions; output shown with the result.stop: when one of your turns has ended (after any memory-engine continuation); event haslast_assistant_message; output joins the turn's notices.Neither can refuse (exit 2 is ordinary for them). The non-tool events now share
hooks::run_event; onlyuser_prompt_submitmay refuse.Known limits (README):
pre_compactruns when/compactis asked even where the agent compacts its own conversation; automatic compaction in the API backend does not fire it yet (agreed follow-up).Tests: payload fields, exit 2 not refusing, and a real turn whose stop hook output shows in the notices. Controls (stop firing removed; exit 2 refusing everywhere) fail them.
Local (Windows): fmt clean; clippy only the existing
with_tool_serverwarning; bin 59 passed; lib 2199 passed, 1 failed: the desktop UIA live test that walks whatever window has focus here (passes in CI).Still to come: Notification, session start/end,
/reviewand/runprompt-hook coverage.