@hasna/terminal 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist/cli.js +64 -16
  2. package/package.json +1 -1
  3. package/src/ai.ts +8 -0
  4. package/src/cli.tsx +57 -18
  5. package/src/output-processor.ts +6 -1
  6. package/src/output-store.ts +58 -12
  7. package/src/tool-profiles.ts +139 -0
  8. package/temp/rtk/.claude/agents/code-reviewer.md +0 -221
  9. package/temp/rtk/.claude/agents/debugger.md +0 -519
  10. package/temp/rtk/.claude/agents/rtk-testing-specialist.md +0 -461
  11. package/temp/rtk/.claude/agents/rust-rtk.md +0 -511
  12. package/temp/rtk/.claude/agents/technical-writer.md +0 -355
  13. package/temp/rtk/.claude/commands/diagnose.md +0 -352
  14. package/temp/rtk/.claude/commands/test-routing.md +0 -362
  15. package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +0 -16
  16. package/temp/rtk/.claude/hooks/rtk-rewrite.sh +0 -70
  17. package/temp/rtk/.claude/hooks/rtk-suggest.sh +0 -152
  18. package/temp/rtk/.claude/rules/cli-testing.md +0 -526
  19. package/temp/rtk/.claude/skills/issue-triage/SKILL.md +0 -348
  20. package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +0 -134
  21. package/temp/rtk/.claude/skills/performance.md +0 -435
  22. package/temp/rtk/.claude/skills/pr-triage/SKILL.md +0 -315
  23. package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +0 -71
  24. package/temp/rtk/.claude/skills/repo-recap.md +0 -206
  25. package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +0 -78
  26. package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +0 -124
  27. package/temp/rtk/.claude/skills/security-guardian.md +0 -503
  28. package/temp/rtk/.claude/skills/ship.md +0 -404
  29. package/temp/rtk/.github/workflows/benchmark.yml +0 -34
  30. package/temp/rtk/.github/workflows/dco-check.yaml +0 -12
  31. package/temp/rtk/.github/workflows/release-please.yml +0 -51
  32. package/temp/rtk/.github/workflows/release.yml +0 -343
  33. package/temp/rtk/.github/workflows/security-check.yml +0 -135
  34. package/temp/rtk/.github/workflows/validate-docs.yml +0 -78
  35. package/temp/rtk/.release-please-manifest.json +0 -3
  36. package/temp/rtk/ARCHITECTURE.md +0 -1491
  37. package/temp/rtk/CHANGELOG.md +0 -640
  38. package/temp/rtk/CLAUDE.md +0 -605
  39. package/temp/rtk/CONTRIBUTING.md +0 -199
  40. package/temp/rtk/Cargo.lock +0 -1668
  41. package/temp/rtk/Cargo.toml +0 -64
  42. package/temp/rtk/Formula/rtk.rb +0 -43
  43. package/temp/rtk/INSTALL.md +0 -390
  44. package/temp/rtk/LICENSE +0 -21
  45. package/temp/rtk/README.md +0 -386
  46. package/temp/rtk/README_es.md +0 -159
  47. package/temp/rtk/README_fr.md +0 -197
  48. package/temp/rtk/README_ja.md +0 -159
  49. package/temp/rtk/README_ko.md +0 -159
  50. package/temp/rtk/README_zh.md +0 -167
  51. package/temp/rtk/ROADMAP.md +0 -15
  52. package/temp/rtk/SECURITY.md +0 -217
  53. package/temp/rtk/TEST_EXEC_TIME.md +0 -102
  54. package/temp/rtk/build.rs +0 -57
  55. package/temp/rtk/docs/AUDIT_GUIDE.md +0 -432
  56. package/temp/rtk/docs/FEATURES.md +0 -1410
  57. package/temp/rtk/docs/TROUBLESHOOTING.md +0 -309
  58. package/temp/rtk/docs/filter-workflow.md +0 -102
  59. package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
  60. package/temp/rtk/docs/tracking.md +0 -583
  61. package/temp/rtk/hooks/opencode-rtk.ts +0 -39
  62. package/temp/rtk/hooks/rtk-awareness.md +0 -29
  63. package/temp/rtk/hooks/rtk-rewrite.sh +0 -61
  64. package/temp/rtk/hooks/test-rtk-rewrite.sh +0 -442
  65. package/temp/rtk/install.sh +0 -124
  66. package/temp/rtk/release-please-config.json +0 -10
  67. package/temp/rtk/scripts/benchmark.sh +0 -592
  68. package/temp/rtk/scripts/check-installation.sh +0 -162
  69. package/temp/rtk/scripts/install-local.sh +0 -37
  70. package/temp/rtk/scripts/rtk-economics.sh +0 -137
  71. package/temp/rtk/scripts/test-all.sh +0 -561
  72. package/temp/rtk/scripts/test-aristote.sh +0 -227
  73. package/temp/rtk/scripts/test-tracking.sh +0 -79
  74. package/temp/rtk/scripts/update-readme-metrics.sh +0 -32
  75. package/temp/rtk/scripts/validate-docs.sh +0 -73
  76. package/temp/rtk/src/aws_cmd.rs +0 -880
  77. package/temp/rtk/src/binlog.rs +0 -1645
  78. package/temp/rtk/src/cargo_cmd.rs +0 -1727
  79. package/temp/rtk/src/cc_economics.rs +0 -1157
  80. package/temp/rtk/src/ccusage.rs +0 -340
  81. package/temp/rtk/src/config.rs +0 -187
  82. package/temp/rtk/src/container.rs +0 -855
  83. package/temp/rtk/src/curl_cmd.rs +0 -134
  84. package/temp/rtk/src/deps.rs +0 -268
  85. package/temp/rtk/src/diff_cmd.rs +0 -367
  86. package/temp/rtk/src/discover/mod.rs +0 -274
  87. package/temp/rtk/src/discover/provider.rs +0 -388
  88. package/temp/rtk/src/discover/registry.rs +0 -2022
  89. package/temp/rtk/src/discover/report.rs +0 -202
  90. package/temp/rtk/src/discover/rules.rs +0 -667
  91. package/temp/rtk/src/display_helpers.rs +0 -402
  92. package/temp/rtk/src/dotnet_cmd.rs +0 -1771
  93. package/temp/rtk/src/dotnet_format_report.rs +0 -133
  94. package/temp/rtk/src/dotnet_trx.rs +0 -593
  95. package/temp/rtk/src/env_cmd.rs +0 -204
  96. package/temp/rtk/src/filter.rs +0 -462
  97. package/temp/rtk/src/filters/README.md +0 -52
  98. package/temp/rtk/src/filters/ansible-playbook.toml +0 -34
  99. package/temp/rtk/src/filters/basedpyright.toml +0 -47
  100. package/temp/rtk/src/filters/biome.toml +0 -45
  101. package/temp/rtk/src/filters/brew-install.toml +0 -37
  102. package/temp/rtk/src/filters/composer-install.toml +0 -40
  103. package/temp/rtk/src/filters/df.toml +0 -16
  104. package/temp/rtk/src/filters/dotnet-build.toml +0 -64
  105. package/temp/rtk/src/filters/du.toml +0 -16
  106. package/temp/rtk/src/filters/fail2ban-client.toml +0 -15
  107. package/temp/rtk/src/filters/gcc.toml +0 -49
  108. package/temp/rtk/src/filters/gcloud.toml +0 -22
  109. package/temp/rtk/src/filters/hadolint.toml +0 -24
  110. package/temp/rtk/src/filters/helm.toml +0 -29
  111. package/temp/rtk/src/filters/iptables.toml +0 -27
  112. package/temp/rtk/src/filters/jj.toml +0 -28
  113. package/temp/rtk/src/filters/jq.toml +0 -24
  114. package/temp/rtk/src/filters/make.toml +0 -41
  115. package/temp/rtk/src/filters/markdownlint.toml +0 -24
  116. package/temp/rtk/src/filters/mix-compile.toml +0 -27
  117. package/temp/rtk/src/filters/mix-format.toml +0 -15
  118. package/temp/rtk/src/filters/mvn-build.toml +0 -44
  119. package/temp/rtk/src/filters/oxlint.toml +0 -43
  120. package/temp/rtk/src/filters/ping.toml +0 -63
  121. package/temp/rtk/src/filters/pio-run.toml +0 -40
  122. package/temp/rtk/src/filters/poetry-install.toml +0 -50
  123. package/temp/rtk/src/filters/pre-commit.toml +0 -35
  124. package/temp/rtk/src/filters/ps.toml +0 -16
  125. package/temp/rtk/src/filters/quarto-render.toml +0 -41
  126. package/temp/rtk/src/filters/rsync.toml +0 -48
  127. package/temp/rtk/src/filters/shellcheck.toml +0 -27
  128. package/temp/rtk/src/filters/shopify-theme.toml +0 -29
  129. package/temp/rtk/src/filters/skopeo.toml +0 -45
  130. package/temp/rtk/src/filters/sops.toml +0 -16
  131. package/temp/rtk/src/filters/ssh.toml +0 -44
  132. package/temp/rtk/src/filters/stat.toml +0 -34
  133. package/temp/rtk/src/filters/swift-build.toml +0 -41
  134. package/temp/rtk/src/filters/systemctl-status.toml +0 -33
  135. package/temp/rtk/src/filters/terraform-plan.toml +0 -35
  136. package/temp/rtk/src/filters/tofu-fmt.toml +0 -16
  137. package/temp/rtk/src/filters/tofu-init.toml +0 -38
  138. package/temp/rtk/src/filters/tofu-plan.toml +0 -35
  139. package/temp/rtk/src/filters/tofu-validate.toml +0 -17
  140. package/temp/rtk/src/filters/trunk-build.toml +0 -39
  141. package/temp/rtk/src/filters/ty.toml +0 -50
  142. package/temp/rtk/src/filters/uv-sync.toml +0 -37
  143. package/temp/rtk/src/filters/xcodebuild.toml +0 -99
  144. package/temp/rtk/src/filters/yamllint.toml +0 -25
  145. package/temp/rtk/src/find_cmd.rs +0 -598
  146. package/temp/rtk/src/format_cmd.rs +0 -386
  147. package/temp/rtk/src/gain.rs +0 -723
  148. package/temp/rtk/src/gh_cmd.rs +0 -1651
  149. package/temp/rtk/src/git.rs +0 -2012
  150. package/temp/rtk/src/go_cmd.rs +0 -592
  151. package/temp/rtk/src/golangci_cmd.rs +0 -254
  152. package/temp/rtk/src/grep_cmd.rs +0 -288
  153. package/temp/rtk/src/gt_cmd.rs +0 -810
  154. package/temp/rtk/src/hook_audit_cmd.rs +0 -283
  155. package/temp/rtk/src/hook_check.rs +0 -171
  156. package/temp/rtk/src/init.rs +0 -1859
  157. package/temp/rtk/src/integrity.rs +0 -537
  158. package/temp/rtk/src/json_cmd.rs +0 -231
  159. package/temp/rtk/src/learn/detector.rs +0 -628
  160. package/temp/rtk/src/learn/mod.rs +0 -119
  161. package/temp/rtk/src/learn/report.rs +0 -184
  162. package/temp/rtk/src/lint_cmd.rs +0 -694
  163. package/temp/rtk/src/local_llm.rs +0 -316
  164. package/temp/rtk/src/log_cmd.rs +0 -248
  165. package/temp/rtk/src/ls.rs +0 -324
  166. package/temp/rtk/src/main.rs +0 -2482
  167. package/temp/rtk/src/mypy_cmd.rs +0 -389
  168. package/temp/rtk/src/next_cmd.rs +0 -241
  169. package/temp/rtk/src/npm_cmd.rs +0 -236
  170. package/temp/rtk/src/parser/README.md +0 -267
  171. package/temp/rtk/src/parser/error.rs +0 -46
  172. package/temp/rtk/src/parser/formatter.rs +0 -336
  173. package/temp/rtk/src/parser/mod.rs +0 -311
  174. package/temp/rtk/src/parser/types.rs +0 -119
  175. package/temp/rtk/src/pip_cmd.rs +0 -302
  176. package/temp/rtk/src/playwright_cmd.rs +0 -479
  177. package/temp/rtk/src/pnpm_cmd.rs +0 -573
  178. package/temp/rtk/src/prettier_cmd.rs +0 -221
  179. package/temp/rtk/src/prisma_cmd.rs +0 -482
  180. package/temp/rtk/src/psql_cmd.rs +0 -382
  181. package/temp/rtk/src/pytest_cmd.rs +0 -384
  182. package/temp/rtk/src/read.rs +0 -217
  183. package/temp/rtk/src/rewrite_cmd.rs +0 -50
  184. package/temp/rtk/src/ruff_cmd.rs +0 -402
  185. package/temp/rtk/src/runner.rs +0 -271
  186. package/temp/rtk/src/summary.rs +0 -297
  187. package/temp/rtk/src/tee.rs +0 -405
  188. package/temp/rtk/src/telemetry.rs +0 -248
  189. package/temp/rtk/src/toml_filter.rs +0 -1655
  190. package/temp/rtk/src/tracking.rs +0 -1416
  191. package/temp/rtk/src/tree.rs +0 -209
  192. package/temp/rtk/src/tsc_cmd.rs +0 -259
  193. package/temp/rtk/src/utils.rs +0 -432
  194. package/temp/rtk/src/verify_cmd.rs +0 -47
  195. package/temp/rtk/src/vitest_cmd.rs +0 -385
  196. package/temp/rtk/src/wc_cmd.rs +0 -401
  197. package/temp/rtk/src/wget_cmd.rs +0 -260
  198. package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +0 -11
  199. package/temp/rtk/tests/fixtures/dotnet/format_changes.json +0 -31
  200. package/temp/rtk/tests/fixtures/dotnet/format_empty.json +0 -1
  201. package/temp/rtk/tests/fixtures/dotnet/format_success.json +0 -12
  202. package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +0 -18
@@ -1,598 +0,0 @@
1
- use crate::tracking;
2
- use anyhow::{Context, Result};
3
- use ignore::WalkBuilder;
4
- use std::collections::HashMap;
5
- use std::path::Path;
6
-
7
- /// Match a filename against a glob pattern (supports `*` and `?`).
8
- fn glob_match(pattern: &str, name: &str) -> bool {
9
- glob_match_inner(pattern.as_bytes(), name.as_bytes())
10
- }
11
-
12
- fn glob_match_inner(pat: &[u8], name: &[u8]) -> bool {
13
- match (pat.first(), name.first()) {
14
- (None, None) => true,
15
- (Some(b'*'), _) => {
16
- // '*' matches zero or more characters
17
- glob_match_inner(&pat[1..], name)
18
- || (!name.is_empty() && glob_match_inner(pat, &name[1..]))
19
- }
20
- (Some(b'?'), Some(_)) => glob_match_inner(&pat[1..], &name[1..]),
21
- (Some(&p), Some(&n)) if p == n => glob_match_inner(&pat[1..], &name[1..]),
22
- _ => false,
23
- }
24
- }
25
-
26
- /// Parsed arguments from either native find or RTK find syntax.
27
- #[derive(Debug)]
28
- struct FindArgs {
29
- pattern: String,
30
- path: String,
31
- max_results: usize,
32
- max_depth: Option<usize>,
33
- file_type: String,
34
- case_insensitive: bool,
35
- }
36
-
37
- impl Default for FindArgs {
38
- fn default() -> Self {
39
- Self {
40
- pattern: "*".to_string(),
41
- path: ".".to_string(),
42
- max_results: 50,
43
- max_depth: None,
44
- file_type: "f".to_string(),
45
- case_insensitive: false,
46
- }
47
- }
48
- }
49
-
50
- /// Consume the next argument from `args` at position `i`, advancing the index.
51
- /// Returns `None` if `i` is past the end of `args`.
52
- fn next_arg(args: &[String], i: &mut usize) -> Option<String> {
53
- *i += 1;
54
- args.get(*i).cloned()
55
- }
56
-
57
- /// Check if args contain native find flags (-name, -type, -maxdepth, etc.)
58
- fn has_native_find_flags(args: &[String]) -> bool {
59
- args.iter()
60
- .any(|a| a == "-name" || a == "-type" || a == "-maxdepth" || a == "-iname")
61
- }
62
-
63
- /// Native find flags that RTK cannot handle correctly.
64
- /// These involve compound predicates, actions, or semantics we don't support.
65
- const UNSUPPORTED_FIND_FLAGS: &[&str] = &[
66
- "-not", "!", "-or", "-o", "-and", "-a", "-exec", "-execdir", "-delete", "-print0", "-newer",
67
- "-perm", "-size", "-mtime", "-mmin", "-atime", "-amin", "-ctime", "-cmin", "-empty", "-link",
68
- "-regex", "-iregex",
69
- ];
70
-
71
- fn has_unsupported_find_flags(args: &[String]) -> bool {
72
- args.iter()
73
- .any(|a| UNSUPPORTED_FIND_FLAGS.contains(&a.as_str()))
74
- }
75
-
76
- /// Parse arguments from raw args vec, supporting both native find and RTK syntax.
77
- ///
78
- /// Native find syntax: `find . -name "*.rs" -type f -maxdepth 3`
79
- /// RTK syntax: `find *.rs [path] [-m max] [-t type]`
80
- fn parse_find_args(args: &[String]) -> Result<FindArgs> {
81
- if args.is_empty() {
82
- return Ok(FindArgs::default());
83
- }
84
-
85
- if has_unsupported_find_flags(args) {
86
- anyhow::bail!(
87
- "rtk find does not support compound predicates or actions (e.g. -not, -exec). Use `find` directly."
88
- );
89
- }
90
-
91
- if has_native_find_flags(args) {
92
- parse_native_find_args(args)
93
- } else {
94
- parse_rtk_find_args(args)
95
- }
96
- }
97
-
98
- /// Parse native find syntax: `find [path] -name "*.rs" -type f -maxdepth 3`
99
- fn parse_native_find_args(args: &[String]) -> Result<FindArgs> {
100
- let mut parsed = FindArgs::default();
101
- let mut i = 0;
102
-
103
- // First non-flag argument is the path (standard find behavior)
104
- if !args[0].starts_with('-') {
105
- parsed.path = args[0].clone();
106
- i = 1;
107
- }
108
-
109
- while i < args.len() {
110
- match args[i].as_str() {
111
- "-name" => {
112
- if let Some(val) = next_arg(args, &mut i) {
113
- parsed.pattern = val;
114
- }
115
- }
116
- "-iname" => {
117
- if let Some(val) = next_arg(args, &mut i) {
118
- parsed.pattern = val;
119
- parsed.case_insensitive = true;
120
- }
121
- }
122
- "-type" => {
123
- if let Some(val) = next_arg(args, &mut i) {
124
- parsed.file_type = val;
125
- }
126
- }
127
- "-maxdepth" => {
128
- if let Some(val) = next_arg(args, &mut i) {
129
- parsed.max_depth = Some(val.parse().context("invalid -maxdepth value")?);
130
- }
131
- }
132
- flag if flag.starts_with('-') => {
133
- eprintln!("rtk find: unknown flag '{}', ignored", flag);
134
- }
135
- _ => {}
136
- }
137
- i += 1;
138
- }
139
-
140
- Ok(parsed)
141
- }
142
-
143
- /// Parse RTK syntax: `find <pattern> [path] [-m max] [-t type]`
144
- fn parse_rtk_find_args(args: &[String]) -> Result<FindArgs> {
145
- let mut parsed = FindArgs {
146
- pattern: args[0].clone(),
147
- ..FindArgs::default()
148
- };
149
- let mut i = 1;
150
-
151
- // Second positional arg (if not a flag) is the path
152
- if i < args.len() && !args[i].starts_with('-') {
153
- parsed.path = args[i].clone();
154
- i += 1;
155
- }
156
-
157
- while i < args.len() {
158
- match args[i].as_str() {
159
- "-m" | "--max" => {
160
- if let Some(val) = next_arg(args, &mut i) {
161
- parsed.max_results = val.parse().context("invalid --max value")?;
162
- }
163
- }
164
- "-t" | "--file-type" => {
165
- if let Some(val) = next_arg(args, &mut i) {
166
- parsed.file_type = val;
167
- }
168
- }
169
- _ => {}
170
- }
171
- i += 1;
172
- }
173
-
174
- Ok(parsed)
175
- }
176
-
177
- /// Entry point from main.rs — parses raw args then delegates to run().
178
- pub fn run_from_args(args: &[String], verbose: u8) -> Result<()> {
179
- let parsed = parse_find_args(args)?;
180
- run(
181
- &parsed.pattern,
182
- &parsed.path,
183
- parsed.max_results,
184
- parsed.max_depth,
185
- &parsed.file_type,
186
- parsed.case_insensitive,
187
- verbose,
188
- )
189
- }
190
-
191
- pub fn run(
192
- pattern: &str,
193
- path: &str,
194
- max_results: usize,
195
- max_depth: Option<usize>,
196
- file_type: &str,
197
- case_insensitive: bool,
198
- verbose: u8,
199
- ) -> Result<()> {
200
- let timer = tracking::TimedExecution::start();
201
-
202
- // Treat "." as match-all
203
- let effective_pattern = if pattern == "." { "*" } else { pattern };
204
-
205
- if verbose > 0 {
206
- eprintln!("find: {} in {}", effective_pattern, path);
207
- }
208
-
209
- let want_dirs = file_type == "d";
210
-
211
- let mut builder = WalkBuilder::new(path);
212
- builder
213
- .hidden(true) // skip hidden files/dirs
214
- .git_ignore(true) // respect .gitignore
215
- .git_global(true)
216
- .git_exclude(true);
217
- if let Some(depth) = max_depth {
218
- builder.max_depth(Some(depth));
219
- }
220
- let walker = builder.build();
221
-
222
- let mut files: Vec<String> = Vec::new();
223
-
224
- for entry in walker {
225
- let entry = match entry {
226
- Ok(e) => e,
227
- Err(_) => continue,
228
- };
229
-
230
- let ft = entry.file_type();
231
- let is_dir = ft.as_ref().is_some_and(|t| t.is_dir());
232
-
233
- // Filter by type
234
- if want_dirs && !is_dir {
235
- continue;
236
- }
237
- if !want_dirs && is_dir {
238
- continue;
239
- }
240
-
241
- let entry_path = entry.path();
242
-
243
- // Get filename for glob matching
244
- let name = match entry_path.file_name() {
245
- Some(n) => n.to_string_lossy(),
246
- None => continue,
247
- };
248
-
249
- let matches = if case_insensitive {
250
- glob_match(&effective_pattern.to_lowercase(), &name.to_lowercase())
251
- } else {
252
- glob_match(effective_pattern, &name)
253
- };
254
- if !matches {
255
- continue;
256
- }
257
-
258
- // Store path relative to search root
259
- let display_path = entry_path
260
- .strip_prefix(path)
261
- .unwrap_or(entry_path)
262
- .to_string_lossy()
263
- .to_string();
264
-
265
- if !display_path.is_empty() {
266
- files.push(display_path);
267
- }
268
- }
269
-
270
- files.sort();
271
-
272
- let raw_output = files.join("\n");
273
-
274
- if files.is_empty() {
275
- let msg = format!("0 for '{}'", effective_pattern);
276
- println!("{}", msg);
277
- timer.track(
278
- &format!("find {} -name '{}'", path, effective_pattern),
279
- "rtk find",
280
- &raw_output,
281
- &msg,
282
- );
283
- return Ok(());
284
- }
285
-
286
- // Group by directory
287
- let mut by_dir: HashMap<String, Vec<String>> = HashMap::new();
288
-
289
- for file in &files {
290
- let p = Path::new(file);
291
- let dir = p
292
- .parent()
293
- .map(|d| d.to_string_lossy().to_string())
294
- .unwrap_or_else(|| ".".to_string());
295
- let dir = if dir.is_empty() { ".".to_string() } else { dir };
296
- let filename = p
297
- .file_name()
298
- .map(|f| f.to_string_lossy().to_string())
299
- .unwrap_or_default();
300
- by_dir.entry(dir).or_default().push(filename);
301
- }
302
-
303
- let mut dirs: Vec<_> = by_dir.keys().cloned().collect();
304
- dirs.sort();
305
- let dirs_count = dirs.len();
306
- let total_files = files.len();
307
-
308
- println!("📁 {}F {}D:", total_files, dirs_count);
309
- println!();
310
-
311
- // Display with proper --max limiting (count individual files)
312
- let mut shown = 0;
313
- for dir in &dirs {
314
- if shown >= max_results {
315
- break;
316
- }
317
-
318
- let files_in_dir = &by_dir[dir];
319
- let dir_display = if dir.len() > 50 {
320
- format!("...{}", &dir[dir.len() - 47..])
321
- } else {
322
- dir.clone()
323
- };
324
-
325
- let remaining_budget = max_results - shown;
326
- if files_in_dir.len() <= remaining_budget {
327
- println!("{}/ {}", dir_display, files_in_dir.join(" "));
328
- shown += files_in_dir.len();
329
- } else {
330
- // Partial display: show only what fits in budget
331
- let partial: Vec<_> = files_in_dir
332
- .iter()
333
- .take(remaining_budget)
334
- .cloned()
335
- .collect();
336
- println!("{}/ {}", dir_display, partial.join(" "));
337
- shown += partial.len();
338
- break;
339
- }
340
- }
341
-
342
- if shown < total_files {
343
- println!("+{} more", total_files - shown);
344
- }
345
-
346
- // Extension summary
347
- let mut by_ext: HashMap<String, usize> = HashMap::new();
348
- for file in &files {
349
- let ext = Path::new(file)
350
- .extension()
351
- .map(|e| e.to_string_lossy().to_string())
352
- .unwrap_or_else(|| "none".to_string());
353
- *by_ext.entry(ext).or_default() += 1;
354
- }
355
-
356
- let mut ext_line = String::new();
357
- if by_ext.len() > 1 {
358
- println!();
359
- let mut exts: Vec<_> = by_ext.iter().collect();
360
- exts.sort_by(|a, b| b.1.cmp(a.1));
361
- let ext_str: Vec<String> = exts
362
- .iter()
363
- .take(5)
364
- .map(|(e, c)| format!(".{}({})", e, c))
365
- .collect();
366
- ext_line = format!("ext: {}", ext_str.join(" "));
367
- println!("{}", ext_line);
368
- }
369
-
370
- let rtk_output = format!("{}F {}D + {}", total_files, dirs_count, ext_line);
371
- timer.track(
372
- &format!("find {} -name '{}'", path, effective_pattern),
373
- "rtk find",
374
- &raw_output,
375
- &rtk_output,
376
- );
377
-
378
- Ok(())
379
- }
380
-
381
- #[cfg(test)]
382
- mod tests {
383
- use super::*;
384
-
385
- /// Convert string slices to Vec<String> for test convenience.
386
- fn args(values: &[&str]) -> Vec<String> {
387
- values.iter().map(|s| s.to_string()).collect()
388
- }
389
-
390
- // --- glob_match unit tests ---
391
-
392
- #[test]
393
- fn glob_match_star_rs() {
394
- assert!(glob_match("*.rs", "main.rs"));
395
- assert!(glob_match("*.rs", "find_cmd.rs"));
396
- assert!(!glob_match("*.rs", "main.py"));
397
- assert!(!glob_match("*.rs", "rs"));
398
- }
399
-
400
- #[test]
401
- fn glob_match_star_all() {
402
- assert!(glob_match("*", "anything.txt"));
403
- assert!(glob_match("*", "a"));
404
- assert!(glob_match("*", ".hidden"));
405
- }
406
-
407
- #[test]
408
- fn glob_match_question_mark() {
409
- assert!(glob_match("?.rs", "a.rs"));
410
- assert!(!glob_match("?.rs", "ab.rs"));
411
- }
412
-
413
- #[test]
414
- fn glob_match_exact() {
415
- assert!(glob_match("Cargo.toml", "Cargo.toml"));
416
- assert!(!glob_match("Cargo.toml", "cargo.toml"));
417
- }
418
-
419
- #[test]
420
- fn glob_match_complex() {
421
- assert!(glob_match("test_*", "test_foo"));
422
- assert!(glob_match("test_*", "test_"));
423
- assert!(!glob_match("test_*", "test"));
424
- }
425
-
426
- // --- dot pattern treated as star ---
427
-
428
- #[test]
429
- fn dot_becomes_star() {
430
- // run() converts "." to "*" internally, test the logic
431
- let effective = if "." == "." { "*" } else { "." };
432
- assert_eq!(effective, "*");
433
- }
434
-
435
- // --- parse_find_args: native find syntax ---
436
-
437
- #[test]
438
- fn parse_native_find_name() {
439
- let parsed = parse_find_args(&args(&[".", "-name", "*.rs"])).unwrap();
440
- assert_eq!(parsed.pattern, "*.rs");
441
- assert_eq!(parsed.path, ".");
442
- assert_eq!(parsed.file_type, "f");
443
- assert_eq!(parsed.max_results, 50);
444
- }
445
-
446
- #[test]
447
- fn parse_native_find_name_and_type() {
448
- let parsed = parse_find_args(&args(&["src", "-name", "*.rs", "-type", "f"])).unwrap();
449
- assert_eq!(parsed.pattern, "*.rs");
450
- assert_eq!(parsed.path, "src");
451
- assert_eq!(parsed.file_type, "f");
452
- }
453
-
454
- #[test]
455
- fn parse_native_find_type_d() {
456
- let parsed = parse_find_args(&args(&[".", "-type", "d"])).unwrap();
457
- assert_eq!(parsed.pattern, "*");
458
- assert_eq!(parsed.file_type, "d");
459
- }
460
-
461
- #[test]
462
- fn parse_native_find_maxdepth() {
463
- let parsed = parse_find_args(&args(&[".", "-name", "*.toml", "-maxdepth", "2"])).unwrap();
464
- assert_eq!(parsed.pattern, "*.toml");
465
- assert_eq!(parsed.max_depth, Some(2));
466
- assert_eq!(parsed.max_results, 50); // max_results unchanged by -maxdepth
467
- }
468
-
469
- #[test]
470
- fn parse_native_find_iname() {
471
- let parsed = parse_find_args(&args(&[".", "-iname", "Makefile"])).unwrap();
472
- assert_eq!(parsed.pattern, "Makefile");
473
- assert!(parsed.case_insensitive);
474
- }
475
-
476
- #[test]
477
- fn parse_native_find_name_is_case_sensitive() {
478
- let parsed = parse_find_args(&args(&[".", "-name", "*.rs"])).unwrap();
479
- assert!(!parsed.case_insensitive);
480
- }
481
-
482
- #[test]
483
- fn parse_native_find_no_path() {
484
- // `find -name "*.rs"` without explicit path defaults to "."
485
- let parsed = parse_find_args(&args(&["-name", "*.rs"])).unwrap();
486
- assert_eq!(parsed.pattern, "*.rs");
487
- assert_eq!(parsed.path, ".");
488
- }
489
-
490
- // --- parse_find_args: unsupported flags ---
491
-
492
- #[test]
493
- fn parse_native_find_rejects_not() {
494
- let result = parse_find_args(&args(&[".", "-name", "*.rs", "-not", "-name", "*_test.rs"]));
495
- assert!(result.is_err());
496
- let msg = result.unwrap_err().to_string();
497
- assert!(msg.contains("compound predicates"));
498
- }
499
-
500
- #[test]
501
- fn parse_native_find_rejects_exec() {
502
- let result = parse_find_args(&args(&[".", "-name", "*.tmp", "-exec", "rm", "{}", ";"]));
503
- assert!(result.is_err());
504
- }
505
-
506
- // --- parse_find_args: RTK syntax ---
507
-
508
- #[test]
509
- fn parse_rtk_syntax_pattern_only() {
510
- let parsed = parse_find_args(&args(&["*.rs"])).unwrap();
511
- assert_eq!(parsed.pattern, "*.rs");
512
- assert_eq!(parsed.path, ".");
513
- }
514
-
515
- #[test]
516
- fn parse_rtk_syntax_pattern_and_path() {
517
- let parsed = parse_find_args(&args(&["*.rs", "src"])).unwrap();
518
- assert_eq!(parsed.pattern, "*.rs");
519
- assert_eq!(parsed.path, "src");
520
- }
521
-
522
- #[test]
523
- fn parse_rtk_syntax_with_flags() {
524
- let parsed = parse_find_args(&args(&["*.rs", "src", "-m", "10", "-t", "d"])).unwrap();
525
- assert_eq!(parsed.pattern, "*.rs");
526
- assert_eq!(parsed.path, "src");
527
- assert_eq!(parsed.max_results, 10);
528
- assert_eq!(parsed.file_type, "d");
529
- }
530
-
531
- #[test]
532
- fn parse_empty_args() {
533
- let parsed = parse_find_args(&args(&[])).unwrap();
534
- assert_eq!(parsed.pattern, "*");
535
- assert_eq!(parsed.path, ".");
536
- }
537
-
538
- // --- run_from_args integration tests ---
539
-
540
- #[test]
541
- fn run_from_args_native_find_syntax() {
542
- // Simulates: find . -name "*.rs" -type f
543
- let result = run_from_args(&args(&[".", "-name", "*.rs", "-type", "f"]), 0);
544
- assert!(result.is_ok());
545
- }
546
-
547
- #[test]
548
- fn run_from_args_rtk_syntax() {
549
- // Simulates: rtk find *.rs src
550
- let result = run_from_args(&args(&["*.rs", "src"]), 0);
551
- assert!(result.is_ok());
552
- }
553
-
554
- #[test]
555
- fn run_from_args_iname_case_insensitive() {
556
- // -iname should match case-insensitively
557
- let result = run_from_args(&args(&[".", "-iname", "cargo.toml"]), 0);
558
- assert!(result.is_ok());
559
- }
560
-
561
- // --- integration: run on this repo ---
562
-
563
- #[test]
564
- fn find_rs_files_in_src() {
565
- // Should find .rs files without error
566
- let result = run("*.rs", "src", 100, None, "f", false, 0);
567
- assert!(result.is_ok());
568
- }
569
-
570
- #[test]
571
- fn find_dot_pattern_works() {
572
- // "." pattern should not error (was broken before)
573
- let result = run(".", "src", 10, None, "f", false, 0);
574
- assert!(result.is_ok());
575
- }
576
-
577
- #[test]
578
- fn find_no_matches() {
579
- let result = run("*.xyz_nonexistent", "src", 50, None, "f", false, 0);
580
- assert!(result.is_ok());
581
- }
582
-
583
- #[test]
584
- fn find_respects_max() {
585
- // With max=2, should not error
586
- let result = run("*.rs", "src", 2, None, "f", false, 0);
587
- assert!(result.is_ok());
588
- }
589
-
590
- #[test]
591
- fn find_gitignored_excluded() {
592
- // target/ is in .gitignore — files inside should not appear
593
- let result = run("*", ".", 1000, None, "f", false, 0);
594
- assert!(result.is_ok());
595
- // We can't easily capture stdout in unit tests, but at least
596
- // verify it runs without error. The smoke tests verify content.
597
- }
598
- }