Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Island names a file, never its folders (21c) (#708)

Oleksandr Ivanchenko70d3f550a125
diff --git a/src/drivers/activity.rs b/src/drivers/activity.rs
index 05fa5baa..f5a3e9b3 100644
--- a/src/drivers/activity.rs
+++ b/src/drivers/activity.rs
@@ -777,6 +777,72 @@ pub fn island_kind_title(name: &str) -> Option<&'static str> {
WordsTool::of(&tool_part(name).to_ascii_lowercase()).map(WordsTool::bare)
}
+/// The tools that read, edit or write one file, by what they do. The one list of them: [`summarize`]
+/// titles them with the file's last two parts ("Reading …/src/main.rs"), and the desktop island
+/// with only its name ([`island_file_title`]).
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum FileTool {
+ Read,
+ Edit,
+ Write,
+}
+
+impl FileTool {
+ /// `tool` is the name without its `mcp__server__` prefix, lowercased.
+ fn of(tool: &str) -> Option<Self> {
+ match tool {
+ "read" | "read_file" | "view" | "cat" => Some(Self::Read),
+ "edit" | "multiedit" | "edit_file" | "str_replace" | "str_replace_based_edit_tool" | "apply_patch" | "file_change"
+ | "notebookedit" => Some(Self::Edit),
+ "write" | "write_file" | "create_file" => Some(Self::Write),
+ _ => None,
+ }
+ }
+
+ /// The title's first word, before the path.
+ fn verb(self) -> &'static str {
+ match self {
+ Self::Read => "Reading",
+ Self::Edit => "Editing",
+ Self::Write => "Writing",
+ }
+ }
+
+ /// The title when the call names no path.
+ fn bare(self) -> &'static str {
+ match self {
+ Self::Read => "Reading a file",
+ Self::Edit => "Editing files",
+ Self::Write => "Writing a file",
+ }
+ }
+}
+
+/// The desktop island's title for a read, edit or write tool (`Read`, `MultiEdit`, `NotebookEdit`,
+/// `apply_patch`, `mcp__x__read_file`), ignoring an `mcp__server__` prefix and case: the step's
+/// chat `title` with its path cut to the file's own name, so "Reading …/src/main.rs" is "Reading
+/// main.rs" and "Editing C:\work\a.md" is "Editing a.md" (21c). Folders can name a client or a
+/// person, and the island sits on shared screens. A title without folders ("Reading a file",
+/// "Reading main.rs") is kept; one that doesn't start with the tool's verb, or whose path has no
+/// name, falls back to the bare title. `None` for every other tool.
+pub fn island_file_title(name: &str, title: &str) -> Option<String> {
+ let kind = FileTool::of(&tool_part(name).to_ascii_lowercase())?;
+ let is_sep = |c: char| c == '/' || c == '\\';
+ let Some(path) = title.strip_prefix(kind.verb()).and_then(|r| r.strip_prefix(' ')) else {
+ return Some(kind.bare().to_string());
+ };
+ if path.trim().is_empty() {
+ return Some(kind.bare().to_string());
+ }
+ if !path.contains(is_sep) {
+ return Some(title.to_string());
+ }
+ match path.trim_end_matches(is_sep).rsplit(is_sep).next().map(str::trim).filter(|n| !n.is_empty() && *n != "…") {
+ Some(file) => Some(format!("{} {file}", kind.verb())),
+ None => Some(kind.bare().to_string()),
+ }
+}
+
/// A tool's name without its `mcp__server__` prefix (`mcp__x__grep` gives `grep`), as
/// [`summarize`] reads it; `name` itself when it has none.
fn tool_part(name: &str) -> &str {
@@ -809,11 +875,10 @@ pub fn summarize(name: &str, args: &Value) -> (String, Option<String>) {
};
return (title.unwrap_or_else(|| kind.bare().to_string()), None);
}
+ if let Some(kind) = FileTool::of(&lower) {
+ return (path().map_or(kind.bare().into(), |p| format!("{} {p}", kind.verb())), None);
+ }
match lower.as_str() {
- "read" | "read_file" | "view" | "cat" => (path().map_or("Reading a file".into(), |p| format!("Reading {p}")), None),
- "edit" | "multiedit" | "edit_file" | "str_replace" | "str_replace_based_edit_tool" | "apply_patch" | "file_change"
- | "notebookedit" => (path().map_or("Editing files".into(), |p| format!("Editing {p}")), None),
- "write" | "write_file" | "create_file" => (path().map_or("Writing a file".into(), |p| format!("Writing {p}")), None),
"webfetch" | "fetch" | "web_fetch" | "browser_open" | "browser_navigate" | "navigate" | "open_url" => match url {
Some(u) => (format!("Opening {}", host_of(u)), Some(u.to_string())),
None => ("Opening a page".into(), None),
@@ -1020,6 +1085,39 @@ mod tests {
assert!(s[0].detail.as_ref().unwrap().chars().count() <= MAX_DETAIL);
}
+ /// 21c: the island's title for a read, edit or write tool is the chat's title with the path cut
+ /// to the file's own name; the chat's title keeps "…/folder/file". Every other tool has none.
+ #[test]
+ fn island_file_titles_name_the_file_only() {
+ let cases: Vec<(&str, Value, &str, &str)> = vec![
+ ("Read", json!({"file_path": "/home/x/clients/acme/contract.md"}), "Reading …/acme/contract.md", "Reading contract.md"),
+ ("Edit", json!({"file_path": "/tmp/acme.md"}), "Editing …/tmp/acme.md", "Editing acme.md"),
+ ("MultiEdit", json!({"file_path": "/repo/src/main.rs"}), "Editing …/src/main.rs", "Editing main.rs"),
+ ("Write", json!({"file_path": "/srv/clients/acme-layoffs/plan.txt"}), "Writing …/acme-layoffs/plan.txt", "Writing plan.txt"),
+ ("NotebookEdit", json!({"notebook_path": "/work/acme/model.ipynb"}), "Editing …/acme/model.ipynb", "Editing model.ipynb"),
+ ("apply_patch", json!({"path": "/work/acme/a.rs"}), "Editing …/acme/a.rs", "Editing a.rs"),
+ ("mcp__x__read_file", json!({"path": "/work/acme/b.md"}), "Reading …/acme/b.md", "Reading b.md"),
+ ("Read", json!({"file_path": "C:\\work\\a.md"}), "Reading C:\\work\\a.md", "Reading a.md"),
+ ("Read", json!({"file_path": "/tmp/acme/"}), "Reading …/tmp/acme", "Reading acme"),
+ ("Read", json!({"file_path": "contract.md"}), "Reading contract.md", "Reading contract.md"),
+ ("Read", Value::Null, "Reading a file", "Reading a file"),
+ ("Edit", Value::Null, "Editing files", "Editing files"),
+ ("Write", Value::Null, "Writing a file", "Writing a file"),
+ ];
+ for (name, args, chat, island) in cases {
+ let title = summarize(name, &args).0;
+ assert_eq!(title, chat, "{name} {args}");
+ assert_eq!(island_file_title(name, &title).as_deref(), Some(island), "{name} {args}");
+ }
+ // A title that isn't the tool's own falls back to the bare title; a path with no name too
+ assert_eq!(island_file_title("Read", "Reading ").as_deref(), Some("Reading a file"));
+ assert_eq!(island_file_title("Read", "Reading …/").as_deref(), Some("Reading a file"));
+ assert_eq!(island_file_title("Edit", "Looking at /x/acme/y.md").as_deref(), Some("Editing files"));
+ for name in ["Bash", "Grep", "WebFetch", "WebSearch", "mcp__linear__list_issues", "mcp__read"] {
+ assert_eq!(island_file_title(name, "Reading …/acme/contract.md"), None, "{name}");
+ }
+ }
+
/// 19a: the island's bare title per search or helper kind, ignoring an mcp prefix and case;
/// every other tool (shell included) has none.
#[test]
diff --git a/src/server/activity.rs b/src/server/activity.rs
index e24b4640..7fe4fb5f 100644
--- a/src/server/activity.rs
+++ b/src/server/activity.rs
@@ -190,9 +190,10 @@ fn step_now(steps: &[Step]) -> Option<(String, String)> {
steps.iter().rev().find(|s| s.kind != "thinking").map(|s| (island_title(s), s.started_at.clone()))
}
-/// A step's title as the island shows it (17a, 19a). A shell step names only its program
-/// ("Running git"), never the command, and a search or helper step only its kind ("Searching the
-/// web"), never the query or brief: the island sits on the person's screen above every app, shared
+/// A step's title as the island shows it (17a, 19a, 21c). A shell step names only its program
+/// ("Running git"), never the command, a search or helper step only its kind ("Searching the
+/// web"), never the query or brief, and a read, edit or write step only the file's name ("Reading
+/// contract.md"), never its folders: the island sits on the person's screen above every app, shared
/// screens and calls included, and redaction only catches known secret shapes. The chat's activity
/// list keeps the full titles. Every other step keeps its title.
fn island_title(s: &Step) -> String {
@@ -203,6 +204,9 @@ fn island_title(s: &Step) -> String {
if let Some(bare) = crate::drivers::activity::island_kind_title(tool) {
return bare.to_string();
}
+ if let Some(title) = crate::drivers::activity::island_file_title(tool, &s.title) {
+ return title;
+ }
if !crate::drivers::activity::is_shell_tool(tool) {
return s.title.clone();
}
@@ -307,12 +311,12 @@ mod tests {
turn.observe(&RuntimeEvent::ToolCallCompleted { id: "1".into(), result: json!({"status": "error", "error": "Permission denied (publickey)"}) });
assert_eq!(current_step("turn-island-failed").unwrap().0, "Running git");
- // A Reading step and a thinking step read as they do today; an approval keeps its title
+ // A Reading step names its file (21c) and a thinking step reads as it does today; an approval keeps its title
let tag = TurnTag { turn_id: "turn-island-other".into(), kwant_id: "k".into(), context_id: "c".into(), thread_id: None };
let turn = TurnActivity::start(tx, tag);
let read = json!({"file_path": "/tmp/notes.md"});
turn.observe(&RuntimeEvent::ToolCallPending { id: "1".into(), name: "Read".into(), args: read.clone() });
- assert_eq!(current_step("turn-island-other").unwrap().0, crate::drivers::activity::summarize("Read", &read).0);
+ assert_eq!(current_step("turn-island-other").unwrap().0, "Reading notes.md");
turn.observe(&RuntimeEvent::ToolCallCompleted { id: "1".into(), result: json!({"status": "ok"}) });
turn.observe(&RuntimeEvent::ThinkingDelta("the key is in ~/.env".into()));
assert_eq!(current_step("turn-island-other").unwrap().0, "Thinking");
@@ -353,7 +357,7 @@ mod tests {
assert!(!title.contains("acme") && !title.contains("4471"), "{title}");
}
- // An approval for a search keeps its (already bare) title; a Reading step keeps its path
+ // An approval for a search keeps its (already bare) title; a Reading step names its file (21c)
let tag = TurnTag { turn_id: "turn-island-words-other".into(), kwant_id: "k".into(), context_id: "c".into(), thread_id: None };
let turn = TurnActivity::start(tx, tag);
approval_waiting("turn-island-words-other", "ap", "WebSearch");
@@ -361,7 +365,43 @@ mod tests {
approval_settled("turn-island-words-other", "ap", "ok");
let read = json!({"file_path": "/tmp/acme.md"});
turn.observe(&RuntimeEvent::ToolCallPending { id: "2".into(), name: "Read".into(), args: read.clone() });
- assert_eq!(current_step("turn-island-words-other").unwrap().0, crate::drivers::activity::summarize("Read", &read).0);
+ assert_eq!(current_step("turn-island-words-other").unwrap().0, "Reading acme.md");
+ }
+
+ /// 21c: the island names a read, edit or write step's file, never its folders; the chat's
+ /// activity list keeps "…/folder/file".
+ #[test]
+ fn current_step_names_a_file_never_its_folders() {
+ let cases: Vec<(&str, Value, &str)> = vec![
+ ("Read", json!({"file_path": "/srv/clients/acme-layoffs/contract.md"}), "Reading contract.md"),
+ ("Edit", json!({"file_path": "/tmp/acme-layoffs/acme.md", "old_string": "a", "new_string": "b"}), "Editing acme.md"),
+ ("MultiEdit", json!({"file_path": "/srv/acme-layoffs/src/main.rs", "edits": []}), "Editing main.rs"),
+ ("Write", json!({"file_path": "/srv/acme-layoffs/notes.txt", "content": "x"}), "Writing notes.txt"),
+ ("NotebookEdit", json!({"notebook_path": "/srv/acme-layoffs/model.ipynb"}), "Editing model.ipynb"),
+ ("Read", json!({"file_path": "C:\\clients\\acme-layoffs\\a.md"}), "Reading a.md"),
+ ("Read", json!({"file_path": "/srv/clients/acme-layoffs/"}), "Reading acme-layoffs"),
+ ("Read", json!({"file_path": "contract.md"}), "Reading contract.md"),
+ ("Read", Value::Null, "Reading a file"),
+ ];
+ let (tx, _rx) = broadcast::channel(64);
+ for (n, (tool, args, want)) in cases.into_iter().enumerate() {
+ let id = format!("turn-island-file-{n}");
+ let tag = TurnTag { turn_id: id.clone(), kwant_id: "k".into(), context_id: "c".into(), thread_id: None };
+ let turn = TurnActivity::start(tx.clone(), tag);
+ turn.observe(&RuntimeEvent::ToolCallPending { id: "1".into(), name: tool.into(), args: args.clone() });
+ assert_eq!(current_step(&id).unwrap().0, want, "{tool} {args}");
+ // The chat's activity list keeps its "…/folder/file" title, byte for byte
+ let chat = turn.with_log(|log| log.steps()[0].clone());
+ assert_eq!(chat.title, crate::drivers::activity::summarize(tool, &args).0);
+ // Between steps, the finished step still names only its file
+ turn.observe(&RuntimeEvent::ToolCallCompleted { id: "1".into(), result: json!({"status": "ok"}) });
+ let (title, _) = current_step(&id).unwrap();
+ assert_eq!(title, want);
+ assert!(!title.contains('/') && !title.contains('\\') && !title.contains("clients"), "{title}");
+ if want != "Reading acme-layoffs" {
+ assert!(!title.contains("acme-layoffs"), "{title}");
+ }
+ }
}
#[test]