@hasna/terminal 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +29 -12
- package/package.json +1 -1
- package/src/ai.ts +50 -36
- package/src/cli.tsx +29 -12
- package/src/context-hints.ts +89 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-store.ts +65 -0
- package/src/providers/index.ts +4 -4
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
use crate::tracking;
|
|
2
|
+
use crate::utils::{strip_ansi, truncate};
|
|
3
|
+
use anyhow::{Context, Result};
|
|
4
|
+
use regex::Regex;
|
|
5
|
+
use std::collections::HashMap;
|
|
6
|
+
use std::process::Command;
|
|
7
|
+
|
|
8
|
+
pub fn run(args: &[String], verbose: u8) -> Result<()> {
|
|
9
|
+
let timer = tracking::TimedExecution::start();
|
|
10
|
+
|
|
11
|
+
let mut cmd = if which_command("mypy").is_some() {
|
|
12
|
+
Command::new("mypy")
|
|
13
|
+
} else {
|
|
14
|
+
let mut c = Command::new("python3");
|
|
15
|
+
c.arg("-m").arg("mypy");
|
|
16
|
+
c
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
for arg in args {
|
|
20
|
+
cmd.arg(arg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if verbose > 0 {
|
|
24
|
+
eprintln!("Running: mypy {}", args.join(" "));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let output = cmd
|
|
28
|
+
.output()
|
|
29
|
+
.context("Failed to run mypy. Is it installed? Try: pip install mypy")?;
|
|
30
|
+
|
|
31
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
32
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
33
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
34
|
+
let clean = strip_ansi(&raw);
|
|
35
|
+
|
|
36
|
+
let filtered = filter_mypy_output(&clean);
|
|
37
|
+
|
|
38
|
+
println!("{}", filtered);
|
|
39
|
+
|
|
40
|
+
timer.track(
|
|
41
|
+
&format!("mypy {}", args.join(" ")),
|
|
42
|
+
&format!("rtk mypy {}", args.join(" ")),
|
|
43
|
+
&raw,
|
|
44
|
+
&filtered,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
std::process::exit(output.status.code().unwrap_or(1));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn which_command(cmd: &str) -> Option<String> {
|
|
51
|
+
Command::new("which")
|
|
52
|
+
.arg(cmd)
|
|
53
|
+
.output()
|
|
54
|
+
.ok()
|
|
55
|
+
.filter(|o| o.status.success())
|
|
56
|
+
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
57
|
+
.map(|s| s.trim().to_string())
|
|
58
|
+
.filter(|s| !s.is_empty())
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
struct MypyError {
|
|
62
|
+
file: String,
|
|
63
|
+
line: usize,
|
|
64
|
+
code: String,
|
|
65
|
+
message: String,
|
|
66
|
+
context_lines: Vec<String>,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn filter_mypy_output(output: &str) -> String {
|
|
70
|
+
lazy_static::lazy_static! {
|
|
71
|
+
// file.py:12: error: Message [error-code]
|
|
72
|
+
// file.py:12:5: error: Message [error-code]
|
|
73
|
+
static ref MYPY_DIAG: Regex = Regex::new(
|
|
74
|
+
r"^(.+?):(\d+)(?::\d+)?: (error|warning|note): (.+?)(?:\s+\[(.+)\])?$"
|
|
75
|
+
).unwrap();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let lines: Vec<&str> = output.lines().collect();
|
|
79
|
+
let mut errors: Vec<MypyError> = Vec::new();
|
|
80
|
+
let mut fileless_lines: Vec<String> = Vec::new();
|
|
81
|
+
let mut i = 0;
|
|
82
|
+
|
|
83
|
+
while i < lines.len() {
|
|
84
|
+
let line = lines[i];
|
|
85
|
+
|
|
86
|
+
// Skip mypy's own summary line
|
|
87
|
+
if line.starts_with("Found ") && line.contains(" error") {
|
|
88
|
+
i += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// Skip "Success: no issues found"
|
|
92
|
+
if line.starts_with("Success:") {
|
|
93
|
+
i += 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if let Some(caps) = MYPY_DIAG.captures(line) {
|
|
98
|
+
let severity = &caps[3];
|
|
99
|
+
let file = caps[1].to_string();
|
|
100
|
+
let line_num: usize = caps[2].parse().unwrap_or(0);
|
|
101
|
+
let message = caps[4].to_string();
|
|
102
|
+
let code = caps
|
|
103
|
+
.get(5)
|
|
104
|
+
.map(|m| m.as_str().to_string())
|
|
105
|
+
.unwrap_or_default();
|
|
106
|
+
|
|
107
|
+
if severity == "note" {
|
|
108
|
+
// Attach note to preceding error if same file and line
|
|
109
|
+
if let Some(last) = errors.last_mut() {
|
|
110
|
+
if last.file == file {
|
|
111
|
+
last.context_lines.push(message);
|
|
112
|
+
i += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Standalone note with no parent -- display as fileless
|
|
117
|
+
fileless_lines.push(line.to_string());
|
|
118
|
+
i += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let mut err = MypyError {
|
|
123
|
+
file,
|
|
124
|
+
line: line_num,
|
|
125
|
+
code,
|
|
126
|
+
message,
|
|
127
|
+
context_lines: Vec::new(),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Capture continuation note lines
|
|
131
|
+
i += 1;
|
|
132
|
+
while i < lines.len() {
|
|
133
|
+
if let Some(next_caps) = MYPY_DIAG.captures(lines[i]) {
|
|
134
|
+
if &next_caps[3] == "note" && next_caps[1] == err.file {
|
|
135
|
+
let note_msg = next_caps[4].to_string();
|
|
136
|
+
err.context_lines.push(note_msg);
|
|
137
|
+
i += 1;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
errors.push(err);
|
|
145
|
+
} else if line.contains("error:") && !line.trim().is_empty() {
|
|
146
|
+
// File-less error (config errors, import errors)
|
|
147
|
+
fileless_lines.push(line.to_string());
|
|
148
|
+
i += 1;
|
|
149
|
+
} else {
|
|
150
|
+
i += 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// No errors at all
|
|
155
|
+
if errors.is_empty() && fileless_lines.is_empty() {
|
|
156
|
+
if output.contains("Success: no issues found") || output.contains("no issues found") {
|
|
157
|
+
return "mypy: No issues found".to_string();
|
|
158
|
+
}
|
|
159
|
+
return "mypy: No issues found".to_string();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Group by file
|
|
163
|
+
let mut by_file: HashMap<String, Vec<&MypyError>> = HashMap::new();
|
|
164
|
+
for err in &errors {
|
|
165
|
+
by_file.entry(err.file.clone()).or_default().push(err);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Count by error code
|
|
169
|
+
let mut by_code: HashMap<String, usize> = HashMap::new();
|
|
170
|
+
for err in &errors {
|
|
171
|
+
if !err.code.is_empty() {
|
|
172
|
+
*by_code.entry(err.code.clone()).or_insert(0) += 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let mut result = String::new();
|
|
177
|
+
|
|
178
|
+
// File-less errors first
|
|
179
|
+
for line in &fileless_lines {
|
|
180
|
+
result.push_str(line);
|
|
181
|
+
result.push('\n');
|
|
182
|
+
}
|
|
183
|
+
if !fileless_lines.is_empty() && !errors.is_empty() {
|
|
184
|
+
result.push('\n');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if !errors.is_empty() {
|
|
188
|
+
result.push_str(&format!(
|
|
189
|
+
"mypy: {} errors in {} files\n",
|
|
190
|
+
errors.len(),
|
|
191
|
+
by_file.len()
|
|
192
|
+
));
|
|
193
|
+
result.push_str("═══════════════════════════════════════\n");
|
|
194
|
+
|
|
195
|
+
// Top error codes summary (only when 2+ distinct codes)
|
|
196
|
+
let mut code_counts: Vec<_> = by_code.iter().collect();
|
|
197
|
+
code_counts.sort_by(|a, b| b.1.cmp(a.1));
|
|
198
|
+
|
|
199
|
+
if code_counts.len() > 1 {
|
|
200
|
+
let codes_str: Vec<String> = code_counts
|
|
201
|
+
.iter()
|
|
202
|
+
.take(5)
|
|
203
|
+
.map(|(code, count)| format!("{} ({}x)", code, count))
|
|
204
|
+
.collect();
|
|
205
|
+
result.push_str(&format!("Top codes: {}\n\n", codes_str.join(", ")));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Files sorted by error count (most errors first)
|
|
209
|
+
let mut files_sorted: Vec<_> = by_file.iter().collect();
|
|
210
|
+
files_sorted.sort_by(|a, b| b.1.len().cmp(&a.1.len()));
|
|
211
|
+
|
|
212
|
+
for (file, file_errors) in &files_sorted {
|
|
213
|
+
result.push_str(&format!("{} ({} errors)\n", file, file_errors.len()));
|
|
214
|
+
|
|
215
|
+
for err in *file_errors {
|
|
216
|
+
if err.code.is_empty() {
|
|
217
|
+
result.push_str(&format!(
|
|
218
|
+
" L{}: {}\n",
|
|
219
|
+
err.line,
|
|
220
|
+
truncate(&err.message, 120)
|
|
221
|
+
));
|
|
222
|
+
} else {
|
|
223
|
+
result.push_str(&format!(
|
|
224
|
+
" L{}: [{}] {}\n",
|
|
225
|
+
err.line,
|
|
226
|
+
err.code,
|
|
227
|
+
truncate(&err.message, 120)
|
|
228
|
+
));
|
|
229
|
+
}
|
|
230
|
+
for ctx in &err.context_lines {
|
|
231
|
+
result.push_str(&format!(" {}\n", truncate(ctx, 120)));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
result.push('\n');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
result.trim().to_string()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#[cfg(test)]
|
|
242
|
+
mod tests {
|
|
243
|
+
use super::*;
|
|
244
|
+
|
|
245
|
+
#[test]
|
|
246
|
+
fn test_filter_mypy_errors_grouped_by_file() {
|
|
247
|
+
let output = "\
|
|
248
|
+
src/server/auth.py:12: error: Incompatible return value type (got \"str\", expected \"int\") [return-value]
|
|
249
|
+
src/server/auth.py:15: error: Argument 1 has incompatible type \"int\"; expected \"str\" [arg-type]
|
|
250
|
+
src/models/user.py:8: error: Name \"foo\" is not defined [name-defined]
|
|
251
|
+
src/models/user.py:10: error: Incompatible types in assignment [assignment]
|
|
252
|
+
src/models/user.py:20: error: Missing return statement [return]
|
|
253
|
+
Found 5 errors in 2 files (checked 10 source files)
|
|
254
|
+
";
|
|
255
|
+
let result = filter_mypy_output(output);
|
|
256
|
+
assert!(result.contains("mypy: 5 errors in 2 files"));
|
|
257
|
+
// user.py has 3 errors, auth.py has 2 -- user.py should come first
|
|
258
|
+
let user_pos = result.find("user.py").unwrap();
|
|
259
|
+
let auth_pos = result.find("auth.py").unwrap();
|
|
260
|
+
assert!(
|
|
261
|
+
user_pos < auth_pos,
|
|
262
|
+
"user.py (3 errors) should appear before auth.py (2 errors)"
|
|
263
|
+
);
|
|
264
|
+
assert!(result.contains("user.py (3 errors)"));
|
|
265
|
+
assert!(result.contains("auth.py (2 errors)"));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
#[test]
|
|
269
|
+
fn test_filter_mypy_with_column_numbers() {
|
|
270
|
+
let output = "\
|
|
271
|
+
src/api.py:10:5: error: Incompatible return value type [return-value]
|
|
272
|
+
";
|
|
273
|
+
let result = filter_mypy_output(output);
|
|
274
|
+
assert!(result.contains("L10:"));
|
|
275
|
+
assert!(result.contains("[return-value]"));
|
|
276
|
+
assert!(result.contains("Incompatible return value type"));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
#[test]
|
|
280
|
+
fn test_filter_mypy_top_codes_summary() {
|
|
281
|
+
let output = "\
|
|
282
|
+
a.py:1: error: Error one [return-value]
|
|
283
|
+
a.py:2: error: Error two [return-value]
|
|
284
|
+
a.py:3: error: Error three [return-value]
|
|
285
|
+
b.py:1: error: Error four [name-defined]
|
|
286
|
+
c.py:1: error: Error five [arg-type]
|
|
287
|
+
Found 5 errors in 3 files
|
|
288
|
+
";
|
|
289
|
+
let result = filter_mypy_output(output);
|
|
290
|
+
assert!(result.contains("Top codes:"));
|
|
291
|
+
assert!(result.contains("return-value (3x)"));
|
|
292
|
+
assert!(result.contains("name-defined (1x)"));
|
|
293
|
+
assert!(result.contains("arg-type (1x)"));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#[test]
|
|
297
|
+
fn test_filter_mypy_single_code_no_summary() {
|
|
298
|
+
let output = "\
|
|
299
|
+
a.py:1: error: Error one [return-value]
|
|
300
|
+
a.py:2: error: Error two [return-value]
|
|
301
|
+
b.py:1: error: Error three [return-value]
|
|
302
|
+
Found 3 errors in 2 files
|
|
303
|
+
";
|
|
304
|
+
let result = filter_mypy_output(output);
|
|
305
|
+
assert!(
|
|
306
|
+
!result.contains("Top codes:"),
|
|
307
|
+
"Top codes should not appear with only one distinct code"
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#[test]
|
|
312
|
+
fn test_filter_mypy_every_error_shown() {
|
|
313
|
+
let output = "\
|
|
314
|
+
src/api.py:10: error: Type \"str\" not assignable to \"int\" [assignment]
|
|
315
|
+
src/api.py:20: error: Missing return statement [return]
|
|
316
|
+
src/api.py:30: error: Name \"bar\" is not defined [name-defined]
|
|
317
|
+
";
|
|
318
|
+
let result = filter_mypy_output(output);
|
|
319
|
+
assert!(result.contains("Type \"str\" not assignable to \"int\""));
|
|
320
|
+
assert!(result.contains("Missing return statement"));
|
|
321
|
+
assert!(result.contains("Name \"bar\" is not defined"));
|
|
322
|
+
assert!(result.contains("L10:"));
|
|
323
|
+
assert!(result.contains("L20:"));
|
|
324
|
+
assert!(result.contains("L30:"));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
#[test]
|
|
328
|
+
fn test_filter_mypy_note_continuation() {
|
|
329
|
+
let output = "\
|
|
330
|
+
src/app.py:10: error: Incompatible types in assignment [assignment]
|
|
331
|
+
src/app.py:10: note: Expected type \"int\"
|
|
332
|
+
src/app.py:10: note: Got type \"str\"
|
|
333
|
+
src/app.py:20: error: Missing return statement [return]
|
|
334
|
+
";
|
|
335
|
+
let result = filter_mypy_output(output);
|
|
336
|
+
assert!(result.contains("Incompatible types in assignment"));
|
|
337
|
+
assert!(result.contains("Expected type \"int\""));
|
|
338
|
+
assert!(result.contains("Got type \"str\""));
|
|
339
|
+
assert!(result.contains("L10:"));
|
|
340
|
+
assert!(result.contains("L20:"));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
#[test]
|
|
344
|
+
fn test_filter_mypy_fileless_errors() {
|
|
345
|
+
let output = "\
|
|
346
|
+
mypy: error: No module named 'nonexistent'
|
|
347
|
+
src/api.py:10: error: Name \"foo\" is not defined [name-defined]
|
|
348
|
+
Found 1 error in 1 file
|
|
349
|
+
";
|
|
350
|
+
let result = filter_mypy_output(output);
|
|
351
|
+
// File-less error should appear verbatim before grouped output
|
|
352
|
+
assert!(result.contains("mypy: error: No module named 'nonexistent'"));
|
|
353
|
+
assert!(result.contains("api.py (1 error"));
|
|
354
|
+
let fileless_pos = result.find("No module named").unwrap();
|
|
355
|
+
let grouped_pos = result.find("api.py").unwrap();
|
|
356
|
+
assert!(
|
|
357
|
+
fileless_pos < grouped_pos,
|
|
358
|
+
"File-less errors should appear before grouped file errors"
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#[test]
|
|
363
|
+
fn test_filter_mypy_no_errors() {
|
|
364
|
+
let output = "Success: no issues found in 5 source files\n";
|
|
365
|
+
let result = filter_mypy_output(output);
|
|
366
|
+
assert_eq!(result, "mypy: No issues found");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
#[test]
|
|
370
|
+
fn test_filter_mypy_no_file_limit() {
|
|
371
|
+
let mut output = String::new();
|
|
372
|
+
for i in 1..=15 {
|
|
373
|
+
output.push_str(&format!(
|
|
374
|
+
"src/file{}.py:{}: error: Error in file {}. [assignment]\n",
|
|
375
|
+
i, i, i
|
|
376
|
+
));
|
|
377
|
+
}
|
|
378
|
+
output.push_str("Found 15 errors in 15 files\n");
|
|
379
|
+
let result = filter_mypy_output(&output);
|
|
380
|
+
assert!(result.contains("15 errors in 15 files"));
|
|
381
|
+
for i in 1..=15 {
|
|
382
|
+
assert!(
|
|
383
|
+
result.contains(&format!("file{}.py", i)),
|
|
384
|
+
"file{}.py missing from output",
|
|
385
|
+
i
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
use crate::tracking;
|
|
2
|
+
use crate::utils::{strip_ansi, truncate};
|
|
3
|
+
use anyhow::{Context, Result};
|
|
4
|
+
use regex::Regex;
|
|
5
|
+
use std::process::Command;
|
|
6
|
+
|
|
7
|
+
pub fn run(args: &[String], verbose: u8) -> Result<()> {
|
|
8
|
+
let timer = tracking::TimedExecution::start();
|
|
9
|
+
|
|
10
|
+
// Try next directly first, fallback to npx if not found
|
|
11
|
+
let next_exists = Command::new("which")
|
|
12
|
+
.arg("next")
|
|
13
|
+
.output()
|
|
14
|
+
.map(|o| o.status.success())
|
|
15
|
+
.unwrap_or(false);
|
|
16
|
+
|
|
17
|
+
let mut cmd = if next_exists {
|
|
18
|
+
Command::new("next")
|
|
19
|
+
} else {
|
|
20
|
+
let mut c = Command::new("npx");
|
|
21
|
+
c.arg("next");
|
|
22
|
+
c
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
cmd.arg("build");
|
|
26
|
+
|
|
27
|
+
for arg in args {
|
|
28
|
+
cmd.arg(arg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if verbose > 0 {
|
|
32
|
+
let tool = if next_exists { "next" } else { "npx next" };
|
|
33
|
+
eprintln!("Running: {} build", tool);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let output = cmd
|
|
37
|
+
.output()
|
|
38
|
+
.context("Failed to run next build (try: npm install -g next)")?;
|
|
39
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
40
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
41
|
+
let raw = format!("{}\n{}", stdout, stderr);
|
|
42
|
+
|
|
43
|
+
let filtered = filter_next_build(&raw);
|
|
44
|
+
|
|
45
|
+
println!("{}", filtered);
|
|
46
|
+
|
|
47
|
+
timer.track("next build", "rtk next build", &raw, &filtered);
|
|
48
|
+
|
|
49
|
+
// Preserve exit code for CI/CD
|
|
50
|
+
if !output.status.success() {
|
|
51
|
+
std::process::exit(output.status.code().unwrap_or(1));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Ok(())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Filter Next.js build output - extract routes, bundles, warnings
|
|
58
|
+
fn filter_next_build(output: &str) -> String {
|
|
59
|
+
lazy_static::lazy_static! {
|
|
60
|
+
// Route line pattern: ○ /dashboard 1.2 kB 132 kB
|
|
61
|
+
static ref ROUTE_PATTERN: Regex = Regex::new(
|
|
62
|
+
r"^[○●◐λ✓]\s+(/[^\s]*)\s+(\d+(?:\.\d+)?)\s*(kB|B)"
|
|
63
|
+
).unwrap();
|
|
64
|
+
|
|
65
|
+
// Bundle size pattern
|
|
66
|
+
static ref BUNDLE_PATTERN: Regex = Regex::new(
|
|
67
|
+
r"^[○●◐λ✓]\s+([\w/\-\.]+)\s+(\d+(?:\.\d+)?)\s*(kB|B)\s+(\d+(?:\.\d+)?)\s*(kB|B)"
|
|
68
|
+
).unwrap();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let mut routes_static = 0;
|
|
72
|
+
let mut routes_dynamic = 0;
|
|
73
|
+
let mut routes_total = 0;
|
|
74
|
+
let mut bundles: Vec<(String, f64, Option<f64>)> = Vec::new();
|
|
75
|
+
let mut warnings = 0;
|
|
76
|
+
let mut errors = 0;
|
|
77
|
+
let mut build_time = String::new();
|
|
78
|
+
|
|
79
|
+
// Strip ANSI codes
|
|
80
|
+
let clean_output = strip_ansi(output);
|
|
81
|
+
|
|
82
|
+
for line in clean_output.lines() {
|
|
83
|
+
// Count route types by symbol
|
|
84
|
+
if line.starts_with("○") {
|
|
85
|
+
routes_static += 1;
|
|
86
|
+
routes_total += 1;
|
|
87
|
+
} else if line.starts_with("●") || line.starts_with("◐") {
|
|
88
|
+
routes_dynamic += 1;
|
|
89
|
+
routes_total += 1;
|
|
90
|
+
} else if line.starts_with("λ") {
|
|
91
|
+
routes_total += 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Extract bundle information (route + size + total size)
|
|
95
|
+
if let Some(caps) = BUNDLE_PATTERN.captures(line) {
|
|
96
|
+
let route = caps[1].to_string();
|
|
97
|
+
let size: f64 = caps[2].parse().unwrap_or(0.0);
|
|
98
|
+
let total: f64 = caps[4].parse().unwrap_or(0.0);
|
|
99
|
+
|
|
100
|
+
// Calculate percentage increase if both sizes present
|
|
101
|
+
let pct_change = if total > 0.0 {
|
|
102
|
+
Some(((total - size) / size) * 100.0)
|
|
103
|
+
} else {
|
|
104
|
+
None
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
bundles.push((route, total, pct_change));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Count warnings and errors
|
|
111
|
+
if line.to_lowercase().contains("warning") {
|
|
112
|
+
warnings += 1;
|
|
113
|
+
}
|
|
114
|
+
if line.to_lowercase().contains("error") && !line.contains("0 error") {
|
|
115
|
+
errors += 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Extract build time
|
|
119
|
+
if line.contains("Compiled") || line.contains("in") {
|
|
120
|
+
if let Some(time_match) = extract_time(line) {
|
|
121
|
+
build_time = time_match;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Detect if build was skipped (already built)
|
|
127
|
+
let already_built = clean_output.contains("already optimized")
|
|
128
|
+
|| clean_output.contains("Cache")
|
|
129
|
+
|| (routes_total == 0 && clean_output.contains("Ready"));
|
|
130
|
+
|
|
131
|
+
// Build filtered output
|
|
132
|
+
let mut result = String::new();
|
|
133
|
+
result.push_str("⚡ Next.js Build\n");
|
|
134
|
+
result.push_str("═══════════════════════════════════════\n");
|
|
135
|
+
|
|
136
|
+
if already_built && routes_total == 0 {
|
|
137
|
+
result.push_str("✓ Already built (using cache)\n\n");
|
|
138
|
+
} else if routes_total > 0 {
|
|
139
|
+
result.push_str(&format!(
|
|
140
|
+
"✓ {} routes ({} static, {} dynamic)\n\n",
|
|
141
|
+
routes_total, routes_static, routes_dynamic
|
|
142
|
+
));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if !bundles.is_empty() {
|
|
146
|
+
result.push_str("Bundles:\n");
|
|
147
|
+
|
|
148
|
+
// Sort by size (descending) and show top 10
|
|
149
|
+
bundles.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal));
|
|
150
|
+
|
|
151
|
+
for (route, size, pct_change) in bundles.iter().take(10) {
|
|
152
|
+
let warning_marker = if let Some(pct) = pct_change {
|
|
153
|
+
if *pct > 10.0 {
|
|
154
|
+
format!(" ⚠️ (+{:.0}%)", pct)
|
|
155
|
+
} else {
|
|
156
|
+
String::new()
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
String::new()
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
result.push_str(&format!(
|
|
163
|
+
" {:<30} {:>6.0} kB{}\n",
|
|
164
|
+
truncate(route, 30),
|
|
165
|
+
size,
|
|
166
|
+
warning_marker
|
|
167
|
+
));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if bundles.len() > 10 {
|
|
171
|
+
result.push_str(&format!("\n ... +{} more routes\n", bundles.len() - 10));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
result.push('\n');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Show build time and status
|
|
178
|
+
if !build_time.is_empty() {
|
|
179
|
+
result.push_str(&format!("Time: {} | ", build_time));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
result.push_str(&format!("Errors: {} | Warnings: {}\n", errors, warnings));
|
|
183
|
+
|
|
184
|
+
result.trim().to_string()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Extract time from build output (e.g., "Compiled in 34.2s")
|
|
188
|
+
fn extract_time(line: &str) -> Option<String> {
|
|
189
|
+
lazy_static::lazy_static! {
|
|
190
|
+
static ref TIME_RE: Regex = Regex::new(r"(\d+(?:\.\d+)?)\s*(s|ms)").unwrap();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
TIME_RE
|
|
194
|
+
.captures(line)
|
|
195
|
+
.map(|caps| format!("{}{}", &caps[1], &caps[2]))
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#[cfg(test)]
|
|
199
|
+
mod tests {
|
|
200
|
+
use super::*;
|
|
201
|
+
|
|
202
|
+
#[test]
|
|
203
|
+
fn test_filter_next_build() {
|
|
204
|
+
let output = r#"
|
|
205
|
+
▲ Next.js 15.2.0
|
|
206
|
+
|
|
207
|
+
Creating an optimized production build ...
|
|
208
|
+
✓ Compiled successfully
|
|
209
|
+
✓ Linting and checking validity of types
|
|
210
|
+
✓ Collecting page data
|
|
211
|
+
○ / 1.2 kB 132 kB
|
|
212
|
+
● /dashboard 2.5 kB 156 kB
|
|
213
|
+
○ /api/auth 0.5 kB 89 kB
|
|
214
|
+
|
|
215
|
+
Route (app) Size First Load JS
|
|
216
|
+
┌ ○ / 1.2 kB 132 kB
|
|
217
|
+
├ ● /dashboard 2.5 kB 156 kB
|
|
218
|
+
└ ○ /api/auth 0.5 kB 89 kB
|
|
219
|
+
|
|
220
|
+
○ (Static) prerendered as static content
|
|
221
|
+
● (SSG) prerendered as static HTML
|
|
222
|
+
λ (Server) server-side renders at runtime
|
|
223
|
+
|
|
224
|
+
✓ Built in 34.2s
|
|
225
|
+
"#;
|
|
226
|
+
let result = filter_next_build(output);
|
|
227
|
+
assert!(result.contains("⚡ Next.js Build"));
|
|
228
|
+
assert!(result.contains("routes"));
|
|
229
|
+
assert!(!result.contains("Creating an optimized")); // Should filter verbose logs
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#[test]
|
|
233
|
+
fn test_extract_time() {
|
|
234
|
+
assert_eq!(extract_time("Built in 34.2s"), Some("34.2s".to_string()));
|
|
235
|
+
assert_eq!(
|
|
236
|
+
extract_time("Compiled in 1250ms"),
|
|
237
|
+
Some("1250ms".to_string())
|
|
238
|
+
);
|
|
239
|
+
assert_eq!(extract_time("No time here"), None);
|
|
240
|
+
}
|
|
241
|
+
}
|