chore: seed sgclaw rust baseline

This commit is contained in:
zyl
2026-03-25 02:17:55 +00:00
parent 5063adc530
commit 8757bbb266
26 changed files with 2825 additions and 0 deletions

53
src/pipe/handshake.rs Normal file
View File

@@ -0,0 +1,53 @@
use std::time::Duration;
use uuid::Uuid;
use crate::pipe::protocol::{supported_actions, AgentMessage, BrowserMessage, PROTOCOL_VERSION};
use crate::pipe::{PipeError, Transport};
use crate::security::derive_session_key;
#[derive(Debug, Clone)]
pub struct HandshakeResult {
pub agent_id: String,
pub session_key: Vec<u8>,
pub capabilities: Vec<String>,
}
pub fn perform_handshake<T: Transport>(
transport: &T,
timeout: Duration,
) -> Result<HandshakeResult, PipeError> {
let init = transport.recv_timeout(timeout)?;
match init {
BrowserMessage::Init {
version,
hmac_seed,
capabilities,
} => {
if version != PROTOCOL_VERSION {
return Err(PipeError::Protocol(format!(
"unsupported protocol version: {version}"
)));
}
let session_key = derive_session_key(&hmac_seed)?;
let agent_id = Uuid::new_v4().to_string();
let ack = AgentMessage::InitAck {
version: PROTOCOL_VERSION.to_string(),
agent_id: agent_id.clone(),
supported_actions: supported_actions(),
};
transport.send(&ack)?;
Ok(HandshakeResult {
agent_id,
session_key,
capabilities,
})
}
other => Err(PipeError::UnexpectedMessage(format!(
"expected init as first message, got {other:?}"
))),
}
}