Repository navigation
refactor(hooks): split hooks.py under the line cap by moving HookManager into an owner - #37859
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: a pure move under the line cap; the re-wrap of Notes
[DESIGN-REVIEWED] 702b10e Description read[DESCRIPTION-READ] 5d58bac1b35b14bd9d31dc56304cf89ec46200274bf09cf114428c28395ee3a2 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. AGENTS.md requires this split: no hand-written file may exceed 2,000 lines. The post- What this change shipsInventory (7 items) — 7 justifiedIntent: get
[FIRST-PRINCIPLES-REVIEWED] 702b10e Description read[DESCRIPTION-READ] db2f1573e50b5cdecf9b85742234563a4b6c211d4f7673b853a1ee1c742ad20c That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
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: This change tightens nothing. It moves TIGHTENING: none. The only change on the gate path is a move: ADJUDICATED: 15 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix, windows and any. The diff adds no new assumption about paths, separators, interpreters or the environment. Its only platform-relevant move is that every shell call now reaches
No platform assumption is left without a candidate. UNADJUDICATED: [SCOPE-REVIEWED] 702b10e |
Sensitive change review
|
…ger into an owner hooks.py had grown to 2,011 lines, over the 2,000-line cap, so the main ratchet audit has been red on every push. Move HookManager and its fail-closed decorator into a new hook_runtime/hook_manager.py owner, and the computer-use observation test into tool_identity, so hooks.py is 1,564 lines. Pure move: hooks.py stays the import path and patch surface, compose runs the moved code on its globals, and the facade wraps judge and on_tool_call again after compose so the wrapped bodies read the facade's globals too. Part of #36565
b4e923c to
42d1ac7
Compare
Fixed in 42d1ac7. The split adds one owner module ( self-added: yes |
Code change approver recommendation: A person should decideWhy: the decider estimates a 7% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 1117 lines, more than the 400 it may approve on its own. This PR moves three definitions out of How patching keeps working. I checked the rebinding against
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 |
…/split-hooks-facade # Conflicts: # test/test_mcp_listing_import_budget.py
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
This review checked head 702b10e against the merge-base. Removed hooks.py blocks (_fail_closed_on_gate_crash, HookManager, _cu_read_only_auto_approve) diff empty against hook_runtime/hook_manager.py and tool_identity.py, apart from imports, docstrings and TYPE_CHECKING lines. hooks.py is now 1,564 lines and is not in the line-cap baseline. The test edits re-pin values to their new true values and loosen nothing. The gate-consultation scan now pins an exact list (self.judge, tier.judge), which is tighter than main's whole-file exemption.
Security: the only new runtime code is the four-line re-wrap loop after compose (hooks.py:1499-1502). It copies the existing ScriptHookStore._atomic_mutation pattern. It rebinds each gate body onto the facade's globals and wraps it again with the facade's _fail_closed_on_gate_crash. The PlatformCompositionError re-raise and the fail-closed deny are unchanged. test_the_gate_entry_points_are_wrapped_on_the_facade pins the wrapper and body globals and checks there is no double wrap. Every CI lane keyed on the gate already covers hook_runtime/. No keystone, deny rule or fail-closed branch is weakened.
Done well: the PR handles the closure hazard (compose cannot reach a body held in a wrapper) with a minimal reused pattern and a test that goes red if any line of the loop is removed.
Optional:
- Repost the Sensitive Change Review template naming head
702b10e1a994d50af0f4df9d0481c35711e4354c. The current one namesb4e923cf, so that check stays red. - Add one line to the body about the
PACKAGE_MODULE_CEILING["mcp-core"]re-pin (486 to 487). - Fix the Tests section. Post the branch-vs-main result for the related backend set, or point to CI Backend Tests instead. Note that
acp/kas_agents.pyis already under the cap via #37828, and add #34777 to the overlap table.
Problem / Motivation
Goal: Bring
src/kiro_crew/hooks.pyback under the 2,000-line cap with a pure move, so the main ratchet audit stops failing on this file.hooks.pyis 2,011 lines onmain, over the 2,000-line cap. The main ratchet audit has failed on every push since 11/13 (#36565), and every PR that toucheshooks.pyfailscheck_file_line_cap.pyuntil the file is split.Why it matters
Main stays red until both over-cap files are split, which hides real regressions behind a known red. Four open PRs edit
hooks.pyand cannot pass the line-cap check while it stays over the cap.Not a goal
__module__of a function changes.src/kiro_crew/acp/kas_agents.py, the other over-cap file (split in its own PR).HookManageritself.What changed (motivation → approach → change)
hooks.pyalready composes its rules fromhook_runtime/owners through_facade_compose.compose, and almost everything left in it is module-level state, which must stay on the facade. The largest definition left wasHookManager(about 400 lines). It stayed there only because its two gate entry points,judgeandon_tool_call, are wrapped by_fail_closed_on_gate_crashwhen the class body runs, andcomposedoes not reach a body held in a wrapper's closure.hook_runtime/hook_manager.pyholdsHookManagerand_fail_closed_on_gate_crash, moved verbatim. Right aftercompose,hooks.pywrapsjudgeandon_tool_callagain around each body rebound onto the facade's globals, the same way it already rebindsScriptHookStore._atomic_mutation. The decorator stays in the class body, so mypy still sees both entry points asAny, as onmain._cu_read_only_auto_approvemoves verbatim tohook_runtime/tool_identity.py, beside the other host-known read-only tests.hooks.pyre-exports all three names. It goes from 2,011 to 1,564 lines;hook_manager.pyis 467 lines andtool_identity.py1,092.test/test_hooks_composition_contract.py: a_LATER_MOVEStable records the three moved names, their owners and their shapes._BASE_OWNERSand_BASE_SHAPE_DIGESTstay as they are, so open PRs that re-pin the digest do not conflict with this one. A new test pins the post-composewrapping. The gate-consultation scan allows exactly the two callsHookManagermakes to the gate itself (self.judge,tier.judge).test/test_hooks.py: the extraction scan skipshook_runtime/hook_manager.pyas it already skipshooks.py.memory-skills-hooks.md(owner table, what stays and why, where new work goes),hook_runtime/__init__.py, and the citations ingovernance.md,acp-client.mdandsecurity-deep-dive.mdnow point at the new homes.Backwards compatibility
Compatible: every name
hooks.pybound onmainstill resolves on it, every patch throughkiro_crew.hooks.<name>still reaches the moved code, andHookManager's members keep their__module__,__qualname__and signatures. The one visible difference isHookManager.__module__, nowkiro_crew.hook_runtime.hook_manager. That is the same rule every class inhook_typesandscript_hooksalready follows, and nothing reads it (composeselects classes by it).Removes nothing: every definition moves and stays importable from
kiro_crew.hooks. No file, key, route or public function is removed.Tests
Proof: not provable -- other: a pure move with no behaviour change, so there is no fix for prove.py to revert
origin/mainvs branch, separate interpreters): all 343 nameshooks.pybinds onmainresolve on the branch, and none is missing. The one added name is_owner_hook_manager. Across the two interpreters, the only difference in (type,__module__,__qualname__) isHookManager.__module__. The 13HookManagermembers are identical on both sides (type,__module__,__qualname__, signature, wrapped or not). In-process identity (hooks.X is <owner>.X) is pinned bytest_every_moved_name_is_one_object_in_its_owner.src/andtest/(658 files) covers 215 names imported withfrom kiro_crew.hooks import ..., 17"kiro_crew.hooks.<name>"patch strings and 104<hooks alias>.<name>reads and writes. All of them resolve.run_scoped_tests.py --surface backendselects (2,971 files) is still running on a Linux DevSpace, on this branch and on cleanmain; the comparison will be added here. Locally,test/test_hooks*.py,test/test_gate_tiers.pyandtest/test_gate_crash_fail_closed.pypass (1,116 passed, 1 skipped).scripts/check_file_line_cap.py(scoped) no longer nameshooks.py. WithRATCHET_SCOPE_WHOLE_TREE=1, the only failure left isacp/kas_agents.py(2,004 lines, sibling PR).hooks.pywas never in.github/file-line-cap-baseline.txt.mypy src/kiro_creware clean (4,733 files). The black gate,test/test_flake_pattern_ratchet.py,test/test_facade_mirror_guards.py,test/test_facade_shared_checks.py,test/test_campaign_facades_base_public_names.py,test/test_file_line_cap.py,scripts/docs_lint.py, the comment-history gate and the brand gate all pass.semgrep scan --config semgrep/ --baseline-commit <merge-base> --erroris clean (local semgrep 1.180.0, not the CI pin 1.78.0).Updated test:
test_the_gate_entry_points_are_wrapped_on_the_facade(new) pins that the wrapper and the one body it holds both run on the facade's globals. Without the post-composewrapping,judgewould read the owner's globals, and patches ofhooks.GATE_TIERSand similar names would no longer reach it.Manual verification
N/A — unit coverage sufficient: the composition contract tests pin placement, identity, globals and patch reach, and the related backend set ran on a Linux DevSpace against clean
main.Related Issues
Part of #36565
Open PRs that edit
hooks.py, and what each meets after this split (git merge-treeagainst this branch):hooks.pyhunkshook_runtime.hook_dispatchimport list (stays in the facade)hook_runtime.hook_dispatchimport list (stays in the facade)HookManager._on_config_changeflags and a newconfirm_git_writespropertyhook_runtime/hook_manager.py. The PR already conflicts withmainin three test filesScriptHook.from_dict(stays in the facade)main(mainhas_script_hook_enabled_from)Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)