@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.
- package/dist/cli.js +64 -16
- package/package.json +1 -1
- package/src/ai.ts +8 -0
- package/src/cli.tsx +57 -18
- package/src/output-processor.ts +6 -1
- package/src/output-store.ts +58 -12
- package/src/tool-profiles.ts +139 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +0 -221
- package/temp/rtk/.claude/agents/debugger.md +0 -519
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +0 -461
- package/temp/rtk/.claude/agents/rust-rtk.md +0 -511
- package/temp/rtk/.claude/agents/technical-writer.md +0 -355
- package/temp/rtk/.claude/commands/diagnose.md +0 -352
- package/temp/rtk/.claude/commands/test-routing.md +0 -362
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +0 -16
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +0 -70
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +0 -152
- package/temp/rtk/.claude/rules/cli-testing.md +0 -526
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +0 -348
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +0 -134
- package/temp/rtk/.claude/skills/performance.md +0 -435
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +0 -315
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +0 -71
- package/temp/rtk/.claude/skills/repo-recap.md +0 -206
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +0 -78
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +0 -124
- package/temp/rtk/.claude/skills/security-guardian.md +0 -503
- package/temp/rtk/.claude/skills/ship.md +0 -404
- package/temp/rtk/.github/workflows/benchmark.yml +0 -34
- package/temp/rtk/.github/workflows/dco-check.yaml +0 -12
- package/temp/rtk/.github/workflows/release-please.yml +0 -51
- package/temp/rtk/.github/workflows/release.yml +0 -343
- package/temp/rtk/.github/workflows/security-check.yml +0 -135
- package/temp/rtk/.github/workflows/validate-docs.yml +0 -78
- package/temp/rtk/.release-please-manifest.json +0 -3
- package/temp/rtk/ARCHITECTURE.md +0 -1491
- package/temp/rtk/CHANGELOG.md +0 -640
- package/temp/rtk/CLAUDE.md +0 -605
- package/temp/rtk/CONTRIBUTING.md +0 -199
- package/temp/rtk/Cargo.lock +0 -1668
- package/temp/rtk/Cargo.toml +0 -64
- package/temp/rtk/Formula/rtk.rb +0 -43
- package/temp/rtk/INSTALL.md +0 -390
- package/temp/rtk/LICENSE +0 -21
- package/temp/rtk/README.md +0 -386
- package/temp/rtk/README_es.md +0 -159
- package/temp/rtk/README_fr.md +0 -197
- package/temp/rtk/README_ja.md +0 -159
- package/temp/rtk/README_ko.md +0 -159
- package/temp/rtk/README_zh.md +0 -167
- package/temp/rtk/ROADMAP.md +0 -15
- package/temp/rtk/SECURITY.md +0 -217
- package/temp/rtk/TEST_EXEC_TIME.md +0 -102
- package/temp/rtk/build.rs +0 -57
- package/temp/rtk/docs/AUDIT_GUIDE.md +0 -432
- package/temp/rtk/docs/FEATURES.md +0 -1410
- package/temp/rtk/docs/TROUBLESHOOTING.md +0 -309
- package/temp/rtk/docs/filter-workflow.md +0 -102
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +0 -583
- package/temp/rtk/hooks/opencode-rtk.ts +0 -39
- package/temp/rtk/hooks/rtk-awareness.md +0 -29
- package/temp/rtk/hooks/rtk-rewrite.sh +0 -61
- package/temp/rtk/hooks/test-rtk-rewrite.sh +0 -442
- package/temp/rtk/install.sh +0 -124
- package/temp/rtk/release-please-config.json +0 -10
- package/temp/rtk/scripts/benchmark.sh +0 -592
- package/temp/rtk/scripts/check-installation.sh +0 -162
- package/temp/rtk/scripts/install-local.sh +0 -37
- package/temp/rtk/scripts/rtk-economics.sh +0 -137
- package/temp/rtk/scripts/test-all.sh +0 -561
- package/temp/rtk/scripts/test-aristote.sh +0 -227
- package/temp/rtk/scripts/test-tracking.sh +0 -79
- package/temp/rtk/scripts/update-readme-metrics.sh +0 -32
- package/temp/rtk/scripts/validate-docs.sh +0 -73
- package/temp/rtk/src/aws_cmd.rs +0 -880
- package/temp/rtk/src/binlog.rs +0 -1645
- package/temp/rtk/src/cargo_cmd.rs +0 -1727
- package/temp/rtk/src/cc_economics.rs +0 -1157
- package/temp/rtk/src/ccusage.rs +0 -340
- package/temp/rtk/src/config.rs +0 -187
- package/temp/rtk/src/container.rs +0 -855
- package/temp/rtk/src/curl_cmd.rs +0 -134
- package/temp/rtk/src/deps.rs +0 -268
- package/temp/rtk/src/diff_cmd.rs +0 -367
- package/temp/rtk/src/discover/mod.rs +0 -274
- package/temp/rtk/src/discover/provider.rs +0 -388
- package/temp/rtk/src/discover/registry.rs +0 -2022
- package/temp/rtk/src/discover/report.rs +0 -202
- package/temp/rtk/src/discover/rules.rs +0 -667
- package/temp/rtk/src/display_helpers.rs +0 -402
- package/temp/rtk/src/dotnet_cmd.rs +0 -1771
- package/temp/rtk/src/dotnet_format_report.rs +0 -133
- package/temp/rtk/src/dotnet_trx.rs +0 -593
- package/temp/rtk/src/env_cmd.rs +0 -204
- package/temp/rtk/src/filter.rs +0 -462
- package/temp/rtk/src/filters/README.md +0 -52
- package/temp/rtk/src/filters/ansible-playbook.toml +0 -34
- package/temp/rtk/src/filters/basedpyright.toml +0 -47
- package/temp/rtk/src/filters/biome.toml +0 -45
- package/temp/rtk/src/filters/brew-install.toml +0 -37
- package/temp/rtk/src/filters/composer-install.toml +0 -40
- package/temp/rtk/src/filters/df.toml +0 -16
- package/temp/rtk/src/filters/dotnet-build.toml +0 -64
- package/temp/rtk/src/filters/du.toml +0 -16
- package/temp/rtk/src/filters/fail2ban-client.toml +0 -15
- package/temp/rtk/src/filters/gcc.toml +0 -49
- package/temp/rtk/src/filters/gcloud.toml +0 -22
- package/temp/rtk/src/filters/hadolint.toml +0 -24
- package/temp/rtk/src/filters/helm.toml +0 -29
- package/temp/rtk/src/filters/iptables.toml +0 -27
- package/temp/rtk/src/filters/jj.toml +0 -28
- package/temp/rtk/src/filters/jq.toml +0 -24
- package/temp/rtk/src/filters/make.toml +0 -41
- package/temp/rtk/src/filters/markdownlint.toml +0 -24
- package/temp/rtk/src/filters/mix-compile.toml +0 -27
- package/temp/rtk/src/filters/mix-format.toml +0 -15
- package/temp/rtk/src/filters/mvn-build.toml +0 -44
- package/temp/rtk/src/filters/oxlint.toml +0 -43
- package/temp/rtk/src/filters/ping.toml +0 -63
- package/temp/rtk/src/filters/pio-run.toml +0 -40
- package/temp/rtk/src/filters/poetry-install.toml +0 -50
- package/temp/rtk/src/filters/pre-commit.toml +0 -35
- package/temp/rtk/src/filters/ps.toml +0 -16
- package/temp/rtk/src/filters/quarto-render.toml +0 -41
- package/temp/rtk/src/filters/rsync.toml +0 -48
- package/temp/rtk/src/filters/shellcheck.toml +0 -27
- package/temp/rtk/src/filters/shopify-theme.toml +0 -29
- package/temp/rtk/src/filters/skopeo.toml +0 -45
- package/temp/rtk/src/filters/sops.toml +0 -16
- package/temp/rtk/src/filters/ssh.toml +0 -44
- package/temp/rtk/src/filters/stat.toml +0 -34
- package/temp/rtk/src/filters/swift-build.toml +0 -41
- package/temp/rtk/src/filters/systemctl-status.toml +0 -33
- package/temp/rtk/src/filters/terraform-plan.toml +0 -35
- package/temp/rtk/src/filters/tofu-fmt.toml +0 -16
- package/temp/rtk/src/filters/tofu-init.toml +0 -38
- package/temp/rtk/src/filters/tofu-plan.toml +0 -35
- package/temp/rtk/src/filters/tofu-validate.toml +0 -17
- package/temp/rtk/src/filters/trunk-build.toml +0 -39
- package/temp/rtk/src/filters/ty.toml +0 -50
- package/temp/rtk/src/filters/uv-sync.toml +0 -37
- package/temp/rtk/src/filters/xcodebuild.toml +0 -99
- package/temp/rtk/src/filters/yamllint.toml +0 -25
- package/temp/rtk/src/find_cmd.rs +0 -598
- package/temp/rtk/src/format_cmd.rs +0 -386
- package/temp/rtk/src/gain.rs +0 -723
- package/temp/rtk/src/gh_cmd.rs +0 -1651
- package/temp/rtk/src/git.rs +0 -2012
- package/temp/rtk/src/go_cmd.rs +0 -592
- package/temp/rtk/src/golangci_cmd.rs +0 -254
- package/temp/rtk/src/grep_cmd.rs +0 -288
- package/temp/rtk/src/gt_cmd.rs +0 -810
- package/temp/rtk/src/hook_audit_cmd.rs +0 -283
- package/temp/rtk/src/hook_check.rs +0 -171
- package/temp/rtk/src/init.rs +0 -1859
- package/temp/rtk/src/integrity.rs +0 -537
- package/temp/rtk/src/json_cmd.rs +0 -231
- package/temp/rtk/src/learn/detector.rs +0 -628
- package/temp/rtk/src/learn/mod.rs +0 -119
- package/temp/rtk/src/learn/report.rs +0 -184
- package/temp/rtk/src/lint_cmd.rs +0 -694
- package/temp/rtk/src/local_llm.rs +0 -316
- package/temp/rtk/src/log_cmd.rs +0 -248
- package/temp/rtk/src/ls.rs +0 -324
- package/temp/rtk/src/main.rs +0 -2482
- package/temp/rtk/src/mypy_cmd.rs +0 -389
- package/temp/rtk/src/next_cmd.rs +0 -241
- package/temp/rtk/src/npm_cmd.rs +0 -236
- package/temp/rtk/src/parser/README.md +0 -267
- package/temp/rtk/src/parser/error.rs +0 -46
- package/temp/rtk/src/parser/formatter.rs +0 -336
- package/temp/rtk/src/parser/mod.rs +0 -311
- package/temp/rtk/src/parser/types.rs +0 -119
- package/temp/rtk/src/pip_cmd.rs +0 -302
- package/temp/rtk/src/playwright_cmd.rs +0 -479
- package/temp/rtk/src/pnpm_cmd.rs +0 -573
- package/temp/rtk/src/prettier_cmd.rs +0 -221
- package/temp/rtk/src/prisma_cmd.rs +0 -482
- package/temp/rtk/src/psql_cmd.rs +0 -382
- package/temp/rtk/src/pytest_cmd.rs +0 -384
- package/temp/rtk/src/read.rs +0 -217
- package/temp/rtk/src/rewrite_cmd.rs +0 -50
- package/temp/rtk/src/ruff_cmd.rs +0 -402
- package/temp/rtk/src/runner.rs +0 -271
- package/temp/rtk/src/summary.rs +0 -297
- package/temp/rtk/src/tee.rs +0 -405
- package/temp/rtk/src/telemetry.rs +0 -248
- package/temp/rtk/src/toml_filter.rs +0 -1655
- package/temp/rtk/src/tracking.rs +0 -1416
- package/temp/rtk/src/tree.rs +0 -209
- package/temp/rtk/src/tsc_cmd.rs +0 -259
- package/temp/rtk/src/utils.rs +0 -432
- package/temp/rtk/src/verify_cmd.rs +0 -47
- package/temp/rtk/src/vitest_cmd.rs +0 -385
- package/temp/rtk/src/wc_cmd.rs +0 -401
- package/temp/rtk/src/wget_cmd.rs +0 -260
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +0 -11
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +0 -31
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +0 -1
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +0 -12
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +0 -18
package/temp/rtk/src/env_cmd.rs
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
use crate::tracking;
|
|
2
|
-
use anyhow::Result;
|
|
3
|
-
use std::collections::HashSet;
|
|
4
|
-
use std::env;
|
|
5
|
-
|
|
6
|
-
/// Show filtered environment variables (hide sensitive data)
|
|
7
|
-
pub fn run(filter: Option<&str>, show_all: bool, verbose: u8) -> Result<()> {
|
|
8
|
-
let timer = tracking::TimedExecution::start();
|
|
9
|
-
|
|
10
|
-
if verbose > 0 {
|
|
11
|
-
eprintln!("Environment variables:");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let sensitive_patterns = get_sensitive_patterns();
|
|
15
|
-
let mut vars: Vec<(String, String)> = env::vars().collect();
|
|
16
|
-
vars.sort_by(|a, b| a.0.cmp(&b.0));
|
|
17
|
-
|
|
18
|
-
// Interesting categories
|
|
19
|
-
let mut path_vars = Vec::new();
|
|
20
|
-
let mut lang_vars = Vec::new();
|
|
21
|
-
let mut cloud_vars = Vec::new();
|
|
22
|
-
let mut tool_vars = Vec::new();
|
|
23
|
-
let mut other_vars = Vec::new();
|
|
24
|
-
|
|
25
|
-
for (key, value) in &vars {
|
|
26
|
-
// Apply filter if provided
|
|
27
|
-
if let Some(f) = filter {
|
|
28
|
-
if !key.to_lowercase().contains(&f.to_lowercase()) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Check if sensitive
|
|
34
|
-
let is_sensitive = sensitive_patterns
|
|
35
|
-
.iter()
|
|
36
|
-
.any(|p| key.to_lowercase().contains(p));
|
|
37
|
-
|
|
38
|
-
let display_value = if is_sensitive && !show_all {
|
|
39
|
-
mask_value(value)
|
|
40
|
-
} else if value.len() > 100 {
|
|
41
|
-
let preview: String = value.chars().take(50).collect();
|
|
42
|
-
format!("{}... ({} chars)", preview, value.chars().count())
|
|
43
|
-
} else {
|
|
44
|
-
value.clone()
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
let entry = (key.clone(), display_value);
|
|
48
|
-
|
|
49
|
-
// Categorize
|
|
50
|
-
if key.contains("PATH") {
|
|
51
|
-
path_vars.push(entry);
|
|
52
|
-
} else if is_lang_var(key) {
|
|
53
|
-
lang_vars.push(entry);
|
|
54
|
-
} else if is_cloud_var(key) {
|
|
55
|
-
cloud_vars.push(entry);
|
|
56
|
-
} else if is_tool_var(key) {
|
|
57
|
-
tool_vars.push(entry);
|
|
58
|
-
} else if filter.is_some() || is_interesting_var(key) {
|
|
59
|
-
other_vars.push(entry);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Print categorized
|
|
64
|
-
if !path_vars.is_empty() {
|
|
65
|
-
println!("📂 PATH Variables:");
|
|
66
|
-
for (k, v) in &path_vars {
|
|
67
|
-
if k == "PATH" {
|
|
68
|
-
// Split PATH for readability
|
|
69
|
-
let paths: Vec<&str> = v.split(':').collect();
|
|
70
|
-
println!(" PATH ({} entries):", paths.len());
|
|
71
|
-
for p in paths.iter().take(5) {
|
|
72
|
-
println!(" {}", p);
|
|
73
|
-
}
|
|
74
|
-
if paths.len() > 5 {
|
|
75
|
-
println!(" ... +{} more", paths.len() - 5);
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
println!(" {}={}", k, v);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if !lang_vars.is_empty() {
|
|
84
|
-
println!("\n🔧 Language/Runtime:");
|
|
85
|
-
for (k, v) in &lang_vars {
|
|
86
|
-
println!(" {}={}", k, v);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if !cloud_vars.is_empty() {
|
|
91
|
-
println!("\n☁️ Cloud/Services:");
|
|
92
|
-
for (k, v) in &cloud_vars {
|
|
93
|
-
println!(" {}={}", k, v);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if !tool_vars.is_empty() {
|
|
98
|
-
println!("\n🛠️ Tools:");
|
|
99
|
-
for (k, v) in &tool_vars {
|
|
100
|
-
println!(" {}={}", k, v);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if !other_vars.is_empty() {
|
|
105
|
-
println!("\n📋 Other:");
|
|
106
|
-
for (k, v) in other_vars.iter().take(20) {
|
|
107
|
-
println!(" {}={}", k, v);
|
|
108
|
-
}
|
|
109
|
-
if other_vars.len() > 20 {
|
|
110
|
-
println!(" ... +{} more", other_vars.len() - 20);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let total = vars.len();
|
|
115
|
-
let shown = path_vars.len()
|
|
116
|
-
+ lang_vars.len()
|
|
117
|
-
+ cloud_vars.len()
|
|
118
|
-
+ tool_vars.len()
|
|
119
|
-
+ other_vars.len().min(20);
|
|
120
|
-
if filter.is_none() {
|
|
121
|
-
println!("\n📊 Total: {} vars (showing {} relevant)", total, shown);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let raw: String = vars.iter().map(|(k, v)| format!("{}={}\n", k, v)).collect();
|
|
125
|
-
let rtk = format!("{} vars -> {} shown", total, shown);
|
|
126
|
-
timer.track("env", "rtk env", &raw, &rtk);
|
|
127
|
-
Ok(())
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
fn get_sensitive_patterns() -> HashSet<&'static str> {
|
|
131
|
-
let mut set = HashSet::new();
|
|
132
|
-
set.insert("key");
|
|
133
|
-
set.insert("secret");
|
|
134
|
-
set.insert("password");
|
|
135
|
-
set.insert("token");
|
|
136
|
-
set.insert("credential");
|
|
137
|
-
set.insert("auth");
|
|
138
|
-
set.insert("private");
|
|
139
|
-
set.insert("api_key");
|
|
140
|
-
set.insert("apikey");
|
|
141
|
-
set.insert("access_key");
|
|
142
|
-
set.insert("jwt");
|
|
143
|
-
set
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
fn mask_value(value: &str) -> String {
|
|
147
|
-
let chars: Vec<char> = value.chars().collect();
|
|
148
|
-
if chars.len() <= 4 {
|
|
149
|
-
"****".to_string()
|
|
150
|
-
} else {
|
|
151
|
-
let prefix: String = chars[..2].iter().collect();
|
|
152
|
-
let suffix: String = chars[chars.len() - 2..].iter().collect();
|
|
153
|
-
format!("{}****{}", prefix, suffix)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
fn is_lang_var(key: &str) -> bool {
|
|
158
|
-
let patterns = [
|
|
159
|
-
"RUST", "CARGO", "PYTHON", "PIP", "NODE", "NPM", "YARN", "DENO", "BUN", "JAVA", "MAVEN",
|
|
160
|
-
"GRADLE", "GO", "GOPATH", "GOROOT", "RUBY", "GEM", "PERL", "PHP", "DOTNET", "NUGET",
|
|
161
|
-
];
|
|
162
|
-
patterns.iter().any(|p| key.to_uppercase().contains(p))
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
fn is_cloud_var(key: &str) -> bool {
|
|
166
|
-
let patterns = [
|
|
167
|
-
"AWS",
|
|
168
|
-
"AZURE",
|
|
169
|
-
"GCP",
|
|
170
|
-
"GOOGLE_CLOUD",
|
|
171
|
-
"DOCKER",
|
|
172
|
-
"KUBERNETES",
|
|
173
|
-
"K8S",
|
|
174
|
-
"HELM",
|
|
175
|
-
"TERRAFORM",
|
|
176
|
-
"VAULT",
|
|
177
|
-
"CONSUL",
|
|
178
|
-
"NOMAD",
|
|
179
|
-
];
|
|
180
|
-
patterns.iter().any(|p| key.to_uppercase().contains(p))
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
fn is_tool_var(key: &str) -> bool {
|
|
184
|
-
let patterns = [
|
|
185
|
-
"EDITOR",
|
|
186
|
-
"VISUAL",
|
|
187
|
-
"SHELL",
|
|
188
|
-
"TERM",
|
|
189
|
-
"GIT",
|
|
190
|
-
"SSH",
|
|
191
|
-
"GPG",
|
|
192
|
-
"BREW",
|
|
193
|
-
"HOMEBREW",
|
|
194
|
-
"XDG",
|
|
195
|
-
"CLAUDE",
|
|
196
|
-
"ANTHROPIC",
|
|
197
|
-
];
|
|
198
|
-
patterns.iter().any(|p| key.to_uppercase().contains(p))
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
fn is_interesting_var(key: &str) -> bool {
|
|
202
|
-
let patterns = ["HOME", "USER", "LANG", "LC_", "TZ", "PWD", "OLDPWD"];
|
|
203
|
-
patterns.iter().any(|p| key.to_uppercase().starts_with(p))
|
|
204
|
-
}
|
package/temp/rtk/src/filter.rs
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
use lazy_static::lazy_static;
|
|
2
|
-
use regex::Regex;
|
|
3
|
-
use std::str::FromStr;
|
|
4
|
-
|
|
5
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
6
|
-
pub enum FilterLevel {
|
|
7
|
-
None,
|
|
8
|
-
Minimal,
|
|
9
|
-
Aggressive,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
impl FromStr for FilterLevel {
|
|
13
|
-
type Err = String;
|
|
14
|
-
|
|
15
|
-
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
16
|
-
match s.to_lowercase().as_str() {
|
|
17
|
-
"none" => Ok(FilterLevel::None),
|
|
18
|
-
"minimal" => Ok(FilterLevel::Minimal),
|
|
19
|
-
"aggressive" => Ok(FilterLevel::Aggressive),
|
|
20
|
-
_ => Err(format!("Unknown filter level: {}", s)),
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
impl std::fmt::Display for FilterLevel {
|
|
26
|
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
27
|
-
match self {
|
|
28
|
-
FilterLevel::None => write!(f, "none"),
|
|
29
|
-
FilterLevel::Minimal => write!(f, "minimal"),
|
|
30
|
-
FilterLevel::Aggressive => write!(f, "aggressive"),
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pub trait FilterStrategy {
|
|
36
|
-
fn filter(&self, content: &str, lang: &Language) -> String;
|
|
37
|
-
#[allow(dead_code)]
|
|
38
|
-
fn name(&self) -> &'static str;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
42
|
-
pub enum Language {
|
|
43
|
-
Rust,
|
|
44
|
-
Python,
|
|
45
|
-
JavaScript,
|
|
46
|
-
TypeScript,
|
|
47
|
-
Go,
|
|
48
|
-
C,
|
|
49
|
-
Cpp,
|
|
50
|
-
Java,
|
|
51
|
-
Ruby,
|
|
52
|
-
Shell,
|
|
53
|
-
Data,
|
|
54
|
-
Unknown,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
impl Language {
|
|
58
|
-
pub fn from_extension(ext: &str) -> Self {
|
|
59
|
-
match ext.to_lowercase().as_str() {
|
|
60
|
-
"rs" => Language::Rust,
|
|
61
|
-
"py" | "pyw" => Language::Python,
|
|
62
|
-
"js" | "mjs" | "cjs" => Language::JavaScript,
|
|
63
|
-
"ts" | "tsx" => Language::TypeScript,
|
|
64
|
-
"go" => Language::Go,
|
|
65
|
-
"c" | "h" => Language::C,
|
|
66
|
-
"cpp" | "cc" | "cxx" | "hpp" | "hh" => Language::Cpp,
|
|
67
|
-
"java" => Language::Java,
|
|
68
|
-
"rb" => Language::Ruby,
|
|
69
|
-
"sh" | "bash" | "zsh" => Language::Shell,
|
|
70
|
-
"json" | "jsonc" | "json5" | "yaml" | "yml" | "toml" | "xml" | "html" | "htm"
|
|
71
|
-
| "css" | "scss" | "svg" | "md" | "markdown" | "txt" | "csv" | "tsv" | "env"
|
|
72
|
-
| "ini" | "cfg" | "conf" | "lock" => Language::Data,
|
|
73
|
-
_ => Language::Unknown,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
pub fn comment_patterns(&self) -> CommentPatterns {
|
|
78
|
-
match self {
|
|
79
|
-
Language::Rust => CommentPatterns {
|
|
80
|
-
line: Some("//"),
|
|
81
|
-
block_start: Some("/*"),
|
|
82
|
-
block_end: Some("*/"),
|
|
83
|
-
doc_line: Some("///"),
|
|
84
|
-
doc_block_start: Some("/**"),
|
|
85
|
-
},
|
|
86
|
-
Language::Python => CommentPatterns {
|
|
87
|
-
line: Some("#"),
|
|
88
|
-
block_start: Some("\"\"\""),
|
|
89
|
-
block_end: Some("\"\"\""),
|
|
90
|
-
doc_line: None,
|
|
91
|
-
doc_block_start: Some("\"\"\""),
|
|
92
|
-
},
|
|
93
|
-
Language::JavaScript
|
|
94
|
-
| Language::TypeScript
|
|
95
|
-
| Language::Go
|
|
96
|
-
| Language::C
|
|
97
|
-
| Language::Cpp
|
|
98
|
-
| Language::Java => CommentPatterns {
|
|
99
|
-
line: Some("//"),
|
|
100
|
-
block_start: Some("/*"),
|
|
101
|
-
block_end: Some("*/"),
|
|
102
|
-
doc_line: None,
|
|
103
|
-
doc_block_start: Some("/**"),
|
|
104
|
-
},
|
|
105
|
-
Language::Ruby => CommentPatterns {
|
|
106
|
-
line: Some("#"),
|
|
107
|
-
block_start: Some("=begin"),
|
|
108
|
-
block_end: Some("=end"),
|
|
109
|
-
doc_line: None,
|
|
110
|
-
doc_block_start: None,
|
|
111
|
-
},
|
|
112
|
-
Language::Shell => CommentPatterns {
|
|
113
|
-
line: Some("#"),
|
|
114
|
-
block_start: None,
|
|
115
|
-
block_end: None,
|
|
116
|
-
doc_line: None,
|
|
117
|
-
doc_block_start: None,
|
|
118
|
-
},
|
|
119
|
-
Language::Data => CommentPatterns {
|
|
120
|
-
line: None,
|
|
121
|
-
block_start: None,
|
|
122
|
-
block_end: None,
|
|
123
|
-
doc_line: None,
|
|
124
|
-
doc_block_start: None,
|
|
125
|
-
},
|
|
126
|
-
Language::Unknown => CommentPatterns {
|
|
127
|
-
line: Some("//"),
|
|
128
|
-
block_start: Some("/*"),
|
|
129
|
-
block_end: Some("*/"),
|
|
130
|
-
doc_line: None,
|
|
131
|
-
doc_block_start: None,
|
|
132
|
-
},
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
#[derive(Debug, Clone)]
|
|
138
|
-
pub struct CommentPatterns {
|
|
139
|
-
pub line: Option<&'static str>,
|
|
140
|
-
pub block_start: Option<&'static str>,
|
|
141
|
-
pub block_end: Option<&'static str>,
|
|
142
|
-
pub doc_line: Option<&'static str>,
|
|
143
|
-
pub doc_block_start: Option<&'static str>,
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
pub struct NoFilter;
|
|
147
|
-
|
|
148
|
-
impl FilterStrategy for NoFilter {
|
|
149
|
-
fn filter(&self, content: &str, _lang: &Language) -> String {
|
|
150
|
-
content.to_string()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
fn name(&self) -> &'static str {
|
|
154
|
-
"none"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
pub struct MinimalFilter;
|
|
159
|
-
|
|
160
|
-
lazy_static! {
|
|
161
|
-
static ref MULTIPLE_BLANK_LINES: Regex = Regex::new(r"\n{3,}").unwrap();
|
|
162
|
-
static ref TRAILING_WHITESPACE: Regex = Regex::new(r"[ \t]+$").unwrap();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
impl FilterStrategy for MinimalFilter {
|
|
166
|
-
fn filter(&self, content: &str, lang: &Language) -> String {
|
|
167
|
-
let patterns = lang.comment_patterns();
|
|
168
|
-
let mut result = String::with_capacity(content.len());
|
|
169
|
-
let mut in_block_comment = false;
|
|
170
|
-
let mut in_docstring = false;
|
|
171
|
-
|
|
172
|
-
for line in content.lines() {
|
|
173
|
-
let trimmed = line.trim();
|
|
174
|
-
|
|
175
|
-
// Handle block comments
|
|
176
|
-
if let (Some(start), Some(end)) = (patterns.block_start, patterns.block_end) {
|
|
177
|
-
if !in_docstring
|
|
178
|
-
&& trimmed.contains(start)
|
|
179
|
-
&& !trimmed.starts_with(patterns.doc_block_start.unwrap_or("###"))
|
|
180
|
-
{
|
|
181
|
-
in_block_comment = true;
|
|
182
|
-
}
|
|
183
|
-
if in_block_comment {
|
|
184
|
-
if trimmed.contains(end) {
|
|
185
|
-
in_block_comment = false;
|
|
186
|
-
}
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Handle Python docstrings (keep them in minimal mode)
|
|
192
|
-
if *lang == Language::Python && trimmed.starts_with("\"\"\"") {
|
|
193
|
-
in_docstring = !in_docstring;
|
|
194
|
-
result.push_str(line);
|
|
195
|
-
result.push('\n');
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if in_docstring {
|
|
200
|
-
result.push_str(line);
|
|
201
|
-
result.push('\n');
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Skip single-line comments (but keep doc comments)
|
|
206
|
-
if let Some(line_comment) = patterns.line {
|
|
207
|
-
if trimmed.starts_with(line_comment) {
|
|
208
|
-
// Keep doc comments
|
|
209
|
-
if let Some(doc) = patterns.doc_line {
|
|
210
|
-
if trimmed.starts_with(doc) {
|
|
211
|
-
result.push_str(line);
|
|
212
|
-
result.push('\n');
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Skip empty lines at this point, we'll normalize later
|
|
220
|
-
if trimmed.is_empty() {
|
|
221
|
-
result.push('\n');
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
result.push_str(line);
|
|
226
|
-
result.push('\n');
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Normalize multiple blank lines to max 2
|
|
230
|
-
let result = MULTIPLE_BLANK_LINES.replace_all(&result, "\n\n");
|
|
231
|
-
result.trim().to_string()
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
fn name(&self) -> &'static str {
|
|
235
|
-
"minimal"
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
pub struct AggressiveFilter;
|
|
240
|
-
|
|
241
|
-
lazy_static! {
|
|
242
|
-
static ref IMPORT_PATTERN: Regex =
|
|
243
|
-
Regex::new(r"^(use |import |from |require\(|#include)").unwrap();
|
|
244
|
-
static ref FUNC_SIGNATURE: Regex = Regex::new(
|
|
245
|
-
r"^(pub\s+)?(async\s+)?(fn|def|function|func|class|struct|enum|trait|interface|type)\s+\w+"
|
|
246
|
-
)
|
|
247
|
-
.unwrap();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
impl FilterStrategy for AggressiveFilter {
|
|
251
|
-
fn filter(&self, content: &str, lang: &Language) -> String {
|
|
252
|
-
let minimal = MinimalFilter.filter(content, lang);
|
|
253
|
-
let mut result = String::with_capacity(minimal.len() / 2);
|
|
254
|
-
let mut brace_depth = 0;
|
|
255
|
-
let mut in_impl_body = false;
|
|
256
|
-
|
|
257
|
-
for line in minimal.lines() {
|
|
258
|
-
let trimmed = line.trim();
|
|
259
|
-
|
|
260
|
-
// Always keep imports
|
|
261
|
-
if IMPORT_PATTERN.is_match(trimmed) {
|
|
262
|
-
result.push_str(line);
|
|
263
|
-
result.push('\n');
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Always keep function/struct/class signatures
|
|
268
|
-
if FUNC_SIGNATURE.is_match(trimmed) {
|
|
269
|
-
result.push_str(line);
|
|
270
|
-
result.push('\n');
|
|
271
|
-
in_impl_body = true;
|
|
272
|
-
brace_depth = 0;
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Track brace depth for implementation bodies
|
|
277
|
-
let open_braces = trimmed.matches('{').count();
|
|
278
|
-
let close_braces = trimmed.matches('}').count();
|
|
279
|
-
|
|
280
|
-
if in_impl_body {
|
|
281
|
-
brace_depth += open_braces as i32;
|
|
282
|
-
brace_depth -= close_braces as i32;
|
|
283
|
-
|
|
284
|
-
// Only keep the opening and closing braces
|
|
285
|
-
if brace_depth <= 1 && (trimmed == "{" || trimmed == "}" || trimmed.ends_with('{'))
|
|
286
|
-
{
|
|
287
|
-
result.push_str(line);
|
|
288
|
-
result.push('\n');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if brace_depth <= 0 {
|
|
292
|
-
in_impl_body = false;
|
|
293
|
-
if !trimmed.is_empty() && trimmed != "}" {
|
|
294
|
-
result.push_str(" // ... implementation\n");
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Keep type definitions, constants, etc.
|
|
301
|
-
if trimmed.starts_with("const ")
|
|
302
|
-
|| trimmed.starts_with("static ")
|
|
303
|
-
|| trimmed.starts_with("let ")
|
|
304
|
-
|| trimmed.starts_with("pub const ")
|
|
305
|
-
|| trimmed.starts_with("pub static ")
|
|
306
|
-
{
|
|
307
|
-
result.push_str(line);
|
|
308
|
-
result.push('\n');
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
result.trim().to_string()
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
fn name(&self) -> &'static str {
|
|
316
|
-
"aggressive"
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
pub fn get_filter(level: FilterLevel) -> Box<dyn FilterStrategy> {
|
|
321
|
-
match level {
|
|
322
|
-
FilterLevel::None => Box::new(NoFilter),
|
|
323
|
-
FilterLevel::Minimal => Box::new(MinimalFilter),
|
|
324
|
-
FilterLevel::Aggressive => Box::new(AggressiveFilter),
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
pub fn smart_truncate(content: &str, max_lines: usize, _lang: &Language) -> String {
|
|
329
|
-
let lines: Vec<&str> = content.lines().collect();
|
|
330
|
-
if lines.len() <= max_lines {
|
|
331
|
-
return content.to_string();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
let mut result = Vec::with_capacity(max_lines);
|
|
335
|
-
let mut kept_lines = 0;
|
|
336
|
-
let mut skipped_section = false;
|
|
337
|
-
|
|
338
|
-
for line in &lines {
|
|
339
|
-
let trimmed = line.trim();
|
|
340
|
-
|
|
341
|
-
// Always keep signatures and important structural elements
|
|
342
|
-
let is_important = FUNC_SIGNATURE.is_match(trimmed)
|
|
343
|
-
|| IMPORT_PATTERN.is_match(trimmed)
|
|
344
|
-
|| trimmed.starts_with("pub ")
|
|
345
|
-
|| trimmed.starts_with("export ")
|
|
346
|
-
|| trimmed == "}"
|
|
347
|
-
|| trimmed == "{";
|
|
348
|
-
|
|
349
|
-
if is_important || kept_lines < max_lines / 2 {
|
|
350
|
-
if skipped_section {
|
|
351
|
-
result.push(format!(
|
|
352
|
-
" // ... {} lines omitted",
|
|
353
|
-
lines.len() - kept_lines
|
|
354
|
-
));
|
|
355
|
-
skipped_section = false;
|
|
356
|
-
}
|
|
357
|
-
result.push((*line).to_string());
|
|
358
|
-
kept_lines += 1;
|
|
359
|
-
} else {
|
|
360
|
-
skipped_section = true;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if kept_lines >= max_lines - 1 {
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if skipped_section || kept_lines < lines.len() {
|
|
369
|
-
result.push(format!(
|
|
370
|
-
"// ... {} more lines (total: {})",
|
|
371
|
-
lines.len() - kept_lines,
|
|
372
|
-
lines.len()
|
|
373
|
-
));
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
result.join("\n")
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
#[cfg(test)]
|
|
380
|
-
mod tests {
|
|
381
|
-
use super::*;
|
|
382
|
-
|
|
383
|
-
#[test]
|
|
384
|
-
fn test_filter_level_parsing() {
|
|
385
|
-
assert_eq!(FilterLevel::from_str("none").unwrap(), FilterLevel::None);
|
|
386
|
-
assert_eq!(
|
|
387
|
-
FilterLevel::from_str("minimal").unwrap(),
|
|
388
|
-
FilterLevel::Minimal
|
|
389
|
-
);
|
|
390
|
-
assert_eq!(
|
|
391
|
-
FilterLevel::from_str("aggressive").unwrap(),
|
|
392
|
-
FilterLevel::Aggressive
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
#[test]
|
|
397
|
-
fn test_language_detection() {
|
|
398
|
-
assert_eq!(Language::from_extension("rs"), Language::Rust);
|
|
399
|
-
assert_eq!(Language::from_extension("py"), Language::Python);
|
|
400
|
-
assert_eq!(Language::from_extension("js"), Language::JavaScript);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
#[test]
|
|
404
|
-
fn test_language_detection_data_formats() {
|
|
405
|
-
assert_eq!(Language::from_extension("json"), Language::Data);
|
|
406
|
-
assert_eq!(Language::from_extension("yaml"), Language::Data);
|
|
407
|
-
assert_eq!(Language::from_extension("yml"), Language::Data);
|
|
408
|
-
assert_eq!(Language::from_extension("toml"), Language::Data);
|
|
409
|
-
assert_eq!(Language::from_extension("xml"), Language::Data);
|
|
410
|
-
assert_eq!(Language::from_extension("md"), Language::Data);
|
|
411
|
-
assert_eq!(Language::from_extension("csv"), Language::Data);
|
|
412
|
-
assert_eq!(Language::from_extension("lock"), Language::Data);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
#[test]
|
|
416
|
-
fn test_data_files_no_comment_stripping() {
|
|
417
|
-
// Regression test for #464: package.json with `/*` in strings
|
|
418
|
-
let json = r#"{
|
|
419
|
-
"workspaces": {
|
|
420
|
-
"packages": [
|
|
421
|
-
"packages/*"
|
|
422
|
-
]
|
|
423
|
-
},
|
|
424
|
-
"scripts": {
|
|
425
|
-
"build": "bun run --workspaces build"
|
|
426
|
-
},
|
|
427
|
-
"lint-staged": {
|
|
428
|
-
"**/package.json": [
|
|
429
|
-
"sort-package-json"
|
|
430
|
-
]
|
|
431
|
-
}
|
|
432
|
-
}"#;
|
|
433
|
-
let filter = MinimalFilter;
|
|
434
|
-
let result = filter.filter(json, &Language::Data);
|
|
435
|
-
assert!(
|
|
436
|
-
result.contains("scripts"),
|
|
437
|
-
"scripts section must be preserved"
|
|
438
|
-
);
|
|
439
|
-
assert!(
|
|
440
|
-
result.contains("packages/*"),
|
|
441
|
-
"glob pattern must be preserved"
|
|
442
|
-
);
|
|
443
|
-
assert!(
|
|
444
|
-
result.contains("**/package.json"),
|
|
445
|
-
"glob pattern must be preserved"
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
#[test]
|
|
450
|
-
fn test_minimal_filter_removes_comments() {
|
|
451
|
-
let code = r#"
|
|
452
|
-
// This is a comment
|
|
453
|
-
fn main() {
|
|
454
|
-
println!("Hello");
|
|
455
|
-
}
|
|
456
|
-
"#;
|
|
457
|
-
let filter = MinimalFilter;
|
|
458
|
-
let result = filter.filter(code, &Language::Rust);
|
|
459
|
-
assert!(!result.contains("// This is a comment"));
|
|
460
|
-
assert!(result.contains("fn main()"));
|
|
461
|
-
}
|
|
462
|
-
}
|