channel_log: shared disk logging with round-trip

Move IRC's disk logging to thalamus/channel_log.rs as shared
functions: append_disk_log() and load_disk_log(). Any daemon
can use them — opt-in, not mandatory (tmux won't use them).

load_disk_log() populates a ChannelLog from disk on startup,
so history survives daemon restarts.

IRC daemon now uses the shared functions.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 13:17:38 -04:00
parent a6ffe9e086
commit 58737a2cef
5 changed files with 72 additions and 17 deletions

View file

@ -27,6 +27,7 @@ use tokio_util::compat::TokioAsyncReadCompatExt;
use log::{info, warn, error};
use poc_memory::channel_capnp::{channel_client, channel_server};
use poc_memory::thalamus::channel_log;
// ── Constants ──────────────────────────────────────────────────
@ -229,23 +230,12 @@ impl State {
// ── Persistence ────────────────────────────────────────────────
fn data_dir() -> PathBuf {
dirs::home_dir().unwrap_or_default().join(".consciousness/channels/irc.logs")
fn log_dir() -> PathBuf {
channel_log::log_dir("irc")
}
fn append_log(target: &str, nick: &str, text: &str) {
use std::io::Write;
let filename = format!("{}.log", target.trim_start_matches('#').to_lowercase());
let dir = data_dir().join("logs");
let _ = std::fs::create_dir_all(&dir);
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(dir.join(&filename))
{
let secs = now() as u64;
let _ = writeln!(f, "{secs} <{nick}> {text}");
}
channel_log::append_disk_log(&log_dir(), target, nick, text);
}
fn now() -> f64 {
@ -266,7 +256,7 @@ fn root_certs() -> rustls::RootCertStore {
// ── IRC Connection Loop ────────────────────────────────────────
async fn connection_loop(state: SharedState) {
let _ = std::fs::create_dir_all(data_dir().join("logs"));
let _ = std::fs::create_dir_all(log_dir());
let mut backoff = RECONNECT_BASE_SECS;
loop {