-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
3132 lines (2775 loc) · 109 KB
/
Copy pathmain.rs
File metadata and controls
3132 lines (2775 loc) · 109 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
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
//! panic-attack: Universal stress testing and logic-based bug signature detection
//!
//! A tool for stress testing programs across multiple attack axes (CPU, memory, disk, network,
//! concurrency) and detecting bug signatures using logic programming techniques inspired by
//! Mozart/Oz and Datalog.
mod a2ml;
mod abduct;
mod adjudicate;
mod aggregate;
mod ambush;
mod amuck;
mod assail;
mod assay;
mod assemblyline;
mod attack;
mod attestation;
mod axial;
#[cfg(feature = "http")]
mod bridge;
mod campaign;
mod comment_marker;
mod diagnostics;
mod ffi_kind;
mod groove;
mod i18n;
mod jit_context;
mod kanren;
mod kin;
mod mass_panic;
mod notify;
mod panll;
mod query;
mod report;
mod signatures;
mod storage;
mod sweep_tracker;
mod test_context;
mod types;
extern crate walkdir;
use crate::a2ml::{Manifest, ReportBundleKind};
use crate::abduct::{
AbductConfig, DependencyScope, ExecutionCommand as AbductExecutionCommand, TimeMode,
};
use crate::adjudicate::AdjudicateConfig;
use crate::aggregate::{AggregateConfig, ProofInput};
use crate::amuck::{AmuckConfig, AmuckPreset, ExecutionCommand as AmuckExecutionCommand};
use crate::assay::{AssayConfig, AssimilateConfig};
use crate::attack::AttackProfile;
use crate::axial::{AxialConfig, ExecutionCommand as AxialExecutionCommand};
use crate::i18n::Lang;
use crate::report::{format_diff, load_report, ReportOutputFormat, ReportTui, ReportView};
use crate::storage::{latest_reports, persist_report};
use anyhow::{anyhow, Context, Result};
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell};
use clap_complete_nushell::Nushell;
use std::collections::HashMap;
use std::fs::{self, File};
use std::io::{self, Read, Write};
use std::path::{Path, PathBuf};
use std::time::Duration;
/// Upper bound on report JSON reads in the CLI. Reports are aggregated
/// scan outputs; 64 MiB is two orders of magnitude beyond any realistic
/// size and bounds tampered or malformed input before parsing.
const REPORT_FILE_READ_LIMIT: u64 = 64 * 1024 * 1024;
/// Read a file into a String, capped at `limit` bytes. Silent-truncates
/// if the file is larger; returns I/O errors as-is via `?`.
fn read_report_bounded(path: &Path) -> Result<String> {
let mut buf = String::new();
File::open(path)
.with_context(|| format!("opening {}", path.display()))?
.take(REPORT_FILE_READ_LIMIT)
.read_to_string(&mut buf)
.with_context(|| format!("reading {}", path.display()))?;
Ok(buf)
}
use types::*;
macro_rules! qprintln {
($quiet:expr, $($arg:tt)+) => {
if !$quiet {
println!($($arg)+);
}
};
}
#[derive(Parser)]
#[command(name = "panic-attack")]
#[command(version)]
#[command(about = "Universal stress testing and logic-based bug signature detection")]
#[command(long_about = None)]
#[command(disable_help_subcommand = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(long, value_enum, default_value_t = ReportView::Accordion, global = true)]
report_view: ReportView,
#[arg(long, default_value_t = false, global = true)]
expand_sections: bool,
#[arg(long, value_enum, default_value_t = ReportOutputFormat::Json, global = true)]
output_format: ReportOutputFormat,
#[arg(long, default_value_t = false, global = true)]
pivot: bool,
#[arg(long, value_name = "DIR", global = true)]
store: Option<PathBuf>,
#[arg(long, default_value_t = false, global = true)]
quiet: bool,
#[arg(long, default_value_t = false, global = true)]
parallel: bool,
}
#[derive(Subcommand)]
enum Commands {
/// Run assail static analysis on a target program
Assail {
/// Target program or directory to analyze
#[arg(value_name = "TARGET")]
target: PathBuf,
/// Output report to file
#[arg(short, long)]
output: Option<PathBuf>,
/// Verbose output
#[arg(short, long)]
verbose: bool,
/// Enable attestation chain (writes .attestation.json sidecar)
#[arg(long, default_value_t = false)]
attest: bool,
/// Path to Ed25519 private key (32-byte seed) for signing the attestation.
/// Requires the `signing` feature.
#[arg(long, value_name = "PATH")]
signing_key: Option<PathBuf>,
/// Browser extension mode: ignore DevTools API eval() usage
#[arg(long, default_value_t = false)]
browser_extension: bool,
/// Headless mode: emit JSON to stdout, suppress interactive prompts (CI-safe)
#[arg(long, default_value_t = false)]
headless: bool,
},
/// Execute a single attack on a target program
Attack {
/// Target program to attack
#[arg(value_name = "PROGRAM")]
program: PathBuf,
/// Attack profile file (json/yaml)
#[arg(long, value_name = "PROFILE")]
profile: Option<PathBuf>,
/// Extra argument(s) passed to the target program
#[arg(long = "arg", value_name = "ARG", action = clap::ArgAction::Append)]
args: Vec<String>,
/// Axis-specific argument, format: AXIS=ARG
#[arg(long = "axis-arg", value_name = "AXIS=ARG", action = clap::ArgAction::Append)]
axis_args: Vec<String>,
/// Probe mode for detecting unsupported flags
#[arg(long, value_enum)]
probe: Option<ProbeModeArg>,
/// Attack axis to use
#[arg(short, long, value_enum)]
axis: AttackAxisArg,
/// Attack intensity
#[arg(short, long, default_value = "medium")]
intensity: IntensityArg,
/// Attack duration in seconds
#[arg(short, long, default_value = "60")]
duration: u64,
},
/// Full assault: combines static analysis (`assail`) with multi-axis dynamic attacks (`attack`).
Assault {
/// Target program to assault
#[arg(value_name = "PROGRAM")]
program: PathBuf,
/// Source directory or file for assail analysis (defaults to PROGRAM)
#[arg(long, value_name = "PATH")]
source: Option<PathBuf>,
/// Attack profile file (json/yaml)
#[arg(long, value_name = "PROFILE")]
profile: Option<PathBuf>,
/// Extra argument(s) passed to the target program
#[arg(long = "arg", value_name = "ARG", action = clap::ArgAction::Append)]
args: Vec<String>,
/// Axis-specific argument, format: AXIS=ARG
#[arg(long = "axis-arg", value_name = "AXIS=ARG", action = clap::ArgAction::Append)]
axis_args: Vec<String>,
/// Probe mode for detecting unsupported flags
#[arg(long, value_enum)]
probe: Option<ProbeModeArg>,
/// Attack axes (default: all)
#[arg(short, long, value_delimiter = ',')]
axes: Option<Vec<AttackAxisArg>>,
/// Attack intensity
#[arg(short, long, default_value = "medium")]
intensity: IntensityArg,
/// Attack duration per axis in seconds
#[arg(short, long, default_value = "30")]
duration: u64,
/// Output report to file
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Ambush: run a target program while applying ambient stressors
Ambush {
/// Target program to ambush
#[arg(value_name = "PROGRAM")]
program: PathBuf,
/// Source directory or file for assail analysis (defaults to PROGRAM)
#[arg(long, value_name = "PATH")]
source: Option<PathBuf>,
/// Timeline file (JSON/YAML) for DAW-style scheduling
#[arg(long, value_name = "TIMELINE")]
timeline: Option<PathBuf>,
/// Attack profile file (json/yaml) for target args
#[arg(long, value_name = "PROFILE")]
profile: Option<PathBuf>,
/// Extra argument(s) passed to the target program
#[arg(long = "arg", value_name = "ARG", action = clap::ArgAction::Append)]
args: Vec<String>,
/// Axis-specific argument, format: AXIS=ARG
#[arg(long = "axis-arg", value_name = "AXIS=ARG", action = clap::ArgAction::Append)]
axis_args: Vec<String>,
/// Stress axes to apply (default: all)
#[arg(short, long, value_delimiter = ',')]
axes: Option<Vec<AttackAxisArg>>,
/// Stress intensity
#[arg(short, long, default_value = "medium")]
intensity: IntensityArg,
/// Ambush duration per axis in seconds
#[arg(short, long, default_value = "30")]
duration: u64,
/// Output report to file
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Amuck: mutate a file with dangerous/user-defined combinations and optionally execute checks
Amuck {
/// Target file to mutate (never modified in place)
#[arg(value_name = "TARGET")]
target: PathBuf,
/// Mutation preset when no --spec is provided
#[arg(long, value_enum, default_value = "dangerous")]
preset: AmuckPresetArg,
/// Custom mutation combinations file (json/yaml)
#[arg(long, value_name = "SPEC")]
spec: Option<PathBuf>,
/// Maximum combinations to execute
#[arg(long, default_value_t = 16)]
max_combinations: usize,
/// Directory where mutated variants are written
#[arg(long, value_name = "DIR", default_value = "runtime/amuck")]
output_dir: PathBuf,
/// Optional executable run per mutated file
#[arg(long, value_name = "PROGRAM")]
exec_program: Option<String>,
/// Arguments for --exec-program; use {file} for the mutated file path
#[arg(long = "exec-arg", value_name = "ARG", action = clap::ArgAction::Append)]
exec_args: Vec<String>,
/// Optional report output path (JSON)
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Abduct: isolate, lock, and time-skew a target file (optionally with dependencies)
Abduct {
/// Target file to abduct into an isolated workspace
#[arg(value_name = "TARGET")]
target: PathBuf,
/// Optional source root used to resolve dependency graph paths
#[arg(long, value_name = "PATH")]
source_root: Option<PathBuf>,
/// Dependency scope for selecting related files
#[arg(long, value_enum, default_value = "direct")]
scope: AbductScopeArg,
/// Workspace root where abduct runs are created
#[arg(long, value_name = "DIR", default_value = "runtime/abduct")]
output_dir: PathBuf,
/// Disable readonly lock-down of copied files
#[arg(long, default_value_t = false)]
no_lock: bool,
/// Shift copied file mtimes by this many days (negative or positive)
#[arg(long, default_value_t = 0)]
mtime_offset_days: i64,
/// Time mode metadata exported to executed process
#[arg(long, value_enum, default_value = "normal")]
time_mode: AbductTimeModeArg,
/// Virtual time scale factor when --time-mode slow
#[arg(long, default_value_t = 0.1)]
time_scale: f64,
/// Optional virtual timestamp (RFC3339) exported as ABDUCT_VIRTUAL_NOW
#[arg(long, value_name = "TIMESTAMP")]
virtual_now: Option<String>,
/// Optional executable to run after lock/time setup
#[arg(long, value_name = "PROGRAM")]
exec_program: Option<String>,
/// Arguments for --exec-program; placeholders: {file}, {workspace}
#[arg(long = "exec-arg", value_name = "ARG", action = clap::ArgAction::Append)]
exec_args: Vec<String>,
/// Timeout (seconds) for the optional execution command
#[arg(long, default_value_t = 120)]
exec_timeout: u64,
/// Optional report output path (JSON)
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Adjudicate: aggregate reports into a campaign-wide expert-system verdict
Adjudicate {
/// Input report files (assault/amuck/abduct JSON, assault YAML)
#[arg(value_name = "REPORTS", required = true)]
reports: Vec<PathBuf>,
/// Optional report output path (JSON)
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Axial: observe target reactions across attack axes from tool outputs and report artifacts
Axial {
/// Target file/program under observation
#[arg(value_name = "TARGET")]
target: PathBuf,
/// Optional executable to run for reaction observation
#[arg(long, value_name = "PROGRAM")]
exec_program: Option<String>,
/// Arguments for --exec-program; placeholder: {target}
#[arg(long = "exec-arg", value_name = "ARG", action = clap::ArgAction::Append)]
exec_args: Vec<String>,
/// Number of repeated observation runs for --exec-program
#[arg(long, default_value_t = 1)]
repeat: usize,
/// Timeout (seconds) per observation run
#[arg(long, default_value_t = 60)]
timeout: u64,
/// Existing reports to observe (can be provided multiple times)
#[arg(long = "report", value_name = "PATH", action = clap::ArgAction::Append)]
reports: Vec<PathBuf>,
/// Include the first N lines from observed output/content
#[arg(long, default_value_t = 20)]
head: usize,
/// Include the last N lines from observed output/content
#[arg(long, default_value_t = 20)]
tail: usize,
/// Exact pattern search (repeatable)
#[arg(long = "grep", value_name = "PATTERN", action = clap::ArgAction::Append)]
grep: Vec<String>,
/// Approximate/fuzzy pattern search (repeatable)
#[arg(long = "agrep", value_name = "PATTERN", action = clap::ArgAction::Append)]
agrep: Vec<String>,
/// Maximum edit distance for --agrep matches
#[arg(long, default_value_t = 2)]
agrep_distance: usize,
/// Output language (ISO 639-1 code: en, es, fr, de, ja)
#[arg(long, value_enum, default_value = "en")]
lang: LangArg,
/// Enable aspell checks on observed text
#[arg(long, default_value_t = false)]
aspell: bool,
/// Aspell dictionary language (default derived from --lang)
#[arg(long, value_name = "CODE")]
aspell_lang: Option<String>,
/// Optional markdown output path
#[arg(long, value_name = "OUT")]
markdown_output: Option<PathBuf>,
/// Optional pandoc target format (e.g. html, docx, gfm, latex)
#[arg(long, value_name = "FMT")]
pandoc_to: Option<String>,
/// Optional pandoc output path (required for custom destination)
#[arg(long, value_name = "OUT")]
pandoc_output: Option<PathBuf>,
/// Optional report output path (JSON)
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Assay: survey a target for proven-library substitution candidates.
///
/// Scans the target for code that has a formally proven drop-in
/// equivalent in a `proven` / `proven-servers` library and reports each
/// swap candidate with the proof artifact that backs it. Operationalises
/// the "Proven cross-fit" section of PROOF-PROGRAMME.md.
Assay {
/// Target directory to survey (default: current directory)
#[arg(value_name = "TARGET", default_value = ".")]
target: PathBuf,
/// Local checkout of a proven / proven-servers library to resolve
/// replacement sources from (repeatable)
#[arg(long = "proven", value_name = "DIR", action = clap::ArgAction::Append)]
proven: Vec<PathBuf>,
/// Output report to file (JSON)
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Assimilate: apply a proven-library substitution found by `assay`.
///
/// Stages the proven module into the tree (backing up the original) and
/// records provenance — source BLAKE3 hash + proof backing — under
/// `.assimilated/`. Call sites that still need manual rewiring are
/// reported, never auto-edited.
Assimilate {
/// Target directory (default: current directory)
#[arg(value_name = "TARGET", default_value = ".")]
target: PathBuf,
/// Local proven / proven-servers checkout(s) for replacement sources
#[arg(long = "proven", value_name = "DIR", action = clap::ArgAction::Append)]
proven: Vec<PathBuf>,
/// Candidate id to apply (run `assay` to list ids); omit with --all
#[arg(long, value_name = "ID")]
candidate: Option<String>,
/// Apply every offered candidate
#[arg(long, default_value_t = false)]
all: bool,
/// Explicit replacement source file (overrides catalogue resolution;
/// only valid with a single --candidate)
#[arg(long, value_name = "FILE")]
from: Option<PathBuf>,
/// Preview only: compute the swap but write nothing
#[arg(long, default_value_t = false)]
dry_run: bool,
/// Output outcome to file (JSON)
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Aggregate: fold external prover output into a report (hashed, trust-tagged).
///
/// Hashes each prover artifact (BLAKE3) for non-repudiation, classifies
/// its verdict (closed / holes / refuted), and reconciles it against an
/// existing report's findings (backed / corroborated / contradicted).
/// Verdicts are explicitly conditioned on the named checker's trust.
Aggregate {
/// External prover output file(s) to fold in (repeatable)
#[arg(long = "proof", value_name = "PATH", action = clap::ArgAction::Append, required = true)]
proofs: Vec<PathBuf>,
/// Friendly-name override(s): PATH=NAME (repeatable)
#[arg(long = "label", value_name = "PATH=NAME", action = clap::ArgAction::Append)]
labels: Vec<String>,
/// Coverage override(s): PATH=[claim:]kind:value (repeatable)
#[arg(long = "covers", value_name = "PATH=SPEC", action = clap::ArgAction::Append)]
covers: Vec<String>,
/// Base assail/assault report to reconcile against (optional)
#[arg(long = "report", value_name = "PATH")]
report: Option<PathBuf>,
/// Output report to file (JSON; default: reports/aggregate-<ts>.json)
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Analyze crash reports for bug signatures
Analyze {
/// Crash report file (JSON)
#[arg(value_name = "REPORT")]
report: PathBuf,
},
/// Render a saved assault report with view controls
Report {
/// JSON assault report path
#[arg(value_name = "REPORT")]
report: PathBuf,
},
/// Interactive review of a saved report
Tui {
/// Assault report JSON file
#[arg(value_name = "REPORT")]
report: PathBuf,
/// Headless mode: print sections as plain text without requiring a TTY (CI-safe)
#[arg(long, default_value_t = false)]
headless: bool,
},
/// GUI review of a saved report.
///
/// `--headless` always works (text panel summaries to stdout). The
/// windowed renderer requires `--features gui` at build time because
/// eframe/egui raise MSRV above 1.85.0.
Gui {
/// Assault report JSON file
#[arg(value_name = "REPORT")]
report: PathBuf,
/// Headless mode: print panel summaries without requiring a display server (CI-safe)
#[arg(long, default_value_t = false)]
headless: bool,
},
/// Compare two assault reports (defaults to latest VerisimDB runs)
Diff {
/// Base report path
#[arg(value_name = "BASE")]
base: Option<PathBuf>,
/// Compare report path
#[arg(value_name = "COMPARE")]
compare: Option<PathBuf>,
/// VerisimDB directory to scan for latest reports
#[arg(long, value_name = "DIR", default_value = "verisimdb-data/verisimdb")]
verisimdb_dir: PathBuf,
},
/// Export the AI manifest as Nickel
Manifest {
/// Alternate AI manifest file
#[arg(short, long, value_name = "PATH")]
path: Option<PathBuf>,
/// Save Nickel output to file
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Export a report file into the A2ML report-bundle document type
A2mlExport {
/// Report kind to encode in the bundle
#[arg(long, value_enum)]
kind: A2mlReportKindArg,
/// Source report file (json/yaml depending on kind)
#[arg(value_name = "INPUT")]
input: PathBuf,
/// Destination A2ML file
#[arg(short, long, value_name = "OUT")]
output: PathBuf,
},
/// Import an A2ML report-bundle file back into JSON
A2mlImport {
/// Source A2ML bundle file
#[arg(value_name = "INPUT")]
input: PathBuf,
/// Destination JSON file
#[arg(short, long, value_name = "OUT")]
output: PathBuf,
/// Optional expected kind check
#[arg(long, value_enum)]
kind: Option<A2mlReportKindArg>,
},
/// Export an assault report as a PanLL event-chain model
Panll {
/// Assault report JSON/YAML file
#[arg(value_name = "REPORT")]
report: PathBuf,
/// Output file for PanLL export (JSON)
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
},
/// Print detailed help text (man-style)
Help {
/// Optional subcommand name to display help for
#[arg(value_name = "COMMAND")]
command: Option<String>,
},
/// Assemblyline: batch-scan a directory of repos (assail each, aggregate results)
Assemblyline {
/// Parent directory containing repos to scan
#[arg(value_name = "DIRECTORY")]
directory: PathBuf,
/// Output report to file
#[arg(short, long)]
output: Option<PathBuf>,
/// Only show repos with findings
#[arg(long)]
findings_only: bool,
/// Minimum number of findings to include a repo
#[arg(long, default_value = "0")]
min_findings: usize,
/// Enable incremental scanning (skip repos unchanged since last run)
#[arg(long)]
incremental: bool,
/// Path to fingerprint cache file (default: .panic-attack-cache.json in DIRECTORY)
#[arg(long, value_name = "FILE")]
cache: Option<PathBuf>,
},
/// Run panic-attack self-diagnostics for Hypatia/gitbot-fleet visibility
Diagnostics {
/// Alternate AI manifest file (default: AI.a2ml)
#[arg(long, value_name = "PATH")]
manifest: Option<PathBuf>,
},
/// Take a ReScript migration snapshot (assail + migration metrics)
MigrationSnapshot {
/// Target ReScript project directory
#[arg(value_name = "TARGET")]
target: PathBuf,
/// Label for this snapshot (e.g. "before", "after", "v12-trial")
#[arg(long, value_name = "LABEL")]
label: String,
/// Measure build time (runs `rescript build`)
#[arg(long, default_value_t = false)]
build_time: bool,
/// Measure bundle size (scans output directory)
#[arg(long, default_value_t = false)]
bundle_size: bool,
/// Store snapshot as VeriSimDB hexad
#[arg(long = "store-hexad", default_value_t = false)]
store_hexad: bool,
/// Output snapshot to file
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Compare two migration snapshots and produce a diff report
MigrationDiff {
/// Before snapshot JSON file
#[arg(value_name = "BEFORE")]
before: PathBuf,
/// After snapshot JSON file
#[arg(value_name = "AFTER")]
after: PathBuf,
/// Output diff report to file
#[arg(short, long)]
output: Option<PathBuf>,
/// Output format (markdown or json)
#[arg(long, default_value = "markdown")]
format: MigrationDiffFormatArg,
},
/// Notify: generate annotated findings summary from an assemblyline report
Notify {
/// Assemblyline JSON report file
#[arg(value_name = "REPORT")]
report: PathBuf,
/// Output markdown file
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
/// Only include repos with critical findings
#[arg(long)]
critical_only: bool,
/// Minimum findings to include a repo
#[arg(long, default_value = "1")]
min_findings: usize,
/// Create GitHub issues for repos with critical findings (requires gh CLI)
#[arg(long)]
create_issues: bool,
/// GitHub owner for issue creation
#[arg(long, default_value = "hyperpolymath")]
github_owner: String,
},
/// Image: generate a system health image from an assemblyline scan (fNIRS-style)
Image {
/// Parent directory containing repos to scan (runs assemblyline internally)
#[arg(value_name = "DIRECTORY")]
directory: PathBuf,
/// Output file for the system image JSON
#[arg(short, long, value_name = "OUT")]
output: Option<PathBuf>,
/// Enable incremental scanning
#[arg(long)]
incremental: bool,
/// Fingerprint cache file
#[arg(long, value_name = "FILE")]
cache: Option<PathBuf>,
/// Take a temporal snapshot (writes to VeriSimDB)
#[arg(long)]
snapshot: bool,
/// Label for the temporal snapshot
#[arg(long, value_name = "LABEL", default_value = "")]
label: String,
/// VeriSimDB directory for snapshots
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
/// Export PanLL-format system image alongside raw output
#[arg(long)]
panll: bool,
},
/// Temporal: navigate system health through time (diff, list, replay)
Temporal {
#[command(subcommand)]
action: TemporalAction,
},
/// Patch Bridge: CVE triage with reachability analysis
#[cfg(feature = "http")]
Bridge {
#[command(subcommand)]
action: BridgeAction,
},
/// Generate shell completions for the specified shell
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: ShellArg,
},
/// Start the groove discovery server for service mesh integration.
///
/// Runs a lightweight HTTP server exposing panic-attacker's static-analysis
/// capabilities via the Gossamer groove protocol. Other groove-aware systems
/// (PanLL, Gossamer, Hypatia, etc.) can discover panic-attacker by probing
/// GET /.well-known/groove on the configured port.
Groove {
/// Port to bind the groove server to
#[arg(short, long, default_value = "7600")]
port: u16,
},
/// Compute the BLAKE3 fingerprint of a directory (for incremental scanning)
Fingerprint {
/// Directory to fingerprint (hashes all source files recursively)
#[arg(value_name = "DIR")]
dir: PathBuf,
},
/// Attestation utilities (verify chain integrity, check signatures)
Attest {
#[command(subcommand)]
action: AttestAction,
},
/// Campaign: lifecycle tracking for findings (register-pr, dismiss, status).
///
/// Operates on the per-finding hexad store written by `assemblyline` when
/// `PANIC_ATTACK_STORE_FINDING_HEXADS=1` is set with verisimdb storage.
Campaign {
#[command(subcommand)]
action: CampaignAction,
},
/// Sweep-tracker: render an issue-#32-style estate-sweep Markdown report.
///
/// Joins per-finding hexads (issue #33 S1) with campaign-state hexads
/// (issue #33 S2) and groups them by repo and/or category. Distinct
/// from `campaign status`: that is a flat per-finding table; this is
/// a hierarchical sweep checklist.
SweepTracker {
/// VeriSimDB data directory (default: `verisimdb-data`).
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
/// Write the Markdown to a file instead of stdout.
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
/// Emit only the "By repo" section.
#[arg(long, group = "sweep_shape", default_value_t = false)]
by_repo: bool,
/// Emit only the "By category" section.
#[arg(long, group = "sweep_shape", default_value_t = false)]
by_category: bool,
},
/// Query persisted findings + campaign state with a small S-expression
/// language (issue #33 S3). See `panic-attack query --help` for syntax.
Query {
/// Query expression, e.g. `(and (category UnsafeCode) (pr-state nil))`.
#[arg(value_name = "EXPR")]
expr: String,
/// VeriSimDB data directory (default: `verisimdb-data`).
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
/// Output format.
#[arg(long, value_enum, default_value_t = QueryFormatArg::Table)]
format: QueryFormatArg,
},
/// Emit a machine-readable description of the panic-attack CLI contract
/// (accepted flags per subcommand, report `schema_version`, CLI version)
/// for external orchestrators.
///
/// This is a generic capability — useful to Chapel mass-panic, Nextflow,
/// Airflow, Slurm, or any shell script that needs to discover the
/// panic-attack interface at runtime without coupling to its source.
/// The output schema is stable across patch releases.
DescribeContract,
/// Push a single hexad JSON file (written by the Chapel metalayer
/// `takeSnapshot` or any other producer) to a running `verisim-panic-api`
/// instance via HTTP `POST /octads`.
///
/// Reads the JSON hexad from `<HEXAD>`, deserialises it as a
/// `PanicAttackHexad`, and pushes it. Uses `$VERISIMDB_URL` if set,
/// otherwise defaults to `http://localhost:8080`.
///
/// On HTTP failure, the file is left in place — re-running the command
/// retries. With `--fallback-dir`, also writes a filesystem copy under
/// `<fallback-dir>/hexads/` so an offline orchestrator can replay later.
///
/// Requires the `http` Cargo feature to be enabled at build time.
/// Closes the v3.0.0 ROADMAP item "VeriSimDB HTTP push from Chapel
/// metalayer (currently file-only)".
#[cfg(feature = "http")]
VerisimPush {
/// Path to the JSON hexad file produced by the Chapel metalayer
/// (or any other producer that emits the canonical hexad schema).
#[arg(value_name = "HEXAD")]
hexad: PathBuf,
/// VeriSimDB gateway URL. Defaults to `$VERISIMDB_URL` if set,
/// otherwise `http://localhost:8080`.
#[arg(long, value_name = "URL")]
url: Option<String>,
/// Filesystem fallback directory. If specified, a copy of the
/// hexad is also written under `<dir>/hexads/<id>.json` so the
/// push survives an offline gateway. The local-only run on the
/// Chapel side already wrote to `verisimdb-data/hexads/`, so this
/// is typically left unset when the push is invoked from Chapel.
#[arg(long, value_name = "DIR")]
fallback_dir: Option<PathBuf>,
/// Retry on transient HTTP failures (network errors, 5xx). The
/// underlying `push_hexad_http_with_retry` exponential-backs off
/// up to three attempts.
#[arg(long, default_value_t = false)]
retry: bool,
},
}
#[derive(clap::ValueEnum, Clone, Debug)]
enum QueryFormatArg {
Table,
Json,
}
#[derive(Subcommand)]
enum AttestAction {
/// Verify an attestation sidecar file (.attestation.json)
Verify {
/// Path to the .attestation.json file
#[arg(value_name = "FILE")]
file: PathBuf,
},
}
/// Campaign subcommands for finding-lifecycle tracking (issue #33 S2).
#[derive(Subcommand)]
enum CampaignAction {
/// Register an open PR against a known finding-id.
RegisterPr {
/// Finding id (e.g. `finding:demo:src/a.rs:1:UnsafeCode`).
#[arg(value_name = "FINDING_ID")]
finding_id: String,
/// PR URL (e.g. `https://github.com/org/repo/pull/123`).
#[arg(value_name = "PR_URL")]
pr_url: String,
/// VeriSimDB data directory (default: `verisimdb-data`).
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
},
/// Mark a finding as dismissed (parked, known-good, out-of-scope).
Dismiss {
/// Finding id.
#[arg(value_name = "FINDING_ID")]
finding_id: String,
/// Short human-readable reason.
#[arg(value_name = "REASON")]
reason: String,
/// VeriSimDB data directory (default: `verisimdb-data`).
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
},
/// Render a Markdown tracker of the current campaign state.
Status {
/// VeriSimDB data directory (default: `verisimdb-data`).
#[arg(long, value_name = "DIR", default_value = "verisimdb-data")]
verisimdb_dir: PathBuf,
/// Write the Markdown to a file instead of stdout.
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
},