Skip to content

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

fix: CLI connection list now queries running server to include WhatsApp

Louis Beaumont348e682da64f
diff --git a/crates/screenpipe-engine/src/cli/connection.rs b/crates/screenpipe-engine/src/cli/connection.rs
index 64dccc3b5..63ff9f0bf 100644
--- a/crates/screenpipe-engine/src/cli/connection.rs
+++ b/crates/screenpipe-engine/src/cli/connection.rs
@@ -6,17 +6,51 @@ use super::ConnectionCommand;
use screenpipe_connect::connections::ConnectionManager;
use serde_json::{json, Map, Value};
+/// Try to get connection list from the running server (includes WhatsApp etc).
+/// Falls back to local ConnectionManager if the server isn't reachable.
+async fn fetch_connections_list(
+ screenpipe_dir: &std::path::Path,
+) -> Vec<Value> {
+ // Try the running server first — it includes dynamic integrations like WhatsApp
+ if let Ok(resp) = reqwest::Client::new()
+ .get("http://localhost:3030/connections")
+ .timeout(std::time::Duration::from_secs(2))
+ .send()
+ .await
+ {
+ if let Ok(body) = resp.json::<Value>().await {
+ if let Some(arr) = body.get("data").and_then(|d| d.as_array()) {
+ return arr.clone();
+ }
+ }
+ }
+
+ // Fallback: use local ConnectionManager (no WhatsApp / dynamic integrations)
+ let cm = ConnectionManager::new(screenpipe_dir.to_path_buf());
+ cm.list()
+ .into_iter()
+ .map(|info| {
+ json!({
+ "id": info.def.id,
+ "name": info.def.name,
+ "description": info.def.description,
+ "connected": info.connected,
+ })
+ })
+ .collect()
+}
+
/// Handle connection subcommands (standalone — does NOT require a running server).
pub async fn handle_connection_command(command: &ConnectionCommand) -> anyhow::Result<()> {
let screenpipe_dir = dirs::home_dir()
.ok_or_else(|| anyhow::anyhow!("could not find home directory"))?
.join(".screenpipe");
- let cm = ConnectionManager::new(screenpipe_dir);
+ let cm = ConnectionManager::new(screenpipe_dir.clone());
match command {
ConnectionCommand::List { json: use_json } => {
- let list = cm.list();
+ let list = fetch_connections_list(&screenpipe_dir).await;
if *use_json {
println!("{}", serde_json::to_string_pretty(&list)?);
} else if list.is_empty() {
@@ -24,17 +58,32 @@ pub async fn handle_connection_command(command: &ConnectionCommand) -> anyhow::R
} else {
println!("{:<20} {:<12} {:<40}", "ID", "STATUS", "NAME");
println!("{}", "-".repeat(72));
- for info in &list {
- let status = if info.connected { "connected" } else { "-" };
- println!(
- "{:<20} {:<12} {:<40}",
- info.def.id, status, info.def.name
- );
+ for item in &list {
+ let id = item.get("id").and_then(|v| v.as_str()).unwrap_or("-");
+ let name = item.get("name").and_then(|v| v.as_str()).unwrap_or("-");
+ let connected = item.get("connected").and_then(|v| v.as_bool()).unwrap_or(false);
+ let status = if connected { "connected" } else { "-" };
+ println!("{:<20} {:<12} {:<40}", id, status, name);
}
}
}
ConnectionCommand::Get { id, json: use_json } => {
+ // WhatsApp: show gateway info instead of credentials
+ if id == "whatsapp" {
+ let info = fetch_whatsapp_info().await;
+ if *use_json {
+ println!("{}", serde_json::to_string_pretty(&info)?);
+ } else {
+ let status = info.get("status").and_then(|v| v.as_str()).unwrap_or("unknown");
+ println!("whatsapp: {}", status);
+ if let Some(desc) = info.get("description").and_then(|v| v.as_str()) {
+ println!("\n{}", desc);
+ }
+ }
+ return Ok(());
+ }
+
match cm.get_credentials(id)? {
Some(creds) => {
if *use_json {
@@ -98,3 +147,22 @@ pub async fn handle_connection_command(command: &ConnectionCommand) -> anyhow::R
Ok(())
}
+
+/// Fetch WhatsApp gateway info from the running server.
+async fn fetch_whatsapp_info() -> Value {
+ if let Ok(resp) = reqwest::Client::new()
+ .get("http://localhost:3030/connections/whatsapp/status")
+ .timeout(std::time::Duration::from_secs(2))
+ .send()
+ .await
+ {
+ if let Ok(body) = resp.json::<Value>().await {
+ return body;
+ }
+ }
+
+ json!({
+ "status": "unknown",
+ "description": "WhatsApp gateway status unavailable. Make sure screenpipe is running."
+ })
+}