Repository navigation
feat(hook-manager): add a pre-commit adapter - #2108
Conversation
68f2454 to
1ecd7b8
Compare
|
Rebased onto Two conflicts, both mechanical:
No source behavior changed. Hosted tests did not run for the old head; this push is the first run on a mergeable base. |
|
@wynneyin, thanks for the PR. It is still marked as a draft, so reviewers have not picked it up: when you'd like a full review, rebase it ( Two early notes from a quick read, in case they are useful before then:
|
1ecd7b8 to
5199bae
Compare
|
Rebased onto main ( Rebase. Two conflicts, both mechanical:
Note 1 — the marker. so a prek hook contains Note 2 — the cleanup. On Tests: No further changes made: no sign-off added and nothing else in the tree touched. The CI run on this push will say whether the |
KatalKavya96
left a comment
There was a problem hiding this comment.
@wynneyin, thanks for the PR.
Three things stood out: you checked the new pre-commit.com marker against the real pre-commit 4.7.0 and prek 0.5.10 hooks instead of trusting the text, and the helper tests now carry both fixtures; the unset cleanup removes only the value the helper wrote itself, with a test for each side; and you regenerated the doctoc block and the isolated-setup fingerprint with the method spelled out, so both are easy to check.
Should change
-
Commit trailer. Both commits (
fe9d0d90,5199bae5) end withCo-Authored-By: Claude Code <noreply@anthropic.com>. AGENTS.md says:MUST NOT use
Co-Authored-By:with an AI agent as co-author. [...] Use aGenerated-by:trailer instead.GitHub carries commit co-authors into the squash message, so this would land on
main. Rewording both commit messages to aGenerated-by:trailer and force-pushing fixes it.
Smaller points
- An operator's
PRE_COMMIT_HOMEis overwritten while the repository uses pre-commit (inline onsandbox-add-project-root.sh:442). - Spec.
tools/spec-loop/specs/agent-isolation-sandbox.mddescribes the prek and lefthook adapters but not pre-commit yet; the lefthook adapter (#1895) updated it in the same PR.
CI has not run on this head yet; I have approved the workflows so it runs alongside your fixes.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.More on how Apache Magpie handles maintainer review:
Contributing guide.
5199bae to
3c9c189
Compare
|
All three points are addressed on Commit trailer. My mistake: I added The trailer went in with Operator value while the repository uses pre-commit. Applied your swap — Spec. The fingerprint moved with the helper, so the chore commit now sets
|
|
Heads-up on CI: the runs for The changes themselves are in; the reply above describes them item by item. |
3c9c189 to
8f2831f
Compare
potiuk
left a comment
There was a problem hiding this comment.
Thanks, all three points from the earlier review are addressed: operator PRE_COMMIT_HOME is kept, the spec is updated, and the trailers are right. I rebased the branch onto main (dropping the fingerprint-only commit, which conflicted) and pushed a small fixup (8f2831f) that regenerates isolated_fingerprint.py and corrects the spec's flag to --hook-type=pre-commit. Please pull (or reset to the branch) before any further change.
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.
All three points are addressed on the current head (checked against the code); dismissing so the PR can merge. Thanks for the review.
8f2831f to
b92b03b
Compare
Contract: tools/hook-manager/README.md. Closes apache#1820. pre-commit writes to the common hooks dir but refuses to install while `git config core.hooksPath` returns anything, so it takes the `hide-global-config` strategy that apache#1895 landed for lefthook; the shim half of the issue already existed. What did not exist is a home variable that cannot spell `~`. `PRE_COMMIT_HOME` reaches `os.path.realpath` unexpanded, so the committed settings cannot name the sandbox home and a `~` value would resolve under the session's working directory. Option 1 from the issue, implemented: - registry: accept `home.expands_tilde: false` and register pre-commit with `nested: false` and `hook_marker: "pre-commit.com"`, the URL in the hook it generates (a `prek` hook carries only `--hook-type=pre-commit`, so the bare name would match another manager's install); - sync-hook-managers.py: carry the flag into the lint tuple, stop requiring the committed `env` entry for such a home (an absolute path is not portable), and generate a fourth block — adapter, variable and sandbox home — into sandbox-add-project-root.sh; - sandbox-add-project-root.sh: write the absolute sandbox home into the project-local settings.local.json when the repository uses the manager, and remove that value from one that does not; a value already in the file is the operator's, so it is kept where it is in both directions (detection follows the contract: root config, tracked nested config, or an installed hook naming the manager); - tools/spec-loop/specs/agent-isolation-sandbox.md: record the adapter beside the prek and lefthook ones, as apache#1895 did for lefthook; - sandbox-lint: for a home the tool does not expand, reject a `~` value and accept the absolute one; an absent value is not an error because the helper writes it per machine and the default home stays denied, so a sandboxed run without it fails instead of escaping. Verified against pre-commit 4.7.0 through the built tree: a bare install refuses with "Cowardly refusing to install hooks with `core.hooksPath` set", the shim installs to `$(git rev-parse --git-common-dir)/hooks/` leaving the shared dir empty, and a linked worktree lands in the main checkout's hooks. The dispatcher now exports a host-only PRE_COMMIT_HOME from the generated table, and the helper dry-run for this repository proposes `~/.cache/pre-commit-sandbox` as an absolute path. Marker: pre-commit 4.7.0's hook carries `https://pre-commit.com`; prek 0.5.10's carries `--hook-type=pre-commit` and no `pre-commit.com`, which is what the two hook fixtures in the helper's tests now assert. Tests: registry validation, the generated helper block, the helper's write/remove behaviour (including a foreign value surviving), the shim's hide-global-config path with a pre-commit-named stand-in, the dispatcher's host home, and the lint's absolute-versus-`~` rule. `pytest tools/agent-isolation/tests/test_sandbox_add_project_root.py tools/agent-isolation/tests/test_hook_manager_shim.py tools/agent-isolation/tests/test_git_hook_dispatcher.py tools/dev/tests/test_sync_hook_managers.py tools/sandbox-lint/tests` passes on the rebased tree: 690 passed. Generated-by: Claude Code (deepseek-v4.1-flash)
…ok flag After the rebase onto main, the isolated-setup fingerprint is regenerated, and the spec names the flag a prek-installed hook actually carries (`--hook-type=pre-commit`). Generated-by: Claude Opus 5
b92b03b to
0445313
Compare
|
@wynneyin I rebased this onto
Please pull ( |
potiuk
left a comment
There was a problem hiding this comment.
The pre-commit adapter is complete across the dispatcher, shim, project-root helper, registry and lint baseline, and the rebase onto current main keeps both sides of the conflicting changes; CI is green.
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
pre-commitintools/hook-manager/registry.jsonwith thehide-global-configinstall strategy. feat(hook-manager): add a lefthook adapter #1895 landed that strategy for lefthook, so the shim half of hook-manager: add a pre-commit adapter #1820 needed no code change: a bare install still refuses withCowardly refusing to install hooks with core.hooksPath set, and the shim'sGIT_CONFIG_GLOBAL=/dev/nullhides the global value.PRE_COMMIT_HOMEreachesos.path.realpathunexpanded, so a~value would resolve under the session's working directory and the committed settings cannot name the sandbox home. Option 1 from the issue:sandbox-add-project-root.shwrites the absolute path into the project-local.claude/settings.local.json, generated from the registry, and removes it from a project that does not use the manager.sandbox-lintaccepts an absolute value and rejects a literal~.Type of change
tools/hook-manager/*.md,tools/agent-isolation/*.sh)tools/dev/,tools/sandbox-lint/)docs/,README.md,CONTRIBUTING.md)prek, workflows, validators)Test plan
uv run pytestintools/devandtools/sandbox-lint: all pass (tools/devcovers the registry validation, the new helper block and the committed-settings rule;tools/sandbox-lintcovers absolute-versus-~).uv run pytestintools/agent-isolationfortest_hook_manager_shim.py,test_sandbox_add_project_root.pyandtest_git_hook_dispatcher.py: all pass. The container-gateway and gpg-overlay files fail on this macOS host withOSError: AF_UNIX path too longbefore any assertion; they are untouched by this change.core.hooksPathpointing at a shared hooks dir:pre-commit install:[ERROR] Cowardly refusing to install hooks with core.hooksPath set., exit 1;~/.claude/bin/pre-commit install:pre-commit installed at .git/hooks/pre-commit, exit 0, shared dir empty, generated hook carries thepre-commitmarker;.git/hooks/pre-commit;sandbox-add-project-root.sh --dry-runin this repository proposes"PRE_COMMIT_HOME": "/home/<user>/.cache/pre-commit-sandbox"insettings.local.json.prek run --files <changed files> --skip workspace-pytest: every hook passes.ruffreportspr-managementandsourcehutonly under a locally resolved ruff 0.17.5; with the locked 0.17.3 those packages pass (ruff check tools/pr-management tools/sourcehut→ all checks passed), and neither is touched here.RFC-AI-0004 compliance
~/.cache/, the default home stays denied, and the host-only home stays under~/.local/share/.Linked issues
Closes #1820
Notes for reviewers
env.PRE_COMMIT_HOMEcannot be portable: pre-commit keeps~literal, and an absolute path differs per machine. Soexpands_tilde: falseis a registry fact,sync-hook-managers.pystops requiring the committed entry for it, and the helper writes the value per project. The contract's Home section now states this..pre-commit-config.yaml(prek uses the same file names), so it counts as using pre-commit, and CI has nosettings.local.json. Failing on the absent value would break CI for a per-machine file. The safety argument still holds: the default home is denied for every registered manager, so a sandboxed run without a home of its own fails instead of writing the home a terminal's commits use.doctoctouched one extra line indocs/setup/sandbox-troubleshooting.md: a heading the committed TOC was already missing. It came along because this PR edits the file.pre-commit init-templatediris not offered as a workaround anywhere in the docs: it forcesoverwrite=True, which moves a foreign hook to.legacyand then deletes it, taking the dispatcher with it.