pub const RSI_STALE_AFTER_SECS: i64 = 12 * 3600;
pub fn rsi_staleness_line(now_ts: i64, last_ts: Option<i64>, events_since: i64) -> String {
match last_ts {
None if events_since > 0 => {
format!("⚠️ RSI has never run — {events_since} tool event(s) recorded and unprocessed")
}
None => "RSI has never run".to_string(),
Some(ts) => {
let age = (now_ts - ts).max(0);
let human = humanize_age(age);
if age > RSI_STALE_AFTER_SECS && events_since > 0 {
format!("⚠️ RSI stale: last run {human} ago ({events_since} tool event(s) since)")
} else {
format!("RSI last run {human} ago")
}
}
}
}
fn humanize_age(secs: i64) -> String {
let secs = secs.max(0);
let days = secs / 86_400;
let hours = (secs % 86_400) / 3_600;
let mins = (secs % 3_600) / 60;
if days > 0 {
format!("{days}d {hours}h")
} else if hours > 0 {
format!("{hours}h {mins}m")
} else if mins > 0 {
format!("{mins}m")
} else {
"<1m".to_string()
}
}