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