feat: Add experimental command filtering mode add allow all commands #6933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a new experimental feature for command validation. When enabled via the experimental settings menu, this feature changes how commands are allowed or denied.
The new logic is as follows:
A command is denied if it matches any prefix in the denylist.
A command is denied if it matches any prefix in the allowlist.
Otherwise, the command is approved.
This provides a simpler, more restrictive validation mode compared to the default "longest prefix match" strategy.
The implementation includes:
A new experimental feature flag COMMAND_FILTERING_MODE.
A new validation function getCommandDecisionAlternate that implements the new logic.
Integration of the feature flag to switch between validation logics.
New tests for the alternate validation logic and updates to existing tests.
Note: I was unable to run the test suite for these changes. I have tested them manually to the extent possible.
Related GitHub Issue
Closes: #
Description
This PR introduces a new experimental feature for command validation. When enabled via the experimental settings menu, this feature changes how commands are allowed or denied.
The new logic is as follows:
A command is denied if it matches any prefix in the denylist.
A command is denied if it matches any prefix in the allowlist.
Otherwise, the command is approved.
This provides a simpler, more restrictive validation mode compared to the default "longest prefix match" strategy.
Implementation details:
A new experimental feature flag COMMAND_FILTERING_MODE was added in src/shared/experiments.ts.
A new validation function getCommandDecisionAlternate was created in webview-ui/src/utils/command-validation.ts to implement the new logic.
The main getCommandDecision function was updated to check the feature flag and delegate to the appropriate validation function.
The ChatView.tsx component was updated to pass the experiments configuration to the validation logic.
Test Procedure
Added a new test file webview-ui/src/utils/tests/command-validation-alternate.spec.ts with unit tests for the new validation logic.
Updated existing tests in webview-ui/src/utils/tests/command-validation.spec.ts to account for the new experiments parameter.
Verification Steps:
Enable the "Command Filtering Mode" in the experimental settings.
Enter a command that is on the allowlist (e.g., npm install). It should be denied.
Enter a command that is on the denylist (e.g., rm -rf /). It should be denied.
Enter a command that is on neither list (e.g., git status). It should be approved.
Disable the feature flag and verify that the original command validation logic is used.
Note: I was unable to run the full test suite (bun test) due to a persistent build environment issue related to linting (ERR_REQUIRE_ESM). The code has been manually reviewed for correctness.
Pre-Submission Checklist
Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
Scope: My changes are focused on the linked issue (one major feature/fix per PR).
Self-Review: I have performed a thorough self-review of my code.
Testing: New and/or updated tests have been added to cover my changes (if applicable).
Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
Contribution Guidelines: I have read and agree to the Contributor Guidelines.
Screenshots / Videos
N/A
Documentation Updates
No documentation updates are required.
Additional Notes
The primary blocker during this task was a build failure in the testing environment, which prevented the test suite from running. The error appears to be a deep dependency issue related to ES Module resolution in a CommonJS-based tool (eslint). I've implemented the feature and tests, but they are unverified by the automated test suite.
Important
Introduces experimental command validation logic with a feature flag to toggle between new and old logic, including new tests and manual testing due to environment issues.
getCommandDecisionAlternate().COMMAND_FILTERING_MODEto toggle between new and old logic.getCommandDecisionAlternate()andgetSingleCommandDecisionAlternate()incommand-validation.ts.getCommandDecision()to use new logic if feature flag is enabled.ChatView.tsxto pass experiments configuration to validation logic.command-validation-alternate.spec.tsfor new logic tests.command-validation.spec.tsto include experiments parameter.This description was created by
for 1bf956c. You can customize this summary. It will automatically update as commits are pushed.