second-brain-core 0.12.0

Core library for second-brain: SQLite storage with vector and lexical indexes, BGE embeddings, and hybrid retrieval
Documentation
/// The directory under the data dir where writes wait for the daemon; the
/// MCP server, the daemon's write gate and its replayer all use it.
pub const DIR_NAME: &str = "queue";

/// `<19-digit unix nanos>-<uuid>.json`; no other name in the directory is
/// an entry, so a file still being written under a temporary name is never
/// read.
pub fn is_entry_name(name: &str) -> bool {
    let Some(stem) = name.strip_suffix(".json") else {
        return false;
    };
    let Some((nanos, id)) = stem.split_at_checked(19) else {
        return false;
    };
    nanos.bytes().all(|b| b.is_ascii_digit())
        && id
            .strip_prefix('-')
            .is_some_and(|id| id.len() == 36 && uuid::Uuid::parse_str(id).is_ok())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn only_timestamped_uuid_json_names_are_entries() {
        let id = "0b5c2f9e-5d0e-4c1a-9a57-0c7f4f1f2a10";
        assert!(is_entry_name(&format!("1793505622000000000-{id}.json")));
        for name in [
            "projects.json".to_string(),
            ".lock".to_string(),
            format!("1793505622000000000-{id}.json.tmp"),
            format!("179350562200000000-{id}.json"),
            format!("1793505622000000000-{id}.unreadable"),
            "1793505622000000000-not-a-uuid.json".to_string(),
        ] {
            assert!(!is_entry_name(&name), "{name}");
        }
    }
}