diff --git a/src/enrich.rs b/src/enrich.rs index f024129..782fd2c 100644 --- a/src/enrich.rs +++ b/src/enrich.rs @@ -19,6 +19,21 @@ use std::hash::{Hash, Hasher}; use crate::store::StoreView; +/// Parse a timestamp string like "2026-03-05T19:56" to unix epoch seconds. +fn parse_timestamp_to_epoch(ts: &str) -> Option { + use chrono::{Local, NaiveDateTime, TimeZone}; + // Try common formats + let formats = ["%Y-%m-%dT%H:%M:%S", "%Y-%m-%dT%H:%M", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M"]; + for fmt in &formats { + if let Ok(ndt) = NaiveDateTime::parse_from_str(ts, fmt) { + if let Some(dt) = Local.from_local_datetime(&ndt).earliest() { + return Some(dt.timestamp()); + } + } + } + None +} + /// Compute the store dedup key for a transcript file. /// This is the same key experience_mine uses to mark a transcript as mined. pub fn transcript_dedup_key(path: &str) -> Result { @@ -353,11 +368,16 @@ pub fn experience_mine( continue; } - // Write to store + // Write to store — use event timestamp, not mining time let mut node = new_node(&key, &full_content); node.node_type = store::NodeType::EpisodicSession; node.category = store::Category::Observation; node.provenance = store::Provenance::AgentExperienceMine; + if !ts.is_empty() { + if let Some(epoch) = parse_timestamp_to_epoch(ts) { + node.created_at = epoch; + } + } let _ = store.upsert_node(node); count += 1;