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
3 changed files with 110 additions and 24 deletions

No files matched your search

+25 -24
View File
@@ -88,7 +88,7 @@ Download from [releases](https://github.com/rtk-ai/rtk/releases):
- Linux: `rtk-x86_64-unknown-linux-musl.tar.gz` / `rtk-aarch64-unknown-linux-gnu.tar.gz`
- Windows: `rtk-x86_64-pc-windows-msvc.zip`
> **Windows users**: Extract the zip and place `rtk.exe` somewhere in your PATH (e.g. `C:\Users\<you>\.local\bin`). Run RTK from **Command Prompt**, **PowerShell**, or **Windows Terminal** — do not double-click the `.exe` (it will flash and close). The full hook system works natively on Windows (and in [WSL](https://learn.microsoft.com/en-us/windows/wsl/install)). See [Windows setup](#windows) below for details.
> **Windows users**: Extract the zip and place `rtk.exe` somewhere in your PATH (e.g. `C:\Users\<you>\.local\bin`). Run RTK from **Command Prompt**, **PowerShell**, or **Windows Terminal** — do not double-click the `.exe` (it will flash and close). For the best experience, use [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) where the full hook system works natively. See [Windows setup](#windows) below for details.
### Verify Installation
@@ -329,26 +329,11 @@ After install, **restart Claude Code**.
## Windows
RTK works fully on native Windows. Since **v0.37.2** the auto-rewrite hook runs as a **native binary command** (`rtk hook claude`) — no Unix shell, bash, or jq required — so commands are rewritten transparently on Command Prompt, PowerShell, and Windows Terminal, just like on Linux and macOS.
RTK works on Windows with some limitations. The auto-rewrite hook (`rtk-rewrite.sh`) requires a Unix shell, so on native Windows RTK falls back to **CLAUDE.md injection mode** — your AI assistant receives RTK instructions but commands are not rewritten automatically.
### Native Windows
### Recommended: WSL (full support)
```powershell
# 1. Download and extract rtk-x86_64-pc-windows-msvc.zip from releases
# 2. Add rtk.exe to your PATH (e.g. C:\Users\<you>\.local\bin)
# 3. Initialize — installs the native binary hook
rtk init -g
```
**Upgrading from an older install?** If you set RTK up before v0.37.2 you may still have the legacy `rtk-rewrite.sh` shell hook (which does need a Unix shell). Re-run `rtk init -g` to migrate to the native binary hook.
**Prerequisites**: some filters shell out to [ripgrep](https://github.com/BurntSushi/ripgrep) (`rg`). Install it and keep it on your PATH (e.g. `winget install BurntSushi.ripgrep.MSVC`) to avoid `Binary 'rg' not found on PATH` warnings.
**Important**: Do not double-click `rtk.exe` — it is a CLI tool that prints usage and exits immediately. Always run it from a terminal (Command Prompt, PowerShell, or Windows Terminal).
### WSL
[WSL](https://learn.microsoft.com/en-us/windows/wsl/install) also works and behaves exactly like Linux:
For the best experience, use [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) (Windows Subsystem for Linux). Inside WSL, RTK works exactly like Linux — full hook support, auto-rewrite, everything:
```bash
# Inside WSL
@@ -356,11 +341,27 @@ curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/instal
rtk init -g
```
| Feature | Native Windows | WSL |
|---------|----------------|-----|
### Native Windows (limited support)
On native Windows (cmd.exe / PowerShell), RTK filters work but the hook does not auto-rewrite commands:
```powershell
# 1. Download and extract rtk-x86_64-pc-windows-msvc.zip from releases
# 2. Add rtk.exe to your PATH
# 3. Initialize (falls back to CLAUDE.md injection)
rtk init -g
# 4. Use rtk explicitly
rtk cargo test
rtk git status
```
**Important**: Do not double-click `rtk.exe` — it is a CLI tool that prints usage and exits immediately. Always run it from a terminal (Command Prompt, PowerShell, or Windows Terminal).
| Feature | WSL | Native Windows |
|---------|-----|----------------|
| Filters (cargo, git, etc.) | Full | Full |
| Auto-rewrite hook | Yes (native binary) | Yes |
| `rtk init -g` | Hook mode | Hook mode |
| Auto-rewrite hook | Yes | No (CLAUDE.md fallback) |
| `rtk init -g` | Hook mode | CLAUDE.md mode |
| `rtk gain` / analytics | Full | Full |
## Supported AI Tools
@@ -369,7 +370,7 @@ RTK supports 14 AI coding tools. Each integration rewrites shell commands to `rt
| Tool | Install | Method |
|------|---------|--------|
| **Claude Code** | `rtk init -g` | PreToolUse hook (native binary) |
| **Claude Code** | `rtk init -g` | PreToolUse hook (bash) |
| **GitHub Copilot (VS Code)** | `rtk init -g --copilot` | PreToolUse hook — transparent rewrite |
| **GitHub Copilot CLI** | `rtk init -g --copilot` | PreToolUse deny-with-suggestion (CLI limitation) |
| **Cursor** | `rtk init -g --agent cursor` | preToolUse hook (hooks.json) |
+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",