Skip to content

formula_auditor: reject claude-agent-sdk#21804

Open
cho-m wants to merge 1 commit intomainfrom
formula_auditor-claude-agent-sdk
Open

formula_auditor: reject claude-agent-sdk#21804
cho-m wants to merge 1 commit intomainfrom
formula_auditor-claude-agent-sdk

Conversation

@cho-m
Copy link
Member

@cho-m cho-m commented Mar 22, 2026


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

Audit to detect

Example output after brew install promptfoo with timing (run in Linux container):

$ time (brew audit --only node_modules promptfoo)
promptfoo
  * Formula promptfoo uses @anthropic-ai/claude-agent-sdk which has an incompatible license.
    All installed npm dependencies must satisfy https://docs.brew.sh/License-Guidelines
Error: 1 problem in 1 formula detected.

real	0m2.998s
user	0m2.186s
sys	0m0.876s

Using an array to extend this with other npm packages.


Future ideas

In future, may consider moving this to a JSON file we store in Homebrew/core so it can be implemented as a tap-specific blacklist. Then can also be used in 3rd-party taps to detect unwanted dependencies.

And in further future, may want to analyze SPDX licenses of all installed npm packages to automatically detect disallowed licenses. May need a whitelist in this case when an npm package doesn't use SPDX.

Copilot AI review requested due to automatic review settings March 22, 2026 17:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new FormulaAuditor audit to detect disallowed npm dependencies (starting with @anthropic-ai/claude-agent-sdk) in installed node_modules trees for core formulae, with accompanying RSpec coverage.

Changes:

  • Introduce FormulaAuditor#audit_node_modules to scan libexec/lib/node_modules for incompatible npm packages in homebrew/core.
  • Emit an audit problem directing maintainers to Homebrew’s license guidelines when a rejected package is found.
  • Add unit tests covering direct, nested, and dot-directory (.pnpm-style) locations, plus core/non-core behavior.

Reviewed changes

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

File Description
Library/Homebrew/formula_auditor.rb Adds a new audit_node_modules audit that searches installed node_modules for a rejected package and reports a license-guidelines error.
Library/Homebrew/test/formula_auditor_spec.rb Adds specs validating detection/skip behavior for the new audit_node_modules audit across common directory layouts.

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

sig { void }
def audit_node_modules
return unless @core_tap

Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

audit_node_modules will run as part of the default FormulaAuditor#audit method list whenever a formula is installed and has libexec/lib/node_modules. Since recursively scanning node_modules can be relatively expensive, consider making this check opt-in (e.g., only run when --only node_modules is specified, or behind a dedicated option) so standard brew audit runs aren't slowed down unexpectedly.

Suggested change
# Make this audit opt-in to avoid expensive recursive node_modules scans on standard runs.
only_list = respond_to?(:only) ? only : nil
return unless only_list&.include?("node_modules") || only_list&.include?(:node_modules)

Copilot uses AI. Check for mistakes.

incompatible_license_packages.each do |package|
# Search for package in all nested node_modules. Also including dot match for .pnpm hoisted packages
next if node_modules.glob("{**/node_modules/,}#{package}/", File::FNM_DOTMATCH).empty?
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

node_modules.glob(...).empty? materializes an array of all matching paths for each package, which can be costly for large node_modules trees. Consider using Dir.glob with a block (or Find.find with early exit) to short-circuit on the first match and avoid allocating large arrays.

Suggested change
next if node_modules.glob("{**/node_modules/,}#{package}/", File::FNM_DOTMATCH).empty?
found = false
Dir.glob(node_modules/"{**/node_modules/,}#{package}/", File::FNM_DOTMATCH) do
found = true
break
end
next unless found

Copilot uses AI. Check for mistakes.
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks!

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