-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
7844 lines (7057 loc) · 266 KB
/
main.rs
File metadata and controls
7844 lines (7057 loc) · 266 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
use std::collections::HashSet;
use std::path::PathBuf;
use std::process::ExitCode;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use rivet_core::coverage;
use rivet_core::diff::{ArtifactDiff, DiagnosticDiff};
use rivet_core::document::{self, DocumentStore};
use rivet_core::impact;
use rivet_core::links::LinkGraph;
use rivet_core::matrix::{self, Direction};
use rivet_core::model::ProjectConfig;
use rivet_core::results::{self, ResultStore};
use rivet_core::schema::Severity;
use rivet_core::store::Store;
use rivet_core::validate;
mod docs;
mod mcp;
mod render;
mod schema_cmd;
mod serve;
fn build_version() -> &'static str {
use std::sync::LazyLock;
static VERSION: LazyLock<String> = LazyLock::new(|| {
let version = env!("CARGO_PKG_VERSION");
let commit = env!("RIVET_GIT_COMMIT");
let branch = env!("RIVET_GIT_BRANCH");
let dirty: bool = env!("RIVET_GIT_DIRTY").parse().unwrap_or(false);
let staged: u32 = env!("RIVET_GIT_STAGED").parse().unwrap_or(0);
let modified: u32 = env!("RIVET_GIT_MODIFIED").parse().unwrap_or(0);
let untracked: u32 = env!("RIVET_GIT_UNTRACKED").parse().unwrap_or(0);
let date = env!("RIVET_BUILD_DATE");
let mut s = format!("{version} ({commit} {branch} {date})");
if dirty {
let mut parts = Vec::new();
if staged > 0 {
parts.push(format!("{staged} staged"));
}
if modified > 0 {
parts.push(format!("{modified} modified"));
}
if untracked > 0 {
parts.push(format!("{untracked} untracked"));
}
if parts.is_empty() {
s.push_str(" [dirty]");
} else {
s.push_str(&format!(" [{}]", parts.join(", ")));
}
}
s
});
&VERSION
}
/// Spawn a background thread to check for newer releases on GitHub.
///
/// The check is rate-limited to once per day via a timestamp file under
/// the platform cache directory (`$XDG_CACHE_HOME`, `$HOME/.cache`,
/// or `%LOCALAPPDATA%` on Windows). The HTTP request has a 3-second
/// timeout so it never blocks startup.
fn check_for_updates() {
std::thread::spawn(|| {
// Resolve platform cache directory without the `dirs` crate.
let cache_dir = if cfg!(target_os = "windows") {
std::env::var_os("LOCALAPPDATA").map(PathBuf::from)
} else {
std::env::var_os("XDG_CACHE_HOME")
.map(PathBuf::from)
.or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))
};
let Some(base) = cache_dir else { return };
let cache = base.join("rivet").join("update-check");
// Bail early if we already checked within the last 24 hours.
if let Ok(meta) = std::fs::metadata(&cache) {
if let Ok(modified) = meta.modified() {
if modified.elapsed().unwrap_or_default() < std::time::Duration::from_secs(86400) {
return;
}
}
}
// Query the GitHub releases API (curl, 3-second timeout).
let Ok(output) = std::process::Command::new("curl")
.args([
"-s",
"-m",
"3",
"https://api.github.com/repos/pulseengine/rivet/releases/latest",
])
.output()
else {
return;
};
if !output.status.success() {
return;
}
let body = String::from_utf8_lossy(&output.stdout);
if let Some(tag) = body.split("\"tag_name\":\"").nth(1) {
if let Some(version) = tag.split('"').next() {
let current = env!("CARGO_PKG_VERSION");
let latest = version.trim_start_matches('v');
if latest != current && !current.contains("dev") {
eprintln!(
"hint: rivet {latest} available (current: {current}). \
Run: cargo install rivet-cli"
);
}
}
}
// Touch the cache file so we don't check again for 24 hours.
if let Some(parent) = cache.parent() {
std::fs::create_dir_all(parent).ok();
}
std::fs::write(&cache, "").ok();
});
}
#[derive(Parser)]
#[command(name = "rivet", about = "SDLC artifact traceability and validation", version = build_version())]
struct Cli {
/// Path to the project directory (containing rivet.yaml)
#[arg(short, long, default_value = ".")]
project: PathBuf,
/// Path to schemas directory
#[arg(long)]
schemas: Option<PathBuf>,
/// Increase verbosity
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Initialize a new rivet project
Init {
/// Project name (defaults to directory name)
#[arg(long)]
name: Option<String>,
/// Preset: dev (default), aspice, stpa, cybersecurity, aadl, do-178c, en-50128
/// Preset: dev (default), aspice, stpa, cybersecurity, aadl, iec-61508, iec-62304
#[arg(long, default_value = "dev")]
preset: String,
/// Schemas to include (overrides preset if given)
#[arg(long, value_delimiter = ',')]
schema: Vec<String>,
/// Directory to initialize (defaults to current directory)
#[arg(long, default_value = ".")]
dir: PathBuf,
/// Generate AGENTS.md (and CLAUDE.md shim) from current project state
#[arg(long)]
agents: bool,
},
/// Validate artifacts against schemas
Validate {
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
/// Use direct (non-incremental) validation instead of the default salsa path
#[arg(long)]
direct: bool,
/// Skip cross-repo validation (broken external refs, backlinks, circular deps, version conflicts)
#[arg(long)]
skip_external_validation: bool,
/// Scope validation to a named baseline (cumulative)
#[arg(long)]
baseline: Option<String>,
/// Track failure convergence across runs to detect agent retry loops
#[arg(long)]
track_convergence: bool,
},
/// Show a single artifact by ID
Get {
/// Artifact ID to retrieve
id: String,
/// Output format: "text" (default), "json", or "yaml"
#[arg(short, long, default_value = "text")]
format: String,
},
/// List artifacts, optionally filtered by type
List {
/// Filter by artifact type
#[arg(short = 't', long)]
r#type: Option<String>,
/// Filter by status
#[arg(short, long)]
status: Option<String>,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
/// Scope listing to a named baseline (cumulative)
#[arg(long)]
baseline: Option<String>,
},
/// Show artifact summary statistics
Stats {
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
/// Scope statistics to a named baseline (cumulative)
#[arg(long)]
baseline: Option<String>,
},
/// Show traceability coverage report
Coverage {
/// Output format: "table" (default) or "json"
#[arg(short, long, default_value = "table")]
format: String,
/// Exit with failure if overall coverage is below this percentage
#[arg(long)]
fail_under: Option<f64>,
/// Show test-to-requirement coverage from source markers
#[arg(long)]
tests: bool,
/// Directories to scan for test markers (default: src/ tests/)
#[arg(long = "scan-paths", value_delimiter = ',')]
scan_paths: Vec<PathBuf>,
/// Scope coverage to a named baseline (cumulative)
#[arg(long)]
baseline: Option<String>,
},
/// Generate a traceability matrix
Matrix {
/// Source artifact type
#[arg(long)]
from: String,
/// Target artifact type
#[arg(long)]
to: String,
/// Link type to trace (default: auto-detect)
#[arg(long)]
link: Option<String>,
/// Direction: "forward" or "backward"
#[arg(long, default_value = "backward")]
direction: String,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Load and validate STPA files directly (without rivet.yaml)
Stpa {
/// Path to STPA directory
path: PathBuf,
/// Path to STPA schema
#[arg(long)]
schema: Option<PathBuf>,
},
/// Compare two versions of artifacts and show what changed
Diff {
/// Path to the base artifact directory (older version)
#[arg(long)]
base: Option<PathBuf>,
/// Path to the head artifact directory (newer version)
#[arg(long)]
head: Option<PathBuf>,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Export artifacts to a specified format
Export {
/// Output format: "reqif", "generic-yaml", "html"
#[arg(short, long)]
format: String,
/// Output path: file for reqif/generic-yaml, directory for html (default: "dist")
#[arg(short, long)]
output: Option<PathBuf>,
/// Single-page mode: combine all HTML reports into one file (html format only)
#[arg(long)]
single_page: bool,
/// Theme: "dark" (PulseEngine, default) or "light" (clean for printing)
#[arg(long, default_value = "dark")]
theme: String,
/// Offline mode: use system fonts only (no Google Fonts)
#[arg(long)]
offline: bool,
/// URL for the home/back link, written to config.js (e.g. "https://pulseengine.eu/projects/")
#[arg(long)]
homepage: Option<String>,
/// Version label for config.js version switcher (default: from rivet.yaml or "dev")
#[arg(long)]
version_label: Option<String>,
/// JSON array of version entries for config.js switcher: [{"label":"v0.1.0","path":"../v0.1.0/"}]
#[arg(long)]
versions: Option<String>,
/// Scope export to a named baseline (cumulative)
#[arg(long)]
baseline: Option<String>,
},
/// Introspect loaded schemas (types, links, rules)
Schema {
#[command(subcommand)]
action: SchemaAction,
},
/// Built-in documentation (topics, search)
Docs {
/// Topic slug to display (omit for topic list)
topic: Option<String>,
/// Search across all docs (like grep)
#[arg(long)]
grep: Option<String>,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
/// Context lines around grep matches
#[arg(short = 'C', long, default_value = "2")]
context: usize,
},
/// Generate .rivet/agent-context.md from current project state
Context,
/// Validate a commit message for artifact trailers (pre-commit hook)
CommitMsgCheck {
/// Path to the commit message file
file: PathBuf,
},
/// Analyze git commit history for artifact traceability
Commits {
/// Only analyze commits after this date (YYYY-MM-DD)
#[arg(long)]
since: Option<String>,
/// Git revision range (e.g., "main..HEAD")
#[arg(long)]
range: Option<String>,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
/// Promote warnings to errors
#[arg(long)]
strict: bool,
},
/// Start the HTMX-powered dashboard server
Serve {
/// Port to listen on (0 = auto-assign)
#[arg(short = 'P', long, default_value = "3000")]
port: u16,
/// Address to bind to (default: 127.0.0.1, localhost only)
#[arg(short = 'B', long, default_value = "127.0.0.1")]
bind: String,
/// Watch filesystem for changes and auto-reload
#[arg(long)]
watch: bool,
},
/// Sync external project dependencies into .rivet/repos/
Sync {
/// Use local path for all externals that have one, skipping git fetch/clone
#[arg(long)]
local: bool,
},
/// Pin external dependencies to exact commits in rivet.lock
Lock {
/// Update all pins to latest refs
#[arg(long)]
update: bool,
},
/// Analyze change impact between current state and a baseline
Impact {
/// Git ref to compare against (branch, tag, or commit)
#[arg(long)]
since: Option<String>,
/// Path to baseline project directory (containing rivet.yaml)
#[arg(long)]
baseline: Option<PathBuf>,
/// Maximum traversal depth (0 = direct only)
#[arg(long, default_value = "10")]
depth: usize,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Manage distributed baselines across repos
Baseline {
#[command(subcommand)]
action: BaselineAction,
},
/// Capture or compare project snapshots for delta tracking
Snapshot {
#[command(subcommand)]
action: SnapshotAction,
},
/// Import artifacts using a custom WASM adapter component
#[cfg(feature = "wasm")]
Import {
/// Path to the WASM adapter component file (.wasm)
#[arg(long)]
adapter: PathBuf,
/// Path to the source data (file or directory)
#[arg(long)]
source: PathBuf,
/// Adapter configuration entries (key=value pairs)
#[arg(long = "config", value_parser = parse_key_val)]
config_entries: Vec<(String, String)>,
},
/// Import test results or artifacts from external formats
ImportResults {
/// Input format (currently: "junit")
#[arg(long)]
format: String,
/// Input file path
file: PathBuf,
/// Output directory for results YAML (default: results/)
#[arg(long, default_value = "results")]
output: PathBuf,
},
/// Print the next available ID for a given artifact type or prefix
NextId {
/// Artifact type (e.g., requirement, feature, design-decision)
#[arg(short = 't', long, group = "id_source")]
r#type: Option<String>,
/// ID prefix directly (e.g., REQ, FEAT, DD)
#[arg(short, long, group = "id_source")]
prefix: Option<String>,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Add a new artifact to the project
Add {
/// Artifact type (e.g., requirement, feature, design-decision)
#[arg(short = 't', long)]
r#type: String,
/// Artifact title
#[arg(long)]
title: String,
/// Artifact description
#[arg(long)]
description: Option<String>,
/// Lifecycle status (default: draft)
#[arg(long, default_value = "draft")]
status: String,
/// Comma-separated tags
#[arg(long, value_delimiter = ',')]
tags: Vec<String>,
/// Field values as key=value pairs
#[arg(long = "field", value_parser = parse_key_val_mutation)]
fields: Vec<(String, String)>,
/// Links as type:target pairs (e.g., --link "satisfies:REQ-001")
#[arg(long = "link", value_parser = parse_link_spec)]
links: Vec<(String, String)>,
/// Target YAML file to append the artifact to
#[arg(long)]
file: Option<PathBuf>,
},
/// Add a link between two artifacts
Link {
/// Source artifact ID
source: String,
/// Link type (e.g., satisfies, implements, derives-from)
#[arg(short = 't', long = "type")]
link_type: String,
/// Target artifact ID
#[arg(long)]
target: String,
},
/// Remove a link between two artifacts
Unlink {
/// Source artifact ID
source: String,
/// Link type (e.g., satisfies, implements, derives-from)
#[arg(short = 't', long = "type")]
link_type: String,
/// Target artifact ID
#[arg(long)]
target: String,
},
/// Modify an existing artifact
Modify {
/// Artifact ID to modify
id: String,
/// Set the lifecycle status
#[arg(long)]
set_status: Option<String>,
/// Set the title
#[arg(long)]
set_title: Option<String>,
/// Add a tag
#[arg(long)]
add_tag: Vec<String>,
/// Remove a tag
#[arg(long)]
remove_tag: Vec<String>,
/// Set a field value (key=value)
#[arg(long = "set-field", value_parser = parse_key_val_mutation)]
set_fields: Vec<(String, String)>,
},
/// Remove an artifact from the project
Remove {
/// Artifact ID to remove
id: String,
/// Force removal even if other artifacts link to this one
#[arg(long)]
force: bool,
},
/// Apply a batch of mutations from a YAML file
Batch {
/// Path to the batch YAML file
file: PathBuf,
},
/// Resolve a computed embed and print the result
Embed {
/// Embed query string, e.g. "stats:types" or "coverage:rule-name"
query: String,
/// Output format: "html" or "text" (default)
#[arg(short, long, default_value = "text")]
format: String,
},
/// Start the language server (LSP over stdio)
Lsp,
/// Start the MCP server (stdio transport)
Mcp,
}
#[derive(Subcommand)]
enum SchemaAction {
/// List all artifact types
List {
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Show detailed info for an artifact type
Show {
/// Artifact type name
name: String,
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// List all link types with inverses
Links {
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// List all traceability rules
Rules {
/// Output format: "text" (default) or "json"
#[arg(short, long, default_value = "text")]
format: String,
},
/// Validate that loaded schemas are well-formed
Validate,
}
#[derive(Debug, Subcommand)]
enum BaselineAction {
/// Verify baseline consistency across all externals
Verify {
/// Baseline name (e.g., "v1.0")
name: String,
/// Fail on missing baseline tags (default: warn only)
#[arg(long)]
strict: bool,
},
/// List baselines found across externals
List,
}
#[derive(Debug, Subcommand)]
enum SnapshotAction {
/// Capture a snapshot of the current project state
Capture {
/// Snapshot name (default: git tag or HEAD short hash)
#[arg(long)]
name: Option<String>,
/// Output file path (default: snapshots/{name}.json)
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Compare current state against a baseline snapshot
Diff {
/// Path to the baseline snapshot JSON file
#[arg(long)]
baseline: Option<PathBuf>,
/// Output format: "text" (default), "json", or "markdown"
#[arg(short, long, default_value = "text")]
format: String,
},
/// List available snapshots
List,
}
fn main() -> ExitCode {
let cli = Cli::parse();
let log_level = match cli.verbose {
0 => "warn",
1 => "info",
_ => "debug",
};
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(log_level))
.format_timestamp(None)
.init();
match run(cli) {
Ok(success) => {
if success {
ExitCode::SUCCESS
} else {
ExitCode::FAILURE
}
}
Err(e) => {
eprintln!("error: {:#}", e);
ExitCode::FAILURE
}
}
}
fn run(cli: Cli) -> Result<bool> {
// Commands that don't need a loaded project.
if let Command::Init {
name,
preset,
schema,
dir,
agents,
} = &cli.command
{
if *agents {
return cmd_init_agents(&cli);
}
return cmd_init(name.as_deref(), preset, schema, dir);
}
if let Command::Docs {
topic,
grep,
format,
context,
} = &cli.command
{
return cmd_docs(topic.as_deref(), grep.as_deref(), format, *context);
}
if let Command::Context = &cli.command {
return cmd_context(&cli);
}
if let Command::CommitMsgCheck { file } = &cli.command {
return cmd_commit_msg_check(&cli, file);
}
if let Command::Lsp = &cli.command {
return cmd_lsp(&cli);
}
if let Command::Mcp = &cli.command {
return cmd_mcp();
}
match &cli.command {
Command::Init { .. }
| Command::Docs { .. }
| Command::Context
| Command::CommitMsgCheck { .. }
| Command::Lsp
| Command::Mcp => unreachable!(),
Command::Stpa { path, schema } => cmd_stpa(path, schema.as_deref(), &cli),
Command::Validate {
format,
direct,
skip_external_validation,
baseline,
track_convergence,
} => cmd_validate(
&cli,
format,
*direct,
*skip_external_validation,
baseline.as_deref(),
*track_convergence,
),
Command::List {
r#type,
status,
format,
baseline,
} => cmd_list(
&cli,
r#type.as_deref(),
status.as_deref(),
format,
baseline.as_deref(),
),
Command::Get { id, format } => cmd_get(&cli, id, format),
Command::Stats { format, baseline } => cmd_stats(&cli, format, baseline.as_deref()),
Command::Coverage {
format,
fail_under,
tests,
scan_paths,
baseline,
} => {
if *tests {
cmd_coverage_tests(&cli, format, scan_paths)
} else {
cmd_coverage(&cli, format, fail_under.as_ref(), baseline.as_deref())
}
}
Command::Matrix {
from,
to,
link,
direction,
format,
} => cmd_matrix(&cli, from, to, link.as_deref(), direction, format),
Command::Diff { base, head, format } => {
cmd_diff(&cli, base.as_deref(), head.as_deref(), format)
}
Command::Export {
format,
output,
single_page,
theme,
offline,
homepage,
version_label,
versions,
baseline,
} => cmd_export(
&cli,
format,
output.as_deref(),
*single_page,
theme,
*offline,
homepage.as_deref(),
version_label.as_deref(),
versions.as_deref(),
baseline.as_deref(),
),
Command::Impact {
since,
baseline,
depth,
format,
} => cmd_impact(&cli, since.as_deref(), baseline.as_deref(), *depth, format),
Command::Schema { action } => cmd_schema(&cli, action),
Command::Commits {
since,
range,
format,
strict,
} => cmd_commits(&cli, since.as_deref(), range.as_deref(), format, *strict),
Command::Serve { port, bind, watch } => {
check_for_updates();
let port = *port;
let watch = *watch;
let bind = bind.clone();
if bind == "0.0.0.0" || bind == "::" {
eprintln!(
"warning: binding to {} exposes the dashboard to all network interfaces",
bind
);
}
let ctx = ProjectContext::load_full(&cli)?;
let schemas_dir = resolve_schemas_dir(&cli);
let mut doc_dirs = Vec::new();
for docs_path in &ctx.config.docs {
let dir = cli.project.join(docs_path);
if dir.is_dir() {
doc_dirs.push(dir);
}
}
// Collect source dirs for file watcher
let source_paths: Vec<PathBuf> = ctx
.config
.sources
.iter()
.map(|s| cli.project.join(&s.path))
.collect();
let project_name = ctx.config.project.name.clone();
let project_path =
std::fs::canonicalize(&cli.project).unwrap_or_else(|_| cli.project.clone());
let rt = tokio::runtime::Runtime::new().context("failed to create tokio runtime")?;
rt.block_on(serve::run(
ctx.store,
ctx.schema,
ctx.graph,
ctx.doc_store.unwrap_or_default(),
ctx.result_store.unwrap_or_default(),
project_name,
project_path.clone(),
schemas_dir.clone(),
doc_dirs.clone(),
port,
bind,
watch,
source_paths,
))?;
Ok(true)
}
Command::Sync { local } => cmd_sync(&cli, *local),
Command::Lock { update } => cmd_lock(&cli, *update),
Command::Baseline { action } => match action {
BaselineAction::Verify { name, strict } => cmd_baseline_verify(&cli, name, *strict),
BaselineAction::List => cmd_baseline_list(&cli),
},
Command::Snapshot { action } => match action {
SnapshotAction::Capture { name, output } => {
cmd_snapshot_capture(&cli, name.as_deref(), output.as_deref())
}
SnapshotAction::Diff { baseline, format } => {
cmd_snapshot_diff(&cli, baseline.as_deref(), format)
}
SnapshotAction::List => cmd_snapshot_list(&cli),
},
#[cfg(feature = "wasm")]
Command::Import {
adapter,
source,
config_entries,
} => cmd_import(adapter, source, config_entries),
Command::ImportResults {
format,
file,
output,
} => cmd_import_results(format, file, output),
Command::NextId {
r#type,
prefix,
format,
} => cmd_next_id(&cli, r#type.as_deref(), prefix.as_deref(), format),
Command::Add {
r#type,
title,
description,
status,
tags,
fields,
links,
file,
} => cmd_add(
&cli,
r#type,
title,
description.as_deref(),
status,
tags,
fields,
links,
file.as_deref(),
),
Command::Link {
source,
link_type,
target,
} => cmd_link(&cli, source, link_type, target),
Command::Unlink {
source,
link_type,
target,
} => cmd_unlink(&cli, source, link_type, target),
Command::Modify {
id,
set_status,
set_title,
add_tag,
remove_tag,
set_fields,
} => cmd_modify(
&cli,
id,
set_status.as_deref(),
set_title.as_deref(),
add_tag,
remove_tag,
set_fields,
),
Command::Remove { id, force } => cmd_remove(&cli, id, *force),
Command::Batch { file } => cmd_batch(&cli, file),
Command::Embed { query, format } => cmd_embed(&cli, query, format),
}
}
/// Preset configuration for `rivet init`.
struct InitPreset {
schemas: Vec<&'static str>,
/// Each entry: (filename, yaml_content)
sample_files: Vec<(&'static str, &'static str)>,
}
fn resolve_preset(preset: &str) -> Result<InitPreset> {
match preset {
"dev" => Ok(InitPreset {
schemas: vec!["common", "dev"],
sample_files: vec![("requirements.yaml", DEV_SAMPLE)],
}),
"aspice" => Ok(InitPreset {
schemas: vec!["common", "aspice"],
sample_files: vec![("requirements.yaml", ASPICE_SAMPLE)],
}),
"stpa" => Ok(InitPreset {
schemas: vec!["common", "stpa"],
sample_files: vec![("safety.yaml", STPA_SAMPLE)],
}),