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

feat: pipe store now works with public github repo

Louis Beaumontb9989ee22653
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index 0281ba5ef..7a33347a1 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -125,7 +125,20 @@ static-ffmpeg = ["ffmpeg-next/static"]
metal = ["candle/metal", "candle-nn/metal", "candle-transformers/metal"]
cuda = ["candle/cuda", "candle-nn/cuda", "candle-transformers/cuda"]
-pipes = ["screenpipe-core/pipes"]
+pipes = [
+ "screenpipe-core/pipes",
+ "tempfile",
+ "url",
+]
+
+[dependencies.tempfile]
+version = "3.2"
+optional = true
+
+[dependencies.url]
+version = "2.2"
+optional = true
+
[[bin]]
name = "screenpipe"
diff --git a/screenpipe-server/src/bin/screenpipe-pipe-runner.rs b/screenpipe-server/src/bin/screenpipe-pipe-runner.rs
index 5507c30cc..8f22b6d18 100644
--- a/screenpipe-server/src/bin/screenpipe-pipe-runner.rs
+++ b/screenpipe-server/src/bin/screenpipe-pipe-runner.rs
@@ -1,13 +1,18 @@
use clap::Parser;
-use log::LevelFilter;
+use log::{info, warn, LevelFilter};
+use reqwest;
#[cfg(feature = "pipes")]
use screenpipe_core::run_js;
use screenpipe_server::Cli;
+use std::io::Write;
use std::path::Path;
+use tempfile::NamedTempFile;
+use url::Url;
#[cfg(feature = "pipes")]
-fn main() {
- let cli = Cli::parse(); // Parse CLI arguments
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let cli = Cli::parse();
if cli.pipe.is_empty() {
eprintln!("No pipe specified. Use --pipe to specify the pipe.");
@@ -20,17 +25,88 @@ fn main() {
.format_timestamp_secs()
.init();
- let path_to_main_module = Path::new(cli.pipe[0].as_str()).canonicalize().unwrap();
+ warn!("Warning: only 1 pipe is supported right now. This will change in the future.");
+
+ let pipe_input = &cli.pipe[0];
+ let path_to_main_module = if Url::parse(pipe_input).is_ok() {
+ download_pipe(pipe_input).await?
+ } else {
+ Path::new(pipe_input).canonicalize()?
+ };
- let runtime = tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .unwrap();
- if let Err(error) = runtime.block_on(run_js(&path_to_main_module.to_string_lossy())) {
+ if let Err(error) = run_js(&path_to_main_module.to_string_lossy()).await {
eprintln!("error: {error}");
}
+
+ Ok(())
+}
+
+fn get_raw_github_url(url: &str) -> Result<String, Box<dyn std::error::Error>> {
+ let parsed_url = Url::parse(url)?;
+ if parsed_url.host_str() == Some("github.com") {
+ let path_segments: Vec<&str> = parsed_url.path_segments().unwrap().collect();
+ if path_segments.len() >= 3 {
+ let (owner, repo, _, branch) = (
+ path_segments[0],
+ path_segments[1],
+ path_segments[2],
+ path_segments[3],
+ );
+ let raw_path = path_segments[4..].join("/");
+ return Ok(format!(
+ "https://raw.githubusercontent.com/{}/{}/{}/{}",
+ owner, repo, branch, raw_path
+ ));
+ }
+ }
+ Ok(url.to_string())
+}
+
+async fn download_pipe(url: &str) -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
+ info!("Downloading pipe from URL: {}", url);
+
+ let raw_url = get_raw_github_url(url)?;
+ let parsed_url = Url::parse(&raw_url)?;
+ if parsed_url.host_str() != Some("raw.githubusercontent.com") {
+ return Err(
+ "Only public GitHub URLs or raw.githubusercontent.com URLs are supported".into(),
+ );
+ }
+
+ info!("Downloading... ");
+ std::io::stdout().flush()?;
+
+ let response = reqwest::get(&raw_url).await?;
+ let content = response.text().await?;
+
+ let mut temp_file = NamedTempFile::new()?;
+ temp_file.write_all(content.as_bytes())?;
+
+ // Extract the file extension from the URL
+ let extension = Path::new(url)
+ .extension()
+ .and_then(|ext| ext.to_str())
+ .unwrap_or("js"); // Default to .js if no extension is found
+
+ // Create a new temporary file with the correct extension
+ let temp_path = temp_file.into_temp_path();
+ let final_path = temp_path.with_extension(extension);
+ std::fs::rename(temp_path, &final_path)?;
+
+ info!("Done!");
+
+ Ok(final_path)
}
+/*
+
+PIPE_URL=https://raw.githubusercontent.com/mediar-ai/screenpipe/main/examples/typescript/pipe-tagging-activity/main.js
+ollama run phi3.5
+cargo build --release --features pipes
+./target/release/screenpipe --pipe $PIPE_URL --port 3035 --data-dir /tmp/sp
+
+*/
+
#[cfg(not(feature = "pipes"))]
fn main() {
eprintln!("Pipes support is not enabled. Compile with --features pipes to enable it.");
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index 217b7589f..b59e97a50 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -139,6 +139,7 @@ pub struct Cli {
#[arg(short = 'm', long)]
pub monitor_id: Option<u32>,
+ #[cfg(feature = "pipes")]
/// File path for the pipe
#[arg(long)]
pub pipe: Vec<String>,