Skip to content

armgit / Wake

Public Imported from GitHub
0

All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.

Rust

fix(remote): support Windows cache paths in rsync (#57)

Corey Chiu1068223f18a6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f22062e..b20fe68 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -43,7 +43,32 @@ jobs:
sudo apt-get install -y --no-install-recommends \
libasound2-dev libfontconfig1-dev libwayland-dev \
libxkbcommon-dev libxkbcommon-x11-dev libssl-dev libzstd-dev \
- pkg-config cmake clang
+ pkg-config cmake clang rsync
+
+ - name: Install cwRsync
+ if: runner.os == 'Windows'
+ run: choco install rsync --version=6.4.8 --yes --no-progress
+
+ - name: Install compiler for the Cygwin SSH fixture
+ if: runner.os == 'Windows'
+ id: cygwin
+ uses: cygwin/cygwin-install-action@3f0a3f9f988f7e96b8c18098ae05eaec175f5b52 # v6
+ with:
+ packages: gcc-core
+ add-to-path: 'false'
+
+ - name: Configure Windows remote sync test
+ if: runner.os == 'Windows'
+ env:
+ CYGWIN_ROOT: ${{ steps.cygwin.outputs.root }}
+ run: |
+ "WAKE_TEST_CYGWIN_ROOT=$env:CYGWIN_ROOT" >> $env:GITHUB_ENV
+ "WAKE_TEST_CWRSYNC_BIN=$env:ChocolateyInstall\lib\rsync\tools\bin" >> $env:GITHUB_ENV
+
+ # 真 rsync + 同运行时的假 SSH,不连外网;覆盖 Windows 盘符和并行缓存目录。
+ - name: Test remote sync paths
+ timeout-minutes: 5
+ run: cargo test -p wake-core --test remote_sync_paths -- --ignored
# 数据层测试:adapter 解析契约 / seq 一致性 / db 往返 / 扫描终态
- name: Test wake-core
diff --git a/CHANGELOG.md b/CHANGELOG.md
index feef649..e6b2623 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## Unreleased
+
+- Fix: Remote sync on Windows now accepts local cache paths with drive letters, avoiding the "source and destination cannot both be remote" error before any files transfer (#56, thanks @zhyg).
+
## [0.8.5] — 2026-09-27
- Fix: Devin CLI sessions stored under `%APPDATA%\devin` are now discovered automatically on Windows (#53, thanks @yougeqiu).
diff --git a/README.md b/README.md
index 3ae345d..5b426aa 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,8 @@ Before you add a host:
- SSH has to work without prompts: load your key into an agent (Wake runs without a terminal, so it can never answer a passphrase prompt) and connect once from a terminal so the host key is already trusted
- `rsync` is needed on both ends — macOS and most Linux distributions ship one; on Windows install it yourself
+On Windows, use `rsync` and `ssh` from the same Cygwin/cwRsync distribution. Put its `bin` directory ahead of Windows OpenSSH in `PATH`, then restart Wake. For Chocolatey's `rsync` package, this directory is `%ChocolateyInstall%\lib\rsync\tools\bin`; the package exposes only `rsync` on `PATH` by default. Check `where.exe rsync` and `where.exe ssh` to confirm both resolve there. Windows' built-in OpenSSH may pass Wake's initial connection check but is [incompatible with Cygwin rsync's transport](https://cygwin.com/pipermail/cygwin/2022-March/251153.html). Test the bundled SSH's key, agent and host configuration before adding a host.
+
How it works, and what it doesn't do yet:
- Wake first asks the remote which of the known agent directories exist, then mirrors only those with `rsync` into `remotes/<host>/` under its own data directory. Only session data and sidecar files are copied, never credentials, and nothing on the remote is ever written
diff --git a/crates/wake-core/src/remote.rs b/crates/wake-core/src/remote.rs
index 0cd27bc..4d0afef 100644
--- a/crates/wake-core/src/remote.rs
+++ b/crates/wake-core/src/remote.rs
@@ -352,7 +352,7 @@ fn present_remote_paths(stdout: &str) -> Vec<&'static str> {
/// 单测卡命令形状。`-R`(--relative)让 `host:./<相对路径>` 在目标重建相对
/// 布局;`--delete` 让远程删除传播到缓存(watcher 收 Remove 后清库内行)——
/// 它只作用于各源树**内部**,整棵源消失由 sync_host 的缺席清理负责。
-fn rsync_args(host: &str, dest: &Path, paths: &[&str]) -> Vec<String> {
+fn rsync_args(host: &str, paths: &[&str]) -> Vec<String> {
// -a enables special files. Override it afterwards: sockets/FIFOs carry no
// session data, and recreating sockets under a long cache path can exceed
// sun_path and abort openrsync's receiver (#47).
@@ -374,7 +374,9 @@ fn rsync_args(host: &str, dest: &Path, paths: &[&str]) -> Vec<String> {
format!("ssh {}", SSH_OPTS.join(" ")),
]);
args.extend(paths.iter().map(|path| format!("{host}:./{path}")));
- args.push(dest.to_string_lossy().to_string());
+ // 目标由子进程的 cwd 指定。Windows 的 C:\... / C:/... 会被 rsync
+ // 当作 host:path,与远端源一起触发 "both be remote" (#56)。
+ args.push(".".to_string());
args
}
@@ -463,7 +465,7 @@ fn remove_cached(path: &Path) -> Result<(), String> {
/// 是用户能看懂的原话("Permission denied (publickey)"、"Host key
/// verification failed")
fn probe_remote(host: &str) -> Result<Vec<&'static str>, String> {
- let output = run_tool("ssh", "OpenSSH", &probe_args(host))?;
+ let output = run_tool("ssh", "OpenSSH", &probe_args(host), None)?;
classify("ssh", &output, &[])?;
Ok(present_remote_paths(&String::from_utf8_lossy(
&output.stdout,
@@ -482,8 +484,8 @@ enum RsyncError {
/// 行全是 ENOENT 时是探测后消失的源,交调用方重探,权限/读错误同样报 23,
/// 照常报错(记成功会隐藏真实缺数据)。
fn run_rsync(host: &str, dest: &Path, paths: &[&str]) -> Result<(), RsyncError> {
- let output =
- run_tool("rsync", "rsync", &rsync_args(host, dest, paths)).map_err(RsyncError::Other)?;
+ let output = run_tool("rsync", "rsync", &rsync_args(host, paths), Some(dest))
+ .map_err(RsyncError::Other)?;
if output.status.code() == Some(23) && only_missing_sources(&output.stderr) {
return Err(RsyncError::SourcesVanished(exit_error("rsync", &output)));
}
@@ -511,16 +513,25 @@ fn run_tool(
bin: &str,
install_hint: &str,
args: &[String],
+ working_dir: Option<&Path>,
) -> Result<std::process::Output, String> {
- let output = std::process::Command::new(bin)
- .args(args)
- .stdin(std::process::Stdio::null())
- .output();
+ let mut command = std::process::Command::new(bin);
+ command.args(args).stdin(std::process::Stdio::null());
+ if let Some(dir) = working_dir {
+ // 每个 host 并行同步,只能设置子进程 cwd,不能改整个 Wake 进程的 cwd。
+ command.current_dir(dir);
+ }
+ let output = command.output();
match output {
Ok(o) => Ok(o),
- Err(e) if e.kind() == std::io::ErrorKind::NotFound => Err(format!(
- "{bin} not found on PATH — install {install_hint} to sync remote hosts"
- )),
+ // Remove host 可能同时删掉缓存目录;这种启动失败不是缺少 rsync。
+ Err(e)
+ if e.kind() == std::io::ErrorKind::NotFound && working_dir.is_none_or(Path::is_dir) =>
+ {
+ Err(format!(
+ "{bin} not found on PATH — install {install_hint} to sync remote hosts"
+ ))
+ }
Err(e) => Err(format!("failed to run {bin}: {e}")),
}
}
@@ -682,7 +693,7 @@ mod tests {
#[test]
fn rsync_args_shape() {
let present = [".claude/projects", ".codex/state_5.sqlite"];
- let args = rsync_args("devbox", Path::new("/tmp/cache/devbox"), &present);
+ let args = rsync_args("devbox", &present);
assert_eq!(args[0], "-az");
let archive = args.iter().position(|a| a == "-az").unwrap();
let no_specials = args.iter().position(|a| a == "--no-specials").unwrap();
@@ -709,7 +720,7 @@ mod tests {
]
);
// 目标在最后
- assert_eq!(args.last().unwrap(), "/tmp/cache/devbox");
+ assert_eq!(args.last().unwrap(), ".");
// 各家声明的 exclude 全部落到命令行(OpenClaw 的凭证靠它挡)。`/` 在字符集里:
// exclude 是单独一个 argv 交给本地 rsync、经协议传给发送端,不过任何 shell;
// 带层级的模式(Craft 的 workspaces/*/sources)只匹配那一层,不误伤同名目录
diff --git a/crates/wake-core/tests/fixtures/remote_sync_ssh.c b/crates/wake-core/tests/fixtures/remote_sync_ssh.c
new file mode 100644
index 0000000..8d3d5a7
--- /dev/null
+++ b/crates/wake-core/tests/fixtures/remote_sync_ssh.c
@@ -0,0 +1,49 @@
+/* SSH stand-in for remote_sync_paths, compiled for the rsync runtime. It only
+ * reads synthetic directories; no shell, network or SSH credentials are used. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static void require(int condition, const char *message) {
+ if (!condition) {
+ fprintf(stderr, "fake SSH: %s\n", message);
+ exit(1);
+ }
+}
+
+int main(int argc, char **argv) {
+ int arg = 1;
+ while (arg < argc && strncmp(argv[arg], "-o", 2) == 0) {
+ arg++;
+ }
+ require(arg < argc, "missing host");
+ const char *host = argv[arg++];
+ require(strcmp(host, "devbox") == 0 || strcmp(host, "otherbox") == 0,
+ "unexpected host");
+ const char *root = getenv("WAKE_TEST_REMOTE_HOME");
+ require(root != NULL, "missing synthetic home");
+ require(chdir(root) == 0 && chdir(host) == 0, "cannot enter synthetic home");
+ require(arg < argc, "missing remote command");
+
+ if (arg == argc - 1 && strncmp(argv[arg], "sh -c ", 6) == 0) {
+ require(strstr(argv[arg], ".claude/projects") != NULL, "unexpected probe");
+ struct stat st;
+ if (stat(".claude/projects", &st) == 0 && S_ISDIR(st.st_mode)) {
+ puts(".claude/projects");
+ }
+ return 0;
+ }
+
+ require(strcmp(argv[arg], "rsync") == 0, "unexpected remote command");
+ int server = 0, sender = 0;
+ for (int i = arg + 1; i < argc; i++) {
+ server |= strcmp(argv[i], "--server") == 0;
+ sender |= strcmp(argv[i], "--sender") == 0;
+ }
+ require(server && sender, "only read-only rsync sender is allowed");
+ execvp(argv[arg], argv + arg);
+ perror("fake SSH: start rsync sender");
+ return 1;
+}
diff --git a/crates/wake-core/tests/remote_sync_paths.rs b/crates/wake-core/tests/remote_sync_paths.rs
new file mode 100644
index 0000000..3044e69
--- /dev/null
+++ b/crates/wake-core/tests/remote_sync_paths.rs
@@ -0,0 +1,149 @@
+//! Real rsync on all three platforms, including cwRsync on Windows (#56).
+//! This single test owns its process environment; all data and child working
+//! directories are synthetic. CI explicitly runs it after installing rsync and
+//! a C compiler (Cygwin GCC on Windows, to match cwRsync's transport runtime).
+use std::fs;
+use std::path::PathBuf;
+use std::process::Command;
+use wake_core::db::Store;
+use wake_core::remote::{host_cache_dir, sync_hosts};
+
+struct RestoreCwd(PathBuf);
+
+impl Drop for RestoreCwd {
+ fn drop(&mut self) {
+ std::env::set_current_dir(&self.0).unwrap();
+ }
+}
+
+#[test]
+#[ignore = "requires rsync and a C compiler; installed and run explicitly in CI"]
+fn remote_sync_handles_native_cache_paths() {
+ let tmp = tempfile::tempdir().unwrap();
+ let bin = tmp.path().join("bin");
+ fs::create_dir_all(&bin).unwrap();
+
+ // Cygwin rsync's transport uses Cygwin descriptors, so a native Windows
+ // fixture cannot forward them. Compile for the same runtime instead.
+ #[cfg(windows)]
+ let mut compiler = {
+ let root = PathBuf::from(
+ std::env::var_os("WAKE_TEST_CYGWIN_ROOT").expect("Cygwin installation for GCC"),
+ );
+ let mut compiler = Command::new(root.join("bin/env.exe"));
+ compiler.arg("/usr/bin/gcc");
+ let mut paths = vec![root.join("bin")];
+ paths.extend(std::env::split_paths(&std::env::var_os("PATH").unwrap()));
+ compiler.env("PATH", std::env::join_paths(paths).unwrap());
+
+ compiler
+ };
+ #[cfg(not(windows))]
+ let mut compiler = Command::new("cc");
+ fs::copy(
+ concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/fixtures/remote_sync_ssh.c"
+ ),
+ bin.join("remote_sync_ssh.c"),
+ )
+ .unwrap();
+ let compiled = compiler
+ .current_dir(&bin)
+ .args([
+ "-std=c11",
+ "-Wall",
+ "-Wextra",
+ "-Werror",
+ "remote_sync_ssh.c",
+ ])
+ .arg("-o")
+ .arg(format!("ssh{}", std::env::consts::EXE_SUFFIX))
+ .output()
+ .unwrap();
+ assert!(
+ compiled.status.success(),
+ "compile fake SSH: {}",
+ String::from_utf8_lossy(&compiled.stderr)
+ );
+ #[cfg(windows)]
+ {
+ // Keep the receiver, sender and fake SSH on cwRsync's bundled runtime,
+ // without invoking Chocolatey's native rsync shim from Cygwin. Stage it
+ // after compilation so GCC's subprocesses cannot load this older DLL
+ // from their working directory instead of their own toolchain runtime.
+ let cwrsync = PathBuf::from(
+ std::env::var_os("WAKE_TEST_CWRSYNC_BIN").expect("cwRsync bin directory"),
+ );
+ fs::copy(cwrsync.join("rsync.exe"), bin.join("rsync.exe")).unwrap();
+ for entry in fs::read_dir(cwrsync).unwrap() {
+ let entry = entry.unwrap();
+ if entry.path().extension().is_some_and(|ext| ext == "dll") {
+ fs::copy(entry.path(), bin.join(entry.file_name())).unwrap();
+ }
+ }
+ }
+ let mut paths = vec![bin];
+ paths.extend(std::env::split_paths(&std::env::var_os("PATH").unwrap()));
+ std::env::set_var("PATH", std::env::join_paths(paths).unwrap());
+ let version = Command::new("rsync").arg("--version").output().unwrap();
+ assert!(version.status.success(), "rsync must be installed");
+ let remote = tmp.path().join("remote");
+ std::env::set_var("WAKE_TEST_REMOTE_HOME", &remote);
+ let local_home = tmp.path().join("empty-home");
+ fs::create_dir_all(&local_home).unwrap();
+ for key in ["HOME", "USERPROFILE", "WAKE_HOME"] {
+ std::env::set_var(key, &local_home);
+ }
+
+ // Even a broken relative destination must only write inside our fixture.
+ let _restore_cwd = RestoreCwd(std::env::current_dir().unwrap());
+ std::env::set_current_dir(&local_home).unwrap();
+ let parent_cwd = std::env::current_dir().unwrap();
+ let session = ".claude/projects/demo/session.jsonl";
+ let deleted = ".claude/projects/demo/deleted.jsonl";
+ let hosts = ["devbox".to_string(), "otherbox".to_string()];
+ for host in &hosts {
+ let source = remote.join(host).join(session);
+ fs::create_dir_all(source.parent().unwrap()).unwrap();
+ fs::write(source, format!("synthetic session from {host}\n")).unwrap();
+ fs::write(remote.join(host).join(deleted), "synthetic old session\n").unwrap();
+ }
+
+ // On Windows this is an absolute drive-letter path, with spaces and Unicode.
+ let db_dir = tmp.path().join("local cache 用户 with spaces");
+ fs::create_dir_all(&db_dir).unwrap();
+ let store = Store::open(&db_dir.join("wake.db")).unwrap();
+ for host in &hosts {
+ store.add_remote_host(host).unwrap();
+ }
+ sync_hosts(&store, &hosts);
+ assert_eq!(std::env::current_dir().unwrap(), parent_cwd);
+ for host in store.list_remote_hosts().unwrap() {
+ assert_eq!(host.last_sync_error, None, "host {}", host.name);
+ assert!(host.last_sync_at.is_some());
+ let cache = host_cache_dir(&db_dir, &host.name);
+ assert_eq!(
+ fs::read(cache.join(session)).unwrap(),
+ fs::read(remote.join(&host.name).join(session)).unwrap(),
+ "parallel hosts must keep separate cache trees"
+ );
+ assert!(cache.join(deleted).is_file());
+ }
+ assert!(!local_home.join(".claude").exists());
+
+ fs::write(remote.join("devbox").join(session), "updated session\n").unwrap();
+ fs::remove_file(remote.join("devbox").join(deleted)).unwrap();
+ sync_hosts(&store, &hosts);
+ assert_eq!(std::env::current_dir().unwrap(), parent_cwd);
+ for host in store.list_remote_hosts().unwrap() {
+ assert_eq!(host.last_sync_error, None, "host {}", host.name);
+ assert_eq!(
+ fs::read(host_cache_dir(&db_dir, &host.name).join(session)).unwrap(),
+ fs::read(remote.join(&host.name).join(session)).unwrap()
+ );
+ }
+ assert!(!host_cache_dir(&db_dir, "devbox").join(deleted).exists());
+ assert!(host_cache_dir(&db_dir, "otherbox").join(deleted).is_file());
+ assert!(remote.join("otherbox").join(deleted).is_file());
+}