rightkit_agent_tools/
journal.rs1use crate::toolbox::{Journal, ToolEvent};
2use std::io::Write;
3use std::path::PathBuf;
4use std::sync::Mutex;
5
6pub struct JsonlJournal {
8 path: PathBuf,
9 lock: Mutex<()>,
10}
11
12impl JsonlJournal {
13 pub fn new(path: impl Into<PathBuf>) -> Self {
14 Self {
15 path: path.into(),
16 lock: Mutex::new(()),
17 }
18 }
19}
20
21impl Journal for JsonlJournal {
22 fn record(&self, event: &ToolEvent) {
23 let _g = self.lock.lock().unwrap_or_else(|e| e.into_inner());
24 if let Ok(mut f) = std::fs::OpenOptions::new()
25 .create(true)
26 .append(true)
27 .open(&self.path)
28 {
29 let _ = writeln!(f, "{}", event.to_value());
30 }
31 }
32}