Skip to content

feat: add auto-presets config to apply presets automatically based on command name#27

Merged
Warashi merged 4 commits into
mainfrom
auto-profile
Jul 19, 2025
Merged

feat: add auto-presets config to apply presets automatically based on command name#27
Warashi merged 4 commits into
mainfrom
auto-profile

Conversation

@Warashi
Copy link
Copy Markdown
Owner

@Warashi Warashi commented Jul 19, 2025

This pull request introduces a new feature called "Auto-Presets" to the cage tool, 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:

    • Added support for auto-presets in the configuration file, allowing presets to be applied automatically based on exact command matches or regex patterns. (config.go, [1] [2] [3]
    • Introduced the AutoPresetRule struct to define rules for auto-presets. (config.go, config.goR26-R31)
  • Core Logic:

    • Implemented GetAutoPresets method to determine applicable presets for a given command based on the rules defined in auto-presets. (config.go, config.goR99-R136)
    • Integrated auto-presets detection into the main execution flow, merging them with command-line presets while maintaining priority for explicit presets. (main.go, main.goR166-R178)

Documentation Updates:

  • README Enhancements:
    • Updated the README.md to document the auto-presets feature, including examples of configuration and usage. (README.md, [1] [2]
    • Clarified that the -preset flag can be used multiple times. (README.md, README.mdL55-R55)

Testing Enhancements:

  • Unit Tests:
    • Added comprehensive tests for the GetAutoPresets method, covering exact matches, regex matches, invalid regex handling, and merging of auto-presets with command-line presets. (config_test.go, config_test.goR395-R588)
    • Verified the order preservation of paths when combining command-line presets and auto-presets. (main_test.go, main_test.goR341-R455)

Warashi and others added 4 commits July 19, 2025 12:34
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>
@Warashi Warashi marked this pull request as ready for review July 19, 2025 03:50
@Warashi Warashi enabled auto-merge July 19, 2025 03:50
@Warashi Warashi merged commit deb710a into main Jul 19, 2025
9 checks passed
@Warashi Warashi deleted the auto-profile branch July 19, 2025 03:51
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.

1 participant