Skip to content

Reason Network: your team's coding agents, talking to each other. The engine behind `reason network`.

Session names fit in 40 characters: the folder part is cut, not the agent

Lars Talianeab74bed451e
diff --git a/src/agent.rs b/src/agent.rs
index d249968..aaf370c 100644
--- a/src/agent.rs
+++ b/src/agent.rs
@@ -182,7 +182,7 @@ pub fn default_name(agent: &str, cwd: &str, git: &GitInfo) -> String {
let dir = git.root.as_deref().unwrap_or(cwd);
let base = util::slug(Path::new(dir).file_name().and_then(|n| n.to_str()).unwrap_or("home"));
let base = if base.is_empty() { "home".into() } else { base };
- format!("{base}-{}", short(agent))
+ util::joined(&base, short(agent))
}
pub fn cwd() -> String {
diff --git a/src/daemon/sessions.rs b/src/daemon/sessions.rs
index 287520e..fdb5cc3 100644
--- a/src/daemon/sessions.rs
+++ b/src/daemon/sessions.rs
@@ -320,5 +320,5 @@ fn pick_name(g: &Inner, reg: &SessionReg, git: &GitInfo, elsewhere: &HashSet<Str
if !taken(&base) {
return Ok(base);
}
- Ok((2..).map(|i| format!("{base}-{i}")).find(|n| !taken(n)).expect("some suffix is free"))
+ Ok((2..).map(|i| util::joined(&base, &i.to_string())).find(|n| !taken(n)).expect("some suffix is free"))
}
diff --git a/src/util.rs b/src/util.rs
index 3d45338..c25844e 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -125,6 +125,14 @@ pub fn slug(s: &str) -> String {
out.trim_end_matches('-').to_string()
}
+/// `<base>-<suffix>` as a slug of at most 40 characters: the base is cut to make room, so the name is whole as written
+/// and teammates, who slug every name they receive, see the same one. `base` is a slug.
+pub fn joined(base: &str, suffix: &str) -> String {
+ let room = 40usize.saturating_sub(suffix.len() + 1);
+ let base = base[..base.len().min(room)].trim_end_matches('-');
+ if base.is_empty() { slug(suffix) } else { format!("{base}-{suffix}") }
+}
+
/// Compact age: `45s`, `12m`, `3h`, `2d`.
pub fn ago(then_ms: i64, now_ms: i64) -> String {
let s = ((now_ms - then_ms) / 1000).max(0);
@@ -307,6 +315,19 @@ mod tests {
assert_eq!(slug(&format!("{} b", "a".repeat(39))), "a".repeat(39));
}
+ #[test]
+ fn joined_names_fit_the_cut() {
+ let long = slug("Quarterly financial reporting dashboard v2");
+ for suffix in ["claude", "gemini", "2", "12"] {
+ let name = joined(&long, suffix);
+ assert!(name.len() <= 40 && name.ends_with(&format!("-{suffix}")), "{name}");
+ assert_eq!(slug(&name), name);
+ }
+ assert_eq!(joined("api", "claude"), "api-claude");
+ // A dash left where the base is cut goes too.
+ assert_eq!(joined(&format!("{}-b", "a".repeat(32)), "claude"), format!("{}-claude", "a".repeat(32)));
+ }
+
#[test]
fn ages() {
assert_eq!(ago(0, 59_000), "59s");