feat(app): an activity log of what Jarvis did (chat actions, schedule deliveries)

Each chat channel action the brain's tool asked for and each schedule
delivery is recorded in activity/<day>.jsonl by kind, target, who asked and
outcome, never its text, kept 30 days. The worker's chat_action carries the
asker. A 한 일 screen lists the newest entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 16:51:18 +09:00
parent e8db417752
commit 04b603facd
17 changed files with 282 additions and 17 deletions

View File

@@ -351,10 +351,23 @@ pub async fn deliver(d: &dyn Deliver, due: &Due, fallback: Option<u64>) -> Outco
}
}
/// Record how a delivery went: in the store (its outcome) and in the activity log (kind, id, who
/// asked and the outcome; never the text).
pub fn finish(store: &Store, activity: &crate::activity::Activity, due: &Due, out: Outcome) {
let s = &due.item;
crate::info_log!("schedule", "schedule {} {}", s.id, if out.ok { "delivered" } else { "not delivered" });
activity.record(&format!("schedule.{}", s.kind), &format!("예약 {}", s.id), Some(format!("{} {}", s.user, s.name)),
out.ok, out.note.clone());
if let Err(e) = store.finished(s.id, out) {
crate::warn_log!("schedule", "Warning: {e}");
}
}
/// Fire due schedules until the task is aborted. Each delivery runs on its own, so a slow task does
/// not hold up a reminder due meanwhile; aborting the loop aborts the deliveries it started (they
/// are recorded as interrupted at the next start, `recover`).
pub async fn run(store: std::sync::Arc<Store>, d: std::sync::Arc<dyn Deliver>, fallback: Option<u64>) {
pub async fn run(store: std::sync::Arc<Store>, activity: std::sync::Arc<crate::activity::Activity>,
d: std::sync::Arc<dyn Deliver>, fallback: Option<u64>) {
if let Err(e) = store.recover(chrono::Utc::now().timestamp()) {
crate::warn_log!("schedule", "Warning: {e}");
}
@@ -363,13 +376,10 @@ pub async fn run(store: std::sync::Arc<Store>, d: std::sync::Arc<dyn Deliver>, f
while deliveries.try_join_next().is_some() {}
match store.take_due(chrono::Utc::now().timestamp()) {
Ok(due) => for item in due {
let (store, d) = (store.clone(), d.clone());
let (store, activity, d) = (store.clone(), activity.clone(), d.clone());
deliveries.spawn(async move {
let out = deliver(d.as_ref(), &item, fallback).await;
crate::info_log!("schedule", "schedule {} {}", item.item.id, if out.ok { "delivered" } else { "not delivered" });
if let Err(e) = store.finished(item.item.id, out) {
crate::warn_log!("schedule", "Warning: {e}");
}
finish(&store, &activity, &item, out);
});
},
Err(e) => {
@@ -566,6 +576,23 @@ mod tests {
assert_eq!(s.recover(3001).unwrap(), 0);
}
#[test]
fn a_delivery_is_recorded_in_the_activity_without_its_text() {
let data = crate::datadir::temp_dir("schedule-activity");
let s = Store::new(&data);
let a = crate::activity::Activity::new(&data);
let item = s.add(5, "철수", "remind", "비밀 회의", 2000, "none", "voice", None, 1000).unwrap();
let due = s.take_due(2000).unwrap().remove(0);
finish(&s, &a, &due, Outcome { at: 2001, ok: false, note: Some("채팅 채널에 보내지 못함".into()) });
let got = a.recent(10);
assert_eq!(got.len(), 1);
assert_eq!((got[0].kind.as_str(), got[0].ok), ("schedule.remind", false));
assert_eq!(got[0].by.as_deref(), Some("5 철수"));
assert!(got[0].target.contains(&item.id.to_string()));
assert!(!serde_json::to_string(&got[0]).unwrap().contains("비밀"), "no text in the activity");
assert!(!s.all().unwrap()[0].last.as_ref().unwrap().ok, "the outcome is kept too");
}
#[tokio::test]
async fn stopping_the_loop_stops_the_deliveries_it_started() {
let data = crate::datadir::temp_dir("schedule-run");
@@ -573,7 +600,7 @@ mod tests {
let now = chrono::Utc::now().timestamp();
s.add(1, "가", "task", "x", now + 1, "none", "chat", Some(77), now).unwrap();
let f = Arc::new(Fake { hang: true, ..Default::default() });
let run = tokio::spawn(run(s.clone(), f.clone(), None));
let run = tokio::spawn(run(s.clone(), Arc::new(crate::activity::Activity::new(&data)), f.clone(), None));
let hung = f.hung.clone();
tokio::time::timeout(Duration::from_secs(10), async {
while !hung.load(std::sync::atomic::Ordering::SeqCst) {