use serde::Serialize;
use crate::identity::Key;
pub const SIDECAR: &str = "openspec-sidecar.json";
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct OpenspecSidecar {
pub format: &'static str,
pub sources: Vec<SourceFile>,
pub nodes: Vec<Provenance>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct SourceFile {
pub path: String,
pub sha256: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Provenance {
pub key: Key,
pub kind: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub capability: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
impl OpenspecSidecar {
pub(super) const fn new() -> Self {
Self {
format: "loft-openspec-sidecar/1",
sources: Vec::new(),
nodes: Vec::new(),
}
}
#[must_use]
pub fn to_json(&self) -> String {
let mut json = serde_json::to_string_pretty(self).expect("the sidecar serialises");
json.push('\n');
json
}
}