Skip to content

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

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

feat(rewrite): consult user TOML filters as fallback#894
tmchow wants to merge 1 commit intortk-ai:developfrom
tmchow:feat/rewrite-consult-toml-filters

Conversation

@tmchow
Copy link
Copy Markdown

@tmchow tmchow commented Mar 28, 2026

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

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 rtk-ai#820
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

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