fix(rewrite): skip cat rewrite when incompatible flags present#847
fix(rewrite): skip cat rewrite when incompatible flags present#847MauroDeryckere wants to merge 1 commit intortk-ai:developfrom
Conversation
cat flags like -v, -A, -e, -t, -s have different semantics than rtk read flags (-v means verbose, -n means line numbers). Blindly forwarding flags caused incorrect behavior (e.g. cat -A file → rtk read -A file which fails). Only skip rewrite for incompatible flags. cat -n (line numbers) maps correctly to rtk read -n, so it is still rewritten for token savings. Plain `cat file` continues to rewrite to `rtk read file` as before.
📊 Automated PR Analysis
SummaryFixes the cat-to-rtk-read rewrite to skip commands with incompatible flags (e.g., -A, -v, -e, -t, -s, --show-all) that have different semantics in rtk read, while still allowing the compatible -n flag. Previously, cat with unsupported flags was blindly rewritten, causing rtk read failures. Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Hey We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes No logic changes — only file moves and import path updates. What you need to doRebase your branch on git fetch origin && git rebase origin/developGit detects renames automatically. If you get import conflicts, update the paths: use crate::git; // now: use crate::cmds::git::git;
use crate::tracking; // now: use crate::core::tracking;
use crate::config; // now: use crate::core::config;
use crate::init; // now: use crate::hooks::init;
use crate::gain; // now: use crate::analytics::gain;Need help rebasing? Tag @aeppling |
Summary
cat→rtk readrewrite when cat is invoked with flags that have different semantics thanrtk read(e.g.-A,-v,-e,-t,-s,--show-all)cat -nsince it maps correctly tortk read -n(both mean line numbers)cat filecontinues to rewrite tortk read fileas beforeProblem
rtk rewriteblindly forwards all cat flags tortk read. This causes incorrect behavior because the flags have different semantics:catmeaningrtk readmeaning-n-v-A-e$at EOL-t^I-sFor example,
cat -A file.cppwas rewritten tortk read -A file.cppwhich fails withrtk: Failed to resolve 'read' via PATH.Fix
Early check in
rewrite_segment(): if the command starts withcatand the first argument starts with-(but is not-n), returnNoneto skip the rewrite. This follows the same pattern used forhead -Nandtailspecial cases.Test plan
test_rewrite_cat_with_incompatible_flags_skipped— verifies-A,-v,-e,-t,-s,--show-allall returnNonetest_rewrite_cat_with_compatible_flags— verifiescat -n file.txtrewrites tortk read -n file.txttest_rewrite_cat_filestill passes — plaincat file→rtk read file