Skip to content

feat(guardrails): add a pre-push-content git hook that scans each pushed commit - #11990

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-10150-41322377809-1
Nov 1, 2026
Merged

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

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10150

Summary

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

Adds the guardrails pre-push-content git-hook entry from the decision recorded on #10150. It runs the pre-commit secrets and machine-path scan on the lines each pushed commit adds to its parent, for every pushed ref. So a token that one commit adds and a later commit of the same push removes still fails the push. A merge is judged only on what it adds against every parent, and commits a remote-tracking ref already holds are skipped. The scan moved out of pre-commit-content.sh into git-hooks/content-scan.sh, which both entries source and install as an asset, so it is shared and not copied. The entry honors checks.guardrails.pre-push-content.declined the way reference-verify does. It is wired into entries.json, the lefthook remote (a second sequential use_stdin pre-push job) and a new .lefthook/pre-push wrapper. Choices made on evidence: content-scan.sh lives beside the entries in git-hooks/ so $here/content-scan.sh resolves both in the plugin and in an installed copy. Findings carry a (commit <id>) suffix inside the <path>:<line>: <message> format, since the fix is to rewrite that commit.

Not verified

  • No test suite was executed here: this lane's Bash runs only the named wrappers, so pre-push-content.test.sh, pre-commit-content.test.sh, lefthook-remote.test.sh, reference-verify.test.sh, git-hooks-notice.test.sh and lib/git-hooks/sh-entries.test.sh (through scripts/run-test-file.sh) are left to the
  • Not fixed, reviewer finding: install.mjs copy computes each entry's state just before writing it. When a release changes a file two installed entries share beside each other, refreshing the first entry rewrites it, and the second then reads as 'modified' and is refused without --force. check-lib.sh
  • Reviewer note, unverified: replaying pre-push stdin to more than one use_stdin job needs a lefthook release that shares stdin across jobs (the reviewer cites 1.6.14). The check-placement README already documents this behavior for lefthook 2.2.2, so I added no version gate.
  • Tidy skipped: the change is 14 files and about 700 changed lines across 3 areas (plugins/guardrails with .changes/guardrails, .lefthook, lib), and touches the shared path lib/, so it is over the tidy cutoffs (10 files, 300 lines, 1 area).
  • The new .sh files (content-scan.sh, pre-push-content.sh, pre-push-content.test.sh, the .lefthook wrapper) could not be chmod +x here; this relies on the lane's patch apply making new #! and .sh files executable, as check-affected's exec-bit note describes.
  • git status inside the sandbox lists untracked .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile and .zshrc at the checkout root. The Read and Glob tools find none of them, so they look like sandbox mount artifacts. This run did not create them and left th

Fix

  • plugins/guardrails/git-hooks/content-scan.sh: new; the scan moved out of pre-commit-content.sh (pattern libraries, tool-failure wrappers, exemptions, per-file judging), wrapped as content_scan_init / content_scan / content_report. Adds a skip for a file whose blob another merge parent already holds,
  • plugins/guardrails/git-hooks/pre-commit-content.sh: now sources content-scan.sh and calls it; messages and behavior unchanged.
  • plugins/guardrails/git-hooks/pre-push-content.sh: new pre-push entry: decline keys, then each commit of each pushed range (rev-list base..tip excluding the remote's tracking refs) judged against its parents' intersected added lines; --worktree mode too.
  • plugins/guardrails/git-hooks/pre-push-content.test.sh: new contract test. Direct cases: clean push, planted token, home path, add-then-remove, tests/fixtures exemption, update range, stacked-on-pushed-branch, deletion, merges of the remote's main (text and binary), an evil merge, the decline keys an
  • plugins/guardrails/git-hooks/entries.json: pre-push-content entry (event pre-push, rewrites false, content-scan.sh plus the three pattern libraries as assets); content-scan.sh added to pre-commit-content's assets.
  • plugins/guardrails/git-hooks/lefthook-remote.yml: guardrails-remote-pre-push-content job (runner sh, use_stdin true), jobs kept sequential, with a comment saying why.
  • .lefthook/pre-push/guardrails-pre-push-content.sh: new lefthook-remote wrapper, same shape as the reference-verify one.
  • plugins/guardrails/git-hooks/lefthook-remote.test.sh: expects two pre-push jobs and four ok entries; test-scope names the new files.
  • plugins/guardrails/git-hooks/pre-commit-content.test.sh: test-scope names content-scan.sh; the installed-asset loop also checks content-scan.sh.
  • lib/git-hooks/sh-entries.test.sh: the lefthook remote now has 4 sh-run scripts.
  • plugins/guardrails/README.md: count line and Git hooks intro say four checks; new pre-push-content table row.
  • plugins/guardrails/skills/setup/SKILL.md: install-git-hooks body and description name the pre-push content entry.
  • plugins/guardrails/skills/setup/reference/git-hook-decisions.md: lefthook-config row no longer says only one job gets the refs; it now matches the check-placement README's sequential-jobs rule.
  • .changes/guardrails/work-resolve-issue-issue-10150-a7d3c510.md: minor changelog fragment (Added and Changed).

Verification

Planted-token runs and pre-push budget, from CI on head d70b888: pre-push-content.test.sh in the test-bash (4) job of pr-require-checks (job log, run) printed, verbatim:

measured: pre-push-content took 1 s on a 20-commit, 40-file-change push
ok: the entry passes the 20-commit push
ok: the entry runs within the 60 s pre-push budget
planted-token push of dossier/GH-7579-pre-push-secrets: exit 1
push of dossier/GH-7579-pre-push-secrets after the planted commit is dropped: exit 0
  • Planted-token push: exit 1 (non-zero, push refused); after the planted commit is dropped: exit 0.
  • Measured duration on the 20-commit push: 1 s, against the 60 s pre-push budget (about 1.7% of it); the test's budget assertion passed.

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

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

The run reports:

  • .lane/checks/bin/check-changelog-fragments: All 153 changelog fragments under .changes/ are valid.
  • .lane/checks/bin/check-changed-skills: CHECK-SKILL setup PASS, 0 errors, 7 warnings. The description is 1009/1024 codepoints (was 996), and the other warnings are about size and gotchas.
  • .lane/checks/bin/check-affected: first run failed shellcheck SC2154 in content-scan.sh (here, CHECKS_TMP and CHECKS_MODE come from the caller); fixed with a file-level directive; rerun after the review fixes: 12 passed, 6 skipped (ruff no .py, typos not installed, validate-plugins and changed-skills
  • .lane/verify/bin/cant-fail-scan --file plugins/guardrails/git-hooks/pre-push-content.test.sh --check: PASS, no gating findings, 1 test file fully read.
  • Fresh-context review subagent over the whole diff (read-only): it traced every expect in pre-push-content.test.sh, pre-commit-content.test.sh, lefthook-remote.test.sh and sh-entries.test.sh and predicted all of them pass. It raised a merge false positive on files judged whole (fixed: from_other_pare
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41322377809

Left out: the items under Not verified.

Related

#10150

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

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #11990, guardrails pre-push-content git hook

No security issues found.

critical-findings: 0

What I checked

I read every hunk of all 14 changed files. None of them matches a TRUSTED PATHS glob. No .claude-plugin/plugin.json or marketplace.json changed, so there are no manifest items. No trust control changed: trusted-trigger, lane token, kill switch, resolve-config/broker, merge holds and .github/actions/* are all untouched.

  • content-scan.sh is a straight extraction from pre-commit-content.sh. The patterns, the path and secret exemptions, the NUL-byte whole-file secret pass, the scan_tool failure wrappers and the 1 MiB skip all match the base. The pre-commit entry still sources check-lib, the scan and then checks_init, as before. scan_error starts at /dev/null and is only checked after content_scan_init has pointed it at $CHECKS_TMP/scan-error.
  • The only new skip in the scan is from_other_parent. It is a no-op for pre-commit because other_parents is empty there. In pre-push it skips a file whose blob another merge parent holds at the same path. That parent's own commits are still listed by rev-list "$tip" --not "$base" --remotes="$remote", so they are judged individually unless a remote-tracking ref already holds them. A secret on an unpushed side branch is caught on the side commit itself.
  • Failures fail closed.
    • When git rev-list fails, pre-push-content.sh calls checks_tool_failed, which writes $CHECKS_TMP/tool-failed. The EXIT trap at check-lib.sh#L159, through checks_finish at #L170-L175, then turns an exit 0 into a failure.
    • When rev-list --parents fails, the commit is diffed against the empty tree, which means a full scan rather than a skip.
  • No injection paths. The remote name (${CHECKS_ARGS%% *}), commit ids from rev-list and NUL-delimited paths from --raw -z are all passed to git as quoted arguments. Nothing reaches eval or an unquoted command.
  • Decline keys. checks.guardrails.pre-push-content.declined and checks.git-hooks.declined are local git config. They can only be set by the person who owns the clone, so they open no new bypass beyond the --no-verify that any client-side hook already allows.
  • Lefthook remote (lefthook-remote.yml, .lefthook/pre-push/guardrails-pre-push-content.sh). This adds a second sequential pre-push job. Consumers of the remote will run it after their next remote sync. The script only reads local git objects and writes to stderr, with no network calls and no credentials, so it gives the pull request author no path to a leak, compromise or charge. The wrapper has the same shape as the existing reference-verify wrapper.
  • Instruction surface. The setup SKILL.md and git-hook-decisions.md changes add to the guidance and correct the lefthook stdin note. They remove or soften no guardrail. I did not consult the instruction-exception register's protected-class list, but nothing was deleted, so the lens did not apply.

Embedded text

The PR context file contains no directives aimed at the review lane.

Spend

This change adds no billed resource. Locally, each push now also runs the content scan; the PR's test caps it at 60 s for a 20-commit push.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no blocking findings

I read every hunk of all 14 changed files. None of them match a trusted-path glob. To check behaviour I also read check-lib.sh (checks_init, checks_push_ranges, checks_diff, checks_changed_lines, checks_change_has_nul, checks_filter_findings) and install.mjs (copyState, copy, the asset handling). I ran nothing. Every test result the PR mentions is the author's claim and is unverified; the PR itself says no test suite was run.

What I checked and found sound

  • Moving the scan into content-scan.sh. pre-commit-content.sh keeps the same order: it sources the pattern libraries, defines the tool wrappers, calls checks_init, computes scan_root after the cd, then runs checks_changed_lines, the scan and the report. The messages are the same as before: checks_git_verb still prints "commit" for pre-commit. The wrappers now exist before checks_init, and scan_error=/dev/null covers that window. Defining scan_error that early is why content_scan_init must run before content_report, which both entries do. Per-call state (scan/, findings, hits, pool, names and the other arrays) is reset at the start of each call, so calling content_scan once per commit is safe.
  • Commit ranges in pre-push-content.sh. rev-list "$tip" --not "$base" --remotes="$remote" leaves out what the remote already holds. In commit_ranges, each parent's parent..commit ranges share the commit's line numbering, so intersecting them gives only the lines a merge adds against every parent. from_other_parent skips a file the merge takes whole from another parent. That parent's own commits are either judged in this push or already on the remote, so the skip loses nothing.
  • Failure handling. A failed rev-list goes through checks_tool_failed, so the hook exits 1. A failed wrapped awk/sed/sort goes to scan_error, and content_report then exits 1. A failed rev-list --parents makes the commit look like a root commit, so it gets scanned against the empty tree: more findings, not fewer.
  • Decline keys. They read the same way as in reference-verify.sh and install.mjs isDeclined: an unset key falls back to the master key, and a non-boolean value does not decline. The tests cover all three cases.
  • Wiring. entries.json assets, the lefthook remote job, and the new .lefthook wrapper (identical in shape to the reference-verify one) are consistent. The test counts are updated in sh-entries.test.sh (4 sh runners) and lefthook-remote.test.sh (four entries).
  • The new git-hook-decisions.md text about sequential use_stdin jobs matches docs/contracts/check-placement/README.md L159-161.

Closing issue #10150

  • "The pre-push step's test exits non-zero on a planted-token fixture and 0 after its revert, both…" (the criterion is cut off in the PR context). The end-to-end test does a real git push with a planted token and expects it to fail, then expects the push to pass once that commit is dropped. This reads "revert" the way the recorded decision does: a later commit that removes the token must still block (decision item 3). A literal git revert would rightly still fail, and the add-then-remove cases test that. The cut-off "both…" part most likely asks for the results to be recorded. The PR says the two exit codes and the timing are not yet in the PR body; they are printed only to the CI log. That part stays open until someone records them.
  • "Every slice sub-issue is closed by a merged PR." This is process tracking that code cannot satisfy. I could not check it.

Notes, not counted as findings

  • Installer refresh refusal (already present on main, now wider). When a release changes one file shared by two installed entries, copy refreshes the first entry and rewrites the shared file. The second entry's state is computed afterwards (install.mjs#L916), so it reads as modified and is refused without --force. check-lib.sh is already shared by every entry, so this is not new. This PR adds more shared files: content-scan.sh and the three pattern libraries are now shared by two entries. The PR lists this under "Not verified"; it is worth a follow-up issue.
  • Changelog fragment. bump: minor fits a new entry. No plugin.json or marketplace.json changed, so there are no manifest lines.
  • Spend. No hold class applies. The only new cost is local hook run time per push; the test holds that under the 60 s pre-push budget.
  • The PR context and closing-issue text contain no instructions aimed at the review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

pr-merge's gate refuses its verifier verdict (verify:fail)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 89a1f98 Nov 1, 2026
86 of 87 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-10150-41322377809-1 branch November 1, 2026 18:08
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 89a1f982d6529d051d049dbfb975d14ea70d66ce; later checks count it verified from this comment.

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.

source-control: dossier branches per owning item - part 2 of 2

1 participant