elicitation 0.10.0

Conversational elicitation of strongly-typed Rust values via MCP
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
//! Command-line interface for elicitation tools.
//!
//! Provides verification orchestration, analysis, and utilities.

use clap::{Parser, Subcommand};
use derive_getters::Getters;
use std::path::PathBuf;

/// Elicitation library tools and verification
#[derive(Debug, Clone, Parser, Getters)]
#[command(name = "elicitation")]
#[command(about = "Type-safe LLM elicitation with formal verification")]
pub struct Cli {
    /// The command to execute
    #[command(subcommand)]
    command: Commands,
}

/// Available commands
#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
    /// Run and manage Kani verification proofs
    Verify {
        /// Action to perform
        #[command(subcommand)]
        action: VerifyAction,
    },

    /// Run and manage Verus verification proofs
    Verus {
        /// Action to perform
        #[command(subcommand)]
        action: VerusAction,
    },

    /// Run and manage Creusot verification modules
    Creusot {
        /// Action to perform
        #[command(subcommand)]
        action: CreusotAction,
    },

    /// Visualize elicitation type structure as a graph
    Graph {
        /// Action to perform
        #[command(subcommand)]
        action: GraphAction,
    },
}

/// Verification actions
#[derive(Debug, Clone, Subcommand)]
pub enum VerifyAction {
    /// List all proof harnesses
    List,

    /// Run all proofs with CSV tracking
    Run {
        /// CSV output file
        #[arg(short, long, default_value = "kani_verification_results.csv")]
        output: PathBuf,

        /// Timeout per test in seconds
        #[arg(short, long, default_value_t = 300)]
        timeout: u64,

        /// Resume mode: skip already-passed tests
        #[arg(short, long)]
        resume: bool,
    },

    /// Show summary statistics from CSV
    Summary {
        /// CSV file to analyze
        #[arg(default_value = "kani_verification_results.csv")]
        file: PathBuf,
    },

    /// Show failed tests from CSV
    Failed {
        /// CSV file to analyze
        #[arg(default_value = "kani_verification_results.csv")]
        file: PathBuf,
    },
}

/// Verus verification actions
#[derive(Debug, Clone, Subcommand)]
pub enum VerusAction {
    /// List all proof modules
    List,

    /// Run Verus verification with CSV tracking
    Run {
        /// CSV output file
        #[arg(short, long, default_value = "verus_verification_results.csv")]
        output: PathBuf,

        /// Timeout per proof in seconds
        #[arg(short, long, default_value_t = 600)]
        timeout: u64,

        /// Resume mode: skip already-passed proofs
        #[arg(short, long)]
        resume: bool,

        /// Path to Verus binary (defaults to VERUS_PATH env var or ~/repos/verus/source/target-verus/release/verus)
        #[arg(long)]
        verus_path: Option<PathBuf>,
    },

    /// Show summary statistics from CSV
    Summary {
        /// CSV file to analyze
        #[arg(short, long, default_value = "verus_verification_results.csv")]
        file: PathBuf,
    },

    /// Show failed proofs from CSV
    Failed {
        /// CSV file to analyze
        #[arg(short, long, default_value = "verus_verification_results.csv")]
        file: PathBuf,
    },
}

/// Creusot verification actions
#[derive(Debug, Clone, Subcommand)]
pub enum CreusotAction {
    /// List all Creusot modules
    List,

    /// Run Creusot verification on all modules
    Run {
        /// CSV output file
        #[arg(short, long, default_value = "creusot_verification_results.csv")]
        output: PathBuf,

        /// Resume mode: skip already-passed modules
        #[arg(short, long)]
        resume: bool,
    },

    /// Run SMT provers and track per-goal results with timestamps
    Prove {
        /// Module-level CSV output file
        #[arg(long, default_value = "creusot_module_results.csv")]
        output: PathBuf,

        /// Per-goal CSV output file
        #[arg(long, default_value = "creusot_goal_results.csv")]
        goals: PathBuf,

        /// Resume mode: skip already-passed modules
        #[arg(long)]
        resume: bool,
    },

    /// Show summary statistics from CSV
    Summary {
        /// CSV file to analyze
        #[arg(short, long, default_value = "creusot_verification_results.csv")]
        file: PathBuf,
    },
}

/// Graph visualization actions
#[derive(Debug, Clone, Subcommand)]
pub enum GraphAction {
    /// List all registered graphable types
    List,

    /// Render a type's structural graph
    Render {
        /// Root type name to render (e.g. `ApplicationConfig`)
        #[arg(short, long)]
        root: String,

        /// Output format
        #[arg(short, long, default_value = "mermaid", value_parser = ["mermaid", "dot"])]
        format: String,

        /// Include primitive/generic leaf nodes in output
        #[arg(long)]
        include_primitives: bool,

        /// Write output to file instead of stdout
        #[arg(short, long)]
        output: Option<PathBuf>,
    },
}

/// Execute the CLI command.
#[tracing::instrument(skip(cli))]
pub fn execute(cli: Cli) -> anyhow::Result<()> {
    tracing::debug!("Executing CLI command");

    match cli.command() {
        Commands::Verify { action } => crate::verification::runner::handle(action),
        Commands::Verus { action } => handle_verus(action),
        Commands::Creusot { action } => handle_creusot(action),
        Commands::Graph { action } => handle_graph(action),
    }
}

/// Handle Verus verification commands.
#[tracing::instrument(skip(action))]
fn handle_verus(action: &VerusAction) -> anyhow::Result<()> {
    tracing::debug!(action = ?action, "Handling Verus command");

    match action {
        VerusAction::List => list_verus_proofs(),
        VerusAction::Run {
            output,
            timeout,
            resume,
            verus_path,
        } => run_verus_proofs(output, *timeout, *resume, verus_path.as_deref()),
        VerusAction::Summary { file } => show_verus_summary(file),
        VerusAction::Failed { file } => show_verus_failed(file),
    }
}

/// Handle Creusot verification commands.
#[tracing::instrument(skip(action))]
fn handle_creusot(action: &CreusotAction) -> anyhow::Result<()> {
    tracing::debug!(action = ?action, "Handling Creusot command");

    match action {
        CreusotAction::List => crate::verification::creusot_runner::list_modules(),
        CreusotAction::Run { output, resume } => {
            let summary = crate::verification::creusot_runner::run_all_modules(output, *resume)?;
            println!();
            println!("✅ Creusot verification complete!");
            println!("   Total: {}", summary.total());
            println!("   Passed: {}", summary.passed());
            println!("   Failed: {}", summary.failed());
            Ok(())
        }
        CreusotAction::Prove {
            output,
            goals,
            resume,
        } => {
            let workspace_root = std::env::current_dir()?;
            let summary = crate::verification::creusot_runner::run_all_modules_prove(
                output,
                goals,
                &workspace_root,
                *resume,
            )?;
            println!();
            println!("✅ Creusot prove complete!");
            println!("   Total: {}", summary.total());
            println!("   Passed: {}", summary.passed());
            println!("   Failed: {}", summary.failed());
            Ok(())
        }
        CreusotAction::Summary { file } => crate::verification::creusot_runner::show_summary(file),
    }
}

/// List all Verus proofs.
fn list_verus_proofs() -> anyhow::Result<()> {
    use crate::verification::verus_runner::VerusProof;

    let proofs = VerusProof::all();
    println!("📋 Available Verus Proofs ({} total):", proofs.len());
    println!();

    let mut by_module: std::collections::BTreeMap<String, Vec<String>> =
        std::collections::BTreeMap::new();
    for proof in proofs {
        by_module
            .entry(proof.module().to_string())
            .or_default()
            .push(proof.name().to_string());
    }

    for (module, proofs) in by_module {
        println!("  {}:", module);
        for proof in proofs {
            println!("    - {}", proof);
        }
        println!();
    }

    Ok(())
}

/// Run all Verus proofs with tracking.
fn run_verus_proofs(
    output: &std::path::Path,
    timeout: u64,
    resume: bool,
    verus_path: Option<&std::path::Path>,
) -> anyhow::Result<()> {
    use crate::verification::verus_runner;

    // Determine Verus path
    let verus_path = if let Some(path) = verus_path {
        path.to_path_buf()
    } else if let Ok(env_path) = std::env::var("VERUS_PATH") {
        // Try environment variable
        std::path::PathBuf::from(shellexpand::tilde(&env_path).to_string())
    } else {
        // Try default location
        let default_path =
            shellexpand::tilde("~/repos/verus/source/target-verus/release/verus").to_string();
        std::path::PathBuf::from(default_path)
    };

    if !verus_path.exists() {
        anyhow::bail!(
            "Verus not found at: {}\nSet VERUS_PATH environment variable or use --verus-path",
            verus_path.display()
        );
    }

    verus_runner::run_all_proofs(&verus_path, output, Some(timeout), resume)?;
    Ok(())
}

/// Show summary of Verus verification results.
fn show_verus_summary(file: &std::path::Path) -> anyhow::Result<()> {
    use crate::verification::verus_runner;

    let summary = verus_runner::summarize_results(file)?;

    println!("📊 Verus Verification Summary");
    println!("============================");
    println!();
    println!("  Total:   {}", summary.total());
    println!("  Passed:  {}", summary.passed());
    println!("  Failed:  {}", summary.failed());
    println!("  Errors:  {} 🔥", summary.errors());
    println!();
    println!("  Success Rate: {:.1}%", summary.success_rate());

    Ok(())
}

/// Show failed Verus proofs.
fn show_verus_failed(file: &std::path::Path) -> anyhow::Result<()> {
    use crate::verification::verus_runner;

    let failed = verus_runner::list_failed_proofs(file)?;

    if failed.is_empty() {
        println!("✅ No failed proofs!");
        return Ok(());
    }

    println!("❌ Failed Verus Proofs ({} total):", failed.len());
    println!();

    for result in failed {
        println!("  {}::{}", result.module(), result.proof());
        println!("    Status: {:?}", result.status());
        println!("    Time: {}s", result.time_seconds());
        if !result.error_message().is_empty() {
            println!(
                "    Error: {}",
                result.error_message().lines().next().unwrap_or("")
            );
        }
        println!();
    }

    Ok(())
}

/// Handle graph visualization commands.
#[tracing::instrument(skip(action))]
fn handle_graph(action: &GraphAction) -> anyhow::Result<()> {
    use crate::type_graph::{
        DotRenderer, GraphRenderer, MermaidDirection, MermaidRenderer, TypeGraph,
    };
    use std::io::Write;

    tracing::debug!(action = ?action, "Handling graph command");

    match action {
        GraphAction::List => {
            let types = TypeGraph::registered_types();
            if types.is_empty() {
                println!("No graphable types registered.");
                println!("Enable the `graph` feature and use `#[derive(Elicit)]` on your types.");
            } else {
                println!("{} registered graphable type(s):\n", types.len());
                for name in types {
                    println!("  {name}");
                }
            }
            Ok(())
        }

        GraphAction::Render {
            root,
            format,
            include_primitives,
            output,
        } => {
            tracing::debug!(root, format, "Rendering type graph");

            let graph = TypeGraph::from_root(root).map_err(|e| anyhow::anyhow!("{e}"))?;

            let rendered = match format.as_str() {
                "dot" => DotRenderer {
                    include_primitives: *include_primitives,
                    ..Default::default()
                }
                .render(&graph),
                _ => MermaidRenderer {
                    direction: MermaidDirection::TopDown,
                    include_primitives: *include_primitives,
                }
                .render(&graph),
            };

            match output {
                Some(path) => {
                    let mut file = std::fs::File::create(path)
                        .map_err(|e| anyhow::anyhow!("Cannot write to {}: {e}", path.display()))?;
                    file.write_all(rendered.as_bytes())?;
                    println!("Written to {}", path.display());
                    tracing::info!(path = %path.display(), format, "Graph written to file");
                }
                None => print!("{rendered}"),
            }

            Ok(())
        }
    }
}