huskies: merge 770

This commit is contained in:
dave
2026-04-28 15:31:29 +00:00
parent 1946709681
commit f63464852b
13 changed files with 212 additions and 266 deletions
+1
View File
@@ -69,6 +69,7 @@ mod wire;
pub use auth::{add_join_token, init_token_auth, init_trusted_keys};
pub(crate) use client::connect_and_sync;
pub use client::{RENDEZVOUS_ERROR_THRESHOLD, spawn_rendezvous_client};
pub(crate) use rpc::try_handle_rpc_text;
pub use server::crdt_sync_handler;
// Test-only re-export used by `crdt_snapshot` tests.
+34 -2
View File
@@ -29,7 +29,10 @@ pub(super) type Handler = fn(Value) -> Value;
///
/// Add new handlers here. The registry is a plain slice — linear scan is
/// fine for the small number of methods expected.
static HANDLERS: &[(&str, Handler)] = &[("health.check", handle_health_check)];
static HANDLERS: &[(&str, Handler)] = &[
("health.check", handle_health_check),
("active_agents.list", handle_active_agents_list),
];
/// Handler for the `health.check` method.
///
@@ -39,6 +42,35 @@ fn handle_health_check(_params: Value) -> Value {
serde_json::json!({"status": "ok"})
}
/// Handler for the `active_agents.list` method.
///
/// Reads the `active_agents` collection from the CRDT and returns an array
/// matching the shape formerly served by `GET /api/agents`. Each entry
/// contains `story_id`, `agent_name`, `status`, `session_id`, and
/// `worktree_path`.
fn handle_active_agents_list(_params: Value) -> Value {
let entries = crate::crdt_state::read_all_active_agents().unwrap_or_default();
let list: Vec<Value> = entries
.into_iter()
.map(|view| {
// agent_id is the composite key "story_id:agent_name".
let (story_id, agent_name) = view
.agent_id
.rsplit_once(':')
.map(|(s, a)| (s.to_string(), a.to_string()))
.unwrap_or_else(|| (view.story_id.unwrap_or_default(), view.agent_id.clone()));
serde_json::json!({
"story_id": story_id,
"agent_name": agent_name,
"status": "running",
"session_id": null,
"worktree_path": null,
})
})
.collect();
Value::Array(list)
}
/// Dispatch an incoming RPC method call to the registered handler.
///
/// Returns `Ok(result)` on success or `Err("NOT_FOUND")` if no handler is
@@ -57,7 +89,7 @@ pub(super) fn dispatch(method: &str, params: Value) -> Result<Value, &'static st
///
/// Returns `None` if the text is not a valid `rpc_request` frame (i.e. it
/// should be forwarded to the CRDT sync handler instead).
pub(super) fn try_handle_rpc_text(text: &str) -> Option<RpcFrame> {
pub(crate) fn try_handle_rpc_text(text: &str) -> Option<RpcFrame> {
let frame: RpcFrame = serde_json::from_str(text).ok()?;
match frame {
RpcFrame::RpcRequest {