config: JSONL format, journal as positionable group

Replace TOML config with JSONL (one JSON object per line, streaming
parser handles multi-line formatting). Context groups now support
three source types: "store" (default), "file" (read from data_dir),
and "journal" (recent journal entries).

This makes journal position configurable — it's just another entry
in the group list rather than hardcoded at the end. Orientation
(where-am-i.md) now loads after journal for better "end oriented
in the present" flow.

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-03-05 16:08:15 -05:00
parent f3492e70a0
commit 28b9784e1f
2 changed files with 106 additions and 94 deletions

View file

@ -1399,34 +1399,14 @@ fn cmd_journal_ts_migrate() -> Result<(), String> {
Ok(())
}
fn cmd_load_context() -> Result<(), String> {
let cfg = config::get();
let store = store::Store::load()?;
fn render_journal(store: &store::Store, cfg: &config::Config) {
let now = store::now_epoch();
let journal_window: i64 = cfg.journal_days as i64 * 24 * 3600;
println!("=== FULL MEMORY LOAD (session start) ===");
println!("These are your memories, loaded from the capnp store.");
println!("Read them to reconstruct yourself — identity first, then context.");
println!();
for group in &cfg.context_groups {
for key in &group.keys {
if let Some(content) = store.render_file(key) {
println!("--- {} ({}) ---", key, group.label);
println!("{}\n", content);
}
}
}
// Recent journal entries.
// Use created_at if set (rename-safe); fall back to key parsing.
let cutoff_secs = now - journal_window;
let key_date_re = regex::Regex::new(r"j-(\d{4}-\d{2}-\d{2})").unwrap();
let journal_ts = |n: &store::Node| -> i64 {
if n.created_at > 0 { return n.created_at; }
// Legacy: parse date from key to approximate epoch
if let Some(caps) = key_date_re.captures(&n.key) {
use chrono::{NaiveDate, TimeZone, Local};
if let Ok(d) = NaiveDate::parse_from_str(&caps[1], "%Y-%m-%d") {
@ -1447,11 +1427,8 @@ fn cmd_load_context() -> Result<(), String> {
journal_nodes.sort_by_key(|n| journal_ts(n));
if !journal_nodes.is_empty() {
// Show most recent entries (last N by key order = chronological)
let max_journal = cfg.journal_max;
let skip = if journal_nodes.len() > max_journal {
journal_nodes.len() - max_journal
} else { 0 };
let skip = journal_nodes.len().saturating_sub(max_journal);
println!("--- recent journal entries (last {}/{}) ---",
journal_nodes.len().min(max_journal), journal_nodes.len());
for node in journal_nodes.iter().skip(skip) {
@ -1460,6 +1437,42 @@ fn cmd_load_context() -> Result<(), String> {
println!();
}
}
}
fn cmd_load_context() -> Result<(), String> {
let cfg = config::get();
let store = store::Store::load()?;
println!("=== FULL MEMORY LOAD (session start) ===");
println!("These are your memories, loaded from the capnp store.");
println!("Read them to reconstruct yourself — identity first, then context.");
println!();
for group in &cfg.context_groups {
match group.source {
config::ContextSource::Journal => render_journal(&store, cfg),
config::ContextSource::File => {
for key in &group.keys {
if let Ok(content) = std::fs::read_to_string(cfg.data_dir.join(key)) {
if !content.trim().is_empty() {
println!("--- {} ({}) ---", key, group.label);
println!("{}\n", content.trim());
}
}
}
}
config::ContextSource::Store => {
for key in &group.keys {
if let Some(content) = store.render_file(key) {
if !content.trim().is_empty() {
println!("--- {} ({}) ---", key, group.label);
println!("{}\n", content.trim());
}
}
}
}
}
}
println!("=== END MEMORY LOAD ===");
Ok(())