@hasna/terminal 2.0.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +52 -21
- package/package.json +1 -1
- package/src/ai.ts +77 -130
- package/src/cli.tsx +51 -21
- package/src/command-validator.ts +11 -0
- package/src/context-hints.ts +291 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-processor.ts +7 -18
- package/src/output-store.ts +65 -0
- package/src/providers/base.ts +3 -1
- package/src/providers/groq.ts +108 -0
- package/src/providers/index.ts +26 -2
- package/src/providers/providers.test.ts +4 -2
- package/src/providers/xai.ts +108 -0
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
- package/dist/App.js +0 -404
- package/dist/Browse.js +0 -79
- package/dist/FuzzyPicker.js +0 -47
- package/dist/Onboarding.js +0 -51
- package/dist/Spinner.js +0 -12
- package/dist/StatusBar.js +0 -49
- package/dist/ai.js +0 -368
- package/dist/cache.js +0 -41
- package/dist/command-rewriter.js +0 -64
- package/dist/command-validator.js +0 -77
- package/dist/compression.js +0 -107
- package/dist/diff-cache.js +0 -107
- package/dist/economy.js +0 -79
- package/dist/expand-store.js +0 -38
- package/dist/file-cache.js +0 -72
- package/dist/file-index.js +0 -62
- package/dist/history.js +0 -62
- package/dist/lazy-executor.js +0 -54
- package/dist/line-dedup.js +0 -59
- package/dist/loop-detector.js +0 -75
- package/dist/mcp/install.js +0 -98
- package/dist/mcp/server.js +0 -569
- package/dist/noise-filter.js +0 -86
- package/dist/output-processor.js +0 -136
- package/dist/output-router.js +0 -41
- package/dist/parsers/base.js +0 -2
- package/dist/parsers/build.js +0 -64
- package/dist/parsers/errors.js +0 -101
- package/dist/parsers/files.js +0 -78
- package/dist/parsers/git.js +0 -99
- package/dist/parsers/index.js +0 -48
- package/dist/parsers/tests.js +0 -89
- package/dist/providers/anthropic.js +0 -39
- package/dist/providers/base.js +0 -4
- package/dist/providers/cerebras.js +0 -95
- package/dist/providers/index.js +0 -49
- package/dist/recipes/model.js +0 -20
- package/dist/recipes/storage.js +0 -136
- package/dist/search/content-search.js +0 -68
- package/dist/search/file-search.js +0 -61
- package/dist/search/filters.js +0 -34
- package/dist/search/index.js +0 -5
- package/dist/search/semantic.js +0 -320
- package/dist/session-boot.js +0 -59
- package/dist/session-context.js +0 -55
- package/dist/sessions-db.js +0 -120
- package/dist/smart-display.js +0 -286
- package/dist/snapshots.js +0 -51
- package/dist/supervisor.js +0 -112
- package/dist/test-watchlist.js +0 -131
- package/dist/tree.js +0 -94
- package/dist/usage-cache.js +0 -65
|
@@ -0,0 +1,367 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
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
|
+
}
|