Repository navigation
fix(rewrite): apply custom TOML filters during command rewrite - #2226
mikeangstadt wants to merge 3 commits into
Conversation
When ripgrep is not on $PATH, rtk grep falls back to system grep but was passing ripgrep-specific flags like -g/--glob, --hidden, --pcre2, --json, etc. that grep does not understand, causing silent failures or wrong results. Adds a stateful filter that removes rg-only flags (and their value arguments) from the extra_args before passing them to grep. Closes rtk-ai#2167
rtk proxy does not invoke a shell — it spawns the command directly via exec. When users pass compound shell syntax (&&, ||, |, ;, $(), etc.), those tokens end up as literal arguments to the spawned process, causing confusion or incorrect behavior (e.g. bogus files/dirs from shell tokens). Adds detect_shell_snippet() that validates the command name and all args for shell control operators and command substitution syntax, returning a clear error with a suggestion to use `sh -c` or `bash -c` instead. Closes rtk-ai#2163
Custom TOML filters (from .rtk/filters.toml or ~/.config/rtk/filters.toml) were parsed and passed rtk verify, but were never consulted by the hook rewrite path. The rewrite engine (discover/registry.rs) only checked the hardcoded RULES array, returning empty for any unrecognized command. Now, when classify_command returns Unsupported, we check the TomlFilterRegistry for a matching custom filter. If found, the command is rewritten to run through "rtk <original>" so that fallback execution applies the filter pipeline. Closes rtk-ai#2179
|
Hey @mikeangstadt Thanks for addressing this, will enhance all gains for RTK toml users There are some blockers, here are some problems i've identified The PR does not compileCheck ci Exclude-list bypass (regression)The Supported arm honors the user's exclude_commands (registry.rs:813); the new Unsupported+TOML arm does not. I verified is_excluded has exactly one call site and there's no upstream gate, then reproduced it with a unit test on the actual PR code: test repro_control_gcc_rewritten_by_toml ... ok # feature works: gcc → "rtk gcc -o x x.c" With exclude_commands = ["gcc"], the PR still force-wraps the command. A user who excluded a command gets it rewritten anyway whenever any of the 58 built-in filters match. Fix: mirror the is_excluded check (with ENV_PREFIX strip) in the new arm. Needs tests for the new behaviorThis is a behavioral change and we need solid tests to ensure no futures regressions. NotesFix is tested and work well, please drop unrelated grep changes, this belong to another PR. I thing you embedded this maybe by wrong base on one of your others PR, please test the code and the fix for the next review so there is no back and forth for compiling issues for example. Thanks for this contribution , awaiting for your changes ! |
…cation Wire TOML-covered commands into the transparent hook rewrite path, and make TOML truncation reversible via the shared tee hints. Part 1 — hook wiring (rtk-ai#2179): The hook's rewrite decision only consulted the static RULES table, so a command covered solely by a TOML filter (jj, jq, just, ssh, ty, nx, turbo, …) was passed through unfiltered by the hook even though `rtk <cmd>` filtered it directly. `rewrite_segment_inner` now consults the TOML registry on a RULES miss (Unsupported) and rewrites to `rtk <cmd>`, which re-enters via run_fallback → the TOML tier. Guards: honors RTK_NO_TOML, respects the exclude list, never rewrites Ignored (denylisted) commands, and a collision guard (is_rtk_reserved_command) prevents rewriting to a name Clap would route to its own subcommand. RTK_META_COMMANDS moved to core::constants as the shared source. Part 2 — reversibility: TOML truncation on success previously dropped lines with a bare "... omitted" marker and no recovery pointer. apply_filter_with_info now reports a Lossiness (Tail / Whole / None); run_fallback emits the line-offset tail hint (`[see remaining: tail -n +N …]`) for a contiguous tail-drop, the full-output hint otherwise, and — when tee is unavailable — shows the full raw rather than an unrecoverable marker. Fixes the symmetric <500B failure-path gap and an inaccurate MIN_TEE_SIZE comment in curl_cmd. All hosts (claude/gemini/copilot/cursor) and `rtk rewrite` are covered via the shared rewrite_command. No hook JSON / integrity-hash changes. The mirrored RULES rows are kept (they feed discover/session/gain metadata). Builds on the approach of rtk-ai#2226. Note: the TOML registry load now lands on the Unsupported hook hot path (~3-8ms native, one-time per process); the Supported path is unaffected. A match-only RegexSet to cut that cost is a documented follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for the clear write up of the two-systems problem. Issue #2179 was fixed on develop by #2748 (merged 2026-07-03): the rewrite path now consults the TOML filter registry in the Unsupported branch, with extra guards for a disabled TOML engine and for rtk's own reserved commands, and a match only RegexSet so the hook stays fast. The grep hunk on this branch targets src/cmds/system/grep_cmd.rs, which #2641 (merged 2026-06-26) removed when rtk stopped substituting rg for grep, so it cannot be carried over. The proxy case is still open: rtk proxy spawns directly, so &&, |, ; and |
Summary
Custom TOML filters (from
.rtk/filters.tomlor~/.config/rtk/filters.toml) were parsed and passedrtk verify, but were never consulted by the hook rewrite path. The rewrite engine (discover/registry.rs) only checked the hardcodedRULESarray, returning empty for any unrecognized command. This meant user-defined TOML filters were non-functional for their primary purpose.Root Cause
The
rtk rewritepath (used by hooks) has no knowledge of TOML filters. There are two independent systems:discover/rules.rs(hardcoded)rtk rewrite, hook.rtk/filters.toml/~/.config/rtk/filters.toml/ built-inrtk verify,run_fallbackWhen a user runs a command matching a custom TOML filter (e.g.
zzprobe --foo):rtk rewrite 'zzprobe --foo'-> hardcoded rules don't match -> returns empty -> hook passes through unchangedrtkprefix -> TOML filter is never applied during executionChange
In
rewrite_segment_inner()indiscover/registry.rs: whenclassify_command()returnsUnsupported, check theTomlFilterRegistrybefore giving up. If a matching custom TOML filter is found, returnSome(format!("rtk {}/{}", cmd_part, redirect_suffix))-- which causes the hook to run the command throughrtk, whererun_fallback()applies the TOML filter pipeline.This is a minimal change: 10 lines added, 1 modified. Only the
Unsupportedbranch is affected -- built-in rules,Ignoredcommands, and excluded commands are unchanged.Closes #2179
Collaborated & orchestrated by ClosedLoop.AI | GitHub