Skip to content

hooks: pre_compact and stop, told and never asked (#26 item 5, second slice) - #34

Merged
blockmandev merged 2 commits into
mainfrom
feat/hook-events-2
Oct 22, 2026
Merged

blockmandev merged 2 commits into
mainfrom
feat/hook-events-2

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Two more operator hook events (admin.json hooks and approved plugins):

  • pre_compact: before /compact; event has trigger (manual) and custom_instructions; output shown with the result.
  • stop: when one of your turns has ended (after any memory-engine continuation); event has last_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; only user_prompt_submit may refuse.

Known limits (README): pre_compact runs when /compact is 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_server warning; 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, /review and /run prompt-hook coverage.

#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.
@blockmandev
blockmandev merged commit 9e527fe into main Oct 22, 2026
7 checks passed
@blockmandev
blockmandev deleted the feat/hook-events-2 branch November 15, 2026 20:29
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