feat(agent): implement agent execution engine and turn handling with background processing

This commit is contained in:
asepharyana
2026-07-20 16:29:39 +07:00
parent 2e8a4f2443
commit efcd191f96
15 changed files with 452 additions and 247 deletions
+3 -3
View File
@@ -12,7 +12,7 @@ pub struct IpcClient {
impl IpcClient {
pub fn connect_unix(path: &str) -> anyhow::Result<Self> {
let stream = UnixStream::connect(path)?;
let conn = crate::ipc::conn::Connection::new(stream);
let conn = crate::ipc::conn::Connection::new(stream)?;
Ok(Self {
conn: Mutex::new(conn),
})
@@ -22,7 +22,7 @@ impl IpcClient {
let mut guard = self
.conn
.lock()
.expect("IpcClient mutex poisoned");
.map_err(|e| anyhow::anyhow!("IpcClient mutex poisoned: {e}"))?;
guard.send(msg)
}
@@ -30,7 +30,7 @@ impl IpcClient {
let mut guard = self
.conn
.lock()
.expect("IpcClient mutex poisoned");
.map_err(|e| anyhow::anyhow!("IpcClient mutex poisoned: {e}"))?;
guard.receive()
}
}
+4 -3
View File
@@ -1,6 +1,7 @@
//! Connection wrapper around a Unix socket stream,
//! pairing a buffered reader with a raw writer.
use anyhow::Context;
use std::io::BufReader;
use std::os::unix::net::UnixStream;
@@ -11,14 +12,14 @@ pub struct Connection {
}
impl Connection {
pub fn new(stream: UnixStream) -> Self {
pub fn new(stream: UnixStream) -> anyhow::Result<Self> {
let reader = BufReader::new(
stream
.try_clone()
.expect("UnixStream::try_clone should never fail on Linux"),
.context("failed to clone Unix stream for IPC reader")?,
);
let writer = stream;
Self { reader, writer }
Ok(Self { reader, writer })
}
pub fn send<T: serde::Serialize>(&mut self, msg: &T) -> anyhow::Result<()> {
+1 -1
View File
@@ -21,6 +21,6 @@ impl IpcServer {
pub fn accept(&self) -> anyhow::Result<crate::ipc::conn::Connection> {
let (stream, _addr) = self.listener.accept()?;
Ok(crate::ipc::conn::Connection::new(stream))
crate::ipc::conn::Connection::new(stream)
}
}