replace libc date math with chrono, extract memory_subdir helper

- date_to_epoch, iso_week_info, weeks_in_month: replaced unsafe libc
  (mktime, strftime, localtime_r) with chrono NaiveDate and IsoWeek
- epoch_to_local: replaced unsafe libc localtime_r with chrono Local
- New util.rs with memory_subdir() helper: ensures subdir exists and
  propagates errors instead of silently ignoring them
- Removed three duplicate agent_results_dir() definitions across
  digest.rs, consolidate.rs, enrich.rs
- load_digest_files, parse_all_digest_links, find_consolidation_reports
  now return Result to properly propagate directory creation errors

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-03-03 17:23:43 -05:00
parent 50da0b7b26
commit f4364e299c
7 changed files with 75 additions and 129 deletions

View file

@ -16,11 +16,7 @@ use std::collections::hash_map::DefaultHasher;
use std::fs;
use std::hash::{Hash, Hasher};
fn agent_results_dir() -> std::path::PathBuf {
let dir = store::memory_dir().join("agent-results");
fs::create_dir_all(&dir).ok();
dir
}
use crate::util::memory_subdir;
/// Extract user/assistant messages with line numbers from a JSONL transcript.
/// (line_number, role, text, timestamp)
@ -194,7 +190,7 @@ pub fn journal_enrich(
// Save result to agent-results
let timestamp = store::format_datetime(store::now_epoch())
.replace([':', '-'], "");
let result_file = agent_results_dir()
let result_file = memory_subdir("agent-results")?
.join(format!("{}.json", timestamp));
let output = serde_json::json!({
"timestamp": timestamp,