Skip to main content

chronicle/cli/
schema.rs

1use crate::error::Result;
2use schemars::schema_for;
3
4/// Run the `git chronicle schema <name>` subcommand.
5///
6/// Prints the JSON Schema for the requested type to stdout.
7/// This makes the CLI self-documenting for AI agents.
8pub fn run(name: &str) -> Result<()> {
9    let schema = match name {
10        "annotate-input" => {
11            schema_for!(crate::annotate::live::LiveInput)
12        }
13        "annotation" => {
14            schema_for!(crate::schema::v2::Annotation)
15        }
16        "knowledge" => {
17            schema_for!(crate::schema::knowledge::KnowledgeStore)
18        }
19        _ => {
20            return Err(crate::error::ChronicleError::Validation {
21                message: format!(
22                    "Unknown schema name: '{name}'. Available: annotate-input, annotation, knowledge"
23                ),
24                location: snafu::Location::default(),
25            });
26        }
27    };
28
29    let json =
30        serde_json::to_string_pretty(&schema).map_err(|e| crate::error::ChronicleError::Json {
31            source: e,
32            location: snafu::Location::default(),
33        })?;
34    println!("{json}");
35
36    Ok(())
37}