Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59da580aa6 | ||
|
|
9a89f2fe83 | ||
|
|
c89c6ac06e |
No files matched your search
@@ -16,6 +16,8 @@ pub struct Config {
|
||||
pub telemetry: TelemetryConfig,
|
||||
#[serde(default)]
|
||||
pub hooks: HooksConfig,
|
||||
#[serde(default)]
|
||||
pub limits: LimitsConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
@@ -94,6 +96,39 @@ impl Default for TelemetryConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LimitsConfig {
|
||||
/// Max total grep results to show (default: 200)
|
||||
pub grep_max_results: usize,
|
||||
/// Max matches per file in grep output (default: 25)
|
||||
pub grep_max_per_file: usize,
|
||||
/// Max staged/modified files shown in git status (default: 15)
|
||||
pub status_max_files: usize,
|
||||
/// Max untracked files shown in git status (default: 10)
|
||||
pub status_max_untracked: usize,
|
||||
/// Max chars for parser passthrough fallback (default: 2000)
|
||||
pub passthrough_max_chars: usize,
|
||||
}
|
||||
|
||||
impl Default for LimitsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
grep_max_results: 200,
|
||||
grep_max_per_file: 25,
|
||||
status_max_files: 15,
|
||||
status_max_untracked: 10,
|
||||
passthrough_max_chars: 2000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get limits config. Falls back to defaults if config can't be loaded.
|
||||
pub fn limits() -> LimitsConfig {
|
||||
Config::load()
|
||||
.map(|c| c.limits)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Check if telemetry is enabled in config. Returns None if config can't be loaded.
|
||||
pub fn telemetry_enabled() -> Option<bool> {
|
||||
Config::load().ok().map(|c| c.telemetry.enabled)
|
||||
|
||||
+55
-25
@@ -1,3 +1,4 @@
|
||||
use crate::config;
|
||||
use crate::tracking;
|
||||
use crate::utils::resolved_command;
|
||||
use anyhow::{Context, Result};
|
||||
@@ -592,33 +593,37 @@ fn format_status_output(porcelain: &str) -> String {
|
||||
}
|
||||
|
||||
// Build summary
|
||||
let limits = config::limits();
|
||||
let max_files = limits.status_max_files;
|
||||
let max_untracked = limits.status_max_untracked;
|
||||
|
||||
if staged > 0 {
|
||||
output.push_str(&format!("✅ Staged: {} files\n", staged));
|
||||
for f in staged_files.iter().take(5) {
|
||||
for f in staged_files.iter().take(max_files) {
|
||||
output.push_str(&format!(" {}\n", f));
|
||||
}
|
||||
if staged_files.len() > 5 {
|
||||
output.push_str(&format!(" ... +{} more\n", staged_files.len() - 5));
|
||||
if staged_files.len() > max_files {
|
||||
output.push_str(&format!(" ... +{} more\n", staged_files.len() - max_files));
|
||||
}
|
||||
}
|
||||
|
||||
if modified > 0 {
|
||||
output.push_str(&format!("📝 Modified: {} files\n", modified));
|
||||
for f in modified_files.iter().take(5) {
|
||||
for f in modified_files.iter().take(max_files) {
|
||||
output.push_str(&format!(" {}\n", f));
|
||||
}
|
||||
if modified_files.len() > 5 {
|
||||
output.push_str(&format!(" ... +{} more\n", modified_files.len() - 5));
|
||||
if modified_files.len() > max_files {
|
||||
output.push_str(&format!(" ... +{} more\n", modified_files.len() - max_files));
|
||||
}
|
||||
}
|
||||
|
||||
if untracked > 0 {
|
||||
output.push_str(&format!("❓ Untracked: {} files\n", untracked));
|
||||
for f in untracked_files.iter().take(3) {
|
||||
for f in untracked_files.iter().take(max_untracked) {
|
||||
output.push_str(&format!(" {}\n", f));
|
||||
}
|
||||
if untracked_files.len() > 3 {
|
||||
output.push_str(&format!(" ... +{} more\n", untracked_files.len() - 3));
|
||||
if untracked_files.len() > max_untracked {
|
||||
output.push_str(&format!(" ... +{} more\n", untracked_files.len() - max_untracked));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1690,23 +1695,48 @@ A added.rs
|
||||
|
||||
#[test]
|
||||
fn test_format_status_output_truncation() {
|
||||
// Test that >5 staged files show "... +N more"
|
||||
let porcelain = r#"## main
|
||||
M file1.rs
|
||||
M file2.rs
|
||||
M file3.rs
|
||||
M file4.rs
|
||||
M file5.rs
|
||||
M file6.rs
|
||||
M file7.rs
|
||||
"#;
|
||||
let result = format_status_output(porcelain);
|
||||
assert!(result.contains("✅ Staged: 7 files"));
|
||||
// Test that >15 staged files show "... +N more"
|
||||
let mut porcelain = String::from("## main\n");
|
||||
for i in 1..=20 {
|
||||
porcelain.push_str(&format!("M file{}.rs\n", i));
|
||||
}
|
||||
let result = format_status_output(&porcelain);
|
||||
assert!(result.contains("✅ Staged: 20 files"));
|
||||
assert!(result.contains("file1.rs"));
|
||||
assert!(result.contains("file5.rs"));
|
||||
assert!(result.contains("... +2 more"));
|
||||
assert!(!result.contains("file6.rs"));
|
||||
assert!(!result.contains("file7.rs"));
|
||||
assert!(result.contains("file15.rs"));
|
||||
assert!(result.contains("... +5 more"));
|
||||
assert!(!result.contains("file16.rs"));
|
||||
assert!(!result.contains("file20.rs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_status_modified_truncation() {
|
||||
// Test that >15 modified files show "... +N more"
|
||||
let mut porcelain = String::from("## main\n");
|
||||
for i in 1..=20 {
|
||||
porcelain.push_str(&format!(" M file{}.rs\n", i));
|
||||
}
|
||||
let result = format_status_output(&porcelain);
|
||||
assert!(result.contains("📝 Modified: 20 files"));
|
||||
assert!(result.contains("file1.rs"));
|
||||
assert!(result.contains("file15.rs"));
|
||||
assert!(result.contains("... +5 more"));
|
||||
assert!(!result.contains("file16.rs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_status_untracked_truncation() {
|
||||
// Test that >10 untracked files show "... +N more"
|
||||
let mut porcelain = String::from("## main\n");
|
||||
for i in 1..=15 {
|
||||
porcelain.push_str(&format!("?? file{}.rs\n", i));
|
||||
}
|
||||
let result = format_status_output(&porcelain);
|
||||
assert!(result.contains("❓ Untracked: 15 files"));
|
||||
assert!(result.contains("file1.rs"));
|
||||
assert!(result.contains("file10.rs"));
|
||||
assert!(result.contains("... +5 more"));
|
||||
assert!(!result.contains("file11.rs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
use crate::config;
|
||||
use crate::tracking;
|
||||
use crate::utils::{resolved_command, truncate};
|
||||
use anyhow::{Context, Result};
|
||||
@@ -106,7 +107,7 @@ fn filter_golangci_json(output: &str) -> String {
|
||||
return format!(
|
||||
"golangci-lint (JSON parse failed: {})\n{}",
|
||||
e,
|
||||
truncate(output, 500)
|
||||
truncate(output, config::limits().passthrough_max_chars)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+5
-3
@@ -1,3 +1,4 @@
|
||||
use crate::config;
|
||||
use crate::tracking;
|
||||
use crate::utils::resolved_command;
|
||||
use anyhow::{Context, Result};
|
||||
@@ -110,7 +111,8 @@ pub fn run(
|
||||
let file_display = compact_path(file);
|
||||
rtk_output.push_str(&format!("📄 {} ({}):\n", file_display, matches.len()));
|
||||
|
||||
for (line_num, content) in matches.iter().take(10) {
|
||||
let per_file = config::limits().grep_max_per_file;
|
||||
for (line_num, content) in matches.iter().take(per_file) {
|
||||
rtk_output.push_str(&format!(" {:>4}: {}\n", line_num, content));
|
||||
shown += 1;
|
||||
if shown >= max_results {
|
||||
@@ -118,8 +120,8 @@ pub fn run(
|
||||
}
|
||||
}
|
||||
|
||||
if matches.len() > 10 {
|
||||
rtk_output.push_str(&format!(" +{}\n", matches.len() - 10));
|
||||
if matches.len() > per_file {
|
||||
rtk_output.push_str(&format!(" +{}\n", matches.len() - per_file));
|
||||
}
|
||||
rtk_output.push('\n');
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
use crate::config;
|
||||
use crate::mypy_cmd;
|
||||
use crate::ruff_cmd;
|
||||
use crate::tracking;
|
||||
@@ -234,7 +235,7 @@ fn filter_eslint_json(output: &str) -> String {
|
||||
return format!(
|
||||
"ESLint output (JSON parse failed: {})\n{}",
|
||||
e,
|
||||
truncate(output, 500)
|
||||
truncate(output, config::limits().passthrough_max_chars)
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -326,7 +327,7 @@ fn filter_pylint_json(output: &str) -> String {
|
||||
return format!(
|
||||
"Pylint output (JSON parse failed: {})\n{}",
|
||||
e,
|
||||
truncate(output, 500)
|
||||
truncate(output, config::limits().passthrough_max_chars)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -306,7 +306,7 @@ enum Commands {
|
||||
#[arg(short = 'l', long, default_value = "80")]
|
||||
max_len: usize,
|
||||
/// Max results to show
|
||||
#[arg(short, long, default_value = "50")]
|
||||
#[arg(short, long, default_value = "200")]
|
||||
max: usize,
|
||||
/// Show only match context (not full line)
|
||||
#[arg(short, long)]
|
||||
|
||||
@@ -70,7 +70,7 @@ impl OutputParser for VitestParser {
|
||||
)
|
||||
} else {
|
||||
// Tier 3: Passthrough
|
||||
ParseResult::Passthrough(truncate_output(input, 500))
|
||||
ParseResult::Passthrough(truncate_output(input, 2000))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -89,12 +89,18 @@ pub trait OutputParser: Sized {
|
||||
let result = Self::parse(input);
|
||||
if result.tier() > max_tier {
|
||||
// Force degradation to passthrough if exceeds max tier
|
||||
return ParseResult::Passthrough(truncate_output(input, 500));
|
||||
return ParseResult::Passthrough(truncate_passthrough(input));
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/// Truncate output using configured passthrough limit
|
||||
pub fn truncate_passthrough(output: &str) -> String {
|
||||
let max_chars = crate::config::limits().passthrough_max_chars;
|
||||
truncate_output(output, max_chars)
|
||||
}
|
||||
|
||||
/// Truncate output to max length with ellipsis
|
||||
pub fn truncate_output(output: &str, max_chars: usize) -> String {
|
||||
let chars: Vec<char> = output.chars().collect();
|
||||
|
||||
@@ -5,7 +5,7 @@ use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::parser::{
|
||||
emit_degradation_warning, emit_passthrough_warning, truncate_output, FormatMode, OutputParser,
|
||||
emit_degradation_warning, emit_passthrough_warning, truncate_passthrough, FormatMode, OutputParser,
|
||||
ParseResult, TestFailure, TestResult, TokenFormatter,
|
||||
};
|
||||
|
||||
@@ -110,7 +110,7 @@ impl OutputParser for PlaywrightParser {
|
||||
}
|
||||
None => {
|
||||
// Tier 3: Passthrough
|
||||
ParseResult::Passthrough(truncate_output(input, 500))
|
||||
ParseResult::Passthrough(truncate_passthrough(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
|
||||
use crate::parser::{
|
||||
emit_degradation_warning, emit_passthrough_warning, truncate_output, Dependency,
|
||||
emit_degradation_warning, emit_passthrough_warning, truncate_passthrough, Dependency,
|
||||
DependencyState, FormatMode, OutputParser, ParseResult, TokenFormatter,
|
||||
};
|
||||
|
||||
@@ -75,7 +75,7 @@ impl OutputParser for PnpmListParser {
|
||||
}
|
||||
None => {
|
||||
// Tier 3: Passthrough
|
||||
ParseResult::Passthrough(truncate_output(input, 500))
|
||||
ParseResult::Passthrough(truncate_passthrough(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ impl OutputParser for PnpmOutdatedParser {
|
||||
}
|
||||
None => {
|
||||
// Tier 3: Passthrough
|
||||
ParseResult::Passthrough(truncate_output(input, 500))
|
||||
ParseResult::Passthrough(truncate_passthrough(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
use crate::config;
|
||||
use crate::tracking;
|
||||
use crate::utils::{resolved_command, truncate};
|
||||
use anyhow::{Context, Result};
|
||||
@@ -121,7 +122,7 @@ pub fn filter_ruff_check_json(output: &str) -> String {
|
||||
return format!(
|
||||
"Ruff check (JSON parse failed: {})\n{}",
|
||||
e,
|
||||
truncate(output, 500)
|
||||
truncate(output, config::limits().passthrough_max_chars)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::parser::{
|
||||
emit_degradation_warning, emit_passthrough_warning, extract_json_object, truncate_output,
|
||||
emit_degradation_warning, emit_passthrough_warning, extract_json_object, truncate_passthrough,
|
||||
FormatMode, OutputParser, ParseResult, TestFailure, TestResult, TokenFormatter,
|
||||
};
|
||||
use crate::tracking;
|
||||
@@ -88,7 +88,7 @@ impl OutputParser for VitestParser {
|
||||
}
|
||||
None => {
|
||||
// Tier 3: Passthrough
|
||||
ParseResult::Passthrough(truncate_output(input, 500))
|
||||
ParseResult::Passthrough(truncate_passthrough(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user