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
//! Clap `Command` tree for the `jacs` binary.
//!
//! Extracted from `main.rs` so the library target (used by the snapshot test
//! in `tests/cli_command_snapshot.rs`) can pick it up without dragging in the
//! full binary entry point. See `src/lib.rs` for the public re-export.
use clap::{Arg, ArgAction, Command, crate_name, value_parser};
use crate::password_bootstrap::quickstart_password_bootstrap_help;
pub fn build_cli() -> Command {
let cmd = Command::new(crate_name!())
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.subcommand(
Command::new("version")
.about("Prints version and build information")
)
.subcommand(
Command::new("config")
.about(" work with JACS configuration")
.subcommand(
Command::new("create")
.about(" create a config file")
)
.subcommand(
Command::new("read")
.about("read configuration and display to screen. This includes both the config file and the env variables.")
),
)
.subcommand(
Command::new("agent")
.about(" work with a JACS agent")
.subcommand(
Command::new("dns")
.about("emit DNS TXT commands for publishing agent fingerprint")
.arg(
Arg::new("agent-file")
.short('a')
.long("agent-file")
.value_parser(value_parser!(String))
.help("Path to agent JSON (optional; defaults via config)"),
)
.arg(
Arg::new("no-dns")
.long("no-dns")
.help("Disable DNS validation; rely on embedded fingerprint")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("require-dns")
.long("require-dns")
.help("Require DNS validation; if domain missing, fail. Not strict (no DNSSEC required).")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("require-strict-dns")
.long("require-strict-dns")
.help("Require strict DNSSEC validation; if domain missing, fail.")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("ignore-dns")
.long("ignore-dns")
.help("Ignore DNS validation entirely.")
.action(ArgAction::SetTrue),
)
.arg(Arg::new("domain").long("domain").value_parser(value_parser!(String)))
.arg(Arg::new("agent-id").long("agent-id").value_parser(value_parser!(String)))
.arg(Arg::new("ttl").long("ttl").value_parser(value_parser!(u32)).default_value("3600"))
.arg(Arg::new("encoding").long("encoding").value_parser(["base64","hex"]).default_value("base64"))
.arg(Arg::new("provider").long("provider").value_parser(["plain","aws","azure","cloudflare"]).default_value("plain"))
)
.subcommand(
Command::new("create")
.about(" create an agent")
.arg(
Arg::new("filename")
.short('f')
.help("Name of the json file with agent schema and jacsAgentType")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("create-keys")
.long("create-keys")
.required(true)
.help("Create keys or not if they already exist. Configure key type in jacs.config.json")
.value_parser(value_parser!(bool)),
),
)
.subcommand(
Command::new("verify")
.about(" verify an agent")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("no-dns")
.long("no-dns")
.help("Disable DNS validation; rely on embedded fingerprint")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("require-dns")
.long("require-dns")
.help("Require DNS validation; if domain missing, fail. Not strict (no DNSSEC required).")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("require-strict-dns")
.long("require-strict-dns")
.help("Require strict DNSSEC validation; if domain missing, fail.")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("ignore-dns")
.long("ignore-dns")
.help("Ignore DNS validation entirely.")
.action(ArgAction::SetTrue),
),
)
.subcommand(
Command::new("lookup")
.about("Look up another agent's public key and DNS info from their domain")
.arg(
Arg::new("domain")
.required(true)
.help("Domain to look up (e.g., agent.example.com)"),
)
.arg(
Arg::new("no-dns")
.long("no-dns")
.help("Skip DNS TXT record lookup")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("strict")
.long("strict")
.help("Require DNSSEC validation for DNS lookup")
.action(ArgAction::SetTrue),
),
)
.subcommand(
Command::new("rotate-keys")
.about("Rotate the agent's cryptographic keys")
.arg(
Arg::new("algorithm")
.long("algorithm")
.value_parser(["ring-Ed25519", "pq2025"])
.help("Signing algorithm for the new keys (defaults to current)"),
)
.arg(
Arg::new("config")
.long("config")
.value_parser(value_parser!(String))
.help("Path to jacs.config.json (default: ./jacs.config.json)"),
),
)
.subcommand(
Command::new("keys-list")
.about("List active and archived key files")
.arg(
Arg::new("config")
.long("config")
.value_parser(value_parser!(String))
.help("Path to jacs.config.json (default: ./jacs.config.json)"),
),
)
.subcommand(
Command::new("repair")
.about("Repair config after an interrupted key rotation")
.arg(
Arg::new("config")
.long("config")
.value_parser(value_parser!(String))
.help("Path to jacs.config.json (default: ./jacs.config.json)"),
),
),
)
.subcommand(
Command::new("task")
.about(" work with a JACS Agent task")
.subcommand(
Command::new("create")
.about(" create a new JACS Task file, either by embedding or parsing a document")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.help("Path to input file. Must be JSON")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("name")
.short('n')
.required(true)
.help("name of task")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("description")
.short('d')
.required(true)
.help("description of task")
.value_parser(value_parser!(String)),
)
)
.subcommand(
Command::new("update")
.about("update an existing task document")
.arg(
Arg::new("filename")
.short('f')
.required(true)
.help("Path to the updated task JSON file")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("task-key")
.short('k')
.required(true)
.help("Task document key (id:version)")
.value_parser(value_parser!(String)),
)
)
)
.subcommand(
Command::new("document")
.about(" work with a general JACS document")
.subcommand(
Command::new("create")
.about(" create a new JACS file, either by embedding or parsing a document")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.help("Path to input file. Must be JSON")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("output")
.short('o')
.help("Output filename. ")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-save")
.long("no-save")
.short('n')
.help("Instead of saving files, print to stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to create")
.long("schema")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("attach")
.help("Path to file or directory for file attachments")
.long("attach")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("embed")
.short('e')
.help("Embed documents or keep the documents external")
.long("embed")
.value_parser(value_parser!(bool)),
),
)
.subcommand(
Command::new("update")
.about("create a new version of document. requires both the original JACS file and the modified jacs metadata")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("new")
.short('n')
.required(true)
.help("Path to new version of document.")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.required(true)
.help("Path to original document.")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("output")
.short('o')
.help("Output filename. Filenames will always end with \"json\"")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-save")
.long("no-save")
.short('n')
.help("Instead of saving files, print to stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to create")
.long("schema")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("attach")
.help("Path to file or directory for file attachments")
.long("attach")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("embed")
.short('e')
.help("Embed documents or keep the documents external")
.long("embed")
.value_parser(value_parser!(bool)),
)
,
)
.subcommand(
Command::new("check-agreement")
.about("given a document, provide alist of agents that should sign document")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.required(true)
.help("Path to original document.")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to create")
.long("schema")
.value_parser(value_parser!(String)),
)
)
.subcommand(
Command::new("create-agreement")
.about("given a document, provide alist of agents that should sign document")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.required(true)
.help("Path to original document.")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("agentids")
.short('i')
.long("agentids")
.value_name("VALUES")
.help("Comma-separated list of agent ids")
.value_delimiter(',')
.required(true)
.action(clap::ArgAction::Set),
)
.arg(
Arg::new("output")
.short('o')
.help("Output filename. Filenames will always end with \"json\"")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-save")
.long("no-save")
.short('n')
.help("Instead of saving files, print to stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to create")
.long("schema")
.value_parser(value_parser!(String)),
)
).subcommand(
Command::new("sign-agreement")
.about("given a document, sign the agreement section")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.required(true)
.help("Path to original document.")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("output")
.short('o')
.help("Output filename. Filenames will always end with \"json\"")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-save")
.long("no-save")
.short('n')
.help("Instead of saving files, print to stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to create")
.long("schema")
.value_parser(value_parser!(String)),
)
)
.subcommand(
Command::new("verify")
.about(" verify a documents hash, siginatures, and schema")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.help("Path to input file. Must be JSON")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to validate")
.long("schema")
.value_parser(value_parser!(String)),
),
)
.subcommand(
Command::new("extract")
.about(" given documents, extract embedded contents if any")
.arg(
Arg::new("agent-file")
.short('a')
.help("Path to the agent file. Otherwise use config jacs_agent_id_and_version")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("filename")
.short('f')
.help("Path to input file. Must be JSON")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("directory")
.short('d')
.help("Path to directory of files. Files should end with .json")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("schema")
.short('s')
.help("Path to JSON schema file to use to validate")
.long("schema")
.value_parser(value_parser!(String)),
),
)
)
.subcommand(
Command::new("key")
.about("Work with JACS cryptographic keys")
.subcommand(
Command::new("reencrypt")
.about("Re-encrypt the private key with a new password")
)
)
.subcommand(
Command::new("mcp")
.about("Start the built-in JACS MCP server (stdio transport)")
.arg(
Arg::new("profile")
.long("profile")
.default_value("core")
.help("Tool profile: 'core' (default, core tools) or 'full' (all tools)"),
)
.subcommand(
Command::new("install")
.about("Deprecated: MCP is now built into the jacs binary")
.hide(true)
)
.subcommand(
Command::new("run")
.about("Deprecated: use `jacs mcp` directly")
.hide(true)
),
)
.subcommand(
Command::new("a2a")
.about("A2A (Agent-to-Agent) trust and discovery commands")
.subcommand(
Command::new("assess")
.about("Assess trust level of a remote A2A Agent Card")
.arg(
Arg::new("source")
.required(true)
.help("Path to Agent Card JSON file or URL"),
)
.arg(
Arg::new("policy")
.long("policy")
.short('p')
.value_parser(["open", "verified", "strict"])
.default_value("verified")
.help("Trust policy to apply (default: verified)"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
),
)
.subcommand(
Command::new("trust")
.about("Add a remote A2A agent to the local trust store")
.arg(
Arg::new("source")
.required(true)
.help("Path to Agent Card JSON file or URL"),
),
)
.subcommand(
Command::new("discover")
.about("Discover a remote A2A agent via its well-known Agent Card")
.arg(
Arg::new("url")
.required(true)
.help("Base URL of the agent (e.g. https://agent.example.com)"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output the full Agent Card as JSON"),
)
.arg(
Arg::new("policy")
.long("policy")
.short('p')
.value_parser(["open", "verified", "strict"])
.default_value("verified")
.help("Trust policy to apply against the discovered card"),
),
)
.subcommand(
Command::new("serve")
.about("Serve this agent's .well-known endpoints for A2A discovery")
.arg(
Arg::new("port")
.long("port")
.value_parser(value_parser!(u16))
.default_value("8080")
.help("Port to listen on (default: 8080)"),
)
.arg(
Arg::new("host")
.long("host")
.default_value("127.0.0.1")
.help("Host to bind to (default: 127.0.0.1)"),
),
)
.subcommand(
Command::new("quickstart")
.about("Create/load an agent and start serving A2A endpoints (password required)")
.after_help(quickstart_password_bootstrap_help())
.arg(
Arg::new("name")
.long("name")
.value_parser(value_parser!(String))
.required(true)
.help("Agent name used for first-time quickstart creation"),
)
.arg(
Arg::new("domain")
.long("domain")
.value_parser(value_parser!(String))
.required(true)
.help("Agent domain used for DNS/public-key verification workflows"),
)
.arg(
Arg::new("description")
.long("description")
.value_parser(value_parser!(String))
.help("Optional human-readable agent description"),
)
.arg(
Arg::new("port")
.long("port")
.value_parser(value_parser!(u16))
.default_value("8080")
.help("Port to listen on (default: 8080)"),
)
.arg(
Arg::new("host")
.long("host")
.default_value("127.0.0.1")
.help("Host to bind to (default: 127.0.0.1)"),
)
.arg(
Arg::new("algorithm")
.long("algorithm")
.short('a')
.value_parser(["pq2025", "ring-Ed25519"])
.help("Signing algorithm (default: pq2025)"),
),
),
)
.subcommand(
Command::new("quickstart")
.about("Create or load a persistent agent for instant sign/verify (password required)")
.after_help(quickstart_password_bootstrap_help())
.arg(
Arg::new("name")
.long("name")
.value_parser(value_parser!(String))
.required(true)
.help("Agent name used for first-time quickstart creation"),
)
.arg(
Arg::new("domain")
.long("domain")
.value_parser(value_parser!(String))
.required(true)
.help("Agent domain used for DNS/public-key verification workflows"),
)
.arg(
Arg::new("description")
.long("description")
.value_parser(value_parser!(String))
.help("Optional human-readable agent description"),
)
.arg(
Arg::new("algorithm")
.long("algorithm")
.short('a')
.value_parser(["ed25519", "pq2025"])
.default_value("pq2025")
.help("Signing algorithm (default: pq2025)"),
)
.arg(
Arg::new("sign")
.long("sign")
.help("Sign JSON from stdin and print signed document to stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("file")
.short('f')
.long("file")
.value_parser(value_parser!(String))
.help("Sign a JSON file instead of reading from stdin (used with --sign)"),
)
)
.subcommand(
Command::new("init")
.about("Initialize JACS by creating both config and agent (with keys)")
.arg(
Arg::new("yes")
.long("yes")
.short('y')
.action(ArgAction::SetTrue)
.help("Automatically set the new agent ID in jacs.config.json without prompting"),
)
)
.subcommand(
Command::new("attest")
.about("Create and verify attestation documents")
.subcommand(
Command::new("create")
.about("Create a signed attestation")
.arg(
Arg::new("subject-type")
.long("subject-type")
.value_parser(["agent", "artifact", "workflow", "identity"])
.help("Type of subject being attested"),
)
.arg(
Arg::new("subject-id")
.long("subject-id")
.value_parser(value_parser!(String))
.help("Identifier of the subject"),
)
.arg(
Arg::new("subject-digest")
.long("subject-digest")
.value_parser(value_parser!(String))
.help("SHA-256 digest of the subject"),
)
.arg(
Arg::new("claims")
.long("claims")
.value_parser(value_parser!(String))
.required(true)
.help("JSON array of claims, e.g. '[{\"name\":\"reviewed\",\"value\":true}]'"),
)
.arg(
Arg::new("evidence")
.long("evidence")
.value_parser(value_parser!(String))
.help("JSON array of evidence references"),
)
.arg(
Arg::new("from-document")
.long("from-document")
.value_parser(value_parser!(String))
.help("Lift attestation from an existing signed document file"),
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.value_parser(value_parser!(String))
.help("Write attestation to file instead of stdout"),
),
)
.subcommand(
Command::new("verify")
.about("Verify an attestation document")
.arg(
Arg::new("file")
.help("Path to the attestation JSON file")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("full")
.long("full")
.action(ArgAction::SetTrue)
.help("Use full verification (evidence + derivation chain)"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
)
.arg(
Arg::new("key-dir")
.long("key-dir")
.value_parser(value_parser!(String))
.help("Directory containing public keys for verification"),
)
.arg(
Arg::new("max-depth")
.long("max-depth")
.value_parser(value_parser!(u32))
.help("Maximum derivation chain depth"),
),
)
.subcommand(
Command::new("export-dsse")
.about("Export an attestation as a DSSE envelope for in-toto/SLSA")
.arg(
Arg::new("file")
.help("Path to the signed attestation JSON file")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.value_parser(value_parser!(String))
.help("Write DSSE envelope to file instead of stdout"),
),
)
.subcommand_required(true)
.arg_required_else_help(true),
)
.subcommand(
Command::new("verify")
.about("Verify a signed JACS document (no agent required)")
.arg(
Arg::new("file")
.help("Path to the signed JACS JSON file")
.required_unless_present("remote")
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("remote")
.long("remote")
.value_parser(value_parser!(String))
.help("Fetch document from URL before verifying"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
)
.arg(
Arg::new("key-dir")
.long("key-dir")
.value_parser(value_parser!(String))
.help("Directory containing public keys for verification"),
)
);
// OS keychain subcommand (only when keychain feature is enabled)
#[cfg(feature = "keychain")]
let cmd = cmd.subcommand(
Command::new("keychain")
.about("Manage private key passwords in the OS keychain (per-agent)")
.subcommand(
Command::new("set")
.about("Store a password in the OS keychain for an agent")
.arg(
Arg::new("agent-id")
.long("agent-id")
.help("Agent ID to associate the password with")
.value_name("AGENT_ID")
.required(true),
)
.arg(
Arg::new("password")
.long("password")
.help("Password to store (if omitted, prompts interactively)")
.value_name("PASSWORD"),
),
)
.subcommand(
Command::new("get")
.about("Retrieve the stored password for an agent (prints to stdout)")
.arg(
Arg::new("agent-id")
.long("agent-id")
.help("Agent ID to look up")
.value_name("AGENT_ID")
.required(true),
),
)
.subcommand(
Command::new("delete")
.about("Remove the stored password for an agent from the OS keychain")
.arg(
Arg::new("agent-id")
.long("agent-id")
.help("Agent ID whose password to delete")
.value_name("AGENT_ID")
.required(true),
),
)
.subcommand(
Command::new("status")
.about("Check if a password is stored for an agent in the OS keychain")
.arg(
Arg::new("agent-id")
.long("agent-id")
.help("Agent ID to check")
.value_name("AGENT_ID")
.required(true),
),
)
.arg_required_else_help(true),
);
let cmd = cmd.subcommand(
Command::new("convert")
.about(
"Convert JACS documents between JSON, YAML, and HTML formats (no agent required)",
)
.arg(
Arg::new("to")
.long("to")
.required(true)
.value_parser(["json", "yaml", "html"])
.help("Target format: json, yaml, or html"),
)
.arg(
Arg::new("from")
.long("from")
.value_parser(["json", "yaml", "html"])
.help("Source format (auto-detected from extension if omitted)"),
)
.arg(
Arg::new("file")
.short('f')
.long("file")
.required(true)
.value_parser(value_parser!(String))
.help("Input file path (use '-' for stdin)"),
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.value_parser(value_parser!(String))
.help("Output file path (defaults to stdout)"),
),
);
// Inline text + media verbs (Task 08, PRD §3.1 / §3.2 / §4.1 / §4.2).
let cmd = cmd
.subcommand(
Command::new("sign-text")
.about("Sign a text/markdown file in place with an inline JACS signature")
.arg(
Arg::new("file")
.help("Path to the text file to sign in place")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("no-backup")
.long("no-backup")
.action(ArgAction::SetTrue)
.help("Skip the automatic <path>.bak backup"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
),
)
.subcommand(
Command::new("verify-text")
.about("Verify inline JACS signatures in a text/markdown file")
.arg(
Arg::new("file")
.help("Path to the signed text file")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("key-dir")
.long("key-dir")
.value_parser(value_parser!(String))
.help("Directory containing signer public keys (.public.pem)"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
)
.arg(
Arg::new("strict")
.long("strict")
.action(ArgAction::SetTrue)
.help(
"Treat 'no JACS signature found' as a hard failure (exits 1 instead of 2)",
),
),
)
.subcommand(
Command::new("sign-image")
.about("Sign an image (PNG, JPEG, WebP) by embedding a JACS signature")
.arg(
Arg::new("input")
.help("Path to the input image")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("out")
.long("out")
.required(true)
.value_parser(value_parser!(String))
.help("Output image path"),
)
.arg(
Arg::new("robust")
.long("robust")
.action(ArgAction::SetTrue)
.help("Enable LSB fallback encoding (modifies pixel data; PNG/JPEG only)"),
)
.arg(
Arg::new("format")
.long("format")
.value_parser(["png", "jpeg", "webp"])
.help("Force a specific format (auto-detected by default)"),
)
.arg(
Arg::new("refuse-overwrite")
.long("refuse-overwrite")
.action(ArgAction::SetTrue)
.help("Refuse to overwrite an existing JACS signature on the input"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
),
)
.subcommand(
Command::new("verify-image")
.about("Verify an embedded JACS signature in an image")
.arg(
Arg::new("file")
.help("Path to the signed image")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("key-dir")
.long("key-dir")
.value_parser(value_parser!(String))
.help("Directory containing signer public keys (.public.pem)"),
)
.arg(
Arg::new("json")
.long("json")
.action(ArgAction::SetTrue)
.help("Output result as JSON"),
)
.arg(
Arg::new("strict")
.long("strict")
.action(ArgAction::SetTrue)
.help(
"Treat 'no JACS signature found' as a hard failure (exits 1 instead of 2)",
),
)
.arg(
Arg::new("robust")
.long("robust")
.action(ArgAction::SetTrue)
.help("Scan LSB channel for the robust-mode payload (default off)"),
),
)
.subcommand(
Command::new("extract-media-signature")
.about("Extract the embedded JACS signature payload from an image")
.arg(
Arg::new("file")
.help("Path to the image to extract from")
.required(true)
.value_parser(value_parser!(String)),
)
.arg(
Arg::new("raw-payload")
.long("raw-payload")
.action(ArgAction::SetTrue)
.help(
"Print the raw base64url wire form instead of the decoded JSON",
),
)
.arg(
Arg::new("robust")
.long("robust")
.action(ArgAction::SetTrue)
.help(
"Scan the LSB channel as a fallback if the metadata channel has \
no payload (R-011; mirrors verify-image --robust)",
),
),
);
cmd
}