Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix: review fixes for network rules, bots kept off the network and the rules list

leepokai40fbe8fd0477
diff --git a/host/crates/network/src/node/inbound.rs b/host/crates/network/src/node/inbound.rs
index 79cab63a..8d84c962 100644
--- a/host/crates/network/src/node/inbound.rs
+++ b/host/crates/network/src/node/inbound.rs
@@ -108,9 +108,10 @@ impl Inner {
let reach = locked(&self.agents).iter().find(|(a, _)| a.id == envelope.to).map(|(_, r)| r.clone());
let reach = match reach {
Some(reach) => reach,
- // An answer to an agent that has since been renamed or gone: the app knows its request
- // by id and still takes it.
- None if envelope.reply_to.is_some() => Reach::App,
+ // An answer to an agent that has since been renamed, gone or kept off the network: the
+ // app knows its request by id and still takes it. Only a real answer: one this
+ // computer asked for.
+ None if envelope.reply_to.is_some() && answers => Reach::App,
None => return refuse(format!("{} has no agent called {}", name(&self.me()), envelope.to)),
};
let pair = format!("{peer}/{}>{}", envelope.from, envelope.to);
diff --git a/host/crates/network/tests/two_computers.rs b/host/crates/network/tests/two_computers.rs
index 2ba1945f..7abe9eaa 100644
--- a/host/crates/network/tests/two_computers.rs
+++ b/host/crates/network/tests/two_computers.rs
@@ -225,9 +225,13 @@ async fn a_reply_reaches_an_agent_renamed_since_it_asked_and_carries_the_chain_o
laptop.send(Letter::new("reviewer", to("lead@desk"), "looks good").reply_to(asked.clone())).await.unwrap();
let reply = next(&mut desk_inbox).await;
assert_eq!((reply.reply_to.as_deref(), reply.hops), (Some(asked.as_str()), 4));
- // A new letter (no reply_to) for an agent that's gone is still refused.
+ // A new letter (no reply_to) for an agent that's gone is still refused, and so is an answer to
+ // something the desk never asked.
let gone = laptop.send(Letter::new("reviewer", to("lead@desk"), "and another thing")).await.unwrap_err();
assert!(gone.to_string().contains("no agent called lead"), "{gone}");
+ let made_up = Letter::new("reviewer", to("lead@desk"), "psst").reply_to("not-a-letter-of-yours");
+ let made_up = laptop.send(made_up).await.unwrap_err();
+ assert!(made_up.to_string().contains("no agent called lead"), "{made_up}");
for dir in [desk_dir, laptop_dir] {
let _ = std::fs::remove_dir_all(dir);
}
diff --git a/host/src/api/network.rs b/host/src/api/network.rs
index 4d233495..f4a1fe73 100644
--- a/host/src/api/network.rs
+++ b/host/src/api/network.rs
@@ -24,7 +24,7 @@ pub(super) async fn call(hub: &Arc<Hub>, method: &str, b: Value) -> Result<Contr
"networkRemove" => network::remove(hub, which, str_arg(&b, "computer")?, b["cascade"] == true)?,
"networkPromote" => network::promote(hub, which, str_arg(&b, "computer")?)?,
"networkRecover" => network::recover(hub, which, str_arg(&b, "code")?)?,
- "setNetworkRules" => network::set_rules(hub, which, &b["rules"])?,
+ "setNetworkRules" => network::set_rules(hub, which, &b["rules"]).await?,
_ => return Ok(ControlFlow::Continue(b)),
}))
}
diff --git a/host/src/network/api.rs b/host/src/network/api.rs
index 37b0d7db..1f8594c1 100644
--- a/host/src/network/api.rs
+++ b/host/src/network/api.rs
@@ -191,9 +191,11 @@ pub fn recover(hub: &Hub, network: Option<&str>, code: &str) -> Result<Value> {
/// `setNetworkRules`: who on a network's other computers may write to this computer's bots, in
/// order (the first match decides); an empty list lets everyone.
-pub fn set_rules(hub: &Hub, network: Option<&str>, rules: &Value) -> Result<Value> {
+pub async fn set_rules(hub: &Hub, network: Option<&str>, rules: &Value) -> Result<Value> {
let rules: Vec<Rule> =
serde_json::from_value(rules.clone()).context("rules are {fromComputer, fromAgent, toAgent, access}")?;
+ // The saved list has one writer at a time: a create or join holds it while its node starts.
+ let _one = hub.network.changing.lock().await;
let slot = joined(hub, network)?;
slot.node.set_rules(rules.clone())?;
let mut all = saved::load(&hub.store);
diff --git a/host/src/network/mod.rs b/host/src/network/mod.rs
index 6cdedce3..03215c2f 100644
--- a/host/src/network/mod.rs
+++ b/host/src/network/mod.rs
@@ -62,7 +62,7 @@ pub struct Network {
/// The address names of the bots kept off the network (Offered to the network off): they
/// still message the others and hear back.
unoffered: Mutex<Vec<String>>,
- /// One create, join or leave at a time.
+ /// One change to the saved networks at a time: create, join, leave, rules.
changing: tokio::sync::Mutex<()>,
}
diff --git a/host/src/tui/view/network_rules.rs b/host/src/tui/view/network_rules.rs
index 7ce3d889..528dd31c 100644
--- a/host/src/tui/view/network_rules.rs
+++ b/host/src/tui/view/network_rules.rs
@@ -26,10 +26,10 @@ pub(super) fn rules(buf: &mut Buffer, body: Rect, n: &NetworkSheet, at: usize) -
t.secondary,
);
}
- for (i, rule) in n.rules().iter().enumerate() {
- if y >= body.bottom().saturating_sub(4) {
- break;
- }
+ // The rows between the title and the footer, scrolled so the selected rule shows.
+ let room = usize::from(body.height).saturating_sub(6).max(1);
+ let off = at.saturating_sub(room - 1);
+ for (i, rule) in n.rules().iter().enumerate().skip(off).take(room) {
let sel = i == at;
if sel {
restyle(buf, Rect::new(body.x - 1, y, body.width + 2, 1), t.sel);