Skip to content

Add config layering system with user and project defaults - #191

Merged
httpdss merged 3 commits into
mainfrom
cursor/config-layering-be12
Aug 23, 2026
Merged

httpdss merged 3 commits into
mainfrom
cursor/config-layering-be12

Conversation

@httpdss

@httpdss httpdss commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Issue

Fixes #98

Description

This PR implements a comprehensive config layering system that allows users to set defaults at multiple levels, reducing CLI verbosity and providing a flexible configuration hierarchy.

Key Features

  1. Multi-layer Configuration Support

    • Built-in defaults (hard-coded baseline values)
    • User config at ~/.config/struct/config.yaml for personal global defaults
    • Project config via .struct.yaml or --config-file flag
    • CLI arguments (highest priority)
  2. Config Precedence Order

    CLI args > Project config > User config > Built-in defaults
    
  3. New structkit config print Command

    • Display the effective configuration after all layers are merged
    • Support for both YAML (default) and JSON output formats
    • Shows which config sources were loaded

Implementation Details

New Files:

  • structkit/config.py - Core config layering logic with functions for loading, merging, and applying configurations
  • structkit/commands/config.py - Config command with print subcommand
  • tests/test_config_layering.py - Comprehensive tests for config layering (15 tests)
  • tests/test_config_command.py - Tests for config command (6 tests)
  • examples/config-layering/ - Complete example with README and sample configs

Modified Files:

  • structkit/main.py - Integrated layered config loading into main CLI flow
  • docs/configuration.md - Added comprehensive documentation for config layering

Supported Config Options

All of the following can be set in config files:

  • structures_path - Path to custom structure definitions
  • source - Named source for structure definitions
  • input_store - Path to the input store file
  • file_strategy - Strategy for handling existing files
  • backup - Path to backup folder
  • global_system_prompt - Global system prompt for OpenAI
  • non_interactive - Run in non-interactive mode
  • output - Output mode (file/console)
  • log - Logging level
  • log_file - Path to log file

Example Usage

Create a user config:

mkdir -p ~/.config/struct
cat > ~/.config/struct/config.yaml << 'EOF'
file_strategy: backup
input_store: ~/.cache/structkit/input.json
structures_path: ~/my-structures
log: WARNING
EOF

View effective config:

structkit config print

Override with CLI args:

structkit config print --log DEBUG -c my-project-config.yaml

See examples/config-layering/ for more comprehensive examples and use cases.

Checklist

  • I have read the contributing guidelines.
  • My code follows the code style of this project.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have updated the documentation accordingly.

Screenshots (if applicable)

Example output of structkit config print:

file_strategy: backup
input_store: /home/user/.cache/structkit/input.json
log: WARNING
non_interactive: false
output: file
structures_path: /home/user/my-structures

Configuration sources:
  1. Built-in defaults: always loaded
  2. User config: /home/user/.config/struct/config.yaml (exists)
  3. Project config: none specified
  4. CLI arguments: highest priority

Additional Comments

  • All 272 existing tests pass, including 21 new tests for this feature
  • Pre-commit hooks pass (trailing-whitespace, end-of-file-fixer, check-yaml)
  • Backward compatible with existing config loading via --config-file
  • The implementation respects the CLI style and patterns used throughout the codebase
  • Does NOT include hook-safety work from PR Add hook safety controls for structkit #190 / issue Pre/Post hooks safety controls #100 as instructed
  • Includes comprehensive examples in examples/config-layering/ with user and project config templates
Open in Web Open in Cursor 

cursoragent and others added 3 commits August 23, 2026 17:53
Implements #98: Config layering and profile defaults

Features:
- Support for user config at ~/.config/struct/config.yaml for global defaults
- Layered config merging: CLI args > project config > user config > built-in defaults
- New 'structkit config print' command to display effective configuration
- Support for YAML and JSON output formats

Changes:
- Add structkit/config.py with layered config loading logic
- Add structkit/commands/config.py for config command
- Update structkit/main.py to integrate config layering
- Add comprehensive tests for config layering and command
- Update docs/configuration.md with config layering documentation

Config precedence order:
1. Built-in defaults (lowest priority)
2. User config (~/.config/struct/config.yaml)
3. Project config (.struct.yaml or --config-file)
4. CLI arguments (highest priority)

Fixes #98

Co-authored-by: Kenneth Belitzky <kenny@belitzky.com>
Add comprehensive examples demonstrating:
- User config setup at ~/.config/struct/config.yaml
- Project config usage
- Config precedence and layering
- Common use cases and tips

Files:
- examples/config-layering/README.md
- examples/config-layering/user-config-example.yaml
- examples/config-layering/project-config-example.yaml

Co-authored-by: Kenneth Belitzky <kenny@belitzky.com>
Add documentation for the new 'structkit config print' command:
- Command usage and syntax
- Description of config layering
- Examples of common use cases
- Link to comprehensive configuration documentation

Co-authored-by: Kenneth Belitzky <kenny@belitzky.com>
@httpdss httpdss added enhancement New feature or request minor labels Aug 23, 2026
@httpdss
httpdss merged commit ab0dc2f into main Aug 23, 2026
3 checks passed
@httpdss
httpdss deleted the cursor/config-layering-be12 branch August 23, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config layering and profile defaults

2 participants