Skip to main content

vela_cli/
lib.rs

1//! `vela` — the command-line binary.
2//!
3//! Hands off to `crate::cli::run_from_args`, after a small read-only
4//! verify intercept (conjecture / proof-packet verification).
5
6use vela_protocol::cli_style as style;
7
8// The CLI / serve / workbench surface, relocated out of the
9// `vela-protocol` library so the substrate crate stays a pure protocol
10// library. These were `vela_protocol::{cli, serve, workbench, cli_*}`
11// before; they now live here and reach into the substrate via
12// `vela_protocol::*`.
13mod atlas;
14pub(crate) use atlas::decl_graph;
15mod bounded_file;
16#[allow(dead_code)]
17pub(crate) mod decision_plan;
18mod frontier;
19pub(crate) use frontier::{cli_frontier, cli_read};
20mod write;
21pub(crate) use write::{cli_finding, cli_write, review_work};
22mod tools;
23mod withdrawal;
24pub(crate) use tools::{cli_check, cli_proof};
25mod config;
26pub(crate) use config::{cli_admin, cli_agents, cli_identity};
27// The full durability seam intentionally lands before every legacy writer is
28// migrated, so some caller-facing pieces remain unused inside this slice.
29#[allow(dead_code)]
30pub(crate) mod frontier_txn;
31mod operation_journal;
32pub(crate) mod review_material;
33mod server;
34pub(crate) mod ui;
35pub(crate) mod workflow;
36pub(crate) use server::{cli_commands, cli_engine, serve};
37// The hosted MCP service: vela-hub embeds the serve dispatcher in-process
38// to run `/mcp` over its git-ingest checkouts. One dispatcher behind every
39// transport — stdio, `vela serve --http`, and the hub.
40pub use server::serve::McpService;
41
42pub mod cli;
43
44pub fn run() {
45    // Color discipline must hold for the read-only intercepts below too:
46    // they print before `run_from_args` initializes styling, so without
47    // this a piped or NO_COLOR invocation would leak ANSI. `init()` is
48    // `Once`-guarded, so the later call in `run_from_args` is a no-op.
49    style::init();
50
51    // Atlas R.2 intercept: read-only verifier subcommands for the
52    // primitives added in R.1 (v0.338). Live ahead of run_from_args()
53    // because the dispatcher in vela-protocol/cli.rs predates these
54    // primitives. When the next vela-protocol release lands them in the
55    // dispatcher proper, this intercept can be removed.
56    if try_handle_atlas_r2_verify_intercept() {
57        return;
58    }
59
60    crate::cli::run_from_args();
61}
62
63fn try_handle_atlas_r2_verify_intercept() -> bool {
64    let argv: Vec<String> = std::env::args().collect();
65    if argv.len() < 3 {
66        return false;
67    }
68    match (argv[1].as_str(), argv[2].as_str()) {
69        ("conjecture", "verify") => {
70            handle_conjecture_verify(&argv[3..]);
71            true
72        }
73        ("proof-packet", "verify") => {
74            handle_proof_packet_verify(&argv[3..]);
75            true
76        }
77        ("proof-packet", "verify-external") => {
78            handle_proof_packet_verify_external(&argv[3..]);
79            true
80        }
81        _ => false,
82    }
83}
84
85fn handle_conjecture_verify(args: &[String]) {
86    let path = match args.first() {
87        Some(p) => p,
88        None => {
89            eprintln!(
90                "{} usage: vela conjecture verify <path>",
91                style::err_prefix()
92            );
93            std::process::exit(2);
94        }
95    };
96    let body = match std::fs::read_to_string(path) {
97        Ok(b) => b,
98        Err(e) => {
99            eprintln!("{} read {path}: {e}", style::err_prefix());
100            std::process::exit(1);
101        }
102    };
103    let conj: vela_protocol_core::conjecture::Conjecture = match serde_json::from_str(&body) {
104        Ok(c) => c,
105        Err(e) => {
106            eprintln!("{} parse {path}: {e}", style::err_prefix());
107            std::process::exit(1);
108        }
109    };
110    if let Err(e) = conj.verify() {
111        eprintln!("{} witness signature/id invalid: {e}", style::err_prefix());
112        std::process::exit(1);
113    }
114    let cosigs = match conj.verify_cosignatures() {
115        Ok(n) => n,
116        Err(e) => {
117            eprintln!("{} co-signature invalid: {e}", style::err_prefix());
118            std::process::exit(1);
119        }
120    };
121    println!(
122        "  {} {} witness:{} cosigners:{} status:{:?}",
123        style::moss("conjecture verified"),
124        conj.id,
125        conj.witness.actor_id,
126        cosigs,
127        conj.status,
128    );
129}
130
131fn handle_proof_packet_verify(args: &[String]) {
132    let path = match args.first() {
133        Some(p) => p,
134        None => {
135            eprintln!(
136                "{} usage: vela proof-packet verify <path>",
137                style::err_prefix()
138            );
139            std::process::exit(2);
140        }
141    };
142    let body = match std::fs::read_to_string(path) {
143        Ok(b) => b,
144        Err(e) => {
145            eprintln!("{} read {path}: {e}", style::err_prefix());
146            std::process::exit(1);
147        }
148    };
149    let packet: vela_edge::proof_packet::ProofPacket = match serde_json::from_str(&body) {
150        Ok(p) => p,
151        Err(e) => {
152            eprintln!("{} parse {path}: {e}", style::err_prefix());
153            std::process::exit(1);
154        }
155    };
156    if let Err(e) = packet.verify() {
157        eprintln!("{} packet invalid: {e}", style::err_prefix());
158        std::process::exit(1);
159    }
160    println!(
161        "  {} {} hash:{} signer:{}",
162        style::moss("proof packet verified"),
163        packet.packet_id,
164        &packet.packet_hash[..24],
165        packet.signer_actor_id,
166    );
167}
168
169fn handle_proof_packet_verify_external(args: &[String]) {
170    let path = match args.first() {
171        Some(p) => p,
172        None => {
173            eprintln!(
174                "{} usage: vela proof-packet verify-external <path>",
175                style::err_prefix()
176            );
177            std::process::exit(2);
178        }
179    };
180    let body = match std::fs::read_to_string(path) {
181        Ok(b) => b,
182        Err(e) => {
183            eprintln!("{} read {path}: {e}", style::err_prefix());
184            std::process::exit(1);
185        }
186    };
187    let packet: vela_edge::proof_packet::ProofPacket = match serde_json::from_str(&body) {
188        Ok(p) => p,
189        Err(e) => {
190            eprintln!("{} parse {path}: {e}", style::err_prefix());
191            std::process::exit(1);
192        }
193    };
194    if let Err(e) = packet.verify() {
195        eprintln!("{} packet invalid: {e}", style::err_prefix());
196        std::process::exit(1);
197    }
198    let n = match packet.verify_external_verifications() {
199        Ok(n) => n,
200        Err(e) => {
201            eprintln!("{} external verification invalid: {e}", style::err_prefix());
202            std::process::exit(1);
203        }
204    };
205    println!(
206        "  {} {} external:{} (signer:{})",
207        style::moss("proof packet + externals verified"),
208        packet.packet_id,
209        n,
210        packet.signer_actor_id,
211    );
212}