pidgin-lang 0.1.2

A compact agent handoff protocol runtime — parse, validate, resolve, and expand Pidgin packets
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
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
use std::fs;
use std::path::{Path, PathBuf};

use clap::{Parser, Subcommand};
use pidgin_lang::context::build_context_plan;
use pidgin_lang::expander::expand_to_run_packet;
use pidgin_lang::logging::{log_event, LogEvent};
use pidgin_lang::metrics::{compare_verbose, estimate_tokens, measure_packet};
use pidgin_lang::parser::parse_packet;
use pidgin_lang::registry::{load_action_registry, load_safety_rules, load_workflow_registry};
use pidgin_lang::resolver::{load_aliases, resolve_all, ResolverContext};
use pidgin_lang::router::{explain_route, route};
use pidgin_lang::safety::{check_resolved_refs_safety, check_safety};
use pidgin_lang::validator::syntax::validate_syntax;
use pidgin_lang::validator::schema::validate_schema;

fn canonicalize_host(host: &Path) -> PathBuf {
    host.canonicalize().unwrap_or_else(|e| {
        eprintln!("error: cannot canonicalize host path {}: {}", host.display(), e);
        std::process::exit(1);
    })
}

fn load_pipeline_configs(host: &Path) -> PipelineConfig {
    let config_dir = host.join(".pidgin");
    let workflow_path = config_dir.join("WORKFLOW_REGISTRY.yaml");
    let action_path = config_dir.join("ACTION_REGISTRY.yaml");
    let safety_path = config_dir.join("SAFETY_RULES.yaml");
    let aliases_path = config_dir.join("REFERENCE_ALIASES.yaml");

    let workflows = match load_workflow_registry(&workflow_path) {
        Ok(w) => w,
        Err(e) => {
            eprintln!("Error loading workflow registry: {}", e);
            std::process::exit(4);
        }
    };
    let actions = match load_action_registry(&action_path) {
        Ok(a) => a,
        Err(e) => {
            eprintln!("Error loading action registry: {}", e);
            std::process::exit(4);
        }
    };
    let safety_rules = match load_safety_rules(&safety_path) {
        Ok(s) => s,
        Err(e) => {
            eprintln!("Error loading safety rules: {}", e);
            std::process::exit(4);
        }
    };
    let aliases = match load_aliases(&aliases_path) {
        Ok(a) => a,
        Err(e) => {
            eprintln!("Error loading reference aliases: {}", e);
            std::process::exit(4);
        }
    };

    PipelineConfig {
        workflows,
        actions,
        safety_rules,
        aliases,
    }
}

struct PipelineConfig {
    workflows: pidgin_lang::registry::WorkflowRegistry,
    actions: pidgin_lang::registry::ActionRegistry,
    safety_rules: pidgin_lang::registry::SafetyRules,
    aliases: pidgin_lang::resolver::ReferenceAliases,
}

#[derive(Parser)]
#[command(name = "pgn", about = "Pidgin — A compact agent handoff protocol runtime")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Parse a Pidgin packet and print the AST
    Parse {
        file: PathBuf,
    },

    /// Validate a Pidgin packet (syntax + schema)
    Validate {
        #[arg(required = true)]
        files: Vec<PathBuf>,
        #[arg(long, default_value = ".")]
        host: PathBuf,
    },

    /// Validate → safety gate → resolve, end to end
    Check {
        file: PathBuf,
        #[arg(long, default_value = ".")]
        host: PathBuf,
    },

    /// Resolve all short references in a packet
    Resolve {
        file: PathBuf,
        #[arg(long, default_value = ".")]
        host: PathBuf,
    },

    /// Expand a packet into its executable form
    Expand {
        file: PathBuf,
        #[arg(long, default_value = ".")]
        host: PathBuf,
        #[arg(long)]
        r#out: Option<PathBuf>,
    },

    /// Build a context plan for what to retrieve
    ContextPlan {
        file: PathBuf,
        #[arg(long, default_value = ".")]
        host: PathBuf,
    },

    /// Estimate token cost of a packet
    Measure {
        file: PathBuf,
    },

    /// Compare a pgn file against a verbose text version
    Compare {
        pgn_file: PathBuf,
        #[arg(long)]
        verbose: PathBuf,
    },

    /// Run the full pipeline (parse → validate → safety → resolve → expand)
    Run {
        file: PathBuf,
        #[arg(long, default_value = ".")]
        host: PathBuf,
        #[arg(long)]
        out: Option<PathBuf>,
    },

    /// Check host configuration
    Doctor {
        #[arg(long, default_value = ".")]
        host: PathBuf,
    },
}

fn main() {
    let cli = Cli::parse();

    match cli.command {
        Commands::Parse { file } => {
            let content = match fs::read_to_string(&file) {
                Ok(c) => c,
                Err(e) => {
                    eprintln!("Error reading file: {}", e);
                    std::process::exit(1);
                }
            };
            match parse_packet(&content) {
                Ok(packet) => println!("{:#?}", packet),
                Err(e) => {
                    eprintln!("Parse error: {}", e);
                    std::process::exit(1);
                }
            }
        }

        Commands::Validate { files, host } => {
            let cfg = load_pipeline_configs(&host);
            let mut all_passed = true;
            for file in &files {
                let content = match fs::read_to_string(file) {
                    Ok(c) => c,
                    Err(e) => {
                        eprintln!("{}: FAIL (read error: {})", file.display(), e);
                        all_passed = false;
                        continue;
                    }
                };
                let packet = match parse_packet(&content) {
                    Ok(p) => p,
                    Err(e) => {
                        eprintln!("{}: FAIL (parse error: {})", file.display(), e);
                        all_passed = false;
                        continue;
                    }
                };
                let mut errors = validate_syntax(&packet);
                errors.extend(validate_schema(&packet, &cfg.workflows));
                if errors.is_empty() {
                    println!("{}: PASS", file.display());
                } else {
                    eprintln!("{}: FAIL", file.display());
                    for err in &errors {
                        eprintln!("  [{}] {}", err.code, err.message);
                    }
                    all_passed = false;
                }
            }
            if !all_passed {
                std::process::exit(1);
            }
        }

        Commands::Check { file, host } => {
            let cfg = load_pipeline_configs(&host);
            let host_root = canonicalize_host(&host);
            let content = match fs::read_to_string(&file) {
                Ok(c) => c,
                Err(e) => {
                    eprintln!("{}: FAIL (read error: {})", file.display(), e);
                    std::process::exit(1);
                }
            };
            let packet = match parse_packet(&content) {
                Ok(p) => p,
                Err(e) => {
                    eprintln!("{}: FAIL (parse error: {})", file.display(), e);
                    std::process::exit(1);
                }
            };

            let mut all_errors: Vec<String> = Vec::new();
            for err in &validate_syntax(&packet) {
                all_errors.push(format!("  [{}] {}", err.code, err.message));
            }
            for err in &validate_schema(&packet, &cfg.workflows) {
                all_errors.push(format!("  [{}] {}", err.code, err.message));
            }

            let safety_result = check_safety(&packet, &cfg.actions, &cfg.safety_rules, &cfg.workflows);
            for rule in &safety_result.fired_rules {
                all_errors.push(format!("  [{}] (safety)", rule));
            }

            let required_inputs = packet
                .fields
                .get("wf")
                .and_then(|v| match v {
                    pidgin_lang::ast::FieldValue::Scalar(s) => cfg.workflows.workflows.get(s),
                    _ => None,
                })
                .map(|w| w.required_inputs.clone())
                .unwrap_or_default();

            let ctx = ResolverContext {
                host_root,
                aliases: cfg.aliases,
                required_inputs,
            };
            let resolved = resolve_all(&packet, &ctx);
            let resolved_fired = check_resolved_refs_safety(&resolved, &cfg.safety_rules.private_paths);
            for rule in &resolved_fired {
                all_errors.push(format!("  [{}] (safety after resolution)", rule));
            }
            for r in &resolved {
                if r.required && matches!(r.status, pidgin_lang::resolver::ResolutionStatus::Unresolved | pidgin_lang::resolver::ResolutionStatus::Forbidden) {
                    let label = match r.status {
                        pidgin_lang::resolver::ResolutionStatus::Unresolved => "UNRESOLVED",
                        pidgin_lang::resolver::ResolutionStatus::Forbidden => "FORBIDDEN",
                        _ => "ERROR",
                    };
                    all_errors.push(format!("  [{}] {} (required)", label, r.original));
                }
            }

            if all_errors.is_empty() {
                println!("{}: PASS", file.display());
            } else {
                println!("{}: FAIL", file.display());
                for err in &all_errors {
                    eprintln!("{}", err);
                }
                let has_validation = !validate_syntax(&packet).is_empty()
                    || !validate_schema(&packet, &cfg.workflows).is_empty();
                std::process::exit(if has_validation { 1 } else { 2 });
            }
        }

        Commands::Resolve { file, host } => {
            let cfg = load_pipeline_configs(&host);
            let host_root = canonicalize_host(&host);
            let content = match fs::read_to_string(&file) {
                Ok(c) => c,
                Err(e) => {
                    eprintln!("{}: Error reading file: {}", file.display(), e);
                    std::process::exit(1);
                }
            };
            let packet = match parse_packet(&content) {
                Ok(p) => p,
                Err(e) => {
                    eprintln!("{}: Parse error: {}", file.display(), e);
                    std::process::exit(1);
                }
            };
            let required_inputs = packet
                .fields
                .get("wf")
                .and_then(|v| match v {
                    pidgin_lang::ast::FieldValue::Scalar(s) => cfg.workflows.workflows.get(s),
                    _ => None,
                })
                .map(|w| w.required_inputs.clone())
                .unwrap_or_default();
            let ctx = ResolverContext {
                host_root,
                aliases: cfg.aliases,
                required_inputs,
            };
            let results = resolve_all(&packet, &ctx);
            if results.is_empty() {
                println!("{}: no references found", file.display());
                return;
            }
            let mut all_ok = true;
            println!("{}: {}", file.display(), results.len());
            for r in &results {
                let status = match r.status {
                    pidgin_lang::resolver::ResolutionStatus::Resolved => "RESOLVED",
                    pidgin_lang::resolver::ResolutionStatus::Missing => "MISSING",
                    pidgin_lang::resolver::ResolutionStatus::Unresolved => "UNRESOLVED",
                    pidgin_lang::resolver::ResolutionStatus::Forbidden => "FORBIDDEN",
                };
                let path = r.resolved_path.as_ref().map(|p| p.display().to_string()).unwrap_or_else(|| "-".to_string());
                println!("  {}  ns={}  id={}  confidence={:.1}  required={}  path={}", status, r.namespace, r.ref_id, r.confidence, r.required, path);
                if r.required && matches!(r.status, pidgin_lang::resolver::ResolutionStatus::Unresolved | pidgin_lang::resolver::ResolutionStatus::Forbidden) {
                    all_ok = false;
                }
            }
            if !all_ok {
                std::process::exit(3);
            }
        }

        Commands::Expand { file, host, r#out } => {
            let cfg = load_pipeline_configs(&host);
            let content = fs::read_to_string(&file).unwrap_or_else(|e| {
                eprintln!("{}: Error reading file: {}", file.display(), e);
                std::process::exit(1);
            });
            let packet = parse_packet(&content).unwrap_or_else(|e| {
                eprintln!("{}: Parse error: {}", file.display(), e);
                std::process::exit(1);
            });

            let syntax_errors = validate_syntax(&packet);
            let schema_errors = validate_schema(&packet, &cfg.workflows);
            if !syntax_errors.is_empty() || !schema_errors.is_empty() {
                eprintln!("{}: Cannot expand — validation errors", file.display());
                for err in &syntax_errors {
                    eprintln!("  [{}] {}", err.code, err.message);
                }
                for err in &schema_errors {
                    eprintln!("  [{}] {}", err.code, err.message);
                }
                std::process::exit(1);
            }

            let safety = check_safety(&packet, &cfg.actions, &cfg.safety_rules, &cfg.workflows);
            let decision = route(&packet, &cfg.workflows, &safety);
            let expanded = expand_to_run_packet(&packet, &[], &safety, &cfg.workflows);

            let yaml = serde_yaml::to_string(&expanded).unwrap_or_else(|e| {
                eprintln!("Error serializing expanded packet: {}", e);
                std::process::exit(5);
            });

            match r#out {
                Some(path) => {
                    fs::write(&path, &yaml).unwrap_or_else(|e| {
                        eprintln!("Error writing output: {}", e);
                        std::process::exit(5);
                    });
                    println!("{}: expanded -> {}", file.display(), path.display());
                }
                None => {
                    println!("---");
                    println!("{}", yaml.trim());
                    println!("---");
                    println!("Route: {}", explain_route(&decision));
                }
            }

            let _ = log_event(
                &host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"),
                &LogEvent::Expand {
                    run_id: packet.run_id.clone(),
                    packet_type: "run".to_string(),
                },
            );
        }

        Commands::ContextPlan { file, host } => {
            let cfg = load_pipeline_configs(&host);
            let host_root = canonicalize_host(&host);
            let content = fs::read_to_string(&file).unwrap_or_else(|e| {
                eprintln!("{}: Error reading file: {}", file.display(), e);
                std::process::exit(1);
            });
            let packet = parse_packet(&content).unwrap_or_else(|e| {
                eprintln!("{}: Parse error: {}", file.display(), e);
                std::process::exit(1);
            });
            let required_inputs = packet
                .fields
                .get("wf")
                .and_then(|v| match v {
                    pidgin_lang::ast::FieldValue::Scalar(s) => cfg.workflows.workflows.get(s),
                    _ => None,
                })
                .map(|w| w.required_inputs.clone())
                .unwrap_or_default();
            let ctx = ResolverContext { host_root, aliases: cfg.aliases, required_inputs };
            let resolved = resolve_all(&packet, &ctx);
            let plan = build_context_plan(&packet, &resolved);
            let yaml = serde_yaml::to_string(&plan).unwrap_or_else(|e| {
                eprintln!("Error serializing context plan: {}", e);
                std::process::exit(5);
            });
            println!("{}", yaml.trim());
        }

        Commands::Measure { file } => {
            let content = fs::read_to_string(&file).unwrap_or_else(|e| {
                eprintln!("{}: Error reading file: {}", file.display(), e);
                std::process::exit(1);
            });
            let tokens = estimate_tokens(&content);
            match parse_packet(&content) {
                Ok(packet) => {
                    let report = measure_packet(&packet);
                    let yaml = serde_yaml::to_string(&report).unwrap_or_else(|e| {
                        eprintln!("Error: {}", e);
                        std::process::exit(5);
                    });
                    println!("{}", yaml.trim());
                }
                Err(_) => {
                    println!("char_count: {}", content.len());
                    println!("estimated_tokens: {}", tokens);
                }
            }
        }

        Commands::Compare { pgn_file, verbose } => {
            let pgn_text = fs::read_to_string(&pgn_file).unwrap_or_else(|e| {
                eprintln!("Error reading pgn file: {}", e);
                std::process::exit(1);
            });
            let verbose_text = fs::read_to_string(&verbose).unwrap_or_else(|e| {
                eprintln!("Error reading verbose file: {}", e);
                std::process::exit(1);
            });
            let report = compare_verbose(&pgn_text, &verbose_text);
            let yaml = serde_yaml::to_string(&report).unwrap_or_else(|e| {
                eprintln!("Error: {}", e);
                std::process::exit(5);
            });
            println!("{}", yaml.trim());
        }

        Commands::Run { file, host, out } => {
            let cfg = load_pipeline_configs(&host);
            let host_root = canonicalize_host(&host);
            let run_id;

            // Parse
            let content = fs::read_to_string(&file).unwrap_or_else(|e| {
                eprintln!("{}: Error reading file: {}", file.display(), e);
                std::process::exit(1);
            });
            let packet = match parse_packet(&content) {
                Ok(p) => { run_id = p.run_id.clone(); p }
                Err(e) => {
                    eprintln!("{}: Parse error: {}", file.display(), e);
                    let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Parse { run_id: file.display().to_string(), ok: false });
                    std::process::exit(1);
                }
            };
            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Parse { run_id: run_id.clone(), ok: true });

            // Validate
            let syntax_errors = validate_syntax(&packet);
            let schema_errors = validate_schema(&packet, &cfg.workflows);
            if !syntax_errors.is_empty() || !schema_errors.is_empty() {
                eprintln!("{}: Validation errors", file.display());
                for err in &syntax_errors { eprintln!("  [{}] {}", err.code, err.message); }
                for err in &schema_errors { eprintln!("  [{}] {}", err.code, err.message); }
                let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Validate { run_id: run_id.clone(), ok: false });
                std::process::exit(1);
            }
            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Validate { run_id: run_id.clone(), ok: true });

            // Safety
            let safety = check_safety(&packet, &cfg.actions, &cfg.safety_rules, &cfg.workflows);
            let rules_str = safety.fired_rules.iter().map(|r| r.to_string()).collect::<Vec<_>>().join(",");
            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::SafetyGate { run_id: run_id.clone(), blocked: safety.blocked, rules: rules_str });
            if safety.blocked {
                eprintln!("{}: Blocked by safety", file.display());
                for rule in &safety.fired_rules { eprintln!("  [{}]", rule); }
                std::process::exit(2);
            }

            // Resolve
            let required_inputs = packet
                .fields.get("wf")
                .and_then(|v| match v { pidgin_lang::ast::FieldValue::Scalar(s) => cfg.workflows.workflows.get(s), _ => None })
                .map(|w| w.required_inputs.clone())
                .unwrap_or_default();
            let ctx = ResolverContext { host_root, aliases: cfg.aliases, required_inputs };
            let resolved = resolve_all(&packet, &ctx);

            // Post-resolution private path check
            let resolved_fired = check_resolved_refs_safety(&resolved, &cfg.safety_rules.private_paths);
            if !resolved_fired.is_empty() {
                for rule in &resolved_fired {
                    eprintln!("{}: Blocked by safety after resolution: {}", file.display(), rule);
                }
                std::process::exit(2);
            }

            let unresolved = resolved.iter().filter(|r| matches!(r.status, pidgin_lang::resolver::ResolutionStatus::Unresolved | pidgin_lang::resolver::ResolutionStatus::Forbidden)).count();
            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Resolve { run_id: run_id.clone(), refs_total: resolved.len(), refs_unresolved: unresolved });
            for r in &resolved {
                if r.required && matches!(r.status, pidgin_lang::resolver::ResolutionStatus::Unresolved | pidgin_lang::resolver::ResolutionStatus::Forbidden) {
                    eprintln!("{}: Required reference {}: {}", file.display(), match r.status {
                        pidgin_lang::resolver::ResolutionStatus::Forbidden => "forbidden (path traversal blocked)",
                        _ => "unresolved",
                    }, r.original);
                    std::process::exit(3);
                }
            }

            // Route
            let decision = route(&packet, &cfg.workflows, &safety);

            // Expand
            let expanded = expand_to_run_packet(&packet, &resolved, &safety, &cfg.workflows);
            let yaml = serde_yaml::to_string(&expanded).unwrap_or_else(|e| {
                eprintln!("Error serializing: {}", e);
                std::process::exit(5);
            });
            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Expand { run_id: run_id.clone(), packet_type: "run".to_string() });

            match out {
                Some(path) => {
                    fs::write(&path, &yaml).unwrap_or_else(|e| {
                        eprintln!("Error writing output: {}", e);
                        std::process::exit(5);
                    });
                    println!("{}: expanded -> {} (dry-run)", file.display(), path.display());
                }
                None => {
                    println!("---");
                    println!("{}", yaml.trim());
                    println!("---");
                    println!("Route: {}", explain_route(&decision));
                }
            }

            let _ = log_event(&host.join(".pidgin").join("logs").join("PIDGIN_RUNTIME_RUNS.csv"), &LogEvent::Run { run_id: run_id.clone(), status: "dry_run_ok".to_string() });
        }

        Commands::Doctor { host } => {
            let config_dir = host.join(".pidgin");
            let checks = vec![
                ("WORKFLOW_REGISTRY.yaml", config_dir.join("WORKFLOW_REGISTRY.yaml")),
                ("ACTION_REGISTRY.yaml", config_dir.join("ACTION_REGISTRY.yaml")),
                ("SAFETY_RULES.yaml", config_dir.join("SAFETY_RULES.yaml")),
                ("REFERENCE_ALIASES.yaml", config_dir.join("REFERENCE_ALIASES.yaml")),
            ];

            let mut all_ok = true;
            for (name, path) in &checks {
                if path.exists() {
                    println!("  OK  {}", name);
                } else {
                    eprintln!("  MISS  {}", name);
                    all_ok = false;
                }
            }

            // Check YAML parsability
            for (name, path) in &checks {
                if path.exists() {
                    match std::fs::read_to_string(path) {
                        Ok(content) => {
                            if serde_yaml::from_str::<serde_yaml::Value>(&content).is_ok() {
                                println!("  OK  {} (valid YAML)", name);
                            } else {
                                eprintln!("  INVALID  {} (malformed YAML)", name);
                                all_ok = false;
                            }
                        }
                        Err(e) => {
                            eprintln!("  ERR  {}: {}", name, e);
                            all_ok = false;
                        }
                    }
                }
            }

            if all_ok {
                println!("All checks passed");
            } else {
                std::process::exit(4);
            }
        }
    }
}