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.

Chat step titles shorten Windows paths too (22w) (#735)

Oleksandr Ivanchenko2195d979f5c8
diff --git a/src/drivers/activity.rs b/src/drivers/activity.rs
index 7d5901fa..ff3866c4 100644
--- a/src/drivers/activity.rs
+++ b/src/drivers/activity.rs
@@ -691,14 +691,28 @@ fn host_of(url: &str) -> String {
.unwrap_or_else(|| url.to_string())
}
+/// A path separator on any of kwant's platforms: `/`, or `\` on Windows (21c, 22w).
+fn is_path_sep(c: char) -> bool {
+ c == '/' || c == '\\'
+}
+
/// The last two parts of a path: enough to recognise the file without the whole folder.
+/// Splits on `/` and `\` alike and keeps the path's own separators, so `C:\Users\x\acme\a.md`
+/// is `…\acme\a.md` and `/srv/app/src/main.rs` is `…/src/main.rs`, as before (22w). A bare drive
+/// (`C:\`) stays as it is.
fn short_path(path: &str) -> String {
- let parts: Vec<&str> = path.trim_end_matches('/').rsplit('/').take(2).collect();
- let short = parts.into_iter().rev().collect::<Vec<_>>().join("/");
- if short.len() < path.trim_end_matches('/').len() {
- format!("…/{short}")
- } else {
- short
+ let trimmed = path.trim_end_matches(is_path_sep);
+ let is_drive = |s: &str| matches!(s.as_bytes(), [d, b':'] if d.is_ascii_alphabetic());
+ if is_drive(trimmed) {
+ return path.to_string();
+ }
+ let Some(last) = trimmed.rfind(is_path_sep) else {
+ return trimmed.to_string();
+ };
+ match trimmed[..last].rfind(is_path_sep) {
+ // Separators are one byte, so `before` is a char boundary; the slice keeps the separator.
+ Some(before) => format!("…{}", &trimmed[before..]),
+ None => trimmed.to_string(),
}
}
@@ -839,7 +853,7 @@ impl FileTool {
/// 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 is_sep = is_path_sep;
let Some(path) = title.strip_prefix(kind.verb()).and_then(|r| r.strip_prefix(' ')) else {
return Some(kind.bare().to_string());
};
@@ -1065,6 +1079,47 @@ mod tests {
assert_eq!(stopped.iter().map(|s| s.status).collect::<Vec<_>>(), ["stopped", "stopped"]);
}
+ /// 22w: `short_path` keeps the last two parts of a Windows path as it does a Unix one, with the
+ /// path's own separators; every `/` path reads exactly as before.
+ #[test]
+ fn short_path_shortens_windows_paths_too() {
+ let cases = [
+ // Unix: unchanged from 0.9.16.
+ ("/srv/app/src/main.rs", "…/src/main.rs"),
+ ("/home/x/clients/acme/contract.md", "…/acme/contract.md"),
+ ("/tmp/acme.md", "…/tmp/acme.md"),
+ ("/tmp/acme/", "…/tmp/acme"),
+ ("src/main.rs", "src/main.rs"),
+ ("a//b/c.md", "…/b/c.md"),
+ ("a/b//c.md", "…//c.md"),
+ ("/a.md", "/a.md"),
+ ("contract.md", "contract.md"),
+ ("/", ""),
+ ("", ""),
+ // Windows: drive letter and backslashes.
+ ("C:\\Users\\x\\clients\\acme\\contract.md", "…\\acme\\contract.md"),
+ ("C:\\work\\a.md", "…\\work\\a.md"),
+ ("C:\\a.md", "C:\\a.md"),
+ ("C:\\work\\acme\\", "…\\work\\acme"),
+ ("work\\a.md", "work\\a.md"),
+ // A bare drive stays as typed.
+ ("C:\\", "C:\\"),
+ ("d:/", "d:/"),
+ // UNC.
+ ("\\\\server\\share\\clients\\a.md", "…\\clients\\a.md"),
+ ("\\\\server\\a.md", "…\\server\\a.md"),
+ // Mixed separators keep their own.
+ ("C:/work\\acme\\a.md", "…\\acme\\a.md"),
+ ("C:/work/acme\\a.md", "…/acme\\a.md"),
+ ("C:\\work\\acme/a.md", "…\\acme/a.md"),
+ // Non-ASCII names slice on char boundaries.
+ ("C:\\Пользователи\\клиент\\договор.md", "…\\клиент\\договор.md"),
+ ];
+ for (path, want) in cases {
+ assert_eq!(short_path(path), want, "{path}");
+ }
+ }
+
#[test]
fn summaries_are_short_and_human() {
let cases = [
@@ -1072,6 +1127,7 @@ mod tests {
("command_execution", json!({"command": ["bash", "-lc", "ls -la"]}), "Running `ls -la`"),
("command_execution", json!({"command": "bash -lc 'cargo test'"}), "Running `cargo test`"),
("Read", json!({"file_path": "/srv/app/src/main.rs"}), "Reading …/src/main.rs"),
+ ("Read", json!({"file_path": "C:\\Users\\x\\clients\\acme\\contract.md"}), "Reading …\\acme\\contract.md"),
("Edit", json!({"file_path": "main.rs"}), "Editing main.rs"),
("WebFetch", json!({"url": "https://www.github.com/x/y"}), "Opening github.com"),
("mcp__kwnt__browser_open", json!({"url": "https://example.com/login"}), "Opening example.com"),
@@ -1109,7 +1165,8 @@ mod tests {
("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": "C:\\work\\a.md"}), "Reading …\\work\\a.md", "Reading a.md"),
+ ("Edit", json!({"file_path": "C:\\Users\\x\\clients\\acme\\contract.md"}), "Editing …\\acme\\contract.md", "Editing contract.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"),