feat: add auto-presets config to apply presets automatically based on command name#27
Merged
Conversation
Add support for automatically applying presets based on the command being executed.
This feature reduces typing and ensures consistent permissions for common tools.
Features:
- Auto-presets configuration section in YAML config files
- Support for exact command name matching
- Support for regex pattern matching
- Auto-presets only apply when no explicit --preset flags are provided
- Comprehensive test coverage for all auto-preset scenarios
Example configuration:
```yaml
auto-presets:
- command: claude
presets:
- claude-code
- command-pattern: ^(npm|npx|yarn)$
presets:
- npm
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Auto-presets are now merged with command-line presets instead of being ignored when explicit presets are provided. Command-line presets take priority by being processed first. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Add TestAutoPresetsWithCommandLinePresets to verify that both types of presets can be used together with proper priority ordering. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Update documentation to clarify that auto-presets are now merged with command-line presets rather than being ignored when explicit presets are provided. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 pull request introduces a new feature called "Auto-Presets" to the
cagetool, enabling automatic application of presets based on the executed command or a regex pattern. It also includes updates to documentation, configuration handling, and tests to support this functionality.Auto-Presets Feature Implementation:
Configuration Updates:
auto-presetsin the configuration file, allowing presets to be applied automatically based on exact command matches or regex patterns. (config.go, [1] [2] [3]AutoPresetRulestruct to define rules for auto-presets. (config.go, config.goR26-R31)Core Logic:
GetAutoPresetsmethod to determine applicable presets for a given command based on the rules defined inauto-presets. (config.go, config.goR99-R136)main.go, main.goR166-R178)Documentation Updates:
README.mdto document the auto-presets feature, including examples of configuration and usage. (README.md, [1] [2]-presetflag can be used multiple times. (README.md, README.mdL55-R55)Testing Enhancements:
GetAutoPresetsmethod, covering exact matches, regex matches, invalid regex handling, and merging of auto-presets with command-line presets. (config_test.go, config_test.goR395-R588)main_test.go, main_test.goR341-R455)