Skip to content

feat(pipe): accept built-in and trusted custom TOML filters in pipe -f#2998

Closed
rNoz wants to merge 1 commit into
rtk-ai:developfrom
rNoz:rnoz/feat-pipe-custom-toml-filters
Closed

feat(pipe): accept built-in and trusted custom TOML filters in pipe -f#2998
rNoz wants to merge 1 commit into
rtk-ai:developfrom
rNoz:rnoz/feat-pipe-custom-toml-filters

Conversation

@rNoz

@rNoz rNoz commented Jul 14, 2026

Copy link
Copy Markdown

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 with Unknown filter '<name>', even though rtk rewrite and the hook already apply them.
  • Now, when no Rust filter matches, the name is resolved against the TOML filter registry. Only built-in and trusted custom filters are loaded (trust gating is enforced by the registry), so untrusted filters are still rejected.
  • A Filter enum dispatches Rust vs TOML through the same never_worse guard, preserving safe fallback behavior.
  • The Unknown filter message now lists available TOML filter names in addition to the built-in Rust names.
  • Solving Refs Custom TOML filters (global or trusted project-local) are never applied by the hook #2179 (custom TOML filters never applied). The hook/rewrite path is already fixed on develop; this closes the remaining rtk pipe -f loose end.

Design

  • src/core/toml_filter.rs: two new public functions over the existing lazy REGISTRY:
    • find_filter_by_name(name) -> Option<&'static CompiledFilter>: name lookup with project > global > built-in precedence (same load order as find_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_worse is still applied to the result.

Trust model (explicit)

  • Built-in TOML filters (src/filters/*.toml) are always trusted and usable via pipe -f.
  • Project-local (.rtk/filters.toml) and user-global (~/.config/rtk/filters.toml) custom filters require rtk trust (or the CI-gated RTK_TRUST_PROJECT_FILTERS=1). Untrusted custom filters are rejected.
  • pipe -f <name> matches by filter name only; match_command is irrelevant here (pipe has no command string).

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all: pass.
  • New tests/pipe_custom_filter_test.rs:
    • trusted_custom_filter_is_applied: trusted .rtk/filters.toml filter runs via pipe -f (noise lines stripped).
    • untrusted_custom_filter_is_rejected: same filter, no trust, exits non-zero with Unknown filter.
    • builtin_toml_filter_works_without_trust: built-in make filter usable via pipe -f.
    • rtk_no_toml_disables_toml_filters_in_pipe: with RTK_NO_TOML=1, a TOML filter name is rejected (Unknown filter).
    • builtin_rust_filter_still_works: grep still works (no regression).
  • New unit tests in pipe_cmd.rs: unknown_filter_message lists built-ins; find_filter_by_name("make") resolves; unknown name returns None.

e2e validation

So far so good, but I will do a final round of e2e checks tomorrow, and set ready for review.

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
@CLAassistant

CLAassistant commented Jul 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rNoz rNoz closed this Jul 14, 2026
@rNoz
rNoz deleted the rnoz/feat-pipe-custom-toml-filters branch July 14, 2026 22:00
@rNoz

rNoz commented Jul 14, 2026

Copy link
Copy Markdown
Author

Closed as forgot one CONTRIBUTING statement (too used to always start with rnoz/ prefix), so favouring the proper PR here: #2999

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.

2 participants