Skip to content

fix(hooks): coerce ScriptHook.enabled without dropping a deny gate - #22854

Merged
KiroCrewCaptain merged 2 commits into
mainfrom
greener/pr-12230
Nov 14, 2026
Merged

KiroCrewCaptain merged 2 commits into
mainfrom
greener/pr-12230

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #12230 (by @aniruddhaadak80, whose commit is kept as-is). Moved to a branch of this repository because src/kiro_crew/hooks.py is a Sensitive Change Review path, which a fork PR cannot pass.

Problem / Motivation

Goal: a hand-edited enabled value in hooks.json means what the operator wrote, and a typo never silently turns a deny gate off.

ScriptHook.from_dict stored enabled verbatim. hooks.json is hand-editable, so "enabled": "false" stayed truthy and the hook kept firing (fire gates on if not hook.enabled). UserDeniedPattern already uses _coerce_bool for the same bool("false") trap.

Why it matters

enabled is the on/off switch for a hook that runs a shell command, including PreToolUse hooks that block tool calls. An operator who writes "false" must get an off hook, and an operator who writes "ture" must not lose a deny gate.

Not a goal

  • No change to which hooks are registered or executed.
  • No change to a valid boolean enabled or to the absent-key default.
  • No new schema validation at the API boundary (the dashboard already sends strict bools).

What changed (motivation → approach → change)

Symptom: "enabled": "false" kept a hook firing. Root cause: no coercion on load. Change: ScriptHook._enabled_from(data), used by from_dict:

  • key absent -> True (unchanged default)
  • real bool -> itself; true/false/1/0/yes/no/on/off strings (any case, trimmed) -> their value, via _coerce_bool
  • JSON int -> != 0 (a hand-edited 0 stays off, 1 stays on)
  • null, "" -> False (both were falsy before). A whitespace-only string (spaces, tabs, a non-breaking space) is not empty: it was truthy before, so it takes the unrecognised path below and loads True with a warning
  • anything else ("ture", "y", [1], {}, 1.0) -> True, with a load-time warning naming the hook id and the value type.

Why unrecognised loads on (maintainer review + AI review on b0e0261): a PreToolUse hook is a deny gate, so off silently drops it. Refusing the entry is not enough either: the gateway registers its store, persisted_hook_store returns it directly, and that store skips an entry it cannot load, so the gate would stop there too. On keeps the gate running in every process, and it is no privilege gain, since anyone who can write hooks.json can write a real true.

Dropped from the earlier revision: the ScriptHookStore.update() hunk. Its only caller validates enabled as a strict bool (HOOK_UPDATE_SCHEMA, _reject_null_enabled) before the store sees it. Also updated the stale acp/kas_wire.py comment that said from_dict takes enabled verbatim.

Backwards compatibility

Compatible: real booleans and an absent key load exactly as before; null, "", 0 loaded falsy before and still load off; a non-empty unrecognised string (including whitespace-only) or list loaded on before and still loads on (now with a warning). Changed: off spellings ("false", "off", "0", "no") go from on to off, and falsy junk ([], {}, 0.0) goes from off to on with a warning.

Reader: src/kiro_crew/hook_runtime/script_hooks.py:ScriptHookStore.fire -- chat|subagent|cron -- gates on the coerced bool; test_registered_store_still_blocks_with_junk_enabled_gate
Reader: src/kiro_crew/hook_runtime/hook_dispatch.py:persisted_hook_store -- subagent|cron -- loads the same bool; test_persisted_store_loads_junk_enabled_gate_on
Reader: src/kiro_crew/acp/kas_wire.py:script hook export -- chat|subagent -- reads the same bool, unchanged for real bools
Reader: src/kiro_crew/acp/kas_agents.py:PreToolUse hook selection -- subagent -- reads the same bool, unchanged for real bools
Reader: src/kiro_crew/dashboard/handlers/hooks_scripts.py:toggle audit -- crew page -- logs the bool; toggle flips a real bool

Tests

  • test_from_dict_coerces_enabled (off/on spellings incl. case and padding, ints 0/1/2/-1, null, ""), test_from_dict_loads_unrecognised_enabled_on_with_warning ("ture", "y", "n", "junk", "enabled", [1], ["x"], [], {}, 1.0, 0.0, and whitespace-only " ", " ", "\t\n", "\u00a0", " \u00a0 "), test_from_dict_recognised_enabled_does_not_warn, test_from_dict_absent_enabled_defaults_on.
  • test_store_load_keeps_hand_disabled_hook_off (hooks.json round trip with "false", 0, null).
  • test_registered_store_still_blocks_with_junk_enabled_gate: gateway path, a PreToolUse exit 2 hook at "enabled" "junk"/"ture"/[1] still fires and blocks.
  • test_persisted_store_loads_junk_enabled_gate_on: standalone path loads the same gate on.
  • pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py: 2824 passed, 1 skipped.
  • black / flake8 / isort clean on the changed lines.

Manual verification

N/A — unit coverage sufficient: the change is a pure load-time coercion, covered end to end through hooks.json round trips and both gate store paths.

Related Issues

None - self-identified defect during hooks review.

Pattern harvest

Rule candidate: review-prompt
Pattern: hand-editable bool stored without coercion (bool("false") trap); an unrecognised value on a deny gate must not be read as off

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project Apache-2.0 license (see CONTRIBUTING.md).

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/script_hooks.py

  • src/kiro_crew/hooks.py

  • @iamwhatever posted a complete reasoning template for 6786a36.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c7f1fe6
  • What rule changed: ScriptHook.from_dict now coerces the stored enabled value instead of copying it verbatim from hooks.json.
  • Before -> after (what was allowed/blocked, now): before, any truthy value enabled a script hook, so "false", "off", "junk" or a non-empty list kept it firing. Now only true, a non-zero int, or an on-spelling string (true/1/yes/on) enables it; off-spellings, 0, null, "" and other junk load as disabled. An absent key still loads enabled.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a hook whose hooks.json entry holds a junk truthy value stops firing until the operator re-enables it in the dashboard. No command is newly blocked by the deny floor, and no secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox run; the change is a load-time value coercion with no sandbox interaction. Evidence is the hooks.json round-trip test test_store_load_keeps_hand_disabled_hook_off ("false", 0, null load off) and 18 from_dict cases, which fail on main and pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py gave 1258 passed, 1 skipped on this head, including the PreToolUse fire and deny paths.
    • Backward compatible (old config / old data / old callers still work, how checked): real booleans and an absent key load as before (covered by existing test_from_dict and new test_from_dict_absent_enabled_defaults_on); null/""/0 were falsy before and stay off. The dashboard writes only strict bools (HOOK_UPDATE_SCHEMA).
    • Existing tests (which suites passed on this head): test_script_hooks, test_hooks_composition_contract and the rest of test_hooks*/test_hook_* pass locally; CI backend suites are running on this head.
  • How to undo: revert this single commit; from_dict goes back to enabled=data.get("enabled", True).

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 6786a36ad569605b7706fc6e7aa2873541f413d0 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 6786a36ad569605b7706fc6e7aa2873541f413d0 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change only coerces enabled when a hook loads, unrecognised values fail closed (the hook loads on), and the readers named in the PR are covered.

Notes

  • portability_vetting restore already rewrites a non-bool enabled to False (see test_truthy_non_bool_enabled_is_written_false), so a junk value now loads on if hand-edited but off if it arrives in a restored bundle. That split looks deliberate (an imported shell hook starts disabled), but say so under Backwards compatibility.

[DESIGN-REVIEWED] 6786a36

Description read

[DESCRIPTION-READ] 9baced3d33644e08b321ff01e704de0c7e05e1fc7204e6b1885b6dc399e7a443

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 6786a36ad569605b7706fc6e7aa2873541f413d0 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix is at mechanism level and reuses the one existing spelling list in config/fields.py:_coerce_bool. The extra int/null/empty-string branches are there to keep values that loaded off before loading off.

What this change ships

Inventory (6 items) — 6 justified

Intent: an operator's hand-edited enabled in hooks.json means what they wrote, and a typo never turns a deny gate off. This is a FIX.

  1. "enabled": "false", "off", "0" and "no" now switch a script hook off instead of leaving it firing — justified
  2. A JSON integer 0 stays off and any other int stays on, so a hand-written 0 is not flipped on by _coerce_bool's default — justified
  3. null and "" still load off, as before — justified
  4. An unrecognised value ("ture", [1], {}, whitespace) loads on and logs a warning naming the hook. Falsy junk ([], {}, 0.0) moves from off to on — justified
  5. The stale kas_wire.py comment saying from_dict stores enabled verbatim is reworded — justified
  6. A new _script_hook_enabled_from owner is registered in the hooks composition contract test — justified

[FIRST-PRINCIPLES-REVIEWED] 6786a36

Description read

[DESCRIPTION-READ] 2ab353c2e7a5b368675e22abebf78cadedb2ec64ba525fd3b1d2110bdec8889f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6786a36ad569605b7706fc6e7aa2873541f413d0 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6786a36

Verdict parsed from the review's SHA-scoped output markers for commit 6786a36ad569605b7706fc6e7aa2873541f413d0.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6786a36ad569605b7706fc6e7aa2873541f413d0 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6786a36ad569605b7706fc6e7aa2873541f413d0 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6786a36

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6786a36ad569605b7706fc6e7aa2873541f413d0 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 6786a36ad569605b7706fc6e7aa2873541f413d0 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 10 classified, 0 newly refused, 10 still allowed.
  • ubuntu-latest (platform posix): 10 classified, 0 newly refused, 10 still allowed.
  • windows-latest (platform windows): 5 classified, 0 newly refused, 5 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: This change tightens how a stored script hook's enabled value is read when hooks.json is loaded. It does not touch the shell deny composite, so the 15 shell candidates are boundary probes only and should come back unchanged. One narrowing is argued here but not confirmed: a hook a person had switched off with 0.0, [] or {} used to load off and now loads on. Nothing can classify that, so it is named under UNADJUDICATED and does not block.

TIGHTENING: ScriptHook.from_dict enabled coercion (enabled=data.get("enabled", True) → enabled=_script_hook_enabled_from(data), with the fallback logger.warning("Script hook %r has an unrecognised 'enabled' value (%s); loading it enabled", ...); return True) -- the ONE threat it refuses: a typo in a PreToolUse deny hook's enabled value turning the gate off without anyone noticing ("Off is not a safe guess: a PreToolUse hook is a deny gate, so reading a typo as off would silently drop it").

ADJUDICATED: 15 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix rows (~/.kirocrew/hooks.json, .venv/bin/python, jq/grep/cp, kirocrew) and windows rows (%USERPROFILE%\.kirocrew\hooks.json, .venv\Scripts\python.exe, findstr, PowerShell Get-Content/ConvertFrom-Json, kirocrew.exe). The diff assumes nothing about paths, separators, argv shape or interpreter. It only reads JSON values, which are the same on every host. So these rows cover the shell operations in the touched area (reading and editing hooks.json, running the hook tests, searching the log for the new warning) in both spellings. No platform assumption was left without a candidate. No any rows were written, because every row names an executable or a path.

UNADJUDICATED: Guard: _script_hook_enabled_from (src/kiro_crew/hook_runtime/script_hooks.py), called from ScriptHook.from_dict (src/kiro_crew/hooks.py:1858). Call path: ScriptHookStore(config_dir) loads hooks.json → ScriptHook.from_dict(entry) → hook.enabled, which ScriptHookStore.fire reads at script_hooks.py:1004 (if not hook.enabled or hook.event != event: continue). From there a PreToolUse hook's exit code becomes a tool-call refusal.

The change in that direction: in BASE, "enabled": 0.0, "enabled": [] and "enabled": {} were falsy, so the hook was skipped. In HEAD they fall through _coerce_bool unrecognised and load ON; the PR's own test test_from_dict_loads_unrecognised_enabled_on_with_warning lists all three as True. So a PreToolUse gate that an operator, or a tool that writes JSON numbers as floats, had turned off with 0.0 now runs. If that gate exits 2, it refuses tool calls that were allowed the day before. The only signal is a load-time warning.

Candidate inputs I would have submitted if a hooks.json load classifier existed:

  • a PreToolUse exit 2 hook with "enabled": 0.0
  • the same hook with "enabled": []
  • the same hook with "enabled": {}
  • the same hook with "enabled": "disabled"
  • the same hook with "enabled": "n"

The last two are plausible hand-written "off" spellings that _coerce_bool does not recognise, so they also load ON.

The narrowest change that still refuses the threat: treat a float like an int (raw != 0), as is already done for 0. Whether an empty container should keep its old falsy reading is a decision to make on its own merits. Neither change brings back the typo-silently-drops-the-gate threat.

There is a second, smaller point: "enabled": "false", "0", "no" and "off" were truthy in BASE, so those gates ran; in HEAD they load off. That is the loosening direction and belongs to the other lanes. KAS listing (kas_wire.normalize_script_hook) already showed them off, so HEAD makes the two paths agree.

[SCOPE-REVIEWED] 6786a36

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 21, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at c7f1fe6. Requesting changes on one point: the direction an unrecognised enabled value fails.

The "false"/"off"/"0" fix is right and well tested (every mutant of _enabled_from goes red).

The problem is the catch-all _coerce_bool(raw, default=False) in _enabled_from. A script hook is not only an action: a PreToolUse hook is a deny gate, and this codebase already treats it as one that fails closed. The ScriptHook docstring (hooks.py) says a crashed or timed-out PreToolUse hook BLOCKS the tool, and persisted_hook_store raises on an entry it cannot load so a gate fails closed instead of reading a saved deny hook as absent. For such a hook, "disabled" is the permissive answer. On main a non-empty junk value ("ture", "y", [1]) is truthy, so the gate runs. With this head the gate silently stops, and the next save writes false back over the operator's value (script_hooks.py:412-418), leaving no trace. The Design lane raised the same point as a Note, and it has no reply.

"Junk must not activate a shell command" does not hold up against an attacker either: anyone who can write hooks.json can write a real true. So the choice only decides what happens to an operator's typo, and for a gate the safe outcome is that it keeps running or the entry is visibly refused.

Suggested shape: keep the recognised spellings, ints, null/"" and the absent-key default as they are, and raise in from_dict for anything else. The fail-soft store then preserves the raw entry in _unparsed_hook_entries (script_hooks.py:403-410), and persisted_hook_store fails closed on it. If you prefer to keep loading it, default junk to enabled for PreToolUse and log a warning at load time. A test with a PreToolUse hook at "enabled": "junk" that still blocks (or refuses to load) would pin either one.

Non-blocking: acp/kas_wire.py:359-364 still says from_dict takes enabled verbatim; please update it in this commit. The First Principles note on the second int rule beside _coerce_bool also has no reply.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 21, 2026
@iamwhatever iamwhatever changed the title fix(hooks): coerce ScriptHook.enabled, failing closed on junk fix(hooks): coerce ScriptHook.enabled, refusing unrecognised values Oct 22, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

@buluoray thanks for the review. Addressed in b0e0261 (rebased on latest main), point by point:

  1. Fail direction of an unrecognised enabled. Took your suggested shape. _enabled_from keeps the recognised spellings (via _coerce_bool, so the spelling list stays in one place), JSON ints, null/"" (now also whitespace-only) as off, and the absent-key default as on. Anything else ("ture", "y", [1], {}, 1.0) now raises ValueError from from_dict. The fail-soft store keeps the raw entry in _unparsed_hook_entries, logs "Skipping unparseable hook entry", and writes it back unchanged on the next save, so the operator value is never overwritten with false. persisted_hook_store raises on it, so the gate fails closed there.
    • One thing to be explicit about: in a process with a registered store (the gateway), the quarantined entry is skipped with that warning rather than failing the gate closed. That is the existing handling for every unloadable entry (for example an invalid event), not something new in this PR. If you would rather have the PreToolUse-defaults-to-enabled variant so the gate keeps running in the gateway too, say so and I will switch.
    • Tests: test_from_dict_refuses_unrecognised_enabled (11 junk values), test_store_keeps_junk_enabled_entry_verbatim (PreToolUse hook at "enabled": "junk": not loaded as off, raw entry preserved across a save), test_persisted_store_fails_closed_on_junk_enabled_gate (PreToolUse hook at "ture": the gate store raises). Nearby inputs also covered: " On ", "YES", ints 2/-1, " ", 0.0.
  2. Stale comment in acp/kas_wire.py. Updated in the same commit: it now says from_dict coerces on load and refuses an unrecognised value, and keeps the is True check as a guard.
  3. Design note (junk silently turns a PreToolUse guard off). Resolved by point 1: junk no longer loads as off, and the refusal is logged at load time.
  4. First Principles note (second int rule beside _coerce_bool). Kept the int branch on purpose. _coerce_bool only reads bools and strings, so without the branch a JSON 1 would now be refused and a JSON 0 would be refused too, which is worse than today for the most natural hand edit after false. The branch is three lines, local to enabled, and pinned by tests for 0, 1, 2, -1. Your review asked to keep ints as they are, so I left them.

Local: pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py gave 2814 passed, 1 skipped. Ready for re-review.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: b0e0261
  • What rule changed: ScriptHook.from_dict now coerces the stored enabled value instead of copying it verbatim from hooks.json, and refuses (raises on) a value it does not recognise.
  • Before -> after (what was allowed/blocked, now): before, any truthy value enabled a script hook, so "false", "off" or a non-empty list kept it firing. Now real bools, the _coerce_bool spellings (true/false/1/0/yes/no/on/off) and JSON ints map to their value; null/"" load off as before; an absent key loads on as before. Any other value ("ture", [1], 1.0) makes from_dict raise: the store keeps that entry verbatim in _unparsed_hook_entries and writes it back unchanged, and persisted_hook_store fails closed on it.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a hook whose hooks.json entry holds an unrecognised enabled value is skipped with a load-time warning in the gateway, and a standalone run with such an entry refuses gated tool calls until the operator fixes the value. No command is newly blocked by the deny floor, and no secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox run; the change is a load-time value coercion with no sandbox interaction. Evidence: test_from_dict_coerces_enabled, test_from_dict_refuses_unrecognised_enabled, test_store_load_keeps_hand_disabled_hook_off, test_store_keeps_junk_enabled_entry_verbatim, test_persisted_store_fails_closed_on_junk_enabled_gate.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py gave 2814 passed, 1 skipped on this head, including the PreToolUse fire and deny paths and the corrupt-hooks.json gate tests.
    • Backward compatible (old config / old data / old callers still work, how checked): real booleans and an absent key load as before (existing test_from_dict, new test_from_dict_absent_enabled_defaults_on); null/""/0 were falsy before and stay off. The dashboard and MCP paths send strict bools (HOOK_CREATE_SCHEMA, HOOK_UPDATE_SCHEMA), so they never reach the raise.
    • Existing tests (which suites passed on this head): test_script_hooks, test_hooks_composition_contract, test_kas_spec_hook_gaps and the rest of test_hooks*/test_hook_/test_kas_ pass locally; CI is running on this head.
  • How to undo: revert the two commits; from_dict goes back to enabled=data.get("enabled", True).

@iamwhatever iamwhatever changed the title fix(hooks): coerce ScriptHook.enabled, refusing unrecognised values fix(hooks): coerce ScriptHook.enabled without dropping a deny gate Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

@buluoray follow-up: I switched to your second option in 8622b49, which replaces my earlier reply on point 1.

The raise variant (b0e0261) had the gap I flagged: both AI reviews confirmed it as blocking. In the gateway, persisted_hook_store returns the registered store directly, and that store skips an entry it cannot load, so a deny hook at "enabled": "ture" stopped firing there, which is the exact case your review is about.

Now, per your suggested alternative:

  1. Unrecognised enabled ("ture", "y", [1], {}, 1.0) loads enabled, with a load-time warning naming the hook id and the value type. Recognised spellings, JSON ints, null/"" and the absent-key default are unchanged from the last revision. I applied it to every event, not only PreToolUse: as you noted, on is no privilege gain (anyone who can write hooks.json can write true), and one rule is simpler than an event-dependent one.
    • Tests: test_registered_store_still_blocks_with_junk_enabled_gate (gateway path, PreToolUse exit 2 hook at "junk"/"ture"/[1] still fires and returns exit 2), test_persisted_store_loads_junk_enabled_gate_on (standalone path), test_from_dict_loads_unrecognised_enabled_on_with_warning (11 values, asserts the warning), test_from_dict_recognised_enabled_does_not_warn.
  2. acp/kas_wire.py comment: still updated, now saying an unrecognised value loads on with a warning.
  3. Design note: resolved, junk no longer turns a guard off, and the load logs it.
  4. First Principles int note: unchanged reasoning, the int branch stays so a JSON 0/1 keeps meaning off/on.

Local: pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py gave 2824 passed, 1 skipped. Ready for re-review.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8622b49
  • What rule changed: ScriptHook.from_dict now coerces the stored enabled value instead of copying it verbatim from hooks.json.
  • Before -> after (what was allowed/blocked, now): before, any truthy value enabled a script hook, so "false", "off" or "0" kept it firing. Now real bools, the _coerce_bool spellings (true/false/1/0/yes/no/on/off) and JSON ints map to their value; null/"" load off as before; an absent key loads on as before; any other value ("ture", [1], 1.0) loads on with a load-time warning, so a PreToolUse deny gate with a typo keeps running.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a hook whose hooks.json entry holds an unrecognised falsy value ([], {}, 0.0) now fires where it did not, with a warning in the log. A deny hook can then block calls it did not block before; no deny gate is dropped, and no secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox run; the change is a load-time value coercion with no sandbox interaction. Evidence: test_from_dict_coerces_enabled, test_from_dict_loads_unrecognised_enabled_on_with_warning, test_store_load_keeps_hand_disabled_hook_off, test_registered_store_still_blocks_with_junk_enabled_gate, test_persisted_store_loads_junk_enabled_gate_on.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py gave 2824 passed, 1 skipped on this head, including the PreToolUse fire and deny paths.
    • Backward compatible (old config / old data / old callers still work, how checked): real booleans and an absent key load as before (existing test_from_dict, new test_from_dict_absent_enabled_defaults_on); null/""/0 stay off; non-empty junk stays on. The dashboard and MCP paths send strict bools (HOOK_CREATE_SCHEMA, HOOK_UPDATE_SCHEMA).
    • Existing tests (which suites passed on this head): test_script_hooks, test_hooks_composition_contract, test_kas_spec_hook_gaps and the rest of test_hooks*/test_hook_/test_kas_ pass locally; CI is running on this head.
  • How to undo: revert the two commits; from_dict goes back to enabled=data.get("enabled", True).

buluoray
buluoray previously approved these changes Oct 22, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 8622b49. Approving: the blocking point from my review at c7f1fe6 is fixed.

1. Fail direction of an unrecognised enabled (was blocking): fixed. ScriptHook._enabled_from (src/kiro_crew/hooks.py:1536-1571, called from from_dict at :1638) keeps the recognised spellings, JSON ints, null/"" and the absent-key default, and loads anything else ("ture", "y", [1], {}, 1.0) enabled with a load-time warning naming the hook id and value type. The recognised/unrecognised split (_coerce_bool with default=True vs default=False) is correct. Both gate paths are pinned: test_registered_store_still_blocks_with_junk_enabled_gate fires a PreToolUse exit 2 hook at "junk"/"ture"/[1] through the registered store and gets the block, and test_persisted_store_loads_junk_enabled_gate_on covers the standalone path. This also avoids the gap in the intermediate raise variant, where the registered store would have skipped the entry.

2. Stale comment in acp/kas_wire.py: fixed (src/kiro_crew/acp/kas_wire.py:359-362).

3. Design note and First Principles int note: both answered; keeping the int branch so a hand-written 0/1 means off/on is sound.

Verification

  • test/test_script_hooks.py: 95 passed. test_script_hooks + test_hooks* + test_hook_* + test_kas_*: 2824 passed, 1 skipped.

  • Mutations of _enabled_from, one at a time, each restored before the next:

    • unrecognised -> False: 15 red (loads_unrecognised_enabled_on_with_warning x11, registered_store_still_blocks... x3, persisted_store_loads_junk_enabled_gate_on)
    • warning removed: 11 red (loads_unrecognised_enabled_on_with_warning)
    • int branch removed: 4 red (coerces_enabled[0], recognised_enabled_does_not_warn[0/1], store_load_keeps_hand_disabled_hook_off[0])
    • null/"" branch removed: 6 red (coerces_enabled[None/""/" "], store_load_keeps_hand_disabled_hook_off[None], ...)
    • absent key -> off: 9 red (absent_enabled_defaults_on, test_create_hook, test_fire_*)
    • warn on recognised values: 2 red (recognised_enabled_does_not_warn[True/on])
    • verbatim read restored: 34 red

    No surviving mutant.

CI on this head: the Security Scope lane failed because its runner could not install the review tool (exit 22), so it reported no verdict and failed closed. That is infrastructure, not this diff; one re-run should clear it. Sensitive Change Review needs this reasoned human approval, which the reasoning template already covers.

Non-blocking follow-ups

  • The memory-skills-hooks spec does not describe how a hand-edited enabled in hooks.json is read on load. One sentence there (recognised spellings map, unrecognised loads on with a warning) would keep the spec in step.
  • test_registered_store_still_blocks_with_junk_enabled_gate runs a real sandboxed hook in tmp_path, so it fails on a host where the sandbox refuses to pin the pytest temp directory. It passes on a neutral basetemp; worth noting in the test or forcing a neutral cwd.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 9972f74
  • What rule changed: ScriptHook.from_dict now coerces the stored enabled value instead of copying it verbatim from hooks.json. (Same code as 8622b49, rebased on latest main; only the new gateway test now runs its hook unsandboxed, as TestScriptHookStoreFire does, so CI hosts reach the real exit code.)
  • Before -> after (what was allowed/blocked, now): before, any truthy value enabled a script hook, so "false", "off" or "0" kept it firing. Now real bools, the _coerce_bool spellings (true/false/1/0/yes/no/on/off) and JSON ints map to their value; null/"" load off as before; an absent key loads on as before; any other value ("ture", [1], 1.0) loads on with a load-time warning, so a PreToolUse deny gate with a typo keeps running.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a hook whose hooks.json entry holds an unrecognised falsy value ([], {}, 0.0) now fires where it did not, with a warning in the log. A deny hook can then block calls it did not block before; no deny gate is dropped, and no secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox run; the change is a load-time value coercion with no sandbox interaction. Evidence: test_from_dict_coerces_enabled, test_from_dict_loads_unrecognised_enabled_on_with_warning, test_store_load_keeps_hand_disabled_hook_off, test_registered_store_still_blocks_with_junk_enabled_gate, test_persisted_store_loads_junk_enabled_gate_on.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py gave 2824 passed, 1 skipped locally, including the PreToolUse fire and deny paths.
    • Backward compatible (old config / old data / old callers still work, how checked): real booleans and an absent key load as before (existing test_from_dict, new test_from_dict_absent_enabled_defaults_on); null/""/0 stay off; non-empty junk stays on. The dashboard and MCP paths send strict bools (HOOK_CREATE_SCHEMA, HOOK_UPDATE_SCHEMA).
    • Existing tests (which suites passed on this head): test_script_hooks, test_hooks_composition_contract, test_kas_spec_hook_gaps and the rest of test_hooks*/test_hook_/test_kas_ pass locally; CI is running on this head.
  • How to undo: revert the two commits; from_dict goes back to enabled=data.get("enabled", True).

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026
@iamwhatever iamwhatever self-assigned this Oct 22, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD

A whitespace-only string silently disables a hook after this change. Before the change, bool(" ") was true, so the deny hook ran. _enabled_from now strips the string and returns false without warning. That contradicts the stated rule that an unrecognized value must preserve the deny gate.

Please treat only None and the empty string as false. Route whitespace-only strings, including non-breaking spaces, through the unrecognized-value path so they load enabled with a warning. Update the compatibility text and tests.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review lanes PASS; the hold was advisory (a downgraded GPT 6.1 finding, a security-checklist item, or a missing reasoning template). The watch holder read the hold and approved explicitly.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 22, 2026 15:38
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 22, 2026
hooks.json is hand-editable and ScriptHook.from_dict stored enabled
verbatim, so a hand-set "false" stayed truthy and the hook kept firing.

Coerce it when loading: recognised on/off spellings and JSON integers map
to their value; null, empty string, lists and other junk load as disabled
(a script hook runs a shell command, so junk must not activate it); an
absent key keeps the default of enabled.

The earlier update() hunk is dropped: its only caller validates enabled
as a strict bool before the store sees it.
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 14, 2026
A PreToolUse script hook is a deny gate, so reading a typo such as
"ture" or [1] as off silently dropped the gate, and the next save wrote
false over the operator's value. Refusing the entry is no better: the
gateway's registered store skips an entry it cannot load, so the gate
would stop there too.

Keep the recognised spellings, JSON ints, null/"" and the absent-key
default, and load anything else enabled with a warning naming the hook.
That keeps the gate running in every process; it is not a privilege
gain, since whoever can write hooks.json can write a real true.

Only null and the empty string load off. A whitespace-only value (spaces,
tabs, a non-breaking space) was truthy before, so a deny gate written that
way ran; it takes the unrecognised path and loads enabled with a warning.

The reader lives in the script_hooks owner as _script_hook_enabled_from,
so hooks.py stays under the 2,000-line cap. Also update the kas_wire
comment that still said from_dict takes enabled verbatim.
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 6786a36
  • What rule changed: ScriptHook.from_dict now coerces the stored enabled value instead of copying it verbatim from hooks.json. This head addresses @bolichen97's HOLD on 9972f74: a whitespace-only string no longer loads off. The reader also moves into the script_hooks owner as _script_hook_enabled_from (bound on kiro_crew.hooks like the other owner names), so hooks.py stays under the 2,000-line cap. Rebased on latest main; the PR is two commits.
  • Before -> after (what was allowed/blocked, now): before, any truthy value enabled a script hook, so "false", "off" or "0" kept it firing. Now real bools, the _coerce_bool spellings and JSON ints map to their value; only null and "" load off (both were falsy before); an absent key loads on; any other value, including a whitespace-only string (" ", "\t\n", a non-breaking space), loads on with a load-time warning, so a PreToolUse deny gate keeps running.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a hook whose hooks.json entry holds an unrecognised falsy value ([], {}, 0.0) now fires where it did not, with a warning in the log. A deny hook can then block calls it did not block before; no deny gate is dropped, and no secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox run; the change is a load-time value coercion with no sandbox interaction. Evidence: test_from_dict_coerces_enabled, test_from_dict_loads_unrecognised_enabled_on_with_warning (now with five whitespace-only cases, which fail on 9972f74: 7 failed before the fix), test_registered_store_still_blocks_with_junk_enabled_gate (now with " " and a non-breaking space), test_store_load_keeps_hand_disabled_hook_off.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest test/test_hook*.py test/test_gate_tiers.py test/test_*script_hook*.py test/test_kas_wire*.py gave 1631 passed, 1 skipped locally, including the PreToolUse fire and deny paths.
    • Backward compatible (old config / old data / old callers still work, how checked): real booleans and an absent key load as before; null/""/0 stay off; non-empty junk, now including whitespace-only strings, stays on as bool() read it before. The dashboard and MCP paths send strict bools (HOOK_CREATE_SCHEMA, HOOK_UPDATE_SCHEMA).
    • Existing tests (which suites passed on this head): test_script_hooks, test_hooks_composition_contract (owner registered in _NEW_OWNER_DEFS), and the rest of test_hook*/test_kas_wire* pass locally; scripts/check_file_line_cap.py passes; CI is running on this head.
  • How to undo: revert the two commits; from_dict goes back to enabled=data.get("enabled", True).

@bolichen97 could you re-review the HOLD point on this head?

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

ScriptHook.from_dict now reads a hand-edited enabled through _script_hook_enabled_from. A missing key stays on. Real bools and the _coerce_bool spellings map to their value, ints map to != 0, and null or "" stay off. Anything unrecognised loads on with a warning, so a typo cannot silently drop a PreToolUse deny gate. The logic is correct against _coerce_bool. Runtime binding works even though the import is TYPE_CHECKING-only, because _facade_compose rebinds owner functions onto the hooks.py globals, where _coerce_bool and logger exist. Every reader I checked (fire, kas_wire, kas_agents, kas_subagent_targets, the dashboard toggle) behaves the same for real bools and correctly for "false". Bundle restore still forces False, and the create path only gets schema-validated bools. Tests cover the coercion table, the warning, a hooks.json round trip, and both the registered and standalone store paths. No regression or failure-open path found.

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 6786a36ad5 · 182 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 14, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

This review found no blocking issue on head 6786a36. It cannot approve while a change request is still open. A maintainer review from 2026-10-22 asked that whitespace-only enabled strings load on with a warning. This head does that: _script_hook_enabled_from sends whitespace and non-breaking spaces down the unrecognised path, and new tests cover five whitespace cases. That reviewer needs to re-review or dismiss the request before this can merge.

What we checked on this head:

  • Each branch of _script_hook_enabled_from (hook_runtime/script_hooks.py:58): absent key, real bools, recognised spellings, ints, None and "", and unrecognised values. Reverting hooks.py:1858 or loosening any branch makes at least one new test fail.
  • All callers now get a real bool: fire(), the KAS export (is True), kas_agents, and the dashboard toggle. create() and update() still validate enabled as a strict bool. An unrecognised value keeps a PreToolUse deny gate on.
  • The new tests follow the determinism and no-side-effects rules.

Done well: test_registered_store_still_blocks_with_junk_enabled_gate loads a hand-edited hooks.json through the registered store, fires a real exit 2 PreToolUse hook, and asserts the block. It tests the gate itself, not only the field value.

Notes:

  • Main has moved since CI ran. fix(hooks): keep the last user deny rules when denied_commands.json cannot be read #34188 took src/kiro_crew/hooks.py to exactly 2,000 lines. This PR adds one net line there, so the merged tree has 2,001 lines, and hooks.py has no row in the line-cap baseline. A rebase that moves one small definition into a hook_runtime owner keeps check_file_line_cap.py green.
  • src/kiro_crew/portability_vetting.py:435-438 still says the store keeps the raw enabled value, and it computes was_on by truthiness. The restore still writes every hook as off, so only the report is wrong. Fix it, or answer the Design lane note with one line under Backwards compatibility.
  • The body's "What changed" section names ScriptHook._enabled_from, which no longer exists. The helper is now _script_hook_enabled_from in hook_runtime/script_hooks.py. Backwards compatibility could also say that on the KAS export, hand-edited strings that exported as off before now export as on.

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

Reviewed at 6786a36, merged onto current main (66dc266). Approving.

Earlier points

  1. bolichen97 on 9972f74: a whitespace-only enabled turned a deny hook off. Fixed. _script_hook_enabled_from (src/kiro_crew/hook_runtime/script_hooks.py:58-94) now treats only None and the exact "" as off. " ", "\t\n" and a non-breaking space fall to _coerce_bool, which does not know them, so they load on with a warning. Tests cover all five spellings, and a PreToolUse exit 2 hook set to " " or "\u00a0" still blocks through the registered store.
  2. buluoray on c7f1fe6: an unrecognised value loaded off and dropped the gate. Still fixed at this head. Junk loads on with a warning naming the hook id and value type.
  3. Stale comment in src/kiro_crew/acp/kas_wire.py:413-416. Still fixed.

Fail-open check

enabled in hooks.json main this head
key missing on on
true, "true", "on", 1, 2 on on
"false", "off", "0", "no" on (string is truthy) off
false, 0, null, "" off off
" ", "\u00a0", "ture", "y", [1], 1.0 on on, with a warning
[], {}, 0.0 off on, with a warning

No value that ran a gate on main stops it now, except the recognised "off" spellings. Those are the operator's explicit off, which is the point of the PR. The loaded hook always holds a real bool, so normalize_script_hook's is True test and the store's fire path agree. Nothing that writes through the API changes.

No regex is added, in source or tests. The spellings come from the existing _coerce_bool table (src/kiro_crew/config/fields.py:123).

Verification

  • Merged head, test/test_script_hooks.py, test_hooks_composition_contract.py, test_kas_wire.py, test_hooks*.py, test_hook_*.py: 1496 passed, 1 skipped.
  • Mutations, one at a time, each restored before the next, run against test/test_script_hooks.py (115 tests):
    • from_dict reads enabled verbatim again (the coercion reverted): 40 red, across test_from_dict_coerces_enabled, test_from_dict_loads_unrecognised_enabled_on_with_warning, test_registered_store_still_blocks_with_junk_enabled_gate, test_persisted_store_loads_junk_enabled_gate_on, test_store_load_keeps_hand_disabled_hook_off.
    • unrecognised value loads off: 22 red (loads_unrecognised_enabled_on_with_warning x16, registered_store_still_blocks_with_junk_enabled_gate x5, persisted_store_loads_junk_enabled_gate_on).
    • whitespace treated as empty: 7 red (the five whitespace cases of loads_unrecognised_enabled_on_with_warning, and registered_store_still_blocks_with_junk_enabled_gate[ ] and [\xa0]).
    • load warning removed: 16 red (loads_unrecognised_enabled_on_with_warning).
  • CI on this head: 94 pass, 15 skipping, 0 failing. Those runs used the base from when the head was pushed, not today's main. Auto-merge is on, so this approval can land it.

Non-blocking follow-ups

  • [], {} and 0.0 used to load off and now load on, so a hook hand-set that way starts running its command. The load warning names it, and anyone who can write hooks.json can write true. Worth one line in the PR body's compatibility notes.
  • docs/system-specs/modules/memory-skills-hooks.md still does not say how a hand-edited enabled is read on load. One sentence would keep the spec in step: recognised spellings map, null and "" load off, anything else loads on with a warning.
  • I did not run the gateway's registered-store load path end to end. The docstring's claim that it skips an entry it cannot load was not re-checked here.

Verdict: APPROVE

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 6786a36ad5; my HOLD from 9972f74838 is resolved.

_script_hook_enabled_from now loads only null and "" as off. A whitespace-only string, including a non-breaking space, is not a value _coerce_bool recognises, so it loads enabled with a warning naming the hook, and the deny gate keeps running. The docstring states the rule, and test_script_hooks.py covers it. Locally the changed tests pass (181 passed). Auto merge is on.

@KiroCrewCaptain
KiroCrewCaptain merged commit 8298ea2 into main Nov 14, 2026
114 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the greener/pr-12230 branch November 14, 2026 19:09
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 14, 2026
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.

5 participants