@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/diff_cmd.rs
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
use crate::tracking;
|
|
2
|
-
use crate::utils::truncate;
|
|
3
|
-
use anyhow::Result;
|
|
4
|
-
use std::fs;
|
|
5
|
-
use std::path::Path;
|
|
6
|
-
|
|
7
|
-
/// Ultra-condensed diff - only changed lines, no context
|
|
8
|
-
pub fn run(file1: &Path, file2: &Path, verbose: u8) -> Result<()> {
|
|
9
|
-
let timer = tracking::TimedExecution::start();
|
|
10
|
-
|
|
11
|
-
if verbose > 0 {
|
|
12
|
-
eprintln!("Comparing: {} vs {}", file1.display(), file2.display());
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let content1 = fs::read_to_string(file1)?;
|
|
16
|
-
let content2 = fs::read_to_string(file2)?;
|
|
17
|
-
let raw = format!("{}\n---\n{}", content1, content2);
|
|
18
|
-
|
|
19
|
-
let lines1: Vec<&str> = content1.lines().collect();
|
|
20
|
-
let lines2: Vec<&str> = content2.lines().collect();
|
|
21
|
-
let diff = compute_diff(&lines1, &lines2);
|
|
22
|
-
let mut rtk = String::new();
|
|
23
|
-
|
|
24
|
-
if diff.added == 0 && diff.removed == 0 {
|
|
25
|
-
rtk.push_str("✅ Files are identical");
|
|
26
|
-
println!("{}", rtk);
|
|
27
|
-
timer.track(
|
|
28
|
-
&format!("diff {} {}", file1.display(), file2.display()),
|
|
29
|
-
"rtk diff",
|
|
30
|
-
&raw,
|
|
31
|
-
&rtk,
|
|
32
|
-
);
|
|
33
|
-
return Ok(());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
rtk.push_str(&format!("📊 {} → {}\n", file1.display(), file2.display()));
|
|
37
|
-
rtk.push_str(&format!(
|
|
38
|
-
" +{} added, -{} removed, ~{} modified\n\n",
|
|
39
|
-
diff.added, diff.removed, diff.modified
|
|
40
|
-
));
|
|
41
|
-
|
|
42
|
-
for change in diff.changes.iter().take(50) {
|
|
43
|
-
match change {
|
|
44
|
-
DiffChange::Added(ln, c) => rtk.push_str(&format!("+{:4} {}\n", ln, truncate(c, 80))),
|
|
45
|
-
DiffChange::Removed(ln, c) => rtk.push_str(&format!("-{:4} {}\n", ln, truncate(c, 80))),
|
|
46
|
-
DiffChange::Modified(ln, old, new) => rtk.push_str(&format!(
|
|
47
|
-
"~{:4} {} → {}\n",
|
|
48
|
-
ln,
|
|
49
|
-
truncate(old, 70),
|
|
50
|
-
truncate(new, 70)
|
|
51
|
-
)),
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if diff.changes.len() > 50 {
|
|
55
|
-
rtk.push_str(&format!("... +{} more changes", diff.changes.len() - 50));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
print!("{}", rtk);
|
|
59
|
-
timer.track(
|
|
60
|
-
&format!("diff {} {}", file1.display(), file2.display()),
|
|
61
|
-
"rtk diff",
|
|
62
|
-
&raw,
|
|
63
|
-
&rtk,
|
|
64
|
-
);
|
|
65
|
-
Ok(())
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/// Run diff from stdin (piped command output)
|
|
69
|
-
pub fn run_stdin(_verbose: u8) -> Result<()> {
|
|
70
|
-
use std::io::{self, Read};
|
|
71
|
-
let timer = tracking::TimedExecution::start();
|
|
72
|
-
|
|
73
|
-
let mut input = String::new();
|
|
74
|
-
io::stdin().read_to_string(&mut input)?;
|
|
75
|
-
|
|
76
|
-
// Parse unified diff format
|
|
77
|
-
let condensed = condense_unified_diff(&input);
|
|
78
|
-
println!("{}", condensed);
|
|
79
|
-
|
|
80
|
-
timer.track("diff (stdin)", "rtk diff (stdin)", &input, &condensed);
|
|
81
|
-
|
|
82
|
-
Ok(())
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
#[derive(Debug)]
|
|
86
|
-
enum DiffChange {
|
|
87
|
-
Added(usize, String),
|
|
88
|
-
Removed(usize, String),
|
|
89
|
-
Modified(usize, String, String),
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
struct DiffResult {
|
|
93
|
-
added: usize,
|
|
94
|
-
removed: usize,
|
|
95
|
-
modified: usize,
|
|
96
|
-
changes: Vec<DiffChange>,
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
fn compute_diff(lines1: &[&str], lines2: &[&str]) -> DiffResult {
|
|
100
|
-
let mut changes = Vec::new();
|
|
101
|
-
let mut added = 0;
|
|
102
|
-
let mut removed = 0;
|
|
103
|
-
let mut modified = 0;
|
|
104
|
-
|
|
105
|
-
// Simple line-by-line comparison (not optimal but fast)
|
|
106
|
-
let max_len = lines1.len().max(lines2.len());
|
|
107
|
-
|
|
108
|
-
for i in 0..max_len {
|
|
109
|
-
let l1 = lines1.get(i).copied();
|
|
110
|
-
let l2 = lines2.get(i).copied();
|
|
111
|
-
|
|
112
|
-
match (l1, l2) {
|
|
113
|
-
(Some(a), Some(b)) if a != b => {
|
|
114
|
-
// Check if it's similar (modification) or completely different
|
|
115
|
-
if similarity(a, b) > 0.5 {
|
|
116
|
-
changes.push(DiffChange::Modified(i + 1, a.to_string(), b.to_string()));
|
|
117
|
-
modified += 1;
|
|
118
|
-
} else {
|
|
119
|
-
changes.push(DiffChange::Removed(i + 1, a.to_string()));
|
|
120
|
-
changes.push(DiffChange::Added(i + 1, b.to_string()));
|
|
121
|
-
removed += 1;
|
|
122
|
-
added += 1;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
(Some(a), None) => {
|
|
126
|
-
changes.push(DiffChange::Removed(i + 1, a.to_string()));
|
|
127
|
-
removed += 1;
|
|
128
|
-
}
|
|
129
|
-
(None, Some(b)) => {
|
|
130
|
-
changes.push(DiffChange::Added(i + 1, b.to_string()));
|
|
131
|
-
added += 1;
|
|
132
|
-
}
|
|
133
|
-
_ => {}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
DiffResult {
|
|
138
|
-
added,
|
|
139
|
-
removed,
|
|
140
|
-
modified,
|
|
141
|
-
changes,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
fn similarity(a: &str, b: &str) -> f64 {
|
|
146
|
-
let a_chars: std::collections::HashSet<char> = a.chars().collect();
|
|
147
|
-
let b_chars: std::collections::HashSet<char> = b.chars().collect();
|
|
148
|
-
|
|
149
|
-
let intersection = a_chars.intersection(&b_chars).count();
|
|
150
|
-
let union = a_chars.union(&b_chars).count();
|
|
151
|
-
|
|
152
|
-
if union == 0 {
|
|
153
|
-
1.0
|
|
154
|
-
} else {
|
|
155
|
-
intersection as f64 / union as f64
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
fn condense_unified_diff(diff: &str) -> String {
|
|
160
|
-
let mut result = Vec::new();
|
|
161
|
-
let mut current_file = String::new();
|
|
162
|
-
let mut added = 0;
|
|
163
|
-
let mut removed = 0;
|
|
164
|
-
let mut changes = Vec::new();
|
|
165
|
-
|
|
166
|
-
for line in diff.lines() {
|
|
167
|
-
if line.starts_with("diff --git") || line.starts_with("--- ") || line.starts_with("+++ ") {
|
|
168
|
-
// File header
|
|
169
|
-
if line.starts_with("+++ ") {
|
|
170
|
-
if !current_file.is_empty() && (added > 0 || removed > 0) {
|
|
171
|
-
result.push(format!("📄 {} (+{} -{})", current_file, added, removed));
|
|
172
|
-
for c in changes.iter().take(10) {
|
|
173
|
-
result.push(format!(" {}", c));
|
|
174
|
-
}
|
|
175
|
-
if changes.len() > 10 {
|
|
176
|
-
result.push(format!(" ... +{} more", changes.len() - 10));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
current_file = line
|
|
180
|
-
.trim_start_matches("+++ ")
|
|
181
|
-
.trim_start_matches("b/")
|
|
182
|
-
.to_string();
|
|
183
|
-
added = 0;
|
|
184
|
-
removed = 0;
|
|
185
|
-
changes.clear();
|
|
186
|
-
}
|
|
187
|
-
} else if line.starts_with('+') && !line.starts_with("+++") {
|
|
188
|
-
added += 1;
|
|
189
|
-
if changes.len() < 15 {
|
|
190
|
-
changes.push(truncate(line, 70));
|
|
191
|
-
}
|
|
192
|
-
} else if line.starts_with('-') && !line.starts_with("---") {
|
|
193
|
-
removed += 1;
|
|
194
|
-
if changes.len() < 15 {
|
|
195
|
-
changes.push(truncate(line, 70));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Last file
|
|
201
|
-
if !current_file.is_empty() && (added > 0 || removed > 0) {
|
|
202
|
-
result.push(format!("📄 {} (+{} -{})", current_file, added, removed));
|
|
203
|
-
for c in changes.iter().take(10) {
|
|
204
|
-
result.push(format!(" {}", c));
|
|
205
|
-
}
|
|
206
|
-
if changes.len() > 10 {
|
|
207
|
-
result.push(format!(" ... +{} more", changes.len() - 10));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
result.join("\n")
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
#[cfg(test)]
|
|
215
|
-
mod tests {
|
|
216
|
-
use super::*;
|
|
217
|
-
|
|
218
|
-
// --- similarity ---
|
|
219
|
-
|
|
220
|
-
#[test]
|
|
221
|
-
fn test_similarity_identical() {
|
|
222
|
-
assert_eq!(similarity("hello", "hello"), 1.0);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
#[test]
|
|
226
|
-
fn test_similarity_completely_different() {
|
|
227
|
-
assert_eq!(similarity("abc", "xyz"), 0.0);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
#[test]
|
|
231
|
-
fn test_similarity_empty_strings() {
|
|
232
|
-
// Both empty: union is 0, returns 1.0 by convention
|
|
233
|
-
assert_eq!(similarity("", ""), 1.0);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
#[test]
|
|
237
|
-
fn test_similarity_partial_overlap() {
|
|
238
|
-
let s = similarity("abcd", "abef");
|
|
239
|
-
// Shared: a, b. Union: a, b, c, d, e, f = 6. Jaccard = 2/6
|
|
240
|
-
assert!((s - 2.0 / 6.0).abs() < f64::EPSILON);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
#[test]
|
|
244
|
-
fn test_similarity_threshold_for_modified() {
|
|
245
|
-
// "let x = 1;" vs "let x = 2;" should be > 0.5 (treated as modification)
|
|
246
|
-
assert!(similarity("let x = 1;", "let x = 2;") > 0.5);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// --- truncate ---
|
|
250
|
-
|
|
251
|
-
#[test]
|
|
252
|
-
fn test_truncate_short_string() {
|
|
253
|
-
assert_eq!(truncate("hello", 10), "hello");
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
#[test]
|
|
257
|
-
fn test_truncate_exact_length() {
|
|
258
|
-
assert_eq!(truncate("hello", 5), "hello");
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
#[test]
|
|
262
|
-
fn test_truncate_long_string() {
|
|
263
|
-
assert_eq!(truncate("hello world!", 8), "hello...");
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// --- compute_diff ---
|
|
267
|
-
|
|
268
|
-
#[test]
|
|
269
|
-
fn test_compute_diff_identical() {
|
|
270
|
-
let a = vec!["line1", "line2", "line3"];
|
|
271
|
-
let b = vec!["line1", "line2", "line3"];
|
|
272
|
-
let result = compute_diff(&a, &b);
|
|
273
|
-
assert_eq!(result.added, 0);
|
|
274
|
-
assert_eq!(result.removed, 0);
|
|
275
|
-
assert_eq!(result.modified, 0);
|
|
276
|
-
assert!(result.changes.is_empty());
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
#[test]
|
|
280
|
-
fn test_compute_diff_added_lines() {
|
|
281
|
-
let a = vec!["line1"];
|
|
282
|
-
let b = vec!["line1", "line2", "line3"];
|
|
283
|
-
let result = compute_diff(&a, &b);
|
|
284
|
-
assert_eq!(result.added, 2);
|
|
285
|
-
assert_eq!(result.removed, 0);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
#[test]
|
|
289
|
-
fn test_compute_diff_removed_lines() {
|
|
290
|
-
let a = vec!["line1", "line2", "line3"];
|
|
291
|
-
let b = vec!["line1"];
|
|
292
|
-
let result = compute_diff(&a, &b);
|
|
293
|
-
assert_eq!(result.removed, 2);
|
|
294
|
-
assert_eq!(result.added, 0);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
#[test]
|
|
298
|
-
fn test_compute_diff_modified_line() {
|
|
299
|
-
// Similar lines (>0.5 similarity) are classified as modified
|
|
300
|
-
let a = vec!["let x = 1;"];
|
|
301
|
-
let b = vec!["let x = 2;"];
|
|
302
|
-
let result = compute_diff(&a, &b);
|
|
303
|
-
assert_eq!(result.modified, 1);
|
|
304
|
-
assert_eq!(result.added, 0);
|
|
305
|
-
assert_eq!(result.removed, 0);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
#[test]
|
|
309
|
-
fn test_compute_diff_completely_different_line() {
|
|
310
|
-
// Dissimilar lines (<= 0.5 similarity) are added+removed, not modified
|
|
311
|
-
let a = vec!["aaaa"];
|
|
312
|
-
let b = vec!["zzzz"];
|
|
313
|
-
let result = compute_diff(&a, &b);
|
|
314
|
-
assert_eq!(result.modified, 0);
|
|
315
|
-
assert_eq!(result.added, 1);
|
|
316
|
-
assert_eq!(result.removed, 1);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
#[test]
|
|
320
|
-
fn test_compute_diff_empty_inputs() {
|
|
321
|
-
let result = compute_diff(&[], &[]);
|
|
322
|
-
assert_eq!(result.added, 0);
|
|
323
|
-
assert_eq!(result.removed, 0);
|
|
324
|
-
assert!(result.changes.is_empty());
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// --- condense_unified_diff ---
|
|
328
|
-
|
|
329
|
-
#[test]
|
|
330
|
-
fn test_condense_unified_diff_single_file() {
|
|
331
|
-
let diff = r#"diff --git a/src/main.rs b/src/main.rs
|
|
332
|
-
--- a/src/main.rs
|
|
333
|
-
+++ b/src/main.rs
|
|
334
|
-
@@ -1,3 +1,4 @@
|
|
335
|
-
fn main() {
|
|
336
|
-
+ println!("hello");
|
|
337
|
-
println!("world");
|
|
338
|
-
}
|
|
339
|
-
"#;
|
|
340
|
-
let result = condense_unified_diff(diff);
|
|
341
|
-
assert!(result.contains("src/main.rs"));
|
|
342
|
-
assert!(result.contains("+1"));
|
|
343
|
-
assert!(result.contains("println"));
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
#[test]
|
|
347
|
-
fn test_condense_unified_diff_multiple_files() {
|
|
348
|
-
let diff = r#"diff --git a/a.rs b/a.rs
|
|
349
|
-
--- a/a.rs
|
|
350
|
-
+++ b/a.rs
|
|
351
|
-
+added line
|
|
352
|
-
diff --git a/b.rs b/b.rs
|
|
353
|
-
--- a/b.rs
|
|
354
|
-
+++ b/b.rs
|
|
355
|
-
-removed line
|
|
356
|
-
"#;
|
|
357
|
-
let result = condense_unified_diff(diff);
|
|
358
|
-
assert!(result.contains("a.rs"));
|
|
359
|
-
assert!(result.contains("b.rs"));
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
#[test]
|
|
363
|
-
fn test_condense_unified_diff_empty() {
|
|
364
|
-
let result = condense_unified_diff("");
|
|
365
|
-
assert!(result.is_empty());
|
|
366
|
-
}
|
|
367
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
pub mod provider;
|
|
2
|
-
pub mod registry;
|
|
3
|
-
mod report;
|
|
4
|
-
pub mod rules;
|
|
5
|
-
|
|
6
|
-
use anyhow::Result;
|
|
7
|
-
use std::collections::HashMap;
|
|
8
|
-
|
|
9
|
-
use provider::{ClaudeProvider, SessionProvider};
|
|
10
|
-
use registry::{
|
|
11
|
-
category_avg_tokens, classify_command, has_rtk_disabled_prefix, split_command_chain,
|
|
12
|
-
strip_disabled_prefix, Classification,
|
|
13
|
-
};
|
|
14
|
-
use report::{DiscoverReport, SupportedEntry, UnsupportedEntry};
|
|
15
|
-
|
|
16
|
-
/// Aggregation bucket for supported commands.
|
|
17
|
-
struct SupportedBucket {
|
|
18
|
-
rtk_equivalent: &'static str,
|
|
19
|
-
category: &'static str,
|
|
20
|
-
count: usize,
|
|
21
|
-
total_output_tokens: usize,
|
|
22
|
-
savings_pct: f64,
|
|
23
|
-
// For display: the most common raw command
|
|
24
|
-
command_counts: HashMap<String, usize>,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// Aggregation bucket for unsupported commands.
|
|
28
|
-
struct UnsupportedBucket {
|
|
29
|
-
count: usize,
|
|
30
|
-
example: String,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
pub fn run(
|
|
34
|
-
project: Option<&str>,
|
|
35
|
-
all: bool,
|
|
36
|
-
since_days: u64,
|
|
37
|
-
limit: usize,
|
|
38
|
-
format: &str,
|
|
39
|
-
verbose: u8,
|
|
40
|
-
) -> Result<()> {
|
|
41
|
-
let provider = ClaudeProvider;
|
|
42
|
-
|
|
43
|
-
// Determine project filter
|
|
44
|
-
let project_filter = if all {
|
|
45
|
-
None
|
|
46
|
-
} else if let Some(p) = project {
|
|
47
|
-
Some(p.to_string())
|
|
48
|
-
} else {
|
|
49
|
-
// Default: current working directory
|
|
50
|
-
let cwd = std::env::current_dir()?;
|
|
51
|
-
let cwd_str = cwd.to_string_lossy().to_string();
|
|
52
|
-
let encoded = ClaudeProvider::encode_project_path(&cwd_str);
|
|
53
|
-
Some(encoded)
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
let sessions = provider.discover_sessions(project_filter.as_deref(), Some(since_days))?;
|
|
57
|
-
|
|
58
|
-
if verbose > 0 {
|
|
59
|
-
eprintln!("Scanning {} session files...", sessions.len());
|
|
60
|
-
for s in &sessions {
|
|
61
|
-
eprintln!(" {}", s.display());
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let mut total_commands: usize = 0;
|
|
66
|
-
let mut already_rtk: usize = 0;
|
|
67
|
-
let mut parse_errors: usize = 0;
|
|
68
|
-
let mut rtk_disabled_count: usize = 0;
|
|
69
|
-
let mut rtk_disabled_cmds: HashMap<String, usize> = HashMap::new();
|
|
70
|
-
let mut supported_map: HashMap<&'static str, SupportedBucket> = HashMap::new();
|
|
71
|
-
let mut unsupported_map: HashMap<String, UnsupportedBucket> = HashMap::new();
|
|
72
|
-
|
|
73
|
-
for session_path in &sessions {
|
|
74
|
-
let extracted = match provider.extract_commands(session_path) {
|
|
75
|
-
Ok(cmds) => cmds,
|
|
76
|
-
Err(e) => {
|
|
77
|
-
if verbose > 0 {
|
|
78
|
-
eprintln!("Warning: skipping {}: {}", session_path.display(), e);
|
|
79
|
-
}
|
|
80
|
-
parse_errors += 1;
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
for ext_cmd in &extracted {
|
|
86
|
-
let parts = split_command_chain(&ext_cmd.command);
|
|
87
|
-
for part in parts {
|
|
88
|
-
total_commands += 1;
|
|
89
|
-
|
|
90
|
-
// Detect RTK_DISABLED= bypass before classification
|
|
91
|
-
if has_rtk_disabled_prefix(part) {
|
|
92
|
-
let actual_cmd = strip_disabled_prefix(part);
|
|
93
|
-
// Only count if the underlying command is one RTK supports
|
|
94
|
-
match classify_command(actual_cmd) {
|
|
95
|
-
Classification::Supported { .. } => {
|
|
96
|
-
rtk_disabled_count += 1;
|
|
97
|
-
let display = truncate_command(actual_cmd);
|
|
98
|
-
*rtk_disabled_cmds.entry(display).or_insert(0) += 1;
|
|
99
|
-
}
|
|
100
|
-
_ => {
|
|
101
|
-
// RTK_DISABLED on unsupported/ignored command — not interesting
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
match classify_command(part) {
|
|
108
|
-
Classification::Supported {
|
|
109
|
-
rtk_equivalent,
|
|
110
|
-
category,
|
|
111
|
-
estimated_savings_pct,
|
|
112
|
-
status,
|
|
113
|
-
} => {
|
|
114
|
-
let bucket = supported_map.entry(rtk_equivalent).or_insert_with(|| {
|
|
115
|
-
SupportedBucket {
|
|
116
|
-
rtk_equivalent,
|
|
117
|
-
category,
|
|
118
|
-
count: 0,
|
|
119
|
-
total_output_tokens: 0,
|
|
120
|
-
savings_pct: estimated_savings_pct,
|
|
121
|
-
command_counts: HashMap::new(),
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
bucket.count += 1;
|
|
126
|
-
|
|
127
|
-
// Estimate tokens for this command
|
|
128
|
-
let output_tokens = if let Some(len) = ext_cmd.output_len {
|
|
129
|
-
// Real: from tool_result content length
|
|
130
|
-
len / 4
|
|
131
|
-
} else {
|
|
132
|
-
// Fallback: category average
|
|
133
|
-
let subcmd = extract_subcmd(part);
|
|
134
|
-
category_avg_tokens(category, subcmd)
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
let savings =
|
|
138
|
-
(output_tokens as f64 * estimated_savings_pct / 100.0) as usize;
|
|
139
|
-
bucket.total_output_tokens += savings;
|
|
140
|
-
|
|
141
|
-
// Track the display name with status
|
|
142
|
-
let display_name = truncate_command(part);
|
|
143
|
-
let entry = bucket
|
|
144
|
-
.command_counts
|
|
145
|
-
.entry(format!("{}:{:?}", display_name, status))
|
|
146
|
-
.or_insert(0);
|
|
147
|
-
*entry += 1;
|
|
148
|
-
}
|
|
149
|
-
Classification::Unsupported { base_command } => {
|
|
150
|
-
let bucket = unsupported_map.entry(base_command).or_insert_with(|| {
|
|
151
|
-
UnsupportedBucket {
|
|
152
|
-
count: 0,
|
|
153
|
-
example: part.to_string(),
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
bucket.count += 1;
|
|
157
|
-
}
|
|
158
|
-
Classification::Ignored => {
|
|
159
|
-
// Check if it starts with "rtk "
|
|
160
|
-
if part.trim().starts_with("rtk ") {
|
|
161
|
-
already_rtk += 1;
|
|
162
|
-
}
|
|
163
|
-
// Otherwise just skip
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Build report
|
|
171
|
-
let mut supported: Vec<SupportedEntry> = supported_map
|
|
172
|
-
.into_values()
|
|
173
|
-
.map(|bucket| {
|
|
174
|
-
// Pick the most common command as the display name
|
|
175
|
-
let (command_with_status, status) = bucket
|
|
176
|
-
.command_counts
|
|
177
|
-
.into_iter()
|
|
178
|
-
.max_by_key(|(_, c)| *c)
|
|
179
|
-
.map(|(name, _)| {
|
|
180
|
-
// Extract status from "command:Status" format
|
|
181
|
-
if let Some(colon_pos) = name.rfind(':') {
|
|
182
|
-
let cmd = name[..colon_pos].to_string();
|
|
183
|
-
let status_str = &name[colon_pos + 1..];
|
|
184
|
-
let status = match status_str {
|
|
185
|
-
"Passthrough" => report::RtkStatus::Passthrough,
|
|
186
|
-
"NotSupported" => report::RtkStatus::NotSupported,
|
|
187
|
-
_ => report::RtkStatus::Existing,
|
|
188
|
-
};
|
|
189
|
-
(cmd, status)
|
|
190
|
-
} else {
|
|
191
|
-
(name, report::RtkStatus::Existing)
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
.unwrap_or_else(|| (String::new(), report::RtkStatus::Existing));
|
|
195
|
-
|
|
196
|
-
SupportedEntry {
|
|
197
|
-
command: command_with_status,
|
|
198
|
-
count: bucket.count,
|
|
199
|
-
rtk_equivalent: bucket.rtk_equivalent,
|
|
200
|
-
category: bucket.category,
|
|
201
|
-
estimated_savings_tokens: bucket.total_output_tokens,
|
|
202
|
-
estimated_savings_pct: bucket.savings_pct,
|
|
203
|
-
rtk_status: status,
|
|
204
|
-
}
|
|
205
|
-
})
|
|
206
|
-
.collect();
|
|
207
|
-
|
|
208
|
-
// Sort by estimated savings descending
|
|
209
|
-
supported.sort_by(|a, b| b.estimated_savings_tokens.cmp(&a.estimated_savings_tokens));
|
|
210
|
-
|
|
211
|
-
let mut unsupported: Vec<UnsupportedEntry> = unsupported_map
|
|
212
|
-
.into_iter()
|
|
213
|
-
.map(|(base, bucket)| UnsupportedEntry {
|
|
214
|
-
base_command: base,
|
|
215
|
-
count: bucket.count,
|
|
216
|
-
example: bucket.example,
|
|
217
|
-
})
|
|
218
|
-
.collect();
|
|
219
|
-
|
|
220
|
-
// Sort by count descending
|
|
221
|
-
unsupported.sort_by(|a, b| b.count.cmp(&a.count));
|
|
222
|
-
|
|
223
|
-
// Build RTK_DISABLED examples sorted by frequency (top 5)
|
|
224
|
-
let rtk_disabled_examples: Vec<String> = {
|
|
225
|
-
let mut sorted: Vec<_> = rtk_disabled_cmds.into_iter().collect();
|
|
226
|
-
sorted.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
|
|
227
|
-
sorted
|
|
228
|
-
.into_iter()
|
|
229
|
-
.take(5)
|
|
230
|
-
.map(|(cmd, count)| format!("{} ({}x)", cmd, count))
|
|
231
|
-
.collect()
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
let report = DiscoverReport {
|
|
235
|
-
sessions_scanned: sessions.len(),
|
|
236
|
-
total_commands,
|
|
237
|
-
already_rtk,
|
|
238
|
-
since_days,
|
|
239
|
-
supported,
|
|
240
|
-
unsupported,
|
|
241
|
-
parse_errors,
|
|
242
|
-
rtk_disabled_count,
|
|
243
|
-
rtk_disabled_examples,
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
match format {
|
|
247
|
-
"json" => println!("{}", report::format_json(&report)),
|
|
248
|
-
_ => print!("{}", report::format_text(&report, limit, verbose > 0)),
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
Ok(())
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/// Extract the subcommand from a command string (second word).
|
|
255
|
-
fn extract_subcmd(cmd: &str) -> &str {
|
|
256
|
-
let parts: Vec<&str> = cmd.trim().splitn(3, char::is_whitespace).collect();
|
|
257
|
-
if parts.len() >= 2 {
|
|
258
|
-
parts[1]
|
|
259
|
-
} else {
|
|
260
|
-
""
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/// Truncate a command for display (keep first meaningful portion).
|
|
265
|
-
fn truncate_command(cmd: &str) -> String {
|
|
266
|
-
let trimmed = cmd.trim();
|
|
267
|
-
// Keep first two words for display
|
|
268
|
-
let parts: Vec<&str> = trimmed.splitn(3, char::is_whitespace).collect();
|
|
269
|
-
match parts.len() {
|
|
270
|
-
0 => String::new(),
|
|
271
|
-
1 => parts[0].to_string(),
|
|
272
|
-
_ => format!("{} {}", parts[0], parts[1]),
|
|
273
|
-
}
|
|
274
|
-
}
|