YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(cli): add `screenpipe sync remote` (SSH/SFTP sync to your own server)
Louis Beaumontf46e85cb1f35
diff --git a/Cargo.toml b/Cargo.tomlindex 199841465..d18afbe1a 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -6,7 +6,7 @@ exclude = ["apps/screenpipe-app-tauri/src-tauri", "crates/screenpipe-integrationresolver = "2"[workspace.package]-version = "0.3.291"+version = "0.3.292"authors = ["louis030195 <[email protected]>"]description = ""repository = "https://github.com/screenpipe/screenpipe"diff --git a/crates/screenpipe-engine/src/cli/mod.rs b/crates/screenpipe-engine/src/cli/mod.rsindex 9a1a80fad..8593d9793 100644--- a/crates/screenpipe-engine/src/cli/mod.rs+++ b/crates/screenpipe-engine/src/cli/mod.rs@@ -809,6 +809,62 @@ pub enum SyncCommand {#[arg(short = 'p', long, default_value_t = 3030)]port: u16,},+ /// Sync ~/.screenpipe to a remote SSH server (SFTP, no cloud account)+ Remote {+ #[command(subcommand)]+ subcommand: RemoteSyncCommand,+ },+}++/// SSH/SFTP-based sync of `~/.screenpipe` to a remote server.+///+/// No cloud account or screenpipe-cloud dependency — pushes the entire data+/// directory over SFTP using a private key from `~/.ssh/`. Use this to+/// centralize multiple machines onto a server you control (home box, VPS).+#[derive(Subcommand)]+pub enum RemoteSyncCommand {+ /// Test SSH connectivity (dry-run, no upload)+ Test {+ #[command(flatten)]+ cfg: RemoteSyncArgs,+ },+ /// Push `~/.screenpipe/` to the remote once+ Now {+ #[command(flatten)]+ cfg: RemoteSyncArgs,+ /// Override the local data directory (default: $HOME/.screenpipe)+ #[arg(long)]+ data_dir: Option<String>,+ },+ /// Scan ~/.ssh/config and ~/.ssh/known_hosts for candidate hosts+ Discover {+ /// Output as JSON+ #[arg(long, default_value_t = false)]+ json: bool,+ },+}++/// Shared connection flags for `screenpipe sync remote {test,now}`.+///+/// All values can also come from env vars: SCREENPIPE_REMOTE_HOST,+/// SCREENPIPE_REMOTE_USER, SCREENPIPE_REMOTE_KEY, SCREENPIPE_REMOTE_PATH.+#[derive(clap::Args, Debug)]+pub struct RemoteSyncArgs {+ /// Remote host (IP or DNS, e.g. "myserver.tail-scale.ts.net")+ #[arg(long, env = "SCREENPIPE_REMOTE_HOST")]+ pub host: String,+ /// SSH user+ #[arg(long, env = "SCREENPIPE_REMOTE_USER")]+ pub user: String,+ /// Path to SSH private key (e.g. ~/.ssh/id_ed25519)+ #[arg(long, env = "SCREENPIPE_REMOTE_KEY")]+ pub key_path: String,+ /// Absolute path on the remote where ~/.screenpipe/ should land+ #[arg(long, env = "SCREENPIPE_REMOTE_PATH")]+ pub remote_path: String,+ /// SSH port+ #[arg(long, default_value_t = 22)]+ pub port: u16,}// =============================================================================diff --git a/crates/screenpipe-engine/src/cli/sync.rs b/crates/screenpipe-engine/src/cli/sync.rsindex cb205539c..21d9494c6 100644--- a/crates/screenpipe-engine/src/cli/sync.rs+++ b/crates/screenpipe-engine/src/cli/sync.rs@@ -11,8 +11,12 @@ use screenpipe_core::sync::{use screenpipe_db::DatabaseManager;use tracing::{debug, error, info};-use super::{get_or_create_machine_id, OutputFormat, RecordArgs, SyncCommand};+use super::{+ get_or_create_machine_id, OutputFormat, RecordArgs, RemoteSyncArgs, RemoteSyncCommand,+ SyncCommand,+};use crate::sync_provider::ScreenpipeSyncProvider;+use screenpipe_connect::remote_sync;/// Start the cloud sync servicepub async fn start_sync_service(@@ -159,6 +163,9 @@ pub async fn handle_sync_command(command: &SyncCommand) -> anyhow::Result<()> {}}}+ SyncCommand::Remote { subcommand } => {+ return handle_remote_sync_command(subcommand).await;+ }SyncCommand::Download { hours, port } => {let url = format!("{}:{}/sync/download?hours={}", server_url, port, hours);match client.post(&url).send().await {@@ -187,3 +194,98 @@ pub async fn handle_sync_command(command: &SyncCommand) -> anyhow::Result<()> {Ok(())}++fn build_sync_config(cfg: &RemoteSyncArgs) -> remote_sync::SyncConfig {+ // Expand leading "~" in the key path so the user can pass `~/.ssh/id_ed25519`.+ let key_path = if let Some(rest) = cfg.key_path.strip_prefix("~/") {+ if let Some(home) = dirs::home_dir() {+ home.join(rest).to_string_lossy().into_owned()+ } else {+ cfg.key_path.clone()+ }+ } else {+ cfg.key_path.clone()+ };++ remote_sync::SyncConfig {+ host: cfg.host.clone(),+ port: cfg.port,+ user: cfg.user.clone(),+ key_path,+ remote_path: cfg.remote_path.clone(),+ // CLI is one-shot; the scheduler is owned by the desktop app.+ interval_minutes: 0,+ enabled: true,+ }+}++/// Handle `screenpipe sync remote ...` — SFTP push of ~/.screenpipe to an SSH server.+async fn handle_remote_sync_command(command: &RemoteSyncCommand) -> anyhow::Result<()> {+ match command {+ RemoteSyncCommand::Test { cfg } => {+ let config = build_sync_config(cfg);+ println!("testing ssh connection to {}@{}:{}…", config.user, config.host, config.port);+ match remote_sync::test_connection(&config).await {+ Ok(()) => println!(" ✓ ok"),+ Err(e) => {+ eprintln!(" ✗ failed: {e}");+ std::process::exit(1);+ }+ }+ }+ RemoteSyncCommand::Now { cfg, data_dir } => {+ let config = build_sync_config(cfg);+ let dir = match data_dir {+ Some(d) if !d.is_empty() => std::path::PathBuf::from(d),+ _ => screenpipe_core::paths::default_screenpipe_data_dir(),+ };+ println!(+ "pushing {} to {}:{}{} …",+ dir.display(),+ config.host,+ if config.port == 22 { String::new() } else { format!(":{}", config.port) },+ config.remote_path,+ );+ let result = remote_sync::sync_to_remote(&config, &dir).await;+ if result.ok {+ println!(+ " ✓ synced {} files ({:.2} MB)",+ result.files_transferred,+ result.bytes_transferred as f64 / 1_048_576.0,+ );+ } else {+ eprintln!(+ " ✗ sync failed after {} files: {}",+ result.files_transferred,+ result.error.unwrap_or_else(|| "unknown".into()),+ );+ std::process::exit(1);+ }+ }+ RemoteSyncCommand::Discover { json } => {+ let hosts = remote_sync::discover_ssh_hosts().await;+ if *json {+ println!("{}", serde_json::to_string_pretty(&hosts)?);+ } else if hosts.is_empty() {+ println!("no candidate hosts found in ~/.ssh/config or ~/.ssh/known_hosts");+ } else {+ println!("candidate ssh hosts:");+ for h in hosts {+ let alias = h.alias.as_deref().map(|a| format!(" ({a})")).unwrap_or_default();+ let user = h.user.as_deref().unwrap_or("<unset>");+ let key = h.key_path.as_deref().unwrap_or("<unset>");+ println!(+ " {host}:{port}{alias} user={user} key={key} source={src}",+ host = h.host,+ port = h.port,+ alias = alias,+ user = user,+ key = key,+ src = h.source,+ );+ }+ }+ }+ }+ Ok(())+}