Skip to content

feat(command-safety): per-manager ALLOW_* env vars for package managers#24

Merged
nichm merged 1 commit into
mainfrom
issue-2-per-manager-toggles
Apr 29, 2026
Merged

feat(command-safety): per-manager ALLOW_* env vars for package managers#24
nichm merged 1 commit into
mainfrom
issue-2-per-manager-toggles

Conversation

@nichm

@nichm nichm commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds COMMAND_SAFETY_ALLOW_* env vars so each package manager can be individually unblocked without touching the others
  • All blocking rules remain active by default — this is purely opt-in per manager
  • COMMAND_SAFETY_DISABLE_PACKAGE_MANAGERS=true still works as an all-or-nothing kill switch

New vars

Set in ~/.zshrc.local before shell-config is sourced:

# Node/JS — unblock specific managers only
export COMMAND_SAFETY_ALLOW_NPM=true   # unblocks npm (yarn/pnpm still blocked)
export COMMAND_SAFETY_ALLOW_NPX=true   # unblocks npx
export COMMAND_SAFETY_ALLOW_YARN=true  # unblocks yarn
export COMMAND_SAFETY_ALLOW_PNPM=true  # unblocks pnpm

# Python — pip and python/python3 are independently configurable
export COMMAND_SAFETY_ALLOW_PIP=true    # unblocks pip/pip3 (python still blocked)
export COMMAND_SAFETY_ALLOW_PYTHON=true # unblocks python/python3 (pip still blocked)

Tests

21 new regression tests in tests/regression/package-manager-allow-vars.bats cover:

  • Each allow var unblocks only its own manager
  • All other managers remain blocked when only one allow is set
  • Node allow vars don't affect Python rules and vice versa

Closes #2

Previously the only escape from npm/yarn/pnpm/pip/python blocking was
COMMAND_SAFETY_DISABLE_PACKAGE_MANAGERS=true (all-or-nothing) or a
per-command --force-* bypass flag. Teams using mixed package managers
had no middle ground.

Add COMMAND_SAFETY_ALLOW_* vars checked at rule-load time so each
manager can be individually unblocked:
  - COMMAND_SAFETY_ALLOW_NPM / ALLOW_NPX / ALLOW_YARN / ALLOW_PNPM
  - COMMAND_SAFETY_ALLOW_PIP  (pip/pip3; python/python3 still blocked)
  - COMMAND_SAFETY_ALLOW_PYTHON  (python/python3; pip still blocked)

Set in ~/.zshrc.local before shell-config is sourced. The file-level
COMMAND_SAFETY_DISABLE_PACKAGE_MANAGERS=true still works to disable all
rules at once. 21 new regression tests cover each allow var and their
independence from each other.

Closes #2
@gemini-code-assist

gemini-code-assist Bot commented Apr 29, 2026

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the command safety system by providing more granular control over package manager restrictions. Users can now opt-in to allow specific tools while maintaining the default blocking behavior for others, improving flexibility for specialized project requirements without compromising the overall safety policy.

Highlights

  • Granular Command Safety: Introduced environment variables (e.g., COMMAND_SAFETY_ALLOW_NPM, COMMAND_SAFETY_ALLOW_PIP) to allow unblocking specific package managers individually without disabling all safety rules.
  • Regression Testing: Added 21 new BATS regression tests to ensure that enabling one allow-flag does not inadvertently unblock other managers and that Node/Python rules remain independent.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

@github-actions github-actions Bot added 🤖 claude-autoreview Claude Code Review in progress 🔍 qodo-mega Mega Reviewer in progress labels Apr 29, 2026
@claude

claude Bot commented Apr 29, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@github-actions github-actions Bot added 🔍 qodo-mega-done Mega Reviewer completed successfully 🤖 claude-autoreview-failed Claude Code Review failed 🔍 qodo-improve Quick Improvers in progress and removed 🔍 qodo-mega Mega Reviewer in progress 🤖 claude-autoreview Claude Code Review in progress labels Apr 29, 2026
@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

1 similar comment
@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@github-actions github-actions Bot added 🔍 qodo-improve-done Quick Improvers completed successfully and removed 🔍 qodo-improve Quick Improvers in progress labels Apr 29, 2026

@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 introduces fine-grained control over package manager safety rules by adding COMMAND_SAFETY_ALLOW_* environment variables. These flags allow users to selectively unblock specific tools like npm, yarn, or pip while keeping others restricted. The changes include updates to the rule definitions, documentation in the settings file, and a comprehensive suite of regression tests. Feedback suggests refactoring the new test file to use helper functions for checking blocked and unblocked states, which would reduce boilerplate and improve maintainability.

Comment on lines +37 to +120
# =============================================================================
# Node managers
# =============================================================================

@test "ALLOW_NPM: npm not blocked when COMMAND_SAFETY_ALLOW_NPM=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_NPM=true
$(_engine_with_rules)
_check_command_rules npm install lodash
"
[ "$status" -ne 1 ]
}

@test "ALLOW_NPM: yarn still blocked when only COMMAND_SAFETY_ALLOW_NPM=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_NPM=true
$(_engine_with_rules)
_check_command_rules yarn add lodash
"
[ "$status" -eq 1 ]
}

@test "ALLOW_NPM: pnpm still blocked when only COMMAND_SAFETY_ALLOW_NPM=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_NPM=true
$(_engine_with_rules)
_check_command_rules pnpm install lodash
"
[ "$status" -eq 1 ]
}

@test "ALLOW_NPX: npx not blocked when COMMAND_SAFETY_ALLOW_NPX=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_NPX=true
$(_engine_with_rules)
_check_command_rules npx create-react-app my-app
"
[ "$status" -ne 1 ]
}

@test "ALLOW_NPX: npm still blocked when only COMMAND_SAFETY_ALLOW_NPX=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_NPX=true
$(_engine_with_rules)
_check_command_rules npm install lodash
"
[ "$status" -eq 1 ]
}

@test "ALLOW_YARN: yarn not blocked when COMMAND_SAFETY_ALLOW_YARN=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_YARN=true
$(_engine_with_rules)
_check_command_rules yarn add lodash
"
[ "$status" -ne 1 ]
}

@test "ALLOW_YARN: npm still blocked when only COMMAND_SAFETY_ALLOW_YARN=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_YARN=true
$(_engine_with_rules)
_check_command_rules npm install lodash
"
[ "$status" -eq 1 ]
}

@test "ALLOW_PNPM: pnpm not blocked when COMMAND_SAFETY_ALLOW_PNPM=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_PNPM=true
$(_engine_with_rules)
_check_command_rules pnpm install lodash
"
[ "$status" -ne 1 ]
}

@test "ALLOW_PNPM: yarn still blocked when only COMMAND_SAFETY_ALLOW_PNPM=true" {
run bash -c "
export COMMAND_SAFETY_ALLOW_PNPM=true
$(_engine_with_rules)
_check_command_rules yarn add lodash
"
[ "$status" -eq 1 ]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

These tests are great for ensuring correctness, but there's a lot of boilerplate repeated in each @test block. To improve maintainability and make the test suite easier to read and extend, consider using helper functions for the common test patterns.

For example, you could define _test_unblocked and _test_still_blocked helpers:

# Helper to check if a command is NOT blocked when its allow-var is set
_test_unblocked() {
    local var_to_set="$1"; shift
    local -a cmd_to_run=("$@")
    run bash -c "
        export $var_to_set=true
        $(_engine_with_rules)
        _check_command_rules ${cmd_to_run[@]}
    "
    [ "$status" -ne 1 ]
}

# Helper to check if a command IS blocked when another allow-var is set
_test_still_blocked() {
    local var_to_set="$1"; shift
    local -a cmd_to_run=("$@")
    run bash -c "
        export $var_to_set=true
        $(_engine_with_rules)
        _check_command_rules ${cmd_to_run[@]}
    "
    [ "$status" -eq 1 ]
}

With these helpers (placed after _engine_with_rules), your tests become much more concise:

@test "ALLOW_NPM: npm not blocked when COMMAND_SAFETY_ALLOW_NPM=true" {
    _test_unblocked COMMAND_SAFETY_ALLOW_NPM npm install lodash
}

@test "ALLOW_NPM: yarn still blocked when only COMMAND_SAFETY_ALLOW_NPM=true" {
    _test_still_blocked COMMAND_SAFETY_ALLOW_NPM yarn add lodash
}

@test "ALLOW_NPM: pnpm still blocked when only COMMAND_SAFETY_ALLOW_NPM=true" {
    _test_still_blocked COMMAND_SAFETY_ALLOW_NPM pnpm install lodash
}

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ef2b227f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if [[ "${COMMAND_SAFETY_ALLOW_PYTHON:-}" != "true" ]]; then

# Catches: python script.py, python -c "code", python -m module, piped python
_rule PYTHON_DIRECT cmd="python" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Exempt python -m pip when ALLOW_PIP is enabled

When COMMAND_SAFETY_ALLOW_PIP=true is set, pip/pip3 are unblocked by skipping their rules, but python -m pip ... and python3 -m pip ... are still blocked because the catch-all PYTHON_DIRECT/PYTHON3_DIRECT rules still match every python/python3 invocation. This breaks a common pip workflow (often the only available one in managed environments) and makes the new per-manager allow flag incomplete for pip usage.

Useful? React with 👍 / 👎.

@nichm nichm merged commit 4525483 into main Apr 29, 2026
10 of 13 checks passed
@nichm nichm deleted the issue-2-per-manager-toggles branch April 29, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 claude-autoreview-failed Claude Code Review failed 🔍 qodo-improve-done Quick Improvers completed successfully 🔍 qodo-mega-done Mega Reviewer completed successfully

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package manager blocking too opinionated — make each manager individually configurable

1 participant