feat(pipe): accept built-in and trusted custom TOML filters in pipe -f#2998
Closed
rNoz wants to merge 1 commit into
Closed
feat(pipe): accept built-in and trusted custom TOML filters in pipe -f#2998rNoz wants to merge 1 commit into
rNoz wants to merge 1 commit into
Conversation
rtk pipe -f only resolved the hard-coded Rust filter names, so trusted project/global TOML filters (and built-in TOML filters) were rejected with "Unknown filter" even though the hook and rtk rewrite already apply them. Resolve the name against the TOML registry when no Rust filter matches. Only built-in and trusted custom filters are loaded, so untrusted filters are still rejected. A Filter enum dispatches Rust vs TOML through the same never_worse guard, and the error message now lists the available TOML filter names. Refs rtk-ai#2179
Author
|
Closed as forgot one CONTRIBUTING statement (too used to always start with rnoz/ prefix), so favouring the proper PR here: #2999 |
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.
Summary
rtk pipe -f <name>only resolved the hard-coded Rust filter names, so trusted project/global TOML filters (and built-in TOML filters) were rejected withUnknown filter '<name>', even thoughrtk rewriteand the hook already apply them.Filterenum dispatches Rust vs TOML through the samenever_worseguard, preserving safe fallback behavior.Unknown filtermessage now lists available TOML filter names in addition to the built-in Rust names.rtk pipe -floose end.Design
src/core/toml_filter.rs: two new public functions over the existing lazyREGISTRY:find_filter_by_name(name) -> Option<&'static CompiledFilter>: name lookup with project > global > built-in precedence (same load order asfind_matching_filter). Untrusted custom filters are never in the registry, so they are never returned.loaded_filter_names() -> Vec<&'static str>: sorted, de-duped, for error messages.src/cmds/system/pipe_cmd.rs:enum Filter { Rust(fn(&str)->String), Toml(&'static CompiledFilter) }.run()tries the built-in Rust resolver first, then the TOML registry by name, else errors with a dynamic message.apply_filter(&Filter, input)dispatches and keeps the panic-catch fallback;never_worseis still applied to the result.Trust model (explicit)
src/filters/*.toml) are always trusted and usable viapipe -f..rtk/filters.toml) and user-global (~/.config/rtk/filters.toml) custom filters requirertk trust(or the CI-gatedRTK_TRUST_PROJECT_FILTERS=1). Untrusted custom filters are rejected.pipe -f <name>matches by filter name only;match_commandis irrelevant here (pipe has no command string).Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all: pass.tests/pipe_custom_filter_test.rs:trusted_custom_filter_is_applied: trusted.rtk/filters.tomlfilter runs viapipe -f(noise lines stripped).untrusted_custom_filter_is_rejected: same filter, no trust, exits non-zero withUnknown filter.builtin_toml_filter_works_without_trust: built-inmakefilter usable viapipe -f.rtk_no_toml_disables_toml_filters_in_pipe: withRTK_NO_TOML=1, a TOML filter name is rejected (Unknown filter).builtin_rust_filter_still_works:grepstill works (no regression).pipe_cmd.rs:unknown_filter_messagelists built-ins;find_filter_by_name("make")resolves; unknown name returnsNone.e2e validation
So far so good, but I will do a final round of e2e checks tomorrow, and set ready for review.