feat(agent): implement agent execution engine and turn handling with background processing
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<()> {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user