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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix: keep shared file saves inside Downloads and clean up deleted bots
leepokaiaa8e26c56889
diff --git a/apps/desktop/src/renderer/views/thread/FileDownloadCard.tsx b/apps/desktop/src/renderer/views/thread/FileDownloadCard.tsxindex c5ca4791..315a2366 100644--- a/apps/desktop/src/renderer/views/thread/FileDownloadCard.tsx+++ b/apps/desktop/src/renderer/views/thread/FileDownloadCard.tsx@@ -1,6 +1,7 @@import type { Entry, SharedFile } from '@shared/models'import { useStore } from '../../store/context'import { Icon } from '../../components/Icon'+import { IconButtonBase } from '../../components/Overlay'import { font } from '../../lib/fonts'import { attachmentSymbol, byteCount } from './Attachments'@@ -16,8 +17,6 @@ export function FileDownloadCard({ entry, file }: { entry: Entry; file: SharedFi<div style={{ ...font('subheadline', 'semibold'), whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }} title={file.name}>{file.name}</div><div role={state?.kind === 'failed' ? 'alert' : 'status'} style={{ ...font('caption2'), color: state?.kind === 'failed' ? 'var(--danger)' : 'var(--secondary)', overflowWrap: 'anywhere' }}>{detail}</div></div>- <button aria-label={`${action}: ${file.name}`} title={action} onClick={() => busy ? store.fileDownloads.cancel(file.id) : void store.fileDownloads.save(store.client, entry.id, file)} style={{ display: 'flex', padding: 8 }}>- <Icon name={busy ? 'xmark' : 'arrow.down.to.line'} size={20} />- </button>+ <IconButtonBase title={action} icon={busy ? 'xmark' : 'arrow.down.to.line'} size={36} onClick={() => busy ? store.fileDownloads.cancel(file.id) : void store.fileDownloads.save(store.client, entry.id, file)} /></div>}diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/FileDownloads.swift b/apps/ios/Kit/Sources/CodyncUI/Store/FileDownloads.swiftindex 9a035470..ed851244 100644--- a/apps/ios/Kit/Sources/CodyncUI/Store/FileDownloads.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Store/FileDownloads.swift@@ -34,10 +34,12 @@ public final class FileDownloads {public func save(client: HostClient?, entry: Entry, file: SharedFile) {guard !retired else { return }- guard tasks.isEmpty, export == nil else {- if tasks[file.id] == nil { states[file.id] = .failed("Finish the current download or export first.") }+ guard tasks.isEmpty else {+ if tasks[file.id] == nil { states[file.id] = .failed("Finish the current download first.") }return}+ // An export whose chat was left never showed its sheet; this tap replaces it.+ dismissExport()guard let client else { states[file.id] = .failed("Connect to this computer to download the file."); return }states[file.id] = .downloading(0)let directory = FileManager.default.temporaryDirectory.appendingPathComponent("CodyncDownloads", isDirectory: true)diff --git a/apps/ios/Kit/Tests/CodyncUITests/FileDownloadLifecycleTests.swift b/apps/ios/Kit/Tests/CodyncUITests/FileDownloadLifecycleTests.swiftindex 040563e1..37cd5d08 100644--- a/apps/ios/Kit/Tests/CodyncUITests/FileDownloadLifecycleTests.swift+++ b/apps/ios/Kit/Tests/CodyncUITests/FileDownloadLifecycleTests.swift@@ -153,3 +153,23 @@ private func downloadEventually(_ condition: @MainActor () async -> Bool) asynclet removed = await downloadEventually { !FileManager.default.fileExists(atPath: item.url.path) }#expect(removed)}++@MainActor @Test func anUnshownExportIsReplacedByTheNextDownload() async throws {+ let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)+ defer { try? FileManager.default.removeItem(at: directory) }+ let downloads = FileDownloads(writer: ControlledDownloadWriter(directory: directory, pauseCompletedFile: false))+ defer { downloads.retire() }+ let client = HostClient(transport: ControlledFileRead())+ let entry = fileEntry()+ // The first export's chat was left, so its sheet never showed or dismissed it.+ downloads.save(client: client, entry: entry, file: emptyFile("stale"))+ let staleReady = await downloadEventually { downloads.export?.id == "stale" }+ try #require(staleReady)+ let stale = try #require(downloads.export)++ downloads.save(client: client, entry: entry, file: emptyFile("next"))+ let replaced = await downloadEventually { downloads.export?.id == "next" }+ #expect(replaced)+ let staleRemoved = await downloadEventually { !FileManager.default.fileExists(atPath: stale.url.path) }+ #expect(staleRemoved)+}diff --git a/host/src/api/files.rs b/host/src/api/files.rsindex 089b5fda..160476a0 100644--- a/host/src/api/files.rs+++ b/host/src/api/files.rs@@ -8,7 +8,7 @@ use std::sync::Arc;pub async fn read(hub: &Arc<Hub>, body: &Value) -> Result<Value> {let entry = hub.store.entry(str_arg(body, "entryId")?).ok_or_else(|| anyhow!("unknown file message"))?;- ensure!(entry.kind == "agent" && entry.data["final"] == true, "not a file message");+ ensure!(entry.kind == crate::store::EntryKind::Agent.as_str() && entry.data["final"] == true, "not a file message");let bot = entry.data["author"].as_str().ok_or_else(|| anyhow!("missing file author"))?;ensure!(entry.bot_id == bot, "not a bot chat file");ensure!(hub.store.bot(bot)?.is_some_and(|row| !row.deleted), "unknown bot");diff --git a/host/src/chat/files.rs b/host/src/chat/files.rsindex 3cf262b7..a5db1265 100644--- a/host/src/chat/files.rs+++ b/host/src/chat/files.rs@@ -52,7 +52,7 @@ fn path(root: &Path, id: &str) -> Result<PathBuf> {pub fn name(value: &str) -> Result<String> {ensure!(!value.is_empty() && value.len() <= 200, "file name must be 1–200 bytes");ensure!(- value != "." && value != ".." && !value.contains(['/', '\\']) && !value.chars().any(char::is_control),+ value != "." && value != ".." && !value.contains(['/', '\\', ':']) && !value.chars().any(char::is_control),"invalid file name");Ok(value.to_owned())diff --git a/host/src/chat/files/tests.rs b/host/src/chat/files/tests.rsindex c39990c8..243d58b1 100644--- a/host/src/chat/files/tests.rs+++ b/host/src/chat/files/tests.rs@@ -102,3 +102,11 @@ fn cancellation_during_copy_stops_before_reading_the_next_chunk() {assert_eq!(reader.1, 1);assert_eq!(output, [42]);}++#[test]+fn names_never_carry_path_or_drive_syntax() {+ for bad in ["", ".", "..", "a/b", "a\\b", "C:evil.bat", "line\nbreak"] {+ assert!(name(bad).is_err(), "{bad:?}");+ }+ assert_eq!(name(".hidden").unwrap(), ".hidden");+}diff --git a/host/src/hub.rs b/host/src/hub.rsindex 7c088a08..5d0b220b 100644--- a/host/src/hub.rs+++ b/host/src/hub.rs@@ -295,6 +295,15 @@ impl Hub {let _ =self.events.send(json!({"type": "bot", "rev": rev, "bot": {"id": id, "deleted": true, "rev": rev}}));}+ // Its shared files are unreachable once the bot is deleted.+ let files = crate::chat::files::root(id);+ tokio::task::spawn_blocking(move || {+ if let Err(error) = std::fs::remove_dir_all(&files)+ && error.kind() != std::io::ErrorKind::NotFound+ {+ tracing::warn!(error = %error, "couldn't remove a deleted bot's shared files");+ }+ });// A deleted bot leaves its groups; what it said there stays.for row in self.store.bots()? {let mut group = row.config;diff --git a/host/src/tui/net.rs b/host/src/tui/net.rsindex 3fdfd46a..2edd5688 100644--- a/host/src/tui/net.rs+++ b/host/src/tui/net.rs@@ -255,8 +255,15 @@ impl Client {/// `dir/name`, or `name (2)` … when that's taken. The name is only its last part (no `../`).fn free_path(dir: &std::path::Path, name: &str) -> PathBuf {- let name =- std::path::Path::new(name).file_name().map_or_else(|| "file".into(), |n| n.to_string_lossy().into_owned());+ // Only the last plain component: a drive prefix ("C:x") or parent can't escape `dir`.+ let name = std::path::Path::new(name)+ .components()+ .filter_map(|c| match c {+ std::path::Component::Normal(n) => Some(n.to_string_lossy().into_owned()),+ _ => None,+ })+ .last()+ .unwrap_or_else(|| "file".into());let (stem, ext) = match name.rsplit_once('.') {Some((s, e)) if !s.is_empty() => (s.to_owned(), format!(".{e}")),_ => (name.clone(), String::new()),@@ -290,6 +297,7 @@ mod tests {let dir = std::env::temp_dir().join(format!("codync-dl-{}", uuid::Uuid::new_v4()));std::fs::create_dir_all(&dir).unwrap();assert_eq!(super::free_path(&dir, "../a.txt"), dir.join("a.txt"));+ assert_eq!(super::free_path(&dir, "/etc/b.txt"), dir.join("b.txt"));std::fs::write(dir.join("a.txt"), "").unwrap();assert_eq!(super::free_path(&dir, "a.txt"), dir.join("a (2).txt"));std::fs::remove_dir_all(&dir).unwrap();