Skip to content

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

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

feat(pipe): accept built-in and trusted custom TOML filters in pipe -f#2999
rNoz wants to merge 1 commit into
rtk-ai:developfrom
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

Solved and working, proofs in this local screenshot:

image

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

@tapheret2 tapheret2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Files: src/cmds/system/README.md, src/cmds/system/pipe_cmd.rs, src/core/toml_filter.rs, tests/pipe_custom_filter_test.rs
Size: +224 / -19

Notes

  • Tests/fixtures present — good signal for correctness.

Thanks @rNoz — independent review on the patch.

@rNoz

rNoz commented Jul 15, 2026

Copy link
Copy Markdown
Author

Tested E2E locally with my local rnoz/integration branch. All working as expected. See the capture. Ready for review/merge.

@rNoz rNoz marked this pull request as ready for review July 15, 2026 18:02
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