Skip to content

fix: move prepare lifecycle hook to explicit setup-hooks script - #334

Merged
avifenesh merged 2 commits into
agent-sh:mainfrom
xiaolai:fix/nlpm-prepare-hook
Apr 23, 2026
Merged

fix: move prepare lifecycle hook to explicit setup-hooks script#334
avifenesh merged 2 commits into
agent-sh:mainfrom
xiaolai:fix/nlpm-prepare-hook

Conversation

@xiaolai

@xiaolai xiaolai commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Automated audit: This PR was generated by NLPM, a natural language programming linter, running via claude-code-action. Please evaluate the diff on its merits.

Bug

package.json currently has:

"prepare": "node bin/dev-cli.js setup-hooks"

npm's prepare lifecycle hook runs automatically on every npm install — including when end users install this package as a dependency in their own projects. This means git hooks (pre-commit, pre-push) get silently installed into any consuming project's .git/hooks/ directory without explicit consent.

This is a Medium-severity security concern: a package that installs git hooks as a side-effect of npm install is unexpected behavior, and the installed hooks run arbitrary code before every commit and push in the consumer's repository.

Fix

Rename preparesetup-hooks so hook installation is opt-in only:

"setup-hooks": "node bin/dev-cli.js setup-hooks"

Contributors who want the git hooks run npm run setup-hooks explicitly after cloning. This is documented in a new "First-Time Setup" section in CONTRIBUTING.md.

The hook content itself is benign (validators and /enhance prompts), but the automatic installation via the lifecycle hook is the issue — it should not happen without the developer's intent.

Changes

  • package.json: rename preparesetup-hooks
  • CONTRIBUTING.md: add "First-Time Setup" section with explicit opt-in instructions

npm's prepare hook runs on every `npm install` in any environment,
causing the package to silently install git hooks into any consumer's
repository without their explicit consent. This is unexpected behavior
for a plugin package consumed by end users.

Rename prepare to setup-hooks so contributors can opt in explicitly by
running `npm run setup-hooks` after cloning, as now documented in
CONTRIBUTING.md.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request transitions the git hook installation process from an automatic 'prepare' script to a manual 'setup-hooks' command in package.json. It also updates CONTRIBUTING.md with a new 'First-Time Setup' section to guide users through this manual process. Feedback was provided to replace an em-dash with a single dash in the documentation to adhere to stylistic preferences.

Comment thread CONTRIBUTING.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes git hook installation opt-in by removing use of npm’s prepare lifecycle hook, preventing hooks from being installed as a side-effect when end users install the package as a dependency.

Changes:

  • Rename package.json script from prepare to an explicit setup-hooks script.
  • Document a first-time contributor setup flow in CONTRIBUTING.md that instructs running npm run setup-hooks manually.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
package.json Removes prepare lifecycle hook usage; introduces explicit setup-hooks npm script.
CONTRIBUTING.md Adds “First-Time Setup” instructions to manually install git hooks via setup-hooks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CONTRIBUTING.md Outdated
@avifenesh

Copy link
Copy Markdown
Collaborator

Thanks for this. The fix makes sense and the changes look clean.

Two things from the bot reviews that should be addressed before merging:

  1. Replace the em-dash with a regular dash in the CONTRIBUTING.md addition (per Copilot suggestion)
  2. Update docs/ARCHITECTURE.md - it still references npm prepare for setup-hooks (per Gemini note)

Other than that, LGTM.

- Remove pre-commit hook installation - it was just a no-op placeholder
  ('lib/ sync now handled by agent-core'), so installing it was pure
  redundancy. Only the pre-push hook (preflight + /enhance reminder +
  release tag validation) actually does anything.
- CONTRIBUTING.md: replace em-dash with single dash per workspace rule;
  update text to reflect that only pre-push is installed now.
- docs/ARCHITECTURE.md: update setup-hooks.js comment - was 'npm prepare'
  before xiaolai's PR; now correctly noted as manual.
@avifenesh

Copy link
Copy Markdown
Collaborator

Thanks @xiaolai! Took your patch and pushed two follow-ups in 71a5055:

  1. Fixed both bot review items - replaced the em-dash in CONTRIBUTING.md with a single dash (workspace rule), and updated docs/ARCHITECTURE.md to remove the stale npm prepare reference.
  2. Removed the redundant pre-commit hook - it was just a no-op placeholder ('lib/ sync now handled by agent-core'). Only the actually-active pre-push hook is installed now.

Updated CONTRIBUTING.md prose to reflect that only pre-push is installed. Merging.

@avifenesh
avifenesh merged commit f369ac4 into agent-sh:main Apr 23, 2026
7 checks passed
@avifenesh avifenesh mentioned this pull request Apr 23, 2026
5 tasks
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.

3 participants