agent loop: claude drives; tool envelope (log/run/status/log)
This commit is contained in:
parent
a061f83cfa
commit
3c9d42b2a7
6 changed files with 147 additions and 47 deletions
|
|
@ -101,5 +101,11 @@ fn dispatch(req: &AgentRequest, agent: &str, broker: &Broker) -> AgentResponse {
|
|||
message: format!("{e:#}"),
|
||||
},
|
||||
},
|
||||
AgentRequest::Status => match broker.count_pending(agent) {
|
||||
Ok(unread) => AgentResponse::Status { unread },
|
||||
Err(e) => AgentResponse::Err {
|
||||
message: format!("{e:#}"),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,20 @@ impl Broker {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Number of undelivered messages addressed to `recipient`. Non-mutating
|
||||
/// — used by the harness to surface "N unread" in tool-result status
|
||||
/// lines without popping the queue.
|
||||
pub fn count_pending(&self, recipient: &str) -> Result<u64> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let n: i64 = conn.query_row(
|
||||
"SELECT COUNT(*) FROM messages
|
||||
WHERE recipient = ?1 AND delivered_at IS NULL",
|
||||
params![recipient],
|
||||
|row| row.get(0),
|
||||
)?;
|
||||
Ok(u64::try_from(n.max(0)).unwrap_or(0))
|
||||
}
|
||||
|
||||
pub fn recv(&self, recipient: &str) -> Result<Option<Message>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let row: Option<(i64, String, String, String)> = conn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue