Skip to content

refactor(hooks): simplify the first third of lib hook-utils.sh - #14349

Merged
kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-14331-42568373896-1
Nov 9, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-14331-42568373896-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #14331

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified functions that start in lines 1-1758 (range 1 of 3 of the 5274-line file) of lib/hook-utils.sh without changing behavior. The bracket-depth arithmetic that hook::_fast_file_path_to and hook::_fast_fields each spelled out is now one helper, hook::_key_depth_is_one, which counts brackets with two substitutions instead of four. hook::_fast_fields shares one value case between top-level and nested keys. hook::_physical_prime reuses hook::_split_lines instead of an inline copy of it. hook::json_str_object_to and hook::read_file_path's read loop are shorter. Design choice (basis: the existing hook::_temp_win_spellings already calls hook::_split_lines through dynamic scope): reuse within the file only, with no code moved between files, per the issue's out-of-scope list. Ran scripts/sync-shared-copies.sh (20 copies) and added a patch fragment for each carrier plugin.

Not verified

  • lib/hook-utils.test.sh and the plugin hook test suites were not run: this lane's Bash runs only the named wrappers, so the suites are left to the PR's CI (they cover hook::_fast_fields against jq, hook::json_str_object_to against jq -nc, and hook::read_file_path)
  • ci-status green on the PR: a PR check left to CI
  • Tidy not run: the change touches lib/ (a listed shared path) and 41 files, over the 10-file and 300-line cutoffs
  • check-affected skipped typos (not installed) and the checks that run code from the checked tree; CI runs them

Fix

  • lib/hook-utils.sh: new hook::_key_depth_is_one replaces the duplicated depth arithmetic in hook::_fast_file_path_to and hook::_fast_fields; hook::_fast_fields merges its two identical value-classification case blocks; hook::_fast_file_path_to folds an if/else into a guard and drops…
  • plugins/{animation,autonomy,bash-format,biome-format,context-guard,desktop-notification,eol-normalizer,explainer-video,go-format,guardrails,harness-ops,markdown-format,playwright,rate-limit-guard,ruff-format,source-control,speech,testing,typos-format}/hooks/hook-utils.sh and…
  • .changes/<plugin>/work-resolve-issue-issue-14331-42568373896-1-*.md (20 files, one per carrier plugin): bump patch, Changed entry for the shared hook-utils.sh sync.

Verification

The runner ran each check from the base copy against 396db28:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • sync-shared-copies wrapper: regenerated 20 copies, exit status 0
  • new-changelog-fragment --carriers-of lib/hook-utils.sh patch: wrote 20 fragments, exit status 0
  • check-changelog-fragments: all 22 changelog fragments under .changes/ are valid
  • check-changed-skills: plugins/repo-hygiene/skills/clean PASS, 0 errors, 4 warnings that were there before this change (description length, body length)
  • check-affected: 13 passed, 6 skipped over 41 changed files
  • fresh-context review subagent over the lib/hook-utils.sh diff: every hunk EQUIVALENT (depth helper bracket patterns under LC_ALL=C, merged case paths, _split_lines dynamic scope and no empty fields under IFS newline, separator on empty/odd args, read loop on empty input and trailing NUL); no…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42568373896

Left out: the items under Not verified.

Related

#14331

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 396db28329992ac7a62c716b6362e0f9ff1d3694: read 41 of 41 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #14349 (refactor of lib/hook-utils.sh, first third)

No security issues found.

Scope read. I read every hunk of these files:

  • lib/hook-utils.sh
  • plugins/animation/hooks/hook-utils.sh, the first path of the 20-copy identical set. Its hunks match the lib/ hunks apart from line offsets.
  • .changes/animation/…-035d4b09.md, the first path of the 19 identical fragments.
  • .changes/repo-hygiene/…-a96892a2.md, which differs only in saying "scripts" where the others say "hooks".

The copy at plugins/repo-hygiene/skills/clean/scripts/hook-utils.sh is a sourced library under a skill's scripts/ directory. That location doesn't change what its content does. No manifest, workflow, settings, hook registration or trusted path is touched.

Why I checked it closely. This library parses hook payloads (tool_input.file_path, and fields via hook::_fast_fields) and resolves physical paths for guardrail hooks. If the refactor changed behaviour, a hook could end up checking a different path than the one the tool actually touches. I checked each hunk for that:

  • hook::_key_depth_is_one (lib/hook-utils.sh:1323-1327) replaces the four-substitution bracket count with ${pre//[^\{\[]/} and ${pre//[^\}\]]/}. The bash glob matcher treats a backslash inside a bracket expression as an escape, so the result is the same open-minus-close count over the placeholder skeleton, where every bracket is structural. A wrong answer here would be caught by the existing jq-parity tests the PR says CI runs. A count that came out wrong in either direction would only send the fast path to the jq fallback (return 2), or it would need a duplicate key, and duplicate keys are already rejected (__hu_idx=-1 leads to return 2).
  • hook::_fast_fields: the merged value case (lib/hook-utils.sh:1548-1556) runs on the top-level token or on the nested token that the k2 block assigns at :1546. That is the same branch structure as the two removed copies.
  • hook::_fast_file_path_to: the __hu_raw to __hu_file rename is safe. hook::json_unescape_to takes its source as $2, which is expanded before the call, and it declares no __hu_file local (:1288).
  • hook::_physical_prime now uses hook::_split_lines (:895-903). Splitting on IFS newline already drops empty fields, so removing the per-line non-empty check changes nothing, and a count mismatch still makes it store nothing. One small difference: IFS is no longer left set to newline for the expand_8dot3_to loop. That loop's code is fully quoted (:640-659), so this has no effect.
  • hook::json_str_object_to: the ${out:+,} separator gives the same output. Every pair is at least "":"", so the string is never empty after the first pair. Escaping still goes through json_escape_jq_to.
  • hook::read_file_path: read -d '' assigns the partial chunk at EOF, so the final append keeps the same chunk list, NUL splits included.

Other checks

  • Instruction-surface lens: not applicable. The diff deletes no standing instruction, hook block list or allowlist.
  • No trust control is widened. No token scope, secret handling or billable resource is touched.
  • Nothing in the PR context reads as an instruction to this lane.
  • Spend: none.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed 396db28329992ac7a62c716b6362e0f9ff1d3694: read 41 of 41 changed file(s); 0 finding(s), 0 as inline comments.

Code review: refactor(hooks): simplify the first third of lib hook-utils.sh

No blocking or advisory findings.

Scope read

  • I read every hunk of lib/hook-utils.sh.
  • I read the first path of each identical-copy group: plugins/animation/hooks/hook-utils.sh stands for 20 generated copies, and the animation fragment stands for 19 fragments. I also read .changes/repo-hygiene/…a96892a2.md, which is not identical to the others because it says "scripts" where they say "hooks".
  • The copies' hunks match the lib/ change, shifted 2 lines for the generated header.
  • Every copy sits at a sourced-library path (hooks/hook-utils.sh, or skills/clean/scripts/hook-utils.sh for repo-hygiene), so a copy's path does not change what its content does. Each fragment sits under its own plugin's .changes/<plugin>/.

Equivalence checks (my reading of the code; I could not run anything)

  • hook::_physical_prime → hook::_split_lines. The helper at lib/hook-utils.sh#L895 fills the caller's local __hu_lines through dynamic scope, the same way hook::_temp_win_spellings already uses it.
    • Dropping the per-line -n check changes nothing. With IFS=$'\n', word splitting folds empty lines away, so an empty realpath line already shows up as a count mismatch.
    • IFS used to stay $'\n' for the rest of the function. Now it does not, but the loop and hook::expand_8dot3_to quote everything, so nothing depends on it.
  • hook::_key_depth_is_one. It counts {/[ minus }/] before the first "#<n>", using two bracket-class substitutions instead of four. That gives the same arithmetic as the old code.
    • Both callers run under LC_ALL=C (the _c_locale guard), and the skeleton only contains structural brackets.
    • Its locals are __hu_-prefixed, so they do not shadow anything either caller reads afterwards.
  • hook::_fast_file_path_to. The if/else became a guard with the same return codes. Its json_unescape_to __hu_file "$__hu_file" passes the value as $2, so writing the result back into the same variable is safe.
    • Removing __hu_raw and __hu_pre from the local list leaks nothing: neither is used in the function any more.
  • hook::_fast_fields. The two identical value-classification case blocks are now one shared block after the k2 branch. Every exit from the k2 branch either continues, returns, or leaves the nested token in __hu_tok, so control flow is unchanged. __hu_raw is still declared local at L1455.
  • hook::json_str_object_to. ${__hu_out:+,} gives the same separators as the old first-pair flag: after the first pair the string is never empty, even for "":"". Zero pairs and an odd trailing argument both still give {} and ignore the leftover.
  • hook::read_file_path. The chunk is reset after each append rather than before each read, and the final append keeps what read held at EOF. The chunk sequence is the same, including for empty input and a trailing NUL.

Closing issue #14331 acceptance criteria

  • Behavior unchanged. I found no behavior difference (see above). lib/hook-utils.test.sh exercises _fast_file_path_to, json_str_object_to and read_file_path, and _physical_prime is reached from the guardrails and harness-ops suites. The author's equivalence review and test coverage claims are author-claimed and unverified: the PR says the suites were not run.
  • Diff edits only the listed file, its generated copies and changelog fragments. Met.
  • Within 400 changed lines and 15 hand-edited files. Met: one hand-edited file, about 200 changed lines in lib/hook-utils.sh.
  • ci-status green. Not judged here: it is left to CI.
  • Only functions that start in range 1 (L1–1758) changed. Met. _physical_prime, _fast_file_path_to, _fast_fields, json_str_object_to, read_file_path and the new helper all start below L1758.
  • sync-shared-copies.sh run and copies committed. Met: the 20 copies match the lib/ change.

Rules and embedded text

  • .claude/rules/mod-authoring.md matches the plugins/*/hooks/** copies. It covers hooks modules and hooks.json, not this sourced library, so it does not apply. The skill-bodies-state-current-rules rule matches the repo-hygiene script copy, which has no skill body text.
  • I found no embedded instructions in the PR context or prior-findings files.

No plugin manifests changed. Spend: none beyond this review run.

@melodic-automation-lanes melodic-automation-lanes Bot added the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 9, 2026
@melodic-automation-lanes

melodic-automation-lanes Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped fix-ci on this pull request: the lane could not fix every failing check, after one retry a model rung up, so a session builder takes it; its run log names each one and why. The lane labels it needs-session for a session builder, who makes the change this lane cannot, and the run ends in a failing pr-unblock/fix-ci status on the head the lane gated.

When a retry on this head can change the outcome, the lane runs one on its own, up to its per-head cap, and edits this comment if it stops again; a run that does not stop clears the status. When no retry can (a review thread the lane does not take or settle, or a failing check after the retries are spent), a person resolves the threads or gets the checks green, then dispatches the workflow below: that run finds the cause gone and clears the status. On a pull request the lanes App opened, the dispatchers start that run once per stop; on any other, a person does. A new commit to the branch starts clean.

To run it again on this head now, dispatch the pr-unblock workflow:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=14349 -f activity=fix-ci

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 396db28329992ac7a62c716b6362e0f9ff1d3694. The lanes clear this reason on their own; the next scheduled run judges it again.

a pr-unblock lane stopped its head (pr-unblock/fix-ci is failure), which clears when the lane runs
  again

@melodic-automation-lanes melodic-automation-lanes Bot removed the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 9, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 1aa7c5b Nov 9, 2026
141 of 147 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-14331-42568373896-1 branch November 9, 2026 07:01
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.

Simplify the hook-utils.sh shared lib source (part 1 of 3)

1 participant