Repository navigation
Conversation
Kaap10
left a comment
There was a problem hiding this comment.
Thanks for working on this @mickwd! The implementation is clean, well-tested, and addresses both requirements from #1918 (the lefthook global option and package runner bypasses, and the command_name normalization).
The logic and test suite look solid. There is just one line-ending issue to fix before CI can turn green:
Line Endings (CRLF to LF)
The 6 modified files were committed with CRLF line endings from Windows. In Apache Magpie, the mixed-line-ending pre-commit hook enforces LF line endings.
You can renormalize the line endings locally and amend your commit with:
git add --renormalize .
git commit --amend --no-edit
git push --force-with-leaseAlternatively, running prek run mixed-line-ending --all-files will automatically convert them to LF.
Once line endings are normalized, this is ready to go!
|
Thanks for the review @Kaap10, glad the logic and tests look good! I checked the line endings, and the 6 files in this PR are already LF in the pushed commit (
So I think the CRLF you saw was a local checkout artifact, not something in the commit. CI hasn't actually failed yet. The workflows show Could a maintainer approve the workflow run? If |
c146748 to
6c14942
Compare
potiuk
left a comment
There was a problem hiding this comment.
Extends the lefthook-hooks-path guard to lefthook install behind global options and package runners, and normalises path-qualified and .exe command heads for every guard. I rebased the branch onto current main and pushed one commit restamping the isolated-setup fingerprint, which the prek check was failing on, so please pull before you push again (git pull --rebase). One gap is left, inline: a few runner spellings still get through.
Smaller observations
- See inline comments on
tools/agent-guard/src/agent_guard/__init__.py:2620.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. The findings
below are observations, not blockers; an Apache Magpie
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.More on how Apache Magpie handles maintainer review:
Contributing guide.
…ns and package runners The lefthook hooks-path guard took the first bare word as the subcommand, so `lefthook --colors off install --force` read `off` and was allowed, and `npx lefthook install --force` never reached the guard at all. Any `install` word now makes the segment an install, and npx, pnpm, yarn, bun and npm exec are looked through when they launch lefthook. argv[0] is normalised once with the helper guarded_head uses, so git.exe or a path-qualified git also reaches the git:* contributed guards. Closes apache#1918
Generated-by: Claude Opus 5
a66683c to
52571f0
Compare
potiuk
left a comment
There was a problem hiding this comment.
Thanks, a66683c6 covers every spelling from the last review: a runner's -c / --call / --shell-mode value and a shell it launches are now split like any other -c string, corepack is looked through, and .cmd / .bat are stripped like .exe, each with a test. I rebased the branch onto main again after #1899 merged (the only conflict was the isolated-setup fingerprint, restamped in the last commit), so please reset to the branch before you push again. Approving.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Magpie handles maintainer review:
Contributing guide.
Summary
lefthook --colors off install --forcereadoffand went through. Anyinstallword now makes it an install and every argument is checked, the same fail closed shape you suggested in the issuenpx,pnpx,bunx,pnpm exec/dlx,yarn exec/dlxandnpm execare looked through when they launch lefthook, including[email protected]and@evilmartians/lefthookargv[0]is normalised once inSegmentwith the samecommand_namehelperguarded_headuses, sogit.exeor/mingw64/bin/git.exenow reaches thegit:*contributed guards tooType of change
tools/*/withpyproject.toml)Test plan
test_skill_guards.pyfor every shape in the issue plus runner forms that must stay allowed (npm install --save-dev lefthook --force,npx lefthook run pre-commit --force,npx prettier --write install), andtest_no_verify_guard_denied_for_a_path_qualified_gitintest_guards.pypytest tests -k "lefthook or path_qualified"gives 77 passed, against the old code the same selection gives 28 failedtools/agent-guardsuite has the same failure set before and after this change. I ran it on Windows where a few existing tests fail for platform reasons (pwd, path separators), none of them touch this coderuff checkandruff format --checkpass, and the plugin copy of the engine is in sync--colors off installis a 1.x shape. Matching anyinstallword covers bothLinked issues
Closes #1918
Notes for reviewers
The runner unwrap takes the first word naming the lefthook package and does not parse each runner's own options. It can over match something like
npm run lefthook, but that only matters when the rest of the line also saysinstallwith a destructive flag, which felt like the right side to err on for a defence in depth guard.