Repository navigation
hooks: user_prompt_submit, the operator's check on each line sent (#26 item 5, first event) - #32
Merged
Merged
Conversation
#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.
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.
First of the missing hook events from #26 item 5.
user_prompt_submitcommands in admin.jsonhooks(and plugins' hooks.json) run when a person's line is about to be sent.hook_event_name,prompt,session_id,cwd), 10 s bound, same runner as the tool hooks.plan_turn(REPL and--acp) and for-t(before the memory session opens)./reviewand/rundo not run it (documented).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_serverwarning; lib 2191 passed, bin 59 passed.Follow-ups (separate PRs): Stop, Notification, PreCompact (on
/compact; automatic compaction after), session start/end,/reviewand/runcoverage.