Compare commits

...
Author SHA1 Message Date
patrickandClaude Opus 4.8 efcbf71609 feat(rules): rewrite mise/just/task runners into rtk (#607 phase 1)
Task runners hide the underlying command from the hook: `mise run lint`
is seen as `mise`, so nothing is rewritten and RTK's filtering never
activates (0% savings). The TOML filters (src/filters/{mise,just,task}.toml,
shipped in v0.31.0) were dormant because no rewrite rule routed these
commands through rtk.

Add 3 rewrite rules mirroring each filter's `match_command` scope:
- `^mise\s+(run|exec|install|upgrade)` -> rtk mise
- `^just`  -> rtk just
- `^task`  -> rtk task

The hook now rewrites the invocation, which flows through run_fallback and
applies the matching TOML filter to strip runner boilerplate. mise is
scoped to task-bearing subcommands so shell integration like
`eval "$(mise activate)"`, `mise ls`, `mise which` is left untouched.

Verified end-to-end against fake runners: boilerplate stripped (mise 77%,
task 87%), exit codes propagated, error output preserved.

Refs #607

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 10:52:14 +02:00
2 changed files with 85 additions and 0 deletions

No files matched your search

+54
View File
@@ -1064,6 +1064,60 @@ mod tests {
);
}
// --- Task runners: mise, just, task (#607) ---
#[test]
fn test_classify_mise_run() {
assert!(matches!(
classify_command("mise run lint"),
Classification::Supported {
rtk_equivalent: "rtk mise",
..
}
));
}
#[test]
fn test_rewrite_mise_run() {
assert_eq!(
rewrite_command_no_prefixes("mise run lint", &[]),
Some("rtk mise run lint".to_string())
);
}
#[test]
fn test_rewrite_mise_exec_and_install() {
assert_eq!(
rewrite_command_no_prefixes("mise exec -- node -v", &[]),
Some("rtk mise exec -- node -v".to_string())
);
assert_eq!(
rewrite_command_no_prefixes("mise install node", &[]),
Some("rtk mise install node".to_string())
);
}
#[test]
fn test_mise_non_task_subcommands_not_rewritten() {
// Only run/exec/install/upgrade are compressed by mise.toml; other
// subcommands (ls, activate, which) must pass through untouched so we
// never wrap shell-integration output like `eval "$(mise activate)"`.
assert_eq!(rewrite_command_no_prefixes("mise ls", &[]), None);
assert_eq!(rewrite_command_no_prefixes("mise activate bash", &[]), None);
}
#[test]
fn test_rewrite_just_and_task() {
assert_eq!(
rewrite_command_no_prefixes("just test", &[]),
Some("rtk just test".to_string())
);
assert_eq!(
rewrite_command_no_prefixes("task build", &[]),
Some("rtk task build".to_string())
);
}
#[test]
fn test_classify_cat_file() {
assert_eq!(
+31
View File
@@ -775,6 +775,37 @@ pub const RULES: &[RtkRule] = &[
subcmd_savings: &[],
subcmd_status: &[],
},
// Task runners (mise, just, task/go-task). The hook rewrites the invocation
// so it flows through run_fallback, which applies the matching TOML filter
// (src/filters/{mise,just,task}.toml) to strip runner boilerplate. Patterns
// mirror each filter's `match_command` scope. See issue #607.
RtkRule {
pattern: r"^mise\s+(run|exec|install|upgrade)(\s|$)",
rtk_cmd: "rtk mise",
rewrite_prefixes: &["mise"],
category: "Build",
savings_pct: 40.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
pattern: r"^just\b",
rtk_cmd: "rtk just",
rewrite_prefixes: &["just"],
category: "Build",
savings_pct: 40.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
pattern: r"^task\b",
rtk_cmd: "rtk task",
rewrite_prefixes: &["task"],
category: "Build",
savings_pct: 40.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
pattern: r"^markdownlint\b",
rtk_cmd: "rtk markdownlint",