Repository navigation
Conversation
A subagent or task-runner permission request hands its PreToolUse hooks the event's rendered tool_input. For an edit call that rendering is a unified diff for the approval row, not JSON, so the hook's stdin carried no tool_input at all and a guard keyed on the edit's path refused every edit. When the rendering is not a JSON object, the gate now passes the call's structured params (AcpEvent.raw_tool_params), credential-redacted like the rendering they replace. A JSON rendering is used as before.
|
This PR and #32830 make the same fix. Each one builds a PreToolUse hook's Please keep one of #32219 and #32830 and close the other, carrying over anything only this one has, for example the |
…tool-input # Conflicts: # src/kiro_crew/hooks.py # test/test_hooks_composition_contract.py
…tool-input # Conflicts: # test/test_hooks_composition_contract.py
Code change approver recommendation: ApproveWhy: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. This fixes a PreToolUse spec hook getting no tool_input for an edit call. The edit's tool_input is the diff shown in the approval row, so it fails JSON parsing. Now, when that string isn't a JSON object, the gate falls back to the call's structured params (raw_tool_params), with every key and string value credential-redacted. The subagent and task-runner paths both reach the gate through SpecHooks.refuse, and both forward the new keyword with *a, **kw. The events on these paths are AcpEvents, which always have raw_tool_params. The hooks can only deny, and the params come from the same sources as the existing rendering (tool-call cache, then the frame's inline copy), so no trust boundary is weakened. The redaction matches the rendering's. The new tests fail without the change, and the pinned call-argument tests cover the SpecHooks wiring. CI ran no test, lint or build jobs because the fork's workflows were awaiting maintainer approval; the only failing check (Sensitive Change Review) failed for a missing reasoning template. The author reports 805 local tests passing. 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 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
Stale-PR cleanup note: this PR and #32830 fix the same seam (a PreToolUse hook's |
Problem / Motivation
Goal: A subagent's or task-runner run's PreToolUse spec hook gets an edit call's arguments as
tool_input, so a hook that checks the edit's file path can allow it.On
kas, every file edit by a delegated agent whose spec has a PreToolUse hook reaches the hook with notool_inputkey at all. A guard that checks the edit'spathcannot see one, so it refuses every edit. The model is told "The user rejected this tool call." Shell calls on the same path are unaffected.Observed on 0.12.0 with a crew agent spec carrying
preToolUse: [{matcher: "*", command: "python3 -I guard.py --role test-writer"}]. The hook's own stderr from astr_replaceon a test file:security_events.jsonlrecords it asoutcome: denied, error: hook_deny, reason: spec_hook.Why it matters
A spec hook that guards writes by path is the normal way to scope a delegated agent ("the test-writer may only write tests"). With this bug, every such agent on
kascan run shell commands but cannot edit a single file, and the refusal it reports misleads both the model and the user.Not a goal
dashboard/chat_turn/permission_prompt.py,tool_approval.py). It parsesevent.tool_inputthe same way and likely has the same gap for edits; it is left for a follow-up so this PR stays on the reported path.What changed (motivation → approach → change)
tool_inputfor an edit call.SpecHooks.refuse(tool_permission.py) handspermission_pre_tool_blockthe event'stool_input, which is the call's rendering for the approval row. For an edit call,session_update_parser.pyreplaces that rendering with a unified diff (input_str = diff_str, since fix(chat): show a diff on kiro-cli v3 replace edit rows #26589).permission_pre_tool_blockthen doesjson.loadson the diff, the parse fails silently,tool_inputstaysNone, andscript_hooks.fireleaves the key out of the payload.pre_tool_hook_input(event_tool_input, event_tool_params)inhook_runtime/hook_dispatch.py. A rendering that parses as a JSON object is used as before. Otherwise the call's structured params (AcpEvent.raw_tool_params) are used, with every string key and leaf credential-redacted (security.redact), matching the redaction the rendering already had.permission_pre_tool_blocktakes a keyword-onlyevent_tool_params=Noneand uses the helper.SpecHooks.refusepassesevent.raw_tool_params.kiro_crew.hooksfacade re-exports the helper.Backwards compatibility
Compatible:
event_tool_paramsis a new keyword-only argument defaulting toNone, and with it absent or with a JSON-object rendering the hook gets exactly what it got before.Removes nothing: the change only adds a
tool_inputwhere the payload previously had none.Tests
test_the_gate_gives_an_edit_hook_the_calls_params_not_its_diff: a diff rendering plus params gives the hook the params.test_the_gate_keeps_a_json_rendering_over_the_params: a JSON rendering still wins.test_the_gate_redacts_the_params_it_falls_back_to: a credential in the params is redacted, and the path stays readable.test_the_gate_with_neither_json_nor_params_sends_no_tool_input: unchanged behaviour when nothing is readable.test_tool_permission.py: the two pinnedpre_toolcall-arg tests now expectevent_tool_params.test_hooks_composition_contract.py:_BASE_SHAPE_DIGESTre-pinned for the new keyword, with a comment line like the earlier re-pins.Proof: PROVEN
test_the_gate_gives_an_edit_hook_the_calls_params_not_its_diff,test_the_gate_redacts_the_params_it_falls_back_to(both fail withKeyError: 'tool_input'when the gate ignores the params; the other two pass either way, as guards). Done by hand with the params fallback disabled, not with prove.py.Ran locally:
test_kas_spec_hook_gaps.py,test_kas_spec_hook_gaps_win_retry.py,test_tool_permission.py,test_hooks_composition_contract.py,test_crew_fired_spec_hooks.py,test_taskrunner_deny_notice.py,test_run_bindings.py,test_mirror_spec_hooks.py,test_script_hooks.py,test_subagent_refused_turn_resume.py: 805 passed.black --checkandflake8clean on the changed files.Manual verification
Not yet done end to end. The live symptom and hook stderr above are from 0.12.0. I have not run a patched gateway to confirm that
raw_tool_paramsis populated on a realkasedit permission request. Theraw_params_cachecomment insession_update_parser.pysays the refinement'srawInputis cached for exactly this event. A maintainer check on a livekassubagent edit would close this.