hive-sh4re/hive-bash-mcp/hive-agent: retype TaskFile timestamps to DateTime<Utc>, drop now_unix from these crates

This commit is contained in:
damocles 2026-08-01 21:34:29 +02:00 committed by mara
commit 2122e23d81
7 changed files with 30 additions and 22 deletions

View file

@ -10,6 +10,7 @@ workspace = true
[dependencies]
anyhow.workspace = true
axum.workspace = true
chrono.workspace = true
reqwest.workspace = true
hyper.workspace = true
hyper-util.workspace = true

View file

@ -17,7 +17,6 @@
use std::path::Path;
use std::time::Duration;
use hive_sh4re::wire_time::now_unix;
use rusqlite::{Connection, Result, params};
/// How often the sweep runs.
@ -56,7 +55,8 @@ fn sweep_once() {
let tasks_dir = harness.join("bash-tasks");
if tasks_dir.is_dir() {
let removed = vacuum_bash_tasks(&tasks_dir, now_unix() - BASH_KEEP_SECS);
let removed =
vacuum_bash_tasks(&tasks_dir, chrono::Utc::now().timestamp() - BASH_KEEP_SECS);
if removed > 0 {
tracing::info!(removed, "bash-tasks vacuum");
}
@ -92,14 +92,14 @@ fn sweep_once() {
/// `Reminders` handle).
fn vacuum_reminders(path: &Path) -> anyhow::Result<usize> {
let store = crate::reminders::Reminders::open(path)?;
store.prune_delivered_older_than(now_unix() - REMINDER_KEEP_SECS)
store.prune_delivered_older_than(chrono::Utc::now().timestamp() - REMINDER_KEEP_SECS)
}
/// Reap acked todo rows older than [`TODO_ACKED_KEEP_SECS`] via the typed
/// store API — same own-short-lived-connection shape as `vacuum_reminders`.
fn vacuum_todos(path: &Path) -> anyhow::Result<usize> {
let store = crate::todos::Todos::open(path)?;
store.reap_acked(now_unix() - TODO_ACKED_KEEP_SECS)
store.reap_acked(chrono::Utc::now().timestamp() - TODO_ACKED_KEEP_SECS)
}
/// Delete eligible bash-task trios in `dir`. Returns the count of `.json`
@ -140,10 +140,15 @@ fn should_delete(json_path: &Path, cutoff: i64) -> bool {
if !TERMINAL_STATUSES.contains(&status) {
return false;
}
// `completed_at` serializes as an RFC3339 string (`TaskFile.completed_at`
// is `Option<DateTime<Utc>>`), not a bare epoch-seconds integer — parse
// it the same way, falling back to "never expired" on anything
// unparseable so a corrupt/legacy field never causes a premature delete.
let completed_at = v
.get("completed_at")
.and_then(serde_json::Value::as_i64)
.unwrap_or(i64::MAX);
.and_then(serde_json::Value::as_str)
.and_then(|s| chrono::DateTime::parse_from_rfc3339(s).ok())
.map_or(i64::MAX, |dt| dt.timestamp());
completed_at < cutoff
}
@ -164,7 +169,7 @@ fn delete_trio(dir: &Path, stem: &str) {
/// agent's `events.sqlite`. Returns the number of rows deleted.
fn vacuum_events(path: &Path) -> Result<u64> {
let conn = Connection::open(path)?;
let cutoff = now_unix() - STREAM_KEEP_SECS;
let cutoff = chrono::Utc::now().timestamp() - STREAM_KEEP_SECS;
let removed = conn.execute(
"DELETE FROM events WHERE kind = 'stream' AND ts < ?1",
params![cutoff],