@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,694 @@
1
+ use crate::mypy_cmd;
2
+ use crate::ruff_cmd;
3
+ use crate::tracking;
4
+ use crate::utils::{package_manager_exec, truncate};
5
+ use anyhow::{Context, Result};
6
+ use regex::Regex;
7
+ use serde::{Deserialize, Serialize};
8
+ use std::collections::HashMap;
9
+ use std::process::Command;
10
+
11
+ #[derive(Debug, Deserialize, Serialize)]
12
+ struct EslintMessage {
13
+ #[serde(rename = "ruleId")]
14
+ rule_id: Option<String>,
15
+ severity: u8,
16
+ message: String,
17
+ line: usize,
18
+ column: usize,
19
+ }
20
+
21
+ #[derive(Debug, Deserialize, Serialize)]
22
+ struct EslintResult {
23
+ #[serde(rename = "filePath")]
24
+ file_path: String,
25
+ messages: Vec<EslintMessage>,
26
+ #[serde(rename = "errorCount")]
27
+ error_count: usize,
28
+ #[serde(rename = "warningCount")]
29
+ warning_count: usize,
30
+ }
31
+
32
+ #[derive(Debug, Deserialize)]
33
+ struct PylintDiagnostic {
34
+ #[serde(rename = "type")]
35
+ msg_type: String, // "warning", "error", "convention", "refactor"
36
+ #[allow(dead_code)]
37
+ module: String,
38
+ #[allow(dead_code)]
39
+ obj: String,
40
+ line: usize,
41
+ #[allow(dead_code)]
42
+ column: usize,
43
+ path: String,
44
+ symbol: String, // rule code like "unused-variable"
45
+ message: String,
46
+ #[serde(rename = "message-id")]
47
+ message_id: String, // e.g., "W0612"
48
+ }
49
+
50
+ /// Check if a linter is Python-based (uses pip/pipx, not npm/pnpm)
51
+ fn is_python_linter(linter: &str) -> bool {
52
+ matches!(linter, "ruff" | "pylint" | "mypy" | "flake8")
53
+ }
54
+
55
+ /// Strip package manager prefixes (npx, bunx, pnpm, pnpm exec, yarn) from args.
56
+ /// Returns the number of args to skip.
57
+ fn strip_pm_prefix(args: &[String]) -> usize {
58
+ let pm_names = ["npx", "bunx", "pnpm", "yarn"];
59
+ let mut skip = 0;
60
+ for arg in args {
61
+ if pm_names.contains(&arg.as_str()) || arg == "exec" {
62
+ skip += 1;
63
+ } else {
64
+ break;
65
+ }
66
+ }
67
+ skip
68
+ }
69
+
70
+ /// Detect the linter name from args (after stripping PM prefixes).
71
+ /// Returns the linter name and whether it was explicitly specified.
72
+ fn detect_linter(args: &[String]) -> (&str, bool) {
73
+ let is_path_or_flag = args.is_empty()
74
+ || args[0].starts_with('-')
75
+ || args[0].contains('/')
76
+ || args[0].contains('.');
77
+
78
+ if is_path_or_flag {
79
+ ("eslint", false)
80
+ } else {
81
+ (&args[0], true)
82
+ }
83
+ }
84
+
85
+ pub fn run(args: &[String], verbose: u8) -> Result<()> {
86
+ let timer = tracking::TimedExecution::start();
87
+
88
+ let skip = strip_pm_prefix(args);
89
+ let effective_args = &args[skip..];
90
+
91
+ let (linter, explicit) = detect_linter(effective_args);
92
+
93
+ // Python linters use Command::new() directly (they're on PATH via pip/pipx)
94
+ // JS linters use package_manager_exec (npx/pnpm exec)
95
+ let mut cmd = if is_python_linter(linter) {
96
+ Command::new(linter)
97
+ } else {
98
+ package_manager_exec(linter)
99
+ };
100
+
101
+ // Add format flags based on linter
102
+ match linter {
103
+ "eslint" => {
104
+ cmd.arg("-f").arg("json");
105
+ }
106
+ "ruff" => {
107
+ // Force JSON output for ruff check
108
+ if !effective_args.contains(&"--output-format".to_string()) {
109
+ cmd.arg("check").arg("--output-format=json");
110
+ }
111
+ }
112
+ "pylint" => {
113
+ // Force JSON2 output for pylint
114
+ if !effective_args.contains(&"--output-format".to_string()) {
115
+ cmd.arg("--output-format=json2");
116
+ }
117
+ }
118
+ "mypy" => {
119
+ // mypy uses default text output (no special flags)
120
+ }
121
+ _ => {
122
+ // Other linters: no special formatting
123
+ }
124
+ }
125
+
126
+ // Add user arguments (skip first if it was the linter name, and skip "check" for ruff if we added it)
127
+ let start_idx = if !explicit {
128
+ 0
129
+ } else if linter == "ruff" && !effective_args.is_empty() && effective_args[0] == "ruff" {
130
+ // Skip "ruff" and "check" if we already added "check"
131
+ if effective_args.len() > 1 && effective_args[1] == "check" {
132
+ 2
133
+ } else {
134
+ 1
135
+ }
136
+ } else {
137
+ 1
138
+ };
139
+
140
+ for arg in &effective_args[start_idx..] {
141
+ // Skip --output-format if we already added it
142
+ if linter == "ruff" && arg.starts_with("--output-format") {
143
+ continue;
144
+ }
145
+ if linter == "pylint" && arg.starts_with("--output-format") {
146
+ continue;
147
+ }
148
+ cmd.arg(arg);
149
+ }
150
+
151
+ // Default to current directory if no path specified (for ruff/pylint/mypy/eslint)
152
+ if matches!(linter, "ruff" | "pylint" | "mypy" | "eslint") {
153
+ let has_path = effective_args
154
+ .iter()
155
+ .skip(start_idx)
156
+ .any(|a| !a.starts_with('-') && !a.contains('='));
157
+ if !has_path {
158
+ cmd.arg(".");
159
+ }
160
+ }
161
+
162
+ if verbose > 0 {
163
+ eprintln!("Running: {} with structured output", linter);
164
+ }
165
+
166
+ let output = cmd.output().context(format!(
167
+ "Failed to run {}. Is it installed? Try: pip install {} (or npm/pnpm for JS linters)",
168
+ linter, linter
169
+ ))?;
170
+
171
+ // Check if process was killed by signal (SIGABRT, SIGKILL, etc.)
172
+ if !output.status.success() && output.status.code().is_none() {
173
+ let stderr = String::from_utf8_lossy(&output.stderr);
174
+ eprintln!("⚠️ Linter process terminated abnormally (possibly out of memory)");
175
+ if !stderr.is_empty() {
176
+ eprintln!(
177
+ "stderr: {}",
178
+ stderr.lines().take(5).collect::<Vec<_>>().join("\n")
179
+ );
180
+ }
181
+ return Ok(());
182
+ }
183
+
184
+ let stdout = String::from_utf8_lossy(&output.stdout);
185
+ let stderr = String::from_utf8_lossy(&output.stderr);
186
+ let raw = format!("{}\n{}", stdout, stderr);
187
+
188
+ // Dispatch to appropriate filter based on linter
189
+ let filtered = match linter {
190
+ "eslint" => filter_eslint_json(&stdout),
191
+ "ruff" => {
192
+ // Reuse ruff_cmd's JSON parser
193
+ if !stdout.trim().is_empty() {
194
+ ruff_cmd::filter_ruff_check_json(&stdout)
195
+ } else {
196
+ "✓ Ruff: No issues found".to_string()
197
+ }
198
+ }
199
+ "pylint" => filter_pylint_json(&stdout),
200
+ "mypy" => mypy_cmd::filter_mypy_output(&raw),
201
+ _ => filter_generic_lint(&raw),
202
+ };
203
+
204
+ let exit_code = output
205
+ .status
206
+ .code()
207
+ .unwrap_or(if output.status.success() { 0 } else { 1 });
208
+ if let Some(hint) = crate::tee::tee_and_hint(&raw, "lint", exit_code) {
209
+ println!("{}\n{}", filtered, hint);
210
+ } else {
211
+ println!("{}", filtered);
212
+ }
213
+
214
+ timer.track(
215
+ &format!("{} {}", linter, args.join(" ")),
216
+ &format!("rtk lint {} {}", linter, args.join(" ")),
217
+ &raw,
218
+ &filtered,
219
+ );
220
+
221
+ if !output.status.success() {
222
+ std::process::exit(output.status.code().unwrap_or(1));
223
+ }
224
+
225
+ Ok(())
226
+ }
227
+
228
+ /// Filter ESLint JSON output - group by rule and file
229
+ fn filter_eslint_json(output: &str) -> String {
230
+ let results: Result<Vec<EslintResult>, _> = serde_json::from_str(output);
231
+
232
+ let results = match results {
233
+ Ok(r) => r,
234
+ Err(e) => {
235
+ // Fallback if JSON parsing fails
236
+ return format!(
237
+ "ESLint output (JSON parse failed: {})\n{}",
238
+ e,
239
+ truncate(output, 500)
240
+ );
241
+ }
242
+ };
243
+
244
+ // Count total issues
245
+ let total_errors: usize = results.iter().map(|r| r.error_count).sum();
246
+ let total_warnings: usize = results.iter().map(|r| r.warning_count).sum();
247
+ let total_files = results.iter().filter(|r| !r.messages.is_empty()).count();
248
+
249
+ if total_errors == 0 && total_warnings == 0 {
250
+ return "✓ ESLint: No issues found".to_string();
251
+ }
252
+
253
+ // Group messages by rule
254
+ let mut by_rule: HashMap<String, usize> = HashMap::new();
255
+ for result in &results {
256
+ for msg in &result.messages {
257
+ if let Some(rule) = &msg.rule_id {
258
+ *by_rule.entry(rule.clone()).or_insert(0) += 1;
259
+ }
260
+ }
261
+ }
262
+
263
+ // Group by file
264
+ let mut by_file: Vec<(&EslintResult, usize)> = results
265
+ .iter()
266
+ .filter(|r| !r.messages.is_empty())
267
+ .map(|r| (r, r.messages.len()))
268
+ .collect();
269
+ by_file.sort_by(|a, b| b.1.cmp(&a.1));
270
+
271
+ // Build output
272
+ let mut result = String::new();
273
+ result.push_str(&format!(
274
+ "ESLint: {} errors, {} warnings in {} files\n",
275
+ total_errors, total_warnings, total_files
276
+ ));
277
+ result.push_str("═══════════════════════════════════════\n");
278
+
279
+ // Show top rules
280
+ let mut rule_counts: Vec<_> = by_rule.iter().collect();
281
+ rule_counts.sort_by(|a, b| b.1.cmp(a.1));
282
+
283
+ if !rule_counts.is_empty() {
284
+ result.push_str("Top rules:\n");
285
+ for (rule, count) in rule_counts.iter().take(10) {
286
+ result.push_str(&format!(" {} ({}x)\n", rule, count));
287
+ }
288
+ result.push('\n');
289
+ }
290
+
291
+ // Show top files with most issues
292
+ result.push_str("Top files:\n");
293
+ for (file_result, count) in by_file.iter().take(10) {
294
+ let short_path = compact_path(&file_result.file_path);
295
+ result.push_str(&format!(" {} ({} issues)\n", short_path, count));
296
+
297
+ // Show top 3 rules in this file
298
+ let mut file_rules: HashMap<String, usize> = HashMap::new();
299
+ for msg in &file_result.messages {
300
+ if let Some(rule) = &msg.rule_id {
301
+ *file_rules.entry(rule.clone()).or_insert(0) += 1;
302
+ }
303
+ }
304
+
305
+ let mut file_rule_counts: Vec<_> = file_rules.iter().collect();
306
+ file_rule_counts.sort_by(|a, b| b.1.cmp(a.1));
307
+
308
+ for (rule, count) in file_rule_counts.iter().take(3) {
309
+ result.push_str(&format!(" {} ({})\n", rule, count));
310
+ }
311
+ }
312
+
313
+ if by_file.len() > 10 {
314
+ result.push_str(&format!("\n... +{} more files\n", by_file.len() - 10));
315
+ }
316
+
317
+ result.trim().to_string()
318
+ }
319
+
320
+ /// Filter pylint JSON2 output - group by symbol and file
321
+ fn filter_pylint_json(output: &str) -> String {
322
+ let diagnostics: Result<Vec<PylintDiagnostic>, _> = serde_json::from_str(output);
323
+
324
+ let diagnostics = match diagnostics {
325
+ Ok(d) => d,
326
+ Err(e) => {
327
+ // Fallback if JSON parsing fails
328
+ return format!(
329
+ "Pylint output (JSON parse failed: {})\n{}",
330
+ e,
331
+ truncate(output, 500)
332
+ );
333
+ }
334
+ };
335
+
336
+ if diagnostics.is_empty() {
337
+ return "✓ Pylint: No issues found".to_string();
338
+ }
339
+
340
+ // Count by type
341
+ let mut errors = 0;
342
+ let mut warnings = 0;
343
+ let mut conventions = 0;
344
+ let mut refactors = 0;
345
+
346
+ for diag in &diagnostics {
347
+ match diag.msg_type.as_str() {
348
+ "error" => errors += 1,
349
+ "warning" => warnings += 1,
350
+ "convention" => conventions += 1,
351
+ "refactor" => refactors += 1,
352
+ _ => {}
353
+ }
354
+ }
355
+
356
+ // Count unique files
357
+ let unique_files: std::collections::HashSet<_> = diagnostics.iter().map(|d| &d.path).collect();
358
+ let total_files = unique_files.len();
359
+
360
+ // Group by symbol (rule code)
361
+ let mut by_symbol: HashMap<String, usize> = HashMap::new();
362
+ for diag in &diagnostics {
363
+ let key = format!("{} ({})", diag.symbol, diag.message_id);
364
+ *by_symbol.entry(key).or_insert(0) += 1;
365
+ }
366
+
367
+ // Group by file
368
+ let mut by_file: HashMap<&str, usize> = HashMap::new();
369
+ for diag in &diagnostics {
370
+ *by_file.entry(&diag.path).or_insert(0) += 1;
371
+ }
372
+
373
+ let mut file_counts: Vec<_> = by_file.iter().collect();
374
+ file_counts.sort_by(|a, b| b.1.cmp(a.1));
375
+
376
+ // Build output
377
+ let mut result = String::new();
378
+ result.push_str(&format!(
379
+ "Pylint: {} issues in {} files\n",
380
+ diagnostics.len(),
381
+ total_files
382
+ ));
383
+
384
+ if errors > 0 || warnings > 0 {
385
+ result.push_str(&format!(" {} errors, {} warnings", errors, warnings));
386
+ if conventions > 0 || refactors > 0 {
387
+ result.push_str(&format!(
388
+ ", {} conventions, {} refactors",
389
+ conventions, refactors
390
+ ));
391
+ }
392
+ result.push('\n');
393
+ }
394
+
395
+ result.push_str("═══════════════════════════════════════\n");
396
+
397
+ // Show top symbols (rules)
398
+ let mut symbol_counts: Vec<_> = by_symbol.iter().collect();
399
+ symbol_counts.sort_by(|a, b| b.1.cmp(a.1));
400
+
401
+ if !symbol_counts.is_empty() {
402
+ result.push_str("Top rules:\n");
403
+ for (symbol, count) in symbol_counts.iter().take(10) {
404
+ result.push_str(&format!(" {} ({}x)\n", symbol, count));
405
+ }
406
+ result.push('\n');
407
+ }
408
+
409
+ // Show top files
410
+ result.push_str("Top files:\n");
411
+ for (file, count) in file_counts.iter().take(10) {
412
+ let short_path = compact_path(file);
413
+ result.push_str(&format!(" {} ({} issues)\n", short_path, count));
414
+
415
+ // Show top 3 rules in this file
416
+ let mut file_symbols: HashMap<String, usize> = HashMap::new();
417
+ for diag in diagnostics.iter().filter(|d| &d.path == *file) {
418
+ let key = format!("{} ({})", diag.symbol, diag.message_id);
419
+ *file_symbols.entry(key).or_insert(0) += 1;
420
+ }
421
+
422
+ let mut file_symbol_counts: Vec<_> = file_symbols.iter().collect();
423
+ file_symbol_counts.sort_by(|a, b| b.1.cmp(a.1));
424
+
425
+ for (symbol, count) in file_symbol_counts.iter().take(3) {
426
+ result.push_str(&format!(" {} ({})\n", symbol, count));
427
+ }
428
+ }
429
+
430
+ if file_counts.len() > 10 {
431
+ result.push_str(&format!("\n... +{} more files\n", file_counts.len() - 10));
432
+ }
433
+
434
+ result.trim().to_string()
435
+ }
436
+
437
+ /// Filter generic linter output (fallback for non-ESLint linters)
438
+ fn filter_generic_lint(output: &str) -> String {
439
+ let mut warnings = 0;
440
+ let mut errors = 0;
441
+ let mut issues: Vec<String> = Vec::new();
442
+
443
+ for line in output.lines() {
444
+ let line_lower = line.to_lowercase();
445
+ if line_lower.contains("warning") {
446
+ warnings += 1;
447
+ issues.push(line.to_string());
448
+ }
449
+ if line_lower.contains("error") && !line_lower.contains("0 error") {
450
+ errors += 1;
451
+ issues.push(line.to_string());
452
+ }
453
+ }
454
+
455
+ if errors == 0 && warnings == 0 {
456
+ return "✓ Lint: No issues found".to_string();
457
+ }
458
+
459
+ let mut result = String::new();
460
+ result.push_str(&format!("Lint: {} errors, {} warnings\n", errors, warnings));
461
+ result.push_str("═══════════════════════════════════════\n");
462
+
463
+ for issue in issues.iter().take(20) {
464
+ result.push_str(&format!("{}\n", truncate(issue, 100)));
465
+ }
466
+
467
+ if issues.len() > 20 {
468
+ result.push_str(&format!("\n... +{} more issues\n", issues.len() - 20));
469
+ }
470
+
471
+ result.trim().to_string()
472
+ }
473
+
474
+ /// Compact file path (remove common prefixes)
475
+ fn compact_path(path: &str) -> String {
476
+ // Remove common prefixes like /Users/..., /home/..., C:\
477
+ let path = path.replace('\\', "/");
478
+
479
+ if let Some(pos) = path.rfind("/src/") {
480
+ format!("src/{}", &path[pos + 5..])
481
+ } else if let Some(pos) = path.rfind("/lib/") {
482
+ format!("lib/{}", &path[pos + 5..])
483
+ } else if let Some(pos) = path.rfind('/') {
484
+ path[pos + 1..].to_string()
485
+ } else {
486
+ path
487
+ }
488
+ }
489
+
490
+ #[cfg(test)]
491
+ mod tests {
492
+ use super::*;
493
+
494
+ #[test]
495
+ fn test_filter_eslint_json() {
496
+ let json = r#"[
497
+ {
498
+ "filePath": "/Users/test/project/src/utils.ts",
499
+ "messages": [
500
+ {
501
+ "ruleId": "prefer-const",
502
+ "severity": 1,
503
+ "message": "Use const instead of let",
504
+ "line": 10,
505
+ "column": 5
506
+ },
507
+ {
508
+ "ruleId": "prefer-const",
509
+ "severity": 1,
510
+ "message": "Use const instead of let",
511
+ "line": 15,
512
+ "column": 5
513
+ }
514
+ ],
515
+ "errorCount": 0,
516
+ "warningCount": 2
517
+ },
518
+ {
519
+ "filePath": "/Users/test/project/src/api.ts",
520
+ "messages": [
521
+ {
522
+ "ruleId": "@typescript-eslint/no-unused-vars",
523
+ "severity": 2,
524
+ "message": "Variable x is unused",
525
+ "line": 20,
526
+ "column": 10
527
+ }
528
+ ],
529
+ "errorCount": 1,
530
+ "warningCount": 0
531
+ }
532
+ ]"#;
533
+
534
+ let result = filter_eslint_json(json);
535
+ assert!(result.contains("ESLint:"));
536
+ assert!(result.contains("prefer-const"));
537
+ assert!(result.contains("no-unused-vars"));
538
+ assert!(result.contains("src/utils.ts"));
539
+ }
540
+
541
+ #[test]
542
+ fn test_compact_path() {
543
+ assert_eq!(
544
+ compact_path("/Users/foo/project/src/utils.ts"),
545
+ "src/utils.ts"
546
+ );
547
+ assert_eq!(
548
+ compact_path("C:\\Users\\project\\src\\api.ts"),
549
+ "src/api.ts"
550
+ );
551
+ assert_eq!(compact_path("simple.ts"), "simple.ts");
552
+ }
553
+
554
+ #[test]
555
+ fn test_filter_pylint_json_no_issues() {
556
+ let output = "[]";
557
+ let result = filter_pylint_json(output);
558
+ assert!(result.contains("✓ Pylint"));
559
+ assert!(result.contains("No issues found"));
560
+ }
561
+
562
+ #[test]
563
+ fn test_filter_pylint_json_with_issues() {
564
+ let json = r#"[
565
+ {
566
+ "type": "warning",
567
+ "module": "main",
568
+ "obj": "",
569
+ "line": 10,
570
+ "column": 0,
571
+ "path": "src/main.py",
572
+ "symbol": "unused-variable",
573
+ "message": "Unused variable 'x'",
574
+ "message-id": "W0612"
575
+ },
576
+ {
577
+ "type": "warning",
578
+ "module": "main",
579
+ "obj": "foo",
580
+ "line": 15,
581
+ "column": 4,
582
+ "path": "src/main.py",
583
+ "symbol": "unused-variable",
584
+ "message": "Unused variable 'y'",
585
+ "message-id": "W0612"
586
+ },
587
+ {
588
+ "type": "error",
589
+ "module": "utils",
590
+ "obj": "bar",
591
+ "line": 20,
592
+ "column": 0,
593
+ "path": "src/utils.py",
594
+ "symbol": "undefined-variable",
595
+ "message": "Undefined variable 'z'",
596
+ "message-id": "E0602"
597
+ }
598
+ ]"#;
599
+
600
+ let result = filter_pylint_json(json);
601
+ assert!(result.contains("3 issues"));
602
+ assert!(result.contains("2 files"));
603
+ assert!(result.contains("1 errors, 2 warnings"));
604
+ assert!(result.contains("unused-variable (W0612)"));
605
+ assert!(result.contains("undefined-variable (E0602)"));
606
+ assert!(result.contains("main.py"));
607
+ assert!(result.contains("utils.py"));
608
+ }
609
+
610
+ #[test]
611
+ fn test_strip_pm_prefix_npx() {
612
+ let args: Vec<String> = vec!["npx".into(), "eslint".into(), "src/".into()];
613
+ assert_eq!(strip_pm_prefix(&args), 1);
614
+ }
615
+
616
+ #[test]
617
+ fn test_strip_pm_prefix_bunx() {
618
+ let args: Vec<String> = vec!["bunx".into(), "eslint".into(), ".".into()];
619
+ assert_eq!(strip_pm_prefix(&args), 1);
620
+ }
621
+
622
+ #[test]
623
+ fn test_strip_pm_prefix_pnpm_exec() {
624
+ let args: Vec<String> = vec!["pnpm".into(), "exec".into(), "eslint".into()];
625
+ assert_eq!(strip_pm_prefix(&args), 2);
626
+ }
627
+
628
+ #[test]
629
+ fn test_strip_pm_prefix_none() {
630
+ let args: Vec<String> = vec!["eslint".into(), "src/".into()];
631
+ assert_eq!(strip_pm_prefix(&args), 0);
632
+ }
633
+
634
+ #[test]
635
+ fn test_strip_pm_prefix_empty() {
636
+ let args: Vec<String> = vec![];
637
+ assert_eq!(strip_pm_prefix(&args), 0);
638
+ }
639
+
640
+ #[test]
641
+ fn test_detect_linter_eslint() {
642
+ let args: Vec<String> = vec!["eslint".into(), "src/".into()];
643
+ let (linter, explicit) = detect_linter(&args);
644
+ assert_eq!(linter, "eslint");
645
+ assert!(explicit);
646
+ }
647
+
648
+ #[test]
649
+ fn test_detect_linter_default_on_path() {
650
+ let args: Vec<String> = vec!["src/".into()];
651
+ let (linter, explicit) = detect_linter(&args);
652
+ assert_eq!(linter, "eslint");
653
+ assert!(!explicit);
654
+ }
655
+
656
+ #[test]
657
+ fn test_detect_linter_default_on_flag() {
658
+ let args: Vec<String> = vec!["--max-warnings=0".into()];
659
+ let (linter, explicit) = detect_linter(&args);
660
+ assert_eq!(linter, "eslint");
661
+ assert!(!explicit);
662
+ }
663
+
664
+ #[test]
665
+ fn test_detect_linter_after_npx_strip() {
666
+ // Simulates: rtk lint npx eslint src/ → after strip_pm_prefix, args = ["eslint", "src/"]
667
+ let full_args: Vec<String> = vec!["npx".into(), "eslint".into(), "src/".into()];
668
+ let skip = strip_pm_prefix(&full_args);
669
+ let effective = &full_args[skip..];
670
+ let (linter, _) = detect_linter(effective);
671
+ assert_eq!(linter, "eslint");
672
+ }
673
+
674
+ #[test]
675
+ fn test_detect_linter_after_pnpm_exec_strip() {
676
+ let full_args: Vec<String> =
677
+ vec!["pnpm".into(), "exec".into(), "biome".into(), "check".into()];
678
+ let skip = strip_pm_prefix(&full_args);
679
+ let effective = &full_args[skip..];
680
+ let (linter, _) = detect_linter(effective);
681
+ assert_eq!(linter, "biome");
682
+ }
683
+
684
+ #[test]
685
+ fn test_is_python_linter() {
686
+ assert!(is_python_linter("ruff"));
687
+ assert!(is_python_linter("pylint"));
688
+ assert!(is_python_linter("mypy"));
689
+ assert!(is_python_linter("flake8"));
690
+ assert!(!is_python_linter("eslint"));
691
+ assert!(!is_python_linter("biome"));
692
+ assert!(!is_python_linter("unknown"));
693
+ }
694
+ }