@hasna/terminal 2.3.0 → 2.3.1

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.
Files changed (202) hide show
  1. package/dist/cli.js +64 -16
  2. package/package.json +1 -1
  3. package/src/ai.ts +8 -0
  4. package/src/cli.tsx +57 -18
  5. package/src/output-processor.ts +6 -1
  6. package/src/output-store.ts +58 -12
  7. package/src/tool-profiles.ts +139 -0
  8. package/temp/rtk/.claude/agents/code-reviewer.md +0 -221
  9. package/temp/rtk/.claude/agents/debugger.md +0 -519
  10. package/temp/rtk/.claude/agents/rtk-testing-specialist.md +0 -461
  11. package/temp/rtk/.claude/agents/rust-rtk.md +0 -511
  12. package/temp/rtk/.claude/agents/technical-writer.md +0 -355
  13. package/temp/rtk/.claude/commands/diagnose.md +0 -352
  14. package/temp/rtk/.claude/commands/test-routing.md +0 -362
  15. package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +0 -16
  16. package/temp/rtk/.claude/hooks/rtk-rewrite.sh +0 -70
  17. package/temp/rtk/.claude/hooks/rtk-suggest.sh +0 -152
  18. package/temp/rtk/.claude/rules/cli-testing.md +0 -526
  19. package/temp/rtk/.claude/skills/issue-triage/SKILL.md +0 -348
  20. package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +0 -134
  21. package/temp/rtk/.claude/skills/performance.md +0 -435
  22. package/temp/rtk/.claude/skills/pr-triage/SKILL.md +0 -315
  23. package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +0 -71
  24. package/temp/rtk/.claude/skills/repo-recap.md +0 -206
  25. package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +0 -78
  26. package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +0 -124
  27. package/temp/rtk/.claude/skills/security-guardian.md +0 -503
  28. package/temp/rtk/.claude/skills/ship.md +0 -404
  29. package/temp/rtk/.github/workflows/benchmark.yml +0 -34
  30. package/temp/rtk/.github/workflows/dco-check.yaml +0 -12
  31. package/temp/rtk/.github/workflows/release-please.yml +0 -51
  32. package/temp/rtk/.github/workflows/release.yml +0 -343
  33. package/temp/rtk/.github/workflows/security-check.yml +0 -135
  34. package/temp/rtk/.github/workflows/validate-docs.yml +0 -78
  35. package/temp/rtk/.release-please-manifest.json +0 -3
  36. package/temp/rtk/ARCHITECTURE.md +0 -1491
  37. package/temp/rtk/CHANGELOG.md +0 -640
  38. package/temp/rtk/CLAUDE.md +0 -605
  39. package/temp/rtk/CONTRIBUTING.md +0 -199
  40. package/temp/rtk/Cargo.lock +0 -1668
  41. package/temp/rtk/Cargo.toml +0 -64
  42. package/temp/rtk/Formula/rtk.rb +0 -43
  43. package/temp/rtk/INSTALL.md +0 -390
  44. package/temp/rtk/LICENSE +0 -21
  45. package/temp/rtk/README.md +0 -386
  46. package/temp/rtk/README_es.md +0 -159
  47. package/temp/rtk/README_fr.md +0 -197
  48. package/temp/rtk/README_ja.md +0 -159
  49. package/temp/rtk/README_ko.md +0 -159
  50. package/temp/rtk/README_zh.md +0 -167
  51. package/temp/rtk/ROADMAP.md +0 -15
  52. package/temp/rtk/SECURITY.md +0 -217
  53. package/temp/rtk/TEST_EXEC_TIME.md +0 -102
  54. package/temp/rtk/build.rs +0 -57
  55. package/temp/rtk/docs/AUDIT_GUIDE.md +0 -432
  56. package/temp/rtk/docs/FEATURES.md +0 -1410
  57. package/temp/rtk/docs/TROUBLESHOOTING.md +0 -309
  58. package/temp/rtk/docs/filter-workflow.md +0 -102
  59. package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
  60. package/temp/rtk/docs/tracking.md +0 -583
  61. package/temp/rtk/hooks/opencode-rtk.ts +0 -39
  62. package/temp/rtk/hooks/rtk-awareness.md +0 -29
  63. package/temp/rtk/hooks/rtk-rewrite.sh +0 -61
  64. package/temp/rtk/hooks/test-rtk-rewrite.sh +0 -442
  65. package/temp/rtk/install.sh +0 -124
  66. package/temp/rtk/release-please-config.json +0 -10
  67. package/temp/rtk/scripts/benchmark.sh +0 -592
  68. package/temp/rtk/scripts/check-installation.sh +0 -162
  69. package/temp/rtk/scripts/install-local.sh +0 -37
  70. package/temp/rtk/scripts/rtk-economics.sh +0 -137
  71. package/temp/rtk/scripts/test-all.sh +0 -561
  72. package/temp/rtk/scripts/test-aristote.sh +0 -227
  73. package/temp/rtk/scripts/test-tracking.sh +0 -79
  74. package/temp/rtk/scripts/update-readme-metrics.sh +0 -32
  75. package/temp/rtk/scripts/validate-docs.sh +0 -73
  76. package/temp/rtk/src/aws_cmd.rs +0 -880
  77. package/temp/rtk/src/binlog.rs +0 -1645
  78. package/temp/rtk/src/cargo_cmd.rs +0 -1727
  79. package/temp/rtk/src/cc_economics.rs +0 -1157
  80. package/temp/rtk/src/ccusage.rs +0 -340
  81. package/temp/rtk/src/config.rs +0 -187
  82. package/temp/rtk/src/container.rs +0 -855
  83. package/temp/rtk/src/curl_cmd.rs +0 -134
  84. package/temp/rtk/src/deps.rs +0 -268
  85. package/temp/rtk/src/diff_cmd.rs +0 -367
  86. package/temp/rtk/src/discover/mod.rs +0 -274
  87. package/temp/rtk/src/discover/provider.rs +0 -388
  88. package/temp/rtk/src/discover/registry.rs +0 -2022
  89. package/temp/rtk/src/discover/report.rs +0 -202
  90. package/temp/rtk/src/discover/rules.rs +0 -667
  91. package/temp/rtk/src/display_helpers.rs +0 -402
  92. package/temp/rtk/src/dotnet_cmd.rs +0 -1771
  93. package/temp/rtk/src/dotnet_format_report.rs +0 -133
  94. package/temp/rtk/src/dotnet_trx.rs +0 -593
  95. package/temp/rtk/src/env_cmd.rs +0 -204
  96. package/temp/rtk/src/filter.rs +0 -462
  97. package/temp/rtk/src/filters/README.md +0 -52
  98. package/temp/rtk/src/filters/ansible-playbook.toml +0 -34
  99. package/temp/rtk/src/filters/basedpyright.toml +0 -47
  100. package/temp/rtk/src/filters/biome.toml +0 -45
  101. package/temp/rtk/src/filters/brew-install.toml +0 -37
  102. package/temp/rtk/src/filters/composer-install.toml +0 -40
  103. package/temp/rtk/src/filters/df.toml +0 -16
  104. package/temp/rtk/src/filters/dotnet-build.toml +0 -64
  105. package/temp/rtk/src/filters/du.toml +0 -16
  106. package/temp/rtk/src/filters/fail2ban-client.toml +0 -15
  107. package/temp/rtk/src/filters/gcc.toml +0 -49
  108. package/temp/rtk/src/filters/gcloud.toml +0 -22
  109. package/temp/rtk/src/filters/hadolint.toml +0 -24
  110. package/temp/rtk/src/filters/helm.toml +0 -29
  111. package/temp/rtk/src/filters/iptables.toml +0 -27
  112. package/temp/rtk/src/filters/jj.toml +0 -28
  113. package/temp/rtk/src/filters/jq.toml +0 -24
  114. package/temp/rtk/src/filters/make.toml +0 -41
  115. package/temp/rtk/src/filters/markdownlint.toml +0 -24
  116. package/temp/rtk/src/filters/mix-compile.toml +0 -27
  117. package/temp/rtk/src/filters/mix-format.toml +0 -15
  118. package/temp/rtk/src/filters/mvn-build.toml +0 -44
  119. package/temp/rtk/src/filters/oxlint.toml +0 -43
  120. package/temp/rtk/src/filters/ping.toml +0 -63
  121. package/temp/rtk/src/filters/pio-run.toml +0 -40
  122. package/temp/rtk/src/filters/poetry-install.toml +0 -50
  123. package/temp/rtk/src/filters/pre-commit.toml +0 -35
  124. package/temp/rtk/src/filters/ps.toml +0 -16
  125. package/temp/rtk/src/filters/quarto-render.toml +0 -41
  126. package/temp/rtk/src/filters/rsync.toml +0 -48
  127. package/temp/rtk/src/filters/shellcheck.toml +0 -27
  128. package/temp/rtk/src/filters/shopify-theme.toml +0 -29
  129. package/temp/rtk/src/filters/skopeo.toml +0 -45
  130. package/temp/rtk/src/filters/sops.toml +0 -16
  131. package/temp/rtk/src/filters/ssh.toml +0 -44
  132. package/temp/rtk/src/filters/stat.toml +0 -34
  133. package/temp/rtk/src/filters/swift-build.toml +0 -41
  134. package/temp/rtk/src/filters/systemctl-status.toml +0 -33
  135. package/temp/rtk/src/filters/terraform-plan.toml +0 -35
  136. package/temp/rtk/src/filters/tofu-fmt.toml +0 -16
  137. package/temp/rtk/src/filters/tofu-init.toml +0 -38
  138. package/temp/rtk/src/filters/tofu-plan.toml +0 -35
  139. package/temp/rtk/src/filters/tofu-validate.toml +0 -17
  140. package/temp/rtk/src/filters/trunk-build.toml +0 -39
  141. package/temp/rtk/src/filters/ty.toml +0 -50
  142. package/temp/rtk/src/filters/uv-sync.toml +0 -37
  143. package/temp/rtk/src/filters/xcodebuild.toml +0 -99
  144. package/temp/rtk/src/filters/yamllint.toml +0 -25
  145. package/temp/rtk/src/find_cmd.rs +0 -598
  146. package/temp/rtk/src/format_cmd.rs +0 -386
  147. package/temp/rtk/src/gain.rs +0 -723
  148. package/temp/rtk/src/gh_cmd.rs +0 -1651
  149. package/temp/rtk/src/git.rs +0 -2012
  150. package/temp/rtk/src/go_cmd.rs +0 -592
  151. package/temp/rtk/src/golangci_cmd.rs +0 -254
  152. package/temp/rtk/src/grep_cmd.rs +0 -288
  153. package/temp/rtk/src/gt_cmd.rs +0 -810
  154. package/temp/rtk/src/hook_audit_cmd.rs +0 -283
  155. package/temp/rtk/src/hook_check.rs +0 -171
  156. package/temp/rtk/src/init.rs +0 -1859
  157. package/temp/rtk/src/integrity.rs +0 -537
  158. package/temp/rtk/src/json_cmd.rs +0 -231
  159. package/temp/rtk/src/learn/detector.rs +0 -628
  160. package/temp/rtk/src/learn/mod.rs +0 -119
  161. package/temp/rtk/src/learn/report.rs +0 -184
  162. package/temp/rtk/src/lint_cmd.rs +0 -694
  163. package/temp/rtk/src/local_llm.rs +0 -316
  164. package/temp/rtk/src/log_cmd.rs +0 -248
  165. package/temp/rtk/src/ls.rs +0 -324
  166. package/temp/rtk/src/main.rs +0 -2482
  167. package/temp/rtk/src/mypy_cmd.rs +0 -389
  168. package/temp/rtk/src/next_cmd.rs +0 -241
  169. package/temp/rtk/src/npm_cmd.rs +0 -236
  170. package/temp/rtk/src/parser/README.md +0 -267
  171. package/temp/rtk/src/parser/error.rs +0 -46
  172. package/temp/rtk/src/parser/formatter.rs +0 -336
  173. package/temp/rtk/src/parser/mod.rs +0 -311
  174. package/temp/rtk/src/parser/types.rs +0 -119
  175. package/temp/rtk/src/pip_cmd.rs +0 -302
  176. package/temp/rtk/src/playwright_cmd.rs +0 -479
  177. package/temp/rtk/src/pnpm_cmd.rs +0 -573
  178. package/temp/rtk/src/prettier_cmd.rs +0 -221
  179. package/temp/rtk/src/prisma_cmd.rs +0 -482
  180. package/temp/rtk/src/psql_cmd.rs +0 -382
  181. package/temp/rtk/src/pytest_cmd.rs +0 -384
  182. package/temp/rtk/src/read.rs +0 -217
  183. package/temp/rtk/src/rewrite_cmd.rs +0 -50
  184. package/temp/rtk/src/ruff_cmd.rs +0 -402
  185. package/temp/rtk/src/runner.rs +0 -271
  186. package/temp/rtk/src/summary.rs +0 -297
  187. package/temp/rtk/src/tee.rs +0 -405
  188. package/temp/rtk/src/telemetry.rs +0 -248
  189. package/temp/rtk/src/toml_filter.rs +0 -1655
  190. package/temp/rtk/src/tracking.rs +0 -1416
  191. package/temp/rtk/src/tree.rs +0 -209
  192. package/temp/rtk/src/tsc_cmd.rs +0 -259
  193. package/temp/rtk/src/utils.rs +0 -432
  194. package/temp/rtk/src/verify_cmd.rs +0 -47
  195. package/temp/rtk/src/vitest_cmd.rs +0 -385
  196. package/temp/rtk/src/wc_cmd.rs +0 -401
  197. package/temp/rtk/src/wget_cmd.rs +0 -260
  198. package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +0 -11
  199. package/temp/rtk/tests/fixtures/dotnet/format_changes.json +0 -31
  200. package/temp/rtk/tests/fixtures/dotnet/format_empty.json +0 -1
  201. package/temp/rtk/tests/fixtures/dotnet/format_success.json +0 -12
  202. package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +0 -18
@@ -1,389 +0,0 @@
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
- }
@@ -1,241 +0,0 @@
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
- }