-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathmain.rs
More file actions
3640 lines (3320 loc) · 120 KB
/
Copy pathmain.rs
File metadata and controls
3640 lines (3320 loc) · 120 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
mod analytics;
mod cmds;
mod core;
mod discover;
mod hooks;
mod learn;
mod parser;
// Re-export command modules for routing
use cmds::cloud::{aws_cmd, container, curl_cmd, psql_cmd, wget_cmd};
use cmds::dotnet::{binlog, dotnet_cmd, dotnet_format_report, dotnet_trx};
use cmds::git::{diff_cmd, gh_cmd, git, glab_cmd, gt_cmd};
use cmds::go::{go_cmd, golangci_cmd};
use cmds::js::{
lint_cmd, next_cmd, npm_cmd, playwright_cmd, pnpm_cmd, prettier_cmd, prisma_cmd, tsc_cmd,
vitest_cmd,
};
use cmds::jvm::{gradlew_cmd, mvn_cmd};
use cmds::php::{ecs_cmd, paratest_cmd, pest_cmd, php_cmd, phpstan_cmd, phpunit_cmd, pint_cmd};
use cmds::python::{mypy_cmd, pip_cmd, pytest_cmd, ruff_cmd, uv_cmd};
use cmds::ruby::{rake_cmd, rspec_cmd, rubocop_cmd};
use cmds::rust::{cargo_cmd, runner};
use cmds::scala::sbt_cmd;
use cmds::system::{
deps, env_cmd, find_cmd, format_cmd, json_cmd, local_llm, log_cmd, ls, pipe_cmd, read, search,
summary, tree, wc_cmd,
};
use anyhow::{Context, Result};
use clap::error::ErrorKind;
use clap::{Parser, Subcommand, ValueEnum};
use std::ffi::OsString;
use std::path::{Path, PathBuf};
/// Target agent for hook installation.
#[derive(Debug, Clone, Copy, PartialEq, ValueEnum)]
pub enum AgentTarget {
/// Claude Code (default)
Claude,
/// Cursor Agent (editor and CLI)
Cursor,
/// Windsurf IDE (Cascade)
Windsurf,
/// Cline / Roo Code (VS Code)
Cline,
/// Kilo Code
Kilocode,
/// Google Antigravity
Antigravity,
/// Kimi AI
Kimi,
/// Pi coding agent
Pi,
/// Hermes CLI
Hermes,
/// Factory Droid CLI
Droid,
/// Mistral Vibe CLI
Vibe,
}
#[derive(Parser)]
#[command(
name = "rtk",
version,
about = "Rust Token Killer - Minimize LLM token consumption",
long_about = "A high-performance CLI proxy designed to filter and summarize system outputs before they reach your LLM context."
)]
struct Cli {
#[command(subcommand)]
command: Commands,
/// Verbosity level (-v, -vv, -vvv) — only recognized before the subcommand
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
/// Ultra-compact mode: ASCII icons, inline format (Level 2 optimizations)
#[arg(long, global = true)]
ultra_compact: bool,
/// Set SKIP_ENV_VALIDATION=1 for child processes (Next.js, tsc, lint, prisma)
#[arg(long = "skip-env", global = true)]
skip_env: bool,
}
#[derive(Debug, Subcommand)]
enum Commands {
/// List directory contents with token-optimized output (proxy to native ls)
Ls {
/// Arguments passed to ls (supports all native ls flags like -l, -a, -h, -R)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Directory tree with token-optimized output (proxy to native tree)
Tree {
/// Arguments passed to tree (supports all native tree flags like -L, -d, -a)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Read file with intelligent filtering
Read {
/// Files to read (supports multiple, like cat)
#[arg(required = true, num_args = 1..)]
files: Vec<PathBuf>,
/// Filter: none (default, full content), minimal, aggressive
#[arg(short, long, default_value = "none")]
level: core::filter::FilterLevel,
/// Max lines
#[arg(short, long, conflicts_with = "tail_lines")]
max_lines: Option<usize>,
/// Keep only last N lines
#[arg(long, conflicts_with = "max_lines")]
tail_lines: Option<usize>,
/// Show line numbers
#[arg(short = 'n', long)]
line_numbers: bool,
},
/// Generate 2-line technical summary (heuristic-based)
Smart {
/// File to analyze
file: PathBuf,
/// Model: heuristic
#[arg(short, long, default_value = "heuristic")]
model: String,
/// Force model download
#[arg(long)]
force_download: bool,
},
/// Git commands with compact output
Git {
/// Change to directory before executing (like git -C <path>, can be repeated)
#[arg(short = 'C', action = clap::ArgAction::Append)]
directory: Vec<String>,
/// Git configuration override (like git -c key=value, can be repeated)
#[arg(short = 'c', action = clap::ArgAction::Append)]
config_override: Vec<String>,
/// Set the path to the .git directory
#[arg(long = "git-dir")]
git_dir: Option<String>,
/// Set the path to the working tree
#[arg(long = "work-tree")]
work_tree: Option<String>,
/// Disable pager (like git --no-pager)
#[arg(long = "no-pager")]
no_pager: bool,
/// Skip optional locks (like git --no-optional-locks)
#[arg(long = "no-optional-locks")]
no_optional_locks: bool,
/// Treat repository as bare (like git --bare)
#[arg(long)]
bare: bool,
/// Treat pathspecs literally (like git --literal-pathspecs)
#[arg(long = "literal-pathspecs")]
literal_pathspecs: bool,
#[command(subcommand)]
command: GitCommands,
},
/// GitHub CLI (gh) commands with token-optimized output
Gh {
/// Subcommand: pr, issue, run, repo
subcommand: String,
/// Additional arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// GitLab CLI (glab) commands with token-optimized output
Glab {
/// Target repository (owner/repo), passed as glab -R flag
#[arg(short = 'R', long = "repo")]
repo: Option<String>,
/// Target group, passed as glab -g flag
#[arg(short = 'g', long = "group")]
group: Option<String>,
/// Subcommand: mr, issue, ci, pipeline, api
subcommand: String,
/// Additional arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// AWS CLI with compact output (force JSON, compress)
Aws {
/// AWS service subcommand (e.g., sts, s3, ec2, ecs, rds, cloudformation)
subcommand: String,
/// Additional arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// PostgreSQL client with compact output (strip borders, compress tables)
#[command(disable_help_flag = true)]
Psql {
/// psql arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// pnpm commands with ultra-compact output
Pnpm {
/// pnpm filter arguments (can be repeated: --filter @app1 --filter @app2)
#[arg(long, short = 'F')]
filter: Vec<String>,
#[command(subcommand)]
command: PnpmCommands,
},
/// Run command and show only errors/warnings
Err {
/// Command to run
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
command: Vec<String>,
},
/// Run tests and show only failures
Test {
/// Test command (e.g. cargo test)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
command: Vec<String>,
},
/// Show JSON (compact values by default, or keys-only with --keys-only)
Json {
/// JSON file
file: PathBuf,
/// Max depth
#[arg(short, long, default_value = "5")]
depth: usize,
/// Show keys only (strip all values, show structure)
#[arg(long)]
keys_only: bool,
},
/// Summarize project dependencies
Deps {
/// Project path
#[arg(default_value = ".")]
path: PathBuf,
},
/// Show environment variables (filtered)
Env {
/// Filter by name (e.g. PATH, AWS)
#[arg(short, long)]
filter: Option<String>,
},
/// Find files with compact tree output (accepts native find flags like -name, -type)
Find {
/// All find arguments (supports both RTK and native find syntax)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Ultra-condensed diff (only changed lines)
Diff {
/// First file or - for stdin (unified diff)
file1: PathBuf,
/// Second file (optional if stdin)
file2: Option<PathBuf>,
},
/// Filter and deduplicate log output
Log {
/// Log file (omit for stdin)
file: Option<PathBuf>,
},
/// .NET commands with compact output (build/test/restore/format)
Dotnet {
#[command(subcommand)]
command: DotnetCommands,
},
/// Docker commands with compact output
Docker {
#[command(subcommand)]
command: DockerCommands,
},
/// Kubectl commands with compact output
Kubectl {
#[command(subcommand)]
command: KubectlCommands,
},
/// OpenShift CLI (oc) commands with compact output
Oc {
#[command(subcommand)]
command: OcCommands,
},
/// Run command and show heuristic summary
Summary {
/// Command to run and summarize
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
command: Vec<String>,
},
/// Compact grep - strips whitespace, truncates, groups by file
Grep {
/// Max line length
#[arg(short = 'l', long, default_value = "80")]
max_len: usize,
/// Max results to show
#[arg(short, long, default_value = "200")]
max: usize,
/// Show only match context (not full line)
#[arg(long)]
context_only: bool,
/// Filter by file type (e.g., ts, py, rust)
#[arg(short = 't', long)]
file_type: Option<String>,
/// Pattern, path, and any grep/rg flags (e.g. -v, -i, -A 3, --glob, --version)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
extra_args: Vec<String>,
},
/// Compact ripgrep - runs rg natively, same output filter as grep
Rg {
/// Pattern, path, and any rg flags (e.g. -v, -i, -t rust, --glob)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
extra_args: Vec<String>,
},
/// Initialize rtk instructions for assistant CLI usage
Init {
/// Add to global assistant config directory instead of local project file
#[arg(short, long)]
global: bool,
/// Install OpenCode plugin (in addition to Claude Code)
#[arg(long)]
opencode: bool,
/// Initialize for Gemini CLI instead of Claude Code
#[arg(long)]
gemini: bool,
/// Target agent to install hooks for (default: claude)
#[arg(long, value_enum)]
agent: Option<AgentTarget>,
/// Show current configuration
#[arg(long)]
show: bool,
/// Inject full instructions into CLAUDE.md (legacy mode)
#[arg(long = "claude-md", group = "mode")]
claude_md: bool,
/// Hook only, no RTK.md
#[arg(long = "hook-only", group = "mode")]
hook_only: bool,
/// Auto-patch settings.json without prompting
#[arg(long = "auto-patch", group = "patch")]
auto_patch: bool,
/// Skip settings.json patching (print manual instructions)
#[arg(long = "no-patch", group = "patch")]
no_patch: bool,
/// Trust and enable detected custom filters without prompting
#[arg(long = "trust-filters", group = "trust")]
trust_filters: bool,
/// Leave detected custom filters disabled without prompting
#[arg(long = "no-trust-filters", group = "trust")]
no_trust_filters: bool,
/// Remove RTK artifacts for the selected assistant mode
#[arg(long)]
uninstall: bool,
/// Target Codex CLI (uses AGENTS.md + RTK.md, no Claude hook patching)
#[arg(long)]
codex: bool,
/// Install GitHub Copilot integration (VS Code + CLI)
#[arg(long)]
copilot: bool,
/// Preview changes without writing any files (combine with -v to show content)
#[arg(long = "dry-run", conflicts_with = "show")]
dry_run: bool,
},
/// Download with compact output (strips progress bars)
Wget {
/// URL to download
url: String,
/// Output file (-O - for stdout)
#[arg(short = 'O', long = "output-document", allow_hyphen_values = true)]
output: Option<String>,
/// Additional wget arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Word/line/byte count with compact output (strips paths and padding)
Wc {
/// Arguments passed to wc (files, flags like -l, -w, -c)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Show token savings summary and history
Gain {
/// Filter statistics to current project (current working directory) // added
#[arg(short, long)]
project: bool,
/// Show ASCII graph of daily savings
#[arg(short, long)]
graph: bool,
/// Show recent command history
#[arg(short = 'H', long)]
history: bool,
/// Show monthly quota savings estimate
#[arg(short, long)]
quota: bool,
/// Subscription tier for quota calculation: pro, 5x, 20x
#[arg(short, long, default_value = "20x", requires = "quota")]
tier: String,
/// Show detailed daily breakdown (all days)
#[arg(short, long)]
daily: bool,
/// Show weekly breakdown
#[arg(short, long)]
weekly: bool,
/// Show monthly breakdown
#[arg(short, long)]
monthly: bool,
/// Show all time breakdowns (daily + weekly + monthly)
#[arg(short, long)]
all: bool,
/// Output format: text, json, csv
#[arg(short, long, default_value = "text")]
format: String,
/// Show parse failure log (commands that fell back to raw execution)
#[arg(short = 'F', long)]
failures: bool,
/// Reset all token savings stats to zero
#[arg(long)]
reset: bool,
/// Skip confirmation prompt when resetting
#[arg(long, requires = "reset")]
yes: bool,
},
/// Claude Code economics: spending (ccusage) vs savings (rtk) analysis
CcEconomics {
/// Show detailed daily breakdown
#[arg(short, long)]
daily: bool,
/// Show weekly breakdown
#[arg(short, long)]
weekly: bool,
/// Show monthly breakdown
#[arg(short, long)]
monthly: bool,
/// Show all time breakdowns (daily + weekly + monthly)
#[arg(short, long)]
all: bool,
/// Output format: text, json, csv
#[arg(short, long, default_value = "text")]
format: String,
},
/// Show or create configuration file
Config {
/// Create default config file
#[arg(long)]
create: bool,
},
/// Jest commands with compact output
Jest {
/// Additional jest arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Vitest commands with compact output
Vitest {
/// Additional vitest arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Prisma commands with compact output (no ASCII art)
Prisma {
#[command(subcommand)]
command: PrismaCommands,
},
/// TypeScript compiler with grouped error output
Tsc {
/// TypeScript compiler arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Next.js build with compact output
Next {
/// Next.js build arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// ESLint with grouped rule violations
Lint {
/// Linter arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Prettier format checker with compact output
Prettier {
/// Prettier arguments (e.g., --check, --write)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Universal format checker (prettier, black, ruff format)
Format {
/// Formatter arguments (auto-detects formatter from project files)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Playwright E2E tests with compact output
Playwright {
/// Playwright arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Cargo commands with compact output
Cargo {
#[command(subcommand)]
command: CargoCommands,
},
/// npm run with filtered output (strip boilerplate)
Npm {
/// npm run arguments (script name + options)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// npx with intelligent routing (tsc, eslint, prisma -> specialized filters)
Npx {
/// npx arguments (command + options)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Curl with auto-JSON detection and schema output
Curl {
/// Curl arguments (URL + options)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Discover missed RTK savings from Claude Code history
Discover {
/// Filter by project path (substring match)
#[arg(short, long)]
project: Option<String>,
/// Max commands per section
#[arg(short, long, default_value = "15")]
limit: usize,
/// Scan all projects (default: current project only)
#[arg(short, long)]
all: bool,
/// Limit to sessions from last N days
#[arg(short, long, default_value = "30")]
since: u64,
/// Output format: text, json
#[arg(short, long, default_value = "text")]
format: String,
},
/// Show RTK adoption across Claude Code sessions
Session {},
/// Manage telemetry consent and data (RGPD/GDPR)
Telemetry {
#[command(subcommand)]
command: core::telemetry_cmd::TelemetrySubcommand,
},
/// Learn CLI corrections from Claude Code error history
Learn {
/// Filter by project path (substring match)
#[arg(short, long)]
project: Option<String>,
/// Scan all projects (default: current project only)
#[arg(short, long)]
all: bool,
/// Limit to sessions from last N days
#[arg(short, long, default_value = "30")]
since: u64,
/// Output format: text, json
#[arg(short, long, default_value = "text")]
format: String,
/// Generate .claude/rules/cli-corrections.md file
#[arg(short, long)]
write_rules: bool,
/// Minimum confidence threshold (0.0-1.0)
#[arg(long, default_value = "0.6")]
min_confidence: f64,
/// Minimum occurrences to include in report
#[arg(long, default_value = "1")]
min_occurrences: usize,
},
/// Execute a shell command via sh -c (raw, no filtering or tracking)
Run {
/// Command string to execute (use -c for shell-like invocation)
#[arg(short = 'c', long = "command")]
command: Option<String>,
/// Positional command arguments (alternative to -c)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Execute command without filtering but track usage
Proxy {
/// Command and arguments to execute
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<OsString>,
},
/// Read stdin, apply filter, print filtered output (Unix pipe mode)
Pipe {
/// Filter name (cargo-test, pytest, phpunit, phpstan, pint, grep, find, git-log, etc.)
#[arg(short, long)]
filter: Option<String>,
/// Pass stdin through without filtering
#[arg(long)]
passthrough: bool,
},
/// Trust project-local TOML filters in current directory
Trust {
/// List all trusted filter files
#[arg(long)]
list: bool,
/// Trust without prompting (for non-interactive use)
#[arg(long, short = 'y')]
yes: bool,
},
/// Revoke trust for project-local TOML filters
Untrust,
/// Verify hook integrity and run TOML filter inline tests
Verify {
/// Run tests only for this filter name
#[arg(long)]
filter: Option<String>,
/// Fail if any filter has no inline tests (CI mode)
#[arg(long)]
require_all: bool,
},
/// Ruff linter/formatter with compact output
Ruff {
/// Ruff arguments (e.g., check, format --check)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Pytest test runner with compact output
Pytest {
/// Pytest arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Mypy type checker with grouped error output
Mypy {
/// Mypy arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// PHP command runner with compact output for artisan and syntax checks
Php {
/// PHP arguments (e.g., artisan about, -l app/Http/Controller.php)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// PHPUnit test runner with compact output
Phpunit {
/// PHPUnit arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// PHPStan analyzer with compact output
Phpstan {
/// PHPStan arguments (e.g., analyse src/)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Pest test runner with compact output
Pest {
/// Pest arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// ParaTest parallel test runner with compact output
Paratest {
/// ParaTest arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// EasyCodingStandard (ECS) code style fixer with compact output
Ecs {
/// ECS arguments (e.g., check src/, --fix)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Laravel Pint (PHP-CS-Fixer) code style fixer with compact output
Pint {
/// Pint arguments (e.g., --test, app/)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Rake/Rails test with compact Minitest output (Ruby)
Rake {
/// Rake arguments (e.g., test, test TEST=path/to/test.rb)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// RuboCop linter with compact output (Ruby)
Rubocop {
/// RuboCop arguments (e.g., --auto-correct, -A)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// RSpec test runner with compact output (Rails/Ruby)
Rspec {
/// RSpec arguments (e.g., spec/models, --tag focus)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Pip package manager with compact output (auto-detects uv)
Pip {
/// Pip arguments (e.g., list, outdated, install)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// uv run with compact output while preserving uv-managed environment semantics
Uv {
/// uv arguments (e.g., run pytest, run --project backend python script.py)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Go commands with compact output
Go {
#[command(subcommand)]
command: GoCommands,
},
/// SBT (Scala Build Tool) commands with compact output
Sbt {
#[command(subcommand)]
command: SbtCommands,
},
/// Graphite (gt) stacked PR commands with compact output
Gt {
#[command(subcommand)]
command: GtCommands,
},
/// golangci-lint wrapper with compact `run` support and passthrough for other invocations
#[command(name = "golangci-lint")]
GolangciLint {
/// Additional golangci-lint arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Android Gradle wrapper with compact output (build, test, lint)
#[command(name = "gradlew")]
Gradlew {
/// Gradle tasks and arguments (e.g., assembleDebug, testDebugUnitTest, lint, --info)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Apache Maven wrapper with compact output (test, integration-test, compile, package, install, verify, deploy)
#[command(name = "mvn")]
Mvn {
/// Maven goals and arguments (e.g., clean install, -DskipTests test, -X)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Show hook rewrite audit metrics (requires RTK_HOOK_AUDIT=1)
#[command(name = "hook-audit")]
HookAudit {
/// Show entries from last N days (0 = all time)
#[arg(short, long, default_value = "7")]
since: u64,
},
/// Rewrite a raw command to its RTK equivalent (single source of truth for hooks)
///
/// Exits 0 and prints the rewritten command if supported.
/// Exits 1 with no output if the command has no RTK equivalent.
///
/// Used by Claude Code, Gemini CLI, and other LLM hooks:
/// REWRITTEN=$(rtk rewrite "$CMD") || exit 0
Rewrite {
/// Raw command to rewrite (e.g. "git status", "cargo test && git push")
/// Accepts multiple args: `rtk rewrite ls -al` is equivalent to `rtk rewrite "ls -al"`
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Hook processors for LLM CLI tools (Gemini CLI, Copilot, etc.)
Hook {
#[command(subcommand)]
command: HookCommands,
},
}
#[derive(Debug, Subcommand)]
enum HookCommands {
/// Process Claude Code PreToolUse hook (reads JSON from stdin)
Claude,
/// Process Cursor Agent hook (reads JSON from stdin)
Cursor,
/// Process Gemini CLI BeforeTool hook (reads JSON from stdin)
Gemini,
/// Process Copilot preToolUse hook (VS Code + Copilot CLI, reads JSON from stdin)
Copilot,
/// Process Factory Droid PreToolUse hook (reads JSON from stdin)
Droid,
/// Process Mistral Vibe CLI pre_tool hook (reads JSON from stdin)
Vibe,
/// Check how a command would be rewritten by the hook engine (dry-run)
Check {
/// Target agent
#[arg(long, default_value = "claude")]
agent: String,
/// Command to check
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
command: Vec<String>,
},
}
#[derive(Debug, Subcommand)]
enum GitCommands {
/// Condensed diff output
Diff {
/// Git arguments (supports all git diff flags like --stat, --cached, etc)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// One-line commit history
Log {
/// Git arguments (supports all git log flags like --oneline, --graph, --all)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Compact status (supports all git status flags)
Status {
/// Git arguments (supports all git status flags like --porcelain, --short, -s)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Compact show (commit summary + stat + compacted diff)
Show {
/// Git arguments (supports all git show flags)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Add files → "ok"
Add {
/// Files and flags to add (supports all git add flags like -A, -p, --all, etc)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Commit → "ok \<hash\>"
Commit {
/// Git commit arguments (supports -a, -m, --amend, --allow-empty, etc)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Checkout branch or restore paths → "ok"
Checkout {
/// Git checkout arguments (supports -b, branch names, refs, -- paths)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Push → "ok \<branch\>"
Push {
/// Git push arguments (supports -u, remote, branch, etc.)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Pull → "ok \<stats\>"
Pull {
/// Git pull arguments (supports --rebase, remote, branch, etc.)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Compact branch listing (current/local/remote)
Branch {
/// Git branch arguments (supports -d, -D, -m, etc.)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Fetch → "ok fetched (N new refs)"
Fetch {
/// Git fetch arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Stash management (list, show, pop, apply, drop)
Stash {
/// Subcommand: list, show, pop, apply, drop, push
subcommand: Option<String>,
/// Additional arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Compact worktree listing
Worktree {
/// Git worktree arguments (add, remove, prune, or empty for list)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Passthrough: runs any unsupported git subcommand directly
#[command(external_subcommand)]
Other(Vec<OsString>),
}
#[derive(Debug, Subcommand)]
enum PnpmCommands {
/// List installed packages (ultra-dense)
List {
/// Depth level (default: 0)
#[arg(short, long, default_value = "0")]
depth: usize,
/// Additional pnpm arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Show outdated packages (condensed: "pkg: old → new")
Outdated {
/// Additional pnpm arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Install packages (filter progress bars)
Install {
/// Additional pnpm arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Typecheck (delegates to tsc filter)
Typecheck {
/// Additional typecheck arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Passthrough: runs any unsupported pnpm subcommand directly