Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86d86915af | ||
|
|
18f4401a93 | ||
|
|
3f37f5a78f | ||
|
|
b2c2914b90 | ||
|
|
91289d761b |
No files matched your search
+1
-1
@@ -1488,4 +1488,4 @@ When implementing a new command, consider:
|
||||
|
||||
**Last Updated**: 2026-02-22
|
||||
**Architecture Version**: 2.2
|
||||
**rtk Version**: 0.28.0
|
||||
**rtk Version**: 0.28.2
|
||||
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Bug Fixes
|
||||
|
||||
* add tokens_saved to telemetry payload ([#471](https://github.com/rtk-ai/rtk/issues/471)) ([#472](https://github.com/rtk-ai/rtk/issues/472)) ([f8b7d52](https://github.com/rtk-ai/rtk/commit/f8b7d52d2d25d09a44f391576bad6a7b271f1f8c))
|
||||
* **proxy:** handle single-quoted command string (shell collapses quotes into one arg) ([#388](https://github.com/rtk-ai/rtk/issues/388))
|
||||
|
||||
## [0.28.1](https://github.com/rtk-ai/rtk/compare/v0.28.0...v0.28.1) (2026-03-10)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ This is a fork with critical fixes for git argument parsing and modern JavaScrip
|
||||
|
||||
**Verify correct installation:**
|
||||
```bash
|
||||
rtk --version # Should show "rtk 0.28.0" (or newer)
|
||||
rtk --version # Should show "rtk 0.28.2" (or newer)
|
||||
rtk gain # Should show token savings stats (NOT "command not found")
|
||||
```
|
||||
|
||||
|
||||
Generated
+1
@@ -853,6 +853,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"shlex",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"toml",
|
||||
|
||||
@@ -30,6 +30,7 @@ tempfile = "3"
|
||||
sha2 = "0.10"
|
||||
ureq = "2"
|
||||
hostname = "0.4"
|
||||
shlex = "1"
|
||||
|
||||
[build-dependencies]
|
||||
toml = "0.8"
|
||||
|
||||
@@ -90,7 +90,7 @@ Download from [releases](https://github.com/rtk-ai/rtk/releases):
|
||||
### Verify Installation
|
||||
|
||||
```bash
|
||||
rtk --version # Should show "rtk 0.28.0"
|
||||
rtk --version # Should show "rtk 0.28.2"
|
||||
rtk gain # Should show token savings stats
|
||||
```
|
||||
|
||||
|
||||
@@ -611,10 +611,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_terraform_unsupported() {
|
||||
match classify_command("terraform plan -var-file=prod.tfvars") {
|
||||
fn test_classify_htop_unsupported() {
|
||||
match classify_command("htop -d 10") {
|
||||
Classification::Unsupported { base_command } => {
|
||||
assert_eq!(base_command, "terraform plan");
|
||||
assert_eq!(base_command, "htop");
|
||||
}
|
||||
other => panic!("expected Unsupported, got {:?}", other),
|
||||
}
|
||||
@@ -886,8 +886,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_rewrite_background_unsupported_right() {
|
||||
assert_eq!(
|
||||
rewrite_command("cargo test & terraform plan", &[]),
|
||||
Some("rtk cargo test & terraform plan".into())
|
||||
rewrite_command("cargo test & htop", &[]),
|
||||
Some("rtk cargo test & htop".into())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -902,7 +902,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_rewrite_unsupported_returns_none() {
|
||||
assert_eq!(rewrite_command("terraform plan", &[]), None);
|
||||
assert_eq!(rewrite_command("htop", &[]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1695,18 +1695,15 @@ mod tests {
|
||||
fn test_rewrite_compound_mixed_supported_unsupported() {
|
||||
// unsupported segments stay raw
|
||||
assert_eq!(
|
||||
rewrite_command("cargo test && terraform plan", &[]),
|
||||
Some("rtk cargo test && terraform plan".into())
|
||||
rewrite_command("cargo test && htop", &[]),
|
||||
Some("rtk cargo test && htop".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rewrite_compound_all_unsupported_returns_none() {
|
||||
// No rewrite at all: returns None
|
||||
assert_eq!(
|
||||
rewrite_command("terraform plan && terraform apply", &[]),
|
||||
None
|
||||
);
|
||||
assert_eq!(rewrite_command("htop && top", &[]), None);
|
||||
}
|
||||
|
||||
// --- sudo / env prefix + rewrite ---
|
||||
|
||||
@@ -48,6 +48,39 @@ pub const PATTERNS: &[&str] = &[
|
||||
r"^aws\s+",
|
||||
// PostgreSQL
|
||||
r"^psql(\s|$)",
|
||||
// TOML-filtered commands
|
||||
r"^ansible-playbook\b",
|
||||
r"^brew\s+(install|upgrade)\b",
|
||||
r"^composer\s+(install|update|require)\b",
|
||||
r"^df(\s|$)",
|
||||
r"^dotnet\s+build\b",
|
||||
r"^du\b",
|
||||
r"^fail2ban-client\b",
|
||||
r"^gcloud\b",
|
||||
r"^hadolint\b",
|
||||
r"^helm\b",
|
||||
r"^iptables\b",
|
||||
r"^make\b",
|
||||
r"^markdownlint\b",
|
||||
r"^mix\s+(compile|format)(\s|$)",
|
||||
r"^mvn\s+(compile|package|clean|install)\b",
|
||||
r"^ping\b",
|
||||
r"^pio\s+run",
|
||||
r"^poetry\s+(install|lock|update)\b",
|
||||
r"^pre-commit\b",
|
||||
r"^ps(\s|$)",
|
||||
r"^quarto\s+render",
|
||||
r"^rsync\b",
|
||||
r"^shellcheck\b",
|
||||
r"^shopify\s+theme\s+(push|pull)",
|
||||
r"^sops\b",
|
||||
r"^swift\s+build\b",
|
||||
r"^systemctl\s+status\b",
|
||||
r"^terraform\s+plan",
|
||||
r"^tofu\s+(fmt|init|plan|validate)(\s|$)",
|
||||
r"^trunk\s+build",
|
||||
r"^uv\s+(sync|pip\s+install)\b",
|
||||
r"^yamllint\b",
|
||||
];
|
||||
|
||||
pub const RULES: &[RtkRule] = &[
|
||||
@@ -317,6 +350,263 @@ pub const RULES: &[RtkRule] = &[
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
// TOML-filtered commands
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy ansible-playbook",
|
||||
rewrite_prefixes: &["ansible-playbook"],
|
||||
category: "Infra",
|
||||
savings_pct: 70.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy brew",
|
||||
rewrite_prefixes: &["brew"],
|
||||
category: "PackageManager",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy composer",
|
||||
rewrite_prefixes: &["composer"],
|
||||
category: "PackageManager",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy df",
|
||||
rewrite_prefixes: &["df"],
|
||||
category: "System",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy dotnet",
|
||||
rewrite_prefixes: &["dotnet"],
|
||||
category: "Build",
|
||||
savings_pct: 70.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy du",
|
||||
rewrite_prefixes: &["du"],
|
||||
category: "System",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy fail2ban-client",
|
||||
rewrite_prefixes: &["fail2ban-client"],
|
||||
category: "Infra",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy gcloud",
|
||||
rewrite_prefixes: &["gcloud"],
|
||||
category: "Infra",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy hadolint",
|
||||
rewrite_prefixes: &["hadolint"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy helm",
|
||||
rewrite_prefixes: &["helm"],
|
||||
category: "Infra",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy iptables",
|
||||
rewrite_prefixes: &["iptables"],
|
||||
category: "Infra",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy make",
|
||||
rewrite_prefixes: &["make"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy markdownlint",
|
||||
rewrite_prefixes: &["markdownlint"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy mix",
|
||||
rewrite_prefixes: &["mix"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy mvn",
|
||||
rewrite_prefixes: &["mvn"],
|
||||
category: "Build",
|
||||
savings_pct: 70.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy ping",
|
||||
rewrite_prefixes: &["ping"],
|
||||
category: "Network",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy pio",
|
||||
rewrite_prefixes: &["pio"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy poetry",
|
||||
rewrite_prefixes: &["poetry"],
|
||||
category: "Python",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy pre-commit",
|
||||
rewrite_prefixes: &["pre-commit"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy ps",
|
||||
rewrite_prefixes: &["ps"],
|
||||
category: "System",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy quarto",
|
||||
rewrite_prefixes: &["quarto"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy rsync",
|
||||
rewrite_prefixes: &["rsync"],
|
||||
category: "Network",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy shellcheck",
|
||||
rewrite_prefixes: &["shellcheck"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy shopify",
|
||||
rewrite_prefixes: &["shopify"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy sops",
|
||||
rewrite_prefixes: &["sops"],
|
||||
category: "Infra",
|
||||
savings_pct: 60.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy swift",
|
||||
rewrite_prefixes: &["swift"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy systemctl",
|
||||
rewrite_prefixes: &["systemctl"],
|
||||
category: "System",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy terraform",
|
||||
rewrite_prefixes: &["terraform"],
|
||||
category: "Infra",
|
||||
savings_pct: 70.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy tofu",
|
||||
rewrite_prefixes: &["tofu"],
|
||||
category: "Infra",
|
||||
savings_pct: 70.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy trunk",
|
||||
rewrite_prefixes: &["trunk"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy uv",
|
||||
rewrite_prefixes: &["uv"],
|
||||
category: "Python",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
RtkRule {
|
||||
rtk_cmd: "rtk proxy yamllint",
|
||||
rewrite_prefixes: &["yamllint"],
|
||||
category: "Build",
|
||||
savings_pct: 65.0,
|
||||
subcmd_savings: &[],
|
||||
subcmd_status: &[],
|
||||
},
|
||||
];
|
||||
|
||||
/// Commands to ignore (shell builtins, trivial, already rtk).
|
||||
|
||||
@@ -50,6 +50,7 @@ pub enum Language {
|
||||
Java,
|
||||
Ruby,
|
||||
Shell,
|
||||
Data,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@@ -66,6 +67,9 @@ impl Language {
|
||||
"java" => Language::Java,
|
||||
"rb" => Language::Ruby,
|
||||
"sh" | "bash" | "zsh" => Language::Shell,
|
||||
"json" | "jsonc" | "json5" | "yaml" | "yml" | "toml" | "xml" | "html" | "htm"
|
||||
| "css" | "scss" | "svg" | "md" | "markdown" | "txt" | "csv" | "tsv" | "env"
|
||||
| "ini" | "cfg" | "conf" | "lock" => Language::Data,
|
||||
_ => Language::Unknown,
|
||||
}
|
||||
}
|
||||
@@ -112,6 +116,13 @@ impl Language {
|
||||
doc_line: None,
|
||||
doc_block_start: None,
|
||||
},
|
||||
Language::Data => CommentPatterns {
|
||||
line: None,
|
||||
block_start: None,
|
||||
block_end: None,
|
||||
doc_line: None,
|
||||
doc_block_start: None,
|
||||
},
|
||||
Language::Unknown => CommentPatterns {
|
||||
line: Some("//"),
|
||||
block_start: Some("/*"),
|
||||
@@ -389,6 +400,52 @@ mod tests {
|
||||
assert_eq!(Language::from_extension("js"), Language::JavaScript);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_language_detection_data_formats() {
|
||||
assert_eq!(Language::from_extension("json"), Language::Data);
|
||||
assert_eq!(Language::from_extension("yaml"), Language::Data);
|
||||
assert_eq!(Language::from_extension("yml"), Language::Data);
|
||||
assert_eq!(Language::from_extension("toml"), Language::Data);
|
||||
assert_eq!(Language::from_extension("xml"), Language::Data);
|
||||
assert_eq!(Language::from_extension("md"), Language::Data);
|
||||
assert_eq!(Language::from_extension("csv"), Language::Data);
|
||||
assert_eq!(Language::from_extension("lock"), Language::Data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_data_files_no_comment_stripping() {
|
||||
// Regression test for #464: package.json with `/*` in strings
|
||||
let json = r#"{
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"packages/*"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bun run --workspaces build"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/package.json": [
|
||||
"sort-package-json"
|
||||
]
|
||||
}
|
||||
}"#;
|
||||
let filter = MinimalFilter;
|
||||
let result = filter.filter(json, &Language::Data);
|
||||
assert!(
|
||||
result.contains("scripts"),
|
||||
"scripts section must be preserved"
|
||||
);
|
||||
assert!(
|
||||
result.contains("packages/*"),
|
||||
"glob pattern must be preserved"
|
||||
);
|
||||
assert!(
|
||||
result.contains("**/package.json"),
|
||||
"glob pattern must be preserved"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minimal_filter_removes_comments() {
|
||||
let code = r#"
|
||||
|
||||
+51
-1
@@ -121,7 +121,16 @@ fn extract_identifier_and_extra_args(args: &[String]) -> Option<(String, Vec<Str
|
||||
}
|
||||
|
||||
// Known gh flags that take a value — skip these and their values
|
||||
let flags_with_value = ["-R", "--repo", "-q", "--jq", "-t", "--template"];
|
||||
let flags_with_value = [
|
||||
"-R",
|
||||
"--repo",
|
||||
"-q",
|
||||
"--jq",
|
||||
"-t",
|
||||
"--template",
|
||||
"--job",
|
||||
"--attempt",
|
||||
];
|
||||
let mut identifier = None;
|
||||
let mut extra = Vec::new();
|
||||
let mut skip_next = false;
|
||||
@@ -1418,6 +1427,47 @@ mod tests {
|
||||
assert!(!should_passthrough_run_view(&["--web".into()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_identifier_with_job_flag_after() {
|
||||
// gh run view 12345 --job 67890
|
||||
let args: Vec<String> = vec!["12345".into(), "--job".into(), "67890".into()];
|
||||
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
|
||||
assert_eq!(id, "12345");
|
||||
assert_eq!(extra, vec!["--job", "67890"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_identifier_with_job_flag_before() {
|
||||
// gh run view --job 67890 12345
|
||||
let args: Vec<String> = vec!["--job".into(), "67890".into(), "12345".into()];
|
||||
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
|
||||
assert_eq!(id, "12345");
|
||||
assert_eq!(extra, vec!["--job", "67890"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_identifier_with_job_and_log_failed() {
|
||||
// gh run view --log-failed --job 67890 12345
|
||||
let args: Vec<String> = vec![
|
||||
"--log-failed".into(),
|
||||
"--job".into(),
|
||||
"67890".into(),
|
||||
"12345".into(),
|
||||
];
|
||||
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
|
||||
assert_eq!(id, "12345");
|
||||
assert_eq!(extra, vec!["--log-failed", "--job", "67890"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_identifier_with_attempt_flag() {
|
||||
// gh run view 12345 --attempt 3
|
||||
let args: Vec<String> = vec!["12345".into(), "--attempt".into(), "3".into()];
|
||||
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
|
||||
assert_eq!(id, "12345");
|
||||
assert_eq!(extra, vec!["--attempt", "3"]);
|
||||
}
|
||||
|
||||
// --- should_passthrough_pr_view tests ---
|
||||
|
||||
#[test]
|
||||
|
||||
+12
-5
@@ -352,9 +352,11 @@ fn run_log(
|
||||
arg.starts_with("--oneline") || arg.starts_with("--pretty") || arg.starts_with("--format")
|
||||
});
|
||||
|
||||
// Check if user provided limit flag
|
||||
// Check if user provided limit flag (-N, -n N, --max-count=N, --max-count N)
|
||||
let has_limit_flag = args.iter().any(|arg| {
|
||||
arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit())
|
||||
(arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit()))
|
||||
|| arg == "-n"
|
||||
|| arg.starts_with("--max-count")
|
||||
});
|
||||
|
||||
// Apply RTK defaults only if user didn't specify them
|
||||
@@ -362,17 +364,22 @@ fn run_log(
|
||||
cmd.args(["--pretty=format:%h %s (%ar) <%an>"]);
|
||||
}
|
||||
|
||||
let limit = if !has_limit_flag {
|
||||
// Only inject -10 limit when RTK is applying its own format.
|
||||
// When user provides --oneline/--pretty/--format, respect git's default (no limit).
|
||||
let limit = if !has_limit_flag && !has_format_flag {
|
||||
cmd.arg("-10");
|
||||
10
|
||||
} else {
|
||||
} else if has_limit_flag {
|
||||
// Extract limit from args if provided
|
||||
args.iter()
|
||||
.find(|arg| {
|
||||
arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit())
|
||||
})
|
||||
.and_then(|arg| arg[1..].parse::<usize>().ok())
|
||||
.unwrap_or(10)
|
||||
.unwrap_or(500)
|
||||
} else {
|
||||
// User format, no limit — use a high cap for filter_log_output
|
||||
500
|
||||
};
|
||||
|
||||
// Only add --no-merges if user didn't explicitly request merge commits
|
||||
|
||||
@@ -121,6 +121,7 @@ fn lang_display_name(lang: &Language) -> &'static str {
|
||||
Language::Java => "Java",
|
||||
Language::Ruby => "Ruby",
|
||||
Language::Shell => "Shell",
|
||||
Language::Data => "Data",
|
||||
Language::Unknown => "Code",
|
||||
}
|
||||
}
|
||||
|
||||
+98
-6
@@ -958,6 +958,35 @@ const RTK_META_COMMANDS: &[&str] = &[
|
||||
"verify",
|
||||
];
|
||||
|
||||
/// Resolve `rtk proxy` arguments, handling the single-quoted-string case.
|
||||
///
|
||||
/// When an LLM writes `rtk proxy 'head -50 file.php'`, the shell strips the quotes
|
||||
/// and delivers `head -50 file.php` as **one** OsString. We detect this (len == 1 with
|
||||
/// spaces) and POSIX-split it with `shlex` so quoted inner arguments like
|
||||
/// `grep -r "pattern with spaces" .` are handled correctly.
|
||||
///
|
||||
/// Falls back to the raw single token when:
|
||||
/// - `shlex` cannot parse (e.g. unmatched quotes)
|
||||
/// - splitting yields an empty token list (e.g. all-whitespace input)
|
||||
/// - the single argument is a path that genuinely contains spaces (ambiguous: we cannot
|
||||
/// distinguish `/Applications/My App` from `My App arg1`; in that case, pass the
|
||||
/// command as multiple args: `rtk proxy /Applications/My\ App arg1`)
|
||||
fn resolve_proxy_args(args: &[std::ffi::OsString]) -> Vec<String> {
|
||||
if args.len() == 1 {
|
||||
let single = args[0].to_string_lossy();
|
||||
if single.contains(' ') {
|
||||
if let Some(tokens) = shlex::split(&single) {
|
||||
if !tokens.is_empty() {
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
args.iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_fallback(parse_error: clap::Error) -> Result<()> {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
|
||||
@@ -1857,17 +1886,15 @@ fn main() -> Result<()> {
|
||||
|
||||
let timer = tracking::TimedExecution::start();
|
||||
|
||||
let cmd_name = args[0].to_string_lossy();
|
||||
let cmd_args: Vec<String> = args[1..]
|
||||
.iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
.collect();
|
||||
let mut effective_args = resolve_proxy_args(&args).into_iter();
|
||||
let cmd_name = effective_args.next().expect("args non-empty checked above");
|
||||
let cmd_args: Vec<String> = effective_args.collect();
|
||||
|
||||
if cli.verbose > 0 {
|
||||
eprintln!("Proxy mode: {} {}", cmd_name, cmd_args.join(" "));
|
||||
}
|
||||
|
||||
let mut child = Command::new(cmd_name.as_ref())
|
||||
let mut child = Command::new(&cmd_name)
|
||||
.args(&cmd_args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -2266,4 +2293,69 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── resolve_proxy_args ────────────────────────────────────────────────────
|
||||
|
||||
fn os(s: &str) -> std::ffi::OsString {
|
||||
std::ffi::OsString::from(s)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_single_quoted_arg_is_split() {
|
||||
// Simulates: rtk proxy 'head -50 app/Models/Domaine.php'
|
||||
// Shell strips quotes → one arg "head -50 app/Models/Domaine.php"
|
||||
let args = vec![os("head -50 app/Models/Domaine.php")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["head", "-50", "app/Models/Domaine.php"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_normal_multi_args_unchanged() {
|
||||
// rtk proxy head -50 app/Models/Domaine.php → 3 separate args, no splitting
|
||||
let args = vec![os("head"), os("-50"), os("app/Models/Domaine.php")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["head", "-50", "app/Models/Domaine.php"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_single_arg_without_spaces_unchanged() {
|
||||
// rtk proxy echo → single arg with no spaces, leave it alone
|
||||
let args = vec![os("echo")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["echo"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_complex_single_quoted_command() {
|
||||
// rtk proxy 'git log --oneline -10'
|
||||
let args = vec![os("git log --oneline -10")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["git", "log", "--oneline", "-10"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_inner_quoted_argument() {
|
||||
// rtk proxy 'grep -r "pattern with spaces" .'
|
||||
// shell delivers: grep -r "pattern with spaces" .
|
||||
let args = vec![os(r#"grep -r "pattern with spaces" ."#)];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["grep", "-r", "pattern with spaces", "."]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_unmatched_quote_fallback() {
|
||||
// shlex returns None on unmatched quotes → fall back to raw single token
|
||||
let args = vec![os("echo \"unterminated")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec!["echo \"unterminated"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_proxy_whitespace_only_arg_fallback() {
|
||||
// shlex splits " " into Ok([]) — empty token list falls back to raw single token
|
||||
// (prevents a panic at the call-site expect())
|
||||
let args = vec![os(" ")];
|
||||
let result = resolve_proxy_args(&args);
|
||||
assert_eq!(result, vec![" "]);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_run_unsupported_returns_none() {
|
||||
assert!(registry::rewrite_command("terraform plan", &[]).is_none());
|
||||
assert!(registry::rewrite_command("htop", &[]).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user