Repository navigation
feat(hooks): limit a Hooks-page hook to one bot or one folder - #47124
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The scope narrows only hooks a person opts into, unscoped hooks behave as before, and one predicate decides it on every event path. Notes
[DESIGN-REVIEWED] fb6c7df Description read[DESCRIPTION-READ] 4bf6da16eb1778afe5a99975c341f3480d49e494ad6eb7e6d8182de99d582718 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: the scope fields are optional, an unscoped hook runs as before, and each scoped path has a consumer. One new private helper re-implements an existing slot lookup. Notes
What this change shipsInventory (10 items) — 9 justifiedIntent: let a person limit a Hooks-page hook to one bot's chats and tasks, or to one folder, so a narrow guard stops firing in every chat. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] fb6c7df Description read[DESCRIPTION-READ] 10111077b9d5095971aa6a09ff8d41c24ef6942e86cc5aa101e9f17ed84175fc That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)UX-level review of UX-Verdict: PASS cannot evaluate: missing the hook form's new "Runs in" picker and folder field. Those two controls are how a person limits a hook to one bot or one folder, which is what this PR is for, and no screenshot shows them. Evidence gaps
Notes
[UX-REVIEWED] fb6c7df Description read[DESCRIPTION-READ] 3b06112aaa8dbd163b5b58a140c8d584373273b101147650e3e51a6108bbd10e That sha256 names everything this verdict read: the PR description, plus the 7 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The change limits where Hooks-page hooks fire, by session bot or folder. It does not touch the tool-call deny composite ( TIGHTENING: A Hooks-page hook with a scope now runs only for sessions in that scope, and KAS execution of such a hook is refused outside it -- the threat is a hook meant for one bot or folder running (or blocking work) in some other chat: ADJUDICATED: 15 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix, windows and any. The diff assumes things about paths:
These rows are commands that scoped hooks and their maintainers actually run, used as controls on the deny composite. They cannot check the path comparison inside UNADJUDICATED:
[SCOPE-REVIEWED] fb6c7df |
166196a to
0f5c3df
Compare
94a5e58 to
c621f40
Compare
c621f40 to
3ec500c
Compare
3ec500c to
cc0429c
Compare
|
Review dispositions for GPT F1 / named delegates lose their bot's scope — fixed. Class: every path that names the bot a call belongs to goes through GPT F3 / channel-linked slots have no project — fixed. The resolver the dashboard installs ( GPT F2 / Opus — PostToolUse folder scope sees no call paths — narrowed and documented. A call's paths and |
cc0429c to
8889aa3
Compare
|
Review dispositions for Opus — folder scope misses a batched tool's nested paths — fixed. Frontend Tests (2) — UX — "screenshots show an older build". The description now carries screenshots captured from this branch: the open picker with and without a folder typed, the table with "Bot and its tasks or /home/…", "Removed bot", a folder and "All chats", the cell wrapping after |
8889aa3 to
11a618a
Compare
|
Review dispositions for GPT F1 — folder scope misses Lint Gate / Coverage Gate were held by the AI review BLOCK on the previous head; they run again on this one. |
11a618a to
91ab7cd
Compare
|
Disposition for the review round on 7f0f60b. Fixed in 1f4485c.
|
1f4485c to
bba9153
Compare
|
Disposition for head bba9153 (rebased on main, no conflicts). GPT: a task can find another run's chat instead of its own ( The cases where a scoped hook still cannot find the chat that started a task are listed in the PR body under Known limits: where a task cannot find the chat that started it. In each of them a bot- or folder-scoped hook does not run, and unscoped hooks are not affected. Further findings of this class are handled against that list rather than with another lookup path. UX: the Runs in text.
|
Sensitive change review
|
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on bba91530a1. The scope design reads right in src/kiro_crew/hook_scope.py: the bot and project come from the session Kiro Crew runs the call under, never from the hook's script or the tool call's arguments; an unreadable scope loads as UNREADABLE_SCOPE and matches nothing; a deleted bot matches nothing; and a scope only ever narrows an unscoped hook. The known-limits list is clear about where a scoped hook does not run, and the test matrix covers every event path against every caller kind.
The real-machine section is what holds this back, on three points (real-machine-verify, "Reviewing"):
- The hooks never ran their own logic. Every row exited 1 because the box's interpreter could not load inside the hook sandbox, and a hook that cannot start blocks. So the run shows which hooks were picked, but not that a scoped hook which does start still denies, or that an out-of-scope one lets the call through. Please run it with a hook command that starts in the sandbox (for example a
/bin/shone-liner that prints and exits 2), and show one denied call and one allowed call. - The After run is on
166196aaf8f, not the head. Please re-run on the current head, or name what changed since and which test pins it. - Cleanup is still open. "The box is deleted once the stacked card PR is verified" means it still exists. Please delete it and paste the empty listing, or say where it is and when it goes.
A live agent turn would be best (a bot's task stopped by its bot-scoped guard, and another chat not stopped). If the model sign-in is still missing, a pod run through the real PreToolUse path is enough, and please say which one you used.
Non-blocking question: _member_id_for loads KiroCrewConfig on each lookup. Is scope_of cached per session, or does every PreToolUse pay for a config load once a scoped hook exists?
|
@bolichen97 thanks. All three points are fixed in the description; the head is unchanged (
Your question: no, |
A hook can now carry scope_bot (a bot's id) and scope_folder (an absolute folder). A bot-scoped hook fires only in that bot's own chat, the tasks it starts and their sub-agents; a folder-scoped hook fires in a chat whose project is under the folder. Either match fires; no scope keeps today's every-chat behaviour. The scope is one decision per session, hook_scope.scope_of: the session's bot and its chat's project. A sub-agent takes the project of the chat it was started from, a task step the scope of its starting chat. A tool call's arguments are never read, so a folder hook does not fire when a chat whose project is elsewhere touches that folder; to guard a folder from every chat, use All chats and test the path in the command. A caller it cannot name is a logged miss, never a fire. Every path that picks stored hooks reads the same decision: the store's fire, the lane dispatch, the KAS hooks list and execute, the KAS auto-approval matchers, the Stop-presence check and /hooks. The Hooks tab gets a Runs in picker and folder field, and each scoped row names its bot and folder; with both set, the picker's shown value joins them with "or".
A run named <id>:chat:... took the older run's folder and bot, because _run_of_key matched the first run whose :chat: prefix fit, in table order. Match every run's own keys first, then the longest-id :chat: prefix.
The phone Hooks page is now a list (#47747), so the scope line that sat under the name in the phone table moves into HooksPhoneList, with the deleted-bot line as the control that opens the editor and the switch described by it. The Bots roster notice is a partial failure, and the page's newer tests mock the roster.
|
@bolichen97 the head moved to
Your earlier three points stand as answered above. |
Sensitive change review
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 15% limit for approving on its own. I recommend approving. The PR adds two optional fields to a Hooks-page hook,
Unscoped hooks behave exactly as before. The new fields round-trip through Tier: 2, held for a person: changes requested. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 15% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed on fb6c7df0b9. All three real-machine points from my change request are now covered (real-machine-verify, "Reviewing"):
- The guards are
/bin/shone-liners that start inside the hook sandbox, so each deny is the guard's own verdict. On main9b73736edfboth guards stop every caller. On the branch each guard denies its own caller and lets the out-of-scope call through, for the bot scope and the folder scope. - The run is on
bba91530a1. Since then the branch was only rebased:7af1efa591is the same backend commit, andfb6c7df0b9touches onlyHooksPage.tsxand its tests, pinned byHooksPage.scope.test.tsx(desktop column and the new phone case). - The box was deleted at 14:47:59Z, and the label-filtered listing is empty.
The Captain's line on this head is verdict=human final=yes, and all checks are green. Approving, with auto merge on.
AI-assisted, sent by Bolin Review bot
Problem / Motivation
Goal: A person can limit a Hooks-page hook to one bot (its chat and the tasks it starts) or to one folder, so a guard meant for one bot or one repository does not fire in every chat.
Every Hooks-page hook fires in every chat today. A person who wants a deny rule for one bot's own tasks, or for any chat that touches one repository, has no way to say so: the hook either stops every chat, or its script has to work out who is calling from fields an agent can set.
Why it matters
Hooks are the one rule a model cannot skip, but a hook that fires everywhere is too blunt to write for one bot's habits or one repository. People end up writing no hook, or a script that guesses its caller.
Not a goal
What changed (motivation → approach → change)
scope_bot(the bot's id, which a rename keeps) andscope_folder(an absolute folder, stored resolved). A hook fires when any scope it names matches; with neither, it fires everywhere as before. The scope is one decision per session,hook_scope.scope_of(key) -> (bot, project), read through one predicate,in_scope, by every path that picks stored hooks:ScriptHookStore.fire(every event), the lane dispatch, the KAS hooks list and execute, the KAS auto-approval matchers (so a bot's hook does not take auto-approval away from other chats), the Stop-presence check and/hooks. The key is the call's own session (scope_key); a sub-agent takes the project of the chat it was started from, a task step the scope of its starting chat.Project.origin_project, fromrun_inputs.start_folderinstart_background,planand the new-from-steps route) and persists it besideorigin_session_key, so a later project change, a closed chat or a restart does not move it. A task started from a task step copies its parent's folder; a start with no chat keeps the folder the person picked, or none. A session key finds its run by whole-key equality with the keys a run id makes, checked across every run first; only when no run owns the key exactly does the longest run id whose chat-tab prefix it carries win, so a run named after another run's chat tab still finds its own run; a plan still being decomposed is found throughTaskRunner._planning_runs. A chat reads its live slot only.membersRosterQuery, matched by member id with the Schedule page'screwmateForJobrule);GET /api/hooksreturns onlyhooks. Until the roster has loaded, a scoped row names its bot by id and none reads as deleted.scope_eitherstring the table cell uses); on a phone the line wraps instead of being cut. A hook whose bot was deleted fires nowhere, and its row says "Its bot was deleted, so this hook doesn't run. Choose another bot or folder." (on a phone, in a full-width line under the row), and the picker lists it as "Deleted bot".Known limits: where a task cannot find the chat that started it
Read from the code at bba9153. In each case below, a bot- or folder-scoped hook does not run for that work, and nothing reports it. Unscoped hooks are not affected.
wf:,wf-pool:,wf-worker:keys). These are not task runs, so they have no folder. They run bot hooks only when the session's own record names the bot. The person sees folder hooks never stop a call in a workflow./tasksent from a Slack code channel. The channel is not a dashboard slot, so the task has no folder. Only bot hooks can run.state.jsonare both gone. No chat is found, so no scoped hook runs.Backwards compatibility
Compatible: a hook with no scope fields loads and fires exactly as before; the two new fields are optional on create and update, and an edit that leaves them out keeps them.
Removes nothing: no field, route or behaviour is taken away; an unscoped hook is unchanged on every path.
Tests
test/test_hook_scope.py: one matrix asks every event path (PreToolUse, PostToolUse, UserPromptSubmit, Stop presence, SessionLaneChanged, KAS list, execute and withhold,/hooks) about every caller kind (bot chat, worker, delegate, sub-agent, nested and continued sub-agent, task step, channel-linked chat, cron, another bot's worker, plain chat, unknown) for an unscoped, bot, folder, other-bot and bot-or-folder hook. Also: an unnamed caller or an unreadable config is a logged miss; a deleted bot matches nothing; a sibling folder with the same prefix is outside; a scope only ever narrows; the store round-trips and keeps scope on edit; an ACP client's PostToolUse names the same session as its PreToolUse.test/test_hook_scope_task_folder.py: one test per case of a task's folder (start from a chat, background and plan, the placeholderrun()replaces; project changed; project cleared; restart; chat closed; task from a task; sub-agent of a step, live and evicted; cron and Projects-page starts; ids with:or a leadingrun:; a plain chat). Each was seen to fail when its rule was removed.website/src/test/HooksPage.scope.test.tsx: the Runs in cell for a bot and folder, a removed bot, and all chats; no row reads as deleted before the Bots roster loads; the form sends the folder typed./hooksfilter or the KAS execute re-check each turns matrix cases red.Proof: not provable -- other: feature PR, the base has no scope fields for the tests to exercise
Manual verification
Frames below are from head
fb6c7df0b9, after the rebase onto main with #47747. New UI copy, awaiting the owner's sign-off: Runs in · All chats · Chats working in {folder} (the empty choice once a folder is typed) · {bot} and its tasks or {folder} · Folder (optional) · Its bot was deleted, so this hook doesn't run. Choose another bot or folder. (decided by the Bot on the owner's hand-over, 12-04); accessible names Bot and Folder.Real-machine verification
Machine: the same throwaway cloud dev box as before (label
hcscope-c2833), Amazon Linux 2023, x86_64, with a scratch data home holding one bot,mate. Each side was installed from agit archiveof its commit into a fresh venv on a standalone CPython 3.12.16.Path: the gateway's own PreToolUse gate,
hook_runtime.hook_dispatch.permission_pre_tool_block(the gate task, sub-agent and channel calls go through), with its real sandboxed hook runner. This is an in-process run, not a live agent turn: the box has no model sign-in. The gateway registers the slot table as the scope's project resolver at startup; the script registers the two chats' folders the same way. The bot's task is recorded with the real record writer (note_crewmate_worker_session).Hooks: two PreToolUse guards on
execute_bash, each a/bin/shone-liner,printf '<name>: stopped this call\n' >&2; exit 2. It starts inside the hook sandbox, so a deny is the guard's own verdict.bot-guardis scoped to botmate;folder-guardis scoped toguarded-repo. Script:proof2.py, the same file on both sides.Before (main
9b73736edf, this PR's base):python proof2.py->After (head
bba91530a1): same command ->On main a scope does not exist, so both guards stop every caller. On the head each guard still starts and denies its own caller, and lets an out-of-scope caller's call through.
Since this run (head
bba91530a1), the branch was rebased onto main after #47747 merged, which made the Hooks page a stacked list on a phone. Only the Hooks page changed:HooksPage.tsxcarries the Runs in column, the deleted-bot line and the picker onto main's version, and the scope line that sat under the name in the phone table moved intoHooksPhoneList.tsx. No backend file changed, so the run above stands for the gate. Pinned bywebsite/src/test/HooksPage.scope.test.tsx(the desktop Runs in column, and a new phone case: the scope line under each name, wrapped and never cut, and a deleted bot's line describing its switch) and by the Hooks page suites (113 tests).Cleanup: the box was deleted at 2026-12-05T14:47:59Z. The provider's listing filtered to its label, at 14:48:31Z:
Screenshots / video
From head
fb6c7df0b9: this branch's Hooks page with a fake hook list and a one-bot roster (Release Helper). One hook names a deleted bot: its row is dimmed and left out of ENABLED (4 of 5), and its sentence is a dotted-underline button that opens the editor on the Runs in picker. A bot plus a folder reads "{bot} and its tasks, and chats working in {folder}". On a phone the page is #47747's list, with the scope line under each hook's name.More
Related Issues
Related: #46782 (lessons checked at the tool call).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.