vios_app 0.1.1

Small JSON vaults: Argon2id + AES-GCM, with optional AAD binding.
Documentation
use std::fs::{self, OpenOptions};
use serde::{Serialize, Deserialize};
use crate::naorix::naorix_emotion::EmotionState;

#[derive(Serialize, Deserialize)]
pub struct NaorixMemory {
    pub vault_id: String,
    pub tone: String,
    pub intent: String,
    pub reem_code: String,
    pub timestamp: String,
    pub cia_hash: String,
    pub parent_hash: String,
}

pub fn update_naorix_memory(vault_id: &str, emotion: &EmotionState, cia_hash: &str) {
    let path = "vaults/naorix_memory.json";
    let mut log: Vec<NaorixMemory> = if let Ok(data) = fs::read_to_string(path) {
        serde_json::from_str(&data).unwrap_or_default()
    } else {
        Vec::new()
    };

    let parent_hash = log.last().map(|m| m.cia_hash.clone()).unwrap_or("🕳 Origin".to_string());

    let new_entry = NaorixMemory {
        vault_id: vault_id.to_string(),
        tone: emotion.tone.clone(),
        intent: emotion.intent.clone(),
        reem_code: emotion.reem_code.clone(),
        timestamp: emotion.timestamp.clone(),
        cia_hash: cia_hash.to_string(),
        parent_hash,
    };

    log.push(new_entry);
    let json = serde_json::to_string_pretty(&log).expect("❌ Failed to serialize memory log.");
    fs::write(path, json).expect("❌ Failed to write naorix_memory.json.");
}