agentoven-cli 0.6.0

CLI for AgentOven — bake production-ready AI agents from the terminal
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
//! `agentoven recipe` — manage multi-agent workflows.

use clap::{Args, Subcommand};
use colored::Colorize;
use serde_json;

use agentoven_core::recipe::{Step, StepKind};

#[derive(Subcommand)]
pub enum RecipeCommands {
    /// Create a new recipe.
    Create(CreateArgs),
    /// List all recipes.
    List,
    /// Get recipe details.
    Get(GetArgs),
    /// Delete a recipe.
    Delete(DeleteArgs),
    /// Bake (execute) a recipe.
    Bake(RecipeBakeArgs),
    /// Show recipe execution history / runs.
    Runs(RunsArgs),
    /// Approve a human gate in a recipe run.
    Approve(ApproveArgs),
}

#[derive(Args)]
pub struct CreateArgs {
    /// Recipe name.
    pub name: String,
    /// Path to recipe definition YAML/TOML.
    #[arg(long, short)]
    pub from: Option<String>,
}

#[derive(Args)]
pub struct GetArgs {
    /// Recipe name.
    pub name: String,
}

#[derive(Args)]
pub struct DeleteArgs {
    /// Recipe name.
    pub name: String,
    /// Skip confirmation.
    #[arg(long)]
    pub force: bool,
}

#[derive(Args)]
pub struct RecipeBakeArgs {
    /// Recipe name.
    pub name: String,
    /// Input data as JSON string.
    #[arg(long, short)]
    pub input: Option<String>,
    /// Input from file.
    #[arg(long)]
    pub input_file: Option<String>,
}

#[derive(Args)]
pub struct RunsArgs {
    /// Recipe name.
    pub name: String,
    /// Number of recent runs to show.
    #[arg(long, short, default_value = "10")]
    pub limit: u32,
}

#[derive(Args)]
pub struct ApproveArgs {
    /// Recipe name.
    pub name: String,
    /// Run ID.
    #[arg(long)]
    pub run_id: String,
    /// Gate ID.
    #[arg(long)]
    pub gate_id: String,
    /// Approve or reject.
    #[arg(long, default_value = "true")]
    pub approved: bool,
    /// Comment.
    #[arg(long)]
    pub comment: Option<String>,
}

pub async fn execute(cmd: RecipeCommands) -> anyhow::Result<()> {
    match cmd {
        RecipeCommands::Create(args) => create(args).await,
        RecipeCommands::List => list().await,
        RecipeCommands::Get(args) => get(args).await,
        RecipeCommands::Delete(args) => delete(args).await,
        RecipeCommands::Bake(args) => bake(args).await,
        RecipeCommands::Runs(args) => runs(args).await,
        RecipeCommands::Approve(args) => approve(args).await,
    }
}

async fn create(args: CreateArgs) -> anyhow::Result<()> {
    println!("\n  📖 Creating recipe: {}\n", args.name.bold());

    let client = agentoven_core::AgentOvenClient::from_env()?;

    let steps = if let Some(ref from_path) = args.from {
        let content = tokio::fs::read_to_string(from_path).await?;
        let parsed: serde_json::Value = if from_path.ends_with(".toml") {
            let toml_val: toml::Value = content.parse()?;
            serde_json::to_value(toml_val)?
        } else if from_path.ends_with(".yaml") || from_path.ends_with(".yml") {
            serde_yaml::from_str(&content)?
        } else {
            serde_json::from_str(&content)?
        };

        // Extract steps array from the parsed document
        let steps_arr = parsed
            .get("steps")
            .and_then(|v| v.as_array())
            .ok_or_else(|| anyhow::anyhow!("Missing 'steps' array in {}", from_path))?;

        steps_arr
            .iter()
            .map(|s| {
                let name = s["name"].as_str().unwrap_or("step").to_string();
                let agent = s.get("agent").and_then(|v| v.as_str()).map(String::from);
                let kind_str = s.get("kind").and_then(|v| v.as_str()).unwrap_or("agent");
                let kind = match kind_str {
                    "human-gate" | "gate" => StepKind::HumanGate,
                    "evaluator" => StepKind::Evaluator,
                    "condition" | "branch" => StepKind::Condition,
                    "fan-out" | "parallel" => StepKind::FanOut,
                    "fan-in" | "join" => StepKind::FanIn,
                    _ => StepKind::Agent,
                };
                let depends_on = s
                    .get("depends_on")
                    .and_then(|v| v.as_array())
                    .map(|arr| {
                        arr.iter()
                            .filter_map(|v| v.as_str().map(String::from))
                            .collect()
                    })
                    .unwrap_or_default();
                let timeout = s.get("timeout").and_then(|v| v.as_str()).map(String::from);
                let parallel = s.get("parallel").and_then(|v| v.as_bool()).unwrap_or(false);

                Step {
                    id: uuid::Uuid::new_v4().to_string(),
                    name,
                    kind,
                    agent,
                    parallel,
                    timeout,
                    depends_on,
                    retry: None,
                    notify: Vec::new(),
                    config: None,
                }
            })
            .collect()
    } else {
        Vec::new()
    };

    let recipe = agentoven_core::Recipe::new(&args.name, steps);
    match client.create_recipe(&recipe).await {
        Ok(created) => {
            println!(
                "  {} Recipe '{}' created (ID: {}).",
                "".green().bold(),
                args.name,
                created.id.dimmed()
            );
            println!(
                "  {} Execute with: {}",
                "".dimmed(),
                format!("agentoven recipe bake {}", args.name).green()
            );
        }
        Err(e) => {
            println!(
                "  {} Could not create recipe: {}",
                "".yellow().bold(),
                e.to_string().dimmed()
            );
            println!(
                "  {} Recipe validated locally. ID: {}",
                "".green().bold(),
                recipe.id.dimmed()
            );
        }
    }
    Ok(())
}

async fn list() -> anyhow::Result<()> {
    println!("\n  📖 Recipes:\n");

    let client = agentoven_core::AgentOvenClient::from_env()?;
    match client.list_recipes().await {
        Ok(recipes) => {
            if recipes.is_empty() {
                println!("  (no recipes yet — use `agentoven recipe create`)");
            } else {
                println!(
                    "  {:<24} {:<12} {:<8} {:<20}",
                    "NAME".bold(),
                    "STATUS".bold(),
                    "STEPS".bold(),
                    "CREATED".bold()
                );
                println!("  {}", "".repeat(66).dimmed());
                for r in &recipes {
                    let name = r["name"].as_str().unwrap_or("-");
                    let status = r["status"].as_str().unwrap_or("-");
                    let steps = r["steps"].as_array().map(|a| a.len()).unwrap_or(0);
                    let created = r["created_at"].as_str().unwrap_or("-");
                    let created_short = if created.len() > 16 {
                        &created[..16]
                    } else {
                        created
                    };
                    println!(
                        "  {:<24} {:<12} {:<8} {}",
                        name, status, steps, created_short
                    );
                }
                println!("\n  {} {} recipe(s)", "".dimmed(), recipes.len());
            }
        }
        Err(e) => {
            println!(
                "  {} Could not list recipes: {}",
                "".yellow().bold(),
                e.to_string().dimmed()
            );
        }
    }
    Ok(())
}

async fn get(args: GetArgs) -> anyhow::Result<()> {
    println!("\n  📖 Recipe: {}\n", args.name.bold());

    let client = agentoven_core::AgentOvenClient::from_env()?;
    match client.get_recipe(&args.name).await {
        Ok(r) => {
            let pretty = serde_json::to_string_pretty(&r).unwrap_or_default();
            for line in pretty.lines() {
                println!("  {}", line.dimmed());
            }
        }
        Err(e) => {
            println!(
                "  {} Not found: {}",
                "".yellow().bold(),
                e.to_string().dimmed()
            );
        }
    }
    Ok(())
}

async fn delete(args: DeleteArgs) -> anyhow::Result<()> {
    if !args.force {
        let confirm = dialoguer::Confirm::new()
            .with_prompt(format!("  Delete recipe '{}'?", args.name))
            .default(false)
            .interact()?;
        if !confirm {
            println!("  {} Cancelled.", "".dimmed());
            return Ok(());
        }
    }

    let client = agentoven_core::AgentOvenClient::from_env()?;
    match client.delete_recipe(&args.name).await {
        Ok(()) => println!("  {} Recipe '{}' deleted.", "".green().bold(), args.name),
        Err(e) => println!(
            "  {} Delete failed: {}",
            "".red().bold(),
            e.to_string().dimmed()
        ),
    }
    Ok(())
}

async fn bake(args: RecipeBakeArgs) -> anyhow::Result<()> {
    println!("\n  🔥 Baking recipe: {}\n", args.name.bold());

    let client = agentoven_core::AgentOvenClient::from_env()?;

    let input = if let Some(ref json_str) = args.input {
        serde_json::from_str(json_str)?
    } else if let Some(ref file_path) = args.input_file {
        let content = tokio::fs::read_to_string(file_path).await?;
        serde_json::from_str(&content)?
    } else {
        serde_json::json!({})
    };

    match client.bake_recipe(&args.name, input).await {
        Ok(result) => {
            println!("  {} Recipe baking started!", "".green().bold());
            if let Some(run_id) = result.get("run_id").or(result.get("task_id")) {
                println!(
                    "  {} Run ID: {}",
                    "".dimmed(),
                    run_id.as_str().unwrap_or("?").cyan()
                );
            }
            println!(
                "  {} Monitor with: {}",
                "".dimmed(),
                format!("agentoven recipe runs {}", args.name).green()
            );
        }
        Err(e) => {
            println!(
                "  {} Recipe bake failed: {}",
                "".red().bold(),
                e.to_string().dimmed()
            );
        }
    }
    Ok(())
}

async fn runs(args: RunsArgs) -> anyhow::Result<()> {
    println!(
        "\n  📊 Runs for recipe: {} (last {})\n",
        args.name.bold(),
        args.limit
    );

    let client = agentoven_core::AgentOvenClient::from_env()?;
    match client.recipe_runs(&args.name).await {
        Ok(runs_list) => {
            if runs_list.is_empty() {
                println!(
                    "  (no runs yet — use `agentoven recipe bake {}` to start)",
                    args.name
                );
            } else {
                println!(
                    "  {:<36} {:<12} {:<12} {:<20}",
                    "RUN ID".bold(),
                    "STATUS".bold(),
                    "DURATION".bold(),
                    "STARTED".bold()
                );
                println!("  {}", "".repeat(82).dimmed());
                for run in runs_list.iter().take(args.limit as usize) {
                    let id = run["id"].as_str().unwrap_or("-");
                    let status = run["status"].as_str().unwrap_or("-");
                    let duration = run["duration"].as_str().unwrap_or("-");
                    let started = run["started_at"].as_str().unwrap_or("-");
                    let started_short = if started.len() > 16 {
                        &started[..16]
                    } else {
                        started
                    };
                    println!(
                        "  {:<36} {:<12} {:<12} {}",
                        id, status, duration, started_short
                    );
                }
                println!("\n  {} {} run(s)", "".dimmed(), runs_list.len());
            }
        }
        Err(e) => {
            println!(
                "  {} Could not fetch runs: {}",
                "".yellow().bold(),
                e.to_string().dimmed()
            );
        }
    }
    Ok(())
}

async fn approve(args: ApproveArgs) -> anyhow::Result<()> {
    let action = if args.approved {
        "Approving"
    } else {
        "Rejecting"
    };
    println!(
        "\n{} gate {} in run {}...\n",
        action,
        args.gate_id.bold(),
        args.run_id.dimmed()
    );

    let client = agentoven_core::AgentOvenClient::from_env()?;
    match client
        .approve_gate(
            &args.name,
            &args.run_id,
            &args.gate_id,
            args.approved,
            args.comment.as_deref(),
        )
        .await
    {
        Ok(_) => {
            println!(
                "  {} Gate {} {}.",
                "".green().bold(),
                args.gate_id,
                if args.approved {
                    "approved"
                } else {
                    "rejected"
                }
            );
        }
        Err(e) => {
            println!("  {} Failed: {}", "".red().bold(), e.to_string().dimmed());
        }
    }
    Ok(())
}