@hasna/terminal 2.3.0 → 2.3.2

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