Skip to content

feat(rewrite): consult user TOML filters as fallback - #894

Closed
tmchow wants to merge 1 commit into
rtk-ai:developfrom
tmchow:feat/rewrite-consult-toml-filters
Closed

tmchow wants to merge 1 commit into
rtk-ai:developfrom
tmchow:feat/rewrite-consult-toml-filters

Conversation

@tmchow

@tmchow tmchow commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rtk rewrite now checks user TOML filters when no built-in Rust handler matches
  • Commands with TOML-only filters (e.g. ssh, jq, just) get rewritten to rtk <cmd> so the hook routes them through the TOML filter engine
  • Built-in Rust registry retains priority over TOML filters

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets
  • cargo test --all (1131 passed)
  • New tests: TOML-only command matched, no filter returns None, registry priority preserved

What changed

In src/hooks/rewrite_cmd.rs, the None branch of registry::rewrite_command() now calls toml_filter::find_matching_filter(cmd) before exiting with code 1. If a TOML filter matches, the command is rewritten as rtk <cmd> and printed to stdout with the same permission verdict handling as built-in commands.

Three new unit tests verify:

  • ssh root@host ls (TOML-only) is matched by find_matching_filter but not by rewrite_command
  • htop has neither registry nor TOML match
  • git status (registry command) is handled by the registry, never reaching the TOML fallback

This contribution was developed with AI assistance (Claude Code).

Fixes #820

@CLAassistant

CLAassistant commented Mar 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

When `registry::rewrite_command()` returns None (no built-in Rust
handler), check `toml_filter::find_matching_filter()` before giving
up. Commands with user-defined TOML filters (e.g. ssh, jq, just)
now get rewritten to `rtk <cmd>` so the hook can route them through
the TOML filter engine.

Built-in Rust registry retains priority over TOML filters.

Fixes #820
@tmchow
tmchow force-pushed the feat/rewrite-consult-toml-filters branch from 8da6283 to e4b48ee Compare April 18, 2026 00:53
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. The TOML filter fallback landed on develop in #2748 (merged 2026-07-03), which implements it inside the rewrite registry in src/discover/registry.rs so rtk rewrite "ssh root@host ls" now prints rtk ssh root@host ls, with additional handling for exclude lists, absolute paths, reserved command names and pipelines. Your test cases are covered by the test_rewrite_toml_* suite in the same file. Note that filter files are now trust gated, so rtk trust is needed before a user filter is consulted. If some part of this PR was missed, please comment or reopen.

@KuSh KuSh closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk rewrite should consult user TOML filters

3 participants