Skip to content

hooks: user_prompt_submit, the operator's check on each line sent (#26 item 5, first event) - #32

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

blockmandev merged 2 commits into
mainfrom
feat/hook-events

Conversation

@blockmandev

Copy link
Copy Markdown
Member

First of the missing hook events from #26 item 5. user_prompt_submit commands in admin.json hooks (and plugins' hooks.json) run when a person's line is about to be sent.

  • JSON on stdin (hook_event_name, prompt, session_id, cwd), 10 s bound, same runner as the tool hooks.
  • Exit 2 refuses the line: reason shown, nothing sent — not to the agent, not to the memory engine.
  • Otherwise stdout is added to the turn's context. The line is never changed.
  • Runs in plan_turn (REPL and --acp) and for -t (before the memory session opens). /review and /run do not run it (documented).
  • Plugin hook merging now uses HookConfig::extend, so a plugin's new event is not dropped.

Tests run real commands: a refused line never reaches the fake memory engine, an allowed one does with the hook's output as context. Controls: ignoring the refusal, or not treating exit 2 as refusing, fails them.

Local (Windows): fmt clean; clippy only the existing with_tool_server warning; lib 2191 passed, bin 59 passed.

Follow-ups (separate PRs): Stop, Notification, PreCompact (on /compact; automatic compaction after), session start/end, /review and /run coverage.

#26)

#26 item 5, first event. The operator's hooks (admin.json `hooks`, and
plugins' hooks.json) ran only around tool calls. `user_prompt_submit`
commands now run when a person's line is about to go to the agent:

- the event is JSON on stdin: hook_event_name UserPromptSubmit, prompt,
  session_id, cwd; bounded at 10 s, through the same runner as the tool
  hooks;
- exit 2 refuses the line, with stderr (else stdout) as the reason:
  nothing is sent, and the memory engine does not hear it either; the
  commands after it are not run;
- otherwise each command's stdout is added to that turn's context, as an
  <operator-hook event="UserPromptSubmit"> block;
- the line itself is never changed.

Where: cli::plan_turn, which the REPL and --acp both use, before the
memory engine is told (TurnPlan::Refused, shown in both); and task_run
for -t, before the memory session opens, so a refused run leaves none
half-open. A greeting answered locally runs no agent and no hook.
/review and /run do not run it; the README says so. The other events
(Stop, Notification, PreCompact, session start/end) are separate changes.

plugins::session_hooks and HookRunner::from_settings merged the plugin
hooks field by field; both now use HookConfig::extend, so a plugin's
user_prompt_submit is not dropped and the next event needs no edit there.
run_shell_command takes the environment and folder rather than a tool
call, so both kinds of hook share it.

Tests: exit 2 refuses with the reason and later commands do not run;
stdout becomes context and the event carries the prompt and session;
tool and prompt lists are separate events; through plan_turn with real
commands, a refused line never reaches the fake memory engine and an
allowed one does, with the hook's output in the context. Controls: with
plan_turn ignoring the refusal, or exit 2 not treated as refusing, the
refusal tests fail.
…se its block

From a security review of d0c5c64.

- plugins::session_hooks merged every plugin's hooks, project-scope ones
  included: <repo>/.incode/plugins/*/hooks.json arrives with whatever
  was cloned, and user_prompt_submit runs on the first line typed, before
  any tool. A project plugin's user_prompt_submit is now dropped (and
  traced); the event is taken from admin.json and the operator's own
  plugins only. The merge moved into hooks_of so it can be tested with
  the plugins given.

- A hook's stdout went into an <operator-hook> block as it was, so output
  holding `</operator-hook>` could end the block and write outside it.
  hooks::prompt_context_block wraps it for both the session and -t, with
  every `</operator-hook` (any letter case) written `< /operator-hook`.

Not changed here: a project plugin's pre_tool_use / post_tool_use
commands were already run before this branch, with no approval step.
That needs a trust decision of its own and is raised separately.

Tests: a project plugin's prompt hook is dropped while a user plugin's
is kept and both tool hooks merge; output with closing tags leaves one
close. Controls: without the scope check, or without breaking up the
tag, each test fails.
@blockmandev
blockmandev merged commit 8ffe4c9 into main Oct 22, 2026
7 checks passed
@blockmandev
blockmandev deleted the feat/hook-events 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