vela-cli 0.77.0

The vela command-line tool: build, check, sign, replay, and publish scientific frontier state.
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
//! `vela` — the command-line binary.
//!
//! Wires the agent handlers from `vela-scientist` into the
//! substrate's CLI dispatch table, then hands off to
//! `vela_protocol::cli::run_from_args`.
//!
//! Doctrine: the substrate library doesn't know about agents. This
//! binary does the marriage.

use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;

use colored::Colorize;

fn main() {
    // Agent handlers (Scout, Notes Compiler, Code Analyst, Datasets,
    // Reviewer, Contradiction Finder, Experiment Planner). These wire
    // the v0.22+ agent inbox into the substrate CLI dispatch.
    vela_protocol::cli::register_scout_handler(scout_handler);
    vela_protocol::cli::register_notes_handler(notes_handler);
    vela_protocol::cli::register_code_handler(code_handler);
    vela_protocol::cli::register_datasets_handler(datasets_handler);
    vela_protocol::cli::register_reviewer_handler(reviewer_handler);
    vela_protocol::cli::register_tensions_handler(tensions_handler);
    vela_protocol::cli::register_experiments_handler(experiments_handler);
    vela_protocol::cli::run_from_args();
}

/// Adapter from the substrate's `ScoutHandler` signature to
/// `vela_scientist::scout::run`. Owns the user-facing rendering of
/// the report so the agent crate can stay UI-free.
fn scout_handler(
    folder: PathBuf,
    frontier: PathBuf,
    backend: Option<String>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::scout::{ScoutInput, run};
        // The substrate's CLI plumbs through a generic `backend`
        // string from the `vela scout --backend` flag. v0.22's only
        // backend is `claude-cli`, so we treat the legacy flag as a
        // model-alias override (e.g. `--backend sonnet`) and ignore
        // empty / "claude-cli" / "default" values.
        let model = backend.and_then(|b| {
            let trimmed = b.trim().to_string();
            if trimmed.is_empty() || trimmed == "claude-cli" || trimmed == "default" {
                None
            } else {
                Some(trimmed)
            }
        });
        let input = ScoutInput {
            folder: folder.clone(),
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!("  {}", "VELA · SCOUT · LITERATURE".dimmed());
                println!("  {}", tick_row(60));
                println!("  agent:           {}", report.run.agent);
                println!("  run id:          {}", report.run.run_id);
                println!(
                    "  model:           {}",
                    if report.run.model.is_empty() {
                        "(env default)"
                    } else {
                        &report.run.model
                    }
                );
                println!("  folder:          {}", folder.display());
                println!("  frontier:        {}", frontier.display());
                println!("  pdfs seen:       {}", report.pdfs_seen);
                println!("  pdfs processed:  {}", report.pdfs_processed);
                println!("  candidates:      {}", report.candidates_emitted);
                println!(
                    "  proposals:       {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:         {} files", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.path, s.reason);
                    }
                    if report.skipped.len() > 5 {
                        println!("{} more", report.skipped.len() - 5);
                    }
                }
                println!();
                if !dry_run && report.proposals_written > 0 {
                    println!(
                        "  next: review in the Workbench Inbox, then `vela queue sign --all`."
                    );
                }
            }
            Err(e) => {
                eprintln!("  scout failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela compile-notes` (v0.23). Same shape as
/// scout_handler — render the report to terminal in a friendly form,
/// or as JSON when requested.
fn notes_handler(
    vault: PathBuf,
    frontier: PathBuf,
    backend: Option<String>,
    max_files: Option<usize>,
    max_items_per_category: Option<usize>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::notes::{NotesInput, run};
        let model = backend.and_then(|b| {
            let trimmed = b.trim().to_string();
            if trimmed.is_empty() || trimmed == "claude-cli" || trimmed == "default" {
                None
            } else {
                Some(trimmed)
            }
        });
        let input = NotesInput {
            vault: vault.clone(),
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            max_files: max_files.or(Some(50)),
            max_items_per_category: max_items_per_category.or(Some(4)),
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!("  {}", "VELA · COMPILE-NOTES · NOTES-COMPILER".dimmed());
                println!("  {}", tick_row(60));
                println!("  agent:                 {}", report.run.agent);
                println!("  run id:                {}", report.run.run_id);
                println!(
                    "  model:                 {}",
                    if report.run.model.is_empty() {
                        "(env default)"
                    } else {
                        &report.run.model
                    }
                );
                println!("  vault:                 {}", vault.display());
                println!("  frontier:              {}", frontier.display());
                println!("  notes seen:            {}", report.notes_seen);
                println!("  notes processed:       {}", report.notes_processed);
                println!("  open questions:        {}", report.open_questions_emitted);
                println!("  hypotheses:            {}", report.hypotheses_emitted);
                println!(
                    "  candidate findings:    {}",
                    report.candidate_findings_emitted
                );
                println!("  tensions:              {}", report.tensions_emitted);
                println!(
                    "  proposals:             {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:               {} files", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.path, s.reason);
                    }
                    if report.skipped.len() > 5 {
                        println!("{} more", report.skipped.len() - 5);
                    }
                }
                println!();
                if !dry_run && report.proposals_written > 0 {
                    println!(
                        "  next: review in the Workbench Inbox, then `vela queue sign --all`."
                    );
                }
            }
            Err(e) => {
                eprintln!("  notes compiler failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela compile-code` (v0.24).
fn code_handler(
    root: PathBuf,
    frontier: PathBuf,
    backend: Option<String>,
    max_files: Option<usize>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::code_analyst::{CodeAnalystInput, run};
        let model = backend.and_then(|b| {
            let trimmed = b.trim().to_string();
            if trimmed.is_empty() || trimmed == "claude-cli" || trimmed == "default" {
                None
            } else {
                Some(trimmed)
            }
        });
        let input = CodeAnalystInput {
            root: root.clone(),
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            max_files: max_files.or(Some(30)),
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!("  {}", "VELA · COMPILE-CODE · CODE-ANALYST".dimmed());
                println!("  {}", tick_row(60));
                println!("  agent:                {}", report.run.agent);
                println!("  run id:               {}", report.run.run_id);
                println!(
                    "  model:                {}",
                    if report.run.model.is_empty() {
                        "(env default)"
                    } else {
                        &report.run.model
                    }
                );
                println!("  root:                 {}", root.display());
                println!("  frontier:             {}", frontier.display());
                println!("  files seen:           {}", report.files_seen);
                println!("  notebooks processed:  {}", report.notebooks_processed);
                println!("  scripts processed:    {}", report.scripts_processed);
                println!("  analyses:             {}", report.analyses_emitted);
                println!("  code findings:        {}", report.code_findings_emitted);
                println!(
                    "  experiment intents:   {}",
                    report.experiment_intents_emitted
                );
                println!(
                    "  proposals:            {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:              {} files", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.path, s.reason);
                    }
                    if report.skipped.len() > 5 {
                        println!("{} more", report.skipped.len() - 5);
                    }
                }
                println!();
                if !dry_run && report.proposals_written > 0 {
                    println!(
                        "  next: review in the Workbench Inbox, then `vela queue sign --all`."
                    );
                }
            }
            Err(e) => {
                eprintln!("  code analyst failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela compile-data` (v0.25).
fn datasets_handler(
    root: PathBuf,
    frontier: PathBuf,
    backend: Option<String>,
    sample_rows: Option<usize>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::datasets::{DatasetInput, run};
        let model = backend.and_then(|b| {
            let trimmed = b.trim().to_string();
            if trimmed.is_empty() || trimmed == "claude-cli" || trimmed == "default" {
                None
            } else {
                Some(trimmed)
            }
        });
        let input = DatasetInput {
            root: root.clone(),
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            sample_rows: sample_rows.unwrap_or(50),
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!("  {}", "VELA · COMPILE-DATA · DATASETS".dimmed());
                println!("  {}", tick_row(60));
                println!("  agent:                {}", report.run.agent);
                println!("  run id:               {}", report.run.run_id);
                println!(
                    "  model:                {}",
                    if report.run.model.is_empty() {
                        "(env default)"
                    } else {
                        &report.run.model
                    }
                );
                println!("  root:                 {}", root.display());
                println!("  frontier:             {}", frontier.display());
                println!("  datasets seen:        {}", report.datasets_seen);
                println!("  csv processed:        {}", report.csv_processed);
                println!("  parquet processed:    {}", report.parquet_processed);
                println!(
                    "  dataset summaries:    {}",
                    report.dataset_summaries_emitted
                );
                println!(
                    "  supported claims:     {}",
                    report.supported_claims_emitted
                );
                println!(
                    "  proposals:            {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:              {} files", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.path, s.reason);
                    }
                    if report.skipped.len() > 5 {
                        println!("{} more", report.skipped.len() - 5);
                    }
                }
                println!();
                if !dry_run && report.proposals_written > 0 {
                    println!(
                        "  next: review in the Workbench Inbox, then `vela queue sign --all`."
                    );
                }
            }
            Err(e) => {
                eprintln!("  datasets agent failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela review-pending` (v0.28).
fn reviewer_handler(
    frontier: PathBuf,
    backend: Option<String>,
    max_proposals: Option<usize>,
    batch_size: usize,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::reviewer::{ReviewerInput, run};
        let model = backend.and_then(|b| {
            let t = b.trim().to_string();
            if t.is_empty() || t == "claude-cli" || t == "default" {
                None
            } else {
                Some(t)
            }
        });
        let input = ReviewerInput {
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            max_proposals: max_proposals.or(Some(30)),
            batch_size,
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!("  {}", "VELA · REVIEW-PENDING · REVIEWER-AGENT".dimmed());
                println!("  {}", tick_row(60));
                println!("  agent:           {}", report.run.agent);
                println!("  run id:          {}", report.run.run_id);
                println!("  frontier:        {}", frontier.display());
                println!("  pending seen:    {}", report.pending_seen);
                println!("  scored:          {}", report.scored);
                println!(
                    "  notes:           {} {}",
                    report.notes_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:         {}", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.proposal_id, s.reason);
                    }
                }
                println!();
            }
            Err(e) => {
                eprintln!("  reviewer agent failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela find-tensions` (v0.28).
fn tensions_handler(
    frontier: PathBuf,
    backend: Option<String>,
    max_findings: Option<usize>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::tensions::{TensionsInput, run};
        let model = backend.and_then(|b| {
            let t = b.trim().to_string();
            if t.is_empty() || t == "claude-cli" || t == "default" {
                None
            } else {
                Some(t)
            }
        });
        let input = TensionsInput {
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            max_findings: max_findings.or(Some(60)),
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!(
                    "  {}",
                    "VELA · FIND-TENSIONS · CONTRADICTION-FINDER".dimmed()
                );
                println!("  {}", tick_row(60));
                println!("  agent:               {}", report.run.agent);
                println!("  run id:              {}", report.run.run_id);
                println!("  frontier:            {}", frontier.display());
                println!("  findings seen:       {}", report.findings_seen);
                println!("  batches processed:   {}", report.batches_processed);
                println!("  tensions emitted:    {}", report.tensions_emitted);
                println!(
                    "  proposals:           {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped batches:     {}", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - batch {}: {}", s.batch, s.reason);
                    }
                }
                println!();
            }
            Err(e) => {
                eprintln!("  contradiction finder failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Adapter for `vela plan-experiments` (v0.28).
fn experiments_handler(
    frontier: PathBuf,
    backend: Option<String>,
    max_findings: Option<usize>,
    dry_run: bool,
    json_out: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
    Box::pin(async move {
        use vela_scientist::experiments::{ExperimentsInput, run};
        let model = backend.and_then(|b| {
            let t = b.trim().to_string();
            if t.is_empty() || t == "claude-cli" || t == "default" {
                None
            } else {
                Some(t)
            }
        });
        let input = ExperimentsInput {
            frontier_path: frontier.clone(),
            model,
            cli_command: std::env::var("VELA_SCIENTIST_CLI")
                .unwrap_or_else(|_| "claude".to_string()),
            apply: !dry_run,
            max_findings: max_findings.or(Some(20)),
        };
        match run(input).await {
            Ok(report) => {
                if json_out {
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&report).unwrap_or_default()
                    );
                    return;
                }
                println!();
                println!(
                    "  {}",
                    "VELA · PLAN-EXPERIMENTS · EXPERIMENT-PLANNER".dimmed()
                );
                println!("  {}", tick_row(60));
                println!("  agent:               {}", report.run.agent);
                println!("  run id:              {}", report.run.run_id);
                println!("  frontier:            {}", frontier.display());
                println!("  questions seen:      {}", report.questions_seen);
                println!("  hypotheses seen:     {}", report.hypotheses_seen);
                println!("  experiments emitted: {}", report.experiments_emitted);
                println!(
                    "  proposals:           {} {}",
                    report.proposals_written,
                    if dry_run {
                        "(dry-run, not written)"
                    } else {
                        "(appended to frontier)"
                    }
                );
                if !report.skipped.is_empty() {
                    println!("  skipped:             {}", report.skipped.len());
                    for s in report.skipped.iter().take(5) {
                        println!("    - {}: {}", s.finding_id, s.reason);
                    }
                }
                println!();
            }
            Err(e) => {
                eprintln!("  experiment planner failed: {e}");
                std::process::exit(1);
            }
        }
    })
}

/// Tiny copy of `vela_protocol::cli_style::tick_row` to keep the
/// binary independent of crate-private chrome helpers. If the
/// instrument styling diverges, that's fine — this binary's output
/// is local-only.
fn tick_row(width: usize) -> String {
    let mut out = String::with_capacity(width);
    for i in 0..width {
        out.push(if i % 4 == 0 { '·' } else { ' ' });
    }
    out
}