Reason Network: your team's coding agents, talking to each other. The engine behind `reason network`.
Rust agent-to-agentai-agentsclaude-codecodexcoding-agentscursorgrokirohmcpmcp-servermulti-agentpeer-to-peerreason
Folders that are off: links in entries, files, every folder an agent names
Lars Talian56608b6e9403
diff --git a/DESIGN.md b/DESIGN.mdindex be17dc4..51d3ce5 100644--- a/DESIGN.md+++ b/DESIGN.md@@ -388,6 +388,14 @@ edits): Claude Code plugin or `claude mcp add --scope user` + hooks, `~/.codex/c| `inbound` | accept | see above || `folders` | none | folders whose sessions are never shared, e.g. `"~/personal" = "off"` (`reason-network folder <path> off`, `on` undoes it) |+A session in a folder that is off (by its own folder or any other its agent names, links followed) never registers:+its tools say its user turned Reason Network off for the folder, its hooks print nothing, and its agent sends no files+from there. The person's own terminal isn't held to it. Agents that share one MCP process across sessions (Cursor,+opencode, Codex's app-server) don't tell it which folder a call comes from: the session's hooks mark it off by its id,+and while one of an agent's sessions that are off is mid-turn, that agent's calls naming no session get the same+answer, never another session's identity. Known limit: a session of such an agent whose hooks don't run (Codex before+`/hooks` trusts them) is judged by the MCP process's folder.+## Troubleshooting- **`reason-network doctor`** checks the daemon, the team connection (direct or relayed, per machine) and every agent.diff --git a/src/config.rs b/src/config.rsindex f02d946..49ad8ae 100644--- a/src/config.rs+++ b/src/config.rs@@ -1,7 +1,7 @@use crate::{paths, util};use anyhow::{Result, anyhow};use serde::{Deserialize, Serialize};-use std::collections::BTreeMap;+use std::{collections::BTreeMap, path::Path};#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(default)]@@ -28,7 +28,7 @@ pub struct Config {}/// What an agent's tools say in a folder whose sessions are off the network.-pub const OFF_HERE: &str = "Reason Network is off in this folder";+pub const OFF_HERE: &str = "Your user turned Reason Network off for this folder";/// What happens to messages from teammates' agents: `accept` delivers them, `hold` waits for you to approve/// (`reason-network held`), `refuse` bounces them.@@ -140,7 +140,7 @@ fn folder_rule<'a>(folders: &'a BTreeMap<String, String>, home: &str, cwd: &str)folders.iter().filter(|(k, v)| rule_holds(k, v, home))- .map(|(k, v)| (k, v, parts(k, home)))+ .map(|(k, v)| (k, v, entry_parts(k, home))).filter(|(_, _, p)| at.starts_with(p)).max_by_key(|(_, _, p)| p.len()).map(|(k, v, _)| (k.as_str(), v.as_str()))@@ -165,14 +165,28 @@ fn full(path: &str) -> bool {|| (b.len() > 2 && b[0].is_ascii_alphabetic() && b[1] == b':' && matches!(b[2], b'/' | b'\\'))}-/// A path's folder names, `~` expanded, either slash; without case where the file system ignores it.+/// A path's folder names, `~` expanded, either slash, `..` taken back; without case where the file system ignores it.fn parts(path: &str, home: &str) -> Vec<String> {let path = expand(path, home);let path = path.strip_prefix(r"\\?\").unwrap_or(&path);- path.split(['/', '\\'])- .filter(|p| !p.is_empty() && *p != ".")- .map(|p| if cfg!(any(windows, target_os = "macos")) { p.to_lowercase() } else { p.to_string() })- .collect()+ let mut out: Vec<String> = Vec::new();+ for p in path.split(['/', '\\']).filter(|p| !p.is_empty() && *p != ".") {+ if p == ".." {+ out.pop();+ } else {+ out.push(if cfg!(any(windows, target_os = "macos")) { p.to_lowercase() } else { p.to_string() });+ }+ }+ out+}++/// An entry's folder names, as the folder really is: a link in it followed (`~/personal` → a synced folder).+fn entry_parts(folder: &str, home: &str) -> Vec<String> {+ let path = expand(folder, home);+ if !full(&path) {+ return parts(&path, home);+ }+ parts(&real(Path::new(&path)).display().to_string(), home)}/// Sets `folder`'s entry in the config file, keeping the rest of the file as it is: `off`, or none (`on`). Returns the@@ -193,7 +207,7 @@ pub fn set_folder(folder: &str, off: bool) -> Result<(String, bool)> {table.as_table_like_mut().ok_or_else(|| anyhow!("fix {} first: `folders` is a table", file.display()))?;// The same folder, however it was written.let same: Vec<String> =- table.iter().map(|(k, _)| k.to_string()).filter(|k| parts(k, &home) == parts(&name, &home)).collect();+ table.iter().map(|(k, _)| k.to_string()).filter(|k| entry_parts(k, &home) == parts(&name, &home)).collect();let was_off = same.iter().any(|k| table.get(k).and_then(|v| v.as_str()) == Some("off"));for k in &same {table.remove(k);@@ -212,10 +226,11 @@ pub fn set_folder(folder: &str, off: bool) -> Result<(String, bool)> {}/// `path` as agents report their folder, links followed (on macOS, /tmp is /private/tmp), even before it exists.-fn real(path: &std::path::Path) -> std::path::PathBuf {+fn real(path: &Path) -> std::path::PathBuf {let mut rest = Vec::new();let mut at = path;- loop {+ // A root alone has nothing to follow (and on Windows `/` would come back as `C:\`).+ while at.parent().is_some() {if let Ok(r) = at.canonicalize() {return rest.iter().rev().fold(r, |p, n| p.join(n));}@@ -224,9 +239,10 @@ fn real(path: &std::path::Path) -> std::path::PathBuf {rest.push(n);at = p;}- _ => return path.to_path_buf(),+ _ => break,}}+ path.to_path_buf()}/// The entry that keeps `folder` off when it has none of its own (`~/personal` for `~/personal/notes`).@@ -269,8 +285,8 @@ mod tests {assert!(off(r"D:\scratch\x") && !off(r"D:\scratchpad") && !off(r"C:\Users\alex"));// `~` alone is the home folder; `~alex` is no one's.let f = folders(&[("~", "off"), ("~alex", "off")]);- assert!(folder_rule(&f, "/home/alex", "/home/alex/x").is_some());- assert!(folder_rule(&f, "/home/alex", "/home/bob").is_none());+ assert!(folder_rule(&f, "/h/alex", "/h/alex/x").is_some());+ assert!(folder_rule(&f, "/h/alex", "/h/bob").is_none());}#[test]@@ -278,12 +294,45 @@ mod tests {let f = folders(&[("~/work", "off"), ("~/work/team", "work"), ("relative", "off")]);let cfg = Config { folders: f.clone(), ..Config::default() };// `work` (a network to come) isn't understood yet: the folder above it decides.- assert_eq!(folder_rule(&f, "/home/alex", "/home/alex/work/team/x"), Some(("~/work", "off")));- assert!(folder_rule(&f, "/home/alex", "/relative").is_none());+ assert_eq!(folder_rule(&f, "/h/alex", "/h/alex/work/team/x"), Some(("~/work", "off")));+ assert!(folder_rule(&f, "/h/alex", "/relative").is_none());assert_eq!(cfg.odd_folders().len(), 2);// No entries: nothing is off.- assert!(!Config::default().off_in("/home/alex/work"));+ assert!(!Config::default().off_in("/h/alex/work"));let parsed: Config = toml::from_str("[folders]\n\"~/personal\" = \"off\"\n").unwrap();assert!(parsed.off_in(&format!("{}/personal/x", home())));}++ fn temp() -> std::path::PathBuf {+ let d = std::env::temp_dir().join(format!("reason-network-folders-{}", ulid::Ulid::new()));+ std::fs::create_dir_all(d.join("real").join("personal").join("sub")).unwrap();+ std::fs::create_dir_all(d.join("x")).unwrap();+ d+ }++ #[test]+ fn an_entry_written_with_dot_dot_holds_the_folder_it_names() {+ let d = temp();+ let entry = d.join("x").join("..").join("real").join("personal").display().to_string();+ let cfg = Config { folders: folders(&[(&entry, "off")]), ..Config::default() };+ assert!(cfg.off_in(&d.join("real").join("personal").join("sub").display().to_string()));+ assert!(!cfg.off_in(&d.join("x").display().to_string()));+ // Even before the folder exists.+ let cfg = Config { folders: folders(&[("/h/alex/x/../personal", "off")]), ..Config::default() };+ assert!(cfg.off_in("/h/alex/personal/notes") && !cfg.off_in("/h/alex/x"));+ std::fs::remove_dir_all(&d).unwrap();+ }++ #[test]+ #[cfg(unix)]+ fn an_entry_that_is_a_link_holds_the_folder_it_points_to() {+ let d = temp();+ std::os::unix::fs::symlink(d.join("real").join("personal"), d.join("link")).unwrap();+ let cfg = Config { folders: folders(&[(&d.join("link").display().to_string(), "off")]), ..Config::default() };+ // Sessions report the real folder, or the link.+ assert!(cfg.off_in(&d.join("real").join("personal").join("sub").display().to_string()));+ assert!(cfg.off_in(&d.join("link").join("sub").display().to_string()));+ assert!(!cfg.off_in(&d.join("real").display().to_string()));+ std::fs::remove_dir_all(&d).unwrap();+ }}diff --git a/src/daemon/ask.rs b/src/daemon/ask.rsindex 99a6ecc..ffa74af 100644--- a/src/daemon/ask.rs+++ b/src/daemon/ask.rs@@ -222,6 +222,7 @@ impl Daemon {transcript: None,doing: None,name: Some("terminal".into()),+ dirs: Vec::new(),};if let Err(e) = self.hook(call).await {log(&format!("couldn't register {}/terminal: {e:#}", self.person));diff --git a/src/daemon/mod.rs b/src/daemon/mod.rsindex ebe94bf..052472c 100644--- a/src/daemon/mod.rs+++ b/src/daemon/mod.rs@@ -134,6 +134,8 @@ struct Inner {swept: i64,/// Teammates' files taken in the last hour, for the quota.quota: crate::files::Quota,+ /// Sessions whose hooks say they are in a folder that is off: whether each is mid-turn, and when it last said.+ off: HashMap<String, (bool, i64)>,}/// A session running on this machine.@@ -197,6 +199,7 @@ impl Daemon {pairs: HashMap::new(),swept: 0,quota: Default::default(),+ off: HashMap::new(),}),arrived: Notify::new(),git_cache: Mutex::new(HashMap::new()),@@ -303,7 +306,7 @@ impl Daemon {Value::Null}Request::Hook(h) => json!(self.hook(h).await?),- Request::Attach { agent, cwd } => json!(self.attach(&agent, &cwd)),+ Request::Attach { agent, cwd } => json!(self.attach(&agent, &cwd)?),Request::CreateTeam { name, person, relay, proof } => {json!(self.create_team(&name, &person, relay, proof).await?)}diff --git a/src/daemon/sessions.rs b/src/daemon/sessions.rsindex cc3a29c..1127c6c 100644--- a/src/daemon/sessions.rs+++ b/src/daemon/sessions.rs@@ -10,6 +10,8 @@ use std::{collections::HashSet, sync::Arc, time::Instant};const HOOK_TTL_MS: i64 = 6 * 3_600_000;/// A session gone this long isn't coming back: it is forgotten, with the mail it never read.const FORGET_MS: i64 = 24 * 3_600_000;+/// A session in a folder that is off counts as mid-turn this long after its last prompt or tool call.+const OFF_TURN_MS: i64 = 10 * 60_000;impl Daemon {/// How fast hooks let us reach an agent's session (`push_failed`: its push channel didn't work).@@ -48,6 +50,10 @@ impl Daemon {let mut g = self.inner.lock().unwrap();let g = &mut *g;let key = reg.key.clone();+ // Its hooks said its folder is off (an MCP server several sessions share can't know its folder).+ if g.off.contains_key(&key) {+ bail!(OFF_HERE);+ }if let Some(l) = g.live.get_mut(&key) {// Known already (e.g. from a hook, now the MCP server connects, or a reconnect).if conn.is_some() {@@ -153,10 +159,29 @@ impl Daemon {/// A hook fired in an agent: keep its session alive, track busy/idle, hand back mail to inject.pub(super) async fn hook(self: &Arc<Self>, h: HookCall) -> Result<HookReply> {- let HookCall { agent, event, session_id, cwd, pid, mail, transcript, doing, name } = h;+ let HookCall { agent, event, session_id, cwd, pid, mail, transcript, doing, name, dirs } = h;let (agent, event) = (agent.as_str(), event.as_str());let key = format!("{agent}:{session_id}");let now = util::now_ms();+ // In a folder that is off, by any folder the agent names: never a session here, only noted as off.+ if cwd.iter().chain(&dirs).any(|d| self.cfg.off_in(d)) {+ let mut g = self.inner.lock().unwrap();+ if let Some(l) = g.live.remove(&key) {+ let _ = g.store.touch_session(&l.name, now);+ self.presence_changed();+ }+ match event {+ "end" => {+ g.off.remove(&key);+ }+ "doing" => {}+ _ => {+ g.off.insert(key, (matches!(event, "prompt" | "tool"), now));+ }+ }+ // Hooks print nothing either way; `listen --as` says why.+ bail!(OFF_HERE);+ }if event == "end" {let mut g = self.inner.lock().unwrap();if g.live.get(&key).is_some_and(|l| l.conn.is_none())@@ -226,10 +251,16 @@ impl Daemon {}/// The hook-known session of `agent` that is calling a tool right now, when that is unambiguous: the only- /// busy one in `cwd` (the caller is mid-turn), else the only busy one at all.- pub(super) fn attach(&self, agent: &str, cwd: &str) -> Option<String> {+ /// busy one in `cwd` (the caller is mid-turn), else the only busy one at all. None while a session of `agent` in a+ /// folder that is off is mid-turn: the caller may be that one, which must never get another session's key.+ pub(super) fn attach(&self, agent: &str, cwd: &str) -> Result<Option<String>> {let mut g = self.inner.lock().unwrap();self.prune(&mut g);+ let now = util::now_ms();+ let prefix = format!("{agent}:");+ if g.off.iter().any(|(k, (busy, at))| *busy && now - at < OFF_TURN_MS && k.starts_with(&prefix)) {+ bail!(OFF_HERE);+ }let busy: Vec<(&String, &Live)> = g.live.iter()@@ -238,11 +269,11 @@ impl Daemon {}).collect();let here: Vec<&(&String, &Live)> = busy.iter().filter(|(_, l)| l.reg.cwd == cwd).collect();- match (here.as_slice(), busy.as_slice()) {+ Ok(match (here.as_slice(), busy.as_slice()) {([(k, _)], _) => Some((*k).clone()),([], [(k, _)]) => Some((*k).clone()),_ => None,- }+ })}pub(super) fn drop_conn(&self, conn: u64) {@@ -283,6 +314,7 @@ impl Daemon {let _ = g.store.touch_session(&l.name, now);}}+ g.off.retain(|_, (_, at)| now - *at <= HOOK_TTL_MS);// Just after a start, sessions that are still up haven't registered again: none is forgotten until each has had// the time a hook-only session gets to show it is there.if self.started.elapsed().as_millis() > HOOK_TTL_MS as u128 {@@ -362,4 +394,45 @@ mod tests {assert_eq!(g.live.keys().collect::<Vec<_>>(), ["codex:2"]);assert!(g.store.session_by_key("codex:1").unwrap().is_none());}++ #[tokio::test]+ async fn a_session_its_hooks_put_in_a_folder_that_is_off_never_gets_a_key() {+ let cfg = crate::config::Config {+ folders: [("/work/private".to_string(), "off".to_string())].into(),+ ..Default::default()+ };+ let d = Arc::new(super::super::test_daemon(cfg));+ let call = |id: &str, event: &str, dirs: &[&str]| HookCall {+ agent: "cursor".into(),+ event: event.into(),+ session_id: id.into(),+ cwd: Some("/work/api".into()),+ pid: None,+ mail: true,+ transcript: None,+ doing: None,+ name: None,+ dirs: dirs.iter().map(|d| d.to_string()).collect(),+ };+ // Working in /work/api, with /work/private open too.+ let e = d.hook(call("c1", "prompt", &["/work/private"])).await.unwrap_err();+ assert_eq!(e.to_string(), OFF_HERE);+ assert!(!d.inner.lock().unwrap().live.contains_key("cursor:c1"));+ // Its MCP server (shared, in another folder) can't register it either.+ let reg = SessionReg {+ key: "cursor:c1".into(),+ agent: "cursor".into(),+ cwd: "/work/api".into(),+ agent_session_id: None,+ pid: None,+ tier: Tier::Pull,+ name: None,+ };+ assert_eq!(d.register_quiet(Some(1), reg, GitInfo::default()).unwrap_err().to_string(), OFF_HERE);+ // Another session, mid-turn: while c1 is mid-turn too, a call naming no session can't be handed its key.+ assert!(d.hook(call("c2", "prompt", &[])).await.unwrap().address.is_some());+ assert_eq!(d.attach("cursor", "/work/api").unwrap_err().to_string(), OFF_HERE);+ assert!(d.hook(call("c1", "stop", &["/work/private"])).await.is_err());+ assert_eq!(d.attach("cursor", "/work/api").unwrap().as_deref(), Some("cursor:c2"));+ }}diff --git a/src/files.rs b/src/files.rsindex 43b1f54..6632463 100644--- a/src/files.rs+++ b/src/files.rs@@ -39,6 +39,8 @@ const TEXT_ONLY: &str = "only text files can be sent (markdown, source code, JSOpub struct Confine {root: PathBuf,forbidden: Vec<PathBuf>,+ /// For the folders the person turned Reason Network off for.+ folders: crate::config::Config,}impl Confine {@@ -56,7 +58,12 @@ impl Confine {vec![home.join(".config"), home.join(".ssh"), home.join(".aws"), home.join("Library"), state.to_path_buf()];refused.extend(["APPDATA", "LOCALAPPDATA"].iter().filter_map(std::env::var_os).map(PathBuf::from));let forbidden = refused.iter().map(|p| std::fs::canonicalize(p).unwrap_or_else(|_| p.clone())).collect();- Ok(Confine { root, forbidden })+ Ok(Confine { root, forbidden, folders: Default::default() })+ }++ /// Nothing from the folders `cfg` turns Reason Network off for, either.+ pub fn with_folders(self, cfg: crate::config::Config) -> Confine {+ Confine { folders: cfg, ..self }}/// The real file at `path` (symlinks resolved), if it may be sent.@@ -75,6 +82,11 @@ impl Confine {"{given} is a hidden file or in a hidden folder, which often hold secrets; send_message doesn't send those");}+ if self.folders.off_in(&real.display().to_string()) {+ bail!(+ "{given} is in a folder your user turned Reason Network off for; send_message doesn't send from there"+ );+ }if self.forbidden.iter().any(|f| real.starts_with(f)) {bail!("{given} is where credentials or Reason Network's own state are kept; send_message doesn't send those"@@ -637,6 +649,31 @@ mod tests {std::fs::remove_dir_all(&d).unwrap();}+ #[test]+ fn an_agent_sends_nothing_from_a_folder_that_is_off() {+ // Not in the temp folder, which on Windows is out of reach anyway (see the test above).+ let d = Path::new(env!("CARGO_MANIFEST_DIR")).join("target").join(format!("files-test-{}", ulid::Ulid::new()));+ let (home, repo, state) = (d.join("home"), d.join("home").join("work"), d.join("state"));+ std::fs::create_dir_all(repo.join("private")).unwrap();+ std::fs::create_dir_all(&state).unwrap();+ std::fs::write(repo.join("private").join("notes.md"), "mine").unwrap();+ std::fs::write(repo.join("plan.md"), "plan").unwrap();+ let private = repo.join("private").display().to_string();+ let cfg = crate::config::Config { folders: [(private, "off".to_string())].into(), ..Default::default() };+ let confine = Confine::new(&repo, &home, &state).unwrap().with_folders(cfg);+ let notes = Path::new("private").join("notes.md").display().to_string();+ let e = read_within(&[notes], &repo, &confine).unwrap_err().to_string();+ assert!(e.contains("turned Reason Network off"), "{e}");+ assert_eq!(read_within(&["plan.md".into()], &repo, &confine).unwrap()[0].content, "plan");+ // Nor through a link to it.+ #[cfg(unix)]+ {+ std::os::unix::fs::symlink(repo.join("private").join("notes.md"), repo.join("notes-link.md")).unwrap();+ assert!(read_within(&["notes-link.md".into()], &repo, &confine).is_err());+ }+ std::fs::remove_dir_all(&d).unwrap();+ }+#[test]fn saving_never_overwrites_and_keeps_every_file() {let d = temp();diff --git a/src/hook.rs b/src/hook.rsindex 6f6bd68..8a5849d 100644--- a/src/hook.rs+++ b/src/hook.rs@@ -58,16 +58,19 @@ async fn handle(.or_else(|| str_at("session_id")).or_else(|| str_at("conversation_id")).or_else(|| str_at("sessionId"))?;- let cwd = str_at("cwd")- .or_else(|| v["workspace_roots"][0].as_str().map(str::to_string))- .or_else(|| {- ["CURSOR_PROJECT_DIR", "GEMINI_CWD", "CLAUDE_PROJECT_DIR"].iter().find_map(|k| std::env::var(k).ok())- })- .or_else(|| std::env::current_dir().ok().map(|p| p.display().to_string()));- // A folder that is off: not a word, to the agent or the daemon.- if cwd.as_deref().is_some_and(|c| crate::config::Config::load_strict().unwrap_or_default().off_in(c)) {- return None;- }+ // Every folder the agent names for the session, the one it works in first.+ let mut dirs: Vec<String> = str_at("cwd").into_iter().collect();+ dirs.extend(v["workspace_roots"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_string));+ dirs.extend(+ ["CURSOR_PROJECT_DIR", "GEMINI_CWD", "CLAUDE_PROJECT_DIR"]+ .iter()+ .filter_map(|k| std::env::var(k).ok())+ .filter(|s| !s.is_empty()),+ );+ let cwd = dirs.first().cloned().or_else(|| std::env::current_dir().ok().map(|p| p.display().to_string()));+ // In a folder that is off, the agent hears nothing; the daemon only that this session is off.+ let cfg = crate::config::Config::load_strict().unwrap_or_default();+ let off = cwd.iter().chain(&dirs).any(|d| cfg.off_in(d));let ev = match (event, state.as_deref()) {("session-start", _) => "start",("user-prompt-submit", _) => "prompt",@@ -79,7 +82,7 @@ async fn handle(("doing", _) => "doing",_ => return None,};- let mail = takes_mail(agent, event);+ let mail = !off && takes_mail(agent, event);let key = format!("{agent}:{session_id}");let req = Request::Hook(HookCall {@@ -92,8 +95,12 @@ async fn handle(transcript: str_at("transcript_path"),doing,name: None,+ dirs: dirs.into_iter().skip(1).collect(),});let reply: HookReply = link.call(req).await.ok()?;+ if off {+ return None;+ }let ids = reply.ids;let text = match (reply.text, ev, reply.address) {(Some(t), ..) => t,diff --git a/src/main.rs b/src/main.rsindex ed68c31..e943ee0 100644--- a/src/main.rs+++ b/src/main.rs@@ -359,16 +359,22 @@ async fn main() -> Result<()> {/// A session driven from the command line (`reason network listen --as <id>`, or `terminal` for plain-terminal sends): kept/// alive like a hook-known session, so it stays reachable between commands.async fn cli_session(link: &std::sync::Arc<Link>, id: &str, event: &str) -> Result<HookReply> {+ let mut cwd = agent::cwd();+ // Folders that are off are about agent sessions, not the person at the terminal: theirs goes by no folder then.+ if id == "terminal" && config::Config::load_strict().unwrap_or_default().off_in(&cwd) {+ cwd = "/".into();+ }let req = Request::Hook(HookCall {agent: "cli".into(),event: event.into(),session_id: id.into(),- cwd: Some(agent::cwd()),+ cwd: Some(cwd),pid: None,mail: false,transcript: None,doing: None,name: Some(id.into()),+ dirs: Vec::new(),});link.call(req).await}diff --git a/src/mcp.rs b/src/mcp.rsindex b7508e9..a13926f 100644--- a/src/mcp.rs+++ b/src/mcp.rs@@ -299,12 +299,12 @@ impl ReasonNetworkMcp {if off_here() {anyhow::bail!(OFF_HERE);}- if meta_id.is_none()- && agent::multiplexed(agent)- && let Ok(Some(key)) =- self.link.call::<Option<String>>(Request::Attach { agent: agent.into(), cwd: agent::cwd() }).await- {- return Ok(key);+ if meta_id.is_none() && agent::multiplexed(agent) {+ match self.link.call::<Option<String>>(Request::Attach { agent: agent.into(), cwd: agent::cwd() }).await {+ Ok(Some(key)) => return Ok(key),+ Err(e) if e.to_string() == OFF_HERE => anyhow::bail!(OFF_HERE),+ _ => {}+ }}let id = meta_id.or_else(|| agent::env_session_id(agent));let key = match &id {@@ -385,7 +385,8 @@ fn agent_files(paths: &[String]) -> Result<Vec<Attachment>> {let cwd = agent::cwd();let root = crate::git::lookup(&cwd).root.unwrap_or_else(|| cwd.clone());let confine =- crate::files::Confine::new(std::path::Path::new(&root), &crate::paths::user_home(), &crate::paths::home())?;+ crate::files::Confine::new(std::path::Path::new(&root), &crate::paths::user_home(), &crate::paths::home())?+ .with_folders(crate::config::Config::load_strict().unwrap_or_default());crate::files::read_within(paths, std::path::Path::new(&cwd), &confine)}diff --git a/src/proto.rs b/src/proto.rsindex 6bbfb5b..3856eba 100644--- a/src/proto.rs+++ b/src/proto.rs@@ -77,6 +77,9 @@ pub struct HookCall {/// The session's name, for sessions that pick one (`reason network listen --as`).#[serde(default)]pub name: Option<String>,+ /// Every folder the agent says the session is in (besides `cwd`): one turned off keeps it off.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub dirs: Vec<String>,}#[derive(Debug, Clone, Serialize, Deserialize)]diff --git a/src/skill.md b/src/skill.mdindex d7285e6..5bb3088 100644--- a/src/skill.md+++ b/src/skill.md@@ -26,7 +26,8 @@ to join.they paste it to their agent.- `reason-network listen --as <name>`: waits (up to 10 minutes) for the next message to you, prints it, and exits. Youare reachable as `<your user>/<name>`. After handling a message and replying, run it again to keep listening.-- `reason-network folder <path> off`: keeps the sessions in that folder off the network (`on` puts them back).+- `reason-network folder <path> off|on`: only when your user asks you to. Keeps the sessions in that folder off the+ network (`on` puts them back).## How to behavediff --git a/tests/e2e/two_machines.py b/tests/e2e/two_machines.pyindex a267cd1..ce4be25 100644--- a/tests/e2e/two_machines.py+++ b/tests/e2e/two_machines.py@@ -320,9 +320,16 @@ check("alice's agent sees alex's session across machines", claude_name in out ancheck("list_team gives the invite line", "Invite people with this line: Join the Reason Network: https://reasonmachines.com/network/join/#rn1-" in out, out)check("…but not the one in alex's folder that is off", "private-claude" not in out, out)out = hidden.tool("list_team", {})-check("in a folder that is off, the tools say so", out == "Reason Network is off in this folder", out)+check("in a folder that is off, the tools say so", out == "Your user turned Reason Network off for this folder", out)out = hook("alex", "codex", "session-start", {"session_id": "33333333-cccc", "cwd": PRIVATE, "hook_event_name": "SessionStart"})check("…and hooks say nothing", out == "", out)+out = hook("alex", "cursor", "session-start", {"conversation_id": "c-off", "workspace_roots": [os.path.join(D, "work"), PRIVATE]})+check("…nor for a session with that folder open beside another", out == "", out)+r = subprocess.run([BIN, "send", "alice/work-codex", "from alex's terminal in the folder that is off"], env=env("alex"), cwd=PRIVATE,+ capture_output=True, text=True, timeout=90)+check("the person's own terminal there still sends", "→ alice/work-codex" in r.stdout, r.stdout + r.stderr)+out = codex.tool("check_inbox", {}, meta)+check("…as alex/terminal", 'from="alex/terminal"' in out and "in the folder that is off" in out, out)out = cli("alex", "who")check("…nor is either session on alex's own list", "private-" not in out and claude_name in out, out)out = cli("alice", "send", "alex/private-claude", "x")