crtx-reflect 0.1.0

Reflection orchestration, prompts, candidate parsing, and schema validation.
Documentation
//! Store-backed quarantine audit records for rejected reflection output.

use chrono::Utc;
use cortex_store::repo::{AuditEntry, AuditRepo};
use cortex_store::{Pool, StoreResult};
use serde_json::json;

/// Stable audit operation for rejected reflection output.
pub const REFLECTION_QUARANTINE_OPERATION: &str = "reflection_quarantine";

/// Append one audit record for rejected reflection output.
///
/// The raw output is intentionally not persisted in the audit row. The row
/// carries a BLAKE3 hash plus parser reason so later quarantine storage can
/// correlate payloads without leaking model output through audit metadata.
pub fn quarantine_record(raw_output: &str, reason: &str, pool: &Pool) -> StoreResult<AuditEntry> {
    let output_hash = blake3::hash(raw_output.as_bytes()).to_hex().to_string();
    let entry = AuditEntry {
        id: cortex_core::AuditRecordId::new(),
        operation: REFLECTION_QUARANTINE_OPERATION.to_string(),
        target_ref: format!("reflection_output:{output_hash}"),
        before_hash: None,
        after_hash: output_hash.clone(),
        reason: reason.to_string(),
        actor_json: json!({
            "kind": "cortex_reflect",
            "component": "parser"
        }),
        source_refs_json: json!({
            "output_hash": output_hash,
            "reason": reason
        }),
        created_at: Utc::now(),
    };

    AuditRepo::new(pool).append(&entry)?;
    Ok(entry)
}