Watch
1
0
Fork
You've already forked souveraine
0

hosted agents: read seeds from the live agents tree, not server/agents

This commit is contained in:
Fimeg 2026-07-16 12:20:56 -04:00
commit da410b1e6a

View file

@ -17,11 +17,16 @@ pub use bridge::FederationBridge;
pub use types::SignedEvent;
/// Read the agent pubkeys this device hosts from
/// `{base}/server/agents/*/seed/public.key`. Cheap — a handful of 32-byte
/// `{base}/agents/*/seed/public.key`. Cheap — a handful of 32-byte
/// files, no DB, no memfs load. Announced to peers so the federation knows
/// which agents live where (instance awareness, FEDERATION.md).
///
/// Note the tree: `{base}/agents/<id>/` holds memory + seed + schedules
/// (the live layout); `{base}/server/agents/<id>/` holds agent.json +
/// conversations and has NO seeds. Entries without a 32-byte
/// `seed/public.key` (e.g. the `schedules`/`system` dirs) are skipped.
pub fn load_hosted_agent_pubkeys(base: &std::path::Path) -> Vec<String> {
let agents_dir = base.join("server").join("agents");
let agents_dir = base.join("agents");
let mut out = Vec::new();
if let Ok(entries) = std::fs::read_dir(&agents_dir) {
for entry in entries.flatten() {
@ -36,3 +41,30 @@ pub fn load_hosted_agent_pubkeys(base: &std::path::Path) -> Vec<String> {
out.sort();
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hosted_agent_pubkeys_read_the_live_agents_tree() {
let base = tempfile::tempdir().unwrap();
// Live layout: {base}/agents/<id>/seed/public.key
let seed = base.path().join("agents/agent-a/seed");
std::fs::create_dir_all(&seed).unwrap();
std::fs::write(seed.join("public.key"), [7u8; 32]).unwrap();
// Non-agent dirs in the same tree must be skipped.
std::fs::create_dir_all(base.path().join("agents/schedules")).unwrap();
// A seed in the server/agents tree (conversations layout) must NOT count.
let wrong = base.path().join("server/agents/agent-b/seed");
std::fs::create_dir_all(&wrong).unwrap();
std::fs::write(wrong.join("public.key"), [9u8; 32]).unwrap();
// Truncated keys are ignored.
let short = base.path().join("agents/agent-c/seed");
std::fs::create_dir_all(&short).unwrap();
std::fs::write(short.join("public.key"), [1u8; 16]).unwrap();
let keys = load_hosted_agent_pubkeys(base.path());
assert_eq!(keys, vec![hex::encode([7u8; 32])]);
}
}