Skip to content

fix: add top-level exclude property to hk.pkl#299

Merged
jdx merged 13 commits into
mainfrom
feature/add-top-level-exclude
Sep 21, 2025
Merged

fix: add top-level exclude property to hk.pkl#299
jdx merged 13 commits into
mainfrom
feature/add-top-level-exclude

Conversation

@jdx

@jdx jdx commented Sep 21, 2025

Copy link
Copy Markdown
Owner

Summary

Add support for a top-level exclude property in hk.pkl configuration files to globally exclude files from all steps and hooks.

  • ✅ Add exclude: (String | List<String>)? property to Config.pkl schema
  • ✅ Support both single string and list of strings syntax for consistency
  • ✅ Integrate with existing exclude logic (settings, CLI, step-level excludes)
  • ✅ Use existing StringOrList pattern for clean implementation
  • ✅ Comprehensive test coverage with 5 bats tests

Usage Examples

// Single pattern as string
exclude = "*.test.js"

// Single pattern as list  
exclude = List("*.test.js")

// Multiple patterns
exclude = List("*.test.js", "*.spec.ts", "node_modules", "dist")

Behavior

  • Top-level exclude: Completely removes files from all processing
  • Step-level exclude: Only excludes files from specific steps
  • Priority: All exclude sources are combined (settings + config + CLI + step-level)

Test Coverage

  • Single pattern as string syntax
  • Single pattern as list syntax
  • Multiple patterns in list
  • Combined top-level and step-level excludes
  • Directory pattern exclusion

🤖 Generated with Claude Code

jdx and others added 3 commits September 21, 2025 15:23
- Add global exclude property to Config.pkl schema
- Support List<String> for global file exclusion patterns
- Integrate config exclude patterns with existing exclude logic in hook.rs
- Add comprehensive bats tests for top-level exclude functionality
- Supports both single patterns and multiple patterns
- Works in combination with existing step-level exclude patterns
- Handles directory patterns (e.g., "node_modules", "dist")

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update Config.pkl schema to accept both String and List<String> for exclude field
- Add serde deserializer to handle String to Vec<String> conversion in Rust
- Add comprehensive tests for both String and List syntax
- Maintain backward compatibility with existing configurations

Examples:
- exclude = "*.test.js" (single string)
- exclude = List("*.test.js", "*.spec.ts") (list of strings)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace custom serde deserializer with existing StringOrList enum
- Follow the same pattern used by other config fields in the codebase
- Cleaner implementation that leverages existing infrastructure
- Removes unnecessary custom deserialization code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jdx jdx changed the title feat: add top-level exclude property to hk.pkl fix: add top-level exclude property to hk.pkl Sep 21, 2025
cursor[bot]

This comment was marked as outdated.

- Remove --exclude-glob from CLI options as --exclude now handles glob patterns
- Update settings.toml to remove exclude-glob references
- Update test to use --exclude instead of --exclude-glob
- Simplify CLI interface by consolidating exclude functionality

Since all exclude patterns are treated as globs anyway, having separate
--exclude and --exclude-glob options was redundant and confusing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
cursor[bot]

This comment was marked as outdated.

jdx and others added 7 commits September 21, 2025 15:41
- Add exclude field to collect_pkl_map() in settings system
- Handle StringOrList conversion properly for PKL exclude patterns
- Remove redundant manual config loading in hook.rs
- Now all PKL config fields are loaded through unified settings system

This provides a clean, unified approach where:
- Settings system handles all configuration sources (CLI, env, git, PKL)
- No duplicate loading or manual config parsing needed
- Proper merge semantics with union behavior for list fields
- Consistent with other settings fields

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add iter() method to StringOrList enum
- Implement IntoIterator trait for owned iteration
- Refactor all StringOrList match patterns to use v.into_iter().collect()
- Significantly cleaner and more idiomatic Rust code

Before:
```rust
match v {
    StringOrList::String(s) => vec![s.clone()],
    StringOrList::List(list) => list.clone(),
}
```

After:
```rust
v.into_iter().collect()
```

This makes StringOrList behave like any other iterable collection,
reducing boilerplate and improving code readability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace manual field enumeration with metadata-driven approach
- Use SETTINGS_META to discover which fields have PKL sources
- Dynamically extract field values using serde_json conversion
- Handle both String and Array serialization of StringOrList types
- More maintainable: adding PKL fields only requires updating settings.toml

Benefits:
- No more manual field additions to collect_pkl_map()
- Automatic support for any field with PKL sources
- Type-safe based on metadata type information
- Handles StringOrList serialization variants correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ttings.rs

Previously, config loading errors were silently ignored using `if let Ok(cfg) = ...` patterns.
This could hide important configuration issues. Now these functions properly return
Result<SourceMap, eyre::Error> and propagate errors to callers with appropriate warnings.

Changes:
- collect_git_map() now returns Result and propagates git config errors
- collect_pkl_map() now returns Result and propagates pkl config errors
- build_from_all_sources() updated to handle Result types with fallback warnings
- explain_value() updated to handle config errors properly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…sages

Previously, get_snapshot() would silently fall back to defaults when config loading
failed. Now it properly propagates errors up through the call chain, resulting in
clear error messages for users when configuration files are broken.

Changes:
- get_snapshot() now returns Result<SettingsSnapshot, eyre::Error>
- Settings::get() uses expect() to provide clear "Failed to load configuration" message
- Config errors now cause immediate failure with helpful error details instead of silent fallback
- Removed unused settings! macro

This ensures users get proper feedback when their config files have syntax errors
or other issues, rather than mysteriously getting default behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added Settings::try_get() as a non-panicking alternative to Settings::get()
that returns Result<Settings, eyre::Error> for callers that want to handle
config errors gracefully.

Updated strategic CLI commands to use try_get():
- config dump/get/explain commands now handle config errors gracefully
- test command uses try_get() for parallel job configuration
- These commands can now show warnings instead of panicking on config errors

Benefits:
- Diagnostic commands (config) can function even with broken configs
- Better user experience with graceful degradation
- Settings::get() kept for backward compatibility where panicking is preferred
- Clear separation between "must work" vs "best effort" config access

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…tests

Performance optimization:
- Settings::get() and try_get() now return Arc<Settings> instead of cloning
- Eliminates expensive Settings struct cloning on every access
- Uses .as_ref() for serialization where needed

Testing improvements:
- Added comprehensive bats tests for config error handling
- Verifies hk check/fix/run fail properly on invalid configs
- Tests config commands (get/dump/explain) fail with helpful error messages
- Ensures error messages include file paths and syntax details

Benefits:
- Better performance: no more cloning large Settings structs
- Better testing: validates error handling works correctly
- Better UX: users get clear feedback on config problems

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
cursor[bot]

This comment was marked as outdated.

jdx and others added 2 commits September 21, 2025 16:09
…dling

Breaking change:
- Removed hk.excludeGlob backward compatibility test since we no longer support it
- Users should migrate to the new top-level exclude property in hk.pkl

Error handling improvements:
- collect_env_map() now returns Result and properly reports invalid env var values
- Environment variables like HK_JOBS=abc now error instead of being silently ignored
- Clear error messages show which env var has invalid value and expected format

This ensures users get proper feedback when environment variables have
invalid values instead of mysterious fallback to defaults.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add schema documentation for the new exclude field in Config.pkl
to fix CI docs-sync check failure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jdx jdx enabled auto-merge (squash) September 21, 2025 16:14
@jdx jdx merged commit 528dba6 into main Sep 21, 2025
5 checks passed
@jdx jdx deleted the feature/add-top-level-exclude branch September 21, 2025 16:17
@jdx jdx mentioned this pull request Sep 21, 2025
jdx added a commit that referenced this pull request Sep 21, 2025
## [1.15.3](https://github.com/jdx/hk/compare/v1.15.2..v1.15.3) -
2025-09-21

### 🐛 Bug Fixes

- prevent duplicate _type fields in JSON cache for groups by
[@jdx](https://github.com/jdx) in
[#297](#297)
- add top-level exclude property to hk.pkl by
[@jdx](https://github.com/jdx) in
[#299](#299)

Co-authored-by: mise-en-dev <123107610+mise-en-dev@users.noreply.github.com>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 24, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.13.7` -> `1.15.5` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/hk (hk)</summary>

### [`v1.15.5`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1155---2025-09-22)

[Compare Source](jdx/hk@v1.15.4...v1.15.5)

##### 🐛 Bug Fixes

- ensure stash cleanup by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;302](jdx/hk#302)

### [`v1.15.4`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1154---2025-09-22)

[Compare Source](jdx/hk@v1.15.3...v1.15.4)

##### 🐛 Bug Fixes

- scope staging to step job files to avoid unrelated file commits; add lockfile regression test by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;300](jdx/hk#300)

### [`v1.15.3`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1153---2025-09-21)

[Compare Source](jdx/hk@v1.15.2...v1.15.3)

##### 🐛 Bug Fixes

- prevent duplicate \_type fields in JSON cache for groups by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;297](jdx/hk#297)
- add top-level exclude property to hk.pkl by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;299](jdx/hk#299)

### [`v1.15.2`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1152---2025-09-20)

[Compare Source](jdx/hk@v1.15.1...v1.15.2)

##### 🐛 Bug Fixes

- prettier bugs; stash/unstash robustness; preserve EOF newline by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;293](jdx/hk#293)

##### 📚 Documentation

- remove references to alternative config formats by [@&#8203;jdx](https://github.com/jdx) in [5e497b6](jdx/hk@5e497b6)

### [`v1.15.1`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1151---2025-09-19)

[Compare Source](jdx/hk@v1.15.0...v1.15.1)

##### 🐛 Bug Fixes

- Skip any hunks that begin before the current position to avoid partial re-application by [@&#8203;jdx](https://github.com/jdx) in [8325a66](jdx/hk@8325a66)

### [`v1.15.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1150---2025-09-19)

[Compare Source](jdx/hk@v1.14.0...v1.15.0)

##### 🚀 Features

- **(docs)** add custom VitePress theme with unique branding by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;287](jdx/hk#287)

##### 🐛 Bug Fixes

- handle fixes and unstaged hunks in the same file by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;283](jdx/hk#283)

##### 📦️ Dependency Updates

- pin dependencies by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;288](jdx/hk#288)
- update actions/checkout action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;289](jdx/hk#289)
- update actions/download-artifact action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;290](jdx/hk#290)
- update actions/upload-pages-artifact action to v4 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;291](jdx/hk#291)

### [`v1.14.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1140---2025-09-18)

[Compare Source](jdx/hk@v1.13.7...v1.14.0)

##### 🚀 Features

- centralized settings registry with codegen by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;284](jdx/hk#284)

##### 🔍 Other Changes

- removed snapshot file by [@&#8203;bhanuprasad14](https://github.com/bhanuprasad14) in [0952af5](jdx/hk@0952af5)
- Extract Pkl error handling into separate method by [@&#8203;jdx](https://github.com/jdx) in [e62cb24](jdx/hk@e62cb24)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTYuNiIsInVwZGF0ZWRJblZlciI6IjQxLjEyMi4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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