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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
mod adapter;
mod adapters;
mod commands;
mod display;
mod mcp_client;
mod mcp_http;
pub use tuff_core::{
cache, catalog, check, config, error, git, lockfile, manifest, oci, pack, paths, registry,
release, resolver, tool, tree_diff,
};
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use commands::{
PackBuildOptions, PackInitOptions, cmd_add, cmd_add_accepting, cmd_add_mcp, cmd_add_pack,
cmd_agent_add, cmd_agent_list, cmd_agent_remove, cmd_agent_set_default, cmd_cache_clear,
cmd_check, cmd_console_key_create, cmd_console_key_list, cmd_console_key_revoke,
cmd_console_publish, cmd_console_serve, cmd_create, cmd_delete, cmd_diff, cmd_generate_index,
cmd_generate_report, cmd_hooks_check_portability, cmd_hooks_matrix, cmd_hooks_spec, cmd_init,
cmd_list, cmd_lock_migrate, cmd_mcp_catalog, cmd_mcp_doctor, cmd_mcp_search, cmd_outdated,
cmd_pack_build, cmd_pack_check, cmd_pack_extract, cmd_pack_init, cmd_pack_inspect,
cmd_pack_pull, cmd_pack_push, cmd_pack_verify, cmd_policy_matrix, cmd_scan, cmd_status,
cmd_untrack, cmd_update,
};
use error::{Result, TuffError};
use manifest::CapabilityType;
#[derive(Parser)]
#[command(name = "tuff", version)]
struct Cli {
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Subcommand)]
enum Command {
/// Initialize project Tuff state.
Init {
/// Initialize global scope.
#[arg(short = 'g', long = "global")]
global: bool,
},
/// Create and track a new capability.
Create {
#[command(subcommand)]
kind: CreateCommand,
},
/// Install a capability.
Add {
/// Path or URL (auto-detect type). Use a subcommand to specify type explicitly.
source: Option<PathBuf>,
/// Override the capability name (only when type is auto-detected).
#[arg(short = 'n', long = "name")]
name: Option<String>,
/// Harness to emit for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Install to global scope.
#[arg(short = 'g', long = "global")]
global: bool,
/// For a policy: install the rules each harness enforces and record the
/// rest in tuff.lock, instead of refusing the policy.
#[arg(long = "accept-unenforced")]
accept_unenforced: bool,
/// For a policy: also register tuff policy evaluate as a hook for rules
/// a native setting covers only in part, such as Claude Code command
/// rules, so reworded commands are caught too.
#[arg(long = "runtime-hook")]
runtime_hook: bool,
#[command(subcommand)]
kind: Option<AddCommand>,
},
/// Find capabilities already in a harness folder that Tuff is not tracking.
Scan {
/// Track what the scan found. Without paths, every untracked capability.
#[arg(long = "adopt")]
adopt: bool,
/// Capability directory to adopt (repeatable; requires --adopt).
paths: Vec<PathBuf>,
/// Output rows as JSON.
#[arg(long = "json")]
json: bool,
},
/// Build, inspect, verify, and extract capability packs.
Pack {
#[command(subcommand)]
action: PackCommand,
},
/// List installed capabilities.
List {
/// Filter by scope: project, global, or all.
#[arg(short = 's', long = "scope", default_value = "all")]
scope: String,
/// Filter by capability type: skill, tool, hook, mcp-server, policy.
#[arg(short = 'p', long = "type")]
kind: Option<String>,
/// Output rows as JSON.
#[arg(long = "json")]
json: bool,
},
/// Show detailed status for installed primitives.
Status,
/// Generate derived Tuff artifacts.
Generate {
#[command(subcommand)]
artifact: GenerateCommand,
},
/// Show installed capabilities with upstream update status.
Outdated {
/// Use unencrypted HTTP for a development registry, when checking a
/// pack-sourced capability.
#[arg(long)]
plain_http: bool,
/// Additional PEM certificate authority to trust (repeatable), when
/// checking a pack-sourced capability.
#[arg(long = "ca-file")]
ca_file: Vec<PathBuf>,
/// Output rows as JSON.
#[arg(long = "json")]
json: bool,
},
/// Diff an installed capability against baseline.
Diff {
/// Installed capability id.
capability_id: String,
/// Harness to diff (defaults to the configured harness).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Option<String>,
/// Diff against latest upstream source instead of baseline.
#[arg(short = 'u', long = "upstream")]
upstream: bool,
/// Diff output format.
#[arg(long = "format", value_enum, default_value_t = commands::DiffFormat::Unified)]
format: commands::DiffFormat,
/// Output the diff as JSON; the same as `--format json`.
#[arg(long = "json", conflicts_with = "format")]
json: bool,
},
/// Reconcile an installed capability with its source or accept local edits.
Update {
/// Capability id to update.
id: String,
/// Scope to update.
#[arg(short = 's', long = "scope")]
scope: Option<String>,
/// Dry run — show what would change without applying.
#[arg(long = "check")]
check: bool,
/// Harness to update (repeatable; defaults to the configured harness).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Force overwrite local changes with upstream (Git and pack sources).
#[arg(short = 'f', long = "force")]
force: bool,
/// For a pack-installed capability: update the whole pack from this
/// artifact instead of resolving its registry.
#[arg(long = "pack", value_name = "ARTIFACT")]
pack: Option<PathBuf>,
/// Use unencrypted HTTP for a development registry, when updating a
/// pack-installed capability.
#[arg(long)]
plain_http: bool,
/// Additional PEM certificate authority to trust (repeatable), when
/// updating a pack-installed capability.
#[arg(long = "ca-file")]
ca_file: Vec<PathBuf>,
},
/// Validate installed capabilities (CI mode).
Check {
/// Output results as JSON.
#[arg(long = "json")]
json: bool,
/// Report failures but exit with code 0.
#[arg(long = "ignore-failures")]
ignore_failures: bool,
/// Validate global scope only.
#[arg(long = "global")]
global: bool,
/// Also fail while a policy rule is recorded as not enforced for a harness.
#[arg(long = "strict")]
strict: bool,
},
/// Delete Tuff-generated capability files.
Delete {
/// Capability id to delete.
id: String,
/// Scope to delete from.
#[arg(short = 's', long = "scope", default_value = "project")]
scope: String,
/// Harness to delete from (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Delete files even when they have local modifications.
#[arg(short = 'f', long = "force")]
force: bool,
},
/// Stop tracking a capability without deleting its harness files.
Untrack {
/// Capability id to untrack.
id: String,
/// Scope to untrack from.
#[arg(short = 's', long = "scope", default_value = "project")]
scope: String,
/// Harness to untrack (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
},
/// Manage the harnesses this project installs for.
Harness {
#[command(subcommand)]
action: HarnessCommand,
},
/// Inspect hook compatibility and portability.
Hooks {
#[command(subcommand)]
action: HooksCommand,
},
/// Inspect what each harness can enforce of a policy.
Policy {
#[command(subcommand)]
action: PolicyCommand,
},
/// Manage Tuff's disposable machine-local cache.
Cache {
#[command(subcommand)]
action: CacheCommand,
},
/// Inspect and migrate the project lockfile.
Lock {
#[command(subcommand)]
action: LockCommand,
},
/// Browse the MCP catalog and registry, and diagnose installed servers.
Mcp {
#[command(subcommand)]
action: McpCommand,
},
/// Run a console server, and report this project's capabilities to one.
Console {
#[command(subcommand)]
action: ConsoleCommand,
},
}
#[derive(Subcommand)]
enum ConsoleCommand {
/// Run the console server.
Serve {
/// Address to listen on. Anything but a loopback address needs --public-read and a key or a trust.
#[arg(long = "addr", value_name = "ADDR", default_value = "127.0.0.1:7474")]
addr: std::net::SocketAddr,
/// Folder for the console database (default: $XDG_DATA_HOME/tuff/console).
#[arg(long = "data", value_name = "DIR")]
data: Option<PathBuf>,
/// Allow a non-loopback address although viewers are not authenticated.
#[arg(long = "public-read")]
public_read: bool,
/// Accept publishing from GitHub Actions jobs of this owner, with no secret (repeatable): github:<owner>.
#[arg(long = "trust", value_name = "PROVIDER:OWNER")]
trust: Vec<String>,
/// The URL publishers use to reach this console, which OIDC tokens name as their audience (default: http://<addr>).
#[arg(long = "public-url", value_name = "URL")]
public_url: Option<String>,
/// Serve generated sample projects from a temporary database, for trying the UI.
#[arg(long = "demo", conflicts_with = "data")]
demo: bool,
},
/// Manage the keys that authorise publishing.
Key {
#[command(subcommand)]
action: ConsoleKeyCommand,
},
/// Send this project's report to a console server.
Publish {
/// The console's URL.
#[arg(
long = "server",
value_name = "URL",
env = "TUFF_CONSOLE_URL",
default_value = "http://127.0.0.1:7474"
)]
server: String,
/// A console API key. Without one, a GitHub Actions job publishes with its OIDC token.
#[arg(
long = "key",
value_name = "KEY",
env = "TUFF_CONSOLE_KEY",
hide_env_values = true
)]
key: Option<String>,
/// Report every project with a tuff.lock under this folder.
#[arg(long = "all")]
all: bool,
/// Also report newer versions (needs the network).
#[arg(long = "outdated")]
outdated: bool,
/// Name the project's repository, required outside git or without an origin remote.
#[arg(long = "project", value_name = "NAME")]
project: Option<String>,
/// Print the report and send nothing.
#[arg(long = "dry-run")]
dry_run: bool,
},
}
#[derive(Subcommand)]
enum ConsoleKeyCommand {
/// Create a key and print it once.
Create {
/// Name the key is listed and revoked by.
name: String,
/// Bind the key to one repository, such as github.com/acme/web.
#[arg(long = "repository", value_name = "REPOSITORY")]
repository: Option<String>,
/// Folder for the console database.
#[arg(long = "data", value_name = "DIR")]
data: Option<PathBuf>,
},
/// List key names, creation times, and last use.
List {
/// Folder for the console database.
#[arg(long = "data", value_name = "DIR")]
data: Option<PathBuf>,
/// Output keys as JSON.
#[arg(long = "json")]
json: bool,
},
/// Revoke a key.
Revoke {
name: String,
/// Folder for the console database.
#[arg(long = "data", value_name = "DIR")]
data: Option<PathBuf>,
},
}
#[derive(Subcommand)]
enum McpCommand {
/// List the built-in MCP server catalog.
Catalog {
/// Output the catalog as JSON.
#[arg(long = "json")]
json: bool,
},
/// Spawn each installed mcp-server capability, complete the MCP
/// initialize handshake, and list its tools.
Doctor {
/// Only check servers wired into this harness (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Check global scope instead of project scope.
#[arg(short = 'g', long = "global")]
global: bool,
/// Output results as JSON.
#[arg(long = "json")]
json: bool,
/// Report failures but exit with code 0.
#[arg(long = "ignore-failures")]
ignore_failures: bool,
/// Seconds to wait for a server to respond before reporting a timeout.
#[arg(long = "timeout", default_value_t = 10)]
timeout_secs: u64,
},
/// Search the MCP registry for servers to install.
Search {
/// What to search for: part of a name, or a word from a description.
query: String,
/// Maximum results to show.
#[arg(long = "limit", default_value_t = 20)]
limit: usize,
/// Registry to search instead of the official one.
#[arg(long = "registry", default_value = tuff_core::registry::DEFAULT_REGISTRY)]
registry: String,
/// Output results as JSON.
#[arg(long = "json")]
json: bool,
},
}
#[derive(Subcommand)]
enum CacheCommand {
/// Delete all disposable cached materialized trees and source clones.
Clear,
}
#[derive(Subcommand)]
enum LockCommand {
/// Rewrite tuff.lock in the current schema version, changing nothing else.
Migrate,
}
#[derive(Subcommand)]
enum GenerateCommand {
/// Generate an agent-facing capability index.
Index {
/// Harness to generate an index for (defaults to the configured harness).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Option<String>,
/// Output path. Defaults to the harness's standard CAPABILITIES.md path.
#[arg(short = 'o', long = "output")]
output: Option<PathBuf>,
},
/// Generate a project capability report.
Report {
/// Output path. Defaults to tuff-report.md.
#[arg(short = 'o', long = "output")]
output: Option<PathBuf>,
},
}
#[derive(Subcommand)]
enum CreateCommand {
/// Create and track a skill.
Skill {
/// Capability id.
id: String,
/// Harnesses to scaffold for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
},
/// Create and track a tool.
Tool {
/// Capability id.
id: String,
/// Harnesses to scaffold for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
},
/// Create and track a hook.
Hook {
/// Capability id.
id: String,
/// Harnesses to scaffold for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
},
/// MCP servers are not scaffolded; use `tuff add mcp` instead.
#[command(name = "mcp-server")]
McpServer {
/// Capability id.
id: String,
/// Harnesses to scaffold for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
},
}
#[derive(Subcommand)]
enum AddCommand {
/// Install a skill from a local path or git URL.
Skill {
/// Path to capability directory, file, or git URL.
source: PathBuf,
/// Override the capability name (default: inferred from source).
name: Option<String>,
/// Harness to emit for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Install to global scope.
#[arg(short = 'g', long = "global")]
global: bool,
},
/// Install a tool from a local path or git URL.
Tool {
source: PathBuf,
name: Option<String>,
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
#[arg(short = 'g', long = "global")]
global: bool,
},
/// Install a hook from a local path or git URL.
Hook {
source: PathBuf,
name: Option<String>,
/// Native harness hook fragment to merge, relative to the source directory.
#[arg(long = "hook-file")]
hook_file: Option<PathBuf>,
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
#[arg(short = 'g', long = "global")]
global: bool,
},
/// Install every capability in a verified pack artifact.
Pack {
source: PathBuf,
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// OCI reference this pack was pulled from (e.g.
/// ghcr.io/acme/engineering:1.2.0), recorded so `tuff outdated` can
/// check whether a newer pack version has been published. Omit if
/// the pack did not come from a registry, or you do not want it
/// checked.
#[arg(long = "reference")]
reference: Option<String>,
},
/// Install external MCP servers from the built-in catalog, the MCP
/// registry, a local path, or a git URL, wiring each into every selected
/// harness's MCP config.
Mcp {
/// Built-in catalog ids, MCP registry names (see `tuff mcp
/// search`), paths to a directory with a tuff.toml, or git URLs.
/// Several may be given at once.
#[arg(required = true)]
sources: Vec<String>,
/// Harness to emit for (repeatable).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Install to global scope.
#[arg(short = 'g', long = "global")]
global: bool,
/// Skip the interactive prompt for a different env var name per
/// catalog entry and accept the catalog's defaults. Implied when
/// stdin isn't a terminal (scripts, CI).
#[arg(short = 'y', long = "yes")]
yes: bool,
/// Registry to resolve a name that is not a built-in catalog id.
#[arg(long = "registry", default_value = tuff_core::registry::DEFAULT_REGISTRY)]
registry: String,
},
}
#[derive(Subcommand)]
enum PackCommand {
/// Create a source pack manifest.
Init {
/// Stable pack name, optionally namespaced with slashes.
name: String,
/// Select tracked capabilities from the current project.
#[arg(long = "from-project")]
from_project: bool,
/// Tracked capability to include (repeatable).
#[arg(short = 'c', long = "capability")]
capability: Vec<String>,
/// Harness to render (repeatable; defaults to the project default).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Initial pack version.
#[arg(long)]
version: Option<String>,
/// Pack description.
#[arg(long)]
description: Option<String>,
},
/// Validate a source pack without writing an artifact.
Check {
/// Pack directory or tuff-pack.toml path.
path: Option<PathBuf>,
},
/// Build a deterministic local pack artifact.
Build {
/// Pack directory or tuff-pack.toml path.
path: Option<PathBuf>,
/// Build tracked capabilities directly from the current project.
#[arg(long)]
name: Option<String>,
/// Pack version (project mode defaults to 0.1.0).
#[arg(long)]
version: Option<String>,
/// Pack description for a one-shot project build.
#[arg(long)]
description: Option<String>,
/// Tracked capability to include (repeatable).
#[arg(short = 'c', long = "capability")]
capability: Vec<String>,
/// Harness to render (repeatable; defaults to the project default).
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: Vec<String>,
/// Artifact output path.
#[arg(short = 'o', long = "output")]
output: Option<PathBuf>,
},
/// Print verified pack metadata.
Inspect {
/// Pack artifact path.
artifact: PathBuf,
/// Print canonical metadata as JSON.
#[arg(long = "json")]
json: bool,
},
/// Verify the complete pack artifact and every stored file.
Verify {
/// Pack artifact path.
artifact: PathBuf,
},
/// Publish a verified pack artifact to an OCI registry tag.
Push {
/// Local pack artifact to publish.
artifact: PathBuf,
/// OCI registry reference with an explicit tag.
reference: String,
/// Replace an existing tag that points to different content.
#[arg(long)]
force: bool,
/// Use unencrypted HTTP for a development registry.
#[arg(long)]
plain_http: bool,
/// Additional PEM certificate authority to trust (repeatable).
#[arg(long = "ca-file")]
ca_file: Vec<PathBuf>,
/// Print deterministic JSON output.
#[arg(long)]
json: bool,
},
/// Pull and verify a pack artifact from an OCI registry.
Pull {
/// OCI registry reference with an explicit tag or digest.
reference: String,
/// New local artifact path. Existing files are never overwritten.
#[arg(short = 'o', long = "output")]
output: PathBuf,
/// Use unencrypted HTTP for a development registry.
#[arg(long)]
plain_http: bool,
/// Additional PEM certificate authority to trust (repeatable).
#[arg(long = "ca-file")]
ca_file: Vec<PathBuf>,
/// Print deterministic JSON output.
#[arg(long)]
json: bool,
},
/// Extract one pre-rendered target into a missing or empty directory.
Extract {
/// Pack artifact path.
artifact: PathBuf,
/// Harness contained in the artifact.
#[arg(short = 'a', long = "harness", value_name = "HARNESS")]
agent: String,
/// Missing or empty output directory.
#[arg(short = 'o', long = "output")]
output: PathBuf,
},
}
fn reject_parent_add_options(
source: Option<&PathBuf>,
name: Option<&String>,
agent: &[String],
global: bool,
policy_options: commands::PolicyOptions,
) -> Result<()> {
if policy_options.accept_unenforced {
return Err(TuffError::usage(
"--accept-unenforced applies to 'tuff add <path>' of a policy, not to typed 'tuff add' commands",
));
}
if policy_options.runtime_hook {
return Err(TuffError::usage(
"--runtime-hook applies to 'tuff add <path>' of a policy, not to typed 'tuff add' commands",
));
}
if source.is_some() || name.is_some() || !agent.is_empty() || global {
return Err(TuffError::usage(
"for typed 'tuff add' commands, put --harness and --global after the capability source",
));
}
Ok(())
}
#[derive(Subcommand)]
enum HarnessCommand {
/// List available and registered harnesses.
List {
/// Show the global harness configuration.
#[arg(short = 'g', long = "global")]
global: bool,
},
/// Register a harness for this repo.
Add {
/// Harness adapter id.
id: String,
},
/// Unregister a harness without changing installed capabilities.
Remove {
/// Harness adapter id.
id: String,
},
/// Set the default harness used when --harness is omitted.
SetDefault {
/// Harness adapter id.
id: String,
/// Set the default for global operations.
#[arg(short = 'g', long = "global")]
global: bool,
},
}
#[derive(Subcommand)]
enum PolicyCommand {
/// Print, for every harness, how each kind of policy rule is enforced.
Matrix {
/// Output the matrix as JSON.
#[arg(long = "json")]
json: bool,
},
/// Answer a harness's hook: read the tool call as JSON on standard
/// input and deny or ask when an installed policy's rule matches it.
/// Tuff registers this command when it installs a policy; it is not
/// meant to be run by hand.
Evaluate {
/// The harness running the hook, such as claude, codex, or cursor.
#[arg(long = "harness", value_name = "HARNESS")]
harness: String,
/// The id of the installed policy to evaluate.
#[arg(long = "policy", value_name = "ID")]
policy: String,
},
}
#[derive(Subcommand)]
enum HooksCommand {
/// Print hook compatibility for registered harnesses.
Matrix,
/// Print the hook specification this binary implements, for every harness.
Spec {
/// Output the specification document as JSON.
#[arg(long = "json")]
json: bool,
},
/// Check whether a tracked hook can render on a target harness.
CheckPortability {
/// Installed hook capability id.
id: String,
/// Registered target adapter id.
#[arg(long = "target")]
target: String,
},
}
fn main() {
if let Err(error) = run() {
report_error(&error, wants_json());
std::process::exit(error.exit_code());
}
}
/// Whether the invocation asked for machine-readable output.
///
/// Read from the raw arguments rather than the parsed command: an error can
/// happen before or during parsing, and a `--json` caller wants one shape
/// on stdout and one shape on stderr, not prose on failure.
fn wants_json() -> bool {
std::env::args().any(|arg| arg == "--json")
}
fn report_error(error: &TuffError, json: bool) {
if json {
let mut envelope = serde_json::json!({
"error": {
"kind": error.kind().as_str(),
"message": error.message(),
}
});
if let Some(hint) = error.hint() {
envelope["error"]["hint"] = serde_json::Value::String(hint.to_string());
}
eprintln!("{envelope}");
return;
}
eprintln!("error: {error}");
if let Some(hint) = error.hint() {
eprintln!("hint: {hint}");
}
}
fn run() -> Result<()> {
let cli = Cli::parse();
let repo_root = std::env::current_dir()?;
match cli.command {
None => {
display::print_welcome();
Ok(())
}
Some(Command::Init { global }) => cmd_init(&repo_root, global),
Some(Command::Create { kind }) => match kind {
CreateCommand::Skill { id, agent } => {
cmd_create(&repo_root, CapabilityType::Skill, &id, &agent)
}
CreateCommand::Tool { id, agent } => {
cmd_create(&repo_root, CapabilityType::Tool, &id, &agent)
}
CreateCommand::Hook { id, agent } => {
cmd_create(&repo_root, CapabilityType::Hook, &id, &agent)
}
CreateCommand::McpServer { id, agent } => {
cmd_create(&repo_root, CapabilityType::McpServer, &id, &agent)
}
},
Some(Command::Add {
source,
name,
agent,
global,
accept_unenforced,
runtime_hook,
kind,
}) => {
let policy_options = commands::PolicyOptions {
accept_unenforced,
runtime_hook,
};
match kind {
None => cmd_add_accepting(
&repo_root,
source.as_deref(),
name.as_deref(),
None,
&agent,
global,
None,
policy_options,
),
Some(AddCommand::Skill {
source: typed_source,
name: typed_name,
agent: typed_agent,
global: typed_global,
}) => {
reject_parent_add_options(
source.as_ref(),
name.as_ref(),
&agent,
global,
policy_options,
)?;
cmd_add(
&repo_root,
Some(typed_source.as_path()),
typed_name.as_deref(),
Some("skill"),
&typed_agent,
typed_global,
None,
)
}
Some(AddCommand::Tool {
source: typed_source,
name: typed_name,
agent: typed_agent,
global: typed_global,
}) => {
reject_parent_add_options(
source.as_ref(),
name.as_ref(),
&agent,
global,
policy_options,
)?;
cmd_add(
&repo_root,
Some(typed_source.as_path()),
typed_name.as_deref(),
Some("tool"),
&typed_agent,
typed_global,
None,
)
}
Some(AddCommand::Hook {
source: typed_source,
name: typed_name,
hook_file,
agent: typed_agent,
global: typed_global,
}) => {
reject_parent_add_options(
source.as_ref(),
name.as_ref(),
&agent,
global,
policy_options,
)?;
cmd_add(
&repo_root,
Some(typed_source.as_path()),
typed_name.as_deref(),
Some("hook"),
&typed_agent,
typed_global,
hook_file.as_deref(),
)
}
Some(AddCommand::Pack {
source: typed_source,
agent: typed_agent,
reference: typed_reference,
}) => {
reject_parent_add_options(
source.as_ref(),
name.as_ref(),
&agent,
global,
policy_options,
)?;
cmd_add_pack(
&repo_root,
&typed_source,
&typed_agent,
typed_reference.as_deref(),
)
}
Some(AddCommand::Mcp {
sources,
agent: typed_agent,
global: typed_global,
yes,
registry,
}) => {
reject_parent_add_options(
source.as_ref(),
name.as_ref(),
&agent,
global,
policy_options,
)?;
cmd_add_mcp(
&repo_root,
&sources,
&typed_agent,
typed_global,
yes,
®istry,
)
}
}
}
Some(Command::Pack { action }) => match action {
PackCommand::Init {
name,
from_project,
capability,
agent,
version,
description,
} => cmd_pack_init(
&repo_root,
PackInitOptions {
name,
from_project,
capabilities: capability,
agents: agent,
version,
description,
},
),
PackCommand::Check { path } => cmd_pack_check(&repo_root, path.as_deref()),
PackCommand::Build {
path,
name,
version,
description,
capability,
agent,
output,
} => cmd_pack_build(
&repo_root,
PackBuildOptions {
path,
name,
version,
description,
capabilities: capability,
agents: agent,
output,
},
),
PackCommand::Inspect { artifact, json } => cmd_pack_inspect(&artifact, json),
PackCommand::Verify { artifact } => cmd_pack_verify(&artifact),
PackCommand::Push {
artifact,
reference,
force,
plain_http,
ca_file,
json,
} => cmd_pack_push(&artifact, &reference, force, plain_http, &ca_file, json),
PackCommand::Pull {
reference,
output,
plain_http,
ca_file,
json,
} => cmd_pack_pull(&reference, &output, plain_http, &ca_file, json),
PackCommand::Extract {
artifact,
agent,
output,
} => cmd_pack_extract(&artifact, &agent, &output),
},
Some(Command::List { scope, kind, json }) => {
cmd_list(&repo_root, &scope, kind.as_deref(), json)
}
Some(Command::Status) => cmd_status(&repo_root),
Some(Command::Generate { artifact }) => match artifact {
GenerateCommand::Index { agent, output } => {
cmd_generate_index(&repo_root, agent.as_deref(), output.as_deref())
}
GenerateCommand::Report { output } => {
cmd_generate_report(&repo_root, output.as_deref())
}
},
Some(Command::Outdated {
plain_http,
ca_file,
json,
}) => cmd_outdated(&repo_root, plain_http, &ca_file, json),
Some(Command::Diff {
capability_id,
agent,
upstream,
format,
json,
}) => cmd_diff(
&repo_root,
&capability_id,
agent.as_deref(),
upstream,
if json {
commands::DiffFormat::Json
} else {
format
},
),
Some(Command::Update {
id,
scope,
check,
agent,
force,
pack,
plain_http,
ca_file,
}) => cmd_update(
&repo_root,
&id,
commands::UpdateOptions {
scope: scope.as_deref(),
requested_targets: &agent,
check,
force,
pack_artifact: pack.as_deref(),
oci_options: tuff_core::oci::OciTransferOptions {
plain_http,
ca_files: ca_file,
},
},
),
Some(Command::Check {
json,
ignore_failures,
global,
strict,
}) => cmd_check(&repo_root, json, ignore_failures, global, strict),
Some(Command::Delete {
id,
scope,
agent,
force,
}) => cmd_delete(&repo_root, &id, &scope, &agent, force),
Some(Command::Scan { adopt, paths, json }) => cmd_scan(&repo_root, adopt, &paths, json),
Some(Command::Untrack { id, scope, agent }) => cmd_untrack(&repo_root, &id, &scope, &agent),
Some(Command::Harness { action }) => match action {
HarnessCommand::List { global } => cmd_agent_list(&repo_root, global),
HarnessCommand::Add { id } => cmd_agent_add(&repo_root, &id),
HarnessCommand::Remove { id } => cmd_agent_remove(&repo_root, &id),
HarnessCommand::SetDefault { id, global } => {
cmd_agent_set_default(&repo_root, &id, global)
}
},
Some(Command::Hooks { action }) => match action {
HooksCommand::Matrix => cmd_hooks_matrix(&repo_root),
HooksCommand::Spec { json } => cmd_hooks_spec(json),
HooksCommand::CheckPortability { id, target } => {
cmd_hooks_check_portability(&repo_root, &id, &target)
}
},
Some(Command::Policy { action }) => match action {
PolicyCommand::Matrix { json } => cmd_policy_matrix(json),
PolicyCommand::Evaluate { harness, policy } => {
std::process::exit(commands::cmd_policy_evaluate(&harness, &policy))
}
},
Some(Command::Cache {
action: CacheCommand::Clear,
}) => cmd_cache_clear(),
Some(Command::Lock {
action: LockCommand::Migrate,
}) => cmd_lock_migrate(&repo_root),
Some(Command::Console { action }) => match action {
ConsoleCommand::Serve {
addr,
data,
public_read,
trust,
public_url,
demo,
} => cmd_console_serve(
addr,
data.as_deref(),
public_read,
&trust,
public_url.as_deref(),
demo,
),
ConsoleCommand::Key { action } => match action {
ConsoleKeyCommand::Create {
name,
repository,
data,
} => cmd_console_key_create(&name, repository.as_deref(), data.as_deref()),
ConsoleKeyCommand::List { data, json } => {
cmd_console_key_list(data.as_deref(), json)
}
ConsoleKeyCommand::Revoke { name, data } => {
cmd_console_key_revoke(&name, data.as_deref())
}
},
ConsoleCommand::Publish {
server,
key,
all,
outdated,
project,
dry_run,
} => cmd_console_publish(
&repo_root,
commands::PublishOptions {
server: &server,
key: key.as_deref(),
all,
outdated,
project: project.as_deref(),
dry_run,
},
),
},
Some(Command::Mcp { action }) => match action {
McpCommand::Catalog { json } => cmd_mcp_catalog(json),
McpCommand::Doctor {
agent,
global,
json,
ignore_failures,
timeout_secs,
} => cmd_mcp_doctor(
&repo_root,
&agent,
global,
json,
ignore_failures,
timeout_secs,
),
McpCommand::Search {
query,
limit,
registry,
json,
} => cmd_mcp_search(&query, limit, ®istry, json),
},
}
}