vela-cli 0.913.0

The vela command-line tool: build, check, sign, replay, and publish scientific frontier state.
Documentation
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
use crate::cli::{fail, fail_return, fmt_timestamp, frontier_dir_for_source, print_json};
use colored::Colorize;
use serde_json::json;
use sha2::Digest;
use std::path::Path;
use vela_edge::doctor;
use vela_edge::packet;
use vela_protocol::cli_style as style;
use vela_protocol::repo;

/// Stable compact status contract for the 0.9 product surface.
pub(crate) fn cmd_status_compact(path: &Path, json_out: bool) {
    crate::ui::set_mode("status", json_out);
    let frontier_dir = frontier_dir_for_source(path);
    let journal_dir = crate::workflow::frontier_transaction_journal_dir(frontier_dir)
        .unwrap_or_else(|error| fail_return(&error));
    crate::frontier_txn::FrontierTxn::verify_recovery_barrier_read_only(frontier_dir, &journal_dir)
        .unwrap_or_else(|error| fail_return(&error.to_string()));
    let observed_at = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Nanos, true);
    let project = vela_protocol::repo::load_from_path(frontier_dir)
        .unwrap_or_else(|error| fail_return(&error));
    let active_policy = vela_protocol::acceptance_policy::load_active_policy_snapshot(frontier_dir);
    let replay = vela_protocol::reducer::verify_replay(&project);
    let policy = vela_protocol::proposals::policy_accept::assess_policy_readiness(
        &project,
        active_policy.as_ref().map_err(String::as_str),
        &observed_at,
    );
    let policy_ok = policy.permit_readiness()
        != vela_protocol::proposals::policy_accept::PermitReadiness::Blocked;
    let status_ok = replay.ok && policy_ok;
    let signals = vela_edge::signals::analyze_at(&project, &[], Some(frontier_dir));
    let mut blockers_by_code = std::collections::BTreeMap::<String, usize>::new();
    for signal in &signals.signals {
        if signal.blocks.iter().any(|block| block == "strict_check") {
            *blockers_by_code.entry(signal.kind.clone()).or_default() += 1;
        }
    }
    let blocker_count = blockers_by_code.values().sum::<usize>();
    let pending_review = project
        .proposals
        .iter()
        .filter(|proposal| proposal.status == "pending_review")
        .count();
    let work_projection = vela_edge::frontier_next::try_frontier_next_projection(
        &project,
        Some(frontier_dir),
        &observed_at,
        1,
    )
    .unwrap_or_else(|error| fail_return(&error));
    let open_work = work_projection.producer_work.configured_open;
    let available_work = work_projection.producer_work.available;
    let leased_work = work_projection.producer_work.leased;
    let git_text = |args: &[&str]| {
        std::process::Command::new("git")
            .arg("-C")
            .arg(frontier_dir)
            .args(args)
            .output()
            .ok()
            .filter(|output| output.status.success())
            .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string())
    };
    let git_commit = git_text(&["rev-parse", "HEAD^{commit}"]);
    let git_tree = git_text(&["rev-parse", "HEAD^{tree}"]);
    let git_clean =
        git_text(&["status", "--porcelain=v1", "--untracked-files=all"]).is_some_and(|status| {
            status.lines().all(|line| {
                line.get(3..)
                    .is_some_and(|path| path.starts_with(".vela/operation-journals/"))
            })
        });
    let actor_registry_path = frontier_dir.join(".vela/actors.json");
    let actor_registry_root = std::fs::read(&actor_registry_path)
        .map(|bytes| format!("sha256:{}", hex::encode(sha2::Sha256::digest(bytes))))
        .unwrap_or_else(|_| {
            vela_protocol::canonical::to_canonical_bytes(&project.actors)
                .map(|bytes| format!("sha256:{}", hex::encode(sha2::Sha256::digest(bytes))))
                .unwrap_or_else(|error| {
                    fail_return(&format!("canonicalize actor registry: {error}"))
                })
        });
    let artifact_root = vela_protocol::canonical::to_canonical_bytes(&project.artifacts)
        .map(|bytes| format!("sha256:{}", hex::encode(sha2::Sha256::digest(bytes))))
        .unwrap_or_else(|error| fail_return(&format!("canonicalize artifacts: {error}")));
    let next_action = if !replay.ok {
        "vela check . --strict"
    } else if !policy_ok {
        "vela doctor . --all --json"
    } else if available_work > 0 || leased_work > 0 {
        "vela next . --json"
    } else if pending_review > 0 {
        "vela review list . --json"
    } else {
        "none"
    };
    let payload = json!({
        "ok": status_ok,
        "command": "status",
        "schema": "vela.status.v1",
        "frontier": {
            "id": project.frontier_id(),
            "name": project.project.name,
        },
        "git": {
            "commit": git_commit,
            "tree": git_tree,
            "clean": git_clean,
        },
        "roots": {
            "event_log": format!("sha256:{}", vela_protocol::events::event_log_hash(&project.events)),
            "snapshot": format!("sha256:{}", vela_protocol::events::snapshot_hash(&project)),
            "proposals": format!("sha256:{}", vela_protocol::proposals::proposal_state_hash(&project.proposals)),
            "actor_registry": actor_registry_root,
            "artifacts": artifact_root,
        },
        "integrity": {
            "replay": if replay.ok { "reproduced" } else { "diverged" },
            "replay_diffs": replay.diffs.len(),
            "strict": if blocker_count == 0 { "pass" } else { "blocked" },
            "blocker_count": blocker_count,
            "blockers_by_code": blockers_by_code,
        },
        "counts": {
            "events": project.events.len(),
            "findings": project.findings.len(),
            "open_work": open_work,
            "available_work": available_work,
            "leased_work": leased_work,
            "pending_review": pending_review,
        },
        "policy": {
            "state": policy.state().as_str(),
            "permit_readiness": policy.permit_readiness().as_str(),
            "reason_codes": policy.reason_codes(),
            "error": policy.detail(),
        },
        "next_action": next_action,
    });
    crate::frontier_txn::FrontierTxn::verify_recovery_barrier_read_only(frontier_dir, &journal_dir)
        .unwrap_or_else(|error| fail_return(&error.to_string()));
    if json_out {
        print_json(&payload);
    } else {
        println!(
            "vela status · {}",
            payload["frontier"]["name"].as_str().unwrap_or("frontier")
        );
        println!("  frontier  {}", project.frontier_id());
        println!(
            "  commit    {}",
            payload["git"]["commit"].as_str().unwrap_or("unavailable")
        );
        println!(
            "  replay    {}",
            payload["integrity"]["replay"].as_str().unwrap_or("unknown")
        );
        println!("  strict    {} blocker(s)", blocker_count);
        for (code, count) in payload["integrity"]["blockers_by_code"]
            .as_object()
            .into_iter()
            .flatten()
        {
            println!("            {} {}", count, code);
        }
        println!("  events    {}", project.events.len());
        println!("  findings  {}", project.findings.len());
        println!(
            "  work      {} available · {} leased · {} configured open",
            available_work, leased_work, open_work
        );
        println!("  review    {} pending", pending_review);
        println!(
            "  policy    {} · Permit {}",
            policy.state().as_str(),
            policy.permit_readiness().as_str()
        );
        if let Some(detail) = policy.detail() {
            println!("            {detail}");
        }
        println!("  next      {next_action}");
    }
    if !status_ok {
        std::process::exit(1);
    }
}

/// Signed-but-uncommitted store state: the worst state a decision can
/// be in (it exists on one machine, invisible to CI, the hub, and every
/// collaborator). Counts changed/untracked files under the frontier's
/// store paths; 0 when not a git repo.
pub(crate) fn unpublished_store_files(path: &Path) -> usize {
    let Ok(out) = std::process::Command::new("git")
        .arg("-C")
        .arg(path)
        .args([
            "status",
            "--porcelain",
            "--",
            ".vela",
            "frontier.json",
            "vela.lock",
            "proof",
        ])
        .output()
    else {
        return 0;
    };
    if !out.status.success() {
        return 0;
    }
    String::from_utf8_lossy(&out.stdout)
        .lines()
        .filter(|l| !l.trim().is_empty())
        .count()
}

/// v0.42: Recent canonical events. The `git log` analogue.
pub(crate) fn cmd_log(path: &Path, limit: usize, kind_filter: Option<&str>, json: bool) {
    crate::ui::set_mode("log", json);
    let project = repo::load_from_path(path).unwrap_or_else(|e| fail_return(&e));
    let mut events: Vec<&vela_protocol::events::StateEvent> = project
        .events
        .iter()
        .filter(|e| match kind_filter {
            Some(k) => e.kind.as_str().contains(k),
            None => true,
        })
        .collect();
    events.sort_by(|a, b| b.timestamp.cmp(&a.timestamp));
    events.truncate(limit);

    if json {
        let payload: Vec<_> = events
            .iter()
            .map(|e| {
                json!({
                    "id": e.id,
                    "kind": e.kind,
                    "actor": e.actor.id,
                    "target": &e.target.id,
                    "target_type": &e.target.r#type,
                    "timestamp": e.timestamp,
                    "reason": e.reason,
                })
            })
            .collect();
        println!(
            "{}",
            serde_json::to_string_pretty(&json!({
                "ok": true,
                "command": "log",
                "events": payload,
            }))
            .expect("serialize log")
        );
        return;
    }

    println!();
    println!(
        "  {}",
        format!("VELA · LOG · {}  (latest {})", path.display(), events.len())
            .to_uppercase()
            .dimmed()
    );
    println!("  {}", style::tick_row(60));
    if events.is_empty() {
        println!("  (no events)");
        return;
    }
    // The width-aware table computes column widths from content and, on a
    // narrow terminal, truncates the widest column with `…`; piped output
    // stays full-width and byte-stable (reason is the flexible last column,
    // pre-capped so a novel-length reason can't blow up the row).
    let clip = |s: &str, w: usize| -> String {
        if s.chars().count() > w {
            format!(
                "{}…",
                s.chars().take(w.saturating_sub(1)).collect::<String>()
            )
        } else {
            s.to_string()
        }
    };
    let mut table = crate::cli::table::Table::new();
    for e in &events {
        table.row([
            fmt_timestamp(&e.timestamp),
            e.kind.as_str().to_string(),
            clip(&e.actor.id, 24),
            clip(&e.target.id, 22),
            e.reason.chars().take(80).collect(),
        ]);
    }
    println!("{}", table.render());
    println!();
}

/// `vela verify <packet_dir>` — same code path as
/// `vela packet validate`, surfaced under a friendlier top-level name.
/// Reads every file in the manifest, recomputes SHA-256, validates the
/// proof-trace chain. Exit 0 on all-match, 1 on any mismatch.
pub(crate) fn cmd_verify(path: &Path, json_output: bool) {
    let result = packet::validate(path);
    match result {
        Ok(output) if json_output => {
            println!(
                "{}",
                serde_json::to_string_pretty(&json!({
                    "ok": true,
                    "command": "verify",
                    "result": output,
                }))
                .expect("failed to serialize verify response")
            );
        }
        Ok(output) => {
            println!("{output}");
            println!(
                "\nverify: ok\n  every file in the manifest matched its claimed sha256.\n  pull this packet on another machine, run the same command, see the same line."
            );
        }
        Err(e) => fail(&e),
    }
}

pub(crate) async fn cmd_doctor(frontier: Option<&Path>, port: u16, all: bool, json_output: bool) {
    let report = doctor::run(frontier, port);
    // The local setup/ceremony lane lives crate-side (identity, pin,
    // policy freshness, adapters, registry) and merges into the report.
    let frontier_dir = if report.frontier_load_ok {
        Some(std::path::PathBuf::from(&report.frontier_path))
    } else {
        None
    };
    let setup = crate::config::doctor_setup::run(frontier_dir.as_deref());
    let setup_blockers = setup
        .iter()
        .filter(|check| check.status == crate::config::doctor_setup::SetupStatus::Fail)
        .map(|check| check.name.to_string())
        .collect::<Vec<_>>();
    let mut blockers = report.blocking.clone();
    blockers.extend(setup_blockers);
    blockers.sort();
    blockers.dedup();
    let next_action = setup
        .iter()
        .find(|check| {
            check.status == crate::config::doctor_setup::SetupStatus::Fail && !check.next.is_empty()
        })
        .map(|check| check.next.clone())
        .or_else(|| report.next_commands.first().cloned());
    if json_output && !all {
        print_json(&json!({
            "schema": "vela.doctor.v1",
            "ok": blockers.is_empty(),
            "command": "doctor",
            "binary_version": report.binary_version,
            "frontier": {
                "path": report.frontier_path,
                "kind": report.frontier_kind,
                "load": if report.frontier_load_ok { "ok" } else { "blocked" },
            },
            "policy": if report.policy_ok { "ready" } else { "needs_attention" },
            "proof": report.proof_status,
            "evidence_ci": if report.evidence_ci_ok { "ok" } else { "blocked" },
            "blockers": blockers,
            "next_action": next_action,
        }));
    } else if json_output {
        let mut merged = serde_json::to_value(&report).unwrap_or_default();
        if let Some(obj) = merged.as_object_mut() {
            obj.insert(
                "setup".to_string(),
                serde_json::to_value(&setup).unwrap_or_default(),
            );
        }
        print_json(&merged);
    } else if all {
        println!("vela doctor");
        println!("  binary:      {}", report.binary_version);
        println!("  frontier:    {}", report.frontier_path);
        println!("  kind:        {}", report.frontier_kind);
        println!(
            "  policy:      {}",
            if report.policy_ok {
                "ok"
            } else {
                "needs attention"
            }
        );
        println!("  proof:       {}", report.proof_status);
        println!(
            "  evidence ci: {}",
            if report.evidence_ci_ok {
                "ok"
            } else {
                "needs attention"
            }
        );
        println!(
            "  serve:       port {} {}",
            report.workbench_port,
            if report.workbench_port_available {
                "available"
            } else {
                "unavailable"
            }
        );
        println!();
        println!("setup:");
        for c in &setup {
            let mark = match c.status {
                crate::config::doctor_setup::SetupStatus::Ok => "ok  ",
                crate::config::doctor_setup::SetupStatus::Warn => "warn",
                crate::config::doctor_setup::SetupStatus::Fail => "FAIL",
            };
            println!("  {mark}  {:<11} {}", c.name, c.detail);
            if !c.next.is_empty() {
                println!("        {:<11} → {}", "", c.next);
            }
        }
        if !report.blocking.is_empty() {
            println!("  blocking:    {}", report.blocking.join(", "));
        }
        if !report.warnings.is_empty() {
            println!("  warnings:    {}", report.warnings.join(", "));
        }
        println!();
        println!("next:");
        for command in &report.next_commands {
            println!("  {command}");
        }
        if let Some(config) = &report.mcp_config {
            println!();
            println!("mcp:");
            println!(
                "  {}",
                serde_json::to_string(config).expect("serialize mcp config")
            );
        }
    } else {
        println!("vela doctor · {}", report.frontier_path);
        println!("  binary    {}", report.binary_version);
        println!(
            "  frontier  {}",
            if report.frontier_load_ok {
                "ok"
            } else {
                "blocked"
            }
        );
        println!(
            "  policy    {}",
            if report.policy_ok {
                "ready"
            } else {
                "needs attention"
            }
        );
        println!("  proof     {}", report.proof_status);
        println!(
            "  blockers  {}",
            if blockers.is_empty() {
                "none".to_string()
            } else {
                blockers.join(", ")
            }
        );
        if let Some(next) = &next_action {
            println!("  next      {next}");
        }
        println!("  details   vela doctor . --all");
    }
    if !blockers.is_empty() {
        std::process::exit(1);
    }
}