vios_app 0.1.1

Small JSON vaults: Argon2id + AES-GCM, with optional AAD binding.
Documentation
// 🧬 vault_lineage_chain.rs – Links VaultMemory into a chronological ancestry chain

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::fs::{OpenOptions};
use std::path::Path;
use crate::vault::vault_structs::VaultMemory;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VaultLineageEntry {
    pub id: String,
    pub timestamp: DateTime<Utc>,
    pub tone: String,
    pub reem_code: String,
    pub cia_signature: String,
    pub parent_id: Option<String>,
    pub link_strength: f32,
}

/// Save a VaultLineageEntry to the lineage chain
pub fn append_lineage_entry(current: &VaultMemory, parent: Option<&VaultMemory>) -> std::io::Result<()> {
    let parent_id = parent.map(|p| p.cia_signature.clone());

    let strength = match parent {
        Some(p) => calculate_link_strength(current, p),
        None => 1.0, // root node
    };

    let entry = VaultLineageEntry {
        id: current.cia_signature.clone(),
        timestamp: DateTime::parse_from_rfc3339(&current.created_at)
            .unwrap()
            .with_timezone(&Utc),
        tone: current.tone.clone(),
        reem_code: current.reem_code.clone(),
        cia_signature: current.cia_signature.clone(),
        parent_id,
        link_strength: strength,
    };

    let path = Path::new("vaults/mesh_logs/lineage_chain.jsonl");
    let file = OpenOptions::new().append(true).create(true).open(path)?;
    let line = serde_json::to_string(&entry)?;
    writeln!(writer, "{}", line)?;
    Ok(())
}

/// Very basic link strength calc based on tone and REEM similarity
fn calculate_link_strength(current: &VaultMemory, parent: &VaultMemory) -> f32 {
    let tone_match = (current.tone == parent.tone) as u8 as f32;
    let reem_match = (current.reem_code == parent.reem_code) as u8 as f32;
    0.5 * tone_match + 0.5 * reem_match
}