Skip to content

fix(git-hooks): run hook entries and the commit-msg hook without calling bash by name - #9976

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9774-40182381805-1
Oct 25, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9774-40182381805-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #9774

Summary

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

Every git-hook entry the plugins install, the shared check lib, the plain dispatcher, the lefthook remote and the convention resolver now start as #!/bin/sh and never run a bash looked up by name, which on Windows can be System32's WSL launcher: commit-msg-convention and the resolver are POSIX sh throughout, and the other entries source check-lib.sh first, which reruns them under the first bash on PATH outside System32 (or applies the missing-tool rule) and turns POSIX mode off when that bash started as sh. The installer's dispatcher runs #!/bin/sh entries with sh (an older copy by its own first line until refreshed) and replaces an earlier release's dispatcher instead of refusing it; lefthook and husky run lines are sh <path>, and a new lib/git-hooks/sh-entries.test.sh asserts all of it, with the commit-msg and resolver tests now running under dash. Hold: a human merges this (it changes a commit gate).

Not verified

  • No test suite ran in this lane (its Bash runs only the named wrappers, and check-affected runs without --tests): scripts/run-test-file.sh on lib/git-hooks/sh-entries.test.sh, plugins/guardrails/git-hooks/commit-msg-convention.test.sh, lib/git-hooks/install.test.mjs, lib/git-hooks/install.test.sh, li
  • The issue's done-when asks for Hold: a human merges this in the PR body; the lane writes the body, so it is in this summary but not otherwise set by this run
  • Existing consumers whose lefthook or husky config already holds an older bash <path> run line keep it: plan treats the path as wired and offers no replacement, so those configs still start bash by name until someone edits them
  • Nothing ran on Windows: Git for Windows' sh, Visual Studio's bundled git and lefthook's runner: sh there are unexercised; the new test stands in with bash invoked under the name sh and with dash on Linux
  • Review finding left as is: commit-msg-convention.sh truncates the resolver's diagnostic at 300 bytes (printf %.300s) where the bash version cut at 300 characters, so a long message can end mid-character
  • No second review pass ran after the fixes to the four review findings
  • The issue's statements that Visual Studio's bundled git ships sh.exe and no bash.exe and that MSYS sh.exe is bash in POSIX mode were not written into docs, comments or fragments as facts: no host this run may read documents them
  • Inside this lane's Bash sandbox, git status shows untracked .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile and .zshrc at the repo root; the Read tool finds none of them, so they look like sandbox mount points rather than files of this change, which thi

Fix

  • lib/git-hooks/check-lib.sh: #!/bin/sh shebang plus a POSIX preamble (one brace group) that finds the first bash on PATH outside System32, Sysnative and WindowsApps; under a non-bash sh it reruns the script there once (CHECKS_REEXEC guard) or applies the contract's missing-tool rule to bash (SKIPPED
  • lib/git-hooks/install.mjs: the plain dispatcher runs an entry whose first line is #!/bin/sh with sh and any other entry by its own first line (no bash command); exported PRIOR_DISPATCHERS holds the previous dispatcher text, which dispatcherState reports as prior so copy replaces it instead of refu
  • lib/git-hooks/install.test.mjs: the fixture entry takes the sh-entry shape; snippet expectations read sh; new cases for replacing an earlier release's dispatcher and for an old bash-shebang entry still running under the new dispatcher
  • lib/git-hooks/sh-entries.test.sh (new): asserts line 1 is #!/bin/sh and no line runs bash as a command (self-tested pattern) for every entries.json script, check-lib.sh and its 10 copies, the dispatcher read from install.mjs, the resolver and its copy, and the .lefthook wrappers; asserts lefthook-re
  • lib/resolve-convention-pattern.sh: rewritten from bash to POSIX sh (no local, [[ ]], substrings or =~) with the same outputs, exit codes, diagnostics and external-command spawns; --help skips the shellcheck directive line
  • lib/resolve-convention-pattern.test.sh: runs the resolver under dash where installed (else sh), adds a bash parity case and a --help content case
  • plugins/guardrails/git-hooks/commit-msg-convention.sh: rewritten as POSIX sh; runs the resolver with sh; printf instead of echo for variable text; heredoc instead of a pipe into grep -q
  • plugins/guardrails/git-hooks/commit-msg-convention.test.sh: runs every case under dash where installed (else sh); the stub resolver is POSIX sh
  • plugins/guardrails/git-hooks/lefthook-remote.yml: every job's runner is sh
  • plugins/guardrails/git-hooks/lefthook-remote.test.sh: parses exec sh from the wrappers, asserts each job's runner is sh, runs the wrappers under dash where installed
  • .lefthook/commit-msg/guardrails-commit-msg-convention.sh, .lefthook/pre-commit/guardrails-pre-commit-content.sh, .lefthook/pre-push/guardrails-reference-verify.sh: POSIX sh wrappers that convert backslashes with tr and exec the entry with sh
  • plugins/guardrails/git-hooks/pre-commit-content.sh, plugins/guardrails/git-hooks/reference-verify.sh, plugins/actionlint/git-hooks/actionlint-check.sh, plugins/bash-format/git-hooks/shell-check.sh, plugins/biome-format/git-hooks/biome-check.sh, plugins/go-format/git-hooks/goimports-format.sh, plugin
  • plugins/guardrails/git-hooks/reference-verify.sh: starts run-guards.sh through checks_bash_run instead of bash
  • plugins/instruction-placement/git-hooks/index-check.sh: starts render-index.sh through checks_bash_run instead of bash
  • plugins/{actionlint,bash-format,biome-format,go-format,guardrails,instruction-placement,markdown-format,powershell-format,ruff-format,typos-format}/lib/git-hooks/check-lib.sh and .../install.mjs (20 files): regenerated copies of the canonicals via scripts/sync-shared-copies.sh
  • plugins/guardrails/hooks/resolve-convention-pattern.sh: regenerated copy of the POSIX resolver
  • docs/conventions/check-placement/README.md: new Shell row in the check-script runtime contract; the dispatcher's first-line rule; an earlier release's dispatcher counts as the plugin's own
  • plugins/guardrails/README.md: Git hooks section says every entry starts under sh and names no bash, and commit-msg-convention is POSIX sh throughout
  • .changes/{actionlint,bash-format,biome-format,go-format,guardrails,instruction-placement,markdown-format,powershell-format,ruff-format,typos-format}/fix-9774-run-git-hooks-without-bash-5d2c8e1a.md (10 new files): patch fragments describing the change for each carrying plugin

Verification

The runner ran each check from the base copy against dfc282f:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • .lane/checks/bin/check-changelog-fragments: "All 11 changelog fragment(s) under .changes/ are valid."
  • .lane/checks/bin/check-affected (--uncommitted, covers changelog-fragments --check and --check-required against base 1e0c778): "10 passed, 6 skipped over 57 changed files"; shellcheck failed on earlier runs (SC1072 from a comment starting # shellcheck, SC1003 on tr '\', SC2209 on unquoted sh valu
  • .lane/verify/bin/sync-shared-copies --check: "All 521 registered copies match their canonical sources."
  • .lane/verify/bin/cant-fail-scan --check --file on lib/git-hooks/sh-entries.test.sh, lib/git-hooks/install.test.mjs, lib/resolve-convention-pattern.test.sh, plugins/guardrails/git-hooks/commit-msg-convention.test.sh, plugins/guardrails/git-hooks/lefthook-remote.test.sh: PASS, no gating findings, for
  • Grep with the new test's command pattern over every entry script, check-lib.sh and copies, the resolver and copy, and the .lefthook wrappers: no line runs bash as a command (only shfmt-rewrite.sh, a sourced asset, not an entry, matches)
  • Local review in one fresh-context subagent over the whole diff: 5 findings; fixed 4 (children of a bash started as sh ran in POSIX mode, so checks_bash_run and CHECKS_CHILD_BASH; the new dispatcher would run other plugins' not-yet-refreshed bash entries under sh, so the first-line rule; the test pat
  • CI gate rules read and checked by hand for the new and changed files: pipefail-grep-q (the commit-msg hook's printf | grep -Eq became a heredoc), fixture-git-isolation (the new test unsets GIT_DIR, GIT_WORK_TREE, GIT_CONFIG), test-tmp-cleanup (trap ... EXIT present), silent-skips and discriminating-
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/40182381805

Left out: the items under Not verified.

Related

#9774

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

Copy link
Copy Markdown
Contributor

claude-security-review reviewed dfc282fe69e33d7ee4dc4b9ebdbc4477cf547496: 0 finding(s), 0 as inline comments.

No security issues found in this pull request.

critical-findings: 0

I could not run Bash in this lane. I read .claude-lane/pr.diff with Read and Grep, and .claude-lane/pr-context.md for the PR description.

What I reviewed. I read the canonical changes in full: the three .lefthook/* wrappers, lib/git-hooks/check-lib.sh, lib/git-hooks/install.mjs (the dispatcher, PRIOR_DISPATCHERS and dispatcherState), lib/resolve-convention-pattern.sh, commit-msg-convention.sh, lefthook-remote.yml, and the guardrails pre-commit-content.sh and reference-verify.sh. The per-plugin check-lib.sh and install.mjs files are generated copies, and the PR reports they match the canonical sources. I did not read the other entry scripts, the test files, the docs or the .changes fragments line by line.

Trusted paths and manifests.

  • No changed file matches .github/standards/trusted-actors/**, .github/actions/check-trusted-trigger/**, **/CODEOWNERS or **/.gitmodules.
  • No plugin.json or marketplace.json is changed, so there are no manifest lines to report.
  • The diff does not change any workflow or permissions.
  • The PR description contains no embedded instructions aimed at the review.

Checks that came out clean.

  • Bash lookup in check-lib.sh. It skips relative PATH entries. It also skips System32, Sysnative and WindowsApps. The rerun is guarded by CHECKS_REEXEC, so it cannot loop. The variable is unset once bash is running.
  • Dispatcher. An entry whose first line is #!/bin/sh runs with sh. Any other entry runs directly and fails closed if it is not executable. Only exact prior dispatcher text is treated as the plugin's own and replaced. A modified hook that carries the sentinel is still modified and is not overwritten without --force.
  • Resolver rewrite.
    • The checks that reject absolute paths, .., backslashes, symlinks and paths outside the repo root are kept.
    • The physical-root prefix test is still a literal comparison, not a glob.
    • A pattern that is not POSIX ERE, or that does not compile, still turns enforcement off with exit 1.
  • commit-msg hook. The unquoted heredoc expands $subject only once, so subject text is not re-expanded. The comment-character test uses a quoted pattern, so it is literal. The resolver's diagnostic is capped at 300 bytes.
  • Lefthook wrappers. They convert backslashes with tr and keep the */info/lefthook-remotes/* gate, so only the fetched copy runs.

Behaviour to know about (not a finding). When the shell is not bash and no usable bash is on PATH outside the WSL-launcher directories, an entry does not run. A person gets a NOTICE and exit 0. An agent (CLAUDECODE=1 or AI_AGENT) gets a FAIL and exit 1. checks.skipmissing=bash also skips it. This is the existing missing-tool rule from the check-placement contract, applied to bash. A cloned repo cannot set checks.skipmissing, because it lives in local git config.

Spend. No change to model, turn limits or schedule frequency, so none to report.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed dfc282fe69e33d7ee4dc4b9ebdbc4477cf547496: 0 finding(s), 0 as inline comments.

Code review: no findings

I read all 57 changed files in .claude-lane/pr.diff and the PR context. For the installer I also read the head lib/git-hooks/install.mjs (copy, wiring, dispatcherState). I could not run anything: Bash is disabled in this lane. Every test and check result below is author-claimed and I did not verify it.

What I checked, and what held up

  • lib/git-hooks/check-lib.sh preamble. It handles the three start modes correctly: plain sh, bash started as sh, and bash.
    • It scans PATH for the first bash outside System32, Sysnative and WindowsApps.
    • It reruns the entry once under that bash, guarded by CHECKS_REEXEC, which is unset afterwards.
    • With no bash it follows the missing-tool rule: SKIPPED when checks.skipmissing names bash, FAIL for an agent, NOTICE for a person.
    • set +o posix comes after the POSIX-only block, so the bash-only functions below it parse normally.
    • checks_bash_run has a fallback for the no-other-bash case that sources the script in a child with POSIX mode off.
    • The CLAUDE_PLUGIN_ROOT="$root" checks_bash_run … call in reference-verify.sh still exports that variable to the child, because POSIX mode is off by then.
  • Dispatcher and installer.
    • The head DISPATCHER matches the previous release's text, which PRIOR_DISPATCHERS reproduces apart from the feed bash line.
    • copy replaces a prior dispatcher, since it refuses only on modified.
    • Other plugins' not-yet-refreshed bash entries still run, executed by their own first line.
    • wiring uses the exact-match isDispatcher, so an old dispatcher shows as "not wired" until copy runs. That prompts the refresh, which is the intended outcome.
  • POSIX conversion of the resolver and commit-msg-convention.sh. I found no behaviour change.
    • The case patterns, the canon_dir_slash#"$canon_prefix" containment test, grep_rc, and the heredoc into grep -Eq all look equivalent.
    • Dropping pipefail changes nothing, because no pipeline's exit status was used.
    • The truncation at 300 bytes instead of 300 characters is acknowledged in the PR as a known gap.
  • .lefthook wrappers and lefthook-remote.yml. $0 plus tr '\134' '/' reproduces the backslash normalisation, and exec sh and runner: sh are consistent.
  • Plugin manifests. The PR changes no plugin.json or marketplace.json, so there are no manifest <field> lines. Each of the 10 touched plugins has a bump: patch fragment, which fits a fix.
  • Trusted paths. None of the globs (trusted-actors, check-trusted-trigger, CODEOWNERS, .gitmodules) matches a changed file. This is a commit gate, but nothing in it is a critical security issue, so there is no hold.
  • Cost. The PR adds no paid resource or billing setting, so no cost hold.

Closing issue #9774, done-when items

  • Present in the diff:
    • The new sh-entries.test.sh asserts no entry, dispatcher or resolver names bash as a command.
    • The commit-msg and resolver tests run under dash.
    • install.test.mjs is updated and covers the prior-dispatcher replacement.
    • The fragments for every changed plugin are there.
    • The sync-shared-copies copies are regenerated.
  • Author-claimed and unverified by me: that scripts/run-test-file.sh exits 0 on those test files, and that sync-shared-copies --check and check-changelog-fragments --check-required pass.
  • Hold: a human merges this appears only quoted inside the PR body's run summary. The PR itself says the lane did not set it separately, so a person should add it if they want the criterion literally met.

Residual risks the author already lists, which I agree with

  • Consumers whose lefthook or husky config already holds an older bash <path> run line keep it, and still start bash by name until someone edits it.
  • Nothing ran on Windows, so Git for Windows' sh, Visual Studio's bundled git and lefthook's runner: sh there are untested.

Embedded text. The PR context contains no instructions aimed at the reviewer. Its fullwidth #! characters look like sanitisation of the shebang text.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head dfc282fe69e33d7ee4dc4b9ebdbc4477cf547496.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 25, 2026
Merged via the queue into main with commit afdeb1e Oct 25, 2026
45 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-9774-40182381805-1 branch October 25, 2026 11:35
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

pr-merge's gate holds it on its risk score (evidence-unbound:claude-review: not bound: no-run; evidence-unbound:claude-security-review: not bound: no-run)

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.

fix(git-hooks): run hook entries and the commit-msg hook without calling bash by name

0 participants