@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,592 @@
1
+ use crate::tracking;
2
+ use crate::utils::truncate;
3
+ use anyhow::{Context, Result};
4
+ use serde::Deserialize;
5
+ use std::collections::HashMap;
6
+ use std::ffi::OsString;
7
+ use std::process::Command;
8
+
9
+ #[derive(Debug, Deserialize)]
10
+ #[allow(dead_code)]
11
+ struct GoTestEvent {
12
+ #[serde(rename = "Time")]
13
+ time: Option<String>,
14
+ #[serde(rename = "Action")]
15
+ action: String,
16
+ #[serde(rename = "Package")]
17
+ package: Option<String>,
18
+ #[serde(rename = "Test")]
19
+ test: Option<String>,
20
+ #[serde(rename = "Output")]
21
+ output: Option<String>,
22
+ #[serde(rename = "Elapsed")]
23
+ elapsed: Option<f64>,
24
+ #[serde(rename = "ImportPath")]
25
+ import_path: Option<String>,
26
+ #[serde(rename = "FailedBuild")]
27
+ failed_build: Option<String>,
28
+ }
29
+
30
+ #[derive(Debug, Default)]
31
+ struct PackageResult {
32
+ pass: usize,
33
+ fail: usize,
34
+ skip: usize,
35
+ build_failed: bool,
36
+ build_errors: Vec<String>,
37
+ failed_tests: Vec<(String, Vec<String>)>, // (test_name, output_lines)
38
+ }
39
+
40
+ pub fn run_test(args: &[String], verbose: u8) -> Result<()> {
41
+ let timer = tracking::TimedExecution::start();
42
+
43
+ let mut cmd = Command::new("go");
44
+ cmd.arg("test");
45
+
46
+ // Force JSON output if not already specified
47
+ if !args.iter().any(|a| a == "-json") {
48
+ cmd.arg("-json");
49
+ }
50
+
51
+ for arg in args {
52
+ cmd.arg(arg);
53
+ }
54
+
55
+ if verbose > 0 {
56
+ eprintln!("Running: go test -json {}", args.join(" "));
57
+ }
58
+
59
+ let output = cmd
60
+ .output()
61
+ .context("Failed to run go test. Is Go installed?")?;
62
+
63
+ let stdout = String::from_utf8_lossy(&output.stdout);
64
+ let stderr = String::from_utf8_lossy(&output.stderr);
65
+ let raw = format!("{}\n{}", stdout, stderr);
66
+
67
+ let exit_code = output
68
+ .status
69
+ .code()
70
+ .unwrap_or(if output.status.success() { 0 } else { 1 });
71
+ let filtered = filter_go_test_json(&stdout);
72
+
73
+ if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_test", exit_code) {
74
+ println!("{}\n{}", filtered, hint);
75
+ } else {
76
+ println!("{}", filtered);
77
+ }
78
+
79
+ // Include stderr if present (build errors, etc.)
80
+ if !stderr.trim().is_empty() {
81
+ eprintln!("{}", stderr.trim());
82
+ }
83
+
84
+ timer.track(
85
+ &format!("go test {}", args.join(" ")),
86
+ &format!("rtk go test {}", args.join(" ")),
87
+ &raw,
88
+ &filtered,
89
+ );
90
+
91
+ // Preserve exit code for CI/CD
92
+ if !output.status.success() {
93
+ std::process::exit(exit_code);
94
+ }
95
+
96
+ Ok(())
97
+ }
98
+
99
+ pub fn run_build(args: &[String], verbose: u8) -> Result<()> {
100
+ let timer = tracking::TimedExecution::start();
101
+
102
+ let mut cmd = Command::new("go");
103
+ cmd.arg("build");
104
+
105
+ for arg in args {
106
+ cmd.arg(arg);
107
+ }
108
+
109
+ if verbose > 0 {
110
+ eprintln!("Running: go build {}", args.join(" "));
111
+ }
112
+
113
+ let output = cmd
114
+ .output()
115
+ .context("Failed to run go build. Is Go installed?")?;
116
+
117
+ let stdout = String::from_utf8_lossy(&output.stdout);
118
+ let stderr = String::from_utf8_lossy(&output.stderr);
119
+ let raw = format!("{}\n{}", stdout, stderr);
120
+
121
+ let exit_code = output
122
+ .status
123
+ .code()
124
+ .unwrap_or(if output.status.success() { 0 } else { 1 });
125
+ let filtered = filter_go_build(&raw);
126
+
127
+ if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_build", exit_code) {
128
+ if !filtered.is_empty() {
129
+ println!("{}\n{}", filtered, hint);
130
+ } else {
131
+ println!("{}", hint);
132
+ }
133
+ } else if !filtered.is_empty() {
134
+ println!("{}", filtered);
135
+ }
136
+
137
+ timer.track(
138
+ &format!("go build {}", args.join(" ")),
139
+ &format!("rtk go build {}", args.join(" ")),
140
+ &raw,
141
+ &filtered,
142
+ );
143
+
144
+ // Preserve exit code for CI/CD
145
+ if !output.status.success() {
146
+ std::process::exit(exit_code);
147
+ }
148
+
149
+ Ok(())
150
+ }
151
+
152
+ pub fn run_vet(args: &[String], verbose: u8) -> Result<()> {
153
+ let timer = tracking::TimedExecution::start();
154
+
155
+ let mut cmd = Command::new("go");
156
+ cmd.arg("vet");
157
+
158
+ for arg in args {
159
+ cmd.arg(arg);
160
+ }
161
+
162
+ if verbose > 0 {
163
+ eprintln!("Running: go vet {}", args.join(" "));
164
+ }
165
+
166
+ let output = cmd
167
+ .output()
168
+ .context("Failed to run go vet. Is Go installed?")?;
169
+
170
+ let stdout = String::from_utf8_lossy(&output.stdout);
171
+ let stderr = String::from_utf8_lossy(&output.stderr);
172
+ let raw = format!("{}\n{}", stdout, stderr);
173
+
174
+ let exit_code = output
175
+ .status
176
+ .code()
177
+ .unwrap_or(if output.status.success() { 0 } else { 1 });
178
+ let filtered = filter_go_vet(&raw);
179
+
180
+ if let Some(hint) = crate::tee::tee_and_hint(&raw, "go_vet", exit_code) {
181
+ if !filtered.is_empty() {
182
+ println!("{}\n{}", filtered, hint);
183
+ } else {
184
+ println!("{}", hint);
185
+ }
186
+ } else if !filtered.is_empty() {
187
+ println!("{}", filtered);
188
+ }
189
+
190
+ timer.track(
191
+ &format!("go vet {}", args.join(" ")),
192
+ &format!("rtk go vet {}", args.join(" ")),
193
+ &raw,
194
+ &filtered,
195
+ );
196
+
197
+ // Preserve exit code for CI/CD
198
+ if !output.status.success() {
199
+ std::process::exit(exit_code);
200
+ }
201
+
202
+ Ok(())
203
+ }
204
+
205
+ pub fn run_other(args: &[OsString], verbose: u8) -> Result<()> {
206
+ if args.is_empty() {
207
+ anyhow::bail!("go: no subcommand specified");
208
+ }
209
+
210
+ let timer = tracking::TimedExecution::start();
211
+
212
+ let subcommand = args[0].to_string_lossy();
213
+ let mut cmd = Command::new("go");
214
+ cmd.arg(&*subcommand);
215
+
216
+ for arg in &args[1..] {
217
+ cmd.arg(arg);
218
+ }
219
+
220
+ if verbose > 0 {
221
+ eprintln!("Running: go {} ...", subcommand);
222
+ }
223
+
224
+ let output = cmd
225
+ .output()
226
+ .with_context(|| format!("Failed to run go {}", subcommand))?;
227
+
228
+ let stdout = String::from_utf8_lossy(&output.stdout);
229
+ let stderr = String::from_utf8_lossy(&output.stderr);
230
+ let raw = format!("{}\n{}", stdout, stderr);
231
+
232
+ print!("{}", stdout);
233
+ eprint!("{}", stderr);
234
+
235
+ timer.track(
236
+ &format!("go {}", subcommand),
237
+ &format!("rtk go {}", subcommand),
238
+ &raw,
239
+ &raw, // No filtering for unsupported commands
240
+ );
241
+
242
+ // Preserve exit code
243
+ if !output.status.success() {
244
+ std::process::exit(output.status.code().unwrap_or(1));
245
+ }
246
+
247
+ Ok(())
248
+ }
249
+
250
+ /// Parse go test -json output (NDJSON format)
251
+ fn filter_go_test_json(output: &str) -> String {
252
+ let mut packages: HashMap<String, PackageResult> = HashMap::new();
253
+ let mut current_test_output: HashMap<(String, String), Vec<String>> = HashMap::new(); // (package, test) -> outputs
254
+ let mut build_output: HashMap<String, Vec<String>> = HashMap::new(); // import_path -> error lines
255
+
256
+ for line in output.lines() {
257
+ let trimmed = line.trim();
258
+ if trimmed.is_empty() {
259
+ continue;
260
+ }
261
+
262
+ let event: GoTestEvent = match serde_json::from_str(trimmed) {
263
+ Ok(e) => e,
264
+ Err(_) => continue, // Skip non-JSON lines
265
+ };
266
+
267
+ // Handle build-output/build-fail events (use ImportPath, no Package)
268
+ match event.action.as_str() {
269
+ "build-output" => {
270
+ if let (Some(import_path), Some(output_text)) = (&event.import_path, &event.output)
271
+ {
272
+ let text = output_text.trim_end().to_string();
273
+ if !text.is_empty() {
274
+ build_output
275
+ .entry(import_path.clone())
276
+ .or_default()
277
+ .push(text);
278
+ }
279
+ }
280
+ continue;
281
+ }
282
+ "build-fail" => {
283
+ // build-fail has ImportPath — we'll handle it when the package-level fail arrives
284
+ continue;
285
+ }
286
+ _ => {}
287
+ }
288
+
289
+ let package = event.package.unwrap_or_else(|| "unknown".to_string());
290
+ let pkg_result = packages.entry(package.clone()).or_default();
291
+
292
+ match event.action.as_str() {
293
+ "pass" => {
294
+ if event.test.is_some() {
295
+ pkg_result.pass += 1;
296
+ }
297
+ }
298
+ "fail" => {
299
+ if let Some(test) = &event.test {
300
+ // Individual test failure
301
+ pkg_result.fail += 1;
302
+
303
+ // Collect output for failed test
304
+ let key = (package.clone(), test.clone());
305
+ let outputs = current_test_output.remove(&key).unwrap_or_default();
306
+ pkg_result.failed_tests.push((test.clone(), outputs));
307
+ } else if event.failed_build.is_some() {
308
+ // Package-level build failure
309
+ pkg_result.build_failed = true;
310
+ // Collect build errors from the import path
311
+ if let Some(import_path) = &event.failed_build {
312
+ if let Some(errors) = build_output.remove(import_path) {
313
+ pkg_result.build_errors = errors;
314
+ }
315
+ }
316
+ }
317
+ }
318
+ "skip" => {
319
+ if event.test.is_some() {
320
+ pkg_result.skip += 1;
321
+ }
322
+ }
323
+ "output" => {
324
+ // Collect output for current test
325
+ if let (Some(test), Some(output_text)) = (&event.test, &event.output) {
326
+ let key = (package.clone(), test.clone());
327
+ current_test_output
328
+ .entry(key)
329
+ .or_default()
330
+ .push(output_text.trim_end().to_string());
331
+ }
332
+ }
333
+ _ => {} // run, pause, cont, etc.
334
+ }
335
+ }
336
+
337
+ // Build summary
338
+ let total_packages = packages.len();
339
+ let total_pass: usize = packages.values().map(|p| p.pass).sum();
340
+ let total_fail: usize = packages.values().map(|p| p.fail).sum();
341
+ let total_skip: usize = packages.values().map(|p| p.skip).sum();
342
+ let total_build_fail: usize = packages.values().filter(|p| p.build_failed).count();
343
+
344
+ let has_failures = total_fail > 0 || total_build_fail > 0;
345
+
346
+ if !has_failures && total_pass == 0 {
347
+ return "Go test: No tests found".to_string();
348
+ }
349
+
350
+ if !has_failures {
351
+ return format!(
352
+ "✓ Go test: {} passed in {} packages",
353
+ total_pass, total_packages
354
+ );
355
+ }
356
+
357
+ let mut result = String::new();
358
+ result.push_str(&format!(
359
+ "Go test: {} passed, {} failed",
360
+ total_pass,
361
+ total_fail + total_build_fail
362
+ ));
363
+ if total_skip > 0 {
364
+ result.push_str(&format!(", {} skipped", total_skip));
365
+ }
366
+ result.push_str(&format!(" in {} packages\n", total_packages));
367
+ result.push_str("═══════════════════════════════════════\n");
368
+
369
+ // Show build failures first
370
+ for (package, pkg_result) in packages.iter() {
371
+ if !pkg_result.build_failed {
372
+ continue;
373
+ }
374
+
375
+ result.push_str(&format!(
376
+ "\n📦 {} [build failed]\n",
377
+ compact_package_name(package)
378
+ ));
379
+
380
+ for line in &pkg_result.build_errors {
381
+ let trimmed = line.trim();
382
+ // Skip the "# package" header line
383
+ if !trimmed.starts_with('#') && !trimmed.is_empty() {
384
+ result.push_str(&format!(" {}\n", truncate(trimmed, 120)));
385
+ }
386
+ }
387
+ }
388
+
389
+ // Show failed tests grouped by package
390
+ for (package, pkg_result) in packages.iter() {
391
+ if pkg_result.fail == 0 {
392
+ continue;
393
+ }
394
+
395
+ result.push_str(&format!(
396
+ "\n📦 {} ({} passed, {} failed)\n",
397
+ compact_package_name(package),
398
+ pkg_result.pass,
399
+ pkg_result.fail
400
+ ));
401
+
402
+ for (test, outputs) in &pkg_result.failed_tests {
403
+ result.push_str(&format!(" ❌ {}\n", test));
404
+
405
+ // Show failure output (limit to key lines)
406
+ let relevant_lines: Vec<&String> = outputs
407
+ .iter()
408
+ .filter(|line| {
409
+ let lower = line.to_lowercase();
410
+ !line.trim().is_empty()
411
+ && !line.starts_with("=== RUN")
412
+ && !line.starts_with("--- FAIL")
413
+ && (lower.contains("error")
414
+ || lower.contains("expected")
415
+ || lower.contains("got")
416
+ || lower.contains("panic")
417
+ || line.trim().starts_with("at "))
418
+ })
419
+ .take(5)
420
+ .collect();
421
+
422
+ for line in relevant_lines {
423
+ result.push_str(&format!(" {}\n", truncate(line, 100)));
424
+ }
425
+ }
426
+ }
427
+
428
+ result.trim().to_string()
429
+ }
430
+
431
+ /// Filter go build output - show only errors
432
+ fn filter_go_build(output: &str) -> String {
433
+ let mut errors: Vec<String> = Vec::new();
434
+
435
+ for line in output.lines() {
436
+ let trimmed = line.trim();
437
+ let lower = trimmed.to_lowercase();
438
+
439
+ // Skip package markers (# package/name lines without errors)
440
+ if trimmed.starts_with('#') && !lower.contains("error") {
441
+ continue;
442
+ }
443
+
444
+ // Collect error lines (file:line:col format or error keywords)
445
+ if !trimmed.is_empty()
446
+ && (lower.contains("error")
447
+ || trimmed.contains(".go:")
448
+ || lower.contains("undefined")
449
+ || lower.contains("cannot"))
450
+ {
451
+ errors.push(trimmed.to_string());
452
+ }
453
+ }
454
+
455
+ if errors.is_empty() {
456
+ return "✓ Go build: Success".to_string();
457
+ }
458
+
459
+ let mut result = String::new();
460
+ result.push_str(&format!("Go build: {} errors\n", errors.len()));
461
+ result.push_str("═══════════════════════════════════════\n");
462
+
463
+ for (i, error) in errors.iter().take(20).enumerate() {
464
+ result.push_str(&format!("{}. {}\n", i + 1, truncate(error, 120)));
465
+ }
466
+
467
+ if errors.len() > 20 {
468
+ result.push_str(&format!("\n... +{} more errors\n", errors.len() - 20));
469
+ }
470
+
471
+ result.trim().to_string()
472
+ }
473
+
474
+ /// Filter go vet output - show issues
475
+ fn filter_go_vet(output: &str) -> String {
476
+ let mut issues: Vec<String> = Vec::new();
477
+
478
+ for line in output.lines() {
479
+ let trimmed = line.trim();
480
+
481
+ // Collect issue lines (vet reports issues with file:line:col format)
482
+ if !trimmed.is_empty() && !trimmed.starts_with('#') && trimmed.contains(".go:") {
483
+ issues.push(trimmed.to_string());
484
+ }
485
+ }
486
+
487
+ if issues.is_empty() {
488
+ return "✓ Go vet: No issues found".to_string();
489
+ }
490
+
491
+ let mut result = String::new();
492
+ result.push_str(&format!("Go vet: {} issues\n", issues.len()));
493
+ result.push_str("═══════════════════════════════════════\n");
494
+
495
+ for (i, issue) in issues.iter().take(20).enumerate() {
496
+ result.push_str(&format!("{}. {}\n", i + 1, truncate(issue, 120)));
497
+ }
498
+
499
+ if issues.len() > 20 {
500
+ result.push_str(&format!("\n... +{} more issues\n", issues.len() - 20));
501
+ }
502
+
503
+ result.trim().to_string()
504
+ }
505
+
506
+ /// Compact package name (remove long paths)
507
+ fn compact_package_name(package: &str) -> String {
508
+ // Remove common module prefixes like github.com/user/repo/
509
+ if let Some(pos) = package.rfind('/') {
510
+ package[pos + 1..].to_string()
511
+ } else {
512
+ package.to_string()
513
+ }
514
+ }
515
+
516
+ #[cfg(test)]
517
+ mod tests {
518
+ use super::*;
519
+
520
+ #[test]
521
+ fn test_filter_go_test_all_pass() {
522
+ let output = r#"{"Time":"2024-01-01T10:00:00Z","Action":"run","Package":"example.com/foo","Test":"TestBar"}
523
+ {"Time":"2024-01-01T10:00:01Z","Action":"output","Package":"example.com/foo","Test":"TestBar","Output":"=== RUN TestBar\n"}
524
+ {"Time":"2024-01-01T10:00:02Z","Action":"pass","Package":"example.com/foo","Test":"TestBar","Elapsed":0.5}
525
+ {"Time":"2024-01-01T10:00:02Z","Action":"pass","Package":"example.com/foo","Elapsed":0.5}"#;
526
+
527
+ let result = filter_go_test_json(output);
528
+ assert!(result.contains("✓ Go test"));
529
+ assert!(result.contains("1 passed"));
530
+ assert!(result.contains("1 packages"));
531
+ }
532
+
533
+ #[test]
534
+ fn test_filter_go_test_with_failures() {
535
+ let output = r#"{"Time":"2024-01-01T10:00:00Z","Action":"run","Package":"example.com/foo","Test":"TestFail"}
536
+ {"Time":"2024-01-01T10:00:01Z","Action":"output","Package":"example.com/foo","Test":"TestFail","Output":"=== RUN TestFail\n"}
537
+ {"Time":"2024-01-01T10:00:02Z","Action":"output","Package":"example.com/foo","Test":"TestFail","Output":" Error: expected 5, got 3\n"}
538
+ {"Time":"2024-01-01T10:00:03Z","Action":"fail","Package":"example.com/foo","Test":"TestFail","Elapsed":0.5}
539
+ {"Time":"2024-01-01T10:00:03Z","Action":"fail","Package":"example.com/foo","Elapsed":0.5}"#;
540
+
541
+ let result = filter_go_test_json(output);
542
+ assert!(result.contains("1 failed"));
543
+ assert!(result.contains("TestFail"));
544
+ assert!(result.contains("expected 5, got 3"));
545
+ }
546
+
547
+ #[test]
548
+ fn test_filter_go_build_success() {
549
+ let output = "";
550
+ let result = filter_go_build(output);
551
+ assert!(result.contains("✓ Go build"));
552
+ assert!(result.contains("Success"));
553
+ }
554
+
555
+ #[test]
556
+ fn test_filter_go_build_errors() {
557
+ let output = r#"# example.com/foo
558
+ main.go:10:5: undefined: missingFunc
559
+ main.go:15:2: cannot use x (type int) as type string"#;
560
+
561
+ let result = filter_go_build(output);
562
+ assert!(result.contains("2 errors"));
563
+ assert!(result.contains("undefined: missingFunc"));
564
+ assert!(result.contains("cannot use x"));
565
+ }
566
+
567
+ #[test]
568
+ fn test_filter_go_vet_no_issues() {
569
+ let output = "";
570
+ let result = filter_go_vet(output);
571
+ assert!(result.contains("✓ Go vet"));
572
+ assert!(result.contains("No issues found"));
573
+ }
574
+
575
+ #[test]
576
+ fn test_filter_go_vet_with_issues() {
577
+ let output = r#"main.go:42:2: Printf format %d has arg x of wrong type string
578
+ utils.go:15:5: unreachable code"#;
579
+
580
+ let result = filter_go_vet(output);
581
+ assert!(result.contains("2 issues"));
582
+ assert!(result.contains("Printf format"));
583
+ assert!(result.contains("unreachable code"));
584
+ }
585
+
586
+ #[test]
587
+ fn test_compact_package_name() {
588
+ assert_eq!(compact_package_name("github.com/user/repo/pkg"), "pkg");
589
+ assert_eq!(compact_package_name("example.com/foo"), "foo");
590
+ assert_eq!(compact_package_name("simple"), "simple");
591
+ }
592
+ }